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