Loading...
Searching...
No Matches
renderSetup.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_VIEW_RENDERING_RENDERSETUP_H
#define BALL_VIEW_RENDERING_RENDERSETUP_H
#ifndef BALL_VIEW_RENDERING_GLRENDERER_H
# include <BALL/VIEW/RENDERING/RENDERERS/glRenderer.h>
#endif
#ifndef BALL_VIEW_RENDERING_RENDERTARGET_H
# include <BALL/VIEW/RENDERING/renderTarget.h>
#endif
#ifndef BALL_VIEW_RENDERING_GLRENDERWINDOW_H
# include <BALL/VIEW/RENDERING/glRenderWindow.h>
#endif
#ifndef BALL_SYSTEM_MUTEX_H
# include <BALL/SYSTEM/mutex.h>
#endif
#include <QtCore/QThread>
#include <QtCore/QWaitCondition>
#include <boost/enable_shared_from_this.hpp>
#include <deque>
class QImage;
namespace BALL {
namespace VIEW {
class ColorMap;
class Scene;
class BALL_VIEW_EXPORT RenderSetup
: public QThread, public boost::enable_shared_from_this<RenderSetup>
{
public:
RenderSetup(Renderer* r, RenderTarget* t, Scene* scene, const Stage* stage);
RenderSetup(const RenderSetup& rs);
virtual ~RenderSetup();
const RenderSetup& operator = (const RenderSetup& rs);
// TODO: this should be boost smart pointers!
Renderer* renderer;
RenderTarget* target;
enum RendererType
{
UNKNOWN_RENDERER = 0,
OPENGL_RENDERER,
POV_RENDERER,
VRML_RENDERER,
STL_RENDERER,
TILING_RENDERER,
RTFACT_RENDERER
};
enum STEREO_SETUP {
NONE,
LEFT_EYE,
RIGHT_EYE
};
void init();
void resize(Size width, Size height);
void pauseRendering() { rendering_paused_ = true; }
void startRendering() { rendering_paused_ = false; }
bool isPaused() const { return rendering_paused_; }
RendererType getRendererType() { return renderer_type_; }
void setReceiveBufferUpdates(bool do_receive) { receive_updates_ = do_receive; }
bool receivesBufferUpdates() const { return receive_updates_; };
void updateCamera(const Camera* camera = 0);
void setOffset(const Vector3& offset);
void setStereoMode(STEREO_SETUP stereo) { stereo_setup_ = stereo; };
void bufferRepresentation(const Representation& rep);
void removeRepresentation(const Representation& rep);
void renderToBuffer();
bool exportPNG(const String& filename);
void setLights(bool reset_all = false);
void updateBackgroundColor();
void setupEnvironmentMap(const QImage& image);
Position prepareGridTextures(const RegularData3D& grid, const ColorMap& map);
void removeGridTextures(const RegularData3D& grid);
Vector3 mapViewportTo3D(Position x, Position y);
Vector2 map3DToViewport(const Vector3& vec);
void pickObjects(Position x1, Position y1, Position x2, Position y2, std::list<GeometricObject*>& objects);
void showRuler(bool show);
void updateMaterialForRepresentation(const Representation* rep);
void projectionModeChanged();
void useContinuousLoop(bool use_loop);
void stop() { MutexLocker ml(&render_mutex_); about_to_quit_ = true; }
bool isAboutToQuit() { return about_to_quit_; }
bool isContinuous() { return use_continuous_loop_; }
void setTimeToLive(int ttl) { ttl_ = ttl; }
int getTimeToLive() const { return ttl_; }
void exportPNGAfterTTL(String filename) { export_after_ttl_ = true; export_after_ttl_filename_ = filename; }
virtual void makeCurrent();
virtual void run();
void lock() { render_mutex_.lock(); }
void unlock() { render_mutex_.unlock(); }
mutable QWaitCondition wait_for_render;
// locks the renderer before the next render call
mutable Mutex loop_mutex;
bool bufferIsReady() { return buffer_is_ready_; }
bool isReadyToSwap();
void setBufferReady(bool is_ready) { buffer_is_ready_ = is_ready; }
std::deque<boost::shared_ptr<RenderSetup> >& getDependentRenderers() { return keep_in_sync_; }
void makeDependentOn(boost::shared_ptr<RenderSetup>& partner) { keep_in_sync_.push_back(partner); }
protected:
// does the hard work and can be called from a continuous loop as well as from event-based rendering
void renderToBuffer_();
void initType_();
bool rendering_paused_;
bool receive_updates_;
bool use_offset_;
bool about_to_quit_;
Camera camera_;
Vector3 camera_offset_;
STEREO_SETUP stereo_setup_;
// switches between rendering continously and rendering upon events
bool use_continuous_loop_;
Scene* scene_;
Stage const* stage_;
// locks the renderer during updates and rendering
mutable Mutex render_mutex_;
bool show_ruler_;
// This pointer is used to avoid uneccessary RTTI calls and casting. If the target is not a
// GLRenderWindow or one of its derived classes, this pointer will simply be NULL
GLRenderWindow* gl_target_;
// This pointer is used to avoid uneccessary RTTI calls and casting. If the renderer is not a
// GLRenderer or one of its derived classes, this pointer will simply be NULL
GLRenderer* gl_renderer_;
// The number of render operations to perform before destruction
int ttl_;
bool export_after_ttl_;
String export_after_ttl_filename_;
// a list of render setups that should be synchronized with this one so that buffer
// swaps only happen simulatneously
std::deque<boost::shared_ptr<RenderSetup> > keep_in_sync_;
bool buffer_is_ready_;
// the type of the encapsulated renderer
RendererType renderer_type_;
};
class BALL_VIEW_EXPORT RenderToBufferFinishedEvent
: public QEvent
{
public:
RenderToBufferFinishedEvent(boost::shared_ptr<RenderSetup> renderer)
: QEvent(static_cast<QEvent::Type>(RENDER_TO_BUFFER_FINISHED_EVENT)),
renderer_(renderer)
{};
boost::shared_ptr<RenderSetup> getRenderer() { return renderer_; }
protected:
boost::shared_ptr<RenderSetup> renderer_;
};
}
}
#endif
BALL_VIEW_EXPORT
#define BALL_VIEW_EXPORT
Definition COMMON/global.h:52
BALL::String
Definition string.h:57
BALL::VIEW::Camera
Definition camera.h:24
BALL::VIEW::ColorMap
Definition colorMap.h:30
BALL::VIEW::GLRenderWindow
Definition glRenderWindow.h:40
BALL::VIEW::GLRenderer
Definition glRenderer.h:76
BALL::VIEW::RenderSetup::RendererType
RendererType
Definition renderSetup.h:63
BALL::VIEW::RenderSetup::TILING_RENDERER
@ TILING_RENDERER
Used for offscreen rendering.
Definition renderSetup.h:80
BALL::VIEW::RenderSetup::STL_RENDERER
@ STL_RENDERER
Renders into an STL file.
Definition renderSetup.h:77
BALL::VIEW::RenderSetup::OPENGL_RENDERER
@ OPENGL_RENDERER
Standard OpenGL renderer.
Definition renderSetup.h:68
BALL::VIEW::RenderSetup::RTFACT_RENDERER
@ RTFACT_RENDERER
RTfact renderer (depends on the RTfact library).
Definition renderSetup.h:83
BALL::VIEW::RenderSetup::POV_RENDERER
@ POV_RENDERER
Renders into a POVRay file.
Definition renderSetup.h:71
BALL::VIEW::RenderSetup::VRML_RENDERER
@ VRML_RENDERER
Renders into a VRML file (deprecated).
Definition renderSetup.h:74
BALL::VIEW::RenderSetup::UNKNOWN_RENDERER
@ UNKNOWN_RENDERER
A fallback.
Definition renderSetup.h:65
BALL::VIEW::RenderSetup::export_after_ttl_filename_
String export_after_ttl_filename_
Definition renderSetup.h:354
BALL::VIEW::RenderSetup::RenderSetup
RenderSetup(const RenderSetup &rs)
BALL::VIEW::RenderSetup::setReceiveBufferUpdates
void setReceiveBufferUpdates(bool do_receive)
Definition renderSetup.h:138
BALL::VIEW::RenderSetup::updateCamera
void updateCamera(const Camera *camera=0)
BALL::VIEW::RenderSetup::use_continuous_loop_
bool use_continuous_loop_
Definition renderSetup.h:332
BALL::VIEW::RenderSetup::exportPNG
bool exportPNG(const String &filename)
BALL::VIEW::RenderSetup::setLights
void setLights(bool reset_all=false)
BALL::VIEW::RenderSetup::lock
void lock()
Definition renderSetup.h:292
BALL::VIEW::RenderSetup::camera_offset_
Vector3 camera_offset_
Definition renderSetup.h:327
BALL::VIEW::RenderSetup::setBufferReady
void setBufferReady(bool is_ready)
Definition renderSetup.h:306
BALL::VIEW::RenderSetup::setStereoMode
void setStereoMode(STEREO_SETUP stereo)
Definition renderSetup.h:164
BALL::VIEW::RenderSetup::getTimeToLive
int getTimeToLive() const
Definition renderSetup.h:276
BALL::VIEW::RenderSetup::renderToBuffer
void renderToBuffer()
BALL::VIEW::RenderSetup::keep_in_sync_
std::deque< boost::shared_ptr< RenderSetup > > keep_in_sync_
Definition renderSetup.h:358
BALL::VIEW::RenderSetup::startRendering
void startRendering()
Definition renderSetup.h:113
BALL::VIEW::RenderSetup::useContinuousLoop
void useContinuousLoop(bool use_loop)
BALL::VIEW::RenderSetup::show_ruler_
bool show_ruler_
Definition renderSetup.h:340
BALL::VIEW::RenderSetup::isPaused
bool isPaused() const
Definition renderSetup.h:117
BALL::VIEW::RenderSetup::mapViewportTo3D
Vector3 mapViewportTo3D(Position x, Position y)
BALL::VIEW::RenderSetup::renderToBuffer_
void renderToBuffer_()
BALL::VIEW::RenderSetup::isReadyToSwap
bool isReadyToSwap()
Returns true iff bufferIsReady() holds for this renderer and all dependent ones.
BALL::VIEW::RenderSetup::prepareGridTextures
Position prepareGridTextures(const RegularData3D &grid, const ColorMap &map)
BALL::VIEW::RenderSetup::loop_mutex
Mutex loop_mutex
Definition renderSetup.h:297
BALL::VIEW::RenderSetup::exportPNGAfterTTL
void exportPNGAfterTTL(String filename)
Definition renderSetup.h:280
BALL::VIEW::RenderSetup::setupEnvironmentMap
void setupEnvironmentMap(const QImage &image)
BALL::VIEW::RenderSetup::init
void init()
BALL::VIEW::RenderSetup::buffer_is_ready_
bool buffer_is_ready_
Definition renderSetup.h:360
BALL::VIEW::RenderSetup::wait_for_render
QWaitCondition wait_for_render
Definition renderSetup.h:295
BALL::VIEW::RenderSetup::projectionModeChanged
void projectionModeChanged()
BALL::VIEW::RenderSetup::RenderSetup
RenderSetup(Renderer *r, RenderTarget *t, Scene *scene, const Stage *stage)
BALL::VIEW::RenderSetup::getDependentRenderers
std::deque< boost::shared_ptr< RenderSetup > > & getDependentRenderers()
Definition renderSetup.h:309
BALL::VIEW::RenderSetup::stage_
Stage const * stage_
Definition renderSetup.h:335
BALL::VIEW::RenderSetup::map3DToViewport
Vector2 map3DToViewport(const Vector3 &vec)
BALL::VIEW::RenderSetup::gl_renderer_
GLRenderer * gl_renderer_
Definition renderSetup.h:348
BALL::VIEW::RenderSetup::stop
void stop()
Definition renderSetup.h:254
BALL::VIEW::RenderSetup::ttl_
int ttl_
Definition renderSetup.h:351
BALL::VIEW::RenderSetup::rendering_paused_
bool rendering_paused_
Definition renderSetup.h:320
BALL::VIEW::RenderSetup::scene_
Scene * scene_
Definition renderSetup.h:334
BALL::VIEW::RenderSetup::export_after_ttl_
bool export_after_ttl_
Definition renderSetup.h:353
BALL::VIEW::RenderSetup::pickObjects
void pickObjects(Position x1, Position y1, Position x2, Position y2, std::list< GeometricObject * > &objects)
BALL::VIEW::RenderSetup::about_to_quit_
bool about_to_quit_
Definition renderSetup.h:324
BALL::VIEW::RenderSetup::STEREO_SETUP
STEREO_SETUP
Definition renderSetup.h:86
BALL::VIEW::RenderSetup::LEFT_EYE
@ LEFT_EYE
Definition renderSetup.h:88
BALL::VIEW::RenderSetup::RIGHT_EYE
@ RIGHT_EYE
Definition renderSetup.h:89
BALL::VIEW::RenderSetup::NONE
@ NONE
Definition renderSetup.h:87
BALL::VIEW::RenderSetup::render_mutex_
Mutex render_mutex_
Definition renderSetup.h:338
BALL::VIEW::RenderSetup::camera_
Camera camera_
Definition renderSetup.h:326
BALL::VIEW::RenderSetup::bufferIsReady
bool bufferIsReady()
Returns true if the buffer has been filled and just waits for painting.
Definition renderSetup.h:300
BALL::VIEW::RenderSetup::target
RenderTarget * target
Definition renderSetup.h:58
BALL::VIEW::RenderSetup::run
virtual void run()
BALL::VIEW::RenderSetup::updateBackgroundColor
void updateBackgroundColor()
BALL::VIEW::RenderSetup::stereo_setup_
STEREO_SETUP stereo_setup_
Definition renderSetup.h:329
BALL::VIEW::RenderSetup::renderer_type_
RendererType renderer_type_
Definition renderSetup.h:363
BALL::VIEW::RenderSetup::initType_
void initType_()
BALL::VIEW::RenderSetup::bufferRepresentation
void bufferRepresentation(const Representation &rep)
BALL::VIEW::RenderSetup::renderer
Renderer * renderer
Definition renderSetup.h:57
BALL::VIEW::RenderSetup::removeRepresentation
void removeRepresentation(const Representation &rep)
BALL::VIEW::RenderSetup::resize
void resize(Size width, Size height)
BALL::VIEW::RenderSetup::~RenderSetup
virtual ~RenderSetup()
BALL::VIEW::RenderSetup::setTimeToLive
void setTimeToLive(int ttl)
Definition renderSetup.h:272
BALL::VIEW::RenderSetup::removeGridTextures
void removeGridTextures(const RegularData3D &grid)
BALL::VIEW::RenderSetup::makeDependentOn
void makeDependentOn(boost::shared_ptr< RenderSetup > &partner)
Definition renderSetup.h:312
BALL::VIEW::RenderSetup::showRuler
void showRuler(bool show)
BALL::VIEW::RenderSetup::pauseRendering
void pauseRendering()
Definition renderSetup.h:106
BALL::VIEW::RenderSetup::receivesBufferUpdates
bool receivesBufferUpdates() const
Definition renderSetup.h:142
BALL::VIEW::RenderSetup::setOffset
void setOffset(const Vector3 &offset)
BALL::VIEW::RenderSetup::getRendererType
RendererType getRendererType()
Definition renderSetup.h:121
BALL::VIEW::RenderSetup::unlock
void unlock()
Definition renderSetup.h:293
BALL::VIEW::RenderSetup::updateMaterialForRepresentation
void updateMaterialForRepresentation(const Representation *rep)
BALL::VIEW::RenderSetup::isAboutToQuit
bool isAboutToQuit()
Definition renderSetup.h:258
BALL::VIEW::RenderSetup::gl_target_
GLRenderWindow * gl_target_
Definition renderSetup.h:344
BALL::VIEW::RenderSetup::isContinuous
bool isContinuous()
Definition renderSetup.h:262
BALL::VIEW::RenderSetup::receive_updates_
bool receive_updates_
Definition renderSetup.h:321
BALL::VIEW::RenderSetup::makeCurrent
virtual void makeCurrent()
BALL::VIEW::RenderSetup::use_offset_
bool use_offset_
Definition renderSetup.h:322
BALL::VIEW::RenderTarget
Definition renderTarget.h:227
BALL::VIEW::RenderToBufferFinishedEvent::getRenderer
boost::shared_ptr< RenderSetup > getRenderer()
Definition renderSetup.h:377
BALL::VIEW::RenderToBufferFinishedEvent::RenderToBufferFinishedEvent
RenderToBufferFinishedEvent(boost::shared_ptr< RenderSetup > renderer)
Definition renderSetup.h:372
BALL::VIEW::RenderToBufferFinishedEvent::renderer_
boost::shared_ptr< RenderSetup > renderer_
Definition renderSetup.h:380
BALL::VIEW::Renderer
Definition renderer.h:55
BALL::VIEW::Representation
Definition representation.h:59
BALL::VIEW::Scene
Definition scene.h:141
BALL::VIEW::Stage
Definition stage.h:239
QEvent
QThread
glRenderWindow.h
glRenderer.h
BALL::Vector2
TVector2< float > Vector2
Definition vector2.h:771
mutex.h
BALL::VIEW
Definition constraints.h:35
BALL::VIEW::RENDER_TO_BUFFER_FINISHED_EVENT
@ RENDER_TO_BUFFER_FINISHED_EVENT
Event posted by renderers after a new buffer is available.
Definition VIEW/KERNEL/common.h:98
BALL
Definition constants.h:13
BALL::MutexLocker
TMutexLocker< BALL_DEFAULT_MUTEXLOCKER_TYPE, BALL_DEFAULT_MUTEX_TYPE > MutexLocker
Definition mutex.h:226
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::RegularData3D
TRegularData3D< float > RegularData3D
Definition regularData3D.h:515
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
BALL::Mutex
TMutex< BALL_DEFAULT_MUTEX_TYPE > Mutex
Definition mutex.h:224
BALL::Vector3
TVector3< float > Vector3
Definition vector3.h:1084
renderTarget.h