aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandros Frantzis <alexandros.frantzis@linaro.org>2012-08-16 19:01:59 +0300
committerAlexandros Frantzis <alexandros.frantzis@linaro.org>2012-08-16 19:01:59 +0300
commite56e75718d1108490e11d1ba68e1a5e785ae9e4c (patch)
tree264815bdd1dd51819f82717287990e9fb7d043bf
parentab5e6cfeb163f03023707a26312a6c3f2b5e5f7e (diff)
parentf50d60daac20ae553ac276e81ef8dc2e69f3ecdb (diff)
downloadglmark2-e56e75718d1108490e11d1ba68e1a5e785ae9e4c.tar.gz
Scene*: Add ::supported() and change ::setup() to return bool.
-rw-r--r--src/scene-buffer.cpp33
-rw-r--r--src/scene-build.cpp11
-rw-r--r--src/scene-bump.cpp73
-rw-r--r--src/scene-conditionals.cpp9
-rw-r--r--src/scene-default-options.cpp4
-rw-r--r--src/scene-desktop.cpp7
-rw-r--r--src/scene-effect-2d.cpp13
-rw-r--r--src/scene-function.cpp9
-rw-r--r--src/scene-grid.cpp7
-rw-r--r--src/scene-ideas.cpp12
-rw-r--r--src/scene-jellyfish.cpp56
-rw-r--r--src/scene-jellyfish.h4
-rw-r--r--src/scene-loop.cpp9
-rw-r--r--src/scene-pulsar.cpp13
-rw-r--r--src/scene-shading.cpp11
-rw-r--r--src/scene-terrain.cpp35
-rw-r--r--src/scene-texture.cpp15
-rw-r--r--src/scene.cpp15
-rw-r--r--src/scene.h58
19 files changed, 258 insertions, 136 deletions
diff --git a/src/scene-buffer.cpp b/src/scene-buffer.cpp
index 5cf11a6..ef3a0b9 100644
--- a/src/scene-buffer.cpp
+++ b/src/scene-buffer.cpp
@@ -327,6 +327,22 @@ SceneBuffer::~SceneBuffer()
}
bool
+SceneBuffer::supported(bool show_errors)
+{
+ if (options_["update-method"].value != "subdata" &&
+ (GLExtensions::MapBuffer == 0 || GLExtensions::UnmapBuffer == 0))
+ {
+ if (show_errors) {
+ Log::error("Requested MapBuffer VBO update method but GL_OES_mapbuffer"
+ " is not supported!\n");
+ }
+ return false;
+ }
+
+ return true;
+}
+
+bool
SceneBuffer::load()
{
running_ = false;
@@ -339,14 +355,14 @@ SceneBuffer::unload()
{
}
-void
+bool
SceneBuffer::setup()
{
using LibMatrix::vec3;
- Scene::setup();
+ if (!Scene::setup())
+ return false;
- bool should_run = true;
bool interleave = (options_["interleave"].value == "true");
Mesh::VBOUpdateMethod update_method;
Mesh::VBOUsage usage;
@@ -374,13 +390,6 @@ SceneBuffer::setup()
nlength = Util::fromString<size_t>(options_["columns"].value);
nwidth = Util::fromString<size_t>(options_["rows"].value);
- if (update_method == Mesh::VBOUpdateMethodMap &&
- (GLExtensions::MapBuffer == 0 || GLExtensions::UnmapBuffer == 0))
- {
- Log::error("Requested MapBuffer VBO update method but GL_OES_mapbuffer"
- " is not supported!\n");
- should_run = false;
- }
priv_->wave = new WaveMesh(5.0, 2.0, nlength, nwidth,
update_fraction * (1.0 - update_dispersion + 0.0001),
@@ -397,9 +406,11 @@ SceneBuffer::setup()
glDisable(GL_CULL_FACE);
currentFrame_ = 0;
- running_ = should_run;
+ running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-build.cpp b/src/scene-build.cpp
index 39a5ae5..22c948a 100644
--- a/src/scene-build.cpp
+++ b/src/scene-build.cpp
@@ -80,12 +80,13 @@ SceneBuild::unload()
mesh_.reset();
}
-void
+bool
SceneBuild::setup()
{
using LibMatrix::vec3;
- Scene::setup();
+ if (!Scene::setup())
+ return false;
/* Set up shaders */
static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert");
@@ -102,7 +103,7 @@ SceneBuild::setup()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
Model model;
@@ -110,7 +111,7 @@ SceneBuild::setup()
bool modelLoaded = model.load(whichModel);
if(!modelLoaded)
- return;
+ return false;
// Now that we're successfully loaded, there are a few quirks about
// some of the known models that we need to account for. The draw
@@ -187,6 +188,8 @@ SceneBuild::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-bump.cpp b/src/scene-bump.cpp
index 6512684..2b6c01f 100644
--- a/src/scene-bump.cpp
+++ b/src/scene-bump.cpp
@@ -58,7 +58,7 @@ SceneBump::unload()
{
}
-void
+bool
SceneBump::setup_model_plain(const std::string &type)
{
static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/bump-poly.vert");
@@ -78,7 +78,7 @@ SceneBump::setup_model_plain(const std::string &type)
high_poly_filename : low_poly_filename;
if(!model.load(poly_filename))
- return;
+ return false;
model.calculate_normals();
@@ -100,16 +100,18 @@ SceneBump::setup_model_plain(const std::string &type)
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
std::vector<GLint> attrib_locations;
attrib_locations.push_back(program_["position"].location());
attrib_locations.push_back(program_["normal"].location());
mesh_.set_attrib_locations(attrib_locations);
+
+ return true;
}
-void
+bool
SceneBump::setup_model_normals()
{
static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/bump-normals.vert");
@@ -118,7 +120,7 @@ SceneBump::setup_model_normals()
Model model;
if(!model.load("asteroid-low"))
- return;
+ return false;
/* Calculate the half vector */
LibMatrix::vec3 halfVector(lightPosition.x(), lightPosition.y(), lightPosition.z());
@@ -147,7 +149,7 @@ SceneBump::setup_model_normals()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
std::vector<GLint> attrib_locations;
@@ -155,11 +157,16 @@ SceneBump::setup_model_normals()
attrib_locations.push_back(program_["texcoord"].location());
mesh_.set_attrib_locations(attrib_locations);
- Texture::load("asteroid-normal-map", &texture_,
- GL_NEAREST, GL_NEAREST, 0);
+ if (!Texture::load("asteroid-normal-map", &texture_,
+ GL_NEAREST, GL_NEAREST, 0))
+ {
+ return false;
+ }
+
+ return true;
}
-void
+bool
SceneBump::setup_model_normals_tangent()
{
static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/bump-normals-tangent.vert");
@@ -168,7 +175,7 @@ SceneBump::setup_model_normals_tangent()
Model model;
if(!model.load("asteroid-low"))
- return;
+ return false;
model.calculate_normals();
@@ -197,7 +204,7 @@ SceneBump::setup_model_normals_tangent()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
std::vector<GLint> attrib_locations;
@@ -207,11 +214,16 @@ SceneBump::setup_model_normals_tangent()
attrib_locations.push_back(program_["tangent"].location());
mesh_.set_attrib_locations(attrib_locations);
- Texture::load("asteroid-normal-map-tangent", &texture_,
- GL_NEAREST, GL_NEAREST, 0);
+ if (!Texture::load("asteroid-normal-map-tangent", &texture_,
+ GL_NEAREST, GL_NEAREST, 0))
+ {
+ return false;
+ }
+
+ return true;
}
-void
+bool
SceneBump::setup_model_height()
{
static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/bump-height.vert");
@@ -220,7 +232,7 @@ SceneBump::setup_model_height()
Model model;
if(!model.load("asteroid-low"))
- return;
+ return false;
model.calculate_normals();
@@ -251,7 +263,7 @@ SceneBump::setup_model_height()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
std::vector<GLint> attrib_locations;
@@ -261,27 +273,38 @@ SceneBump::setup_model_height()
attrib_locations.push_back(program_["tangent"].location());
mesh_.set_attrib_locations(attrib_locations);
- Texture::load("asteroid-height-map", &texture_,
- GL_NEAREST, GL_NEAREST, 0);
+ if (!Texture::load("asteroid-height-map", &texture_,
+ GL_NEAREST, GL_NEAREST, 0))
+ {
+ return false;
+ }
+
+ return true;
}
-void
+bool
SceneBump::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
const std::string &bump_render = options_["bump-render"].value;
Texture::find_textures();
Model::find_models();
+
+ bool setup_succeeded = false;
+
if (bump_render == "normals")
- setup_model_normals();
+ setup_succeeded = setup_model_normals();
else if (bump_render == "normals-tangent")
- setup_model_normals_tangent();
+ setup_succeeded = setup_model_normals_tangent();
else if (bump_render == "height")
- setup_model_height();
+ setup_succeeded = setup_model_height();
else if (bump_render == "off" || bump_render == "high-poly")
- setup_model_plain(bump_render);
+ setup_succeeded = setup_model_plain(bump_render);
+ if (!setup_succeeded)
+ return false;
mesh_.build_vbo();
@@ -296,6 +319,8 @@ SceneBump::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-conditionals.cpp b/src/scene-conditionals.cpp
index 61367a8..778cb33 100644
--- a/src/scene-conditionals.cpp
+++ b/src/scene-conditionals.cpp
@@ -89,10 +89,11 @@ get_fragment_shader_source(int steps, bool conditionals)
return source.str();
}
-void
+bool
SceneConditionals::setup()
{
- SceneGrid::setup();
+ if (!SceneGrid::setup())
+ return false;
/* Parse options */
bool vtx_conditionals = options_["vertex-conditionals"].value == "true";
@@ -104,7 +105,7 @@ SceneConditionals::setup()
std::string frg_shader(get_fragment_shader_source(frg_steps, frg_conditionals));
if (!Scene::load_shaders_from_strings(program_, vtx_shader, frg_shader))
- return;
+ return false;
program_.start();
@@ -115,6 +116,8 @@ SceneConditionals::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
Scene::ValidationResult
diff --git a/src/scene-default-options.cpp b/src/scene-default-options.cpp
index 78a7ac5..0cc8c89 100644
--- a/src/scene-default-options.cpp
+++ b/src/scene-default-options.cpp
@@ -23,7 +23,7 @@
#include "benchmark.h"
#include "log.h"
-void
+bool
SceneDefaultOptions::setup()
{
const std::map<std::string, Scene *> &scenes = Benchmark::scenes();
@@ -50,6 +50,8 @@ SceneDefaultOptions::setup()
}
}
}
+
+ return true;
}
bool
diff --git a/src/scene-desktop.cpp b/src/scene-desktop.cpp
index 64e7550..b1431f8 100644
--- a/src/scene-desktop.cpp
+++ b/src/scene-desktop.cpp
@@ -792,10 +792,11 @@ SceneDesktop::unload()
{
}
-void
+bool
SceneDesktop::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
/* Parse the options */
unsigned int windows(0);
@@ -868,6 +869,8 @@ SceneDesktop::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-effect-2d.cpp b/src/scene-effect-2d.cpp
index 27275dc..9185d7b 100644
--- a/src/scene-effect-2d.cpp
+++ b/src/scene-effect-2d.cpp
@@ -295,10 +295,11 @@ SceneEffect2D::unload()
glDeleteTextures(1, &texture_);
}
-void
+bool
SceneEffect2D::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
Texture::find_textures();
@@ -312,7 +313,7 @@ SceneEffect2D::setup()
if (!parse_matrix(options_["kernel"].value, kernel,
kernel_width, kernel_height))
{
- return;
+ return false;
}
/* Normalize the kernel matrix if needed */
@@ -330,12 +331,12 @@ SceneEffect2D::setup()
kernel_height));
if (frg_source.str().empty())
- return;
+ return false;
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
std::vector<int> vertex_format;
@@ -358,6 +359,8 @@ SceneEffect2D::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-function.cpp b/src/scene-function.cpp
index 58412be..0bd9468 100644
--- a/src/scene-function.cpp
+++ b/src/scene-function.cpp
@@ -116,10 +116,11 @@ get_fragment_shader_source(int steps, bool function, std::string &complexity)
return source.str();
}
-void
+bool
SceneFunction::setup()
{
- SceneGrid::setup();
+ if (!SceneGrid::setup())
+ return false;
/* Parse options */
bool vtx_function = options_["vertex-function"].value == "true";
@@ -136,7 +137,7 @@ SceneFunction::setup()
frg_complexity));
if (!Scene::load_shaders_from_strings(program_, vtx_shader, frg_shader))
- return;
+ return false;
program_.start();
@@ -147,6 +148,8 @@ SceneFunction::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
Scene::ValidationResult
diff --git a/src/scene-grid.cpp b/src/scene-grid.cpp
index a7cc105..a9d07e0 100644
--- a/src/scene-grid.cpp
+++ b/src/scene-grid.cpp
@@ -53,10 +53,11 @@ SceneGrid::unload()
{
}
-void
+bool
SceneGrid::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
int grid_size(Util::fromString<int>(options_["grid-size"].value));
double grid_length(Util::fromString<double>(options_["grid-length"].value));
@@ -78,6 +79,8 @@ SceneGrid::setup()
currentFrame_ = 0;
rotation_ = 0.0f;
+
+ return true;
}
void
diff --git a/src/scene-ideas.cpp b/src/scene-ideas.cpp
index 91eb34e..af716bd 100644
--- a/src/scene-ideas.cpp
+++ b/src/scene-ideas.cpp
@@ -58,6 +58,7 @@ public:
void update_time();
void update_projection(const mat4& proj);
void draw();
+ bool valid() { return valid_; }
private:
void postIdle();
@@ -223,12 +224,17 @@ SceneIdeas::unload()
{
}
-void
+bool
SceneIdeas::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
+
priv_ = new SceneIdeasPrivate();
priv_->initialize(options_);
+ if (!priv_->valid())
+ return false;
+
priv_->update_projection(canvas_.projection());
// Core Scene state
@@ -236,6 +242,8 @@ SceneIdeas::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-jellyfish.cpp b/src/scene-jellyfish.cpp
index 5253dd9..bc18ee3 100644
--- a/src/scene-jellyfish.cpp
+++ b/src/scene-jellyfish.cpp
@@ -54,20 +54,24 @@ SceneJellyfish::unload()
{
}
-void
+bool
SceneJellyfish::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
// Set up our private object that does all of the lifting
priv_ = new JellyfishPrivate();
- priv_->initialize();
+ if (!priv_->initialize())
+ return false;
// Set core scene timing after actual initialization so we don't measure
// set up time.
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
running_ = true;
+
+ return true;
}
void
@@ -107,7 +111,7 @@ using LibMatrix::vec2;
using std::string;
using std::vector;
-void
+bool
GradientRenderer::init()
{
// Program set up
@@ -118,7 +122,7 @@ GradientRenderer::init()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
positionLocation_ = program_["position"].location();
uvLocation_ = program_["uvIn"].location();
@@ -144,6 +148,8 @@ GradientRenderer::init()
glBufferSubData(GL_ARRAY_BUFFER, uvOffset_, uvs_.size() * sizeof(vec2),
&uvs_.front());
glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ return true;
}
void
@@ -355,10 +361,24 @@ JellyfishPrivate::JellyfishPrivate() :
blendFuncSrc_(0),
blendFuncDst_(0)
{
+}
+
+JellyfishPrivate::~JellyfishPrivate()
+{
+ positions_.clear();
+ normals_.clear();
+ colors_.clear();
+ texcoords_.clear();
+ indices_.clear();
+}
+
+bool
+JellyfishPrivate::initialize()
+{
static const string modelFilename(GLMARK_DATA_PATH"/models/jellyfish.jobj");
if (!load_obj(modelFilename))
{
- return;
+ return false;
}
// Now that we've setup the vertex data, we can setup the map of how
@@ -376,26 +396,16 @@ JellyfishPrivate::JellyfishPrivate() :
dataMap_.texcoordOffset = dataMap_.colorOffset + dataMap_.colorSize;
dataMap_.texcoordSize = texcoords_.size() * sv3;
dataMap_.totalSize += dataMap_.texcoordSize;
-}
-
-JellyfishPrivate::~JellyfishPrivate()
-{
- positions_.clear();
- normals_.clear();
- colors_.clear();
- texcoords_.clear();
- indices_.clear();
-}
-void
-JellyfishPrivate::initialize()
-{
lastUpdateTime_ = Util::get_timestamp_us() / 1000.0;
currentTime_ = static_cast<uint64_t>(lastUpdateTime_) % 100000000 / 1000.0;
whichCaustic_ = static_cast<uint64_t>(currentTime_ * 30) % 32 + 1;
rotation_ = 0.0;
- gradient_.init();
+ if (!gradient_.init())
+ {
+ return false;
+ }
// Set up program first so we can store attribute and uniform locations
// away for the
@@ -409,7 +419,7 @@ JellyfishPrivate::initialize()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
// Stash away attribute and uniform locations for handy use.
@@ -452,6 +462,7 @@ JellyfishPrivate::initialize()
if (!gotTex || textureObjects_[0] == 0)
{
Log::error("Jellyfish texture set up failed!!!\n");
+ return false;
}
glBindTexture(GL_TEXTURE_2D, 0);
// Then, the caustics textures
@@ -467,6 +478,7 @@ JellyfishPrivate::initialize()
if (!gotTex || textureObjects_[i] == 0)
{
Log::error("Caustics texture[%u] set up failed!!!\n", i);
+ return false;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -484,6 +496,8 @@ JellyfishPrivate::initialize()
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
+
+ return true;
}
void
diff --git a/src/scene-jellyfish.h b/src/scene-jellyfish.h
index 77be159..1e0db3a 100644
--- a/src/scene-jellyfish.h
+++ b/src/scene-jellyfish.h
@@ -48,7 +48,7 @@ public:
vertices_.clear();
uvs_.clear();
}
- void init();
+ bool init();
void cleanup();
void draw();
};
@@ -114,7 +114,7 @@ class JellyfishPrivate
public:
JellyfishPrivate();
~JellyfishPrivate();
- void initialize();
+ bool initialize();
void update_viewport(const LibMatrix::vec2& viewport);
void update_time();
void cleanup();
diff --git a/src/scene-loop.cpp b/src/scene-loop.cpp
index 5e3f095..564a2fe 100644
--- a/src/scene-loop.cpp
+++ b/src/scene-loop.cpp
@@ -110,10 +110,11 @@ get_vertex_shader_source(int steps, bool loop, bool uniform)
}
-void
+bool
SceneLoop::setup()
{
- SceneGrid::setup();
+ if (!SceneGrid::setup())
+ return false;
/* Parse options */
bool vtx_loop = options_["vertex-loop"].value == "true";
@@ -130,7 +131,7 @@ SceneLoop::setup()
frg_uniform));
if (!Scene::load_shaders_from_strings(program_, vtx_shader, frg_shader))
- return;
+ return false;
program_.start();
@@ -144,6 +145,8 @@ SceneLoop::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
Scene::ValidationResult
diff --git a/src/scene-pulsar.cpp b/src/scene-pulsar.cpp
index 7d10dbd..6ab661c 100644
--- a/src/scene-pulsar.cpp
+++ b/src/scene-pulsar.cpp
@@ -73,10 +73,11 @@ ScenePulsar::unload()
{
}
-void
+bool
ScenePulsar::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
// Disable back-face culling
glDisable(GL_CULL_FACE);
@@ -119,8 +120,8 @@ ScenePulsar::setup()
if (options_["texture"].value == "true") {
frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic-tex.frag";
Texture::find_textures();
- Texture::load("crate-base", &texture_,
- GL_NEAREST, GL_NEAREST, 0);
+ if (!Texture::load("crate-base", &texture_, GL_NEAREST, GL_NEAREST, 0))
+ return false;
} else {
frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.frag";
@@ -136,7 +137,7 @@ ScenePulsar::setup()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
create_and_setup_mesh();
@@ -148,6 +149,8 @@ ScenePulsar::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-shading.cpp b/src/scene-shading.cpp
index e760209..22b5ad5 100644
--- a/src/scene-shading.cpp
+++ b/src/scene-shading.cpp
@@ -132,10 +132,11 @@ get_fragment_shader_source(const string& frg_file, unsigned int lights)
return source.str();
}
-void
+bool
SceneShading::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f);
static const LibMatrix::vec4 materialDiffuse(0.0f, 0.0f, 1.0f, 1.0f);
@@ -181,7 +182,7 @@ SceneShading::setup()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
Model model;
@@ -189,7 +190,7 @@ SceneShading::setup()
bool modelLoaded = model.load(whichModel);
if(!modelLoaded)
- return;
+ return false;
// Now that we're successfully loaded, there are a few quirks about
// some of the known models that we need to account for. The draw
@@ -257,6 +258,8 @@ SceneShading::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene-terrain.cpp b/src/scene-terrain.cpp
index 9b5bd22..bf8e18b 100644
--- a/src/scene-terrain.cpp
+++ b/src/scene-terrain.cpp
@@ -231,6 +231,21 @@ SceneTerrain::~SceneTerrain()
}
bool
+SceneTerrain::supported(bool show_errors)
+{
+ GLint vertex_textures;
+ glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &vertex_textures);
+
+ if (show_errors && vertex_textures <= 0) {
+ Log::error("SceneTerrain requires Vertex Texture Fetch support, "
+ "but GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS is %d\n",
+ vertex_textures);
+ }
+
+ return vertex_textures > 0;
+}
+
+bool
SceneTerrain::load()
{
Scene::load();
@@ -246,23 +261,11 @@ SceneTerrain::unload()
Scene::unload();
}
-void
+bool
SceneTerrain::setup()
{
- Scene::setup();
-
- /* Ensure implementation supports vertex texture fetch */
- GLint vertex_textures;
- glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &vertex_textures);
- if (vertex_textures <= 0) {
- Log::error("SceneTerrain requires Vertex Texture Fetch support, "
- "but GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS is %d\n",
- vertex_textures);
- currentFrame_ = 0;
- startTime_ = Util::get_timestamp_us() / 1000000.0;
- running_ = false;
- return;
- }
+ if (!Scene::setup())
+ return false;
/* Parse options */
float repeat = Util::fromString<double>(options_["repeat-overlay"].value);
@@ -313,6 +316,8 @@ SceneTerrain::setup()
currentFrame_ = 0;
startTime_ = Util::get_timestamp_us() / 1000000.0;
running_ = true;
+
+ return true;
}
void
diff --git a/src/scene-texture.cpp b/src/scene-texture.cpp
index 62bd6eb..12aec1b 100644
--- a/src/scene-texture.cpp
+++ b/src/scene-texture.cpp
@@ -103,10 +103,11 @@ SceneTexture::unload()
mesh_.reset();
}
-void
+bool
SceneTexture::setup()
{
- Scene::setup();
+ if (!Scene::setup())
+ return false;
static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert");
static const std::string vtx_shader_texgen_filename(GLMARK_DATA_PATH"/shaders/light-basic-texgen.vert");
@@ -138,8 +139,8 @@ SceneTexture::setup()
}
const string& whichTexture(options_["texture"].value);
- Texture::load(whichTexture, &texture_,
- min_filter, mag_filter, 0);
+ if (!Texture::load(whichTexture, &texture_, min_filter, mag_filter, 0))
+ return false;
// Load shaders
bool doTexGen(options_["texgen"].value == "true");
@@ -168,14 +169,14 @@ SceneTexture::setup()
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(),
frg_source.str()))
{
- return;
+ return false;
}
Model model;
const string& whichModel(options_["model"].value);
bool modelLoaded = model.load(whichModel);
if(!modelLoaded)
- return;
+ return false;
// Now that we're successfully loaded, there are a few quirks about
// some of the known models that we need to account for. The draw
@@ -251,6 +252,8 @@ SceneTexture::setup()
running_ = true;
startTime_ = Util::get_timestamp_us() / 1000000.0;
lastUpdateTime_ = startTime_;
+
+ return true;
}
void
diff --git a/src/scene.cpp b/src/scene.cpp
index be6dd9a..975537d 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -76,6 +76,13 @@ Scene::~Scene()
}
bool
+Scene::supported(bool show_errors)
+{
+ static_cast<void>(show_errors);
+ return true;
+}
+
+bool
Scene::load()
{
return true;
@@ -86,7 +93,7 @@ Scene::unload()
{
}
-void
+bool
Scene::setup()
{
duration_ = Util::fromString<double>(options_["duration"].value);
@@ -101,6 +108,12 @@ Scene::setup()
ShaderSource::ShaderTypeFragment
);
+ currentFrame_ = 0;
+ running_ = false;
+ startTime_ = Util::get_timestamp_us() / 1000000.0;
+ lastUpdateTime_ = startTime_;
+
+ return supported(true);
}
void
diff --git a/src/scene.h b/src/scene.h
index c52239a..a455fbd 100644
--- a/src/scene.h
+++ b/src/scene.h
@@ -74,6 +74,15 @@ public:
};
/**
+ * Checks whether this scene (in its current configuration) is supported.
+ *
+ * @param show_errors whether to log errors about unsupported features
+ *
+ * @return whether the scene is supported
+ */
+ virtual bool supported(bool show_errors);
+
+ /**
* Performs option-independent resource loading and configuration.
*
* It should be safe to call ::load() (and the corresponding ::unload())
@@ -95,9 +104,12 @@ public:
* This method also prepares a scene for a benchmark run.
* It should be called just before running a scene/benchmark.
*
- * @return the operation status
+ * The base Scene::setup() method also checks whether a scene
+ * configuration is supported by calling ::supported(true).
+ *
+ * @return whether setting the scene up succeeded
*/
- virtual void setup();
+ virtual bool setup();
/**
* Performs option-dependent resource unloading.
@@ -232,7 +244,7 @@ class SceneDefaultOptions : public Scene
public:
SceneDefaultOptions(Canvas &pCanvas) : Scene(pCanvas, "") {}
bool set_option(const std::string &opt, const std::string &val);
- void setup();
+ bool setup();
private:
std::list<std::pair<std::string, std::string> > defaultOptions_;
@@ -244,7 +256,7 @@ public:
SceneBuild(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -272,7 +284,7 @@ public:
SceneTexture(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -300,7 +312,7 @@ public:
SceneShading(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -327,7 +339,7 @@ public:
SceneGrid(Canvas &pCanvas, const std::string &name);
virtual bool load();
virtual void unload();
- virtual void setup();
+ virtual bool setup();
virtual void teardown();
virtual void update();
virtual void draw();
@@ -346,7 +358,7 @@ class SceneConditionals : public SceneGrid
{
public:
SceneConditionals(Canvas &pCanvas);
- void setup();
+ bool setup();
ValidationResult validate();
~SceneConditionals();
@@ -356,7 +368,7 @@ class SceneFunction : public SceneGrid
{
public:
SceneFunction(Canvas &pCanvas);
- void setup();
+ bool setup();
ValidationResult validate();
~SceneFunction();
@@ -366,7 +378,7 @@ class SceneLoop : public SceneGrid
{
public:
SceneLoop(Canvas &pCanvas);
- void setup();
+ bool setup();
ValidationResult validate();
~SceneLoop();
@@ -378,7 +390,7 @@ public:
SceneBump(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -393,10 +405,10 @@ protected:
float rotation_;
float rotationSpeed_;
private:
- void setup_model_plain(const std::string &type);
- void setup_model_normals();
- void setup_model_normals_tangent();
- void setup_model_height();
+ bool setup_model_plain(const std::string &type);
+ bool setup_model_normals();
+ bool setup_model_normals_tangent();
+ bool setup_model_height();
};
class SceneEffect2D : public Scene
@@ -405,7 +417,7 @@ public:
SceneEffect2D(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -426,7 +438,7 @@ public:
ScenePulsar(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -455,7 +467,7 @@ public:
SceneDesktop(Canvas &canvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -473,9 +485,10 @@ class SceneBuffer : public Scene
{
public:
SceneBuffer(Canvas &canvas);
+ bool supported(bool show_errors);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -495,7 +508,7 @@ public:
SceneIdeas(Canvas &pCanvas);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -513,9 +526,10 @@ class SceneTerrain : public Scene
{
public:
SceneTerrain(Canvas &pCanvas);
+ bool supported(bool show_errors);
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();
@@ -536,7 +550,7 @@ public:
~SceneJellyfish();
bool load();
void unload();
- void setup();
+ bool setup();
void teardown();
void update();
void draw();