comparison engine/core/video/opengl/glimage.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, 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
33 // FIFE includes
34 // These includes are split up in two parts, separated by one empty line
35 // First block: files included from the FIFE root src directory
36 // Second block: files included from the same folder
37 #include "video/image.h"
38
39 #include "fife_opengl.h"
40
41 namespace FIFE {
42 // FIXME: due to image chunking issues, GLImage uses SDLImage to draw primitives on its surface
43 // remember though that OpenGL backend is not separate thing of SDL; instead it sits on top of it
44 class SDLImage;
45
46
47 /** Implements an Image using OpenGL.
48 *
49 * This class contains a texture handle bound to the data given to the constructor;
50 * it draws a textured @i Quad to the screen.
51 *
52 * @see Image
53 * @note Width and height are not limited to powers of two; non-power of two
54 * images will be converted internally.
55 * @todo Check the correctness of the generateTexture function on big endian systems (ppc)
56 */
57 class GLImage : public Image {
58 public:
59 GLImage(SDL_Surface* surface);
60 GLImage(const uint8_t* data, unsigned int width, unsigned int height);
61 virtual ~GLImage();
62 void render(const Rect& rect, SDL_Surface* dst, unsigned char alpha = 255);
63 void saveImage(const std::string& filename);
64 bool putPixel(int x, int y, int r, int g, int b);
65 void drawLine(const Point& p1, const Point& p2, int r, int g, int b);
66 void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b);
67
68 protected:
69 void setClipArea(const Rect& cliparea, bool clear);
70
71 private:
72 // number of rows into which this image is sliced, so that it "becomes power of 2 compatible"
73 unsigned int m_rows;
74 // see m_rows
75 unsigned int m_cols;
76
77 // ratio of texture fill in last column. E.g. in case image width = 300, chunk = 256x256,
78 // last column chunk width = 64 -> ratio is (300-256) / 64 = 0.6875
79 // this means that texture fills 68.75% the last column
80 float m_last_col_fill_ratio;
81 // @see m_last_col_fill_ratio
82 float m_last_row_fill_ratio;
83
84 /** the width of last column to render. This is also power of two
85 * (e.g. if chunks are 256x256 and image width = 300, last column = 64
86 */
87 unsigned int m_last_col_width;
88 // see m_last_col_width
89 unsigned int m_last_row_height;
90
91 /** Holds texture ids that are used to access textures in GL rendering context
92 */
93 GLuint* m_textureids;
94
95 /** Frees allocated memory and calls resetGlImage
96 */
97 void cleanup();
98
99 /** Resets GLImage variables
100 */
101 void resetGlimage();
102
103 //void saveAsPng(const std::string& filename, SDL_Surface& surface);
104
105 /** Generates chunks for render. For reference, see
106 * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_4.html
107 */
108 void generateTextureChunks();
109
110 /** Original SDLImage where GLImage is created from
111 * FIXME: at the moment SDLImage is used to draw graphics (e.g. line) on screen
112 * this is clearly not optimal, but image chunking makes somewhat harder to do
113 * proper drawing of graphics (e.g. how to segment lines into correct boxes).
114 * It might be possible to use some kind of offscreen OpenGL image for this
115 * purpose
116 */
117 SDLImage* m_sdlimage;
118
119 unsigned int m_chunk_size;
120 };
121 }
122
123 #endif
124 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */