FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gleimage.h
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 #ifndef FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLEIMAGE_H
23 #define FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLEIMAGE_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"
40 
41 namespace FIFE {
42  struct GLRenderState;
43 
53  class GLeImage : public Image {
54  public:
55  GLeImage(IResourceLoader* loader = 0);
56  GLeImage(const std::string& name, IResourceLoader* loader = 0);
57  GLeImage(SDL_Surface* surface);
58  GLeImage(const std::string& name, SDL_Surface* surface);
59  GLeImage(const uint8_t* data, uint32_t width, uint32_t height);
60  GLeImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
61 
62  virtual ~GLeImage();
63  virtual void invalidate();
64  virtual void setSurface(SDL_Surface* surface);
65  virtual void render(const Rect& rect, uint8_t alpha = 255, uint8_t const* rgb = 0);
66  virtual void renderZ(const Rect& rect, float vertexZ, uint8_t alpha = 255, bool forceNewBatch = false, uint8_t const* rgb = 0);
67  virtual void useSharedImage(const ImagePtr& shared, const Rect& region);
68  virtual void forceLoadInternal();
69  virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr& img);
70  virtual void load();
71  virtual void free();
72 
73  GLuint getTexId() const;
74  const GLfloat* getTexCoords() const;
75  bool isCompressed() const { return m_compressed; }
76  void setCompressed(bool compressed) { m_compressed = compressed; }
77  private:
78  // texture coords to use
79  GLfloat m_tex_coords[4];
80 
81  // Was this image compressed by OpenGL driver during loading ?
83 
84  // [0] [2] ->(x)
85  // [1] +------+
86  // | |
87  // | |
88  // [3] +------+
89  //
90  // |
91  // v
92  // (y)
93  // To map these indices with previous one:
94  // [0]:=[1]:=0.0f, [2]:=m_col_tex_coords, [3]:=m_row_tex_coords
95 
96 
99  GLuint m_texId;
100 
103  void cleanup();
104 
107  void resetGlimage();
108 
111  void generateGLTexture();
112  void generateGLSharedTexture(const GLeImage* shared, const Rect& region);
113  void validateShared();
114 
115  inline bool renderCheck(const Rect& rect, uint8_t alpha);
116 
119 
120  SDL_Color m_colorkey;
121 
123  // Holds Atlas ImagePtr if this is a shared image
125  // Holds Atlas Name if this is a shared image
126  std::string m_atlas_name;
127  };
128 
129 }
130 
131 #endif
132 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
Implements an Image using experimental OpenGL.
Definition: gleimage.h:53
GLuint getTexId() const
Definition: gleimage.cpp:430
void generateGLSharedTexture(const GLeImage *shared, const Rect &region)
Definition: gleimage.cpp:330
const GLfloat * getTexCoords() const
Definition: gleimage.cpp:434
uint32_t m_chunk_size_h
Definition: gleimage.h:118
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: gleimage.cpp:97
Base Class for Images.
Definition: image.h:47
void setCompressed(bool compressed)
Definition: gleimage.h:76
void cleanup()
Frees allocated memory and calls resetGlImage.
Definition: gleimage.cpp:111
void validateShared()
Definition: gleimage.cpp:372
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: gleimage.cpp:345
GLeImage(IResourceLoader *loader=0)
Definition: gleimage.cpp:39
bool m_compressed
Definition: gleimage.h:82
GLfloat m_tex_coords[4]
Definition: gleimage.h:79
unsigned char uint8_t
Definition: core.h:38
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
Definition: gleimage.cpp:389
bool renderCheck(const Rect &rect, uint8_t alpha)
Definition: gleimage.cpp:124
virtual void free()
Definition: gleimage.cpp:425
uint32_t m_chunk_size_w
Definition: gleimage.h:117
SDL_Color m_colorkey
Definition: gleimage.h:120
virtual void forceLoadInternal()
Forces to load the image into internal memory of GPU.
Definition: gleimage.cpp:364
ImagePtr m_atlas_img
Definition: gleimage.h:124
bool isCompressed() const
Definition: gleimage.h:75
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: gleimage.cpp:147
GLeImage * m_shared_img
Definition: gleimage.h:122
void resetGlimage()
Resets GLeImage variables.
Definition: gleimage.cpp:102
void generateGLTexture()
Generates the GL Texture for use when rendering.
Definition: gleimage.cpp:161
virtual ~GLeImage()
Definition: gleimage.cpp:89
GLuint m_texId
Holds texture ids that are used to access textures in GL rendering context.
Definition: gleimage.h:99
virtual void invalidate()
Invalidates the Image causing it to be reset or re-loaded.
Definition: gleimage.cpp:93
unsigned int uint32_t
Definition: core.h:40
std::string m_atlas_name
Definition: gleimage.h:126
virtual void renderZ(const Rect &rect, float vertexZ, uint8_t alpha=255, bool forceNewBatch=false, uint8_t const *rgb=0)
Definition: gleimage.cpp:154
virtual void load()
Definition: gleimage.cpp:399