0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[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   //! @return texture width (0 LOD)
62   inline GLsizei SizeX() const
63   {
64     return mySizeX;
65   }
66
67   //! @return texture height (0 LOD)
68   inline GLsizei SizeY() const
69   {
70     return mySizeY;
71   }
72
73   //! @return texture ID
74   inline GLuint TextureId() const
75   {
76     return myTextureId;
77   }
78
79   //! @return texture format
80   inline GLint GetFormat() const
81   {
82     return myTextFormat;
83   }
84
85   //! Creates Texture id if not yet generated.
86   //! Data should be initialized by another method.
87   Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theCtx);
88
89   //! Destroy object - will release GPU memory if any.
90   Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
91
92   //! Bind this Texture to specified unit.
93   Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
94                              const GLenum                  theTextureUnit = GL_TEXTURE0) const;
95
96   //! Unbind texture from specified unit.
97   Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
98                                const GLenum                  theTextureUnit = GL_TEXTURE0) const;
99
100   //! Notice that texture will be unbound after this call.
101   Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
102                              const Image_PixMap&           theImage,
103                              const Graphic3d_TypeOfTexture theType);
104
105   //! @return true if texture was generated within mipmaps
106   Standard_EXPORT const Standard_Boolean HasMipmaps() const;
107
108   //! @return assigned texture parameters (not necessary applied)
109   Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
110
111   //! @param texture parameters
112   Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams);
113
114 protected:
115
116   GLuint           myTextureId;  //!< GL resource ID
117   GLenum           myTarget;     //!< GL_TEXTURE_1D/GL_TEXTURE_2D
118   GLsizei          mySizeX;      //!< texture width
119   GLsizei          mySizeY;      //!< texture height
120   GLint            myTextFormat; //!< texture format - GL_RGB, GL_RGBA,...
121   Standard_Boolean myHasMipmaps; //!< flag indicates that texture was uploaded with mipmaps
122
123   Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
124
125 public:
126
127   DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition
128
129 };
130
131 #endif // _OpenGl_Texture_H__