MCPcopy Create free account
hub / github.com/android/ndk-samples / Render

Method Render

teapots/image-decoder/src/main/cpp/TeapotRenderer.cpp:148–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148void TeapotRenderer::Render() {
149 //
150 // Feed Projection and Model View matrices to the shaders
151 ndk_helper::Mat4 mat_vp = mat_projection_ * mat_view_;
152
153 // Bind the VBO
154 glBindBuffer(GL_ARRAY_BUFFER, vbo_);
155
156 int32_t iStride = sizeof(TEAPOT_VERTEX);
157 // Pass the vertex data
158 glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, iStride, nullptr);
159 glEnableVertexAttribArray(ATTRIB_VERTEX);
160
161 glVertexAttribPointer(ATTRIB_NORMAL, 3, GL_FLOAT, GL_FALSE, iStride,
162 reinterpret_cast<void*>(3 * sizeof(GLfloat)));
163 glEnableVertexAttribArray(ATTRIB_NORMAL);
164
165 // Bind the IB
166 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_);
167
168 glUseProgram(shader_param_.program_);
169
170 TEAPOT_MATERIALS material = {
171 {1.0f, 0.5f, 0.5f},
172 {1.0f, 1.0f, 1.0f, 10.f},
173 {0.1f, 0.1f, 0.1f},
174 };
175
176 // Update uniforms
177 glUniform4f(shader_param_.material_diffuse_, material.diffuse_color[0],
178 material.diffuse_color[1], material.diffuse_color[2], 1.f);
179
180 glUniform4f(shader_param_.material_specular_, material.specular_color[0],
181 material.specular_color[1], material.specular_color[2],
182 material.specular_color[3]);
183 //
184 // using glUniform3fv here was troublesome
185 //
186 glUniform3f(shader_param_.material_ambient_, material.ambient_color[0],
187 material.ambient_color[1], material.ambient_color[2]);
188
189 glUniformMatrix4fv(shader_param_.matrix_projection_, 1, GL_FALSE,
190 mat_vp.Ptr());
191 glUniformMatrix4fv(shader_param_.matrix_view_, 1, GL_FALSE, mat_view_.Ptr());
192 glUniform3f(shader_param_.light0_, 100.f, -200.f, -600.f);
193
194 glDrawElements(GL_TRIANGLES, num_indices_, GL_UNSIGNED_SHORT, nullptr);
195
196 glBindBuffer(GL_ARRAY_BUFFER, 0);
197 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
198}
199
200bool TeapotRenderer::LoadShaders(SHADER_PARAMS* params, const char* strVsh,
201 const char* strFsh) {

Callers 1

DrawFrameMethod · 0.45

Calls 1

PtrMethod · 0.80

Tested by

no test coverage detected