GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Glip::CorePipeline::GeometryModel Class Reference

Geometry stored on the host. More...

#include <Geometry.hpp>

Inheritance diagram for Glip::CorePipeline::GeometryModel:
Inheritance graph

Public Types

enum  GeometryType {
  CustomModel,
  StandardQuad,
  ReversedQuad,
  PointsGrid2D,
  PointsGrid3D,
  Unknown
}
 Description of the type of geometry (automatic). More...
 

Public Member Functions

 GeometryModel (const GeometryModel &mdl)
 GeometryModel copy constructor. More...
 
unsigned int getNumVertices (void) const
 Get the number of vertices. More...
 
unsigned int getNumElements (void) const
 Get the number of GL primitives (elements). More...
 
const GLfloat & x (GLuint i) const
 Read the X coordinate of the vertex at given index. More...
 
const GLfloat & y (GLuint i) const
 Read the Y coordinate of the vertex at given index. More...
 
const GLfloat & z (GLuint i) const
 Read the Z coordinate of the vertex at given index. More...
 
const GLfloat & ny (GLuint i) const
 Access the Y coordinate of the normal at given index. More...
 
const GLfloat & u (GLuint i) const
 Access the U coordinate of the texel at given index. More...
 
const GLfloat & v (GLuint i) const
 Access the V coordinate of the texel at given index. More...
 
const GLuint & a (GLuint i) const
 Access the index of the first vertex of the element at given index. More...
 
const GLuint & b (GLuint i) const
 Access the index of the second vertex of the element at given index. More...
 
const GLuint & c (GLuint i) const
 Access the index of the third vertex of the element at given index. More...
 
bool testIndices (void) const
 Test if all the indices are valid. More...
 
bool operator== (const GeometryModel &mdl) const
 Test if two models are identical. More...
 
HdlVBOgetVBO (GLenum freq) const
 Get the VBO corresponding to this model. It is not recommended to use directly the VBO but, instead, use a GeometryInstance object. More...
 

Static Public Member Functions

static int getNumVerticesInPrimitive (const GLenum &_primitiveGL)
 Get the number of vertices per element for the given primitive. More...
 
static int getPrimitiveStride (const GLenum &_primitiveGL)
 Get the stride between elements of the given primitive. More...
 

Public Attributes

const GeometryType type
 Geometry Type.
 
const bool hasNormals
 True if it has texture coordinates attached.
 
const bool hasTexCoords
 Dimension of the geometry (either 2 or 3).
 
const int dim
 True if it has normals data attached.
 
const int numVerticesPerElement
 Number of vertices per elements of the geometry.
 
const int elementStride
 Stride between the elements.
 
const GLenum primitiveGL
 ID of the primitive for GL.
 

Protected Member Functions

 GeometryModel (GeometryType _type, int _dim, GLenum _primitiveGL, bool _hasNormals, bool _hasTexCoords)
 Geometry model constructor. More...
 
void reserveVertices (size_t nVertices)
 Prepare the memory to receive a number of vertices. More...
 
void increaseVerticesReservation (size_t nNewVertices)
 Prepare the memory to receive a new number of vertices. More...
 
void reserveElements (size_t nVertices)
 Prepare the memory to receive a number of elements. More...
 
void increaseElementsReservation (size_t nNewVertices)
 Prepare the memory to receive a new number of elements. More...
 
void addVertices2DInterleaved (const size_t N, const GLfloat *interleavedXY, const GLfloat *interleavedNormalsXY=NULL, const GLfloat *interleavedUV=NULL)
 Add multiple vertives in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More...
 
void addVertices2D (const size_t N, const GLfloat *x, const GLfloat *y, const GLfloat *nx=NULL, const GLfloat *ny=NULL, const GLfloat *u=NULL, const GLfloat *v=NULL)
 Add multiple vertices in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More...
 
GLuint addVertex2D (const GLfloat &x, const GLfloat &y, const GLfloat &nx=0.0f, const GLfloat &ny=0.0f, const GLfloat &u=0.0f, const GLfloat &v=0.0f)
 Add a vertex in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More...
 
