gl4es updated, added latest changes by ptitSeb
This commit is contained in:
@@ -3,11 +3,11 @@ gl4es
|
||||
|
||||
This is a library providing OpenGL 1.x functionality for OpenGL ES accelerated hardware.
|
||||
|
||||
This is a fork a glshim (https://github.com/lunixbochs/glshim). Go check this lib if you need things like RemoteGL or if need support for TinyGLES (for 100% software rendering).
|
||||
This is a fork a glshim (https://github.com/lunixbochs/glshim). Go check this lib if you need things like RemoteGL or TinyGLES (for 100% software rendering).
|
||||
|
||||
The focusse is on compatibility with a wide selection of game and software, as well as speed.
|
||||
The focus is on compatibility with a wide selection of game and software, as well as speed.
|
||||
|
||||
It has been tested successfully of a large selection of games and software, including: Mincraft, OpenMW, SeriousSam, RVGL, TSMC, TORCS, SpeedDreams, GL-117, Blender 2.68 and many more.
|
||||
It has been tested successfully of a large selection of games and software, including: Mincraft, OpenMW, SeriousSam, RVGL, TSMC, TORCS, SpeedDreams, GL-117, Foobillard(plus), Blender 2.68 and many more.
|
||||
|
||||
Most function of OpenGL up to 1.5 are supported, with some notable exceptions:
|
||||
* Reading of Depth or Stencil buffer will not work
|
||||
@@ -235,13 +235,19 @@ Vertex Array BGRA extension
|
||||
* 0 : Default, GL_ARB_vertex_array_bgra not exposed (still emulated)
|
||||
* 1 : Extension exposed may be faster in some cases (Arx Libertatis mainly)
|
||||
|
||||
##### LIBGL_BEGINEND
|
||||
Merge of subsequent glBegin/glEnd blocks (will be non-effective if BATCH mode is used)
|
||||
* 0 : Don't try to merge
|
||||
* 1 : Try to merge, even if there is a glColor / glNormal in between (default)
|
||||
* 2 : Try hard to merge, even if there is a glColor / glNormal or Matrix operations in between
|
||||
|
||||
----
|
||||
|
||||
Version history
|
||||
----
|
||||
|
||||
##### Current version
|
||||
* Added some optimisations for sequencial glBegin/glEnd blocks
|
||||
##### 0.9.5
|
||||
* Added some optimisations for sequencial glBegin/glEnd blocks, with a switch to control them
|
||||
* Fixed many issue with Lights introduced with 0.9.4
|
||||
* Fixed Android build introduced with 0.9.4
|
||||
|
||||
|
||||
@@ -25,5 +25,9 @@
|
||||
#define GL_NOERROR_HINT_GL4ES 0xA10A
|
||||
// same as using LIBGL_NODOWNSAMPLING=x
|
||||
#define GL_NODOWNSAMPLING_HINT_GL4ES 0xA10B
|
||||
// same as using LIBGL_NOVAOCACHE=x
|
||||
#define GL_NOVAOCACHE_HINT_GL4ES 0xA10C
|
||||
// same as using LIBGL_BEGINEND=x
|
||||
#define GL_BEGINEND_HINT_GL4ES 0xA10D
|
||||
|
||||
#endif
|
||||
@@ -525,6 +525,12 @@ void gl4es_glGetFloatv(GLenum pname, GLfloat *params) {
|
||||
case GL_NODOWNSAMPLING_HINT_GL4ES:
|
||||
*params=globals4es.nodownsampling;
|
||||
break;
|
||||
case GL_NOVAOCACHE_HINT_GL4ES:
|
||||
*params=globals4es.novaocache;
|
||||
break;
|
||||
case GL_BEGINEND_HINT_GL4ES:
|
||||
*params=globals4es.beginend;
|
||||
break;
|
||||
default:
|
||||
errorGL();
|
||||
gles_glGetFloatv(pname, params);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "debug.h"
|
||||
#include "../glx/hardext.h"
|
||||
#include "init.h"
|
||||
#include "matrix.h"
|
||||
|
||||
glstate_t *glstate = NULL;
|
||||
|
||||
@@ -1036,6 +1037,10 @@ void gl4es_glBegin(GLenum mode) {
|
||||
glstate->list.active->mode = mode;
|
||||
glstate->list.active->mode_init = mode;
|
||||
noerrorShim(); // TODO, check Enum validity
|
||||
if (!(glstate->list.compiling || glstate->gl_batch) && (globals4es.beginend==2) && !(glstate->polygon_mode==GL_LINE)) { //TODO: check TexGen?
|
||||
// immediate MV matrix handling
|
||||
gl4es_immediateMVBegin();
|
||||
}
|
||||
}
|
||||
void glBegin(GLenum mode) AliasExport("gl4es_glBegin");
|
||||
|
||||
@@ -1047,7 +1052,7 @@ void gl4es_glEnd() {
|
||||
if (glstate->enable.texture[a] && ((glstate->list.active->tex[a]==0) && !(glstate->enable.texgen_s[a] || glstate->texture.pscoordreplace[a])))
|
||||
rlMultiTexCoord4f(glstate->list.active, GL_TEXTURE0+a, glstate->texcoord[a][0], glstate->texcoord[a][1], glstate->texcoord[a][2], glstate->texcoord[a][3]);
|
||||
// render if we're not in a display list
|
||||
if (!(glstate->list.compiling || glstate->gl_batch) && (!(globals4es.mergelist) || (glstate->polygon_mode==GL_LINE))) {
|
||||
if (!(glstate->list.compiling || glstate->gl_batch) && (!(globals4es.beginend) || (glstate->polygon_mode==GL_LINE))) {
|
||||
renderlist_t *mylist = glstate->list.active;
|
||||
glstate->list.active = NULL;
|
||||
mylist = end_renderlist(mylist);
|
||||
@@ -1600,6 +1605,8 @@ void flush() {
|
||||
free_renderlist(mylist);
|
||||
glstate->gl_batch = old;
|
||||
}
|
||||
if(glstate->immediateMV)
|
||||
gl4es_immediateMVEnd();
|
||||
init_statebatch();
|
||||
glstate->list.active = (glstate->gl_batch)?alloc_renderlist():NULL;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,17 @@ void gl4es_glHint(GLenum pname, GLenum mode) {
|
||||
else
|
||||
errorShim(GL_INVALID_ENUM);
|
||||
break;
|
||||
case GL_NOVAOCACHE_HINT_GL4ES:
|
||||
if (mode<=1)
|
||||
globals4es.novaocache = mode;
|
||||
else
|
||||
errorShim(GL_INVALID_ENUM);
|
||||
break;
|
||||
case GL_BEGINEND_HINT_GL4ES:
|
||||
if(mode<=2)
|
||||
globals4es.beginend = mode;
|
||||
else
|
||||
errorShim(GL_INVALID_ENUM);
|
||||
default:
|
||||
errorGL();
|
||||
gles_glHint(pname, mode);
|
||||
|
||||
@@ -45,6 +45,7 @@ void initialize_gl4es() {
|
||||
memset(&globals4es, 0, sizeof(globals4es));
|
||||
globals4es.mergelist = 1;
|
||||
globals4es.queries = 1;
|
||||
globals4es.beginend = 1;
|
||||
// overides by env. variables
|
||||
char *env_nobanner = getenv("LIBGL_NOBANNER");
|
||||
if (env_nobanner && strcmp(env_nobanner, "1") == 0)
|
||||
@@ -266,7 +267,23 @@ void initialize_gl4es() {
|
||||
|
||||
env(LIBGL_NOTEXMAT, globals4es.texmat, "Don't handle Texture Matrice internaly");
|
||||
env(LIBGL_NOVAOCACHE, globals4es.novaocache, "Don't use VAO cache");
|
||||
|
||||
|
||||
char *env_beginend = getenv("LIBGL_BEGINEND");
|
||||
if(env_beginend) {
|
||||
if (strcmp(env_beginend, "0") == 0) {
|
||||
globals4es.beginend = 0;
|
||||
SHUT(LOGD("LIBGL: Don't try to merge subsequent glBegin/glEnd blocks\n"));
|
||||
}
|
||||
if (strcmp(env_beginend, "1") == 0) {
|
||||
globals4es.beginend = 1;
|
||||
SHUT(LOGD("LIBGL: Try to merge subsequent glBegin/glEnd blocks, even if there is a glColor / glNormal in between\n"));
|
||||
}
|
||||
if (strcmp(env_beginend, "2") == 0) {
|
||||
globals4es.beginend = 2;
|
||||
SHUT(LOGD("LIBGL: Try hard to merge subsequent glBegin/glEnd blocks, even if there is a glColor / glNormal or Matrix operations in between\n"));
|
||||
}
|
||||
}
|
||||
|
||||
char cwd[1024];
|
||||
if (getcwd(cwd, sizeof(cwd))!= NULL)
|
||||
SHUT(LOGD("LIBGL: Current folder is:%s\n", cwd));
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef struct _globals4es {
|
||||
#endif
|
||||
int texmat;
|
||||
int novaocache;
|
||||
int beginend;
|
||||
char version[50];
|
||||
} globals4es_t;
|
||||
|
||||
|
||||
@@ -1281,6 +1281,9 @@ void FASTMATH rlVertex4f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z, GL
|
||||
|
||||
GLfloat * const vert = list->vert + (list->len++ * 4);
|
||||
vert[0] = x; vert[1] = y; vert[2] = z; vert[3] = w;
|
||||
if(glstate->immediateMV) { // need to trasform the vector if immediateMV is active
|
||||
vector_matrix(vert, getMVMat(), vert);
|
||||
}
|
||||
}
|
||||
|
||||
void rlNormal3f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z) {
|
||||
@@ -1296,6 +1299,9 @@ void rlNormal3f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z) {
|
||||
|
||||
GLfloat *normal = list->lastNormal;
|
||||
normal[0] = x; normal[1] = y; normal[2] = z;
|
||||
if(glstate->immediateMV) { // need to trasform the vector if immediateMV is active
|
||||
vector3_matrix(normal, getMVMat(), normal);
|
||||
}
|
||||
}
|
||||
|
||||
void rlColor4f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
||||
|
||||
@@ -48,7 +48,10 @@ static int send_to_hardware() {
|
||||
case GL_PROJECTION:
|
||||
return 1;
|
||||
case GL_MODELVIEW:
|
||||
return 1;
|
||||
if (glstate->immediateMV)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
case GL_TEXTURE:
|
||||
return (globals4es.texmat)?1:0;
|
||||
}
|
||||
@@ -88,7 +91,9 @@ DBG(printf("glMatrixMode(%s), list=%p\n", PrintEnum(mode), glstate->list.active)
|
||||
|
||||
void gl4es_glPushMatrix() {
|
||||
DBG(printf("glPushMatrix(), list=%p\n", glstate->list.active);)
|
||||
PUSH_IF_COMPILING(glPushMatrix);
|
||||
/*if (glstate->list.active && !(glstate->immediateMV && glstate->matrix_mode==GL_MODELVIEW))*/ {
|
||||
PUSH_IF_COMPILING(glPushMatrix);
|
||||
}
|
||||
// get matrix mode
|
||||
GLint matrix_mode = glstate->matrix_mode;
|
||||
noerrorShim();
|
||||
@@ -118,8 +123,9 @@ DBG(printf("glPushMatrix(), list=%p\n", glstate->list.active);)
|
||||
|
||||
void gl4es_glPopMatrix() {
|
||||
DBG(printf("glPopMatrix(), list=%p\n", glstate->list.active);)
|
||||
PUSH_IF_COMPILING(glPopMatrix);
|
||||
LOAD_GLES(glLoadMatrixf);
|
||||
/*if (glstate->list.active && !(glstate->immediateMV && glstate->matrix_mode==GL_MODELVIEW))*/ {
|
||||
PUSH_IF_COMPILING(glPopMatrix);
|
||||
}
|
||||
// get matrix mode
|
||||
GLint matrix_mode = glstate->matrix_mode;
|
||||
// go...
|
||||
@@ -128,7 +134,7 @@ DBG(printf("glPopMatrix(), list=%p\n", glstate->list.active);)
|
||||
#define P(A) if(glstate->A->top) { \
|
||||
--glstate->A->top; \
|
||||
glstate->A->identity = is_identity(update_current_mat()); \
|
||||
if (send_to_hardware()) gles_glLoadMatrixf(update_current_mat()); \
|
||||
if (send_to_hardware()) {LOAD_GLES(glLoadMatrixf); gles_glLoadMatrixf(update_current_mat()); } \
|
||||
} else errorShim(GL_STACK_UNDERFLOW)
|
||||
case GL_PROJECTION:
|
||||
P(projection_matrix);
|
||||
@@ -151,10 +157,8 @@ DBG(printf("glPopMatrix(), list=%p\n", glstate->list.active);)
|
||||
|
||||
void gl4es_glLoadMatrixf(const GLfloat * m) {
|
||||
DBG(printf("glLoadMatrix(%f, %f, %f, %f, %f, %f, %f...), list=%p\n", m[0], m[1], m[2], m[3], m[4], m[5], m[6], glstate->list.active);)
|
||||
LOAD_GLES(glLoadMatrixf);
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
|
||||
if (glstate->list.active) {
|
||||
if (glstate->list.active && !(glstate->immediateMV && glstate->matrix_mode==GL_MODELVIEW)) {
|
||||
if(glstate->list.pending) flush();
|
||||
else {
|
||||
NewStage(glstate->list.active, STAGE_MATRIX);
|
||||
@@ -165,16 +169,17 @@ DBG(printf("glLoadMatrix(%f, %f, %f, %f, %f, %f, %f...), list=%p\n", m[0], m[1],
|
||||
}
|
||||
memcpy(update_current_mat(), m, 16*sizeof(GLfloat));
|
||||
const int id = update_current_identity(0);
|
||||
if(send_to_hardware())
|
||||
if(send_to_hardware()) {
|
||||
LOAD_GLES(glLoadMatrixf);
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
if(id) gles_glLoadIdentity(); // in case the driver as some special optimisations
|
||||
else gles_glLoadMatrixf(m);
|
||||
}
|
||||
}
|
||||
|
||||
void gl4es_glMultMatrixf(const GLfloat * m) {
|
||||
DBG(printf("glMultMatrix(%f, %f, %f, %f, %f, %f, %f...), list=%p\n", m[0], m[1], m[2], m[3], m[4], m[5], m[6], glstate->list.active);)
|
||||
LOAD_GLES(glLoadMatrixf);
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
if (glstate->list.active) {
|
||||
if (glstate->list.active && !(glstate->immediateMV && glstate->matrix_mode==GL_MODELVIEW)) {
|
||||
if(glstate->list.pending) flush();
|
||||
else {
|
||||
if(glstate->list.active->stage == STAGE_MATRIX) {
|
||||
@@ -191,15 +196,17 @@ DBG(printf("glMultMatrix(%f, %f, %f, %f, %f, %f, %f...), list=%p\n", m[0], m[1],
|
||||
GLfloat *current_mat = update_current_mat();
|
||||
matrix_mul(current_mat, m, current_mat);
|
||||
const int id = update_current_identity(0);
|
||||
if(send_to_hardware())
|
||||
if(send_to_hardware()) {
|
||||
LOAD_GLES(glLoadMatrixf);
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
if(id) gles_glLoadIdentity(); // in case the driver as some special optimisations
|
||||
else gles_glLoadMatrixf(current_mat);
|
||||
}
|
||||
}
|
||||
|
||||
void gl4es_glLoadIdentity() {
|
||||
DBG(printf("glLoadIdentity(), list=%p\n", glstate->list.active);)
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
if (glstate->list.active) {
|
||||
if (glstate->list.active && !(glstate->immediateMV && glstate->matrix_mode==GL_MODELVIEW)) {
|
||||
if(glstate->list.pending) flush();
|
||||
else {
|
||||
NewStage(glstate->list.active, STAGE_MATRIX);
|
||||
@@ -210,7 +217,10 @@ DBG(printf("glLoadIdentity(), list=%p\n", glstate->list.active);)
|
||||
}
|
||||
set_identity(update_current_mat());
|
||||
update_current_identity(1);
|
||||
if(send_to_hardware()) gles_glLoadIdentity();
|
||||
if(send_to_hardware()) {
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
gles_glLoadIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
void gl4es_glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
||||
@@ -287,6 +297,42 @@ DBG(printf("glFrustumf(%f, %f, %f, %f, %f, %f) list=%p\n", left, right, top, bot
|
||||
gl4es_glMultMatrixf(tmp);
|
||||
}
|
||||
|
||||
void gl4es_immediateMVBegin() {
|
||||
if(glstate->immediateMV)
|
||||
return; // nothing to do...
|
||||
|
||||
glstate->immediateMV = 1;
|
||||
|
||||
// set MV matrix to identity
|
||||
if(!glstate->modelview_matrix->identity) {
|
||||
LOAD_GLES(glLoadIdentity);
|
||||
LOAD_GLES(glMatrixMode);
|
||||
if(glstate->matrix_mode!=GL_MODELVIEW)
|
||||
gles_glMatrixMode(GL_MODELVIEW);
|
||||
gles_glLoadIdentity();
|
||||
if(glstate->matrix_mode!=GL_MODELVIEW)
|
||||
gles_glMatrixMode(glstate->matrix_mode);
|
||||
}
|
||||
|
||||
}
|
||||
void gl4es_immediateMVEnd() {
|
||||
if(glstate->immediateMV==0)
|
||||
return; // nothing to do
|
||||
|
||||
glstate->immediateMV=0;
|
||||
|
||||
// send MV matrix back
|
||||
if(!glstate->modelview_matrix->identity) {
|
||||
LOAD_GLES(glLoadMatrixf);
|
||||
LOAD_GLES(glMatrixMode);
|
||||
if(glstate->matrix_mode!=GL_MODELVIEW)
|
||||
gles_glMatrixMode(GL_MODELVIEW);
|
||||
gles_glLoadMatrixf(getMVMat());
|
||||
if(glstate->matrix_mode!=GL_MODELVIEW)
|
||||
gles_glMatrixMode(glstate->matrix_mode);
|
||||
}
|
||||
}
|
||||
|
||||
void glMatrixMode(GLenum mode) AliasExport("gl4es_glMatrixMode");
|
||||
void glPushMatrix() AliasExport("gl4es_glPushMatrix");
|
||||
void glPopMatrix() AliasExport("gl4es_glPopMatrix");
|
||||
|
||||
@@ -18,4 +18,7 @@ static inline GLfloat* getTexMat(int tmu) {
|
||||
|
||||
static inline GLfloat* getMVMat() {
|
||||
return glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16;
|
||||
}
|
||||
}
|
||||
|
||||
void gl4es_immediateMVBegin();
|
||||
void gl4es_immediateMVEnd();
|
||||
@@ -194,6 +194,7 @@ typedef struct {
|
||||
int shared_cnt;
|
||||
light_state_t light;
|
||||
material_state_t material;
|
||||
int immediateMV;
|
||||
} glstate_t;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
#define MAJOR 0
|
||||
#define MINOR 9
|
||||
#define REVISION 4
|
||||
#define REVISION 5
|
||||
|
||||
#endif //_GL4ES_VERSION_H
|
||||
|
||||
Reference in New Issue
Block a user