OpenGL ES SDK for Android
ARM Developer Center
|
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>
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... | |
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:
Definition at line 44 of file InstancedSolidTorus.h.
Instantiates a representation of a solid torus, using user-provided radius and tube radius.
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.
Draws instanced solid torus.
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.
|
private |
Initializes control mesh data and stores it in appropriate uniform buffers.
Definition at line 99 of file InstancedSolidTorus.cpp.
|
privatevirtual |
Initialize vertex attribute arrays and buffer objects coresponding to them. Make sure that programID has been set before this function is called.
Implements Torus.
Definition at line 144 of file InstancedSolidTorus.cpp.
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.
|
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.
|
staticprivate |
Number of indices needed to create a control mesh.
Definition at line 62 of file InstancedSolidTorus.h.
|
staticprivate |
Total number of control points in a patch.
Definition at line 54 of file InstancedSolidTorus.h.
|
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.
|
staticprivate |
Total number of components describing a patch (only U/V components are defined).
Definition at line 78 of file InstancedSolidTorus.h.
|
staticprivate |
Number of vertices in one edge of a patch.
Definition at line 70 of file InstancedSolidTorus.h.
|
staticprivate |
Number of control points in one dimension for a patch.
Definition at line 50 of file InstancedSolidTorus.h.
|
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.
|
staticprivate |
Number of instances needed to draw the whole torus.
Definition at line 66 of file InstancedSolidTorus.h.
|
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.
|
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.
|
staticprivate |
Total number of vertices in a patch.
Definition at line 74 of file InstancedSolidTorus.h.
|
staticprivate |
Number of quads in a patch.
Definition at line 58 of file InstancedSolidTorus.h.