OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstancedSolidTorus Class Reference

Class derived form Torus abstract class. It manages drawing of a rotating solid torus, built from separate patches. Each patch is modelled as a Bezier surface approximating surface of a perfect torus. To satisfy the C1 continuity between neighbour patches, the number of circles creating the torus and also the number of points in each circle is restricted to 12. It allows us to divide both circles of torus ("big" and "small") into 4 quadrants and approximate each of it using bicubic Bezier curves. Control mesh vertices has to be distored, so the derivatives on the patch edges are equal and resulting image is round. That is why we cannot use the regular way to determine control points. The patches are in fact very dense square-shaped meshes, used as input attributes by vertex shader. The shader changes their shape on the basis of the distorted control mesh and places them next to each other, forming a round torus. The class, apart from inherited components, manages: More...

#include <InstancedSolidTorus.h>

Inheritance diagram for InstancedSolidTorus:
Torus

Public Member Functions

 InstancedSolidTorus (float torusRadius, float circleRadius)
 Instantiates a representation of a solid torus, using user-provided radius and tube radius. More...
 
 ~InstancedSolidTorus (void)
 Frees allocated memory. More...
 
void draw (float *rotationVector)
 Draws instanced solid torus. More...
 
- Public Member Functions inherited from Torus
virtual ~Torus (void)
 Frees allocated memory. More...
 
void setProjectionMatrix (MaliSDK::Matrix *projectionMatrix)
 Pass the correctly defined projection matrix to the program related to the torus model. More...
 

Private Member Functions

bool initializeControlUniformBuffers (void)
 Initializes control mesh data and stores it in appropriate uniform buffers. More...
 
bool initializeVertexAttribs (void)
 Initialize vertex attribute arrays and buffer objects coresponding to them. Make sure that programID has been set before this function is called. More...
 
void setLightParameters (void)
 Sets directionl light parameters, such as light direction, its color and ambient intensity and passes it to corresponding uniforms in shader. More...
 

Private Attributes

GLuint controlIndicesBufferID
 Index of a buffer that we bind to GL_UNIFORM_BUFFER binding point. It stores uniform control indices of torus control mesh. More...
 
GLuint controlVerticesBufferID
 Index of a buffer that we bind to GL_UNIFORM_BUFFER binding point. It stores uniform control vertices of torus control mesh. More...
 
GLuint patchIndicesBufferID
 Index of a buffer that we bind to GL_ELEMENT_ARRAY_BUFFER binding point. It containts indices of patch triangles, so that we can use an element-type draw call to show the object. More...
 
GLuint patchVertexBufferID
 Index of a buffer that we bind to GL_ARRAY_BUFFER binding point. It stores patch vertices passed as an input to the corresponding vertex shader. More...
 

Static Private Attributes

static const unsigned int patchDimension = 4
 Number of control points in one dimension for a patch. More...
 
static const unsigned int controlPointsInPatchCount = patchDimension * patchDimension
 Total number of control points in a patch. More...
 
static const unsigned int quadsInPatchCount = (patchDimension - 1) * (patchDimension - 1)
 Number of quads in a patch. More...
 
static const unsigned int controlPointsIndicesCount = controlPointsInPatchCount * torusVerticesCount / quadsInPatchCount
 Number of indices needed to create a control mesh. More...
 
static const unsigned int patchInstancesCount = controlPointsIndicesCount / controlPointsInPatchCount
 Number of instances needed to draw the whole torus. More...
 
static const unsigned int patchDensity = 16
 Number of vertices in one edge of a patch. More...
 
static const unsigned int patchVerticesCount = patchDensity * patchDensity
 Total number of vertices in a patch. More...
 
static const unsigned int patchComponentsCount = patchVerticesCount * 2
 Total number of components describing a patch (only U/V components are defined). More...
 
static const unsigned int patchTriangleIndicesCount = (patchDensity - 1) * (patchDensity - 1) * 6
 Number of indices that need to be defined to draw quads consisting of triangles (6 points per quad needed) over the entire patch. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Torus
static void setResourceDirectory (std::string requiredResourceDirectory)
 Set the resource directory for all tori. More...
 
- Protected Member Functions inherited from Torus
 Torus (void)
 Protected constructor used to do intialization general to all torus objects. More...
 
void setColor (float red, float green, float blue, float alpha)
 Sets the uniform color of the drawn torus. More...
 
void setupGraphics (const std::string vertexShaderPath, const std::string fragmentShaderPath)
 Initialize constant OpenGL components such as program, shaders and constant matrices. More...
 
- Protected Attributes inherited from Torus
float torusRadius
 Distance between the center of torus and the center of its tube. More...
 
float circleRadius
 Radius of circles that model the tube. More...
 
GLuint programID
 ID of a program linked to the torus model. More...
 
GLuint vaoID
 ID of a vertex array object that stores pointers to vertex data sources used to rasterize given mesh. More...
 
- Static Protected Attributes inherited from Torus
static std::string resourceDirectory
 
static const unsigned int vertexComponentsCount = 4
 Number of coordinates for one vertex. More...
 
static const unsigned int circlesCount = 12
 Number of circles in torus model. More...
 
static const unsigned int pointsPerCircleCount = 12
 Number of points in one circle. More...
 
static const unsigned int torusVerticesCount = pointsPerCircleCount * circlesCount
 Total number of vertices in torus model. More...
 
