bf75be98 |
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 | |
a174a3c5 |
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 | |
bf75be98 |
79 | //! Creates Texture id if not yet generated. |
80 | //! Data should be initialized by another method. |
81 | Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theCtx); |
82 | |
83 | //! Destroy object - will release GPU memory if any. |
84 | Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx); |
85 | |
86 | //! Bind this Texture to specified unit. |
87 | Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx, |
88 | const GLenum theTextureUnit = GL_TEXTURE0) const; |
89 | |
90 | //! Unbind texture from specified unit. |
91 | Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theCtx, |
92 | const GLenum theTextureUnit = GL_TEXTURE0) const; |
93 | |
94 | //! Notice that texture will be unbound after this call. |
95 | Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx, |
96 | const Image_PixMap& theImage, |
97 | const Graphic3d_TypeOfTexture theType); |
98 | |
99 | //! @return true if texture was generated within mipmaps |
100 | Standard_EXPORT const Standard_Boolean HasMipmaps() const; |
101 | |
102 | //! @return assigned texture parameters (not necessary applied) |
103 | Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const; |
104 | |
105 | //! @param texture parameters |
106 | Standard_EXPORT void SetParams (const Handle(Graphic3d_TextureParams)& theParams); |
107 | |
108 | protected: |
109 | |
110 | GLuint myTextureId; //!< GL resource ID |
111 | GLenum myTarget; //!< GL_TEXTURE_1D/GL_TEXTURE_2D |
112 | GLsizei mySizeX; //!< texture width |
113 | GLsizei mySizeY; //!< texture height |
114 | GLint myTextFormat; //!< texture format - GL_RGB, GL_RGBA,... |
115 | Standard_Boolean myHasMipmaps; //!< flag indicates that texture was uploaded with mipmaps |
116 | |
117 | Handle(Graphic3d_TextureParams) myParams; //!< texture parameters |
118 | |
119 | public: |
120 | |
121 | DEFINE_STANDARD_RTTI(OpenGl_Texture) // Type definition |
122 | |
123 | }; |
124 | |
125 | #endif // _OpenGl_Texture_H__ |