Debian Codegraph @

engine/core/video/opengl/glimage.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_H
23 #define FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_H
24
25 // Standard C++ library includes
26 #include <vector>
27
28 // Platform specific includes
29 #include "util/base/fife_stdint.h"
30
31 // 3rd party library includes
32 #include <SDL_video.h>
33
34 // FIFE includes
35 // These includes are split up in two parts, separated by one empty line
36 // First block: files included from the FIFE root src directory
37 // Second block: files included from the same folder
38 #include "video/image.h"
39
40 #include "fife_opengl.h"
41
42 namespace FIFE {
43
44 /** Implements an Image using OpenGL.
45 *
46 * This class contains a texture handle bound to the data given to the constructor;
47 * it draws a textured Quad to the screen.
48 *
49 * @see Image
50 * @note Width and height are not limited to powers of two;
51 * non-power of two images will be converted internally,
52 * if they are not supported by the hardware (ARB_texture_non_power_of_two).
53 * @todo Check the correctness of the generateTexture function on big endian systems (ppc)
54 */
55 class GLImage : public Image {
56 public:
57 GLImage(IResourceLoader* loader = 0);
58 GLImage(const std::string& name, IResourceLoader* loader = 0);
59 GLImage(SDL_Surface* surface);
60 GLImage(const std::string& name, SDL_Surface* surface);
61 GLImage(const uint8_t* data, uint32_t width, uint32_t height);
62 GLImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
63
64 virtual ~GLImage();
65 virtual void invalidate();
66 virtual void setSurface(SDL_Surface* surface);
67 virtual void render(const Rect& rect, uint8_t alpha = 255, uint8_t const* rgb = 0);
68 virtual void render(const Rect& rect, const ImagePtr& overlay, uint8_t alpha = 255, uint8_t const* rgb = 0);
69
70 virtual void renderZ(const Rect& rect, float vertexZ, uint8_t alpha = 255, uint8_t const* rgb = 0);
71 virtual void renderZ(const Rect& rect, float vertexZ, const ImagePtr& overlay, uint8_t alpha = 255, uint8_t const* rgb = 0);
72
73 virtual void useSharedImage(const ImagePtr& shared, const Rect& region);
74 virtual void forceLoadInternal();
75 virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr& img);
76 virtual void load();
77 virtual void free();
78
79 GLuint getTexId() const;
80 const GLfloat* getTexCoords() const;
81 bool isCompressed() const { return m_compressed; }
82 void setCompressed(bool compressed) { m_compressed = compressed; }
83 private:
84 // texture coords to use
85 GLfloat m_tex_coords[4];
86
87 // Was this image compressed by OpenGL driver during loading ?
88 bool m_compressed;
89
90 // [0] [2] ->(x)
91 // [1] +------+
92 // | |
93 // | |
94 // [3] +------+
95 //
96 // |
97 // v
98 // (y)
99 // To map these indices with previous one:
100 // [0]:=[1]:=0.0f, [2]:=m_col_tex_coords, [3]:=m_row_tex_coords
101
102
103 /** Holds texture ids that are used to access textures in GL rendering context
104 */
105 GLuint m_texId;
106
107 /** Frees allocated memory and calls resetGlImage
108 */
109 void cleanup();
110
111 /** Resets GLImage variables
112 */
113 void resetGlimage();
114
115 /** Generates the GL Texture for use when rendering.
116 */
117 void generateGLTexture();
118 void generateGLSharedTexture(const GLImage* shared, const Rect& region);
119 void validateShared();
120
121 uint32_t m_chunk_size_w;
122 uint32_t m_chunk_size_h;
123
124 SDL_Color m_colorkey;
125
126 GLImage* m_shared_img;
127 // Holds Atlas ImagePtr if this is a shared image
128 ImagePtr m_atlas_img;
129 // Holds Atlas Name if this is a shared image
130 std::string m_atlas_name;
131 };
132
133 }
134
135 #endif