summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2025-06-21 16:51:22 -0300
committerFrederico Linhares <fred@linhares.blue>2025-06-21 16:51:22 -0300
commit8bedf8a366cb6c1179bc89678c863517b9356d48 (patch)
tree4a285592f804802d59f2af090113f607344ffdce
parentb3428170ac0a1837d3568f7b49312cbb01179f5d (diff)
refa Remove View2DHEADmaster
View2D is almost useless and add too much complexity for the engine, so I am removing it.
-rw-r--r--lib/menu.rb23
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_solid.cpp36
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_solid.hpp8
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_wired.cpp37
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_wired.hpp10
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d.cpp6
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d.hpp6
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp6
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp6
-rw-r--r--src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp6
-rw-r--r--src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp6
-rw-r--r--src/blu_cat/gra/renderer.cpp163
-rw-r--r--src/blu_cat/gra/renderer.hpp28
-rw-r--r--src/blu_cat/gra/texture.cpp6
-rw-r--r--src/blu_cat/gra/view.cpp (renamed from src/blu_cat/gra/view_3d.cpp)65
-rw-r--r--src/blu_cat/gra/view.hpp (renamed from src/blu_cat/gra/view_3d.hpp)31
-rw-r--r--src/blu_cat/gra/view_2d.cpp160
-rw-r--r--src/blu_cat/gra/view_2d.hpp60
-rw-r--r--src/blu_cat/int/core.cpp10
-rw-r--r--src/candy_gear/candy_gear.cpp41
-rw-r--r--src/candy_gear/core.cpp6
-rw-r--r--src/candy_gear/sprite.cpp11
-rw-r--r--src/candy_gear/vector_4d.cpp12
-rw-r--r--src/candy_gear/view.cpp (renamed from src/candy_gear/view_3d.cpp)62
-rw-r--r--src/candy_gear/view.hpp (renamed from src/candy_gear/view_3d.hpp)12
-rw-r--r--src/candy_gear/view_2d.cpp90
-rw-r--r--src/candy_gear/view_2d.hpp33
-rw-r--r--test/src/mode/demo.rb20
-rw-r--r--test/src/mode/title.rb7
29 files changed, 341 insertions, 626 deletions
diff --git a/lib/menu.rb b/lib/menu.rb
index 801b5a7..47e9646 100644
--- a/lib/menu.rb
+++ b/lib/menu.rb
@@ -1,4 +1,4 @@
-# Copyright 2022-2024 Frederico de Oliveira Linhares
+# Copyright 2022-2025 Frederico de Oliveira Linhares
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -89,24 +89,21 @@ module CandyGear
}
end
- def draw(view, x, y, width, height)
+ def draw(x, y, width, height)
num_horizontal_sprites = width / @border_width + 1;
num_horizontal_sprites += 1 if width % @border_width > 0;
num_vertical_sprites = height / @border_height;
num_vertical_sprites += 1 if height % @border_height > 0;
# Draw the corners.
- @sprites[:box_top_left].draw(view, x, y, border_width, border_height);
+ @sprites[:box_top_left].draw(x, y, border_width, border_height);
@sprites[:box_top_right].draw(
- view,
@border_width * (num_horizontal_sprites + 1) + x, y,
border_width, border_height);
@sprites[:box_bottom_left].draw(
- view,
x, @border_height * (num_vertical_sprites + 1) + y,
border_width, border_height);
@sprites[:box_bottom_right].draw(
- view,
@border_width * (num_horizontal_sprites + 1) + x,
@border_height * (num_vertical_sprites + 1) + y,
border_width, border_height);
@@ -115,22 +112,19 @@ module CandyGear
num_horizontal_sprites.times do |i|
# Top
@sprites[:box_top].draw(
- view, @border_width * (i + 1) + x, y,
- border_width, border_height);
+ @border_width * (i + 1) + x, y, border_width, border_height);
# Bottom
@sprites[:box_bottom].draw(
- view, @border_width * (i + 1) + x,
+ @border_width * (i + 1) + x,
@border_height * (num_vertical_sprites + 1) + y,
border_width, border_height);
end
num_vertical_sprites.times do |i|
# Left
@sprites[:box_left].draw(
- view,
x, @border_height * (i + 1) + y, border_width, border_height);
# Right
@sprites[:box_right].draw(
- view,
@border_width * (num_horizontal_sprites + 1) + x,
@border_height * (i + 1) + y,
border_width, border_height);
@@ -152,8 +146,7 @@ module CandyGear
attr_reader(:width, :height);
- def initialize(view, menu_view, pos_x, pos_y, options)
- @view = view;
+ def initialize(menu_view, pos_x, pos_y, options)
@menu_view = menu_view;
@pos_x = pos_x;
@@ -205,11 +198,10 @@ module CandyGear
end
def draw()
- @menu_view.draw(@view, @pos_x, @pos_y, @width, @height);
+ @menu_view.draw(@pos_x, @pos_y, @width, @height);
@options.each_with_index do |opt, i|
opt.text.draw(
- @view,
@pos_x + @menu_view.border_width +
@menu_view.border_width,
@pos_y + @menu_view.border_height +
@@ -218,7 +210,6 @@ module CandyGear
end
@menu_view.sprites[:arrow_select].draw(
- @view,
@pos_x + @menu_view.border_width,
@pos_y + @menu_view.border_height +
@option_max_height * @current_option,
diff --git a/src/blu_cat/gra/graphics_pipeline_2d_solid.cpp b/src/blu_cat/gra/graphics_pipeline_2d_solid.cpp
index 7acca09..05dcbe1 100644
--- a/src/blu_cat/gra/graphics_pipeline_2d_solid.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_solid.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -235,26 +235,25 @@ GraphicsPipeline2DSolid::~GraphicsPipeline2DSolid()
void
GraphicsPipeline2DSolid::draw(
- std::shared_ptr<View2D> view, const VkCommandBuffer draw_command_buffer,
- const size_t current_frame, const size_t next_frame,
- const uint32_t image_index)
+ const VkCommandBuffer draw_command_buffer, const size_t current_frame,
+ const size_t next_frame, const uint32_t image_index)
{
// TODO set viewport just once per view, not once per pipeline.
{ // Set viewport
VkViewport vk_viewport{};
- vk_viewport.x = view->region.x;
- vk_viewport.y = view->region.y;
- vk_viewport.width = view->region.z;
- vk_viewport.height = view->region.w;
+ vk_viewport.x = 0;
+ vk_viewport.y = 0;
+ vk_viewport.width = static_cast<float>(BluCat::INT::core.display_width);
+ vk_viewport.height = static_cast<float>(BluCat::INT::core.display_height);
vk_viewport.minDepth = 0.0f;
vk_viewport.maxDepth = 1.0f;
vkCmdSetViewport(draw_command_buffer, 0, 1, &vk_viewport);
VkRect2D vk_scissor{};
- vk_scissor.offset.x = static_cast<int32_t>(view->region.x);
- vk_scissor.offset.y = static_cast<int32_t>(view->region.y);
- vk_scissor.extent.width = static_cast<uint32_t>(view->region.z);
- vk_scissor.extent.height = static_cast<uint32_t>(view->region.w);
+ vk_scissor.offset.x = 0;
+ vk_scissor.offset.y = 0;
+ vk_scissor.extent.width = BluCat::INT::core.display_width;
+ vk_scissor.extent.height = BluCat::INT::core.display_height;
vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
}
@@ -264,14 +263,17 @@ GraphicsPipeline2DSolid::draw(
// FIXME: I know sorting is expensive, but I need to figure out better what
// to do here.
- std::sort(view->sprites_to_draw[current_frame].begin(),
- view->sprites_to_draw[current_frame].end());
+ std::sort(BluCat::INT::core.vk_renderer->sprites_to_draw[
+ current_frame].begin(),
+ BluCat::INT::core.vk_renderer->sprites_to_draw[
+ current_frame].end());
// Draw sprites
- for(auto& sprite_to_draw: view->sprites_to_draw[current_frame])
+ for(auto& sprite_to_draw:
+ BluCat::INT::core.vk_renderer->sprites_to_draw[current_frame])
{
std::array<VkDescriptorSet, 2> vk_descriptor_sets{
- view->descriptor_sets_2d[image_index],
+ BluCat::INT::core.vk_renderer->descriptor_sets_2d[image_index],
sprite_to_draw.sprite->texture->descriptor_sets[image_index]};
VkDeviceSize offsets[]{0};
@@ -292,7 +294,7 @@ GraphicsPipeline2DSolid::draw(
}
// Prepare for the next frame.
- view->sprites_to_draw[next_frame].clear();
+ BluCat::INT::core.vk_renderer->sprites_to_draw[next_frame].clear();
}
}
diff --git a/src/blu_cat/gra/graphics_pipeline_2d_solid.hpp b/src/blu_cat/gra/graphics_pipeline_2d_solid.hpp
index c1520c2..c2d85d5 100644
--- a/src/blu_cat/gra/graphics_pipeline_2d_solid.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_solid.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
#include "vulkan.hpp"
#include "command_pool.hpp"
-#include "view_2d.hpp"
namespace BluCat::GRA
{
@@ -34,9 +33,8 @@ struct GraphicsPipeline2DSolid
~GraphicsPipeline2DSolid();
void
- draw(std::shared_ptr<View2D> view, const VkCommandBuffer draw_command_buffer,
- const size_t current_frame, const size_t next_frame,
- const uint32_t image_index);
+ draw(const VkCommandBuffer draw_command_buffer, const size_t current_frame,
+ const size_t next_frame, const uint32_t image_index);
};
}
diff --git a/src/blu_cat/gra/graphics_pipeline_2d_wired.cpp b/src/blu_cat/gra/graphics_pipeline_2d_wired.cpp
index 20491ed..1273c67 100644
--- a/src/blu_cat/gra/graphics_pipeline_2d_wired.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_wired.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -247,33 +247,32 @@ GraphicsPipeline2DWired::~GraphicsPipeline2DWired()
void
GraphicsPipeline2DWired::draw(
- std::shared_ptr<View2D> view, const VkCommandBuffer draw_command_buffer,
- const size_t current_frame, const size_t next_frame,
- const uint32_t image_index)
+ const VkCommandBuffer draw_command_buffer, const size_t current_frame,
+ const size_t next_frame, const uint32_t image_index)
{
- // Set viewport
- {
+ // TODO set viewport just once per view, not once per pipeline.
+ { // Set viewport
VkViewport vk_viewport{};
- vk_viewport.x = view->region.x;
- vk_viewport.y = view->region.y;
- vk_viewport.width = view->region.z;
- vk_viewport.height = view->region.w;
+ vk_viewport.x = 0;
+ vk_viewport.y = 0;
+ vk_viewport.width = static_cast<float>(BluCat::INT::core.display_width);
+ vk_viewport.height = static_cast<float>(BluCat::INT::core.display_height);
vk_viewport.minDepth = 0.0f;
vk_viewport.maxDepth = 1.0f;
vkCmdSetViewport(draw_command_buffer, 0, 1, &vk_viewport);
VkRect2D vk_scissor{};
- vk_scissor.offset.x = static_cast<int32_t>(view->region.x);
- vk_scissor.offset.y = static_cast<int32_t>(view->region.y);
- vk_scissor.extent.width = static_cast<uint32_t>(view->region.z);
- vk_scissor.extent.height = static_cast<uint32_t>(view->region.w);
+ vk_scissor.offset.x = 0;
+ vk_scissor.offset.y = 0;
+ vk_scissor.extent.width = BluCat::INT::core.display_width;
+ vk_scissor.extent.height = BluCat::INT::core.display_height;
vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
}
// Draw rectangles
{
std::array<VkDescriptorSet, 1> vk_descriptor_sets{
- view->descriptor_sets_2d[image_index]};
+ BluCat::INT::core.vk_renderer->descriptor_sets_2d[image_index]};
VkDeviceSize offsets[]{0};
vkCmdBindDescriptorSets(
@@ -287,9 +286,11 @@ GraphicsPipeline2DWired::draw(
draw_command_buffer, this->index_buffer->buffer, 0,
VK_INDEX_TYPE_UINT32);
- for(auto i{0}; i < view->rectangles_to_draw[current_frame].size(); i++)
+ for(auto i{0}; i < BluCat::INT::core.vk_renderer->rectangles_to_draw[
+ current_frame].size(); i++)
{
- auto &rect{view->rectangles_to_draw[current_frame][i]};
+ auto &rect{BluCat::INT::core.vk_renderer->rectangles_to_draw[
+ current_frame][i]};
UDOVector4D position{rect.position};
UDOVector3D color{rect.color};
@@ -308,7 +309,7 @@ GraphicsPipeline2DWired::draw(
}
// Prepare for the next frame.
- view->rectangles_to_draw[next_frame].clear();
+ BluCat::INT::core.vk_renderer->rectangles_to_draw[next_frame].clear();
}
}
diff --git a/src/blu_cat/gra/graphics_pipeline_2d_wired.hpp b/src/blu_cat/gra/graphics_pipeline_2d_wired.hpp
index 7d2752e..9fc46c4 100644
--- a/src/blu_cat/gra/graphics_pipeline_2d_wired.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_wired.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@
#include <memory>
#include "vulkan.hpp"
-#include "view_2d.hpp"
+#include "command_pool.hpp"
+#include "destination_buffer.hpp"
namespace BluCat::GRA
{
@@ -37,9 +38,8 @@ struct GraphicsPipeline2DWired
~GraphicsPipeline2DWired();
void
- draw(std::shared_ptr<View2D> view, const VkCommandBuffer draw_command_buffer,
- const size_t current_frame, const size_t next_frame,
- const uint32_t image_index);
+ draw(const VkCommandBuffer draw_command_buffer, const size_t current_frame,
+ const size_t next_frame, const uint32_t image_index);
};
}
diff --git a/src/blu_cat/gra/graphics_pipeline_3d.cpp b/src/blu_cat/gra/graphics_pipeline_3d.cpp
index 1f7324a..288e186 100644
--- a/src/blu_cat/gra/graphics_pipeline_3d.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_3d.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -257,7 +257,7 @@ GraphicsPipeline3D::~GraphicsPipeline3D()
void
GraphicsPipeline3D::draw(
- std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
+ std::shared_ptr<View> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
vkCmdBindPipeline(
@@ -286,7 +286,7 @@ GraphicsPipeline3D::draw(
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
INT::core.vk_light->descriptor_sets_world[image_index],
- view->descriptor_sets_3d[image_index],
+ view->descriptor_sets[image_index],
instance->descriptor_sets[image_index],
instance->texture->descriptor_sets[image_index]};
diff --git a/src/blu_cat/gra/graphics_pipeline_3d.hpp b/src/blu_cat/gra/graphics_pipeline_3d.hpp
index 0dc0b03..2e30e02 100644
--- a/src/blu_cat/gra/graphics_pipeline_3d.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_3d.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
#include "vulkan.hpp"
#include "command_pool.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
namespace BluCat::GRA
{
@@ -34,7 +34,7 @@ struct GraphicsPipeline3D
~GraphicsPipeline3D();
void
- draw(std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
+ draw(std::shared_ptr<View> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index);
};
diff --git a/src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp b/src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp
index e8eda6b..79a85f1 100644
--- a/src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -266,7 +266,7 @@ GraphicsPipeline3DSkeletal::~GraphicsPipeline3DSkeletal()
void
GraphicsPipeline3DSkeletal::draw(
- std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
+ std::shared_ptr<View> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
vkCmdBindPipeline(
@@ -295,7 +295,7 @@ GraphicsPipeline3DSkeletal::draw(
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
INT::core.vk_light->descriptor_sets_world[image_index],
- view->descriptor_sets_3d[image_index],
+ view->descriptor_sets[image_index],
instance->descriptor_sets[image_index],
instance->texture->descriptor_sets[image_index]};
diff --git a/src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp b/src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp
index bad117d..16d65b0 100644
--- a/src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
#include "vulkan.hpp"
#include "command_pool.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
namespace BluCat::GRA
{
@@ -34,7 +34,7 @@ struct GraphicsPipeline3DSkeletal
~GraphicsPipeline3DSkeletal();
void
- draw(std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
+ draw(std::shared_ptr<View> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index);
};
diff --git a/src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp b/src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp
index 14796d3..63e10b9 100644
--- a/src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -265,7 +265,7 @@ GraphicsPipelineSprite3D::~GraphicsPipelineSprite3D()
void
GraphicsPipelineSprite3D::draw(
- std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
+ std::shared_ptr<View> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
vkCmdBindPipeline(
@@ -290,7 +290,7 @@ GraphicsPipelineSprite3D::draw(
{
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
INT::core.vk_light->descriptor_sets_world[image_index],
- view->descriptor_sets_3d[image_index],
+ view->descriptor_sets[image_index],
sprite.sprite_3d->descriptor_sets[image_index],
sprite.sprite_3d->sprite->texture->descriptor_sets[image_index]};
VkDeviceSize offsets[]{0};
diff --git a/src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp b/src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp
index 325d943..d03b8e8 100644
--- a/src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
#include "vulkan.hpp"
#include "command_pool.hpp"
#include "sprite_3d.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
namespace BluCat::GRA
{
@@ -35,7 +35,7 @@ struct GraphicsPipelineSprite3D
~GraphicsPipelineSprite3D();
void
- draw(std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
+ draw(std::shared_ptr<View> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index);
};
diff --git a/src/blu_cat/gra/renderer.cpp b/src/blu_cat/gra/renderer.cpp
index d13f814..36b9925 100644
--- a/src/blu_cat/gra/renderer.cpp
+++ b/src/blu_cat/gra/renderer.cpp
@@ -25,15 +25,39 @@ namespace
{
void
+load_2d_uniform_buffer(void *obj)
+{
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
+
+ try
+ {
+ self->ub_2d.reserve(BluCat::INT::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
+ self->ub_2d.emplace_back(
+ BluCat::INT::core.vk_device_with_swapchain,
+ sizeof(BluCat::GRA::UDOView2D));
+ }
+ catch(const std::exception& e)
+ {
+ throw CommandError{e.what()};
+ }
+}
+
+void
+unload_2d_uniform_buffer(void *obj)
+{
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
+
+ self->ub_2d.clear();
+}
+
+void
load_descriptor_pool(void *obj)
{
auto self = static_cast<BluCat::GRA::Renderer*>(obj);
- uint32_t uniform_buffer_count = 0;
- for(auto &view : self->views_3d)
- uniform_buffer_count += (view->ub_3d.size() + view->ub_2d.size());
- for(auto &view : self->views_2d)
- uniform_buffer_count += (view->ub_2d.size());
+ uint32_t uniform_buffer_count = self->ub_2d.size();
+ for(auto &view : self->views) uniform_buffer_count += view->ub_3d.size();
VkDescriptorPoolSize descriptor_pool_size{};
descriptor_pool_size.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
@@ -52,9 +76,7 @@ load_descriptor_pool(void *obj)
&self->descriptor_pool) != VK_SUCCESS)
throw CommandError{"Failed to create a Vulkan descriptor pool."};
- for(auto &view : self->views_3d)
- view->load_descriptor_sets(self->descriptor_pool);
- for(auto &view : self->views_2d)
+ for(auto &view : self->views)
view->load_descriptor_sets(self->descriptor_pool);
}
@@ -63,8 +85,7 @@ unload_descriptor_pool(void *obj)
{
auto self = static_cast<BluCat::GRA::Renderer*>(obj);
- for(auto &view : self->views_3d) view->unload_descriptor_sets();
- for(auto &view : self->views_2d) view->unload_descriptor_sets();
+ for(auto &view : self->views) view->unload_descriptor_sets();
vkDestroyDescriptorPool(
BluCat::INT::core.vk_device_with_swapchain->device, self->descriptor_pool,
@@ -72,6 +93,64 @@ unload_descriptor_pool(void *obj)
}
void
+load_descriptor_sets_2d(void *obj)
+{
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
+
+ std::vector<VkDescriptorSetLayout> layouts(
+ BluCat::INT::core.vk_swapchain->images_count,
+ BluCat::INT::core.vk_descriptor_set_layout->view);
+
+ VkDescriptorSetAllocateInfo alloc_info{};
+ alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
+ alloc_info.descriptorPool = self->descriptor_pool;
+ alloc_info.descriptorSetCount = layouts.size();
+ alloc_info.pSetLayouts = layouts.data();
+
+ self->descriptor_sets_2d.resize(layouts.size());
+ if(vkAllocateDescriptorSets(
+ BluCat::INT::core.vk_device_with_swapchain->device, &alloc_info,
+ self->descriptor_sets_2d.data()) != VK_SUCCESS)
+ throw CommandError{"Failed to create Vulkan descriptor sets for view."};
+}
+
+void
+load_resources_to_descriptor_sets_2d(void *obj)
+{
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
+
+ for(auto i{0}; i < self->ub_2d.size(); i++)
+ {
+ VkDescriptorBufferInfo view_2d_info{};
+ view_2d_info.buffer = self->ub_2d[i].buffer;
+ view_2d_info.offset = 0;
+ view_2d_info.range = sizeof(BluCat::GRA::UDOView2D);
+
+ std::array<VkWriteDescriptorSet, 1> write_descriptors{};
+ write_descriptors[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ write_descriptors[0].dstSet = self->descriptor_sets_2d[i];
+ write_descriptors[0].dstBinding = 0;
+ write_descriptors[0].dstArrayElement = 0;
+ write_descriptors[0].descriptorCount = 1;
+ write_descriptors[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ write_descriptors[0].pBufferInfo = &view_2d_info;
+ write_descriptors[0].pImageInfo = nullptr;
+ write_descriptors[0].pTexelBufferView = nullptr;
+
+ vkUpdateDescriptorSets(
+ BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
+ write_descriptors.data(), 0, nullptr);
+
+ BluCat::GRA::UDOView2D ubo_view_2d;
+ ubo_view_2d.proj = glm::ortho(
+ 0.0f, self->projection_width,
+ 0.0f, self->projection_height,
+ 0.0f, 100.0f);
+ self->ub_2d[i].copy_data(&ubo_view_2d);
+ }
+}
+
+void
load_queue_family(void *obj)
{
auto self = static_cast<BluCat::GRA::Renderer*>(obj);
@@ -128,7 +207,10 @@ load_draw_command_buffer(void *obj)
}
const CommandChain loader{
+ {&load_2d_uniform_buffer, &unload_2d_uniform_buffer},
{&load_descriptor_pool, &unload_descriptor_pool},
+ {&load_descriptor_sets_2d, nullptr},
+ {&load_resources_to_descriptor_sets_2d, nullptr},
{&load_queue_family, nullptr},
{&load_command_pool, &unload_command_pool},
{&load_draw_command_buffer, nullptr}
@@ -139,21 +221,25 @@ const CommandChain loader{
namespace BluCat::GRA
{
-Renderer::Renderer(std::vector<std::shared_ptr<View2D>> views_2d,
- std::vector<std::shared_ptr<View3D>> views_3d):
+Renderer::Renderer(
+ std::vector<std::shared_ptr<View>> views, F32 width, F32 height):
skeletal_models_to_draw{BluCat::INT::core.vk_swapchain->images_count},
static_models_to_draw{BluCat::INT::core.vk_swapchain->images_count},
sprites_3d_to_draw{BluCat::INT::core.vk_swapchain->images_count},
+ rectangles_to_draw{BluCat::INT::core.vk_swapchain->images_count},
+ sprites_to_draw{BluCat::INT::core.vk_swapchain->images_count},
+ projection_width{width},
+ projection_height{height},
clear_screen_color{0.0f, 0.0f, 0.0f, 1.0f},
- views_2d{views_2d},
- views_3d{views_3d}
+ views{views}
{
loader.execute(this);
}
-Renderer::Renderer(std::initializer_list<std::shared_ptr<View2D>> views_2d,
- std::initializer_list<std::shared_ptr<View3D>> views_3d):
- Renderer(std::vector(views_2d), std::vector(views_3d))
+Renderer::Renderer(
+ std::initializer_list<std::shared_ptr<View>> views,
+ F32 width, F32 height):
+ Renderer(std::vector(views), width, height)
{
}
@@ -251,7 +337,7 @@ Renderer::draw()
draw_command_buffer, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
}
- for(auto &view: this->views_3d)
+ for(auto &view: this->views)
{
{ // Set viewport
VkViewport vk_viewport{};
@@ -272,16 +358,17 @@ Renderer::draw()
}
BluCat::INT::core.vk_graphics_pipeline_3d->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
+ view, draw_command_buffer,
+ BluCat::INT::core.vk_swapchain->current_frame,
image_index);
BluCat::INT::core.vk_graphics_pipeline_sprite_3d->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
- image_index);
+ view, draw_command_buffer,
+ BluCat::INT::core.vk_swapchain->current_frame, image_index);
BluCat::INT::core.vk_graphics_pipeline_3d_skeletal->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
- image_index);
+ view, draw_command_buffer,
+ BluCat::INT::core.vk_swapchain->current_frame, image_index);
{ // Update view uniform buffers
BluCat::GRA::UDOView3D ubo_view_3d{};
@@ -325,27 +412,15 @@ Renderer::draw()
}
{ // 2D solid drawing
- for(auto &view: this->views_2d)
- BluCat::INT::core.vk_graphics_pipeline_2d_solid->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
- next_frame, image_index);
-
- for(auto &view: this->views_3d)
- BluCat::INT::core.vk_graphics_pipeline_2d_solid->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
- next_frame, image_index);
+ BluCat::INT::core.vk_graphics_pipeline_2d_solid->draw(
+ draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
+ next_frame, image_index);
}
{ // 2D wired drawing
- for(auto &view: this->views_2d)
- BluCat::INT::core.vk_graphics_pipeline_2d_wired->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
- next_frame, image_index);
-
- for(auto &view: this->views_3d)
- BluCat::INT::core.vk_graphics_pipeline_2d_wired->draw(
- view, draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
- next_frame, image_index);
+ BluCat::INT::core.vk_graphics_pipeline_2d_wired->draw(
+ draw_command_buffer, BluCat::INT::core.vk_swapchain->current_frame,
+ next_frame, image_index);
}
vkCmdEndRenderPass(draw_command_buffer);
@@ -415,10 +490,8 @@ Renderer::draw()
BluCat::INT::core.vk_swapchain->current_frame].clear();
this->sprites_3d_to_draw[
BluCat::INT::core.vk_swapchain->current_frame].clear();
- for(auto &view: this->views_2d)
- view->sprites_to_draw[BluCat::INT::core.vk_swapchain->current_frame].clear();
- for(auto &view: this->views_3d)
- view->sprites_to_draw[BluCat::INT::core.vk_swapchain->current_frame].clear();
+ this->sprites_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame].clear();
}
}
diff --git a/src/blu_cat/gra/renderer.hpp b/src/blu_cat/gra/renderer.hpp
index 82948cb..58b9972 100644
--- a/src/blu_cat/gra/renderer.hpp
+++ b/src/blu_cat/gra/renderer.hpp
@@ -22,14 +22,15 @@
#include <vector>
#include "vulkan.hpp"
+#include "queue_family.hpp"
+#include "rectangle.hpp"
#include "skeletal_mesh.hpp"
#include "skeletal_model.hpp"
#include "sprite_3d.hpp"
+#include "sprite_to_draw.hpp"
#include "static_mesh.hpp"
#include "static_model.hpp"
-#include "queue_family.hpp"
-#include "view_2d.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
namespace BluCat::GRA
{
@@ -52,16 +53,25 @@ struct Renderer
VkDescriptorPool descriptor_pool;
VkClearColorValue clear_screen_color;
- std::vector<std::shared_ptr<View2D>> views_2d;
- std::vector<std::shared_ptr<View3D>> views_3d;
+
+ float projection_width, projection_height;
+
+ // FIXME: if these vectors get resized, they can cause a segmentation fault!
+ std::vector<UniformBuffer> ub_2d;
+ std::vector<VkDescriptorSet> descriptor_sets_2d;
+
+ std::vector<std::vector<Rectangle>> rectangles_to_draw;
+ std::vector<std::vector<SpriteToDraw>> sprites_to_draw;
+
+ std::vector<std::shared_ptr<View>> views;
+
QueueFamily *queue_family;
VkCommandPool command_pool;
std::vector<VkCommandBuffer> draw_command_buffers;
- Renderer(std::vector<std::shared_ptr<View2D>> views_2d,
- std::vector<std::shared_ptr<View3D>> views_3d);
- Renderer(std::initializer_list<std::shared_ptr<View2D>> views_2d,
- std::initializer_list<std::shared_ptr<View3D>> views_3d);
+ Renderer(std::vector<std::shared_ptr<View>> views, F32 width, F32 height);
+ Renderer(std::initializer_list<std::shared_ptr<View>> views,
+ F32 width, F32 height);
~Renderer();
void
diff --git a/src/blu_cat/gra/texture.cpp b/src/blu_cat/gra/texture.cpp
index 5abf751..7546d56 100644
--- a/src/blu_cat/gra/texture.cpp
+++ b/src/blu_cat/gra/texture.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -173,8 +173,8 @@ load_sampler(void *obj)
sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sampler_info.pNext = nullptr;
sampler_info.flags = 0;
- sampler_info.magFilter = VK_FILTER_LINEAR;
- sampler_info.minFilter = VK_FILTER_LINEAR;
+ sampler_info.magFilter = VK_FILTER_NEAREST;
+ sampler_info.minFilter = VK_FILTER_NEAREST;
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
diff --git a/src/blu_cat/gra/view_3d.cpp b/src/blu_cat/gra/view.cpp
index dc310e3..26017ce 100644
--- a/src/blu_cat/gra/view_3d.cpp
+++ b/src/blu_cat/gra/view.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,27 +14,30 @@
* limitations under the License.
*/
-#include "view_3d.hpp"
+#include "view.hpp"
#include <array>
#include "../int/core.hpp"
#include "uniform_data_object.hpp"
+#include <iostream>
+
namespace
{
void
-load_3d_uniform_buffer(void *obj)
+load_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::GRA::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
try
{
self->ub_3d.reserve(BluCat::INT::core.vk_swapchain->images_count);
for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
self->ub_3d.emplace_back(
- BluCat::INT::core.vk_device_with_swapchain, sizeof(BluCat::GRA::UDOView3D));
+ BluCat::INT::core.vk_device_with_swapchain,
+ sizeof(BluCat::GRA::UDOView3D));
}
catch(const std::exception& e)
{
@@ -43,17 +46,17 @@ load_3d_uniform_buffer(void *obj)
}
void
-unload_3d_uniform_buffer(void *obj)
+unload_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::GRA::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
self->ub_3d.clear();
}
void
-load_descriptor_sets_3d(void *obj)
+load_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::GRA::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
BluCat::INT::core.vk_swapchain->images_count,
@@ -65,17 +68,17 @@ load_descriptor_sets_3d(void *obj)
alloc_info.descriptorSetCount = layouts.size();
alloc_info.pSetLayouts = layouts.data();
- self->descriptor_sets_3d.resize(layouts.size());
+ self->descriptor_sets.resize(layouts.size());
if(vkAllocateDescriptorSets(
BluCat::INT::core.vk_device_with_swapchain->device, &alloc_info,
- self->descriptor_sets_3d.data()) != VK_SUCCESS)
+ self->descriptor_sets.data()) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan descriptor sets for view."};
}
void
-load_resources_to_descriptor_sets_3d(void *obj)
+load_resources_to_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::GRA::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
for(auto i{0}; i < self->ub_3d.size(); i++)
{
@@ -86,7 +89,7 @@ load_resources_to_descriptor_sets_3d(void *obj)
std::array<VkWriteDescriptorSet, 1> write_descriptors{};
write_descriptors[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- write_descriptors[0].dstSet = self->descriptor_sets_3d[i];
+ write_descriptors[0].dstSet = self->descriptor_sets[i];
write_descriptors[0].dstBinding = 0;
write_descriptors[0].dstArrayElement = 0;
write_descriptors[0].descriptorCount = 1;
@@ -96,18 +99,18 @@ load_resources_to_descriptor_sets_3d(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
- write_descriptors.data(), 0, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device,
+ write_descriptors.size(), write_descriptors.data(), 0, nullptr);
}
}
const CommandChain loader{
- {&load_3d_uniform_buffer, &unload_3d_uniform_buffer}
+ {&load_uniform_buffer, &unload_uniform_buffer}
};
const CommandChain descriptor_sets_loader{
- {&load_descriptor_sets_3d, nullptr},
- {&load_resources_to_descriptor_sets_3d, nullptr}
+ {&load_descriptor_sets, nullptr},
+ {&load_resources_to_descriptor_sets, nullptr}
};
}
@@ -115,41 +118,41 @@ const CommandChain descriptor_sets_loader{
namespace BluCat::GRA
{
-View3D::View3D(
- glm::vec4 region, float projection_width, float projection_height):
- View2D{region, projection_width, projection_height},
+View::View(
+ glm::vec4 region, float projection_width,
+ float projection_height):
+ region{region},
+ projection_width{projection_width},
+ projection_height{projection_height},
field_of_view{45.0f},
+ descriptor_pool{VK_NULL_HANDLE},
camera_position{std::make_shared<glm::vec3>(0.0f, 0.0f, 0.0f)},
camera_orientation{std::make_shared<glm::quat>(0.0f, 0.0f, 0.0f, 0.0f)}
{
- ::loader.execute(this);
+ loader.execute(this);
}
-View3D::~View3D()
+View::~View()
{
- ::loader.revert(this);
+ loader.revert(this);
}
void
-View3D::load_descriptor_sets(VkDescriptorPool descriptor_pool)
+View::load_descriptor_sets(VkDescriptorPool descriptor_pool)
{
if(this->descriptor_pool != VK_NULL_HANDLE) return;
- auto parent = dynamic_cast<BluCat::GRA::View2D*>(this);
this->descriptor_pool = descriptor_pool;
- View2D::descriptor_sets_loader.execute(parent);
::descriptor_sets_loader.execute(this);
}
void
-View3D::unload_descriptor_sets()
+View::unload_descriptor_sets()
{
if(this->descriptor_pool == VK_NULL_HANDLE) return;
- auto parent = dynamic_cast<BluCat::GRA::View2D*>(this);
this->descriptor_pool = VK_NULL_HANDLE;
::descriptor_sets_loader.revert(this);
- View2D::descriptor_sets_loader.revert(parent);
}
}
diff --git a/src/blu_cat/gra/view_3d.hpp b/src/blu_cat/gra/view.hpp
index f09c70f..a61ac34 100644
--- a/src/blu_cat/gra/view_3d.hpp
+++ b/src/blu_cat/gra/view.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,35 +14,42 @@
* limitations under the License.
*/
-#ifndef BLU_CAT_GRA_VIEW_3D_H
-#define BLU_CAT_GRA_VIEW_3D_H 1
+#ifndef BLU_CAT_GRA_VIEW_H
+#define BLU_CAT_GRA_VIEW_H 1
-#include "view_2d.hpp"
+#include <memory>
+#include <unordered_map>
+#include <vector>
+
+#include "vulkan.hpp"
+#include "uniform_buffer.hpp"
namespace BluCat::GRA
{
-struct View3D: public View2D
+struct View
{
- float field_of_view;
+ glm::vec4 region;
+ float field_of_view, projection_width, projection_height;
+
// FIXME: if this vector get resized, it can cause a segmentation fault!
std::vector<UniformBuffer> ub_3d;
- std::vector<VkDescriptorSet> descriptor_sets_3d;
+ VkDescriptorPool descriptor_pool;
+ std::vector<VkDescriptorSet> descriptor_sets;
std::shared_ptr<glm::vec3> camera_position;
std::shared_ptr<glm::quat> camera_orientation;
- View3D(glm::vec4 region, float projection_width, float projection_height);
- ~View3D();
-
void
load_descriptor_sets(VkDescriptorPool descriptor_pool);
-
void
unload_descriptor_sets();
+
+ View(glm::vec4 region, float projection_width, float projection_height);
+ ~View();
};
}
-#endif /* BLU_CAT_GRA_VIEW_3D_H */
+#endif /* BLU_CAT_GRA_VIEW_H */
diff --git a/src/blu_cat/gra/view_2d.cpp b/src/blu_cat/gra/view_2d.cpp
deleted file mode 100644
index 948b145..0000000
--- a/src/blu_cat/gra/view_2d.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "view_2d.hpp"
-
-#include <array>
-
-#include "../int/core.hpp"
-#include "uniform_data_object.hpp"
-
-namespace
-{
-
-void
-load_2d_uniform_buffer(void *obj)
-{
- auto self = static_cast<BluCat::GRA::View2D*>(obj);
-
- try
- {
- self->ub_2d.reserve(BluCat::INT::core.vk_swapchain->images_count);
- for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
- self->ub_2d.emplace_back(
- BluCat::INT::core.vk_device_with_swapchain, sizeof(BluCat::GRA::UDOView2D));
- }
- catch(const std::exception& e)
- {
- throw CommandError{e.what()};
- }
-}
-
-void
-unload_2d_uniform_buffer(void *obj)
-{
- auto self = static_cast<BluCat::GRA::View2D*>(obj);
-
- self->ub_2d.clear();
-}
-
-void
-load_descriptor_sets_2d(void *obj)
-{
- auto self = static_cast<BluCat::GRA::View2D*>(obj);
-
- std::vector<VkDescriptorSetLayout> layouts(
- BluCat::INT::core.vk_swapchain->images_count,
- BluCat::INT::core.vk_descriptor_set_layout->view);
-
- VkDescriptorSetAllocateInfo alloc_info{};
- alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
- alloc_info.descriptorPool = self->descriptor_pool;
- alloc_info.descriptorSetCount = layouts.size();
- alloc_info.pSetLayouts = layouts.data();
-
- self->descriptor_sets_2d.resize(layouts.size());
- if(vkAllocateDescriptorSets(
- BluCat::INT::core.vk_device_with_swapchain->device, &alloc_info,
- self->descriptor_sets_2d.data()) != VK_SUCCESS)
- throw CommandError{"Failed to create Vulkan descriptor sets for view."};
-}
-
-void
-load_resources_to_descriptor_sets_2d(void *obj)
-{
- auto self = static_cast<BluCat::GRA::View2D*>(obj);
-
- for(auto i{0}; i < self->ub_2d.size(); i++)
- {
- VkDescriptorBufferInfo view_2d_info{};
- view_2d_info.buffer = self->ub_2d[i].buffer;
- view_2d_info.offset = 0;
- view_2d_info.range = sizeof(BluCat::GRA::UDOView2D);
-
- std::array<VkWriteDescriptorSet, 1> write_descriptors{};
- write_descriptors[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- write_descriptors[0].dstSet = self->descriptor_sets_2d[i];
- write_descriptors[0].dstBinding = 0;
- write_descriptors[0].dstArrayElement = 0;
- write_descriptors[0].descriptorCount = 1;
- write_descriptors[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- write_descriptors[0].pBufferInfo = &view_2d_info;
- write_descriptors[0].pImageInfo = nullptr;
- write_descriptors[0].pTexelBufferView = nullptr;
-
- vkUpdateDescriptorSets(
- BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
- write_descriptors.data(), 0, nullptr);
-
- BluCat::GRA::UDOView2D ubo_view_2d;
- ubo_view_2d.proj = glm::ortho(
- 0.0f, self->projection_width,
- 0.0f, self->projection_height,
- 0.0f, 100.0f);
- self->ub_2d[i].copy_data(&ubo_view_2d);
- }
-}
-
-}
-
-namespace BluCat::GRA
-{
-
-const CommandChain View2D::loader{
- {&load_2d_uniform_buffer, &unload_2d_uniform_buffer}
-};
-
-const CommandChain View2D::descriptor_sets_loader{
- {&load_descriptor_sets_2d, nullptr},
- {&load_resources_to_descriptor_sets_2d, nullptr}
-};
-
-View2D::View2D(
- glm::vec4 region, float projection_width, float projection_height):
- projection_width{projection_width},
- projection_height{projection_height},
- region{region},
- descriptor_pool{VK_NULL_HANDLE},
- rectangles_to_draw{BluCat::INT::core.vk_swapchain->images_count},
- sprites_to_draw{BluCat::INT::core.vk_swapchain->images_count}
-{
- loader.execute(this);
-}
-
-View2D::~View2D()
-{
- loader.revert(this);
-}
-
-void
-View2D::load_descriptor_sets(VkDescriptorPool descriptor_pool)
-{
- if(this->descriptor_pool != VK_NULL_HANDLE) return;
-
- this->descriptor_pool = descriptor_pool;
- descriptor_sets_loader.execute(this);
-}
-
-void
-View2D::unload_descriptor_sets()
-{
- if(this->descriptor_pool == VK_NULL_HANDLE) return;
-
- this->descriptor_pool = VK_NULL_HANDLE;
- descriptor_sets_loader.revert(this);
-}
-
-}
diff --git a/src/blu_cat/gra/view_2d.hpp b/src/blu_cat/gra/view_2d.hpp
deleted file mode 100644
index 84b9f09..0000000
--- a/src/blu_cat/gra/view_2d.hpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BLU_CAT_GRA_VIEW_2D_H
-#define BLU_CAT_GRA_VIEW_2D_H 1
-
-#include <memory>
-#include <unordered_map>
-#include <vector>
-
-#include "vulkan.hpp"
-#include "sprite_to_draw.hpp"
-#include "rectangle.hpp"
-
-namespace BluCat::GRA
-{
-
-struct View2D
-{
- glm::vec4 region;
- float projection_width, projection_height;
-
- // FIXME: if these vectors get resized, they can cause a segmentation fault!
- std::vector<UniformBuffer> ub_2d;
-
- VkDescriptorPool descriptor_pool;
- std::vector<VkDescriptorSet> descriptor_sets_2d;
-
- std::vector<std::vector<Rectangle>> rectangles_to_draw;
- std::vector<std::vector<SpriteToDraw>> sprites_to_draw;
-
- View2D(glm::vec4 region, float projection_width, float projection_height);
- virtual ~View2D();
-
- void
- virtual load_descriptor_sets(VkDescriptorPool descriptor_pool);
-
- void
- virtual unload_descriptor_sets();
-
-protected:
- static const CommandChain loader, descriptor_sets_loader;
-};
-
-}
-
-#endif /* BLU_CAT_GRA_VIEW_2D_H */
diff --git a/src/blu_cat/int/core.cpp b/src/blu_cat/int/core.cpp
index d631d17..7e78b89 100644
--- a/src/blu_cat/int/core.cpp
+++ b/src/blu_cat/int/core.cpp
@@ -692,13 +692,13 @@ load_renderer(void *obj)
{
try
{
+ auto width{static_cast<float>(BluCat::INT::core.display_width)};
+ auto height{static_cast<float>(BluCat::INT::core.display_height)};
glm::vec4 region(
- 0.f, 0.f,
- static_cast<float>(BluCat::INT::core.display_width),
- static_cast<float>(BluCat::INT::core.display_height));
+ 0.f, 0.f, width, height);
BluCat::INT::core.vk_renderer = new BluCat::GRA::Renderer(
- {},
- {std::make_shared<BluCat::GRA::View3D>(region, region.z, region.w)});
+ {std::make_shared<BluCat::GRA::View>(region, region.z, region.w)},
+ width, height);
}
catch(const CommandError &e)
{
diff --git a/src/candy_gear/candy_gear.cpp b/src/candy_gear/candy_gear.cpp
index b1758a4..7b5a9d9 100644
--- a/src/candy_gear/candy_gear.cpp
+++ b/src/candy_gear/candy_gear.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,7 @@
#include <mruby/string.h>
#include "core.hpp"
-#include "view_2d.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
static mrb_value
cg_mCandyGear_set_game_name(mrb_state *mrb, mrb_value self)
@@ -36,40 +35,28 @@ cg_mCandyGear_set_game_name(mrb_state *mrb, mrb_value self)
}
static mrb_value
-cg_mCandyGear_set_views(mrb_state *mrb, mrb_value self)
+cg_mCandyGear_change_views(mrb_state *mrb, mrb_value self)
{
- struct RClass *cg_m, *cg_cView2D, *cg_cView3D;
+ struct RClass *cg_m, *cg_cView;
mrb_value *array;
mrb_int array_len;
+ mrb_float width, height;
- std::vector<std::shared_ptr<BluCat::GRA::View2D>> views_2d;
- std::vector<std::shared_ptr<BluCat::GRA::View3D>> views_3d;
+ std::vector<std::shared_ptr<BluCat::GRA::View>> views;
cg_m = mrb_module_get(mrb, "CandyGear");
- cg_cView2D = mrb_class_get_under(mrb, cg_m, "View2D");
- cg_cView3D = mrb_class_get_under(mrb, cg_m, "View3D");
+ cg_cView = mrb_class_get_under(mrb, cg_m, "View");
- mrb_get_args(mrb, "a", &array, &array_len);
+ mrb_get_args(mrb, "aff", &array, &array_len, &width, &height);
for(mrb_int i{0}; i < array_len; i++)
{
- if(mrb_obj_is_kind_of(mrb, array[i], cg_cView2D))
- {
- auto v = (std::shared_ptr<BluCat::GRA::View2D>*)DATA_PTR(array[i]);
- views_2d.push_back(*v);
- }
- else if(mrb_obj_is_kind_of(mrb, array[i], cg_cView3D))
- {
- auto v = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(array[i]);
- views_3d.push_back(*v);
- }
+ auto v = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(array[i]);
+ views.push_back(*v);
}
- // A Renderer need at least one view to work.
- if(views_2d.size() > 0 || views_3d.size() > 0)
- {
- delete BluCat::INT::core.vk_renderer;
- BluCat::INT::core.vk_renderer = new BluCat::GRA::Renderer({views_2d, views_3d});
- }
+ delete BluCat::INT::core.vk_renderer;
+ BluCat::INT::core.vk_renderer = new BluCat::GRA::Renderer(
+ {views, static_cast<F32>(width), static_cast<F32>(height)});
return self;
}
@@ -138,7 +125,7 @@ cg_candy_gear_init(mrb_state *mrb)
cg_m = mrb_module_get(mrb, "CandyGear");
mrb_define_class_method(
- mrb, cg_m, "views=", cg_mCandyGear_set_views, MRB_ARGS_REQ(1));
+ mrb, cg_m, "change_views", cg_mCandyGear_change_views, MRB_ARGS_REQ(3));
mrb_define_class_method(
mrb, cg_m, "log", cg_mCandyGear_log, MRB_ARGS_REQ(2));
mrb_define_class_method(
diff --git a/src/candy_gear/core.cpp b/src/candy_gear/core.cpp
index 6897921..0f5330c 100644
--- a/src/candy_gear/core.cpp
+++ b/src/candy_gear/core.cpp
@@ -31,8 +31,7 @@
#include "texture.hpp"
#include "vector_3d.hpp"
#include "vector_4d.hpp"
-#include "view_2d.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
#ifdef DEBUG
#include <sstream>
@@ -117,8 +116,7 @@ load_mruby_interface(void *obj)
cg_texture_init(cg_core.mrb);
cg_vector_3d_init(cg_core.mrb);
cg_vector_4d_init(cg_core.mrb);
- cg_view_2d_init(cg_core.mrb);
- cg_view_3d_init(cg_core.mrb);
+ cg_view_init(cg_core.mrb);
}
}
diff --git a/src/candy_gear/sprite.cpp b/src/candy_gear/sprite.cpp
index daf96a8..2847d76 100644
--- a/src/candy_gear/sprite.cpp
+++ b/src/candy_gear/sprite.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
#include "texture.hpp"
#include "vector_4d.hpp"
-#include "view_2d.hpp"
#include "../blu_cat/gra/sprite.hpp"
void
@@ -61,17 +60,13 @@ cg_cSprite_initialize(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cSprite_draw(mrb_state *mrb, mrb_value self)
{
- mrb_value view_value;
- BluCat::GRA::View2D *view_2d;
mrb_float x, y, w, h, z_index{0.0};
auto ptr = (std::shared_ptr<BluCat::GRA::Sprite>*)DATA_PTR(self);
- mrb_get_args(mrb, "offff|f", &view_value, &x, &y, &w, &h, &z_index);
-
- view_2d = cg_cView_to_view_2d(mrb, view_value);
+ mrb_get_args(mrb, "ffff|f", &x, &y, &w, &h, &z_index);
glm::vec4 rect(x, y, x + w, y + h);
- auto &sprites_to_draw = view_2d->sprites_to_draw[
+ auto &sprites_to_draw = BluCat::INT::core.vk_renderer->sprites_to_draw[
BluCat::INT::core.vk_swapchain->current_frame];
sprites_to_draw.emplace_back(*ptr, rect, z_index);
diff --git a/src/candy_gear/vector_4d.cpp b/src/candy_gear/vector_4d.cpp
index b44b612..5ee674d 100644
--- a/src/candy_gear/vector_4d.cpp
+++ b/src/candy_gear/vector_4d.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
#include <mruby/array.h>
#include "vector_3d.hpp"
-#include "view_2d.hpp"
+#include "view.hpp"
namespace
{
@@ -347,19 +347,15 @@ cg_cVector4D_collide(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cVector4D_draw_rectangle(mrb_state *mrb, mrb_value self)
{
- mrb_value view_value;
- BluCat::GRA::View2D *view_2d;
std::shared_ptr<glm::vec3> *color;
auto ptr = (std::shared_ptr<glm::vec4>*)DATA_PTR(self);
- mrb_get_args(mrb, "od", &view_value, &color, &cg_vector_3d_type);
-
- view_2d = cg_cView_to_view_2d(mrb, view_value);
+ mrb_get_args(mrb, "d", &color, &cg_vector_3d_type);
glm::vec4 position(
(*ptr)->x, (*ptr)->y, (*ptr)->x + (*ptr)->z, (*ptr)->y + (*ptr)->w);
BluCat::GRA::Rectangle rect{position, (**color)};
- auto &rectangles = view_2d->rectangles_to_draw[
+ auto &rectangles = BluCat::INT::core.vk_renderer->rectangles_to_draw[
BluCat::INT::core.vk_swapchain->current_frame];
rectangles.push_back(rect);
diff --git a/src/candy_gear/view_3d.cpp b/src/candy_gear/view.cpp
index b829cca..40a03a8 100644
--- a/src/candy_gear/view_3d.cpp
+++ b/src/candy_gear/view.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,53 +14,53 @@
* limitations under the License.
*/
-#include "view_3d.hpp"
+#include "view.hpp"
#include "sprite.hpp"
#include "orientation_3d.hpp"
#include "vector_3d.hpp"
#include "vector_4d.hpp"
#include "../blu_cat/gra/sprite.hpp"
-#include "../blu_cat/gra/view_3d.hpp"
+#include "../blu_cat/gra/view.hpp"
void
-cg_free_view_3d(mrb_state *mrb, void* obj)
+cg_free_view(mrb_state *mrb, void* obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::GRA::View3D>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::View>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
}
-const struct mrb_data_type cg_view_3d_type = { "CG_View3D", cg_free_view_3d };
+const struct mrb_data_type cg_view_type = { "CG_View", cg_free_view };
static mrb_value
-cg_cView3D_initialize(mrb_state *mrb, mrb_value self)
+cg_cView_initialize(mrb_state *mrb, mrb_value self)
{
std::shared_ptr<glm::vec4> *region;
mrb_float projection_width, projection_height;
- std::shared_ptr<BluCat::GRA::View3D> *ptr;
+ std::shared_ptr<BluCat::GRA::View> *ptr;
mrb_get_args(mrb, "dff", &region, &cg_vector_4d_type,
&projection_width, &projection_height);
- ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::GRA::View3D>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::GRA::View3D>));
+ ptr = (std::shared_ptr<BluCat::GRA::View>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::View>));
- new(ptr)std::shared_ptr<BluCat::GRA::View3D>(
- std::make_shared<BluCat::GRA::View3D>(
+ new(ptr)std::shared_ptr<BluCat::GRA::View>(
+ std::make_shared<BluCat::GRA::View>(
*region->get(), projection_width, projection_height));
- mrb_data_init(self, ptr, &cg_view_3d_type);
+ mrb_data_init(self, ptr, &cg_view_type);
return self;
}
static mrb_value
-cg_cView3D_set_camera_position(mrb_state *mrb, mrb_value self)
+cg_cView_set_camera_position(mrb_state *mrb, mrb_value self)
{
std::shared_ptr<glm::vec3> *camera_position;
- auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self);
mrb_get_args(mrb, "d", &camera_position, &cg_vector_3d_type);
(*ptr)->camera_position = (*camera_position);
@@ -69,10 +69,10 @@ cg_cView3D_set_camera_position(mrb_state *mrb, mrb_value self)
}
static mrb_value
-cg_cView3D_set_camera_orientation(mrb_state *mrb, mrb_value self)
+cg_cView_set_camera_orientation(mrb_state *mrb, mrb_value self)
{
std::shared_ptr<glm::quat> *camera_orientation;
- auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self);
mrb_get_args(mrb, "d", &camera_orientation, &cg_orientation_3d_type);
(*ptr)->camera_orientation = (*camera_orientation);
@@ -81,9 +81,9 @@ cg_cView3D_set_camera_orientation(mrb_state *mrb, mrb_value self)
}
static mrb_value
-cg_cView3D_get_field_of_view(mrb_state *mrb, mrb_value self)
+cg_cView_get_field_of_view(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self);
return mrb_float_value(mrb, (*ptr)->field_of_view);
@@ -91,10 +91,10 @@ cg_cView3D_get_field_of_view(mrb_state *mrb, mrb_value self)
}
static mrb_value
-cg_cView3D_set_field_of_view(mrb_state *mrb, mrb_value self)
+cg_cView_set_field_of_view(mrb_state *mrb, mrb_value self)
{
mrb_float fov;
- auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self);
mrb_get_args(mrb, "f", &fov);
(*ptr)->field_of_view = fov;
@@ -103,25 +103,25 @@ cg_cView3D_set_field_of_view(mrb_state *mrb, mrb_value self)
}
void
-cg_view_3d_init(mrb_state *mrb)
+cg_view_init(mrb_state *mrb)
{
- struct RClass *cg_m, *cg_cView3D;
+ struct RClass *cg_m, *cg_cView;
cg_m = mrb_module_get(mrb, "CandyGear");
- cg_cView3D = mrb_define_class_under(mrb, cg_m, "View3D", mrb->object_class);
- MRB_SET_INSTANCE_TT(cg_cView3D, MRB_TT_DATA);
+ cg_cView = mrb_define_class_under(mrb, cg_m, "View", mrb->object_class);
+ MRB_SET_INSTANCE_TT(cg_cView, MRB_TT_DATA);
mrb_define_method(
- mrb, cg_cView3D, "initialize", cg_cView3D_initialize, MRB_ARGS_REQ(3));
+ mrb, cg_cView, "initialize", cg_cView_initialize, MRB_ARGS_REQ(3));
mrb_define_method(
- mrb, cg_cView3D, "camera_position=", cg_cView3D_set_camera_position,
+ mrb, cg_cView, "camera_position=", cg_cView_set_camera_position,
MRB_ARGS_REQ(1));
mrb_define_method(
- mrb, cg_cView3D, "camera_orientation=", cg_cView3D_set_camera_orientation,
+ mrb, cg_cView, "camera_orientation=", cg_cView_set_camera_orientation,
MRB_ARGS_REQ(1));
mrb_define_method(
- mrb, cg_cView3D, "field_of_view", cg_cView3D_get_field_of_view,
+ mrb, cg_cView, "field_of_view", cg_cView_get_field_of_view,
MRB_ARGS_NONE());
mrb_define_method(
- mrb, cg_cView3D, "field_of_view=", cg_cView3D_set_field_of_view,
+ mrb, cg_cView, "field_of_view=", cg_cView_set_field_of_view,
MRB_ARGS_REQ(1));
}
diff --git a/src/candy_gear/view_3d.hpp b/src/candy_gear/view.hpp
index 22aa084..ce1b556 100644
--- a/src/candy_gear/view_3d.hpp
+++ b/src/candy_gear/view.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_VIEW_3D_H
-#define CANDY_GEAR_VIEW_3D_H 1
+#ifndef CANDY_GEAR_VIEW_H
+#define CANDY_GEAR_VIEW_H 1
#include "core.hpp"
-extern const struct mrb_data_type cg_view_3d_type;
+extern const struct mrb_data_type cg_view_type;
void
-cg_view_3d_init(mrb_state *mrb);
+cg_view_init(mrb_state *mrb);
-#endif /* CANDY_GEAR_VIEW_3D_H */
+#endif /* CANDY_GEAR_VIEW_H */
diff --git a/src/candy_gear/view_2d.cpp b/src/candy_gear/view_2d.cpp
deleted file mode 100644
index e0dc8a1..0000000
--- a/src/candy_gear/view_2d.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "view_2d.hpp"
-
-#include "sprite.hpp"
-#include "vector_4d.hpp"
-#include "view_3d.hpp"
-#include "../blu_cat/gra/sprite.hpp"
-#include "../blu_cat/gra/view_2d.hpp"
-
-void
-cg_free_view_2d(mrb_state *mrb, void* obj)
-{
- auto ptr = static_cast<std::shared_ptr<BluCat::GRA::View2D>*>(obj);
-
- ptr->~shared_ptr();
- mrb_free(mrb, ptr);
-}
-
-const struct mrb_data_type cg_view_2d_type = { "CG_View2D", cg_free_view_2d };
-
-static mrb_value
-cg_cView2D_initialize(mrb_state *mrb, mrb_value self)
-{
- std::shared_ptr<glm::vec4> *region;
- mrb_float projection_width, projection_height;
- std::shared_ptr<BluCat::GRA::View2D> *ptr;
-
- mrb_get_args(mrb, "dff", &region, &cg_vector_4d_type,
- &projection_width, &projection_height);
- ptr = (std::shared_ptr<BluCat::GRA::View2D>*)DATA_PTR(self);
- if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::GRA::View2D>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::GRA::View2D>));
-
- new(ptr)std::shared_ptr<BluCat::GRA::View2D>(
- std::make_shared<BluCat::GRA::View2D>(
- *region->get(), projection_width, projection_height));
-
- mrb_data_init(self, ptr, &cg_view_2d_type);
- return self;
-}
-
-BluCat::GRA::View2D*
-cg_cView_to_view_2d(mrb_state *mrb, mrb_value view_value)
-{
- BluCat::GRA::View2D* view_2d;
- const mrb_data_type *type = DATA_TYPE(view_value);
-
- if(type == &cg_view_2d_type)
- view_2d = static_cast<std::shared_ptr<BluCat::GRA::View2D>*>(
- DATA_PTR(view_value))->get();
- else if (type == &cg_view_3d_type)
- view_2d = static_cast<BluCat::GRA::View2D*>(
- static_cast<std::shared_ptr<BluCat::GRA::View3D>*>(
- DATA_PTR(view_value))->get());
- else
- mrb_raisef(
- mrb, E_TYPE_ERROR, "wrong argument type %s (expected %s or %s)",
- type->struct_name, cg_view_2d_type.struct_name,
- cg_view_3d_type.struct_name);
-
- return view_2d;
-}
-
-void
-cg_view_2d_init(mrb_state *mrb)
-{
- struct RClass *cg_m, *cg_cView2D;
-
- cg_m = mrb_module_get(mrb, "CandyGear");
- cg_cView2D = mrb_define_class_under(mrb, cg_m, "View2D", mrb->object_class);
- MRB_SET_INSTANCE_TT(cg_cView2D, MRB_TT_DATA);
- mrb_define_method(
- mrb, cg_cView2D, "initialize", cg_cView2D_initialize, MRB_ARGS_REQ(3));
-}
diff --git a/src/candy_gear/view_2d.hpp b/src/candy_gear/view_2d.hpp
deleted file mode 100644
index 9b742a0..0000000
--- a/src/candy_gear/view_2d.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CANDY_GEAR_VIEW_2D_H
-#define CANDY_GEAR_VIEW_2D_H 1
-
-#include "core.hpp"
-
-extern const struct mrb_data_type cg_view_2d_type;
-
-// Receives a mrb_value that points to a View2D or a View3D and returns a
-// pointer to View2D. If the mrb_value points to a View3D, the view will be
-// cast to a BluCat::GRA::View2D.
-BluCat::GRA::View2D*
-cg_cView_to_view_2d(mrb_state *mrb, mrb_value view_value);
-
-void
-cg_view_2d_init(mrb_state *mrb);
-
-#endif /* CANDY_GEAR_VIEW_2D_H */
diff --git a/test/src/mode/demo.rb b/test/src/mode/demo.rb
index 65ea52a..86ef578 100644
--- a/test/src/mode/demo.rb
+++ b/test/src/mode/demo.rb
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 Frederico de Oliveira Linhares
+# Copyright 2022-2025 Frederico de Oliveira Linhares
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -81,14 +81,12 @@ module Mode
@camera_orientation = CandyGear::Orientation3D.new(0.0, 0.0, 0.0);
color = CandyGear::Vector3D.new(0.12, 0.12, 0.18);
- @view1 = CandyGear::View2D.new(
- CandyGear::Vector4D.new(0, 0, 1280, 240), 640, 120);
- @view2 = CandyGear::View3D.new(
+ @view = CandyGear::View.new(
CandyGear::Vector4D.new(0, 240, 1280, 480), 1280, 480);
- CandyGear.views = [@view1, @view2];
+ CandyGear.change_views([@view], 640, 360);
- @view2.camera_position = @camera_position;
- @view2.camera_orientation = @camera_orientation;
+ @view.camera_position = @camera_position;
+ @view.camera_orientation = @camera_orientation;
end
def key_down(key)
@@ -125,16 +123,16 @@ module Mode
def tick()
@sprite.draw(
- @view1, @sprite_position.x, @sprite_position.y,
+ @sprite_position.x, @sprite_position.y,
@sprite_position.w, @sprite_position.h);
@japanese_text_sprite.draw(
- @view1, @japanese_text_position.x, @japanese_text_position.y,
+ @japanese_text_position.x, @japanese_text_position.y,
@japanese_text_position.w, @japanese_text_position.h);
@english_text_sprite.draw(
- @view1, @english_text_position.x, @english_text_position.y,
+ @english_text_position.x, @english_text_position.y,
@english_text_position.w, @english_text_position.h);
@instances_orientation.rotate(0.0, BOX_ROTATION_SPEED, 0.0);
- @rectangle.draw_rectangle(@view1, @color);
+ @rectangle.draw_rectangle(@color);
@instances.each {_1.draw()};
@skeletal_model.draw();
# @sprite_3d.draw();
diff --git a/test/src/mode/title.rb b/test/src/mode/title.rb
index 6347b70..2e5a35b 100644
--- a/test/src/mode/title.rb
+++ b/test/src/mode/title.rb
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 Frederico de Oliveira Linhares
+# Copyright 2022-2025 Frederico de Oliveira Linhares
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
module Mode
class Title
def initialize()
- @view = CandyGear::View2D.new(
+ @view = CandyGear::View.new(
CandyGear::Vector4D.new(0, 0, 1280, 720), 640, 360);
- CandyGear.views = [@view];
+ CandyGear.change_views([@view], 640, 360);
@menu = CandyGear::Menu.new(
- @view,
$global_data[:menu_view], 10, 10,
[
{text: "Demo", action: -> {change_mode(:demo);}},