From 21d0ff23c7f4ad812765c9b13816578094bcd9e6 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 9 Nov 2019 12:07:12 +0100 Subject: [PATCH] add code metrics to time-lapse frame generation --- src/canvas_layer.cpp | 23 +++++++++++++++++++++-- src/rtt.cpp | 13 +++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/canvas_layer.cpp b/src/canvas_layer.cpp index 0b7ce9d..84ccd56 100644 --- a/src/canvas_layer.cpp +++ b/src/canvas_layer.cpp @@ -74,7 +74,7 @@ Texture2D Layer::gen_equirect(glm::ivec2 size /*= { 0, 0 }*/) latlong.bindFramebuffer(); - latlong.clear({ 0, 1, 1, 1 }); + //latlong.clear({ 0, 1, 1, 1 }); glViewport(0, 0, latlong.getWidth(), latlong.getHeight()); @@ -108,6 +108,8 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/) { gl_state gl; gl.save(); + + auto t0 = std::chrono::high_resolution_clock::now(); TextureCube cube; RTT latlong; @@ -116,12 +118,14 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/) size = { w, h }; cube = gen_cube(); + auto t1 = std::chrono::high_resolution_clock::now(); latlong.create(size.x * 4, size.y * 2); + auto t2 = std::chrono::high_resolution_clock::now(); glDisable(GL_BLEND); latlong.bindFramebuffer(); - latlong.clear({ 0, 1, 1, 1 }); + //latlong.clear({ 0, 1, 1, 1 }); glViewport(0, 0, latlong.getWidth(), latlong.getHeight()); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, cube.m_cubetex_id); @@ -133,11 +137,26 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/) Canvas::I->m_plane.draw_fill(); latlong.unbindFramebuffer(); + auto t3 = std::chrono::high_resolution_clock::now(); pbo.create(latlong); + auto t4 = std::chrono::high_resolution_clock::now(); latlong.destroy(); cube.destroy(); + + typedef std::chrono::duration micro; + LOG("frame time: %d\n" + "- gen cube: %d\n" + "- create latlong: %d\n" + "- draw latlong: %d\n" + "- create pbo: %d\n", + std::chrono::duration_cast(t4-t0).count(), // total + std::chrono::duration_cast(t1-t0).count(), // gen cube + std::chrono::duration_cast(t2-t1).count(), // create latlong + std::chrono::duration_cast(t3-t2).count(), // draw latlong + std::chrono::duration_cast(t4-t3).count() // create pbo + ); gl.restore(); }); diff --git a/src/rtt.cpp b/src/rtt.cpp index 6aec616..7f91e85 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -507,9 +507,10 @@ void PBO::unbind() noexcept glm::uint8_t* PBO::map() noexcept { App::I->render_task([this] { - glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id); - mapped_ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, width * height * 4, GL_MAP_READ_BIT); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id); + mapped_ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, + width * height * 4, GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); }); return mapped_ptr; } @@ -517,8 +518,8 @@ glm::uint8_t* PBO::map() noexcept void PBO::unmap() noexcept { App::I->render_task([this] { - glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id); - glUnmapBuffer(GL_PIXEL_PACK_BUFFER); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id); + glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); }); }