From 645a2516c6872b8327b74b5bcf3e7cbefdd0357a Mon Sep 17 00:00:00 2001 From: lubomyr Date: Thu, 2 Feb 2017 17:41:09 +0200 Subject: [PATCH] gl4es updated, added latest changes by ptitSeb --- project/jni/gl4es/src/gl/getter.c | 3 +- project/jni/gl4es/src/gl/gl.c | 99 ++++++++++++++++++------------ project/jni/gl4es/src/gl/list.c | 5 +- project/jni/gl4es/src/gl/state.h | 2 - project/jni/gl4es/src/gl/texture.c | 33 ++++------ project/jni/gl4es/src/gl/texture.h | 4 ++ 6 files changed, 81 insertions(+), 65 deletions(-) diff --git a/project/jni/gl4es/src/gl/getter.c b/project/jni/gl4es/src/gl/getter.c index 7bd64a9f8..ddc9cd50e 100755 --- a/project/jni/gl4es/src/gl/getter.c +++ b/project/jni/gl4es/src/gl/getter.c @@ -9,7 +9,8 @@ GLenum gl4es_glGetError() { if(globals4es.noerror) return GL_NO_ERROR; if (glstate->shim_error) { - GLenum tmp = glstate->last_error; + GLenum tmp = gles_glGetError(); // to purge GLES error stack + tmp = glstate->last_error; glstate->last_error = GL_NO_ERROR; return tmp; } diff --git a/project/jni/gl4es/src/gl/gl.c b/project/jni/gl4es/src/gl/gl.c index 6d0285841..f3d3e27ad 100755 --- a/project/jni/gl4es/src/gl/gl.c +++ b/project/jni/gl4es/src/gl/gl.c @@ -276,13 +276,13 @@ void gl4es_glEnable(GLenum cap) { } } PUSH_IF_COMPILING(glEnable) - +#ifdef TEXSTREAM if (globals4es.texstream && (cap==GL_TEXTURE_2D)) { if (glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]) if (glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]->streamed) cap = GL_TEXTURE_STREAM_IMG; } - +#endif LOAD_GLES(glEnable); proxy_glEnable(cap, true, gles_glEnable); } @@ -502,6 +502,10 @@ static inline bool should_intercept_render(GLenum mode) { if (glstate->enable.texture[aa]) { if ((glstate->enable.texgen_s[aa] || glstate->enable.texgen_t[aa] || glstate->enable.texgen_r[aa] || glstate->enable.texgen_q[aa])) return true; + if ((!glstate->vao->tex_coord_array[aa]) && !(mode==GL_POINT && glstate->texture.pscoordreplace[aa])) + return true; + if ((glstate->vao->tex_coord_array[aa]) && (glstate->vao->pointers.tex_coord[aa].size == 1)) + return true; } } if(glstate->polygon_mode == GL_LINE && mode>=GL_TRIANGLES) @@ -513,7 +517,7 @@ static inline bool should_intercept_render(GLenum mode) { return ( (glstate->vao->vertex_array && ! valid_vertex_type(glstate->vao->pointers.vertex.type)) || (mode == GL_LINES && glstate->enable.line_stipple) || - (mode == GL_QUADS) || (glstate->list.active && (glstate->list.compiling || glstate->gl_batch)) + /*(mode == GL_QUADS) ||*/ (glstate->list.active && (glstate->list.compiling || glstate->gl_batch)) ); } @@ -568,7 +572,7 @@ void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid return; } - if (should_intercept_render(mode)) { + if (should_intercept_render(mode) || (mode==GL_QUADS)) { renderlist_t *list = NULL; GLsizei min, max; @@ -599,6 +603,7 @@ void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid LOAD_GLES(glDisable); LOAD_GLES(glEnableClientState); LOAD_GLES(glDisableClientState); + LOAD_GLES(glMultiTexCoord4f); GLuint len = 0; for (int i=0; ivao->pointers.vertex.size, glstate->vao->pointers.vertex.type, glstate->vao->pointers.vertex.stride, glstate->vao->pointers.vertex.pointer); GLuint old_tex = glstate->texture.client; #define TEXTURE(A) gl4es_glClientActiveTexture(A+GL_TEXTURE0); - for (int aa=0; aaenable.texture[aa]); @@ -650,7 +655,13 @@ void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid if (glstate->vao->tex_coord_array[aa]) { TEXTURE(aa); tex_setup_texcoord(len, itarget); - } + } else + gles_glMultiTexCoord4f(GL_TEXTURE0+aa, glstate->texcoord[aa][0], glstate->texcoord[aa][1], glstate->texcoord[aa][2], glstate->texcoord[aa][3]); + } else if (glstate->clientstate.tex_coord_array[aa]) { + // special case, Tex disable but CoordArray enabled... disabling it temporarly + TEXTURE(aa); + glstate->clientstate.tex_coord_array[aa] = 0; + gles_glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } if (glstate->texture.client!=old_tex) @@ -658,7 +669,7 @@ void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid // POLYGON mode as LINE is "intercepted" and drawn using list gles_glDrawElements(mode, count, GL_UNSIGNED_SHORT, sindices); - for (int aa=0; aaenable.texture[aa]) && (IS_ANYTEX(glstate->enable.texture[aa]))) { TEXTURE(aa); gles_glDisable(GL_TEXTURE_2D); @@ -706,6 +717,7 @@ void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { LOAD_GLES(glDisable); LOAD_GLES(glEnableClientState); LOAD_GLES(glDisableClientState); + LOAD_GLES(glMultiTexCoord4f); if (glstate->list.active && (glstate->list.compiling || glstate->gl_batch)) { NewStage(glstate->list.active, STAGE_DRAW); @@ -719,31 +731,6 @@ void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { if (glstate->polygon_mode == GL_POINT && mode>=GL_TRIANGLES) mode = GL_POINTS; - if (glstate->polygon_mode != GL_LINES && mode==GL_QUADS) { - static GLushort *indices = NULL; - static int indcnt = 0; - if(indcnt < count+first) { - indcnt = count + first; - if (indices) free(indices); - indices = (GLushort*)malloc(sizeof(GLushort)*(indcnt*3/2)); - for (int i=0, j=0; i+3vao->elements; - glstate->vao->elements = NULL; - gl4es_glDrawElements(GL_TRIANGLES, count*3/2, GL_UNSIGNED_SHORT, indices+first*3/2); - glstate->vao->elements = old_vao_elements; - return; - } - if (should_intercept_render(mode)) { renderlist_t *list; list = arrays_to_renderlist(NULL, mode, first, count+first); @@ -751,6 +738,35 @@ void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { draw_renderlist(list); free_renderlist(list); } else { + if (mode==GL_QUADS) { + static GLushort *indices = NULL; + static int indcnt = 0; + static int indfirst = 0; + if((indcnt < count) || (indfirst!=first)) { + if(indcnt < count) { + indcnt = count; + if (indices) free(indices); + indices = (GLushort*)malloc(sizeof(GLushort)*(indcnt*3/2)); + } + indfirst = first; + for (int i=0, j=0; i+3vao->elements; + glstate->vao->elements = NULL; + gl4es_glDrawElements(GL_TRIANGLES, count*3/2, GL_UNSIGNED_SHORT, indices); + glstate->vao->elements = old_vao_elements; + return; + } + LOAD_GLES(glDrawArrays); GLenum mode_init = mode; @@ -774,7 +790,7 @@ void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { gles_glVertexPointer(glstate->vao->pointers.vertex.size, glstate->vao->pointers.vertex.type, glstate->vao->pointers.vertex.stride, glstate->vao->pointers.vertex.pointer); GLuint old_tex = glstate->texture.client; #define TEXTURE(A) gl4es_glClientActiveTexture(A+GL_TEXTURE0); - for (int aa=0; aaenable.texture[aa]); @@ -786,9 +802,13 @@ void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { if (glstate->vao->tex_coord_array[aa]) { TEXTURE(aa); tex_setup_texcoord(count+first, itarget); - /*glClientActiveTexture(aa+GL_TEXTURE0); - gles_glTexCoordPointer(glstate->pointers.tex_coord[aa].size, glstate->pointers.tex_coord[aa].type, glstate->pointers.tex_coord[aa].stride, glstate->pointers.tex_coord[aa].pointer);*/ - } + } else + gles_glMultiTexCoord4f(GL_TEXTURE0+aa, glstate->texcoord[aa][0], glstate->texcoord[aa][1], glstate->texcoord[aa][2], glstate->texcoord[aa][3]); + } else if (glstate->clientstate.tex_coord_array[aa]) { + // special case, Tex disable but CoordArray enabled... disabling it temporarly + TEXTURE(aa); + glstate->clientstate.tex_coord_array[aa] = 0; + gles_glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } if (glstate->texture.client!=old_tex) @@ -796,7 +816,7 @@ void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { gles_glDrawArrays(mode, first, count); - for (int aa=0; aaenable.texture[aa]) && (IS_ANYTEX(glstate->enable.texture[aa]))) { TEXTURE(aa); gles_glDisable(GL_TEXTURE_2D); @@ -1660,9 +1680,10 @@ void glPointParameterfv(GLenum pname, const GLfloat * params) AliasExport("gl4es void gl4es_glMultiDrawArrays(GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount) { LOAD_GLES_EXT(glMultiDrawArrays); - if((!gles_glMultiDrawArrays) || should_intercept_render(mode) || (glstate->list.active && (glstate->list.compiling || glstate->gl_batch)) + if((!gles_glMultiDrawArrays) || should_intercept_render(mode) || (mode==GL_QUADS) || (glstate->list.active && (glstate->list.compiling || glstate->gl_batch)) || (glstate->render_mode == GL_SELECT) || ((glstate->polygon_mode == GL_LINE) || (glstate->polygon_mode == GL_POINT)) ) { + // GL_QUADS special case can probably by improved // divide the call // TODO optimize with forcing Batch mode for (int i=0; ilist.active && (glstate->list.compiling || glstate->gl_batch)) + if((!gles_glMultiDrawElements) || should_intercept_render(mode) || (mode==GL_QUADS) || (glstate->list.active && (glstate->list.compiling || glstate->gl_batch)) || (glstate->render_mode == GL_SELECT) || ((glstate->polygon_mode == GL_LINE) || (glstate->polygon_mode == GL_POINT)) || (type != GL_UNSIGNED_SHORT) ) { // divide the call diff --git a/project/jni/gl4es/src/gl/list.c b/project/jni/gl4es/src/gl/list.c index 3ba734642..df33de80e 100755 --- a/project/jni/gl4es/src/gl/list.c +++ b/project/jni/gl4es/src/gl/list.c @@ -681,12 +681,13 @@ void adjust_renderlist(renderlist_t *list) { list->stage = STAGE_LAST; list->open = false; for (int a=0; atexture.bound[a][ENABLED_TEX2D]; //TODO check if hardcoded TEX2D is ok + const GLint itarget = get_target(glstate->enable.texture[a]); + gltexture_t *bound = glstate->texture.bound[a][itarget]; // in case of Texture bounding inside a list if (list->set_texture && (list->tmu == a)) bound = gl4es_getTexture(list->target_texture, list->texture); // GL_ARB_texture_rectangle - if ((list->tex[a]) && glstate->texture.rect_arb[a] && (bound)) { + if ((list->tex[a]) && (itarget == ENABLED_TEXTURE_RECTANGLE) && (bound)) { tex_coord_rect_arb(list->tex[a], list->len, bound->width, bound->height); } } diff --git a/project/jni/gl4es/src/gl/state.h b/project/jni/gl4es/src/gl/state.h index d3a6489de..f148393bc 100755 --- a/project/jni/gl4es/src/gl/state.h +++ b/project/jni/gl4es/src/gl/state.h @@ -51,8 +51,6 @@ typedef struct { pack_skip_rows, pack_image_height; GLboolean pack_lsb_first; - // TODO: do we only need to worry about GL_TEXTURE_2D? - GLboolean rect_arb[MAX_TEX]; gltexture_t *bound[MAX_TEX][ENABLED_TEXTURE_LAST]; GLboolean pscoordreplace[MAX_TEX]; khash_t(tex) *list; diff --git a/project/jni/gl4es/src/gl/texture.c b/project/jni/gl4es/src/gl/texture.c index 12c9144cd..4f6547de9 100755 --- a/project/jni/gl4es/src/gl/texture.c +++ b/project/jni/gl4es/src/gl/texture.c @@ -88,7 +88,7 @@ void tex_setup_texcoord(GLuint len, GLuint itarget) { // check if some changes are needed int changes = 0; - if ((glstate->texture.rect_arb[texunit]) + if ((itarget == ENABLED_TEXTURE_RECTANGLE) || (bound && ((bound->width!=bound->nwidth)||(bound->height!=bound->nheight) )) || !(globals4es.texmat || glstate->texture_matrix[texunit]->identity) ) @@ -102,7 +102,7 @@ void tex_setup_texcoord(GLuint len, GLuint itarget) { } copy_gl_pointer_tex_noalloc(tex[texunit], &glstate->vao->pointers.tex_coord[texunit], 4, 0, len); // Normalize if needed - if ((glstate->texture.rect_arb[texunit])) + if (itarget == ENABLED_TEXTURE_RECTANGLE) tex_coord_rect_arb(tex[texunit], len, bound->width, bound->height); // Apply transformation matrix if any if (!(globals4es.texmat || glstate->texture_matrix[texunit]->identity)) @@ -940,8 +940,8 @@ void gl4es_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoff errorGL(); } - if (bound && bound->mipmap_need && !bound->mipmap_auto && (globals4es.automipmap!=3) && (!globals4es.texstream || (globals4es.texstream && !bound->streamed))) - gles_glTexParameteri( target, GL_GENERATE_MIPMAP, GL_FALSE ); + /*if (bound && bound->mipmap_need && !bound->mipmap_auto && (globals4es.automipmap!=3) && (!globals4es.texstream || (globals4es.texstream && !bound->streamed))) + gles_glTexParameteri( target, GL_GENERATE_MIPMAP, GL_FALSE );*/ if ((target==GL_TEXTURE_2D) && globals4es.texcopydata && bound && ((globals4es.texstream && !bound->streamed) || !globals4es.texstream)) { //printf("*texcopy* glTexSubImage2D, xy=%i,%i, size=%i,%i=>%i,%i, format=%s, type=%s, tex=%u\n", xoffset, yoffset, width, height, bound->width, bound->height, PrintEnum(format), PrintEnum(type), bound->glname); @@ -1173,7 +1173,6 @@ tex_changed=1; // seems buggy, temporary disabling that... } #endif - glstate->texture.rect_arb[glstate->texture.active] = (target == GL_TEXTURE_RECTANGLE_ARB); target = map_tex_target(target); glstate->texture.bound[glstate->texture.active][itarget] = tex; @@ -1373,28 +1372,20 @@ void gl4es_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GL case GL_TEXTURE_WIDTH: if (target==GL_PROXY_TEXTURE_2D) (*params) = nlevel(proxy_width,level); - else + else { (*params) = nlevel((bound)?bound->width:2048,level); - /*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; - }*/ + if(level && (!bound || (bound && !(bound->mipmap_auto || bound->mipmap_need)))) + (*params) = 0; // Mipmap level not loaded + } break; case GL_TEXTURE_HEIGHT: if (target==GL_PROXY_TEXTURE_2D) (*params) = nlevel(proxy_height,level); - else + else { (*params) = nlevel((bound)?bound->height:2048,level); - /*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; - }*/ + if(level && (!bound || (bound && !(bound->mipmap_auto || bound->mipmap_need)))) + (*params) = 0; // Mipmap level not loaded + } break; case GL_TEXTURE_INTERNAL_FORMAT: if (target==GL_PROXY_TEXTURE_2D) diff --git a/project/jni/gl4es/src/gl/texture.h b/project/jni/gl4es/src/gl/texture.h index ea5bc615c..9ddcef64e 100755 --- a/project/jni/gl4es/src/gl/texture.h +++ b/project/jni/gl4es/src/gl/texture.h @@ -97,6 +97,7 @@ typedef enum { ENABLED_TEX1D = 0, ENABLED_TEX2D, ENABLED_TEX3D, + ENABLED_TEXTURE_RECTANGLE, ENABLED_CUBE_MAP, ENABLED_TEXTURE_LAST } texture_enabled_t; @@ -161,6 +162,7 @@ static inline GLuint what_target(GLenum target) { case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: return ENABLED_CUBE_MAP; case GL_TEXTURE_RECTANGLE_ARB: + return ENABLED_TEXTURE_RECTANGLE; case GL_TEXTURE_2D: default: return ENABLED_TEX2D; @@ -172,6 +174,8 @@ static inline GLenum to_target(GLuint itarget) { return GL_TEXTURE_1D; case ENABLED_TEX3D: return GL_TEXTURE_3D; + case ENABLED_TEXTURE_RECTANGLE: + return GL_TEXTURE_RECTANGLE_ARB; case ENABLED_CUBE_MAP: return GL_TEXTURE_CUBE_MAP; case ENABLED_TEX2D: