ecere/gfx/OpenGL: Fixed remaining issues
authorJerome St-Louis <jerome@ecere.com>
Fri, 29 Jul 2016 09:26:01 +0000 (05:26 -0400)
committerJerome St-Louis <jerome@ecere.com>
Fri, 29 Jul 2016 09:36:44 +0000 (05:36 -0400)
- Projection matrix not being reset properly
- Texture states not being reset properly
- First frame with normal mapped not rendred properly due to first SetLight not preserving light direction
- Fixed direct matrix computation and related warning
- ecere.epj: Removed duplicate MinEmscripten entry caused by bad merge

ecere/ecere.epj
ecere/src/gfx/3D/models/Object3DSFormat.ec
ecere/src/gfx/Display.ec
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec

index 8d9c18b..219dc3c 100644 (file)
@@ -1224,12 +1224,6 @@ if distributed with the Ecere SDK Windows installer.
                                        "Options" : {
                                           "ExcludeFromBuild" : false
                                        }
-                                    },
-                                    {
-                                       "Name" : "MinEmscripten",
-                                       "Options" : {
-                                          "ExcludeFromBuild" : false
-                                       }
                                     }
                                  ]
                               },
index 5866f22..4e8b972 100644 (file)
@@ -1586,6 +1586,9 @@ static bool ReadEditChunks(FileInfo * info, void * data)
                material.baseMap.MakeMipMaps(info->displaySystem);
             if(material.bumpMap)
                material.bumpMap.MakeMipMaps(info->displaySystem);
+            if(material.specularMap)
+               material.specularMap.MakeMipMaps(info->displaySystem);
+
             // COPY_NITEM(mat, material);
             CopyBytes(((byte *)(mat)) + sizeof(class NamedItem), ((byte *)(material)) + sizeof(class NamedItem), sizeof(class Material) - sizeof(class NamedItem));
          }
index 7b0e991..f6a4a5f 100644 (file)
@@ -717,6 +717,10 @@ public:
    // --- Lights ---
    void SetLight(int id, Light light)
    {
+      if(!display3D)
+      {
+         display3D = Display3D { };
+      }
       displaySystem.driver.SetLight(this, id, light);
    }
 
@@ -960,7 +964,7 @@ public:
                      Matrix t, inv = camera.viewMatrix;
                      Vector3D ot { };
                      Vector3D cPos = camera.cPosition;
-                     Vector3D pos = camera.position;
+                     Vector3D pos;
                      bool positional = l[3] ? true : false;
 
                      inv.Scale(1.0/nearPlane, -1.0/nearPlane,-1.0/nearPlane);
index 7f76816..3af5390 100644 (file)
@@ -379,6 +379,7 @@ class OGLDisplay : struct
    bool depthWrite;
    int x, y;
    uint vao;
+   int maxTMU;
 
 #if defined(__WIN32__)
    HDC hdc;
@@ -525,26 +526,6 @@ static HGLRC winCreateContext(HDC hdc, int * contextVersion, bool * isCompatible
 }
 #endif
 
-#if ENABLE_GL_FFP
-static int maxTMU = 0;
-
-static void disableRemainingTMUs(int lastTMU)
-{
-   int t;
-   for(t = lastTMU; t < maxTMU; t++)
-   {
-      glActiveTexture(GL_TEXTURE0 + t);
-      glClientActiveTexture(GL_TEXTURE0 + t);
-      glDisable(GL_TEXTURE_2D);
-      glDisable(GL_TEXTURE_CUBE_MAP);
-      GLDisableClientState(TEXCOORDS);
-   }
-   glActiveTexture(GL_TEXTURE0);
-   glClientActiveTexture(GL_TEXTURE0);
-   maxTMU = lastTMU;
-}
-#endif
-
 class OpenGLDisplayDriver : DisplayDriver
 {
    class_property(name) = "OpenGL";
@@ -2813,6 +2794,24 @@ class OpenGLDisplayDriver : DisplayDriver
          }
       }
    }
+#if ENABLE_GL_FFP
+   void ::disableRemainingTMUs(Display display, int lastTMU)
+   {
+      OGLDisplay oglDisplay = display.driverData;
+      int t;
+      for(t = lastTMU; t < oglDisplay.maxTMU; t++)
+      {
+         glActiveTexture(GL_TEXTURE0 + t);
+         glClientActiveTexture(GL_TEXTURE0 + t);
+         glDisable(GL_TEXTURE_2D);
+         glDisable(GL_TEXTURE_CUBE_MAP);
+         GLDisableClientState(TEXCOORDS);
+      }
+      glActiveTexture(GL_TEXTURE0);
+      glClientActiveTexture(GL_TEXTURE0);
+      oglDisplay.maxTMU = lastTMU;
+   }
+#endif
 
 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
    void SetRenderState(Display display, RenderState state, uint value)
@@ -3181,15 +3180,18 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
 
          // *** Restore 2D MODELVIEW Matrix ***
+         GLMatrixMode(MatrixMode::modelView);
+         GLPopMatrix();
+
+         // *** Restore 2D TEXTURE Matrix ***
+         GLMatrixMode(MatrixMode::texture);
          GLPopMatrix();
 
          // *** Restore 2D PROJECTION Matrix ***
          GLMatrixMode(MatrixMode::projection);
          GLPopMatrix();
 
-         // *** Restore 2D TEXTURE Matrix ***
-         GLMatrixMode(MatrixMode::texture);
-         GLPopMatrix();
+         // NOTE: We expect the 2D projection matrix to be the active one for GetSurface to call glOrtho()
 
 #if ENABLE_GL_SHADERS
          if(glCaps_shaders)
@@ -3199,8 +3201,9 @@ class OpenGLDisplayDriver : DisplayDriver
 #if ENABLE_GL_FFP
          if(!glCaps_shaders)
          {
-            disableRemainingTMUs(1);
+            disableRemainingTMUs(display, 0);
             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
             glDisable(GL_TEXTURE_CUBE_MAP);
          #if _GLES
             glDisable(GL_TEXTURE_GEN_STR);
@@ -3593,21 +3596,13 @@ class OpenGLDisplayDriver : DisplayDriver
 
             GLMatrixMode(MatrixMode::texture);
             {
-               double * s = display.display3D.camera.inverseTranspose.array;
-               Quaternion q = display.display3D.camera.cOrientation;
-               Matrix mat;
-               Euler e = q;
-               //e.yaw *= -1;
-               q = e;
-               mat.RotationQuaternion(q);
-               mat.Scale(2,-2,-2);
-               s = mat.array;
-
+               double * s = display.display3D.camera.viewMatrix.array;
+               double k = 2.0;
                Matrix m
                { {
-                  s[0],s[1],s[2],0,
-                  s[4],s[5],s[6],0,
-                  s[8],s[9],s[10],0,
+                  k*s[0],-k*s[4],-k*s[8], 0,
+                  k*s[1],-k*s[5],-k*s[9], 0,
+                  k*s[2],-k*s[6],-k*s[10],0,
                   0,0,0,1
                } };
                GLLoadMatrixd(m.array);
@@ -3682,7 +3677,7 @@ class OpenGLDisplayDriver : DisplayDriver
 #if ENABLE_GL_FFP
       if(!glCaps_shaders)
       {
-         disableRemainingTMUs(tmu);
+         disableRemainingTMUs(display, tmu);
 
          if(mesh.flags.colors)
          {