GLE2RICE: Some fixes from muppen64plus-ae
authorptitSeb <sebastien.chev@gmail.com>
Fri, 1 Nov 2013 19:49:15 +0000 (20:49 +0100)
committerptitSeb <sebastien.chev@gmail.com>
Fri, 1 Nov 2013 19:49:15 +0000 (20:49 +0100)
source/gles2rice/src/OGLES2FragmentShaders.cpp [changed mode: 0644->0755]
source/gles2rice/src/OGLES2FragmentShaders.h [changed mode: 0644->0755]
source/gles2rice/src/OGLGraphicsContext.cpp [changed mode: 0644->0755]
source/gles2rice/src/OGLRender.cpp
source/gles2rice/src/OGLRenderExt.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 4c5f06e..29b8e97
@@ -24,7 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #define ALPHA_TEST "    if(gl_FragColor.a < AlphaRef) discard;                        \n"
 //#define ALPHA_TEST
-
+#define ENABLE  true
+#define DISABLE  false
 
 GLuint vertexProgram = 9999;
 const char *vertexShader =
@@ -35,8 +36,6 @@ const char *vertexShader =
 "attribute lowp vec2    aTexCoord1;                         \n"\
 "attribute lowp vec2    aAtlasTransform;                    \n"\
 "                                                           \n"\
-"uniform lowp vec2 FogMinMax;                               \n"\
-"                                                           \n"\
 "varying lowp float vFactor;                                \n"\
 "varying lowp vec4  vShadeColor;                            \n"\
 "varying mediump vec2 vTexCoord0;                           \n"\
@@ -49,7 +48,6 @@ const char *vertexShader =
 "vShadeColor = aColor;                                      \n"\
 "vTexCoord0 = aTexCoord0;                                   \n"\
 "vTexCoord1 = aTexCoord1;                                   \n"\
-"vFog = clamp((FogMinMax[1] - (gl_Position.z/aPosition.w))/(FogMinMax[1]-FogMinMax[0]),0.0,1.0);                                   \n"\
 "                                                           \n"\
 "}                                                          \n"\
 "                                                           \n";
@@ -71,12 +69,12 @@ const char *fragmentHeader =
 "uniform vec4 PrimFrac;                                     \n"\
 "uniform float AlphaRef;                                    \n"\
 "uniform vec4 FogColor;                                     \n"\
+"uniform vec2  FogMinMax;                                   \n"\
 "                                                           \n"\
 "varying lowp float vFactor;                                \n"\
 "varying lowp vec4  vShadeColor;                            \n"\
 "varying mediump vec2  vTexCoord0;                          \n"\
 "varying lowp vec2  vTexCoord1;                             \n"\
-"varying lowp float vFog;                                   \n"\
 "                                                           \n"\
 "void main()                                                \n"\
 "{                                                          \n"\
@@ -93,19 +91,19 @@ const char *fragmentHeader =
 const char *fragmentFooter =
 "                                                           \n"\
 "#ifdef FOG                                                 \n"\
-"gl_FragColor.rgb = mix(FogColor.rgb,comb.rgb,vFog * step(0.5,1.0-FogColor.a));        \n"\
-"gl_FragColor.a = comb.a;                                   \n"\
-"#else                                                      \n"\
-"gl_FragColor = comb;                                       \n"\
-"#endif                                                     \n"\
-"                                                           \n"\
-"#ifdef ALPHA_TEST                                          \n"\
-ALPHA_TEST
-"#endif                                                     \n"\
-"                                                           \n"\
-"                                                           \n"\
-"                                                           \n"\
-"                                                           \n"\
+"   float z = gl_FragCoord.z * 2.0 - 1.0;                                   \n"\
+"   float FogFactor = (FogMinMax[1] - z) / (FogMinMax[1] - FogMinMax[0]);   \n"\
+"   FogFactor = clamp(FogFactor, 0.0, 1.0);                                 \n"\
+"                                                                           \n"\
+"   gl_FragColor.rgb = mix(FogColor.rgb, comb.rgb, FogFactor );             \n"\
+"   gl_FragColor.a = comb.a;                                                \n"\
+"#else                                                                      \n"\
+"   gl_FragColor = comb;                                                    \n"\
+"#endif                                                                     \n"\
+"                                                                           \n"\
+"#ifdef ALPHA_TEST                                                          \n"\
+   ALPHA_TEST                                                                  
+"#endif                                                                     \n"\
 "}                                                          \n";
 
 //Fragment shader for InitCycleCopy
@@ -196,6 +194,10 @@ COGL_FragmentProgramCombiner::COGL_FragmentProgramCombiner(CRender *pRender)
     m_pDecodedMux = new DecodedMuxForPixelShader;
     m_bFragmentProgramIsSupported = true;
     m_AlphaRef = 0.0f;
+    bAlphaTestState = DISABLE;
+    bAlphaTestPreviousState = DISABLE;
+    bFogState = DISABLE;
+    bFogPreviousState = DISABLE;
 
     //Create shaders for fill and copy
     GLint success;
@@ -489,8 +491,6 @@ void COGL_FragmentProgramCombiner::GenerateProgramStr()
         strcat(oglNewFP, "#define NEED_TEX0\n");
     if (bNeedT1)
         strcat(oglNewFP, "#define NEED_TEX1\n");
-    if(gRDP.bFogEnableInBlender && gRSP.bFogEnabled && options.fogMethod > 0)
-        strcat(oglNewFP,"#define FOG");
     strcat(oglNewFP, fragmentHeader);
     strcat(oglNewFP, newFPBody);
     strcat(oglNewFP, fragmentFooter);
@@ -519,103 +519,109 @@ int COGL_FragmentProgramCombiner::ParseDecodedMux()
     }
 
 
-    //Create 2 shaders, with and without alphatest
+    //Create 4 shaders, with and without alphatest + with and without fog
     GenerateProgramStr();
 
     for(int alphaTest = 0;alphaTest < 2;alphaTest++)
     {
-        res.fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
-
-        char* tmpShader = (char*)malloc(sizeof(char) * 4096);
-        strcpy(tmpShader,"#version " GLSL_VERSION "\n");
-
-        if(alphaTest == 1)
-        {
-            strcat(tmpShader,"#define ALPHA_TEST\n");
-        }
-
-        res.alphaTest = alphaTest == 1;
-        strcat(tmpShader,oglNewFP);
-
-        glShaderSource(res.fragmentShaderID, 1,(const char**) &tmpShader,NULL);
-        free(tmpShader);
-
-
-        OPENGL_CHECK_ERRORS;
-        glCompileShader(res.fragmentShaderID);
-
-        glGetShaderiv(res.fragmentShaderID, GL_COMPILE_STATUS, &success);
-        if (!success)
-        {
-            char Log[1024];
-            GLint nLength;
-            glGetShaderInfoLog(res.fragmentShaderID, 1024, &nLength, Log);
-            printf("Error compiling shader!\n %s",oglNewFP);
-            printf("%s", Log);
-        }
-
-        res.programID = glCreateProgram();
-        glAttachShader(res.programID,res.vertexShaderID);
-        glAttachShader(res.programID,res.fragmentShaderID);
-
-        //Bind Attributes
-        glBindAttribLocation(res.programID,VS_COLOR,"aColor");
-        OPENGL_CHECK_ERRORS;
-        glBindAttribLocation(res.programID,VS_TEXCOORD0,"aTexCoord0");
-        OPENGL_CHECK_ERRORS;
-        glBindAttribLocation(res.programID,VS_TEXCOORD1,"aTexCoord1");
-        OPENGL_CHECK_ERRORS;
-        glBindAttribLocation(res.programID,VS_POSITION,"aPosition");
-        OPENGL_CHECK_ERRORS;
-
-        glLinkProgram(res.programID);
-        OPENGL_CHECK_ERRORS;
-
-        glGetProgramiv(res.programID, GL_LINK_STATUS, &success);
-        if (!success)
-        {
-            char Log[1024];
-            GLint nLength;
-            glGetShaderInfoLog(res.fragmentShaderID, 1024, &nLength, Log);
-            printf("Error linking program!\n");
-            printf("%s\n",Log);
-        }
-
-        glUseProgram(res.programID);
-        OPENGL_CHECK_ERRORS;
-
-        //Bind texture samplers
-        GLint tex0 = glGetUniformLocation(res.programID,"uTex0");
-        GLint tex1 = glGetUniformLocation(res.programID,"uTex1");
-
-        if(tex0 != -1)
-            glUniform1i(tex0,0);
-        if(tex1 != -1)
-            glUniform1i(tex1,1);
-
-        //Bind Uniforms
-        res.PrimColorLocation = glGetUniformLocation(res.programID,"PrimColor");
-        OPENGL_CHECK_ERRORS;
-        res.EnvColorLocation = glGetUniformLocation(res.programID,"EnvColor");
-        OPENGL_CHECK_ERRORS;
-        res.PrimFracLocation = glGetUniformLocation(res.programID,"PrimFrac");
-        OPENGL_CHECK_ERRORS;
-        res.EnvFracLocation = glGetUniformLocation(res.programID,"EnvFrac");
-        OPENGL_CHECK_ERRORS;
-        res.AlphaRefLocation = glGetUniformLocation(res.programID,"AlphaRef");
-        OPENGL_CHECK_ERRORS;
-        res.FogColorLocation = glGetUniformLocation(res.programID,"FogColor");
-        OPENGL_CHECK_ERRORS;
-        res.FogMinMaxLocation = glGetUniformLocation(res.programID,"FogMinMax");
-        OPENGL_CHECK_ERRORS;
-
-        res.dwMux0 = m_pDecodedMux->m_dwMux0;
-        res.dwMux1 = m_pDecodedMux->m_dwMux1;
-        res.fogIsUsed = gRDP.bFogEnableInBlender && gRSP.bFogEnabled;
-
-        m_vCompiledShaders.push_back(res);
+               for(int fog = 0;fog < 2;fog++) {
+                       res.fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
+
+                       char* tmpShader = (char*)malloc(sizeof(char) * 4096);
+                       strcpy(tmpShader,"#version " GLSL_VERSION "\n");
+
+                       if(alphaTest == 1)
+                       {
+                               strcat(tmpShader,"#define ALPHA_TEST\n");
+                       }
+                       if(fog == 1)
+                       {
+                               strcat(tmpShader,"#define FOG\n");
+                       }
+
+                       res.fogIsUsed = fog == 1;
+                       res.alphaTest = alphaTest == 1;
+                       strcat(tmpShader,oglNewFP);
+
+                       glShaderSource(res.fragmentShaderID, 1,(const char**) &tmpShader,NULL);
+                       free(tmpShader);
+
+
+                       OPENGL_CHECK_ERRORS;
+                       glCompileShader(res.fragmentShaderID);
+
+                       glGetShaderiv(res.fragmentShaderID, GL_COMPILE_STATUS, &success);
+                       if (!success)
+                       {
+                               char Log[1024];
+                               GLint nLength;
+                               glGetShaderInfoLog(res.fragmentShaderID, 1024, &nLength, Log);
+                               printf("Error compiling shader!\n %s",oglNewFP);
+                               printf("%s", Log);
+                       }
+
+                       res.programID = glCreateProgram();
+                       glAttachShader(res.programID,res.vertexShaderID);
+                       glAttachShader(res.programID,res.fragmentShaderID);
+
+                       //Bind Attributes
+                       glBindAttribLocation(res.programID,VS_COLOR,"aColor");
+                       OPENGL_CHECK_ERRORS;
+                       glBindAttribLocation(res.programID,VS_TEXCOORD0,"aTexCoord0");
+                       OPENGL_CHECK_ERRORS;
+                       glBindAttribLocation(res.programID,VS_TEXCOORD1,"aTexCoord1");
+                       OPENGL_CHECK_ERRORS;
+                       glBindAttribLocation(res.programID,VS_POSITION,"aPosition");
+                       OPENGL_CHECK_ERRORS;
+
+                       glLinkProgram(res.programID);
+                       OPENGL_CHECK_ERRORS;
+
+                       glGetProgramiv(res.programID, GL_LINK_STATUS, &success);
+                       if (!success)
+                       {
+                               char Log[1024];
+                               GLint nLength;
+                               glGetShaderInfoLog(res.fragmentShaderID, 1024, &nLength, Log);
+                               printf("Error linking program!\n");
+                               printf("%s\n",Log);
+                       }
+
+                       glUseProgram(res.programID);
+                       OPENGL_CHECK_ERRORS;
+
+                       //Bind texture samplers
+                       GLint tex0 = glGetUniformLocation(res.programID,"uTex0");
+                       GLint tex1 = glGetUniformLocation(res.programID,"uTex1");
+
+                       if(tex0 != -1)
+                               glUniform1i(tex0,0);
+                       if(tex1 != -1)
+                               glUniform1i(tex1,1);
+
+                       //Bind Uniforms
+                       res.PrimColorLocation = glGetUniformLocation(res.programID,"PrimColor");
+                       OPENGL_CHECK_ERRORS;
+                       res.EnvColorLocation = glGetUniformLocation(res.programID,"EnvColor");
+                       OPENGL_CHECK_ERRORS;
+                       res.PrimFracLocation = glGetUniformLocation(res.programID,"PrimFrac");
+                       OPENGL_CHECK_ERRORS;
+                       res.EnvFracLocation = glGetUniformLocation(res.programID,"EnvFrac");
+                       OPENGL_CHECK_ERRORS;
+                       res.AlphaRefLocation = glGetUniformLocation(res.programID,"AlphaRef");
+                       OPENGL_CHECK_ERRORS;
+                       res.FogColorLocation = glGetUniformLocation(res.programID,"FogColor");
+                       OPENGL_CHECK_ERRORS;
+                       res.FogMinMaxLocation = glGetUniformLocation(res.programID,"FogMinMax");
+                       OPENGL_CHECK_ERRORS;
+
+                       res.dwMux0 = m_pDecodedMux->m_dwMux0;
+                       res.dwMux1 = m_pDecodedMux->m_dwMux1;
+
+                       m_vCompiledShaders.push_back(res);
+               }
     }
-    m_lastIndex = m_vCompiledShaders.size()-2;
+    m_lastIndex = m_vCompiledShaders.size()-4;
 
     return m_lastIndex;
 }
@@ -682,38 +688,23 @@ void COGL_FragmentProgramCombiner::GenerateCombinerSettingConstants(int index)
         OPENGL_CHECK_ERRORS;
     }
 
-    //if(prog.FogColorLocation != -1 && prog.FogMinMaxLocation != -1)
-    //{
-    //    //Pass fog colour and distance, use 0 alpha if fog disabled
-    //    glUniform4f(prog.FogColorLocation, gRDP.fvFogColor[0],gRDP.fvFogColor[1],gRDP.fvFogColor[2],
-    //        gRSP.bFogEnabled ? gRDP.fvFogColor[0] : 0.0f);
-    //    glUniform2f(prog.FogMinMaxLocation,gRSPfFogMin,gRSPfFogMax);
-    //}
-
-    if(prog.AlphaRefLocation != -1)
-        glUniform1f(prog.AlphaRefLocation,m_AlphaRef);
-    OPENGL_CHECK_ERRORS;
-}
-
-void COGL_FragmentProgramCombiner::UpdateFog(bool bEnable)
-{
-    if(m_lastIndex < 0 || m_lastIndex >= m_vCompiledShaders.size())
-        return;
-    OGLShaderCombinerSaveType prog = m_vCompiledShaders[m_lastIndex];
-
-    //if(bEnable)
-    //    DebugMessage(M64MSG_INFO,"Fog Color %x Min %f Max %f",gRDP.fogColor,gRSPfFogMin,gRSPfFogMax);
-
-    if(prog.FogColorLocation != -1 && prog.FogMinMaxLocation != -1)
+       if(prog.FogColorLocation != -1)
     {
-        //Pass fog colour and distance, use 0 alpha if fog disabled
-        glUniform4f(prog.FogColorLocation, gRDP.fvFogColor[0],gRDP.fvFogColor[1],gRDP.fvFogColor[2],
-            bEnable ? gRDP.fvFogColor[0] : 0.0f);
-        //glUniform4f(prog.FogColorLocation, 1.0f,0.3f,0.3f,1.0f);
-        //OPENGL_CHECK_ERRORS;
+        glUniform4f(prog.FogColorLocation, gRDP.fvFogColor[0],gRDP.fvFogColor[1],gRDP.fvFogColor[2], gRDP.fvFogColor[3]);
+        OPENGL_CHECK_ERRORS;
+    }
+       
+       if(prog.FogMinMaxLocation != -1)        
+       {
         glUniform2f(prog.FogMinMaxLocation,gRSPfFogMin,gRSPfFogMax);
         OPENGL_CHECK_ERRORS;
     }
+       
+    if(prog.AlphaRefLocation != -1)
+       {
+        glUniform1f(prog.AlphaRefLocation,m_AlphaRef);
+               OPENGL_CHECK_ERRORS;
+       }
 }
 
 int COGL_FragmentProgramCombiner::FindCompiledMux()
