FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
FIFE::GLImage Class Reference

Implements an Image using OpenGL. More...

#include <glimage.h>

+ Inheritance diagram for FIFE::GLImage:
+ Collaboration diagram for FIFE::GLImage:

Public Member Functions

 GLImage (IResourceLoader *loader=0)
 
 GLImage (const std::string &name, IResourceLoader *loader=0)
 
 GLImage (SDL_Surface *surface)
 
 GLImage (const std::string &name, SDL_Surface *surface)
 
 GLImage (const uint8_t *data, uint32_t width, uint32_t height)
 
 GLImage (const std::string &name, const uint8_t *data, uint32_t width, uint32_t height)
 
virtual ~GLImage ()
 
virtual void invalidate ()
 Invalidates the Image causing it to be reset or re-loaded. More...
 
virtual void setSurface (SDL_Surface *surface)
 This frees the current suface and replaces it with the surface passed in the parameter (which can be NULL). More...
 
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 rectangle rect. More...
 
virtual void render (const Rect &rect, const ImagePtr &overlay, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, const ImagePtr &overlay, uint8_t alpha=255, uint8_t const *rgb=0)
 
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. More...
 
virtual void forceLoadInternal ()
 Forces to load the image into internal memory of GPU. More...
 
virtual void copySubimage (uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
 Copies given image into this one with respect to given offsets. More...
 
virtual void load ()
 
virtual void free ()
 
GLuint getTexId () const
 
const GLfloat * getTexCoords () const
 
bool isCompressed () const
 
void setCompressed (bool compressed)
 
- Public Member Functions inherited from FIFE::Image
 Image (IResourceLoader *loader=0)
 Constructor. More...
 
 Image (const std::string &name, IResourceLoader *loader=0)
 
 Image (SDL_Surface *surface)
 Constructor. More...
 
 Image (const std::string &name, SDL_Surface *surface)
 
 Image (const uint8_t *data, uint32_t width, uint32_t height)
 Constructor. More...
 
 Image (const std::string &name, const uint8_t *data, uint32_t width, uint32_t height)
 
virtual ~Image ()
 Destructor. More...
 
virtual void renderZ (const Rect &rect, float vertexZ, uint8_t alpha=255, bool forceNewBatch=false, uint8_t const *rgb=0)
 
SDL_Surface * detachSurface ()
 Removes underlying SDL_Surface from the image (if exists) and returns this. More...
 
SDL_Surface * getSurface ()
 
const SDL_Surface * getSurface () const
 
void saveImage (const std::string &filename)
 Saves the image using given filename. More...
 
uint32_t getWidth () const
 
uint32_t getHeight () const
 
Rect getArea () const
 
void setXShift (int32_t xshift)
 
int32_t getXShift () const
 
void setYShift (int32_t yshift)
 
int32_t getYShift () const
 
void getPixelRGBA (int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
 
virtual size_t getSize ()
 
bool isSharedImage () const
 Returns true if this image shares data with another one. More...
 
const RectgetSubImageRect () const
 Returns area of the image it occupies in the shared image. More...
 
- Public Member Functions inherited from FIFE::IResource
 IResource (const std::string &name, IResourceLoader *loader=0)
 
virtual ~IResource ()
 
virtual const std::string & getName ()
 
ResourceHandle getHandle ()
 
virtual ResourceState getState ()
 
virtual void setState (const ResourceState &state)
 

Private Member Functions

void cleanup ()
 Frees allocated memory and calls resetGlImage. More...
 
void resetGlimage ()
 Resets GLImage variables. More...
 
void generateGLTexture ()
 Generates the GL Texture for use when rendering. More...
 
void generateGLSharedTexture (const GLImage *shared, const Rect &region)
 
void validateShared ()
 

Private Attributes

GLfloat m_tex_coords [4]
 
bool m_compressed
 
GLuint m_texId
 Holds texture ids that are used to access textures in GL rendering context. More...
 
uint32_t m_chunk_size_w
 
uint32_t m_chunk_size_h
 
SDL_Color m_colorkey
 
GLImagem_shared_img
 
ImagePtr m_atlas_img
 
std::string m_atlas_name
 

Additional Inherited Members

- Public Types inherited from FIFE::IResource
- Static Public Member Functions inherited from FIFE::Image
static void saveAsPng (const std::string &filename, const SDL_Surface &surface)
 Saves the SDL_Surface to png format. More...
 
static bool putPixel (SDL_Surface *surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 
- Protected Member Functions inherited from FIFE::Image
void reset (SDL_Surface *surface)
 Resets the image to default values (including the x and y shift values), frees the current surface and sets the surface to the passed SDL_Surface (which can be NULL). More...
 
- Protected Attributes inherited from FIFE::Image
SDL_Surface * m_surface
 
int32_t m_xshift
 
int32_t m_yshift
 
bool m_shared
 
Rect m_subimagerect
 
- Protected Attributes inherited from FIFE::IResource
std::string m_name
 
IResourceLoaderm_loader
 
ResourceState m_state
 

Detailed Description

Implements an Image using OpenGL.

This class contains a texture handle bound to the data given to the constructor; it draws a textured Quad to the screen.

See also
Image
Note
Width and height are not limited to powers of two; non-power of two images will be converted internally, if they are not supported by the hardware (ARB_texture_non_power_of_two).

Definition at line 55 of file glimage.h.

Constructor & Destructor Documentation

FIFE::GLImage::GLImage ( IResourceLoader loader = 0)

Definition at line 40 of file glimage.cpp.

References resetGlimage().

FIFE::GLImage::GLImage ( const std::string &  name,
IResourceLoader loader = 0 
)

Definition at line 48 of file glimage.cpp.

References resetGlimage().

FIFE::GLImage::GLImage ( SDL_Surface *  surface)

Definition at line 56 of file glimage.cpp.

References resetGlimage().

FIFE::GLImage::GLImage ( const std::string &  name,
SDL_Surface *  surface 
)

Definition at line 64 of file glimage.cpp.

References resetGlimage().

FIFE::GLImage::GLImage ( const uint8_t *  data,
uint32_t  width,
uint32_t  height 
)

Definition at line 72 of file glimage.cpp.

References FIFE::Image::m_surface, and resetGlimage().

FIFE::GLImage::GLImage ( const std::string &  name,
const uint8_t *  data,
uint32_t  width,
uint32_t  height 
)

Definition at line 81 of file glimage.cpp.

References FIFE::Image::m_surface, and resetGlimage().

FIFE::GLImage::~GLImage ( )
virtual

Definition at line 90 of file glimage.cpp.

References cleanup().

Member Function Documentation

void FIFE::GLImage::cleanup ( )
private

Frees allocated memory and calls resetGlImage.

Definition at line 112 of file glimage.cpp.

References m_compressed, FIFE::Image::m_shared, m_tex_coords, and m_texId.

Referenced by resetGlimage(), and ~GLImage().

+ Here is the caller graph for this function:

void FIFE::GLImage::copySubimage ( uint32_t  xoffset,
uint32_t  yoffset,
const ImagePtr img 
)
virtual

Copies given image into this one with respect to given offsets.

Reimplemented from FIFE::Image.

Definition at line 533 of file glimage.cpp.

References FIFE::Image::copySubimage(), FIFE::Image::getHeight(), FIFE::Image::getSurface(), FIFE::Image::getWidth(), FIFE::DynamicSingleton< RenderBackend >::instance(), and m_texId.

void FIFE::GLImage::forceLoadInternal ( )
virtual

Forces to load the image into internal memory of GPU.

Implements FIFE::Image.

Definition at line 506 of file glimage.cpp.

References generateGLTexture(), FIFE::Image::m_shared, m_texId, and validateShared().

Referenced by render(), FIFE::RenderBackendOpenGL::renderGuiGeometry(), and renderZ().

+ Here is the caller graph for this function:

void FIFE::GLImage::free ( )
virtual
void FIFE::GLImage::generateGLSharedTexture ( const GLImage shared,
const Rect region 
)
private
const GLfloat * FIFE::GLImage::getTexCoords ( ) const

Definition at line 583 of file glimage.cpp.

References m_tex_coords.

Referenced by render(), and renderZ().

+ Here is the caller graph for this function:

GLuint FIFE::GLImage::getTexId ( ) const

Definition at line 579 of file glimage.cpp.

References m_texId.

Referenced by FIFE::RenderBackendOpenGL::attachRenderTarget(), render(), FIFE::RenderBackendOpenGL::renderGuiGeometry(), and renderZ().

+ Here is the caller graph for this function:

void FIFE::GLImage::invalidate ( )
virtual

Invalidates the Image causing it to be reset or re-loaded.

Implements FIFE::Image.

Definition at line 94 of file glimage.cpp.

References resetGlimage().

bool FIFE::GLImage::isCompressed ( ) const
inline

Definition at line 81 of file glimage.h.

References m_compressed.

Referenced by FIFE::RenderBackendOpenGL::attachRenderTarget().

+ Here is the caller graph for this function:

void FIFE::GLImage::render ( const Rect rect,
uint8_t  alpha = 255,
uint8_t const *  rgb = 0 
)
virtual

Renders itself to the current render target (main screen or attached destination image) at the rectangle rect.

Convenience function

Parameters
rectThe position and clipping where to draw this image to.
alphaThe alpha value, with which to draw self.
rgbThe color value of overlay if any.

Implements FIFE::Image.

Definition at line 125 of file glimage.cpp.

References FIFE::RenderBackend::addImageToArray(), FIFE::RectType< T >::bottom(), generateGLTexture(), FIFE::RenderBackend::getRenderTargetSurface(), FIFE::DynamicSingleton< RenderBackend >::instance(), FIFE::Image::m_shared, FIFE::Image::m_surface, m_tex_coords, m_texId, FIFE::RectType< T >::right(), validateShared(), FIFE::RectType< T >::x, and FIFE::RectType< T >::y.

void FIFE::GLImage::renderZ ( const Rect rect,
float  vertexZ,
uint8_t  alpha = 255,
uint8_t const *  rgb = 0 
)
virtual
void FIFE::GLImage::resetGlimage ( )
private

Resets GLImage variables.

Definition at line 103 of file glimage.cpp.

References cleanup(), FIFE::RenderBackend::getColorKey(), FIFE::DynamicSingleton< RenderBackend >::instance(), m_chunk_size_h, m_chunk_size_w, and m_colorkey.

Referenced by GLImage(), invalidate(), and setSurface().

+ Here is the caller graph for this function:

void FIFE::GLImage::setCompressed ( bool  compressed)
inline

Definition at line 82 of file glimage.h.

References m_compressed.

Referenced by FIFE::RenderBackendOpenGL::attachRenderTarget().

+ Here is the caller graph for this function:

void FIFE::GLImage::setSurface ( SDL_Surface *  surface)
virtual

This frees the current suface and replaces it with the surface passed in the parameter (which can be NULL).

See also
Image::reset(SDL_Surface* surface)
Parameters
surfacethe SDL_Surface to use for this image

Implements FIFE::Image.

Definition at line 98 of file glimage.cpp.

References FIFE::Image::reset(), and resetGlimage().

Referenced by free().

+ Here is the caller graph for this function:

void FIFE::GLImage::useSharedImage ( const ImagePtr shared,
const Rect region 
)
virtual
void FIFE::GLImage::validateShared ( )
private

Member Data Documentation

ImagePtr FIFE::GLImage::m_atlas_img
private

Definition at line 128 of file glimage.h.

Referenced by load(), and useSharedImage().

std::string FIFE::GLImage::m_atlas_name
private

Definition at line 130 of file glimage.h.

Referenced by load(), and useSharedImage().

uint32_t FIFE::GLImage::m_chunk_size_h
private

Definition at line 122 of file glimage.h.

Referenced by generateGLTexture(), and resetGlimage().

uint32_t FIFE::GLImage::m_chunk_size_w
private

Definition at line 121 of file glimage.h.

Referenced by generateGLTexture(), and resetGlimage().

SDL_Color FIFE::GLImage::m_colorkey
private

Definition at line 124 of file glimage.h.

Referenced by generateGLTexture(), and resetGlimage().

bool FIFE::GLImage::m_compressed
private
GLImage* FIFE::GLImage::m_shared_img
private

Definition at line 126 of file glimage.h.

Referenced by load(), useSharedImage(), and validateShared().

GLfloat FIFE::GLImage::m_tex_coords[4]
private
GLuint FIFE::GLImage::m_texId
private

Holds texture ids that are used to access textures in GL rendering context.

Definition at line 105 of file glimage.h.

Referenced by cleanup(), copySubimage(), forceLoadInternal(), generateGLTexture(), getTexId(), load(), render(), renderZ(), useSharedImage(), and validateShared().


The documentation for this class was generated from the following files: