renderSetup.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_RENDERSETUP_H
00006 #define BALL_VIEW_RENDERING_RENDERSETUP_H
00007 
00008 #ifndef BALL_VIEW_RENDERING_GLRENDERER_H
00009 # include <BALL/VIEW/RENDERING/glRenderer.h>
00010 #endif
00011 
00012 #ifndef BALL_VIEW_RENDERING_RENDERTARGET_H
00013 # include <BALL/VIEW/RENDERING/renderTarget.h>
00014 #endif
00015 
00016 #ifndef BALL_VIEW_RENDERING_GLRENDERWINDOW_H
00017 # include <BALL/VIEW/RENDERING/glRenderWindow.h>
00018 #endif
00019 
00020 #ifndef BALL_SYSTEM_MUTEX_H
00021 # include <BALL/SYSTEM/mutex.h>
00022 #endif
00023 
00024 #include <QtCore/qthread.h>
00025 
00026 namespace BALL {
00027   namespace VIEW {
00028 
00029     class Scene;
00030 
00036     class BALL_VIEW_EXPORT RenderSetup
00037       : public QThread
00038     {
00039       public:
00040         RenderSetup(Renderer* r, RenderTarget* t, Scene* scene, const Stage* stage);
00041 
00042         RenderSetup(const RenderSetup& rs);
00043 
00044         const RenderSetup& operator = (const RenderSetup& rs);
00045 
00046         // TODO: this should be boost smart pointers!
00047         Renderer*       renderer;
00048         RenderTarget*   target;
00049 
00050         enum STEREO_SETUP {
00051           NONE,
00052           LEFT_EYE,
00053           RIGHT_EYE
00054         };
00055 
00058         void init();
00059 
00062         void resize(Size width, Size height);
00063 
00070         void pauseRendering() { rendering_paused_ = true; }
00071 
00077         void startRendering() { rendering_paused_ = false; }
00078 
00081         bool isPaused() const { return rendering_paused_; }
00082 
00098         void setReceiveBufferUpdates(bool do_receive) { receive_updates_ = do_receive; }
00099 
00102         bool receivesBufferUpdates() const { return receive_updates_; };
00103 
00109         void updateCamera(const Camera* camera = 0);
00110 
00116         void setOffset(const Vector3& offset);
00117 
00124         void setStereoMode(STEREO_SETUP stereo) { stereo_setup_ = stereo; };
00125 
00130         void bufferRepresentation(const Representation& rep);
00131 
00136         void removeRepresentation(const Representation& rep);
00137 
00144         void renderToBuffer();
00145 
00148         bool exportPNG(const String& filename);
00149 
00152         void setLights(bool reset_all = false);
00153 
00156         void updateBackgroundColor();
00157         
00163         Position prepareGridTextures(const RegularData3D& grid, const ColorMap& map);
00164 
00170         void removeGridTextures(const RegularData3D& grid);
00171 
00175         Vector3 mapViewportTo3D(Position x, Position y);
00176 
00180         Vector2 map3DToViewport(const Vector3& vec);
00181 
00184         void pickObjects(Position x1, Position y1, Position x2, Position y2, List<GeometricObject*>& objects);
00185 
00194         void showRuler(bool show);
00195 
00198         void useContinuousLoop(bool use_loop);
00199 
00202         bool isContinuous() { return use_continuous_loop_; }
00203 
00210         virtual void makeCurrent();
00211 
00212         virtual void run();
00213 
00214       protected:
00215         // does the hard work and can be called from a continuous loop as well as from event-based rendering
00216         void renderToBuffer_();
00217 
00218         bool rendering_paused_;
00219         bool receive_updates_;
00220         bool use_offset_;
00221 
00222         Camera  camera_;
00223         Vector3 camera_offset_;
00224 
00225         STEREO_SETUP stereo_setup_;
00226 
00227         // switches between rendering continously and rendering upon events
00228         bool use_continuous_loop_;
00229 
00230         Scene* scene_;
00231         Stage const* stage_;
00232 
00233         // locks the renderer during updates and rendering
00234         mutable Mutex render_mutex_;
00235 
00236         Size width_;
00237         Size height_;
00238         bool do_resize_;
00239 
00240         bool show_ruler_;
00241 
00242         // This pointer is used to avoid uneccessary RTTI calls and casting. If the target is not a
00243         // GLRenderWindow or one of its derived classes, this pointer will simply be NULL
00244         GLRenderWindow* gl_target_;
00245     };
00246   }
00247 }
00248 
00249 #endif