static const unsigned int componentsCount = torusVerticesCount * vertexComponentsCount
 Total number of components in torus model, needed to determine the size of vertex arrays. More...
 

Detailed Description

Class derived form Torus abstract class. It manages drawing of a rotating solid torus, built from separate patches. Each patch is modelled as a Bezier surface approximating surface of a perfect torus. To satisfy the C1 continuity between neighbour patches, the number of circles creating the torus and also the number of points in each circle is restricted to 12. It allows us to divide both circles of torus ("big" and "small") into 4 quadrants and approximate each of it using bicubic Bezier curves. Control mesh vertices has to be distored, so the derivatives on the patch edges are equal and resulting image is round. That is why we cannot use the regular way to determine control points. The patches are in fact very dense square-shaped meshes, used as input attributes by vertex shader. The shader changes their shape on the basis of the distorted control mesh and places them next to each other, forming a round torus. The class, apart from inherited components, manages:

  • 2 uniform buffers where control point vertices and indices are stored,
  • an array buffer storing patch vertices,
  • an element array buffer storing indices, which are used in a glDrawElementsInstanced() call. It is also capable of determining the needed indices arrays.

Definition at line 44 of file InstancedSolidTorus.h.

Constructor & Destructor Documentation

InstancedSolidTorus::InstancedSolidTorus ( float  torusRadius,
float  circleRadius 
)

Instantiates a representation of a solid torus, using user-provided radius and tube radius.

Parameters
torusRadius[in] Distance between center of torus and center of its tube.
circleRadius[in] Radius of circles that model the tube.

Definition at line 37 of file InstancedSolidTorus.cpp.

InstancedSolidTorus::~InstancedSolidTorus ( void  )

Frees allocated memory.

Definition at line 64 of file InstancedSolidTorus.cpp.

Member Function Documentation

void InstancedSolidTorus::draw ( float rotationVector)
virtual

Draws instanced solid torus.

Parameters
rotationVector[in] Vector of 3 elements storing rotation parameters to be passed to the vertex shader.

Implements Torus.

Definition at line 74 of file InstancedSolidTorus.cpp.

bool InstancedSolidTorus::initializeControlUniformBuffers ( void  )
private

Initializes control mesh data and stores it in appropriate uniform buffers.

Definition at line 99 of file InstancedSolidTorus.cpp.

bool InstancedSolidTorus::initializeVertexAttribs ( void  )
privatevirtual

Initialize vertex attribute arrays and buffer objects coresponding to them. Make sure that programID has been set before this function is called.

Returns
false if error reported, true otherwise.

Implements Torus.

Definition at line 144 of file InstancedSolidTorus.cpp.

void InstancedSolidTorus::setLightParameters ( void  )
private

Sets directionl light parameters, such as light direction, its color and ambient intensity and passes it to corresponding uniforms in shader.

Definition at line 185 of file InstancedSolidTorus.cpp.

Member Data Documentation

GLuint InstancedSolidTorus::controlIndicesBufferID
private

Index of a buffer that we bind to GL_UNIFORM_BUFFER binding point. It stores uniform control indices of torus control mesh.

Definition at line 87 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::controlPointsIndicesCount = controlPointsInPatchCount * torusVerticesCount / quadsInPatchCount
staticprivate

Number of indices needed to create a control mesh.

Definition at line 62 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::controlPointsInPatchCount = patchDimension * patchDimension
staticprivate

Total number of control points in a patch.

Definition at line 54 of file InstancedSolidTorus.h.

GLuint InstancedSolidTorus::controlVerticesBufferID
private

Index of a buffer that we bind to GL_UNIFORM_BUFFER binding point. It stores uniform control vertices of torus control mesh.

Definition at line 91 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::patchComponentsCount = patchVerticesCount * 2
staticprivate

Total number of components describing a patch (only U/V components are defined).

Definition at line 78 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::patchDensity = 16
staticprivate

Number of vertices in one edge of a patch.

Definition at line 70 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::patchDimension = 4
staticprivate

Number of control points in one dimension for a patch.

Definition at line 50 of file InstancedSolidTorus.h.

GLuint InstancedSolidTorus::patchIndicesBufferID
private

Index of a buffer that we bind to GL_ELEMENT_ARRAY_BUFFER binding point. It containts indices of patch triangles, so that we can use an element-type draw call to show the object.

Definition at line 96 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::patchInstancesCount = controlPointsIndicesCount / controlPointsInPatchCount
staticprivate

Number of instances needed to draw the whole torus.

Definition at line 66 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::patchTriangleIndicesCount = (patchDensity - 1) * (patchDensity - 1) * 6
staticprivate

Number of indices that need to be defined to draw quads consisting of triangles (6 points per quad needed) over the entire patch.

Definition at line 82 of file InstancedSolidTorus.h.

GLuint InstancedSolidTorus::patchVertexBufferID
private

Index of a buffer that we bind to GL_ARRAY_BUFFER binding point. It stores patch vertices passed as an input to the corresponding vertex shader.

Definition at line 101 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::patchVerticesCount = patchDensity * patchDensity
staticprivate

Total number of vertices in a patch.

Definition at line 74 of file InstancedSolidTorus.h.

const unsigned int InstancedSolidTorus::quadsInPatchCount = (patchDimension - 1) * (patchDimension - 1)
staticprivate

Number of quads in a patch.

Definition at line 58 of file InstancedSolidTorus.h.


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