#include <OpenGl_Context.hxx>
#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_ArbTexBindless.hxx>
-IMPLEMENT_STANDARD_HANDLE (OpenGl_ShaderProgram, OpenGl_Resource)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_ShaderProgram, OpenGl_Resource)
+#include <OpenGl_GlCore32.hxx>
OpenGl_VariableSetterSelector OpenGl_ShaderProgram::mySetterSelector = OpenGl_VariableSetterSelector();
"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
+
+ "occTexTrsf2d", // OpenGl_OCCT_TEXTURE_TRSF2D
+ "occPointSize" // OpenGl_OCCT_POINT_SIZE
};
return Standard_False;
}
+ TCollection_AsciiString aHeader = !myProxy.IsNull() && !myProxy->Header().IsEmpty()
+ ? (myProxy->Header() + "\n")
+ : TCollection_AsciiString();
+
TCollection_AsciiString aDeclarations;
aDeclFile.Open (OSD_ReadOnly, OSD_Protection());
aDeclFile.Read (aDeclarations, (int)aDeclFile.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 = aHeader + 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 highp int;\n"
+ : "precision mediump float;\n"
+ "precision mediump int;\n");
+ aSource = aHeader + aPrefix + aSource;
+ #else
+ aSource = aHeader + aSource;
+ #endif
+ break;
+ }
}
if (!aShader->LoadSource (theCtx, aSource))
SetAttributeName (theCtx, Graphic3d_TOA_POS, "occVertex");
SetAttributeName (theCtx, Graphic3d_TOA_NORM, "occNormal");
SetAttributeName (theCtx, Graphic3d_TOA_UV, "occTexCoord");
- SetAttributeName (theCtx, Graphic3d_TOA_COLOR, "occColor");
+ SetAttributeName (theCtx, Graphic3d_TOA_COLOR, "occVertColor");
if (!Link (theCtx))
{
}
myShaderObjects.Append (theShader);
- theCtx->core20->glAttachShader (myProgramID, theShader->myShaderID);
+ theCtx->core20fwd->glAttachShader (myProgramID, theShader->myShaderID);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glDetachShader (myProgramID, theShader->myShaderID);
+ theCtx->core20fwd->glDetachShader (myProgramID, theShader->myShaderID);
return Standard_True;
}
}
GLint aStatus = GL_FALSE;
- theCtx->core20->glLinkProgram (myProgramID);
- theCtx->core20->glGetProgramiv (myProgramID, GL_LINK_STATUS, &aStatus);
+ theCtx->core20fwd->glLinkProgram (myProgramID);
+ theCtx->core20fwd->glGetProgramiv (myProgramID, GL_LINK_STATUS, &aStatus);
if (aStatus == GL_FALSE)
{
return Standard_False;
}
GLint aLength = 0;
- theCtx->core20->glGetProgramiv (myProgramID, GL_INFO_LOG_LENGTH, &aLength);
+ theCtx->core20fwd->glGetProgramiv (myProgramID, GL_INFO_LOG_LENGTH, &aLength);
if (aLength > 0)
{
GLchar* aLog = (GLchar*) alloca (aLength);
memset (aLog, 0, aLength);
- theCtx->core20->glGetProgramInfoLog (myProgramID, aLength, NULL, aLog);
+ theCtx->core20fwd->glGetProgramInfoLog (myProgramID, aLength, NULL, aLog);
theOutput = aLog;
}
return Standard_True;
const GLchar* theName) const
{
return myProgramID != NO_PROGRAM
- ? theCtx->core20->glGetUniformLocation (myProgramID, theName)
+ ? theCtx->core20fwd->glGetUniformLocation (myProgramID, theName)
: INVALID_LOCATION;
}
const GLchar* theName) const
{
return myProgramID != NO_PROGRAM
- ? theCtx->core20->glGetAttribLocation (myProgramID, theName)
+ ? theCtx->core20fwd->glGetAttribLocation (myProgramID, theName)
: INVALID_LOCATION;
}
return Standard_False;
}
- theCtx->core20->glGetUniformiv (myProgramID, theLocation, theValue);
+ theCtx->core20fwd->glGetUniformiv (myProgramID, theLocation, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glGetUniformfv (myProgramID, theLocation, theValue);
+ theCtx->core20fwd->glGetUniformfv (myProgramID, theLocation, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glGetVertexAttribiv (theIndex, GL_CURRENT_VERTEX_ATTRIB, theValue);
+ theCtx->core20fwd->glGetVertexAttribiv (theIndex, GL_CURRENT_VERTEX_ATTRIB, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glGetVertexAttribfv (theIndex, GL_CURRENT_VERTEX_ATTRIB, theValue);
+ theCtx->core20fwd->glGetVertexAttribfv (theIndex, GL_CURRENT_VERTEX_ATTRIB, theValue);
return Standard_True;
}
theCtx->core20fwd->glBindAttribLocation (myProgramID, theIndex, theName);
return Standard_True;
}
-
+
// =======================================================================
// function : SetAttribute
// purpose :
return Standard_False;
}
- theCtx->core20->glUniform1i (theLocation, theValue);
+ theCtx->core20fwd->glUniform1i (theLocation, theValue);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ const GLchar* theName,
+ const OpenGl_Vec2u& theValue)
+{
+ return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ const OpenGl_Vec2u& theValue)
+{
+ if (theCtx->core32 == NULL || myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+#if !defined(GL_ES_VERSION_2_0)
+ theCtx->core32->glUniform2uiv (theLocation, 1, theValue.GetData());
+#endif
+
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ const GLchar* theName,
+ const GLsizei theCount,
+ const OpenGl_Vec2u* theValue)
+{
+ return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theCount, theValue);
+}
+
+// =======================================================================
+// function : SetUniform
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
+ GLint theLocation,
+ const GLsizei theCount,
+ const OpenGl_Vec2u* theValue)
+{
+ if (theCtx->core32 == NULL || myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+ {
+ return Standard_False;
+ }
+
+#if !defined(GL_ES_VERSION_2_0)
+ theCtx->core32->glUniform2uiv (theLocation, theCount, theValue->GetData());
+#endif
+
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform1f (theLocation, theValue);
+ theCtx->core20fwd->glUniform1f (theLocation, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform2iv (theLocation, 1, theValue);
+ theCtx->core20fwd->glUniform2iv (theLocation, 1, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform3iv (theLocation, 1, theValue);
+ theCtx->core20fwd->glUniform3iv (theLocation, 1, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform4iv (theLocation, 1, theValue);
+ theCtx->core20fwd->glUniform4iv (theLocation, 1, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform2fv (theLocation, 1, theValue);
+ theCtx->core20fwd->glUniform2fv (theLocation, 1, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform3fv (theLocation, 1, theValue);
+ theCtx->core20fwd->glUniform3fv (theLocation, 1, theValue);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform4fv (theLocation, 1, theValue);
+ theCtx->core20fwd->glUniform4fv (theLocation, 1, theValue);
return Standard_True;
}
// =======================================================================
Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName,
- const OpenGl_Matrix& theValue,
+ const OpenGl_Mat4& theValue,
GLboolean theTranspose)
{
return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
// =======================================================================
Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
GLint theLocation,
- const OpenGl_Matrix& theValue,
+ const OpenGl_Mat4& theValue,
GLboolean theTranspose)
{
if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
return Standard_False;
}
- theCtx->core20->glUniformMatrix4fv (theLocation, 1, theTranspose, *theValue.mat);
+ theCtx->core20fwd->glUniformMatrix4fv (theLocation, 1, GL_FALSE, theTranspose ? theValue.Transposed() : theValue);
return Standard_True;
}
// =======================================================================
Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName,
- const Tmatrix3& theValue,
+ const OpenGl_Matrix& theValue,
GLboolean theTranspose)
{
return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
// =======================================================================
Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
GLint theLocation,
- const Tmatrix3& theValue,
+ const OpenGl_Matrix& theValue,
GLboolean theTranspose)
{
- if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
- {
- return Standard_False;
- }
-
- theCtx->core20->glUniformMatrix4fv (theLocation, 1, theTranspose, *theValue);
- return Standard_True;
+ return SetUniform (theCtx, theLocation, OpenGl_Mat4::Map (*theValue.mat), theTranspose);
}
// =======================================================================
return Standard_False;
}
- theCtx->core20->glUniform1fv (theLocation, theCount, theData);
+ theCtx->core20fwd->glUniform1fv (theLocation, theCount, theData);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform2fv (theLocation, theCount, theData[0].GetData());
+ theCtx->core20fwd->glUniform2fv (theLocation, theCount, theData[0].GetData());
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform3fv (theLocation, theCount, theData[0].GetData());
+ theCtx->core20fwd->glUniform3fv (theLocation, theCount, theData[0].GetData());
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform4fv (theLocation, theCount, theData[0].GetData());
+ theCtx->core20fwd->glUniform4fv (theLocation, theCount, theData[0].GetData());
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform1iv (theLocation, theCount, theData);
+ theCtx->core20fwd->glUniform1iv (theLocation, theCount, theData);
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform2iv (theLocation, theCount, theData[0].GetData());
+ theCtx->core20fwd->glUniform2iv (theLocation, theCount, theData[0].GetData());
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform3iv (theLocation, theCount, theData[0].GetData());
+ theCtx->core20fwd->glUniform3iv (theLocation, theCount, theData[0].GetData());
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform4iv (theLocation, theCount, theData[0].GetData());
+ theCtx->core20fwd->glUniform4iv (theLocation, theCount, theData[0].GetData());
return Standard_True;
}
return Standard_False;
}
- theCtx->core20->glUniform1i (theLocation, theTextureUnit);
+ theCtx->core20fwd->glUniform1i (theLocation, theTextureUnit);
return Standard_True;
}
Standard_Boolean OpenGl_ShaderProgram::Create (const Handle(OpenGl_Context)& theCtx)
{
if (myProgramID == NO_PROGRAM
- && theCtx->core20 != NULL)
+ && theCtx->core20fwd != NULL)
{
- myProgramID = theCtx->core20->glCreateProgram();
+ myProgramID = theCtx->core20fwd->glCreateProgram();
}
return myProgramID != NO_PROGRAM;
}
}
- if (theCtx->core20 != NULL
+ if (theCtx->core20fwd != NULL
&& theCtx->IsValid())
{
- theCtx->core20->glDeleteProgram (myProgramID);
+ theCtx->core20fwd->glDeleteProgram (myProgramID);
}
myProgramID = NO_PROGRAM;