@@ -730,8 +721,8 @@ int COGL_FragmentProgramCombiner::FindCompiledMux()
     {
         if( m_vCompiledShaders[i].dwMux0 == m_pDecodedMux->m_dwMux0 
             && m_vCompiledShaders[i].dwMux1 == m_pDecodedMux->m_dwMux1 
-            && m_vCompiledShaders[i].fogIsUsed == (gRDP.bFogEnableInBlender && gRSP.bFogEnabled)
-            && m_vCompiledShaders[i].alphaTest == m_AlphaRef > 0.0f)
+            && m_vCompiledShaders[i].fogIsUsed == bFogState
+            && m_vCompiledShaders[i].alphaTest == bAlphaTestState)
         {
             return (int)i;
         }
@@ -763,7 +754,8 @@ void COGL_FragmentProgramCombiner::InitCombinerCycle12(void)
 
     bool combinerIsChanged = false;
 
-    if( m_pDecodedMux->m_dwMux0 != m_dwLastMux0 || m_pDecodedMux->m_dwMux1 != m_dwLastMux1 || m_lastIndex < 0 )
+    if( m_pDecodedMux->m_dwMux0 != m_dwLastMux0 || m_pDecodedMux->m_dwMux1 != m_dwLastMux1 
+         || bAlphaTestState != bAlphaTestPreviousState || bFogState != bFogPreviousState || m_lastIndex < 0 )
     {
         combinerIsChanged = true;
         m_lastIndex = FindCompiledMux();
@@ -774,7 +766,10 @@ void COGL_FragmentProgramCombiner::InitCombinerCycle12(void)
 
         m_dwLastMux0 = m_pDecodedMux->m_dwMux0;
         m_dwLastMux1 = m_pDecodedMux->m_dwMux1;
-    }
+        bAlphaTestPreviousState = bAlphaTestState;
+        bFogPreviousState = bFogState;
+        m_AlphaRef = (float)(m_pOGLRender->m_dwAlpha)/255.0f;    
+       }
 
 
     GenerateCombinerSettingConstants(m_lastIndex);
