Skip to content

Commit

Permalink
RoundedQuad, NineSlice.
Browse files Browse the repository at this point in the history
- Fix sector UVs and verts.
  • Loading branch information
karnkaul committed Aug 23, 2023
1 parent c411568 commit 815aa97
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 92 deletions.
39 changes: 26 additions & 13 deletions engine/include/le/graphics/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,53 @@ namespace le::graphics {
struct Quad {
glm::vec2 size{1.0f};
UvRect uv{uv_rect_v};
Rgba rgb{white_v};
Rgba rgba{white_v};
glm::vec3 origin{};

auto operator==(Quad const&) const -> bool = default;
};

struct Circle {
static constexpr std::uint8_t resolution_v{128};
static constexpr int resolution_v{128};

float diameter{1.0f};
std::uint32_t resolution{resolution_v};
Rgba rgb{white_v};
int resolution{resolution_v};
Rgba rgba{white_v};
glm::vec3 origin{};

auto operator==(Circle const&) const -> bool = default;
};

struct RoundedQuad : Quad {
float corner_radius{0.25f};
int corner_resolution{8};

auto operator==(RoundedQuad const&) const -> bool = default;
};

struct NineSlice {
glm::vec2 size{1.0f};
glm::vec2 top{0.25f};
glm::vec2 bottom{0.25f};
struct Size {
glm::vec2 total{1.0f};
glm::vec2 top{0.25f};
glm::vec2 bottom{0.25f};

[[nodiscard]] auto rescaled(glm::vec2 extent) const -> Size;

auto operator==(Size const&) const -> bool = default;
};

Size size{};
UvRect top_uv{.lt = {}, .rb = glm::vec2{0.25f}};
UvRect bottom_uv{.lt = glm::vec2{0.75f}, .rb = glm::vec2{1.0f}};
bool rounded_corners{}; // TODO
Rgba rgb{white_v};
Rgba rgba{white_v};
glm::vec3 origin{};

[[nodiscard]] auto rescaled(glm::vec2 extent) const -> NineSlice;

auto operator==(NineSlice const&) const -> bool = default;
};

struct Cube {
glm::vec3 size{1.0f};
Rgba rgb{white_v};
Rgba rgba{white_v};
glm::vec3 origin{};

auto operator==(Cube const&) const -> bool = default;
Expand All @@ -56,7 +68,7 @@ struct Sphere {

float diameter{1.0f};
std::uint32_t resolution{resolution_v};
Rgba rgb{white_v};
Rgba rgba{white_v};
glm::vec3 origin{};

auto operator==(Sphere const&) const -> bool = default;
Expand All @@ -83,6 +95,7 @@ struct Geometry {

auto append(Quad const& quad) -> Geometry&;
auto append(Circle const& circle) -> Geometry&;
auto append(RoundedQuad const& rounded_quad) -> Geometry&;
auto append(NineSlice const& nine_slice) -> Geometry&;

auto append(Cube const& cube) -> Geometry&;
Expand Down
2 changes: 1 addition & 1 deletion engine/include/le/graphics/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Renderer : public MonoInstance<Renderer> {
auto bake_objects(RenderFrame const& render_frame) -> void;

std::unique_ptr<DearImGui> m_imgui{};
PipelineCache m_pipeline_cache;
PipelineCache m_pipeline_cache{};
SamplerCache m_sampler_cache{};
DescriptorCache m_descriptor_cache{};
ScratchBufferCache m_scratch_buffer_cache{};
Expand Down
2 changes: 1 addition & 1 deletion engine/src/graphics/cache/pipeline_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ auto PipelineCache::clear_pipelines() -> void {
}

auto PipelineCache::clear_pipelines_and_shaders() -> void {
Device::self().get_device().waitIdle();
m_device.waitIdle();
clear_pipelines();
m_shader_cache.clear_shaders();
}
Expand Down
4 changes: 2 additions & 2 deletions engine/src/graphics/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ auto make_device(Gpu const& gpu) -> vk::UniqueDevice {
}
}

auto dynamic_rendering_feature = vk::PhysicalDeviceDynamicRenderingFeatures{1};
auto synchronization_2_feature = vk::PhysicalDeviceSynchronization2FeaturesKHR{1};
auto dynamic_rendering_feature = vk::PhysicalDeviceDynamicRenderingFeatures{vk::True};
auto synchronization_2_feature = vk::PhysicalDeviceSynchronization2FeaturesKHR{vk::True};
synchronization_2_feature.pNext = &dynamic_rendering_feature;

dci.queueCreateInfoCount = 1;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/graphics/font/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ auto Font::Pen::generate_quads(Geometry& out, std::string_view line) -> Pen& {
auto const quad = Quad{
.size = rect.extent(),
.uv = glyph.uv_rect,
.rgb = vertex_colour,
.rgba = vertex_colour,
.origin = glm::vec3{rect.centre(), 0.0f},
};
out.append(quad);
Expand Down

0 comments on commit 815aa97

Please sign in to comment.