BALL  1.4.1
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>
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, std::list<GeometricObject*>& objects);
00185 
00194         void showRuler(bool show);
00195 
00198         void projectionModeChanged();
00199 
00202         void useContinuousLoop(bool use_loop);
00203 
00206         bool isContinuous() { return use_continuous_loop_; }
00207 
00214         virtual void makeCurrent();
00215 
00216         virtual void run();
00217 
00218       protected:
00219         // does the hard work and can be called from a continuous loop as well as from event-based rendering
00220         void renderToBuffer_();
00221 
00222         bool rendering_paused_;
00223         bool receive_updates_;
00224         bool use_offset_;
00225 
00226         Camera  camera_;
00227         Vector3 camera_offset_;
00228 
00229         STEREO_SETUP stereo_setup_;
00230 
00231         // switches between rendering continously and rendering upon events
00232         bool use_continuous_loop_;
00233 
00234         Scene* scene_;
00235         Stage const* stage_;
00236 
00237         // locks the renderer during updates and rendering
00238         mutable Mutex render_mutex_;
00239 
00240         Size width_;
00241         Size height_;
00242         bool do_resize_;
00243 
00244         bool show_ruler_;
00245 
00246         // This pointer is used to avoid uneccessary RTTI calls and casting. If the target is not a
00247         // GLRenderWindow or one of its derived classes, this pointer will simply be NULL
00248         GLRenderWindow* gl_target_;
00249     };
00250   }
00251 }
00252 
00253 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines