summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-08 17:51:10 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-08 17:51:10 +0000
commitb749d0c61b0d33324b4f2f0a127f7a2571d9082f (patch)
tree0e4e43a05ea5a9accb3c284e4c0eec6201af96ae /tests
parentfaf9740f37e68cae0822bb196a6c3a163a7e364e (diff)
downloaddimension-b749d0c61b0d33324b4f2f0a127f7a2571d9082f.tar.xz
Don't animate in GL tests - turns out it's hellishly slow on slower
computers.
Diffstat (limited to 'tests')
-rw-r--r--tests/gl.c98
-rw-r--r--tests/glxx.cpp61
-rw-r--r--tests/tests.c2
-rw-r--r--tests/tests.h3
-rw-r--r--tests/testsxx.cpp2
5 files changed, 87 insertions, 79 deletions
diff --git a/tests/gl.c b/tests/gl.c
index 294e4cb..e6daa3e 100644
--- a/tests/gl.c
+++ b/tests/gl.c
@@ -26,9 +26,7 @@ main() {
dmnsn_display *display;
dmnsn_progress *progress;
dmnsn_scene *scene;
- dmnsn_object *cube;
- dmnsn_matrix trans;
- const unsigned int frames = 10;
+ dmnsn_canvas *canvas;
unsigned int i;
/* Set the resilience low for tests */
@@ -48,12 +46,6 @@ main() {
return EXIT_FAILURE;
}
- /* Get the cube object */
- dmnsn_array_get(scene->objects, 1, &cube);
-
- /* Get the camera transformation matrix */
- trans = dmnsn_get_perspective_camera_trans(scene->camera);
-
/* Create a new glX display */
display = dmnsn_new_display(scene->canvas);
if (!display) {
@@ -62,53 +54,69 @@ main() {
return EXIT_FAILURE;
}
- /* Render the animation */
- for (i = 0; i < frames; ++i) {
- /* Render the scene */
+ /* Render the scene */
+
+ progress = dmnsn_raytrace_scene_async(scene);
+ if (!progress) {
+ dmnsn_delete_display(display);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Couldn't start raytracing worker thread! ---\n");
+ return EXIT_FAILURE;
+ }
- progress = dmnsn_raytrace_scene_async(scene);
- if (!progress) {
+ /* Display the scene as it's rendered */
+ while (dmnsn_get_progress(progress) < 1.0) {
+ if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
dmnsn_delete_display(display);
dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Couldn't start raytracing worker thread! ---\n");
+ fprintf(stderr, "--- Drawing to openGL failed! ---\n");
return EXIT_FAILURE;
}
+ dmnsn_display_flush(display);
+ }
- progressbar("Raytracing scene: ", progress);
+ if (dmnsn_finish_progress(progress) != 0) {
+ dmnsn_delete_display(display);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Raytracing failed! ---\n");
+ return EXIT_FAILURE;
+ }
- if (dmnsn_finish_progress(progress) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Raytracing failed! ---\n");
- return EXIT_FAILURE;
- }
+ /* Make sure we show the completed rendering */
+ if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
+ dmnsn_delete_display(display);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Drawing to openGL failed! ---\n");
+ return EXIT_FAILURE;
+ }
+ dmnsn_display_flush(display);
- /* Display the scene */
+ /* Show the image on screen for a bit */
+ sleep(1);
- if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Drawing to openGL failed! ---\n");
- return EXIT_FAILURE;
- }
- dmnsn_display_frame(display);
-
- /* Rotate the cube and camera for the next frame */
-
- cube->trans = dmnsn_matrix_mul(
- dmnsn_matrix_inverse(
- dmnsn_rotation_matrix(dmnsn_vector_construct(0.025, 0.0, 0.0))
- ),
- cube->trans
- );
-
- trans = dmnsn_matrix_mul(
- dmnsn_rotation_matrix(dmnsn_vector_construct(0.0, -0.05, 0.0)),
- trans
- );
- dmnsn_set_perspective_camera_trans(scene->camera, trans);
+ /* Read a canvas from the GL buffer */
+ canvas = dmnsn_gl_read_canvas(0, 0, scene->canvas->x, scene->canvas->y);
+ if (!canvas) {
+ dmnsn_delete_display(display);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Reading canvas from GL buffer failed! ---\n");
+ return EXIT_FAILURE;
+ }
+
+ /* And write it back */
+ if (dmnsn_gl_write_canvas(canvas) != 0) {
+ dmnsn_delete_canvas(canvas);
+ dmnsn_delete_display(display);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Drawing to openGL failed! ---\n");
+ return EXIT_FAILURE;
}
+ dmnsn_display_flush(display);
+
+ /* Show the image on screen for a bit */
+ sleep(1);
+ dmnsn_delete_canvas(canvas);
dmnsn_delete_display(display);
dmnsn_delete_default_scene(scene);
return EXIT_SUCCESS;
diff --git a/tests/glxx.cpp b/tests/glxx.cpp
index 419e43d..2515156 100644
--- a/tests/glxx.cpp
+++ b/tests/glxx.cpp
@@ -32,44 +32,43 @@ main() {
// Create the default test scene
Scene scene = Tests::default_scene();
- // Get the camera
- Perspective_Camera& camera
- = dynamic_cast<Perspective_Camera&>(scene.camera());
-
- // Find the cube
- Cube* cube = 0;
- for (Scene::Iterator i = scene.begin(); i != scene.end(); ++i) {
- cube = dynamic_cast<Cube*>(&*i);
- if (cube) {
- break;
- }
- }
- if (!cube) {
- throw Dimension_Error("Couldn't find a cube in the default scene.");
- }
-
- Raytracer raytracer(scene);
- GL_Drawer drawer(scene.canvas());
+ // Create a glX window
Tests::Display display(scene.canvas());
- // Render the animation
- const unsigned int frames = 10;
- for (unsigned int i = 0; i < frames; ++i) {
+ {
+ Raytracer raytracer(scene);
+ GL_Drawer drawer(scene.canvas());
+
// Render the scene
- Progress rprogress = raytracer.render_async();
- std::cout << "Raytracing scene: " << rprogress << std::endl;
- rprogress.finish();
+ Progress progress = raytracer.render_async();
- // Display the frame
+ // Display the scene as it's rendered
+ while (progress.progress() < 1.0) {
+ drawer.draw();
+ display.flush();
+ }
+
+ // Make sure we show the completed rendering
+ progress.finish();
drawer.draw();
display.flush();
-
- // Rotate the cube and camera for the next frame
- cube->trans(
- inverse(Matrix::rotation(Vector(0.025, 0.0, 0.0)))*cube->trans()
- );
- camera.trans(Matrix::rotation(Vector(0.0, -0.05, 0.0))*camera.trans());
}
+ // Pause for a second
+ sleep(1);
+
+ // Read the canvas back from the GL buffer
+ GL_Reader reader;
+ Canvas canvas
+ = reader.read(0, 0, scene.canvas().width(), scene.canvas().height());
+
+ // And write it again
+ GL_Drawer drawer(canvas);
+ drawer.draw();
+ display.flush();
+
+ // Pause for a second
+ sleep(1);
+
return EXIT_SUCCESS;
}
diff --git a/tests/tests.c b/tests/tests.c
index 8532585..e91e290 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -221,7 +221,7 @@ dmnsn_delete_display(dmnsn_display *display)
}
void
-dmnsn_display_frame(dmnsn_display *display)
+dmnsn_display_flush(dmnsn_display *display)
{
glFlush();
glXSwapBuffers(display->dpy, display->win);
diff --git a/tests/tests.h b/tests/tests.h
index 88aa3f1..bedc215 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -23,6 +23,7 @@
#include "../libdimension/dimension.h"
#include <GL/glx.h>
#include <GL/gl.h>
+#include <unistd.h>
#include <stdio.h>
#ifdef __cplusplus
@@ -53,7 +54,7 @@ dmnsn_display *dmnsn_new_display(const dmnsn_canvas *canvas);
void dmnsn_delete_display(dmnsn_display *display);
/* Flush the GL buffers */
-void dmnsn_display_frame(dmnsn_display *display);
+void dmnsn_display_flush(dmnsn_display *display);
/*
* Asynchronicity
diff --git a/tests/testsxx.cpp b/tests/testsxx.cpp
index 08c778b..e8dc910 100644
--- a/tests/testsxx.cpp
+++ b/tests/testsxx.cpp
@@ -74,7 +74,7 @@ namespace Dimension
void
Display::flush()
{
- dmnsn_display_frame(m_display);
+ dmnsn_display_flush(m_display);
}
}