old mode 100644 (file)
new mode 100755 (executable)
index 9e77eaa..70b97cf
@@ -52,8 +52,14 @@ class COGL_FragmentProgramCombiner : public COGLColorCombiner4
 {
 public:
     bool Initialize(void);
-    float m_AlphaRef;
-    void UpdateFog(bool bEnable);
+    void SetFogState(bool bEnable)
+    {
+        bFogState = bEnable;
+    }
+    void SetAlphaTestState(bool bEnable)
+    {
+        bAlphaTestState = bEnable;
+    }
 
 protected:
     friend class OGLDeviceBuilder;
@@ -75,6 +81,11 @@ private:
     int FindCompiledMux();
     virtual void GenerateCombinerSetting(int index);
     virtual void GenerateCombinerSettingConstants(int index);
+    float m_AlphaRef;
+    bool bAlphaTestState;
+    bool bAlphaTestPreviousState;
+    bool bFogState;
+    bool bFogPreviousState;
 
 #ifdef DEBUGGER
     void DisplaySimpleMuxString(void);
old mode 100644 (file)
new mode 100755 (executable)
index 3be9fc0..6c1f4e8
@@ -287,13 +287,14 @@ void COGLGraphicsContext::InitState(void)
     glDepthRange(-1, 1);
 
 #elif SDL_VIDEO_OPENGL_ES2
-    glDepthRangef(0.0f, 1.0f);
+    glDepthRangef(-1.0f, 1.0f);
 #endif
     OPENGL_CHECK_ERRORS;
 }
 
 void COGLGraphicsContext::InitOGLExtension(void)
 {
+#if SDL_VIDEO_OPENGL
     // important extension features, it is very bad not to have these feature
     m_bSupportMultiTexture = IsExtensionSupported(OSAL_GL_ARB_MULTITEXTURE);
     m_bSupportTextureEnvCombine = IsExtensionSupported("GL_EXT_texture_env_combine");
@@ -307,7 +308,11 @@ void COGLGraphicsContext::InitOGLExtension(void)
     m_bSupportRescaleNormal = IsExtensionSupported("GL_EXT_rescale_normal");
     m_bSupportLODBias = IsExtensionSupported("GL_EXT_texture_lod_bias");
     m_bSupportAnisotropicFiltering = IsExtensionSupported("GL_EXT_texture_filter_anisotropic");
-
+#else
+    m_bSupportMultiTexture = true;
+    m_bSupportFogCoord = false;
+    m_bSupportAnisotropicFiltering = true;
+#endif
     // Compute maxAnisotropicFiltering
     m_maxAnisotropicFiltering = 0;
 
@@ -331,7 +336,8 @@ void COGLGraphicsContext::InitOGLExtension(void)
         if((uint32) m_maxAnisotropicFiltering > options.anisotropicFiltering)
         m_maxAnisotropicFiltering = options.anisotropicFiltering;
     }
