diff --git a/project/jni/glshim/src/gl/framebuffers.c b/project/jni/glshim/src/gl/framebuffers.c index f43dc9f37..423456f6d 100755 --- a/project/jni/glshim/src/gl/framebuffers.c +++ b/project/jni/glshim/src/gl/framebuffers.c @@ -467,6 +467,14 @@ void createMainFBO(int width, int height) { gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gles_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + #ifdef USE_DRAWTEX + { + LOAD_GLES(glTexParameteriv); + // setup the texture for glDrawTexiOES + GLint coords [] = {0, 0, mainfbo_width, mainfbo_height}; + gles_glTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, coords ); + } + #endif gles_glBindTexture(GL_TEXTURE_2D, 0); // create the render buffers gles_glGenRenderbuffers(1, &mainfbo_dep); @@ -514,7 +522,9 @@ void createMainFBO(int width, int height) { } void blitMainFBO() { + #ifdef USE_DRAWTEX LOAD_GLES_OES(glDrawTexi); + #endif LOAD_GLES(glBindTexture); LOAD_GLES(glActiveTexture); LOAD_GLES(glClientActiveTexture); @@ -541,7 +551,7 @@ void blitMainFBO() { gles_glGetIntegerv(GL_VIEWPORT, old_vp); gles_glViewport(0, 0, mainfbo_width, mainfbo_height); // Draw the texture - #if 0 + #ifdef USE_DRAWTEX gles_glDrawTexi(0, 0, 0, mainfbo_width, mainfbo_height); #else { diff --git a/project/jni/glshim/src/gl/gl.c b/project/jni/glshim/src/gl/gl.c index 2f129aaaf..9dec4bca0 100755 --- a/project/jni/glshim/src/gl/gl.c +++ b/project/jni/glshim/src/gl/gl.c @@ -1237,10 +1237,14 @@ void glshim_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) { if (glstate.list.active) { if (glstate.list.active->stage != STAGE_DRAW) { if (glstate.list.active->stage != STAGE_DRAW) { + if ((glstate.list.compiling || glstate.gl_batch) && glstate.list.active) { + glstate.list.active->lastNormal[0] = nx; glstate.list.active->lastNormal[1] = ny; glstate.list.active->lastNormal[2] = nz; + } PUSH_IF_COMPILING(glNormal3f); } } else { rlNormal3f(glstate.list.active, nx, ny, nz); + glstate.list.active->lastNormal[0] = nx; glstate.list.active->lastNormal[1] = ny; glstate.list.active->lastNormal[2] = nz; noerrorShim(); } } @@ -1266,9 +1270,15 @@ void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) __attribute__((alias void glshim_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { if (glstate.list.active) { if (glstate.list.active->stage != STAGE_DRAW) { + if ((glstate.list.compiling || glstate.gl_batch) && glstate.list.active) { + glstate.list.active->lastColors[0] = red; glstate.list.active->lastColors[1] = green; + glstate.list.active->lastColors[2] = blue; glstate.list.active->lastColors[3] = alpha; + } PUSH_IF_COMPILING(glColor4f); } rlColor4f(glstate.list.active, red, green, blue, alpha); + glstate.list.active->lastColors[0] = red; glstate.list.active->lastColors[1] = green; + glstate.list.active->lastColors[2] = blue; glstate.list.active->lastColors[3] = alpha; noerrorShim(); } #ifndef USE_ES2 @@ -1287,6 +1297,8 @@ void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) __attrib void glshim_glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b) { if (glstate.list.active) { rlSecondary3f(glstate.list.active, r, g, b); + glstate.list.active->lastSecondaryColors[0] = r; glstate.list.active->lastSecondaryColors[1] = g; + glstate.list.active->lastSecondaryColors[2] = b; noerrorShim(); } else { noerrorShim(); diff --git a/project/jni/glshim/src/gl/list.c b/project/jni/glshim/src/gl/list.c index a2760350b..9ef87812a 100755 --- a/project/jni/glshim/src/gl/list.c +++ b/project/jni/glshim/src/gl/list.c @@ -14,62 +14,17 @@ renderlist_t *alloc_renderlist() { renderlist_t *list = (renderlist_t *)malloc(sizeof(renderlist_t)); memset(list, 0, sizeof(*list)); - /* - list->len = 0; - list->ilen = 0;*/ list->cap = DEFAULT_RENDER_LIST_CAPACITY; - /* - list->calls.len = 0; - list->calls.cap = 0; - list->calls.calls = NULL; - - list->mode = 0; - list->mode_init = 0; - list->shared_arrays = false; - list->vert = NULL; - list->normal = NULL; - list->color = NULL; - list->secondary = NULL; - - list->glcall_list = 0; - list->raster = NULL; - - list->stage = STAGE_NONE; - - list->pushattribute = 0; - list->popattribute = false; - - list->raster_op = 0; - for (a=0; a<3; a++) - list->raster_xyz[a]=0.0f; - - list->matrix_op = 0; - for (a=0; a<16; a++) - list->matrix_val[a]=((a%4)==0)?1.0f:0.0f; // load identity matrix - */ list->matrix_val[0] = list->matrix_val[5] = list->matrix_val[10] = list->matrix_val[15] = 1.0f; - /* - for (a=0; atex[a] = NULL; - list->material = NULL; - list->light = NULL; - list->texgen = NULL; - list->lightmodel = NULL;*/ list->lightmodelparam = GL_LIGHT_MODEL_AMBIENT; - /* - list->indices = NULL; - list->indice_cap = 0; - list->set_texture = false; - list->texture = 0;*/ list->target_texture = GL_TEXTURE_2D; list->tmu = glstate.texture.active; - /* - list->polygon_mode = 0; - list->fog_op = 0; - - list->prev = NULL; - list->next = NULL;*/ + + memcpy(list->lastNormal, glstate.normal, 3*sizeof(GLfloat)); + memcpy(list->lastSecondaryColors, glstate.secondary, 3*sizeof(GLfloat)); + memcpy(list->lastColors, glstate.color, 4*sizeof(GLfloat)); + list->open = true; return list; } @@ -489,6 +444,10 @@ renderlist_t *extend_renderlist(renderlist_t *list) { renderlist_t *new = alloc_renderlist(); new->prev = list->prev; list->prev->next = new; + // just in case + memcpy(new->lastNormal, list->lastNormal, 3*sizeof(GLfloat)); + memcpy(new->lastSecondaryColors, list->lastSecondaryColors, 3*sizeof(GLfloat)); + memcpy(new->lastColors, list->lastColors, 4*sizeof(GLfloat)); // detach list->prev = NULL; // free list now @@ -499,6 +458,10 @@ renderlist_t *extend_renderlist(renderlist_t *list) { list->next = new; new->prev = list; new->tmu = list->tmu; + // copy local state + memcpy(new->lastNormal, list->lastNormal, 3*sizeof(GLfloat)); + memcpy(new->lastSecondaryColors, list->lastSecondaryColors, 3*sizeof(GLfloat)); + memcpy(new->lastColors, list->lastColors, 4*sizeof(GLfloat)); if (list->open) end_renderlist(list); return new; @@ -1129,7 +1092,7 @@ void rlColor4f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b, GLfloat a) { int i; if (list->len) for (i = 0; i < list->len; i++) { GLfloat *color = (list->color + (i * 4)); - memcpy(color, glstate.color, sizeof(GLfloat) * 4); + memcpy(color,list->lastColors, sizeof(GLfloat) * 4); }/* else { GLfloat *color = list->color; color[0] = r; color[1] = g; color[2] = b; color[3] = a; @@ -1147,7 +1110,7 @@ void rlSecondary3f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b) { int i; if (list->len) for (i = 0; i < list->len; i++) { GLfloat *secondary = (list->secondary + (i * 4)); - memcpy(secondary, glstate.secondary, sizeof(GLfloat) * 4); + memcpy(secondary, list->lastSecondaryColors, sizeof(GLfloat) * 4); } } diff --git a/project/jni/glshim/src/gl/list.h b/project/jni/glshim/src/gl/list.h index fb4154411..797f34adf 100755 --- a/project/jni/glshim/src/gl/list.h +++ b/project/jni/glshim/src/gl/list.h @@ -93,6 +93,8 @@ typedef struct _renderlist_t { GLenum mode; GLenum mode_init; // initial requested mode GLfloat lastNormal[3]; + GLfloat lastColors[4]; + GLfloat lastSecondaryColors[3]; call_list_t calls; diff --git a/project/jni/glshim/src/gl/raster.c b/project/jni/glshim/src/gl/raster.c index 22b226718..54668b05e 100755 --- a/project/jni/glshim/src/gl/raster.c +++ b/project/jni/glshim/src/gl/raster.c @@ -9,6 +9,8 @@ GLfloat zoomy=1.0f; GLuint raster_texture=0; GLsizei raster_width=0; GLsizei raster_height=0; +GLsizei raster_realwidth=0; +GLsizei raster_realheight=0; GLint raster_x1, raster_x2, raster_y1, raster_y2; #define min(a, b) ((a)width=%i, rast->height=%i, rPos.x=%f, rPos.y=%f, rast->zoomxy=%f/%f raster->texture=%u\n", rast->width, rast->height, rPos.x, rPos.y, rast->zoomx, rast->zoomy, rast->texture); +//printf("render_raster_list, rast->x/y=%f/%f rast->width/height=%i/%i, rPos.x/y/z=%f/%f/%f, rast->zoomxy=%f/%f raster->texture=%u\n", rast->xorig, rast->yorig, rast->width, rast->height, rPos.x, rPos.y, rPos.z, rast->zoomx, rast->zoomy, rast->texture); + #ifdef USE_DRAWTEX + LOAD_GLES_OES(glDrawTexf); + LOAD_GLES(glEnable); + LOAD_GLES(glDisable); + #else LOAD_GLES(glEnableClientState); LOAD_GLES(glDisableClientState); - LOAD_GLES(glBindTexture); LOAD_GLES(glVertexPointer); LOAD_GLES(glTexCoordPointer); LOAD_GLES(glDrawArrays); + #endif + LOAD_GLES(glBindTexture); LOAD_GLES(glActiveTexture); LOAD_GLES(glClientActiveTexture); if (rast->texture) { - glshim_glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); - GLfloat old_projection[16], old_modelview[16], old_texture[16]; - GLuint old_tex = glstate.texture.active; if (old_tex!=0) gles_glActiveTexture(GL_TEXTURE0); GLuint old_cli = glstate.texture.client; if (old_cli!=0) gles_glClientActiveTexture(GL_TEXTURE0); + #ifdef USE_DRAWTEX + glshim_glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); + + gltexture_t *old_bind = glstate.texture.bound[0]; + glshim_glEnable(GL_TEXTURE_2D); + gles_glBindTexture(GL_TEXTURE_2D, rast->texture); + + if (rast->bitmap) { + glshim_glEnable(GL_ALPHA_TEST); + glshim_glAlphaFunc(GL_GREATER, 0.0f); + } else { + glshim_glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + + gles_glDrawTexf(rPos.x-rast->xorig, rPos.y-rast->yorig, rPos.z, rast->width * rast->zoomx, rast->height * rast->zoomy); + if (!glstate.enable.texture_2d[0]) glshim_glDisable(GL_TEXTURE_2D); + if (old_tex!=0) gles_glActiveTexture(GL_TEXTURE0+old_tex); + if (old_cli!=0) gles_glClientActiveTexture(GL_TEXTURE0+old_cli); + if (old_bind == NULL) + gles_glBindTexture(GL_TEXTURE_2D, 0); + else + gles_glBindTexture(GL_TEXTURE_2D, old_bind->glname); + #else + glshim_glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); + GLfloat old_projection[16], old_modelview[16], old_texture[16]; + glshim_glGetFloatv(GL_TEXTURE_MATRIX, old_texture); glshim_glGetFloatv(GL_PROJECTION_MATRIX, old_projection); glshim_glGetFloatv(GL_MODELVIEW_MATRIX, old_modelview); @@ -484,6 +527,7 @@ void render_raster_list(rasterlist_t* rast) { glshim_glLoadMatrixf(old_modelview); glshim_glMatrixMode(GL_PROJECTION); glshim_glLoadMatrixf(old_projection); + #endif glshim_glPopAttrib(); } rPos.x += rast->xmove;