Hash :
da02c6d9
Author :
Date :
2021-09-22T11:54:42
samples: Improve TorusLighting samples. Adjust the code style of the ES1 and ES2 TorusLighting samples to match the one of TorusBufferStorage. Use the step function override to calculate rotation and move state changes that are required only once out of the draw function. Bug: angleproject:5751 Change-Id: Ie663c7ecfd306504b6f9e9390ec24b251194f970 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3178904 Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Based on CubeMapActivity.java from The Android Open Source Project ApiDemos
// https://android.googlesource.com/platform/development/+/refs/heads/master/samples/ApiDemos/src/com/example/android/apis/graphics/CubeMapActivity.java
#include "SampleApplication.h"
#include "torus.h"
const float kDegreesPerSecond = 90.0f;
class GLES1TorusLightingSample : public SampleApplication
{
public:
GLES1TorusLightingSample(int argc, char **argv)
: SampleApplication("GLES1 Torus Lighting", argc, argv, 1, 0)
{}
bool initialize() override
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
GLfloat light_model_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_model_ambient);
glEnable(GL_LIGHT0);
GLfloat lightDir[] = {0.0f, 0.0f, 1.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_POSITION, lightDir);
GenerateTorus(&mVertexBuffer, &mIndexBuffer, &mIndexCount);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glVertexPointer(3, GL_FLOAT, 6 * sizeof(GLfloat), nullptr);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 6 * sizeof(GLfloat),
reinterpret_cast<const void *>(3 * sizeof(GLfloat)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
float ratio = static_cast<float>(getWindow()->getWidth()) /
static_cast<float>(getWindow()->getHeight());
glMatrixMode(GL_PROJECTION);
glFrustumf(-ratio, ratio, -1, 1, 1.0f, 20.0f);
return true;
}
void destroy() override
{
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &mVertexBuffer);
glDeleteBuffers(1, &mIndexBuffer);
}
void step(float dt, double totalTime) override { mAngle += kDegreesPerSecond * dt; }
void draw() override
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
glRotatef(mAngle, 0, 1, 0);
glRotatef(mAngle * 0.25f, 1, 0, 0);
glDrawElements(GL_TRIANGLES, mIndexCount, GL_UNSIGNED_SHORT, 0);
}
private:
GLuint mVertexBuffer = 0;
GLuint mIndexBuffer = 0;
GLsizei mIndexCount = 0;
float mAngle = 0;
};
int main(int argc, char **argv)
{
GLES1TorusLightingSample app(argc, argv);
return app.run();
}