Fixed pipeline - accumulate all ambient light sources.
Fix clearing of all light sources.
return myWorldViewState;
}
+//! Packed properties of light source
+class OpenGl_ShaderLightParameters
+{
+public:
+
+ OpenGl_Vec4 Color;
+ OpenGl_Vec4 Position;
+ OpenGl_Vec4 Direction;
+ OpenGl_Vec4 Parameters;
+
+ //! Returns packed (serialized) representation of light source properties
+ const OpenGl_Vec4* Packed() { return reinterpret_cast<OpenGl_Vec4*> (this); }
+ static Standard_Size NbOfVec4() { return 4; }
+
+};
+
+//! Packed light source type information
+class OpenGl_ShaderLightType
+{
+public:
+
+ Standard_Integer Type;
+ Standard_Integer IsHeadlight;
+
+ //! Returns packed (serialized) representation of light source type
+ const OpenGl_Vec2i* Packed() { return reinterpret_cast<OpenGl_Vec2i*> (this); }
+ static Standard_Size NbOfVec2i() { return 1; }
+
+};
+
// =======================================================================
// function : PushLightSourceState
// purpose : Pushes state of OCCT light sources to the program
return;
}
- const GLint aTypesLoc = theProgram->GetStateLocation (OpenGl_OCC_LIGHT_SOURCE_TYPES);
- const GLint aParamsLoc = theProgram->GetStateLocation (OpenGl_OCC_LIGHT_SOURCE_PARAMS);
-
const Standard_Integer aLightsDefNb = Min (myLightSourceState.LightSources()->Size(), OpenGLMaxLights);
if (aLightsDefNb < 1)
{
return;
}
- OpenGl_Vec2i* aTypesArray = new OpenGl_Vec2i[aLightsDefNb];
- OpenGl_Vec4* aParamsArray = new OpenGl_Vec4 [aLightsDefNb * 4];
+ 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;
continue;
}
- aTypesArray[aLightsNb].x() = aLight.Type;
- aTypesArray[aLightsNb].y() = aLight.IsHeadlight;
+ OpenGl_ShaderLightType& aLightType = aLightTypeArray[aLightsNb];
+ aLightType.Type = aLight.Type;
+ aLightType.IsHeadlight = aLight.IsHeadlight;
- aParamsArray[aLightsNb * 4 + 0] = aLight.Color;
- aParamsArray[aLightsNb * 4 + 1] = aLight.Type == Visual3d_TOLS_DIRECTIONAL
- ? -aLight.Direction
- : aLight.Position;
+ OpenGl_ShaderLightParameters& aLightParams = aLightParamsArray[aLightsNb];
+ aLightParams.Color = aLight.Color;
+ aLightParams.Position = aLight.Type == Visual3d_TOLS_DIRECTIONAL
+ ? -aLight.Direction
+ : aLight.Position;
if (aLight.Type == Visual3d_TOLS_SPOT)
{
- aParamsArray[aLightsNb * 4 + 2] = aLight.Direction;
+ aLightParams.Direction = aLight.Direction;
}
- aParamsArray[aLightsNb * 4 + 3] = aLight.Params;
+ aLightParams.Parameters = aLight.Params;
++aLightsNb;
}
anAmbient);
if (aLightsNb > 0)
{
- myContext->core20->glUniform2iv (aTypesLoc, aLightsNb, aTypesArray [0].GetData());
- myContext->core20->glUniform4fv (aParamsLoc, aLightsNb * 4, aParamsArray[0].GetData());
+ 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(),
+ aLightParamsArray[0].Packed());
}
- delete[] aTypesArray;
- delete[] aParamsArray;
+ delete[] aLightParamsArray;
+ delete[] aLightTypeArray;
theProgram->UpdateState (OpenGl_LIGHT_SOURCES_STATE, myLightSourceState.Index());
}
aSpaces[aPlaneId] = myContext->Clipping().GetEquationSpace (aPlane);
++aPlaneId;
}
- myContext->core20->glUniform4fv (aLocEquations, aPlanesNb, anEquations[0].GetData());
- myContext->core20->glUniform1iv (aLocSpaces, aPlanesNb, aSpaces);
+ theProgram->SetUniform (myContext, aLocEquations, aPlanesNb, anEquations[0].GetData());
+ theProgram->SetUniform (myContext, aLocSpaces, aPlanesNb, aSpaces);
+
delete[] anEquations;
delete[] aSpaces;
}
aParams[3] = aSpecular;
aParams[4].x() = aProps.shine;
aParams[4].y() = aProps.trans;
- theCtx->core20->glUniform4fv (aLoc, 5, aParams[0].GetData());
+ theProgram->SetUniform (theCtx, aLoc, 5, aParams);
}
}
aParams[3] = THE_COLOR_BLACK_VEC4;
aParams[4].x() = 0.0f; // shininess
aParams[4].y() = 0.0f; // transparency
- theCtx->core20->glUniform4fv (theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL),
- 5, aParams[0].GetData());
+ theProgram->SetUniform (theCtx, theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL),
+ 5, aParams);
}
// =======================================================================
aParams[3] = THE_COLOR_BLACK_VEC4;
aParams[4].x() = 0.0f; // shininess
aParams[4].y() = 0.0f; // transparency
- theCtx->core20->glUniform4fv (theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL),
- 5, aParams[0].GetData());
+ theProgram->SetUniform (theCtx, theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL),
+ 5, aParams);
}
// =======================================================================
aParams[3] = THE_COLOR_BLACK_VEC4;
aParams[4].x() = 0.0f; // shininess
aParams[4].y() = 0.0f; // transparency
- theCtx->core20->glUniform4fv (theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL),
- 5, aParams[0].GetData());
+ theProgram->SetUniform (theCtx, theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL),
+ 5, aParams);
}
}; // nameless namespace
return Standard_True;
}
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the float uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const Standard_ShortReal* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform1fv (theLocation, theCount, theData);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the float2 uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec2* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform2fv (theLocation, theCount, theData[0].GetData());
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the float3 uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec3* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform3fv (theLocation, theCount, theData[0].GetData());
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the float4 uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec4* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform4fv (theLocation, theCount, theData[0].GetData());
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the integer uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const Standard_Integer* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform1iv (theLocation, theCount, theData);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the int2 uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec2i* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform2iv (theLocation, theCount, theData[0].GetData());
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the int3 uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec3i* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform3iv (theLocation, theCount, theData[0].GetData());
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose : Specifies the value of the int4 uniform array
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec4i* theData)
+{
+ if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20->glUniform4iv (theLocation, theCount, theData[0].GetData());
+ return Standard_True;
+}
+
// =======================================================================
// function : SetSampler
// purpose : Specifies the value of the sampler uniform variable
const Tmatrix3& theValue,
GLboolean theTranspose = GL_FALSE);
+ //! Specifies the value of the float uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const Standard_ShortReal* theData);
+
+ //! Specifies the value of the float2 uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec2* theData);
+
+ //! Specifies the value of the float3 uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec3* theData);
+
+ //! Specifies the value of the float4 uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec4* theData);
+
+ //! Specifies the value of the integer uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const Standard_Integer* theData);
+
+ //! Specifies the value of the int2 uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec2i* theData);
+
+ //! Specifies the value of the int3 uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec3i* theData);
+
+ //! Specifies the value of the int4 uniform array
+ Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ GLuint theCount,
+ const OpenGl_Vec4i* theData);
+
public:
//! Specifies the value of the sampler uniform variable.
* Set des lumieres
*/
static void bind_light (const OpenGl_Light& theLight,
- GLenum& theLightGlId)
+ GLenum& theLightGlId,
+ Graphic3d_Vec4& theAmbientColor)
{
// Only 8 lights in OpenGL...
if (theLightGlId > GL_LIGHT7)
if (theLight.Type == Visual3d_TOLS_AMBIENT)
{
- // setup RGBA intensity of the ambient light
- glLightModelfv (GL_LIGHT_MODEL_AMBIENT, theLight.Color.GetData());
+ // add RGBA intensity of the ambient light
+ theAmbientColor += theLight.Color;
return;
}
// Apply Lights
{
// setup lights
- glLightModelfv (GL_LIGHT_MODEL_AMBIENT, THE_DEFAULT_AMBIENT);
+ Graphic3d_Vec4 anAmbientColor (THE_DEFAULT_AMBIENT[0],
+ THE_DEFAULT_AMBIENT[1],
+ THE_DEFAULT_AMBIENT[2],
+ THE_DEFAULT_AMBIENT[3]);
GLenum aLightGlId = GL_LIGHT0;
for (OpenGl_ListOfLight::Iterator aLightIt (myLights);
aLightIt.More(); aLightIt.Next())
{
- bind_light (aLightIt.Value(), aLightGlId);
+ bind_light (aLightIt.Value(), aLightGlId, anAmbientColor);
}
+
+ // apply accumulated ambient color
+ anAmbientColor.a() = 1.0f;
+ glLightModelfv (GL_LIGHT_MODEL_AMBIENT, anAmbientColor.GetData());
+
if (aLightGlId != GL_LIGHT0)
{
glEnable (GL_LIGHTING);
{
isGlobal = Standard_False;
}
+ else if (anArgCase.IsEqual ("DEF")
+ || anArgCase.IsEqual ("DEFAULTS"))
+ {
+ toCreate = Standard_False;
+ aViewer->SetDefaultLights();
+ }
+ else if (anArgCase.IsEqual ("CLR")
+ || anArgCase.IsEqual ("CLEAR"))
+ {
+ toCreate = Standard_False;
+ aView->InitActiveLights();
+ while (aView->MoreActiveLights())
+ {
+ aViewer->DelLight (aView->ActiveLight());
+ aView->InitActiveLights();
+ }
+ }
else if (anArgCase.IsEqual ("AMB")
|| anArgCase.IsEqual ("AMBIENT")
|| anArgCase.IsEqual ("AMBLIGHT"))
return 1;
}
}
+ else if (anArgCase.IsEqual ("ANG")
+ || anArgCase.IsEqual ("ANGLE"))
+ {
+ if (++anArgIt >= theArgsNb)
+ {
+ std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
+ return 1;
+ }
+
+ Standard_Real anAngle = Atof (theArgVec[anArgIt]);
+
+ if (!aLightSpot.IsNull())
+ {
+ aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
+ }
+ }
else if (anArgCase.IsEqual ("CONSTATTEN")
|| anArgCase.IsEqual ("CONSTATTENUATION"))
{
__FILE__, VDefaults, group);
theCommands.Add("vlight",
"vlight [add|new {amb}ient|directional|{spot}light|positional]"
+ "\n\t\t: [{def}aults] [clear]"
"\n\t\t: [{del}ete|change lightId] [local|global]"
"\n\t\t: [{pos}ition X Y Z] [color colorName] [{head}light 0|1]"
"\n\t\t: [{constAtten}uation value] [{linearAtten}uation value]"
-- Category: Class methods
--------------------------
- Limit ( myclass )
- returns Integer from Standard;
- ---Level: Internal
- ---Purpose: Maximum number of activatable light sources.
- ---Category: Class methods
-
- ----------------------------
- -- Category: Private methods
- ----------------------------
-
- Identification ( me )
- returns Integer from Standard
- is static private;
- ---Level: Internal
- ---Purpose: Returns the light identification.
- ---Category: Private methods
-
IsValid ( myclass;
AAngle : Real from Standard )
returns Boolean from Standard
myCLight.Position.z() = float (thePos.Z());
}
-// =======================================================================
-// function : Limit
-// purpose :
-// =======================================================================
-Standard_Integer Visual3d_Light::Limit()
-{
- // Old method, replaced by GraphicDriver::InquireLightLimit()
- return 0;
-}
-
-// =======================================================================
-// function : Identification
-// purpose :
-// =======================================================================
-Standard_Integer Visual3d_Light::Identification() const
-{
- return 0;
-}
-
// =======================================================================
// function : IsValid
// purpose :
MyGraphicDriver->InquireLightLimit());
if (MyCView.Context.NbActiveLight < 1)
{
+ MyGraphicDriver->SetLight (MyCView);
return;
}
--- /dev/null
+puts "========"
+puts "Test to verify the lights are turned off after 'vlight clear' (and scene is black)"
+puts "========"
+
+# create box
+box b 1 2 3
+
+# draw box
+vinit View1
+vclear
+vsetdispmode 1
+vdisplay b
+vfit
+
+vlight clear
+
+set color [vreadpixel 100 100 rgb]
+set black "0 0 0\n"
+if {[string equal $color $black] != 1} {error "Lights do not seems to be cleared!"}