X-Git-Url: https://deadsoftware.ru/gitweb?p=nanogl.git;a=blobdiff_plain;f=nanoWrap.cpp;h=62e37ad3382b9be144ba24a03a1b5324629a60c9;hp=8749bfbf3a98a7e00858124d1cb075625638e46f;hb=HEAD;hpb=ff570586136c0e09212a18d77ed14b57264edb90 diff --git a/nanoWrap.cpp b/nanoWrap.cpp index 8749bfb..62e37ad 100644 --- a/nanoWrap.cpp +++ b/nanoWrap.cpp @@ -67,8 +67,8 @@ struct nanoState 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; @@ -246,6 +246,64 @@ static GLboolean arraysValid = GL_FALSE; static GLboolean skipnanogl; +#define STACK_ATTRIB_ENABLE_BIT_LEN (sizeof(stackAttribEnableBit) / sizeof(stackAttribEnableBit[0])) +static const GLenum stackAttribEnableBit[] = +{ + GL_ALPHA_TEST, + GL_BLEND, + GL_CLIP_PLANE0, + GL_CLIP_PLANE1, + GL_CLIP_PLANE2, + GL_CLIP_PLANE3, + GL_CLIP_PLANE4, + GL_CLIP_PLANE5, + GL_COLOR_MATERIAL, + GL_CULL_FACE, + GL_DEPTH_TEST, + GL_DITHER, + GL_FOG, + GL_LIGHT0, + GL_LIGHT1, + GL_LIGHT2, + GL_LIGHT3, + GL_LIGHT4, + GL_LIGHT5, + GL_LIGHT6, + GL_LIGHT7, + GL_LIGHTING, + GL_LINE_SMOOTH, + GL_COLOR_LOGIC_OP, + GL_MULTISAMPLE, + GL_NORMALIZE, + GL_POINT_SMOOTH, + GL_POLYGON_OFFSET_LINE, + GL_POLYGON_OFFSET_FILL, + GL_POLYGON_OFFSET_POINT, + GL_POLYGON_SMOOTH, + GL_POLYGON_STIPPLE, + GL_SAMPLE_ALPHA_TO_COVERAGE, + GL_SAMPLE_ALPHA_TO_ONE, + GL_SAMPLE_COVERAGE, + GL_SCISSOR_TEST, + GL_STENCIL_TEST, + GL_TEXTURE_1D, + GL_TEXTURE_2D, + GL_TEXTURE_GEN_S, + GL_TEXTURE_GEN_T, + GL_TEXTURE_GEN_R, + GL_TEXTURE_GEN_Q, +}; + +#define MAX_ATTRIB_STACK 16 +struct attribStore +{ + GLbitfield mask; + GLboolean enable[STACK_ATTRIB_ENABLE_BIT_LEN]; +}; + +static struct attribStore attribStack[MAX_ATTRIB_STACK]; +static int attribStackCount = 0; + void InitGLStructs( ) { ptrVertexAttribArray = vertexattribs; @@ -269,6 +327,9 @@ void InitGLStructs( ) vertexMark = 0; indexbase = 0; arraysValid = GL_FALSE; + + memset(attribStack, 0, sizeof( struct attribStore )); + attribStackCount = 0; } void ResetNanoState( ) @@ -342,6 +403,9 @@ void ResetNanoState( ) arraysValid = GL_FALSE; skipnanogl = GL_FALSE; + + memset(attribStack, 0, sizeof( struct attribStore )); + attribStackCount = 0; } void FlushOnStateChange( ) @@ -789,12 +853,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: @@ -1095,12 +1158,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: @@ -1190,7 +1252,7 @@ void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) 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 @@ -1281,7 +1343,7 @@ void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei wid { unsigned char *data = (unsigned char*)pixels; - if( internalformat == GL_RGB && format == GL_RGBA ) // strip alpha from texture + if( pixels && internalformat == GL_RGB && format == GL_RGBA ) // strip alpha from texture { unsigned char *in = data, *out; int i = 0, size = width * height * 4; @@ -1324,7 +1386,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 ) ) { @@ -1383,7 +1445,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 ); @@ -1757,6 +1819,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 ) @@ -1766,6 +1859,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 ) { @@ -1777,7 +1880,7 @@ void glDeleteTextures( GLsizei n, const GLuint *textures ) glEsImpl->glDeleteTextures( n, textures ); } -void glClearDepth( GLclampf depth ) +void glClearDepth( GLclampd depth ) { FlushOnStateChange( ); glEsImpl->glClearDepthf( depth ); @@ -1817,12 +1920,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; @@ -1872,6 +1981,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, @@ -2148,9 +2260,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__ ) @@ -2189,6 +2305,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( ); @@ -2338,6 +2460,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, @@ -2500,3 +2625,146 @@ void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buff { glEsImpl->glBufferSubData( target, offset, size, buffer ); } + +GLboolean glIsEnabled(GLenum cap) +{ + FlushOnStateChange( ); + + if( skipnanogl ) + { + return glEsImpl->glIsEnabled(cap); + } + + switch ( cap ) + { + case GL_ALPHA_TEST: + return nanoglState.alpha_test; + case GL_BLEND: + return nanoglState.blend; + case GL_COLOR_LOGIC_OP: + return nanoglState.color_logic_op; + case GL_COLOR_MATERIAL: + return nanoglState.color_material; + case GL_CULL_FACE: + return nanoglState.cull_face; + case GL_DEPTH_TEST: + return nanoglState.depth_test; + case GL_DITHER: + return nanoglState.dither; + case GL_FOG: + return nanoglState.fog; + case GL_LIGHT0: + return nanoglState.light0; + case GL_LIGHT1: + return nanoglState.light1; + case GL_LIGHT2: + return nanoglState.light2; + case GL_LIGHT3: + return nanoglState.light3; + case GL_LIGHT4: + return nanoglState.light4; + case GL_LIGHT5: + return nanoglState.light5; + case GL_LIGHT6: + return nanoglState.light6; + case GL_LIGHT7: + return nanoglState.light7; + case GL_LIGHTING: + return nanoglState.lighting; + case GL_LINE_SMOOTH: + return nanoglState.line_smooth; + case GL_MULTISAMPLE: + return nanoglState.multisample; + case GL_NORMALIZE: + return nanoglState.normalize; + case GL_POLYGON_OFFSET_FILL: + return nanoglState.polygon_offset_fill; + case GL_RESCALE_NORMAL: + return nanoglState.rescale_normal; + case GL_SAMPLE_ALPHA_TO_COVERAGE: + return nanoglState.sample_alpha_to_coverage; + case GL_SAMPLE_ALPHA_TO_ONE: + return nanoglState.sample_alpha_to_one; + case GL_SAMPLE_COVERAGE: + return nanoglState.sample_coverage; + case GL_SCISSOR_TEST: + return nanoglState.scissor_test; + case GL_STENCIL_TEST: + return nanoglState.stencil_test; + case GL_TEXTURE_2D: + return activetmuState->texture_2d.value; + default: + return glIsEnabled(cap); + } +} + +void glPushAttrib(GLbitfield mask) +{ + FlushOnStateChange( ); + + if( (attribStackCount < 0) || (attribStackCount > MAX_ATTRIB_STACK) ) + { + return; + } + + attribStack[attribStackCount].mask = mask; + + if( mask & GL_ENABLE_BIT ) + { + for(int i = 0; i < STACK_ATTRIB_ENABLE_BIT_LEN; i++) + { + attribStack[attribStackCount].enable[i] = glIsEnabled(stackAttribEnableBit[i]); + } + } + + if( mask & GL_COLOR_BUFFER_BIT ) + { + // TODO + } + + if( mask & GL_CURRENT_BIT ) + { + // TODO + } + + attribStackCount += 1; +} + +void glPopAttrib() +{ + FlushOnStateChange( ); + + attribStackCount -= 1; + if((attribStackCount < 0) || (attribStackCount > MAX_ATTRIB_STACK)) + { + attribStackCount += 1; + return; + } + + GLbitfield mask = attribStack[attribStackCount].mask; + + if( mask & GL_ENABLE_BIT ) + { + for(int i = 0; i < STACK_ATTRIB_ENABLE_BIT_LEN; i++) + { + if( attribStack[attribStackCount].enable[i] ) + { + glEnable(stackAttribEnableBit[i]); + } + else + { + glDisable(stackAttribEnableBit[i]); + } + } + } + + if( mask & GL_COLOR_BUFFER_BIT ) + { + // TODO + } + + if( mask & GL_CURRENT_BIT ) + { + // TODO + } +}