File indexing completed on 2025-01-18 10:03:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _Graphic3d_ShaderManager_HeaderFile
0015 #define _Graphic3d_ShaderManager_HeaderFile
0016
0017 #include <Aspect_GraphicsLibrary.hxx>
0018 #include <Graphic3d_ShaderFlags.hxx>
0019 #include <Graphic3d_StereoMode.hxx>
0020 #include <Graphic3d_Vec2.hxx>
0021 #include <Standard_Transient.hxx>
0022 #include <TCollection_AsciiString.hxx>
0023
0024 class Graphic3d_LightSet;
0025 class Graphic3d_ShaderProgram;
0026
0027
0028 enum Graphic3d_GlslExtension
0029 {
0030 Graphic3d_GlslExtension_GL_OES_standard_derivatives,
0031 Graphic3d_GlslExtension_GL_EXT_shader_texture_lod,
0032 Graphic3d_GlslExtension_GL_EXT_frag_depth,
0033 Graphic3d_GlslExtension_GL_EXT_gpu_shader4,
0034 };
0035 enum { Graphic3d_GlslExtension_NB = Graphic3d_GlslExtension_GL_EXT_gpu_shader4 + 1 };
0036
0037
0038 class Graphic3d_ShaderManager : public Standard_Transient
0039 {
0040 DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderManager, Standard_Transient)
0041 public:
0042
0043
0044 Standard_EXPORT Graphic3d_ShaderManager (Aspect_GraphicsLibrary theGapi);
0045
0046
0047 Standard_EXPORT virtual ~Graphic3d_ShaderManager();
0048
0049
0050 bool IsGapiGreaterEqual (Standard_Integer theVerMajor,
0051 Standard_Integer theVerMinor) const
0052 {
0053 return (myGapiVersion[0] > theVerMajor)
0054 || (myGapiVersion[0] == theVerMajor && myGapiVersion[1] >= theVerMinor);
0055 }
0056
0057
0058 Standard_Integer GapiVersionMajor() const { return myGapiVersion[0]; }
0059
0060
0061 Standard_Integer GapiVersionMinor() const { return myGapiVersion[1]; }
0062
0063
0064 void SetGapiVersion (Standard_Integer theVerMajor,
0065 Standard_Integer theVerMinor)
0066 {
0067 myGapiVersion.SetValues (theVerMajor, theVerMinor);
0068 }
0069
0070
0071
0072 bool UseRedAlpha() const { return myUseRedAlpha; }
0073
0074
0075 void SetUseRedAlpha (bool theUseRedAlpha) { myUseRedAlpha = theUseRedAlpha; }
0076
0077
0078 bool HasFlatShading() const { return myHasFlatShading; }
0079
0080
0081 bool ToReverseDFdxSign() const { return myToReverseDFdxSign; }
0082
0083
0084 void SetFlatShading (bool theToUse,
0085 bool theToReverseSign)
0086 {
0087 myHasFlatShading = theToUse;
0088 myToReverseDFdxSign = theToReverseSign;
0089 }
0090
0091
0092 bool ToEmulateDepthClamp() const { return myToEmulateDepthClamp; }
0093
0094
0095 void SetEmulateDepthClamp (bool theToEmulate) { myToEmulateDepthClamp = theToEmulate; }
0096
0097
0098 bool HasGlslExtension (Graphic3d_GlslExtension theExt) const { return myGlslExtensions[theExt]; }
0099
0100
0101 void EnableGlslExtension (Graphic3d_GlslExtension theExt,
0102 bool theToEnable = true) { myGlslExtensions[theExt] = theToEnable; }
0103
0104 protected:
0105
0106
0107
0108
0109 Standard_EXPORT TCollection_AsciiString genLightKey (const Handle(Graphic3d_LightSet)& theLights,
0110 const bool theHasShadowMap) const;
0111
0112
0113 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramFont() const;
0114
0115
0116
0117
0118 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramUnlit (Standard_Integer theBits,
0119 Standard_Boolean theIsOutline = false) const;
0120
0121
0122
0123
0124 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramGouraud (const Handle(Graphic3d_LightSet)& theLights,
0125 Standard_Integer theBits) const;
0126
0127
0128
0129
0130
0131
0132
0133 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramPhong (const Handle(Graphic3d_LightSet)& theLights,
0134 const Standard_Integer theBits,
0135 const Standard_Boolean theIsFlatNormal,
0136 const Standard_Boolean theIsPBR,
0137 const Standard_Integer theNbShadowMaps) const;
0138
0139
0140 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramBoundBox() const;
0141
0142
0143 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getBgCubeMapProgram() const;
0144
0145
0146 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getBgSkydomeProgram() const;
0147
0148
0149 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getColoredQuadProgram() const;
0150
0151
0152 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getPBREnvBakingProgram (Standard_Integer theIndex) const;
0153
0154
0155 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramFboBlit (Standard_Integer theNbSamples,
0156 Standard_Boolean theIsFallback_sRGB) const;
0157
0158
0159 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramStereo (Graphic3d_StereoMode theStereoMode) const;
0160
0161
0162 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramOitCompositing (Standard_Boolean theMsaa) const;
0163
0164
0165 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramOitDepthPeelingBlend (Standard_Boolean theMsaa) const;
0166
0167
0168 Standard_EXPORT Handle(Graphic3d_ShaderProgram) getStdProgramOitDepthPeelingFlush (Standard_Boolean theMsaa) const;
0169
0170 protected:
0171
0172
0173 Standard_EXPORT bool hasGlslBitwiseOps() const;
0174
0175
0176
0177
0178
0179
0180
0181 Standard_EXPORT Standard_Integer defaultGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
0182 const TCollection_AsciiString& theName,
0183 Standard_Integer theBits,
0184 bool theUsesDerivates = false) const;
0185
0186
0187
0188
0189
0190 Standard_EXPORT void defaultOitGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
0191 const TCollection_AsciiString& theName,
0192 bool theMsaa) const;
0193
0194
0195 Standard_EXPORT TCollection_AsciiString pointSpriteAlphaSrc (Standard_Integer theBits) const;
0196
0197
0198 Standard_EXPORT TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString& theBaseColorSrc,
0199 Standard_Integer theBits) const;
0200
0201
0202
0203
0204
0205
0206
0207
0208 Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights,
0209 const Handle(Graphic3d_LightSet)& theLights,
0210 Standard_Boolean theHasVertColor,
0211 Standard_Boolean theIsPBR,
0212 Standard_Boolean theHasTexColor,
0213 Standard_Integer theNbShadowMaps) const;
0214
0215 protected:
0216
0217 Aspect_GraphicsLibrary myGapi;
0218 Graphic3d_Vec2i myGapiVersion;
0219 Standard_Boolean myGlslExtensions[Graphic3d_GlslExtension_NB];
0220 Standard_Boolean myHasFlatShading;
0221 Standard_Boolean myToReverseDFdxSign;
0222 Standard_Boolean mySetPointSize;
0223 Standard_Boolean myUseRedAlpha;
0224 Standard_Boolean myToEmulateDepthClamp;
0225 Standard_Boolean mySRgbState;
0226
0227 };
0228
0229 #endif