ecere/gfx: Moved CubeMap to Bitmap.ec
[sdk] / ecere / src / gfx / drivers / gl3 / defaultShader.ec
index ca968e1..1f52d97 100644 (file)
@@ -4,34 +4,6 @@ import "shaders"
 
 namespace gfx::drivers;
 
-public class CubeMap : Bitmap
-{
-public:
-   void Load(DisplaySystem displaySystem, const String * names, const String extension, bool oldStyle)
-   {
-      int i;
-      for(i = 0; i < 6; i++)
-      {
-         char location[MAX_LOCATION];
-         Bitmap face = i > 0 ? { } : this;
-         strcpy(location, names[i]);
-         if(extension)
-            ChangeExtension(location, extension, location);
-         if(face.Load(location, null, null))
-         {
-            face.driverData = driverData;
-            displaySystem.driver.MakeDDBitmap(displaySystem, face, true, (i + 1) | (oldStyle << 3));
-         }
-         if(i > 0)
-         {
-            face.driverData = 0;
-            delete face;
-         }
-      }
-   }
-};
-
-
 // **********   Default Shader   **********
 public enum LightMode { off, dir, pos, posAtt, posSpot, posSpotAtt };
 public enum SwizzleMode { off, alpha, red };
@@ -190,9 +162,9 @@ public:
    float modelView[16];
    float projection[16];
    float matTexture[16];
-   float cubemap_matrix[16];
+   float cubemap_matrix[9];
 
-   float normalsMatrix[16];
+   float normalsMatrix[9];
    float nearPlane;
    float globalAmbient[3];
 
@@ -263,10 +235,14 @@ public:
       int i;
 
 #ifdef _DEBUG
-       PrintLn("Compiling shader for state: ", state);
+       //PrintLn("Compiling shader for state: ", state);
 #endif
 
+#if defined(__EMSCRIPTEN__)
       defs.concatf("#version 100\n");
+#else
+      defs.concatf("#version 110\n");
+#endif
       defs.concatf("\n#define NUM_LIGHTS %d",               8);
       defs.concatf("\n#define MODELVIEW %d",                state.modelView          ? 1 : 0);
       defs.concatf("\n#define PER_VERTEX_COLOR %d",         state.perVertexColor     ? 1 : 0);
@@ -300,7 +276,7 @@ public:
       defs.concatf("\n\n#line 0\n");
 
 #ifdef _DEBUG
-        printf((String)defs._string);
+      //puts((String)defs._string);
 #endif
       return defs;
    }
@@ -378,7 +354,7 @@ public:
          glUniform1f(shader.uNearPlane, nearPlane);
          glUniform3fv(shader.uGlobalAmbient, 1, globalAmbient);
 
-         glUniformMatrix4fv(shader.uNormalsMatrix, 1, GL_FALSE, normalsMatrix);
+         glUniformMatrix3fv(shader.uNormalsMatrix, 1, GL_FALSE, normalsMatrix);
 
          if(state.normalsMapping)
             glUniform1i(shader.uBumpTex, 1);
@@ -392,7 +368,7 @@ public:
       if(state.environmentMapping)
       {
          glUniform1i(shader.uEnvTex, 3);
-         glUniformMatrix4fv(shader.uCubeMapMatrix, 1, GL_FALSE, cubemap_matrix);
+         glUniformMatrix3fv(shader.uCubeMapMatrix, 1, GL_FALSE, cubemap_matrix);
          if(state.reflection)
             glUniform1f(shader.uMatReflectivity, reflectivity);
          if(state.refraction)
@@ -417,14 +393,13 @@ public:
    void setCamera(Camera camera)
    {
       double * c = camera.inverseTranspose.array;
-      float m[16] =
+      float m[9] =
       {
-         (float) c[0], (float) c[1], (float)-c[2], 0,
-         (float)-c[4], (float) c[5], (float) c[6], 0,
-         (float)-c[8], (float) c[9], (float) c[10], 0,
-         0, 0, 0, 1
+         (float) c[0], (float) c[1], (float)-c[2],
+         (float)-c[4], (float) c[5], (float) c[6],
+         (float)-c[8], (float) c[9], (float) c[10]
       };
-      memcpy(cubemap_matrix, m, 16 * sizeof(float));
+      memcpy(cubemap_matrix, m, 9 * sizeof(float));
       uniformsModified = true;
    }
 
@@ -459,14 +434,13 @@ public:
          t.Transpose(inv);
          inv.Inverse(t);
          {
-            float m[16] =
+            float m[9] =
             {
-               (float)i[0],(float)i[1],(float)i[2],(float)i[3],
-               (float)i[4],(float)i[5],(float)i[6],(float)i[7],
-               (float)i[8],(float)i[9],(float)i[10],(float)i[11],
-               (float)i[12],(float)i[13],(float)i[14],(float)i[15]
+               (float)i[0],(float)i[1],(float)i[2],
+               (float)i[4],(float)i[5],(float)i[6],
+               (float)i[8],(float)i[9],(float)i[10]
             };
-            memcpy(normalsMatrix, m, 16 * sizeof(float));
+            memcpy(normalsMatrix, m, 9 * sizeof(float));
          }
 
          uniformsModified = true;
@@ -627,6 +601,7 @@ public:
          ((DefaultShaderBits)state).twoSided = material.flags.doubleSided && !material.flags.singleSideLight;
          ((DefaultShaderBits)state).lightBits = material.flags.noLighting ? 0 : lightBits;
          ((DefaultShaderBits)state).lighting = (!material.flags.noLighting && lightBits) ? true : false;
+         color[0] = 1, color[1] = 1, color[2] = 1, color[3] = material.opacity;
          diffuse[0]  = material.diffuse.r,  diffuse[1]  = material.diffuse.g,  diffuse[2]  = material.diffuse.b, diffuse[3] = material.opacity;
          ambient[0]  = material.ambient.r,  ambient[1]  = material.ambient.g,  ambient[2]  = material.ambient.b;
          specular[0] = material.specular.r, specular[1] = material.specular.g, specular[2] = material.specular.b;