File indexing completed on 2025-01-18 10:04:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _OpenGl_Sampler_Header
0017 #define _OpenGl_Sampler_Header
0018
0019 #include <Graphic3d_TextureParams.hxx>
0020 #include <OpenGl_Resource.hxx>
0021
0022 class OpenGl_Texture;
0023
0024
0025
0026 class OpenGl_Sampler : public OpenGl_Resource
0027 {
0028 friend class OpenGl_Context;
0029 friend class OpenGl_Texture;
0030 friend class OpenGl_Text;
0031 DEFINE_STANDARD_RTTIEXT(OpenGl_Sampler, OpenGl_Resource)
0032 public:
0033
0034
0035 static const unsigned int NO_SAMPLER = 0;
0036
0037 public:
0038
0039
0040 Standard_EXPORT OpenGl_Sampler (const Handle(Graphic3d_TextureParams)& theParams);
0041
0042
0043 Standard_EXPORT virtual ~OpenGl_Sampler();
0044
0045
0046 Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
0047
0048
0049 virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
0050
0051
0052 Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theContext);
0053
0054
0055
0056
0057 Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theContext,
0058 const OpenGl_Texture& theTexture);
0059
0060
0061 Standard_Boolean IsValid() const
0062 {
0063 return isValidSampler();
0064 }
0065
0066
0067 void Bind (const Handle(OpenGl_Context)& theCtx)
0068 {
0069 Bind (theCtx, myParams->TextureUnit());
0070 }
0071
0072
0073 void Unbind (const Handle(OpenGl_Context)& theCtx)
0074 {
0075 Unbind (theCtx, myParams->TextureUnit());
0076 }
0077
0078
0079 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
0080 const Graphic3d_TextureUnit theUnit);
0081
0082
0083 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
0084 const Graphic3d_TextureUnit theUnit);
0085
0086
0087 void SetParameter (const Handle(OpenGl_Context)& theCtx,
0088 unsigned int theTarget,
0089 unsigned int theParam,
0090 Standard_Integer theValue)
0091 {
0092 setParameter (theCtx, this, theTarget, theParam, theValue);
0093 }
0094
0095
0096 unsigned int SamplerID() const
0097 {
0098 return mySamplerID;
0099 }
0100
0101
0102
0103 bool IsImmutable() const { return myIsImmutable; }
0104
0105
0106 void SetImmutable() { myIsImmutable = true; }
0107
0108
0109 const Handle(Graphic3d_TextureParams)& Parameters() { return myParams; }
0110
0111
0112 Standard_EXPORT void SetParameters (const Handle(Graphic3d_TextureParams)& theParams);
0113
0114
0115 bool ToUpdateParameters() const { return mySamplerRevision != myParams->SamplerRevision(); }
0116
0117 protected:
0118
0119
0120 Standard_Boolean isValidSampler() const
0121 {
0122 return mySamplerID != NO_SAMPLER;
0123 }
0124
0125
0126 Standard_EXPORT static void setParameter (const Handle(OpenGl_Context)& theContext,
0127 OpenGl_Sampler* theSampler,
0128 unsigned int theTarget,
0129 unsigned int theParam,
0130 Standard_Integer theValue);
0131
0132
0133
0134
0135
0136
0137
0138
0139 Standard_EXPORT static void applySamplerParams (const Handle(OpenGl_Context)& theCtx,
0140 const Handle(Graphic3d_TextureParams)& theParams,
0141 OpenGl_Sampler* theSampler,
0142 const unsigned int theTarget,
0143 const Standard_Integer theMaxMipLevel);
0144
0145
0146 Standard_EXPORT static void applyGlobalTextureParams (const Handle(OpenGl_Context)& theCtx,
0147 const OpenGl_Texture& theTexture,
0148 const Handle(Graphic3d_TextureParams)& theParams);
0149
0150
0151 Standard_EXPORT static void resetGlobalTextureParams (const Handle(OpenGl_Context)& theCtx,
0152 const OpenGl_Texture& theTexture,
0153 const Handle(Graphic3d_TextureParams)& theParams);
0154
0155 protected:
0156
0157 Handle(Graphic3d_TextureParams) myParams;
0158 unsigned int mySamplerRevision;
0159 unsigned int mySamplerID;
0160 bool myIsImmutable;
0161
0162 };
0163
0164 DEFINE_STANDARD_HANDLE(OpenGl_Sampler, OpenGl_Resource)
0165
0166 #endif