geometrydata.h 5.68 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-2013, 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 Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, 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
25
26
27
// 
// ================================================================================================

#ifndef GEOMETRYDATA_H__
#define GEOMETRYDATA_H__

28
#include "tgt/tgt_gl.h"
29
#include "tgt/bounds.h"
30
#include "core/datastructures/abstractdata.h"
31
#include <vector>
32

33
34
namespace tgt {
    class BufferObject;
35
    class GLCanvas;
36
37
}

schultezub's avatar
schultezub committed
38
namespace campvis {
39
    /**
40
     * Abstract base class for geometry data in CAMPVis.
41
     * 
42
43
44
45
46
47
48
49
50
51
52
     * GeometryData consists of a set of vertices (vec3) and optionally colors (vec4), texture 
     * coordinates (vec3) and/or normals (vec3) for each vertex.
     * GeometryData stores the geometry on the CPU side (local RAM) and takes care of transparently 
     * mapping it into GPU memory in order to render it using OpenGL. The mapping of vertex 
     * information to OpenGL vertex attributes is as follows:
     *  - Vertex positions: Vertex attribute 0
     *  - Vertex texture coordinates: Vertex attribute 1
     *  - Vertex colors: Vertex attribute 2
     *  - Vertex normals: Vertex attribute 3
     * 
     */    
53
    class CAMPVIS_CORE_API GeometryData : public AbstractData, public IHasWorldBounds {
54
    public:
55
56
57
58
59
        /**
         * Constructor
         * \param   vertexFeatures  List of features present for each vertex
         */
        explicit GeometryData();
60

61
62
63
64
        /**
         * Copy constructor
         * \param   rhs GeometryData to copy
         */
65
66
67
        GeometryData(const GeometryData& rhs);

        /**
68
         * Destructor, deletes VBOs/VAO if necessary.
69
         */
70
71
        virtual ~GeometryData();

72
73
74
75
76
        /**
         * Assignment operator.
         * \param   rhs GeometryData to assign to this.
         * \return  *this after assignment
         */
77
78
        GeometryData& operator=(const GeometryData& rhs);

79
        /// \see AbstractData::clone()
80
81
        virtual AbstractData* clone() const = 0;

82
83
84
85
        /**
         * Renders this GeometryData.
         * Must be called from a valid OpenGL context.
         */
86
        virtual void render(GLenum mode = GL_POLYGON) const = 0;
87
88
89
90
91
92
        
        /**
         * Returns the geometry extent in world coordinates.
         * \return  The geometry extent in world coordinates.
         */
        virtual tgt::Bounds getWorldBounds() const = 0;
93
94

        /**
95
96
97
         * Returns the Pointer to the OpenGL Buffer with the vertex positions.
         * May be 0 if not yet created.
         * \return  _verticesBuffer
98
99
100
         */
        const tgt::BufferObject* getVerticesBuffer() const;

101
102
103
104
105
        /**
         * Returns the Pointer to the OpenGL Buffer with the vertex texture coordinates.
         * May be 0 if none are present or not yet created.
         * \return  _texCoordsBuffer
         */
106
107
        const tgt::BufferObject* getTextureCoordinatesBuffer() const;

108
109
110
111
112
        /**
         * Returns the Pointer to the OpenGL Buffer with the vertex colors. 
         * May be 0 if none are present or not yet created.
         * \return  _colorsBuffer
         */
113
114
        const tgt::BufferObject* getColorsBuffer() const;

115
116
117
118
119
        /**
         * Returns the Pointer to the OpenGL Buffer with the vertex normals.
         * May be 0 if none are present or not yet created.
         * \return  _normalsBuffer
         */
120
121
        const tgt::BufferObject* getNormalsBuffer() const;

122
123
124
        /// \see AbstractData::getVideoMemoryFootprint()
        virtual size_t getVideoMemoryFootprint() const;

125
    protected:
126
127
128
129
130
        /**
         * Deletes all OpenGL BufferObjects.
         */
        void deleteBuffers() const;

131
        // mutable to support const lazy initialization
132
        mutable bool _buffersDirty;             ///< Flag whether the buffers are dirty (i.e. need to be (re)initialized)
133

134
        enum { NUM_BUFFERS = 4 };               ///< Number of buffers in _buffers array
135
136
137

        union {
            struct {
138
139
140
141
                mutable tgt::BufferObject* _verticesBuffer;     ///< Pointer to the OpenGL Buffer with the vertex positions
                mutable tgt::BufferObject* _texCoordsBuffer;    ///< Pointer to the OpenGL Buffer with the vertex texture coordinates
                mutable tgt::BufferObject* _colorsBuffer;       ///< Pointer to the OpenGL Buffer with the vertex colors
                mutable tgt::BufferObject* _normalsBuffer;      ///< Pointer to the OpenGL Buffer with the vertex normals
142
143
            };

144
            mutable tgt::BufferObject* _buffers[NUM_BUFFERS];   ///< Array of all buffers
145
146
147
        };

    private:
148
149

        static const std::string loggerCat_;
150
151
152
153
154
    };

}

#endif // GEOMETRYDATA_H__