Debug line drawing
This commit is contained in:
@@ -12,12 +12,10 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "KeyboardMovementController.hpp"
|
||||
#include "buffers/HostSingleT.hpp"
|
||||
#include "camera/Camera.hpp"
|
||||
#include "camera/CameraManager.hpp"
|
||||
#include "engine/Average.hpp"
|
||||
#include "engine/assets/TransferManager.hpp"
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include "engine/literals/size.hpp"
|
||||
#include "model/builders/SceneBuilder.hpp"
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#define FGL_DELETE_DEFAULT_CTOR( ClassName ) ClassName() = delete;
|
||||
#define FGL_DELETE_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = delete;
|
||||
#define FGL_DELETE_COPY_CTOR( ClassName ) ClassName( const ClassName& ) = delete;
|
||||
@@ -36,11 +34,18 @@
|
||||
//! Warns if the structure field is not alligned with a set number of bytes
|
||||
#define FGL_STRICT_ALIGNMENT( bytesize ) [[gnu::warn_if_not_aligned( bytesize )]]
|
||||
|
||||
#define FGL_ASSERT( ... ) assert( __VA_ARGS__ );
|
||||
#ifndef NDEBUG
|
||||
#include <stdexcept>
|
||||
#define FGL_ASSERT( test, msg ) \
|
||||
if ( !( test ) ) throw std::runtime_error( msg );
|
||||
#else
|
||||
#define FGL_ASSERT( test, msg )
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
#include <utility>
|
||||
#define FGL_UNREACHABLE() \
|
||||
FGL_ASSERT( false ); \
|
||||
FGL_ASSERT( false, "Should have been unreachable!" ); \
|
||||
std::unreachable()
|
||||
#else
|
||||
#define FGL_UNREACHABLE() std::unreachable()
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "camera/Camera.hpp"
|
||||
#include "camera/CameraSwapchain.hpp"
|
||||
#include "pipeline/Pipeline.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -20,4 +21,9 @@ namespace fgl::engine
|
||||
return camera->getDescriptor( frame_idx );
|
||||
}
|
||||
|
||||
void FrameInfo::bindCamera( internal::Pipeline& pipeline )
|
||||
{
|
||||
//TODO: This
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "descriptors/Descriptor.hpp"
|
||||
#include "descriptors/DescriptorSetLayout.hpp"
|
||||
#include "pipeline/Pipeline.hpp"
|
||||
#include "primitives/Frustum.hpp"
|
||||
#include "rendering/types.hpp"
|
||||
|
||||
@@ -98,6 +99,9 @@ namespace fgl::engine
|
||||
SwapChain& swap_chain;
|
||||
|
||||
std::vector< std::vector< GameObject >* > in_view_leafs {};
|
||||
|
||||
//! Binds the camera descriptor to the command buffer
|
||||
void bindCamera( internal::Pipeline& pipeline );
|
||||
};
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace fgl::engine::memory
|
||||
void* BufferSuballocation::ptr() const
|
||||
{
|
||||
assert( m_handle != nullptr );
|
||||
FGL_ASSERT( m_handle->mapped, "Buffer must be mappable to use `ptr()`" );
|
||||
return m_handle->mapped;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "Camera.hpp"
|
||||
#include "engine/debug/DEBUG_NAMES.hpp"
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include "engine/literals/size.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
@@ -43,8 +42,6 @@ namespace fgl::engine
|
||||
|
||||
m_primary_camera = createCamera( { 1920, 1080 } );
|
||||
m_primary_camera->setName( CAMERA_EDITOR_NAME );
|
||||
|
||||
debug::setDebugDrawingCamera( getPrimary() );
|
||||
}
|
||||
|
||||
std::shared_ptr< Camera > CameraManager::createCamera( const vk::Extent2D extent )
|
||||
|
||||
@@ -140,6 +140,7 @@ namespace fgl::engine
|
||||
//m_terrain_system.pass( frame_info );
|
||||
|
||||
m_entity_renderer.pass( frame_info );
|
||||
m_line_drawer.pass( frame_info );
|
||||
|
||||
m_composition_system.pass( frame_info );
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "engine/systems/CompositionSystem.hpp"
|
||||
#include "engine/systems/CullingSystem.hpp"
|
||||
#include "engine/systems/EntityRendererSystem.hpp"
|
||||
#include "engine/systems/LineDrawer.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -26,6 +27,7 @@ namespace fgl::engine
|
||||
// SubPass 0
|
||||
//TerrainSystem m_terrain_system { Device::getInstance(), m_renderpass };
|
||||
EntityRendererSystem m_entity_renderer { Device::getInstance(), m_renderpass };
|
||||
LineDrawer m_line_drawer { Device::getInstance(), m_renderpass };
|
||||
|
||||
// SubPass 1
|
||||
CompositionSystem m_composition_system { Device::getInstance(), m_renderpass };
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
//
|
||||
// Created by kj16609 on 1/28/24.
|
||||
//
|
||||
|
||||
#include "drawers.hpp"
|
||||
|
||||
#include "engine/camera/Camera.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp"
|
||||
#include "engine/primitives/boxes/OrientedBoundingBox.hpp"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
#include "imgui/imgui.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
#include "tracy_colors.hpp"
|
||||
|
||||
#if ENABLE_IMGUI_DRAWERS
|
||||
|
||||
namespace fgl::engine::debug
|
||||
{
|
||||
inline static std::optional< std::shared_ptr< Camera > > debug_camera { std::nullopt };
|
||||
|
||||
Camera& getDebugDrawingCamera()
|
||||
{
|
||||
assert( debug_camera.has_value() && debug_camera.value() != nullptr && "Debug camera not set" );
|
||||
return *debug_camera.value();
|
||||
}
|
||||
|
||||
void setDebugDrawingCamera( std::shared_ptr< Camera >& cam )
|
||||
{
|
||||
assert( cam );
|
||||
debug_camera = cam;
|
||||
}
|
||||
|
||||
const ImVec2 windowSize()
|
||||
{
|
||||
return ImGui::GetMainViewport()->Size;
|
||||
}
|
||||
|
||||
Coordinate< CoordinateSpace::Screen > toScreenSpace( Coordinate< CoordinateSpace::World > world_point )
|
||||
{
|
||||
const ImVec2 window_size { windowSize() };
|
||||
|
||||
const Coordinate< CoordinateSpace::Screen > screen_point { glm::projectZO(
|
||||
world_point.vec(),
|
||||
glm::mat4( 1.0f ),
|
||||
getDebugDrawingCamera().getProjectionViewMatrix(),
|
||||
glm::vec4( 0.0f, 0.0f, window_size.x, window_size.y ) ) };
|
||||
|
||||
return screen_point;
|
||||
}
|
||||
|
||||
ImVec2 glmToImgui( const glm::vec2 vec )
|
||||
{
|
||||
return ImVec2( vec.x, vec.y );
|
||||
}
|
||||
|
||||
ImVec2 glmToImgui( const Coordinate< CoordinateSpace::Screen > coordinate )
|
||||
{
|
||||
return glmToImgui( coordinate.vec() );
|
||||
}
|
||||
|
||||
bool isBehind( const glm::vec3 point )
|
||||
{
|
||||
return point.z > 1.0f || point.z < 0.0f;
|
||||
}
|
||||
|
||||
bool inView( const glm::vec3 point )
|
||||
{
|
||||
const ImVec2 window_size { windowSize() };
|
||||
|
||||
return !isBehind( point ) && ( point.x > 0.0f && point.x < window_size.x )
|
||||
&& ( point.y > 0.0f && point.y < window_size.y );
|
||||
}
|
||||
|
||||
namespace world
|
||||
{
|
||||
|
||||
inline void
|
||||
drawLineI( const LineSegment< CoordinateSpace::World > line, const glm::vec3 color, const float thickness )
|
||||
{
|
||||
//Check if the line in intersecting the frustum
|
||||
if ( getDebugDrawingCamera().getFrustumBounds().intersects( line ) )
|
||||
drawLine( line, glm::vec3( 0.0f, 1.0f, 0.0f ), thickness );
|
||||
else
|
||||
drawLine( line, color, thickness );
|
||||
}
|
||||
|
||||
void drawBoundingBox( const OrientedBoundingBox< CoordinateSpace::World >& box, const glm::vec3 color )
|
||||
{
|
||||
ZoneScopedC( TRACY_DRAWER_FUNC_COLOR );
|
||||
for ( const auto& line : box.lines() )
|
||||
{
|
||||
auto p1 { line.getPosition() };
|
||||
auto p2 { line.getEnd() };
|
||||
drawLine( LineSegment( p1, p2 ), color );
|
||||
}
|
||||
|
||||
for ( const auto point : box.points() )
|
||||
{
|
||||
drawPointText( point, color );
|
||||
}
|
||||
}
|
||||
|
||||
void drawBoundingBox( const AxisAlignedBoundingBox< CoordinateSpace::World >& box, const glm::vec3 color )
|
||||
{
|
||||
ZoneScopedC( TRACY_DRAWER_FUNC_COLOR );
|
||||
for ( const auto& line : box.lines() )
|
||||
{
|
||||
auto p1 { line.getPosition() };
|
||||
auto p2 { line.getEnd() };
|
||||
drawLine( LineSegment( p1, p2 ), color );
|
||||
}
|
||||
|
||||
for ( const auto point : box.points() )
|
||||
{
|
||||
drawPointText( point, color );
|
||||
}
|
||||
}
|
||||
|
||||
void drawBoundingBox( const AxisAlignedBoundingCube< CoordinateSpace::World >& box, const glm::vec3 color )
|
||||
{
|
||||
ZoneScopedC( TRACY_DRAWER_FUNC_COLOR );
|
||||
for ( const auto& line : box.lines() )
|
||||
{
|
||||
auto p1 { line.getPosition() };
|
||||
auto p2 { line.getEnd() };
|
||||
drawLine( LineSegment( p1, p2 ), color );
|
||||
}
|
||||
|
||||
for ( const auto point : box.points() )
|
||||
{
|
||||
drawPointText( point, color );
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
drawLine( const LineSegment< CoordinateSpace::World > line, const glm::vec3 color, const float thickness )
|
||||
{
|
||||
Coordinate< CoordinateSpace::Screen > start_screen { toScreenSpace( line.getPosition() ) };
|
||||
Coordinate< CoordinateSpace::Screen > end_screen { toScreenSpace( line.getEnd() ) };
|
||||
|
||||
if ( isBehind( start_screen.vec() ) && isBehind( end_screen.vec() ) ) return;
|
||||
|
||||
const auto frustum { getDebugDrawingCamera().getFrustumBounds() };
|
||||
|
||||
if ( !frustum.intersects( line ) ) return;
|
||||
|
||||
//Check if either point is behind the camera
|
||||
if ( isBehind( start_screen.vec() ) )
|
||||
{
|
||||
const auto new_line { line.flip() };
|
||||
|
||||
const auto new_point { frustum.intersection( new_line ) };
|
||||
|
||||
start_screen = toScreenSpace( new_point );
|
||||
}
|
||||
else if ( isBehind( end_screen.vec() ) )
|
||||
{
|
||||
const auto new_point { frustum.intersection( line ) };
|
||||
|
||||
end_screen = toScreenSpace( new_point );
|
||||
}
|
||||
|
||||
if ( glm::any( glm::isnan( end_screen.vec() ) ) || glm::any( glm::isnan( start_screen.vec() ) ) ) return;
|
||||
|
||||
ImGui::GetBackgroundDrawList()->AddLine(
|
||||
glmToImgui( start_screen ), glmToImgui( end_screen ), ImColor( color.x, color.y, color.z ), thickness );
|
||||
}
|
||||
|
||||
void drawLine(
|
||||
const Coordinate< CoordinateSpace::World > start,
|
||||
const Coordinate< CoordinateSpace::World > end,
|
||||
const glm::vec3 color )
|
||||
{
|
||||
drawLine( LineSegment( start, end ), color );
|
||||
}
|
||||
|
||||
void drawPointText( const Coordinate< CoordinateSpace::World > point, const glm::vec3 color )
|
||||
{
|
||||
const glm::vec3 screen_point { toScreenSpace( point ).vec() };
|
||||
|
||||
if ( !inView( screen_point ) ) return;
|
||||
|
||||
drawPoint( point, "", color );
|
||||
|
||||
const std::string text { "World: (" + std::to_string( point.vec().x ) + ", "
|
||||
+ std::to_string( point.vec().y ) + ", " + std::to_string( point.vec().z ) + ")" };
|
||||
|
||||
screen::drawText( glm::vec2( screen_point.x, screen_point.y ), text, color, glm::vec2( 0.0f, 20.f ) );
|
||||
|
||||
const std::string text2 { "Screen: (" + std::to_string( screen_point.x ) + ", "
|
||||
+ std::to_string( screen_point.y ) + ", " + std::to_string( screen_point.z )
|
||||
+ ")" };
|
||||
|
||||
screen::drawText( glm::vec2( screen_point.x, screen_point.y ), text2, color, glm::vec2( 0.0f, 30.0f ) );
|
||||
|
||||
const Frustum frustum { getDebugDrawingCamera().getFrustumBounds() };
|
||||
//const bool in_view { frustum.pointInside( point ) };
|
||||
//TODO: This
|
||||
const bool in_view { false };
|
||||
|
||||
drawBoolAlpha( point, in_view, glm::vec2( 0.0f, 40.0f ) );
|
||||
}
|
||||
|
||||
void drawPointLabel( const Coordinate< CoordinateSpace::World > point, const std::string label )
|
||||
{
|
||||
const glm::vec3 screen_point { toScreenSpace( point ).vec() };
|
||||
|
||||
if ( !inView( screen_point ) ) return;
|
||||
|
||||
screen::drawText( glm::vec2( screen_point.x, screen_point.y ), label );
|
||||
}
|
||||
|
||||
void drawPoint(
|
||||
const Coordinate< CoordinateSpace::World > point, const std::string label, const glm::vec3 color )
|
||||
{
|
||||
const glm::vec3 screen_point { toScreenSpace( point ).vec() };
|
||||
if ( !inView( screen_point ) ) return;
|
||||
|
||||
const float div { screen_point.z };
|
||||
|
||||
ImGui::GetBackgroundDrawList()
|
||||
->AddCircleFilled( glmToImgui( screen_point ), div * 5.0f, ImColor( color.x, color.y, color.z ) );
|
||||
|
||||
drawPointLabel( point, label );
|
||||
}
|
||||
|
||||
void drawBoolAlpha( const Coordinate< CoordinateSpace::World > point, const bool value, const glm::vec2 offset )
|
||||
{
|
||||
const auto screen_point { toScreenSpace( point ) };
|
||||
|
||||
const auto color { value ? glm::vec3( 0.0f, 1.0f, 0.0f ) : glm::vec3( 1.0f, 0.0f, 0.0f ) };
|
||||
|
||||
screen::drawText(
|
||||
glm::vec2( screen_point.vec().x, screen_point.vec().y + offset.y ), value ? "true" : "false", color );
|
||||
}
|
||||
|
||||
void drawVector(
|
||||
const Coordinate< CoordinateSpace::World > point,
|
||||
Vector vector,
|
||||
const std::string label,
|
||||
const glm::vec3 color )
|
||||
{
|
||||
drawLine( point, point + vector, color );
|
||||
drawPoint( point + vector, label, color );
|
||||
drawPoint( point, "", color );
|
||||
//drawPointLabel( point, label );
|
||||
//drawPointText( point + glm::normalize( vector ) );
|
||||
|
||||
//Draw ending lines for the vector (two perpendicular lines)
|
||||
const WorldCoordinate perpendicular_vector {
|
||||
glm::normalize( glm::cross( vector.vec(), glm::vec3( 0.0f, 1.0f, 0.0f ) ) ) / 4.0f
|
||||
};
|
||||
const WorldCoordinate perpendicular_vector2 {
|
||||
glm::normalize( glm::cross( vector.vec(), perpendicular_vector.vec() ) ) / 4.0f
|
||||
};
|
||||
|
||||
drawLine(
|
||||
point + glm::normalize( vector.vec() ) + perpendicular_vector,
|
||||
point + glm::normalize( vector.vec() ) - perpendicular_vector,
|
||||
color );
|
||||
|
||||
drawLine(
|
||||
point + glm::normalize( vector.vec() ) + perpendicular_vector2,
|
||||
point + glm::normalize( vector.vec() ) - perpendicular_vector2,
|
||||
color );
|
||||
}
|
||||
|
||||
void drawVector(
|
||||
const Coordinate< CoordinateSpace::World > point,
|
||||
NormalVector vector,
|
||||
const std::string label,
|
||||
const glm::vec3 color )
|
||||
{
|
||||
drawVector( point, Vector( vector ), label, color );
|
||||
}
|
||||
|
||||
void drawFrustum(
|
||||
const Frustum< CoordinateSpace::World >& frustum, [[maybe_unused]] const WorldCoordinate point )
|
||||
{
|
||||
drawPlane( frustum.near, frustum.near.getPosition(), "near" );
|
||||
drawPlane( frustum.far, frustum.far.getPosition(), "far" );
|
||||
drawPlane( frustum.top, frustum.top.getPosition(), "top" );
|
||||
drawPlane( frustum.bottom, frustum.bottom.getPosition(), "bottom" );
|
||||
drawPlane( frustum.right, frustum.right.getPosition(), "right" );
|
||||
drawPlane( frustum.left, frustum.left.getPosition(), "left" );
|
||||
}
|
||||
|
||||
void drawFrustum()
|
||||
{
|
||||
const Frustum frustum { getDebugDrawingCamera().getFrustumBounds() };
|
||||
drawFrustum( frustum, getDebugDrawingCamera().getFrustumPosition() );
|
||||
}
|
||||
|
||||
void drawPlane(
|
||||
const Plane< CoordinateSpace::World >& plane,
|
||||
const WorldCoordinate point,
|
||||
const std::string label,
|
||||
const glm::vec3 color )
|
||||
{
|
||||
const NormalVector normal { plane.getDirection() };
|
||||
|
||||
assert( point.vec() != constants::DEFAULT_VEC3 );
|
||||
|
||||
drawLine( point, point + normal, color );
|
||||
drawPoint( point + normal, label, color );
|
||||
}
|
||||
|
||||
} // namespace world
|
||||
|
||||
namespace screen
|
||||
{
|
||||
void
|
||||
drawText( const glm::vec2 position, const std::string& text, const glm::vec3 color, const glm::vec2 offset )
|
||||
{
|
||||
ImGui::GetBackgroundDrawList()
|
||||
->AddText( glmToImgui( position + offset ), ImColor( color.x, color.y, color.z ), text.c_str() );
|
||||
}
|
||||
|
||||
void drawBoolAlpha(
|
||||
const glm::vec2 screen_point,
|
||||
[[maybe_unused]] const Camera& camera,
|
||||
const bool value,
|
||||
const glm::vec2 offset )
|
||||
{
|
||||
const auto color { value ? glm::vec3( 0.0f, 1.0f, 0.0f ) : glm::vec3( 1.0f, 0.0f, 0.0f ) };
|
||||
drawText( glm::vec2( screen_point.x, screen_point.y + offset.y ), value ? "true" : "false", color );
|
||||
}
|
||||
|
||||
} // namespace screen
|
||||
|
||||
} // namespace fgl::engine::debug
|
||||
|
||||
#endif
|
||||
@@ -1,203 +0,0 @@
|
||||
//
|
||||
// Created by kj16609 on 1/28/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "engine/primitives/Frustum.hpp"
|
||||
#include "engine/primitives/lines/LineSegment.hpp"
|
||||
#include "engine/primitives/planes/PointPlane.hpp"
|
||||
#include "engine/primitives/points/Coordinate.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
template < CoordinateSpace type >
|
||||
struct OrientedBoundingBox;
|
||||
template < CoordinateSpace type >
|
||||
class AxisAlignedBoundingBox;
|
||||
template < CoordinateSpace type >
|
||||
class AxisAlignedBoundingCube;
|
||||
|
||||
template < CoordinateSpace type >
|
||||
class Coordinate;
|
||||
|
||||
template < CoordinateSpace type >
|
||||
class LineSegment;
|
||||
|
||||
class Camera;
|
||||
|
||||
struct SinglePointDistancePlane;
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
#ifndef ENABLE_IMGUI_DRAWERS
|
||||
#define ENABLE_IMGUI_DRAWERS 0
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_IMGUI
|
||||
#define ENABLE_IMGUI 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_IMGUI_DRAWERS
|
||||
namespace fgl::engine::debug
|
||||
{
|
||||
Camera& getDebugDrawingCamera();
|
||||
void setDebugDrawingCamera( std::shared_ptr< Camera >& );
|
||||
|
||||
namespace world
|
||||
{
|
||||
void drawBoundingBox(
|
||||
const OrientedBoundingBox< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
void drawBoundingBox(
|
||||
const AxisAlignedBoundingBox< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
void drawBoundingBox(
|
||||
const AxisAlignedBoundingCube< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
void drawLine(
|
||||
Coordinate< CoordinateSpace::World > start,
|
||||
Coordinate< CoordinateSpace::World > end,
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
void drawPointLabel( Coordinate< CoordinateSpace::World > point, std::string label );
|
||||
|
||||
void drawLineI(
|
||||
LineSegment< CoordinateSpace::World > line,
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f },
|
||||
float thickness = 1.0f );
|
||||
void drawLine(
|
||||
LineSegment< CoordinateSpace::World > line,
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f },
|
||||
float thickness = 1.0f );
|
||||
|
||||
void drawPointText( Coordinate< CoordinateSpace::World > point, glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
void drawBoolAlpha( Coordinate< CoordinateSpace::World > point, bool value, glm::vec2 offset = {} );
|
||||
void drawPoint(
|
||||
Coordinate< CoordinateSpace::World > point,
|
||||
std::string label = "",
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
void drawVector(
|
||||
Coordinate< CoordinateSpace::World > point,
|
||||
Vector vector,
|
||||
std::string label = "",
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
void drawVector(
|
||||
Coordinate< CoordinateSpace::World > point,
|
||||
NormalVector vector,
|
||||
std::string label = "",
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
void drawFrustum( const Frustum< CoordinateSpace::World >& frustum, WorldCoordinate coordinate );
|
||||
void drawFrustum();
|
||||
|
||||
void drawPlane(
|
||||
const Plane< CoordinateSpace::World >& plane,
|
||||
WorldCoordinate point,
|
||||
std::string label = "",
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f } );
|
||||
|
||||
} // namespace world
|
||||
|
||||
namespace screen
|
||||
{
|
||||
|
||||
void drawText(
|
||||
glm::vec2 position,
|
||||
const std::string& text,
|
||||
glm::vec3 color = { 1.0f, 1.0f, 1.0f },
|
||||
glm::vec2 offset = {} );
|
||||
|
||||
void drawBoolAlpha( glm::vec2 screen_point, const Camera& camera, bool value, glm::vec2 offset = {} );
|
||||
|
||||
} // namespace screen
|
||||
|
||||
} // namespace fgl::engine::debug
|
||||
#else
|
||||
|
||||
namespace fgl::engine::debug
|
||||
{
|
||||
inline void setDebugDrawingCamera( [[maybe_unused]] Camera& cam )
|
||||
{}
|
||||
|
||||
namespace world
|
||||
{
|
||||
|
||||
//Dummy functions
|
||||
inline void drawBoundingBox(
|
||||
[[maybe_unused]] const OrientedBoundingBox< CoordinateSpace::World >&, [[maybe_unused]] const glm::vec3 )
|
||||
{}
|
||||
|
||||
inline void drawBoundingBox( [[maybe_unused]] const OrientedBoundingBox< CoordinateSpace::World >& )
|
||||
{}
|
||||
|
||||
inline void drawLine(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >,
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >,
|
||||
[[maybe_unused]] const glm::vec3,
|
||||
[[maybe_unused]] const float )
|
||||
{}
|
||||
|
||||
inline void drawPointLabel(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >, [[maybe_unused]] const std::string )
|
||||
{}
|
||||
|
||||
inline void drawLine(
|
||||
[[maybe_unused]] const Line< CoordinateSpace::World >,
|
||||
[[maybe_unused]] const glm::vec3,
|
||||
[[maybe_unused]] const float )
|
||||
{}
|
||||
|
||||
inline void drawPointText(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >, [[maybe_unused]] const glm::vec3 )
|
||||
{}
|
||||
|
||||
inline void drawBoolAlpha(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >,
|
||||
[[maybe_unused]] const Camera&,
|
||||
[[maybe_unused]] const bool,
|
||||
[[maybe_unused]] const glm::vec2 )
|
||||
{}
|
||||
|
||||
inline void drawPoint(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >,
|
||||
[[maybe_unused]] const std::string,
|
||||
[[maybe_unused]] const glm::vec3 )
|
||||
{}
|
||||
|
||||
inline void drawVector(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >,
|
||||
[[maybe_unused]] Vector,
|
||||
[[maybe_unused]] const std::string,
|
||||
[[maybe_unused]] const glm::vec3 )
|
||||
{}
|
||||
|
||||
inline void drawVector(
|
||||
[[maybe_unused]] const Coordinate< CoordinateSpace::World >,
|
||||
[[maybe_unused]] NormalVector,
|
||||
[[maybe_unused]] const std::string,
|
||||
[[maybe_unused]] const glm::vec3 )
|
||||
{}
|
||||
|
||||
inline void drawFrustum(
|
||||
[[maybe_unused]] const Frustum< CoordinateSpace::World >&, [[maybe_unused]] const WorldCoordinate )
|
||||
{}
|
||||
|
||||
inline void drawFrustum()
|
||||
{}
|
||||
|
||||
inline void drawPlane(
|
||||
[[maybe_unused]] const Plane< CoordinateSpace::World >&,
|
||||
[[maybe_unused]] const WorldCoordinate,
|
||||
[[maybe_unused]] const std::string,
|
||||
[[maybe_unused]] const glm::vec3 )
|
||||
{}
|
||||
|
||||
} // namespace world
|
||||
|
||||
} // namespace fgl::engine::debug
|
||||
|
||||
#endif
|
||||
@@ -76,4 +76,30 @@ namespace fgl::engine::descriptors
|
||||
using PushConstantT = BindingSet< 0 >;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DescriptorSetCollection<>
|
||||
{
|
||||
using DescriptorSetTuple = std::tuple< void >;
|
||||
|
||||
static constexpr auto SIZE { 0 };
|
||||
|
||||
static constexpr std::uint64_t DescriptorSetCount { 0 };
|
||||
|
||||
//If the first descriptor set is a constant range, then the pipeline has a constant range
|
||||
static constexpr bool has_constant_range { false };
|
||||
|
||||
static constexpr std::uint16_t binding_sets { 0 };
|
||||
|
||||
static constexpr std::uint16_t max_binding_set { 0 };
|
||||
|
||||
static constexpr std::uint16_t set_count { 0 };
|
||||
|
||||
static constexpr std::uint16_t empty_sets { 0 };
|
||||
|
||||
template < std::uint64_t BindingIDX >
|
||||
using BindingSet = void;
|
||||
|
||||
static std::vector< vk::raii::DescriptorSetLayout > createDescriptorSets() { return {}; }
|
||||
};
|
||||
|
||||
} // namespace fgl::engine::descriptors
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "engine/FGL_DEFINES.hpp"
|
||||
#include "engine/concepts/is_valid_pipeline_input.hpp"
|
||||
|
||||
namespace fgl::engine::descriptors
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace fgl::engine::filesystem
|
||||
|
||||
DirInfo::DirInfo( const std::filesystem::path& path ) : m_path( path ), total_size( 0 )
|
||||
{
|
||||
FGL_ASSERT( std::filesystem::exists( path ) );
|
||||
FGL_ASSERT( std::filesystem::exists( path ), "Path must exist" );
|
||||
for ( auto itter = std::filesystem::directory_iterator( path ); itter != std::filesystem::directory_iterator();
|
||||
++itter )
|
||||
{
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace fgl::engine
|
||||
return INVALID_TEXTURE_ID;
|
||||
}
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::World > Primitive::getWorldBounds() const
|
||||
OrientedBoundingBox< CoordinateSpace::Model > Primitive::getBoundingBox() const
|
||||
{
|
||||
return m_transform->mat() * m_bounding_box;
|
||||
return m_bounding_box;
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -74,8 +74,6 @@ namespace fgl::engine
|
||||
|
||||
PrimitiveTextures m_textures;
|
||||
|
||||
std::optional< TransformComponent > m_transform;
|
||||
|
||||
//! Returns true if the primitive is ready to be rendered (must have all textures, vertex buffer, and index buffer ready)
|
||||
bool ready() const { return m_textures.ready() && m_vertex_buffer.ready() && m_index_buffer.ready(); }
|
||||
|
||||
@@ -88,9 +86,10 @@ namespace fgl::engine
|
||||
m_index_buffer( std::move( index_buffer ) ),
|
||||
m_bounding_box( bounding_box ),
|
||||
m_mode( mode ),
|
||||
m_textures(),
|
||||
m_transform()
|
||||
{}
|
||||
m_textures()
|
||||
{
|
||||
assert( m_bounding_box.scale != glm::vec3( 0.0f ) );
|
||||
}
|
||||
|
||||
Primitive(
|
||||
VertexBufferSuballocation&& vertex_buffer,
|
||||
@@ -102,9 +101,10 @@ namespace fgl::engine
|
||||
m_index_buffer( std::move( index_buffer ) ),
|
||||
m_bounding_box( bounding_box ),
|
||||
m_mode( mode ),
|
||||
m_textures( std::forward< decltype( m_textures ) >( textures ) ),
|
||||
m_transform()
|
||||
{}
|
||||
m_textures( std::forward< decltype( m_textures ) >( textures ) )
|
||||
{
|
||||
assert( m_bounding_box.scale != glm::vec3( 0.0f ) );
|
||||
}
|
||||
|
||||
Primitive() = delete;
|
||||
Primitive( const Primitive& other ) = delete;
|
||||
@@ -119,7 +119,8 @@ namespace fgl::engine
|
||||
|
||||
TextureID getAlbedoTextureID() const;
|
||||
TextureID getNormalTextureID() const;
|
||||
OrientedBoundingBox< CoordinateSpace::World > getWorldBounds() const;
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > getBoundingBox() const;
|
||||
};
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -19,6 +19,11 @@ namespace fgl::engine
|
||||
info.assembly_info.topology = vk::PrimitiveTopology::eTriangleStrip;
|
||||
}
|
||||
|
||||
void PipelineConfigInfo::setLineTopo( PipelineConfigInfo& info )
|
||||
{
|
||||
info.assembly_info.topology = vk::PrimitiveTopology::eLineList;
|
||||
}
|
||||
|
||||
void PipelineConfigInfo::setPointPatch( PipelineConfigInfo& info )
|
||||
{
|
||||
info.assembly_info.topology = vk::PrimitiveTopology::ePatchList;
|
||||
|
||||
@@ -53,8 +53,11 @@ namespace fgl::engine
|
||||
static void setVertexInputType( PipelineConfigInfo& info, const VertexInputType type );
|
||||
|
||||
static void disableVertexInput( PipelineConfigInfo& info );
|
||||
|
||||
static void setTriangleListTopo( PipelineConfigInfo& info );
|
||||
static void setTriangleStripTopo( PipelineConfigInfo& info );
|
||||
static void setLineTopo( PipelineConfigInfo& info );
|
||||
|
||||
static void setQuadTesselation( PipelineConfigInfo& info );
|
||||
static void setPointPatch( PipelineConfigInfo& info );
|
||||
static void defaultConfig( PipelineConfigInfo& info );
|
||||
|
||||
@@ -21,18 +21,18 @@ namespace fgl::engine
|
||||
constexpr static std::uint16_t binding_sets { DescriptorSetCollection::binding_sets };
|
||||
constexpr static bool has_binding_sets { binding_sets != 0 };
|
||||
|
||||
//! Returns the binding type assocaited with the index
|
||||
template < std::uint16_t binding_set_idx >
|
||||
using BindingSet = typename DescriptorSetCollection::template BindingSet< binding_set_idx >;
|
||||
|
||||
constexpr static std::uint16_t max_binding_set { DescriptorSetCollection::max_binding_set };
|
||||
|
||||
constexpr static std::uint16_t set_count { DescriptorSetCollection::set_count };
|
||||
|
||||
constexpr static std::uint16_t empty_sets { DescriptorSetCollection::empty_sets };
|
||||
|
||||
//! Returns the binding type assocaited with the index
|
||||
template < std::uint16_t binding_set_idx >
|
||||
using BindingSet = typename DescriptorSetCollection::template BindingSet< binding_set_idx >;
|
||||
|
||||
static_assert(
|
||||
( set_count == 0 && has_constant_range ) || ( set_count == ( max_binding_set + 1 ) ),
|
||||
set_count == 0 || ( set_count == ( max_binding_set + 1 ) ),
|
||||
"Binding sets must not have any spaces (Use EmptySet<idx>)" );
|
||||
|
||||
template < std::uint16_t idx >
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
#include "Frustum.hpp"
|
||||
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp"
|
||||
#include "engine/primitives/boxes/OrientedBoundingBox.hpp"
|
||||
#include "lines/InfiniteLine.hpp"
|
||||
#include "lines/LineSegment.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -19,15 +19,16 @@ namespace fgl::engine
|
||||
|
||||
float dot { glm::dot( vector_between, direction.vec() ) };
|
||||
|
||||
assert( !std::isnan( dot ) );
|
||||
if ( std::isnan( dot ) ) return 0.0f;
|
||||
|
||||
assert( !std::isinf( dot ) );
|
||||
|
||||
return dot;
|
||||
}
|
||||
|
||||
void processPlane(
|
||||
const Plane< CoordinateSpace::World > plane,
|
||||
const LineSegment< CoordinateSpace::World > line,
|
||||
const Plane< CoordinateSpace::World >& plane,
|
||||
const LineSegment< CoordinateSpace::World >& line,
|
||||
std::vector< WorldCoordinate >& out_enter_intersections,
|
||||
std::vector< WorldCoordinate >& out_exit_intersections )
|
||||
{
|
||||
@@ -54,7 +55,7 @@ namespace fgl::engine
|
||||
}
|
||||
|
||||
WorldCoordinate getFirstExit(
|
||||
const std::vector< WorldCoordinate >& exit_intersections, const LineSegment< CoordinateSpace::World > line )
|
||||
const std::vector< WorldCoordinate >& exit_intersections, const LineSegment< CoordinateSpace::World >& line )
|
||||
{
|
||||
assert( exit_intersections.size() > 0 );
|
||||
|
||||
@@ -77,7 +78,7 @@ namespace fgl::engine
|
||||
}
|
||||
|
||||
WorldCoordinate getLastEnter(
|
||||
const std::vector< WorldCoordinate >& enter_intersections, const LineSegment< CoordinateSpace::World > line )
|
||||
const std::vector< WorldCoordinate >& enter_intersections, const LineSegment< CoordinateSpace::World >& line )
|
||||
{
|
||||
assert( enter_intersections.size() > 0 );
|
||||
|
||||
@@ -118,9 +119,6 @@ namespace fgl::engine
|
||||
processPlane( top, line, enter_intersections, exit_intersections );
|
||||
processPlane( bottom, line, enter_intersections, exit_intersections );
|
||||
|
||||
assert( enter_intersections.size() > 1 );
|
||||
assert( exit_intersections.size() > 1 );
|
||||
|
||||
if ( enter_intersections.size() == 0 ) return false;
|
||||
if ( exit_intersections.size() == 0 ) return false;
|
||||
|
||||
@@ -132,10 +130,7 @@ namespace fgl::engine
|
||||
|
||||
if ( show_intersect ) [[unlikely]]
|
||||
{
|
||||
debug::world::drawVector(
|
||||
last_enter, line.getDirection(), std::to_string( distance_to_enter ), glm::vec3( 0.f, 1.f, 0.0f ) );
|
||||
debug::world::drawVector(
|
||||
first_exit, line.getDirection(), std::to_string( distance_to_exit ), glm::vec3( 1.f, 0.f, 0.0f ) );
|
||||
//TODO:
|
||||
}
|
||||
|
||||
return distance_to_exit >= distance_to_enter;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -58,9 +58,11 @@ namespace fgl::engine
|
||||
Rotation::Rotation( const float pitch, const float roll, const float yaw ) :
|
||||
glm::quat( buildQuat( { pitch, roll, yaw } ) )
|
||||
{
|
||||
FGL_ASSERT( ::fgl::engine::pitch( *this ) - pitch < glm::epsilon< float >() );
|
||||
FGL_ASSERT( ::fgl::engine::yaw( *this ) - yaw < glm::epsilon< float >() );
|
||||
FGL_ASSERT( ::fgl::engine::roll( *this ) - roll < glm::epsilon< float >() );
|
||||
FGL_ASSERT(
|
||||
::fgl::engine::pitch( *this ) - pitch < glm::epsilon< float >(), "Rotation axis does not match input" );
|
||||
FGL_ASSERT( ::fgl::engine::yaw( *this ) - yaw < glm::epsilon< float >(), "Rotation axis does not match input" );
|
||||
FGL_ASSERT(
|
||||
::fgl::engine::roll( *this ) - roll < glm::epsilon< float >(), "Rotation axis does not match input" );
|
||||
}
|
||||
|
||||
RotationModifier< RotationModifierType::Roll > Rotation::roll()
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace fgl::engine::interface
|
||||
{
|
||||
|
||||
class NormalVector;
|
||||
struct NormalVector;
|
||||
|
||||
//! Dummy class to allow for inheriting to pass 'is_bounding_box[
|
||||
struct BoundingBox
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace fgl::engine
|
||||
|
||||
//Vectors
|
||||
class Vector;
|
||||
class NormalVector;
|
||||
struct NormalVector;
|
||||
|
||||
template < MatrixType MType >
|
||||
class Matrix : public glm::mat4
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
class NormalVector;
|
||||
struct NormalVector;
|
||||
class Vector;
|
||||
|
||||
class RotationMatrix : public glm::mat3
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace fgl::engine
|
||||
class Coordinate;
|
||||
|
||||
class Vector;
|
||||
class NormalVector;
|
||||
struct NormalVector;
|
||||
|
||||
template < typename T >
|
||||
concept is_plane = requires( T t ) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
namespace fgl::engine
|
||||
{
|
||||
class Vector;
|
||||
class NormalVector;
|
||||
struct NormalVector;
|
||||
|
||||
template < CoordinateSpace CType >
|
||||
class Coordinate : private glm::vec3
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace fgl::engine
|
||||
template < CoordinateSpace type >
|
||||
class Coordinate;
|
||||
|
||||
class NormalVector;
|
||||
struct NormalVector;
|
||||
|
||||
//TODO: Make normalized form of Vector
|
||||
class Vector : private glm::vec3
|
||||
|
||||
@@ -111,4 +111,7 @@ namespace fgl::engine
|
||||
submitCommandBuffers( const vk::raii::CommandBuffer& buffers, PresentIndex present_index );
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
using PerFrameArray = std::array< T, SwapChain::MAX_FRAMES_IN_FLIGHT >;
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace fgl::engine
|
||||
compiler = std::make_unique< shaderc::Compiler >();
|
||||
}
|
||||
|
||||
FGL_ASSERT( compiler );
|
||||
FGL_ASSERT( compiler, "Compiler invalid!" );
|
||||
|
||||
return *compiler;
|
||||
}
|
||||
|
||||
@@ -44,13 +44,15 @@ namespace fgl::engine
|
||||
|
||||
for ( const auto* model_component_ptr : model_components )
|
||||
{
|
||||
const auto& model_transform { model_component_ptr->m_transform };
|
||||
|
||||
const auto& comp { *model_component_ptr };
|
||||
for ( const Primitive& primitive : comp->m_primitives )
|
||||
{
|
||||
if ( !primitive.ready() ) continue;
|
||||
|
||||
// Does this primitive pass the bounds check
|
||||
if ( !frustum.intersects( primitive.getWorldBounds() ) ) continue;
|
||||
if ( !frustum.intersects( model_transform.mat() * primitive.getBoundingBox() ) ) continue;
|
||||
|
||||
//assert( primitive.m_texture );
|
||||
const ModelMatrixInfo matrix_info { .model_matrix = obj.getTransform().mat4(),
|
||||
|
||||
@@ -38,9 +38,6 @@ namespace fgl::engine
|
||||
|
||||
using ModelMatrixInfoBufferSuballocation = HostVector< ModelMatrixInfo >;
|
||||
|
||||
template < typename T >
|
||||
using PerFrameArray = std::array< T, SwapChain::MAX_FRAMES_IN_FLIGHT >;
|
||||
|
||||
// Simple parameter buffers
|
||||
PerFrameArray< std::unique_ptr< DrawParameterBufferSuballocation > > m_draw_simple_parameter_buffers {};
|
||||
PerFrameArray< std::unique_ptr< ModelMatrixInfoBufferSuballocation > > m_simple_model_matrix_info_buffers {};
|
||||
|
||||
93
src/engine/systems/LineDrawer.cpp
Normal file
93
src/engine/systems/LineDrawer.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Created by kj16609 on 8/10/24.
|
||||
//
|
||||
|
||||
#include "LineDrawer.hpp"
|
||||
|
||||
#include "engine/FrameInfo.hpp"
|
||||
#include "engine/buffers/vector/HostVector.hpp"
|
||||
#include "engine/camera/CameraDescriptor.hpp"
|
||||
#include "engine/model/ModelVertex.hpp"
|
||||
#include "engine/model/SimpleVertex.hpp"
|
||||
#include "engine/primitives/points/Coordinate.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
struct VertexLine
|
||||
{
|
||||
SimpleVertex p1 {};
|
||||
SimpleVertex p2 {};
|
||||
};
|
||||
|
||||
inline static std::vector< VertexLine > m_lines {};
|
||||
|
||||
LineDrawer::LineDrawer( Device& device, vk::raii::RenderPass& render_pass )
|
||||
{
|
||||
PipelineConfigInfo config { render_pass };
|
||||
|
||||
PipelineConfigInfo::addGBufferAttachmentsConfig( config );
|
||||
PipelineConfigInfo::setVertexInputType( config, Simple );
|
||||
PipelineConfigInfo::setLineTopo( config );
|
||||
|
||||
m_pipeline = std::make_unique< LinePipeline >( device, std::move( config ) );
|
||||
}
|
||||
|
||||
LineDrawer::~LineDrawer()
|
||||
{}
|
||||
|
||||
vk::raii::CommandBuffer& LineDrawer::setupSystem( FrameInfo& info )
|
||||
{
|
||||
auto& command_buffer { info.command_buffer };
|
||||
m_pipeline->bind( command_buffer );
|
||||
|
||||
m_pipeline->bindDescriptor( command_buffer, CameraDescriptorSet::m_set_idx, info.getCameraDescriptor() );
|
||||
|
||||
return command_buffer;
|
||||
}
|
||||
|
||||
void LineDrawer::pass( FrameInfo& info )
|
||||
{
|
||||
ZoneScopedN( "Debug line drawing" );
|
||||
auto& command_buffer { setupSystem( info ) };
|
||||
TracyVkZone( info.tracy_ctx, *command_buffer, "Draw debug lines" );
|
||||
|
||||
if ( m_lines.size() == 0 )
|
||||
{
|
||||
VertexLine line;
|
||||
auto& [ p1, p2 ] = line;
|
||||
p1.m_position = constants::WORLD_CENTER;
|
||||
p2.m_position = constants::WORLD_FORWARD * 20.0f;
|
||||
|
||||
m_lines.emplace_back( line );
|
||||
}
|
||||
|
||||
auto& line_vertex_buffer { m_line_vertex_buffer[ info.frame_idx ] };
|
||||
|
||||
line_vertex_buffer = std::make_unique< HostVector< VertexLine > >( info.model_matrix_info_buffer, m_lines );
|
||||
|
||||
command_buffer.bindVertexBuffers( 0, line_vertex_buffer->getVkBuffer(), { line_vertex_buffer->getOffset() } );
|
||||
|
||||
command_buffer.draw( m_lines.size() * 2, m_lines.size(), 0, 0 );
|
||||
}
|
||||
|
||||
void cleanupLineQueue()
|
||||
{
|
||||
m_lines.clear();
|
||||
}
|
||||
|
||||
namespace debug
|
||||
{
|
||||
void drawLine( const WorldCoordinate& p1, const WorldCoordinate& p2 )
|
||||
{
|
||||
VertexLine line {};
|
||||
auto& [ p1v, p2v ] = line;
|
||||
|
||||
p1v.m_position = p1.vec();
|
||||
p2v.m_position = p2.vec();
|
||||
|
||||
m_lines.emplace_back( std::move( line ) );
|
||||
}
|
||||
} // namespace debug
|
||||
|
||||
} // namespace fgl::engine
|
||||
46
src/engine/systems/LineDrawer.hpp
Normal file
46
src/engine/systems/LineDrawer.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by kj16609 on 8/10/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "engine/buffers/vector/HostVector.hpp"
|
||||
#include "engine/camera/CameraDescriptor.hpp"
|
||||
#include "engine/descriptors/Descriptor.hpp"
|
||||
#include "engine/descriptors/DescriptorSetCollection.hpp"
|
||||
#include "engine/pipeline/PipelineT.hpp"
|
||||
#include "engine/rendering/SwapChain.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
struct VertexLine;
|
||||
struct FrameInfo;
|
||||
struct ModelVertex;
|
||||
|
||||
class LineDrawer
|
||||
{
|
||||
using VertexShader = VertexShaderT< "shaders/line.vert" >;
|
||||
using FragmentShader = FragmentShaderT< "shaders/line.frag" >;
|
||||
|
||||
using LinePipeline = PipelineT<
|
||||
ShaderCollection< VertexShader, FragmentShader >,
|
||||
descriptors::DescriptorSetCollection< descriptors::EmptyDescriptorSet< 0 >, CameraDescriptorSet > >;
|
||||
|
||||
std::unique_ptr< LinePipeline > m_pipeline {};
|
||||
|
||||
PerFrameArray< std::unique_ptr< HostVector< VertexLine > > > m_line_vertex_buffer {};
|
||||
|
||||
public:
|
||||
|
||||
FGL_DELETE_ALL_Ro5( LineDrawer );
|
||||
|
||||
vk::raii::CommandBuffer& setupSystem( FrameInfo& info );
|
||||
void pass( FrameInfo& info );
|
||||
|
||||
LineDrawer( Device& device, vk::raii::RenderPass& render_pass );
|
||||
|
||||
~LineDrawer();
|
||||
};
|
||||
|
||||
void cleanupLineQueue();
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <engine/FrameInfo.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include "engine/model/Model.hpp"
|
||||
#include "engine/primitives/Frustum.hpp"
|
||||
|
||||
@@ -221,8 +220,8 @@ namespace fgl::engine
|
||||
{
|
||||
if ( ( draw_inview_bounds || std::holds_alternative< OctTreeNodeLeaf >( this->m_node_data ) ) && m_parent )
|
||||
{
|
||||
if ( draw_leaf_fit_bounds ) debug::world::drawBoundingBox( m_fit_bounding_box );
|
||||
if ( draw_leaf_real_bounds ) debug::world::drawBoundingBox( m_bounds );
|
||||
// if ( draw_leaf_fit_bounds ) debug::world::drawBoundingBox( m_fit_bounding_box );
|
||||
// if ( draw_leaf_real_bounds ) debug::world::drawBoundingBox( m_bounds );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
5
src/shaders/include/camera.glsl
Normal file
5
src/shaders/include/camera.glsl
Normal file
@@ -0,0 +1,5 @@
|
||||
layout (set = 1, binding = 0) uniform CameraInfo {
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
mat4 inverse_view;
|
||||
} ubo;
|
||||
3
src/shaders/include/gbuffer_out.glsl
Normal file
3
src/shaders/include/gbuffer_out.glsl
Normal file
@@ -0,0 +1,3 @@
|
||||
layout (location = 0) out vec4 out_position;
|
||||
layout (location = 1) out vec4 out_normal;
|
||||
layout (location = 2) out vec4 out_albedo;
|
||||
7
src/shaders/line.frag
Normal file
7
src/shaders/line.frag
Normal file
@@ -0,0 +1,7 @@
|
||||
#version 450
|
||||
|
||||
#include "include/gbuffer_out.glsl"
|
||||
|
||||
void main() {
|
||||
out_albedo = vec4(1.0);
|
||||
}
|
||||
10
src/shaders/line.vert
Normal file
10
src/shaders/line.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
|
||||
#include "include/camera.glsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ubo.projection * ubo.view * vec4(in_pos, 1.0);
|
||||
}
|
||||
@@ -9,9 +9,7 @@ layout (location = 3) in flat uint in_albedo_idx;
|
||||
layout (location = 4) in flat uint in_normal_idx;
|
||||
layout (location = 5) in flat uint in_metallic_roughness_idx;
|
||||
|
||||
layout (location = 0) out vec4 out_position;
|
||||
layout (location = 1) out vec4 out_normal;
|
||||
layout (location = 2) out vec4 out_albedo;
|
||||
#include "include/gbuffer_out.glsl"
|
||||
|
||||
layout (set = 1, binding = 0) uniform CameraInfo {
|
||||
mat4 projection;
|
||||
|
||||
@@ -11,11 +11,7 @@ layout (location = 3) out flat uint out_albedo_id;
|
||||
layout (location = 4) out flat uint out_normal_id;
|
||||
layout (location = 5) out flat uint out_metallic_roughness_id;
|
||||
|
||||
layout (set = 1, binding = 0) uniform CameraInfo {
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
mat4 inverse_view;
|
||||
} ubo;
|
||||
#include "include/camera.glsl"
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user