summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2022-12-23 15:02:39 -0300
committerFrederico Linhares <fred@linhares.blue>2022-12-23 15:02:39 -0300
commit75337ae1c59e8b2c3bc6fbcd7ccafc7a8205d6b2 (patch)
tree10b33abdf881e33ff20b7a11a789f62dd05124cf /src
parent1cd2d838bf1682e125d52d12ac6f2960df65c7e0 (diff)
feat Add size to projections in 2D views
Diffstat (limited to 'src')
-rw-r--r--src/core.cpp2
-rw-r--r--src/view_2d.cpp9
-rw-r--r--src/view_3d.cpp9
-rw-r--r--src/vk/view_2d.cpp9
-rw-r--r--src/vk/view_2d.hpp3
-rw-r--r--src/vk/view_3d.cpp5
-rw-r--r--src/vk/view_3d.hpp2
7 files changed, 25 insertions, 14 deletions
diff --git a/src/core.cpp b/src/core.cpp
index 0de2dbd..bd5ea75 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -649,7 +649,7 @@ load_vk_renderer(void *obj)
static_cast<float>(cg_core.display_height));
cg_core.vk_renderer = new VK::Renderer(
{},
- {std::make_shared<VK::View3D>(region)});
+ {std::make_shared<VK::View3D>(region, region.z, region.w)});
}
catch(const CommandError &e)
{
diff --git a/src/view_2d.cpp b/src/view_2d.cpp
index 3f4325d..4a973d6 100644
--- a/src/view_2d.cpp
+++ b/src/view_2d.cpp
@@ -37,16 +37,19 @@ 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<VK::View2D> *ptr;
- mrb_get_args(mrb, "d", &region, &cg_vector_4d_type);
+ mrb_get_args(mrb, "dff", &region, &cg_vector_4d_type,
+ &projection_width, &projection_height);
ptr = (std::shared_ptr<VK::View2D>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
ptr = (std::shared_ptr<VK::View2D>*)mrb_malloc(
mrb, sizeof(std::shared_ptr<VK::View2D>));
new(ptr)std::shared_ptr<VK::View2D>(
- std::make_shared<VK::View2D>(*region->get()));
+ std::make_shared<VK::View2D>(
+ *region->get(), projection_width, projection_height));
mrb_data_init(self, ptr, &cg_view_2d_type);
return self;
@@ -83,5 +86,5 @@ cg_view_2d_init(mrb_state *mrb)
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(1));
+ mrb, cg_cView2D, "initialize", cg_cView2D_initialize, MRB_ARGS_REQ(3));
}
diff --git a/src/view_3d.cpp b/src/view_3d.cpp
index 1b733b8..92e57c9 100644
--- a/src/view_3d.cpp
+++ b/src/view_3d.cpp
@@ -38,16 +38,19 @@ static mrb_value
cg_cView3D_initialize(mrb_state *mrb, mrb_value self)
{
std::shared_ptr<glm::vec4> *region;
+ mrb_float projection_width, projection_height;
std::shared_ptr<VK::View3D> *ptr;
- mrb_get_args(mrb, "d", &region, &cg_vector_4d_type);
+ mrb_get_args(mrb, "dff", &region, &cg_vector_4d_type,
+ &projection_width, &projection_height);
ptr = (std::shared_ptr<VK::View3D>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
ptr = (std::shared_ptr<VK::View3D>*)mrb_malloc(
mrb, sizeof(std::shared_ptr<VK::View3D>));
new(ptr)std::shared_ptr<VK::View3D>(
- std::make_shared<VK::View3D>(*region->get()));
+ std::make_shared<VK::View3D>(
+ *region->get(), projection_width, projection_height));
mrb_data_init(self, ptr, &cg_view_3d_type);
return self;
@@ -86,7 +89,7 @@ cg_view_3d_init(mrb_state *mrb)
cg_cView3D = mrb_define_class_under(mrb, cg_m, "View3D", mrb->object_class);
MRB_SET_INSTANCE_TT(cg_cView3D, MRB_TT_DATA);
mrb_define_method(
- mrb, cg_cView3D, "initialize", cg_cView3D_initialize, MRB_ARGS_REQ(1));
+ mrb, cg_cView3D, "initialize", cg_cView3D_initialize, MRB_ARGS_REQ(3));
mrb_define_method(
mrb, cg_cView3D, "camera_position=", cg_cView3D_set_camera_position,
MRB_ARGS_REQ(1));
diff --git a/src/vk/view_2d.cpp b/src/vk/view_2d.cpp
index a80cc89..b6f208c 100644
--- a/src/vk/view_2d.cpp
+++ b/src/vk/view_2d.cpp
@@ -101,8 +101,8 @@ load_resources_to_descriptor_sets_2d(void *obj)
VK::UBOView2D ubo_view_2d;
ubo_view_2d.proj = glm::ortho(
- 0.0f, self->region.z,
- 0.0f, self->region.w,
+ 0.0f, self->projection_width,
+ 0.0f, self->projection_height,
0.0f, 100.0f);
self->ub_2d[i].copy_data(&ubo_view_2d);
}
@@ -122,7 +122,10 @@ const CommandChain View2D::descriptor_sets_loader{
{&load_resources_to_descriptor_sets_2d, nullptr}
};
-View2D::View2D(glm::vec4 region):
+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{cg_core.vk_swapchain->images_count},
diff --git a/src/vk/view_2d.hpp b/src/vk/view_2d.hpp
index f49c3be..caa3d0f 100644
--- a/src/vk/view_2d.hpp
+++ b/src/vk/view_2d.hpp
@@ -31,6 +31,7 @@ namespace VK
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;
@@ -43,7 +44,7 @@ struct View2D
std::unordered_map<std::shared_ptr<Sprite>, std::vector<glm::vec4>>>
sprites_to_draw;
- View2D(glm::vec4 region);
+ View2D(glm::vec4 region, float projection_width, float projection_height);
virtual ~View2D();
void
diff --git a/src/vk/view_3d.cpp b/src/vk/view_3d.cpp
index 39d1159..d9e9844 100644
--- a/src/vk/view_3d.cpp
+++ b/src/vk/view_3d.cpp
@@ -122,8 +122,9 @@ const CommandChain descriptor_sets_loader{
namespace VK
{
-View3D::View3D(glm::vec4 region):
- View2D{region},
+View3D::View3D(
+ glm::vec4 region, float projection_width, float projection_height):
+ View2D{region, projection_width, projection_height},
camera_position{std::make_shared<glm::vec3>(0.0f, 0.0f, 0.0f)},
camera_rotation{std::make_shared<glm::vec3>(0.0f, 0.0f, 0.0f)}
{
diff --git a/src/vk/view_3d.hpp b/src/vk/view_3d.hpp
index ba08957..1d51070 100644
--- a/src/vk/view_3d.hpp
+++ b/src/vk/view_3d.hpp
@@ -32,7 +32,7 @@ struct View3D: public View2D
std::shared_ptr<glm::vec3> camera_position;
std::shared_ptr<glm::vec3> camera_rotation;
- View3D(glm::vec4 region);
+ View3D(glm::vec4 region, float projection_width, float projection_height);
~View3D();
void