FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
renderbackend.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
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 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "renderbackend.h"
31 #include "video/devicecaps.h"
32 
33 namespace FIFE {
34  RenderBackend::RenderBackend(const SDL_Color& colorkey):
35  m_screen(NULL),
36  m_target(NULL),
37  m_compressimages(false),
38  m_useframebuffer(false),
39  m_usenpot(false),
40  m_isalphaoptimized(false),
41  m_iscolorkeyenabled(false),
42  m_colorkey(colorkey),
43  m_isMipmapping(false),
44  m_textureFilter(TEXTURE_FILTER_NONE),
45  m_maxAnisotropy(0),
46  m_monochrome(false),
47  m_isDepthBuffer(false),
48  m_alphaValue(0.3),
49  m_isframelimit(false),
50  m_frame_start(0),
51  m_framelimit(60) {
52 
53  m_isbackgroundcolor = false;
54  m_backgroundcolor.r = 0;
55  m_backgroundcolor.g = 0;
56  m_backgroundcolor.b = 0;
57  }
58 
60  }
61 
63  //delete m_screen;
64  //m_screen = NULL;
65  SDL_QuitSubSystem(SDL_INIT_VIDEO);
66  SDL_Quit();
67  }
68 
70  if (m_isframelimit) {
71  m_frame_start = SDL_GetTicks();
72  }
73  }
74 
76  if (m_isframelimit) {
77  uint16_t frame_time = SDL_GetTicks() - m_frame_start;
78  const float frame_limit = 1000.0f/m_framelimit;
79  if (frame_time < frame_limit) {
80  SDL_Delay(static_cast<Uint32>(frame_limit) - frame_time);
81  }
82  }
83  }
84 
86  return m_screenMode;
87  }
88 
90  return m_screen->w;
91  }
92 
94  return m_screen->h;
95  }
96 
97  const Rect& RenderBackend::getArea() const {
98  static Rect r(0, 0, m_screen->w, m_screen->h);
99  return r;
100  }
101 
102  void RenderBackend::pushClipArea(const Rect& cliparea, bool clear) {
103  ClipInfo ci;
104  ci.r = cliparea;
105  ci.clearing = clear;
106  m_clipstack.push(ci);
107  setClipArea(cliparea, clear);
108  }
109 
111  assert(!m_clipstack.empty());
112  m_clipstack.pop();
113  if (m_clipstack.empty()) {
114  setClipArea(getArea(), false);
115  } else {
116  ClipInfo ci = m_clipstack.top();
117  // instead of using ci.clearing, we set it to false
118  // to avoid double clearing
119  setClipArea(ci.r, false);
120  }
121  }
122 
124  if (!m_clipstack.empty()) {
125  return m_clipstack.top().r;
126  } else {
127  return getArea();
128  }
129  }
130 
132  setClipArea(getArea(), true);
133  }
134 
136  m_textureFilter = filter;
137  }
138 
140  return m_textureFilter;
141  }
142 
144  m_isMipmapping = enabled;
145  }
146 
148  return m_isMipmapping;
149  }
150 
152  return m_maxAnisotropy;
153  }
154 
156  m_monochrome = enabled;
157  }
158 
160  return m_monochrome;
161  }
162 
164  m_isDepthBuffer = enabled;
165  }
166 
168  return m_isDepthBuffer;
169  }
170 
172  m_alphaValue = alpha;
173  }
174 
176  return m_alphaValue;
177  }
178 
179  void RenderBackend::setColorKeyEnabled(bool colorkeyenable) {
180  m_iscolorkeyenabled = colorkeyenable;
181  }
182 
184  return m_iscolorkeyenabled;
185  }
186 
187  void RenderBackend::setColorKey(const SDL_Color& colorkey) {
188  m_colorkey = colorkey;
189  }
190 
191  const SDL_Color& RenderBackend::getColorKey() const {
192  return m_colorkey;
193  }
194 
196  if (r != m_backgroundcolor.r || g != m_backgroundcolor.g || b != m_backgroundcolor.b) {
197  m_isbackgroundcolor = true;
198  m_backgroundcolor.r = r;
199  m_backgroundcolor.g = g;
200  m_backgroundcolor.b = b;
201  }
202  }
203 
205  setBackgroundColor(0,0,0);
206  }
207 
208  const SDL_PixelFormat& RenderBackend::getPixelFormat() const {
209  return m_rgba_format;
210  }
211 
213  m_isframelimit = limited;
214  }
215 
217  return m_isframelimit;
218  }
219 
221  m_framelimit = framelimit;
222  }
223 
225  return m_framelimit;
226  }
227 
229  return m_target;
230  }
231 }
SDL_Surface * m_target
virtual void setClipArea(const Rect &cliparea, bool clear)=0
Sets given clip area into image.
RenderBackend(const SDL_Color &colorkey)
Constructor.
void setColorKey(const SDL_Color &colorkey)
Sets the global colorkey to use for images.
void setMonochromeEnabled(bool enabled)
Enables or disables monochrome rendering.
TextureFiltering getTextureFiltering() const
SDL_PixelFormat m_rgba_format
void setBackgroundColor(uint8_t r, uint8_t g, uint8_t b)
Set the background color.
uint32_t getHeight() const
bool isFrameLimitEnabled() const
Gets whether the frame limiter is in use.
int32_t getMaxAnisotropy() const
Gets max antisotropy for antisotropic filtering.
void setColorKeyEnabled(bool colorkeyenable)
Sets whether to use the colorkey feature.
uint16_t getFrameLimit() const
Gets the frame limit.
bool isMipmappingEnabled() const
void resetBackgroundColor()
Reset the background color to black.
bool isColorKeyEnabled() const
Gets whether the colorkey feature is in use.
unsigned char uint8_t
Definition: core.h:38
void pushClipArea(const Rect &cliparea, bool clear=true)
Pushes clip area to clip stack Clip areas define which area is drawn on screen.
const SDL_Color & getColorKey() const
Gets the global colorkey setting.
virtual void startFrame()
Called when a new frame starts.
void setMipmappingEnabled(bool enabled)
Enables or disables the usage of mipmapping.
void setAlphaTestValue(float alpha)
Sets the value for alpha test.
void setFrameLimit(uint16_t framelimit)
Sets the frame limit.
virtual ~RenderBackend()
Destructor.
void setTextureFiltering(TextureFiltering filter)
Sets the texture filtering method.
void popClipArea()
Pops clip area from clip stack.
unsigned short uint16_t
Definition: core.h:39
SDL_Surface * m_screen
void setDepthBufferEnabled(bool enabled)
Enables or disables depth buffer rendering.
SDL_Color m_backgroundcolor
bool isMonochromeEnabled() const
uint32_t getWidth() const
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
void clearClipArea()
Clears any possible clip areas.
void setFrameLimitEnabled(bool limited)
Sets whether to use the frame limiter.
SDL_Surface * getRenderTargetSurface()
Returns currently attached render surface.
TextureFiltering m_textureFilter
TextureFiltering
Definition: renderbackend.h:99
const SDL_PixelFormat & getPixelFormat() const
Gets the current screen rgba format.
ScreenMode m_screenMode
const Rect & getClipArea() const
Gets the current clip area.
void deinit()
Performs cleanup actions.
std::stack< ClipInfo > m_clipstack
unsigned int uint32_t
Definition: core.h:40
float getAlphaTestValue() const
bool isDepthBufferEnabled() const
const ScreenMode & getCurrentScreenMode() const
Get current screen mode.
const Rect & getArea() const