glimage.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_GLIMAGE_H
00023 #define FIFE_VIDEO_RENDERBACKENDS_OPENGL_GLIMAGE_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 
00040 #include "fife_opengl.h"
00041 
00042 namespace FIFE {
00043 
00053     class GLImage : public Image {
00054     public:
00055         GLImage(IResourceLoader* loader = 0);
00056         GLImage(const std::string& name, IResourceLoader* loader = 0);
00057         GLImage(SDL_Surface* surface);
00058         GLImage(const std::string& name, SDL_Surface* surface);
00059         GLImage(const uint8_t* data, uint32_t width, uint32_t height);
00060         GLImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
00061 
00062         virtual ~GLImage();
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 useSharedImage(const ImagePtr& shared, const Rect& region);
00067         virtual void forceLoadInternal();
00068         virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr& img);
00069         virtual void load();
00070         virtual void free();
00071 
00072         GLuint getTexId() const;
00073         const GLfloat* getTexCoords() const;
00074         bool isCompressed() const { return m_compressed; }
00075         void setCompressed(bool compressed) { m_compressed = compressed; }
00076     private:
00077         // texture coords to use
00078         GLfloat m_tex_coords[4];
00079 
00080         // Was this image compressed by OpenGL driver during loading ?
00081         bool m_compressed;
00082 
00083         //     [0]    [2]    ->(x)
00084         // [1]  +------+
00085         //      |      |
00086         //      |      |
00087         // [3]  +------+
00088         //
00089         //      |
00090         //      v
00091         //     (y)
00092         // To map these indices with previous one:
00093         // [0]:=[1]:=0.0f, [2]:=m_col_tex_coords, [3]:=m_row_tex_coords
00094 
00095 
00098         GLuint m_texId;
00099 
00102         void cleanup();
00103 
00106         void resetGlimage();
00107 
00110         void generateGLTexture();
00111         void generateGLSharedTexture(const GLImage* shared, const Rect& region);
00112         void validateShared();
00113 
00114         uint32_t m_chunk_size_w;
00115         uint32_t m_chunk_size_h;
00116 
00117         SDL_Color m_colorkey;
00118 
00119         GLImage* m_shared_img;
00120         // Holds Atlas ImagePtr if this is a shared image
00121         ImagePtr m_atlas_img;
00122         // Holds Atlas Name if this is a shared image
00123         std::string m_atlas_name;
00124     };
00125 
00126 }
00127 
00128 #endif
00129 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */