Visualization Library v1.0.3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes

vl::Geometry Class Reference

The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points. More...

#include <Geometry.hpp>

Inheritance diagram for vl::Geometry:
vl::Renderable vl::IVertexAttribSet vl::Object vl::BezierSurface

List of all members.

Classes

class  TextureArray

Public Member Functions

 Geometry ()
 Constructor.
virtual ~Geometry ()
 Destructor.
ref< GeometryshallowCopy () const
 Performs a shallow copy of a Geometry.
GeometryshallowCopyFrom (const Geometry &)
 Performs a shallow copy of the specified Geometry.
ref< GeometrydeepCopy () const
 Performs a deep copy of a Geometry.
GeometrydeepCopyFrom (const Geometry &)
 Performs a deep copy of the specified Geometry.
Collection< DrawCall > * drawCalls ()
 Returns the list of DrawCall objects bound to a Geometry.
const Collection< DrawCall > * drawCalls () const
 Returns the list of DrawCall objects bound to a Geometry.
void setColorArray (const fvec4 &color)
 Fills the color array with the given color.
virtual void clearArrays (bool clear_draw_calls=true)
 Removes all the previously installed arrays.
virtual void updateDirtyBufferObject (EBufferObjectUpdateMode mode)
 Updates all the vertex buffer objects of both vertex arrays and draw calls that are marked as dirty.
virtual void deleteBufferObject ()
 Deletes all the vertex buffer objects of both vertex arrays and draw calls.
void convertToVertexAttribs ()
 Converts the fixed function pipeline arrays (vertex array, normal arrays) into the generic ones.
void computeNormals (bool verbose=false)
 Computes the normals in a "smooth" way, i.e.
bool flipNormals ()
 Inverts the orientation of the normals.
void fixTriangleWinding ()
 Converts all draw calls to triangles and fixes their winding according to the Geometry's normals.
void transform (const mat4 &matr, bool normalize=true)
 Transforms vertices and normals belonging to this geometry.
void convertDrawCallToDrawArrays ()
 Converts all the DrawCall objects bound to a Geometry into DrawArrays.
DrawCallmergeTriangleStrips ()
 Merges all the PT_TRIANGLE_STRIP DrawElementsUInt objects into one single PT_TRIANGLE_STRIP DrawElementsUInt.
void mergeDrawCallsWithPrimitiveRestart (EPrimitiveType primitive_type)
 Merges all the draw calls that use the given primitive type into one single draw call using primitive restart.
void mergeDrawCallsWithMultiDrawElements (EPrimitiveType primitive_type)
 Merges all the draw calls that use the given primitive type into one single MultiDrawElements draw call.
void mergeDrawCallsWithTriangles (EPrimitiveType primitive_type)
 Merges all the draw calls that use the given primitive type or PT_TRIANGLES into one single PT_TRIANGLES draw call.
void triangulateDrawCalls ()
 Converts PT_QUADS, PT_QUADS_STRIP and PT_POLYGON into PT_TRIANGLE primitives.
DrawRangeElements
*MultiDrawElements to the best
fitting of *UInt UShort UByte
taking into instancing and
base vertex note Primitive
type can be any *void 
shrinkDrawCalls ()
void makeGLESFriendly ()
 Calls triangulateDrawCalls(), shrinkDrawCalls() and convertToVertexAttribs().
bool sortVertices ()
 Sorts the vertices of the geometry (position, normals, textures, colors etc.) to maximize vertex-cache coherency.
void regenerateVertices (const std::vector< u32 > &map_new_to_old)
 Regenerates the vertex position and attributes using the given new-to-old map.
void colorizePrimitives ()
 Assigns a random color to each vertex of each DrawCall object. If a vertex is shared among more than one DrawCall object its color is undefined.
void setVertexArray (ArrayAbstract *data)
 Conventional vertex array.
const ArrayAbstractvertexArray () const
 Conventional vertex array.
