NGL  6.5
The NCCA Graphics Library
ngl::VAOPrimitives Class Reference

VAO based object primitives used for fast openGL drawing this is a singelton class so we use the instance method to get access and construct the only instance. More...

#include <VAOPrimitives.h>

+ Inheritance diagram for ngl::VAOPrimitives:
+ Collaboration diagram for ngl::VAOPrimitives:

Public Member Functions

void draw (const std::string &_name) noexcept
 Draw one of the VBO's created via a name lookup. More...
 
void draw (const std::string &_name, GLenum _mode) noexcept
 Draw one of the VBO's created via a name lookup. More...
 
void createSphere (const std::string &_name, Real _radius, int _precision) noexcept
 create a triangulated Sphere as a vbo with auto generated texture cords More...
 
void createLineGrid (const std::string &_name, Real _width, Real _depth, int _steps) noexcept
 create a line based grid (like the maya ground plane) More...
 
void createCylinder (const std::string &_name, const Real _radius, Real _height, unsigned int _slices, unsigned int _stacks) noexcept
 create a Quad Cylinder as a vbo with auto generated texture cords More...
 
void createCone (const std::string &_name, Real _base, Real _height, unsigned int _slices, unsigned int _stacks) noexcept
 create a Quad Cone as a vao with auto generated texture cords More...
 
void createDisk (const std::string &_name, Real _radius, unsigned int _slices) noexcept
 create a trinagle fan disk (use as end caps for Cylinder etc) More...
 
void createTorus (const std::string &_name, Real _minorRadius, Real _majorRadius, unsigned int _nSides, unsigned int _nRings, bool _flipTX=false) noexcept
 create a VBO based torus from rings of quads. More...
 
void createTrianglePlane (const std::string &_name, const Real _width, const Real _depth, const int _wP, const int _dP, const Vec3 &_vN) noexcept
 create a triangulated plane as a vbo with auto generated texture cords More...
 
void createCapsule (const std::string &_name, const Real _radius=1.0f, const Real _height=2.0f, const int _precision=20) noexcept
 create a triangulated capsule (Cylinder with spherical ends) More...
 
void loadBinary (const std::string &_name, const std::string &_fName, const GLenum _type) noexcept
 load a VBO from a binary file created from Obj2VBO program More...
 
void clear () noexcept
 clear the VAO elements created (is also called by dtor) This is usefull if you don't want the default primitives More...
 
AbstractVAOgetVAOFromName (const std::string &_name)
 get the raw VAO so we can map it etc More...
 
- Public Member Functions inherited from ngl::Singleton< VAOPrimitives >
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 

Private Member Functions

 VAOPrimitives () noexcept
 default constructor More...
 
virtual ~VAOPrimitives ()
 dtor More...
 
void createVAOFromHeader (const std::string &_name, Real const *_data, unsigned int _Size) noexcept
 create a VAO from a static header file of data in the TNV format this will usually be created from the Obj2VBO program in the Models directory More...
 
void createDefaultVAOs () noexcept
 create the default VAO's this is done by the ctor anyway but can be called if the clear method is called. Note you will need to incude VAOHeaders in the client side More...
 
void createVAO (const std::string &_name, const std::vector< vertData > &_data, const GLenum _mode) noexcept
 the method to actually create the VAO from the various other methods Note this is used in conjunction with the vertData struct More...
 
void fghCircleTable (std::unique_ptr< Real[]> &io_sint, std::unique_ptr< Real[]> &io_cost, int _n) noexcept
 create the elements of a circle this is borrowed from freeglut More...
 

Private Attributes

std::unordered_map< std::string, AbstractVAO * > m_createdVAOs
 a map to store the VAO by name More...
 

Friends

class Singleton< VAOPrimitives >
 
class Vec3
 

Additional Inherited Members

- Static Public Member Functions inherited from ngl::Singleton< VAOPrimitives >
static VAOPrimitivesinstance ()
 Get the instance. More...
 
- Protected Member Functions inherited from ngl::Singleton< VAOPrimitives >
 Singleton ()
 Constructor. More...
 
virtual ~Singleton ()
 Destructor. More...
 
- Static Protected Member Functions inherited from ngl::Singleton< VAOPrimitives >
static void killSingleton ()
 
- Static Protected Attributes inherited from ngl::Singleton< VAOPrimitives >
static VAOPrimitivess_instance
 unique instance of the singleton More...
 

Detailed Description

VAO based object primitives used for fast openGL drawing this is a singelton class so we use the instance method to get access and construct the only instance.

Author
Jonathan Macey
Version
1.0
Date
Last Revision 20/06/11 created and removed VBO class

Definition at line 54 of file VAOPrimitives.h.

Constructor & Destructor Documentation

ngl::VAOPrimitives::VAOPrimitives ( )
privatenoexcept

default constructor

Definition at line 34 of file VAOPrimitives.cpp.

References createDefaultVAOs().

+ Here is the call graph for this function:

virtual ngl::VAOPrimitives::~VAOPrimitives ( )
inlineprivatevirtual

dtor

Definition at line 175 of file VAOPrimitives.h.

