0024521: Visualization - automatic back face culling is not turned on for Solids...
[occt.git] / src / OpenGl / OpenGl_Texture.hxx
CommitLineData
bf75be98 1// Created by: Kirill GAVRILOV
973c2be1 2// Copyright (c) 2014 OPEN CASCADE SAS
bf75be98 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
bf75be98 5//
973c2be1 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.
bf75be98 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
bf75be98 14
15#ifndef _OpenGl_Texture_H__
16#define _OpenGl_Texture_H__
17
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>
23
24class Handle(OpenGl_Context);
25class OpenGl_Context;
26class Image_PixMap;
27
28//! Texture resource.
29class OpenGl_Texture : public OpenGl_Resource
30{
31
32public:
33
34 //! Helpful constants
35 static const GLuint NO_TEXTURE = 0;
36
37public:
38
39 //! Create uninitialized VBO.
40 Standard_EXPORT OpenGl_Texture (const Handle(Graphic3d_TextureParams)& theParams = NULL);
41
42 //! Destroy object.
43 Standard_EXPORT virtual ~OpenGl_Texture();
44
45 //! @return true if current object was initialized
46 inline bool IsValid() const
47 {
48 return myTextureId != NO_TEXTURE;
49 }
50
51 //! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
52 inline GLenum GetTarget() const
53 {
54 return myTarget;
55 }
56
a174a3c5 57 //! @return texture width (0 LOD)
58 inline GLsizei SizeX() const
59 {
60 return mySizeX;
61 }
62
63 //! @return texture height (0 LOD)
64 inline GLsizei SizeY() const
65 {
66 return mySizeY;
67 }
68
69 //! @return texture ID
70 inline GLuint TextureId() const
71 {
72 return myTextureId;
73 }
74
a577aaab 75 //! @return texture format
76 inline GLint GetFormat() const
77 {
78 return myTextFormat;
79 }
80
bf75be98 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);
84
85 //! Destroy object - will release GPU memory if any.
86 Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
87
88 //! Bind this Texture to specified unit.
89 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx,
90 const GLenum theTextureUnit = GL_TEXTURE0) const;
91
92 //! Unbind texture from specified unit.
93 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx,
94 const GLenum theTextureUnit = GL_TEXTURE0) const;
95
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);
100
101 //! @return true if texture was generated within mipmaps
102 Standard_EXPORT const Standard_Boolean HasMipmaps() const;
103
104 //! @return assigned texture parameters (not necessary applied)
105 Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const;
106
107 //! @param texture parameters
108 Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams);
109
110protected:
111
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
118
119 Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
120
121public:
122
123 DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition
124
125};
126
127#endif // _OpenGl_Texture_H__