# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1286380193 0 # Node ID 5f381fa3476997795401e63d4985040789e82430 # Parent 46b95d06c8c2f7b1bf9ae647c734985d3b213c66 * Added the clearBackBuffer() function to the renderbackends. * Renamed setClearScreen() to setClearBackBuffer() * The SDL render backend now honors what was set with setClearBackBuffer() * Documented testRenderedViewPort() * The OpenGL backend no longer clears the screen every frame by default. testRenderedViewPort() takes care of clearing the screen for now. Note: if the user overrides the default and enables clearing of the backbuffer that it may be cleared twice in one frame (OpenGL only)! diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/opengl/renderbackendopengl.cpp --- a/engine/core/video/opengl/renderbackendopengl.cpp Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/opengl/renderbackendopengl.cpp Wed Oct 06 15:49:53 2010 +0000 @@ -43,7 +43,7 @@ m_rgba_format = *(testsurface->format); SDL_FreeSurface(testsurface); - m_clear = true; + m_clear = false; } const std::string& RenderBackendOpenGL::getName() const { @@ -64,6 +64,11 @@ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // temporary hack } + void RenderBackendOpenGL::clearBackBuffer() { + GLDisable flag(GL_SCISSOR_TEST); + glClear(GL_COLOR_BUFFER_BIT); + } + Image* RenderBackendOpenGL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs, const std::string& title, const std::string& icon) { delete m_screen; m_screen = 0; @@ -134,8 +139,7 @@ void RenderBackendOpenGL::startFrame() { if(m_clear) { - GLDisable flag(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT); + clearBackBuffer(); } } diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/opengl/renderbackendopengl.h --- a/engine/core/video/opengl/renderbackendopengl.h Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/opengl/renderbackendopengl.h Wed Oct 06 15:49:53 2010 +0000 @@ -45,6 +45,8 @@ void startFrame(); void endFrame(); void init(); + void clearBackBuffer(); + Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen, const std::string& title, const std::string& icon); Image* createImage(const uint8_t* data, unsigned int width, unsigned int height); Image* createImage(SDL_Surface* surface); diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/renderbackend.cpp --- a/engine/core/video/renderbackend.cpp Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/renderbackend.cpp Wed Oct 06 15:49:53 2010 +0000 @@ -34,6 +34,7 @@ RenderBackend::RenderBackend(const SDL_Color& colorkey): m_screen(NULL), + m_clear(false), m_isalphaoptimized(false), m_iscolorkeyenabled(false), m_colorkey(colorkey) { diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/renderbackend.h --- a/engine/core/video/renderbackend.h Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/renderbackend.h Wed Oct 06 15:49:53 2010 +0000 @@ -75,6 +75,10 @@ */ virtual void init() = 0; + /** Forces a clear of the backbuffer + */ + virtual void clearBackBuffer() = 0; + /** Performs cleanup actions. */ virtual void deinit(); @@ -103,11 +107,6 @@ */ virtual Image* createImage(SDL_Surface* surface) = 0; - /** Sets if the screen (backbuffer) should be cleared before rendering the next frame - * @param clear true = clear screen before next frame, false = do not clear screen - */ - void setClearScreen(bool clear) { m_clear = clear; }; - /** Returns a pointer to the main screen Image * @return A pointer to the main screen Image, or 0 if no mainscreen exists. */ @@ -147,6 +146,11 @@ */ const SDL_Color& getColorKey() const; + /** Sets if the backbuffer should be cleared before rendering the next frame. + * @param clear true = clear screen before next frame, false = do not clear screen + */ + void setClearBackBuffer(bool clear) { m_clear = clear; }; + protected: Image* m_screen; bool m_clear; diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/sdl/renderbackendsdl.cpp --- a/engine/core/video/sdl/renderbackendsdl.cpp Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.cpp Wed Oct 06 15:49:53 2010 +0000 @@ -60,6 +60,16 @@ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // temporary hack } + void RenderBackendSDL::clearBackBuffer() { + SDL_Rect rect; + rect.x = 0; + rect.y = 0; + rect.w = getWidth(); + rect.h = getHeight(); + SDL_SetClipRect(m_screen->getSurface(), &rect); + SDL_FillRect(m_screen->getSurface(), 0, 0x00); + } + Image* RenderBackendSDL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs, const std::string& title, const std::string& icon) { Uint32 flags = 0; if (fs) { @@ -120,13 +130,9 @@ } void RenderBackendSDL::startFrame() { - SDL_Rect rect; - rect.x = 0; - rect.y = 0; - rect.w = getWidth(); - rect.h = getHeight(); - SDL_SetClipRect(m_screen->getSurface(), &rect); - SDL_FillRect(m_screen->getSurface(), 0, 0x00); + if (m_clear) { + clearBackBuffer(); + } } void RenderBackendSDL::endFrame() { diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/sdl/renderbackendsdl.h --- a/engine/core/video/sdl/renderbackendsdl.h Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.h Wed Oct 06 15:49:53 2010 +0000 @@ -47,6 +47,8 @@ void startFrame(); void endFrame(); void init(); + void clearBackBuffer(); + Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen, const std::string& title, const std::string& icon); Image* createImage(const uint8_t* data, unsigned int width, unsigned int height); Image* createImage(SDL_Surface* surface); diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/video/video.i --- a/engine/core/video/video.i Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/video/video.i Wed Oct 06 15:49:53 2010 +0000 @@ -172,7 +172,7 @@ bool isColorKeyEnabled() const; void setColorKey(const SDL_Color& colorkey); const SDL_Color& getColorKey() const; - void setClearScreen(bool clear); + void setClearBackBuffer(bool clear); }; enum MouseCursorType { diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/view/camera.cpp --- a/engine/core/view/camera.cpp Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/view/camera.cpp Wed Oct 06 15:49:53 2010 +0000 @@ -129,7 +129,7 @@ delete r_it->second; } m_renderers.clear(); - m_renderbackend->setClearScreen(true); + m_renderbackend->setClearBackBuffer(true); delete m_map_observer; } @@ -448,10 +448,9 @@ } if(trec1 && trec2 && trec3 && trec4) { - m_renderbackend->setClearScreen(false); return false; } - m_renderbackend->setClearScreen(true); + m_renderbackend->clearBackBuffer(); return true; } diff -r 46b95d06c8c2 -r 5f381fa34769 engine/core/view/camera.h --- a/engine/core/view/camera.h Wed Oct 06 14:09:24 2010 +0000 +++ b/engine/core/view/camera.h Wed Oct 06 15:49:53 2010 +0000 @@ -278,10 +278,15 @@ void onRendererPipelinePositionChanged(RendererBase* renderer); void onRendererEnabledChanged(RendererBase* renderer); + /** Use with OpenGL only! Checks to see if the entire viewport was rendered last frame. + * If so it wont clear the backbuffer. + */ bool testRenderedViewPort(); + /** Renders camera */ void render(); + private: friend class MapObserver; void addLayer(Layer* layer);