From bf1ecff0d9849adc3e103b16b4d5502a26d22f2b Mon Sep 17 00:00:00 2001 From: lubomyr Date: Wed, 9 Mar 2016 22:43:09 +0200 Subject: [PATCH] glshim updated, added latest changes by ptitSeb --- project/jni/glshim/src/gl/debug.c | 4 ++ project/jni/glshim/src/gl/pixel.c | 6 +-- project/jni/glshim/src/gl/texture.c | 63 +++++++++++++++++++++-------- project/jni/nanogl | 1 + 4 files changed, 54 insertions(+), 20 deletions(-) create mode 160000 project/jni/nanogl diff --git a/project/jni/glshim/src/gl/debug.c b/project/jni/glshim/src/gl/debug.c index 9e6b6dee6..baa1c3c15 100755 --- a/project/jni/glshim/src/gl/debug.c +++ b/project/jni/glshim/src/gl/debug.c @@ -70,6 +70,10 @@ const char* PrintEnum(GLenum what) { p(GL_UNSIGNED_SHORT_5_6_5_REV); p(GL_FLOAT); p(GL_DOUBLE); + // texture infos + p(GL_TEXTURE_WIDTH); + p(GL_TEXTURE_HEIGHT); + p(GL_TEXTURE_COMPRESSED); // texture pack/unpack p(GL_UNPACK_ALIGNMENT); // framebuffer diff --git a/project/jni/glshim/src/gl/pixel.c b/project/jni/glshim/src/gl/pixel.c index 659b2e549..e1aca880e 100755 --- a/project/jni/glshim/src/gl/pixel.c +++ b/project/jni/glshim/src/gl/pixel.c @@ -457,7 +457,7 @@ bool half_pixel(const GLvoid *src0, const GLvoid *src1, ) default: // TODO: add glSetError? - printf("libGL: half_pixel: Unsupported source data type: %04X\n", src_type); + printf("libGL: half_pixel: Unsupported source data type: %s\n", PrintEnum(src_type)); return false; break; } @@ -848,8 +848,8 @@ bool pixel_halfscale(const GLvoid *old, GLvoid **new, GLuint width, GLuint height, GLenum format, GLenum type) { GLuint pixel_size, new_width, new_height; - new_width = width / 2; - new_height = height / 2; + new_width = width / 2; if(new_width==0) new_width=1; + new_height = height / 2; if(new_height==0) new_height==1; /* if (new_width*2!=width || new_height*2!=height) { printf("LIBGL: halfscaling %ux%u failed\n", width, height); return false; diff --git a/project/jni/glshim/src/gl/texture.c b/project/jni/glshim/src/gl/texture.c index 8e0fa3b57..b9049542e 100755 --- a/project/jni/glshim/src/gl/texture.c +++ b/project/jni/glshim/src/gl/texture.c @@ -225,7 +225,7 @@ static void *swizzle_texture(GLsizei width, GLsizei height, pixels = pix2; } dest_format = internalformat; - *type = internalformat; + *type = dest_type; *format = dest_format; } GLvoid *pix2 = pixels; @@ -308,15 +308,15 @@ GLenum swizzle_internalformat(GLenum *internalformat) { break; // compressed format... case GL_COMPRESSED_ALPHA: - ret = GL_ALPHA; + ret = GL_COMPRESSED_RGBA; sret = GL_ALPHA; break; case GL_COMPRESSED_LUMINANCE: - ret = GL_LUMINANCE; + ret = GL_COMPRESSED_RGB; sret = GL_LUMINANCE; break; case GL_COMPRESSED_LUMINANCE_ALPHA: - ret = GL_LUMINANCE_ALPHA; + ret = GL_COMPRESSED_RGBA; if (nolumalpha) sret = GL_RGBA; else @@ -328,7 +328,15 @@ GLenum swizzle_internalformat(GLenum *internalformat) { case GL_COMPRESSED_RGBA: sret = GL_RGBA; break; - + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + ret = GL_COMPRESSED_RGB; + sret = GL_RGB; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: // not good, but there is no DXT3 compressor + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + ret = GL_COMPRESSED_RGBA; + sret = GL_RGB; + break; default: ret = GL_RGBA; sret = GL_RGBA; @@ -1327,7 +1335,7 @@ GLboolean glshim_glAreTexturesResident(GLsizei n, const GLuint *textures, GLbool } void glshim_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params) { -//printf("glGetTexLevelParameteriv(0x%04X, %d, 0x%04X, %p)\n", target, level, pname, params); + //printf("glGetTexLevelParameteriv(%s, %d, %s, %p)\n", PrintEnum(target), level, PrintEnum(pname), params); // simplification: (mostly) not taking "target" into account here if (glstate.gl_batch) flush(); *params = 0; @@ -1339,16 +1347,26 @@ void glshim_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, G (*params) = proxy_width>>level; else (*params) = ((bound)?bound->width:2048)>>level; - if (*params<=0) // 1 is the minimum, not 0 - *params = 1; + if(bound && ((bound->orig_internal==GL_COMPRESSED_RGB) || (bound->orig_internal==GL_COMPRESSED_RGBA))) { + if (*params<4) // minimum size of a compressed block is 4 + *params = 0; + } else { + if (*params<=0) // 1 is the minimum, not 0 + *params = 1; + } break; case GL_TEXTURE_HEIGHT: if (target==GL_PROXY_TEXTURE_2D) (*params) = proxy_height>>level; else (*params) = ((bound)?bound->height:2048)>>level; - if (*params<=0) // 1 is the minimum, not 0 - *params = 1; + if(bound && ((bound->orig_internal==GL_COMPRESSED_RGB) || (bound->orig_internal==GL_COMPRESSED_RGBA))) { + if (*params<4) // minimum size of a compressed block is 4 + *params = 0; + } else { + if (*params<=0) // 1 is the minimum, not 0, but only on uncompressed textures + *params = 1; + } break; case GL_TEXTURE_INTERNAL_FORMAT: if (bound && bound->compressed) @@ -1416,18 +1434,29 @@ void glshim_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type if (glstate.gl_batch) flush(); if (glstate.texture.bound[glstate.texture.active]==NULL) return; // no texture bounded... + gltexture_t* bound = glstate.texture.bound[glstate.texture.active]; + int width = bound->width; + int height = bound->height; if (level != 0) { - //TODO - printf("STUBBED glGetTexImage with level=%i\n", level); - return; + //printf("STUBBED glGetTexImage with level=%i\n", level); + void* tmp = malloc(width*height*pixel_sizeof(format, type)); // tmp space... + void* tmp2; + glshim_glGetTexImage(target, 0, format, type, tmp); + for (int i=0; i1) width>>=1; + if(height>1) height>>=1; + } + memcpy(img, tmp, width*height*pixel_sizeof(format, type)); + free(tmp); + return; } if (target!=GL_TEXTURE_2D) return; - gltexture_t* bound = glstate.texture.bound[glstate.texture.active]; - int width = bound->width; - int height = bound->height; //printf("glGetTexImage(0x%04X, %i, 0x%04X, 0x%04X, 0x%p), texture=%u, size=%i,%i\n", target, level, format, type, img, bound->glname, width, height); GLvoid *dst = img; @@ -1879,8 +1908,8 @@ void glshim_glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, void glshim_glGetCompressedTexImage(GLenum target, GLint lod, GLvoid *img) { if (glstate.gl_batch) flush(); -// printf("LIBGL: Stub GetCompressedTexImage\n"); gltexture_t* bound = glstate.texture.bound[glstate.texture.active]; + //printf("glGetCompressedTexImage(%s, %i, %p), bound=%p, bound->orig_internal=%s\n", PrintEnum(target), lod, img, bound, (bound)?PrintEnum(bound->orig_internal):"nil"); errorShim(GL_INVALID_OPERATION); if(!bound) return; diff --git a/project/jni/nanogl b/project/jni/nanogl new file mode 160000 index 000000000..5ea04e403 --- /dev/null +++ b/project/jni/nanogl @@ -0,0 +1 @@ +Subproject commit 5ea04e4036c1b08a520699d8f3da32be31797625