Visualization, Graphic3d_ShaderProgram - add mat3/mat4 types to PushVariable (#1112)

Port of commit 1e1584357 adapted to the new source layout
and modern NCollection_Mat3/NCollection_Mat4 types.

- Graphic3d_ShaderVariable: register NCollection_Mat3<float> and
  NCollection_Mat4<float> type IDs; add template instantiations
  and Graphic3d_UniformMat3/Graphic3d_UniformMat4 typedefs.
- Graphic3d_ShaderProgram: add PushVariableMat3() and PushVariableMat4()
  convenience methods.
- OpenGl_ShaderProgram: add single-value SetUniform() for mat3
  (wrapping glUniformMatrix3fv); register mat3/mat4 in
  OpenGl_VariableSetterSelector so custom uniforms are dispatched.
- ViewerTest (vshader command): add -vec2, -vec3, -vec4, -mat3, -mat4
  argument parsing for setting custom uniform variables from Draw Harness.
- Add Draw Harness test exercising the new uniform types.
This commit is contained in:
Kirill Gavrilov
2026-02-23 18:16:45 +00:00
committed by dpasukhi
parent e8012824d6
commit be39f6f6be
7 changed files with 199 additions and 1 deletions
@@ -135,7 +135,11 @@ OpenGl_VariableSetterSelector::OpenGl_VariableSetterSelector()
Graphic3d_UniformValueTypeID<NCollection_Vec3<int>>::ID,
new OpenGl_VariableSetter<NCollection_Vec3<int>>())(
Graphic3d_UniformValueTypeID<NCollection_Vec4<int>>::ID,
new OpenGl_VariableSetter<NCollection_Vec4<int>>());
new OpenGl_VariableSetter<NCollection_Vec4<int>>())(
Graphic3d_UniformValueTypeID<NCollection_Mat3<float>>::ID,
new OpenGl_VariableSetter<NCollection_Mat3<float>>())(
Graphic3d_UniformValueTypeID<NCollection_Mat4<float>>::ID,
new OpenGl_VariableSetter<NCollection_Mat4<float>>());
}
// =======================================================================
@@ -1267,6 +1271,26 @@ bool OpenGl_ShaderProgram::SetUniform(const occ::handle<OpenGl_Context>& theCtx,
return true;
}
//=================================================================================================
bool OpenGl_ShaderProgram::SetUniform(const occ::handle<OpenGl_Context>& theCtx,
GLint theLocation,
const NCollection_Mat3<float>& theValue,
GLboolean theTranspose)
{
if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
{
return false;
}
theCtx->core20fwd->glUniformMatrix3fv(theLocation,
1,
GL_FALSE,
theTranspose ? theValue.Transposed().GetData()
: theValue.GetData());
return true;
}
// =======================================================================
// function : SetUniform
// purpose : Specifies the value of the floating-point uniform 4x4 matrix
@@ -496,6 +496,23 @@ public:
GLuint theCount,
const NCollection_Mat3<float>* theData);
//! Specifies the value of the float uniform 3x3 matrix.
//! Wrapper for glUniformMatrix3fv()
bool SetUniform(const occ::handle<OpenGl_Context>& theCtx,
const GLchar* theName,
const NCollection_Mat3<float>& theValue,
GLboolean theTranspose = GL_FALSE)
{
return SetUniform(theCtx, GetUniformLocation(theCtx, theName), theValue, theTranspose);
}
//! Specifies the value of the float uniform 3x3 matrix.
//! Wrapper for glUniformMatrix3fv()
Standard_EXPORT bool SetUniform(const occ::handle<OpenGl_Context>& theCtx,
GLint theLocation,
const NCollection_Mat3<float>& theValue,
GLboolean theTranspose = GL_FALSE);
//! Specifies the value of the float uniform 4x4 matrix.
//! Wrapper for glUniformMatrix4fv()
bool SetUniform(const occ::handle<OpenGl_Context>& theCtx,