campvispainter.h 3.97 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
#ifndef CAMPVISPAINTER_H__
#define CAMPVISPAINTER_H__
27

schultezub's avatar
schultezub committed
28
#include "sigslot/sigslot.h"
schultezub's avatar
schultezub committed
29
30
#include "tbb/atomic.h"
#include "tbb/compat/condition_variable"
31

schultezub's avatar
schultezub committed
32
#include "tgt/logmanager.h"
33
#include "tgt/painter.h"
schultezub's avatar
schultezub committed
34
35
36

namespace tgt {
    class Shader;
37
    class QtThreadedCanvas;
38
    class Texture;
schultezub's avatar
schultezub committed
39
40
}

schultezub's avatar
schultezub committed
41
namespace campvis {
42
    class AbstractPipeline;
schultezub's avatar
schultezub committed
43
44

    /**
45
     * Painter class for CAMPVis, rendering the render target of an AbstractPipeline.
schultezub's avatar
schultezub committed
46
     */
47
    class CampVisPainter : public tgt::Painter, public sigslot::has_slots<> {
schultezub's avatar
schultezub committed
48
    public:
49
        /**
50
         * Creates a new CampVisPainter rendering the render target of \a pipeline on \a canvas.
51
52
53
         * \param   canvas      Canvas to render on
         * \param   pipeline    Pipeline to render
         */
54
        CampVisPainter(tgt::GLCanvas* canvas, AbstractPipeline* pipeline);
schultezub's avatar
schultezub committed
55

56
57
58
        /**
         * Destructor, stops and waits for the rendering thread if it's still running.
         */
59
        virtual ~CampVisPainter();
60
61

        /**
62
         * Schedule a repaint job for the pipeline's render target
63
         */
64
        virtual void repaint();
65
66

        /// \see tgt::Painter::sizeChanged
67
        virtual void sizeChanged(const tgt::ivec2& size);
68
69
70
71

        /**
         * Initializes the painter, i.e. loads the OpenGL shader.
         */
schultezub's avatar
schultezub committed
72
        virtual void init();
73
74
75
76

        /**
         * Deinitializes the painter, i.e. disposes its shader.
         */
77
        virtual void deinit();
schultezub's avatar
schultezub committed
78

79
80
81
82
83
84
85
86
87
88
        /**
         * Sets the target canvas for rendering
         * \param   canvas  Canvas to render on, must be of type QtThreadedCanvas
         */
        virtual void setCanvas(tgt::GLCanvas* canvas);

        /**
         * Pipeline with the render target to render.
         * \param   pipeline    Pipeline to render
         */
89
        void setPipeline(AbstractPipeline* pipeline);
90

91
92
        void setErrorTexture(tgt::Texture* texture);

93
94
95
96
        /**
         * Slot being notified when the pipeline's render target changed.
         */
        void onRenderTargetChanged();
schultezub's avatar
schultezub committed
97
98

    private:
99
100
101
102
103
        /**
         * Performs the actual rendering of the pipeline's render target
         */
        virtual void paint();

schultezub's avatar
schultezub committed
104
        static const std::string loggerCat_;
schultezub's avatar
schultezub committed
105

106
        AbstractPipeline* _pipeline;                        ///< Pipeline to render
schultezub's avatar
schultezub committed
107
        tgt::Shader* _copyShader;                           ///< Shader for copying the render target to the framebuffer.
108
109
        tbb::atomic<bool> _dirty;                           ///< Flag whether render result is dirty and needs to be rerendered.
        std::condition_variable _renderCondition;           ///< conditional wait condition for rendering
110
111

        tgt::Texture* _errorTexture;
schultezub's avatar
schultezub committed
112
113
114
    };

}
115

schultezub's avatar
schultezub committed
116
#endif // CAMPVISPAINTER_H__