#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace entt::literals; const char* argv0; TEST(blur_render_task, it) { MM::Engine engine; auto& sdl_ss = engine.addService(); ASSERT_TRUE(engine.enableService()); sdl_ss.createGLWindow("blur_render_task_test", 1280, 720); engine.addService(); ASSERT_TRUE(engine.enableService()); bool provide_ret = engine.provide(); ASSERT_TRUE(provide_ret); auto& scene = engine.tryService()->getScene(); engine.addService(argv0, "blur_render_task_test"); ASSERT_TRUE(engine.enableService()); engine.addService(); ASSERT_TRUE(engine.enableService()); auto& rs = engine.addService(); ASSERT_TRUE(engine.enableService()); #ifdef MM_AUTOTEST engine.addService(50); // 50 frames ASSERT_TRUE(engine.enableService()); #endif //rs.addRenderTask(engine).target_fbo = "game_view"; rs.addRenderTask(engine).target_fbo = "blur_io"; MM::OpenGL::RenderTasks::SimpleRect& bsrr_rend = rs.addRenderTask(engine); bsrr_rend.target_fbo = "blur_io"; MM::OpenGL::RenderTasks::Blur& blur_rend = rs.addRenderTask(engine); blur_rend.in_tex = "blur_io"; blur_rend.out_tex = "blur_io"; blur_rend.temp_tex = "blur_temp"; blur_rend.out_fbo = "blur_io"; blur_rend.temp_fbo = "blur_temp"; // render to display auto& ctfb = rs.addRenderTask(engine); ctfb.src_tex = "blur_io"; ctfb.target_fbo = "display"; rs.addRenderTask(engine); auto [w, h] = sdl_ss.getWindowSize(); auto& rm_t = MM::ResourceManager::ref(); { // setup textures rm_t.load( "blur_io", GL_RGB, w, h, GL_RGB, GL_UNSIGNED_BYTE ); rm_t.load( "blur_temp", GL_RGB, w, h, GL_RGB, GL_UNSIGNED_BYTE ); } { // setup fbo s //rs.targets["game_view"] = MM::OpenGL::FBOBuilder::start() //.attachTexture(MM::OpenGL::Texture::createEmpty(GL_RGB, w, h, GL_RGB, GL_UNSIGNED_BYTE)) //.finish(); rs.targets["blur_io"] = MM::OpenGL::FBOBuilder::start() .attachTexture(rm_t.get("blur_io"_hs)) .setResize(true) .finish(); rs.targets["blur_temp"] = MM::OpenGL::FBOBuilder::start() .attachTexture(rm_t.get("blur_temp"_hs)) .setResize(true) .finish(); } scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); // in this example only rotation is touched auto& cam = scene.ctx().emplace(); cam.setOrthographic(); cam.updateView(); // setup v system auto& org = scene.ctx().emplace(); org.emplace("simple_rotational_velocity_patching"); org.emplace("position3d_from_2d"); org.emplace("transform3d_translate"); org.emplace("transform3d_rotate2d"); org.emplace("transform3d_scale2d"); org.emplace("transform_clear_dirty"); // HACK: instead you would switch to this scene engine.getService().updateOrganizerVertices(scene); MM::Random::SRNG rng{42}; for (int i = 0; i < 10; i++) { auto e = scene.create(); auto& p = scene.emplace(e); p.pos.x = i * 9.f - 40; // zoffset is created by event auto& s = scene.emplace(e); s.scale = {5,5}; scene.emplace(e); auto& v = scene.emplace(e); v.rot_vel = i * 0.3f; if (rng.roll(0.5f)) { auto& col = scene.emplace(e); col.color = {rng.zeroToOne(), rng.zeroToOne(), rng.zeroToOne(), 1.f}; } } engine.run(); } int main(int argc, char** argv) { argv0 = argv[0]; ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }