27 #include <GLES3/gl3.h>
28 #include <GLES3/gl3ext.h>
32 using namespace MaliSDK;
38 this->torusRadius = torusRadius;
39 this->circleRadius = circleRadius;
40 this->indicesBufferID = 0;
43 const string fragmentShaderPath =
resourceDirectory +
"Instanced_Tessellation_Wireframe_shader.frag";
45 const string vertexShaderPath =
resourceDirectory +
"Instanced_Tessellation_Wireframe_shader.vert";
51 initializeBufferForIndices();
54 initializeVertexAttribs();
57 setColor(1.0
f, 0.3
f, 0.0
f, 1.0
f);
62 GL_CHECK(glDeleteBuffers(1, &indicesBufferID));
68 unsigned int indices[indicesCount];
73 GL_CHECK(glGenBuffers(1, &indicesBufferID));
74 GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBufferID));
75 GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesCount *
sizeof(
int), indices, GL_STATIC_DRAW));
86 GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBufferID));
89 GL_CHECK(glUniform3fv(rotationVectorLocation, 1, rotationVector));
92 GL_CHECK(glDrawElements(GL_LINES, indicesCount, GL_UNSIGNED_INT, 0));
102 GLuint vertexBufferID = 0;
105 float torusVertices[componentsCount];
113 if (positionLocation != -1)
116 GL_CHECK(glGenBuffers(1, &vertexBufferID));
117 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID));
120 GL_CHECK(glBufferData(GL_ARRAY_BUFFER, componentsCount *
sizeof(
float), torusVertices, GL_STATIC_DRAW));
123 GL_CHECK(glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL));
124 GL_CHECK(glEnableVertexAttribArray(positionLocation));
128 LOGE(
"Could not locate \"position\" input attribute in program [%d].",
programID);
bool initializeVertexAttribs(void)
Initialize vertex attribute arrays and buffer objects coresponding to them. Make sure that programID ...
static void calculateWireframeIndices(unsigned int circlesCount, unsigned int pointsPerCircleCount, unsigned int *indices)
Determines indices for glDrawElements() call for wireframed torus.
static void generateVertices(float torusRadius, float circleRadius, unsigned int circlesCount, unsigned int pointsPerCircleCount, float *vertices)
Generate vertices of the torus model.
void initializeBufferForIndices(void)
Determine indices needed for a single glDrawElements() call in GL_LINES mode.
GLsizei GLenum const void * indices
bool setupGraphics(int width, int height)
void draw(float *rotationVector)
Draw the torus model.
WireframeTorus(float torusRadius, float circleRadius)
Instantiates a representation of a solid torus, using user-provided radius and tube radius...
GLint rotationVectorLocation
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count