FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glimage.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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 // Standard C++ library includes
23 #include <cassert>
24 #include <iostream>
25 // 3rd party library includes
26 
27 // FIFE includes
28 // These includes are split up in two parts, separated by one empty line
29 // First block: files included from the FIFE root src directory
30 // Second block: files included from the same folder
31 #include "util/structures/rect.h"
32 #include "video/imagemanager.h"
33 #include "video/sdl/sdlimage.h"
34 #include "video/renderbackend.h"
36 
37 #include "glimage.h"
38 
39 namespace FIFE {
41  Image(loader),
42  m_compressed(false),
43  m_texId(0) {
44 
45  resetGlimage();
46  }
47 
48  GLImage::GLImage(const std::string& name, IResourceLoader* loader):
49  Image(name, loader),
50  m_compressed(false),
51  m_texId(0) {
52 
53  resetGlimage();
54  }
55 
56  GLImage::GLImage(SDL_Surface* surface):
57  Image(surface),
58  m_compressed(false),
59  m_texId(0) {
60 
61  resetGlimage();
62  }
63 
64  GLImage::GLImage(const std::string& name, SDL_Surface* surface):
65  Image(name, surface),
66  m_compressed(false),
67  m_texId(0) {
68 
69  resetGlimage();
70  }
71 
72  GLImage::GLImage(const uint8_t* data, uint32_t width, uint32_t height):
73  Image(data, width, height),
74  m_compressed(false),
75  m_texId(0) {
76 
77  assert(m_surface);
78  resetGlimage();
79  }
80 
81  GLImage::GLImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height):
82  Image(name, data, width, height),
83  m_compressed(false),
84  m_texId(0) {
85 
86  assert(m_surface);
87  resetGlimage();
88  }
89 
91  cleanup();
92  }
93 
95  resetGlimage();
96  }
97 
98  void GLImage::setSurface(SDL_Surface* surface) {
99  reset(surface);
100  resetGlimage();
101  }
102 
104  cleanup();
105 
106  m_chunk_size_w = 0;
107  m_chunk_size_h = 0;
108 
110  }
111 
113  if (m_texId) {
114  if(!m_shared) {
115  glDeleteTextures(1, &m_texId);
116  }
117  m_texId = 0;
118  m_compressed = false;
119  }
120 
121  m_tex_coords[0] = m_tex_coords[1] =
122  m_tex_coords[2] = m_tex_coords[3] = 0.0f;
123  }
124 
125  void GLImage::render(const Rect& rect, uint8_t alpha, uint8_t const* rgb) {
126  // completely transparent so dont bother rendering
127  if (0 == alpha) {
128  return;
129  }
131  SDL_Surface* target = rb->getRenderTargetSurface();
132  assert(target != m_surface); // can't draw on the source surface
133 
134  // not on the screen. dont render
135  if (rect.right() < 0 || rect.x > static_cast<int32_t>(target->w) ||
136  rect.bottom() < 0 || rect.y > static_cast<int32_t>(target->h)) {
137  return;
138  }
139 
140  if (!m_texId) {
142  } else if (m_shared) {
143  validateShared();
144  }
145 
146  rb->addImageToArray(m_texId, rect, m_tex_coords, alpha, rgb);
147  }
148 
149  void GLImage::render(const Rect& rect, const ImagePtr& overlay, uint8_t alpha, uint8_t const* rgb) {
150  // completely transparent so dont bother rendering
151  if (0 == alpha) {
152  return;
153  }
155  SDL_Surface* target = rb->getRenderTargetSurface();
156  assert(target != m_surface); // can't draw on the source surface
157 
158  // not on the screen. dont render
159  if (rect.right() < 0 || rect.x > static_cast<int32_t>(target->w) ||
160  rect.bottom() < 0 || rect.y > static_cast<int32_t>(target->h)) {
161  return;
162  }
163 
164  if (!m_texId) {
166  } else if (m_shared) {
167  validateShared();
168  }
169 
170  GLImage* img = static_cast<GLImage*>(overlay.get());
171  img->forceLoadInternal();
172 
173  static_cast<RenderBackendOpenGL*>(rb)->addImageToArray(rect, m_texId, m_tex_coords, img->getTexId(), img->getTexCoords(), alpha, rgb);
174  //rb->addImageToArray(rect, m_texId, m_tex_coords, img->getTexId(), img->getTexCoords(), alpha, rgb);
175  }
176 
177  void GLImage::renderZ(const Rect& rect, float vertexZ, uint8_t alpha, uint8_t const* rgb) {
178  // completely transparent so dont bother rendering
179  if (0 == alpha) {
180  return;
181  }
183  SDL_Surface* target = rb->getRenderTargetSurface();
184  assert(target != m_surface); // can't draw on the source surface
185 
186  // not on the screen. dont render
187  if (rect.right() < 0 || rect.x > static_cast<int32_t>(target->w) ||
188  rect.bottom() < 0 || rect.y > static_cast<int32_t>(target->h)) {
189  return;
190  }
191 
192  if (!m_texId) {
194  } else if (m_shared) {
195  validateShared();
196  }
197 
198  static_cast<RenderBackendOpenGL*>(rb)->addImageToArrayZ(m_texId, rect, vertexZ, m_tex_coords, alpha, rgb);
199  //rb->addImageToArray(m_texId, rect, m_tex_coords, alpha, rgb);
200  }
201 
202  void GLImage::renderZ(const Rect& rect, float vertexZ, const ImagePtr& overlay, uint8_t alpha, uint8_t const* rgb) {
203  // completely transparent so dont bother rendering
204  if (0 == alpha) {
205  return;
206  }
208  SDL_Surface* target = rb->getRenderTargetSurface();
209  assert(target != m_surface); // can't draw on the source surface
210 
211  // not on the screen. dont render
212  if (rect.right() < 0 || rect.x > static_cast<int32_t>(target->w) ||
213  rect.bottom() < 0 || rect.y > static_cast<int32_t>(target->h)) {
214  return;
215  }
216 
217  if (!m_texId) {
219  } else if (m_shared) {
220  validateShared();
221  }
222 
223  GLImage* img = static_cast<GLImage*>(overlay.get());
224  img->forceLoadInternal();
225 
226  static_cast<RenderBackendOpenGL*>(rb)->addImageToArrayZ(rect, vertexZ, m_texId, m_tex_coords, img->getTexId(), img->getTexCoords(), alpha, rgb);
227  //rb->addImageToArray(rect, m_texId, m_tex_coords, img->getTexId(), img->getTexCoords(), alpha, rgb);
228  }
229 
231  if (m_shared) {
232  // First make sure we loaded big image to opengl
233  validateShared();
234  return;
235  }
236  // ultimate possibility to load the image
237  // is used e.g. in case a cursor or gui image is freed even if there is a reference
238  if (!m_surface) {
240  load();
241  }
242  }
243  const uint32_t width = m_surface->w;
244  const uint32_t height = m_surface->h;
245 
246  // With OpenGL 2.0 or GL_ARB_texture_non_power_of_two we don't really need to care
247  // about non power of 2 textures
248  if(GLEE_ARB_texture_non_power_of_two && RenderBackend::instance()->isNPOTEnabled()) {
249  m_chunk_size_w = width;
250  m_chunk_size_h = height;
251  }
252  else {
253  //calculate the nearest larger power of 2
254  m_chunk_size_w = nextPow2(width);
255  m_chunk_size_h = nextPow2(height);
256  }
257 
258  // used to calculate the fill ratio for given chunk
259  m_tex_coords[0] = m_tex_coords[1] = 0.0f;
260  m_tex_coords[2] = static_cast<float>(m_surface->w%m_chunk_size_w) / static_cast<float>(m_chunk_size_w);
261  m_tex_coords[3] = static_cast<float>(m_surface->h%m_chunk_size_h) / static_cast<float>(m_chunk_size_h);
262 
263  if (m_tex_coords[2] == 0.0f){
264  m_tex_coords[2] = 1.0f;
265  }
266 
267  if (m_tex_coords[3] == 0.0f){
268  m_tex_coords[3] = 1.0f;
269  }
270 
271  uint8_t* data = static_cast<uint8_t*>(m_surface->pixels);
272  int32_t pitch = m_surface->pitch;
273 
274  assert(!m_texId);
275 
276  // get texture id from opengl
277  glGenTextures(1, &m_texId);
278  // set focus on that texture
279  static_cast<RenderBackendOpenGL*>(RenderBackend::instance())->bindTexture(m_texId);
280  // set filters for texture
281  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
282  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
283  bool mipmapping = RenderBackend::instance()->isMipmappingEnabled();
284  if (mipmapping) {
285  glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
286  }
287  // without mipmapping, trilinear and bilinear filters are the same
288  switch (RenderBackend::instance()->getTextureFiltering()) {
289  case TEXTURE_FILTER_NONE:
290  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
291  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
292  break;
294  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
295  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
296  break;
298  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
299  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
300  break;
302  // currently trilinear anisotropic
303  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast<GLint>(RenderBackend::instance()->getMaxAnisotropy()));
304  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
305  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
306  break;
307  default:
308  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
309  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
310  break;
311  }
312 
313  GLint internalFormat = GL_RGBA8;
314  if(GLEE_ARB_texture_compression && RenderBackend::instance()->isImageCompressingEnabled()) {
315  internalFormat = GL_COMPRESSED_RGBA;
316  m_compressed = true;
317  } else {
318  m_compressed = false;
319  }
320 
321  bool monochrome = RenderBackend::instance()->isMonochromeEnabled();
322  SDL_Surface* target = RenderBackend::instance()->getRenderTargetSurface();
323  int32_t bpp_target = target->format->BitsPerPixel;
324  int32_t bpp_source = m_surface->format->BitsPerPixel;
325  // create 16 bit texture, RGBA_4444
326  if (bpp_target == 16 && bpp_source == 32) {
327  uint16_t* oglbuffer = new uint16_t[m_chunk_size_w * m_chunk_size_h];
328  memset(oglbuffer, 0x00, m_chunk_size_w*m_chunk_size_h*sizeof(uint16_t));
329 
330  for (uint32_t y = 0; y < height; ++y) {
331  for (uint32_t x = 0; x < width; ++x) {
332  uint32_t pos = (y * pitch) + (x * 4);
333 
334  uint8_t r = data[pos + 0];
335  uint8_t g = data[pos + 1];
336  uint8_t b = data[pos + 2];
337  uint8_t a = data[pos + 3];
338 
340  // only set alpha to zero if colorkey feature is enabled
341  if (r == m_colorkey.r && g == m_colorkey.g && b == m_colorkey.b) {
342  a = 0;
343  }
344  }
345  // if monochrome rendering is enabled, then the colors are converted to grayscale
346  if (monochrome) {
347  uint8_t lum = static_cast<uint8_t>(r*0.3 + g*0.59 + b*0.11);
348  r = lum;
349  g = lum;
350  b = lum;
351  }
352  oglbuffer[(y*m_chunk_size_w) + x] = ((r >> 4) << 12) |
353  ((g >> 4) << 8) |
354  ((b >> 4) << 4) |
355  ((a >> 4) << 0);
356  }
357  }
358  // in case of compression we let OpenGL handle it
359  if (!m_compressed) {
360  internalFormat = GL_RGBA4;
361  }
362 
363  // transfer data from sdl buffer
364  glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_chunk_size_w, m_chunk_size_h,
365  0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, oglbuffer);
366 
367  delete[] oglbuffer;
368  return;
369  }
370 
371  if(GLEE_ARB_texture_non_power_of_two && RenderBackend::instance()->isNPOTEnabled()) {
372  if(RenderBackend::instance()->isColorKeyEnabled()) {
373  uint8_t* oglbuffer = new uint8_t[width * height * 4];
374  memcpy(oglbuffer, data, width * height * 4 * sizeof(uint8_t));
375 
376  for (uint32_t y = 0; y < height; ++y) {
377  for (uint32_t x = 0; x < width * 4; x += 4) {
378  uint32_t gid = x + y * pitch;
379 
380  uint8_t r = oglbuffer[gid + 0];
381  uint8_t g = oglbuffer[gid + 1];
382  uint8_t b = oglbuffer[gid + 2];
383 
384  // set alpha to zero
385  if (r == m_colorkey.r && g == m_colorkey.g && b == m_colorkey.b) {
386  oglbuffer[gid + 3] = 0;
387  }
388  // if monochrome rendering is enabled, then the colors are converted to grayscale
389  if (monochrome) {
390  uint8_t lum = static_cast<uint8_t>(r*0.3 + g*0.59 + b*0.11);
391  oglbuffer[gid + 0] = lum;
392  oglbuffer[gid + 1] = lum;
393  oglbuffer[gid + 2] = lum;
394  }
395  }
396  }
397 
398  // transfer data from sdl buffer
399  glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_chunk_size_w, m_chunk_size_h,
400  0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
401 
402  delete [] oglbuffer;
403  } else if (monochrome) {
404  uint8_t* oglbuffer = new uint8_t[width * height * 4];
405  memcpy(oglbuffer, data, width * height * 4 * sizeof(uint8_t));
406 
407  for (uint32_t y = 0; y < height; ++y) {
408  for (uint32_t x = 0; x < width * 4; x += 4) {
409  uint32_t gid = x + y * pitch;
410  // if monochrome rendering is enabled, then the colors are converted to grayscale
411  uint8_t lum = static_cast<uint8_t>(oglbuffer[gid + 0]*0.3 + oglbuffer[gid + 1]*0.59 + oglbuffer[gid + 2]*0.11);
412  oglbuffer[gid + 0] = lum;
413  oglbuffer[gid + 1] = lum;
414  oglbuffer[gid + 2] = lum;
415  }
416  }
417 
418  // transfer data from sdl buffer
419  glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_chunk_size_w, m_chunk_size_h,
420  0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
421 
422  delete [] oglbuffer;
423  } else {
424  // transfer data directly from sdl buffer
425  glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_chunk_size_w, m_chunk_size_h,
426  0, GL_RGBA, GL_UNSIGNED_BYTE, data);
427  }
428  // Non power of 2 textures are not supported, we need to pad the size of texture to nearest power of 2
429  } else {
430  uint32_t* oglbuffer = new uint32_t[m_chunk_size_w * m_chunk_size_h];
431  memset(oglbuffer, 0x00, m_chunk_size_w*m_chunk_size_h*sizeof(uint32_t));
432 
433  for (uint32_t y = 0; y < height; ++y) {
434  for (uint32_t x = 0; x < width; ++x) {
435  uint32_t pos = (y * pitch) + (x * 4);
436 
437  uint8_t a = data[pos + 3];
438  uint8_t b = data[pos + 2];
439  uint8_t g = data[pos + 1];
440  uint8_t r = data[pos + 0];
441 
443  // only set alpha to zero if colorkey feature is enabled
444  if (r == m_colorkey.r && g == m_colorkey.g && b == m_colorkey.b) {
445  a = 0;
446  }
447  }
448  // if monochrome rendering is enabled, then the colors are converted to grayscale
449  if (monochrome) {
450  uint8_t lum = static_cast<uint8_t>(r*0.3 + g*0.59 + b*0.11);
451  r = lum;
452  g = lum;
453  b = lum;
454  }
455 
456  oglbuffer[(y*m_chunk_size_w) + x] = r | (g << 8) | (b << 16) | (a<<24);
457  }
458  }
459 
460  // transfer data from sdl buffer
461  glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_chunk_size_w, m_chunk_size_h,
462  0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(oglbuffer));
463 
464  delete[] oglbuffer;
465  }
466  }
467 
468  void GLImage::generateGLSharedTexture(const GLImage* shared, const Rect& region) {
469  uint32_t width = shared->getWidth();
470  uint32_t height = shared->getHeight();
471 
472  if(!GLEE_ARB_texture_non_power_of_two || !RenderBackend::instance()->isNPOTEnabled()) {
473  width = nextPow2(width);
474  height = nextPow2(height);
475  }
476 
477  if (RenderBackend::instance()->getTextureFiltering() != TEXTURE_FILTER_NONE || RenderBackend::instance()->isMipmappingEnabled()) {
478  // half pixel correction
479  m_tex_coords[0] = (static_cast<GLfloat>(region.x)+0.5) / static_cast<GLfloat>(width);
480  m_tex_coords[1] = (static_cast<GLfloat>(region.y)+0.5) / static_cast<GLfloat>(height);
481  m_tex_coords[2] = (static_cast<GLfloat>(region.x + region.w)-0.5) / static_cast<GLfloat>(width);
482  m_tex_coords[3] = (static_cast<GLfloat>(region.y + region.h)-0.5) / static_cast<GLfloat>(height);
483  } else {
484  m_tex_coords[0] = static_cast<GLfloat>(region.x) / static_cast<GLfloat>(width);
485  m_tex_coords[1] = static_cast<GLfloat>(region.y) / static_cast<GLfloat>(height);
486  m_tex_coords[2] = static_cast<GLfloat>(region.x + region.w) / static_cast<GLfloat>(width);
487  m_tex_coords[3] = static_cast<GLfloat>(region.y + region.h) / static_cast<GLfloat>(height);
488  }
489  }
490 
491  void GLImage::useSharedImage(const ImagePtr& shared, const Rect& region) {
492  GLImage* img = static_cast<GLImage*>(shared.get());
493 
494  m_shared_img = img;
495  m_texId = img->m_texId;
496  m_shared = true;
497  m_subimagerect = region;
498  m_atlas_img = shared;
502 
503  if(m_texId) {
504  generateGLSharedTexture(img, region);
505  }
506 
508  }
509 
511  if (m_texId == 0) {
513  } else if (m_shared) {
514  validateShared();
515  }
516  }
517 
519  // if image is valid we can return
521  return;
522  }
523 
525  m_shared_img->load();
527  } else if (!m_shared_img->m_texId) {
529  }
530 
535  }
536 
537  void GLImage::copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr& img) {
538  Image::copySubimage(xoffset, yoffset, img);
539 
540  if(m_texId) {
541  static_cast<RenderBackendOpenGL*>(RenderBackend::instance())->bindTexture(m_texId);
542  glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, img->getWidth(), img->getHeight(),
543  GL_RGBA, GL_UNSIGNED_BYTE, img->getSurface()->pixels);
544  }
545  }
546 
547  void GLImage::load() {
548  if (m_shared) {
549  // check atlas image
550  // if it does not exist, it is generated.
551  if (!ImageManager::instance()->exists(m_atlas_name)) {
553  GLImage* img = static_cast<GLImage*>(newAtlas.get());
554  m_atlas_img = newAtlas;
555  m_shared_img = img;
556  }
557  validateShared();
558  // check if texture ids and surfaces are identical
563  if (m_texId) {
565  }
566  }
568  } else {
569  Image::load();
570  }
571  }
572 
573  void GLImage::free() {
574  setSurface(NULL);
576  }
577 
578  GLuint GLImage::getTexId() const {
579  return m_texId;
580  }
581 
582  const GLfloat* GLImage::getTexCoords() const {
583  return m_tex_coords;
584  }
585 }
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
void reset(SDL_Surface *surface)
Resets the image to default values (including the x and y shift values), frees the current surface an...
Definition: image.cpp:110
virtual void addImageToArray(uint32_t id, const Rect &rec, float const *st, uint8_t alpha, uint8_t const *rgba)=0
Add the Image data to the array.
Abstract interface for all the renderbackends.
T * get() const
allows direct access to underlying pointer
Definition: sharedptr.h:155
virtual void invalidate()
Invalidates the Image causing it to be reset or re-loaded.
Definition: glimage.cpp:94
void generateGLTexture()
Generates the GL Texture for use when rendering.
Definition: glimage.cpp:230
virtual ResourceState getState()
Definition: resource.h:70
virtual void load()
Definition: glimage.cpp:547
virtual void load()
Definition: image.cpp:124
uint32_t m_chunk_size_w
Definition: glimage.h:119
Base Class for Images.
Definition: image.h:47
SDL_Surface * m_surface
Definition: image.h:159
T h
Height of the rectangle.
Definition: rect.h:93
T x
The X Coordinate.
Definition: rect.h:84
GLfloat m_tex_coords[4]
Definition: glimage.h:83
virtual void setSurface(SDL_Surface *surface)
This frees the current suface and replaces it with the surface passed in the parameter (which can be ...
Definition: glimage.cpp:98
unsigned nextPow2(unsigned x)
Returns the next higher power of 2 based on the passed argument.
Definition: fife_math.h:292
void resetGlimage()
Resets GLImage variables.
Definition: glimage.cpp:103
GLImage(IResourceLoader *loader=0)
Definition: glimage.cpp:40
GLuint getTexId() const
Definition: glimage.cpp:578
std::string m_atlas_name
Definition: glimage.h:128
const GLfloat * getTexCoords() const
Definition: glimage.cpp:582
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
Definition: glimage.cpp:537
virtual void useSharedImage(const ImagePtr &shared, const Rect &region)
After this call all image data will be taken from the given image and its subregion.
Definition: glimage.cpp:491
SDL_Color m_colorkey
Definition: glimage.h:122
static RenderBackend * instance()
Definition: singleton.h:84
bool isMipmappingEnabled() const
uint32_t getHeight() const
Definition: image.cpp:160
bool isColorKeyEnabled() const
Gets whether the colorkey feature is in use.
unsigned char uint8_t
Definition: core.h:38
GLuint m_texId
Holds texture ids that are used to access textures in GL rendering context.
Definition: glimage.h:103
T bottom() const
The Y coordinate of the bottom edge.
Definition: rect.h:173
SDL_Surface * getSurface()
Definition: image.h:95
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
Definition: image.cpp:315
const SDL_Color & getColorKey() const
Gets the global colorkey setting.
virtual ~GLImage()
Definition: glimage.cpp:90
void generateGLSharedTexture(const GLImage *shared, const Rect &region)
Definition: glimage.cpp:468
virtual const std::string & getName()
Definition: resource.h:66
uint32_t getWidth() const
Definition: image.cpp:151
ResourceState m_state
Definition: resource.h:81
unsigned short uint16_t
Definition: core.h:39
T y
The Y Coordinate.
Definition: rect.h:87
Rect m_subimagerect
Definition: image.h:176
bool isMonochromeEnabled() const
GLImage * m_shared_img
Definition: glimage.h:124
T right() const
The X coordinate of the right edge.
Definition: rect.h:168
virtual void setState(const ResourceState &state)
Definition: resource.h:71
virtual void forceLoadInternal()
Forces to load the image into internal memory of GPU.
Definition: glimage.cpp:510
void cleanup()
Frees allocated memory and calls resetGlImage.
Definition: glimage.cpp:112
bool m_compressed
Definition: glimage.h:86
SDL_Surface * getRenderTargetSurface()
Returns currently attached render surface.
uint32_t m_chunk_size_h
Definition: glimage.h:120
virtual void free()
Definition: glimage.cpp:573
bool m_shared
Definition: image.h:174
Implements an Image using OpenGL.
Definition: glimage.h:53
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)
Renders itself to the current render target (main screen or attached destination image) at the rectan...
Definition: glimage.cpp:125
unsigned int uint32_t
Definition: core.h:40
ImagePtr m_atlas_img
Definition: glimage.h:126
T w
Width of the rectangle.
Definition: rect.h:90
virtual void renderZ(const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
Definition: glimage.cpp:177
The main class of the OpenGL-based renderer.
void validateShared()
Definition: glimage.cpp:518