gl4es updated, added latest changes by ptitSeb

This commit is contained in:
lubomyr
2016-12-03 00:51:12 +02:00
parent 72a4905ea4
commit 45f514b823
12 changed files with 120 additions and 83 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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);

View File

@@ -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:

View File

@@ -235,19 +235,11 @@ static void proxy_glEnable(GLenum cap, bool enable, void (*next)(GLenum)) {
else
glstate->enable.texture[glstate->texture.active] &= ~(1<<ENABLED_TEX3D);
break;
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:
{
GLuint itarget=ENABLED_CUBE_MAP_POSITIVE_X+(cap-GL_TEXTURE_CUBE_MAP_POSITIVE_X);
if(enable)
glstate->enable.texture[glstate->texture.active] |= (1<<itarget);
else
glstate->enable.texture[glstate->texture.active] &= ~(1<<itarget);
}
case GL_TEXTURE_CUBE_MAP:
if(enable)
glstate->enable.texture[glstate->texture.active] |= (1<<ENABLED_CUBE_MAP);
else
glstate->enable.texture[glstate->texture.active] &= ~(1<<ENABLED_CUBE_MAP);
next(cap);
break;
@@ -363,16 +355,7 @@ GLboolean gl4es_glIsEnabled(GLenum cap) {
case GL_TEXTURE_1D: return glstate->enable.texture[glstate->texture.active]&(1<<ENABLED_TEX1D);
case GL_TEXTURE_2D: return glstate->enable.texture[glstate->texture.active]&(1<<ENABLED_TEX2D);
case GL_TEXTURE_3D: return glstate->enable.texture[glstate->texture.active]&(1<<ENABLED_TEX3D);
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:
{
GLuint itarget=ENABLED_CUBE_MAP_POSITIVE_X+(cap-GL_TEXTURE_CUBE_MAP_POSITIVE_X);
return glstate->enable.texture[glstate->texture.active]&(1<<itarget);
}
case GL_TEXTURE_CUBE_MAP: return glstate->enable.texture[glstate->texture.active]&(1<<ENABLED_CUBE_MAP);
clientisenabled(GL_VERTEX_ARRAY, vertex_array);
clientisenabled(GL_NORMAL_ARRAY, normal_array);
clientisenabled(GL_COLOR_ARRAY, color_array);

View File

@@ -31,8 +31,16 @@ static void fast_math() {
void load_libs();
void glx_init();
#ifdef NO_INIT_CONSTRUCTOR
__attribute__((visibility("default")))
#else
__attribute__((constructor))
#endif
void initialize_gl4es() {
// only init 1 time
static int inited = 0;
if(inited) return;
inited = 1;
// default init of globals
memset(&globals4es, 0, sizeof(globals4es));
globals4es.mergelist = 1;

View File

@@ -927,45 +927,46 @@ void draw_renderlist(renderlist_t *list) {
gl4es_glBlendFunc(GL_SRC_ALPHA, GL_ONE);
list->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]<len) {free(texgened[A]); texgened[A]=malloc(4*sizeof(GLfloat)*len); texgenedsz[A]=len; } use_texgen[A]=1
GLint needclean[MAX_TEX];
for (int a=0; a<hardext.maxtex; a++) {
if(glstate->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->ilen<list->len)?indices:NULL, (list->ilen<list->len)?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->ilen<list->len)?indices:NULL, (list->ilen<list->len)?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]<len) {free(texgened[A]); texgened[A]=malloc(4*sizeof(GLfloat)*len); texgenedsz[A]=len; } use_texgen[A]=1
GLint needclean[MAX_TEX];
for (int a=0; a<hardext.maxtex; a++) {
if(glstate->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->ilen<list->len)?indices:NULL, (list->ilen<list->len)?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->ilen<list->len)?indices:NULL, (list->ilen<list->len)?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; a<hardext.maxtex; a++) {
if ((list->tex[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);

View File

@@ -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;
}
}

View File

@@ -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<<level)>(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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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