diff --git a/project/jni/glshim/src/gl/gl.c b/project/jni/glshim/src/gl/gl.c index 98fd29cac..fa2eef754 100755 --- a/project/jni/glshim/src/gl/gl.c +++ b/project/jni/glshim/src/gl/gl.c @@ -30,7 +30,7 @@ GLuint readhack_seq = 0; GLuint gl_batch = 0; GLuint gl_mergelist = 1; int blendhack = 0; -char gl_version[50]; +char glshim_version[50]; int initialized = 0; int noerror = 0; @@ -121,7 +121,7 @@ const GLubyte *glshim_glGetString(GLenum name) { printf("**warning** glGetString(%i) called with bad init\n", name);*/ switch (name) { case GL_VERSION: - return (GLubyte *)gl_version; + return (GLubyte *)glshim_version; case GL_EXTENSIONS: return (const GLubyte *)(char *){ "GL_EXT_abgr " @@ -1208,7 +1208,7 @@ void glBegin(GLenum mode) __attribute__((alias("glshim_glBegin"))); void glshim_glEnd() { if (!glstate.list.active) return; - // check if TEXTUREx is activate and no TexCoord (or texgen), in that cas, create a dummy one base on glstate... + // check if TEXTUREx is activate and no TexCoord (or texgen), in that case, create a dummy one base on glstate... for (int a=0; atex[a]==0) && (!glstate.enable.texgen_s[a]))) rlMultiTexCoord4f(glstate.list.active, GL_TEXTURE0+a, glstate.texcoord[a][0], glstate.texcoord[a][1], glstate.texcoord[a][2], glstate.texcoord[a][3]); @@ -1227,7 +1227,6 @@ void glshim_glEnd() { void glEnd() __attribute__((alias("glshim_glEnd"))); void glshim_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) { - glstate.normal[0] = nx; glstate.normal[1] = ny; glstate.normal[2] = nz; if (glstate.list.active) { if (glstate.list.active->stage != STAGE_DRAW) { if (glstate.list.active->stage != STAGE_DRAW) { @@ -1245,6 +1244,7 @@ void glshim_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) { errorGL(); } #endif + glstate.normal[0] = nx; glstate.normal[1] = ny; glstate.normal[2] = nz; } void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) __attribute__((alias("glshim_glNormal3f"))); @@ -1257,9 +1257,6 @@ void glshim_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) { void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) __attribute__((alias("glshim_glVertex4f"))); void glshim_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { - // change the state first thing - glstate.color[0] = red; glstate.color[1] = green; - glstate.color[2] = blue; glstate.color[3] = alpha; if (glstate.list.active) { if (glstate.list.active->stage != STAGE_DRAW) { PUSH_IF_COMPILING(glColor4f); @@ -1274,19 +1271,22 @@ void glshim_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { errorGL(); } #endif + // change the state last thing + glstate.color[0] = red; glstate.color[1] = green; + glstate.color[2] = blue; glstate.color[3] = alpha; } void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) __attribute__((alias("glshim_glColor4f"))); void glshim_glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b) { - // change the state first thing - glstate.secondary[0] = r; glstate.secondary[1] = g; - glstate.secondary[2] = b; if (glstate.list.active) { rlSecondary3f(glstate.list.active, r, g, b); noerrorShim(); } else { noerrorShim(); } + // change the state last thing + glstate.secondary[0] = r; glstate.secondary[1] = g; + glstate.secondary[2] = b; } void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b) __attribute__((alias("glshim_glSecondaryColor3f"))); @@ -1328,20 +1328,18 @@ void glMaterialf(GLenum face, GLenum pname, const GLfloat param) __attribute__(( #endif void glshim_glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) { - glstate.texcoord[0][0] = s; glstate.texcoord[0][1] = t; - glstate.texcoord[0][2] = r; glstate.texcoord[0][3] = q; if (glstate.list.active) { rlTexCoord4f(glstate.list.active, s, t, r, q); noerrorShim(); } else { noerrorShim(); } + glstate.texcoord[0][0] = s; glstate.texcoord[0][1] = t; + glstate.texcoord[0][2] = r; glstate.texcoord[0][3] = q; } void glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) __attribute__((alias("glshim_glTexCoord4f"))); void glshim_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { - glstate.texcoord[target-GL_TEXTURE0][0] = s; glstate.texcoord[target-GL_TEXTURE0][1] = t; - glstate.texcoord[target-GL_TEXTURE0][2] = r; glstate.texcoord[target-GL_TEXTURE0][3] = q; // TODO, error if target is unsuported texture.... if (glstate.list.active) { rlMultiTexCoord4f(glstate.list.active, target, s, t, r, q); @@ -1349,6 +1347,8 @@ void glshim_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GL } else { noerrorShim(); } + glstate.texcoord[target-GL_TEXTURE0][0] = s; glstate.texcoord[target-GL_TEXTURE0][1] = t; + glstate.texcoord[target-GL_TEXTURE0][2] = r; glstate.texcoord[target-GL_TEXTURE0][3] = q; } void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) __attribute__((alias("glshim_glMultiTexCoord4f"))); void glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) __attribute__((alias("glshim_glMultiTexCoord4f"))); diff --git a/project/jni/glshim/src/gl/list.c b/project/jni/glshim/src/gl/list.c index 7828860aa..99a77ff4a 100755 --- a/project/jni/glshim/src/gl/list.c +++ b/project/jni/glshim/src/gl/list.c @@ -1112,7 +1112,7 @@ void rlNormal3f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z) { list->normal = alloc_sublist(3, list->cap); // catch up int i; - if (list->len) for (i = 0; i < list->len-1; i++) { + if (list->len) for (i = 0; i < list->len; i++) { GLfloat *normal = (list->normal + (i * 3)); memcpy(normal, list->lastNormal, sizeof(GLfloat) * 3); } @@ -1127,7 +1127,7 @@ void rlColor4f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b, GLfloat a) { list->color = alloc_sublist(4, list->cap); // catch up int i; - if (list->len) for (i = 0; i < list->len-1; i++) { + if (list->len) for (i = 0; i < list->len; i++) { GLfloat *color = (list->color + (i * 4)); memcpy(color, glstate.color, sizeof(GLfloat) * 4); }/* else { @@ -1145,7 +1145,7 @@ void rlSecondary3f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b) { list->secondary = alloc_sublist(4, list->cap); // catch up int i; - if (list->len) for (i = 0; i < list->len-1; i++) { + if (list->len) for (i = 0; i < list->len; i++) { GLfloat *secondary = (list->secondary + (i * 4)); memcpy(secondary, glstate.secondary, sizeof(GLfloat) * 4); } @@ -1250,7 +1250,7 @@ void rlTexCoord4f(renderlist_t *list, GLfloat s, GLfloat t, GLfloat r, GLfloat q list->tex[0] = alloc_sublist(4, list->cap); // catch up GLfloat *tex = list->tex[0]; - if (list->len) for (int i = 0; i < list->len-1; i++) { + if (list->len) for (int i = 0; i < list->len; i++) { memcpy(tex, glstate.texcoord[0], sizeof(GLfloat) * 4); tex += 4; } @@ -1267,7 +1267,7 @@ void rlMultiTexCoord4f(renderlist_t *list, GLenum target, GLfloat s, GLfloat t, list->tex[tmu] = alloc_sublist(4, list->cap); // catch up GLfloat *tex = list->tex[tmu]; - if (list->len) for (int i = 0; i < list->len-1; i++) { + if (list->len) for (int i = 0; i < list->len; i++) { memcpy(tex, glstate.texcoord[tmu], sizeof(GLfloat) * 4); tex += 4; } diff --git a/project/jni/glshim/src/gl/pixel.c b/project/jni/glshim/src/gl/pixel.c index c5fb82251..fb50e8d8c 100755 --- a/project/jni/glshim/src/gl/pixel.c +++ b/project/jni/glshim/src/gl/pixel.c @@ -713,12 +713,13 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, } return true; } - if ((src_format == GL_BGRA) && (dst_format == GL_LUMINANCE_ALPHA) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { + if (((src_format == GL_BGRA)||(src_format == GL_RGBA)) && (dst_format == GL_LUMINANCE_ALPHA) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { GLuint tmp; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { tmp = *(const GLuint*)src_pos; - *(GLushort*)dst_pos = (tmp&0x0000ff00) | (tmp&0x000000ff); + *(GLushort*)dst_pos = (((((char*)src_pos)[2] + ((char*)src_pos)[1] + ((char*)src_pos)[0])/3)&0xff)<<8 | ((char*)src_pos)[3]; +// *(GLushort*)dst_pos = (tmp&0x0000ff00) | (tmp&0x000000ff); src_pos += src_stride; dst_pos += dst_stride; } @@ -727,8 +728,7 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, } return true; } - if ((src_format == GL_BGR) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { - GLuint tmp; + if (((src_format == GL_BGR)||(src_format == GL_BGRA)) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { ((char*)dst_pos)[0] = ((char*)src_pos)[2]; @@ -742,8 +742,21 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, } return true; } - if ((src_format == GL_RGB) && (dst_format == GL_RGB) && (dst_type = GL_UNSIGNED_SHORT_5_6_5) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { - GLuint tmp; + if ((src_format == GL_RGBA) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + ((char*)dst_pos)[0] = ((char*)src_pos)[0]; + ((char*)dst_pos)[1] = ((char*)src_pos)[1]; + ((char*)dst_pos)[2] = ((char*)src_pos)[2]; + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; + } + if (((src_format == GL_RGB)||(src_format == GL_RGBA)) && (dst_format == GL_RGB) && (dst_type = GL_UNSIGNED_SHORT_5_6_5) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[2]&0xf8)>>(3)) | ((GLushort)(((char*)src_pos)[1]&0xfc)<<(5-2)) | ((GLushort)(((char*)src_pos)[0]&0xf8)<<(11-3)); @@ -756,7 +769,6 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, return true; } if (((src_format == GL_BGR) || (src_format == GL_BGRA)) && (dst_format == GL_RGB) && (dst_type = GL_UNSIGNED_SHORT_5_6_5) && ((src_type == GL_UNSIGNED_BYTE)||(src_type == GL_UNSIGNED_INT_8_8_8_8_REV))) { - GLuint tmp; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[0]&0xf8)>>(3)) | ((GLushort)(((char*)src_pos)[1]&0xfc)<<(5-2)) | ((GLushort)(((char*)src_pos)[2]&0xf8)<<(11-3)); diff --git a/project/jni/glshim/src/gl/texture.c b/project/jni/glshim/src/gl/texture.c index 2a9f71e20..3e618c33b 100755 --- a/project/jni/glshim/src/gl/texture.c +++ b/project/jni/glshim/src/gl/texture.c @@ -384,8 +384,8 @@ void glshim_glTexImage2D(GLenum target, GLint level, GLint internalformat, //printf("glTexImage2D on target=%s with unpack_row_length(%i), size(%i,%i) and skip(%i,%i), format(internal)=%s(%s), type=%s, data=%08x, level=%i (mipmap_need=%i, mipmap_auto=%i) => texture=%u (streamed=%i), glstate.list.compiling=%d\n", PrintEnum(target), glstate.texture.unpack_row_length, width, height, glstate.texture.unpack_skip_pixels, glstate.texture.unpack_skip_rows, PrintEnum(format), PrintEnum(internalformat), PrintEnum(type), data, level, (glstate.texture.bound[glstate.texture.active])?glstate.texture.bound[glstate.texture.active]->mipmap_need:0, (glstate.texture.bound[glstate.texture.active])?glstate.texture.bound[glstate.texture.active]->mipmap_auto:0, (glstate.texture.bound[glstate.texture.active])?glstate.texture.bound[glstate.texture.active]->texture:0, (glstate.texture.bound[glstate.texture.active])?glstate.texture.bound[glstate.texture.active]->streamed:0, glstate.list.compiling); // proxy case if (target == GL_PROXY_TEXTURE_2D) { - proxy_width = ((width<(texshrink==8)?8192:2048)?0:width; - proxy_height = ((height<(texshrink==8)?8192:2048)?0:height; + proxy_width = ((width<(texshrink>=8)?8192:2048)?0:width; + proxy_height = ((height<(texshrink>=8)?8192:2048)?0:height; proxy_intformat = swizzle_internalformat(&internalformat); return; } @@ -1779,7 +1779,7 @@ void glshim_glCompressedTexImage2D(GLenum target, GLint level, GLenum internalfo errorShim(GL_INVALID_OPERATION); return; // no texture bounded... } -//printf("glCompressedTexImage2D on target=%s with size(%i,%i), internalformat=s, imagesize=%i, upackbuffer=%p\n", PrintEnum(target), width, height, PrintEnum(internalformat), imageSize, glstate.buffers.unpack?glstate.buffers.unpack->data:0); + //printf("glCompressedTexImage2D on target=%s with size(%i,%i), internalformat=%s, imagesize=%i, upackbuffer=%p\n", PrintEnum(target), width, height, PrintEnum(internalformat), imageSize, glstate.vao->unpack?glstate.vao->unpack->data:0); // hack... if (internalformat==GL_RGBA8) internalformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; @@ -1802,6 +1802,9 @@ void glshim_glCompressedTexImage2D(GLenum target, GLint level, GLenum internalfo GLvoid *datab = (GLvoid*)data; if (unpack) datab += (uintptr_t)unpack->data; + + GLenum format = GL_RGBA; + GLenum type = GL_UNSIGNED_BYTE; if (isDXTc(internalformat)) { GLvoid *pixels, *half; @@ -1825,11 +1828,15 @@ void glshim_glCompressedTexImage2D(GLenum target, GLint level, GLenum internalfo // automaticaly reduce the pixel size half=pixels; glstate.texture.bound[glstate.texture.active]->alpha = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?false:true; - glstate.texture.bound[glstate.texture.active]->format = GL_RGBA; //internalformat; - glstate.texture.bound[glstate.texture.active]->type = GL_UNSIGNED_SHORT_4_4_4_4; + format = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?GL_RGB:GL_RGBA; + glstate.texture.bound[glstate.texture.active]->format = format; //internalformat; + type = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?GL_UNSIGNED_SHORT_5_6_5:GL_UNSIGNED_SHORT_4_4_4_4; + glstate.texture.bound[glstate.texture.active]->type = type; glstate.texture.bound[glstate.texture.active]->compressed = true; - if (pixel_thirdscale(pixels, &half, width, height, GL_RGBA, GL_UNSIGNED_BYTE)) - fact = 1; + if (pixel_convert(pixels, &half, width, height, GL_RGBA, GL_UNSIGNED_BYTE, format, type, 0)) + fact = 0; +// if (pixel_thirdscale(pixels, &half, width, height, GL_RGBA, GL_UNSIGNED_BYTE)) +// fact = 1; else glstate.texture.bound[glstate.texture.active]->type = GL_UNSIGNED_BYTE; } else { @@ -1840,7 +1847,7 @@ void glshim_glCompressedTexImage2D(GLenum target, GLint level, GLenum internalfo glshim_glGetIntegerv(GL_UNPACK_ALIGNMENT, &oldalign); if (oldalign!=1) glshim_glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glshim_glTexImage2D(target, level, GL_RGBA, width>>fact, height>>fact, border, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, half); + glshim_glTexImage2D(target, level, GL_RGBA, width>>fact, height>>fact, border, type, format, half); if (oldalign!=1) glshim_glPixelStorei(GL_UNPACK_ALIGNMENT, oldalign); if (half!=pixels) diff --git a/project/jni/glshim/src/glx/glx.c b/project/jni/glshim/src/glx/glx.c index 7777dfde3..beae5405f 100755 --- a/project/jni/glshim/src/glx/glx.c +++ b/project/jni/glshim/src/glx/glx.c @@ -168,7 +168,7 @@ extern int copytex; extern int nolumalpha; extern int blendhack; extern int noerror; -extern char gl_version[50]; +extern char glshim_version[50]; bool g_recyclefbo = false; static int g_width=0, g_height=0; @@ -434,9 +434,9 @@ static void scan_env() { char *env_version = getenv("LIBGL_VERSION"); if (env_version) { - printf("LIBGL: Overide version string with \"%s\" (should be in the form of \"1.x\")\n", gl_version); + printf("LIBGL: Overide version string with \"%s\" (should be in the form of \"1.x\")\n", env_version); } - snprintf(gl_version, 49, "%s glshim wrapper", (env_version)?env_version:"1.5"); + snprintf(glshim_version, 49, "%s glshim wrapper", (env_version)?env_version:"1.5"); char cwd[1024]; if (getcwd(cwd, sizeof(cwd))!= NULL)