OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstancedSolidTorus.h
Go to the documentation of this file.
1 /* Copyright (c) 2012-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef INSTANCED_SOLID_TORUS_H
22 #define INSTANCED_SOLID_TORUS_H
23 
24 #include "Torus.h"
25 
44 class InstancedSolidTorus : public Torus
45 {
46 private:
50  static const unsigned int patchDimension = 4;
58  static const unsigned int quadsInPatchCount = (patchDimension - 1) * (patchDimension - 1);
70  static const unsigned int patchDensity = 16;
74  static const unsigned int patchVerticesCount = patchDensity * patchDensity;
78  static const unsigned int patchComponentsCount = patchVerticesCount * 2;
82  static const unsigned int patchTriangleIndicesCount = (patchDensity - 1) * (patchDensity - 1) * 6;
83 
102 
107 
108  bool initializeVertexAttribs(void);
109 
114  void setLightParameters(void);
115 
116 public:
117 
125 
129  ~InstancedSolidTorus(void);
130 
136  void draw(float* rotationVector);
137 };
138 
139 #endif /* INSTANCED_SOLID_TORUS_H. */
static const unsigned int patchVerticesCount
Total number of vertices in a patch.
static const unsigned int patchComponentsCount
Total number of components describing a patch (only U/V components are defined).
static const unsigned int patchDimension
Number of control points in one dimension for a patch.
static const unsigned int controlPointsIndicesCount
Number of indices needed to create a control mesh.
float torusRadius
Distance between the center of torus and the center of its tube.
Definition: Torus.h:70
static const unsigned int controlPointsInPatchCount
Total number of control points in a patch.
GLuint patchIndicesBufferID
Index of a buffer that we bind to GL_ELEMENT_ARRAY_BUFFER binding point. It containts indices of patc...
void draw(float *rotationVector)
Draws instanced solid torus.
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:
~InstancedSolidTorus(void)
Frees allocated memory.
GLuint controlIndicesBufferID
Index of a buffer that we bind to GL_UNIFORM_BUFFER binding point. It stores uniform control indices ...
static const unsigned int patchDensity
Number of vertices in one edge of a patch.
float circleRadius
Radius of circles that model the tube.
Definition: Torus.h:74
Abstract class that draws torus on the screen. It stores generic data describing the drawn torus: ...
Definition: Torus.h:39
GLuint patchVertexBufferID
Index of a buffer that we bind to GL_ARRAY_BUFFER binding point. It stores patch vertices passed as a...
static const unsigned int quadsInPatchCount
Number of quads in a patch.
static const unsigned int patchInstancesCount
Number of instances needed to draw the whole torus.
static const unsigned int torusVerticesCount
Total number of vertices in torus model.
Definition: Torus.h:61
bool initializeVertexAttribs(void)
Initialize vertex attribute arrays and buffer objects coresponding to them. Make sure that programID ...
InstancedSolidTorus(float torusRadius, float circleRadius)
Instantiates a representation of a solid torus, using user-provided radius and tube radius...
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
bool initializeControlUniformBuffers(void)
Initializes control mesh data and stores it in appropriate uniform buffers.
void setLightParameters(void)
Sets directionl light parameters, such as light direction, its color and ambient intensity and passes...
static const unsigned int patchTriangleIndicesCount
Number of indices that need to be defined to draw quads consisting of triangles (6 points per quad ne...
GLuint controlVerticesBufferID
Index of a buffer that we bind to GL_UNIFORM_BUFFER binding point. It stores uniform control vertices...