bufferedRenderer.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 #ifndef BALL_VIEW_RENDERING_BUFFEREDRENDERER_H
00006 #define BALL_VIEW_RENDERING_BUFFEREDRENDERER_H
00007 
00008 #ifndef BALL_VIEW_RENDERING_RENDERER_H
00009 # include <BALL/VIEW/RENDERING/renderer.h>
00010 #endif
00011 
00012 #ifndef BALL_VIEW_RENDERING_RENDERTARGET_H
00013 # include <BALL/VIEW/RENDERING/renderTarget.h>
00014 #endif
00015 
00016 namespace BALL
00017 {
00018   namespace VIEW
00019   {
00029     class BufferedRenderer
00030       : public Renderer
00031     {
00032     public:
00033       BufferedRenderer()
00034        : Renderer(), 
00035          bufferFormat() { }
00036 
00037       virtual ~BufferedRenderer() throw() { }
00038 
00043       bool setFrameBufferFormat(const FrameBufferFormat &format)
00044       {
00045         if( supports(format) )
00046         {
00047           bufferFormat = format;
00048                     formatUpdated();          
00049           return true;
00050         }
00051 
00052         return false;
00053       }
00054 
00059       void renderToBuffer(RenderTarget* renderTarget, const Stage& stage)
00060                 throw(BALL::Exception::InvalidFormat, BALL::Exception::NoBufferAvailable)
00061       {
00062         prepareBufferedRendering(stage);
00063 
00064         FrameBufferPtr buffer = renderTarget->getBuffer();
00065         assert(buffer);
00066 
00067         if (buffer->getFormat() != bufferFormat)
00068         {
00069           throw BALL::Exception::InvalidFormat(__FILE__, __LINE__, "Buffer with wrong framebuffer format supplied");
00070         }
00071 
00072         renderToBufferImpl( buffer );
00073 
00074         renderTarget->releaseBuffer(buffer);
00075       }
00076 
00078       virtual bool supports(const PixelFormat &format) const = 0;
00079 
00086       virtual Resolution getSupportedResolution(
00087         const Resolution &min, const Resolution &max,
00088         const PixelFormat &format) const
00089                 throw(BALL::Exception::FormatUnsupported) = 0;
00090 
00091     protected:
00092 
00098       virtual bool supports(const FrameBufferFormat &format) const = 0;
00099 
00103       virtual void formatUpdated() = 0;
00104 
00107       virtual void prepareBufferedRendering(const Stage& stage) = 0;
00108 
00113       virtual void renderToBufferImpl(FrameBufferPtr buffer) = 0;            
00114         
00116       const FrameBufferFormat &getFrameBufferFormat() const
00117       { return bufferFormat; }
00118 
00119     private:
00120 
00121       FrameBufferFormat bufferFormat;
00122     };
00123   } //namespace VIEW
00124 
00125 } //namespace BALL
00126 
00127 
00128 #endif // BALL_VIEW_RENDERING_BUFFEREDRENDERER_H