ArrayAbstractvertexArray ()
 Conventional vertex array.
void setNormalArray (ArrayAbstract *data)
 Conventional normal array.
const ArrayAbstractnormalArray () const
 Conventional normal array.
ArrayAbstractnormalArray ()
 Conventional normal array.
void setColorArray (ArrayAbstract *data)
 Conventional color array.
const ArrayAbstractcolorArray () const
 Conventional color array.
ArrayAbstractcolorArray ()
 Conventional color array.
void setSecondaryColorArray (ArrayAbstract *data)
 Conventional secondary color array.
const ArrayAbstractsecondaryColorArray () const
 Conventional secondary color array.
ArrayAbstractsecondaryColorArray ()
 Conventional secondary color array.
void setFogCoordArray (ArrayAbstract *data)
 Conventional fog array.
const ArrayAbstractfogCoordArray () const
 Conventional fog array.
ArrayAbstractfogCoordArray ()
 Conventional fog array.
void setTexCoordArray (int tex_unit, ArrayAbstract *data)
 Conventional texture coords arrays.
const ArrayAbstracttexCoordArray (int tex_unit) const
 Conventional texture coords arrays.
ArrayAbstracttexCoordArray (int tex_unit)
 Conventional texture coords arrays.
int texCoordArrayCount () const
 Number of texture coordinate arrays currently present.
void getTexCoordArrayAt (int i, int &out_tex_unit, const ArrayAbstract *&tex_array) const
 Gets the i-th texture coordinate information, where i must be 0 <= i < texCoordArrayCount().
void setVertexAttribArray (unsigned int attrib_location, ArrayAbstract *data, bool normalize=true, EVertexAttribInterpretation data_behav=VAI_NORMAL)
void setVertexAttribArray (const VertexAttribInfo &info)
 Binds a generic vertex attribute.
const VertexAttribInfovertexAttribArray (unsigned int attrib_location) const
 Returns a generic vertex attribute's info.
VertexAttribInfovertexAttribArray (unsigned int attrib_location)
 Returns a generic vertex attribute's info.
Collection< VertexAttribInfo > * vertexAttribArrays ()
 The list of VertexAttribInfo objects bound to a Geometry.
const Collection
< VertexAttribInfo > * 
vertexAttribArrays () const
 The list of VertexAttribInfo objects bound to a Geometry.

Static Public Member Functions

static void computeTangentSpace (u32 vert_count, const vl::fvec3 *vertex, const vl::fvec3 *normal, const vl::fvec2 *texcoord, const vl::DrawCall *primitives, vl::fvec3 *tangent, vl::fvec3 *bitangent)
 Computes the tangent (and optionally bitangent) vectors used to form a TBN matrix to be used for bumpmapping.

Public Attributes

DrawRangeElements
*MultiDrawElements to the best
fitting of *UInt UShort UByte
taking into 
account: primitive restart
 Shrinks DrawElements.

Protected Member Functions

virtual void computeBounds_Implementation ()
virtual void render_Implementation (const Actor *actor, const Shader *shader, const Camera *camera, OpenGLContext *gl_context) const

Protected Attributes

Collection< DrawCallmDrawCalls
ref< ArrayAbstractmVertexArray
ref< ArrayAbstractmNormalArray
ref< ArrayAbstractmColorArray
ref< ArrayAbstractmSecondaryColorArray
ref< ArrayAbstractmFogCoordArray
Collection< TextureArray > mTexCoordArrays
Collection< VertexAttribInfomVertexAttribArrays

Detailed Description

The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.

See also:

Definition at line 67 of file Geometry.hpp.


Constructor & Destructor Documentation

Geometry::Geometry (  )
Geometry::~Geometry (  ) [virtual]

Destructor.

Definition at line 53 of file Geometry.cpp.


Member Function Documentation

ref< Geometry > Geometry::shallowCopy (  ) const

Performs a shallow copy of a Geometry.

See also:
deepCopy()

Definition at line 140 of file Geometry.cpp.