Member Function Documentation

void ngl::VAOPrimitives::clear ( )
noexcept

clear the VAO elements created (is also called by dtor) This is usefull if you don't want the default primitives

Definition at line 879 of file VAOPrimitives.cpp.

References m_createdVAOs.

void ngl::VAOPrimitives::createCapsule ( const std::string _name,
const Real  _radius = 1.0f,
const Real  _height = 2.0f,
const int  _precision = 20 
)
noexcept

create a triangulated capsule (Cylinder with spherical ends)

Parameters
[in]_namethe name of the object created used when drawing
[in]_radiusthe radius of the capsule
[in]_heightthe height of the capsule
[in]_precisionthe precision of the tri mesh created (number of steps)
Todo:
add UV's at some stage

Definition at line 228 of file VAOPrimitives.cpp.

References createVAO(), GL_TRIANGLES, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createCone ( const std::string _name,
Real  _base,
Real  _height,
unsigned int  _slices,
unsigned int  _stacks 
)
noexcept

create a Quad Cone as a vao with auto generated texture cords

Parameters
[in]_namethe name of the object created used when drawing
[in]_basethe base radius of the cone
[in]_heightthe height of the cone
[in]_slicesthe number of quad elements around the cone
[in]_stacksthe number of quad elements along the centeral axis

Definition at line 518 of file VAOPrimitives.cpp.

References createVAO(), fghCircleTable(), GL_TRIANGLE_STRIP, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::vertData::u, ngl::vertData::v, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createCylinder ( const std::string _name,
const Real  _radius,
Real  _height,
unsigned int  _slices,
unsigned int  _stacks 
)
noexcept

create a Quad Cylinder as a vbo with auto generated texture cords

Parameters
[in]_namethe name of the object created used when drawing
[in]_radiusthe base radius of the Cylinder
[in]_heightthe height of the Cylinder
[in]_slicesthe number of quad elements around the Cylinder
[in]_stacksthe number of quad elements along the centeral axis

Definition at line 411 of file VAOPrimitives.cpp.

References createVAO(), fghCircleTable(), GL_TRIANGLES, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::vertData::u, ngl::vertData::v, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createDefaultVAOs ( )
privatenoexcept

create the default VAO's this is done by the ctor anyway but can be called if the clear method is called. Note you will need to incude VAOHeaders in the client side

Note
these data sets are huge and compilation takes a long time hence only enable if needed

Definition at line 14 of file createDefaultVAOs.cpp.

References ngl::buddah, ngl::buddahSIZE, ngl::bunny, ngl::bunnySIZE, createVAOFromHeader(), ngl::cube, ngl::cubeSIZE, ngl::dodecahedron, ngl::dodecahedronSIZE, ngl::dragon, ngl::dragonSIZE, ngl::football, ngl::footballSIZE, ngl::icosahedron, ngl::icosahedronSIZE, ngl::Octahedron, ngl::OctahedronSIZE, ngl::teapot, ngl::teapotSIZE, tetrahedron, tetrahedronSIZE, ngl::troll, and ngl::trollSIZE.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::VAOPrimitives::createDisk ( const std::string _name,
Real  _radius,
unsigned int  _slices 
)
noexcept

create a trinagle fan disk (use as end caps for Cylinder etc)

Parameters
[in]_namethe name of the object created used when drawing
[in]_radiusthe disk radius
[in]_slicesthe number of triangles to form the disk

Definition at line 587 of file VAOPrimitives.cpp.

References createVAO(), fghCircleTable(), GL_TRIANGLE_FAN, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::vertData::u, ngl::vertData::v, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createLineGrid ( const std::string _name,
Real  _width,
Real  _depth,
int  _steps 
)
noexcept

create a line based grid (like the maya ground plane)

Parameters
[in]_namethe name of the object created used when drawing
[in]_widththe width of the grid
[in]_depththe depth of the grid
[in]_stepsthe number of steps for the grid

Definition at line 112 of file VAOPrimitives.cpp.

References createVAO(), GL_LINES, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createSphere ( const std::string _name,
Real  _radius,
int  _precision 
)
noexcept

create a triangulated Sphere as a vbo with auto generated texture cords

Parameters
[in]_namethe name of the object created used when drawing
[in]_radiusthe sphere radius
[in]_precisionthe number of triange subdivisions to use

Definition at line 164 of file VAOPrimitives.cpp.

References createVAO(), GL_TRIANGLE_STRIP, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::PI2, ngl::TWO_PI, ngl::vertData::u, ngl::vertData::v, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createTorus ( const std::string _name,
Real  _minorRadius,
Real  _majorRadius,
unsigned int  _nSides,
unsigned int  _nRings,
bool  _flipTX = false 
)
noexcept

create a VBO based torus from rings of quads.

Parameters
[in]_namethe name of the VBO created for calling with the draw method
[in]_minorRadiusthe inner radius of the torus
[in]_majorRadiusthe outer radius of the torus.
[in]_nSidesthe precision (number of quads) for the majorRadius
[in]_nRingsthe precision (number of quads) for the minor Radius
[in]_flipTXflip the texture co-ord generation default false.

Definition at line 634 of file VAOPrimitives.cpp.

References createVAO(), GL_TRIANGLES, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::vertData::u, ngl::vertData::v, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createTrianglePlane ( const std::string _name,
const Real  _width,
const Real  _depth,
const int  _wP,
const int  _dP,
const Vec3 _vN 
)
noexcept

create a triangulated plane as a vbo with auto generated texture cords

Parameters
[in]_namethe name of the object created used when drawing
[in]_widththe width of the plane based on the center of the plane being at 0,0,0
[in]_depththe height of the plane based on the center of the plane being at 0,0,0
[in]_wPthe precision of the width, this is basically the steps (per quad) which will be triangulated for each (wP == 1 will give 1 quad mad of 2 tris)
[in]_dPthe precision of the Depth, this is basically the steps (per quad) which will be triangulated for each (wP == 1 will give 1 quad mad of 2 tris)
[in]_vNThe Vertex normal (used for each vertex)

Definition at line 798 of file VAOPrimitives.cpp.

References createVAO(), GL_TRIANGLES, ngl::vertData::nx, ngl::vertData::ny, ngl::vertData::nz, ngl::vertData::u, ngl::vertData::v, ngl::vertData::x, ngl::vertData::y, and ngl::vertData::z.

+ Here is the call graph for this function:

void ngl::VAOPrimitives::createVAO ( const std::string _name,
const std::vector< vertData > &  _data,
const GLenum  _mode 
)
privatenoexcept

the method to actually create the VAO from the various other methods Note this is used in conjunction with the vertData struct

Parameters
[in]_namethe name to store in the map of the VBO
[in]_datathe raw data packed into the vertData structure
[in]_modethe mode to draw

Definition at line 335 of file VAOPrimitives.cpp.

References ngl::AbstractVAO::bind(), ngl::VAOFactory::createVAO(), GL_FLOAT, m_createdVAOs, ngl::AbstractVAO::setData(), ngl::AbstractVAO::setNumIndices(), ngl::AbstractVAO::setVertexAttributePointer(), and ngl::AbstractVAO::unbind().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::VAOPrimitives::createVAOFromHeader ( const std::string _name,
Real const *  _data,
unsigned int  _Size 
)
privatenoexcept

create a VAO from a static header file of data in the TNV format this will usually be created from the Obj2VBO program in the Models directory

Parameters
[in]_namethe name reference for the VBO lookup
[in]_dataa pointer to the data to load
[in]_Sizethe size of the array of data to load

Definition at line 75 of file VAOPrimitives.cpp.

References ngl::AbstractVAO::bind(), ngl::VAOFactory::createVAO(), GL_FLOAT, GL_TRIANGLES, m_createdVAOs, ngl::AbstractVAO::setData(), ngl::AbstractVAO::setNumIndices(), ngl::AbstractVAO::setVertexAttributePointer(), and ngl::AbstractVAO::unbind().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::VAOPrimitives::draw ( const std::string _name)
noexcept

Draw one of the VBO's created via a name lookup.

Parameters
[in]_namethe name of the VBO to lookup in the VBO map

Definition at line 42 of file VAOPrimitives.cpp.

References m_createdVAOs.

void ngl::VAOPrimitives::draw ( const std::string _name,
GLenum  _mode 
)
noexcept

Draw one of the VBO's created via a name lookup.

Parameters
[in]_namethe name of the VBO to lookup in the VBO map
[in]_modethe draw mode for the VBO override the default

Definition at line 58 of file VAOPrimitives.cpp.

References m_createdVAOs.

void ngl::VAOPrimitives::fghCircleTable ( std::unique_ptr< Real[]> &  io_sint,
std::unique_ptr< Real[]> &  io_cost,
int  _n 
)
privatenoexcept

create the elements of a circle this is borrowed from freeglut

Parameters
[in,out]io_sinta pointer to the sin elements of the table
[in,out]io_costa pointer to the cos element of the table
[in]_nthe number of points to calculate.

Definition at line 385 of file VAOPrimitives.cpp.

References ngl::PI.

+ Here is the caller graph for this function:

AbstractVAO * ngl::VAOPrimitives::getVAOFromName ( const std::string _name)

get the raw VAO so we can map it etc

Definition at line 896 of file VAOPrimitives.cpp.

References m_createdVAOs.

void ngl::VAOPrimitives::loadBinary ( const std::string _name,
const std::string _fName,
const GLenum  _type 
)
noexcept

load a VBO from a binary file created from Obj2VBO program

Parameters
[in]_namethe name of the VBO to be stored as ref to this object
[in]_fNamethe name of the file to load.
[in]_typethe draw mode type

Friends And Related Function Documentation

friend class Singleton< VAOPrimitives >
friend

Definition at line 57 of file VAOPrimitives.h.

friend class Vec3
friend

Definition at line 58 of file VAOPrimitives.h.

Member Data Documentation

std::unordered_map<std::string,AbstractVAO *> ngl::VAOPrimitives::m_createdVAOs
private

a map to store the VAO by name

Definition at line 166 of file VAOPrimitives.h.


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