0023632: Add support for NPOT mipmap textures in TKOpenGl
[occt.git] / src / OpenGl / OpenGl_Texture.hxx
1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 #ifndef _OpenGl_Texture_H__
20 #define _OpenGl_Texture_H__
21
22 #include <OpenGl_GlCore13.hxx>
23 #include <OpenGl_Resource.hxx>
24 #include <Handle_OpenGl_Texture.hxx>
25 #include <Graphic3d_TypeOfTexture.hxx>
26 #include <Handle_Graphic3d_TextureParams.hxx>
27
28 class Handle(OpenGl_Context);
29 class OpenGl_Context;
30 class Image_PixMap;
31
32 //! Texture resource.
33 class OpenGl_Texture : public OpenGl_Resource
34 {
35
36 public:
37
38   //! Helpful constants
39   static const GLuint NO_TEXTURE = 0;
40
41 public:
42
43   //! Create uninitialized VBO.
44   Standard_EXPORT OpenGl_Texture (const Handle(Graphic3d_TextureParams)& theParams = NULL);
45
46   //! Destroy object.
47   Standard_EXPORT virtual ~OpenGl_Texture();
48
49   //! @return true if current object was initialized
50   inline bool IsValid() const
51   {
52     return myTextureId != NO_TEXTURE;
53   }
54
55   //! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
56   inline GLenum GetTarget() const
57   {
58     return myTarget;
59   }
60
61   //! Creates Texture id if not yet generated.
62   //! Data should be initialized by another method.
63   Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theCtx);
64
65   //! Destroy object - will release GPU memory if any.
66   Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
67
68   //! Bind this Texture to specified unit.
69   Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
70                              const GLenum                  theTextureUnit = GL_TEXTURE0) const;
71
72   //! Unbind texture from specified unit.
73   Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
74                                const GLenum                  theTextureUnit = GL_TEXTURE0) const;
75
76   //! Notice that texture will be unbound after this call.
77   Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
78                              const Image_PixMap&           theImage,
79                              const Graphic3d_TypeOfTexture theType);
80
81   //! @return true if texture was generated within mipmaps
82   Standard_EXPORT const Standard_Boolean HasMipmaps() const;
83
84   //! @return assigned texture parameters (not necessary applied)
85   Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
86
87   //! @param texture parameters
88   Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams);
89
90 protected:
91
92   GLuint           myTextureId;  //!< GL resource ID
93   GLenum           myTarget;     //!< GL_TEXTURE_1D/GL_TEXTURE_2D
94   GLsizei          mySizeX;      //!< texture width
95   GLsizei          mySizeY;      //!< texture height
96   GLint            myTextFormat; //!< texture format - GL_RGB, GL_RGBA,...
97   Standard_Boolean myHasMipmaps; //!< flag indicates that texture was uploaded with mipmaps
98
99   Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
100
101 public:
102
103   DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition
104
105 };
106
107 #endif // _OpenGl_Texture_H__