1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2012 OPEN CASCADE SAS
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.
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.
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.
19 #ifndef _OpenGl_Texture_H__
20 #define _OpenGl_Texture_H__
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>
28 class Handle(OpenGl_Context);
33 class OpenGl_Texture : public OpenGl_Resource
39 static const GLuint NO_TEXTURE = 0;
43 //! Create uninitialized VBO.
44 Standard_EXPORT OpenGl_Texture (const Handle(Graphic3d_TextureParams)& theParams = NULL);
47 Standard_EXPORT virtual ~OpenGl_Texture();
49 //! @return true if current object was initialized
50 inline bool IsValid() const
52 return myTextureId != NO_TEXTURE;
55 //! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
56 inline GLenum GetTarget() const
61 //! @return texture width (0 LOD)
62 inline GLsizei SizeX() const
67 //! @return texture height (0 LOD)
68 inline GLsizei SizeY() const
73 //! @return texture ID
74 inline GLuint TextureId() const
79 //! @return texture format
80 inline GLint GetFormat() const
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);
89 //! Destroy object - will release GPU memory if any.
90 Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
92 //! Bind this Texture to specified unit.
93 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
94 const GLenum theTextureUnit = GL_TEXTURE0) const;
96 //! Unbind texture from specified unit.
97 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
98 const GLenum theTextureUnit = GL_TEXTURE0) const;
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);
105 //! @return true if texture was generated within mipmaps
106 Standard_EXPORT const Standard_Boolean HasMipmaps() const;
108 //! @return assigned texture parameters (not necessary applied)
109 Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
111 //! @param texture parameters
112 Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams);
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
123 Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
127 DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition
131 #endif // _OpenGl_Texture_H__