=== added file 'src/scene-build.cpp'
@@ -0,0 +1,185 @@
+/*
+ * Copyright © 2008 Ben Smith
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Ben Smith (original glmark benchmark)
+ * Alexandros Frantzis (glmark2)
+ */
+#include "scene.h"
+#include "log.h"
+#include "mat.h"
+#include "stack.h"
+#include <cmath>
+
+SceneBuild::SceneBuild(Screen &pScreen) :
+ Scene(pScreen, "build")
+{
+ mOptions["use-vbo"] = Scene::Option("use-vbo", "true",
+ "Whether to use VBOs for rendering [true,false]");
+}
+
+SceneBuild::~SceneBuild()
+{
+}
+
+int SceneBuild::load()
+{
+ static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert");
+ static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.frag");
+ Model model;
+
+ if(!model.load_3ds(GLMARK_DATA_PATH"/models/horse.3ds"))
+ return 0;
+
+ model.calculate_normals();
+ model.convert_to_mesh(&mMesh);
+
+ if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename))
+ return 0;
+
+ mVertexAttribLocation = mProgram.getAttribIndex("position");
+ mNormalAttribLocation = mProgram.getAttribIndex("normal");
+ mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord");
+
+ mRotationSpeed = 36.0f;
+
+ mRunning = false;
+
+ return 1;
+}
+
+void SceneBuild::unload()
+{
+ mMesh.reset();
+
+ mProgram.stop();
+ mProgram.release();
+}
+
+void SceneBuild::setup()
+{
+ Scene::setup();
+
+ static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f);
+ static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f);
+ static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
+ static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f);
+
+ mUseVbo = (mOptions["use-vbo"].value == "true");
+
+ if (mUseVbo)
+ mMesh.build_vbo();
+
+ mProgram.start();
+
+ // Load lighting and material uniforms
+ mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient");
+ mProgram.loadUniformVector(lightPosition, "LightSourcePosition");
+ mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse");
+ mProgram.loadUniformVector(materialColor, "MaterialColor");
+
+ mCurrentFrame = 0;
+ mRotation = 0.0;
+ mRunning = true;
+ mStartTime = SDL_GetTicks() / 1000.0;
+ mLastUpdateTime = mStartTime;
+}
+
+void
+SceneBuild::teardown()
+{
+ mProgram.stop();
+
+ if (mUseVbo)
+ mMesh.delete_vbo();
+
+ Scene::teardown();
+}
+
+void SceneBuild::update()
+{
+ double current_time = SDL_GetTicks() / 1000.0;
+ double dt = current_time - mLastUpdateTime;
+ double elapsed_time = current_time - mStartTime;
+
+ mLastUpdateTime = current_time;
+
+ if (elapsed_time >= mDuration) {
+ mAverageFPS = mCurrentFrame / elapsed_time;
+ mRunning = false;
+ }
+
+ mRotation += mRotationSpeed * dt;
+
+ mCurrentFrame++;
+}
+
+void SceneBuild::draw()
+{
+ LibMatrix::Stack4 model_view;
+
+ // Load the ModelViewProjectionMatrix uniform in the shader
+ LibMatrix::mat4 model_view_proj(mScreen.mProjection);
+
+ model_view.translate(0.0f, 0.0f, -2.5f);
+ model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f);
+ model_view_proj *= model_view.getCurrent();
+
+ mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
+
+ // Load the NormalMatrix uniform in the shader. The NormalMatrix is the
+ // inverse transpose of the model view matrix.
+ LibMatrix::mat4 normal_matrix(model_view.getCurrent());
+ normal_matrix.inverse().transpose();
+ mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix");
+
+ if (mUseVbo) {
+ mMesh.render_vbo(mVertexAttribLocation,
+ mNormalAttribLocation,
+ mTexcoordAttribLocation);
+ }
+ else {
+ mMesh.render_array(mVertexAttribLocation,
+ mNormalAttribLocation,
+ mTexcoordAttribLocation);
+ }
+}
+
+Scene::ValidationResult
+SceneBuild::validate()
+{
+ static const double radius_3d(std::sqrt(3.0));
+
+ if (mRotation != 0)
+ return Scene::ValidationUnknown;
+
+ Screen::Pixel ref(0xa7, 0xa7, 0xa7, 0xff);
+ Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2,
+ mScreen.mHeight / 2);
+
+ double dist = pixel_value_distance(pixel, ref);
+ if (dist < radius_3d + 0.01) {
+ return Scene::ValidationSuccess;
+ }
+ else {
+ Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n",
+ ref.to_le32(), pixel.to_le32(), dist);
+ return Scene::ValidationFailure;
+ }
+}
=== added file 'src/scene-default-options.cpp'
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Alexandros Frantzis (glmark2)
+ */
+#include "scene.h"
+#include "benchmark.h"
+
+void SceneDefaultOptions::setup()
+{
+ const std::map<std::string, Scene *> &scenes = Benchmark::scenes();
+
+ for (std::list<std::pair<std::string, std::string> >::const_iterator iter = mDefaultOptions.begin();
+ iter != mDefaultOptions.end();
+ iter++)
+ {
+ for (std::map<std::string, Scene *>::const_iterator scene_iter = scenes.begin();
+ scene_iter != scenes.end();
+ scene_iter++)
+ {
+ scene_iter->second->set_option_default(iter->first, iter->second);
+ }
+ }
+}
+
+bool
+SceneDefaultOptions::set_option(const std::string &opt, const std::string &val)
+{
+ mDefaultOptions.push_back(std::pair<std::string, std::string>(opt, val));
+ return true;
+}
=== added file 'src/scene-shading.cpp'
@@ -0,0 +1,209 @@
+/*
+ * Copyright © 2008 Ben Smith
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Ben Smith (original glmark benchmark)
+ * Alexandros Frantzis (glmark2)
+ */
+#include "scene.h"
+#include "mat.h"
+#include "stack.h"
+#include "vec.h"
+#include "log.h"
+
+#include <cmath>
+
+SceneShading::SceneShading(Screen &pScreen) :
+ Scene(pScreen, "shading")
+{
+ mOptions["shading"] = Scene::Option("shading", "gouraud",
+ "[gouraud, phong]");
+}
+
+SceneShading::~SceneShading()
+{
+}
+
+int SceneShading::load()
+{
+ Model model;
+
+ if(!model.load_3ds(GLMARK_DATA_PATH"/models/cat.3ds"))
+ return 0;
+
+ model.calculate_normals();
+ model.convert_to_mesh(&mMesh);
+
+ mMesh.build_vbo();
+
+ mRotationSpeed = 36.0f;
+
+ mRunning = false;
+
+ return 1;
+}
+
+void SceneShading::unload()
+{
+ mMesh.reset();
+}
+
+void SceneShading::setup()
+{
+ Scene::setup();
+
+ static const LibMatrix::vec3 lightAmbient(0.1f, 0.1f, 0.1f);
+ static const LibMatrix::vec3 lightDiffuse(0.8f, 0.8f, 0.8f);
+ static const LibMatrix::vec3 lightSpecular(0.8f, 0.8f, 0.8f);
+ static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
+
+ static const LibMatrix::vec3 materialAmbient(1.0f, 1.0f, 1.0f);
+ static const LibMatrix::vec3 materialDiffuse(1.0f, 1.0f, 1.0f);
+ static const LibMatrix::vec3 materialSpecular(1.0f, 1.0f, 1.0f);
+ static const LibMatrix::vec4 materialColor(0.0f, 0.0f, 1.0f, 1.0f);
+
+ std::string vtx_shader_filename;
+ std::string frg_shader_filename;
+ const std::string &shading = mOptions["shading"].value;
+
+ if (shading == "gouraud") {
+ vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.vert";
+ frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.frag";
+ }
+ else if (shading == "phong") {
+ vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.vert";
+ frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.frag";
+ }
+
+ if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename))
+ return;
+
+ mProgram.start();
+
+ mVertexAttribLocation = mProgram.getAttribIndex("position");
+ mNormalAttribLocation = mProgram.getAttribIndex("normal");
+ mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord");
+
+ // Load lighting and material uniforms
+ mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient");
+ mProgram.loadUniformVector(lightPosition, "LightSourcePosition");
+ mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse");
+ mProgram.loadUniformVector(lightSpecular, "LightSourceSpecular");
+
+ mProgram.loadUniformVector(materialAmbient, "MaterialAmbient");
+ mProgram.loadUniformVector(materialDiffuse, "MaterialDiffuse");
+ mProgram.loadUniformVector(materialSpecular, "MaterialSpecular");
+ mProgram.loadUniformVector(materialColor, "MaterialColor");
+
+ // Calculate and load the half vector
+ LibMatrix::vec3 halfVector(lightPosition[0], lightPosition[1], lightPosition[2]);
+ halfVector.normalize();
+ halfVector += LibMatrix::vec3(0.0, 0.0, 1.0);
+ halfVector.normalize();
+ mProgram.loadUniformVector(halfVector, "LightSourceHalfVector");
+
+ mCurrentFrame = 0;
+ mRotation = 0.0f;
+ mRunning = true;
+ mStartTime = SDL_GetTicks() / 1000.0;
+ mLastUpdateTime = mStartTime;
+}
+
+void SceneShading::teardown()
+{
+ mProgram.stop();
+ mProgram.release();
+
+ Scene::teardown();
+}
+
+void SceneShading::update()
+{
+ double current_time = SDL_GetTicks() / 1000.0;
+ double dt = current_time - mLastUpdateTime;
+ double elapsed_time = current_time - mStartTime;
+
+ mLastUpdateTime = current_time;
+
+ if (elapsed_time >= mDuration) {
+ mAverageFPS = mCurrentFrame / elapsed_time;
+ mRunning = false;
+ }
+
+ mRotation += mRotationSpeed * dt;
+
+ mCurrentFrame++;
+}
+
+void SceneShading::draw()
+{
+ // Load the ModelViewProjectionMatrix uniform in the shader
+ LibMatrix::Stack4 model_view;
+ LibMatrix::mat4 model_view_proj(mScreen.mProjection);
+
+ model_view.translate(0.0f, 0.0f, -5.0f);
+ model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f);
+ model_view_proj *= model_view.getCurrent();
+
+ mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
+
+ // Load the NormalMatrix uniform in the shader. The NormalMatrix is the
+ // inverse transpose of the model view matrix.
+ LibMatrix::mat4 normal_matrix(model_view.getCurrent());
+ normal_matrix.inverse().transpose();
+ mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix");
+
+ mMesh.render_vbo(mVertexAttribLocation,
+ mNormalAttribLocation,
+ mTexcoordAttribLocation);
+}
+
+Scene::ValidationResult
+SceneShading::validate()
+{
+ static const double radius_3d(std::sqrt(3.0));
+
+ if (mRotation != 0)
+ return Scene::ValidationUnknown;
+
+ Screen::Pixel ref;
+
+ Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2,
+ mScreen.mHeight / 2);
+
+ const std::string &filter = mOptions["shading"].value;
+
+ if (filter == "gouraud")
+ ref = Screen::Pixel(0x00, 0x00, 0xca, 0xff);
+ else if (filter == "phong")
+ ref = Screen::Pixel(0x1a, 0x1a, 0xbb, 0xff);
+ else
+ return Scene::ValidationUnknown;
+
+ double dist = pixel_value_distance(pixel, ref);
+
+ if (dist < radius_3d + 0.01) {
+ return Scene::ValidationSuccess;
+ }
+ else {
+ Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n",
+ ref.to_le32(), pixel.to_le32(), dist);
+ return Scene::ValidationFailure;
+ }
+}
=== added file 'src/scene-texture.cpp'
@@ -0,0 +1,212 @@
+/*
+ * Copyright © 2008 Ben Smith
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Ben Smith (original glmark benchmark)
+ * Alexandros Frantzis (glmark2)
+ */
+#include "scene.h"
+#include "mat.h"
+#include "stack.h"
+#include "vec.h"
+#include "log.h"
+
+#include "program.h"
+#include <cmath>
+
+SceneTexture::SceneTexture(Screen &pScreen) :
+ Scene(pScreen, "texture")
+{
+ mOptions["texture-filter"] = Scene::Option("texture-filter", "nearest",
+ "[nearest, linear, mipmap]");
+}
+
+SceneTexture::~SceneTexture()
+{
+}
+
+int SceneTexture::load()
+{
+ static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert");
+ static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic-tex.frag");
+ Model model;
+
+ if(!model.load_3ds(GLMARK_DATA_PATH"/models/cube.3ds"))
+ return 0;
+
+ model.calculate_normals();
+ model.convert_to_mesh(&mCubeMesh);
+ mCubeMesh.build_vbo();
+
+ if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename))
+ return 0;
+
+ mVertexAttribLocation = mProgram.getAttribIndex("position");
+ mNormalAttribLocation = mProgram.getAttribIndex("normal");
+ mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord");
+
+ mRotationSpeed = LibMatrix::vec3(36.0f, 36.0f, 36.0f);
+
+ mRunning = false;
+
+ return 1;
+}
+
+void SceneTexture::unload()
+{
+ mCubeMesh.reset();
+
+ mProgram.stop();
+ mProgram.release();
+}
+
+void SceneTexture::setup()
+{
+ Scene::setup();
+
+ static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f);
+ static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f);
+ static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
+ static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f);
+
+ // Create texture according to selected filtering
+ GLint min_filter = GL_NONE;
+ GLint mag_filter = GL_NONE;
+ const std::string &filter = mOptions["texture-filter"].value;
+
+ if (filter == "nearest") {
+ min_filter = GL_NEAREST;
+ mag_filter = GL_NEAREST;
+ }
+ else if (filter == "linear") {
+ min_filter = GL_LINEAR;
+ mag_filter = GL_LINEAR;
+ }
+ else if (filter == "mipmap") {
+ min_filter = GL_LINEAR_MIPMAP_LINEAR;
+ mag_filter = GL_LINEAR;
+ }
+
+ Texture::load(GLMARK_DATA_PATH"/textures/crate-base.bmp", &mTexture,
+ min_filter, mag_filter, 0);
+
+ mProgram.start();
+
+ // Load lighting and material uniforms
+ mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient");
+ mProgram.loadUniformVector(lightPosition, "LightSourcePosition");
+ mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse");
+ mProgram.loadUniformVector(materialColor, "MaterialColor");
+
+ mCurrentFrame = 0;
+ mRotation = LibMatrix::vec3();
+ mRunning = true;
+ mStartTime = SDL_GetTicks() / 1000.0;
+ mLastUpdateTime = mStartTime;
+}
+
+void SceneTexture::teardown()
+{
+ mProgram.stop();
+ glDeleteTextures(1, &mTexture);
+
+ Scene::teardown();
+}
+
+void SceneTexture::update()
+{
+ double current_time = SDL_GetTicks() / 1000.0;
+ double dt = current_time - mLastUpdateTime;
+ double elapsed_time = current_time - mStartTime;
+
+ mLastUpdateTime = current_time;
+
+ if (elapsed_time >= mDuration) {
+ mAverageFPS = mCurrentFrame / elapsed_time;
+ mRunning = false;
+ }
+
+ mRotation += mRotationSpeed * dt;
+
+ mCurrentFrame++;
+}
+
+void SceneTexture::draw()
+{
+ // Load the ModelViewProjectionMatrix uniform in the shader
+ LibMatrix::Stack4 model_view;
+ LibMatrix::mat4 model_view_proj(mScreen.mProjection);
+
+ model_view.translate(0.0f, 0.0f, -5.0f);
+ model_view.rotate(mRotation.x(), 1.0f, 0.0f, 0.0f);
+ model_view.rotate(mRotation.y(), 0.0f, 1.0f, 0.0f);
+ model_view.rotate(mRotation.z(), 0.0f, 0.0f, 1.0f);
+ model_view_proj *= model_view.getCurrent();
+
+ mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
+
+ // Load the NormalMatrix uniform in the shader. The NormalMatrix is the
+ // inverse transpose of the model view matrix.
+ LibMatrix::mat4 normal_matrix(model_view.getCurrent());
+ normal_matrix.inverse().transpose();
+ mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix");
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, mTexture);
+
+ mCubeMesh.render_vbo(mVertexAttribLocation,
+ mNormalAttribLocation,
+ mTexcoordAttribLocation);
+}
+
+Scene::ValidationResult
+SceneTexture::validate()
+{
+ static const double radius_3d(std::sqrt(3.0));
+
+ if (mRotation.x() != 0 || mRotation.y() != 0 || mRotation.z() != 0)
+ return Scene::ValidationUnknown;
+
+ Screen::Pixel ref;
+
+ Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2,
+ mScreen.mHeight / 2);
+
+ const std::string &filter = mOptions["texture-filter"].value;
+
+ if (filter == "nearest")
+ ref = Screen::Pixel(0x3a, 0x3a, 0x3b, 0xff);
+ else if (filter == "linear")
+ ref = Screen::Pixel(0x34, 0x34, 0x35, 0xff);
+ else if (filter == "mipmap")
+ ref = Screen::Pixel(0x33, 0x33, 0x35, 0xff);
+ else
+ return Scene::ValidationUnknown;
+
+ double dist = pixel_value_distance(pixel, ref);
+
+ if (dist < radius_3d + 0.01) {
+ return Scene::ValidationSuccess;
+ }
+ else {
+ Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n",
+ ref.to_le32(), pixel.to_le32(), dist);
+ return Scene::ValidationFailure;
+ }
+}
=== removed file 'src/scenebuild.cpp'
@@ -1,185 +0,0 @@
-/*
- * Copyright © 2008 Ben Smith
- * Copyright © 2010-2011 Linaro Limited
- *
- * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
- *
- * glmark2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * glmark2. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Ben Smith (original glmark benchmark)
- * Alexandros Frantzis (glmark2)
- */
-#include "scene.h"
-#include "log.h"
-#include "mat.h"
-#include "stack.h"
-#include <cmath>
-
-SceneBuild::SceneBuild(Screen &pScreen) :
- Scene(pScreen, "build")
-{
- mOptions["use-vbo"] = Scene::Option("use-vbo", "true",
- "Whether to use VBOs for rendering [true,false]");
-}
-
-SceneBuild::~SceneBuild()
-{
-}
-
-int SceneBuild::load()
-{
- static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert");
- static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.frag");
- Model model;
-
- if(!model.load_3ds(GLMARK_DATA_PATH"/models/horse.3ds"))
- return 0;
-
- model.calculate_normals();
- model.convert_to_mesh(&mMesh);
-
- if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename))
- return 0;
-
- mVertexAttribLocation = mProgram.getAttribIndex("position");
- mNormalAttribLocation = mProgram.getAttribIndex("normal");
- mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord");
-
- mRotationSpeed = 36.0f;
-
- mRunning = false;
-
- return 1;
-}
-
-void SceneBuild::unload()
-{
- mMesh.reset();
-
- mProgram.stop();
- mProgram.release();
-}
-
-void SceneBuild::setup()
-{
- Scene::setup();
-
- static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f);
- static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f);
- static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
- static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f);
-
- mUseVbo = (mOptions["use-vbo"].value == "true");
-
- if (mUseVbo)
- mMesh.build_vbo();
-
- mProgram.start();
-
- // Load lighting and material uniforms
- mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient");
- mProgram.loadUniformVector(lightPosition, "LightSourcePosition");
- mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse");
- mProgram.loadUniformVector(materialColor, "MaterialColor");
-
- mCurrentFrame = 0;
- mRotation = 0.0;
- mRunning = true;
- mStartTime = SDL_GetTicks() / 1000.0;
- mLastUpdateTime = mStartTime;
-}
-
-void
-SceneBuild::teardown()
-{
- mProgram.stop();
-
- if (mUseVbo)
- mMesh.delete_vbo();
-
- Scene::teardown();
-}
-
-void SceneBuild::update()
-{
- double current_time = SDL_GetTicks() / 1000.0;
- double dt = current_time - mLastUpdateTime;
- double elapsed_time = current_time - mStartTime;
-
- mLastUpdateTime = current_time;
-
- if (elapsed_time >= mDuration) {
- mAverageFPS = mCurrentFrame / elapsed_time;
- mRunning = false;
- }
-
- mRotation += mRotationSpeed * dt;
-
- mCurrentFrame++;
-}
-
-void SceneBuild::draw()
-{
- LibMatrix::Stack4 model_view;
-
- // Load the ModelViewProjectionMatrix uniform in the shader
- LibMatrix::mat4 model_view_proj(mScreen.mProjection);
-
- model_view.translate(0.0f, 0.0f, -2.5f);
- model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f);
- model_view_proj *= model_view.getCurrent();
-
- mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
-
- // Load the NormalMatrix uniform in the shader. The NormalMatrix is the
- // inverse transpose of the model view matrix.
- LibMatrix::mat4 normal_matrix(model_view.getCurrent());
- normal_matrix.inverse().transpose();
- mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix");
-
- if (mUseVbo) {
- mMesh.render_vbo(mVertexAttribLocation,
- mNormalAttribLocation,
- mTexcoordAttribLocation);
- }
- else {
- mMesh.render_array(mVertexAttribLocation,
- mNormalAttribLocation,
- mTexcoordAttribLocation);
- }
-}
-
-Scene::ValidationResult
-SceneBuild::validate()
-{
- static const double radius_3d(std::sqrt(3.0));
-
- if (mRotation != 0)
- return Scene::ValidationUnknown;
-
- Screen::Pixel ref(0xa7, 0xa7, 0xa7, 0xff);
- Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2,
- mScreen.mHeight / 2);
-
- double dist = pixel_value_distance(pixel, ref);
- if (dist < radius_3d + 0.01) {
- return Scene::ValidationSuccess;
- }
- else {
- Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n",
- ref.to_le32(), pixel.to_le32(), dist);
- return Scene::ValidationFailure;
- }
-}
=== removed file 'src/scenedefaultoptions.cpp'
@@ -1,47 +0,0 @@
-/*
- * Copyright © 2010-2011 Linaro Limited
- *
- * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
- *
- * glmark2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * glmark2. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Alexandros Frantzis (glmark2)
- */
-#include "scene.h"
-#include "benchmark.h"
-
-void SceneDefaultOptions::setup()
-{
- const std::map<std::string, Scene *> &scenes = Benchmark::scenes();
-
- for (std::list<std::pair<std::string, std::string> >::const_iterator iter = mDefaultOptions.begin();
- iter != mDefaultOptions.end();
- iter++)
- {
- for (std::map<std::string, Scene *>::const_iterator scene_iter = scenes.begin();
- scene_iter != scenes.end();
- scene_iter++)
- {
- scene_iter->second->set_option_default(iter->first, iter->second);
- }
- }
-}
-
-bool
-SceneDefaultOptions::set_option(const std::string &opt, const std::string &val)
-{
- mDefaultOptions.push_back(std::pair<std::string, std::string>(opt, val));
- return true;
-}
=== removed file 'src/sceneshading.cpp'
@@ -1,209 +0,0 @@
-/*
- * Copyright © 2008 Ben Smith
- * Copyright © 2010-2011 Linaro Limited
- *
- * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
- *
- * glmark2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * glmark2. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Ben Smith (original glmark benchmark)
- * Alexandros Frantzis (glmark2)
- */
-#include "scene.h"
-#include "mat.h"
-#include "stack.h"
-#include "vec.h"
-#include "log.h"
-
-#include <cmath>
-
-SceneShading::SceneShading(Screen &pScreen) :
- Scene(pScreen, "shading")
-{
- mOptions["shading"] = Scene::Option("shading", "gouraud",
- "[gouraud, phong]");
-}
-
-SceneShading::~SceneShading()
-{
-}
-
-int SceneShading::load()
-{
- Model model;
-
- if(!model.load_3ds(GLMARK_DATA_PATH"/models/cat.3ds"))
- return 0;
-
- model.calculate_normals();
- model.convert_to_mesh(&mMesh);
-
- mMesh.build_vbo();
-
- mRotationSpeed = 36.0f;
-
- mRunning = false;
-
- return 1;
-}
-
-void SceneShading::unload()
-{
- mMesh.reset();
-}
-
-void SceneShading::setup()
-{
- Scene::setup();
-
- static const LibMatrix::vec3 lightAmbient(0.1f, 0.1f, 0.1f);
- static const LibMatrix::vec3 lightDiffuse(0.8f, 0.8f, 0.8f);
- static const LibMatrix::vec3 lightSpecular(0.8f, 0.8f, 0.8f);
- static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
-
- static const LibMatrix::vec3 materialAmbient(1.0f, 1.0f, 1.0f);
- static const LibMatrix::vec3 materialDiffuse(1.0f, 1.0f, 1.0f);
- static const LibMatrix::vec3 materialSpecular(1.0f, 1.0f, 1.0f);
- static const LibMatrix::vec4 materialColor(0.0f, 0.0f, 1.0f, 1.0f);
-
- std::string vtx_shader_filename;
- std::string frg_shader_filename;
- const std::string &shading = mOptions["shading"].value;
-
- if (shading == "gouraud") {
- vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.vert";
- frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.frag";
- }
- else if (shading == "phong") {
- vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.vert";
- frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.frag";
- }
-
- if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename))
- return;
-
- mProgram.start();
-
- mVertexAttribLocation = mProgram.getAttribIndex("position");
- mNormalAttribLocation = mProgram.getAttribIndex("normal");
- mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord");
-
- // Load lighting and material uniforms
- mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient");
- mProgram.loadUniformVector(lightPosition, "LightSourcePosition");
- mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse");
- mProgram.loadUniformVector(lightSpecular, "LightSourceSpecular");
-
- mProgram.loadUniformVector(materialAmbient, "MaterialAmbient");
- mProgram.loadUniformVector(materialDiffuse, "MaterialDiffuse");
- mProgram.loadUniformVector(materialSpecular, "MaterialSpecular");
- mProgram.loadUniformVector(materialColor, "MaterialColor");
-
- // Calculate and load the half vector
- LibMatrix::vec3 halfVector(lightPosition[0], lightPosition[1], lightPosition[2]);
- halfVector.normalize();
- halfVector += LibMatrix::vec3(0.0, 0.0, 1.0);
- halfVector.normalize();
- mProgram.loadUniformVector(halfVector, "LightSourceHalfVector");
-
- mCurrentFrame = 0;
- mRotation = 0.0f;
- mRunning = true;
- mStartTime = SDL_GetTicks() / 1000.0;
- mLastUpdateTime = mStartTime;
-}
-
-void SceneShading::teardown()
-{
- mProgram.stop();
- mProgram.release();
-
- Scene::teardown();
-}
-
-void SceneShading::update()
-{
- double current_time = SDL_GetTicks() / 1000.0;
- double dt = current_time - mLastUpdateTime;
- double elapsed_time = current_time - mStartTime;
-
- mLastUpdateTime = current_time;
-
- if (elapsed_time >= mDuration) {
- mAverageFPS = mCurrentFrame / elapsed_time;
- mRunning = false;
- }
-
- mRotation += mRotationSpeed * dt;
-
- mCurrentFrame++;
-}
-
-void SceneShading::draw()
-{
- // Load the ModelViewProjectionMatrix uniform in the shader
- LibMatrix::Stack4 model_view;
- LibMatrix::mat4 model_view_proj(mScreen.mProjection);
-
- model_view.translate(0.0f, 0.0f, -5.0f);
- model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f);
- model_view_proj *= model_view.getCurrent();
-
- mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
-
- // Load the NormalMatrix uniform in the shader. The NormalMatrix is the
- // inverse transpose of the model view matrix.
- LibMatrix::mat4 normal_matrix(model_view.getCurrent());
- normal_matrix.inverse().transpose();
- mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix");
-
- mMesh.render_vbo(mVertexAttribLocation,
- mNormalAttribLocation,
- mTexcoordAttribLocation);
-}
-
-Scene::ValidationResult
-SceneShading::validate()
-{
- static const double radius_3d(std::sqrt(3.0));
-
- if (mRotation != 0)
- return Scene::ValidationUnknown;
-
- Screen::Pixel ref;
-
- Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2,
- mScreen.mHeight / 2);
-
- const std::string &filter = mOptions["shading"].value;
-
- if (filter == "gouraud")
- ref = Screen::Pixel(0x00, 0x00, 0xca, 0xff);
- else if (filter == "phong")
- ref = Screen::Pixel(0x1a, 0x1a, 0xbb, 0xff);
- else
- return Scene::ValidationUnknown;
-
- double dist = pixel_value_distance(pixel, ref);
-
- if (dist < radius_3d + 0.01) {
- return Scene::ValidationSuccess;
- }
- else {
- Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n",
- ref.to_le32(), pixel.to_le32(), dist);
- return Scene::ValidationFailure;
- }
-}
=== removed file 'src/scenetexture.cpp'
@@ -1,212 +0,0 @@
-/*
- * Copyright © 2008 Ben Smith
- * Copyright © 2010-2011 Linaro Limited
- *
- * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
- *
- * glmark2 is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * glmark2. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Ben Smith (original glmark benchmark)
- * Alexandros Frantzis (glmark2)
- */
-#include "scene.h"
-#include "mat.h"
-#include "stack.h"
-#include "vec.h"
-#include "log.h"
-
-#include "program.h"
-#include <cmath>
-
-SceneTexture::SceneTexture(Screen &pScreen) :
- Scene(pScreen, "texture")
-{
- mOptions["texture-filter"] = Scene::Option("texture-filter", "nearest",
- "[nearest, linear, mipmap]");
-}
-
-SceneTexture::~SceneTexture()
-{
-}
-
-int SceneTexture::load()
-{
- static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert");
- static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic-tex.frag");
- Model model;
-
- if(!model.load_3ds(GLMARK_DATA_PATH"/models/cube.3ds"))
- return 0;
-
- model.calculate_normals();
- model.convert_to_mesh(&mCubeMesh);
- mCubeMesh.build_vbo();
-
- if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename))
- return 0;
-
- mVertexAttribLocation = mProgram.getAttribIndex("position");
- mNormalAttribLocation = mProgram.getAttribIndex("normal");
- mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord");
-
- mRotationSpeed = LibMatrix::vec3(36.0f, 36.0f, 36.0f);
-
- mRunning = false;
-
- return 1;
-}
-
-void SceneTexture::unload()
-{
- mCubeMesh.reset();
-
- mProgram.stop();
- mProgram.release();
-}
-
-void SceneTexture::setup()
-{
- Scene::setup();
-
- static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f);
- static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f);
- static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
- static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f);
-
- // Create texture according to selected filtering
- GLint min_filter = GL_NONE;
- GLint mag_filter = GL_NONE;
- const std::string &filter = mOptions["texture-filter"].value;
-
- if (filter == "nearest") {
- min_filter = GL_NEAREST;
- mag_filter = GL_NEAREST;
- }
- else if (filter == "linear") {
- min_filter = GL_LINEAR;
- mag_filter = GL_LINEAR;
- }
- else if (filter == "mipmap") {
- min_filter = GL_LINEAR_MIPMAP_LINEAR;
- mag_filter = GL_LINEAR;
- }
-
- Texture::load(GLMARK_DATA_PATH"/textures/crate-base.bmp", &mTexture,
- min_filter, mag_filter, 0);
-
- mProgram.start();
-
- // Load lighting and material uniforms
- mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient");
- mProgram.loadUniformVector(lightPosition, "LightSourcePosition");
- mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse");
- mProgram.loadUniformVector(materialColor, "MaterialColor");
-
- mCurrentFrame = 0;
- mRotation = LibMatrix::vec3();
- mRunning = true;
- mStartTime = SDL_GetTicks() / 1000.0;
- mLastUpdateTime = mStartTime;
-}
-
-void SceneTexture::teardown()
-{
- mProgram.stop();
- glDeleteTextures(1, &mTexture);
-
- Scene::teardown();
-}
-
-void SceneTexture::update()
-{
- double current_time = SDL_GetTicks() / 1000.0;
- double dt = current_time - mLastUpdateTime;
- double elapsed_time = current_time - mStartTime;
-
- mLastUpdateTime = current_time;
-
- if (elapsed_time >= mDuration) {
- mAverageFPS = mCurrentFrame / elapsed_time;
- mRunning = false;
- }
-
- mRotation += mRotationSpeed * dt;
-
- mCurrentFrame++;
-}
-
-void SceneTexture::draw()
-{
- // Load the ModelViewProjectionMatrix uniform in the shader
- LibMatrix::Stack4 model_view;
- LibMatrix::mat4 model_view_proj(mScreen.mProjection);
-
- model_view.translate(0.0f, 0.0f, -5.0f);
- model_view.rotate(mRotation.x(), 1.0f, 0.0f, 0.0f);
- model_view.rotate(mRotation.y(), 0.0f, 1.0f, 0.0f);
- model_view.rotate(mRotation.z(), 0.0f, 0.0f, 1.0f);
- model_view_proj *= model_view.getCurrent();
-
- mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
-
- // Load the NormalMatrix uniform in the shader. The NormalMatrix is the
- // inverse transpose of the model view matrix.
- LibMatrix::mat4 normal_matrix(model_view.getCurrent());
- normal_matrix.inverse().transpose();
- mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix");
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, mTexture);
-
- mCubeMesh.render_vbo(mVertexAttribLocation,
- mNormalAttribLocation,
- mTexcoordAttribLocation);
-}
-
-Scene::ValidationResult
-SceneTexture::validate()
-{
- static const double radius_3d(std::sqrt(3.0));
-
- if (mRotation.x() != 0 || mRotation.y() != 0 || mRotation.z() != 0)
- return Scene::ValidationUnknown;
-
- Screen::Pixel ref;
-
- Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2,
- mScreen.mHeight / 2);
-
- const std::string &filter = mOptions["texture-filter"].value;
-
- if (filter == "nearest")
- ref = Screen::Pixel(0x3a, 0x3a, 0x3b, 0xff);
- else if (filter == "linear")
- ref = Screen::Pixel(0x34, 0x34, 0x35, 0xff);
- else if (filter == "mipmap")
- ref = Screen::Pixel(0x33, 0x33, 0x35, 0xff);
- else
- return Scene::ValidationUnknown;
-
- double dist = pixel_value_distance(pixel, ref);
-
- if (dist < radius_3d + 0.01) {
- return Scene::ValidationSuccess;
- }
- else {
- Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n",
- ref.to_le32(), pixel.to_le32(), dist);
- return Scene::ValidationFailure;
- }
-}