References Geometry().

Geometry & Geometry::shallowCopyFrom ( const Geometry other )

Performs a shallow copy of the specified Geometry.

See also:
deepCopy()

Definition at line 147 of file Geometry.cpp.

References mColorArray, mDrawCalls, mFogCoordArray, mNormalArray, mSecondaryColorArray, mTexCoordArrays, mVertexArray, and mVertexAttribArrays.

ref< Geometry > Geometry::deepCopy (  ) const

Performs a deep copy of a Geometry.

See also:
shallowCopy()

Definition at line 98 of file Geometry.cpp.

References Geometry().

Geometry & Geometry::deepCopyFrom ( const Geometry other )
Collection<DrawCall>* vl::Geometry::drawCalls (  ) [inline]
const Collection<DrawCall>* vl::Geometry::drawCalls (  ) const [inline]

Returns the list of DrawCall objects bound to a Geometry.

Definition at line 117 of file Geometry.hpp.

void vl::Geometry::setColorArray ( const fvec4 color ) [inline]

Fills the color array with the given color.

Definition at line 120 of file Geometry.hpp.

References vl::ref< T >::get(), vl::VA_Color, vl::VA_Position, and VL_CHECK.

Referenced by colorizePrimitives(), convertToVertexAttribs(), vl::VLXClassWrapper_Geometry::importGeometry(), and regenerateVertices().

void Geometry::clearArrays ( bool  clear_draw_calls = true ) [virtual]
void Geometry::updateDirtyBufferObject ( EBufferObjectUpdateMode  mode ) [virtual]
void Geometry::deleteBufferObject (  ) [virtual]
void Geometry::convertToVertexAttribs (  )

Converts the fixed function pipeline arrays (vertex array, normal arrays) into the generic ones.

The generic attribute indices are allocated in the following way:

Remarks:
  • Already existing generic vertex attributes are overwritten if their binding location collides with one of the non-NULL fixed function pipeline arrays being converted.
  • After this function all the fixed function pipeline arrays are set to NULL.

Definition at line 292 of file Geometry.cpp.

References vl::Collection< T >::clear(), colorArray(), fogCoordArray(), mTexCoordArrays, normalArray(), NULL, secondaryColorArray(), setColorArray(), setFogCoordArray(), setNormalArray(), setSecondaryColorArray(), setVertexArray(), setVertexAttribArray(), vl::Collection< T >::size(), vl::VA_Color, vl::VA_Normal, vl::VA_Position, vl::VA_TexCoord0, vertexArray(), vertexAttribArray(), and vl::Log::warning().

Referenced by makeGLESFriendly().

void Geometry::computeNormals ( bool  verbose = false )

Computes the normals in a "smooth" way, i.e.

averaging the normals of those polygons that share one or more vertices.

This function computes smoothed normals for triangle primitives and leaves unchanged the normals of line and point primitives when possible, i.e. when they don't share vertices with the polygonal primitives.

Note:
This function modifies the local buffers. After calling this you might want to update the buffers allocated on the GPU.

Definition at line 346 of file Geometry.cpp.

References vl::cross(), vl::VertexAttribInfo::data(), drawCalls(), vl::ref< T >::get(), vl::ArrayAbstract::getAsVec3(), vl::Vector3< T_Scalar >::length(), mDrawCalls, vl::Vector3< T_Scalar >::normalize(), NULL, setNormalArray(), setVertexAttribArray(), vl::Collection< T >::size(), vl::ArrayAbstract::size(), vl::VA_Normal, vl::VA_Position, vertexArray(), vertexAttribArray(), VL_CHECK, and vl::Log::warning().

Referenced by vl::DaeLoader::load().

bool Geometry::flipNormals (  )

Inverts the orientation of the normals.

Returns true if the normals could be flipped. The function fails if the normals are defined in a format other than ArrayFloat3.

Definition at line 273 of file Geometry.cpp.

References vl::Object::as(), vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::at(), vl::VertexAttribInfo::data(), normalArray(), NULL, vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::size(), vl::VA_Normal, and vertexAttribArray().

void Geometry::fixTriangleWinding (  )
void Geometry::transform ( const mat4 matr,
bool  normalize = true 
)

Transforms vertices and normals belonging to this geometry.

If 'normalize' == true the normals are normalized after being transformed

Note:
This functions supports every possible vertex format, type and layout.
See also:

Definition at line 511 of file Geometry.cpp.

References vl::Matrix4< T_Scalar >::as3x3(), vl::VertexAttribInfo::data(), vl::Matrix4< T_Scalar >::invert(), normalArray(), vl::ArrayAbstract::normalize(), NULL, vl::ArrayAbstract::transform(), vl::Matrix4< T_Scalar >::transpose(), vl::VA_Normal, vl::VA_Position, vertexArray(), and vertexAttribArray().

void Geometry::convertDrawCallToDrawArrays (  )
DrawCall * Geometry::mergeTriangleStrips (  )
void Geometry::mergeDrawCallsWithPrimitiveRestart ( EPrimitiveType  primitive_type )
void Geometry::mergeDrawCallsWithMultiDrawElements ( EPrimitiveType  primitive_type )
void Geometry::mergeDrawCallsWithTriangles ( EPrimitiveType  primitive_type )
void Geometry::triangulateDrawCalls (  )

Converts PT_QUADS, PT_QUADS_STRIP and PT_POLYGON into PT_TRIANGLE primitives.

Note:
Eventual base vertex and primitive restart are baked into the resulting triangle soup.

Definition at line 935 of file Geometry.cpp.

References vl::Collection< T >::at(), vl::DrawCall::countTriangles(), drawCalls(), vl::TriangleIterator::hasNext(), vl::DrawCall::instances(), vl::DrawCall::primitiveType(), vl::PT_POLYGON, vl::PT_QUAD_STRIP, vl::PT_QUADS, vl::PT_TRIANGLES, vl::DrawCall::triangleIterator(), and VL_CHECK.

Referenced by makeGLESFriendly().

void Geometry::shrinkDrawCalls (  )
void Geometry::makeGLESFriendly (  )
bool Geometry::sortVertices (  )

Sorts the vertices of the geometry (position, normals, textures, colors etc.) to maximize vertex-cache coherency.

This function will work only if all the DrawCalls are DrawElements* and will generate a new set of DrawElementsUInt. This function will fail if any of the DrawCalls is using primitive restart functionality.

Returns:
true if all the DrawCall are DrawElements* and none of the DrawCalls is using primitive restart.

Definition at line 1207 of file Geometry.cpp.

References vl::Object::as(), vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::at(), vl::Collection< T >::at(), vl::DrawElementsBase::baseVertex(), vl::Collection< T >::clear(), vl::VertexAttribInfo::data(), drawCalls(), vl::Log::error(), vl::DrawElements< arr_type >::indexBuffer(), vl::DrawElementsBase::instances(), NULL, vl::DrawCall::primitiveRestartEnabled(), vl::DrawCall::primitiveType(), vl::Collection< T >::push_back(), regenerateVertices(), vl::ArrayAbstract::size(), vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::size(), vl::Collection< T >::size(), vl::VA_Position, vertexArray(), vertexAttribArray(), and vl::Log::warning().

void Geometry::regenerateVertices ( const std::vector< u32 > &  map_new_to_old )

Regenerates the vertex position and attributes using the given new-to-old map.

Where 'map_new_to_old[i] == j' means that the i-th new vertex attribute should take it's value from the old j-th vertex attribute.

Definition at line 884 of file Geometry.cpp.

References vl::Collection< T >::at(), colorArray(), fogCoordArray(), vl::ref< T >::get(), normalArray(), vl::VertexMapper::regenerate(), secondaryColorArray(), setColorArray(), vl::VertexAttribInfo::setData(), setFogCoordArray(), setNormalArray(), setSecondaryColorArray(), setTexCoordArray(), setVertexArray(), vl::Collection< T >::size(), texCoordArray(), vertexArray(), vertexAttribArrays(), and VL_MAX_TEXTURE_UNITS.

Referenced by convertDrawCallToDrawArrays(), vl::DoubleVertexRemover::removeDoubles(), and sortVertices().

void Geometry::colorizePrimitives (  )
void Geometry::computeTangentSpace ( u32  vert_count,
const vl::fvec3 vertex,
const vl::fvec3 normal,
const vl::fvec2 texcoord,
const vl::DrawCall primitives,
vl::fvec3 tangent,
vl::fvec3 bitangent 
) [static]

Computes the tangent (and optionally bitangent) vectors used to form a TBN matrix to be used for bumpmapping.

Parameters:
vert_countThe number of elements stored in vertex, normal, texcoord, tangent and bitangent.
vertexArray containing the vertex positions.
normalArray containing the normals of the vertices.
texcoordArray containing the 2d texture coordinates of the bumpmap.
primitivesThe triangles, quads etc. defining the geometry of the object.
tangent[out] Returns the tangent vector of the vertices. This parameter is mandatory.
bitangent[out] Returns the bitangent vector of the vertics. This parameter can be NULL.

Definition at line 1346 of file Geometry.cpp.

References vl::cross(), vl::dot(), vl::TriangleIterator::hasNext(), vl::normalize(), vl::DrawCall::triangleIterator(), VL_CHECK, vl::Vector2< T_Scalar >::x(), vl::Vector3< T_Scalar >::x(), vl::Vector2< T_Scalar >::y(), vl::Vector3< T_Scalar >::y(), and vl::Vector3< T_Scalar >::z().

void Geometry::setVertexArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::vertexArray (  ) const [inline, virtual]
ArrayAbstract* vl::Geometry::vertexArray (  ) [inline, virtual]

Conventional vertex array.

Implements vl::IVertexAttribSet.

Definition at line 270 of file Geometry.hpp.

void Geometry::setNormalArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::normalArray (  ) const [inline, virtual]
ArrayAbstract* vl::Geometry::normalArray (  ) [inline, virtual]

Conventional normal array.

Implements vl::IVertexAttribSet.

Definition at line 276 of file Geometry.hpp.

void Geometry::setColorArray ( ArrayAbstract data ) [virtual]

Conventional color array.

Implements vl::IVertexAttribSet.

Definition at line 188 of file Geometry.cpp.

References vl::ArrayAbstract::glSize(), vl::ArrayAbstract::glType(), mColorArray, and VL_CHECK.

const ArrayAbstract* vl::Geometry::colorArray (  ) const [inline, virtual]

Conventional color array.

Implements vl::IVertexAttribSet.

Definition at line 280 of file Geometry.hpp.

Referenced by convertToVertexAttribs(), vl::VLXClassWrapper_Geometry::exportGeometry(), and regenerateVertices().

ArrayAbstract* vl::Geometry::colorArray (  ) [inline, virtual]

Conventional color array.

Implements vl::IVertexAttribSet.

Definition at line 282 of file Geometry.hpp.

void Geometry::setSecondaryColorArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::secondaryColorArray (  ) const [inline, virtual]

Conventional secondary color array.

Implements vl::IVertexAttribSet.

Definition at line 286 of file Geometry.hpp.

Referenced by convertToVertexAttribs(), vl::VLXClassWrapper_Geometry::exportGeometry(), and regenerateVertices().

ArrayAbstract* vl::Geometry::secondaryColorArray (  ) [inline, virtual]

Conventional secondary color array.

Implements vl::IVertexAttribSet.

Definition at line 288 of file Geometry.hpp.

void Geometry::setFogCoordArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::fogCoordArray (  ) const [inline, virtual]

Conventional fog array.

Implements vl::IVertexAttribSet.