void addVertices3DInterleaved (const size_t N, const GLfloat *interleavedXYZ, const GLfloat *interleavedNormalsXYZ=NULL, const GLfloat *interleavedUV=NULL)
 Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More...
 
void addVertices3D (const size_t N, const GLfloat *x, const GLfloat *y, const GLfloat *z, const GLfloat *nx=NULL, const GLfloat *ny=NULL, const GLfloat *nz=NULL, const GLfloat *u=NULL, const GLfloat *v=NULL)
 Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More...
 
GLuint addVertex3D (const GLfloat &x, const GLfloat &y, const GLfloat &z, const GLfloat &nx=0.0f, const GLfloat &ny=0.0f, const GLfloat &nz=0.0f, const GLfloat &u=0.0f, const GLfloat &v=0.0f)
 Add a vertex in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More...
 
void addElementsInterleaved (const size_t N, GLuint *interleavedIndices)
 Add primitive elements to the model. More...
 
void addElements (const size_t N, GLuint *a, GLuint *b=NULL, GLuint *c=NULL, GLuint *d=NULL)
 Add primitive elements to the model. More...
 
GLuint addElement (GLuint a)
 Add a primitive element to the model. More...
 
GLuint addElement (GLuint a, GLuint b)
 Add a primitive element to the model. More...
 
GLuint addElement (GLuint a, GLuint b, GLuint c)
 Add a primitive element to the model. More...
 
GLuint addElement (GLuint a, GLuint b, GLuint c, GLuint d)
 Add a primitive element to the model. More...
 
GLuint addElement (const std::vector< GLuint > &indices)
 Add (a) primitive element(s) to the model. More...
 
GLfloat & x (GLuint i)
 Access the X coordinate of the vertex at given index. More...
 
GLfloat & y (GLuint i)
 Access the Y coordinate of the vertex at given index. More...
 
GLfloat & z (GLuint i)
 Access the Z coordinate of the vertex at given index. More...
 
GLfloat & nx (GLuint i)
 Access the X coordinate of the normal at given index. More...
 
GLfloat & ny (GLuint i)
 Access the Y coordinate of the normal at given index. More...
 
GLfloat & u (GLuint i)
 Access the U coordinate of the texel at given index. More...
 
GLfloat & v (GLuint i)
 Access the V coordinate of the texel at given index. More...
 
GLuint & a (GLuint i)
 Access the index of the first vertex of the element at given index. More...
 
GLuint & b (GLuint i)
 Access the index of the second vertex of the element at given index. More...
 
GLuint & c (GLuint i)
 Access the index of the third vertex of the element at given index. More...
 
void generateNormals (void)
 Automatically generate the normals. More...
 

Detailed Description

Geometry stored on the host.

Member Enumeration Documentation

Description of the type of geometry (automatic).

Enumerator
CustomModel 

Custom model.

StandardQuad 

Standard quad, covering the area between (-1,-1) and (1,1).

ReversedQuad 

Reversed quad, covering the area between (-1,-1) and (1,1).

PointsGrid2D 

2D grid of dots.

PointsGrid3D 

3D grid of dots.

Unknown 

Unknown geometry type.

Constructor & Destructor Documentation

GeometryModel::GeometryModel ( GeometryType  _type,
int  _dim,
GLenum  _primitiveGL,
bool  _hasNormals,
bool  _hasTexCoords 
)
protected

Geometry model constructor.

Parameters
_typeThe type of the geometry (MUST BE GeometryModel::CustomModel for all user defined models).
_dimThe minimum number of spatial dimensions needed to describe the geometry (either 2 or 3).
_primitiveGLThe GL ID of the element primitive (among GL_POINTS​, GL_LINES​, GL_LINES_ADJACENCY, GL_LINE_STRIP, GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP_ADJACENCY)
_hasNormalsSet to true if the geometry has normals data attached.
_hasTexCoordsSet to true if the geometry has texel coordinates attached.
GeometryModel::GeometryModel ( const GeometryModel mdl)

GeometryModel copy constructor.

Parameters
mdlThe source model.

Member Function Documentation

GLuint & GeometryModel::a ( GLuint  i)
protected

Access the index of the first vertex of the element at given index.

Access the index of the fourth vertex of the element at given index.

