#define BOOST_TEST_MODULE test_render #include "test-helpers.hpp" #include "testMainWindow.h" #include "testRenderOutput.h" #include #include #include #include #include #include #include #include #include #include #include #include #include class TestScene : public SceneProvider { RailVehicleClass train {"brush47"}; Terrain terrain {[]() { auto gd = std::make_shared(GeoData::Limits {{0, 0}, {100, 100}}); gd->generateRandom(); return gd; }()}; void content(const SceneShader & shader) const { terrain.render(shader); train.render(shader, Location {{52, 50, 2}}, {Location {}, Location {}}); train.render(shader, Location {{52, 30, 2}}, {Location {}, Location {}}); } void lights(const SceneShader &) const { } void shadows(const ShadowMapper & shadowMapper) const { terrain.shadows(shadowMapper); train.shadows(shadowMapper, Location {{52, 50, 2}}); train.shadows(shadowMapper, Location {{52, 30, 2}}); } }; BOOST_GLOBAL_FIXTURE(ApplicationBase); BOOST_GLOBAL_FIXTURE(TestMainWindow); BOOST_DATA_TEST_CASE(cam, boost::unit_test::data::xrange(0.5F, 30.F, 1.3F) * boost::unit_test::data::xrange(0.5F, 10.F, 0.3F) * boost::unit_test::data::xrange(50.F, 500.F, 70.F), dist, near, far) { static constexpr glm::vec3 pos {-10, -10, 60}; Camera cam {pos, half_pi, 1.f, near, far}; const auto e = cam.extentsAtDist(dist); BOOST_CHECK_CLOSE_VEC(e[0], pos + glm::vec3(-dist, dist, -dist)); BOOST_CHECK_CLOSE_VEC(e[1], pos + glm::vec3(-dist, dist, dist)); BOOST_CHECK_CLOSE_VEC(e[2], pos + glm::vec3(dist, dist, -dist)); BOOST_CHECK_CLOSE_VEC(e[3], pos + glm::vec3(dist, dist, dist)); } BOOST_FIXTURE_TEST_SUITE(w, TestRenderOutput); BOOST_AUTO_TEST_CASE(basic) { SceneRenderer ss {size, output}; ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); TestScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); Texture::save(outImage, size, "/tmp/basic.tga"); } BOOST_AUTO_TEST_CASE(pointlight) { SceneRenderer ss {size, output}; ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); class PointLightScene : public TestScene { public: void environment(const SceneShader &, const SceneRenderer & r) const override { r.setAmbientLight({0.2F, 0.2F, 0.2F}); r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this); } void lights(const SceneShader & shader) const override { for (int x = 50; x < 100; x += 20) { for (int y = 50; y < 2000; y += 20) { shader.pointLight.add({x, y, 4}, {1.0, 1.0, 1.0}, 0.1); } } } }; PointLightScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); Texture::save(outImage, size, "/tmp/pointlight.tga"); } BOOST_AUTO_TEST_CASE(spotlight) { SceneRenderer ss {size, output}; ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); class PointLightScene : public TestScene { public: void environment(const SceneShader &, const SceneRenderer & r) const override { r.setAmbientLight({0.2F, 0.2F, 0.2F}); r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this); } void lights(const SceneShader & shader) const override { shader.spotLight.add({50, 50, 15}, down, {1.0, 1.0, 1.0}, 0.01, 1); shader.spotLight.add({51, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001, .5); shader.spotLight.add({53, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001, .5); shader.spotLight.add({60, 50, 3}, north + east, {1.0, 1.0, 1.0}, 0.0001, .7); } }; PointLightScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); Texture::save(outImage, size, "/tmp/spotlight.tga"); } BOOST_AUTO_TEST_SUITE_END();