From 45f514b823f6e7c5b616f22c20723f70cdfa81c9 Mon Sep 17 00:00:00 2001 From: lubomyr Date: Sat, 3 Dec 2016 00:51:12 +0200 Subject: [PATCH] gl4es updated, added latest changes by ptitSeb --- project/jni/gl4es/Android.mk | 1 + project/jni/gl4es/README.md | 3 +- project/jni/gl4es/src/gl/debug.c | 7 +++ project/jni/gl4es/src/gl/getter.c | 2 + project/jni/gl4es/src/gl/gl.c | 29 +++---------- project/jni/gl4es/src/gl/init.c | 8 ++++ project/jni/gl4es/src/gl/list.c | 67 +++++++++++++++-------------- project/jni/gl4es/src/gl/texgen.c | 59 +++++++++++++++++++++---- project/jni/gl4es/src/gl/texture.c | 6 +-- project/jni/gl4es/src/gl/texture.h | 19 +++----- project/jni/gl4es/src/glx/hardext.c | 1 + project/jni/gl4es/src/glx/hardext.h | 1 + 12 files changed, 120 insertions(+), 83 deletions(-) diff --git a/project/jni/gl4es/Android.mk b/project/jni/gl4es/Android.mk index 24037fef1..4c760222c 100755 --- a/project/jni/gl4es/Android.mk +++ b/project/jni/gl4es/Android.mk @@ -51,6 +51,7 @@ LOCAL_SRC_FILES := \ src/glx/streaming.c \ LOCAL_CFLAGS += -g -std=c99 -funwind-tables -O3 -DBCMHOST -fvisibility=hidden -include include/android_debug.h +#LOCAL_CFLAGS += -DNO_INIT_CONSTRUCTOR #LOCAL_LDLIBS := -ldl -llog diff --git a/project/jni/gl4es/README.md b/project/jni/gl4es/README.md index b008b07ff..353994af1 100755 --- a/project/jni/gl4es/README.md +++ b/project/jni/gl4es/README.md @@ -225,7 +225,8 @@ Initial Hardware test Version history ---- -##### Current version +##### 0.9.3 + * Added support for Cube Mapping (with hardware support) * Improved Texture state tracking * Added LIBGL_NOTEXMAT env. var. switch for Texture Matrix handling * Added GL_EXT_vertex_array_bgra (and NEONinzed some loop) diff --git a/project/jni/gl4es/src/gl/debug.c b/project/jni/gl4es/src/gl/debug.c index 077f21873..71d71f19c 100755 --- a/project/jni/gl4es/src/gl/debug.c +++ b/project/jni/gl4es/src/gl/debug.c @@ -18,6 +18,13 @@ const char* PrintEnum(GLenum what) { p(GL_PROXY_TEXTURE_3D); p(GL_READ_FRAMEBUFFER); p(GL_DRAW_FRAMEBUFFER); + p(GL_TEXTURE_CUBE_MAP); + p(GL_TEXTURE_CUBE_MAP_POSITIVE_X); + p(GL_TEXTURE_CUBE_MAP_NEGATIVE_X); + p(GL_TEXTURE_CUBE_MAP_POSITIVE_Y); + p(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); + p(GL_TEXTURE_CUBE_MAP_POSITIVE_Z); + p(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); // format p(GL_RED); p(GL_R); diff --git a/project/jni/gl4es/src/gl/getter.c b/project/jni/gl4es/src/gl/getter.c index d286f2f46..0c3f2ba29 100755 --- a/project/jni/gl4es/src/gl/getter.c +++ b/project/jni/gl4es/src/gl/getter.c @@ -124,6 +124,8 @@ const GLubyte *gl4es_glGetString(GLenum name) { "GL_ARB_draw_buffers "); if(hardext.pointsprite) strcat(extensions, "GL_ARB_point_sprite "); + if(hardext.cubemap) + strcat(extensions, "GL_ARB_texture_cube_map "); } switch (name) { case GL_VERSION: diff --git a/project/jni/gl4es/src/gl/gl.c b/project/jni/gl4es/src/gl/gl.c index a9d6f3b41..81dd333f0 100755 --- a/project/jni/gl4es/src/gl/gl.c +++ b/project/jni/gl4es/src/gl/gl.c @@ -235,19 +235,11 @@ static void proxy_glEnable(GLenum cap, bool enable, void (*next)(GLenum)) { else glstate->enable.texture[glstate->texture.active] &= ~(1<enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<tex[0] = gen_stipple_tex_coords(list->vert, list->len); } - } - static GLfloat *texgened[MAX_TEX] = {0}; - static int texgenedsz[MAX_TEX] = {0}; - int use_texgen[MAX_TEX]; - #define RS(A, len) if(texgenedsz[A]enable.texture[a]) { - const GLint itarget = get_target(glstate->enable.texture[a]); - needclean[a]=0; - use_texgen[a]=0; - if ((glstate->enable.texgen_s[a] || glstate->enable.texgen_t[a] || glstate->enable.texgen_r[a] || glstate->enable.texgen_q[a])) { - RS(a, list->len); - gen_tex_coords(list->vert, list->normal, &texgened[a], list->len, &needclean[a], a, (list->ilenlen)?indices:NULL, (list->ilenlen)?list->ilen:0); - } else if ((list->tex[a]==NULL) && !(list->mode==GL_POINT && glstate->texture.pscoordreplace[a])) { - RS(a, list->len); - gen_tex_coords(list->vert, list->normal, &texgened[a], list->len, &needclean[a], a, (list->ilenlen)?indices:NULL, (list->ilenlen)?list->ilen:0); - } - // adjust the tex_coord now if needed, even on texgened ones - gltexture_t *bound = glstate->texture.bound[a][itarget]; - if((list->tex[a] || use_texgen[a]) && ((!(globals4es.texmat || glstate->texture_matrix[a]->identity)) || (bound) && ((bound->width != bound->nwidth) || (bound->height != bound->nheight)))) { - if(!use_texgen[a]) { + } + static GLfloat *texgened[MAX_TEX] = {0}; + static int texgenedsz[MAX_TEX] = {0}; + int use_texgen[MAX_TEX] = {0}; + #define TEXTURE(A) if (cur_tex!=A) {gl4es_glClientActiveTexture(A+GL_TEXTURE0); cur_tex=A;} + old_tex = glstate->texture.client; + GLuint cur_tex = old_tex; + #define RS(A, len) if(texgenedsz[A]enable.texture[a]) { + const GLint itarget = get_target(glstate->enable.texture[a]); + needclean[a]=0; + use_texgen[a]=0; + if ((glstate->enable.texgen_s[a] || glstate->enable.texgen_t[a] || glstate->enable.texgen_r[a] || glstate->enable.texgen_q[a])) { + TEXTURE(a); RS(a, list->len); - memcpy(texgened[a], list->tex[a], 4*sizeof(GLfloat)*list->len); + gen_tex_coords(list->vert, list->normal, &texgened[a], list->len, &needclean[a], a, (list->ilenlen)?indices:NULL, (list->ilenlen)?list->ilen:0); + } else if ((list->tex[a]==NULL) && !(list->mode==GL_POINT && glstate->texture.pscoordreplace[a])) { + RS(a, list->len); + gen_tex_coords(list->vert, list->normal, &texgened[a], list->len, &needclean[a], a, (list->ilenlen)?indices:NULL, (list->ilenlen)?list->ilen:0); } - if (!(globals4es.texmat || glstate->texture_matrix[a]->identity)) - tex_coord_matrix(texgened[a], list->len, getTexMat(a)); - if ((bound) && ((bound->width != bound->nwidth) || (bound->height != bound->nheight))) { - tex_coord_npot(texgened[a], list->len, bound->width, bound->height, bound->nwidth, bound->nheight); + // adjust the tex_coord now if needed, even on texgened ones + gltexture_t *bound = glstate->texture.bound[a][itarget]; + if((list->tex[a] || (use_texgen[a] && !needclean[a])) && ((!(globals4es.texmat || glstate->texture_matrix[a]->identity)) || (bound) && ((bound->width != bound->nwidth) || (bound->height != bound->nheight)))) { + if(!use_texgen[a]) { + RS(a, list->len); + memcpy(texgened[a], list->tex[a], 4*sizeof(GLfloat)*list->len); + } + if (!(globals4es.texmat || glstate->texture_matrix[a]->identity)) + tex_coord_matrix(texgened[a], list->len, getTexMat(a)); + if ((bound) && ((bound->width != bound->nwidth) || (bound->height != bound->nheight))) { + tex_coord_npot(texgened[a], list->len, bound->width, bound->height, bound->nwidth, bound->nheight); + } } } } - } - #undef RS - old_tex = glstate->texture.client; - GLuint cur_tex = old_tex; - #define TEXTURE(A) if (cur_tex!=A) {gl4es_glClientActiveTexture(A+GL_TEXTURE0); cur_tex=A;} + #undef RS for (int a=0; atex[a] || use_texgen[a])/* && glstate->enable.texture[a]*/) { + if ((list->tex[a] || (use_texgen[a] && !needclean[a]))/* && glstate->enable.texture[a]*/) { TEXTURE(a); if(!glstate->clientstate.tex_coord_array[a]) { gles_glEnableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/project/jni/gl4es/src/gl/texgen.c b/project/jni/gl4es/src/gl/texgen.c index 51ebf1cca..d71ca7670 100755 --- a/project/jni/gl4es/src/gl/texgen.c +++ b/project/jni/gl4es/src/gl/texgen.c @@ -1,4 +1,7 @@ #include "texgen.h" +#include "init.h" +#include "matrix.h" +#include "../glx/hardext.h" //extern void* eglGetProcAddress(const char*); @@ -271,11 +274,35 @@ void gen_tex_coords(GLfloat *verts, GLfloat *norm, GLfloat **coords, GLint count && (glstate->enable.texgen_t[texture] && (glstate->texgen[texture].T==GL_REFLECTION_MAP)) && (glstate->enable.texgen_r[texture] && (glstate->texgen[texture].R==GL_REFLECTION_MAP))) { - if (!IS_TEX2D(glstate->enable.texture[texture])) - return; - if ((*coords)==NULL) - *coords = (GLfloat *)malloc(count * 4 * sizeof(GLfloat)); - reflection_loop(verts, norm, *coords, (indices)?ilen:count, indices); + if(hardext.cubemap) { + *needclean=1; + // setup reflection map! + GLuint old_tex=glstate->texture.active; + if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + texture); + LOAD_GLES_OES(glTexGeni); + LOAD_GLES_OES(glTexGenfv); + LOAD_GLES(glEnable); + // setup cube map mode + gles_glTexGeni(GL_TEXTURE_GEN_STR, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); + // enable texgen + gles_glEnable(GL_TEXTURE_GEN_STR); + // check Texture Matrix + if (!(globals4es.texmat || glstate->texture_matrix[texture]->identity)) { + LOAD_GLES(glLoadMatrixf); + GLenum old_mat = glstate->matrix_mode; + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(GL_TEXTURE); + gles_glLoadMatrixf(getTexMat(texture)); + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(old_mat); + } + + if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + old_tex); + } else { + if (!IS_TEX2D(glstate->enable.texture[texture])) + return; + if ((*coords)==NULL) + *coords = (GLfloat *)malloc(count * 4 * sizeof(GLfloat)); + reflection_loop(verts, norm, *coords, (indices)?ilen:count, indices); + } return; } // special case: NORMAL_MAP needs the 3 texgen to make sense @@ -284,18 +311,24 @@ void gen_tex_coords(GLfloat *verts, GLfloat *norm, GLfloat **coords, GLint count && (glstate->enable.texgen_r[texture] && (glstate->texgen[texture].R==GL_NORMAL_MAP))) { *needclean=1; - // setup reflection map! + // setup normal map! GLuint old_tex=glstate->texture.active; if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + texture); LOAD_GLES_OES(glTexGeni); LOAD_GLES_OES(glTexGenfv); LOAD_GLES(glEnable); // setup cube map mode - gles_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); - gles_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); - gles_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); + gles_glTexGeni(GL_TEXTURE_GEN_STR, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); // enable texgen gles_glEnable(GL_TEXTURE_GEN_STR); + // check Texture Matrix + if (!(globals4es.texmat || glstate->texture_matrix[texture]->identity)) { + LOAD_GLES(glLoadMatrixf); + GLenum old_mat = glstate->matrix_mode; + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(GL_TEXTURE); + gles_glLoadMatrixf(getTexMat(texture)); + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(old_mat); + } if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + old_tex); @@ -332,6 +365,14 @@ void gen_tex_clean(GLint cleancode, int texture) { GLuint old_tex=glstate->texture.active; LOAD_GLES(glDisable); gles_glDisable(GL_TEXTURE_GEN_STR); + // check Texture Matrix + if (!(globals4es.texmat || glstate->texture_matrix[texture]->identity)) { + LOAD_GLES(glLoadIdentity); + GLenum old_mat = glstate->matrix_mode; + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(GL_TEXTURE); + gles_glLoadIdentity(); + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(old_mat); + } return; } } diff --git a/project/jni/gl4es/src/gl/texture.c b/project/jni/gl4es/src/gl/texture.c index b9bcd39fc..1bde96aa6 100755 --- a/project/jni/gl4es/src/gl/texture.c +++ b/project/jni/gl4es/src/gl/texture.c @@ -445,7 +445,7 @@ void gl4es_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data) { - //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); + //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][what_target(target)])?glstate->texture.bound[glstate->texture.active][what_target(target)]->mipmap_need:0, (glstate->texture.bound[glstate->texture.active][what_target(target)])?glstate->texture.bound[glstate->texture.active][what_target(target)]->mipmap_auto:0, (glstate->texture.bound[glstate->texture.active][what_target(target)])?glstate->texture.bound[glstate->texture.active][what_target(target)]->texture:0, (glstate->texture.bound[glstate->texture.active][what_target(target)])?glstate->texture.bound[glstate->texture.active][what_target(target)]->streamed:0, glstate->list.compiling); // proxy case if (target == GL_PROXY_TEXTURE_2D || target == GL_PROXY_TEXTURE_1D || target == GL_PROXY_TEXTURE_3D) { proxy_width = ((width<(globals4es.texshrink>=8)?8192:2048)?0:width; @@ -822,7 +822,7 @@ void gl4es_glTexImage2D(GLenum target, GLint level, GLint internalformat, if (bound && ((bound->mipmap_need && (globals4es.automipmap!=3)) || (bound->mipmap_auto))) gles_glTexParameteri( target, GL_GENERATE_MIPMAP, GL_TRUE ); else { - gles_glTexParameteri( target, GL_GENERATE_MIPMAP, GL_FALSE ); + if(itarget!=ENABLED_CUBE_MAP) gles_glTexParameteri( target, GL_GENERATE_MIPMAP, GL_FALSE ); if ((bound) && (bound->mipmap_need)) { // remove the need for mipmap... bound->mipmap_need = 0; @@ -900,7 +900,7 @@ void gl4es_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoff LOAD_GLES(glTexSubImage2D); LOAD_GLES(glTexParameteri); noerrorShim(); - //printf("glTexSubImage2D on target=%s with unpack_row_length(%i), size(%i,%i), pos(%i,%i) and skip={%i,%i}, format=%s, type=%s, level=%i, texture=%u\n", PrintEnum(target), glstate->texture.unpack_row_length, width, height, xoffset, yoffset, glstate->texture.unpack_skip_pixels, glstate->texture.unpack_skip_rows, PrintEnum(format), PrintEnum(type), level, glstate->texture.bound[glstate->texture.active]->texture); + //printf("glTexSubImage2D on target=%s with unpack_row_length(%i), size(%i,%i), pos(%i,%i) and skip={%i,%i}, format=%s, type=%s, level=%i, texture=%u\n", PrintEnum(target), glstate->texture.unpack_row_length, width, height, xoffset, yoffset, glstate->texture.unpack_skip_pixels, glstate->texture.unpack_skip_rows, PrintEnum(format), PrintEnum(type), level, glstate->texture.bound[glstate->texture.active][itarget]->texture); if (width==0 || height==0) { glstate->gl_batch = old_glbatch; return; diff --git a/project/jni/gl4es/src/gl/texture.h b/project/jni/gl4es/src/gl/texture.h index 2473941d1..ea5bc615c 100755 --- a/project/jni/gl4es/src/gl/texture.h +++ b/project/jni/gl4es/src/gl/texture.h @@ -97,12 +97,7 @@ typedef enum { ENABLED_TEX1D = 0, ENABLED_TEX2D, ENABLED_TEX3D, - ENABLED_CUBE_MAP_POSITIVE_X, - ENABLED_CUBE_MAP_NEGATIVE_X, - ENABLED_CUBE_MAP_POSITIVE_Y, - ENABLED_CUBE_MAP_NEGATIVE_Y, - ENABLED_CUBE_MAP_POSITIVE_Z, - ENABLED_CUBE_MAP_NEGATIVE_Z, + ENABLED_CUBE_MAP, ENABLED_TEXTURE_LAST } texture_enabled_t; @@ -157,13 +152,14 @@ static inline GLuint what_target(GLenum target) { return ENABLED_TEX1D; case GL_TEXTURE_3D: return ENABLED_TEX3D; + case GL_TEXTURE_CUBE_MAP: case GL_TEXTURE_CUBE_MAP_POSITIVE_X: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - return ENABLED_CUBE_MAP_POSITIVE_X+(target-GL_TEXTURE_CUBE_MAP_POSITIVE_X); + return ENABLED_CUBE_MAP; case GL_TEXTURE_RECTANGLE_ARB: case GL_TEXTURE_2D: default: @@ -176,13 +172,8 @@ static inline GLenum to_target(GLuint itarget) { return GL_TEXTURE_1D; case ENABLED_TEX3D: return GL_TEXTURE_3D; - case ENABLED_CUBE_MAP_POSITIVE_X: - case ENABLED_CUBE_MAP_NEGATIVE_X: - case ENABLED_CUBE_MAP_POSITIVE_Y: - case ENABLED_CUBE_MAP_NEGATIVE_Y: - case ENABLED_CUBE_MAP_POSITIVE_Z: - case ENABLED_CUBE_MAP_NEGATIVE_Z: - return GL_TEXTURE_CUBE_MAP_POSITIVE_X+(itarget-ENABLED_CUBE_MAP_POSITIVE_X); + case ENABLED_CUBE_MAP: + return GL_TEXTURE_CUBE_MAP; case ENABLED_TEX2D: default: return GL_TEXTURE_2D; diff --git a/project/jni/gl4es/src/glx/hardext.c b/project/jni/gl4es/src/glx/hardext.c index af21665f6..be6997a9c 100755 --- a/project/jni/gl4es/src/glx/hardext.c +++ b/project/jni/gl4es/src/glx/hardext.c @@ -120,6 +120,7 @@ void GetHardwareExtensions(int notest) S("GL_EXT_multi_draw_arrays", multidraw, 1); S("GL_EXT_texture_format_BGRA8888", bgra8888, 0); S("GL_OES_depth_texture", depthtex, 1); + S("GL_OES_texture_cube_map", cubemap, 1); // Now get some max stuffs gles_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &hardext.maxsize); diff --git a/project/jni/gl4es/src/glx/hardext.h b/project/jni/gl4es/src/glx/hardext.h index 9deb7838f..d62c1ac4c 100755 --- a/project/jni/gl4es/src/glx/hardext.h +++ b/project/jni/gl4es/src/glx/hardext.h @@ -21,6 +21,7 @@ typedef struct _hardext { int multidraw; // GL_EXT_multi_draw_arrays int bgra8888; // GL_EXT_texture_format_BGRA8888 (not used yet) int depthtex; // GL_OES_depth_texture + int cubemap; // GL_OES_texture_cube_map unsigned int readf; // implementation Read Format unsigned int readt; // implementation Read Type int srgb; // EGL_KHR_gl_colorspace