FIFE  2008.0
renderbackend.cpp
1 /***************************************************************************
2  * Copyright (C) 2005-2011 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 
78  const ScreenMode& RenderBackend::getCurrentScreenMode() const{
79  return m_screenMode;
80  }
81 
82  uint32_t RenderBackend::getWidth() const {
83  return m_screen->w;
84  }
85 
86  uint32_t RenderBackend::getHeight() const {
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  setClipArea(ci.r, ci.clearing);
111  }
112  }
113 
115  if (m_clipstack.empty()) {
116  return m_clipstack.top().r;
117  } else {
118  return getArea();
119  }
120  }
121 
123  setClipArea(getArea(), true);
124  }
125 
126 
127  void RenderBackend::setColorKeyEnabled(bool colorkeyenable) {
128  m_iscolorkeyenabled = colorkeyenable;
129  }
130 
132  return m_iscolorkeyenabled;
133  }
134 
135  void RenderBackend::setColorKey(const SDL_Color& colorkey) {
136  m_colorkey = colorkey;
137  }
138 
139  const SDL_Color& RenderBackend::getColorKey() const {
140  return m_colorkey;
141  }
142 
143  void RenderBackend::setBackgroundColor(uint8_t r, uint8_t g, uint8_t b) {
144  if (r != m_backgroundcolor.r || g != m_backgroundcolor.g || b != m_backgroundcolor.b) {
145  m_isbackgroundcolor = true;
146  m_backgroundcolor.r = r;
147  m_backgroundcolor.g = g;
148  m_backgroundcolor.b = b;
149  }
150  }
151 
153  setBackgroundColor(0,0,0);
154  }
155 
156  const SDL_PixelFormat& RenderBackend::getPixelFormat() const {
157  return m_rgba_format;
158  }
159 
161  m_isframelimit = limited;
162  }
163 
165  return m_isframelimit;
166  }
167 
168  void RenderBackend::setFrameLimit(uint16_t framelimit) {
169  m_framelimit = framelimit;
170  }
171 
172  uint16_t RenderBackend::getFrameLimit() const {
173  return m_framelimit;
174  }
175 
177  return m_target;
178  }
179 }
virtual void setClipArea(const Rect &cliparea, bool clear)=0
RenderBackend(const SDL_Color &colorkey)
void setColorKey(const SDL_Color &colorkey)
void setBackgroundColor(uint8_t r, uint8_t g, uint8_t b)
bool isFrameLimitEnabled() const
void setColorKeyEnabled(bool colorkeyenable)
uint16_t getFrameLimit() const
bool isColorKeyEnabled() const
void pushClipArea(const Rect &cliparea, bool clear=true)
const SDL_Color & getColorKey() const
virtual void startFrame()
void setFrameLimit(uint16_t framelimit)
virtual void endFrame()
void setFrameLimitEnabled(bool limited)
SDL_Surface * getRenderTargetSurface()
const SDL_PixelFormat & getPixelFormat() const
const Rect & getClipArea() const
const ScreenMode & getCurrentScreenMode() const
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39