geometrydata.h 4.13 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, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

#ifndef GEOMETRYDATA_H__
#define GEOMETRYDATA_H__

#include "core/datastructures/abstractdata.h"
34
#include <vector>
35

36
37
namespace tgt {
    class BufferObject;
38
    class QtCanvas;
39
40
}

schultezub's avatar
schultezub committed
41
namespace campvis {
42
43
44
45
46
47
48
49
50
    /**
     * Abstract base class for data handled by a DataHandle and stored in a DataContainer.
     * 
     * \todo 
     */
    class GeometryData : public AbstractData {
    public:
        GeometryData();

51
52
53
54
55
        GeometryData(const GeometryData& rhs);

        /**
         * Destructor, deletes VBOs/VAO if necessary. Hence, needs a valid OpenGL context
         */
56
57
        virtual ~GeometryData();

58
59
        GeometryData& operator=(const GeometryData& rhs);

60
61
        static void deleteBuffers(std::vector<tgt::BufferObject*> buffers);

62
63
        virtual AbstractData* clone() const = 0;

64
65
66
        /// \see AbstractData::getVideoMemoryFootprint()
        virtual size_t getVideoMemoryFootprint() const;

67
68
69
70
        /**
         * Renders this GeometryData.
         * Must be called from a valid OpenGL context.
         */
71
        virtual void render() const = 0;
72
73
74
75

        /**
         * Creates the OpenGL VBOs and the VAO for this geometry.
         * Must be called from a valid OpenGL context.
76
         * \note    When overwriting this method, make sure to call base class method first!
77
         */
78
        virtual void createGLBuffers() const;
79
80
81
82
83
84
85
86
87

        const tgt::BufferObject* getVerticesBuffer() const;

        const tgt::BufferObject* getTextureCoordinatesBuffer() const;

        const tgt::BufferObject* getColorsBuffer() const;

        const tgt::BufferObject* getNormalsBuffer() const;

88
    protected:
89
90
        // mutable to support const lazy initialization
        mutable bool _buffersInitialized;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

        enum { NUM_BUFFERS = 4 };

        union {
            struct {
                mutable tgt::BufferObject* _verticesBuffer;
                mutable tgt::BufferObject* _texCoordsBuffer;
                mutable tgt::BufferObject* _colorsBuffer;
                mutable tgt::BufferObject* _normalsBuffer;
            };

            mutable tgt::BufferObject* _buffers[NUM_BUFFERS];
        };

    private:
        mutable tgt::QtCanvas* _context;        ///< OpenGL context the buffers were created in (so that they can be deleted correctly)
107
108
109
110
111
    };

}

#endif // GEOMETRYDATA_H__