Parameters
iThe element index.
Returns
Read/write access to the index of the first vertex of the element.
Parameters
iThe element index.
Returns
Read/write access to the index of the fourth vertex of the element.
const GLuint & GeometryModel::a ( GLuint  i) const

Access the index of the first vertex of the element at given index.

Access the index of the fourth vertex of the element at given index.

Parameters
iThe element index.
Returns
Read/write access to the index of the first vertex of the element.
Parameters
iThe element index.
Returns
Read/write access to the index of the fourth vertex of the element.
GLuint GeometryModel::addElement ( GLuint  a)
protected

Add a primitive element to the model.

Parameters
aIndex of the first vertex.
Returns
The index of the newly created element.
GLuint GeometryModel::addElement ( GLuint  a,
GLuint  b 
)
protected

Add a primitive element to the model.

Parameters
aIndex of the first vertex.
bIndex of the second vertex.
Returns
The index of the newly created element.
GLuint GeometryModel::addElement ( GLuint  a,
GLuint  b,
GLuint  c 
)
protected

Add a primitive element to the model.

Parameters
aIndex of the first vertex.
bIndex of the second vertex.
cIndex of the third vertex.
Returns
The index of the newly created element.
GLuint GeometryModel::addElement ( GLuint  a,
GLuint  b,
GLuint  c,
GLuint  d 
)
protected

Add a primitive element to the model.

Parameters
aIndex of the first vertex.
bIndex of the second vertex.
cIndex of the third vertex.
dIndex of the fourth vertex.
Returns
The index of the newly created element.
GLuint GeometryModel::addElement ( const std::vector< GLuint > &  indices)
protected

Add (a) primitive element(s) to the model.

Parameters
indicesA vector containing the indices of all the vertices used.
Returns
The index of the (last) created element.
void GeometryModel::addElements ( const size_t  N,
GLuint *  a,
GLuint *  b = NULL,
GLuint *  c = NULL,
GLuint *  d = NULL 
)
protected

Add primitive elements to the model.

Parameters
NNumber of primitive elements.
aFirst vertices indices.
bSecond vertices indices.
cThird vertices indices.
dFourth vertices indices.

All arrays must contain N indices.

void GeometryModel::addElementsInterleaved ( const size_t  N,
GLuint *  interleavedIndices 
)
protected

Add primitive elements to the model.

Parameters
NNumber of primitive elements.
interleavedIndicesArray of vertices indices. Must contain N*numVerticesPerElement indices.
GLuint GeometryModel::addVertex2D ( const GLfloat &  x,
const GLfloat &  y,
const GLfloat &  nx = 0.0f,
const GLfloat &  ny = 0.0f,
const GLfloat &  u = 0.0f,
const GLfloat &  v = 0.0f 
)
protected

Add a vertex in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.

Parameters
xThe X coordinate.
yThe Y coordinate.
nxThe X component of the normal.
nyThe Y component of the normal.
uThe U coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false).
vThe V coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false).
Returns
The index of the newly created vertex.
GLuint GeometryModel::addVertex3D ( const GLfloat &  x,
const GLfloat &  y,
const GLfloat &  z,
const GLfloat &  nx = 0.0f,
const GLfloat &  ny = 0.0f,
const GLfloat &  nz = 0.0f,
const GLfloat &  u = 0.0f,
const GLfloat &  v = 0.0f 
)
protected

Add a vertex in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.

Parameters
xThe X coordinate.
yThe Y coordinate.
zThe Z coordinate.
nxThe X component of the normal.
nyThe Y component of the normal.
nzThe Z component of the normal.
uThe U coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false).
vThe V coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false).
Returns
The index of the newly created vertex.
void GeometryModel::addVertices2D ( const size_t  N,
const GLfloat *  x,
const GLfloat *  y,
const GLfloat *  nx = NULL,
const GLfloat *  ny = NULL,
const GLfloat *  u = NULL,
const GLfloat *  v = NULL 
)
protected

Add multiple vertices in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.

Parameters
NThe number of vertices to be added.
xThe array of spatial X coordinates.
yThe array of spatial Y coordinates.
nxThe array of normal components along X.
nyThe array of normal components along Y.
uThe array of texture U coordinates.
vThe array of texture V coordinates.

