File indexing completed on 2026-10-02 09:12:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Graphic3d_ShaderProgram_HeaderFile
0017 #define _Graphic3d_ShaderProgram_HeaderFile
0018
0019 #include <Graphic3d_RenderTransparentMethod.hxx>
0020 #include <Graphic3d_ShaderAttribute.hxx>
0021 #include <Graphic3d_ShaderObject.hxx>
0022 #include <Graphic3d_ShaderVariable.hxx>
0023 #include <Graphic3d_TextureParams.hxx>
0024 #include <NCollection_Sequence.hxx>
0025
0026
0027
0028
0029
0030
0031
0032
0033 class Graphic3d_ShaderProgram : public Standard_Transient
0034 {
0035 DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderProgram, Standard_Transient)
0036 public:
0037
0038 static const int THE_MAX_LIGHTS_DEFAULT = 8;
0039
0040
0041 static const int THE_MAX_CLIP_PLANES_DEFAULT = 8;
0042
0043
0044 static const int THE_NB_FRAG_OUTPUTS = 1;
0045
0046 public:
0047
0048 Standard_EXPORT Graphic3d_ShaderProgram();
0049
0050
0051 Standard_EXPORT ~Graphic3d_ShaderProgram() override;
0052
0053
0054 Standard_EXPORT virtual bool IsDone() const;
0055
0056
0057 const TCollection_AsciiString& GetId() const { return myID; }
0058
0059
0060
0061
0062
0063 void SetId(const TCollection_AsciiString& theId) { myID = theId; }
0064
0065
0066 const TCollection_AsciiString& Header() const { return myHeader; }
0067
0068
0069
0070
0071
0072
0073
0074
0075 void SetHeader(const TCollection_AsciiString& theHeader) { myHeader = theHeader; }
0076
0077
0078 void AppendToHeader(const TCollection_AsciiString& theHeaderLine)
0079 {
0080 if (!myHeader.IsEmpty())
0081 {
0082 myHeader += "\n";
0083 }
0084 myHeader += theHeaderLine;
0085 }
0086
0087
0088
0089
0090 int NbLightsMax() const { return myNbLightsMax; }
0091
0092
0093 void SetNbLightsMax(int theNbLights) { myNbLightsMax = theNbLights; }
0094
0095
0096 int NbShadowMaps() const { return myNbShadowMaps; }
0097
0098
0099 void SetNbShadowMaps(int theNbMaps) { myNbShadowMaps = theNbMaps; }
0100
0101
0102
0103
0104 int NbClipPlanesMax() const { return myNbClipPlanesMax; }
0105
0106
0107 void SetNbClipPlanesMax(int theNbPlanes) { myNbClipPlanesMax = theNbPlanes; }
0108
0109
0110 Standard_EXPORT bool AttachShader(const occ::handle<Graphic3d_ShaderObject>& theShader);
0111
0112
0113 Standard_EXPORT bool DetachShader(const occ::handle<Graphic3d_ShaderObject>& theShader);
0114
0115
0116 const NCollection_Sequence<occ::handle<Graphic3d_ShaderObject>>& ShaderObjects() const
0117 {
0118 return myShaderObjects;
0119 }
0120
0121
0122
0123 const NCollection_Sequence<occ::handle<Graphic3d_ShaderVariable>>& Variables() const
0124 {
0125 return myVariables;
0126 }
0127
0128
0129 const NCollection_Sequence<occ::handle<Graphic3d_ShaderAttribute>>& VertexAttributes() const
0130 {
0131 return myAttributes;
0132 }
0133
0134
0135
0136 Standard_EXPORT void SetVertexAttributes(
0137 const NCollection_Sequence<occ::handle<Graphic3d_ShaderAttribute>>& theAttributes);
0138
0139
0140
0141 int NbFragmentOutputs() const { return myNbFragOutputs; }
0142
0143
0144
0145 void SetNbFragmentOutputs(const int theNbOutputs) { myNbFragOutputs = theNbOutputs; }
0146
0147
0148 bool HasAlphaTest() const { return myHasAlphaTest; }
0149
0150
0151
0152
0153 void SetAlphaTest(bool theAlphaTest) { myHasAlphaTest = theAlphaTest; }
0154
0155
0156
0157 bool HasDefaultSampler() const { return myHasDefSampler; }
0158
0159
0160 void SetDefaultSampler(bool theHasDefSampler) { myHasDefSampler = theHasDefSampler; }
0161
0162
0163 Graphic3d_RenderTransparentMethod OitOutput() const { return myOitOutput; }
0164
0165
0166
0167
0168 void SetOitOutput(Graphic3d_RenderTransparentMethod theOutput) { myOitOutput = theOutput; }
0169
0170
0171
0172 bool IsPBR() const { return myIsPBR; }
0173
0174
0175
0176 void SetPBR(bool theIsPBR) { myIsPBR = theIsPBR; }
0177
0178
0179 int TextureSetBits() const { return myTextureSetBits; }
0180
0181
0182 void SetTextureSetBits(int theBits) { myTextureSetBits = theBits; }
0183
0184
0185
0186
0187 template <class T>
0188 bool PushVariable(const TCollection_AsciiString& theName, const T& theValue);
0189
0190
0191 Standard_EXPORT void ClearVariables();
0192
0193
0194 bool PushVariableFloat(const TCollection_AsciiString& theName, const float theValue)
0195 {
0196 return PushVariable(theName, theValue);
0197 }
0198
0199
0200 bool PushVariableVec2(const TCollection_AsciiString& theName,
0201 const NCollection_Vec2<float>& theValue)
0202 {
0203 return PushVariable(theName, theValue);
0204 }
0205
0206
0207 bool PushVariableVec3(const TCollection_AsciiString& theName,
0208 const NCollection_Vec3<float>& theValue)
0209 {
0210 return PushVariable(theName, theValue);
0211 }
0212
0213
0214 bool PushVariableVec4(const TCollection_AsciiString& theName,
0215 const NCollection_Vec4<float>& theValue)
0216 {
0217 return PushVariable(theName, theValue);
0218 }
0219
0220
0221 bool PushVariableInt(const TCollection_AsciiString& theName, const int theValue)
0222 {
0223 return PushVariable(theName, theValue);
0224 }
0225
0226
0227 bool PushVariableVec2i(const TCollection_AsciiString& theName,
0228 const NCollection_Vec2<int>& theValue)
0229 {
0230 return PushVariable(theName, theValue);
0231 }
0232
0233
0234 bool PushVariableVec3i(const TCollection_AsciiString& theName,
0235 const NCollection_Vec3<int>& theValue)
0236 {
0237 return PushVariable(theName, theValue);
0238 }
0239
0240
0241 bool PushVariableVec4i(const TCollection_AsciiString& theName,
0242 const NCollection_Vec4<int>& theValue)
0243 {
0244 return PushVariable(theName, theValue);
0245 }
0246
0247
0248 bool PushVariableMat3(const TCollection_AsciiString& theName,
0249 const NCollection_Mat3<float>& theValue)
0250 {
0251 return PushVariable(theName, theValue);
0252 }
0253
0254
0255 bool PushVariableMat4(const TCollection_AsciiString& theName,
0256 const NCollection_Mat4<float>& theValue)
0257 {
0258 return PushVariable(theName, theValue);
0259 }
0260
0261 public:
0262
0263
0264
0265 Standard_EXPORT static const TCollection_AsciiString& ShadersFolder();
0266
0267 private:
0268 TCollection_AsciiString myID;
0269 NCollection_Sequence<occ::handle<Graphic3d_ShaderObject>>
0270 myShaderObjects;
0271 NCollection_Sequence<occ::handle<Graphic3d_ShaderVariable>>
0272 myVariables;
0273 NCollection_Sequence<occ::handle<Graphic3d_ShaderAttribute>>
0274 myAttributes;
0275
0276 TCollection_AsciiString myHeader;
0277 int myNbLightsMax;
0278 int myNbShadowMaps;
0279 int myNbClipPlanesMax;
0280 int myNbFragOutputs;
0281 int myTextureSetBits;
0282 Graphic3d_RenderTransparentMethod myOitOutput;
0283 bool myHasDefSampler;
0284 bool myHasAlphaTest;
0285 bool myIsPBR;
0286
0287 };
0288
0289
0290
0291
0292
0293 template <class T>
0294 inline bool Graphic3d_ShaderProgram::PushVariable(const TCollection_AsciiString& theName,
0295 const T& theValue)
0296 {
0297 occ::handle<Graphic3d_ShaderVariable> aVariable =
0298 Graphic3d_ShaderVariable::Create(theName, theValue);
0299 if (aVariable.IsNull() || !aVariable->IsDone())
0300 {
0301 return false;
0302 }
0303
0304 myVariables.Append(aVariable);
0305 return true;
0306 }
0307
0308 #endif