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 //! 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);
65 //! Destroy object - will release GPU memory if any.
66 Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
68 //! Bind this Texture to specified unit.
69 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
70 const GLenum theTextureUnit = GL_TEXTURE0) const;
72 //! Unbind texture from specified unit.
73 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
74 const GLenum theTextureUnit = GL_TEXTURE0) const;
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);
81 //! @return true if texture was generated within mipmaps
82 Standard_EXPORT const Standard_Boolean HasMipmaps() const;
84 //! @return assigned texture parameters (not necessary applied)
85 Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
87 //! @param texture parameters
88 Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams);
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
99 Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
103 DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition
107 #endif // _OpenGl_Texture_H__