All arrays must contain N indices.

void GeometryModel::addVertices2DInterleaved ( const size_t  N,
const GLfloat *  interleavedXY,
const GLfloat *  interleavedNormalsXY = NULL,
const GLfloat *  interleavedUV = NULL 
)
protected

Add multiple vertives in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.

Parameters
NThe number of vertices to be added.
interleavedXYThe interleaved array of the spatial coordinates.
interleavedNormalsXYThe interleaved array of the normals data.
interleavedUVThe interleaved array of the texture coordinates.

The vertices coordinates and normals arrays must contain N*dim elements. The texture coordinates array must contain 2*N elements.

void GeometryModel::addVertices3D ( const size_t  N,
const GLfloat *  x,
const GLfloat *  y,
const GLfloat *  z,
const GLfloat *  nx = NULL,
const GLfloat *  ny = NULL,
const GLfloat *  nz = NULL,
const GLfloat *  u = NULL,
const GLfloat *  v = NULL 
)
protected

Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.

Parameters
NThe number of vertices to be added.
xThe array of spatial X coordinates.
yThe array of spatial Y coordinates.
zThe array of spatial Z coordinates.
nxThe array of normal components along X.
nyThe array of normal components along Y.
nzThe array of normal components along Z.
uThe array of texture U coordinates.
vThe array of texture V coordinates.

All arrays must contain N indices.

void GeometryModel::addVertices3DInterleaved ( const size_t  N,
const GLfloat *  interleavedXYZ,
const GLfloat *  interleavedNormalsXYZ = NULL,
const GLfloat *  interleavedUV = NULL 
)
protected

Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.

Parameters
NThe number of vertices to be added.
interleavedXYZThe interleaved array of the spatial coordinates.
interleavedNormalsXYZThe interleaved array of the normals data.
interleavedUVThe interleaved array of the texture coordinates.

The vertices coordinates and normals arrays must contain N*dim elements. The texture coordinates array must contain 2*N elements.

GLuint & GeometryModel::b ( GLuint  i)
protected

Access the index of the second vertex of the element at given index.

Parameters
iThe element index.
Returns
Read/write access to the index of the second vertex of the element.
const GLuint & GeometryModel::b ( GLuint  i) const

Access the index of the second vertex of the element at given index.

Parameters
iThe element index.
Returns
Read/write access to the index of the second vertex of the element.
GLuint & GeometryModel::c ( GLuint  i)
protected

Access the index of the third vertex of the element at given index.

Parameters
iThe element index.
Returns
Read/write access to the index of the third vertex of the element.
const GLuint & GeometryModel::c ( GLuint  i) const

Access the index of the third vertex of the element at given index.

Parameters
iThe element index.
Returns
Read/write access to the index of the third vertex of the element.
void GeometryModel::generateNormals ( void  )
protected

Automatically generate the normals.

If the primitive is GL_POINTS, this will reset the normals to 0.

unsigned int GeometryModel::getNumElements ( void  ) const

Get the number of GL primitives (elements).

Returns
The current number of GL primitives (element).
unsigned int GeometryModel::getNumVertices ( void  ) const

Get the number of vertices.

Returns
The current number of vertices registered for this model.
int GeometryModel::getNumVerticesInPrimitive ( const GLenum &  _primitiveGL)
static

Get the number of vertices per element for the given primitive.

Parameters
_primitiveGLThe GL primitive (accepted are : GL_POINTS​, GL_LINES​, GL_LINES_ADJACENCY, GL_LINE_STRIP, GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP_ADJACENCY).
Returns
The number of elements per primitive.
int GeometryModel::getPrimitiveStride ( const GLenum &  _primitiveGL)
static

Get the stride between elements of the given primitive.

Parameters
_primitiveGLThe GL primitive (accepted are : GL_POINTS​, GL_LINES​, GL_LINES_ADJACENCY, GL_LINE_STRIP, GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP_ADJACENCY).
Returns
The stride between elements of the given primitive.
HdlVBO * GeometryModel::getVBO ( GLenum  freq) const

Get the VBO corresponding to this model. It is not recommended to use directly the VBO but, instead, use a GeometryInstance object.

