diff --git a/nanoWrap.cpp b/nanoWrap.cpp
index e159046488ad94dbd24f21818ec451b63992eea3..5c5eec805314a6a8deb061897e67b88e7b0e7d54 100644 (file)
--- a/nanoWrap.cpp
+++ b/nanoWrap.cpp
GLboolean depth_test;
GLboolean dither;
GLboolean fog;
- GLboolean lighti;
+ GLboolean light0;
+ GLboolean light1;
+ GLboolean light2;
+ GLboolean light3;
+ GLboolean light4;
+ GLboolean light5;
+ GLboolean light6;
+ GLboolean light7;
GLboolean lighting;
GLboolean line_smooth;
GLboolean matrix_palette_oes;
GLboolean scissor_test;
GLboolean stencil_test;
GLboolean depthmask;
- GLclampf depth_range_near;
- GLclampf depth_range_far;
+ GLclampd depth_range_near;
+ GLclampd depth_range_far;
GLenum depth_func;
GLenum cullface;
GLenum shademodel;
static struct nanoState nanoglState;
static struct nanoState nanoglInitState =
- {
+{
GL_FALSE,
GL_FALSE,
GL_FALSE,
GL_FALSE,
GL_FALSE,
GL_FALSE,
+ GL_FALSE,
+ GL_FALSE,
+ GL_FALSE,
+ GL_FALSE,
+ GL_FALSE,
+ GL_FALSE,
+ GL_FALSE,
GL_TRUE,
GL_FALSE,
GL_FALSE,
static struct nanotmuState *activetmuState = &tmuState0;
-extern "C++" GlESInterface *glEsImpl;
+extern GlESInterface *glEsImpl;
static GLenum wrapperPrimitiveMode = GL_QUADS;
GLboolean useTexCoordArray = GL_FALSE;
static GLboolean arraysValid = GL_FALSE;
+static GLboolean skipnanogl;
+
void InitGLStructs( )
{
ptrVertexAttribArray = vertexattribs;
glEsImpl->glMatrixMode( nanoglState.matrixmode );
- glEsImpl->glColor4f( currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha );
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
glEsImpl->glBlendFunc( nanoglState.sfactor, nanoglState.dfactor );
glEsImpl->glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value );
arraysValid = GL_FALSE;
+ skipnanogl = GL_FALSE;
}
void FlushOnStateChange( )
{
+ if( skipnanogl )
+ return;
if ( delayedttmuchange )
{
delayedttmuchange = GL_FALSE;
*ptrIndexArray++ = indexCount++;
*ptrIndexArray++ = indexCount++;
*ptrIndexArray++ = indexCount++;
- int vcount = ( ( vertexCount - vertexMark ) - 3 );
+ int vcount = ( ( vertexCount - vertexMark ) - 3 );
for ( int count = 0; count < vcount; count++ )
{
*ptrIndexArray++ = indexbase;
void glEnable( GLenum cap )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glEnable( cap );
+ return;
+ }
GLboolean statechanged = GL_FALSE;
switch ( cap )
{
break;
}
case GL_FOG:
- //case GL_LIGHTi
+ {
+ if ( !nanoglState.fog )
{
- if ( !nanoglState.fog )
- {
- nanoglState.fog = GL_TRUE;
- statechanged = GL_TRUE;
- }
- break;
+ nanoglState.fog = GL_TRUE;
+ statechanged = GL_TRUE;
}
+ break;
+ }
+ case GL_LIGHT0:
+ {
+ if ( !nanoglState.light0 )
+ {
+ nanoglState.light0 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT1:
+ {
+ if ( !nanoglState.light1 )
+ {
+ nanoglState.light1 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT2:
+ {
+ if ( !nanoglState.light2 )
+ {
+ nanoglState.light2 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT3:
+ {
+ if ( !nanoglState.light3 )
+ {
+ nanoglState.light3 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT4:
+ {
+ if ( !nanoglState.light4 )
+ {
+ nanoglState.light4 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT5:
+ {
+ if ( !nanoglState.light5 )
+ {
+ nanoglState.light5 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT6:
+ {
+ if ( !nanoglState.light6 )
+ {
+ nanoglState.light6 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT7:
+ {
+ if ( !nanoglState.light7 )
+ {
+ nanoglState.light7 = GL_TRUE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
case GL_LIGHTING:
{
if ( !nanoglState.lighting )
case GL_STENCIL_TEST:
{
return;
- /* if (!nanoglState.stencil_test)
+ if (!nanoglState.stencil_test)
{
nanoglState.stencil_test = GL_TRUE;
statechanged = GL_TRUE;
- }*/
+ }
break;
}
case GL_TEXTURE_2D:
}
break;
}
+#if 0 // todo: implement cubemap texgen
+ case GL_TEXTURE_GEN_S:
+ case GL_TEXTURE_GEN_T:
+ case GL_TEXTURE_GEN_R:
+ case GL_TEXTURE_GEN_Q:
+ {
+ FlushOnStateChange( );
+ nanoglState.texgen = true;
+ return;
+ }
+#endif
default:
break;
}
void glDisable( GLenum cap )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glDisable( cap );
+ return;
+ }
GLboolean statechanged = GL_FALSE;
switch ( cap )
{
break;
}
case GL_FOG:
- //case GL_LIGHTi
+ {
+ if ( nanoglState.fog )
{
- if ( nanoglState.fog )
- {
- nanoglState.fog = GL_FALSE;
- statechanged = GL_TRUE;
- }
- break;
+ nanoglState.fog = GL_FALSE;
+ statechanged = GL_TRUE;
}
+ break;
+ }
+ case GL_LIGHT0:
+ {
+ if ( !nanoglState.light0 )
+ {
+ nanoglState.light0 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT1:
+ {
+ if ( !nanoglState.light1 )
+ {
+ nanoglState.light1 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT2:
+ {
+ if ( !nanoglState.light2 )
+ {
+ nanoglState.light2 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT3:
+ {
+ if ( !nanoglState.light3 )
+ {
+ nanoglState.light3 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT4:
+ {
+ if ( !nanoglState.light4 )
+ {
+ nanoglState.light4 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT5:
+ {
+ if ( !nanoglState.light5 )
+ {
+ nanoglState.light5 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT6:
+ {
+ if ( !nanoglState.light6 )
+ {
+ nanoglState.light6 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
+ case GL_LIGHT7:
+ {
+ if ( !nanoglState.light7 )
+ {
+ nanoglState.light7 = GL_FALSE;
+ statechanged = GL_TRUE;
+ }
+ break;
+ }
case GL_LIGHTING:
{
if ( nanoglState.lighting )
case GL_STENCIL_TEST:
{
return;
- /* if (nanoglState.stencil_test)
+ if (nanoglState.stencil_test)
{
nanoglState.stencil_test = GL_FALSE;
statechanged = GL_TRUE;
- }*/
+ }
break;
}
case GL_TEXTURE_2D:
}
break;
}
+#if 0
+ case GL_TEXTURE_GEN_S:
+ case GL_TEXTURE_GEN_T:
+ case GL_TEXTURE_GEN_R:
+ case GL_TEXTURE_GEN_Q:
+ {
+ FlushOnStateChange( );
+ nanoglState.texgen = false;
+ return;
+ }
+#endif
default:
break;
}
currentVertexAttrib.alpha = (unsigned char)ClampTo255( alpha * 255.0f );
}
-void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
+void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
{
FlushOnStateChange( );
#ifdef USE_CORE_PROFILE
@@ -1006,6 +1200,50 @@ void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat
#endif
}
+// Rikku2000: Light
+void glLightf( GLenum light, GLenum pname, GLfloat param )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glLightf( light, pname, param );
+}
+void glLightfv( GLenum light, GLenum pname, const GLfloat *params )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glLightfv( light, pname, params );
+}
+void glLightModelf( GLenum pname, GLfloat param )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glLightModelf( pname, param );
+}
+void glLightModelfv( GLenum pname, const GLfloat *params )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glLightModelfv( pname, params );
+}
+void glMaterialf( GLenum face, GLenum pname, GLfloat param )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glMaterialf( face, pname, param );
+}
+void glMaterialfv( GLenum face, GLenum pname, const GLfloat *params )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glMaterialfv( face, pname, params );
+}
+void glColorMaterial( GLenum face, GLenum mode )
+{
+ FlushOnStateChange( );
+
+ glEsImpl->glColorMaterial( face, mode );
+}
+
void glMatrixMode( GLenum mode )
{
if ( nanoglState.matrixmode == mode )
void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
{
- FlushOnStateChange( );
+ unsigned char *data = (unsigned char*)pixels;
+
+ if( internalformat == GL_RGB && format == GL_RGBA ) // strip alpha from texture
+ {
+ unsigned char *in = data, *out;
+ int i = 0, size = width * height * 4;
+
+ data = out = (unsigned char*)malloc( size );
+
+ for( i = 0; i < size; i += 4, in += 4, out += 4 )
+ {
+ memcpy( out, in, 3 );
+ out[3] = 255;
+ }
+ }
+
internalformat = format;
- glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, pixels );
+ glEsImpl->glTexImage2D( target, level, internalformat, width, height, border, format, type, data );
+
+ if( data != pixels )
+ free(data);
}
void glDrawBuffer( GLenum /*mode*/ )
glEsImpl->glScalef( x, y, z );
}
-void glDepthRange( GLclampf zNear, GLclampf zFar )
+void glDepthRange( GLclampd zNear, GLclampd zFar )
{
if ( ( nanoglState.depth_range_near == zNear ) && ( nanoglState.depth_range_far == zFar ) )
{
glEsImpl->glCullFace( mode );
}
-void glFrustum( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar )
+void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar )
{
FlushOnStateChange( );
glEsImpl->glFrustumf( left, right, bottom, top, zNear, zFar );
GLfloat *vert = (GLfloat *)ptrVertexAttribArray++;
*vert++ = x;
*vert++ = y;
- *vert++ = z;
+ *vert++ = z;
#if defined( __MULTITEXTURE_SUPPORT__ )
memcpy( vert, ¤tVertexAttrib.red, 5 * sizeof( GLfloat ) );
#else
currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
currentVertexAttrib.alpha = (unsigned char)ClampTo255( v[3] * 255.0f );
+ if( skipnanogl )
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
}
void glColor3ubv( const GLubyte *v )
currentVertexAttrib.green = v[1];
currentVertexAttrib.blue = v[2];
currentVertexAttrib.alpha = 255;
+ if( skipnanogl )
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
}
void glColor4ubv( const GLubyte *v )
currentVertexAttrib.green = v[1];
currentVertexAttrib.blue = v[2];
currentVertexAttrib.alpha = v[3];
+ if( skipnanogl )
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
}
void glColor3fv( const GLfloat *v )
currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f );
currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f );
currentVertexAttrib.alpha = 255;
+ if( skipnanogl )
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
}
//-- nicknekit: xash3d funcs --
currentVertexAttrib.green = green;
currentVertexAttrib.blue = blue;
currentVertexAttrib.alpha = alpha;
+ if( skipnanogl )
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
}
void glColor3ub( GLubyte red, GLubyte green, GLubyte blue )
currentVertexAttrib.green = green;
currentVertexAttrib.blue = blue;
currentVertexAttrib.alpha = 255;
+ if( skipnanogl )
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
}
void glNormal3fv( const GLfloat *v )
return glEsImpl->glIsTexture( texture );
}
+// TODO: add native normal/reflection map texgen support
+
void glTexGeni( GLenum coord, GLenum pname, GLint param )
{
- //for mirrors? not needed for original hl?
+ FlushOnStateChange();
+ //glEsImpl->glTexGeniOES( coord, pname, param );
}
void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
{
- //for mirrors? not needed for original hl?
+ FlushOnStateChange();
+ //glEsImpl->glTexGenfvOES( coord, pname, params );
}
//-- --//
void glBlendFunc( GLenum sfactor, GLenum dfactor )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glBlendFunc( sfactor, dfactor );
+ return;
+ }
if ( ( nanoglState.sfactor == sfactor ) && ( nanoglState.dfactor == dfactor ) )
{
return;
}
+
nanoglState.sfactor = sfactor;
nanoglState.dfactor = dfactor;
FlushOnStateChange( );
void glTexEnvf( GLenum target, GLenum pname, GLfloat param )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glTexEnvf( target, pname, param );
+ return;
+ }
if ( target == GL_TEXTURE_ENV )
{
if ( pname == GL_TEXTURE_ENV_MODE )
void glDepthMask( GLboolean flag )
{
+ if( !skipnanogl )
+ {
if ( nanoglState.depthmask == flag )
{
return;
}
nanoglState.depthmask = flag;
FlushOnStateChange( );
+ }
glEsImpl->glDepthMask( flag );
}
void glBindTexture( GLenum target, GLuint texture )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glBindTexture( target,texture );
+ return;
+ }
if ( activetmuState->boundtexture.value == texture )
{
return;
void glActiveTexture( GLenum texture )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glActiveTexture( texture );
+ return;
+ }
+ if ( activetmu == texture )
+ {
+ return;
+ }
+ if ( delayedttmuchange )
+ {
+ delayedttmuchange = GL_FALSE;
+ }
+ else
+ {
+ delayedttmuchange = GL_TRUE;
+ delayedtmutarget = texture;
+ }
+ if ( texture == GL_TEXTURE0 )
+ {
+ activetmuState = &tmuState0;
+ }
+ else
+ {
+ activetmuState = &tmuState1;
+ }
+ activetmu = texture;
+}
+
+void glActiveTextureARB( GLenum texture )
+{
+ if( skipnanogl )
+ {
+ glEsImpl->glActiveTexture( texture );
+ return;
+ }
if ( activetmu == texture )
{
return;
void glClientActiveTexture( GLenum texture )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glClientActiveTexture( texture );
+ return;
+ }
+ clientactivetmu = texture;
+}
+void glClientActiveTextureARB( GLenum texture )
+{
+ if( skipnanogl )
+ {
+ glEsImpl->glClientActiveTexture( texture );
+ return;
+ }
clientactivetmu = texture;
}
+
void glPolygonMode( GLenum face, GLenum mode )
{
}
glEsImpl->glDeleteTextures( n, textures );
}
-void glClearDepth( GLclampf depth )
+void glClearDepth( GLclampd depth )
{
FlushOnStateChange( );
glEsImpl->glClearDepthf( depth );
void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glDrawElements( mode, count, type, indices );
+ return;
+ }
// ensure that all primitives specified between glBegin/glEnd pairs
// are rendered first, and that we have correct tmu in use..
FlushOnStateChange( );
@@ -1621,8 +1974,17 @@ void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indi
glEsImpl->glDrawElements( mode, count, type, indices );
}
+bool vboarray;
+
void glEnableClientState( GLenum array )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glEnableClientState( array );
+ if( array == GL_VERTEX_ARRAY )
+ vboarray = true;
+ return;
+ }
struct nanotmuState *clientstate = NULL;
if ( clientactivetmu == GL_TEXTURE0 )
{
}
void glDisableClientState( GLenum array )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glDisableClientState( array );
+ if( array == GL_VERTEX_ARRAY )
+ vboarray = false;
+ return;
+ }
struct nanotmuState *clientstate = NULL;
if ( clientactivetmu == GL_TEXTURE0 )
{
}
void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
{
+
+ if( skipnanogl )
+ {
+ glEsImpl->glVertexPointer( size, type, stride, pointer );
+ return;
+ }
if ( tmuState0.vertex_array.size == size &&
tmuState0.vertex_array.stride == stride &&
tmuState0.vertex_array.type == type &&
@@ -1748,6 +2123,11 @@ void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *poi
}
void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glTexCoordPointer( size, type, stride, pointer );
+ return;
+ }
struct nanotmuState *clientstate = NULL;
if ( clientactivetmu == GL_TEXTURE0 )
{
glEsImpl->glPixelStorei( pname, param );
}
+void glFogi( GLenum pname, GLint param )
+{
+ FlushOnStateChange( );
+ glEsImpl->glFogf( pname, param );
+}
+
void glFogf( GLenum pname, GLfloat param )
{
FlushOnStateChange( );
void glTexEnvi( GLenum target, GLenum pname, GLint param )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glTexEnvi( target, pname, param );
+ return;
+ }
if ( target == GL_TEXTURE_ENV )
{
if ( pname == GL_TEXTURE_ENV_MODE )
return glMultiTexCoord2fARB( a, b, c );
}
-void glMultiTexCoord2f( GLenum, GLfloat, GLfloat )
+void glMultiTexCoord2f( GLenum a, GLfloat b, GLfloat c )
{
+ glMultiTexCoord2fARB(a,b,c);
}
#endif
void glDrawArrays( GLenum mode, GLint first, GLsizei count )
{
+ if( skipnanogl )
+ {
+ glEsImpl->glDrawArrays( mode, first, count );
+ return;
+ }
// ensure that all primitives specified between glBegin/glEnd pairs
// are rendered first, and that we have correct tmu in use..
if ( mode == GL_QUADS )
@@ -2111,3 +2508,42 @@ void glRenderbufferStorage( GLenum target, GLenum internalformat, GLsizei width,
FlushOnStateChange( );
glEsImpl->glRenderbufferStorage( target, internalformat, width, height );
}
+
+void glBindBufferARB( GLuint target, GLuint index )
+{
+ static int sindex;
+
+ if( index && !sindex && !skipnanogl )
+ FlushOnStateChange();
+ glEsImpl->glDisableClientState( GL_COLOR_ARRAY );
+ glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f,
+ currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f );
+
+ skipnanogl = (!!index) || vboarray;
+ glEsImpl->glBindBuffer( target, index );
+ if( sindex && !index )
+ {
+ arraysValid = GL_FALSE;
+ }
+ sindex = index;
+}
+
+void glGenBuffersARB( GLuint count, GLuint *indexes )
+{
+ glEsImpl->glGenBuffers( count, indexes );
+}
+
+void glDeleteBuffersARB( GLuint count, GLuint *indexes )
+{
+ glEsImpl->glDeleteBuffers( count, indexes );
+}
+
+void glBufferDataARB( GLuint target, GLuint size, void *buffer, GLuint type )
+{
+ glEsImpl->glBufferData( target, size, buffer, type );
+}
+
+void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buffer )
+{
+ glEsImpl->glBufferSubData( target, offset, size, buffer );
+}