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

View File

@@ -244,6 +244,20 @@ public:
return PushVariable(theName, theValue);
}
//! Pushes mat3 uniform.
bool PushVariableMat3(const TCollection_AsciiString& theName,
const NCollection_Mat3<float>& theValue)
{
return PushVariable(theName, theValue);
}
//! Pushes mat4 uniform.
bool PushVariableMat4(const TCollection_AsciiString& theName,
const NCollection_Mat4<float>& theValue)
{
return PushVariable(theName, theValue);
}
public:
//! The path to GLSL programs determined from CSF_ShadersDirectory or CASROOT environment
//! variables.

View File

@@ -26,6 +26,8 @@ template struct Graphic3d_UniformValue<NCollection_Vec4<float>>;
template struct Graphic3d_UniformValue<NCollection_Vec2<int>>;
template struct Graphic3d_UniformValue<NCollection_Vec3<int>>;
template struct Graphic3d_UniformValue<NCollection_Vec4<int>>;
template struct Graphic3d_UniformValue<NCollection_Mat3<float>>;
template struct Graphic3d_UniformValue<NCollection_Mat4<float>>;
// =======================================================================
// function : ~Graphic3d_ValueInterface

View File

@@ -24,6 +24,7 @@
#include <NCollection_Vec4.hxx>
#include <NCollection_Mat3.hxx>
#include <NCollection_Mat4.hxx>
#include <Standard_Transient.hxx>
#include <TCollection_AsciiString.hxx>
@@ -101,6 +102,18 @@ struct Graphic3d_UniformValueTypeID<NCollection_Vec4<int>>
static const size_t ID = __LINE__;
};
template <>
struct Graphic3d_UniformValueTypeID<NCollection_Mat3<float>>
{
static const size_t ID = __LINE__;
};
template <>
struct Graphic3d_UniformValueTypeID<NCollection_Mat4<float>>
{
static const size_t ID = __LINE__;
};
//! Describes specific value of custom uniform variable.
template <class T>
struct Graphic3d_UniformValue : public Graphic3d_ValueInterface
@@ -142,6 +155,12 @@ typedef Graphic3d_UniformValue<NCollection_Vec3<float>> Graphic3d_UniformVec3;
//! Floating-point uniform 4D vector.
typedef Graphic3d_UniformValue<NCollection_Vec4<float>> Graphic3d_UniformVec4;
//! Floating-point uniform 3x3 matrix.
typedef Graphic3d_UniformValue<NCollection_Mat3<float>> Graphic3d_UniformMat3;
//! Floating-point uniform 4x4 matrix.
typedef Graphic3d_UniformValue<NCollection_Mat4<float>> Graphic3d_UniformMat4;
//! Describes custom uniform shader variable.
class Graphic3d_ShaderVariable : public Standard_Transient
{