Parameters
freqThe GL frequency of read/write operations (among : GL_STATIC_DRAW_ARB, GL_STATIC_READ_ARB, GL_STATIC_COPY_ARB, GL_DYNAMIC_DRAW_ARB, GL_DYNAMIC_READ_ARB, GL_DYNAMIC_COPY_ARB, GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, GL_STREAM_COPY_ARB).
Returns
A pointer to the newly created VBO. It is of the responsability of the user to call delete on this object.
void GeometryModel::increaseElementsReservation ( size_t  nNewElements)
protected

Prepare the memory to receive a new number of elements.

Parameters
nNewElementsThe number of elements to be added.
void GeometryModel::increaseVerticesReservation ( size_t  nNewVertices)
protected

Prepare the memory to receive a new number of vertices.

Parameters
nNewVerticesThe number of vertices to be added.
const GLfloat & GeometryModel::nx ( GLuint  i)
protected

Access the X coordinate of the normal at given index.

Parameters
iThe vertex index.
Returns
Read/write access to corresponding variable.
Parameters
iThe vertex index.
Returns
Read access to corresponding variable.
GLfloat & GeometryModel::ny ( GLuint  i)
protected

Access the Y coordinate of the normal at given index.

Parameters
iThe vertex index.
Returns
Read/write access to corresponding variable.
const GLfloat & GeometryModel::ny ( GLuint  i) const

Access the Y coordinate of the normal at given index.

Parameters
iThe vertex index.
Returns
Read access to corresponding variable.
bool GeometryModel::operator== ( const GeometryModel mdl) const

Test if two models are identical.

Parameters
mdlThe reference model.
Returns
true if the two models are identical.
void GeometryModel::reserveElements ( size_t  nElements)
protected

Prepare the memory to receive a number of elements.

Parameters
nElementsThe total number of elements to contain.
void GeometryModel::reserveVertices ( size_t  nVertices)
protected

Prepare the memory to receive a number of vertices.

Parameters
nVerticesThe total number of vertices to contain.
bool GeometryModel::testIndices ( void  ) const

Test if all the indices are valid.

Returns
True if all the indices are valid.
GLfloat & GeometryModel::u ( GLuint  i)
protected

Access the U coordinate of the texel at given index.

Parameters
iThe vertex/texel index.
Returns
Read/write access to corresponding variable.
const GLfloat & GeometryModel::u ( GLuint  i) const

Access the U coordinate of the texel at given index.

Parameters
iThe vertex/texel index.
Returns
Read-only access to corresponding variable.
GLfloat & GeometryModel::v ( GLuint  i)
protected

Access the V coordinate of the texel at given index.

Parameters
iThe vertex/texel index.
Returns
Read/write access to corresponding variable.
const GLfloat & GeometryModel::v ( GLuint  i) const

Access the V coordinate of the texel at given index.

Parameters
iThe vertex/texel index.
Returns
Read-only access to corresponding variable.
GLfloat & GeometryModel::x ( GLuint  i)
protected

Access the X coordinate of the vertex at given index.

Parameters
iThe vertex index.
Returns
Read/write access to corresponding variable.
const GLfloat & GeometryModel::x ( GLuint  i) const

Read the X coordinate of the vertex at given index.

Parameters
iThe vertex index.
Returns
Read access to corresponding variable.
GLfloat & GeometryModel::y ( GLuint  i)
protected

Access the Y coordinate of the vertex at given index.

Parameters
iThe vertex index.
Returns
Read/write access to corresponding variable.
const GLfloat & GeometryModel::y ( GLuint  i) const

Read the Y coordinate of the vertex at given index.

Parameters
iThe vertex index.
Returns
Read access to corresponding variable.
GLfloat & GeometryModel::z ( GLuint  i)
protected

Access the Z coordinate of the vertex at given index.

Access the Z coordinate of the normal at given index.

Parameters
iThe vertex index.
Returns
Read/write access to corresponding variable.
const GLfloat & GeometryModel::z ( GLuint  i) const

Read the Z coordinate of the vertex at given index.

Access the Z coordinate of the normal at given index.

Parameters
iThe vertex index.
Returns
Read access to corresponding variable.

The documentation for this class was generated from the following files: