gleimage.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLEIMAGE_H
00023 #define FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLEIMAGE_H
00024 
00025 // Standard C++ library includes
00026 #include <vector>
00027 
00028 // Platform specific includes
00029 #include "util/base/fife_stdint.h"
00030 
00031 // 3rd party library includes
00032 #include <SDL_video.h>
00033 
00034 // FIFE includes
00035 // These includes are split up in two parts, separated by one empty line
00036 // First block: files included from the FIFE root src directory
00037 // Second block: files included from the same folder
00038 #include "video/image.h"
00039 #include "video/opengl/fife_opengl.h"
00040 
00041 namespace FIFE {
00042     struct GLRenderState;
00043 
00053     class GLeImage : public Image {
00054     public:
00055         GLeImage(IResourceLoader* loader = 0);
00056         GLeImage(const std::string& name, IResourceLoader* loader = 0);
00057         GLeImage(SDL_Surface* surface);
00058         GLeImage(const std::string& name, SDL_Surface* surface);
00059         GLeImage(const uint8_t* data, uint32_t width, uint32_t height);
00060         GLeImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
00061 
00062         virtual ~GLeImage();
00063         virtual void invalidate();
00064         virtual void setSurface(SDL_Surface* surface);
00065         virtual void render(const Rect& rect, uint8_t alpha = 255, uint8_t const* rgb = 0);
00066         virtual void renderZ(const Rect& rect, float vertexZ, uint8_t alpha = 255, bool forceNewBatch = false, uint8_t const* rgb = 0);
00067         virtual void useSharedImage(const ImagePtr& shared, const Rect& region);
00068         virtual void forceLoadInternal();
00069         virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr& img);
00070         virtual void load();
00071         virtual void free();
00072 
00073         GLuint getTexId() const;
00074         const GLfloat* getTexCoords() const;
00075         bool isCompressed() const { return m_compressed; }
00076         void setCompressed(bool compressed) { m_compressed = compressed; }
00077     private:
00078         // texture coords to use
00079         GLfloat m_tex_coords[4];
00080 
00081         // Was this image compressed by OpenGL driver during loading ?
00082         bool m_compressed;
00083 
00084         //     [0]    [2]    ->(x)
00085         // [1]  +------+
00086         //      |      |
00087         //      |      |
00088         // [3]  +------+
00089         //
00090         //      |
00091         //      v
00092         //     (y)
00093         // To map these indices with previous one:
00094         // [0]:=[1]:=0.0f, [2]:=m_col_tex_coords, [3]:=m_row_tex_coords
00095 
00096 
00099         GLuint m_texId;
00100 
00103         void cleanup();
00104 
00107         void resetGlimage();
00108 
00111         void generateGLTexture();
00112         void generateGLSharedTexture(const GLeImage* shared, const Rect& region);
00113         void validateShared();
00114 
00115         inline bool renderCheck(const Rect& rect, uint8_t alpha);
00116 
00117         uint32_t m_chunk_size_w;
00118         uint32_t m_chunk_size_h;
00119 
00120         SDL_Color m_colorkey;
00121 
00122         GLeImage* m_shared_img;
00123         // Holds Atlas ImagePtr if this is a shared image
00124         ImagePtr m_atlas_img;
00125         // Holds Atlas Name if this is a shared image
00126         std::string m_atlas_name;
00127     };
00128 
00129 }
00130 
00131 #endif
00132 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */