From 59c4ecf735fd6ce7967703cabac153e8c29afaf7 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:44:56 +0100 Subject: [PATCH 01/76] make render_m_showTextures added render_m_showPasses added render_m_plot added render_cursor added render_drag_and_drop_prompt added render_help added new namespace, prefix to internal functions --- src/core/sandbox.cpp | 593 ++++++++++++++++++++++--------------------- 1 file changed, 305 insertions(+), 288 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 717aebe1..5bb302ac 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1944,343 +1944,360 @@ void Sandbox::renderPost() { if (vera::getWindowStyle() != vera::EMBEDDED) console_uniforms_refresh(); } +namespace { +struct render_ui_t { + float w = (float)(vera::getWindowWidth()); + float h = (float)(vera::getWindowHeight()); + float scale = 1; + float xStep = w * scale; + float yStep = h * scale; + float xOffset = w - xStep; + float yOffset = h - yStep; + float p = vera::getPixelDensity(); + float x = (float)(vera::getWindowWidth()) * 0.5; + float y = h + 10; +}; +namespace renderable_objects { +void overlay_m_showTextures(const Uniforms& uniforms) { + int nTotal = uniforms.textures.size(); + if (nTotal > 0) { + glDisable(GL_DEPTH_TEST); + TRACK_BEGIN("renderUI:textures") + render_ui_t lolo; + lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; + lolo.xStep = lolo.w * lolo.scale; + lolo.yStep = lolo.h * lolo.scale; + lolo.xOffset = lolo.xStep; + lolo.yOffset = lolo.h - lolo.yStep; + + vera::textAngle(-HALF_PI); + vera::textAlign(vera::ALIGN_TOP); + vera::textAlign(vera::ALIGN_LEFT); + vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); -void Sandbox::renderUI() { - TRACK_BEGIN("renderUI") + for (vera::TexturesMap::const_iterator it = uniforms.textures.begin(); it != uniforms.textures.end(); it++) { + vera::TextureStreamsMap::const_iterator slit = uniforms.streams.find(it->first); + if ( slit != uniforms.streams.end() ) + vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, true); + else + vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - // // IN PUT TEXTURES - if (m_showTextures) { + vera::text(it->first, lolo.xOffset + lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - int nTotal = uniforms.textures.size(); - if (nTotal > 0) { - glDisable(GL_DEPTH_TEST); - TRACK_BEGIN("renderUI:textures") - float w = (float)(vera::getWindowWidth()); - float h = (float)(vera::getWindowHeight()); - float a = h/w; - float scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - float xStep = w * scale * a; - float yStep = h * scale; - float xOffset = xStep; - float yOffset = h - yStep; - - vera::textAngle(0.0); - vera::textAlign(vera::ALIGN_TOP); - vera::textAlign(vera::ALIGN_LEFT); - vera::textSize(xStep * 0.2f / vera::getPixelDensity(false)); - - for (vera::TexturesMap::iterator it = uniforms.textures.begin(); it != uniforms.textures.end(); it++) { - float imgAspect = ((float)it->second->getWidth()/(float)it->second->getHeight()); - float imgW = xStep * imgAspect; - vera::TextureStreamsMap::const_iterator slit = uniforms.streams.find(it->first); - if ( slit != uniforms.streams.end() ) - vera::image((vera::TextureStream*)slit->second, xStep * 0.5 + imgW * 0.5, yOffset, imgW, yStep, true); - else - vera::image(it->second, xStep * 0.5 + imgW * 0.5, yOffset, imgW, yStep); - - vera::text(it->first, 0, vera::getWindowHeight() - yOffset - yStep); - - yOffset -= yStep * 2.0; - } - TRACK_END("renderUI:textures") + lolo.yOffset -= lolo.yStep * 2.0; } + TRACK_END("renderUI:textures") } +} - // RESULTING BUFFERS - if (m_showPasses) { - glDisable(GL_DEPTH_TEST); - TRACK_BEGIN("renderUI:buffers") - - // DEBUG BUFFERS - int nTotal = uniforms.buffers.size(); - nTotal += uniforms.doubleBuffers.size(); - nTotal += uniforms.pyramids.size(); - nTotal += uniforms.floods.size(); - if (m_postprocessing && uniforms.models.size() > 0 ) { - nTotal += 1; - nTotal += uniforms.functions["u_scene"].present; - nTotal += uniforms.functions["u_sceneDepth"].present; - } - nTotal += uniforms.functions["u_sceneNormal"].present; - nTotal += uniforms.functions["u_scenePosition"].present; - nTotal += m_sceneRender.getBuffersTotal(); - - if (nTotal > 0) { - float w = (float)(vera::getWindowWidth()); - float h = (float)(vera::getWindowHeight()); - float scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - float xStep = w * scale; - float yStep = h * scale; - float xOffset = w - xStep; - float yOffset = h - yStep; - - vera::textAngle(0.0); - vera::textSize(xStep * 0.2f / vera::getPixelDensity(false)); - vera::textAlign(vera::ALIGN_TOP); - vera::textAlign(vera::ALIGN_LEFT); - - for (size_t i = 0; i < uniforms.buffers.size(); i++) { - glm::vec2 offset = glm::vec2(xOffset, yOffset); - glm::vec2 scale = glm::vec2(yStep); - scale.x *= ((float)uniforms.buffers[i]->getWidth()/(float)uniforms.buffers[i]->getHeight()); - offset.x += xStep - scale.x; - - vera::image(uniforms.buffers[i], offset.x, offset.y, scale.x, scale.y); - vera::text("u_buffer" + vera::toString(i), xOffset - scale.x, vera::getWindowHeight() - yOffset - yStep); - - yOffset -= yStep * 2.0; - } +void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const SceneRender& m_sceneRender) { + glDisable(GL_DEPTH_TEST); + TRACK_BEGIN("renderUI:buffers") + + // DEBUG BUFFERS + int nTotal = uniforms.buffers.size(); + nTotal += uniforms.doubleBuffers.size(); + nTotal += uniforms.pyramids.size(); + if (m_postprocessing && uniforms.models.size() > 0 ) { + nTotal += 1; + nTotal += uniforms.functions["u_scene"].present; + nTotal += uniforms.functions["u_sceneDepth"].present; + } + nTotal += uniforms.functions["u_sceneNormal"].present; + nTotal += uniforms.functions["u_scenePosition"].present; + nTotal += m_sceneRender.getBuffersTotal(); + + if (nTotal > 0) { + render_ui_t lolo; + lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; + lolo.xStep = lolo.w * lolo.scale; + lolo.yStep = lolo.h * lolo.scale; + lolo.xOffset = lolo.w - lolo.xStep; + lolo.yOffset = lolo.h - lolo.yStep; + + vera::textAngle(-HALF_PI); + vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); + vera::textAlign(vera::ALIGN_BOTTOM); + vera::textAlign(vera::ALIGN_LEFT); - for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { - glm::vec2 offset = glm::vec2(xOffset, yOffset); - glm::vec2 scale = glm::vec2(yStep); - scale.x *= ((float)uniforms.doubleBuffers[i]->src->getWidth()/(float)uniforms.doubleBuffers[i]->src->getHeight()); - offset.x += xStep - scale.x; + for (size_t i = 0; i < uniforms.buffers.size(); i++) { + glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 scale = glm::vec2(lolo.yStep); + scale.x *= ((float)uniforms.buffers[i]->getWidth()/(float)uniforms.buffers[i]->getHeight()); + offset.x += lolo.xStep - scale.x; - vera::image(uniforms.doubleBuffers[i]->src, offset.x, offset.y, scale.x, scale.y); - vera::text("u_doubleBuffer" + vera::toString(i), xOffset - scale.x, vera::getWindowHeight() - yOffset - yStep); + vera::image(uniforms.buffers[i], offset.x, offset.y, scale.x, scale.y); + vera::text("u_buffer" + vera::toString(i), lolo.xOffset - scale.x, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - yOffset -= yStep * 2.0; - } + lolo.yOffset -= lolo.yStep * 2.0; + } - for (size_t i = 0; i < uniforms.pyramids.size(); i++) { - glm::vec2 offset = glm::vec2(xOffset, yOffset); - glm::vec2 scale = glm::vec2(yStep); - scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); - float w = scale.x; - offset.x += xStep - w; - for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { - - if (j < uniforms.pyramids[i].getDepth()) - vera::image(uniforms.pyramids[i].getResult(j), offset.x, offset.y, scale.x, scale.y); - else - vera::image(uniforms.pyramids[i].getResult(j), offset.x + w * 2.0f, offset.y, scale.x, scale.y); - - offset.x -= scale.x; - if (j < uniforms.pyramids[i].getDepth()) { - scale *= 0.5; - offset.y = yOffset - yStep * 0.5; - } - else { - offset.y = yOffset + yStep * 0.5; - scale *= 2.0; - } - offset.x -= scale.x; + for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { + glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 scale = glm::vec2(lolo.yStep); + scale.x *= ((float)uniforms.doubleBuffers[i]->src->getWidth()/(float)uniforms.doubleBuffers[i]->src->getHeight()); + offset.x += lolo.xStep - scale.x; - } + vera::image(uniforms.doubleBuffers[i]->src, offset.x, offset.y, scale.x, scale.y); + vera::text("u_doubleBuffer" + vera::toString(i), lolo.xOffset - scale.x, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; + lolo.yOffset -= lolo.yStep * 2.0; + } - } + for (size_t i = 0; i < uniforms.pyramids.size(); i++) { + glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 scale = glm::vec2(lolo.yStep); + scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); + float w = scale.x; + offset.x += lolo.xStep - w; + for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { - for (size_t i = 0; i < uniforms.floods.size(); i++) { - glm::vec2 offset = glm::vec2(xOffset, yOffset); - glm::vec2 scale = glm::vec2(yStep); - scale.x *= ((float)uniforms.floods[i].dst->getWidth()/(float)uniforms.floods[i].dst->getHeight()); - offset.x += xStep - scale.x; + if (j < uniforms.pyramids[i].getDepth()) + vera::image(uniforms.pyramids[i].getResult(j), offset.x, offset.y, scale.x, scale.y); + else + vera::image(uniforms.pyramids[i].getResult(j), offset.x + w * 2.0f, offset.y, scale.x, scale.y); - vera::image(uniforms.floods[i].dst, offset.x, offset.y, scale.x, scale.y); - vera::text("u_flood" + vera::toString(i), xOffset - scale.x, vera::getWindowHeight() - yOffset - yStep); + offset.x -= scale.x; + if (j < uniforms.pyramids[i].getDepth()) { + scale *= 0.5; + offset.y = lolo.yOffset - lolo.yStep * 0.5; + } + else { + offset.y = lolo.yOffset + lolo.yStep * 0.5; + scale *= 2.0; + } + offset.x -= scale.x; - yOffset -= yStep * 2.0; } - if (uniforms.models.size() > 0) { - vera::fill(0.0); - for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { - if ( it->second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); - // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - vera::text("u_lightShadowMap", xOffset - xStep, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; - } + // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); + lolo.yOffset -= lolo.yStep * 2.0; + + } + + if (uniforms.models.size() > 0) { + for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { + if ( it->second->getShadowMap()->getDepthTextureId() ) { + vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); + // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); + vera::text("u_lightShadowMap", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; } - vera::fill(1.0); } + } - if (uniforms.functions["u_scenePosition"].present) { - vera::image(&m_sceneRender.positionFbo, xOffset, yOffset, xStep, yStep); - vera::text("u_scenePosition", xOffset - xStep, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; - } + if (uniforms.functions["u_scenePosition"].present) { + vera::image(&m_sceneRender.positionFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + vera::text("u_scenePosition", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; + } - if (uniforms.functions["u_sceneNormal"].present) { - vera::image(&m_sceneRender.normalFbo, xOffset, yOffset, xStep, yStep); - vera::text("u_sceneNormal", xOffset - xStep, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; - } + if (uniforms.functions["u_sceneNormal"].present) { + vera::image(&m_sceneRender.normalFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + vera::text("u_sceneNormal", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; + } - for (size_t i = 0; i < m_sceneRender.buffersFbo.size(); i++) { - vera::image(m_sceneRender.buffersFbo[i], xOffset, yOffset, xStep, yStep); - vera::text("u_sceneBuffer" + vera::toString(i), xOffset - xStep, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; - } + for (size_t i = 0; i < m_sceneRender.buffersFbo.size(); i++) { + vera::image(m_sceneRender.buffersFbo[i], lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + vera::text("u_sceneBuffer" + vera::toString(i), lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; + } - if (uniforms.functions["u_scene"].present) { - vera::image(&m_sceneRender.renderFbo, xOffset, yOffset, xStep, yStep); - vera::text("u_scene", xOffset - xStep, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; - } + if (uniforms.functions["u_scene"].present) { + vera::image(&m_sceneRender.renderFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + vera::text("u_scene", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; + } - if (uniforms.functions["u_sceneDepth"].present) { - vera::fill(0.0); - if (uniforms.activeCamera) - vera::imageDepth(&m_sceneRender.renderFbo, xOffset, yOffset, xStep, yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - vera::text("u_sceneDepth", xOffset - xStep, vera::getWindowHeight() - yOffset - yStep); - yOffset -= yStep * 2.0; - vera::fill(1.0); - } + if (uniforms.functions["u_sceneDepth"].present) { + if (uniforms.activeCamera) + vera::imageDepth(&m_sceneRender.renderFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + vera::text("u_sceneDepth", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; } - TRACK_END("renderUI:buffers") } + TRACK_END("renderUI:buffers") +}; - if (m_plot != PLOT_OFF && m_plot_texture ) { - glDisable(GL_DEPTH_TEST); - TRACK_BEGIN("renderUI:plot_data") - - float p = vera::getPixelDensity(); - float w = 100 * p; - float h = 30 * p; - float x = (float)(vera::getWindowWidth()) * 0.5; - float y = h + 10; - - m_plot_shader.use(); - m_plot_shader.setUniform("u_scale", w, h); - m_plot_shader.setUniform("u_translate", x, y); - m_plot_shader.setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); - m_plot_shader.setUniform("u_viewport", w, h); - m_plot_shader.setUniform("u_model", glm::vec3(1.0f)); - m_plot_shader.setUniform("u_modelMatrix", glm::mat4(1.0f)); - m_plot_shader.setUniform("u_viewMatrix", glm::mat4(1.0f)); - m_plot_shader.setUniform("u_projectionMatrix", glm::mat4(1.0f)); - m_plot_shader.setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); - m_plot_shader.setUniformTexture("u_plotData", m_plot_texture, 0); - - vera::getBillboard()->render(&m_plot_shader); - TRACK_END("renderUI:plot_data") - } +void overlay_m_plot(vera::Shader& m_plot_shader, const vera::Texture* const m_plot_texture) { + glDisable(GL_DEPTH_TEST); + TRACK_BEGIN("renderUI:plot_data") + + render_ui_t lolo; + lolo.p = vera::getPixelDensity(); + lolo.w = 100 * lolo.p; + lolo.h = 30 * lolo.p; + lolo.x = (float)(vera::getWindowWidth()) * 0.5; + lolo.y = lolo.h + 10; + + m_plot_shader.use(); + m_plot_shader.setUniform("u_scale", lolo.w, lolo.h); + m_plot_shader.setUniform("u_translate", lolo.x, lolo.y); + m_plot_shader.setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); + m_plot_shader.setUniform("u_viewport", lolo.w, lolo.h); + m_plot_shader.setUniform("u_model", glm::vec3(1.0f)); + m_plot_shader.setUniform("u_modelMatrix", glm::mat4(1.0f)); + m_plot_shader.setUniform("u_viewMatrix", glm::mat4(1.0f)); + m_plot_shader.setUniform("u_projectionMatrix", glm::mat4(1.0f)); + m_plot_shader.setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); + m_plot_shader.setUniformTexture("u_plotData", m_plot_texture, 0); + + vera::getBillboard()->render(&m_plot_shader); + TRACK_END("renderUI:plot_data") +} - if (cursor && vera::getMouseEntered()) { - TRACK_BEGIN("renderUI:cursor") - if (m_cross_vbo == nullptr) - m_cross_vbo = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); +void overlay_cursor(std::unique_ptr &m_cross_vbo) { + TRACK_BEGIN("renderUI:cursor") + if (m_cross_vbo == nullptr) + m_cross_vbo = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); + + vera::Shader* fill = vera::getFillShader(); + fill->use(); + fill->setUniform("u_modelViewProjectionMatrix", glm::translate(vera::getOrthoMatrix(), glm::vec3(vera::getMouseX(), vera::getMouseY(), 0.0f) ) ); + fill->setUniform("u_color", glm::vec4(1.0f)); + m_cross_vbo->render(fill); + TRACK_END("renderUI:cursor") +} - vera::Shader* fill = vera::getFillShader(); - fill->use(); - fill->setUniform("u_modelViewProjectionMatrix", glm::translate(vera::getOrthoMatrix(), glm::vec3(vera::getMouseX(), vera::getMouseY(), 0.0f) ) ); - fill->setUniform("u_color", glm::vec4(1.0f)); - m_cross_vbo->render(fill); - TRACK_END("renderUI:cursor") - } +void overlay_prompt_drag_and_drop() { + render_ui_t lolo; + lolo.xStep = lolo.w * 0.05; + lolo.yStep = lolo.h * 0.05; + lolo.x = lolo.xStep * 2.0f; + lolo.y = lolo.yStep * 3.0f; + + vera::Camera *cam = vera::getCamera(); + vera::resetCamera(); + + vera::fill(0.0f, 0.0f, 0.0f, 0.75f); + vera::noStroke(); + vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); - if (frag_index == -1 && vert_index == -1 && geom_index == -1 && vera::getWindowStyle() != vera::EMBEDDED) { - float w = (float)(vera::getWindowWidth()); - float h = (float)(vera::getWindowHeight()); - float xStep = w * 0.05; - float yStep = h * 0.05; - float x = xStep * 2.0f; - float y = yStep * 3.0f; + vera::fill(1.0f); + vera::textAlign(vera::ALIGN_MIDDLE); + vera::textAlign(vera::ALIGN_CENTER); + vera::textAngle(0.0f); - vera::Camera *cam = vera::getCamera(); - vera::resetCamera(); + vera::textSize(38.0f); + vera::text("Drag & Drop", lolo.w * 0.5f, lolo.h * 0.45f); + + vera::textSize(22.0f); + vera::text(".vert .frag .ply .lst .obj .gltf .glb", lolo.w * 0.5f, lolo.h * 0.55f); + + vera::setCamera(cam); +} - vera::fill(0.0f, 0.0f, 0.0f, 0.75f); - vera::noStroke(); - vera::rect(glm::vec2(w * 0.5f, h * 0.5f), glm::vec2(w - xStep * 2.0f, h - yStep * 2.0f)); +void overlay_prompt_help(Uniforms& uniforms, int& geom_index, SceneRender& m_sceneRender, bool help, bool verbose) { - vera::fill(1.0f); + render_ui_t lolo; + lolo.xStep = lolo.w * 0.05; + lolo.yStep = lolo.h * 0.05; + lolo.x = lolo.xStep * 2.0f; + lolo.y = lolo.yStep * 3.0f; - vera::textAngle(0.0f); - vera::textAlign(vera::ALIGN_MIDDLE); - vera::textAlign(vera::ALIGN_CENTER); + vera::Camera *cam = vera::getCamera(); + vera::resetCamera(); - vera::textSize(38.0f); - vera::text("Drag & Drop", w * 0.5f, h * 0.45f); + vera::fill(0.0f, 0.0f, 0.0f, 0.75f); + vera::noStroke(); + vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); - vera::textSize(22.0f); - vera::text(".vert .frag .ply .lst .obj .gltf .glb", w * 0.5f, h * 0.55f); + vera::fill(1.0f); + vera::textAlign(vera::ALIGN_MIDDLE); + vera::textAlign(vera::ALIGN_LEFT); + vera::textAngle(0.0f); + vera::textSize(22.0f); + lolo.yStep = vera::getFontHeight() * 1.5f; - vera::setCamera(cam); + if (geom_index != -1) { + vera::text("a - " + std::string( m_sceneRender.showAxis? "hide" : "show" ) + " axis", lolo.x, lolo.y); + lolo.y += lolo.yStep; + vera::text("b - " + std::string( m_sceneRender.showBBoxes? "hide" : "show" ) + " bounding boxes", lolo.x, lolo.y); + lolo.y += lolo.yStep; } - if (help) { - float w = (float)(vera::getWindowWidth()); - float h = (float)(vera::getWindowHeight()); - float xStep = w * 0.05; - float yStep = h * 0.05; - float x = xStep * 2.0f; - float y = yStep * 3.0f; - - vera::Camera *cam = vera::getCamera(); - vera::resetCamera(); - - vera::fill(0.0f, 0.0f, 0.0f, 0.75f); - vera::noStroke(); - vera::rect(glm::vec2(w * 0.5f, h * 0.5f), glm::vec2(w - xStep * 2.0f, h - yStep * 2.0f)); - - vera::fill(1.0f); - vera::textAlign(vera::ALIGN_MIDDLE); - vera::textAlign(vera::ALIGN_LEFT); - vera::textAngle(0.0f); - vera::textSize(22.0f); - yStep = vera::getFontHeight() * 1.5f; + vera::text("c - hide/show cursor", lolo.x, lolo.y); + lolo.y += lolo.yStep; - if (geom_index != -1) { - vera::text("a - " + std::string( m_sceneRender.showAxis? "hide" : "show" ) + " axis", x, y); - y += yStep; - vera::text("b - " + std::string( m_sceneRender.showBBoxes? "hide" : "show" ) + " bounding boxes", x, y); - y += yStep; - } + if (geom_index != -1) { + vera::text("d - " + std::string( m_sceneRender.dynamicShadows? "disable" : "enable" ) + " dynamic shadows", lolo.x, lolo.y); + lolo.y += lolo.yStep; + vera::text("f - hide/show floor", lolo.x, lolo.y); + lolo.y += lolo.yStep; + } + vera::text("F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen", lolo.x, lolo.y); + lolo.y += lolo.yStep; + if (geom_index != -1) { + vera::text("g - " + std::string( m_sceneRender.showGrid? "hide" : "show" ) + " grid", lolo.x, lolo.y); + lolo.y += lolo.yStep; + } - vera::text("c - hide/show cursor", x, y); - y += yStep; + vera::text("h - " + std::string( help? "hide" : "show" ) + " help", lolo.x, lolo.y); + lolo.y += lolo.yStep; + vera::text("i - hide/show extra info", lolo.x, lolo.y); + lolo.y += lolo.yStep; + vera::text("o - open shaders on default editor", lolo.x, lolo.y); + lolo.y += lolo.yStep; + vera::text("p - hide/show render passes/buffers", lolo.x, lolo.y); + lolo.y += lolo.yStep; + + if (uniforms.streams.size() > 0) { + vera::text("r - restart stream textures", lolo.x, lolo.y); + lolo.y += lolo.yStep; + } - if (geom_index != -1) { - vera::text("d - " + std::string( m_sceneRender.dynamicShadows? "disable" : "enable" ) + " dynamic shadows", x, y); - y += yStep; - vera::text("f - hide/show floor", x, y); - y += yStep; - } - vera::text("F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen", x, y); - y += yStep; - if (geom_index != -1) { - vera::text("g - " + std::string( m_sceneRender.showGrid? "hide" : "show" ) + " grid", x, y); - y += yStep; - } + if (geom_index != -1) { + vera::text("s - hide/show sky", lolo.x, lolo.y); + lolo.y += lolo.yStep; + } - vera::text("h - " + std::string( help? "hide" : "show" ) + " help", x, y); - y += yStep; - vera::text("i - hide/show extra info", x, y); - y += yStep; - vera::text("o - open shaders on default editor", x, y); - y += yStep; - vera::text("p - hide/show render passes/buffers", x, y); - y += yStep; + vera::text("t - hide/show loaded textures", lolo.x, lolo.y); + lolo.y += lolo.yStep; + vera::text("v - " + std::string( verbose? "disable" : "enable" ) + " verbose", lolo.x, lolo.y); + lolo.y += lolo.yStep; - if (uniforms.streams.size() > 0) { - vera::text("r - restart stream textures", x, y); - y += yStep; - } + if (uniforms.streams.size() > 0) { + vera::text("space - start/stop stream textures", lolo.x, lolo.y); + lolo.y += lolo.yStep; + } - if (geom_index != -1) { - vera::text("s - hide/show sky", x, y); - y += yStep; - } + vera::setCamera(cam); + glDisable(GL_DEPTH_TEST); +} +} - vera::text("t - hide/show loaded textures", x, y); - y += yStep; - vera::text("v - " + std::string( verbose? "disable" : "enable" ) + " verbose", x, y); - y += yStep; +} - if (uniforms.streams.size() > 0) { - vera::text("space - start/stop stream textures", x, y); - y += yStep; - } - - vera::setCamera(cam); - glDisable(GL_DEPTH_TEST); +void Sandbox::renderUI() { + TRACK_BEGIN("renderUI") + using namespace renderable_objects; + + // // IN PUT TEXTURES + if (m_showTextures) { + overlay_m_showTextures(uniforms); + } + + // RESULTING BUFFERS + if (m_showPasses) { + overlay_m_showPasses(uniforms, m_postprocessing, m_sceneRender); + } + + if (m_plot != PLOT_OFF && m_plot_texture ) { + overlay_m_plot(m_plot_shader, m_plot_texture); + } + + if (cursor && vera::getMouseEntered()) { + overlay_cursor(m_cross_vbo); + } + + if (frag_index == -1 && vert_index == -1 && geom_index == -1) { + overlay_prompt_drag_and_drop(); + } + + if (help) { + overlay_prompt_help(uniforms, geom_index, m_sceneRender,help, verbose); } TRACK_END("renderUI") From 172837cb9356ecd0efa6cd237e922734b5743e21 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:15:04 +0100 Subject: [PATCH 02/76] added helper lambda print_text added triggered_text --- src/core/sandbox.cpp | 75 +++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 5bb302ac..fa7d45b4 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2211,56 +2211,37 @@ void overlay_prompt_help(Uniforms& uniforms, int& geom_index, SceneRender& m_sce vera::textSize(22.0f); lolo.yStep = vera::getFontHeight() * 1.5f; - if (geom_index != -1) { - vera::text("a - " + std::string( m_sceneRender.showAxis? "hide" : "show" ) + " axis", lolo.x, lolo.y); - lolo.y += lolo.yStep; - vera::text("b - " + std::string( m_sceneRender.showBBoxes? "hide" : "show" ) + " bounding boxes", lolo.x, lolo.y); - lolo.y += lolo.yStep; - } - - vera::text("c - hide/show cursor", lolo.x, lolo.y); - lolo.y += lolo.yStep; - - if (geom_index != -1) { - vera::text("d - " + std::string( m_sceneRender.dynamicShadows? "disable" : "enable" ) + " dynamic shadows", lolo.x, lolo.y); - lolo.y += lolo.yStep; - vera::text("f - hide/show floor", lolo.x, lolo.y); - lolo.y += lolo.yStep; - } - vera::text("F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen", lolo.x, lolo.y); - lolo.y += lolo.yStep; - if (geom_index != -1) { - vera::text("g - " + std::string( m_sceneRender.showGrid? "hide" : "show" ) + " grid", lolo.x, lolo.y); + const auto print_text = [&](const std::string& prompt){ + vera::text(prompt, lolo.x, lolo.y); lolo.y += lolo.yStep; - } - - vera::text("h - " + std::string( help? "hide" : "show" ) + " help", lolo.x, lolo.y); - lolo.y += lolo.yStep; - vera::text("i - hide/show extra info", lolo.x, lolo.y); - lolo.y += lolo.yStep; - vera::text("o - open shaders on default editor", lolo.x, lolo.y); - lolo.y += lolo.yStep; - vera::text("p - hide/show render passes/buffers", lolo.x, lolo.y); - lolo.y += lolo.yStep; - - if (uniforms.streams.size() > 0) { - vera::text("r - restart stream textures", lolo.x, lolo.y); - lolo.y += lolo.yStep; - } - - if (geom_index != -1) { - vera::text("s - hide/show sky", lolo.x, lolo.y); - lolo.y += lolo.yStep; - } + }; - vera::text("t - hide/show loaded textures", lolo.x, lolo.y); - lolo.y += lolo.yStep; - vera::text("v - " + std::string( verbose? "disable" : "enable" ) + " verbose", lolo.x, lolo.y); - lolo.y += lolo.yStep; + const auto geometry_available = geom_index != -1; + const auto uniform_streams_available = uniforms.streams.size() > 0; + + using kv = std::pair; + const auto help_prompts = { + kv{geometry_available, "a - " + std::string( m_sceneRender.showAxis? "hide" : "show" ) + " axis"} + , {geometry_available, "b - " + std::string( m_sceneRender.showBBoxes? "hide" : "show" ) + " bounding boxes"} + , {true, "c - hide/show cursor"} + , {geometry_available, "d - " + std::string( m_sceneRender.dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} + , {geometry_available, "f - hide/show floor"} + , {true, "F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen"} + , {geometry_available, "g - " + std::string( m_sceneRender.showGrid? "hide" : "show" ) + " grid"} + , {true, "h - " + std::string( help? "hide" : "show" ) + " help"} + , {true, "i - hide/show extra info"} + , {true, "o - open shaders on default editor"} + , {true, "p - hide/show render passes/buffers"} + , {uniform_streams_available, "r - restart stream textures"} + , {geometry_available, "s - hide/show sky"} + , {true, "t - hide/show loaded textures"} + , {true, "v - " + std::string( verbose? "disable" : "enable" ) + " verbose"} + , {uniform_streams_available, "space - start/stop stream textures"} + }; - if (uniforms.streams.size() > 0) { - vera::text("space - start/stop stream textures", lolo.x, lolo.y); - lolo.y += lolo.yStep; + for(const auto& prompt : help_prompts) { + if(std::get<0>(prompt)) // activated prompt + print_text(std::get<1>(prompt)); } vera::setCamera(cam); From 2aa65bbf87dce85549e7085f0ed50928ca69b875 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 17 Dec 2022 00:23:25 +0100 Subject: [PATCH 03/76] added helper lambda: print_text added print_fbo_text added print_buffers_text --- src/core/sandbox.cpp | 61 ++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index fa7d45b4..6074a084 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2021,28 +2021,31 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene vera::textAlign(vera::ALIGN_BOTTOM); vera::textAlign(vera::ALIGN_LEFT); - for (size_t i = 0; i < uniforms.buffers.size(); i++) { - glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); - glm::vec2 scale = glm::vec2(lolo.yStep); - scale.x *= ((float)uniforms.buffers[i]->getWidth()/(float)uniforms.buffers[i]->getHeight()); - offset.x += lolo.xStep - scale.x; - - vera::image(uniforms.buffers[i], offset.x, offset.y, scale.x, scale.y); - vera::text("u_buffer" + vera::toString(i), lolo.xOffset - scale.x, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - + const auto print_text = [&](const std::string& prompt, const float offsetx) { + vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); lolo.yOffset -= lolo.yStep * 2.0; + }; + + const auto print_fbo_text = [&](const vera::Fbo& lala, const std::string& prompt) { + vera::image(&lala, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + print_text(prompt, lolo.xOffset - lolo.xStep); + }; + + const auto print_buffers_text =[&](const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt) { + glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 scale = glm::vec2(lolo.yStep); + scale.x *= ((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()); + offset.x += lolo.xStep - scale.x; + vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); + print_text(prompt + vera::toString(i), lolo.xOffset - scale.x); + }; + + for (size_t i = 0; i < uniforms.buffers.size(); i++) { + print_buffers_text(*uniforms.buffers[i], i, "u_buffer"); } for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { - glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); - glm::vec2 scale = glm::vec2(lolo.yStep); - scale.x *= ((float)uniforms.doubleBuffers[i]->src->getWidth()/(float)uniforms.doubleBuffers[i]->src->getHeight()); - offset.x += lolo.xStep - scale.x; - - vera::image(uniforms.doubleBuffers[i]->src, offset.x, offset.y, scale.x, scale.y); - vera::text("u_doubleBuffer" + vera::toString(i), lolo.xOffset - scale.x, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - - lolo.yOffset -= lolo.yStep * 2.0; + print_buffers_text(*uniforms.doubleBuffers[i]->src, i, "u_doubleBuffer"); } for (size_t i = 0; i < uniforms.pyramids.size(); i++) { @@ -2081,41 +2084,31 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene if ( it->second->getShadowMap()->getDepthTextureId() ) { vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - vera::text("u_lightShadowMap", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + print_text("u_lightShadowMap", lolo.xOffset - lolo.xStep); } } } if (uniforms.functions["u_scenePosition"].present) { - vera::image(&m_sceneRender.positionFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - vera::text("u_scenePosition", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + print_fbo_text(m_sceneRender.positionFbo, "u_scenePosition"); } if (uniforms.functions["u_sceneNormal"].present) { - vera::image(&m_sceneRender.normalFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - vera::text("u_sceneNormal", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + print_fbo_text(m_sceneRender.normalFbo, "u_sceneNormal"); } for (size_t i = 0; i < m_sceneRender.buffersFbo.size(); i++) { - vera::image(m_sceneRender.buffersFbo[i], lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - vera::text("u_sceneBuffer" + vera::toString(i), lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + print_fbo_text(*m_sceneRender.buffersFbo[i], "u_sceneBuffer"); } if (uniforms.functions["u_scene"].present) { - vera::image(&m_sceneRender.renderFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - vera::text("u_scene", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + print_fbo_text(m_sceneRender.renderFbo, "u_scene"); } if (uniforms.functions["u_sceneDepth"].present) { if (uniforms.activeCamera) vera::imageDepth(&m_sceneRender.renderFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - vera::text("u_sceneDepth", lolo.xOffset - lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + print_text("u_sceneDepth", lolo.xOffset - lolo.xStep); } } TRACK_END("renderUI:buffers") From 36229eeb350ef45c5f12e8430df9e5a99a8280aa Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 17 Dec 2022 02:23:00 +0100 Subject: [PATCH 04/76] added delta split choice array added helper variables --- src/core/sandbox.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 6074a084..4852a49d 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2056,22 +2056,17 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene offset.x += lolo.xStep - w; for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { - if (j < uniforms.pyramids[i].getDepth()) - vera::image(uniforms.pyramids[i].getResult(j), offset.x, offset.y, scale.x, scale.y); - else - vera::image(uniforms.pyramids[i].getResult(j), offset.x + w * 2.0f, offset.y, scale.x, scale.y); + const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); + const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; - offset.x -= scale.x; - if (j < uniforms.pyramids[i].getDepth()) { - scale *= 0.5; - offset.y = lolo.yOffset - lolo.yStep * 0.5; - } - else { - offset.y = lolo.yOffset + lolo.yStep * 0.5; - scale *= 2.0; - } + vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; + using kv = std::pair; + std::tie(scale, offset.y) = is_lower_depth + ? kv{scale *= 0.5, lolo.yOffset - lolo.yStep * 0.5} + : kv{scale *= 2.0, lolo.yOffset + lolo.yStep * 0.5}; + offset.x -= scale.x; } // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); From 4dab77121af3a49ae4a7d8f4140bf448ba52fdac Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 17 Dec 2022 07:47:57 +0100 Subject: [PATCH 05/76] added std::accumulate over nTotalArray --- src/core/sandbox.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 4852a49d..90e9b147 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2,6 +2,7 @@ #include // stat #include // std::find +#include #include #include #include @@ -1996,17 +1997,22 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene TRACK_BEGIN("renderUI:buffers") // DEBUG BUFFERS - int nTotal = uniforms.buffers.size(); - nTotal += uniforms.doubleBuffers.size(); - nTotal += uniforms.pyramids.size(); - if (m_postprocessing && uniforms.models.size() > 0 ) { - nTotal += 1; - nTotal += uniforms.functions["u_scene"].present; - nTotal += uniforms.functions["u_sceneDepth"].present; - } - nTotal += uniforms.functions["u_sceneNormal"].present; - nTotal += uniforms.functions["u_scenePosition"].present; - nTotal += m_sceneRender.getBuffersTotal(); + const auto is_postprocessing_with_uniforms = m_postprocessing + && uniforms.models.size() > 0; + using kv = std::pair; + const auto nTotalArray = { + kv{true, uniforms.buffers.size()} + , {true, uniforms.doubleBuffers.size()} + , {true, uniforms.pyramids.size()} + , {is_postprocessing_with_uniforms, 1} + , {is_postprocessing_with_uniforms, uniforms.functions["u_scene"].present} + , {is_postprocessing_with_uniforms, uniforms.functions["u_sceneDepth"].present} + , {true, uniforms.functions["u_sceneNormal"].present} + , {true, uniforms.functions["u_scenePosition"].present} + , {true, m_sceneRender.getBuffersTotal()} + }; + const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} + , [](const int acc, const kv& kv) { return acc + ((kv.first) ? kv.second : 0); }); if (nTotal > 0) { render_ui_t lolo; From 2c6d079172b6d73013f2236b74f8d43e6b164071 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 17 Dec 2022 16:42:38 +0100 Subject: [PATCH 06/76] make helpful local-scope lambdas into free-functions --- src/core/sandbox.cpp | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 90e9b147..da6e30ee 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1992,6 +1992,25 @@ void overlay_m_showTextures(const Uniforms& uniforms) { } } +void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { + vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + lolo.yOffset -= lolo.yStep * 2.0; +} + +void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_t& lolo) { + vera::image(&lala, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + print_text(prompt, lolo.xOffset - lolo.xStep, lolo); +} + +void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& lolo) { + glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 scale = glm::vec2(lolo.yStep); + scale.x *= ((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()); + offset.x += lolo.xStep - scale.x; + vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); + print_text(prompt + vera::toString(i), lolo.xOffset - scale.x, lolo); +} + void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const SceneRender& m_sceneRender) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") @@ -2027,31 +2046,12 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene vera::textAlign(vera::ALIGN_BOTTOM); vera::textAlign(vera::ALIGN_LEFT); - const auto print_text = [&](const std::string& prompt, const float offsetx) { - vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; - }; - - const auto print_fbo_text = [&](const vera::Fbo& lala, const std::string& prompt) { - vera::image(&lala, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - print_text(prompt, lolo.xOffset - lolo.xStep); - }; - - const auto print_buffers_text =[&](const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt) { - glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); - glm::vec2 scale = glm::vec2(lolo.yStep); - scale.x *= ((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()); - offset.x += lolo.xStep - scale.x; - vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); - print_text(prompt + vera::toString(i), lolo.xOffset - scale.x); - }; - for (size_t i = 0; i < uniforms.buffers.size(); i++) { - print_buffers_text(*uniforms.buffers[i], i, "u_buffer"); + print_buffers_text(*uniforms.buffers[i], i, "u_buffer", lolo); } for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { - print_buffers_text(*uniforms.doubleBuffers[i]->src, i, "u_doubleBuffer"); + print_buffers_text(*uniforms.doubleBuffers[i]->src, i, "u_doubleBuffer", lolo); } for (size_t i = 0; i < uniforms.pyramids.size(); i++) { @@ -2085,31 +2085,31 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene if ( it->second->getShadowMap()->getDepthTextureId() ) { vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - print_text("u_lightShadowMap", lolo.xOffset - lolo.xStep); + print_text("u_lightShadowMap", lolo.xOffset - lolo.xStep, lolo); } } } if (uniforms.functions["u_scenePosition"].present) { - print_fbo_text(m_sceneRender.positionFbo, "u_scenePosition"); + print_fbo_text(m_sceneRender.positionFbo, "u_scenePosition", lolo); } if (uniforms.functions["u_sceneNormal"].present) { - print_fbo_text(m_sceneRender.normalFbo, "u_sceneNormal"); + print_fbo_text(m_sceneRender.normalFbo, "u_sceneNormal", lolo); } for (size_t i = 0; i < m_sceneRender.buffersFbo.size(); i++) { - print_fbo_text(*m_sceneRender.buffersFbo[i], "u_sceneBuffer"); + print_fbo_text(*m_sceneRender.buffersFbo[i], "u_sceneBuffer", lolo); } if (uniforms.functions["u_scene"].present) { - print_fbo_text(m_sceneRender.renderFbo, "u_scene"); + print_fbo_text(m_sceneRender.renderFbo, "u_scene", lolo); } if (uniforms.functions["u_sceneDepth"].present) { if (uniforms.activeCamera) vera::imageDepth(&m_sceneRender.renderFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - print_text("u_sceneDepth", lolo.xOffset - lolo.xStep); + print_text("u_sceneDepth", lolo.xOffset - lolo.xStep, lolo); } } TRACK_END("renderUI:buffers") From 3c172d2904af0274ce5451bfcd2a55e0f75f3f88 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 17 Dec 2022 19:08:10 +0100 Subject: [PATCH 07/76] added vtable_kv_t added do_something_lightmap added do_something_pyramid added do_something_doublebuffers added do_something_singlebuffer defined stronger typename: renderer_process_info_t strongtyped do_something_* functions made helper local variable added prompt_id parameter moved Uniforms& assignment into function parameter list null-mask unneeded parameters --- src/core/sandbox.cpp | 154 +++++++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 64 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index da6e30ee..25973176 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2011,6 +2011,77 @@ void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::s print_text(prompt + vera::toString(i), lolo.xOffset - scale.x, lolo); } +using renderer_process_info_t = std::tuple; + +void do_something_00(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t& abc, render_ui_t& lolo) { + if (uniforms.functions[prompt_id].present) { + print_fbo_text(*std::get<1>(abc), prompt_id, lolo); + } +} + +void do_something_01(const std::string& prompt_id, Uniforms& , const renderer_process_info_t& abc, render_ui_t& lolo) { + const auto& fbolist = *std::get<2>(abc); + for (size_t i = 0; i < fbolist.size(); i++) { + print_fbo_text(*fbolist[i], prompt_id, lolo); + } +} + +void do_something_02(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t& abc, render_ui_t& lolo) { + if (uniforms.functions[prompt_id].present) { + if (uniforms.activeCamera) + vera::imageDepth(*std::get<1>(abc), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + print_text(prompt_id, lolo.xOffset - lolo.xStep, lolo); + } +} + +void do_something_lightmap(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { + if (uniforms.models.size() > 0) { + for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { + if ( it->second->getShadowMap()->getDepthTextureId() ) { + vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); + // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); + print_text(prompt_id, lolo.xOffset - lolo.xStep, lolo); + } + } + } +} + +void do_something_pyramid(const std::string&, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { + for (size_t i = 0; i < uniforms.pyramids.size(); i++) { + glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 scale = glm::vec2(lolo.yStep); + scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); + float w = scale.x; + offset.x += lolo.xStep - w; + for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { + const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); + const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; + + vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); + offset.x -= scale.x; + + std::tie(scale, offset.y) = is_lower_depth + ? std::pair{scale *= 0.5, lolo.yOffset - lolo.yStep * 0.5} + : std::pair{scale *= 2.0, lolo.yOffset + lolo.yStep * 0.5}; + offset.x -= scale.x; + } + // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); + lolo.yOffset -= lolo.yStep * 2.0; + } +} + +void do_something_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { + for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { + print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, lolo); + } +} + +void do_something_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { + for (size_t i = 0; i < uniforms.buffers.size(); i++) { + print_buffers_text(*uniforms.buffers[i], i, prompt_id, lolo); + } +} + void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const SceneRender& m_sceneRender) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") @@ -2046,70 +2117,25 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene vera::textAlign(vera::ALIGN_BOTTOM); vera::textAlign(vera::ALIGN_LEFT); - for (size_t i = 0; i < uniforms.buffers.size(); i++) { - print_buffers_text(*uniforms.buffers[i], i, "u_buffer", lolo); - } - - for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { - print_buffers_text(*uniforms.doubleBuffers[i]->src, i, "u_doubleBuffer", lolo); - } - - for (size_t i = 0; i < uniforms.pyramids.size(); i++) { - glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); - glm::vec2 scale = glm::vec2(lolo.yStep); - scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); - float w = scale.x; - offset.x += lolo.xStep - w; - for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { - - const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); - const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; - - vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); - offset.x -= scale.x; - - using kv = std::pair; - std::tie(scale, offset.y) = is_lower_depth - ? kv{scale *= 0.5, lolo.yOffset - lolo.yStep * 0.5} - : kv{scale *= 2.0, lolo.yOffset + lolo.yStep * 0.5}; - offset.x -= scale.x; - } - - // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); - lolo.yOffset -= lolo.yStep * 2.0; - - } - - if (uniforms.models.size() > 0) { - for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { - if ( it->second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); - // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - print_text("u_lightShadowMap", lolo.xOffset - lolo.xStep, lolo); - } - } - } - - if (uniforms.functions["u_scenePosition"].present) { - print_fbo_text(m_sceneRender.positionFbo, "u_scenePosition", lolo); - } - - if (uniforms.functions["u_sceneNormal"].present) { - print_fbo_text(m_sceneRender.normalFbo, "u_sceneNormal", lolo); - } - - for (size_t i = 0; i < m_sceneRender.buffersFbo.size(); i++) { - print_fbo_text(*m_sceneRender.buffersFbo[i], "u_sceneBuffer", lolo); - } - - if (uniforms.functions["u_scene"].present) { - print_fbo_text(m_sceneRender.renderFbo, "u_scene", lolo); - } - - if (uniforms.functions["u_sceneDepth"].present) { - if (uniforms.activeCamera) - vera::imageDepth(&m_sceneRender.renderFbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - print_text("u_sceneDepth", lolo.xOffset - lolo.xStep, lolo); + using func_sig_t = auto (*)(const std::string&, Uniforms&, const renderer_process_info_t&, render_ui_t&)-> void; + using vtable_kv_t = std::pair; + const std::array somelist { + vtable_kv_t{{"u_buffer", nullptr, nullptr}, do_something_singlebuffer} + , {{"u_doubleBuffer", nullptr, nullptr}, do_something_doublebuffers} + , {{"u_pyramid0", nullptr, nullptr}, do_something_pyramid} + , {{"u_lightShadowMap", nullptr, nullptr}, do_something_lightmap} + , {{"u_scenePosition", &m_sceneRender.positionFbo, nullptr}, do_something_00} + , {{"u_sceneNormal", &m_sceneRender.normalFbo, nullptr}, do_something_00} + , {{"u_sceneBuffer", nullptr, &m_sceneRender.buffersFbo}, do_something_01} + , {{"u_scene", &m_sceneRender.renderFbo, nullptr}, do_something_00} + , {{"u_sceneDepth", &m_sceneRender.renderFbo, nullptr}, do_something_02} + }; + + for(const auto& abc : somelist) { + const auto process_renderer = std::get<1>(abc); + const auto& process_info = std::get<0>(abc); + const auto& prompt_id = std::get<0>(process_info); + process_renderer(prompt_id, uniforms, process_info, lolo); } } TRACK_END("renderUI:buffers") From 625fcf54658eab181ecd37218919815ce479500a Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 04:31:13 +0100 Subject: [PATCH 08/76] added process_render_passes --- src/core/sandbox.cpp | 69 +++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 25973176..562bea42 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2082,6 +2082,41 @@ void do_something_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, } } +void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, int nTotal){ + render_ui_t lolo; + lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; + lolo.xStep = lolo.w * lolo.scale; + lolo.yStep = lolo.h * lolo.scale; + lolo.xOffset = lolo.w - lolo.xStep; + lolo.yOffset = lolo.h - lolo.yStep; + + vera::textAngle(-HALF_PI); + vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); + vera::textAlign(vera::ALIGN_BOTTOM); + vera::textAlign(vera::ALIGN_LEFT); + + using func_sig_t = auto (*)(const std::string&, Uniforms&, const renderer_process_info_t&, render_ui_t&)-> void; + using vtable_kv_t = std::pair; + const std::array somelist { + vtable_kv_t{{"u_buffer", nullptr, nullptr}, do_something_singlebuffer} + , {{"u_doubleBuffer", nullptr, nullptr}, do_something_doublebuffers} + , {{"u_pyramid0", nullptr, nullptr}, do_something_pyramid} + , {{"u_lightShadowMap", nullptr, nullptr}, do_something_lightmap} + , {{"u_scenePosition", &m_sceneRender.positionFbo, nullptr}, do_something_00} + , {{"u_sceneNormal", &m_sceneRender.normalFbo, nullptr}, do_something_00} + , {{"u_sceneBuffer", nullptr, &m_sceneRender.buffersFbo}, do_something_01} + , {{"u_scene", &m_sceneRender.renderFbo, nullptr}, do_something_00} + , {{"u_sceneDepth", &m_sceneRender.renderFbo, nullptr}, do_something_02} + }; + + for(const auto& abc : somelist) { + const auto process_renderer = std::get<1>(abc); + const auto& process_info = std::get<0>(abc); + const auto& prompt_id = std::get<0>(process_info); + process_renderer(prompt_id, uniforms, process_info, lolo); + } +} + void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const SceneRender& m_sceneRender) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") @@ -2103,40 +2138,8 @@ void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const Scene }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const int acc, const kv& kv) { return acc + ((kv.first) ? kv.second : 0); }); - if (nTotal > 0) { - render_ui_t lolo; - lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.xStep = lolo.w * lolo.scale; - lolo.yStep = lolo.h * lolo.scale; - lolo.xOffset = lolo.w - lolo.xStep; - lolo.yOffset = lolo.h - lolo.yStep; - - vera::textAngle(-HALF_PI); - vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); - vera::textAlign(vera::ALIGN_BOTTOM); - vera::textAlign(vera::ALIGN_LEFT); - - using func_sig_t = auto (*)(const std::string&, Uniforms&, const renderer_process_info_t&, render_ui_t&)-> void; - using vtable_kv_t = std::pair; - const std::array somelist { - vtable_kv_t{{"u_buffer", nullptr, nullptr}, do_something_singlebuffer} - , {{"u_doubleBuffer", nullptr, nullptr}, do_something_doublebuffers} - , {{"u_pyramid0", nullptr, nullptr}, do_something_pyramid} - , {{"u_lightShadowMap", nullptr, nullptr}, do_something_lightmap} - , {{"u_scenePosition", &m_sceneRender.positionFbo, nullptr}, do_something_00} - , {{"u_sceneNormal", &m_sceneRender.normalFbo, nullptr}, do_something_00} - , {{"u_sceneBuffer", nullptr, &m_sceneRender.buffersFbo}, do_something_01} - , {{"u_scene", &m_sceneRender.renderFbo, nullptr}, do_something_00} - , {{"u_sceneDepth", &m_sceneRender.renderFbo, nullptr}, do_something_02} - }; - - for(const auto& abc : somelist) { - const auto process_renderer = std::get<1>(abc); - const auto& process_info = std::get<0>(abc); - const auto& prompt_id = std::get<0>(process_info); - process_renderer(prompt_id, uniforms, process_info, lolo); - } + process_render_passes(uniforms, m_sceneRender, nTotal); } TRACK_END("renderUI:buffers") }; From cf8a01b0447ed412bc4ddc6466065af980f9342c Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 04:59:30 +0100 Subject: [PATCH 09/76] added metatable added metadata-type to parameter list strongtyped metadata{} strongtyped vtable_metatadata_with_pred_t made vtable_metatadata_with_pred_t{} a local strongtype --- src/core/sandbox.cpp | 144 ++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 69 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 562bea42..e7451cb4 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1960,8 +1960,20 @@ struct render_ui_t { float y = h + 10; }; namespace renderable_objects { -void overlay_m_showTextures(const Uniforms& uniforms) { - int nTotal = uniforms.textures.size(); +struct metadata { + Uniforms * uniforms; + const SceneRender* m_sceneRender; + const bool* m_postprocessing; + vera::Shader* m_plot_shader; + vera::Texture** m_plot_texture; + std::unique_ptr* m_cross_vbo; + const int* geom_index; + const bool* help; + const bool* verbose; +}; + +void overlay_m_showTextures(const metadata& muu) { + int nTotal = muu.uniforms->textures.size(); if (nTotal > 0) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") @@ -1977,9 +1989,9 @@ void overlay_m_showTextures(const Uniforms& uniforms) { vera::textAlign(vera::ALIGN_LEFT); vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); - for (vera::TexturesMap::const_iterator it = uniforms.textures.begin(); it != uniforms.textures.end(); it++) { - vera::TextureStreamsMap::const_iterator slit = uniforms.streams.find(it->first); - if ( slit != uniforms.streams.end() ) + for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { + vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); + if ( slit != muu.uniforms->streams.end() ) vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, true); else vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); @@ -2117,34 +2129,34 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, } } -void overlay_m_showPasses(Uniforms& uniforms, bool m_postprocessing, const SceneRender& m_sceneRender) { +void overlay_m_showPasses(const metadata& muu) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") // DEBUG BUFFERS - const auto is_postprocessing_with_uniforms = m_postprocessing - && uniforms.models.size() > 0; + const auto is_postprocessing_with_uniforms = muu.m_postprocessing + && muu.uniforms->models.size() > 0; using kv = std::pair; const auto nTotalArray = { - kv{true, uniforms.buffers.size()} - , {true, uniforms.doubleBuffers.size()} - , {true, uniforms.pyramids.size()} + kv{true, muu.uniforms->buffers.size()} + , {true, muu.uniforms->doubleBuffers.size()} + , {true, muu.uniforms->pyramids.size()} , {is_postprocessing_with_uniforms, 1} - , {is_postprocessing_with_uniforms, uniforms.functions["u_scene"].present} - , {is_postprocessing_with_uniforms, uniforms.functions["u_sceneDepth"].present} - , {true, uniforms.functions["u_sceneNormal"].present} - , {true, uniforms.functions["u_scenePosition"].present} - , {true, m_sceneRender.getBuffersTotal()} + , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_scene"].present} + , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_sceneDepth"].present} + , {true, muu.uniforms->functions["u_sceneNormal"].present} + , {true, muu.uniforms->functions["u_scenePosition"].present} + , {true, muu.m_sceneRender->getBuffersTotal()} }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const int acc, const kv& kv) { return acc + ((kv.first) ? kv.second : 0); }); if (nTotal > 0) { - process_render_passes(uniforms, m_sceneRender, nTotal); + process_render_passes(*muu.uniforms, *muu.m_sceneRender, nTotal); } TRACK_END("renderUI:buffers") }; -void overlay_m_plot(vera::Shader& m_plot_shader, const vera::Texture* const m_plot_texture) { +void overlay_m_plot(const metadata& muu) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") @@ -2155,36 +2167,36 @@ void overlay_m_plot(vera::Shader& m_plot_shader, const vera::Texture* const m_pl lolo.x = (float)(vera::getWindowWidth()) * 0.5; lolo.y = lolo.h + 10; - m_plot_shader.use(); - m_plot_shader.setUniform("u_scale", lolo.w, lolo.h); - m_plot_shader.setUniform("u_translate", lolo.x, lolo.y); - m_plot_shader.setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); - m_plot_shader.setUniform("u_viewport", lolo.w, lolo.h); - m_plot_shader.setUniform("u_model", glm::vec3(1.0f)); - m_plot_shader.setUniform("u_modelMatrix", glm::mat4(1.0f)); - m_plot_shader.setUniform("u_viewMatrix", glm::mat4(1.0f)); - m_plot_shader.setUniform("u_projectionMatrix", glm::mat4(1.0f)); - m_plot_shader.setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); - m_plot_shader.setUniformTexture("u_plotData", m_plot_texture, 0); - - vera::getBillboard()->render(&m_plot_shader); + muu.m_plot_shader->use(); + muu.m_plot_shader->setUniform("u_scale", lolo.w, lolo.h); + muu.m_plot_shader->setUniform("u_translate", lolo.x, lolo.y); + muu.m_plot_shader->setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); + muu.m_plot_shader->setUniform("u_viewport", lolo.w, lolo.h); + muu.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); + muu.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); + muu.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); + muu.m_plot_shader->setUniform("u_projectionMatrix", glm::mat4(1.0f)); + muu.m_plot_shader->setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); + muu.m_plot_shader->setUniformTexture("u_plotData", *muu.m_plot_texture, 0); + + vera::getBillboard()->render(&*muu.m_plot_shader); TRACK_END("renderUI:plot_data") } -void overlay_cursor(std::unique_ptr &m_cross_vbo) { +void overlay_cursor(const metadata& muu) { TRACK_BEGIN("renderUI:cursor") - if (m_cross_vbo == nullptr) - m_cross_vbo = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); + if ((*muu.m_cross_vbo) == nullptr) + (*muu.m_cross_vbo) = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); vera::Shader* fill = vera::getFillShader(); fill->use(); fill->setUniform("u_modelViewProjectionMatrix", glm::translate(vera::getOrthoMatrix(), glm::vec3(vera::getMouseX(), vera::getMouseY(), 0.0f) ) ); fill->setUniform("u_color", glm::vec4(1.0f)); - m_cross_vbo->render(fill); + (*muu.m_cross_vbo)->render(fill); TRACK_END("renderUI:cursor") } -void overlay_prompt_drag_and_drop() { +void overlay_prompt_drag_and_drop(const metadata&) { render_ui_t lolo; lolo.xStep = lolo.w * 0.05; lolo.yStep = lolo.h * 0.05; @@ -2212,8 +2224,7 @@ void overlay_prompt_drag_and_drop() { vera::setCamera(cam); } -void overlay_prompt_help(Uniforms& uniforms, int& geom_index, SceneRender& m_sceneRender, bool help, bool verbose) { - +void overlay_prompt_help(const metadata& muu) { render_ui_t lolo; lolo.xStep = lolo.w * 0.05; lolo.yStep = lolo.h * 0.05; @@ -2239,26 +2250,26 @@ void overlay_prompt_help(Uniforms& uniforms, int& geom_index, SceneRender& m_sce lolo.y += lolo.yStep; }; - const auto geometry_available = geom_index != -1; - const auto uniform_streams_available = uniforms.streams.size() > 0; + const auto geometry_available = *muu.geom_index != -1; + const auto uniform_streams_available = muu.uniforms->streams.size() > 0; using kv = std::pair; const auto help_prompts = { - kv{geometry_available, "a - " + std::string( m_sceneRender.showAxis? "hide" : "show" ) + " axis"} - , {geometry_available, "b - " + std::string( m_sceneRender.showBBoxes? "hide" : "show" ) + " bounding boxes"} + kv{geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} + , {geometry_available, "b - " + std::string( muu.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} , {true, "c - hide/show cursor"} - , {geometry_available, "d - " + std::string( m_sceneRender.dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} + , {geometry_available, "d - " + std::string( muu.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} , {geometry_available, "f - hide/show floor"} , {true, "F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen"} - , {geometry_available, "g - " + std::string( m_sceneRender.showGrid? "hide" : "show" ) + " grid"} - , {true, "h - " + std::string( help? "hide" : "show" ) + " help"} + , {geometry_available, "g - " + std::string( muu.m_sceneRender->showGrid? "hide" : "show" ) + " grid"} + , {true, "h - " + std::string( muu.help? "hide" : "show" ) + " help"} , {true, "i - hide/show extra info"} , {true, "o - open shaders on default editor"} , {true, "p - hide/show render passes/buffers"} , {uniform_streams_available, "r - restart stream textures"} , {geometry_available, "s - hide/show sky"} , {true, "t - hide/show loaded textures"} - , {true, "v - " + std::string( verbose? "disable" : "enable" ) + " verbose"} + , {true, "v - " + std::string( muu.verbose? "disable" : "enable" ) + " verbose"} , {uniform_streams_available, "space - start/stop stream textures"} }; @@ -2278,31 +2289,26 @@ void Sandbox::renderUI() { TRACK_BEGIN("renderUI") using namespace renderable_objects; - // // IN PUT TEXTURES - if (m_showTextures) { - overlay_m_showTextures(uniforms); - } - - // RESULTING BUFFERS - if (m_showPasses) { - overlay_m_showPasses(uniforms, m_postprocessing, m_sceneRender); - } - - if (m_plot != PLOT_OFF && m_plot_texture ) { - overlay_m_plot(m_plot_shader, m_plot_texture); - } - - if (cursor && vera::getMouseEntered()) { - overlay_cursor(m_cross_vbo); - } + const auto display_m_plots = m_plot != PLOT_OFF && m_plot_texture ; + const auto diplay_cursor = cursor && vera::getMouseEntered(); + const auto no_geometry_available = frag_index == -1 && vert_index == -1 && geom_index == -1; - if (frag_index == -1 && vert_index == -1 && geom_index == -1) { - overlay_prompt_drag_and_drop(); - } + struct vtable_metatadata_with_pred_t { + using function_sig_t = auto (*)(const renderable_objects::metadata&) -> void; + const bool predicate; + const function_sig_t do_overlay_action; + const renderable_objects::metadata parameters; + }; - if (help) { - overlay_prompt_help(uniforms, geom_index, m_sceneRender,help, verbose); - } + const std::array lala = { + vtable_metatadata_with_pred_t{m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + , {m_showPasses, &overlay_m_showPasses, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + , {display_m_plots, &overlay_m_plot, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} + , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} + , {no_geometry_available, &overlay_prompt_drag_and_drop, {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + , {help, &overlay_prompt_help, {&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose}} + }; + for(const auto& _: lala) { if(_.predicate) _.do_overlay_action(_.parameters); } TRACK_END("renderUI") } From 1ea6982b1e0a31bfb80bbec078e2b3a82dad54aa Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 06:35:03 +0100 Subject: [PATCH 10/76] strongtyped vtable_kv_t --- src/core/sandbox.cpp | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index e7451cb4..9f56a0e5 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2023,16 +2023,16 @@ void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::s print_text(prompt + vera::toString(i), lolo.xOffset - scale.x, lolo); } -using renderer_process_info_t = std::tuple; +using renderer_process_info_t = std::tuple; void do_something_00(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t& abc, render_ui_t& lolo) { if (uniforms.functions[prompt_id].present) { - print_fbo_text(*std::get<1>(abc), prompt_id, lolo); + print_fbo_text(*std::get<0>(abc), prompt_id, lolo); } } void do_something_01(const std::string& prompt_id, Uniforms& , const renderer_process_info_t& abc, render_ui_t& lolo) { - const auto& fbolist = *std::get<2>(abc); + const auto& fbolist = *std::get<1>(abc); for (size_t i = 0; i < fbolist.size(); i++) { print_fbo_text(*fbolist[i], prompt_id, lolo); } @@ -2041,7 +2041,7 @@ void do_something_01(const std::string& prompt_id, Uniforms& , const renderer_pr void do_something_02(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t& abc, render_ui_t& lolo) { if (uniforms.functions[prompt_id].present) { if (uniforms.activeCamera) - vera::imageDepth(*std::get<1>(abc), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + vera::imageDepth(*std::get<0>(abc), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); print_text(prompt_id, lolo.xOffset - lolo.xStep, lolo); } } @@ -2107,26 +2107,24 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, vera::textAlign(vera::ALIGN_BOTTOM); vera::textAlign(vera::ALIGN_LEFT); - using func_sig_t = auto (*)(const std::string&, Uniforms&, const renderer_process_info_t&, render_ui_t&)-> void; - using vtable_kv_t = std::pair; + struct vtable_kv_t{ + using func_sig_t = auto (*)(const std::string&, Uniforms&, const renderer_process_info_t&, render_ui_t&)-> void; + const std::string prompt_id; + const renderer_process_info_t process_info; + const func_sig_t process_renderer; + }; const std::array somelist { - vtable_kv_t{{"u_buffer", nullptr, nullptr}, do_something_singlebuffer} - , {{"u_doubleBuffer", nullptr, nullptr}, do_something_doublebuffers} - , {{"u_pyramid0", nullptr, nullptr}, do_something_pyramid} - , {{"u_lightShadowMap", nullptr, nullptr}, do_something_lightmap} - , {{"u_scenePosition", &m_sceneRender.positionFbo, nullptr}, do_something_00} - , {{"u_sceneNormal", &m_sceneRender.normalFbo, nullptr}, do_something_00} - , {{"u_sceneBuffer", nullptr, &m_sceneRender.buffersFbo}, do_something_01} - , {{"u_scene", &m_sceneRender.renderFbo, nullptr}, do_something_00} - , {{"u_sceneDepth", &m_sceneRender.renderFbo, nullptr}, do_something_02} + vtable_kv_t{"u_buffer", {nullptr, nullptr}, do_something_singlebuffer} + , {"u_doubleBuffer", {nullptr, nullptr}, do_something_doublebuffers} + , {"u_pyramid0", {nullptr, nullptr}, do_something_pyramid} + , {"u_lightShadowMap", {nullptr, nullptr}, do_something_lightmap} + , {"u_scenePosition", {&m_sceneRender.positionFbo, nullptr}, do_something_00} + , {"u_sceneNormal", {&m_sceneRender.normalFbo, nullptr}, do_something_00} + , {"u_sceneBuffer", {nullptr, &m_sceneRender.buffersFbo}, do_something_01} + , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_something_00} + , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_something_02} }; - - for(const auto& abc : somelist) { - const auto process_renderer = std::get<1>(abc); - const auto& process_info = std::get<0>(abc); - const auto& prompt_id = std::get<0>(process_info); - process_renderer(prompt_id, uniforms, process_info, lolo); - } + for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, lolo); } } void overlay_m_showPasses(const metadata& muu) { From 790816b2172fcd4b8c84f842d6213f1f9055be34 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 06:43:53 +0100 Subject: [PATCH 11/76] strongtyped kv_prompt --- src/core/sandbox.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 9f56a0e5..91f661c8 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2251,9 +2251,13 @@ void overlay_prompt_help(const metadata& muu) { const auto geometry_available = *muu.geom_index != -1; const auto uniform_streams_available = muu.uniforms->streams.size() > 0; - using kv = std::pair; + struct kv_prompt { + bool predicate; + std::string message; + }; + const auto help_prompts = { - kv{geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} + kv_prompt{geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} , {geometry_available, "b - " + std::string( muu.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} , {true, "c - hide/show cursor"} , {geometry_available, "d - " + std::string( muu.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} @@ -2270,11 +2274,7 @@ void overlay_prompt_help(const metadata& muu) { , {true, "v - " + std::string( muu.verbose? "disable" : "enable" ) + " verbose"} , {uniform_streams_available, "space - start/stop stream textures"} }; - - for(const auto& prompt : help_prompts) { - if(std::get<0>(prompt)) // activated prompt - print_text(std::get<1>(prompt)); - } + for(const auto& _ : help_prompts) { if(_.predicate) print_text(_.message); } vera::setCamera(cam); glDisable(GL_DEPTH_TEST); From ab81b3ed817512798f71580a7c3aa49630519fed Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 07:36:30 +0100 Subject: [PATCH 12/76] moved metadata, overlay_m_showTextures declaration to better place --- src/core/sandbox.cpp | 87 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 91f661c8..96fd11f5 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1960,49 +1960,6 @@ struct render_ui_t { float y = h + 10; }; namespace renderable_objects { -struct metadata { - Uniforms * uniforms; - const SceneRender* m_sceneRender; - const bool* m_postprocessing; - vera::Shader* m_plot_shader; - vera::Texture** m_plot_texture; - std::unique_ptr* m_cross_vbo; - const int* geom_index; - const bool* help; - const bool* verbose; -}; - -void overlay_m_showTextures(const metadata& muu) { - int nTotal = muu.uniforms->textures.size(); - if (nTotal > 0) { - glDisable(GL_DEPTH_TEST); - TRACK_BEGIN("renderUI:textures") - render_ui_t lolo; - lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.xStep = lolo.w * lolo.scale; - lolo.yStep = lolo.h * lolo.scale; - lolo.xOffset = lolo.xStep; - lolo.yOffset = lolo.h - lolo.yStep; - - vera::textAngle(-HALF_PI); - vera::textAlign(vera::ALIGN_TOP); - vera::textAlign(vera::ALIGN_LEFT); - vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); - - for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { - vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); - if ( slit != muu.uniforms->streams.end() ) - vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, true); - else - vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - - vera::text(it->first, lolo.xOffset + lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - - lolo.yOffset -= lolo.yStep * 2.0; - } - TRACK_END("renderUI:textures") - } -} void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); @@ -2127,6 +2084,50 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, lolo); } } +struct metadata { + Uniforms * uniforms; + const SceneRender* m_sceneRender; + const bool* m_postprocessing; + vera::Shader* m_plot_shader; + vera::Texture** m_plot_texture; + std::unique_ptr* m_cross_vbo; + const int* geom_index; + const bool* help; + const bool* verbose; +}; + +void overlay_m_showTextures(const metadata& muu) { + int nTotal = muu.uniforms->textures.size(); + if (nTotal > 0) { + glDisable(GL_DEPTH_TEST); + TRACK_BEGIN("renderUI:textures") + render_ui_t lolo; + lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; + lolo.xStep = lolo.w * lolo.scale; + lolo.yStep = lolo.h * lolo.scale; + lolo.xOffset = lolo.xStep; + lolo.yOffset = lolo.h - lolo.yStep; + + vera::textAngle(-HALF_PI); + vera::textAlign(vera::ALIGN_TOP); + vera::textAlign(vera::ALIGN_LEFT); + vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); + + for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { + vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); + if ( slit != muu.uniforms->streams.end() ) + vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, true); + else + vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); + + vera::text(it->first, lolo.xOffset + lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); + + lolo.yOffset -= lolo.yStep * 2.0; + } + TRACK_END("renderUI:textures") + } +} + void overlay_m_showPasses(const metadata& muu) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") From 58e75381bd9b9458b7f138d15f72ce17c2ed5b4d Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 17:35:37 +0100 Subject: [PATCH 13/76] moved render_ui_t to renderable_objects namespace --- src/core/sandbox.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 96fd11f5..82201281 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1945,7 +1945,9 @@ void Sandbox::renderPost() { if (vera::getWindowStyle() != vera::EMBEDDED) console_uniforms_refresh(); } + namespace { +namespace renderable_objects { struct render_ui_t { float w = (float)(vera::getWindowWidth()); @@ -1959,7 +1961,6 @@ struct render_ui_t { float x = (float)(vera::getWindowWidth()) * 0.5; float y = h + 10; }; -namespace renderable_objects { void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); From 0ea1d6d69f13f5eba50470ae28acaac3a226a121 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 17:38:43 +0100 Subject: [PATCH 14/76] rename struct-name to: overlay_fn_args_t --- src/core/sandbox.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 82201281..3f47466c 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2085,7 +2085,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, lolo); } } -struct metadata { +struct overlay_fn_args_t { Uniforms * uniforms; const SceneRender* m_sceneRender; const bool* m_postprocessing; @@ -2097,7 +2097,7 @@ struct metadata { const bool* verbose; }; -void overlay_m_showTextures(const metadata& muu) { +void overlay_m_showTextures(const overlay_fn_args_t& muu) { int nTotal = muu.uniforms->textures.size(); if (nTotal > 0) { glDisable(GL_DEPTH_TEST); @@ -2129,7 +2129,7 @@ void overlay_m_showTextures(const metadata& muu) { } } -void overlay_m_showPasses(const metadata& muu) { +void overlay_m_showPasses(const overlay_fn_args_t& muu) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") @@ -2156,7 +2156,7 @@ void overlay_m_showPasses(const metadata& muu) { TRACK_END("renderUI:buffers") }; -void overlay_m_plot(const metadata& muu) { +void overlay_m_plot(const overlay_fn_args_t& muu) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") @@ -2183,7 +2183,7 @@ void overlay_m_plot(const metadata& muu) { TRACK_END("renderUI:plot_data") } -void overlay_cursor(const metadata& muu) { +void overlay_cursor(const overlay_fn_args_t& muu) { TRACK_BEGIN("renderUI:cursor") if ((*muu.m_cross_vbo) == nullptr) (*muu.m_cross_vbo) = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); @@ -2196,7 +2196,7 @@ void overlay_cursor(const metadata& muu) { TRACK_END("renderUI:cursor") } -void overlay_prompt_drag_and_drop(const metadata&) { +void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t lolo; lolo.xStep = lolo.w * 0.05; lolo.yStep = lolo.h * 0.05; @@ -2224,7 +2224,7 @@ void overlay_prompt_drag_and_drop(const metadata&) { vera::setCamera(cam); } -void overlay_prompt_help(const metadata& muu) { +void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.xStep = lolo.w * 0.05; lolo.yStep = lolo.h * 0.05; @@ -2293,15 +2293,14 @@ void Sandbox::renderUI() { const auto diplay_cursor = cursor && vera::getMouseEntered(); const auto no_geometry_available = frag_index == -1 && vert_index == -1 && geom_index == -1; - struct vtable_metatadata_with_pred_t { - using function_sig_t = auto (*)(const renderable_objects::metadata&) -> void; + struct vtable_overlay_fn_args_with_pred_t { + using function_sig_t = auto (*)(const overlay_fn_args_t&) -> void; const bool predicate; const function_sig_t do_overlay_action; - const renderable_objects::metadata parameters; + const overlay_fn_args_t parameters; }; - - const std::array lala = { - vtable_metatadata_with_pred_t{m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + const std::array lala = { + vtable_overlay_fn_args_with_pred_t{m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {m_showPasses, &overlay_m_showPasses, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {display_m_plots, &overlay_m_plot, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} From 7f337fbdd79ce2c5c823e153a066b44aa0504ca4 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 17:41:42 +0100 Subject: [PATCH 15/76] rename struct-name to: help_prompt_t --- src/core/sandbox.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 3f47466c..579c7642 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2253,13 +2253,12 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { const auto geometry_available = *muu.geom_index != -1; const auto uniform_streams_available = muu.uniforms->streams.size() > 0; - struct kv_prompt { + struct help_prompt_t { bool predicate; std::string message; }; - const auto help_prompts = { - kv_prompt{geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} + help_prompt_t{geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} , {geometry_available, "b - " + std::string( muu.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} , {true, "c - hide/show cursor"} , {geometry_available, "d - " + std::string( muu.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} From 095606648bd89eed7fe77e309dcfb506b4c9a09d Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 17:44:16 +0100 Subject: [PATCH 16/76] rename struct-name to: num_of_passes_t --- src/core/sandbox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 579c7642..3513cc33 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2136,9 +2136,9 @@ void overlay_m_showPasses(const overlay_fn_args_t& muu) { // DEBUG BUFFERS const auto is_postprocessing_with_uniforms = muu.m_postprocessing && muu.uniforms->models.size() > 0; - using kv = std::pair; + using num_of_passes_t = std::pair; const auto nTotalArray = { - kv{true, muu.uniforms->buffers.size()} + num_of_passes_t{true, muu.uniforms->buffers.size()} , {true, muu.uniforms->doubleBuffers.size()} , {true, muu.uniforms->pyramids.size()} , {is_postprocessing_with_uniforms, 1} @@ -2149,7 +2149,7 @@ void overlay_m_showPasses(const overlay_fn_args_t& muu) { , {true, muu.m_sceneRender->getBuffersTotal()} }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} - , [](const int acc, const kv& kv) { return acc + ((kv.first) ? kv.second : 0); }); + , [](const int acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); if (nTotal > 0) { process_render_passes(*muu.uniforms, *muu.m_sceneRender, nTotal); } From 4658d4f52a3c26fe239bfec7cb3efe5e12436b46 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 17:49:27 +0100 Subject: [PATCH 17/76] rename typename to: render_pass_args_t rename struct-name to: vtable_render_pass_t strongtype render_pass_args_t renamed function-names to: do_pass_{*} added namespace: render_pass_actions --- src/core/sandbox.cpp | 57 ++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 3513cc33..c8928d79 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1981,30 +1981,33 @@ void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::s print_text(prompt + vera::toString(i), lolo.xOffset - scale.x, lolo); } -using renderer_process_info_t = std::tuple; +namespace render_pass_actions { +struct render_pass_args_t { + const vera::Fbo* const fbo; + const BuffersList* const fbolist; +}; -void do_something_00(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t& abc, render_ui_t& lolo) { +void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { if (uniforms.functions[prompt_id].present) { - print_fbo_text(*std::get<0>(abc), prompt_id, lolo); + print_fbo_text(*abc.fbo, prompt_id, lolo); } } -void do_something_01(const std::string& prompt_id, Uniforms& , const renderer_process_info_t& abc, render_ui_t& lolo) { - const auto& fbolist = *std::get<1>(abc); - for (size_t i = 0; i < fbolist.size(); i++) { - print_fbo_text(*fbolist[i], prompt_id, lolo); +void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& abc, render_ui_t& lolo) { + for (size_t i = 0; i < abc.fbolist->size(); i++) { + print_fbo_text(*(*abc.fbolist)[i], prompt_id, lolo); } } -void do_something_02(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t& abc, render_ui_t& lolo) { +void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { if (uniforms.functions[prompt_id].present) { if (uniforms.activeCamera) - vera::imageDepth(*std::get<0>(abc), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + vera::imageDepth(*abc.fbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); print_text(prompt_id, lolo.xOffset - lolo.xStep, lolo); } } -void do_something_lightmap(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { +void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { if (uniforms.models.size() > 0) { for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { if ( it->second->getShadowMap()->getDepthTextureId() ) { @@ -2016,7 +2019,7 @@ void do_something_lightmap(const std::string& prompt_id, Uniforms& uniforms, con } } -void do_something_pyramid(const std::string&, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { +void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { for (size_t i = 0; i < uniforms.pyramids.size(); i++) { glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); glm::vec2 scale = glm::vec2(lolo.yStep); @@ -2040,19 +2043,21 @@ void do_something_pyramid(const std::string&, Uniforms& uniforms, const renderer } } -void do_something_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { +void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, lolo); } } -void do_something_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const renderer_process_info_t&, render_ui_t& lolo) { +void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { for (size_t i = 0; i < uniforms.buffers.size(); i++) { print_buffers_text(*uniforms.buffers[i], i, prompt_id, lolo); } } +} // namespace [render_pass_actions] void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, int nTotal){ + using namespace render_pass_actions; render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; lolo.xStep = lolo.w * lolo.scale; @@ -2065,22 +2070,22 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, vera::textAlign(vera::ALIGN_BOTTOM); vera::textAlign(vera::ALIGN_LEFT); - struct vtable_kv_t{ - using func_sig_t = auto (*)(const std::string&, Uniforms&, const renderer_process_info_t&, render_ui_t&)-> void; + struct vtable_render_pass_t{ + using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void; const std::string prompt_id; - const renderer_process_info_t process_info; + const render_pass_args_t process_info; const func_sig_t process_renderer; }; - const std::array somelist { - vtable_kv_t{"u_buffer", {nullptr, nullptr}, do_something_singlebuffer} - , {"u_doubleBuffer", {nullptr, nullptr}, do_something_doublebuffers} - , {"u_pyramid0", {nullptr, nullptr}, do_something_pyramid} - , {"u_lightShadowMap", {nullptr, nullptr}, do_something_lightmap} - , {"u_scenePosition", {&m_sceneRender.positionFbo, nullptr}, do_something_00} - , {"u_sceneNormal", {&m_sceneRender.normalFbo, nullptr}, do_something_00} - , {"u_sceneBuffer", {nullptr, &m_sceneRender.buffersFbo}, do_something_01} - , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_something_00} - , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_something_02} + const std::array somelist { + vtable_render_pass_t{"u_buffer", {nullptr, nullptr}, do_pass_singlebuffer} + , {"u_doubleBuffer", {nullptr, nullptr}, do_pass_doublebuffers} + , {"u_pyramid0", {nullptr, nullptr}, do_pass_pyramid} + , {"u_lightShadowMap", {nullptr, nullptr}, do_pass_lightmap} + , {"u_scenePosition", {&m_sceneRender.positionFbo, nullptr}, do_pass_scene} + , {"u_sceneNormal", {&m_sceneRender.normalFbo, nullptr}, do_pass_scene} + , {"u_sceneBuffer", {nullptr, &m_sceneRender.buffersFbo}, do_pass_scenebuffer} + , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_pass_scene} + , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_pass_scenedepth} }; for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, lolo); } } From b8eff21ccba59931cbfe1fa67974714e07027677 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:54:04 +0100 Subject: [PATCH 18/76] added namespace: overlay_actions --- src/core/sandbox.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index c8928d79..bfdd1710 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2090,6 +2090,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, lolo); } } +namespace overlay_actions { struct overlay_fn_args_t { Uniforms * uniforms; const SceneRender* m_sceneRender; @@ -2285,13 +2286,13 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { vera::setCamera(cam); glDisable(GL_DEPTH_TEST); } +} // namespace [overlay_actions] } - } void Sandbox::renderUI() { TRACK_BEGIN("renderUI") - using namespace renderable_objects; + using namespace renderable_objects::overlay_actions; const auto display_m_plots = m_plot != PLOT_OFF && m_plot_texture ; const auto diplay_cursor = cursor && vera::getMouseEntered(); From 06d202971c7590c26ad463d5bddf96feed564745 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:55:13 +0100 Subject: [PATCH 19/76] added label for: end-of-anon-namespace, renderable_objects --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index bfdd1710..717f8944 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2287,8 +2287,8 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { glDisable(GL_DEPTH_TEST); } } // namespace [overlay_actions] -} -} +} // namespace [renderable_objects] +} // namespace [_] void Sandbox::renderUI() { TRACK_BEGIN("renderUI") From c2e4ba2e1b54bd0ea94d74baa6009ce69dc54e60 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 21:37:34 +0100 Subject: [PATCH 20/76] added set_common_text_attributes --- src/core/sandbox.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 717f8944..1d171470 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2056,6 +2056,13 @@ void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, cons } } // namespace [render_pass_actions] +void set_common_text_attributes(float textangle, float textsize, vera::VerticalAlign v, vera::HorizontalAlign h){ + vera::textAngle(textangle); + vera::textSize(textsize); + vera::textAlign(v); + vera::textAlign(h); +} + void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, int nTotal){ using namespace render_pass_actions; render_ui_t lolo; @@ -2065,10 +2072,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, lolo.xOffset = lolo.w - lolo.xStep; lolo.yOffset = lolo.h - lolo.yStep; - vera::textAngle(-HALF_PI); - vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); - vera::textAlign(vera::ALIGN_BOTTOM); - vera::textAlign(vera::ALIGN_LEFT); + set_common_text_attributes(-HALF_PI, lolo.yStep * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); struct vtable_render_pass_t{ using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void; @@ -2115,10 +2119,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { lolo.xOffset = lolo.xStep; lolo.yOffset = lolo.h - lolo.yStep; - vera::textAngle(-HALF_PI); - vera::textAlign(vera::ALIGN_TOP); - vera::textAlign(vera::ALIGN_LEFT); - vera::textSize(lolo.yStep * 0.2f / vera::getPixelDensity(false)); + set_common_text_attributes(-HALF_PI, lolo.yStep * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); @@ -2217,11 +2218,8 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); vera::fill(1.0f); - vera::textAlign(vera::ALIGN_MIDDLE); - vera::textAlign(vera::ALIGN_CENTER); - vera::textAngle(0.0f); + set_common_text_attributes(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER); - vera::textSize(38.0f); vera::text("Drag & Drop", lolo.w * 0.5f, lolo.h * 0.45f); vera::textSize(22.0f); @@ -2245,10 +2243,8 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); vera::fill(1.0f); - vera::textAlign(vera::ALIGN_MIDDLE); - vera::textAlign(vera::ALIGN_LEFT); - vera::textAngle(0.0f); - vera::textSize(22.0f); + set_common_text_attributes(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT); + lolo.yStep = vera::getFontHeight() * 1.5f; const auto print_text = [&](const std::string& prompt){ From 2eea67c7693a022ff3fbb8df6aa1acb34d6bb170 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 23:22:22 +0100 Subject: [PATCH 21/76] make num_of_passes_t ordering match vtable_render_pass_t --- src/core/sandbox.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 1d171470..de8c842d 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2145,15 +2145,15 @@ void overlay_m_showPasses(const overlay_fn_args_t& muu) { && muu.uniforms->models.size() > 0; using num_of_passes_t = std::pair; const auto nTotalArray = { - num_of_passes_t{true, muu.uniforms->buffers.size()} - , {true, muu.uniforms->doubleBuffers.size()} - , {true, muu.uniforms->pyramids.size()} - , {is_postprocessing_with_uniforms, 1} - , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_scene"].present} - , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_sceneDepth"].present} - , {true, muu.uniforms->functions["u_sceneNormal"].present} + num_of_passes_t{true, muu.uniforms->buffers.size()} //buffer + , {true, muu.uniforms->doubleBuffers.size()} // doublebuffer + , {true, muu.uniforms->pyramids.size()} //pyramid + , {is_postprocessing_with_uniforms, 1} // lightmap , {true, muu.uniforms->functions["u_scenePosition"].present} + , {true, muu.uniforms->functions["u_sceneNormal"].present} , {true, muu.m_sceneRender->getBuffersTotal()} + , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_scene"].present} + , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_sceneDepth"].present} }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const int acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); From 9123cdc7e76f2101ed8933e66b39ce1687f978c9 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 18 Dec 2022 23:56:39 +0100 Subject: [PATCH 22/76] removed unneeded whitespacing --- src/core/sandbox.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index de8c842d..a7c9c9c8 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1948,7 +1948,6 @@ void Sandbox::renderPost() { namespace { namespace renderable_objects { - struct render_ui_t { float w = (float)(vera::getWindowWidth()); float h = (float)(vera::getWindowHeight()); @@ -1988,15 +1987,13 @@ struct render_pass_args_t { }; void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { - if (uniforms.functions[prompt_id].present) { + if (uniforms.functions[prompt_id].present) print_fbo_text(*abc.fbo, prompt_id, lolo); - } } void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& abc, render_ui_t& lolo) { - for (size_t i = 0; i < abc.fbolist->size(); i++) { + for (size_t i = 0; i < abc.fbolist->size(); i++) print_fbo_text(*(*abc.fbolist)[i], prompt_id, lolo); - } } void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { @@ -2029,10 +2026,8 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; - vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; - std::tie(scale, offset.y) = is_lower_depth ? std::pair{scale *= 0.5, lolo.yOffset - lolo.yStep * 0.5} : std::pair{scale *= 2.0, lolo.yOffset + lolo.yStep * 0.5}; @@ -2044,15 +2039,13 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a } void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { - for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) { + for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, lolo); - } } void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { - for (size_t i = 0; i < uniforms.buffers.size(); i++) { + for (size_t i = 0; i < uniforms.buffers.size(); i++) print_buffers_text(*uniforms.buffers[i], i, prompt_id, lolo); - } } } // namespace [render_pass_actions] @@ -2127,9 +2120,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, true); else vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - vera::text(it->first, lolo.xOffset + lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; } TRACK_END("renderUI:textures") @@ -2216,12 +2207,9 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); - vera::fill(1.0f); set_common_text_attributes(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER); - vera::text("Drag & Drop", lolo.w * 0.5f, lolo.h * 0.45f); - vera::textSize(22.0f); vera::text(".vert .frag .ply .lst .obj .gltf .glb", lolo.w * 0.5f, lolo.h * 0.55f); @@ -2241,7 +2229,6 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); - vera::fill(1.0f); set_common_text_attributes(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT); From ba88a7ac8b42a66c935d748508b3de60144384dd Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:24:41 +0100 Subject: [PATCH 23/76] align table data --- src/core/sandbox.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index a7c9c9c8..93c76d80 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2073,8 +2073,8 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, const render_pass_args_t process_info; const func_sig_t process_renderer; }; - const std::array somelist { - vtable_render_pass_t{"u_buffer", {nullptr, nullptr}, do_pass_singlebuffer} + const std::array somelist { vtable_render_pass_t + {"u_buffer", {nullptr, nullptr}, do_pass_singlebuffer} , {"u_doubleBuffer", {nullptr, nullptr}, do_pass_doublebuffers} , {"u_pyramid0", {nullptr, nullptr}, do_pass_pyramid} , {"u_lightShadowMap", {nullptr, nullptr}, do_pass_lightmap} @@ -2135,8 +2135,8 @@ void overlay_m_showPasses(const overlay_fn_args_t& muu) { const auto is_postprocessing_with_uniforms = muu.m_postprocessing && muu.uniforms->models.size() > 0; using num_of_passes_t = std::pair; - const auto nTotalArray = { - num_of_passes_t{true, muu.uniforms->buffers.size()} //buffer + const auto nTotalArray = { num_of_passes_t + {true, muu.uniforms->buffers.size()} //buffer , {true, muu.uniforms->doubleBuffers.size()} // doublebuffer , {true, muu.uniforms->pyramids.size()} //pyramid , {is_postprocessing_with_uniforms, 1} // lightmap @@ -2246,8 +2246,8 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { bool predicate; std::string message; }; - const auto help_prompts = { - help_prompt_t{geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} + const auto help_prompts = { help_prompt_t + {geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} , {geometry_available, "b - " + std::string( muu.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} , {true, "c - hide/show cursor"} , {geometry_available, "d - " + std::string( muu.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} @@ -2287,8 +2287,8 @@ void Sandbox::renderUI() { const function_sig_t do_overlay_action; const overlay_fn_args_t parameters; }; - const std::array lala = { - vtable_overlay_fn_args_with_pred_t{m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + const std::array lala = { vtable_overlay_fn_args_with_pred_t + {m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {m_showPasses, &overlay_m_showPasses, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {display_m_plots, &overlay_m_plot, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} From 88569e87ed9e868605ba894b14c998fc44b12a32 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:34:01 +0100 Subject: [PATCH 24/76] prefer glm::vec2 datatype for: step --- src/core/sandbox.cpp | 89 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 93c76d80..aaa9fa61 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1952,30 +1952,29 @@ struct render_ui_t { float w = (float)(vera::getWindowWidth()); float h = (float)(vera::getWindowHeight()); float scale = 1; - float xStep = w * scale; - float yStep = h * scale; - float xOffset = w - xStep; - float yOffset = h - yStep; + glm::vec2 step = {w * scale, h * scale}; + float xOffset = w - step.x; + float yOffset = h - step.y; float p = vera::getPixelDensity(); float x = (float)(vera::getWindowWidth()) * 0.5; float y = h + 10; }; void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { - vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.step.y); + lolo.yOffset -= lolo.step.y * 2.0; } void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_t& lolo) { - vera::image(&lala, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - print_text(prompt, lolo.xOffset - lolo.xStep, lolo); + vera::image(&lala, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y); + print_text(prompt, lolo.xOffset - lolo.step.x, lolo); } void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& lolo) { glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); - glm::vec2 scale = glm::vec2(lolo.yStep); + glm::vec2 scale = glm::vec2(lolo.step.y); scale.x *= ((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()); - offset.x += lolo.xStep - scale.x; + offset.x += lolo.step.x - scale.x; vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); print_text(prompt + vera::toString(i), lolo.xOffset - scale.x, lolo); } @@ -1999,8 +1998,8 @@ void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_ void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { if (uniforms.functions[prompt_id].present) { if (uniforms.activeCamera) - vera::imageDepth(*abc.fbo, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - print_text(prompt_id, lolo.xOffset - lolo.xStep, lolo); + vera::imageDepth(*abc.fbo, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + print_text(prompt_id, lolo.xOffset - lolo.step.x, lolo); } } @@ -2008,9 +2007,9 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re if (uniforms.models.size() > 0) { for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { if ( it->second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, it->second->getShadowMapFar(), it->second->getShadowMapNear()); + vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y, it->second->getShadowMapFar(), it->second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - print_text(prompt_id, lolo.xOffset - lolo.xStep, lolo); + print_text(prompt_id, lolo.xOffset - lolo.step.x, lolo); } } } @@ -2019,22 +2018,22 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { for (size_t i = 0; i < uniforms.pyramids.size(); i++) { glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); - glm::vec2 scale = glm::vec2(lolo.yStep); + glm::vec2 scale = glm::vec2(lolo.step.y); scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); float w = scale.x; - offset.x += lolo.xStep - w; + offset.x += lolo.step.x - w; for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; std::tie(scale, offset.y) = is_lower_depth - ? std::pair{scale *= 0.5, lolo.yOffset - lolo.yStep * 0.5} - : std::pair{scale *= 2.0, lolo.yOffset + lolo.yStep * 0.5}; + ? std::pair{scale *= 0.5, lolo.yOffset - lolo.step.y * 0.5} + : std::pair{scale *= 2.0, lolo.yOffset + lolo.step.y * 0.5}; offset.x -= scale.x; } // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); - lolo.yOffset -= lolo.yStep * 2.0; + lolo.yOffset -= lolo.step.y * 2.0; } } @@ -2060,12 +2059,12 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, using namespace render_pass_actions; render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.xStep = lolo.w * lolo.scale; - lolo.yStep = lolo.h * lolo.scale; - lolo.xOffset = lolo.w - lolo.xStep; - lolo.yOffset = lolo.h - lolo.yStep; + lolo.step.x = lolo.w * lolo.scale; + lolo.step.y = lolo.h * lolo.scale; + lolo.xOffset = lolo.w - lolo.step.x; + lolo.yOffset = lolo.h - lolo.step.y; - set_common_text_attributes(-HALF_PI, lolo.yStep * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); + set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); struct vtable_render_pass_t{ using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void; @@ -2107,21 +2106,21 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { TRACK_BEGIN("renderUI:textures") render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.xStep = lolo.w * lolo.scale; - lolo.yStep = lolo.h * lolo.scale; - lolo.xOffset = lolo.xStep; - lolo.yOffset = lolo.h - lolo.yStep; + lolo.step.x = lolo.w * lolo.scale; + lolo.step.y = lolo.h * lolo.scale; + lolo.xOffset = lolo.step.x; + lolo.yOffset = lolo.h - lolo.step.y; - set_common_text_attributes(-HALF_PI, lolo.yStep * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); + set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); if ( slit != muu.uniforms->streams.end() ) - vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep, true); + vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y, true); else - vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.xStep, lolo.yStep); - vera::text(it->first, lolo.xOffset + lolo.xStep, vera::getWindowHeight() - lolo.yOffset + lolo.yStep); - lolo.yOffset -= lolo.yStep * 2.0; + vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y); + vera::text(it->first, lolo.xOffset + lolo.step.x, vera::getWindowHeight() - lolo.yOffset + lolo.step.y); + lolo.yOffset -= lolo.step.y * 2.0; } TRACK_END("renderUI:textures") } @@ -2196,17 +2195,17 @@ void overlay_cursor(const overlay_fn_args_t& muu) { void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t lolo; - lolo.xStep = lolo.w * 0.05; - lolo.yStep = lolo.h * 0.05; - lolo.x = lolo.xStep * 2.0f; - lolo.y = lolo.yStep * 3.0f; + lolo.step.x = lolo.w * 0.05; + lolo.step.y = lolo.h * 0.05; + lolo.x = lolo.step.x * 2.0f; + lolo.y = lolo.step.y * 3.0f; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); - vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); + vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.step.x * 2.0f, lolo.h - lolo.step.y * 2.0f)); vera::fill(1.0f); set_common_text_attributes(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER); vera::text("Drag & Drop", lolo.w * 0.5f, lolo.h * 0.45f); @@ -2218,25 +2217,25 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; - lolo.xStep = lolo.w * 0.05; - lolo.yStep = lolo.h * 0.05; - lolo.x = lolo.xStep * 2.0f; - lolo.y = lolo.yStep * 3.0f; + lolo.step.x = lolo.w * 0.05; + lolo.step.y = lolo.h * 0.05; + lolo.x = lolo.step.x * 2.0f; + lolo.y = lolo.step.y * 3.0f; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); - vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.xStep * 2.0f, lolo.h - lolo.yStep * 2.0f)); + vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.step.x * 2.0f, lolo.h - lolo.step.y * 2.0f)); vera::fill(1.0f); set_common_text_attributes(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT); - lolo.yStep = vera::getFontHeight() * 1.5f; + lolo.step.y = vera::getFontHeight() * 1.5f; const auto print_text = [&](const std::string& prompt){ vera::text(prompt, lolo.x, lolo.y); - lolo.y += lolo.yStep; + lolo.y += lolo.step.y; }; const auto geometry_available = *muu.geom_index != -1; From 59f895b82e1b8d57bc244ff7079ad3f330f5cf5f Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:35:29 +0100 Subject: [PATCH 25/76] prefer glm::vec2 datatype for: offset --- src/core/sandbox.cpp | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index aaa9fa61..f1679d93 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1953,30 +1953,29 @@ struct render_ui_t { float h = (float)(vera::getWindowHeight()); float scale = 1; glm::vec2 step = {w * scale, h * scale}; - float xOffset = w - step.x; - float yOffset = h - step.y; + glm::vec2 offset = {w - step.x, h - step.y}; float p = vera::getPixelDensity(); float x = (float)(vera::getWindowWidth()) * 0.5; float y = h + 10; }; void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { - vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.yOffset + lolo.step.y); - lolo.yOffset -= lolo.step.y * 2.0; + vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.offset.y + lolo.step.y); + lolo.offset.y -= lolo.step.y * 2.0; } void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_t& lolo) { - vera::image(&lala, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y); - print_text(prompt, lolo.xOffset - lolo.step.x, lolo); + vera::image(&lala, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); + print_text(prompt, lolo.offset.x - lolo.step.x, lolo); } void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& lolo) { - glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 offset = glm::vec2(lolo.offset.x, lolo.offset.y); glm::vec2 scale = glm::vec2(lolo.step.y); scale.x *= ((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()); offset.x += lolo.step.x - scale.x; vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); - print_text(prompt + vera::toString(i), lolo.xOffset - scale.x, lolo); + print_text(prompt + vera::toString(i), lolo.offset.x - scale.x, lolo); } namespace render_pass_actions { @@ -1998,8 +1997,8 @@ void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_ void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { if (uniforms.functions[prompt_id].present) { if (uniforms.activeCamera) - vera::imageDepth(*abc.fbo, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - print_text(prompt_id, lolo.xOffset - lolo.step.x, lolo); + vera::imageDepth(*abc.fbo, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + print_text(prompt_id, lolo.offset.x - lolo.step.x, lolo); } } @@ -2007,9 +2006,9 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re if (uniforms.models.size() > 0) { for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { if ( it->second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it->second->getShadowMap(), lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y, it->second->getShadowMapFar(), it->second->getShadowMapNear()); + vera::imageDepth(it->second->getShadowMap(), lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, it->second->getShadowMapFar(), it->second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - print_text(prompt_id, lolo.xOffset - lolo.step.x, lolo); + print_text(prompt_id, lolo.offset.x - lolo.step.x, lolo); } } } @@ -2017,7 +2016,7 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { for (size_t i = 0; i < uniforms.pyramids.size(); i++) { - glm::vec2 offset = glm::vec2(lolo.xOffset, lolo.yOffset); + glm::vec2 offset = glm::vec2(lolo.offset.x, lolo.offset.y); glm::vec2 scale = glm::vec2(lolo.step.y); scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); float w = scale.x; @@ -2028,12 +2027,12 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; std::tie(scale, offset.y) = is_lower_depth - ? std::pair{scale *= 0.5, lolo.yOffset - lolo.step.y * 0.5} - : std::pair{scale *= 2.0, lolo.yOffset + lolo.step.y * 0.5}; + ? std::pair{scale *= 0.5, lolo.offset.y - lolo.step.y * 0.5} + : std::pair{scale *= 2.0, lolo.offset.y + lolo.step.y * 0.5}; offset.x -= scale.x; } // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); - lolo.yOffset -= lolo.step.y * 2.0; + lolo.offset.y -= lolo.step.y * 2.0; } } @@ -2061,8 +2060,8 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; lolo.step.x = lolo.w * lolo.scale; lolo.step.y = lolo.h * lolo.scale; - lolo.xOffset = lolo.w - lolo.step.x; - lolo.yOffset = lolo.h - lolo.step.y; + lolo.offset.x = lolo.w - lolo.step.x; + lolo.offset.y = lolo.h - lolo.step.y; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); @@ -2108,19 +2107,19 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; lolo.step.x = lolo.w * lolo.scale; lolo.step.y = lolo.h * lolo.scale; - lolo.xOffset = lolo.step.x; - lolo.yOffset = lolo.h - lolo.step.y; + lolo.offset.x = lolo.step.x; + lolo.offset.y = lolo.h - lolo.step.y; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); if ( slit != muu.uniforms->streams.end() ) - vera::image((vera::TextureStream*)slit->second, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y, true); + vera::image((vera::TextureStream*)slit->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, true); else - vera::image(it->second, lolo.xOffset, lolo.yOffset, lolo.step.x, lolo.step.y); - vera::text(it->first, lolo.xOffset + lolo.step.x, vera::getWindowHeight() - lolo.yOffset + lolo.step.y); - lolo.yOffset -= lolo.step.y * 2.0; + vera::image(it->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); + vera::text(it->first, lolo.offset.x + lolo.step.x, vera::getWindowHeight() - lolo.offset.y + lolo.step.y); + lolo.offset.y -= lolo.step.y * 2.0; } TRACK_END("renderUI:textures") } From ece6cc5f06eddcc9d2bd869cbb4dae52fe829e12 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:48:17 +0100 Subject: [PATCH 26/76] prefer glm::vec2 datatype for: pos --- src/core/sandbox.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index f1679d93..4258f9b6 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1955,8 +1955,7 @@ struct render_ui_t { glm::vec2 step = {w * scale, h * scale}; glm::vec2 offset = {w - step.x, h - step.y}; float p = vera::getPixelDensity(); - float x = (float)(vera::getWindowWidth()) * 0.5; - float y = h + 10; + glm::vec2 pos = {w * 0.5, h + 10}; }; void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { @@ -2160,12 +2159,12 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { lolo.p = vera::getPixelDensity(); lolo.w = 100 * lolo.p; lolo.h = 30 * lolo.p; - lolo.x = (float)(vera::getWindowWidth()) * 0.5; - lolo.y = lolo.h + 10; + lolo.pos.x = (float)(vera::getWindowWidth()) * 0.5; + lolo.pos.y = lolo.h + 10; muu.m_plot_shader->use(); muu.m_plot_shader->setUniform("u_scale", lolo.w, lolo.h); - muu.m_plot_shader->setUniform("u_translate", lolo.x, lolo.y); + muu.m_plot_shader->setUniform("u_translate", lolo.pos.x, lolo.pos.y); muu.m_plot_shader->setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); muu.m_plot_shader->setUniform("u_viewport", lolo.w, lolo.h); muu.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); @@ -2196,8 +2195,8 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t lolo; lolo.step.x = lolo.w * 0.05; lolo.step.y = lolo.h * 0.05; - lolo.x = lolo.step.x * 2.0f; - lolo.y = lolo.step.y * 3.0f; + lolo.pos.x = lolo.step.x * 2.0f; + lolo.pos.y = lolo.step.y * 3.0f; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); @@ -2218,8 +2217,8 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.step.x = lolo.w * 0.05; lolo.step.y = lolo.h * 0.05; - lolo.x = lolo.step.x * 2.0f; - lolo.y = lolo.step.y * 3.0f; + lolo.pos.x = lolo.step.x * 2.0f; + lolo.pos.y = lolo.step.y * 3.0f; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); @@ -2233,8 +2232,8 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { lolo.step.y = vera::getFontHeight() * 1.5f; const auto print_text = [&](const std::string& prompt){ - vera::text(prompt, lolo.x, lolo.y); - lolo.y += lolo.step.y; + vera::text(prompt, lolo.pos.x, lolo.pos.y); + lolo.pos.y += lolo.step.y; }; const auto geometry_available = *muu.geom_index != -1; From e8bfb5a6b7ed38e6882e998351c57020d5a6f3df Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:56:34 +0100 Subject: [PATCH 27/76] condense initialisation of render_ui_t: w, h --- src/core/sandbox.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 4258f9b6..29ecfb1d 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2157,8 +2157,7 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.p = vera::getPixelDensity(); - lolo.w = 100 * lolo.p; - lolo.h = 30 * lolo.p; + std::tie(lolo.w, lolo.h) = std::pair{100 * lolo.p, 30 * lolo.p}; lolo.pos.x = (float)(vera::getWindowWidth()) * 0.5; lolo.pos.y = lolo.h + 10; From 97397da9ddb0f9eb6965a77cc79bf758b75a54e1 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:59:58 +0100 Subject: [PATCH 28/76] condense initialisation of render_ui_t: pos --- src/core/sandbox.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 29ecfb1d..b64332a5 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2158,8 +2158,7 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.p = vera::getPixelDensity(); std::tie(lolo.w, lolo.h) = std::pair{100 * lolo.p, 30 * lolo.p}; - lolo.pos.x = (float)(vera::getWindowWidth()) * 0.5; - lolo.pos.y = lolo.h + 10; + lolo.pos = {(float)(vera::getWindowWidth()) * 0.5, lolo.h + 10}; muu.m_plot_shader->use(); muu.m_plot_shader->setUniform("u_scale", lolo.w, lolo.h); @@ -2194,8 +2193,7 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t lolo; lolo.step.x = lolo.w * 0.05; lolo.step.y = lolo.h * 0.05; - lolo.pos.x = lolo.step.x * 2.0f; - lolo.pos.y = lolo.step.y * 3.0f; + lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); @@ -2216,8 +2214,7 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.step.x = lolo.w * 0.05; lolo.step.y = lolo.h * 0.05; - lolo.pos.x = lolo.step.x * 2.0f; - lolo.pos.y = lolo.step.y * 3.0f; + lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); From 85e5dea8a67230f88c0e58225fd86da2e2b5b2d3 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 01:03:41 +0100 Subject: [PATCH 29/76] condense initialisation of render_ui_t: step --- src/core/sandbox.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index b64332a5..d2833a22 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2057,8 +2057,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, using namespace render_pass_actions; render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step.x = lolo.w * lolo.scale; - lolo.step.y = lolo.h * lolo.scale; + lolo.step = {lolo.w * lolo.scale, lolo.h * lolo.scale}; lolo.offset.x = lolo.w - lolo.step.x; lolo.offset.y = lolo.h - lolo.step.y; @@ -2104,8 +2103,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { TRACK_BEGIN("renderUI:textures") render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step.x = lolo.w * lolo.scale; - lolo.step.y = lolo.h * lolo.scale; + lolo.step = {lolo.w * lolo.scale, lolo.h * lolo.scale}; lolo.offset.x = lolo.step.x; lolo.offset.y = lolo.h - lolo.step.y; @@ -2191,8 +2189,7 @@ void overlay_cursor(const overlay_fn_args_t& muu) { void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t lolo; - lolo.step.x = lolo.w * 0.05; - lolo.step.y = lolo.h * 0.05; + lolo.step = {lolo.w * 0.05, lolo.h * 0.05}; lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; vera::Camera *cam = vera::getCamera(); @@ -2212,8 +2209,7 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; - lolo.step.x = lolo.w * 0.05; - lolo.step.y = lolo.h * 0.05; + lolo.step = {lolo.w * 0.05, lolo.h * 0.05}; lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; vera::Camera *cam = vera::getCamera(); From 005986f33f55f83f7a86c70e4af92e0926d4cb5a Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 01:06:08 +0100 Subject: [PATCH 30/76] condense initialisation of render_ui_t: offset --- src/core/sandbox.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index d2833a22..9c519936 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2058,8 +2058,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; lolo.step = {lolo.w * lolo.scale, lolo.h * lolo.scale}; - lolo.offset.x = lolo.w - lolo.step.x; - lolo.offset.y = lolo.h - lolo.step.y; + lolo.offset = {lolo.w - lolo.step.x, lolo.h - lolo.step.y}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); @@ -2104,8 +2103,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; lolo.step = {lolo.w * lolo.scale, lolo.h * lolo.scale}; - lolo.offset.x = lolo.step.x; - lolo.offset.y = lolo.h - lolo.step.y; + lolo.offset = {lolo.step.x, lolo.h - lolo.step.y}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); From 09c6d702488e73139c1b9789f5fa02e6b573ab4d Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 19 Dec 2022 23:29:19 +0100 Subject: [PATCH 31/76] prefer glm::vec2 datatype for: {w,h} --- src/core/sandbox.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 9c519936..79950418 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1949,13 +1949,12 @@ void Sandbox::renderPost() { namespace { namespace renderable_objects { struct render_ui_t { - float w = (float)(vera::getWindowWidth()); - float h = (float)(vera::getWindowHeight()); + glm::vec2 dimensions = {vera::getWindowWidth(), vera::getWindowHeight()}; float scale = 1; - glm::vec2 step = {w * scale, h * scale}; - glm::vec2 offset = {w - step.x, h - step.y}; + glm::vec2 step = {dimensions.x * scale, dimensions.y * scale}; + glm::vec2 offset = {dimensions.x - step.x, dimensions.y - step.y}; float p = vera::getPixelDensity(); - glm::vec2 pos = {w * 0.5, h + 10}; + glm::vec2 pos = {dimensions.x * 0.5, dimensions.y + 10}; }; void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { @@ -2057,8 +2056,8 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, using namespace render_pass_actions; render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step = {lolo.w * lolo.scale, lolo.h * lolo.scale}; - lolo.offset = {lolo.w - lolo.step.x, lolo.h - lolo.step.y}; + lolo.step = {lolo.dimensions.x * lolo.scale, lolo.dimensions.y * lolo.scale}; + lolo.offset = {lolo.dimensions.x - lolo.step.x, lolo.dimensions.y - lolo.step.y}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); @@ -2102,8 +2101,8 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { TRACK_BEGIN("renderUI:textures") render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step = {lolo.w * lolo.scale, lolo.h * lolo.scale}; - lolo.offset = {lolo.step.x, lolo.h - lolo.step.y}; + lolo.step = {lolo.dimensions.x * lolo.scale, lolo.dimensions.y * lolo.scale}; + lolo.offset = {lolo.step.x, lolo.dimensions.y - lolo.step.y}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); @@ -2153,14 +2152,14 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { render_ui_t lolo; lolo.p = vera::getPixelDensity(); - std::tie(lolo.w, lolo.h) = std::pair{100 * lolo.p, 30 * lolo.p}; - lolo.pos = {(float)(vera::getWindowWidth()) * 0.5, lolo.h + 10}; + std::tie(lolo.dimensions.x, lolo.dimensions.y) = std::pair{100 * lolo.p, 30 * lolo.p}; + lolo.pos = {(float)(vera::getWindowWidth()) * 0.5, lolo.dimensions.y + 10}; muu.m_plot_shader->use(); - muu.m_plot_shader->setUniform("u_scale", lolo.w, lolo.h); + muu.m_plot_shader->setUniform("u_scale", lolo.dimensions.x, lolo.dimensions.y); muu.m_plot_shader->setUniform("u_translate", lolo.pos.x, lolo.pos.y); muu.m_plot_shader->setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); - muu.m_plot_shader->setUniform("u_viewport", lolo.w, lolo.h); + muu.m_plot_shader->setUniform("u_viewport", lolo.dimensions.x, lolo.dimensions.y); muu.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); muu.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); muu.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); @@ -2187,7 +2186,7 @@ void overlay_cursor(const overlay_fn_args_t& muu) { void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t lolo; - lolo.step = {lolo.w * 0.05, lolo.h * 0.05}; + lolo.step = {lolo.dimensions.x * 0.05, lolo.dimensions.y * 0.05}; lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; vera::Camera *cam = vera::getCamera(); @@ -2195,19 +2194,19 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); - vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.step.x * 2.0f, lolo.h - lolo.step.y * 2.0f)); + vera::rect(glm::vec2(lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.5f), glm::vec2(lolo.dimensions.x - lolo.step.x * 2.0f, lolo.dimensions.y - lolo.step.y * 2.0f)); vera::fill(1.0f); set_common_text_attributes(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER); - vera::text("Drag & Drop", lolo.w * 0.5f, lolo.h * 0.45f); + vera::text("Drag & Drop", lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.45f); vera::textSize(22.0f); - vera::text(".vert .frag .ply .lst .obj .gltf .glb", lolo.w * 0.5f, lolo.h * 0.55f); + vera::text(".vert .frag .ply .lst .obj .gltf .glb", lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.55f); vera::setCamera(cam); } void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; - lolo.step = {lolo.w * 0.05, lolo.h * 0.05}; + lolo.step = {lolo.dimensions.x * 0.05, lolo.dimensions.y * 0.05}; lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; vera::Camera *cam = vera::getCamera(); @@ -2215,7 +2214,7 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); - vera::rect(glm::vec2(lolo.w * 0.5f, lolo.h * 0.5f), glm::vec2(lolo.w - lolo.step.x * 2.0f, lolo.h - lolo.step.y * 2.0f)); + vera::rect(glm::vec2(lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.5f), glm::vec2(lolo.dimensions.x - lolo.step.x * 2.0f, lolo.dimensions.y - lolo.step.y * 2.0f)); vera::fill(1.0f); set_common_text_attributes(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT); From a8c1f6b6c4e66f12e3f3812b83bd6f5affe06f27 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Tue, 20 Dec 2022 00:13:43 +0100 Subject: [PATCH 32/76] added overlay_black_box --- src/core/sandbox.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 79950418..334d0b30 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2184,8 +2184,7 @@ void overlay_cursor(const overlay_fn_args_t& muu) { TRACK_END("renderUI:cursor") } -void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { - render_ui_t lolo; +vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalAlign v, vera::HorizontalAlign h, render_ui_t& lolo) { lolo.step = {lolo.dimensions.x * 0.05, lolo.dimensions.y * 0.05}; lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; @@ -2196,7 +2195,14 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { vera::noStroke(); vera::rect(glm::vec2(lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.5f), glm::vec2(lolo.dimensions.x - lolo.step.x * 2.0f, lolo.dimensions.y - lolo.step.y * 2.0f)); vera::fill(1.0f); - set_common_text_attributes(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER); + set_common_text_attributes(textangle, textsize, v, h); + return cam; +} + +void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { + render_ui_t lolo; + vera::Camera *cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, lolo); + vera::text("Drag & Drop", lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.45f); vera::textSize(22.0f); vera::text(".vert .frag .ply .lst .obj .gltf .glb", lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.55f); @@ -2206,18 +2212,7 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { void overlay_prompt_help(const overlay_fn_args_t& muu) { render_ui_t lolo; - lolo.step = {lolo.dimensions.x * 0.05, lolo.dimensions.y * 0.05}; - lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; - - vera::Camera *cam = vera::getCamera(); - vera::resetCamera(); - - vera::fill(0.0f, 0.0f, 0.0f, 0.75f); - vera::noStroke(); - vera::rect(glm::vec2(lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.5f), glm::vec2(lolo.dimensions.x - lolo.step.x * 2.0f, lolo.dimensions.y - lolo.step.y * 2.0f)); - vera::fill(1.0f); - set_common_text_attributes(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT); - + vera::Camera *cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, lolo); lolo.step.y = vera::getFontHeight() * 1.5f; const auto print_text = [&](const std::string& prompt){ From a2215c28748cf57a4c68ce5a534f2ed1fe28c1f3 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 21 Dec 2022 00:34:11 +0100 Subject: [PATCH 33/76] simplify mathematical equations --- src/core/sandbox.cpp | 51 ++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 334d0b30..26259655 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1951,10 +1951,10 @@ namespace renderable_objects { struct render_ui_t { glm::vec2 dimensions = {vera::getWindowWidth(), vera::getWindowHeight()}; float scale = 1; - glm::vec2 step = {dimensions.x * scale, dimensions.y * scale}; - glm::vec2 offset = {dimensions.x - step.x, dimensions.y - step.y}; + glm::vec2 step = dimensions * scale; + glm::vec2 offset = dimensions - step; float p = vera::getPixelDensity(); - glm::vec2 pos = {dimensions.x * 0.5, dimensions.y + 10}; + glm::vec2 pos = dimensions * glm::vec2{0.5, 1} + glm::vec2{0, 10}; }; void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { @@ -1968,12 +1968,10 @@ void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_ } void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& lolo) { - glm::vec2 offset = glm::vec2(lolo.offset.x, lolo.offset.y); - glm::vec2 scale = glm::vec2(lolo.step.y); - scale.x *= ((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()); - offset.x += lolo.step.x - scale.x; - vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); - print_text(prompt + vera::toString(i), lolo.offset.x - scale.x, lolo); + glm::vec2 scale = lolo.step.y * glm::vec2{((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()), 1}; + glm::vec2 offset = lolo.offset + glm::vec2{lolo.step.x - scale.x, 0}; + vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); + print_text(prompt + vera::toString(i), lolo.offset.x - scale.x, lolo); } namespace render_pass_actions { @@ -2014,11 +2012,9 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { for (size_t i = 0; i < uniforms.pyramids.size(); i++) { - glm::vec2 offset = glm::vec2(lolo.offset.x, lolo.offset.y); - glm::vec2 scale = glm::vec2(lolo.step.y); - scale.x *= ((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()); - float w = scale.x; - offset.x += lolo.step.x - w; + glm::vec2 scale = lolo.step.y * glm::vec2{((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()), 1}; + glm::vec2 offset = lolo.offset + glm::vec2{lolo.step.x - scale.x, 0}; + const auto w = scale.x; for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; @@ -2056,8 +2052,8 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, using namespace render_pass_actions; render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step = {lolo.dimensions.x * lolo.scale, lolo.dimensions.y * lolo.scale}; - lolo.offset = {lolo.dimensions.x - lolo.step.x, lolo.dimensions.y - lolo.step.y}; + lolo.step = {lolo.dimensions * lolo.scale}; + lolo.offset = {lolo.dimensions - lolo.step}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); @@ -2101,7 +2097,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { TRACK_BEGIN("renderUI:textures") render_ui_t lolo; lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step = {lolo.dimensions.x * lolo.scale, lolo.dimensions.y * lolo.scale}; + lolo.step = {lolo.dimensions * lolo.scale}; lolo.offset = {lolo.step.x, lolo.dimensions.y - lolo.step.y}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); @@ -2112,7 +2108,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { vera::image((vera::TextureStream*)slit->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, true); else vera::image(it->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); - vera::text(it->first, lolo.offset.x + lolo.step.x, vera::getWindowHeight() - lolo.offset.y + lolo.step.y); + vera::text(it->first, glm::vec2{lolo.offset.x, vera::getWindowHeight() - lolo.offset.y} + lolo.step); lolo.offset.y -= lolo.step.y * 2.0; } TRACK_END("renderUI:textures") @@ -2151,15 +2147,14 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { TRACK_BEGIN("renderUI:plot_data") render_ui_t lolo; - lolo.p = vera::getPixelDensity(); - std::tie(lolo.dimensions.x, lolo.dimensions.y) = std::pair{100 * lolo.p, 30 * lolo.p}; + lolo.dimensions = glm::vec2{100, 30} * lolo.p; lolo.pos = {(float)(vera::getWindowWidth()) * 0.5, lolo.dimensions.y + 10}; muu.m_plot_shader->use(); - muu.m_plot_shader->setUniform("u_scale", lolo.dimensions.x, lolo.dimensions.y); - muu.m_plot_shader->setUniform("u_translate", lolo.pos.x, lolo.pos.y); - muu.m_plot_shader->setUniform("u_resolution", (float)vera::getWindowWidth(), (float)vera::getWindowHeight()); - muu.m_plot_shader->setUniform("u_viewport", lolo.dimensions.x, lolo.dimensions.y); + muu.m_plot_shader->setUniform("u_scale", lolo.dimensions); + muu.m_plot_shader->setUniform("u_translate", lolo.pos); + muu.m_plot_shader->setUniform("u_resolution", {vera::getWindowWidth(), vera::getWindowHeight()}); + muu.m_plot_shader->setUniform("u_viewport", lolo.dimensions); muu.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); muu.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); muu.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); @@ -2185,15 +2180,15 @@ void overlay_cursor(const overlay_fn_args_t& muu) { } vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalAlign v, vera::HorizontalAlign h, render_ui_t& lolo) { - lolo.step = {lolo.dimensions.x * 0.05, lolo.dimensions.y * 0.05}; - lolo.pos = {lolo.step.x * 2.0f, lolo.step.y * 3.0f}; + lolo.step = lolo.dimensions * 0.05f; + lolo.pos = lolo.step * glm::vec2{2.0f, 3.0f}; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); - vera::rect(glm::vec2(lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.5f), glm::vec2(lolo.dimensions.x - lolo.step.x * 2.0f, lolo.dimensions.y - lolo.step.y * 2.0f)); + vera::rect(lolo.dimensions * 0.5f, lolo.dimensions - lolo.step * 2.0f); vera::fill(1.0f); set_common_text_attributes(textangle, textsize, v, h); return cam; @@ -2216,7 +2211,7 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { lolo.step.y = vera::getFontHeight() * 1.5f; const auto print_text = [&](const std::string& prompt){ - vera::text(prompt, lolo.pos.x, lolo.pos.y); + vera::text(prompt, lolo.pos); lolo.pos.y += lolo.step.y; }; From 4502b0320d1865b07e3773b59c0f2454dc6a845e Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 21 Dec 2022 01:17:29 +0100 Subject: [PATCH 34/76] convert to use print_text --- src/core/sandbox.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 26259655..262acb37 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2108,8 +2108,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { vera::image((vera::TextureStream*)slit->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, true); else vera::image(it->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); - vera::text(it->first, glm::vec2{lolo.offset.x, vera::getWindowHeight() - lolo.offset.y} + lolo.step); - lolo.offset.y -= lolo.step.y * 2.0; + print_text(it->first, lolo.offset.x + lolo.step.x, lolo); } TRACK_END("renderUI:textures") } From 7d7317de4367d405627b1aa05e5f708b4ba20e6e Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Thu, 22 Dec 2022 10:30:45 +0100 Subject: [PATCH 35/76] refactor overlay_m_showTextures --- src/core/sandbox.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 262acb37..e876e5f8 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2091,24 +2091,24 @@ struct overlay_fn_args_t { }; void overlay_m_showTextures(const overlay_fn_args_t& muu) { - int nTotal = muu.uniforms->textures.size(); - if (nTotal > 0) { + if (muu.uniforms->textures.size() > 0) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") render_ui_t lolo; - lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; + lolo.scale = fmin(1.0f / (float)(muu.uniforms->textures.size()), 0.25) * 0.5; lolo.step = {lolo.dimensions * lolo.scale}; lolo.offset = {lolo.step.x, lolo.dimensions.y - lolo.step.y}; set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); - for (vera::TexturesMap::const_iterator it = muu.uniforms->textures.begin(); it != muu.uniforms->textures.end(); it++) { - vera::TextureStreamsMap::const_iterator slit = muu.uniforms->streams.find(it->first); - if ( slit != muu.uniforms->streams.end() ) - vera::image((vera::TextureStream*)slit->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, true); + for(const auto& texture : muu.uniforms->textures) { + const auto textureStream_match = std::find_if(std::begin(muu.uniforms->streams), std::end(muu.uniforms->streams) + , [&](vera::TextureStreamsMap::value_type stream){return texture.first == stream.first;}); + if ( textureStream_match != std::end(muu.uniforms->streams) ) + vera::image((vera::TextureStream*)textureStream_match->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, true); else - vera::image(it->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); - print_text(it->first, lolo.offset.x + lolo.step.x, lolo); + vera::image(texture.second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); + print_text(texture.first, lolo.offset.x + lolo.step.x, lolo); } TRACK_END("renderUI:textures") } From 6b2435e1dbed96257cd601cd6174c145405c5728 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 16:37:07 +0100 Subject: [PATCH 36/76] renamed lolo to uio --- src/core/sandbox.cpp | 127 ++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index e876e5f8..8e252694 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1957,21 +1957,21 @@ struct render_ui_t { glm::vec2 pos = dimensions * glm::vec2{0.5, 1} + glm::vec2{0, 10}; }; -void print_text(const std::string& prompt, const float offsetx, render_ui_t& lolo) { - vera::text(prompt, offsetx, vera::getWindowHeight() - lolo.offset.y + lolo.step.y); - lolo.offset.y -= lolo.step.y * 2.0; +void print_text(const std::string& prompt, const float offsetx, render_ui_t& uio) { + vera::text(prompt, offsetx, vera::getWindowHeight() - uio.offset.y + uio.step.y); + uio.offset.y -= uio.step.y * 2.0; } -void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_t& lolo) { - vera::image(&lala, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); - print_text(prompt, lolo.offset.x - lolo.step.x, lolo); +void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_t& uio) { + vera::image(&lala, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); + print_text(prompt, uio.offset.x - uio.step.x, uio); } -void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& lolo) { - glm::vec2 scale = lolo.step.y * glm::vec2{((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()), 1}; - glm::vec2 offset = lolo.offset + glm::vec2{lolo.step.x - scale.x, 0}; +void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& uio) { + glm::vec2 scale = uio.step.y * glm::vec2{((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()), 1}; + glm::vec2 offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); - print_text(prompt + vera::toString(i), lolo.offset.x - scale.x, lolo); + print_text(prompt + vera::toString(i), uio.offset.x - scale.x, uio); } namespace render_pass_actions { @@ -1980,40 +1980,40 @@ struct render_pass_args_t { const BuffersList* const fbolist; }; -void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { +void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& uio) { if (uniforms.functions[prompt_id].present) - print_fbo_text(*abc.fbo, prompt_id, lolo); + print_fbo_text(*abc.fbo, prompt_id, uio); } -void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& abc, render_ui_t& lolo) { +void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& abc, render_ui_t& uio) { for (size_t i = 0; i < abc.fbolist->size(); i++) - print_fbo_text(*(*abc.fbolist)[i], prompt_id, lolo); + print_fbo_text(*(*abc.fbolist)[i], prompt_id, uio); } -void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& lolo) { +void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& uio) { if (uniforms.functions[prompt_id].present) { if (uniforms.activeCamera) - vera::imageDepth(*abc.fbo, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - print_text(prompt_id, lolo.offset.x - lolo.step.x, lolo); + vera::imageDepth(*abc.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + print_text(prompt_id, uio.offset.x - uio.step.x, uio); } } -void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { +void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { if (uniforms.models.size() > 0) { for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { if ( it->second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it->second->getShadowMap(), lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, it->second->getShadowMapFar(), it->second->getShadowMapNear()); + vera::imageDepth(it->second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it->second->getShadowMapFar(), it->second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - print_text(prompt_id, lolo.offset.x - lolo.step.x, lolo); + print_text(prompt_id, uio.offset.x - uio.step.x, uio); } } } } -void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { +void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { for (size_t i = 0; i < uniforms.pyramids.size(); i++) { - glm::vec2 scale = lolo.step.y * glm::vec2{((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()), 1}; - glm::vec2 offset = lolo.offset + glm::vec2{lolo.step.x - scale.x, 0}; + glm::vec2 scale = uio.step.y * glm::vec2{((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()), 1}; + glm::vec2 offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; const auto w = scale.x; for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); @@ -2021,23 +2021,24 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; std::tie(scale, offset.y) = is_lower_depth - ? std::pair{scale *= 0.5, lolo.offset.y - lolo.step.y * 0.5} - : std::pair{scale *= 2.0, lolo.offset.y + lolo.step.y * 0.5}; + ? std::pair{scale *= 0.5, uio.offset.y - uio.step.y * 0.5} + : std::pair{scale *= 2.0, uio.offset.y + uio.step.y * 0.5}; + offset.x -= scale.x; } // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); - lolo.offset.y -= lolo.step.y * 2.0; + uio.offset.y -= uio.step.y * 2.0; } } -void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { +void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) - print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, lolo); + print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, uio); } -void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& lolo) { +void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { for (size_t i = 0; i < uniforms.buffers.size(); i++) - print_buffers_text(*uniforms.buffers[i], i, prompt_id, lolo); + print_buffers_text(*uniforms.buffers[i], i, prompt_id, uio); } } // namespace [render_pass_actions] @@ -2050,12 +2051,12 @@ void set_common_text_attributes(float textangle, float textsize, vera::VerticalA void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, int nTotal){ using namespace render_pass_actions; - render_ui_t lolo; - lolo.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; - lolo.step = {lolo.dimensions * lolo.scale}; - lolo.offset = {lolo.dimensions - lolo.step}; + render_ui_t uio; + uio.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; + uio.step = uio.dimensions * uio.scale; + uio.offset = uio.dimensions - uio.step; - set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); + set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); struct vtable_render_pass_t{ using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void; @@ -2074,7 +2075,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_pass_scene} , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_pass_scenedepth} }; - for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, lolo); } + for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, uio); } } namespace overlay_actions { @@ -2094,21 +2095,21 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { if (muu.uniforms->textures.size() > 0) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") - render_ui_t lolo; - lolo.scale = fmin(1.0f / (float)(muu.uniforms->textures.size()), 0.25) * 0.5; - lolo.step = {lolo.dimensions * lolo.scale}; - lolo.offset = {lolo.step.x, lolo.dimensions.y - lolo.step.y}; + render_ui_t uio; + uio.scale = fmin(1.0f / (float)(muu.uniforms->textures.size()), 0.25) * 0.5; + uio.step = uio.dimensions * uio.scale; + uio.offset = {uio.step.x, uio.dimensions.y - uio.step.y}; - set_common_text_attributes(-HALF_PI, lolo.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); + set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); for(const auto& texture : muu.uniforms->textures) { const auto textureStream_match = std::find_if(std::begin(muu.uniforms->streams), std::end(muu.uniforms->streams) , [&](vera::TextureStreamsMap::value_type stream){return texture.first == stream.first;}); if ( textureStream_match != std::end(muu.uniforms->streams) ) - vera::image((vera::TextureStream*)textureStream_match->second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y, true); + vera::image((vera::TextureStream*)textureStream_match->second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, true); else - vera::image(texture.second, lolo.offset.x, lolo.offset.y, lolo.step.x, lolo.step.y); - print_text(texture.first, lolo.offset.x + lolo.step.x, lolo); + vera::image(texture.second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); + print_text(texture.first, uio.offset.x + uio.step.x, uio); } TRACK_END("renderUI:textures") } @@ -2145,15 +2146,15 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") - render_ui_t lolo; - lolo.dimensions = glm::vec2{100, 30} * lolo.p; - lolo.pos = {(float)(vera::getWindowWidth()) * 0.5, lolo.dimensions.y + 10}; + render_ui_t uio; + uio.dimensions = glm::vec2{100, 30} * uio.p; + uio.pos = {(float)(vera::getWindowWidth()) * 0.5, uio.dimensions.y + 10}; muu.m_plot_shader->use(); - muu.m_plot_shader->setUniform("u_scale", lolo.dimensions); - muu.m_plot_shader->setUniform("u_translate", lolo.pos); + muu.m_plot_shader->setUniform("u_scale", uio.dimensions); + muu.m_plot_shader->setUniform("u_translate", uio.pos); muu.m_plot_shader->setUniform("u_resolution", {vera::getWindowWidth(), vera::getWindowHeight()}); - muu.m_plot_shader->setUniform("u_viewport", lolo.dimensions); + muu.m_plot_shader->setUniform("u_viewport", uio.dimensions); muu.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); muu.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); muu.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); @@ -2178,40 +2179,40 @@ void overlay_cursor(const overlay_fn_args_t& muu) { TRACK_END("renderUI:cursor") } -vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalAlign v, vera::HorizontalAlign h, render_ui_t& lolo) { - lolo.step = lolo.dimensions * 0.05f; - lolo.pos = lolo.step * glm::vec2{2.0f, 3.0f}; +vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalAlign v, vera::HorizontalAlign h, render_ui_t& uio) { + uio.step = uio.dimensions * 0.05f; + uio.pos = uio.step * glm::vec2{2.0f, 3.0f}; vera::Camera *cam = vera::getCamera(); vera::resetCamera(); vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); - vera::rect(lolo.dimensions * 0.5f, lolo.dimensions - lolo.step * 2.0f); + vera::rect(uio.dimensions * 0.5f, uio.dimensions - uio.step * 2.0f); vera::fill(1.0f); set_common_text_attributes(textangle, textsize, v, h); return cam; } void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { - render_ui_t lolo; - vera::Camera *cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, lolo); + render_ui_t uio; + vera::Camera *cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); - vera::text("Drag & Drop", lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.45f); + vera::text("Drag & Drop", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.45f); vera::textSize(22.0f); - vera::text(".vert .frag .ply .lst .obj .gltf .glb", lolo.dimensions.x * 0.5f, lolo.dimensions.y * 0.55f); + vera::text(".vert .frag .ply .lst .obj .gltf .glb", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.55f); vera::setCamera(cam); } void overlay_prompt_help(const overlay_fn_args_t& muu) { - render_ui_t lolo; - vera::Camera *cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, lolo); - lolo.step.y = vera::getFontHeight() * 1.5f; + render_ui_t uio; + vera::Camera *cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); + uio.step.y = vera::getFontHeight() * 1.5f; const auto print_text = [&](const std::string& prompt){ - vera::text(prompt, lolo.pos); - lolo.pos.y += lolo.step.y; + vera::text(prompt, uio.pos); + uio.pos.y += uio.step.y; }; const auto geometry_available = *muu.geom_index != -1; From 7d433645852d32333bd760e3ef85a941caf3b42c Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 16:39:20 +0100 Subject: [PATCH 37/76] renamed muu to "o" --- src/core/sandbox.cpp | 90 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 8e252694..b2bd6196 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2091,21 +2091,21 @@ struct overlay_fn_args_t { const bool* verbose; }; -void overlay_m_showTextures(const overlay_fn_args_t& muu) { - if (muu.uniforms->textures.size() > 0) { +void overlay_m_showTextures(const overlay_fn_args_t& o) { + if (o.uniforms->textures.size() > 0) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") render_ui_t uio; - uio.scale = fmin(1.0f / (float)(muu.uniforms->textures.size()), 0.25) * 0.5; + uio.scale = fmin(1.0f / (float)(o.uniforms->textures.size()), 0.25) * 0.5; uio.step = uio.dimensions * uio.scale; uio.offset = {uio.step.x, uio.dimensions.y - uio.step.y}; set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); - for(const auto& texture : muu.uniforms->textures) { - const auto textureStream_match = std::find_if(std::begin(muu.uniforms->streams), std::end(muu.uniforms->streams) + for(const auto& texture : o.uniforms->textures) { + const auto textureStream_match = std::find_if(std::begin(o.uniforms->streams), std::end(o.uniforms->streams) , [&](vera::TextureStreamsMap::value_type stream){return texture.first == stream.first;}); - if ( textureStream_match != std::end(muu.uniforms->streams) ) + if ( textureStream_match != std::end(o.uniforms->streams) ) vera::image((vera::TextureStream*)textureStream_match->second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, true); else vera::image(texture.second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); @@ -2115,34 +2115,34 @@ void overlay_m_showTextures(const overlay_fn_args_t& muu) { } } -void overlay_m_showPasses(const overlay_fn_args_t& muu) { +void overlay_m_showPasses(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") // DEBUG BUFFERS - const auto is_postprocessing_with_uniforms = muu.m_postprocessing - && muu.uniforms->models.size() > 0; + const auto is_postprocessing_with_uniforms = o.m_postprocessing + && o.uniforms->models.size() > 0; using num_of_passes_t = std::pair; const auto nTotalArray = { num_of_passes_t - {true, muu.uniforms->buffers.size()} //buffer - , {true, muu.uniforms->doubleBuffers.size()} // doublebuffer - , {true, muu.uniforms->pyramids.size()} //pyramid + {true, o.uniforms->buffers.size()} //buffer + , {true, o.uniforms->doubleBuffers.size()} // doublebuffer + , {true, o.uniforms->pyramids.size()} //pyramid , {is_postprocessing_with_uniforms, 1} // lightmap - , {true, muu.uniforms->functions["u_scenePosition"].present} - , {true, muu.uniforms->functions["u_sceneNormal"].present} - , {true, muu.m_sceneRender->getBuffersTotal()} - , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_scene"].present} - , {is_postprocessing_with_uniforms, muu.uniforms->functions["u_sceneDepth"].present} + , {true, o.uniforms->functions["u_scenePosition"].present} + , {true, o.uniforms->functions["u_sceneNormal"].present} + , {true, o.m_sceneRender->getBuffersTotal()} + , {is_postprocessing_with_uniforms, o.uniforms->functions["u_scene"].present} + , {is_postprocessing_with_uniforms, o.uniforms->functions["u_sceneDepth"].present} }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const int acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); if (nTotal > 0) { - process_render_passes(*muu.uniforms, *muu.m_sceneRender, nTotal); + process_render_passes(*o.uniforms, *o.m_sceneRender, nTotal); } TRACK_END("renderUI:buffers") }; -void overlay_m_plot(const overlay_fn_args_t& muu) { +void overlay_m_plot(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") @@ -2150,32 +2150,32 @@ void overlay_m_plot(const overlay_fn_args_t& muu) { uio.dimensions = glm::vec2{100, 30} * uio.p; uio.pos = {(float)(vera::getWindowWidth()) * 0.5, uio.dimensions.y + 10}; - muu.m_plot_shader->use(); - muu.m_plot_shader->setUniform("u_scale", uio.dimensions); - muu.m_plot_shader->setUniform("u_translate", uio.pos); - muu.m_plot_shader->setUniform("u_resolution", {vera::getWindowWidth(), vera::getWindowHeight()}); - muu.m_plot_shader->setUniform("u_viewport", uio.dimensions); - muu.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); - muu.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); - muu.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); - muu.m_plot_shader->setUniform("u_projectionMatrix", glm::mat4(1.0f)); - muu.m_plot_shader->setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); - muu.m_plot_shader->setUniformTexture("u_plotData", *muu.m_plot_texture, 0); - - vera::getBillboard()->render(&*muu.m_plot_shader); + o.m_plot_shader->use(); + o.m_plot_shader->setUniform("u_scale", uio.dimensions); + o.m_plot_shader->setUniform("u_translate", uio.pos); + o.m_plot_shader->setUniform("u_resolution", {vera::getWindowWidth(), vera::getWindowHeight()}); + o.m_plot_shader->setUniform("u_viewport", uio.dimensions); + o.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); + o.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); + o.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); + o.m_plot_shader->setUniform("u_projectionMatrix", glm::mat4(1.0f)); + o.m_plot_shader->setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); + o.m_plot_shader->setUniformTexture("u_plotData", *o.m_plot_texture, 0); + + vera::getBillboard()->render(&*o.m_plot_shader); TRACK_END("renderUI:plot_data") } -void overlay_cursor(const overlay_fn_args_t& muu) { +void overlay_cursor(const overlay_fn_args_t& o) { TRACK_BEGIN("renderUI:cursor") - if ((*muu.m_cross_vbo) == nullptr) - (*muu.m_cross_vbo) = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); + if ((*o.m_cross_vbo) == nullptr) + (*o.m_cross_vbo) = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); vera::Shader* fill = vera::getFillShader(); fill->use(); fill->setUniform("u_modelViewProjectionMatrix", glm::translate(vera::getOrthoMatrix(), glm::vec3(vera::getMouseX(), vera::getMouseY(), 0.0f) ) ); fill->setUniform("u_color", glm::vec4(1.0f)); - (*muu.m_cross_vbo)->render(fill); + (*o.m_cross_vbo)->render(fill); TRACK_END("renderUI:cursor") } @@ -2205,7 +2205,7 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { vera::setCamera(cam); } -void overlay_prompt_help(const overlay_fn_args_t& muu) { +void overlay_prompt_help(const overlay_fn_args_t& o) { render_ui_t uio; vera::Camera *cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); uio.step.y = vera::getFontHeight() * 1.5f; @@ -2215,29 +2215,29 @@ void overlay_prompt_help(const overlay_fn_args_t& muu) { uio.pos.y += uio.step.y; }; - const auto geometry_available = *muu.geom_index != -1; - const auto uniform_streams_available = muu.uniforms->streams.size() > 0; + const auto geometry_available = *o.geom_index != -1; + const auto uniform_streams_available = o.uniforms->streams.size() > 0; struct help_prompt_t { bool predicate; std::string message; }; const auto help_prompts = { help_prompt_t - {geometry_available, "a - " + std::string( muu.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} - , {geometry_available, "b - " + std::string( muu.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} + {geometry_available, "a - " + std::string( o.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} + , {geometry_available, "b - " + std::string( o.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} , {true, "c - hide/show cursor"} - , {geometry_available, "d - " + std::string( muu.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} + , {geometry_available, "d - " + std::string( o.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} , {geometry_available, "f - hide/show floor"} , {true, "F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen"} - , {geometry_available, "g - " + std::string( muu.m_sceneRender->showGrid? "hide" : "show" ) + " grid"} - , {true, "h - " + std::string( muu.help? "hide" : "show" ) + " help"} + , {geometry_available, "g - " + std::string( o.m_sceneRender->showGrid? "hide" : "show" ) + " grid"} + , {true, "h - " + std::string( o.help? "hide" : "show" ) + " help"} , {true, "i - hide/show extra info"} , {true, "o - open shaders on default editor"} , {true, "p - hide/show render passes/buffers"} , {uniform_streams_available, "r - restart stream textures"} , {geometry_available, "s - hide/show sky"} , {true, "t - hide/show loaded textures"} - , {true, "v - " + std::string( muu.verbose? "disable" : "enable" ) + " verbose"} + , {true, "v - " + std::string( o.verbose? "disable" : "enable" ) + " verbose"} , {uniform_streams_available, "space - start/stop stream textures"} }; for(const auto& _ : help_prompts) { if(_.predicate) print_text(_.message); } From d27b08256a5962a1bc32e526bf8ca897e65baa8d Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 16:54:36 +0100 Subject: [PATCH 38/76] removed unneeded whitespace --- src/core/sandbox.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index b2bd6196..0aa47d7b 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2023,7 +2023,6 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a std::tie(scale, offset.y) = is_lower_depth ? std::pair{scale *= 0.5, uio.offset.y - uio.step.y * 0.5} : std::pair{scale *= 2.0, uio.offset.y + uio.step.y * 0.5}; - offset.x -= scale.x; } // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); @@ -2055,7 +2054,6 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, uio.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; uio.step = uio.dimensions * uio.scale; uio.offset = uio.dimensions - uio.step; - set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); struct vtable_render_pass_t{ @@ -2099,7 +2097,6 @@ void overlay_m_showTextures(const overlay_fn_args_t& o) { uio.scale = fmin(1.0f / (float)(o.uniforms->textures.size()), 0.25) * 0.5; uio.step = uio.dimensions * uio.scale; uio.offset = {uio.step.x, uio.dimensions.y - uio.step.y}; - set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); for(const auto& texture : o.uniforms->textures) { @@ -2118,7 +2115,6 @@ void overlay_m_showTextures(const overlay_fn_args_t& o) { void overlay_m_showPasses(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") - // DEBUG BUFFERS const auto is_postprocessing_with_uniforms = o.m_postprocessing && o.uniforms->models.size() > 0; @@ -2136,16 +2132,14 @@ void overlay_m_showPasses(const overlay_fn_args_t& o) { }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const int acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); - if (nTotal > 0) { + if (nTotal > 0) process_render_passes(*o.uniforms, *o.m_sceneRender, nTotal); - } TRACK_END("renderUI:buffers") }; void overlay_m_plot(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") - render_ui_t uio; uio.dimensions = glm::vec2{100, 30} * uio.p; uio.pos = {(float)(vera::getWindowWidth()) * 0.5, uio.dimensions.y + 10}; @@ -2185,7 +2179,6 @@ vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalA vera::Camera *cam = vera::getCamera(); vera::resetCamera(); - vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); vera::rect(uio.dimensions * 0.5f, uio.dimensions - uio.step * 2.0f); @@ -2197,11 +2190,9 @@ vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalA void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t uio; vera::Camera *cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); - vera::text("Drag & Drop", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.45f); vera::textSize(22.0f); vera::text(".vert .frag .ply .lst .obj .gltf .glb", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.55f); - vera::setCamera(cam); } @@ -2214,7 +2205,6 @@ void overlay_prompt_help(const overlay_fn_args_t& o) { vera::text(prompt, uio.pos); uio.pos.y += uio.step.y; }; - const auto geometry_available = *o.geom_index != -1; const auto uniform_streams_available = o.uniforms->streams.size() > 0; @@ -2252,7 +2242,6 @@ void overlay_prompt_help(const overlay_fn_args_t& o) { void Sandbox::renderUI() { TRACK_BEGIN("renderUI") using namespace renderable_objects::overlay_actions; - const auto display_m_plots = m_plot != PLOT_OFF && m_plot_texture ; const auto diplay_cursor = cursor && vera::getMouseEntered(); const auto no_geometry_available = frag_index == -1 && vert_index == -1 && geom_index == -1; From 56622d8ec519073ca7a7cf66538bc804f5336252 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 17:03:52 +0100 Subject: [PATCH 39/76] simplify do_pass_lightmap for-loop --- src/core/sandbox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 0aa47d7b..383cb105 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2000,9 +2000,9 @@ void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { if (uniforms.models.size() > 0) { - for (vera::LightsMap::iterator it = uniforms.lights.begin(); it != uniforms.lights.end(); ++it ) { - if ( it->second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it->second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it->second->getShadowMapFar(), it->second->getShadowMapNear()); + for (const auto& it : uniforms.lights) { + if ( it.second->getShadowMap()->getDepthTextureId() ) { + vera::imageDepth(it.second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it.second->getShadowMapFar(), it.second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); print_text(prompt_id, uio.offset.x - uio.step.x, uio); } From 34770a549c30f8e120cf07ffa20eeba4fb340c06 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 17:09:14 +0100 Subject: [PATCH 40/76] remove unneeded whitespace --- src/core/sandbox.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 383cb105..24ccfb14 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1981,13 +1981,11 @@ struct render_pass_args_t { }; void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& uio) { - if (uniforms.functions[prompt_id].present) - print_fbo_text(*abc.fbo, prompt_id, uio); + if (uniforms.functions[prompt_id].present) { print_fbo_text(*abc.fbo, prompt_id, uio); } } void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& abc, render_ui_t& uio) { - for (size_t i = 0; i < abc.fbolist->size(); i++) - print_fbo_text(*(*abc.fbolist)[i], prompt_id, uio); + for(const auto& fbo : (*abc.fbolist)) { print_fbo_text(*fbo, prompt_id, uio); } } void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& uio) { From 34c2719fcf1bd2e4bcacad0af22d2a20c8318574 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 17:15:23 +0100 Subject: [PATCH 41/76] rename abc to "current" --- src/core/sandbox.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 24ccfb14..3adbe0a3 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1980,18 +1980,18 @@ struct render_pass_args_t { const BuffersList* const fbolist; }; -void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& uio) { - if (uniforms.functions[prompt_id].present) { print_fbo_text(*abc.fbo, prompt_id, uio); } +void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { + if (uniforms.functions[prompt_id].present) { print_fbo_text(*current.fbo, prompt_id, uio); } } -void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& abc, render_ui_t& uio) { - for(const auto& fbo : (*abc.fbolist)) { print_fbo_text(*fbo, prompt_id, uio); } +void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& current, render_ui_t& uio) { + for(const auto& fbo : (*current.fbolist)) { print_fbo_text(*fbo, prompt_id, uio); } } -void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& abc, render_ui_t& uio) { +void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { if (uniforms.functions[prompt_id].present) { if (uniforms.activeCamera) - vera::imageDepth(*abc.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + vera::imageDepth(*current.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); print_text(prompt_id, uio.offset.x - uio.step.x, uio); } } From 908f6c98a7b4dd78373087854be66d8c9480bd3c Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 17:29:05 +0100 Subject: [PATCH 42/76] renamed local lambda to print_help_prompt --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 3adbe0a3..975e3fc9 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2199,7 +2199,7 @@ void overlay_prompt_help(const overlay_fn_args_t& o) { vera::Camera *cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); uio.step.y = vera::getFontHeight() * 1.5f; - const auto print_text = [&](const std::string& prompt){ + const auto print_help_prompt = [&](const std::string& prompt){ vera::text(prompt, uio.pos); uio.pos.y += uio.step.y; }; @@ -2228,7 +2228,7 @@ void overlay_prompt_help(const overlay_fn_args_t& o) { , {true, "v - " + std::string( o.verbose? "disable" : "enable" ) + " verbose"} , {uniform_streams_available, "space - start/stop stream textures"} }; - for(const auto& _ : help_prompts) { if(_.predicate) print_text(_.message); } + for(const auto& _ : help_prompts) { if(_.predicate) print_help_prompt(_.message); } vera::setCamera(cam); glDisable(GL_DEPTH_TEST); From 973599f7a326decde2d394ca58cbbbdebac157cf Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 18:01:15 +0100 Subject: [PATCH 43/76] renamed lala to fbo --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 975e3fc9..3ea6d867 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1962,8 +1962,8 @@ void print_text(const std::string& prompt, const float offsetx, render_ui_t& uio uio.offset.y -= uio.step.y * 2.0; } -void print_fbo_text(const vera::Fbo& lala, const std::string& prompt, render_ui_t& uio) { - vera::image(&lala, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); +void print_fbo_text(const vera::Fbo& fbo, const std::string& prompt, render_ui_t& uio) { + vera::image(&fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); print_text(prompt, uio.offset.x - uio.step.x, uio); } From 1f2dd65afb2e256dd3f9b500098314245e97386d Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Fri, 23 Dec 2022 18:06:14 +0100 Subject: [PATCH 44/76] renamed lala to overlay_table --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 3ea6d867..a3892fac 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2250,7 +2250,7 @@ void Sandbox::renderUI() { const function_sig_t do_overlay_action; const overlay_fn_args_t parameters; }; - const std::array lala = { vtable_overlay_fn_args_with_pred_t + const std::array overlay_table = { vtable_overlay_fn_args_with_pred_t {m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {m_showPasses, &overlay_m_showPasses, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {display_m_plots, &overlay_m_plot, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} @@ -2258,7 +2258,7 @@ void Sandbox::renderUI() { , {no_geometry_available, &overlay_prompt_drag_and_drop, {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {help, &overlay_prompt_help, {&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose}} }; - for(const auto& _: lala) { if(_.predicate) _.do_overlay_action(_.parameters); } + for(const auto& _: overlay_table) { if(_.predicate) _.do_overlay_action(_.parameters); } TRACK_END("renderUI") } From fd0399262367285eac9837c4513b907429f9e66b Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 24 Dec 2022 13:18:22 +0100 Subject: [PATCH 45/76] prefer ranged-for-loop over iterators --- src/core/sandbox.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index a3892fac..7bda6dfb 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2009,14 +2009,14 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re } void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { - for (size_t i = 0; i < uniforms.pyramids.size(); i++) { - glm::vec2 scale = uio.step.y * glm::vec2{((float)uniforms.pyramids[i].getWidth()/(float)uniforms.pyramids[i].getHeight()), 1}; + for(const auto& pyramid : uniforms.pyramids) { + glm::vec2 scale = uio.step.y * glm::vec2{((float)pyramid.getWidth()/(float)pyramid.getHeight()), 1}; glm::vec2 offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; const auto w = scale.x; - for (size_t j = 0; j < uniforms.pyramids[i].getDepth() * 2; j++ ) { - const auto is_lower_depth = (j < uniforms.pyramids[i].getDepth()); + for (size_t j = 0; j < pyramid.getDepth() * 2; j++ ) { + const auto is_lower_depth = (j < pyramid.getDepth()); const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; - vera::image(uniforms.pyramids[i].getResult(j), delta_offset, offset.y, scale.x, scale.y); + vera::image(pyramid.getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; std::tie(scale, offset.y) = is_lower_depth ? std::pair{scale *= 0.5, uio.offset.y - uio.step.y * 0.5} From 8c2a4c758c9e9a38abea49aa6521e6d004e1c5d6 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 24 Dec 2022 19:29:52 +0100 Subject: [PATCH 46/76] shorthand datatype to reduce codesize --- src/core/sandbox.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 7bda6dfb..9049efe7 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2018,9 +2018,8 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a const auto delta_offset = is_lower_depth ? offset.x : offset.x + w * 2.0f; vera::image(pyramid.getResult(j), delta_offset, offset.y, scale.x, scale.y); offset.x -= scale.x; - std::tie(scale, offset.y) = is_lower_depth - ? std::pair{scale *= 0.5, uio.offset.y - uio.step.y * 0.5} - : std::pair{scale *= 2.0, uio.offset.y + uio.step.y * 0.5}; + using _t = std::pair; + std::tie(scale, offset.y) = is_lower_depth ? _t{scale *= 0.5, uio.offset.y - uio.step.y * 0.5} : _t{scale *= 2.0, uio.offset.y + uio.step.y * 0.5}; offset.x -= scale.x; } // vera::text("u_pyramid0" + vera::toString(i), xOffset - scale.x * 2.0, vera::getWindowHeight() - yOffset + yStep); From 377080ee8ba6a7a29bd44aa3c284af2923f00a44 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 02:10:53 +0100 Subject: [PATCH 47/76] const-harden some variables --- src/core/sandbox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 9049efe7..3a4eabc8 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2186,7 +2186,7 @@ vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalA void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t uio; - vera::Camera *cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); + vera::Camera* const cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); vera::text("Drag & Drop", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.45f); vera::textSize(22.0f); vera::text(".vert .frag .ply .lst .obj .gltf .glb", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.55f); @@ -2195,7 +2195,7 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { void overlay_prompt_help(const overlay_fn_args_t& o) { render_ui_t uio; - vera::Camera *cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); + vera::Camera* const cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); uio.step.y = vera::getFontHeight() * 1.5f; const auto print_help_prompt = [&](const std::string& prompt){ @@ -2206,8 +2206,8 @@ void overlay_prompt_help(const overlay_fn_args_t& o) { const auto uniform_streams_available = o.uniforms->streams.size() > 0; struct help_prompt_t { - bool predicate; - std::string message; + const bool predicate; + const std::string message; }; const auto help_prompts = { help_prompt_t {geometry_available, "a - " + std::string( o.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} From e0e220d21e55be6996d7e34c87d31bb578cd17da Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 02:19:34 +0100 Subject: [PATCH 48/76] prefer "return on false" prefer "return on false" prefer "return on false" (by continue;) prefer "return on false" --- src/core/sandbox.cpp | 63 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 3a4eabc8..d7c3c910 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1989,22 +1989,21 @@ void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_ } void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { - if (uniforms.functions[prompt_id].present) { - if (uniforms.activeCamera) - vera::imageDepth(*current.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); - print_text(prompt_id, uio.offset.x - uio.step.x, uio); - } + if (!uniforms.functions[prompt_id].present) + return; + if (uniforms.activeCamera) + vera::imageDepth(*current.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + print_text(prompt_id, uio.offset.x - uio.step.x, uio); } void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { - if (uniforms.models.size() > 0) { - for (const auto& it : uniforms.lights) { - if ( it.second->getShadowMap()->getDepthTextureId() ) { - vera::imageDepth(it.second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it.second->getShadowMapFar(), it.second->getShadowMapNear()); - // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); - print_text(prompt_id, uio.offset.x - uio.step.x, uio); - } - } + if (uniforms.models.empty()) + return; + for (const auto& it : uniforms.lights) { + if (!it.second->getShadowMap()->getDepthTextureId()) { continue; } + vera::imageDepth(it.second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it.second->getShadowMapFar(), it.second->getShadowMapNear()); + // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); + print_text(prompt_id, uio.offset.x - uio.step.x, uio); } } @@ -2087,26 +2086,26 @@ struct overlay_fn_args_t { }; void overlay_m_showTextures(const overlay_fn_args_t& o) { - if (o.uniforms->textures.size() > 0) { - glDisable(GL_DEPTH_TEST); - TRACK_BEGIN("renderUI:textures") - render_ui_t uio; - uio.scale = fmin(1.0f / (float)(o.uniforms->textures.size()), 0.25) * 0.5; - uio.step = uio.dimensions * uio.scale; - uio.offset = {uio.step.x, uio.dimensions.y - uio.step.y}; - set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); - - for(const auto& texture : o.uniforms->textures) { - const auto textureStream_match = std::find_if(std::begin(o.uniforms->streams), std::end(o.uniforms->streams) - , [&](vera::TextureStreamsMap::value_type stream){return texture.first == stream.first;}); - if ( textureStream_match != std::end(o.uniforms->streams) ) - vera::image((vera::TextureStream*)textureStream_match->second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, true); - else - vera::image(texture.second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); - print_text(texture.first, uio.offset.x + uio.step.x, uio); - } - TRACK_END("renderUI:textures") + if (o.uniforms->textures.empty()) + return; + glDisable(GL_DEPTH_TEST); + TRACK_BEGIN("renderUI:textures") + render_ui_t uio; + uio.scale = fmin(1.0f / (float)(o.uniforms->textures.size()), 0.25) * 0.5; + uio.step = uio.dimensions * uio.scale; + uio.offset = {uio.step.x, uio.dimensions.y - uio.step.y}; + set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); + + for(const auto& texture : o.uniforms->textures) { + const auto textureStream_match = std::find_if(std::begin(o.uniforms->streams), std::end(o.uniforms->streams) + , [&](vera::TextureStreamsMap::value_type stream){return texture.first == stream.first;}); + if ( textureStream_match != std::end(o.uniforms->streams) ) + vera::image((vera::TextureStream*)textureStream_match->second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, true); + else + vera::image(texture.second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); + print_text(texture.first, uio.offset.x + uio.step.x, uio); } + TRACK_END("renderUI:textures") } void overlay_m_showPasses(const overlay_fn_args_t& o) { From 0e9eadae239f95574165416cbcda520e81bb0005 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 03:39:03 +0100 Subject: [PATCH 49/76] removed unneeded whitespace --- src/core/sandbox.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index d7c3c910..6680a793 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1989,16 +1989,14 @@ void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_ } void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { - if (!uniforms.functions[prompt_id].present) - return; + if (!uniforms.functions[prompt_id].present) { return; } if (uniforms.activeCamera) vera::imageDepth(*current.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); print_text(prompt_id, uio.offset.x - uio.step.x, uio); } void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { - if (uniforms.models.empty()) - return; + if (uniforms.models.empty()) { return; } for (const auto& it : uniforms.lights) { if (!it.second->getShadowMap()->getDepthTextureId()) { continue; } vera::imageDepth(it.second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it.second->getShadowMapFar(), it.second->getShadowMapNear()); @@ -2086,8 +2084,7 @@ struct overlay_fn_args_t { }; void overlay_m_showTextures(const overlay_fn_args_t& o) { - if (o.uniforms->textures.empty()) - return; + if (o.uniforms->textures.empty()) { return; } glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") render_ui_t uio; @@ -2128,8 +2125,7 @@ void overlay_m_showPasses(const overlay_fn_args_t& o) { }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const int acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); - if (nTotal > 0) - process_render_passes(*o.uniforms, *o.m_sceneRender, nTotal); + if (nTotal > 0) { process_render_passes(*o.uniforms, *o.m_sceneRender, nTotal); } TRACK_END("renderUI:buffers") }; @@ -2257,7 +2253,6 @@ void Sandbox::renderUI() { , {help, &overlay_prompt_help, {&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose}} }; for(const auto& _: overlay_table) { if(_.predicate) _.do_overlay_action(_.parameters); } - TRACK_END("renderUI") } From 614e3d2595c525b1c01e5ec0c9b7f6391fd0860a Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 03:39:56 +0100 Subject: [PATCH 50/76] prefer std::vector::empty --- src/core/sandbox.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 6680a793..a23f0d68 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2109,8 +2109,7 @@ void overlay_m_showPasses(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") // DEBUG BUFFERS - const auto is_postprocessing_with_uniforms = o.m_postprocessing - && o.uniforms->models.size() > 0; + const auto is_postprocessing_with_uniforms = o.m_postprocessing && !o.uniforms->models.empty(); using num_of_passes_t = std::pair; const auto nTotalArray = { num_of_passes_t {true, o.uniforms->buffers.size()} //buffer From 767a04a55892938fcabfebdc4f47ebd328ee020b Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 06:20:28 +0100 Subject: [PATCH 51/76] promote int to size_t --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index a23f0d68..e64b5ed6 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2042,7 +2042,7 @@ void set_common_text_attributes(float textangle, float textsize, vera::VerticalA vera::textAlign(h); } -void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, int nTotal){ +void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, size_t nTotal){ using namespace render_pass_actions; render_ui_t uio; uio.scale = fmin(1.0f / (float)(nTotal), 0.25) * 0.5; @@ -2123,7 +2123,7 @@ void overlay_m_showPasses(const overlay_fn_args_t& o) { , {is_postprocessing_with_uniforms, o.uniforms->functions["u_sceneDepth"].present} }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} - , [](const int acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); + , [](const size_t acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); if (nTotal > 0) { process_render_passes(*o.uniforms, *o.m_sceneRender, nTotal); } TRACK_END("renderUI:buffers") }; From f659ce455c63c66d61dfe81bf36f3085b9579461 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 06:23:51 +0100 Subject: [PATCH 52/76] convert datatype{}* to const auto (compiler type deduction) --- src/core/sandbox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index e64b5ed6..4ddde891 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2156,7 +2156,7 @@ void overlay_cursor(const overlay_fn_args_t& o) { if ((*o.m_cross_vbo) == nullptr) (*o.m_cross_vbo) = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); - vera::Shader* fill = vera::getFillShader(); + const auto fill = vera::getFillShader(); fill->use(); fill->setUniform("u_modelViewProjectionMatrix", glm::translate(vera::getOrthoMatrix(), glm::vec3(vera::getMouseX(), vera::getMouseY(), 0.0f) ) ); fill->setUniform("u_color", glm::vec4(1.0f)); @@ -2168,7 +2168,7 @@ vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalA uio.step = uio.dimensions * 0.05f; uio.pos = uio.step * glm::vec2{2.0f, 3.0f}; - vera::Camera *cam = vera::getCamera(); + const auto cam = vera::getCamera(); vera::resetCamera(); vera::fill(0.0f, 0.0f, 0.0f, 0.75f); vera::noStroke(); @@ -2180,7 +2180,7 @@ vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalA void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { render_ui_t uio; - vera::Camera* const cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); + const auto cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); vera::text("Drag & Drop", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.45f); vera::textSize(22.0f); vera::text(".vert .frag .ply .lst .obj .gltf .glb", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.55f); @@ -2189,7 +2189,7 @@ void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { void overlay_prompt_help(const overlay_fn_args_t& o) { render_ui_t uio; - vera::Camera* const cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); + const auto cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); uio.step.y = vera::getFontHeight() * 1.5f; const auto print_help_prompt = [&](const std::string& prompt){ From dac5f29a387549849f33cfdf56004434b345ef98 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 06:27:03 +0100 Subject: [PATCH 53/76] convert datatype{} to [const] auto - (compiler type deduction) --- src/core/sandbox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 4ddde891..dca4e741 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1968,8 +1968,8 @@ void print_fbo_text(const vera::Fbo& fbo, const std::string& prompt, render_ui_t } void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::string& prompt, render_ui_t& uio) { - glm::vec2 scale = uio.step.y * glm::vec2{((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()), 1}; - glm::vec2 offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; + const auto scale = uio.step.y * glm::vec2{((float)uniforms_buffer.getWidth()/(float)uniforms_buffer.getHeight()), 1}; + const auto offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; vera::image(uniforms_buffer, offset.x, offset.y, scale.x, scale.y); print_text(prompt + vera::toString(i), uio.offset.x - scale.x, uio); } @@ -2007,8 +2007,8 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { for(const auto& pyramid : uniforms.pyramids) { - glm::vec2 scale = uio.step.y * glm::vec2{((float)pyramid.getWidth()/(float)pyramid.getHeight()), 1}; - glm::vec2 offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; + auto scale = uio.step.y * glm::vec2{((float)pyramid.getWidth()/(float)pyramid.getHeight()), 1}; + auto offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; const auto w = scale.x; for (size_t j = 0; j < pyramid.getDepth() * 2; j++ ) { const auto is_lower_depth = (j < pyramid.getDepth()); From 8e39acce931ebf7acee0064f19afd5619be55b77 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 06:49:40 +0100 Subject: [PATCH 54/76] rename local variable to: lightmap --- src/core/sandbox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index dca4e741..031c7754 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1997,9 +1997,9 @@ void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { if (uniforms.models.empty()) { return; } - for (const auto& it : uniforms.lights) { - if (!it.second->getShadowMap()->getDepthTextureId()) { continue; } - vera::imageDepth(it.second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, it.second->getShadowMapFar(), it.second->getShadowMapNear()); + for (const auto& lightmap : uniforms.lights) { + if (!lightmap.second->getShadowMap()->getDepthTextureId()) { continue; } + vera::imageDepth(lightmap.second->getShadowMap(), uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, lightmap.second->getShadowMapFar(), lightmap.second->getShadowMapNear()); // vera::image(it->second->getShadowMap(), xOffset, yOffset, xStep, yStep); print_text(prompt_id, uio.offset.x - uio.step.x, uio); } From 99c1f00947304f89df4788990cf79c9c1681ef2b Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 17:37:42 +0100 Subject: [PATCH 55/76] renamed dispatch-table to: render_pass_table --- src/core/sandbox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 031c7754..42c20552 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2054,9 +2054,9 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void; const std::string prompt_id; const render_pass_args_t process_info; - const func_sig_t process_renderer; + const func_sig_t process_render_pass; }; - const std::array somelist { vtable_render_pass_t + const auto render_pass_table = { vtable_render_pass_t {"u_buffer", {nullptr, nullptr}, do_pass_singlebuffer} , {"u_doubleBuffer", {nullptr, nullptr}, do_pass_doublebuffers} , {"u_pyramid0", {nullptr, nullptr}, do_pass_pyramid} @@ -2067,7 +2067,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_pass_scene} , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_pass_scenedepth} }; - for(const auto& _ : somelist) { _.process_renderer(_.prompt_id, uniforms, _.process_info, uio); } + for(const auto& _ : render_pass_table) { _.process_render_pass(_.prompt_id, uniforms, _.process_info, uio); } } namespace overlay_actions { From c39581d6e0cd2c7113c397bf61fa4bb417699729 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 23:52:09 +0100 Subject: [PATCH 56/76] function renamed to: overlay_plot_data --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 42c20552..68eea43f 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2128,7 +2128,7 @@ void overlay_m_showPasses(const overlay_fn_args_t& o) { TRACK_END("renderUI:buffers") }; -void overlay_m_plot(const overlay_fn_args_t& o) { +void overlay_plot_data(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") render_ui_t uio; @@ -2246,7 +2246,7 @@ void Sandbox::renderUI() { const std::array overlay_table = { vtable_overlay_fn_args_with_pred_t {m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {m_showPasses, &overlay_m_showPasses, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} - , {display_m_plots, &overlay_m_plot, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} + , {display_m_plots, &overlay_plot_data, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} , {no_geometry_available, &overlay_prompt_drag_and_drop, {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {help, &overlay_prompt_help, {&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose}} From 1dafe26ab1d354a614685abd5e90647ab472978a Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 23:54:33 +0100 Subject: [PATCH 57/76] function renamed to: overlay_show_buffer_passes --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 68eea43f..ba9b7c8c 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2105,7 +2105,7 @@ void overlay_m_showTextures(const overlay_fn_args_t& o) { TRACK_END("renderUI:textures") } -void overlay_m_showPasses(const overlay_fn_args_t& o) { +void overlay_show_buffer_passes(const overlay_fn_args_t& o) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") // DEBUG BUFFERS @@ -2245,7 +2245,7 @@ void Sandbox::renderUI() { }; const std::array overlay_table = { vtable_overlay_fn_args_with_pred_t {m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} - , {m_showPasses, &overlay_m_showPasses, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + , {m_showPasses, &overlay_show_buffer_passes, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {display_m_plots, &overlay_plot_data, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} , {no_geometry_available, &overlay_prompt_drag_and_drop, {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} From eeb9f28f26415692b64ee63aa16824a46680786f Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sun, 25 Dec 2022 23:55:40 +0100 Subject: [PATCH 58/76] function renamed to: overlay_show_textures --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index ba9b7c8c..37763e35 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2083,7 +2083,7 @@ struct overlay_fn_args_t { const bool* verbose; }; -void overlay_m_showTextures(const overlay_fn_args_t& o) { +void overlay_show_textures(const overlay_fn_args_t& o) { if (o.uniforms->textures.empty()) { return; } glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") @@ -2244,7 +2244,7 @@ void Sandbox::renderUI() { const overlay_fn_args_t parameters; }; const std::array overlay_table = { vtable_overlay_fn_args_with_pred_t - {m_showTextures, &overlay_m_showTextures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} + {m_showTextures, &overlay_show_textures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {m_showPasses, &overlay_show_buffer_passes, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {display_m_plots, &overlay_plot_data, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} From fc8f4a46196fe432d901902f1daf63d1e905848c Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Mon, 26 Dec 2022 00:41:04 +0100 Subject: [PATCH 59/76] prefer const auto for: overlay_table --- src/core/sandbox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 37763e35..bbd56c44 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2243,7 +2243,7 @@ void Sandbox::renderUI() { const function_sig_t do_overlay_action; const overlay_fn_args_t parameters; }; - const std::array overlay_table = { vtable_overlay_fn_args_with_pred_t + const auto overlay_table = { vtable_overlay_fn_args_with_pred_t {m_showTextures, &overlay_show_textures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {m_showPasses, &overlay_show_buffer_passes, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} , {display_m_plots, &overlay_plot_data, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} From dd4c0af4a16bf7685cc02e284c0741f1016d4dc5 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 07:49:26 +0100 Subject: [PATCH 60/76] prefer if-statements over dispatch table --- src/core/sandbox.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index bbd56c44..be971b17 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2237,21 +2237,13 @@ void Sandbox::renderUI() { const auto diplay_cursor = cursor && vera::getMouseEntered(); const auto no_geometry_available = frag_index == -1 && vert_index == -1 && geom_index == -1; - struct vtable_overlay_fn_args_with_pred_t { - using function_sig_t = auto (*)(const overlay_fn_args_t&) -> void; - const bool predicate; - const function_sig_t do_overlay_action; - const overlay_fn_args_t parameters; - }; - const auto overlay_table = { vtable_overlay_fn_args_with_pred_t - {m_showTextures, &overlay_show_textures, {&uniforms, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} - , {m_showPasses, &overlay_show_buffer_passes, {&uniforms, &m_sceneRender, &m_postprocessing, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} - , {display_m_plots, &overlay_plot_data, {nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture, nullptr, nullptr, nullptr, nullptr}} - , {diplay_cursor, &overlay_cursor, {nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr}} - , {no_geometry_available, &overlay_prompt_drag_and_drop, {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}} - , {help, &overlay_prompt_help, {&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose}} - }; - for(const auto& _: overlay_table) { if(_.predicate) _.do_overlay_action(_.parameters); } + if(m_showTextures) { overlay_show_textures ({&uniforms});} + if(m_showPasses) { overlay_show_buffer_passes({&uniforms, &m_sceneRender, &m_postprocessing, nullptr});} + if(display_m_plots){ overlay_plot_data({nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture});} + if(diplay_cursor) { overlay_cursor({nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr});} + if(no_geometry_available) { overlay_prompt_drag_and_drop({nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr});} + if(help) { overlay_prompt_help({&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose});} + TRACK_END("renderUI") } From 99bd88ea3375790d92e48ab4eb3fd90aa55365e3 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 07:52:18 +0100 Subject: [PATCH 61/76] prefer customised parameters for: overlay_show_textures --- src/core/sandbox.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index be971b17..43e39e18 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2083,20 +2083,20 @@ struct overlay_fn_args_t { const bool* verbose; }; -void overlay_show_textures(const overlay_fn_args_t& o) { - if (o.uniforms->textures.empty()) { return; } +void overlay_show_textures(const Uniforms& uniforms) { + if (uniforms.textures.empty()) { return; } glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:textures") render_ui_t uio; - uio.scale = fmin(1.0f / (float)(o.uniforms->textures.size()), 0.25) * 0.5; + uio.scale = fmin(1.0f / (float)(uniforms.textures.size()), 0.25) * 0.5; uio.step = uio.dimensions * uio.scale; uio.offset = {uio.step.x, uio.dimensions.y - uio.step.y}; set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_TOP, vera::ALIGN_LEFT); - for(const auto& texture : o.uniforms->textures) { - const auto textureStream_match = std::find_if(std::begin(o.uniforms->streams), std::end(o.uniforms->streams) + for(const auto& texture : uniforms.textures) { + const auto textureStream_match = std::find_if(std::begin(uniforms.streams), std::end(uniforms.streams) , [&](vera::TextureStreamsMap::value_type stream){return texture.first == stream.first;}); - if ( textureStream_match != std::end(o.uniforms->streams) ) + if ( textureStream_match != std::end(uniforms.streams) ) vera::image((vera::TextureStream*)textureStream_match->second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, true); else vera::image(texture.second, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y); @@ -2237,7 +2237,7 @@ void Sandbox::renderUI() { const auto diplay_cursor = cursor && vera::getMouseEntered(); const auto no_geometry_available = frag_index == -1 && vert_index == -1 && geom_index == -1; - if(m_showTextures) { overlay_show_textures ({&uniforms});} + if(m_showTextures) { overlay_show_textures (uniforms);} if(m_showPasses) { overlay_show_buffer_passes({&uniforms, &m_sceneRender, &m_postprocessing, nullptr});} if(display_m_plots){ overlay_plot_data({nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture});} if(diplay_cursor) { overlay_cursor({nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr});} From 7b834fd74bf954366bc8dacc1c14f3b67cf10bcf Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 07:56:49 +0100 Subject: [PATCH 62/76] prefer customised parameters for: overlay_show_buffer_passes --- src/core/sandbox.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 43e39e18..16a48196 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2105,26 +2105,26 @@ void overlay_show_textures(const Uniforms& uniforms) { TRACK_END("renderUI:textures") } -void overlay_show_buffer_passes(const overlay_fn_args_t& o) { +void overlay_show_buffer_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, bool m_postprocessing) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:buffers") // DEBUG BUFFERS - const auto is_postprocessing_with_uniforms = o.m_postprocessing && !o.uniforms->models.empty(); + const auto is_postprocessing_with_uniforms = m_postprocessing && !uniforms.models.empty(); using num_of_passes_t = std::pair; const auto nTotalArray = { num_of_passes_t - {true, o.uniforms->buffers.size()} //buffer - , {true, o.uniforms->doubleBuffers.size()} // doublebuffer - , {true, o.uniforms->pyramids.size()} //pyramid + {true, uniforms.buffers.size()} //buffer + , {true, uniforms.doubleBuffers.size()} // doublebuffer + , {true, uniforms.pyramids.size()} //pyramid , {is_postprocessing_with_uniforms, 1} // lightmap - , {true, o.uniforms->functions["u_scenePosition"].present} - , {true, o.uniforms->functions["u_sceneNormal"].present} - , {true, o.m_sceneRender->getBuffersTotal()} - , {is_postprocessing_with_uniforms, o.uniforms->functions["u_scene"].present} - , {is_postprocessing_with_uniforms, o.uniforms->functions["u_sceneDepth"].present} + , {true, uniforms.functions["u_scenePosition"].present} + , {true, uniforms.functions["u_sceneNormal"].present} + , {true, m_sceneRender.getBuffersTotal()} + , {is_postprocessing_with_uniforms, uniforms.functions["u_scene"].present} + , {is_postprocessing_with_uniforms, uniforms.functions["u_sceneDepth"].present} }; const auto nTotal = std::accumulate(std::begin(nTotalArray), std::end(nTotalArray), int{} , [](const size_t acc, const num_of_passes_t& kv) { return acc + ((kv.first) ? kv.second : 0); }); - if (nTotal > 0) { process_render_passes(*o.uniforms, *o.m_sceneRender, nTotal); } + if (nTotal > 0) { process_render_passes(uniforms, m_sceneRender, nTotal); } TRACK_END("renderUI:buffers") }; @@ -2238,7 +2238,7 @@ void Sandbox::renderUI() { const auto no_geometry_available = frag_index == -1 && vert_index == -1 && geom_index == -1; if(m_showTextures) { overlay_show_textures (uniforms);} - if(m_showPasses) { overlay_show_buffer_passes({&uniforms, &m_sceneRender, &m_postprocessing, nullptr});} + if(m_showPasses) { overlay_show_buffer_passes(uniforms, m_sceneRender, m_postprocessing);} if(display_m_plots){ overlay_plot_data({nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture});} if(diplay_cursor) { overlay_cursor({nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr});} if(no_geometry_available) { overlay_prompt_drag_and_drop({nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr});} From b6612c131666a6bda998582c196e2d36b86814df Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:04:14 +0100 Subject: [PATCH 63/76] prefer customised parameters for: overlay_plot_data --- src/core/sandbox.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 16a48196..f45db12e 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2128,26 +2128,26 @@ void overlay_show_buffer_passes(Uniforms& uniforms, const SceneRender& m_sceneRe TRACK_END("renderUI:buffers") }; -void overlay_plot_data(const overlay_fn_args_t& o) { +void overlay_plot_data(vera::Shader& m_plot_shader, const vera::Texture* const m_plot_texture) { glDisable(GL_DEPTH_TEST); TRACK_BEGIN("renderUI:plot_data") render_ui_t uio; uio.dimensions = glm::vec2{100, 30} * uio.p; uio.pos = {(float)(vera::getWindowWidth()) * 0.5, uio.dimensions.y + 10}; - o.m_plot_shader->use(); - o.m_plot_shader->setUniform("u_scale", uio.dimensions); - o.m_plot_shader->setUniform("u_translate", uio.pos); - o.m_plot_shader->setUniform("u_resolution", {vera::getWindowWidth(), vera::getWindowHeight()}); - o.m_plot_shader->setUniform("u_viewport", uio.dimensions); - o.m_plot_shader->setUniform("u_model", glm::vec3(1.0f)); - o.m_plot_shader->setUniform("u_modelMatrix", glm::mat4(1.0f)); - o.m_plot_shader->setUniform("u_viewMatrix", glm::mat4(1.0f)); - o.m_plot_shader->setUniform("u_projectionMatrix", glm::mat4(1.0f)); - o.m_plot_shader->setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); - o.m_plot_shader->setUniformTexture("u_plotData", *o.m_plot_texture, 0); - - vera::getBillboard()->render(&*o.m_plot_shader); + m_plot_shader.use(); + m_plot_shader.setUniform("u_scale", uio.dimensions); + m_plot_shader.setUniform("u_translate", uio.pos); + m_plot_shader.setUniform("u_resolution", {vera::getWindowWidth(), vera::getWindowHeight()}); + m_plot_shader.setUniform("u_viewport", uio.dimensions); + m_plot_shader.setUniform("u_model", glm::vec3(1.0f)); + m_plot_shader.setUniform("u_modelMatrix", glm::mat4(1.0f)); + m_plot_shader.setUniform("u_viewMatrix", glm::mat4(1.0f)); + m_plot_shader.setUniform("u_projectionMatrix", glm::mat4(1.0f)); + m_plot_shader.setUniform("u_modelViewProjectionMatrix", vera::getOrthoMatrix()); + m_plot_shader.setUniformTexture("u_plotData", m_plot_texture, 0); + + vera::getBillboard()->render(&m_plot_shader); TRACK_END("renderUI:plot_data") } @@ -2239,7 +2239,7 @@ void Sandbox::renderUI() { if(m_showTextures) { overlay_show_textures (uniforms);} if(m_showPasses) { overlay_show_buffer_passes(uniforms, m_sceneRender, m_postprocessing);} - if(display_m_plots){ overlay_plot_data({nullptr, nullptr, nullptr, &m_plot_shader, &m_plot_texture});} + if(display_m_plots){ overlay_plot_data(m_plot_shader, m_plot_texture);} if(diplay_cursor) { overlay_cursor({nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr});} if(no_geometry_available) { overlay_prompt_drag_and_drop({nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr});} if(help) { overlay_prompt_help({&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose});} From a3283cf46a45c31f718b1cff4efb13d98311f8a7 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:07:40 +0100 Subject: [PATCH 64/76] prefer customised parameters for: overlay_cursor --- src/core/sandbox.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index f45db12e..3fb3f1a7 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2151,16 +2151,16 @@ void overlay_plot_data(vera::Shader& m_plot_shader, const vera::Texture* const m TRACK_END("renderUI:plot_data") } -void overlay_cursor(const overlay_fn_args_t& o) { +void overlay_cursor(std::unique_ptr& m_cross_vbo) { TRACK_BEGIN("renderUI:cursor") - if ((*o.m_cross_vbo) == nullptr) - (*o.m_cross_vbo) = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); + if (m_cross_vbo == nullptr) + m_cross_vbo = std::unique_ptr(new vera::Vbo( vera::crossMesh( glm::vec3(0.0f, 0.0f, 0.0f), 10.0f) )); const auto fill = vera::getFillShader(); fill->use(); fill->setUniform("u_modelViewProjectionMatrix", glm::translate(vera::getOrthoMatrix(), glm::vec3(vera::getMouseX(), vera::getMouseY(), 0.0f) ) ); fill->setUniform("u_color", glm::vec4(1.0f)); - (*o.m_cross_vbo)->render(fill); + m_cross_vbo->render(fill); TRACK_END("renderUI:cursor") } @@ -2240,7 +2240,7 @@ void Sandbox::renderUI() { if(m_showTextures) { overlay_show_textures (uniforms);} if(m_showPasses) { overlay_show_buffer_passes(uniforms, m_sceneRender, m_postprocessing);} if(display_m_plots){ overlay_plot_data(m_plot_shader, m_plot_texture);} - if(diplay_cursor) { overlay_cursor({nullptr, nullptr, nullptr, nullptr, nullptr, &m_cross_vbo, nullptr, nullptr, nullptr});} + if(diplay_cursor) { overlay_cursor(m_cross_vbo);} if(no_geometry_available) { overlay_prompt_drag_and_drop({nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr});} if(help) { overlay_prompt_help({&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose});} From 9de7ff4f5e26df3a197c9e0ba25c29e1c24f7ad4 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:08:30 +0100 Subject: [PATCH 65/76] prefer customised parameters for: overlay_prompt_drag_and_drop --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 3fb3f1a7..557bfab7 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2178,7 +2178,7 @@ vera::Camera* overlay_black_box(float textangle, float textsize, vera::VerticalA return cam; } -void overlay_prompt_drag_and_drop(const overlay_fn_args_t&) { +void overlay_prompt_drag_and_drop() { render_ui_t uio; const auto cam = overlay_black_box(0.0f, 38.0f, vera::ALIGN_MIDDLE, vera::ALIGN_CENTER, uio); vera::text("Drag & Drop", uio.dimensions.x * 0.5f, uio.dimensions.y * 0.45f); @@ -2241,7 +2241,7 @@ void Sandbox::renderUI() { if(m_showPasses) { overlay_show_buffer_passes(uniforms, m_sceneRender, m_postprocessing);} if(display_m_plots){ overlay_plot_data(m_plot_shader, m_plot_texture);} if(diplay_cursor) { overlay_cursor(m_cross_vbo);} - if(no_geometry_available) { overlay_prompt_drag_and_drop({nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr});} + if(no_geometry_available) { overlay_prompt_drag_and_drop();} if(help) { overlay_prompt_help({&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose});} TRACK_END("renderUI") From a887b792c72636a985287afec4a12840298a54f0 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:13:23 +0100 Subject: [PATCH 66/76] prefer customised parameters for: overlay_prompt_help --- src/core/sandbox.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 557bfab7..e0291885 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2187,7 +2187,7 @@ void overlay_prompt_drag_and_drop() { vera::setCamera(cam); } -void overlay_prompt_help(const overlay_fn_args_t& o) { +void overlay_prompt_help(const Uniforms& uniforms, const SceneRender& m_sceneRender, int geom_index, bool help, bool verbose) { render_ui_t uio; const auto cam = overlay_black_box(0.0f, 22.0f, vera::ALIGN_MIDDLE, vera::ALIGN_LEFT, uio); uio.step.y = vera::getFontHeight() * 1.5f; @@ -2196,29 +2196,29 @@ void overlay_prompt_help(const overlay_fn_args_t& o) { vera::text(prompt, uio.pos); uio.pos.y += uio.step.y; }; - const auto geometry_available = *o.geom_index != -1; - const auto uniform_streams_available = o.uniforms->streams.size() > 0; + const auto geometry_available = geom_index != -1; + const auto uniform_streams_available = !uniforms.streams.empty(); struct help_prompt_t { const bool predicate; const std::string message; }; const auto help_prompts = { help_prompt_t - {geometry_available, "a - " + std::string( o.m_sceneRender->showAxis? "hide" : "show" ) + " axis"} - , {geometry_available, "b - " + std::string( o.m_sceneRender->showBBoxes? "hide" : "show" ) + " bounding boxes"} + {geometry_available, "a - " + std::string( m_sceneRender.showAxis? "hide" : "show" ) + " axis"} + , {geometry_available, "b - " + std::string( m_sceneRender.showBBoxes? "hide" : "show" ) + " bounding boxes"} , {true, "c - hide/show cursor"} - , {geometry_available, "d - " + std::string( o.m_sceneRender->dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} + , {geometry_available, "d - " + std::string( m_sceneRender.dynamicShadows? "disable" : "enable" ) + " dynamic shadows"} , {geometry_available, "f - hide/show floor"} , {true, "F - " + std::string( vera::isFullscreen() ? "disable" : "enable" ) + " fullscreen"} - , {geometry_available, "g - " + std::string( o.m_sceneRender->showGrid? "hide" : "show" ) + " grid"} - , {true, "h - " + std::string( o.help? "hide" : "show" ) + " help"} + , {geometry_available, "g - " + std::string( m_sceneRender.showGrid? "hide" : "show" ) + " grid"} + , {true, "h - " + std::string( help? "hide" : "show" ) + " help"} , {true, "i - hide/show extra info"} , {true, "o - open shaders on default editor"} , {true, "p - hide/show render passes/buffers"} , {uniform_streams_available, "r - restart stream textures"} , {geometry_available, "s - hide/show sky"} , {true, "t - hide/show loaded textures"} - , {true, "v - " + std::string( o.verbose? "disable" : "enable" ) + " verbose"} + , {true, "v - " + std::string( verbose? "disable" : "enable" ) + " verbose"} , {uniform_streams_available, "space - start/stop stream textures"} }; for(const auto& _ : help_prompts) { if(_.predicate) print_help_prompt(_.message); } @@ -2242,7 +2242,7 @@ void Sandbox::renderUI() { if(display_m_plots){ overlay_plot_data(m_plot_shader, m_plot_texture);} if(diplay_cursor) { overlay_cursor(m_cross_vbo);} if(no_geometry_available) { overlay_prompt_drag_and_drop();} - if(help) { overlay_prompt_help({&uniforms, &m_sceneRender, nullptr, nullptr, nullptr, nullptr, &geom_index, &help, &verbose});} + if(help) { overlay_prompt_help(uniforms, m_sceneRender, geom_index, help, verbose);} TRACK_END("renderUI") } From 62042c392991b878bb3fa711afad2f3c366c1fbe Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:13:59 +0100 Subject: [PATCH 67/76] removed overlay_fn_args_t --- src/core/sandbox.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index e0291885..281fb8f7 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2071,18 +2071,6 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, } namespace overlay_actions { -struct overlay_fn_args_t { - Uniforms * uniforms; - const SceneRender* m_sceneRender; - const bool* m_postprocessing; - vera::Shader* m_plot_shader; - vera::Texture** m_plot_texture; - std::unique_ptr* m_cross_vbo; - const int* geom_index; - const bool* help; - const bool* verbose; -}; - void overlay_show_textures(const Uniforms& uniforms) { if (uniforms.textures.empty()) { return; } glDisable(GL_DEPTH_TEST); From fe2d1473d2c143ef685c06fdafcd1ff048f41554 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:28:17 +0100 Subject: [PATCH 68/76] prefer direct function calls over dispatch table --- src/core/sandbox.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 281fb8f7..af54da50 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2050,24 +2050,15 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, uio.offset = uio.dimensions - uio.step; set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); - struct vtable_render_pass_t{ - using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void; - const std::string prompt_id; - const render_pass_args_t process_info; - const func_sig_t process_render_pass; - }; - const auto render_pass_table = { vtable_render_pass_t - {"u_buffer", {nullptr, nullptr}, do_pass_singlebuffer} - , {"u_doubleBuffer", {nullptr, nullptr}, do_pass_doublebuffers} - , {"u_pyramid0", {nullptr, nullptr}, do_pass_pyramid} - , {"u_lightShadowMap", {nullptr, nullptr}, do_pass_lightmap} - , {"u_scenePosition", {&m_sceneRender.positionFbo, nullptr}, do_pass_scene} - , {"u_sceneNormal", {&m_sceneRender.normalFbo, nullptr}, do_pass_scene} - , {"u_sceneBuffer", {nullptr, &m_sceneRender.buffersFbo}, do_pass_scenebuffer} - , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_pass_scene} - , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_pass_scenedepth} - }; - for(const auto& _ : render_pass_table) { _.process_render_pass(_.prompt_id, uniforms, _.process_info, uio); } + do_pass_singlebuffer("u_buffer", uniforms, {nullptr, nullptr}, uio); + do_pass_doublebuffers("u_doubleBuffer", uniforms, {nullptr, nullptr}, uio); + do_pass_pyramid("u_pyramid0", uniforms, {nullptr, nullptr}, uio); + do_pass_lightmap("u_lightShadowMap", uniforms, {nullptr, nullptr}, uio); + do_pass_scene("u_scenePosition", uniforms, {&m_sceneRender.positionFbo, nullptr}, uio); + do_pass_scene("u_sceneNormal", uniforms, {&m_sceneRender.normalFbo, nullptr}, uio); + do_pass_scenebuffer("u_sceneBuffer", uniforms, {nullptr, &m_sceneRender.buffersFbo}, uio); + do_pass_scene("u_scene", uniforms, {&m_sceneRender.renderFbo, nullptr}, uio); + do_pass_scenedepth("u_sceneDepth", uniforms, {&m_sceneRender.renderFbo, nullptr}, uio); } namespace overlay_actions { From 146fc6a43ddaafc37b2ef9b73e876b5811dec5f7 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:30:36 +0100 Subject: [PATCH 69/76] prefer customised paramters: do_pass_singlebuffer --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index af54da50..2867d5ec 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2029,7 +2029,7 @@ void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, con print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, uio); } -void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { +void do_pass_singlebuffer(const std::string& prompt_id, Uniforms& uniforms, render_ui_t& uio) { for (size_t i = 0; i < uniforms.buffers.size(); i++) print_buffers_text(*uniforms.buffers[i], i, prompt_id, uio); } @@ -2050,7 +2050,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, uio.offset = uio.dimensions - uio.step; set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); - do_pass_singlebuffer("u_buffer", uniforms, {nullptr, nullptr}, uio); + do_pass_singlebuffer("u_buffer", uniforms, uio); do_pass_doublebuffers("u_doubleBuffer", uniforms, {nullptr, nullptr}, uio); do_pass_pyramid("u_pyramid0", uniforms, {nullptr, nullptr}, uio); do_pass_lightmap("u_lightShadowMap", uniforms, {nullptr, nullptr}, uio); From 9a1b5a72dd761633ae43e5f99f4b486299119e59 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:32:21 +0100 Subject: [PATCH 70/76] prefer customised parameters: do_pass_doublebuffers --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 2867d5ec..af6e4e9b 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2024,7 +2024,7 @@ void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_a } } -void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { +void do_pass_doublebuffers(const std::string& prompt_id, Uniforms& uniforms, render_ui_t& uio) { for (size_t i = 0; i < uniforms.doubleBuffers.size(); i++) print_buffers_text(*uniforms.doubleBuffers[i]->src, i, prompt_id, uio); } @@ -2051,7 +2051,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, set_common_text_attributes(-HALF_PI, uio.step.y * 0.2f / vera::getPixelDensity(false), vera::ALIGN_BOTTOM, vera::ALIGN_LEFT); do_pass_singlebuffer("u_buffer", uniforms, uio); - do_pass_doublebuffers("u_doubleBuffer", uniforms, {nullptr, nullptr}, uio); + do_pass_doublebuffers("u_doubleBuffer", uniforms, uio); do_pass_pyramid("u_pyramid0", uniforms, {nullptr, nullptr}, uio); do_pass_lightmap("u_lightShadowMap", uniforms, {nullptr, nullptr}, uio); do_pass_scene("u_scenePosition", uniforms, {&m_sceneRender.positionFbo, nullptr}, uio); From 41fcff55058f528eabe353f83cdd87076bbdf41c Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:33:18 +0100 Subject: [PATCH 71/76] prefer customised parameters: do_pass_pyramid --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index af6e4e9b..527738ea 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -2005,7 +2005,7 @@ void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const re } } -void do_pass_pyramid(const std::string&, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { +void do_pass_pyramid(const std::string&, Uniforms& uniforms, render_ui_t& uio) { for(const auto& pyramid : uniforms.pyramids) { auto scale = uio.step.y * glm::vec2{((float)pyramid.getWidth()/(float)pyramid.getHeight()), 1}; auto offset = uio.offset + glm::vec2{uio.step.x - scale.x, 0}; @@ -2052,7 +2052,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, do_pass_singlebuffer("u_buffer", uniforms, uio); do_pass_doublebuffers("u_doubleBuffer", uniforms, uio); - do_pass_pyramid("u_pyramid0", uniforms, {nullptr, nullptr}, uio); + do_pass_pyramid("u_pyramid0", uniforms, uio); do_pass_lightmap("u_lightShadowMap", uniforms, {nullptr, nullptr}, uio); do_pass_scene("u_scenePosition", uniforms, {&m_sceneRender.positionFbo, nullptr}, uio); do_pass_scene("u_sceneNormal", uniforms, {&m_sceneRender.normalFbo, nullptr}, uio); From a03fae3283361388b36d07819590567c6d9d11e8 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:34:08 +0100 Subject: [PATCH 72/76] prefer customised parameters: do_pass_lightmap --- src/core/sandbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 527738ea..121c5b49 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1995,7 +1995,7 @@ void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const print_text(prompt_id, uio.offset.x - uio.step.x, uio); } -void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t&, render_ui_t& uio) { +void do_pass_lightmap(const std::string& prompt_id, Uniforms& uniforms, render_ui_t& uio) { if (uniforms.models.empty()) { return; } for (const auto& lightmap : uniforms.lights) { if (!lightmap.second->getShadowMap()->getDepthTextureId()) { continue; } @@ -2053,7 +2053,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, do_pass_singlebuffer("u_buffer", uniforms, uio); do_pass_doublebuffers("u_doubleBuffer", uniforms, uio); do_pass_pyramid("u_pyramid0", uniforms, uio); - do_pass_lightmap("u_lightShadowMap", uniforms, {nullptr, nullptr}, uio); + do_pass_lightmap("u_lightShadowMap", uniforms, uio); do_pass_scene("u_scenePosition", uniforms, {&m_sceneRender.positionFbo, nullptr}, uio); do_pass_scene("u_sceneNormal", uniforms, {&m_sceneRender.normalFbo, nullptr}, uio); do_pass_scenebuffer("u_sceneBuffer", uniforms, {nullptr, &m_sceneRender.buffersFbo}, uio); From b373aed4e358414e7e5c0f62ab75433e8dcaf0e3 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:36:03 +0100 Subject: [PATCH 73/76] prefer customised parameters: do_pass_scene --- src/core/sandbox.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 121c5b49..57cba1a6 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1980,8 +1980,8 @@ struct render_pass_args_t { const BuffersList* const fbolist; }; -void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { - if (uniforms.functions[prompt_id].present) { print_fbo_text(*current.fbo, prompt_id, uio); } +void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const vera::Fbo& fbo, render_ui_t& uio) { + if (uniforms.functions[prompt_id].present) { print_fbo_text(fbo, prompt_id, uio); } } void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& current, render_ui_t& uio) { @@ -2054,10 +2054,10 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, do_pass_doublebuffers("u_doubleBuffer", uniforms, uio); do_pass_pyramid("u_pyramid0", uniforms, uio); do_pass_lightmap("u_lightShadowMap", uniforms, uio); - do_pass_scene("u_scenePosition", uniforms, {&m_sceneRender.positionFbo, nullptr}, uio); - do_pass_scene("u_sceneNormal", uniforms, {&m_sceneRender.normalFbo, nullptr}, uio); + do_pass_scene("u_scenePosition", uniforms, m_sceneRender.positionFbo, uio); + do_pass_scene("u_sceneNormal", uniforms, m_sceneRender.normalFbo, uio); do_pass_scenebuffer("u_sceneBuffer", uniforms, {nullptr, &m_sceneRender.buffersFbo}, uio); - do_pass_scene("u_scene", uniforms, {&m_sceneRender.renderFbo, nullptr}, uio); + do_pass_scene("u_scene", uniforms, m_sceneRender.renderFbo, uio); do_pass_scenedepth("u_sceneDepth", uniforms, {&m_sceneRender.renderFbo, nullptr}, uio); } From 6232d7ac9527e94dc4dc80bd35e0bc45e6ed54d4 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:37:46 +0100 Subject: [PATCH 74/76] prefer customised parameters: do_pass_scenebuffer --- src/core/sandbox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index 57cba1a6..f1cf2c65 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1984,8 +1984,8 @@ void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const vera: if (uniforms.functions[prompt_id].present) { print_fbo_text(fbo, prompt_id, uio); } } -void do_pass_scenebuffer(const std::string& prompt_id, Uniforms& , const render_pass_args_t& current, render_ui_t& uio) { - for(const auto& fbo : (*current.fbolist)) { print_fbo_text(*fbo, prompt_id, uio); } +void do_pass_scenebuffer(const std::string& prompt_id, const BuffersList& fbolist, render_ui_t& uio) { + for(const auto& fbo : fbolist) { print_fbo_text(*fbo, prompt_id, uio); } } void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { @@ -2056,7 +2056,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, do_pass_lightmap("u_lightShadowMap", uniforms, uio); do_pass_scene("u_scenePosition", uniforms, m_sceneRender.positionFbo, uio); do_pass_scene("u_sceneNormal", uniforms, m_sceneRender.normalFbo, uio); - do_pass_scenebuffer("u_sceneBuffer", uniforms, {nullptr, &m_sceneRender.buffersFbo}, uio); + do_pass_scenebuffer("u_sceneBuffer", m_sceneRender.buffersFbo, uio); do_pass_scene("u_scene", uniforms, m_sceneRender.renderFbo, uio); do_pass_scenedepth("u_sceneDepth", uniforms, {&m_sceneRender.renderFbo, nullptr}, uio); } From 1377ce9ebfbf516837c02fd0c435dfa6058c6fce Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:39:37 +0100 Subject: [PATCH 75/76] prefer customised parameters: do_pass_scenedepth --- src/core/sandbox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index f1cf2c65..e90fec93 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1988,10 +1988,10 @@ void do_pass_scenebuffer(const std::string& prompt_id, const BuffersList& fbolis for(const auto& fbo : fbolist) { print_fbo_text(*fbo, prompt_id, uio); } } -void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const render_pass_args_t& current, render_ui_t& uio) { +void do_pass_scenedepth(const std::string& prompt_id, Uniforms& uniforms, const vera::Fbo& fbo, render_ui_t& uio) { if (!uniforms.functions[prompt_id].present) { return; } if (uniforms.activeCamera) - vera::imageDepth(*current.fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); + vera::imageDepth(fbo, uio.offset.x, uio.offset.y, uio.step.x, uio.step.y, uniforms.activeCamera->getFarClip(), uniforms.activeCamera->getNearClip()); print_text(prompt_id, uio.offset.x - uio.step.x, uio); } @@ -2058,7 +2058,7 @@ void process_render_passes(Uniforms& uniforms, const SceneRender& m_sceneRender, do_pass_scene("u_sceneNormal", uniforms, m_sceneRender.normalFbo, uio); do_pass_scenebuffer("u_sceneBuffer", m_sceneRender.buffersFbo, uio); do_pass_scene("u_scene", uniforms, m_sceneRender.renderFbo, uio); - do_pass_scenedepth("u_sceneDepth", uniforms, {&m_sceneRender.renderFbo, nullptr}, uio); + do_pass_scenedepth("u_sceneDepth", uniforms, m_sceneRender.renderFbo, uio); } namespace overlay_actions { From 8d1d75c3d43b0a0c15376379ab5870ff8e7a3ac5 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Wed, 28 Dec 2022 08:40:02 +0100 Subject: [PATCH 76/76] removed: render_pass_args_t --- src/core/sandbox.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/core/sandbox.cpp b/src/core/sandbox.cpp index e90fec93..17db399b 100644 --- a/src/core/sandbox.cpp +++ b/src/core/sandbox.cpp @@ -1975,11 +1975,6 @@ void print_buffers_text(const vera::Fbo& uniforms_buffer, size_t i, const std::s } namespace render_pass_actions { -struct render_pass_args_t { - const vera::Fbo* const fbo; - const BuffersList* const fbolist; -}; - void do_pass_scene(const std::string& prompt_id, Uniforms& uniforms, const vera::Fbo& fbo, render_ui_t& uio) { if (uniforms.functions[prompt_id].present) { print_fbo_text(fbo, prompt_id, uio); } }