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_isframelimit(false),
44  m_framelimit(60) {
45 
46  m_isbackgroundcolor = false;
47  m_backgroundcolor.r = 0;
48  m_backgroundcolor.g = 0;
49  m_backgroundcolor.b = 0;
50  }
51 
53  }
54 
56  //delete m_screen;
57  //m_screen = NULL;
58  SDL_QuitSubSystem(SDL_INIT_VIDEO);
59  SDL_Quit();
60  }
61 
63  if (m_isframelimit) {
64  m_frame_start = SDL_GetTicks();
65  }
66  }
67 
69  if (m_isframelimit) {
70  uint16_t frame_time = SDL_GetTicks() - m_frame_start;
71  const float frame_limit = 1000.0f/m_framelimit;
72  if (frame_time < frame_limit) {
73  SDL_Delay(static_cast<Uint32>(frame_limit) - frame_time);
74  }
75  }
76  }
77 
79  return m_screenMode;
80  }
81 
83  return m_screen->w;
84  }
85 
87  return m_screen->h;
88  }
89 
90  const Rect& RenderBackend::getArea() const {
91  static Rect r(0, 0, m_screen->w, m_screen->h);
92  return r;
93  }
94 
95  void RenderBackend::pushClipArea(const Rect& cliparea, bool clear) {
96  ClipInfo ci;
97  ci.r = cliparea;
98  ci.clearing = clear;
99  m_clipstack.push(ci);
100  setClipArea(cliparea, clear);
101  }
102 
104  assert(!m_clipstack.empty());
105  m_clipstack.pop();
106  if (m_clipstack.empty()) {
107  setClipArea(getArea(), false);
108  } else {
109  ClipInfo ci = m_clipstack.top();
110  // instead of using ci.clearing, we set it to false
111  // to avoid double clearing
112  setClipArea(ci.r, false);
113  }
114  }
115 
117  if (!m_clipstack.empty()) {
118  return m_clipstack.top().r;
119  } else {
120  return getArea();
121  }
122  }
123 
125  setClipArea(getArea(), true);
126  }
127 
128 
129  void RenderBackend::setColorKeyEnabled(bool colorkeyenable) {
130  m_iscolorkeyenabled = colorkeyenable;
131  }
132 
134  return m_iscolorkeyenabled;
135  }
136 
137  void RenderBackend::setColorKey(const SDL_Color& colorkey) {
138  m_colorkey = colorkey;
139  }
140 
141  const SDL_Color& RenderBackend::getColorKey() const {
142  return m_colorkey;
143  }
144 
146  if (r != m_backgroundcolor.r || g != m_backgroundcolor.g || b != m_backgroundcolor.b) {
147  m_isbackgroundcolor = true;
148  m_backgroundcolor.r = r;
149  m_backgroundcolor.g = g;
150  m_backgroundcolor.b = b;
151  }
152  }
153 
155  setBackgroundColor(0,0,0);
156  }
157 
158  const SDL_PixelFormat& RenderBackend::getPixelFormat() const {
159  return m_rgba_format;
160  }
161 
163  m_isframelimit = limited;
164  }
165 
167  return m_isframelimit;
168  }
169 
171  m_framelimit = framelimit;
172  }
173 
175  return m_framelimit;
176  }
177 
179  return m_target;
180  }
181 }
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.
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.
void setColorKeyEnabled(bool colorkeyenable)
Sets whether to use the colorkey feature.
uint16_t getFrameLimit() const
Gets the frame limit.
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 setFrameLimit(uint16_t framelimit)
Sets the frame limit.
virtual ~RenderBackend()
Destructor.
void popClipArea()
Pops clip area from clip stack.
unsigned short uint16_t
Definition: core.h:39
SDL_Surface * m_screen
SDL_Color m_backgroundcolor
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.
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
const ScreenMode & getCurrentScreenMode() const
Get current screen mode.
const Rect & getArea() const