ScummVM API documentation
texture.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GRAPHICS_OPENGL_TEXTURE_H
23 #define GRAPHICS_OPENGL_TEXTURE_H
24 
25 #include "graphics/opengl/system_headers.h"
26 #include "graphics/opengl/context.h"
27 
28 #include "graphics/pixelformat.h"
29 #include "graphics/surface.h"
30 
31 #include "common/rect.h"
32 #include "common/rotationmode.h"
33 
34 namespace OpenGL {
35 
36 enum WrapMode {
37  kWrapModeBorder,
38  kWrapModeEdge,
39  kWrapModeRepeat,
40  kWrapModeMirroredRepeat
41 };
42 
48 class Texture {
49 public:
57  Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType, bool autoCreate = true);
58  ~Texture();
59 
65  void enableLinearFiltering(bool enable);
66 
70  bool isLinearFilteringEnabled() const { return (_glFilter == GL_LINEAR); }
71 
77  void setWrapMode(WrapMode wrapMode);
78 
82  void destroy();
83 
87  void create();
88 
94  bool bind() const;
95 
106  bool setSize(uint width, uint height);
107 
113  void setFlip(bool flip) { if (_flip != flip) { _flip = flip; computeTexCoords(); } }
114 
120  void setRotation(Common::RotationMode rotation) { if (_rotation != rotation) { _rotation = rotation; computeTexCoords(); } }
121 
130  void updateArea(const Common::Rect &area, const Graphics::Surface &src);
131 
135  uint getWidth() const { return _width; }
136 
140  uint getHeight() const { return _height; }
141 
145  uint getLogicalWidth() const { return _logicalWidth; }
146 
150  uint getLogicalHeight() const { return _logicalHeight; }
151 
155  const GLfloat *getTexCoords() const { return _texCoords; }
156 
163  GLuint getGLTexture() const { return _glTexture; }
164 
165  static inline const Graphics::PixelFormat getRGBPixelFormat() {
167  }
168 
169  static inline const Graphics::PixelFormat getRGBAPixelFormat() {
171  }
172 
173  static inline const Graphics::PixelFormat getBGRAPixelFormat() {
175  }
176 
177 protected:
178  void computeTexCoords();
179 
180  const GLenum _glIntFormat;
181  const GLenum _glFormat;
182  const GLenum _glType;
183 
184  uint _width, _height;
185  uint _logicalWidth, _logicalHeight;
186  bool _flip;
187  Common::RotationMode _rotation;
188 
189  GLfloat _texCoords[4*2];
190 
191  GLint _glFilter;
192 
193  GLuint _glTexture;
194 };
195 
196 } // End of namespace OpenGL
197 
198 #endif
bool setSize(uint width, uint height)
void setRotation(Common::RotationMode rotation)
Definition: texture.h:120
void setWrapMode(WrapMode wrapMode)
Definition: surface.h:67
void enableLinearFiltering(bool enable)
void setFlip(bool flip)
Definition: texture.h:113
Definition: pixelformat.h:138
uint getHeight() const
Definition: texture.h:140
Definition: rect.h:524
void updateArea(const Common::Rect &area, const Graphics::Surface &src)
GLuint getGLTexture() const
Definition: texture.h:163
static constexpr PixelFormat createFormatRGBA32(bool alpha=true)
Definition: pixelformat.h:207
uint getLogicalWidth() const
Definition: texture.h:145
uint getWidth() const
Definition: texture.h:135
bool bind() const
Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType, bool autoCreate=true)
Definition: renderbuffer.h:27
Definition: texture.h:48
static constexpr PixelFormat createFormatBGRA32(bool alpha=true)
Definition: pixelformat.h:216
const GLfloat * getTexCoords() const
Definition: texture.h:155
uint getLogicalHeight() const
Definition: texture.h:150
static constexpr PixelFormat createFormatRGB24()
Definition: pixelformat.h:189
RotationMode
Definition: rotationmode.h:44
bool isLinearFilteringEnabled() const
Definition: texture.h:70