renderbackend.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
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 // Standard C++ library includes
00023 
00024 // 3rd party library includes
00025 
00026 // FIFE includes
00027 // These includes are split up in two parts, separated by one empty line
00028 // First block: files included from the FIFE root src directory
00029 // Second block: files included from the same folder
00030 #include "renderbackend.h"
00031 
00032 namespace FIFE {
00033     
00034     const unsigned int DEFAULT_CHUNKING_SIZE = 256;
00035     const unsigned int MAX_CHUNKING_SIZE = 262144;  // pixels!
00036     
00037     RenderBackend::RenderBackend(const SDL_Color& colorkey): 
00038         m_screen(NULL), 
00039         m_isalphaoptimized(false), 
00040         m_chunkingsize(DEFAULT_CHUNKING_SIZE),
00041         m_iscolorkeyenabled(false),
00042         m_colorkey(colorkey) {
00043     }
00044 
00045 
00046     RenderBackend::~RenderBackend() {
00047     }
00048 
00049     void RenderBackend::deinit() {
00050         delete m_screen;
00051         m_screen = NULL;
00052         SDL_QuitSubSystem(SDL_INIT_VIDEO);
00053     }
00054 
00055     void RenderBackend::captureScreen(const std::string& filename) {
00056         m_screen->saveImage(filename);
00057     }
00058     
00059     void RenderBackend::pushClipArea(const Rect& cliparea, bool clear) {
00060         assert(m_screen);
00061         m_screen->pushClipArea(cliparea, clear);
00062         }
00063     
00064     void RenderBackend::popClipArea() {
00065         assert(m_screen);
00066         m_screen->popClipArea();
00067     }
00068     
00069     const Rect& RenderBackend::getClipArea() const {
00070         assert(m_screen);
00071         return m_screen->getClipArea();
00072     }
00073     
00074     SDL_Surface* RenderBackend::getSurface() {
00075         assert(m_screen);
00076         return m_screen->getSurface();
00077     }
00078     
00079     unsigned int RenderBackend::getWidth() const {
00080         assert(m_screen);
00081         return m_screen->getWidth();
00082     }
00083     
00084     unsigned int RenderBackend::getHeight() const {
00085         assert(m_screen);
00086         return m_screen->getHeight();
00087     }
00088     
00089     const Rect& RenderBackend::getArea() {
00090         assert(m_screen);
00091         SDL_Surface* s = m_screen->getSurface();
00092         static Rect r(0, 0, s->w, s->h);
00093         return r;
00094     }
00095     
00096     void RenderBackend::getPixelRGBA(int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) {
00097         assert(m_screen);
00098         m_screen->getPixelRGBA(x, y, r, g, b, a);
00099     }
00100     
00101     void RenderBackend::saveImage(const std::string& filename) {
00102         assert(m_screen);
00103         m_screen->saveImage(filename);
00104     }
00105     
00106     void RenderBackend::setAlphaOptimizerEnabled(bool enabled) {
00107         assert(m_screen);
00108         m_screen->setAlphaOptimizerEnabled(enabled);
00109     }
00110     
00111     bool RenderBackend::isAlphaOptimizerEnabled() {
00112         assert(m_screen);
00113         return m_screen->isAlphaOptimizerEnabled();
00114     }
00115     
00116     void RenderBackend::setChunkingSize(unsigned int size) {
00117         if (size > MAX_CHUNKING_SIZE) {
00118             size = MAX_CHUNKING_SIZE;
00119         }
00120         m_chunkingsize = 1;
00121         while (m_chunkingsize < size) {
00122             m_chunkingsize <<= 1;
00123         }
00124     }
00125     
00126     unsigned int RenderBackend::getChunkingSize() {
00127         return m_chunkingsize;
00128     }
00129 
00130     void RenderBackend::setColorKeyEnabled(bool colorkeyenable) {
00131         m_iscolorkeyenabled = colorkeyenable;
00132     }
00133 
00134     bool RenderBackend::isColorKeyEnabled() const {
00135         return m_iscolorkeyenabled;
00136     }
00137 
00138     void RenderBackend::setColorKey(const SDL_Color& colorkey) {
00139         m_colorkey = colorkey;
00140     }
00141 
00142     const SDL_Color& RenderBackend::getColorKey() const {
00143         return m_colorkey;
00144     }
00145 }