#include <OSD_File.hxx>
#include <OSD_Protection.hxx>
+#include <Graphic3d_Buffer.hxx>
#include <Standard_Assert.hxx>
#include <Standard_Atomic.hxx>
#include <TCollection_ExtendedString.hxx>
"occTextureEnable", // OpenGl_OCCT_TEXTURE_ENABLE
"occDistinguishingMode", // OpenGl_OCCT_DISTINGUISH_MODE
"occFrontMaterial", // OpenGl_OCCT_FRONT_MATERIAL
- "occBackMaterial" // OpenGl_OCCT_BACK_MATERIAL
+ "occBackMaterial", // OpenGl_OCCT_BACK_MATERIAL
+ "occColor", // OpenGl_OCCT_COLOR
+
+ "occPointSize" // OpenGl_OCCT_POINT_SIZE
};
}
TCollection_AsciiString aSource = aDeclarations + anIter.Value()->Source();
- if (anIter.Value()->Type() == Graphic3d_TOS_VERTEX)
+ switch (anIter.Value()->Type())
{
- aSource = TCollection_AsciiString ("#define VERTEX_SHADER\n") + aSource;
+ case Graphic3d_TOS_VERTEX:
+ {
+ aSource = TCollection_AsciiString ("#define VERTEX_SHADER\n") + aSource;
+ break;
+ }
+ case Graphic3d_TOS_FRAGMENT:
+ {
+ #if defined(GL_ES_VERSION_2_0)
+ TCollection_AsciiString aPrefix (theCtx->hasHighp
+ ? "precision highp float;\n"
+ : "precision mediump float;\n");
+ aSource = aPrefix + aSource;
+ #endif
+ break;
+ }
}
if (!aShader->LoadSource (theCtx, aSource))
}
}
+ // bind locations for pre-defined Vertex Attributes
+ SetAttributeName (theCtx, Graphic3d_TOA_POS, "occVertex");
+ SetAttributeName (theCtx, Graphic3d_TOA_NORM, "occNormal");
+ SetAttributeName (theCtx, Graphic3d_TOA_UV, "occTexCoord");
+ SetAttributeName (theCtx, Graphic3d_TOA_COLOR, "occVertColor");
+
if (!Link (theCtx))
{
TCollection_AsciiString aLog;
return Standard_False;
}
- theCtx->core20->glLinkProgram (myProgramID);
-
GLint aStatus = GL_FALSE;
+ theCtx->core20->glLinkProgram (myProgramID);
theCtx->core20->glGetProgramiv (myProgramID, GL_LINK_STATUS, &aStatus);
+ if (aStatus == GL_FALSE)
+ {
+ return Standard_False;
+ }
for (GLint aVar = 0; aVar < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES; ++aVar)
{
myStateLocations[aVar] = GetUniformLocation (theCtx, PredefinedKeywords[aVar]);
}
-
- return aStatus != GL_FALSE;
+ return Standard_True;
}
// =======================================================================
return Standard_True;
}
-// =======================================================================
-// function : Bind
-// purpose : Sets the program object as part of current rendering state
-// =======================================================================
-void OpenGl_ShaderProgram::Bind (const Handle(OpenGl_Context)& theCtx) const
-{
- if (myProgramID == NO_PROGRAM)
- {
- return;
- }
-
- theCtx->core20->glUseProgram (myProgramID);
- theCtx->ShaderManager()->myIsPP = Standard_True;
-}
-
// =======================================================================
// function : ApplyVariables
// purpose : Fetches uniform variables from proxy shader program
return Standard_True;
}
-// =======================================================================
-// function : BindWithVariables
-// purpose : Binds the program object and applies variables
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::BindWithVariables (const Handle(OpenGl_Context)& theCtx)
-{
- Bind (theCtx);
- return ApplyVariables (theCtx);
-}
-
-// =======================================================================
-// function : Unbind
-// purpose : Reverts to fixed-function graphics pipeline (FFP)
-// =======================================================================
-void OpenGl_ShaderProgram::Unbind (const Handle(OpenGl_Context)& theCtx)
-{
- if (theCtx->ShaderManager()->myIsPP)
- {
- theCtx->core20->glUseProgram (NO_PROGRAM);
- theCtx->ShaderManager()->myIsPP = Standard_False;
- }
-}
-
// =======================================================================
// function : ActiveState
// purpose : Returns index of last modification for specified state type
return Standard_True;
}
+// =======================================================================
+// function : SetAttributeName
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttributeName (const Handle(OpenGl_Context)& theCtx,
+ GLint theIndex,
+ const GLchar* theName)
+{
+ theCtx->core20fwd->glBindAttribLocation (myProgramID, theIndex, theName);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ const GLchar* theName,
+ GLfloat theValue)
+{
+ return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ GLint theIndex,
+ GLfloat theValue)
+{
+ if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20fwd->glVertexAttrib1f (theIndex, theValue);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ const GLchar* theName,
+ const OpenGl_Vec2& theValue)
+{
+ return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ GLint theIndex,
+ const OpenGl_Vec2& theValue)
+{
+ if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20fwd->glVertexAttrib2fv (theIndex, theValue);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ const GLchar* theName,
+ const OpenGl_Vec3& theValue)
+{
+ return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ GLint theIndex,
+ const OpenGl_Vec3& theValue)
+{
+ if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20fwd->glVertexAttrib3fv (theIndex, theValue);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ const GLchar* theName,
+ const OpenGl_Vec4& theValue)
+{
+ return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
+}
+
+// =======================================================================
+// function : SetAttribute
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
+ GLint theIndex,
+ const OpenGl_Vec4& theValue)
+{
+ if (myProgramID == NO_PROGRAM || theIndex == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+ theCtx->core20fwd->glVertexAttrib4fv (theIndex, theValue);
+ return Standard_True;
+}
+
// =======================================================================
// function : SetUniform
// purpose : Specifies the value of the integer uniform variable
// function : Release
// purpose : Destroys shader program
// =======================================================================
-void OpenGl_ShaderProgram::Release (const OpenGl_Context* theCtx)
+void OpenGl_ShaderProgram::Release (OpenGl_Context* theCtx)
{
if (myProgramID == NO_PROGRAM)
{
for (OpenGl_ShaderList::Iterator anIter (myShaderObjects); anIter.More(); anIter.Next())
{
- anIter.ChangeValue()->Release (theCtx);
- anIter.ChangeValue().Nullify();
+ if (!anIter.Value().IsNull())
+ {
+ anIter.ChangeValue()->Release (theCtx);
+ anIter.ChangeValue().Nullify();
+ }
}
if (theCtx->core20 != NULL