-
+       
+#if SDL_VIDEO_OPENGL
     // Nvidia only extension features (optional)
     m_bSupportNVRegisterCombiner = IsExtensionSupported("GL_NV_register_combiners");
     m_bSupportTextureMirrorRepeat = IsExtensionSupported("GL_IBM_texture_mirrored_repeat") || IsExtensionSupported("ARB_texture_mirrored_repeat");
@@ -340,7 +346,9 @@ void COGLGraphicsContext::InitOGLExtension(void)
     m_bSupportBlendColor = IsExtensionSupported("GL_EXT_blend_color");
     m_bSupportBlendSubtract = IsExtensionSupported("GL_EXT_blend_subtract");
     m_bSupportNVTextureEnvCombine4 = IsExtensionSupported("GL_NV_texture_env_combine4");
-
+#else
+    m_supportTextureMirror = true;
+#endif
 }
 
 bool COGLGraphicsContext::IsExtensionSupported(const char* pExtName)
index ee99b97..5f25f16 100755 (executable)
@@ -45,10 +45,6 @@ UVFlagMap OGLXUVFlagMaps[] =
     {TEXTURE_UV_FLAG_CLAMP, GL_CLAMP},
 };
 
-#if SDL_VIDEO_OPENGL_ES2
-  static GLuint disabledTextureID;
-#endif
-
 //===================================================================
 OGLRender::OGLRender()
 {
@@ -62,28 +58,8 @@ OGLRender::OGLRender()
         m_texUnitEnabled[i]=FALSE;
     }
 
-#if SDL_VIDEO_OPENGL
     m_bEnableMultiTexture = false;
 
-#elif SDL_VIDEO_OPENGL_ES2
-    m_bEnableMultiTexture = true;
-
-    //Create a texture as replacement for glEnable/Disable(GL_TEXTURE_2D)
-    unsigned int white[8*8];
-       for (int i=0; i<8*8; i++) {
-               //white[i].r = white[i].g = white[i].b = 0;
-               //white[i].a = 0;
-               white[i] = 0;
-       }
-    glGenTextures(1,&disabledTextureID);
-    OPENGL_CHECK_ERRORS;
-    glBindTexture(GL_TEXTURE_2D, disabledTextureID);
-    OPENGL_CHECK_ERRORS;
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-    OPENGL_CHECK_ERRORS;
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, white);
-    OPENGL_CHECK_ERRORS;
-#endif
 }
 
 OGLRender::~OGLRender()
