DEADSOFTWARE

Remove stupid gles bug hacks
authormittorn <mittorn@sibmail.com>
Tue, 8 Aug 2017 06:07:20 +0000 (13:07 +0700)
committermittorn <mittorn@sibmail.com>
Tue, 8 Aug 2017 06:07:20 +0000 (13:07 +0700)
nanoWrap.cpp

index 3e88b0f8150d9c6a2b16dc5388ec49c16c0e525f..8749bfbf3a98a7e00858124d1cb075625638e46f 100644 (file)
@@ -67,7 +67,6 @@ struct nanoState
        GLboolean scissor_test;
        GLboolean stencil_test;
        GLboolean depthmask;
-       GLboolean stupidglesbug;
        GLclampf depth_range_near;
        GLclampf depth_range_far;
        GLenum depth_func;
@@ -114,7 +113,6 @@ static struct nanoState nanoglInitState =
         GL_FALSE,
         GL_FALSE,
         GL_TRUE,
-               GL_FALSE,
         0.0f,
         1.0f,
         GL_LESS,
@@ -1185,19 +1183,10 @@ 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 );
 }
 
@@ -1290,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( 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*/ )
@@ -1402,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,
@@ -1435,18 +1433,9 @@ void glColor3ubv( const GLubyte *v )
 void glColor4ubv( const GLubyte *v )
 {
        //*((unsigned int*)(&currentVertexAttrib.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 +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,
@@ -1573,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( );