FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
renderbackend.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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_RENDERBACKEND_H
23 #define FIFE_VIDEO_RENDERBACKEND_H
24 
25 // Standard C++ library includes
26 #include <string>
27 #include <vector>
28 
29 // Platform specific includes
30 #include "util/base/fife_stdint.h"
31 
32 // 3rd party library includes
33 #include <SDL.h>
34 #include <SDL_video.h>
35 
36 // FIFE includes
37 // These includes are split up in two parts, separated by one empty line
38 // First block: files included from the FIFE root src directory
39 // Second block: files included from the same folder
40 #include "util/base/singleton.h"
41 #include "util/structures/point.h"
42 #include "util/structures/rect.h"
43 #include "video/devicecaps.h"
44 
45 #include "image.h"
46 
47 namespace FIFE {
48 
49  class Image;
50 
52  class RenderBackend: public AbstractImage, public DynamicSingleton<RenderBackend> {
53  public:
57  RenderBackend(const SDL_Color& colorkey);
58 
61  virtual ~RenderBackend();
62 
66  virtual const std::string& getName() const = 0;
67 
70  virtual void startFrame() = 0;
71 
74  virtual void endFrame() = 0;
75 
78  virtual void init(const std::string& driver) = 0;
79 
82  virtual void clearBackBuffer() = 0;
83 
86  virtual void setLightingModel(unsigned int lighting) = 0;
87 
90  virtual unsigned int getLightingModel() const = 0;
91 
94  virtual void enableLighting() = 0;
95 
98  virtual void disableLighting() = 0;
99 
102  virtual void setLighting(float red, float green, float blue, float alpha) = 0;
103 
106  virtual void resetLighting() = 0;
107 
110  virtual void enableStencilTest() = 0;
111 
114  virtual void disableStencilTest() = 0;
115 
118  virtual void setStencilTest(Uint8 stencil_ref, unsigned int stencil_op, unsigned int stencil_func) = 0;
119 
122  virtual void resetStencilBuffer(Uint8 buffer) = 0;
123 
126  virtual Uint8 getStencilRef() const = 0;
127 
130  virtual void enableAlphaTest() = 0;
131 
134  virtual void disableAlphaTest() = 0;
135 
138  virtual void setAlphaTest(float ref_alpha) = 0;
139 
142  virtual void changeBlending(int scr, int dst) = 0;
143 
146  virtual void deinit();
147 
154  virtual Image* createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon) = 0;
155 
160  virtual Image* setScreenMode(const ScreenMode& mode) = 0;
161 
168  virtual Image* createImage(const uint8_t* data, unsigned int width, unsigned int height) = 0;
169 
175  virtual Image* createImage(SDL_Surface* surface) = 0;
176 
180  Image* getScreenImage() const { return m_screen; };
181 
184  void captureScreen(const std::string& filename);
185 
186  SDL_Surface* getSurface();
187 
191  const ScreenMode& getCurrentScreenMode() const;
192 
193  unsigned int getWidth() const;
194  unsigned int getHeight() const;
195  unsigned int getScreenWidth() const { return getWidth(); }
196  unsigned int getScreenHeight() const { return getHeight(); }
197  const Rect& getArea();
198  void getPixelRGBA(int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
199  void pushClipArea(const Rect& cliparea, bool clear=true);
200  void popClipArea();
201  const Rect& getClipArea() const;
202  void setAlphaOptimizerEnabled(bool enabled);
203  bool isAlphaOptimizerEnabled();
204  void saveImage(const std::string& filename);
205 
208  void setColorKeyEnabled(bool colorkeyenable);
209 
212  bool isColorKeyEnabled() const;
213 
216  void setColorKey(const SDL_Color& colorkey);
217 
220  const SDL_Color& getColorKey() const;
221 
222  protected:
223  Image* m_screen;
224  bool m_isalphaoptimized;
225  unsigned int m_chunkingsize;
226  bool m_iscolorkeyenabled;
227  SDL_Color m_colorkey;
228  ScreenMode m_screenMode;
229  };
230 }
231 
232 #endif