=== modified file 'src/android.cpp'
@@ -33,10 +33,12 @@
#include "util.h"
#include "main-loop.h"
#include "benchmark-collection.h"
+#include "scene-collection.h"
static Canvas *g_canvas;
static MainLoop *g_loop;
static BenchmarkCollection *g_benchmark_collection;
+static SceneCollection *g_scene_collection;
static std::ostream *g_log_extra;
class MainLoopAndroid : public MainLoop
@@ -251,36 +253,6 @@
DummyCanvas() : Canvas(0, 0) {}
};
-/**
- * Creates all the available scenes and adds them to the supplied vector.
- *
- * @param scenes the vector to add the scenes to
- * @param canvas the canvas to create the scenes with
- */
-static void
-create_and_add_scenes(std::vector<Scene*>& scenes, Canvas& canvas)
-{
- scenes.push_back(new SceneDefaultOptions(canvas));
- scenes.push_back(new SceneBuild(canvas));
- scenes.push_back(new SceneTexture(canvas));
- scenes.push_back(new SceneShading(canvas));
- scenes.push_back(new SceneConditionals(canvas));
- scenes.push_back(new SceneFunction(canvas));
- scenes.push_back(new SceneLoop(canvas));
- scenes.push_back(new SceneBump(canvas));
- scenes.push_back(new SceneEffect2D(canvas));
- scenes.push_back(new ScenePulsar(canvas));
- scenes.push_back(new SceneDesktop(canvas));
- scenes.push_back(new SceneBuffer(canvas));
- scenes.push_back(new SceneIdeas(canvas));
- scenes.push_back(new SceneTerrain(canvas));
- scenes.push_back(new SceneJellyfish(canvas));
- scenes.push_back(new SceneShadow(canvas));
- scenes.push_back(new SceneRefract(canvas));
- scenes.push_back(new SceneClear(canvas));
-}
-
-
void
Java_org_linaro_glmark2_native_init(JNIEnv* env, jclass clazz,
jobject asset_manager,
@@ -328,17 +300,9 @@
Log::info("glmark2 %s\n", GLMARK_VERSION);
g_canvas->print_info();
- std::vector<Scene*> scenes;
-
/* Add and register scenes */
- create_and_add_scenes(scenes, *g_canvas);
-
- for (std::vector<Scene*>::const_iterator iter = scenes.begin();
- iter != scenes.end();
- iter++)
- {
- Benchmark::register_scene(**iter);
- }
+ g_scene_collection = new SceneCollection(*g_canvas);
+ g_scene_collection->register_scenes();
g_benchmark_collection = new BenchmarkCollection();
g_benchmark_collection->populate_from_options();
@@ -373,6 +337,7 @@
delete g_loop;
delete g_benchmark_collection;
+ delete g_scene_collection;
delete g_canvas;
delete g_log_extra;
}
@@ -413,12 +378,11 @@
Util::android_set_asset_manager(AAssetManager_fromJava(env, asset_manager));
- std::vector<Scene*> scenes;
DummyCanvas canvas;
+ SceneCollection sc(canvas);
+ const std::vector<Scene*>& scenes = sc.get();
std::vector<jobject> si_vector;
- create_and_add_scenes(scenes, canvas);
-
/* Create SceneInfo instances for all the scenes */
for (std::vector<Scene*>::const_iterator iter = scenes.begin();
iter != scenes.end();
@@ -436,8 +400,6 @@
for (size_t i = 0; i < si_vector.size(); i++)
env->SetObjectArrayElement(si_array, i, si_vector[i]);
- Util::dispose_pointer_vector(scenes);
-
return si_array;
}
=== modified file 'src/main.cpp'
@@ -31,6 +31,7 @@
#include "text-renderer.h"
#include "main-loop.h"
#include "benchmark-collection.h"
+#include "scene-collection.h"
#include <iostream>
#include <fstream>
@@ -215,10 +216,9 @@
canvas.visual_config(Options::visual_config);
- vector<Scene*> scenes;
-
// Register the scenes, so they can be looked up by name
- add_and_register_scenes(scenes, canvas);
+ SceneCollection scenes(canvas);
+ scenes.register_scenes();
if (Options::list_scenes) {
list_scenes();
@@ -243,7 +243,5 @@
else
do_benchmark(canvas);
- Util::dispose_pointer_vector(scenes);
-
return 0;
}
=== added file 'src/scene-collection.h'
@@ -0,0 +1,81 @@
+//
+// Copyright Š 2013 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:
+// Jesse Barker
+// Alexandros Frantzis
+//
+#ifndef GLMARK2_SCENE_COLLECTION_H_
+#define GLMARK2_SCENE_COLLECTION_H_
+
+#include <vector>
+#include "scene.h"
+
+
+class SceneCollection
+{
+public:
+ SceneCollection(Canvas& canvas)
+ {
+ add_scenes(canvas);
+ }
+ ~SceneCollection() { Util::dispose_pointer_vector(scenes_); }
+ void register_scenes()
+ {
+ for (std::vector<Scene*>::const_iterator iter = scenes_.begin();
+ iter != scenes_.end();
+ iter++)
+ {
+ Benchmark::register_scene(**iter);
+ }
+ }
+ const std::vector<Scene*>& get() { return scenes_; }
+
+private:
+ std::vector<Scene*> scenes_;
+
+ //
+ // Creates all the available scenes and adds them to the supplied vector.
+ //
+ // @param scenes the vector to add the scenes to
+ // @param canvas the canvas to create the scenes with
+ //
+ void add_scenes(Canvas& canvas)
+ {
+ scenes_.push_back(new SceneDefaultOptions(canvas));
+ scenes_.push_back(new SceneBuild(canvas));
+ scenes_.push_back(new SceneTexture(canvas));
+ scenes_.push_back(new SceneShading(canvas));
+ scenes_.push_back(new SceneConditionals(canvas));
+ scenes_.push_back(new SceneFunction(canvas));
+ scenes_.push_back(new SceneLoop(canvas));
+ scenes_.push_back(new SceneBump(canvas));
+ scenes_.push_back(new SceneEffect2D(canvas));
+ scenes_.push_back(new ScenePulsar(canvas));
+ scenes_.push_back(new SceneDesktop(canvas));
+ scenes_.push_back(new SceneBuffer(canvas));
+ scenes_.push_back(new SceneIdeas(canvas));
+ scenes_.push_back(new SceneTerrain(canvas));
+ scenes_.push_back(new SceneJellyfish(canvas));
+ scenes_.push_back(new SceneShadow(canvas));
+ scenes_.push_back(new SceneRefract(canvas));
+ scenes_.push_back(new SceneClear(canvas));
+
+ }
+};
+#endif // GLMARK2_SCENE_COLLECTION_H_