0024345: TKOpenGl - GLSL compatibility issues on NV40 (GeForce 6xxx/7xxx)
[occt.git] / src / OpenGl / OpenGl_ShaderManager.cxx
index 4092769..9837f4a 100644 (file)
@@ -261,7 +261,7 @@ public:
 
   //! Returns packed (serialized) representation of light source properties
   const OpenGl_Vec4* Packed()  { return reinterpret_cast<OpenGl_Vec4*> (this); }
-  static Standard_Size NbOfVec4() { return 4; }
+  static Standard_Integer NbOfVec4() { return 4; }
 
 };
 
@@ -275,7 +275,7 @@ public:
 
   //! Returns packed (serialized) representation of light source type
   const OpenGl_Vec2i* Packed() { return reinterpret_cast<OpenGl_Vec2i*> (this); }
-  static Standard_Size NbOfVec2i() { return 1; }
+  static Standard_Integer NbOfVec2i() { return 1; }
 
 };
 
@@ -291,6 +291,12 @@ void OpenGl_ShaderManager::PushLightSourceState (const Handle(OpenGl_ShaderProgr
     return;
   }
 
+  OpenGl_ShaderLightType* aLightTypeArray = new OpenGl_ShaderLightType[OpenGLMaxLights];
+  for (Standard_Integer aLightIt = 0; aLightIt < OpenGLMaxLights; ++aLightIt)
+  {
+    aLightTypeArray[aLightIt].Type = -1;
+  }
+
   const Standard_Integer aLightsDefNb = Min (myLightSourceState.LightSources()->Size(), OpenGLMaxLights);
   if (aLightsDefNb < 1)
   {
@@ -300,12 +306,15 @@ void OpenGl_ShaderManager::PushLightSourceState (const Handle(OpenGl_ShaderProgr
     theProgram->SetUniform (myContext,
                             theProgram->GetStateLocation (OpenGl_OCC_LIGHT_AMBIENT),
                             OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
+    theProgram->SetUniform (myContext,
+                            theProgram->GetStateLocation (OpenGl_OCC_LIGHT_SOURCE_TYPES),
+                            OpenGLMaxLights * OpenGl_ShaderLightType::NbOfVec2i(),
+                            aLightTypeArray[0].Packed());
     theProgram->UpdateState (OpenGl_LIGHT_SOURCES_STATE, myLightSourceState.Index());
     return;
   }
 
   OpenGl_ShaderLightParameters* aLightParamsArray = new OpenGl_ShaderLightParameters[aLightsDefNb];
-  OpenGl_ShaderLightType*       aLightTypeArray   = new OpenGl_ShaderLightType[aLightsDefNb];
 
   OpenGl_Vec4 anAmbient (0.0f, 0.0f, 0.0f, 0.0f);
   Standard_Integer aLightsNb = 0;
@@ -345,12 +354,12 @@ void OpenGl_ShaderManager::PushLightSourceState (const Handle(OpenGl_ShaderProgr
   theProgram->SetUniform (myContext,
                           theProgram->GetStateLocation (OpenGl_OCC_LIGHT_AMBIENT),
                           anAmbient);
+  theProgram->SetUniform (myContext,
+                          theProgram->GetStateLocation (OpenGl_OCC_LIGHT_SOURCE_TYPES),
+                          OpenGLMaxLights * OpenGl_ShaderLightType::NbOfVec2i(),
+                          aLightTypeArray[0].Packed());
   if (aLightsNb > 0)
   {
-    theProgram->SetUniform (myContext,
-                            theProgram->GetStateLocation (OpenGl_OCC_LIGHT_SOURCE_TYPES),
-                            aLightsNb * OpenGl_ShaderLightType::NbOfVec2i(),
-                            aLightTypeArray[0].Packed());
     theProgram->SetUniform (myContext,
                             theProgram->GetStateLocation (OpenGl_OCC_LIGHT_SOURCE_PARAMS),
                             aLightsNb * OpenGl_ShaderLightParameters::NbOfVec4(),
@@ -612,6 +621,7 @@ static void PushAspectFace (const Handle(OpenGl_Context)&       theCtx,
                           theProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE),
                           theAspect->DistinguishingMode());
 
+  const float aDefSpecCol[4] = {1.0f, 1.0f, 1.0f, 1.0f};
   OpenGl_Vec4 aParams[5];
   for (Standard_Integer anIndex = 0; anIndex < 2; ++anIndex)
   {
@@ -624,22 +634,27 @@ static void PushAspectFace (const Handle(OpenGl_Context)&       theCtx,
     }
 
     const OPENGL_SURF_PROP& aProps = (anIndex == 0) ? theAspect->IntFront() : theAspect->IntBack();
-    const OpenGl_Vec4 anEmission (aProps.emscol.rgb[0] * aProps.emsv,
-                                  aProps.emscol.rgb[1] * aProps.emsv,
-                                  aProps.emscol.rgb[2] * aProps.emsv,
-                                  aProps.emscol.rgb[3] * aProps.emsv);
-    const OpenGl_Vec4 anAmbient  (aProps.ambcol.rgb[0] * aProps.amb,
-                                  aProps.ambcol.rgb[1] * aProps.amb,
-                                  aProps.ambcol.rgb[2] * aProps.amb,
-                                  aProps.ambcol.rgb[3] * aProps.amb);
-    const OpenGl_Vec4 aDiffuse   (aProps.difcol.rgb[0] * aProps.diff,
-                                  aProps.difcol.rgb[1] * aProps.diff,
-                                  aProps.difcol.rgb[2] * aProps.diff,
-                                  aProps.difcol.rgb[3] * aProps.diff);
-    const OpenGl_Vec4 aSpecular  (aProps.speccol.rgb[0] * aProps.spec,
-                                  aProps.speccol.rgb[1] * aProps.spec,
-                                  aProps.speccol.rgb[2] * aProps.spec,
-                                  aProps.speccol.rgb[3] * aProps.spec);
+    const float* aSrcEms = aProps.isphysic ? aProps.emscol.rgb : aProps.matcol.rgb;
+    const OpenGl_Vec4 anEmission (aSrcEms[0] * aProps.emsv,
+                                  aSrcEms[1] * aProps.emsv,
+                                  aSrcEms[2] * aProps.emsv,
+                                  1.0f);
+    const float* aSrcAmb = aProps.isphysic ? aProps.ambcol.rgb : aProps.matcol.rgb;
+    const OpenGl_Vec4 anAmbient  (aSrcAmb[0] * aProps.amb,
+                                  aSrcAmb[1] * aProps.amb,
+                                  aSrcAmb[2] * aProps.amb,
+                                  1.0f);
+    const float* aSrcDif = aProps.isphysic ? aProps.difcol.rgb : aProps.matcol.rgb;
+    const OpenGl_Vec4 aDiffuse   (aSrcDif[0] * aProps.diff,
+                                  aSrcDif[1] * aProps.diff,
+                                  aSrcDif[2] * aProps.diff,
+                                  1.0f);
+    const float* aSrcSpe = aProps.isphysic ? aProps.speccol.rgb : aDefSpecCol;
+    const OpenGl_Vec4 aSpecular  (aSrcSpe[0] * aProps.spec,
+                                  aSrcSpe[1] * aProps.spec,
+                                  aSrcSpe[2] * aProps.spec,
+                                  1.0f);
+
     aParams[0] = anEmission;
     aParams[1] = anAmbient;
     aParams[2] = aDiffuse;