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 #ifndef OpenGl_Texture_HeaderFile
0016 #define OpenGl_Texture_HeaderFile
0017
0018 #include <Graphic3d_CubeMap.hxx>
0019 #include <Graphic3d_Vec3.hxx>
0020 #include <OpenGl_TextureFormat.hxx>
0021 #include <OpenGl_NamedResource.hxx>
0022 #include <OpenGl_Sampler.hxx>
0023 #include <Graphic3d_TextureUnit.hxx>
0024 #include <Graphic3d_TypeOfTexture.hxx>
0025
0026
0027
0028 class OpenGl_Texture : public OpenGl_NamedResource
0029 {
0030 DEFINE_STANDARD_RTTIEXT(OpenGl_Texture, OpenGl_NamedResource)
0031 public:
0032
0033
0034 static const unsigned int NO_TEXTURE = 0;
0035
0036
0037
0038
0039 Standard_EXPORT static Standard_Size PixelSizeOfPixelFormat (Standard_Integer theInternalFormat);
0040
0041 public:
0042
0043
0044 Standard_EXPORT OpenGl_Texture (const TCollection_AsciiString& theResourceId = TCollection_AsciiString(),
0045 const Handle(Graphic3d_TextureParams)& theParams = Handle(Graphic3d_TextureParams)());
0046
0047
0048 Standard_EXPORT virtual ~OpenGl_Texture();
0049
0050
0051 virtual bool IsValid() const { return myTextureId != NO_TEXTURE; }
0052
0053
0054 unsigned int GetTarget() const { return myTarget; }
0055
0056
0057 const Graphic3d_Vec3i& Size() const { return mySize; }
0058
0059
0060 Standard_Integer SizeX() const { return mySize.x(); }
0061
0062
0063 Standard_Integer SizeY() const { return mySize.y(); }
0064
0065
0066 Standard_Integer SizeZ() const { return mySize.z(); }
0067
0068
0069 unsigned int TextureId() const { return myTextureId; }
0070
0071
0072 unsigned int GetFormat() const { return myTextFormat; }
0073
0074
0075 Standard_Integer SizedFormat() const { return mySizedFormat; }
0076
0077
0078 bool IsAlpha() const { return myIsAlpha; }
0079
0080
0081
0082 void SetAlpha (const bool theValue) { myIsAlpha = theValue; }
0083
0084
0085
0086 bool IsTopDown() const { return myIsTopDown; }
0087
0088
0089 void SetTopDown (bool theIsTopDown) { myIsTopDown = theIsTopDown; }
0090
0091
0092
0093 Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theCtx);
0094
0095
0096 Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
0097
0098
0099 const Handle(OpenGl_Sampler)& Sampler() const { return mySampler; }
0100
0101
0102 void SetSampler (const Handle(OpenGl_Sampler)& theSampler) { mySampler = theSampler; }
0103
0104
0105
0106 Standard_EXPORT bool InitSamplerObject (const Handle(OpenGl_Context)& theCtx);
0107
0108
0109
0110 void Bind (const Handle(OpenGl_Context)& theCtx) const
0111 {
0112 Bind (theCtx, mySampler->Parameters()->TextureUnit());
0113 }
0114
0115
0116
0117 void Unbind (const Handle(OpenGl_Context)& theCtx) const
0118 {
0119 Unbind (theCtx, mySampler->Parameters()->TextureUnit());
0120 }
0121
0122
0123
0124 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
0125 const Graphic3d_TextureUnit theTextureUnit) const;
0126
0127
0128
0129 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
0130 const Graphic3d_TextureUnit theTextureUnit) const;
0131
0132
0133 Standard_Size Revision() const { return myRevision; }
0134
0135
0136 void SetRevision (const Standard_Size theRevision) { myRevision = theRevision; }
0137
0138
0139 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
0140 const Image_PixMap& theImage,
0141 const Graphic3d_TypeOfTexture theType,
0142 const Standard_Boolean theIsColorMap);
0143
0144
0145
0146
0147 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
0148 const OpenGl_TextureFormat& theFormat,
0149 const Graphic3d_Vec3i& theSizeXYZ,
0150 const Graphic3d_TypeOfTexture theType,
0151 const Image_PixMap* theImage = NULL);
0152
0153
0154
0155
0156 bool Init (const Handle(OpenGl_Context)& theCtx,
0157 const OpenGl_TextureFormat& theFormat,
0158 const Graphic3d_Vec2i& theSizeXY,
0159 const Graphic3d_TypeOfTexture theType,
0160 const Image_PixMap* theImage = NULL)
0161 {
0162 return Init (theCtx, theFormat, Graphic3d_Vec3i (theSizeXY, 1), theType, theImage);
0163 }
0164
0165
0166
0167
0168 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
0169 const Handle(Graphic3d_TextureRoot)& theTextureMap);
0170
0171
0172 Standard_EXPORT bool GenerateMipmaps (const Handle(OpenGl_Context)& theCtx);
0173
0174
0175 Standard_EXPORT bool InitCompressed (const Handle(OpenGl_Context)& theCtx,
0176 const Image_CompressedPixMap& theImage,
0177 const Standard_Boolean theIsColorMap);
0178
0179
0180 Standard_EXPORT bool Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
0181 const Standard_Integer theNbSamples,
0182 const Standard_Integer theTextFormat,
0183 const Standard_Integer theSizeX,
0184 const Standard_Integer theSizeY);
0185
0186
0187
0188 Standard_EXPORT bool InitRectangle (const Handle(OpenGl_Context)& theCtx,
0189 const Standard_Integer theSizeX,
0190 const Standard_Integer theSizeY,
0191 const OpenGl_TextureFormat& theFormat);
0192
0193
0194 Standard_EXPORT bool Init3D (const Handle(OpenGl_Context)& theCtx,
0195 const OpenGl_TextureFormat& theFormat,
0196 const Graphic3d_Vec3i& theSizeXYZ,
0197 const void* thePixels);
0198
0199
0200 Standard_Boolean HasMipmaps() const { return myMaxMipLevel > 0; }
0201
0202
0203 Standard_Integer MaxMipmapLevel() const { return myMaxMipLevel; }
0204
0205
0206 Standard_Integer NbSamples() const { return myNbSamples; }
0207
0208
0209 Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
0210
0211
0212 virtual bool IsPointSprite() const { return false; }
0213
0214
0215
0216
0217
0218
0219
0220
0221 Standard_EXPORT bool ImageDump (Image_PixMap& theImage,
0222 const Handle(OpenGl_Context)& theCtx,
0223 Graphic3d_TextureUnit theTexUnit,
0224 Standard_Integer theLevel = 0,
0225 Standard_Integer theCubeSide = 0) const;
0226
0227 public:
0228
0229 Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")
0230 static bool GetDataFormat (const Handle(OpenGl_Context)& theCtx,
0231 const Image_Format theFormat,
0232 Standard_Integer& theTextFormat,
0233 unsigned int& thePixelFormat,
0234 unsigned int& theDataType)
0235 {
0236 OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindFormat (theCtx, theFormat, false);
0237 theTextFormat = aFormat.InternalFormat();
0238 thePixelFormat = aFormat.PixelFormat();
0239 theDataType = aFormat.DataType();
0240 return aFormat.IsValid();
0241 }
0242
0243 Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")
0244 static bool GetDataFormat (const Handle(OpenGl_Context)& theCtx,
0245 const Image_PixMap& theData,
0246 Standard_Integer& theTextFormat,
0247 unsigned int& thePixelFormat,
0248 unsigned int& theDataType)
0249 {
0250 OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindFormat (theCtx, theData.Format(), false);
0251 theTextFormat = aFormat.InternalFormat();
0252 thePixelFormat = aFormat.PixelFormat();
0253 theDataType = aFormat.DataType();
0254 return aFormat.IsValid();
0255 }
0256
0257 Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")
0258 bool Init (const Handle(OpenGl_Context)& theCtx,
0259 const Standard_Integer theTextFormat,
0260 const unsigned int thePixelFormat,
0261 const unsigned int theDataType,
0262 const Standard_Integer theSizeX,
0263 const Standard_Integer theSizeY,
0264 const Graphic3d_TypeOfTexture theType,
0265 const Image_PixMap* theImage = NULL)
0266 {
0267 OpenGl_TextureFormat aFormat;
0268 aFormat.SetInternalFormat (theTextFormat);
0269 aFormat.SetPixelFormat (thePixelFormat);
0270 aFormat.SetDataType (theDataType);
0271 return Init (theCtx, aFormat, Graphic3d_Vec2i (theSizeX, theSizeY), theType, theImage);
0272 }
0273
0274 Standard_DEPRECATED("Deprecated method, theIsColorMap parameter should be explicitly specified")
0275 bool Init (const Handle(OpenGl_Context)& theCtx,
0276 const Image_PixMap& theImage,
0277 const Graphic3d_TypeOfTexture theType)
0278 {
0279 return Init (theCtx, theImage, theType, true);
0280 }
0281
0282 Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")
0283 bool Init3D (const Handle(OpenGl_Context)& theCtx,
0284 const Standard_Integer theTextFormat,
0285 const unsigned int thePixelFormat,
0286 const unsigned int theDataType,
0287 const Standard_Integer theSizeX,
0288 const Standard_Integer theSizeY,
0289 const Standard_Integer theSizeZ,
0290 const void* thePixels)
0291 {
0292 OpenGl_TextureFormat aFormat;
0293 aFormat.SetInternalFormat (theTextFormat);
0294 aFormat.SetPixelFormat (thePixelFormat);
0295 aFormat.SetDataType (theDataType);
0296 return Init3D (theCtx, aFormat, Graphic3d_Vec3i (theSizeX, theSizeY, theSizeZ), thePixels);
0297 }
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 Standard_EXPORT bool InitCubeMap (const Handle(OpenGl_Context)& theCtx,
0309 const Handle(Graphic3d_CubeMap)& theCubeMap,
0310 Standard_Size theSize,
0311 Image_Format theFormat,
0312 Standard_Boolean theToGenMipmap,
0313 Standard_Boolean theIsColorMap);
0314
0315 protected:
0316
0317
0318 Standard_EXPORT void applyDefaultSamplerParams (const Handle(OpenGl_Context)& theCtx);
0319
0320 protected:
0321
0322 Handle(OpenGl_Sampler) mySampler;
0323 Standard_Size myRevision;
0324 unsigned int myTextureId;
0325 unsigned int myTarget;
0326 Graphic3d_Vec3i mySize;
0327 unsigned int myTextFormat;
0328 Standard_Integer mySizedFormat;
0329 Standard_Integer myNbSamples;
0330 Standard_Integer myMaxMipLevel;
0331 bool myIsAlpha;
0332 bool myIsTopDown;
0333
0334 };
0335
0336 DEFINE_STANDARD_HANDLE(OpenGl_Texture, OpenGl_NamedResource)
0337
0338 #endif