@@ -206,6 +182,25 @@ void OGLRender::Initialize(void)
     OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT;
     m_bSupportClampToEdge = true;
     OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
+
+    glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
+    OPENGL_CHECK_ERRORS;
+
+    if( m_bMultiTexture )
+    {
+        glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
+        OPENGL_CHECK_ERRORS;
+        glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u));
+        OPENGL_CHECK_ERRORS;
+    }
+    else
+    {
+        glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
+        OPENGL_CHECK_ERRORS;
+    }
+
+    glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
+    OPENGL_CHECK_ERRORS;
 #endif
 
 #ifdef PAULSCODE
@@ -617,6 +612,13 @@ bool OGLRender::RenderTexRect()
             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v
     };
 
+    GLfloat tex2[] = {
+            g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v,
+            g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
+            g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
+            g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v
+    };
+
     float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
     GLfloat vertices[] = {
@@ -629,6 +631,7 @@ bool OGLRender::RenderTexRect()
     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_TRUE, 0, &colour );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
+       glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, 0, &tex2);
     OPENGL_CHECK_ERRORS;
     glDrawArrays(GL_TRIANGLE_FAN,0,4);
     OPENGL_CHECK_ERRORS;
@@ -637,7 +640,7 @@ bool OGLRender::RenderTexRect()
     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
-
+    glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u));
 #endif
 
     if( cullface ) glEnable(GL_CULL_FACE);
@@ -690,6 +693,7 @@ bool OGLRender::RenderFillRect(uint32 dwColor, float depth)
     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
     glDisableVertexAttribArray(VS_TEXCOORD0);
+       glDisableVertexAttribArray(VS_TEXCOORD1);
     OPENGL_CHECK_ERRORS;
     glDrawArrays(GL_TRIANGLE_FAN,0,4);
     OPENGL_CHECK_ERRORS;
@@ -698,6 +702,7 @@ bool OGLRender::RenderFillRect(uint32 dwColor, float depth)
     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
     glEnableVertexAttribArray(VS_TEXCOORD0);
+       glEnableVertexAttribArray(VS_TEXCOORD1);
 
 #endif
 
@@ -871,6 +876,16 @@ void OGLRender::DrawSimple2DTexture(float x0, float y0, float x1, float y1, floa
             g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
     };
 
+    GLfloat tex2[] = {
+            g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
+            g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
+            g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
+
+            g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
+            g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
+            g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v,
+    };
+       
      float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
     GLfloat vertices[] = {
@@ -886,6 +901,7 @@ void OGLRender::DrawSimple2DTexture(float x0, float y0, float x1, float y1, floa
     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
+       glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, 0, &tex2);
     OPENGL_CHECK_ERRORS;
     glDrawArrays(GL_TRIANGLES,0,6);
     OPENGL_CHECK_ERRORS;
@@ -894,6 +910,7 @@ void OGLRender::DrawSimple2DTexture(float x0, float y0, float x1, float y1, floa
     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
+       glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u));
 
 #endif
 
@@ -946,6 +963,7 @@ void OGLRender::DrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColo
     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
     glDisableVertexAttribArray(VS_TEXCOORD0);
+       glDisableVertexAttribArray(VS_TEXCOORD1);
     OPENGL_CHECK_ERRORS;
     glDrawArrays(GL_TRIANGLE_FAN,0,4);
     OPENGL_CHECK_ERRORS;
@@ -954,6 +972,7 @@ void OGLRender::DrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColo
     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
     glEnableVertexAttribArray(VS_TEXCOORD0);
+       glEnableVertexAttribArray(VS_TEXCOORD1);
 
 #endif
 
@@ -1026,24 +1045,19 @@ void OGLRender::SetAlphaTestEnable(BOOL bAlphaTestEnable)
 #ifdef DEBUGGER
     if( bAlphaTestEnable && debuggerEnableAlphaTest )
 #else
-    if( bAlphaTestEnable )
-#endif
+
 #if SDL_VIDEO_OPENGL
