00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "renderbackend.h"
00031 #include "video/devicecaps.h"
00032
00033 namespace FIFE {
00034 RenderBackend::RenderBackend(const SDL_Color& colorkey):
00035 m_screen(NULL),
00036 m_target(NULL),
00037 m_compressimages(false),
00038 m_useframebuffer(false),
00039 m_usenpot(false),
00040 m_isalphaoptimized(false),
00041 m_iscolorkeyenabled(false),
00042 m_colorkey(colorkey),
00043 m_isframelimit(false),
00044 m_framelimit(60) {
00045
00046 m_isbackgroundcolor = false;
00047 m_backgroundcolor.r = 0;
00048 m_backgroundcolor.g = 0;
00049 m_backgroundcolor.b = 0;
00050 }
00051
00052 RenderBackend::~RenderBackend() {
00053 }
00054
00055 void RenderBackend::deinit() {
00056
00057
00058 SDL_QuitSubSystem(SDL_INIT_VIDEO);
00059 SDL_Quit();
00060 }
00061
00062 void RenderBackend::startFrame() {
00063 if (m_isframelimit) {
00064 m_frame_start = SDL_GetTicks();
00065 }
00066 }
00067
00068 void RenderBackend::endFrame () {
00069 if (m_isframelimit) {
00070 uint16_t frame_time = SDL_GetTicks() - m_frame_start;
00071 const float frame_limit = 1000.0f/m_framelimit;
00072 if (frame_time < frame_limit) {
00073 SDL_Delay(static_cast<Uint32>(frame_limit) - frame_time);
00074 }
00075 }
00076 }
00077
00078 const ScreenMode& RenderBackend::getCurrentScreenMode() const{
00079 return m_screenMode;
00080 }
00081
00082 uint32_t RenderBackend::getWidth() const {
00083 return m_screen->w;
00084 }
00085
00086 uint32_t RenderBackend::getHeight() const {
00087 return m_screen->h;
00088 }
00089
00090 const Rect& RenderBackend::getArea() const {
00091 static Rect r(0, 0, m_screen->w, m_screen->h);
00092 return r;
00093 }
00094
00095 void RenderBackend::pushClipArea(const Rect& cliparea, bool clear) {
00096 ClipInfo ci;
00097 ci.r = cliparea;
00098 ci.clearing = clear;
00099 m_clipstack.push(ci);
00100 setClipArea(cliparea, clear);
00101 }
00102
00103 void RenderBackend::popClipArea() {
00104 assert(!m_clipstack.empty());
00105 m_clipstack.pop();
00106 if (m_clipstack.empty()) {
00107 setClipArea(getArea(), false);
00108 } else {
00109 ClipInfo ci = m_clipstack.top();
00110 setClipArea(ci.r, ci.clearing);
00111 }
00112 }
00113
00114 const Rect& RenderBackend::getClipArea() const {
00115 if (m_clipstack.empty()) {
00116 return m_clipstack.top().r;
00117 } else {
00118 return getArea();
00119 }
00120 }
00121
00122 void RenderBackend::clearClipArea() {
00123 setClipArea(getArea(), true);
00124 }
00125
00126
00127 void RenderBackend::setColorKeyEnabled(bool colorkeyenable) {
00128 m_iscolorkeyenabled = colorkeyenable;
00129 }
00130
00131 bool RenderBackend::isColorKeyEnabled() const {
00132 return m_iscolorkeyenabled;
00133 }
00134
00135 void RenderBackend::setColorKey(const SDL_Color& colorkey) {
00136 m_colorkey = colorkey;
00137 }
00138
00139 const SDL_Color& RenderBackend::getColorKey() const {
00140 return m_colorkey;
00141 }
00142
00143 void RenderBackend::setBackgroundColor(uint8_t r, uint8_t g, uint8_t b) {
00144 if (r != m_backgroundcolor.r || g != m_backgroundcolor.g || b != m_backgroundcolor.b) {
00145 m_isbackgroundcolor = true;
00146 m_backgroundcolor.r = r;
00147 m_backgroundcolor.g = g;
00148 m_backgroundcolor.b = b;
00149 }
00150 }
00151
00152 void RenderBackend::resetBackgroundColor() {
00153 setBackgroundColor(0,0,0);
00154 }
00155
00156 const SDL_PixelFormat& RenderBackend::getPixelFormat() const {
00157 return m_rgba_format;
00158 }
00159
00160 void RenderBackend::setFrameLimitEnabled(bool limited) {
00161 m_isframelimit = limited;
00162 }
00163
00164 bool RenderBackend::isFrameLimitEnabled() const {
00165 return m_isframelimit;
00166 }
00167
00168 void RenderBackend::setFrameLimit(uint16_t framelimit) {
00169 m_framelimit = framelimit;
00170 }
00171
00172 uint16_t RenderBackend::getFrameLimit() const {
00173 return m_framelimit;
00174 }
00175
00176 SDL_Surface* RenderBackend::getRenderTargetSurface() {
00177 return m_target;
00178 }
00179 }