X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=nanoWrap.cpp;h=0e997fe783b5cfd83a7d7b6112111472c25d3f6b;hb=ab44ab4e29101bce2bc183dc931250f258f4ce78;hp=3a6fb389186ffabacd6c7c2f95abab39d0631dd8;hpb=7d739ba89833eb4e9c4bc969bbf4ec746bccc08d;p=nanogl.git diff --git a/nanoWrap.cpp b/nanoWrap.cpp index 3a6fb38..0e997fe 100644 --- a/nanoWrap.cpp +++ b/nanoWrap.cpp @@ -44,7 +44,14 @@ struct nanoState 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; @@ -60,9 +67,8 @@ struct nanoState GLboolean scissor_test; GLboolean stencil_test; GLboolean depthmask; - GLboolean stupidglesbug; - GLclampf depth_range_near; - GLclampf depth_range_far; + GLclampd depth_range_near; + GLclampd depth_range_far; GLenum depth_func; GLenum cullface; GLenum shademodel; @@ -88,6 +94,13 @@ 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_TRUE, GL_FALSE, GL_FALSE, @@ -100,7 +113,6 @@ static struct nanoState nanoglInitState = GL_FALSE, GL_FALSE, GL_TRUE, - GL_FALSE, 0.0f, 1.0f, GL_LESS, @@ -166,7 +178,7 @@ static struct nanotmuState tmuInitState = static struct nanotmuState *activetmuState = &tmuState0; -extern "C++" GlESInterface *glEsImpl; +extern GlESInterface *glEsImpl; static GLenum wrapperPrimitiveMode = GL_QUADS; GLboolean useTexCoordArray = GL_FALSE; @@ -493,7 +505,7 @@ void glEnd( void ) *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; @@ -587,15 +599,86 @@ void glEnable( GLenum 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 ) @@ -822,15 +905,86 @@ void glDisable( GLenum 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 ) @@ -1029,23 +1183,14 @@ void glLoadIdentity( void ) } void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) -{ - if( nanoglState.stupidglesbug ) - { - currentVertexAttrib.red = (unsigned char)ClampTo255( ( red * alpha ) * 255.0f ); - currentVertexAttrib.green = (unsigned char)ClampTo255( ( green * alpha ) * 255.0f ); - currentVertexAttrib.blue = (unsigned char)ClampTo255( ( blue * alpha ) * 255.0f ); - } - else - { - currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f ); - currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f ); - currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f ); - } +{ + currentVertexAttrib.red = (unsigned char)ClampTo255( red * 255.0f ); + currentVertexAttrib.green = (unsigned char)ClampTo255( green * 255.0f ); + currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * 255.0f ); 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 @@ -1055,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 ) @@ -1090,9 +1279,27 @@ void glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) 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( pixels && 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*/ ) @@ -1117,7 +1324,7 @@ void glScalef( GLfloat x, GLfloat y, GLfloat z ) 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 ) ) { @@ -1176,7 +1383,7 @@ void glCullFace( GLenum mode ) 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 ); @@ -1193,7 +1400,7 @@ void glVertex3f( GLfloat x, GLfloat y, GLfloat z ) GLfloat *vert = (GLfloat *)ptrVertexAttribArray++; *vert++ = x; *vert++ = y; - *vert++ = z; + *vert++ = z; #if defined( __MULTITEXTURE_SUPPORT__ ) memcpy( vert, ¤tVertexAttrib.red, 5 * sizeof( GLfloat ) ); #else @@ -1202,19 +1409,10 @@ void glVertex3f( GLfloat x, GLfloat y, GLfloat z ) } void glColor4fv( const GLfloat *v ) -{ - if( nanoglState.stupidglesbug ) - { - currentVertexAttrib.red = (unsigned char)ClampTo255( ( v[0] * v[3] ) * 255.0f ); - currentVertexAttrib.green = (unsigned char)ClampTo255( ( v[1] * v[3] ) * 255.0f ); - currentVertexAttrib.blue = (unsigned char)ClampTo255( ( v[2] * v[3] ) * 255.0f ); - } - else - { - currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f ); - currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * 255.0f ); - currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * 255.0f ); - } +{ + currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * 255.0f ); + 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, @@ -1235,18 +1433,9 @@ void glColor3ubv( const GLubyte *v ) void glColor4ubv( const GLubyte *v ) { //*((unsigned int*)(¤tVertexAttrib.red)) = *((unsigned int*)(v)); - if( nanoglState.stupidglesbug ) - { - currentVertexAttrib.red = (unsigned char)ClampTo255( v[0] * v[3] / 255.0f ); - currentVertexAttrib.green = (unsigned char)ClampTo255( v[1] * v[3] / 255.0f ); - currentVertexAttrib.blue = (unsigned char)ClampTo255( v[2] * v[3] / 255.0f ); - } - else - { - currentVertexAttrib.red = v[0]; - currentVertexAttrib.green = v[1]; - currentVertexAttrib.blue = v[2]; - } + currentVertexAttrib.red = v[0]; + currentVertexAttrib.green = v[1]; + currentVertexAttrib.blue = v[2]; currentVertexAttrib.alpha = v[3]; if( skipnanogl ) glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f, @@ -1268,18 +1457,9 @@ void glColor3fv( const GLfloat *v ) void glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha ) { - if( nanoglState.stupidglesbug ) - { - currentVertexAttrib.red = (unsigned char)ClampTo255( red * alpha / 255.0f ); - currentVertexAttrib.green = (unsigned char)ClampTo255( green * alpha / 255.0f ); - currentVertexAttrib.blue = (unsigned char)ClampTo255( blue * alpha / 255.0f ); - } - else - { - currentVertexAttrib.red = red; - currentVertexAttrib.green = green; - currentVertexAttrib.blue = blue; - } + currentVertexAttrib.red = red; + currentVertexAttrib.green = green; + currentVertexAttrib.blue = blue; currentVertexAttrib.alpha = alpha; if( skipnanogl ) glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f, @@ -1373,15 +1553,7 @@ void glBlendFunc( GLenum sfactor, GLenum dfactor ) { return; } - - if( sfactor == GL_SRC_ALPHA && dfactor == GL_ONE ) - { - sfactor = GL_ONE; // workaround gles bug - nanoglState.stupidglesbug = GL_TRUE; - } - else - nanoglState.stupidglesbug = GL_FALSE; - + nanoglState.sfactor = sfactor; nanoglState.dfactor = dfactor; FlushOnStateChange( ); @@ -1585,6 +1757,37 @@ void glActiveTexture( GLenum texture ) activetmu = texture; } +void glActiveTextureARB( 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 glClientActiveTexture( GLenum texture ) { if( skipnanogl ) @@ -1594,6 +1797,16 @@ void glClientActiveTexture( GLenum texture ) } clientactivetmu = texture; } +void glClientActiveTextureARB( GLenum texture ) +{ + if( skipnanogl ) + { + glEsImpl->glClientActiveTexture( texture ); + return; + } + clientactivetmu = texture; +} + void glPolygonMode( GLenum face, GLenum mode ) { @@ -1605,7 +1818,7 @@ void glDeleteTextures( GLsizei n, const GLuint *textures ) glEsImpl->glDeleteTextures( n, textures ); } -void glClearDepth( GLclampf depth ) +void glClearDepth( GLclampd depth ) { FlushOnStateChange( ); glEsImpl->glClearDepthf( depth ); @@ -2017,6 +2230,12 @@ void glPixelStorei( GLenum pname, GLint param ) glEsImpl->glPixelStorei( pname, param ); } +void glFogi( GLenum pname, GLint param ) +{ + FlushOnStateChange( ); + glEsImpl->glFogf( pname, param ); +} + void glFogf( GLenum pname, GLfloat param ) { FlushOnStateChange( ); @@ -2327,4 +2546,4 @@ void glBufferDataARB( GLuint target, GLuint size, void *buffer, GLuint type ) void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buffer ) { glEsImpl->glBufferSubData( target, offset, size, buffer ); -} \ No newline at end of file +}