File indexing completed on 2024-11-15 09:47:01
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 typedef NCollection_Sequence<Handle(Graphic3d_ShaderObject)> Graphic3d_ShaderObjectList;
0028
0029
0030 typedef NCollection_Sequence<Handle(Graphic3d_ShaderVariable)> Graphic3d_ShaderVariableList;
0031
0032
0033 typedef NCollection_Sequence<Handle(Graphic3d_ShaderAttribute)> Graphic3d_ShaderAttributeList;
0034
0035
0036 class Graphic3d_ShaderProgram : public Standard_Transient
0037 {
0038 DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderProgram, Standard_Transient)
0039 public:
0040
0041
0042 static const Standard_Integer THE_MAX_LIGHTS_DEFAULT = 8;
0043
0044
0045 static const Standard_Integer THE_MAX_CLIP_PLANES_DEFAULT = 8;
0046
0047
0048 static const Standard_Integer THE_NB_FRAG_OUTPUTS = 1;
0049
0050 public:
0051
0052
0053 Standard_EXPORT Graphic3d_ShaderProgram();
0054
0055
0056 Standard_EXPORT virtual ~Graphic3d_ShaderProgram();
0057
0058
0059 Standard_EXPORT virtual Standard_Boolean IsDone() const;
0060
0061
0062 const TCollection_AsciiString& GetId() const { return myID; }
0063
0064
0065
0066
0067 void SetId (const TCollection_AsciiString& theId) { myID = theId; }
0068
0069
0070 const TCollection_AsciiString& Header() const { return myHeader; }
0071
0072
0073
0074
0075
0076
0077
0078
0079 void SetHeader (const TCollection_AsciiString& theHeader) { myHeader = theHeader; }
0080
0081
0082 void AppendToHeader (const TCollection_AsciiString& theHeaderLine)
0083 {
0084 if (!myHeader.IsEmpty())
0085 {
0086 myHeader += "\n";
0087 }
0088 myHeader += theHeaderLine;
0089 }
0090
0091
0092
0093
0094 Standard_Integer NbLightsMax() const { return myNbLightsMax; }
0095
0096
0097 void SetNbLightsMax (Standard_Integer theNbLights) { myNbLightsMax = theNbLights; }
0098
0099
0100 Standard_Integer NbShadowMaps() const { return myNbShadowMaps; }
0101
0102
0103 void SetNbShadowMaps (Standard_Integer theNbMaps) { myNbShadowMaps = theNbMaps; }
0104
0105
0106
0107
0108 Standard_Integer NbClipPlanesMax() const { return myNbClipPlanesMax; }
0109
0110
0111 void SetNbClipPlanesMax (Standard_Integer theNbPlanes) { myNbClipPlanesMax = theNbPlanes; }
0112
0113
0114 Standard_EXPORT Standard_Boolean AttachShader (const Handle(Graphic3d_ShaderObject)& theShader);
0115
0116
0117 Standard_EXPORT Standard_Boolean DetachShader (const Handle(Graphic3d_ShaderObject)& theShader);
0118
0119
0120 const Graphic3d_ShaderObjectList& ShaderObjects() const { return myShaderObjects; }
0121
0122
0123
0124 const Graphic3d_ShaderVariableList& Variables() const { return myVariables; }
0125
0126
0127 const Graphic3d_ShaderAttributeList& VertexAttributes() const { return myAttributes; }
0128
0129
0130
0131 Standard_EXPORT void SetVertexAttributes (const Graphic3d_ShaderAttributeList& theAttributes);
0132
0133
0134
0135 Standard_Integer NbFragmentOutputs() const { return myNbFragOutputs; }
0136
0137
0138
0139 void SetNbFragmentOutputs (const Standard_Integer theNbOutputs) { myNbFragOutputs = theNbOutputs; }
0140
0141
0142 Standard_Boolean HasAlphaTest() const { return myHasAlphaTest; }
0143
0144
0145
0146 void SetAlphaTest (Standard_Boolean theAlphaTest) { myHasAlphaTest = theAlphaTest; }
0147
0148
0149 Standard_Boolean HasDefaultSampler() const { return myHasDefSampler; }
0150
0151
0152 void SetDefaultSampler (Standard_Boolean theHasDefSampler) { myHasDefSampler = theHasDefSampler; }
0153
0154
0155 Graphic3d_RenderTransparentMethod OitOutput() const { return myOitOutput; }
0156
0157
0158
0159
0160 void SetOitOutput (Graphic3d_RenderTransparentMethod theOutput) { myOitOutput = theOutput; }
0161
0162
0163
0164 Standard_Boolean IsPBR() const { return myIsPBR; }
0165
0166
0167 void SetPBR (Standard_Boolean theIsPBR) { myIsPBR = theIsPBR; }
0168
0169
0170 Standard_Integer TextureSetBits() const { return myTextureSetBits; }
0171
0172
0173 void SetTextureSetBits (Standard_Integer theBits) { myTextureSetBits = theBits; }
0174
0175
0176
0177
0178 template<class T>
0179 Standard_Boolean PushVariable (const TCollection_AsciiString& theName,
0180 const T& theValue);
0181
0182
0183 Standard_EXPORT void ClearVariables();
0184
0185
0186 Standard_Boolean PushVariableFloat (const TCollection_AsciiString& theName, const float theValue) { return PushVariable (theName, theValue); }
0187
0188
0189 Standard_Boolean PushVariableVec2 (const TCollection_AsciiString& theName, const Graphic3d_Vec2& theValue) { return PushVariable (theName, theValue); }
0190
0191
0192 Standard_Boolean PushVariableVec3 (const TCollection_AsciiString& theName, const Graphic3d_Vec3& theValue) { return PushVariable (theName, theValue); }
0193
0194
0195 Standard_Boolean PushVariableVec4 (const TCollection_AsciiString& theName, const Graphic3d_Vec4& theValue) { return PushVariable (theName, theValue); }
0196
0197
0198 Standard_Boolean PushVariableInt (const TCollection_AsciiString& theName, const int theValue) { return PushVariable (theName, theValue); }
0199
0200
0201 Standard_Boolean PushVariableVec2i (const TCollection_AsciiString& theName, const Graphic3d_Vec2i& theValue) { return PushVariable (theName, theValue); }
0202
0203
0204 Standard_Boolean PushVariableVec3i (const TCollection_AsciiString& theName, const Graphic3d_Vec3i& theValue) { return PushVariable (theName, theValue); }
0205
0206
0207 Standard_Boolean PushVariableVec4i (const TCollection_AsciiString& theName, const Graphic3d_Vec4i& theValue) { return PushVariable (theName, theValue); }
0208
0209 public:
0210
0211
0212
0213 Standard_EXPORT static const TCollection_AsciiString& ShadersFolder();
0214
0215 private:
0216
0217 TCollection_AsciiString myID;
0218 Graphic3d_ShaderObjectList myShaderObjects;
0219 Graphic3d_ShaderVariableList myVariables;
0220 Graphic3d_ShaderAttributeList myAttributes;
0221 TCollection_AsciiString myHeader;
0222 Standard_Integer myNbLightsMax;
0223 Standard_Integer myNbShadowMaps;
0224 Standard_Integer myNbClipPlanesMax;
0225 Standard_Integer myNbFragOutputs;
0226 Standard_Integer myTextureSetBits;
0227 Graphic3d_RenderTransparentMethod myOitOutput;
0228 Standard_Boolean myHasDefSampler;
0229 Standard_Boolean myHasAlphaTest;
0230 Standard_Boolean myIsPBR;
0231
0232 };
0233
0234 DEFINE_STANDARD_HANDLE (Graphic3d_ShaderProgram, Standard_Transient)
0235
0236
0237
0238
0239
0240 template<class T> inline
0241 Standard_Boolean Graphic3d_ShaderProgram::PushVariable (const TCollection_AsciiString& theName,
0242 const T& theValue)
0243 {
0244 Handle(Graphic3d_ShaderVariable) aVariable = Graphic3d_ShaderVariable::Create (theName, theValue);
0245 if (aVariable.IsNull() || !aVariable->IsDone())
0246 {
0247 return Standard_False;
0248 }
0249
0250 myVariables.Append (aVariable);
0251 return Standard_True;
0252 }
0253
0254 #endif