summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-19 12:30:30 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-19 12:30:30 +0000
commit6df9d5ad90812d598904831e046753ecc0d11e52 (patch)
treeb6d638e7198de28d2a46b4dd25aa5dddfca24d23
parentSave size of output in SceneRender and set viewport accordingly (diff)
downloadilt-6df9d5ad90812d598904831e046753ecc0d11e52.tar.bz2
ilt-6df9d5ad90812d598904831e046753ecc0d11e52.tar.xz
ilt-6df9d5ad90812d598904831e046753ecc0d11e52.zip
Shared context, persist main window in test, send test for upcoming pointlight
-rw-r--r--test/test-render.cpp35
-rw-r--r--ui/applicationBase.cpp1
2 files changed, 30 insertions, 6 deletions
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 89b2d90..62090e3 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -12,9 +12,9 @@
#include <ui/sceneRenderer.h>
#include <ui/window.h>
-class TestRenderWindow : public Window {
+class TestRenderOutput {
public:
- TestRenderWindow() : Window(640, 480, __FILE__, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN)
+ TestRenderOutput() : size {640, 480}
{
glBindFramebuffer(GL_FRAMEBUFFER, output);
const auto configuregdata
@@ -37,18 +37,27 @@ public:
throw std::runtime_error("Framebuffer not complete!");
}
}
+ const glm::ivec2 size;
+ glFrameBuffer output;
+ glRenderBuffer depth;
+ glTexture outImage;
+};
+
+class TestMainWindow : public Window {
+ // This exists only to hold an OpenGL context open for the duration of the tests,
+ // in the same way a real main window would always exist.
+public:
+ TestMainWindow() : Window {1, 1, __FILE__, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN} { }
void
tick(TickDuration) override
{
}
- glFrameBuffer output;
- glRenderBuffer depth;
- glTexture outImage;
};
BOOST_GLOBAL_FIXTURE(ApplicationBase);
+BOOST_GLOBAL_FIXTURE(TestMainWindow);
-BOOST_FIXTURE_TEST_SUITE(w, TestRenderWindow);
+BOOST_FIXTURE_TEST_SUITE(w, TestRenderOutput);
BOOST_AUTO_TEST_CASE(basic)
{
@@ -64,4 +73,18 @@ BOOST_AUTO_TEST_CASE(basic)
Texture::save(outImage, size, "/tmp/basic.tga");
}
+BOOST_AUTO_TEST_CASE(pointlight)
+{
+ auto gd = std::make_shared<GeoData>(GeoData::Limits {{0, 0}, {100, 100}});
+ gd->generateRandom();
+ Terrain terrain {gd};
+ SceneRenderer ss {size, output};
+ ss.camera.pos = {-10, -10, 60};
+ ss.camera.forward = glm::normalize(glm::vec3 {1, 1, -0.5F});
+ ss.render([&terrain](const auto & shader) {
+ terrain.render(shader);
+ });
+ Texture::save(outImage, size, "/tmp/pointlight.tga");
+}
+
BOOST_AUTO_TEST_SUITE_END();
diff --git a/ui/applicationBase.cpp b/ui/applicationBase.cpp
index 5c87359..cad449d 100644
--- a/ui/applicationBase.cpp
+++ b/ui/applicationBase.cpp
@@ -16,6 +16,7 @@ ApplicationBase::ApplicationBase()
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
+ SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
}
ApplicationBase::~ApplicationBase()