Skip to content

Commit bcd88ac

Browse files
committed
Documenting
- Buffer_objects - Edge_container - Io_plugins - Primitive_container - Scene_group_item - Scene_interface - Scene_item - Triangle_container - Viewer Interface
1 parent 9aeb012 commit bcd88ac

File tree

13 files changed

+288
-36
lines changed

13 files changed

+288
-36
lines changed

Polyhedron/demo/Polyhedron/Edge_container.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void Edge_container::initGL(const Scene_item& item, Viewer_interface *viewer) co
2727
VBOs[Indices] =
2828
new CGAL::Three::Vbo("indices",
2929
QOpenGLBuffer::IndexBuffer);
30+
if(VAOs[viewer])
31+
delete VAOs[viewer];
3032
VAOs[viewer] = new CGAL::Three::Vao(item.getShaderProgram(program_id, viewer));
3133
VAOs[viewer]->addVbo(VBOs[Vertices]);
3234
VAOs[viewer]->addVbo(VBOs[Indices]);
7.24 KB
Loading
742 Bytes
Loading

Three/demo/Three/Example_plugin/Dock_widget_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private Q_SLOTS:
8585
}
8686
//! [action]
8787
//! [closure]
88-
void closure()
88+
void closure() Q_DECL_OVERRIDE
8989
{
9090
dock_widget->hide();
9191
}

