diff --git a/project/jni/glshim/src/gl/gl.c b/project/jni/glshim/src/gl/gl.c index 6b0011cb2..2f129aaaf 100755 --- a/project/jni/glshim/src/gl/gl.c +++ b/project/jni/glshim/src/gl/gl.c @@ -687,8 +687,13 @@ void glshim_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid } noerrorShim(); - GLushort *sindices = copy_gl_array((glstate.vao->elements)?glstate.vao->elements->data + (uintptr_t)indices:indices, - type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + GLushort *sindices; + bool need_free = (type!=GL_UNSIGNED_SHORT); + if(need_free) + sindices = copy_gl_array((glstate.vao->elements)?glstate.vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + else + sindices = (glstate.vao->elements)?(glstate.vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; bool compiling = (glstate.list.active && (glstate.list.compiling || glstate.gl_batch)); if (compiling) { @@ -700,7 +705,7 @@ void glshim_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid normalize_indices(sindices, &max, &min, count); list = arrays_to_renderlist(list, mode, min, max + 1); - list->indices = sindices; + list->indices = (need_free)?sindices:copy_gl_array(sindices, type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); list->ilen = count; list->indice_cap = count; //end_renderlist(list); @@ -715,7 +720,7 @@ void glshim_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid normalize_indices(sindices, &max, &min, count); list = arrays_to_renderlist(list, mode, min, max + 1); - list->indices = sindices; + list->indices = (need_free)?sindices:copy_gl_array(sindices, type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); list->ilen = count; list->indice_cap = count; end_renderlist(list); @@ -871,7 +876,8 @@ void glshim_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid shift_pointer(tex_coord[aa], tex_coord_array[aa]); shift_pointer(normal, normal_array); #undef shift_pointer - free(sindices); + if(need_free) + free(sindices); } } void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) __attribute__((alias("glshim_glDrawElements"))); diff --git a/project/jni/glshim/src/gl/pixel.c b/project/jni/glshim/src/gl/pixel.c index fb50e8d8c..4d3a1cf9f 100755 --- a/project/jni/glshim/src/gl/pixel.c +++ b/project/jni/glshim/src/gl/pixel.c @@ -713,13 +713,58 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, } return true; } - 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))) { + if ((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 = (((((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); + //tmp = *(const GLuint*)src_pos; + unsigned char* byte_src = (unsigned char*)src_pos; + *(GLushort*)dst_pos = ((((int)byte_src[0])*77 + ((int)byte_src[1])*151 + ((int)byte_src[2])*28)&0xff00)>>8 | (byte_src[3]<<8); + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + 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))) { + GLuint tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + //tmp = *(const GLuint*)src_pos; + unsigned char* byte_src = (unsigned char*)src_pos; + *(GLushort*)dst_pos = ((((int)byte_src[2])*77 + ((int)byte_src[1])*151 + ((int)byte_src[0])*28)&0xff00)>>8 | (byte_src[3]<<8); + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; + } + if (((src_format == GL_RGBA)||(src_format == GL_RGB)) && (dst_format == GL_LUMINANCE) && (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; + unsigned char* byte_src = (unsigned char*)src_pos; + *(unsigned char*)dst_pos = (((int)byte_src[0])*77 + ((int)byte_src[1])*151 + ((int)byte_src[2])*28)>>8; + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; + } + if (((src_format == GL_BGRA)||(src_format == GL_BGR)) && (dst_format == GL_LUMINANCE) && (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; + unsigned char* byte_src = (unsigned char*)src_pos; + *(unsigned char*)dst_pos = (((int)byte_src[2])*77 + ((int)byte_src[1])*151 + ((int)byte_src[0])*28)>>8; src_pos += src_stride; dst_pos += dst_stride; } @@ -756,7 +801,7 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, } 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))) { + 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)); @@ -768,7 +813,7 @@ 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))) { + 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))) { 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)); @@ -779,6 +824,54 @@ bool pixel_convert(const GLvoid *src, GLvoid **dst, dst_pos += dst_width; } return true; + } + if ((src_format == GL_RGBA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_5_5_5_1) && ((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-1)) | ((GLushort)(((char*)src_pos)[1]&0xf8)<<(5-2)) | ((GLushort)(((char*)src_pos)[0]&0xf8)<<(10-2)) | ((GLushort)(((char*)src_pos)[3]>0)?1:0); + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; + } + if ((src_format == GL_BGRA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_5_5_5_1) && ((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)[0]&0xf8)>>(3-1)) | ((GLushort)(((char*)src_pos)[1]&0xf8)<<(5-2)) | ((GLushort)(((char*)src_pos)[2]&0xf8)<<(10-2)) | ((GLushort)(((char*)src_pos)[3]>0)?1:0); + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; + } + if ((src_format == GL_RGBA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_4_4_4_4) && ((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)[3]&0xf0))>>(4) | ((GLushort)(((char*)src_pos)[2]&0xf0)) | ((GLushort)(((char*)src_pos)[1]&0xf0))<<(4) | ((GLushort)(((char*)src_pos)[0]&0xf0))<<(8); + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; + } + if ((src_format == GL_BGRA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_4_4_4_4) && ((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)[3]&0xf0)>>(4)) | ((GLushort)(((char*)src_pos)[0]&0xf0)) | ((GLushort)(((char*)src_pos)[1]&0xf0)<<(4)) | ((GLushort)(((char*)src_pos)[2]&0xf0)<<(8)); + src_pos += src_stride; + dst_pos += dst_stride; + } + if (stride) + dst_pos += dst_width; + } + return true; } if (! remap_pixel((const GLvoid *)src_pos, (GLvoid *)dst_pos, src_color, src_type, dst_color, dst_type)) { diff --git a/project/jni/glshim/src/gl/texture.c b/project/jni/glshim/src/gl/texture.c index 83245eed1..8429c31aa 100755 --- a/project/jni/glshim/src/gl/texture.c +++ b/project/jni/glshim/src/gl/texture.c @@ -119,6 +119,45 @@ static int is_fake_compressed_rgba(GLenum internalformat) return 0; } +void internal2format_type(GLenum internalformat, GLenum *format, GLenum *type) +{ + switch(internalformat) { + case GL_LUMINANCE: + *format = GL_LUMINANCE; + *type = GL_UNSIGNED_BYTE; + break; + case GL_LUMINANCE_ALPHA: + *format = GL_LUMINANCE_ALPHA; + *type = GL_UNSIGNED_BYTE; + break; + case GL_RGB5: + *format = GL_RGB; + *type = GL_UNSIGNED_SHORT_5_6_5; + break; + case GL_RGB: + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + break; + case GL_RGB5_A1: + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_5_5_5_1; + break; + case GL_RGBA4: + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_4_4_4_4; + break; + case GL_RGBA: + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + break; + default: + printf("LIBGL: Warning, unknonw Internalformat (%s)\n", PrintEnum(internalformat)); + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + break; + } +} + static void *swizzle_texture(GLsizei width, GLsizei height, GLenum *format, GLenum *type, GLenum intermediaryformat, GLenum internalformat, @@ -127,8 +166,10 @@ static void *swizzle_texture(GLsizei width, GLsizei height, GLenum dest_format = GL_RGBA; GLenum dest_type = GL_UNSIGNED_BYTE; switch (*format) { - case GL_RGB: case GL_LUMINANCE: + dest_format = GL_LUMINANCE; + break; + case GL_RGB: dest_format = GL_RGB; break; case GL_ALPHA: @@ -149,7 +190,9 @@ static void *swizzle_texture(GLsizei width, GLsizei height, else dest_format = GL_LUMINANCE_ALPHA; break; + // vvvvv all this are internal formats, so it should not happens case GL_RGB5: + dest_format = GL_RGB; dest_type = GL_UNSIGNED_SHORT_5_6_5; convert = true; break; @@ -157,6 +200,11 @@ static void *swizzle_texture(GLsizei width, GLsizei height, dest_format = GL_RGB; *format = GL_RGB; break; + case GL_RGBA4: + dest_format = GL_RGBA; + dest_type = GL_UNSIGNED_SHORT_4_4_4_4; + *format = GL_RGBA; + break; case GL_RGBA8: dest_format = GL_RGBA; *format = GL_RGBA; @@ -174,7 +222,8 @@ static void *swizzle_texture(GLsizei width, GLsizei height, case GL_UNSIGNED_SHORT_4_4_4_4: if(dest_format==GL_RGBA) dest_type = GL_UNSIGNED_SHORT_4_4_4_4; - convert = true; + else + convert = true; break; case GL_UNSIGNED_SHORT_1_5_5_5_REV: if(dest_format==GL_RGBA) @@ -184,7 +233,8 @@ static void *swizzle_texture(GLsizei width, GLsizei height, case GL_UNSIGNED_SHORT_5_5_5_1: if(dest_format==GL_RGBA) dest_type = GL_UNSIGNED_SHORT_5_5_5_1; - convert = true; + else + convert = true; break; case GL_UNSIGNED_SHORT_5_6_5_REV: if (dest_format==GL_RGB) @@ -194,6 +244,8 @@ static void *swizzle_texture(GLsizei width, GLsizei height, case GL_UNSIGNED_SHORT_5_6_5: if (dest_format==GL_RGB) dest_type = GL_UNSIGNED_SHORT_5_6_5; + else + convert = true; break; case GL_UNSIGNED_BYTE: break; @@ -211,8 +263,7 @@ static void *swizzle_texture(GLsizei width, GLsizei height, if (is_fake_compressed_rgba(internalformat)) internalformat=GL_RGBA; if(*format != intermediaryformat || intermediaryformat!=internalformat) { - dest_format = intermediaryformat; - dest_type = GL_UNSIGNED_BYTE; + internal2format_type(intermediaryformat, &dest_format, &dest_type); convert = true; } if (data) { @@ -228,8 +279,9 @@ static void *swizzle_texture(GLsizei width, GLsizei height, *format = dest_format; if(dest_format!=internalformat) { GLvoid *pix2 = (GLvoid *)pixels; + internal2format_type(internalformat, &dest_format, &dest_type); if (! pixel_convert(pixels, &pix2, width, height, - dest_format, dest_type, internalformat, dest_type, 0)) { + *format, *type, dest_format, dest_type, 0)) { printf("libGL swizzle error: (%s, %s -> %s, %s)\n", PrintEnum(dest_format), PrintEnum(dest_type), PrintEnum(internalformat), PrintEnum(dest_type)); return NULL; @@ -239,7 +291,6 @@ static void *swizzle_texture(GLsizei width, GLsizei height, free(pixels); pixels = pix2; } - dest_format = internalformat; *type = dest_type; *format = dest_format; } @@ -257,8 +308,9 @@ static void *swizzle_texture(GLsizei width, GLsizei height, } } else { if (convert) { + internal2format_type(internalformat, &dest_format, &dest_type); // in case they are differents *type = dest_type; - *format = internalformat; + *format = dest_format; } } return (void *)data; @@ -281,6 +333,8 @@ GLenum swizzle_internalformat(GLenum *internalformat) { sret = GL_LUMINANCE_ALPHA; break; case GL_RGB5: + sret = GL_RGB5; + break; case GL_RGB8: case GL_RGB: case GL_BGR: @@ -290,14 +344,18 @@ GLenum swizzle_internalformat(GLenum *internalformat) { case 3: ret = GL_RGB; sret = GL_RGB; break; + case GL_RGBA4: + sret = GL_RGBA4; + break; + case GL_RGB5_A1: + sret = GL_RGB5_A1; + break; case GL_RGBA: case GL_RGBA8: - case GL_RGBA4: case GL_BGRA: case GL_RGBA16: case GL_RGBA16F: case GL_RGBA32F: - case GL_RGB5_A1: case GL_RGB10_A2: case 4: ret = GL_RGBA; sret = GL_RGBA; @@ -872,20 +930,25 @@ void glshim_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yof #endif { //pixels = (GLvoid *)swizzle_texture(width, height, &format, &type, old); - if (!pixel_convert(old, &pixels, width, height, format, type, orig_internal, bound->type, 0)) { + GLenum dest_format, dest_type; + internal2format_type(orig_internal, &dest_format, &dest_type); + if (!pixel_convert(old, &pixels, width, height, format, type, dest_format, dest_type, 0)) { printf("LIBGL: Error in pixel_convert while glTexSubImage2D\n"); } else { + format = dest_format; + type = dest_type; if(orig_internal!=internalformat) { GLvoid* pix2 = pixels; - if (!pixel_convert(pixels, &pix2, width, height, orig_internal, bound->type, internalformat, bound->type, 0)) { + internal2format_type(internalformat, &dest_format, &dest_type); + if (!pixel_convert(pixels, &pix2, width, height, format, type, dest_format, dest_type, 0)) { printf("LIBGL: Error in pixel_convert while glTexSubImage2D\n"); } if (pixels != pix2 && pixels != old) free(pixels); pixels = pix2; + format = dest_format; + type = dest_type; } - format = internalformat; - type = bound->type; } } @@ -1209,8 +1272,8 @@ void glshim_glTexParameteri(GLenum target, GLenum pname, GLint param) { case GL_LINEAR_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_LINEAR: if (texture) - texture->mipmap_need = true; - if ((automipmap==3) || ((texture) && (texture->mipmap_auto==0))) + texture->mipmap_need = true; + if ((automipmap==3) || ((texture) && (automipmap==1) && (texture->mipmap_auto==0))) switch (param) { case GL_NEAREST_MIPMAP_NEAREST: case GL_NEAREST_MIPMAP_LINEAR: diff --git a/project/jni/glshim/src/glx/glx.c b/project/jni/glshim/src/glx/glx.c index eef7a1fee..cf9f90464 100755 --- a/project/jni/glshim/src/glx/glx.c +++ b/project/jni/glshim/src/glx/glx.c @@ -148,6 +148,7 @@ static int fbcontext_count = 0; #ifdef PANDORA #ifndef FBIO_WAITFORVSYNC #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) +static float pandora_gamma = 0.0f; #endif static int fbdev = -1; static bool g_vsync = false; @@ -207,9 +208,26 @@ static void xrefresh() { system("xrefresh"); } +#ifdef PANDORA +static void pandora_reset_gamma() { + if(pandora_gamma>0.0f) + system("sudo /usr/pandora/scripts/op_gamma.sh 0"); +} +static void pandora_set_gamma() { + if(pandora_gamma>0.0f) { + char buf[50]; + sprintf(buf, "sudo /usr/pandora/scripts/op_gamma.sh %.2f", pandora_gamma); + system(buf); + } +} +#endif + static void signal_handler(int sig) { if (g_xrefresh) xrefresh(); +#ifdef PANDORA + pandora_reset_gamma(); +#endif #ifdef BCMHOST if (g_bcm_active) { @@ -439,6 +457,14 @@ static void scan_env() { printf("LIBGL: Overide version string with \"%s\" (should be in the form of \"1.x\")\n", env_version); } snprintf(glshim_version, 49, "%s glshim wrapper", (env_version)?env_version:"1.5"); +#ifdef PANDORA + char *env_gamma = getenv("LIBGL_GAMMA"); + if (env_gamma) { + pandora_gamma=atof(env_gamma); + printf("LIBGL: Set gamma to %.2f\n", pandora_gamma); + atexit(pandora_reset_gamma); + } +#endif char cwd[1024]; if (getcwd(cwd, sizeof(cwd))!= NULL) @@ -725,6 +751,9 @@ Bool glXMakeCurrent(Display *display, context->drawable = drawable; +#ifdef PANDORA + pandora_set_gamma(); +#endif CheckEGLErrors(); if (result) { if (g_usefbo) {