Skip to content

Commit

Permalink
[misc] minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Jan 7, 2025
1 parent 7a29e8a commit 53dc757
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion editor/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ namespace

namespace buttons_toolbar
{
float button_size = 19.0f;
float button_size = 19.0f;
unordered_map<IconType, Widget*> widgets;

// a button that when pressed will call "on press" and derives it's color (active/inactive) based on "get_visibility".
Expand Down
5 changes: 2 additions & 3 deletions editor/Widgets/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#pragma once

//= INCLUDES ================
//= INCLUDES ======
#include "Widget.h"
#include "RHI/RHI_Viewport.h"
//===========================
//=================

class Viewport : public Widget
{
Expand Down
18 changes: 10 additions & 8 deletions runtime/Physics/PhysicsDebugDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "../Rendering/Renderer.h"
//================================

//= NAMESPACES =====
//= NAMESPACES ===============
using namespace std;
//==================
using namespace Spartan::Math;
//============================

namespace Spartan
{
Expand All @@ -49,20 +50,21 @@ namespace Spartan
void PhysicsDebugDraw::drawLine(const btVector3& from, const btVector3& to, const btVector3& color_from, const btVector3& color_to)
{
// a bit dangerous to reinterpret these parameters but this is a performance critical path
// a better way would be to use a custom physics debug draw since the one from Bullet is a cpu hog
// a better way would be to use a custom physics debug draw since the one from Bullet is extremely slow
Renderer::DrawLine(
reinterpret_cast<const Math::Vector3&>(from),
reinterpret_cast<const Math::Vector3&>(to),
reinterpret_cast<const Vector3&>(from),
reinterpret_cast<const Vector3&>(to),
reinterpret_cast<const Color&>(color_from),
reinterpret_cast<const Color&>(color_to),
true
);
}

void PhysicsDebugDraw::drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color)
void PhysicsDebugDraw::drawContactPoint(const btVector3& point_on_b, const btVector3& normal_on_b, btScalar distance, int life_time, const btVector3& color)
{
const btVector3& from = PointOnB;
const btVector3 to = PointOnB + normalOnB * distance;
const btVector3& from = point_on_b;
const btVector3 to = point_on_b + normal_on_b * distance;

drawLine(from, to, color);
}

Expand Down
35 changes: 17 additions & 18 deletions runtime/Rendering/Renderer_Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,26 +2116,21 @@ namespace Spartan
if (!shader_v->IsCompiled() || !shader_p->IsCompiled())
return;

cmd_list->BeginTimeblock("lines");

// set pipeline state
static RHI_PipelineState pso;
pso.shaders[RHI_Shader_Type::Vertex] = shader_v;
pso.shaders[RHI_Shader_Type::Pixel] = shader_p;
pso.rasterizer_state = GetRasterizerState(Renderer_RasterizerState::Solid);
pso.render_target_color_textures[0] = tex_out;
pso.clear_color[0] = rhi_color_load;
pso.render_target_depth_texture = GetRenderTarget(Renderer_RenderTarget::gbuffer_depth_output);
pso.primitive_toplogy = RHI_PrimitiveTopology::LineList;

// draw independent lines
const bool draw_lines_depth_off = m_lines_index_depth_off != numeric_limits<uint32_t>::max();
const bool draw_lines_depth_on = m_lines_index_depth_on > ((m_line_vertices.size() / 2) - 1);
if ((draw_lines_depth_off || draw_lines_depth_on) && !m_line_vertices.empty())
{
m_pcb_pass_cpu.transform = Matrix::Identity;
cmd_list->PushConstants(m_pcb_pass_cpu);
cmd_list->SetCullMode(RHI_CullMode::None);
cmd_list->BeginTimeblock("lines");

// set pipeline state
static RHI_PipelineState pso;
pso.shaders[RHI_Shader_Type::Vertex] = shader_v;
pso.shaders[RHI_Shader_Type::Pixel] = shader_p;
pso.rasterizer_state = GetRasterizerState(Renderer_RasterizerState::Solid);
pso.render_target_color_textures[0] = tex_out;
pso.clear_color[0] = rhi_color_load;
pso.render_target_depth_texture = GetRenderTarget(Renderer_RenderTarget::gbuffer_depth_output);
pso.primitive_toplogy = RHI_PrimitiveTopology::LineList;

// grow vertex buffer (if needed)
uint32_t vertex_count = static_cast<uint32_t>(m_line_vertices.size());
Expand All @@ -2149,6 +2144,10 @@ namespace Spartan
memset(buffer, 0, m_vertex_buffer_lines->GetObjectSize());
copy(m_line_vertices.begin(), m_line_vertices.end(), buffer);

m_pcb_pass_cpu.transform = Matrix::Identity;
cmd_list->PushConstants(m_pcb_pass_cpu);
cmd_list->SetCullMode(RHI_CullMode::None);

// depth off
if (draw_lines_depth_off)
{
Expand All @@ -2174,12 +2173,12 @@ namespace Spartan
}

cmd_list->SetCullMode(RHI_CullMode::Back);

cmd_list->EndTimeblock();
}

m_lines_index_depth_off = numeric_limits<uint32_t>::max(); // max +1 will wrap it to 0
m_lines_index_depth_on = (static_cast<uint32_t>(m_line_vertices.size()) / 2) - 1; // -1 because +1 will make it go to size / 2

cmd_list->EndTimeblock();
}

void Renderer::Pass_Outline(RHI_CommandList* cmd_list, RHI_Texture* tex_out)
Expand Down

0 comments on commit 53dc757

Please sign in to comment.