Three/include/CGAL/Three/Buffer_objects.h

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ namespace CGAL {
1111
namespace Three {
1212

1313
struct Vbo;
14-
14+
//!
15+
//! \brief The Vao struct is a wrapper for the `QOpenGLVertexArrayObject`.
16+
//! They are context dependent, most of the time it means `Viewer` dependent.
17+
//!
1518
struct Vao{
1619

1720
QOpenGLVertexArrayObject* vao;
1821
QOpenGLShaderProgram* program;
1922
std::vector<Vbo*> vbos;
20-
23+
//!
24+
//! \brief Creates a `Vao`.
25+
//! \param program the `QOpenGLShaderProgram` associated with this `Vao`.
26+
//! \attention This must be called within a valid OpenGLContext.
27+
//! Most of the time, initGL() functions are safe places to do so.
28+
//!
2129
Vao( QOpenGLShaderProgram* program)
2230
:vao(new QOpenGLVertexArrayObject()),
2331
program(program)
@@ -30,25 +38,31 @@ struct Vao{
3038
delete vao;
3139
}
3240

41+
//!Adds a `Vbo` to the list of Vbos.
3342
void addVbo(Vbo* vbo)
3443
{
3544
vbos.push_back(vbo);
3645
}
3746

47+
//!Makes the `Vao` and its program active until `release()` is called.
3848
void bind()
3949
{
4050
program->bind();
4151
vao->bind();
4252
}
4353

54+
//!Makes the `Vao` and its program not active.
4455
void release()
4556
{
4657
vao->release();
4758
program->release();
4859
}
4960
};
5061

51-
62+
//!
63+
//! \brief The Vbo struct is a wrapper for the `QOpenGLBufferObject` item.
64+
//! It contains the data necessary for the rendering of any displayed entity.
65+
//! A Vbo can be shared between Vaos of the same context.
5266
struct Vbo
5367
{
5468

@@ -62,7 +76,19 @@ struct Vbo
6276
int tupleSize;
6377
int stride;
6478
bool allocated;
65-
79+
//!
80+
//! \brief Creates a `Vbo`.
81+
//! \param attribute the name of the corresponding data in the shader.
82+
//! \param vbo_type is almost always `QOpenGLBuffer::VertexBuffer` but can be `QOpenGLBuffer::IndexBuffer`
83+
//! if it contains the indices for an indexed rendering.
84+
//! \param data_type the GL data type. Mostly GL_FLOAT.
85+
//! \param offset the offset in the buffer. See OpenGL documentation.
86+
//! \param tupleSize the size of the tuple. If it contains vector_3s, then tuple_size is 3.
87+
//! \param stride the stride for the buffer. See OpenGL documentation.
88+
89+
//! \attention This must be called within a valid OpenGLContext.
90+
//! Most of the time, initGL() functions are safe places to do so.
91+
//!
6692
Vbo(
6793
const char* attribute,
6894
QOpenGLBuffer::Type vbo_type = QOpenGLBuffer::VertexBuffer,
@@ -88,16 +114,23 @@ struct Vbo
88114
vbo.destroy();
89115
}
90116

117+
//! Makes the `Vbo` active until `release()` is called.
91118
bool bind()
92119
{
93120
return vbo.bind();
94121
}
95122

123+
//!Makes the `Vbo` and its program not active.
96124
void release()
97125
{
98126
vbo.release();
99127
}
100128

129+
//!
130+
//! \brief allocate gives CPU data to the GPU.
131+
//! \param data the content of the buffer.
132+
//! \param datasize the number of bytes in `data`.
133+
//!
101134
void allocate(void* data, int datasize)
102135
{
103136
this->data = data;

Three/include/CGAL/Three/Edge_container.h

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,60 @@ using namespace CGAL::Three;
3737
namespace CGAL {
3838
namespace Three {
3939

40+
//!
41+
//! \brief The Edge_container struct wraps the OpenGL data for drawing lines.
42+
//!
4043
struct DEMO_FRAMEWORK_EXPORT Edge_container :public Primitive_container
4144
{
4245

4346
enum vbosName {
44-
Vertices = 0,
45-
Indices,
46-
Normals,
47-
Colors,
48-
Radius,
49-
Barycenters,
50-
NbOfVbos
47+
Vertices = 0, //! Designates the buffer that contains the vertex coordinates.
48+
Indices, //! Designates the buffer that contains the vertex indices.
49+
Normals, //! Designates the buffer that contains the normal coordinates.
50+
Colors, //! Designates the buffer that contains the color components.
51+
Radius, //! Designates the buffer that contains the radius of wire spheres.
52+
Barycenters, //! Designates the buffer that contains the barycenter of c3t3 facets or the center of wire spheres, for example.
53+
NbOfVbos //! Designates the size of the VBOs vector for `Edge_containers`s
5154
};
5255

56+
//!
57+
//! \brief The constructor.
58+
//! \param program is the `QOpenGLShaderProgram` that is used by this `Edge_container` `Vao`.
59+
//! \param indexed must be `true` if the data is indexed, `false` otherwise. If `true`, VBOs[Indices] must be filled.
60+
//!
5361
Edge_container(int program, bool indexed);
62+
63+
//!
64+
//! \brief initGL creates the `Vbo`s and `Vao`s of this `Edge_container`.
65+
//! \attention It must be called within a valid OpenGL context. The `draw()` function of an item is always a safe place to call this.
66+
//!
67+
//! \todo Is it a good idea to call InitGL of each item in the scene so the developper doesn't have to worry about this in each draw() of each item ?
68+
//!
69+
//! \param item the `Scene_item` that uses this `Edge_container`.
70+
//! \param viewer the active `Viewer_interface`.
71+
//!
5472
void initGL(const Scene_item &item, Viewer_interface *viewer) const Q_DECL_OVERRIDE;
73+
74+
//!
75+
//! \brief draw is the function that actually renders the data.
76+
//! \param item the `Scene_item` that uses this `Edge_container`.
77+
//! \param viewer the active `Viewer_interface`.
78+
//! \param is_color_uniform must be `false` if `VBOs`[`Colors`] is not empty, `true` otherwise.
79+
//!
5580
void draw(const Scene_item &item, CGAL::Three::Viewer_interface* viewer,
5681
bool is_color_uniform,
5782
QOpenGLFramebufferObject* = NULL) const Q_DECL_OVERRIDE;
5883
//drawing variables
84+
//!
85+
//! \brief plane contains the coefficients of the plane used in some programs :
86+
//! - `PROGRAM_CUTPLANE_SPHERES`
87+
//! - `PROGRAM_C3T3_EDGES`
88+
//!
5989
QVector4D plane;
90+
//!
91+
//! \brief f_matrix is a Matrix4x4 used in some programs:
92+
//! - PROGRAM_WITHOUT_LIGHT
93+
//!
6094
QMatrix4x4 f_matrix;
6195
}; //end of class Triangle_container
6296
}

Three/include/CGAL/Three/Polyhedron_demo_io_plugin_interface.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ class Polyhedron_demo_io_plugin_interface
5959
//! Specifies if the io_plugin is able to load an item or not.
6060
//! This must be overriden.
6161
virtual bool canLoad() const = 0;
62-
//! Loads an item from a file.
63-
//! This must be overriden.
64-
virtual Scene_item* load(QFileInfo fileinfo, CGAL::Three::Scene_interface* scene, QMainWindow*) = 0;
62+
63+
//! \brief Loads an item from a file.
64+
//!
65+
//! //! This must be overriden.
66+
//! \param fileinfo the path to the item file.
67+
//! \param scene the `Scene_interface` that will hold the item. Mostly used for group_items.
68+
//! \param mw the application `MainWindow`. Mostly used for getting the `is_polyhedron_mode` property.
69+
//! \return the loaded `Scene_item`
70+
//!
71+
virtual Scene_item* load(QFileInfo fileinfo, CGAL::Three::Scene_interface* scene, QMainWindow* mw) = 0;
6572
//!Specifies if the io_plugin can save the item or not.
6673
//!This must be overriden.
6774
virtual bool canSave(const Scene_item*) = 0;

Three/include/CGAL/Three/Primitive_container.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ class QOpenGLFramebufferObject;
3838
namespace CGAL {
3939
namespace Three {
4040

41+
//!
42+
//! \brief The Primitive_container struct provides a base for the OpenGL data wrappers.
43+
//!
4144
struct DEMO_FRAMEWORK_EXPORT Primitive_container
4245
{
4346

47+
//!
48+
//! \brief Primitive_container constructor.
49+
//! \param program the `QOpenGLShaderProgram` used by the VAOs.
50+
//! \param indexed must be `true` if the data is indexed, `false` otherwise.
51+
//!
4452
Primitive_container(int program, bool indexed)
4553
: program_id(program), indexed(indexed),
4654
flat_size(0), idx_size(0)
@@ -56,17 +64,41 @@ struct DEMO_FRAMEWORK_EXPORT Primitive_container
5664
removeViewer(viewer);
5765
}
5866
}
67+
68+
//!
69+
//! \brief initGL initializes the OpenGL containers.
70+
//! \attention It must be called within a valid OpenGL context. The `draw()` function of an item is always a safe place to call this.
71+
//!
72+
//! \param item the `Scene_item` that uses this container.
73+
//! \param viewer the active `Viewer_interface`.
5974
virtual void initGL(const CGAL::Three::Scene_item& item, CGAL::Three::Viewer_interface* viewer) const = 0;
75+
76+
//!
77+
//! \brief removeViewer deletes and removes the Vao assigned to `viewer` from `Vaos`.
78+
//! \param viewer the `Viewer_interface` to remove.
79+
//!
6080
void removeViewer(CGAL::Three::Viewer_interface* viewer) const
6181
{
6282
delete VAOs[viewer];
6383
VAOs.remove(viewer);
6484
}
6585

86+
//!
87+
//! \brief draw is the function that actually renders the data.
88+
//! \param item the `Scene_item` that uses this container.
89+
//! \param viewer the active `Viewer_interface`.
90+
//! \param is_color_uniform should be `true` if the item is unicolor.
91+
//!
6692
virtual void draw(const Scene_item &item, CGAL::Three::Viewer_interface* viewer,
6793
bool is_color_uniform,
6894
QOpenGLFramebufferObject* fbo = NULL) const = 0;
6995

96+
//!
97+
//! \brief initializeBuffers sends the data to the GPU memory.
98+
//!
99+
//! It actually fills up the buffers with the data provided by `Vbo::allocate()`;
100+
//! \param viewer the active `Viewer_interface`.
101+
//!
70102
void initializeBuffers(CGAL::Three::Viewer_interface* viewer) const
71103
{
72104
if(!VAOs[viewer])
@@ -102,6 +134,9 @@ struct DEMO_FRAMEWORK_EXPORT Primitive_container
102134
is_init[viewer] = true;
103135
}
104136

137+
//!
138+
//! \brief reset_vbos de-allocates the `Vbo`s. It must be called when the `Vbo`s data is updated.
139+
//!
105140
void reset_vbos()
106141
{
107142
Q_FOREACH(CGAL::Three::Vbo* vbo, VBOs)
@@ -112,16 +147,46 @@ struct DEMO_FRAMEWORK_EXPORT Primitive_container
112147
}
113148
}
114149

150+
//!
151+
//! \brief VAOs holds the `Vao`s for each `Viewer_interface`. As a `Vao` is context dependent, there must be one Vao for each `Viewer_interface`.
152+
//!
115153
mutable QMap<CGAL::Three::Viewer_interface*, Vao*> VAOs;
154+
//!
155+
//! \brief VBOs holds the `Vbo`s containing the data for this container.
156+
//!
116157
mutable std::vector<Vbo*> VBOs;
158+
//!
159+
//! \brief program_id is the `OpenGL_program_IDs` used with this container.
160+
//!
117161
int program_id;
162+
//!
163+
//! \brief indexed specifies if the data is indexed or not. This matters for the internal drawing functions.
164+
//!
118165
bool indexed;
119166
mutable QMap<CGAL::Three::Viewer_interface*, bool> is_init;
120167
mutable QMap<CGAL::Three::Viewer_interface*, bool> is_gl_init;
168+
169+
//!
170+
//! \brief is_selected must be filled with the selected state of the item that holds this container everytime this state changes.
171+
//! If program_id doesn't use this property, it can be ignored.
172+
//!
121173
mutable bool is_selected;
174+
//!
175+
//! \brief flat_size contains the number of units contained in the vertex buffer.
176+
//! You can ignore it if `indexed` is true.
177+
//!
122178
mutable std::size_t flat_size;
179+
//! \brief flat_size contains the number of units contained in the barycenter buffer.
180+
//! You can ignore it if `program_id` is not an instanced program (like PROGRAM_SPHERES, PROGRAM_CUTPLANE_SPHERES,
181+
//! PROGRAM_INSTANCED_WIRE or PROGRAM_INSTANCED).
123182
mutable std::size_t center_size;
183+
//!
184+
//! \brief idx_size contains the number of indices in an `Index_buffer`. You can ignore it if `indexed` is `false`.
185+
//!
124186
mutable std::size_t idx_size;
187+
//!
188+
//! \brief color contains the color of the data. Ignore it if `is_color_uniform` is `false` in `draw()`.
189+
//!
125190
mutable QColor color;
126191
}; //end of class Triangle_container
127192

Three/include/CGAL/Three/Scene_group_item.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class DEMO_FRAMEWORK_EXPORT Scene_group_item : public Scene_item
4747
{
4848
Q_OBJECT
4949
public :
50+
//!
51+
//! \brief The `Scene_group_item` constructor.
52+
//! \param name The name of this item.
53+
//! \param scene the scene that will hold this item.
54+
//!
5055
Scene_group_item(QString name,Scene_interface *scene);
5156
~Scene_group_item() {}
5257
//!Sets the scene;
@@ -122,23 +127,20 @@ public :
122127
///@{
123128
//!\brief draws all the children
124129
//!
125-
//! Calls `Scene_item::draw()`, then calls `Scene_item::drawEdges()`
126-
//! and `Scene_item::drawPoints` for each child if its current
130+
//! Calls `Scene_item::draw()`for each child if its current
127131
//! rendering mode is adequat.
128132
//! @see #RenderingMode
129133
virtual void draw(CGAL::Three::Viewer_interface*, int pass,
130134
bool is_writing, QOpenGLFramebufferObject*fbo) const;
131135
//!\brief draws all the children
132136
//!
133-
//! Calls `Scene_item::drawEdges()`, then calls `Scene_item::draw()`
134-
//! and `Scene_item::drawPoints` for each child if its current
137+
//! Calls `Scene_item::drawEdges()`for each child if its current
135138
//! rendering mode is adequat.
136139
//! @see #RenderingMode
137140
virtual void drawEdges(CGAL::Three::Viewer_interface*) const;
138141
//!\brief draws all the children
139142
//!
140-
//! Calls `Scene_item::drawPoints()`, then calls `Scene_item::draw()`
141-
//! and `Scene_item::drawEdges()` for each child if its current
143+
//! Calls `Scene_item::drawPoints()`for each child if its current
142144
//! rendering mode is adequat.
143145
//! @see #RenderingMode
144146
virtual void drawPoints(CGAL::Three::Viewer_interface*) const;
@@ -224,6 +226,10 @@ public :
224226
void moveDown(int);
225227

226228
public Q_SLOTS:
229+
//!
230+
//! \brief adjustIds maintains the list of children up to date when an item has been erased.
231+
//! \param removed_id the index of the item that has been erased.
232+
//!
227233
void adjustIds(Scene_interface::Item_id removed_id)
228234
{
229235
for(int i = 0; i < children.size(); ++i)

Three/include/CGAL/Three/Scene_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class Scene_interface {
129129
virtual Item_id selectionBindex() const = 0;
130130

131131
//!\brief The scene's Bbox
132+
//!\param all detemines if the items that are not visible
133+
//! should be taken into account in the resulting Bbox.
134+
//! `true` means they should.
132135
//!@returns the scene's bounding box
133136
//! @see Scene_interface::Bbox
134137
virtual Bbox bbox(bool all = false) const = 0;

0 commit comments

Comments
 (0)