mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-08-10 00:02:41 +08:00
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:
committed by
dpasukhi
parent
e8012824d6
commit
be39f6f6be
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user