Definition at line 292 of file Geometry.hpp.

Referenced by convertToVertexAttribs(), vl::VLXClassWrapper_Geometry::exportGeometry(), and regenerateVertices().

ArrayAbstract* vl::Geometry::fogCoordArray (  ) [inline, virtual]

Conventional fog array.

Implements vl::IVertexAttribSet.

Definition at line 294 of file Geometry.hpp.

void Geometry::setTexCoordArray ( int  tex_unit,
ArrayAbstract data 
) [virtual]
const ArrayAbstract* vl::Geometry::texCoordArray ( int  tex_unit ) const [inline, virtual]

Conventional texture coords arrays.

Implements vl::IVertexAttribSet.

Definition at line 298 of file Geometry.hpp.

References NULL.

Referenced by vl::VLXClassWrapper_Geometry::exportGeometry(), regenerateVertices(), and vl::BezierSurface::updateBezierSurface().

ArrayAbstract* vl::Geometry::texCoordArray ( int  tex_unit ) [inline, virtual]

Conventional texture coords arrays.

Implements vl::IVertexAttribSet.

Definition at line 306 of file Geometry.hpp.

References NULL.

int vl::Geometry::texCoordArrayCount (  ) const [inline, virtual]

Number of texture coordinate arrays currently present.

Implements vl::IVertexAttribSet.

Definition at line 314 of file Geometry.hpp.

void vl::Geometry::getTexCoordArrayAt ( int  i,
int &  out_tex_unit,
const ArrayAbstract *&  tex_array 
) const [inline, virtual]

Gets the i-th texture coordinate information, where i must be 0 <= i < texCoordArrayCount().

Implements vl::IVertexAttribSet.

Definition at line 316 of file Geometry.hpp.

References VL_CHECK.

void vl::Geometry::setVertexAttribArray ( unsigned int  attrib_location,
ArrayAbstract data,
bool  normalize = true,
EVertexAttribInterpretation  data_behav = VAI_NORMAL 
) [inline]
void Geometry::setVertexAttribArray ( const VertexAttribInfo info ) [virtual]
const VertexAttribInfo * Geometry::vertexAttribArray ( unsigned int  attrib_location ) const [virtual]
VertexAttribInfo * Geometry::vertexAttribArray ( unsigned int  attrib_location ) [virtual]

Returns a generic vertex attribute's info.

Implements vl::IVertexAttribSet.

Definition at line 549 of file Geometry.cpp.

References vl::Collection< T >::at(), vl::VertexAttribInfo::attribLocation(), NULL, vl::Collection< T >::size(), and vertexAttribArrays().

Collection<VertexAttribInfo>* vl::Geometry::vertexAttribArrays (  ) [inline, virtual]
const Collection<VertexAttribInfo>* vl::Geometry::vertexAttribArrays (  ) const [inline, virtual]

The list of VertexAttribInfo objects bound to a Geometry.

Implements vl::IVertexAttribSet.

Definition at line 333 of file Geometry.hpp.

void Geometry::computeBounds_Implementation (  ) [protected, virtual]
void Geometry::render_Implementation ( const Actor actor,
const Shader shader,
const Camera camera,
OpenGLContext gl_context 
) const [protected, virtual]

Member Data Documentation

DrawRangeElements* MultiDrawElements to the best fitting of* UInt UShort UByte taking into vl::Geometry::account

Shrinks DrawElements.

Definition at line 221 of file Geometry.hpp.

Definition at line 341 of file Geometry.hpp.

Referenced by clearArrays(), computeNormals(), deepCopyFrom(), Geometry(), and shallowCopyFrom().

Collection<TextureArray> vl::Geometry::mTexCoordArrays [protected]

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

Visualization Library v1.0.3 Reference Documentation
Copyright Michele Bosi. All rights reserved.
Updated on Tue Feb 7 2017 00:55:10.
Permission is granted to use this page to write and publish articles regarding Visualization Library.