+    if( bAlphaTestEnable )
         glEnable(GL_ALPHA_TEST);
     else
         glDisable(GL_ALPHA_TEST);
+    OPENGL_CHECK_ERRORS;
 #elif SDL_VIDEO_OPENGL_ES2
-    {
-        COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
-        frag->m_AlphaRef = m_dwAlpha / 255.0f;
-    }
-    else
-    {
-        COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
-        frag->m_AlphaRef = 0.0f;
-    }
+    COGL_FragmentProgramCombiner* frag = (COGL_FragmentProgramCombiner*)m_pColorCombiner;
+    frag->SetAlphaTestState(bAlphaTestEnable);
+#endif
+
 #endif
-    OPENGL_CHECK_ERRORS;
 }
 
 void OGLRender::BindTexture(GLuint texture, int unitno)
@@ -1079,27 +1093,11 @@ void OGLRender::EnableTexUnit(int unitno, BOOL flag)
     if( m_texUnitEnabled[0] != flag )
     {
         m_texUnitEnabled[0] = flag;
-#if SDL_VIDEO_OPENGL
+
         if( flag == TRUE )
             glEnable(GL_TEXTURE_2D);
         else
             glDisable(GL_TEXTURE_2D);
-#elif SDL_VIDEO_OPENGL_ES2
-        if(flag)
-        {
-            pglActiveTexture(GL_TEXTURE0_ARB + unitno);
-            OPENGL_CHECK_ERRORS;
-            glBindTexture(GL_TEXTURE_2D,m_curBoundTex[unitno]);
-        }
-        else
-        {
-            pglActiveTexture(GL_TEXTURE0_ARB + unitno);
-            OPENGL_CHECK_ERRORS;
-            glEnable(GL_BLEND); //Need blend for transparent disabled texture
-            glBindTexture(GL_TEXTURE_2D,disabledTextureID);
-        }
-#endif
-        OPENGL_CHECK_ERRORS;
     }
 }
 
@@ -1177,9 +1175,6 @@ void OGLRender::SetFogMinMax(float fMin, float fMax)
     OPENGL_CHECK_ERRORS;
     glFogf(GL_FOG_END, gRSPfFogMax); // Fog End Depth
     OPENGL_CHECK_ERRORS;
-#elif SDL_VIDEO_OPENGL_ES2
-    ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
-    OPENGL_CHECK_ERRORS;
 #endif
 }
 
@@ -1192,7 +1187,7 @@ void OGLRender::TurnFogOnOff(bool flag)
         glDisable(GL_FOG);
     OPENGL_CHECK_ERRORS;
 #elif SDL_VIDEO_OPENGL_ES2
-    ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(flag);
+    ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->SetFogState(flag);
     OPENGL_CHECK_ERRORS;
 #endif
 }
@@ -1228,7 +1223,7 @@ void OGLRender::SetFogEnable(bool bEnable)
         OPENGL_CHECK_ERRORS;
     }
 #elif SDL_VIDEO_OPENGL_ES2
-    ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->UpdateFog(gRSP.bFogEnabled);
+    ((COGL_FragmentProgramCombiner*)m_pColorCombiner)->SetFogState(gRSP.bFogEnabled);
     OPENGL_CHECK_ERRORS;
 #endif
 }
old mode 100644 (file)
new mode 100755 (executable)
index e632208..fe6d799
@@ -84,7 +84,17 @@ void OGLRender::DrawSpriteR_Render()    // With Rotation
             g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
     };
 
-     float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
+    GLfloat tex2[] = {
+            g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
+            g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
+            g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
+
+            g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
+            g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
+            g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v,
+    };
+
+ float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
 
     GLfloat vertices[] = {
             -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
@@ -100,6 +110,7 @@ void OGLRender::DrawSpriteR_Render()    // With Rotation
     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
+       glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, 0, &tex2);
     //OPENGL_CHECK_ERRORS;
     glDrawArrays(GL_TRIANGLES,0,6);
     //OPENGL_CHECK_ERRORS;
@@ -108,6 +119,7 @@ void OGLRender::DrawSpriteR_Render()    // With Rotation
     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
+       glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u));
 
 #endif