X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=nanoWrap.cpp;h=9cf8c7c2055bc96645be154220b88f2da5c6119c;hb=5bdf537d06bac340e861338af9c3fea99d3724cf;hp=3e88b0f8150d9c6a2b16dc5388ec49c16c0e525f;hpb=472a91567501b466be9161d26025060306f869d2;p=nanogl.git diff --git a/nanoWrap.cpp b/nanoWrap.cpp index 3e88b0f..9cf8c7c 100644 --- a/nanoWrap.cpp +++ b/nanoWrap.cpp @@ -67,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; @@ -114,7 +113,6 @@ static struct nanoState nanoglInitState = GL_FALSE, GL_FALSE, GL_TRUE, - GL_FALSE, 0.0f, 1.0f, GL_LESS, @@ -791,12 +789,11 @@ void glEnable( GLenum cap ) } case GL_STENCIL_TEST: { - return; if (!nanoglState.stencil_test) - { - nanoglState.stencil_test = GL_TRUE; - statechanged = GL_TRUE; - } + { + nanoglState.stencil_test = GL_TRUE; + statechanged = GL_TRUE; + } break; } case GL_TEXTURE_2D: @@ -1097,12 +1094,11 @@ void glDisable( GLenum cap ) } case GL_STENCIL_TEST: { - return; if (nanoglState.stencil_test) - { - nanoglState.stencil_test = GL_FALSE; - statechanged = GL_TRUE; - } + { + nanoglState.stencil_test = GL_FALSE; + statechanged = GL_TRUE; + } break; } case GL_TEXTURE_2D: @@ -1185,23 +1181,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 @@ -1290,9 +1277,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*/ ) @@ -1317,7 +1322,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 ) ) { @@ -1376,7 +1381,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 ); @@ -1402,19 +1407,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, @@ -1435,18 +1431,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, @@ -1468,18 +1455,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, @@ -1573,15 +1551,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( ); @@ -1785,6 +1755,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 ) @@ -1794,6 +1795,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 ) { @@ -1805,7 +1816,7 @@ void glDeleteTextures( GLsizei n, const GLuint *textures ) glEsImpl->glDeleteTextures( n, textures ); } -void glClearDepth( GLclampf depth ) +void glClearDepth( GLclampd depth ) { FlushOnStateChange( ); glEsImpl->glClearDepthf( depth ); @@ -1845,12 +1856,18 @@ void glCallList( GLuint list ) } void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ) { + FlushOnStateChange( ); + glEsImpl->glColorMask( red, green, blue, alpha ); } void glStencilFunc( GLenum func, GLint ref, GLuint mask ) { + FlushOnStateChange( ); + glEsImpl->glStencilFunc( func, ref, mask ); } void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ) { + FlushOnStateChange( ); + glEsImpl->glStencilOp( fail, zfail, zpass ); } struct ptrstate vertex_array; @@ -1900,6 +1917,9 @@ void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indi else { glEsImpl->glDisableClientState( GL_COLOR_ARRAY ); + glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f, + currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f ); + } glEsImpl->glColorPointer( tmuState0.color_array.size, tmuState0.color_array.type, @@ -2176,9 +2196,13 @@ void glPolygonOffset( GLfloat factor, GLfloat units ) } void glStencilMask( GLuint mask ) { + FlushOnStateChange( ); + glEsImpl->glStencilMask( mask ); } void glClearStencil( GLint s ) { + FlushOnStateChange( ); + glEsImpl->glClearStencil( s ); } #if defined( __MULTITEXTURE_SUPPORT__ ) @@ -2217,6 +2241,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( ); @@ -2366,6 +2396,9 @@ void glDrawArrays( GLenum mode, GLint first, GLsizei count ) else { glEsImpl->glDisableClientState( GL_COLOR_ARRAY ); + glEsImpl->glColor4f( currentVertexAttrib.red/255.0f, currentVertexAttrib.green/255.0f, + currentVertexAttrib.blue/255.0f, currentVertexAttrib.alpha/255.0f ); + } glEsImpl->glColorPointer( tmuState0.color_array.size, tmuState0.color_array.type,