1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _OpenGl_Texture_H__
16 #define _OpenGl_Texture_H__
18 #include <OpenGl_GlCore13.hxx>
19 #include <OpenGl_Resource.hxx>
20 #include <Handle_OpenGl_Texture.hxx>
21 #include <Graphic3d_TypeOfTexture.hxx>
22 #include <Handle_Graphic3d_TextureParams.hxx>
24 class Handle(OpenGl_Context);
29 class OpenGl_Texture : public OpenGl_Resource
35 static const GLuint NO_TEXTURE = 0;
39 //! Create uninitialized VBO.
40 Standard_EXPORT OpenGl_Texture (const Handle(Graphic3d_TextureParams)& theParams = NULL);
43 Standard_EXPORT virtual ~OpenGl_Texture();
45 //! @return true if current object was initialized
46 inline bool IsValid() const
48 return myTextureId != NO_TEXTURE;
51 //! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
52 inline GLenum GetTarget() const
57 //! @return texture width (0 LOD)
58 inline GLsizei SizeX() const
63 //! @return texture height (0 LOD)
64 inline GLsizei SizeY() const
69 //! @return texture ID
70 inline GLuint TextureId() const
75 //! @return texture format
76 inline GLint GetFormat() const
81 //! Creates Texture id if not yet generated.
82 //! Data should be initialized by another method.
83 Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theCtx);
85 //! Destroy object - will release GPU memory if any.
86 Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
88 //! Bind this Texture to specified unit.
89 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
90 const GLenum theTextureUnit = GL_TEXTURE0) const;
92 //! Unbind texture from specified unit.
93 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
94 const GLenum theTextureUnit = GL_TEXTURE0) const;
96 //! Notice that texture will be unbound after this call.
97 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx,
98 const Image_PixMap& theImage,
99 const Graphic3d_TypeOfTexture theType);
101 //! @return true if texture was generated within mipmaps
102 Standard_EXPORT const Standard_Boolean HasMipmaps() const;
104 //! @return assigned texture parameters (not necessary applied)
105 Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
107 //! @param texture parameters
108 Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams);
112 GLuint myTextureId; //!< GL resource ID
113 GLenum myTarget; //!< GL_TEXTURE_1D/GL_TEXTURE_2D
114 GLsizei mySizeX; //!< texture width
115 GLsizei mySizeY; //!< texture height
116 GLint myTextFormat; //!< texture format - GL_RGB, GL_RGBA,...
117 Standard_Boolean myHasMipmaps; //!< flag indicates that texture was uploaded with mipmaps
119 Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
123 DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition
127 #endif // _OpenGl_Texture_H__