summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blu_cat/com/binary_reader.cpp (renamed from src/binary_reader.cpp)57
-rw-r--r--src/blu_cat/com/binary_reader.hpp (renamed from src/binary_reader.hpp)45
-rw-r--r--src/blu_cat/com/binary_writer.cpp180
-rw-r--r--src/blu_cat/com/binary_writer.hpp74
-rw-r--r--src/blu_cat/com/command.cpp (renamed from src/command.cpp)0
-rw-r--r--src/blu_cat/com/command.hpp (renamed from src/command.hpp)6
-rw-r--r--src/blu_cat/com/job_queue.cpp (renamed from src/job_queue.cpp)5
-rw-r--r--src/blu_cat/com/job_queue.hpp (renamed from src/job_queue.hpp)11
-rw-r--r--src/blu_cat/com/numbers.hpp (renamed from src/blucat/core.hpp)42
-rw-r--r--src/blu_cat/com/worker.cpp (renamed from src/worker.cpp)5
-rw-r--r--src/blu_cat/com/worker.hpp (renamed from src/worker.hpp)11
-rw-r--r--src/blu_cat/gra/animation.cpp (renamed from src/blucat/animation.cpp)2
-rw-r--r--src/blu_cat/gra/animation.hpp (renamed from src/blucat/animation.hpp)10
-rw-r--r--src/blu_cat/gra/animation/frame.hpp (renamed from src/blucat/animation/frame.hpp)10
-rw-r--r--src/blu_cat/gra/base_buffer.cpp (renamed from src/blucat/base_buffer.cpp)2
-rw-r--r--src/blu_cat/gra/base_buffer.hpp (renamed from src/blucat/base_buffer.hpp)12
-rw-r--r--src/blu_cat/gra/character.cpp (renamed from src/blucat/character.cpp)37
-rw-r--r--src/blu_cat/gra/character.hpp (renamed from src/blucat/character.hpp)10
-rw-r--r--src/blu_cat/gra/command_pool.cpp (renamed from src/blucat/command_pool.cpp)2
-rw-r--r--src/blu_cat/gra/command_pool.hpp (renamed from src/blucat/command_pool.hpp)12
-rw-r--r--src/blu_cat/gra/descriptor_set_layout.cpp (renamed from src/blucat/descriptor_set_layout.cpp)36
-rw-r--r--src/blu_cat/gra/descriptor_set_layout.hpp (renamed from src/blucat/descriptor_set_layout.hpp)10
-rw-r--r--src/blu_cat/gra/destination_buffer.cpp (renamed from src/blucat/destination_buffer.cpp)2
-rw-r--r--src/blu_cat/gra/destination_buffer.hpp (renamed from src/blucat/destination_buffer.hpp)10
-rw-r--r--src/blu_cat/gra/device.cpp (renamed from src/blucat/device.cpp)13
-rw-r--r--src/blu_cat/gra/device.hpp (renamed from src/blucat/device.hpp)10
-rw-r--r--src/blu_cat/gra/font.cpp (renamed from src/blucat/font.cpp)7
-rw-r--r--src/blu_cat/gra/font.hpp (renamed from src/blucat/font.hpp)8
-rw-r--r--src/blu_cat/gra/framebuffer.cpp (renamed from src/blucat/framebuffer.cpp)78
-rw-r--r--src/blu_cat/gra/framebuffer.hpp (renamed from src/blucat/framebuffer.hpp)10
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_solid.cpp (renamed from src/blucat/graphics_pipeline_2d_solid.cpp)67
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_solid.hpp (renamed from src/blucat/graphics_pipeline_2d_solid.hpp)18
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_solid_layout.cpp (renamed from src/blucat/graphics_pipeline_2d_solid_layout.cpp)18
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_solid_layout.hpp (renamed from src/blucat/graphics_pipeline_2d_solid_layout.hpp)10
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_wired.cpp (renamed from src/blucat/graphics_pipeline_2d_wired.cpp)80
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_wired.hpp (renamed from src/blucat/graphics_pipeline_2d_wired.hpp)20
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_wired_layout.cpp (renamed from src/blucat/graphics_pipeline_2d_wired_layout.cpp)20
-rw-r--r--src/blu_cat/gra/graphics_pipeline_2d_wired_layout.hpp (renamed from src/blucat/graphics_pipeline_2d_wired_layout.hpp)10
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d.cpp (renamed from src/blucat/graphics_pipeline_3d.cpp)51
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d.hpp (renamed from src/blucat/graphics_pipeline_3d.hpp)16
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d_layout.cpp (renamed from src/blucat/graphics_pipeline_3d_layout.cpp)20
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d_layout.hpp (renamed from src/blucat/graphics_pipeline_3d_layout.hpp)10
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp (renamed from src/blucat/graphics_pipeline_3d_skeletal.cpp)56
-rw-r--r--src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp (renamed from src/blucat/graphics_pipeline_3d_skeletal.hpp)16
-rw-r--r--src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp (renamed from src/blucat/graphics_pipeline_sprite_3d.cpp)46
-rw-r--r--src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp (renamed from src/blucat/graphics_pipeline_sprite_3d.hpp)16
-rw-r--r--src/blu_cat/gra/image.cpp (renamed from src/blucat/image.cpp)8
-rw-r--r--src/blu_cat/gra/image.hpp (renamed from src/blucat/image.hpp)14
-rw-r--r--src/blu_cat/gra/light.cpp (renamed from src/blucat/light.cpp)50
-rw-r--r--src/blu_cat/gra/light.hpp (renamed from src/blucat/light.hpp)10
-rw-r--r--src/blu_cat/gra/log.cpp (renamed from src/log.cpp)0
-rw-r--r--src/blu_cat/gra/log.hpp (renamed from src/log.hpp)0
-rw-r--r--src/blu_cat/gra/qoi.cpp (renamed from src/blucat/qoi.cpp)6
-rw-r--r--src/blu_cat/gra/qoi.hpp (renamed from src/blucat/qoi.hpp)2
-rw-r--r--src/blu_cat/gra/queue.cpp (renamed from src/blucat/queue.cpp)4
-rw-r--r--src/blu_cat/gra/queue.hpp (renamed from src/blucat/queue.hpp)16
-rw-r--r--src/blu_cat/gra/queue_family.cpp (renamed from src/blucat/queue_family.cpp)8
-rw-r--r--src/blu_cat/gra/queue_family.hpp (renamed from src/blucat/queue_family.hpp)14
-rw-r--r--src/blu_cat/gra/rectangle.cpp (renamed from src/blucat/rectangle.cpp)2
-rw-r--r--src/blu_cat/gra/rectangle.hpp (renamed from src/blucat/rectangle.hpp)10
-rw-r--r--src/blu_cat/gra/render_pass.cpp (renamed from src/blucat/render_pass.cpp)26
-rw-r--r--src/blu_cat/gra/render_pass.hpp (renamed from src/blucat/render_pass.hpp)10
-rw-r--r--src/blu_cat/gra/renderer.cpp (renamed from src/blucat/renderer.cpp)291
-rw-r--r--src/blu_cat/gra/renderer.hpp (renamed from src/blucat/renderer.hpp)44
-rw-r--r--src/blu_cat/gra/skeletal_mesh.cpp252
-rw-r--r--src/blu_cat/gra/skeletal_mesh.hpp (renamed from src/blucat/skeletal_mesh.hpp)10
-rw-r--r--src/blu_cat/gra/skeletal_mesh_vertex.hpp (renamed from src/blucat/skeletal_mesh_vertex.hpp)10
-rw-r--r--src/blu_cat/gra/skeletal_model.cpp (renamed from src/blucat/skeletal_model.cpp)110
-rw-r--r--src/blu_cat/gra/skeletal_model.hpp (renamed from src/blucat/skeletal_model.hpp)10
-rw-r--r--src/blu_cat/gra/source_buffer.cpp (renamed from src/blucat/source_buffer.cpp)6
-rw-r--r--src/blu_cat/gra/source_buffer.hpp (renamed from src/blucat/source_buffer.hpp)8
-rw-r--r--src/blu_cat/gra/sprite.cpp (renamed from src/blucat/sprite.cpp)24
-rw-r--r--src/blu_cat/gra/sprite.hpp (renamed from src/blucat/sprite.hpp)12
-rw-r--r--src/blu_cat/gra/sprite_3d.cpp (renamed from src/blucat/sprite_3d.cpp)34
-rw-r--r--src/blu_cat/gra/sprite_3d.hpp (renamed from src/blucat/sprite_3d.hpp)10
-rw-r--r--src/blu_cat/gra/sprite_to_draw.cpp (renamed from src/blucat/sprite_to_draw.cpp)2
-rw-r--r--src/blu_cat/gra/sprite_to_draw.hpp (renamed from src/blucat/sprite_to_draw.hpp)10
-rw-r--r--src/blu_cat/gra/static_mesh.cpp (renamed from src/blucat/static_mesh.cpp)70
-rw-r--r--src/blu_cat/gra/static_mesh.hpp (renamed from src/blucat/static_mesh.hpp)10
-rw-r--r--src/blu_cat/gra/static_mesh_vertex.hpp (renamed from src/blucat/static_mesh_vertex.hpp)10
-rw-r--r--src/blu_cat/gra/static_model.cpp (renamed from src/blucat/static_model.cpp)30
-rw-r--r--src/blu_cat/gra/static_model.hpp (renamed from src/blucat/static_model.hpp)10
-rw-r--r--src/blu_cat/gra/swapchain.cpp (renamed from src/blucat/swapchain.cpp)61
-rw-r--r--src/blu_cat/gra/swapchain.hpp (renamed from src/blucat/swapchain.hpp)12
-rw-r--r--src/blu_cat/gra/texture.cpp (renamed from src/blucat/texture.cpp)117
-rw-r--r--src/blu_cat/gra/texture.hpp (renamed from src/blucat/texture.hpp)12
-rw-r--r--src/blu_cat/gra/uniform_buffer.cpp (renamed from src/blucat/uniform_buffer.cpp)2
-rw-r--r--src/blu_cat/gra/uniform_buffer.hpp (renamed from src/blucat/uniform_buffer.hpp)10
-rw-r--r--src/blu_cat/gra/uniform_data_object.hpp (renamed from src/blucat/uniform_data_object.hpp)10
-rw-r--r--src/blu_cat/gra/view.cpp (renamed from src/blucat/view_3d.cpp)81
-rw-r--r--src/blu_cat/gra/view.hpp (renamed from src/blucat/view_3d.hpp)33
-rw-r--r--src/blu_cat/gra/vulkan.hpp24
-rw-r--r--src/blu_cat/int/core.cpp761
-rw-r--r--src/blu_cat/int/core.hpp141
-rw-r--r--src/blu_cat/net/client/client.cpp64
-rw-r--r--src/blu_cat/net/client/client.hpp61
-rw-r--r--src/blu_cat/net/common/connection.cpp133
-rw-r--r--src/blu_cat/net/common/connection.hpp69
-rw-r--r--src/blu_cat/net/common/connection_callback.hpp (renamed from src/view_2d.hpp)32
-rw-r--r--src/blu_cat/net/common/message.hpp40
-rw-r--r--src/blu_cat/net/common/tsqueue.hpp106
-rw-r--r--src/blu_cat/net/server/server.cpp94
-rw-r--r--src/blu_cat/net/server/server.hpp53
-rw-r--r--src/blucat/skeletal_mesh.cpp204
-rw-r--r--src/blucat/view_2d.cpp160
-rw-r--r--src/blucat/view_2d.hpp60
-rw-r--r--src/candy_gear/candy_gear.cpp (renamed from src/candy_gear.cpp)45
-rw-r--r--src/candy_gear/candy_gear.hpp (renamed from src/candy_gear.hpp)0
-rw-r--r--src/candy_gear/core.cpp129
-rw-r--r--src/candy_gear/core.hpp51
-rw-r--r--src/candy_gear/font.cpp (renamed from src/font.cpp)12
-rw-r--r--src/candy_gear/font.hpp (renamed from src/font.hpp)0
-rw-r--r--src/candy_gear/graphic.cpp (renamed from src/graphic.cpp)6
-rw-r--r--src/candy_gear/graphic.hpp (renamed from src/graphic.hpp)0
-rw-r--r--src/candy_gear/key.cpp (renamed from src/key.cpp)0
-rw-r--r--src/candy_gear/key.hpp (renamed from src/key.hpp)0
-rw-r--r--src/candy_gear/main.cpp (renamed from src/main.cpp)14
-rw-r--r--src/candy_gear/orientation_3d.cpp (renamed from src/orientation_3d.cpp)0
-rw-r--r--src/candy_gear/orientation_3d.hpp (renamed from src/orientation_3d.hpp)0
-rw-r--r--src/candy_gear/skeletal_mesh.cpp (renamed from src/skeletal_mesh.cpp)16
-rw-r--r--src/candy_gear/skeletal_mesh.hpp (renamed from src/skeletal_mesh.hpp)0
-rw-r--r--src/candy_gear/skeletal_model.cpp (renamed from src/skeletal_model.cpp)32
-rw-r--r--src/candy_gear/skeletal_model.hpp (renamed from src/skeletal_model.hpp)0
-rw-r--r--src/candy_gear/sound.cpp (renamed from src/sound.cpp)0
-rw-r--r--src/candy_gear/sound.hpp (renamed from src/sound.hpp)0
-rw-r--r--src/candy_gear/sprite.cpp (renamed from src/sprite.cpp)33
-rw-r--r--src/candy_gear/sprite.hpp (renamed from src/sprite.hpp)0
-rw-r--r--src/candy_gear/sprite_3d.cpp (renamed from src/sprite_3d.cpp)22
-rw-r--r--src/candy_gear/sprite_3d.hpp (renamed from src/sprite_3d.hpp)0
-rw-r--r--src/candy_gear/static_mesh.cpp (renamed from src/static_mesh.cpp)16
-rw-r--r--src/candy_gear/static_mesh.hpp (renamed from src/static_mesh.hpp)0
-rw-r--r--src/candy_gear/static_model.cpp (renamed from src/static_model.cpp)34
-rw-r--r--src/candy_gear/static_model.hpp (renamed from src/static_model.hpp)0
-rw-r--r--src/candy_gear/texture.cpp (renamed from src/texture.cpp)34
-rw-r--r--src/candy_gear/texture.hpp (renamed from src/texture.hpp)2
-rw-r--r--src/candy_gear/vector_3d.cpp (renamed from src/vector_3d.cpp)0
-rw-r--r--src/candy_gear/vector_3d.hpp (renamed from src/vector_3d.hpp)0
-rw-r--r--src/candy_gear/vector_4d.cpp (renamed from src/vector_4d.cpp)16
-rw-r--r--src/candy_gear/vector_4d.hpp (renamed from src/vector_4d.hpp)0
-rw-r--r--src/candy_gear/view.cpp (renamed from src/view_3d.cpp)64
-rw-r--r--src/candy_gear/view.hpp (renamed from src/view_3d.hpp)12
-rw-r--r--src/core.cpp850
-rw-r--r--src/core.hpp148
-rw-r--r--src/view_2d.cpp90
144 files changed, 3625 insertions, 2675 deletions
diff --git a/src/binary_reader.cpp b/src/blu_cat/com/binary_reader.cpp
index 0727703..bb4d231 100644
--- a/src/binary_reader.cpp
+++ b/src/blu_cat/com/binary_reader.cpp
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -16,24 +16,25 @@
#include "binary_reader.hpp"
+#include <bit>
#include <fstream>
namespace
{
union IntAndFloat32bit{
- uint32_t i;
- float f;
+ UI32 i;
+ F32 f;
};
union IntAndFloat64bit{
- uint64_t i;
- double f;
+ UI64 i;
+ F64 f;
};
}
-BinaryReader::BinaryReader(std::string file_path):
+BinaryReader::BinaryReader(const std::string &file_path):
_pointer{0}
{
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
@@ -46,7 +47,7 @@ BinaryReader::BinaryReader(std::string file_path):
this->_size = file.tellg();
file.seekg(0);
- this->data = new uint8_t[this->_size];
+ this->data = new UI8[this->_size];
file.read((char*)data, this->_size);
}
@@ -60,36 +61,54 @@ BinaryReader::~BinaryReader()
delete[] this->data;
}
-uint8_t
+UI8
BinaryReader::read_ui8()
{
return this->data[this->_pointer++];
}
-uint32_t
+UI32
BinaryReader::read_ui32()
{
- uint8_t b1{this->data[_pointer++]}, b2{this->data[_pointer++]},
+ UI8 b1{this->data[_pointer++]}, b2{this->data[_pointer++]},
b3{this->data[_pointer++]}, b4{this->data[_pointer++]};
return b1 << 24 | b2 << 16 | b3 << 8 | b4;
}
-uint64_t
+UI64
BinaryReader::read_ui64()
{
- uint8_t b1{this->data[_pointer++]}, b2{this->data[_pointer++]},
+ UI8 b1{this->data[_pointer++]}, b2{this->data[_pointer++]},
b3{this->data[_pointer++]}, b4{this->data[_pointer++]},
b5{this->data[_pointer++]}, b6{this->data[_pointer++]},
b7{this->data[_pointer++]}, b8{this->data[_pointer++]};
- return (uint64_t)b1 << 56 | (uint64_t)b2 << 48 | (uint64_t)b3 << 40 |
- (uint64_t)b4 << 32 | (uint64_t)b5 << 24 | (uint64_t)b6 << 16 |
- (uint64_t)b7 << 8 | (uint64_t)b8;
+ return (UI64)b1 << 56 | (UI64)b2 << 48 | (UI64)b3 << 40 |
+ (UI64)b4 << 32 | (UI64)b5 << 24 | (UI64)b6 << 16 |
+ (UI64)b7 << 8 | (UI64)b8;
}
-float
-BinaryReader::read_float()
+I8
+BinaryReader::read_i8()
+{
+ return std::bit_cast<I8>(this->read_ui8());
+}
+
+I32
+BinaryReader::read_i32()
+{
+ return std::bit_cast<I32>(this->read_ui32());
+}
+
+I64
+BinaryReader::read_i64()
+{
+ return std::bit_cast<I64>(this->read_ui64());
+}
+
+F32
+BinaryReader::read_f32()
{
IntAndFloat32bit num;
num.i = read_ui32();
@@ -97,8 +116,8 @@ BinaryReader::read_float()
return num.f;
}
-double
-BinaryReader::read_double()
+F64
+BinaryReader::read_f64()
{
IntAndFloat64bit num;
num.i = read_ui64();
diff --git a/src/binary_reader.hpp b/src/blu_cat/com/binary_reader.hpp
index e09c13a..fec88b6 100644
--- a/src/binary_reader.hpp
+++ b/src/blu_cat/com/binary_reader.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,43 +14,54 @@
* limitations under the License.
*/
-#include <cstdint>
+#ifndef BLU_CAT_COM_BINARY_READER_H
+#define BLU_CAT_COM_BINARY_READER_H 1
+
#include <string>
-#include "blucat/core.hpp"
+#include "numbers.hpp"
class BinaryReader
{
- int _pointer;
- int _size;
- uint8_t *data;
+ UI64F _pointer;
+ UI64F _size;
+ UI8 *data;
public:
- BinaryReader(const std::string file_path);
+ BinaryReader(const std::string &file_path);
BinaryReader(const char *file_path);
~BinaryReader();
- inline int
+ inline UI64F
pointer(){return this->_pointer;};
- inline int
+ inline UI64F
size(){return this->_size;};
- uint8_t
+ UI8
read_ui8();
- uint32_t
+ UI32
read_ui32();
- uint64_t
+ UI64
read_ui64();
- float
- read_float();
+ I8
+ read_i8();
+
+ I32
+ read_i32();
+
+ I64
+ read_i64();
- double
- read_double();
+ F32
+ read_f32();
+
+ F64
+ read_f64();
glm::vec2
read_vec2();
@@ -67,3 +78,5 @@ public:
void
read_chars(char *str, int size);
};
+
+#endif /* BLU_CAT_COM_BINARY_READER_H */
diff --git a/src/blu_cat/com/binary_writer.cpp b/src/blu_cat/com/binary_writer.cpp
new file mode 100644
index 0000000..7af3b6d
--- /dev/null
+++ b/src/blu_cat/com/binary_writer.cpp
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ * 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 "binary_writer.hpp"
+
+namespace
+{
+
+union IntAndFloat32bit{
+ UI32 i;
+ F32 f;
+};
+
+union IntAndFloat64bit{
+ UI64 i;
+ F64 f;
+};
+
+}
+
+BinaryWriter::BinaryWriter(const char *file_path):
+ output{file_path, std::ios::binary}
+{
+}
+
+BinaryWriter::BinaryWriter(const std::string &file_path):
+ BinaryWriter{file_path.c_str()}
+{
+}
+
+void
+BinaryWriter::write_ui8(UI8 var)
+{
+ this->output.put(var);
+}
+
+void
+BinaryWriter::write_ui32(UI32 var)
+{
+ using namespace std;
+
+ UI8 b1 = var >> 24;
+ UI8 b2 = var >> 16;
+ UI8 b3 = var >> 8;
+ UI8 b4 = var;
+
+ this->output.put(b1);
+ this->output.put(b2);
+ this->output.put(b3);
+ this->output.put(b4);
+}
+
+void
+BinaryWriter::write_ui64(UI64 var)
+{
+ using namespace std;
+
+ UI8 b1 = var >> 56;
+ UI8 b2 = var >> 48;
+ UI8 b3 = var >> 40;
+ UI8 b4 = var >> 32;
+ UI8 b5 = var >> 24;
+ UI8 b6 = var >> 16;
+ UI8 b7 = var >> 8;
+ UI8 b8 = var;
+
+ this->output.put(b1);
+ this->output.put(b2);
+ this->output.put(b3);
+ this->output.put(b4);
+ this->output.put(b5);
+ this->output.put(b6);
+ this->output.put(b7);
+ this->output.put(b8);
+}
+
+void
+BinaryWriter::write_i8(I8 var)
+{
+ this->write_ui8(std::bit_cast<UI8>(var));
+}
+
+void
+BinaryWriter::write_i32(I32 var)
+{
+ this->write_ui32(std::bit_cast<UI32>(var));
+}
+
+void
+BinaryWriter::write_i64(I64 var)
+{
+ this->write_ui64(std::bit_cast<UI64>(var));
+}
+
+void
+BinaryWriter::write_f32(F32 var)
+{
+ IntAndFloat32bit num;
+ num.f = var;
+ write_ui32(num.i);
+}
+
+void
+BinaryWriter::write_f64(F64 var)
+{
+ IntAndFloat64bit num;
+ num.f = var;
+ write_ui64(num.i);
+}
+
+void
+BinaryWriter::write_vec2(glm::vec2 var)
+{
+ IntAndFloat32bit x, y;
+ x.f = var.x;
+ y.f = var.y;
+
+ this->write_ui32(x.i);
+ this->write_ui32(y.i);
+}
+
+void
+BinaryWriter::write_vec3(glm::vec3 var)
+{
+ IntAndFloat32bit x, y, z;
+ x.f = var.x;
+ y.f = var.y;
+ z.f = var.z;
+
+ this->write_ui32(x.i);
+ this->write_ui32(y.i);
+ this->write_ui32(z.i);
+}
+
+void
+BinaryWriter::write_quat(glm::quat var)
+{
+ IntAndFloat32bit w, x, y, z;
+ w.f = var.w;
+ x.f = var.x;
+ y.f = var.y;
+ z.f = var.z;
+
+ this->write_ui32(w.i);
+ this->write_ui32(x.i);
+ this->write_ui32(y.i);
+ this->write_ui32(z.i);
+}
+
+void
+BinaryWriter::write_mat4(glm::mat4 var)
+{
+ float *offset_matrix_data{glm::value_ptr(var)};
+ IntAndFloat32bit num;
+
+ for(int i{0}; i < 16; i++)
+ {
+ num.f = offset_matrix_data[i];
+ this->write_ui32(num.i);
+ }
+}
+
+void
+BinaryWriter::write_chars(const char *str, int size)
+{
+ for(int i{0}; i < size; i++) this->write_ui8((UI8)str[i]);
+}
diff --git a/src/blu_cat/com/binary_writer.hpp b/src/blu_cat/com/binary_writer.hpp
new file mode 100644
index 0000000..76bccb3
--- /dev/null
+++ b/src/blu_cat/com/binary_writer.hpp
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ * 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_COM_BINARY_WRITER_H
+#define BLU_CAT_COM_BINARY_WRITER_H 1
+
+#include <fstream>
+#include <string>
+
+#include "numbers.hpp"
+
+class BinaryWriter
+{
+ std::ofstream output;
+
+public:
+
+ BinaryWriter(const std::string &file_path);
+ BinaryWriter(const char *file_path);
+
+ void
+ write_ui8(UI8 var);
+
+ void
+ write_ui32(UI32 var);
+
+ void
+ write_ui64(UI64 var);
+
+ void
+ write_i8(I8 var);
+
+ void
+ write_i32(I32 var);
+
+ void
+ write_i64(I64 var);
+
+ void
+ write_f32(F32 var);
+
+ void
+ write_f64(F64 var);
+
+ void
+ write_vec2(glm::vec2 var);
+
+ void
+ write_vec3(glm::vec3 var);
+
+ void
+ write_quat(glm::quat var);
+
+ void
+ write_mat4(glm::mat4 var);
+
+ void
+ write_chars(const char *str, int size);
+};
+
+#endif /* BLU_CAT_COM_BINARY_WRITER_H */
diff --git a/src/command.cpp b/src/blu_cat/com/command.cpp
index a1d3240..a1d3240 100644
--- a/src/command.cpp
+++ b/src/blu_cat/com/command.cpp
diff --git a/src/command.hpp b/src/blu_cat/com/command.hpp
index 47552a5..5079c58 100644
--- a/src/command.hpp
+++ b/src/blu_cat/com/command.hpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_COMMAND_CHAIN_H
-#define CANDY_GEAR_COMMAND_CHAIN_H 1
+#ifndef BLU_CAT_COM_COMMAND_CHAIN_H
+#define BLU_CAT_COM_COMMAND_CHAIN_H 1
#include <cstdint>
#include <initializer_list>
@@ -89,4 +89,4 @@ public:
};
-#endif /* CANDY_GEAR_COMMAND_CHAIN_H */
+#endif /* BLU_CAT_COM_COMMAND_CHAIN_H */
diff --git a/src/job_queue.cpp b/src/blu_cat/com/job_queue.cpp
index 49bf34f..beaf989 100644
--- a/src/job_queue.cpp
+++ b/src/blu_cat/com/job_queue.cpp
@@ -18,6 +18,9 @@
#include <chrono>
+namespace BluCat::COM
+{
+
JobQueue::JobQueue():
jobs{},
_stop{false}
@@ -59,3 +62,5 @@ JobQueue::pop()
return Job{nullptr};
}
}
+
+}
diff --git a/src/job_queue.hpp b/src/blu_cat/com/job_queue.hpp
index 2a7735b..856946d 100644
--- a/src/job_queue.hpp
+++ b/src/blu_cat/com/job_queue.hpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_JOB_QUEUE_H
-#define CANDY_GEAR_JOB_QUEUE_H 1
+#ifndef BLU_CAT_COM_JOB_QUEUE_H
+#define BLU_CAT_COM_JOB_QUEUE_H 1
#include <atomic>
#include <condition_variable>
@@ -23,6 +23,9 @@
#include <functional>
#include <mutex>
+namespace BluCat::COM
+{
+
class Worker;
typedef std::function<void(void)> Job;
@@ -49,4 +52,6 @@ public:
push(Job job);
};
-#endif /* CANDY_GEAR_JOB_QUEUE_H */
+}
+
+#endif /* BLU_CAT_COM_JOB_QUEUE_H */
diff --git a/src/blucat/core.hpp b/src/blu_cat/com/numbers.hpp
index 169e3bc..1fd3400 100644
--- a/src/blucat/core.hpp
+++ b/src/blu_cat/com/numbers.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,8 +14,11 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_CORE_H
-#define CANDY_GEAR_BLUCAT_CORE_H 1
+#ifndef BLU_CAT_COM_NUMBERS_H
+#define BLU_CAT_COM_NUMBERS_H 1
+
+#include <cstdint>
+#include <stdfloat>
// GLM uses some definitions to control their behavior, so you should not
// include it directly. Instead, use this header.
@@ -29,6 +32,35 @@
#include <glm/gtx/quaternion.hpp>
#include <glm/vec3.hpp>
-#include <vulkan/vulkan.h>
+// Signed int
+typedef int8_t I8;
+typedef int16_t I16;
+typedef int32_t I32;
+typedef int64_t I64;
+
+// Unsigned int
+typedef uint8_t UI8;
+typedef uint16_t UI16;
+typedef uint32_t UI32;
+typedef uint64_t UI64;
+
+// Fast signed int
+typedef int_fast8_t I8F;
+typedef int_fast16_t I16F;
+typedef int_fast32_t I32F;
+typedef int_fast64_t I64F;
+
+// Fast unsigned int
+typedef uint_fast8_t UI8F;
+typedef uint_fast16_t UI16F;
+typedef uint_fast32_t UI32F;
+typedef uint_fast64_t UI64F;
+
+// Floats
+typedef std::float32_t F32;
+typedef std::float64_t F64;
+
+constexpr UI32F SIZE_32_BIT{4};
+constexpr UI32F SIZE_64_BIT{8};
-#endif /* CANDY_GEAR_BLUCAT_CORE_H */
+#endif /* BLU_CAT_COM_NUMBERS_H */
diff --git a/src/worker.cpp b/src/blu_cat/com/worker.cpp
index bcf654e..847b571 100644
--- a/src/worker.cpp
+++ b/src/blu_cat/com/worker.cpp
@@ -18,6 +18,9 @@
#include <thread>
+namespace BluCat::COM
+{
+
Worker::Worker(JobQueue *job_queue):
job_queue{job_queue}
{
@@ -32,3 +35,5 @@ Worker::operator()()
if(job) job();
}
}
+
+}
diff --git a/src/worker.hpp b/src/blu_cat/com/worker.hpp
index 449e1b0..d74aa24 100644
--- a/src/worker.hpp
+++ b/src/blu_cat/com/worker.hpp
@@ -14,11 +14,14 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_WORKER_H
-#define CANDY_GEAR_WORKER_H 1
+#ifndef BLU_CAT_COM_WORKER_H
+#define BLU_CAT_COM_WORKER_H 1
#include "job_queue.hpp"
+namespace BluCat::COM
+{
+
class Worker
{
JobQueue *job_queue;
@@ -30,4 +33,6 @@ public:
operator()();
};
-#endif /* CANDY_GEAR_WORKER_H */
+}
+
+#endif /* BLU_CAT_COM_WORKER_H */
diff --git a/src/blucat/animation.cpp b/src/blu_cat/gra/animation.cpp
index b4daeef..dc2c281 100644
--- a/src/blucat/animation.cpp
+++ b/src/blu_cat/gra/animation.cpp
@@ -16,7 +16,7 @@
#include "animation.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
Bone::Bone(glm::mat4 offset_matrix):
diff --git a/src/blucat/animation.hpp b/src/blu_cat/gra/animation.hpp
index c789c5e..1275b48 100644
--- a/src/blucat/animation.hpp
+++ b/src/blu_cat/gra/animation.hpp
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_ANIMATION_H
-#define CANDY_GEAR_BLUCAT_ANIMATION_H 1
+#ifndef BLU_CAT_GRA_ANIMATION_H
+#define BLU_CAT_GRA_ANIMATION_H 1
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "animation/frame.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Bone
@@ -48,4 +48,4 @@ struct Animation
}
-#endif /* CANDY_GEAR_BLUCAT_ANIMATION_H */
+#endif /* BLU_CAT_GRA_ANIMATION_H */
diff --git a/src/blucat/animation/frame.hpp b/src/blu_cat/gra/animation/frame.hpp
index a1d5f39..b1ea913 100644
--- a/src/blucat/animation/frame.hpp
+++ b/src/blu_cat/gra/animation/frame.hpp
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_FRAME_H
-#define CANDY_GEAR_BLUCAT_FRAME_H 1
+#ifndef BLU_CAT_GRA_FRAME_H
+#define BLU_CAT_GRA_FRAME_H 1
#include <vector>
-#include "../core.hpp"
+#include "../vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
template<typename T>
@@ -82,4 +82,4 @@ struct Channel
};
}
-#endif /* CANDY_GEAR_BLUCAT_FRAME_H */
+#endif /* BLU_CAT_GRA_FRAME_H */
diff --git a/src/blucat/base_buffer.cpp b/src/blu_cat/gra/base_buffer.cpp
index 762c89a..1add9fb 100644
--- a/src/blucat/base_buffer.cpp
+++ b/src/blu_cat/gra/base_buffer.cpp
@@ -16,7 +16,7 @@
#include "base_buffer.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
const CommandChain BaseBuffer::loader{
diff --git a/src/blucat/base_buffer.hpp b/src/blu_cat/gra/base_buffer.hpp
index 03b838c..cb4cdf8 100644
--- a/src/blucat/base_buffer.hpp
+++ b/src/blu_cat/gra/base_buffer.hpp
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_BASE_BUFFER_H
-#define CANDY_GEAR_BLUCAT_BASE_BUFFER_H 1
+#ifndef BLU_CAT_GRA_BASE_BUFFER_H
+#define BLU_CAT_GRA_BASE_BUFFER_H 1
-#include "../command.hpp"
-#include "core.hpp"
+#include "../com/command.hpp"
+#include "vulkan.hpp"
#include "device.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
class BaseBuffer
@@ -53,4 +53,4 @@ class BaseBuffer
}
-#endif /* CANDY_GEAR_BLUCAT_BASE_BUFFER_H */
+#endif /* BLU_CAT_GRA_BASE_BUFFER_H */
diff --git a/src/blucat/character.cpp b/src/blu_cat/gra/character.cpp
index c13ffef..f0e7512 100644
--- a/src/blucat/character.cpp
+++ b/src/blu_cat/gra/character.cpp
@@ -16,8 +16,8 @@
#include "character.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "../com/command.hpp"
+#include "../int/core.hpp"
#include "font.hpp"
#include "image.hpp"
#include "source_buffer.hpp"
@@ -27,16 +27,16 @@ namespace
struct CharacterBuilder
{
- BluCat::Character *character;
+ BluCat::GRA::Character *character;
FT_Face face;
uint32_t character_code;
CharacterBuilder(
- BluCat::Character *character, FT_Face face, uint32_t character_code);
+ BluCat::GRA::Character *character, FT_Face face, uint32_t character_code);
};
CharacterBuilder::CharacterBuilder(
- BluCat::Character *character, FT_Face face, uint32_t character_code):
+ BluCat::GRA::Character *character, FT_Face face, uint32_t character_code):
character{character},
face{face},
character_code{character_code}
@@ -104,8 +104,8 @@ load_image(void *obj)
}
}
- BluCat::SourceBuffer source_image_buffer{
- cg_core.vk_device_with_swapchain, source_image_raw.data(),
+ BluCat::GRA::SourceBuffer source_image_buffer{
+ BluCat::INT::core.vk_device_with_swapchain, source_image_raw.data(),
image_size};
{ // Create Vulkan image.
@@ -116,8 +116,8 @@ load_image(void *obj)
vk_extent3d.height = self->face->glyph->bitmap.rows;
vk_extent3d.depth = 1;
- BluCat::Image::create(
- cg_core.vk_device_with_swapchain,
+ BluCat::GRA::Image::create(
+ BluCat::INT::core.vk_device_with_swapchain,
&self->character->image,
&self->character->device_memory,
VK_FORMAT_R8G8B8A8_UNORM,
@@ -126,21 +126,21 @@ load_image(void *obj)
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
}
- catch(BluCat::Image::Error error)
+ catch(BluCat::GRA::Image::Error error)
{
throw CommandError{error.what()};
}
}
{ // Copy image from buffer into image.
- auto queue_family{cg_core.vk_device_with_swapchain->
+ auto queue_family{BluCat::INT::core.vk_device_with_swapchain->
get_queue_family_with_presentation()};
auto queue{queue_family->get_queue()};
- BluCat::CommandPool command_pool{queue_family, 1};
+ BluCat::GRA::CommandPool command_pool{queue_family, 1};
VkCommandBuffer vk_command_buffer{command_pool.command_buffers[0]};
queue.submit_one_time_command(vk_command_buffer, [&](){
- BluCat::Image::move_image_state(
+ BluCat::GRA::Image::move_image_state(
vk_command_buffer, self->character->image, VK_FORMAT_R8G8B8A8_UNORM,
0, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_HOST_BIT,
@@ -162,7 +162,7 @@ load_image(void *obj)
vk_command_buffer, source_image_buffer.buffer, self->character->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy);
- BluCat::Image::move_image_state(
+ BluCat::GRA::Image::move_image_state(
vk_command_buffer, self->character->image, VK_FORMAT_R8G8B8A8_UNORM,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -179,10 +179,11 @@ unload_image(void *obj)
auto self = static_cast<CharacterBuilder*>(obj);
vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->character->image, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->character->image,
+ nullptr);
vkFreeMemory(
- cg_core.vk_device_with_swapchain->device, self->character->device_memory,
- nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device,
+ self->character->device_memory, nullptr);
}
const CommandChain loader{
@@ -191,7 +192,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
Character::Character(FT_Face face, uint32_t character_code)
diff --git a/src/blucat/character.hpp b/src/blu_cat/gra/character.hpp
index 43cc765..8968384 100644
--- a/src/blucat/character.hpp
+++ b/src/blu_cat/gra/character.hpp
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_CHARACTER_H
-#define CANDY_GEAR_BLUCAT_CHARACTER_H 1
+#ifndef BLU_CAT_GRA_CHARACTER_H
+#define BLU_CAT_GRA_CHARACTER_H 1
#include <ft2build.h>
#include FT_FREETYPE_H
-#include "core.hpp"
+#include "vulkan.hpp"
#include <vector>
-namespace BluCat
+namespace BluCat::GRA
{
struct Character
@@ -46,4 +46,4 @@ struct Character
}
-#endif /* CANDY_GEAR_BLUCAT_CHARACTER_H */
+#endif /* BLU_CAT_GRA_CHARACTER_H */
diff --git a/src/blucat/command_pool.cpp b/src/blu_cat/gra/command_pool.cpp
index 898d7ae..2602522 100644
--- a/src/blucat/command_pool.cpp
+++ b/src/blu_cat/gra/command_pool.cpp
@@ -16,7 +16,7 @@
#include "command_pool.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
const CommandChain CommandPool::loader{
diff --git a/src/blucat/command_pool.hpp b/src/blu_cat/gra/command_pool.hpp
index aa23387..7487365 100644
--- a/src/blucat/command_pool.hpp
+++ b/src/blu_cat/gra/command_pool.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_COMMAND_POOL_H
-#define CANDY_GEAR_BLUCAT_COMMAND_POOL_H 1
+#ifndef BLU_CAT_GRA_COMMAND_POOL_H
+#define BLU_CAT_GRA_COMMAND_POOL_H 1
#include <vector>
-#include "../command.hpp"
-#include "core.hpp"
+#include "../com/command.hpp"
#include "device.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
class CommandPool
@@ -56,4 +56,4 @@ private:
}
-#endif /* CANDY_GEAR_BLUCAT_COMMAND_POOL_H */
+#endif /* BLU_CAT_GRA_COMMAND_POOL_H */
diff --git a/src/blucat/descriptor_set_layout.cpp b/src/blu_cat/gra/descriptor_set_layout.cpp
index 0fc5208..e1e8852 100644
--- a/src/blucat/descriptor_set_layout.cpp
+++ b/src/blu_cat/gra/descriptor_set_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
namespace
{
@@ -26,7 +26,7 @@ namespace
void
load_world(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
std::array<VkDescriptorSetLayoutBinding, 2> set_layouts{};
set_layouts[0].binding = 0;
@@ -49,7 +49,7 @@ load_world(void *obj)
layout_info.pBindings = set_layouts.data();
if(vkCreateDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, &layout_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &layout_info, nullptr,
&self->world) != VK_SUCCESS)
throw CommandError{
"Failed to create Vulkan descriptor set layout for world view."};
@@ -58,16 +58,16 @@ load_world(void *obj)
void
unload_world(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->world, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->world, nullptr);
}
void
load_view(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
std::array<VkDescriptorSetLayoutBinding, 1> layout_bindings{};
@@ -85,7 +85,7 @@ load_view(void *obj)
layout_info.pBindings = layout_bindings.data();
if(vkCreateDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, &layout_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &layout_info, nullptr,
&self->view) != VK_SUCCESS)
throw CommandError{
"Failed to create Vulkan descriptor set layout for view."};
@@ -94,16 +94,16 @@ load_view(void *obj)
void
unload_view(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->view, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->view, nullptr);
}
void
load_texture(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
std::array<VkDescriptorSetLayoutBinding, 1> layout_bindings{};
@@ -122,7 +122,7 @@ load_texture(void *obj)
layout_info.pBindings = layout_bindings.data();
if(vkCreateDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, &layout_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &layout_info, nullptr,
&self->texture) != VK_SUCCESS)
throw CommandError{
"Failed to create Vulkan descriptor set layout for textures."};
@@ -131,16 +131,16 @@ load_texture(void *obj)
void
unload_texture(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->texture, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->texture, nullptr);
}
void
load_model(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
std::array<VkDescriptorSetLayoutBinding, 1> layout_bindings;
layout_bindings[0].binding = 0;
@@ -157,7 +157,7 @@ load_model(void *obj)
layout_info.pBindings = layout_bindings.data();
if(vkCreateDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, &layout_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &layout_info, nullptr,
&self->model) != VK_SUCCESS)
throw CommandError{
"Failed to create Vulkan descriptor set layout for model instance."};
@@ -166,10 +166,10 @@ load_model(void *obj)
void
unload_model(void *obj)
{
- auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->model, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->model, nullptr);
}
const CommandChain loader{
@@ -181,7 +181,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
DescriptorSetLayout::DescriptorSetLayout()
diff --git a/src/blucat/descriptor_set_layout.hpp b/src/blu_cat/gra/descriptor_set_layout.hpp
index 144a137..42003b9 100644
--- a/src/blucat/descriptor_set_layout.hpp
+++ b/src/blu_cat/gra/descriptor_set_layout.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_DESCRIPTOR_SET_LAYOUT_H
-#define CANDY_GEAR_BLUCAT_DESCRIPTOR_SET_LAYOUT_H 1
+#ifndef BLU_CAT_GRA_DESCRIPTOR_SET_LAYOUT_H
+#define BLU_CAT_GRA_DESCRIPTOR_SET_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct DescriptorSetLayout
@@ -35,4 +35,4 @@ struct DescriptorSetLayout
}
-#endif /* CANDY_GEAR_BLUCAT_DESCRIPTOR_SET_LAYOUT_H */
+#endif /* BLU_CAT_GRA_DESCRIPTOR_SET_LAYOUT_H */
diff --git a/src/blucat/destination_buffer.cpp b/src/blu_cat/gra/destination_buffer.cpp
index ea5f31e..3c53db4 100644
--- a/src/blucat/destination_buffer.cpp
+++ b/src/blu_cat/gra/destination_buffer.cpp
@@ -18,7 +18,7 @@
#include "command_pool.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
DestinationBuffer::DestinationBuffer(
diff --git a/src/blucat/destination_buffer.hpp b/src/blu_cat/gra/destination_buffer.hpp
index 8c098ab..7df1e50 100644
--- a/src/blucat/destination_buffer.hpp
+++ b/src/blu_cat/gra/destination_buffer.hpp
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_DESTINATION_BUFFER_H
-#define CANDY_GEAR_BLUCAT_DESTINATION_BUFFER_H 1
+#ifndef BLU_CAT_GRA_DESTINATION_BUFFER_H
+#define BLU_CAT_GRA_DESTINATION_BUFFER_H 1
#include "base_buffer.hpp"
-#include "core.hpp"
+#include "vulkan.hpp"
#include "source_buffer.hpp"
#include "queue_family.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct DestinationBuffer: public BaseBuffer
@@ -51,4 +51,4 @@ struct DestinationBuffer: public BaseBuffer
}
-#endif /* CANDY_GEAR_BLUCAT_DESTINATION_BUFFER_H */
+#endif /* BLU_CAT_GRA_DESTINATION_BUFFER_H */
diff --git a/src/blucat/device.cpp b/src/blu_cat/gra/device.cpp
index cf21fa4..b2d114a 100644
--- a/src/blucat/device.cpp
+++ b/src/blu_cat/gra/device.cpp
@@ -23,7 +23,7 @@
#include <sstream>
#endif
-#include "../core.hpp"
+#include "../int/core.hpp"
namespace
{
@@ -61,7 +61,7 @@ create_shader_module(VkDevice vk_device, const char *filename)
}
}
-namespace BluCat
+namespace BluCat::GRA
{
Device::Device(VkPhysicalDevice vk_physical_device, bool with_swapchain)
@@ -98,7 +98,7 @@ Device::Device(VkPhysicalDevice vk_physical_device, bool with_swapchain)
message << "Device ID: " << physical_properties.deviceID << std::endl;
message << "Device type: " << physical_properties.deviceType <<
std::endl;
- cg_core.log.message(Log::Level::Trace, message.str());
+ BluCat::INT::core.log.message(Log::Level::Trace, message.str());
#endif
std::vector<VkDeviceQueueCreateInfo> device_queue_create_infos;
@@ -300,7 +300,8 @@ Device::Device(VkPhysicalDevice vk_physical_device, bool with_swapchain)
// Select families with presentation support.
VkBool32 present_supported;
vkGetPhysicalDeviceSurfaceSupportKHR(
- vk_physical_device, i, cg_core.window_surface, &present_supported);
+ vk_physical_device, i, BluCat::INT::core.window_surface,
+ &present_supported);
if(present_supported)
this->queue_families_with_presentation.push_back(
&this->queue_families[i]);
@@ -371,7 +372,7 @@ Device::get_queue_family_with_graphics() const
*/
std::uniform_int_distribution<std::size_t> random_distribution{
0, this->queue_families_with_graphics.size() -1};
- auto random = random_distribution(random_number_generator);
+ auto random = random_distribution(INT::random_number_generator);
return this->queue_families_with_graphics[0];
}
@@ -385,7 +386,7 @@ Device::get_queue_family_with_presentation() const
*/
std::uniform_int_distribution<std::size_t> random_distribution{
0, this->queue_families_with_presentation.size() -1};
- auto random = random_distribution(random_number_generator);
+ auto random = random_distribution(INT::random_number_generator);
return this->queue_families_with_presentation[0];
}
diff --git a/src/blucat/device.hpp b/src/blu_cat/gra/device.hpp
index bcfca4d..fd53198 100644
--- a/src/blucat/device.hpp
+++ b/src/blu_cat/gra/device.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_DEVICE_H
-#define CANDY_GEAR_BLUCAT_DEVICE_H 1
+#ifndef BLU_CAT_GRA_DEVICE_H
+#define BLU_CAT_GRA_DEVICE_H 1
#include <cstdlib>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "queue_family.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Device
@@ -66,4 +66,4 @@ public:
}
-#endif /* CANDY_GEAR_BLUCAT_DEVICE_H */
+#endif /* BLU_CAT_GRA_DEVICE_H */
diff --git a/src/blucat/font.cpp b/src/blu_cat/gra/font.cpp
index 4195b57..a9c2074 100644
--- a/src/blucat/font.cpp
+++ b/src/blu_cat/gra/font.cpp
@@ -16,15 +16,16 @@
#include "font.hpp"
-#include "../core.hpp"
+#include "../int/core.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
Font::Font(const char* font_path, int font_size)
{
FT_Error error;
- error = FT_New_Face(cg_core.font_library, font_path, 0, &this->face);
+ error = FT_New_Face(
+ BluCat::INT::core.font_library, font_path, 0, &this->face);
if(error == FT_Err_Unknown_File_Format) throw std::invalid_argument(
"The font file could be opened and read, but it appears that its font "
"format is unsupported.");
diff --git a/src/blucat/font.hpp b/src/blu_cat/gra/font.hpp
index 1b9be69..72ec6d3 100644
--- a/src/blucat/font.hpp
+++ b/src/blu_cat/gra/font.hpp
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_FONT_H
-#define CANDY_GEAR_BLUCAT_FONT_H 1
+#ifndef BLU_CAT_GRA_FONT_H
+#define BLU_CAT_GRA_FONT_H 1
#include <memory>
#include <unordered_map>
#include "character.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Font
@@ -39,4 +39,4 @@ struct Font
}
-#endif /* CANDY_GEAR_BLUCAT_FONT_H */
+#endif /* BLU_CAT_GRA_FONT_H */
diff --git a/src/blucat/framebuffer.cpp b/src/blu_cat/gra/framebuffer.cpp
index e761ff2..e2d0b7c 100644
--- a/src/blucat/framebuffer.cpp
+++ b/src/blu_cat/gra/framebuffer.cpp
@@ -16,7 +16,8 @@
#include "framebuffer.hpp"
-#include "../core.hpp"
+#include "../com/command.hpp"
+#include "../int/core.hpp"
#include "image.hpp"
namespace
@@ -24,17 +25,17 @@ namespace
void
load_depth_image(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
VkExtent3D extent3d{};
- extent3d.width = cg_core.display_width;
- extent3d.height = cg_core.display_height;
+ extent3d.width = BluCat::INT::core.display_width;
+ extent3d.height = BluCat::INT::core.display_height;
extent3d.depth = 1;
try
{
- BluCat::Image::create(
- cg_core.vk_device_with_swapchain,
+ BluCat::GRA::Image::create(
+ BluCat::INT::core.vk_device_with_swapchain,
&self->depth_image,
&self->depth_image_memory,
VK_FORMAT_D32_SFLOAT,
@@ -44,7 +45,7 @@ load_depth_image(void *obj)
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
);
}
- catch(BluCat::Image::Error error)
+ catch(BluCat::GRA::Image::Error error)
{
std::string error_message{"Failed to create depth image → "};
error_message += error.what();
@@ -55,29 +56,29 @@ load_depth_image(void *obj)
void
unload_depth_image(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->depth_image,
+ BluCat::INT::core.vk_device_with_swapchain->device, self->depth_image,
nullptr);
vkFreeMemory(
- cg_core.vk_device_with_swapchain->device,
+ BluCat::INT::core.vk_device_with_swapchain->device,
self->depth_image_memory, nullptr);
}
void
load_depth_image_view(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
try
{
- BluCat::Image::create_view(
- cg_core.vk_device_with_swapchain, &self->depth_image_view,
+ BluCat::GRA::Image::create_view(
+ BluCat::INT::core.vk_device_with_swapchain, &self->depth_image_view,
self->depth_image,
VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_DEPTH_BIT);
}
- catch(BluCat::Image::Error error)
+ catch(BluCat::GRA::Image::Error error)
{
std::string error_message{"Failed to create depth image view → "};
error_message += error.what();
@@ -88,37 +89,38 @@ load_depth_image_view(void *obj)
void
unload_depth_image_view(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->depth_image_view, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->depth_image_view,
+ nullptr);
}
void
load_3d(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
- self->pipeline_3d.resize(cg_core.vk_swapchain->images_count);
- for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->pipeline_3d.resize(BluCat::INT::core.vk_swapchain->images_count);
+ for (auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
{
std::array<VkImageView, 2> attachments = {
- cg_core.vk_swapchain->image_views[i],
+ BluCat::INT::core.vk_swapchain->image_views[i],
self->depth_image_view
};
VkFramebufferCreateInfo framebuffer_info{};
framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ framebuffer_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_3d;
framebuffer_info.attachmentCount = attachments.size();
framebuffer_info.pAttachments = attachments.data();
- framebuffer_info.width = cg_core.display_width;
- framebuffer_info.height = cg_core.display_height;
+ framebuffer_info.width = BluCat::INT::core.display_width;
+ framebuffer_info.height = BluCat::INT::core.display_height;
framebuffer_info.layers = 1;
if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
&self->pipeline_3d[i]) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Framebuffer."};
}
@@ -127,37 +129,37 @@ load_3d(void *obj)
void
unload_3d(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
for(auto framebuffer: self->pipeline_3d)
vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, framebuffer, nullptr);
}
void
load_2d(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
- self->pipeline_2d.resize(cg_core.vk_swapchain->images_count);
- for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->pipeline_2d.resize(BluCat::INT::core.vk_swapchain->images_count);
+ for (auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
{
std::array<VkImageView, 1> attachments = {
- cg_core.vk_swapchain->image_views[i]
+ BluCat::INT::core.vk_swapchain->image_views[i]
};
VkFramebufferCreateInfo framebuffer_info{};
framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_2d;
+ framebuffer_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_2d;
framebuffer_info.attachmentCount = attachments.size();
framebuffer_info.pAttachments = attachments.data();
- framebuffer_info.width = cg_core.display_width;
- framebuffer_info.height = cg_core.display_height;
+ framebuffer_info.width = BluCat::INT::core.display_width;
+ framebuffer_info.height = BluCat::INT::core.display_height;
framebuffer_info.layers = 1;
if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
- &self->pipeline_2d[i])
+ BluCat::INT::core.vk_device_with_swapchain->device, &framebuffer_info,
+ nullptr, &self->pipeline_2d[i])
!= VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Framebuffer."};
}
@@ -166,11 +168,11 @@ load_2d(void *obj)
void
unload_2d(void *obj)
{
- auto self = static_cast<BluCat::Framebuffer*>(obj);
+ auto self = static_cast<BluCat::GRA::Framebuffer*>(obj);
for(auto framebuffer: self->pipeline_2d)
vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, framebuffer, nullptr);
}
const CommandChain loader{
@@ -182,7 +184,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
Framebuffer::Framebuffer()
diff --git a/src/blucat/framebuffer.hpp b/src/blu_cat/gra/framebuffer.hpp
index 32968a6..ddbf5c4 100644
--- a/src/blucat/framebuffer.hpp
+++ b/src/blu_cat/gra/framebuffer.hpp
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_FRAMEBUFFER_H
-#define CANDY_GEAR_BLUCAT_FRAMEBUFFER_H 1
+#ifndef BLU_CAT_GRA_FRAMEBUFFER_H
+#define BLU_CAT_GRA_FRAMEBUFFER_H 1
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Framebuffer
@@ -40,4 +40,4 @@ struct Framebuffer
}
-#endif /* CANDY_GEAR_BLUCAT_FRAMEBUFFER_H */
+#endif /* BLU_CAT_GRA_FRAMEBUFFER_H */
diff --git a/src/blucat/graphics_pipeline_2d_solid.cpp b/src/blu_cat/gra/graphics_pipeline_2d_solid.cpp
index 28b19b6..05dcbe1 100644
--- a/src/blucat/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.
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -28,7 +28,7 @@ namespace
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DSolid*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DSolid*>(obj);
VkPipelineShaderStageCreateInfo vert_shader_stage_info{};
vert_shader_stage_info.sType =
@@ -37,7 +37,7 @@ load_pipeline(void *obj)
vert_shader_stage_info.flags = 0;
vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vert_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->vert2d_solid_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->vert2d_solid_shader_module;
vert_shader_stage_info.pName = "main";
vert_shader_stage_info.pSpecializationInfo = nullptr;
@@ -48,7 +48,7 @@ load_pipeline(void *obj)
frag_shader_stage_info.flags = 0;
frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
frag_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->frag2d_solid_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->frag2d_solid_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -91,14 +91,14 @@ load_pipeline(void *obj)
VkViewport viewport = {};
viewport.x = 0;
viewport.y = 0;
- viewport.width = cg_core.display_width;
- viewport.height = cg_core.display_height;
+ viewport.width = BluCat::INT::core.display_width;
+ viewport.height = BluCat::INT::core.display_height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor = {};
scissor.offset = {0, 0};
- scissor.extent = {cg_core.display_width, cg_core.display_height};
+ scissor.extent = {BluCat::INT::core.display_width, BluCat::INT::core.display_height};
VkPipelineViewportStateCreateInfo viewport_state = {};
viewport_state.sType =
@@ -191,14 +191,14 @@ load_pipeline(void *obj)
pipeline_info.pColorBlendState = &color_blending;
pipeline_info.pDynamicState = &dynamic_state_info;
pipeline_info.layout =
- cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline;
- pipeline_info.renderPass = cg_core.vk_render_pass->pipeline_2d;
+ BluCat::INT::core.vk_graphics_pipeline_2d_solid_layout->pipeline;
+ pipeline_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_2d;
pipeline_info.subpass = 0;
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
pipeline_info.basePipelineIndex = -1;
if(vkCreateGraphicsPipelines(
- cg_core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
+ BluCat::INT::core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
&pipeline_info, nullptr, &self->graphic_pipeline)
!= VK_SUCCESS)
throw CommandError{"Failed to create graphics pipeline."};
@@ -207,10 +207,11 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DSolid*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DSolid*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -219,7 +220,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline2DSolid::GraphicsPipeline2DSolid()
@@ -234,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);
}
@@ -263,20 +263,23 @@ 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};
vkCmdBindDescriptorSets(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline, 0,
+ INT::core.vk_graphics_pipeline_2d_solid_layout->pipeline, 0,
vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
vkCmdBindVertexBuffers(
draw_command_buffer, 0, 1, &sprite_to_draw.sprite->vertex_buffer->buffer,
@@ -285,13 +288,13 @@ GraphicsPipeline2DSolid::draw(
UDOVector4D position{sprite_to_draw.position};
vkCmdPushConstants(
draw_command_buffer,
- cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline,
+ INT::core.vk_graphics_pipeline_2d_solid_layout->pipeline,
VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(UDOVector4D), &position);
vkCmdDraw(draw_command_buffer, Sprite::vertex_count, 1, 0, 0);
}
// 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/blucat/graphics_pipeline_2d_solid.hpp b/src/blu_cat/gra/graphics_pipeline_2d_solid.hpp
index eae54ae..c2d85d5 100644
--- a/src/blucat/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.
@@ -14,16 +14,15 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_SOLID_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_SOLID_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_SOLID_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_SOLID_H 1
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
-#include "view_2d.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline2DSolid
@@ -34,11 +33,10 @@ 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);
};
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_SOLID_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_SOLID_H */
diff --git a/src/blucat/graphics_pipeline_2d_solid_layout.cpp b/src/blu_cat/gra/graphics_pipeline_2d_solid_layout.cpp
index 7b537a2..476bac1 100644
--- a/src/blucat/graphics_pipeline_2d_solid_layout.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_solid_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -27,17 +27,17 @@ namespace
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DSolidLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DSolidLayout*>(obj);
std::array<VkDescriptorSetLayout, 2> set_layouts{
- cg_core.vk_descriptor_set_layout->view,
- cg_core.vk_descriptor_set_layout->texture
+ BluCat::INT::core.vk_descriptor_set_layout->view,
+ BluCat::INT::core.vk_descriptor_set_layout->texture
};
std::array<VkPushConstantRange, 1> push_constants;
push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
push_constants[0].offset = 0;
- push_constants[0].size = sizeof(BluCat::UDOVector4D);
+ push_constants[0].size = sizeof(BluCat::GRA::UDOVector4D);
VkPipelineLayoutCreateInfo pipeline_layout_info{};
pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
@@ -47,7 +47,7 @@ load_pipeline(void *obj)
pipeline_layout_info.pPushConstantRanges = push_constants.data();
if(vkCreatePipelineLayout(
- cg_core.vk_device_with_swapchain->device, &pipeline_layout_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &pipeline_layout_info,
nullptr, &self->pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan pipeline layout."};
}
@@ -55,10 +55,10 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DSolidLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DSolidLayout*>(obj);
vkDestroyPipelineLayout(
- cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}
const CommandChain loader{
@@ -67,7 +67,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline2DSolidLayout::GraphicsPipeline2DSolidLayout()
diff --git a/src/blucat/graphics_pipeline_2d_solid_layout.hpp b/src/blu_cat/gra/graphics_pipeline_2d_solid_layout.hpp
index 77172be..6abd65d 100644
--- a/src/blucat/graphics_pipeline_2d_solid_layout.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_solid_layout.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_LAYOUT_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_LAYOUT_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_LAYOUT_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline2DSolidLayout
@@ -32,4 +32,4 @@ struct GraphicsPipeline2DSolidLayout
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_LAYOUT_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_LAYOUT_H */
diff --git a/src/blucat/graphics_pipeline_2d_wired.cpp b/src/blu_cat/gra/graphics_pipeline_2d_wired.cpp
index 192a9d6..1273c67 100644
--- a/src/blucat/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.
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "rectangle.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -29,17 +29,17 @@ namespace
void
load_indexes(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DWired*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DWired*>(obj);
self->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::INT::core.vk_device_with_swapchain->get_queue_family_with_graphics();
std::array<uint32_t, 4> indexes{0, 1, 2, 3};
void *indexes_data{indexes.data()};
size_t indexes_size{sizeof(indexes[0]) * indexes.size()};
- BluCat::SourceBuffer source_index_buffer{
+ BluCat::GRA::SourceBuffer source_index_buffer{
self->queue_family->device, indexes_data, indexes_size};
- self->index_buffer = new BluCat::DestinationBuffer{
+ self->index_buffer = new BluCat::GRA::DestinationBuffer{
self->queue_family, &source_index_buffer,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT};
}
@@ -47,7 +47,7 @@ load_indexes(void *obj)
void
unload_indexes(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DWired*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DWired*>(obj);
delete self->index_buffer;
}
@@ -55,7 +55,7 @@ unload_indexes(void *obj)
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DWired*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DWired*>(obj);
VkPipelineShaderStageCreateInfo vert_shader_stage_info{};
vert_shader_stage_info.sType =
@@ -64,7 +64,7 @@ load_pipeline(void *obj)
vert_shader_stage_info.flags = 0;
vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vert_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->vert2d_wired_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->vert2d_wired_shader_module;
vert_shader_stage_info.pName = "main";
vert_shader_stage_info.pSpecializationInfo = nullptr;
@@ -75,7 +75,7 @@ load_pipeline(void *obj)
frag_shader_stage_info.flags = 0;
frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
frag_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->frag2d_wired_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->frag2d_wired_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -105,14 +105,14 @@ load_pipeline(void *obj)
VkViewport viewport = {};
viewport.x = 0;
viewport.y = 0;
- viewport.width = cg_core.display_width;
- viewport.height = cg_core.display_height;
+ viewport.width = BluCat::INT::core.display_width;
+ viewport.height = BluCat::INT::core.display_height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor = {};
scissor.offset = {0, 0};
- scissor.extent = {cg_core.display_width, cg_core.display_height};
+ scissor.extent = {BluCat::INT::core.display_width, BluCat::INT::core.display_height};
VkPipelineViewportStateCreateInfo viewport_state = {};
viewport_state.sType =
@@ -203,14 +203,14 @@ load_pipeline(void *obj)
pipeline_info.pColorBlendState = &color_blending;
pipeline_info.pDynamicState = &dynamic_state_info;
pipeline_info.layout =
- cg_core.vk_graphics_pipeline_2d_wired_layout->pipeline;
- pipeline_info.renderPass = cg_core.vk_render_pass->pipeline_2d;
+ BluCat::INT::core.vk_graphics_pipeline_2d_wired_layout->pipeline;
+ pipeline_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_2d;
pipeline_info.subpass = 0;
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
pipeline_info.basePipelineIndex = -1;
if(vkCreateGraphicsPipelines(
- cg_core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
+ BluCat::INT::core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
&pipeline_info, nullptr, &self->graphic_pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create graphics pipeline."};
}
@@ -218,10 +218,11 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DWired*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DWired*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -231,7 +232,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline2DWired::GraphicsPipeline2DWired()
@@ -246,38 +247,37 @@ 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(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_2d_wired_layout->pipeline, 0,
+ INT::core.vk_graphics_pipeline_2d_wired_layout->pipeline, 0,
vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
vkCmdBindPipeline(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -286,19 +286,21 @@ 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};
vkCmdPushConstants(
draw_command_buffer,
- cg_core.vk_graphics_pipeline_2d_wired_layout->pipeline,
+ INT::core.vk_graphics_pipeline_2d_wired_layout->pipeline,
VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(UDOVector4D), &position);
vkCmdPushConstants(
draw_command_buffer,
- cg_core.vk_graphics_pipeline_2d_wired_layout->pipeline,
+ INT::core.vk_graphics_pipeline_2d_wired_layout->pipeline,
VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(UDOVector4D), sizeof(UDOVector3D),
&color);
vkCmdDrawIndexed(
@@ -307,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/blucat/graphics_pipeline_2d_wired.hpp b/src/blu_cat/gra/graphics_pipeline_2d_wired.hpp
index 32d965b..9fc46c4 100644
--- a/src/blucat/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.
@@ -14,15 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_WIRED_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_WIRED_H 1
#include <memory>
-#include "core.hpp"
-#include "view_2d.hpp"
+#include "vulkan.hpp"
+#include "command_pool.hpp"
+#include "destination_buffer.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline2DWired
@@ -37,11 +38,10 @@ 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);
};
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_WIRED_H */
diff --git a/src/blucat/graphics_pipeline_2d_wired_layout.cpp b/src/blu_cat/gra/graphics_pipeline_2d_wired_layout.cpp
index eaa6af7..431a845 100644
--- a/src/blucat/graphics_pipeline_2d_wired_layout.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_wired_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "graphics_pipeline_2d_solid_layout.hpp"
#include "uniform_data_object.hpp"
@@ -28,20 +28,20 @@ namespace
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DWiredLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DWiredLayout*>(obj);
std::array<VkDescriptorSetLayout, 1> set_layouts{
- cg_core.vk_descriptor_set_layout->view
+ BluCat::INT::core.vk_descriptor_set_layout->view
};
std::array<VkPushConstantRange, 2> push_constants;
push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
push_constants[0].offset = 0;
- push_constants[0].size = sizeof(BluCat::UDOVector4D);
+ push_constants[0].size = sizeof(BluCat::GRA::UDOVector4D);
push_constants[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
- push_constants[1].offset = sizeof(BluCat::UDOVector4D);
- push_constants[1].size = sizeof(BluCat::UDOVector3D);
+ push_constants[1].offset = sizeof(BluCat::GRA::UDOVector4D);
+ push_constants[1].size = sizeof(BluCat::GRA::UDOVector3D);
VkPipelineLayoutCreateInfo pipeline_layout_info{};
pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
@@ -51,7 +51,7 @@ load_pipeline(void *obj)
pipeline_layout_info.pPushConstantRanges = push_constants.data();
if(vkCreatePipelineLayout(
- cg_core.vk_device_with_swapchain->device, &pipeline_layout_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &pipeline_layout_info,
nullptr, &self->pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan pipeline layout."};
}
@@ -59,10 +59,10 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline2DWiredLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline2DWiredLayout*>(obj);
vkDestroyPipelineLayout(
- cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}
const CommandChain loader{
@@ -71,7 +71,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline2DWiredLayout::GraphicsPipeline2DWiredLayout()
diff --git a/src/blucat/graphics_pipeline_2d_wired_layout.hpp b/src/blu_cat/gra/graphics_pipeline_2d_wired_layout.hpp
index d447230..16f23ea 100644
--- a/src/blucat/graphics_pipeline_2d_wired_layout.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_2d_wired_layout.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_LAYOUT_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_LAYOUT_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_WIRED_LAYOUT_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_WIRED_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline2DWiredLayout
@@ -32,4 +32,4 @@ struct GraphicsPipeline2DWiredLayout
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_LAYOUT_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_2D_LAYOUT_H */
diff --git a/src/blucat/graphics_pipeline_3d.cpp b/src/blu_cat/gra/graphics_pipeline_3d.cpp
index c1b60a6..288e186 100644
--- a/src/blucat/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.
@@ -19,8 +19,8 @@
#include <array>
#include <stdexcept>
-#include "../core.hpp"
-#include "core.hpp"
+#include "../int/core.hpp"
+#include "vulkan.hpp"
#include "static_mesh_vertex.hpp"
#include "uniform_data_object.hpp"
@@ -30,7 +30,7 @@ namespace
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline3D*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline3D*>(obj);
VkPipelineShaderStageCreateInfo vert_shader_stage_info = {};
vert_shader_stage_info.sType =
@@ -39,7 +39,7 @@ load_pipeline(void *obj)
vert_shader_stage_info.flags = 0;
vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vert_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->vert3d_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->vert3d_shader_module;
vert_shader_stage_info.pName = "main";
vert_shader_stage_info.pSpecializationInfo = nullptr;
@@ -50,7 +50,7 @@ load_pipeline(void *obj)
frag_shader_stage_info.flags = 0;
frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
frag_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->frag3d_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->frag3d_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -61,7 +61,7 @@ load_pipeline(void *obj)
VkVertexInputBindingDescription vertex_input_binding{};
vertex_input_binding.binding = 0;
- vertex_input_binding.stride = sizeof(BluCat::StaticMeshVertex);
+ vertex_input_binding.stride = sizeof(BluCat::GRA::StaticMeshVertex);
vertex_input_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
std::array<VkVertexInputAttributeDescription, 3> vertex_attribute{};
@@ -69,17 +69,17 @@ load_pipeline(void *obj)
vertex_attribute[0].location = 0;
vertex_attribute[0].binding = 0;
vertex_attribute[0].format = VK_FORMAT_R32G32B32_SFLOAT;
- vertex_attribute[0].offset = offsetof(BluCat::StaticMeshVertex, position);
+ vertex_attribute[0].offset = offsetof(BluCat::GRA::StaticMeshVertex, position);
// Normal.
vertex_attribute[1].location = 1;
vertex_attribute[1].binding = 0;
vertex_attribute[1].format = VK_FORMAT_R32G32B32_SFLOAT;
- vertex_attribute[1].offset = offsetof(BluCat::StaticMeshVertex, normal);
+ vertex_attribute[1].offset = offsetof(BluCat::GRA::StaticMeshVertex, normal);
// Texture coordinate.
vertex_attribute[2].location = 2;
vertex_attribute[2].binding = 0;
vertex_attribute[2].format = VK_FORMAT_R32G32_SFLOAT;
- vertex_attribute[2].offset = offsetof(BluCat::StaticMeshVertex, texture_coord);
+ vertex_attribute[2].offset = offsetof(BluCat::GRA::StaticMeshVertex, texture_coord);
VkPipelineVertexInputStateCreateInfo vertex_input_info = {};
vertex_input_info.sType =
@@ -103,14 +103,14 @@ load_pipeline(void *obj)
VkViewport viewport = {};
viewport.x = 0;
viewport.y = 0;
- viewport.width = cg_core.display_width;
- viewport.height = cg_core.display_height;
+ viewport.width = BluCat::INT::core.display_width;
+ viewport.height = BluCat::INT::core.display_height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor = {};
scissor.offset = {0, 0};
- scissor.extent = {cg_core.display_width, cg_core.display_height};
+ scissor.extent = {BluCat::INT::core.display_width, BluCat::INT::core.display_height};
VkPipelineViewportStateCreateInfo viewport_state = {};
viewport_state.sType =
@@ -213,14 +213,14 @@ load_pipeline(void *obj)
pipeline_info.pDepthStencilState = &depth_stencil;
pipeline_info.pColorBlendState = &color_blending;
pipeline_info.pDynamicState = &dynamic_state_info;
- pipeline_info.layout = cg_core.vk_graphics_pipeline_3d_layout->pipeline;
- pipeline_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ pipeline_info.layout = BluCat::INT::core.vk_graphics_pipeline_3d_layout->pipeline;
+ pipeline_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_3d;
pipeline_info.subpass = 0;
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
pipeline_info.basePipelineIndex = -1;
if(vkCreateGraphicsPipelines(
- cg_core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
+ BluCat::INT::core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
&pipeline_info, nullptr, &self->graphic_pipeline)
!= VK_SUCCESS)
throw CommandError{"Failed to create graphics pipeline."};
@@ -229,10 +229,11 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline3D*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline3D*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -241,7 +242,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline3D::GraphicsPipeline3D()
@@ -256,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(
@@ -265,7 +266,7 @@ GraphicsPipeline3D::draw(
// Draw models
for(auto& [static_mesh, instances]:
- cg_core.vk_renderer->static_models_to_draw[current_frame])
+ INT::core.vk_renderer->static_models_to_draw[current_frame])
{
VkBuffer vertex_buffers[]{static_mesh->vertex_buffer->buffer};
VkDeviceSize offsets[]{0};
@@ -284,20 +285,20 @@ GraphicsPipeline3D::draw(
glm::mat4 rotation_matrix{glm::toMat4(*instance->orientation)};
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
- cg_core.vk_light->descriptor_sets_world[image_index],
- view->descriptor_sets_3d[image_index],
+ INT::core.vk_light->descriptor_sets_world[image_index],
+ view->descriptor_sets[image_index],
instance->descriptor_sets[image_index],
instance->texture->descriptor_sets[image_index]};
vkCmdBindDescriptorSets(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_3d_layout->pipeline, 0,
+ INT::core.vk_graphics_pipeline_3d_layout->pipeline, 0,
vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
vkCmdDrawIndexed(
draw_command_buffer, static_mesh->index_count, 1, 0, 0, 0);
- BluCat::UDOStaticModel udo_static_model{};
+ BluCat::GRA::UDOStaticModel udo_static_model{};
udo_static_model.base_matrix = translation_matrix * rotation_matrix;
instance->uniform_buffers[image_index].copy_data(&udo_static_model);
}
diff --git a/src/blucat/graphics_pipeline_3d.hpp b/src/blu_cat/gra/graphics_pipeline_3d.hpp
index de0c422..2e30e02 100644
--- a/src/blucat/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.
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_H 1
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline3D
@@ -34,10 +34,10 @@ 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);
};
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_H */
diff --git a/src/blucat/graphics_pipeline_3d_layout.cpp b/src/blu_cat/gra/graphics_pipeline_3d_layout.cpp
index b2a54d6..504b46e 100644
--- a/src/blucat/graphics_pipeline_3d_layout.cpp
+++ b/src/blu_cat/gra/graphics_pipeline_3d_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -27,13 +27,13 @@ namespace
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline3DLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline3DLayout*>(obj);
std::array<VkDescriptorSetLayout, 4> set_layouts{
- cg_core.vk_descriptor_set_layout->world,
- cg_core.vk_descriptor_set_layout->view,
- cg_core.vk_descriptor_set_layout->model,
- cg_core.vk_descriptor_set_layout->texture};
+ BluCat::INT::core.vk_descriptor_set_layout->world,
+ BluCat::INT::core.vk_descriptor_set_layout->view,
+ BluCat::INT::core.vk_descriptor_set_layout->model,
+ BluCat::INT::core.vk_descriptor_set_layout->texture};
VkPipelineLayoutCreateInfo pipeline_layout_info{};
pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
@@ -43,7 +43,7 @@ load_pipeline(void *obj)
pipeline_layout_info.pPushConstantRanges = nullptr;
if(vkCreatePipelineLayout(
- cg_core.vk_device_with_swapchain->device,
+ BluCat::INT::core.vk_device_with_swapchain->device,
&pipeline_layout_info, nullptr, &self->pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan pipeline layout."};
}
@@ -51,10 +51,10 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline3DLayout*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline3DLayout*>(obj);
vkDestroyPipelineLayout(
- cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}
const CommandChain loader{
@@ -63,7 +63,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline3DLayout::GraphicsPipeline3DLayout()
diff --git a/src/blucat/graphics_pipeline_3d_layout.hpp b/src/blu_cat/gra/graphics_pipeline_3d_layout.hpp
index 2b44dac..13820c4 100644
--- a/src/blucat/graphics_pipeline_3d_layout.hpp
+++ b/src/blu_cat/gra/graphics_pipeline_3d_layout.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_LAYOUT_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_LAYOUT_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_LAYOUT_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline3DLayout
@@ -32,4 +32,4 @@ struct GraphicsPipeline3DLayout
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_LAYOUT_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_LAYOUT_H */
diff --git a/src/blucat/graphics_pipeline_3d_skeletal.cpp b/src/blu_cat/gra/graphics_pipeline_3d_skeletal.cpp
index b039c00..79a85f1 100644
--- a/src/blucat/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.
@@ -19,8 +19,7 @@
#include <array>
#include <stdexcept>
-#include "../core.hpp"
-#include "core.hpp"
+#include "../int/core.hpp"
#include "skeletal_mesh_vertex.hpp"
#include "uniform_data_object.hpp"
@@ -30,7 +29,7 @@ namespace
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline3DSkeletal*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline3DSkeletal*>(obj);
VkPipelineShaderStageCreateInfo vert_shader_stage_info = {};
vert_shader_stage_info.sType =
@@ -39,7 +38,7 @@ load_pipeline(void *obj)
vert_shader_stage_info.flags = 0;
vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vert_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->vert3d_skeletal_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->vert3d_skeletal_shader_module;
vert_shader_stage_info.pName = "main";
vert_shader_stage_info.pSpecializationInfo = nullptr;
@@ -50,7 +49,7 @@ load_pipeline(void *obj)
frag_shader_stage_info.flags = 0;
frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
frag_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->frag3d_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->frag3d_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -61,7 +60,7 @@ load_pipeline(void *obj)
VkVertexInputBindingDescription vertex_input_binding{};
vertex_input_binding.binding = 0;
- vertex_input_binding.stride = sizeof(BluCat::SkeletalMeshVertex);
+ vertex_input_binding.stride = sizeof(BluCat::GRA::SkeletalMeshVertex);
vertex_input_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
std::array<VkVertexInputAttributeDescription, 5> vertex_attribute{};
@@ -69,27 +68,27 @@ load_pipeline(void *obj)
vertex_attribute[0].location = 0;
vertex_attribute[0].binding = 0;
vertex_attribute[0].format = VK_FORMAT_R32G32B32_SFLOAT;
- vertex_attribute[0].offset = offsetof(BluCat::SkeletalMeshVertex, position);
+ vertex_attribute[0].offset = offsetof(BluCat::GRA::SkeletalMeshVertex, position);
// Normal.
vertex_attribute[1].location = 1;
vertex_attribute[1].binding = 0;
vertex_attribute[1].format = VK_FORMAT_R32G32B32_SFLOAT;
- vertex_attribute[1].offset = offsetof(BluCat::SkeletalMeshVertex, normal);
+ vertex_attribute[1].offset = offsetof(BluCat::GRA::SkeletalMeshVertex, normal);
// Texture coordinate.
vertex_attribute[2].location = 2;
vertex_attribute[2].binding = 0;
vertex_attribute[2].format = VK_FORMAT_R32G32_SFLOAT;
- vertex_attribute[2].offset = offsetof(BluCat::SkeletalMeshVertex, texture_coord);
+ vertex_attribute[2].offset = offsetof(BluCat::GRA::SkeletalMeshVertex, texture_coord);
// Bones ids.
vertex_attribute[3].location = 3;
vertex_attribute[3].binding = 0;
vertex_attribute[3].format = VK_FORMAT_R32G32B32A32_SINT;
- vertex_attribute[3].offset = offsetof(BluCat::SkeletalMeshVertex, bone_ids);
+ vertex_attribute[3].offset = offsetof(BluCat::GRA::SkeletalMeshVertex, bone_ids);
// Bones weights.
vertex_attribute[4].location = 4;
vertex_attribute[4].binding = 0;
vertex_attribute[4].format = VK_FORMAT_R32G32B32A32_SFLOAT;
- vertex_attribute[4].offset = offsetof(BluCat::SkeletalMeshVertex, bone_weights);
+ vertex_attribute[4].offset = offsetof(BluCat::GRA::SkeletalMeshVertex, bone_weights);
VkPipelineVertexInputStateCreateInfo vertex_input_info = {};
vertex_input_info.sType =
@@ -113,14 +112,14 @@ load_pipeline(void *obj)
VkViewport viewport = {};
viewport.x = 0;
viewport.y = 0;
- viewport.width = cg_core.display_width;
- viewport.height = cg_core.display_height;
+ viewport.width = BluCat::INT::core.display_width;
+ viewport.height = BluCat::INT::core.display_height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor = {};
scissor.offset = {0, 0};
- scissor.extent = {cg_core.display_width, cg_core.display_height};
+ scissor.extent = {BluCat::INT::core.display_width, BluCat::INT::core.display_height};
VkPipelineViewportStateCreateInfo viewport_state = {};
viewport_state.sType =
@@ -223,14 +222,14 @@ load_pipeline(void *obj)
pipeline_info.pDepthStencilState = &depth_stencil;
pipeline_info.pColorBlendState = &color_blending;
pipeline_info.pDynamicState = &dynamic_state_info;
- pipeline_info.layout = cg_core.vk_graphics_pipeline_3d_layout->pipeline;
- pipeline_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ pipeline_info.layout = BluCat::INT::core.vk_graphics_pipeline_3d_layout->pipeline;
+ pipeline_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_3d;
pipeline_info.subpass = 0;
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
pipeline_info.basePipelineIndex = -1;
if(vkCreateGraphicsPipelines(
- cg_core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
+ BluCat::INT::core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
&pipeline_info, nullptr, &self->graphic_pipeline)
!= VK_SUCCESS)
throw CommandError{"Failed to create graphics pipeline."};
@@ -239,10 +238,11 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipeline3DSkeletal*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipeline3DSkeletal*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -251,7 +251,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipeline3DSkeletal::GraphicsPipeline3DSkeletal()
@@ -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(
@@ -275,7 +275,7 @@ GraphicsPipeline3DSkeletal::draw(
// Draw models
for(auto& [skeletal_mesh, instances]:
- cg_core.vk_renderer->skeletal_models_to_draw[current_frame])
+ INT::core.vk_renderer->skeletal_models_to_draw[current_frame])
{
VkBuffer vertex_buffers[]{skeletal_mesh->vertex_buffer->buffer};
VkDeviceSize offsets[]{0};
@@ -294,21 +294,21 @@ GraphicsPipeline3DSkeletal::draw(
glm::mat4 rotation_matrix{glm::toMat4(*instance->orientation)};
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
- cg_core.vk_light->descriptor_sets_world[image_index],
- view->descriptor_sets_3d[image_index],
+ INT::core.vk_light->descriptor_sets_world[image_index],
+ view->descriptor_sets[image_index],
instance->descriptor_sets[image_index],
instance->texture->descriptor_sets[image_index]};
vkCmdBindDescriptorSets(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_3d_layout->pipeline, 0,
+ INT::core.vk_graphics_pipeline_3d_layout->pipeline, 0,
vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
vkCmdDrawIndexed(
draw_command_buffer, skeletal_mesh->index_count, 1, 0, 0, 0);
- BluCat::UDOSkeletalModel udo_skeletal_model{};
- instance->tick(cg_core.delta_time);
+ BluCat::GRA::UDOSkeletalModel udo_skeletal_model{};
+ instance->tick(INT::core.delta_time);
udo_skeletal_model.base_matrix = translation_matrix * rotation_matrix;
std::copy(instance->bone_transforms.begin(),
instance->bone_transforms.end(),
diff --git a/src/blucat/graphics_pipeline_3d_skeletal.hpp b/src/blu_cat/gra/graphics_pipeline_3d_skeletal.hpp
index 430d2ec..16d65b0 100644
--- a/src/blucat/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.
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_SKELETAL_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_SKELETAL_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_SKELETAL_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_3D_SKELETAL_H 1
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipeline3DSkeletal
@@ -34,10 +34,10 @@ 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);
};
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_SKELETAL_3D_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_SKELETAL_3D_H */
diff --git a/src/blucat/graphics_pipeline_sprite_3d.cpp b/src/blu_cat/gra/graphics_pipeline_sprite_3d.cpp
index a71e8bc..63e10b9 100644
--- a/src/blucat/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.
@@ -18,8 +18,7 @@
#include <array>
-#include "../core.hpp"
-#include "core.hpp"
+#include "../int/core.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -28,7 +27,7 @@ namespace
struct Sprite3DOrder
{
- std::shared_ptr<BluCat::Sprite3D> sprite_3d;
+ std::shared_ptr<BluCat::GRA::Sprite3D> sprite_3d;
float distance;
};
@@ -47,7 +46,7 @@ operator>(const Sprite3DOrder &a, const Sprite3DOrder &b)
void
load_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipelineSprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipelineSprite3D*>(obj);
VkPipelineShaderStageCreateInfo vert_shader_stage_info{};
vert_shader_stage_info.sType =
@@ -56,7 +55,7 @@ load_pipeline(void *obj)
vert_shader_stage_info.flags = 0;
vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vert_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->vert_sprite_3d_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->vert_sprite_3d_shader_module;
vert_shader_stage_info.pName = "main";
vert_shader_stage_info.pSpecializationInfo = nullptr;
@@ -67,7 +66,7 @@ load_pipeline(void *obj)
frag_shader_stage_info.flags = 0;
frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
frag_shader_stage_info.module =
- cg_core.vk_device_with_swapchain->frag_sprite_3d_shader_module;
+ BluCat::INT::core.vk_device_with_swapchain->frag_sprite_3d_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -110,14 +109,14 @@ load_pipeline(void *obj)
VkViewport viewport = {};
viewport.x = 0;
viewport.y = 0;
- viewport.width = cg_core.display_width;
- viewport.height = cg_core.display_height;
+ viewport.width = BluCat::INT::core.display_width;
+ viewport.height = BluCat::INT::core.display_height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor = {};
scissor.offset = {0, 0};
- scissor.extent = {cg_core.display_width, cg_core.display_height};
+ scissor.extent = {BluCat::INT::core.display_width, BluCat::INT::core.display_height};
VkPipelineViewportStateCreateInfo viewport_state = {};
viewport_state.sType =
@@ -222,14 +221,14 @@ load_pipeline(void *obj)
pipeline_info.pDepthStencilState = &depth_stencil;
pipeline_info.pColorBlendState = &color_blending;
pipeline_info.pDynamicState = &dynamic_state_info;
- pipeline_info.layout = cg_core.vk_graphics_pipeline_3d_layout->pipeline;
- pipeline_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ pipeline_info.layout = BluCat::INT::core.vk_graphics_pipeline_3d_layout->pipeline;
+ pipeline_info.renderPass = BluCat::INT::core.vk_render_pass->pipeline_3d;
pipeline_info.subpass = 0;
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
pipeline_info.basePipelineIndex = -1;
if(vkCreateGraphicsPipelines(
- cg_core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
+ BluCat::INT::core.vk_device_with_swapchain->device, VK_NULL_HANDLE, 1,
&pipeline_info, nullptr, &self->graphic_pipeline)
!= VK_SUCCESS)
throw CommandError{"Failed to create graphics pipeline sprite 3d."};
@@ -238,10 +237,11 @@ load_pipeline(void *obj)
void
unload_pipeline(void *obj)
{
- auto self = static_cast<BluCat::GraphicsPipelineSprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::GraphicsPipelineSprite3D*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -250,7 +250,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
GraphicsPipelineSprite3D::GraphicsPipelineSprite3D()
@@ -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(
@@ -275,10 +275,10 @@ GraphicsPipelineSprite3D::draw(
std::vector<Sprite3DOrder> sprite_3d_order;
{ // Sort sprites 3D
sprite_3d_order.reserve(
- cg_core.vk_renderer->sprites_3d_to_draw[current_frame].size());
+ INT::core.vk_renderer->sprites_3d_to_draw[current_frame].size());
- for(std::shared_ptr<BluCat::Sprite3D> sprite:
- cg_core.vk_renderer->sprites_3d_to_draw[current_frame])
+ for(std::shared_ptr<BluCat::GRA::Sprite3D> sprite:
+ INT::core.vk_renderer->sprites_3d_to_draw[current_frame])
sprite_3d_order.emplace_back(
sprite, glm::distance(*view->camera_position, *sprite->position));
@@ -289,8 +289,8 @@ GraphicsPipelineSprite3D::draw(
for(auto& sprite: sprite_3d_order)
{
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
- cg_core.vk_light->descriptor_sets_world[image_index],
- view->descriptor_sets_3d[image_index],
+ INT::core.vk_light->descriptor_sets_world[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};
@@ -300,7 +300,7 @@ GraphicsPipelineSprite3D::draw(
&sprite.sprite_3d->sprite->vertex_buffer->buffer, offsets);
vkCmdBindDescriptorSets(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_3d_layout->pipeline, 0,
+ INT::core.vk_graphics_pipeline_3d_layout->pipeline, 0,
vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
UDOSprite3D ubo_sprite_3d{};
diff --git a/src/blucat/graphics_pipeline_sprite_3d.hpp b/src/blu_cat/gra/graphics_pipeline_sprite_3d.hpp
index 969f905..d03b8e8 100644
--- a/src/blucat/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.
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_SPRITE_3D_H
-#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_SPRITE_3D_H 1
+#ifndef BLU_CAT_GRA_GRAPHICS_PIPELINE_SPRITE_3D_H
+#define BLU_CAT_GRA_GRAPHICS_PIPELINE_SPRITE_3D_H 1
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
#include "sprite_3d.hpp"
-#include "view_3d.hpp"
+#include "view.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct GraphicsPipelineSprite3D
@@ -35,10 +35,10 @@ 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);
};
}
-#endif /* CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_SPRITE_3D_H */
+#endif /* BLU_CAT_GRA_GRAPHICS_PIPELINE_SPRITE_3D_H */
diff --git a/src/blucat/image.cpp b/src/blu_cat/gra/image.cpp
index 7f8633f..76e4f9d 100644
--- a/src/blucat/image.cpp
+++ b/src/blu_cat/gra/image.cpp
@@ -16,9 +16,9 @@
#include "image.hpp"
-#include "../core.hpp"
+#include "../int/core.hpp"
-namespace BluCat::Image
+namespace BluCat::GRA::Image
{
Error::Error(const std::string &m):
@@ -39,7 +39,7 @@ Error::what() const noexcept
void
create(
- BluCat::Device *device,
+ BluCat::GRA::Device *device,
VkImage *image,
VkDeviceMemory *image_memory,
VkFormat format,
@@ -117,7 +117,7 @@ void move_image_state(
}
void create_view(
- BluCat::Device *device,
+ BluCat::GRA::Device *device,
VkImageView *image_view,
const VkImage &image,
VkFormat format,
diff --git a/src/blucat/image.hpp b/src/blu_cat/gra/image.hpp
index cb6cfd4..ba64b76 100644
--- a/src/blucat/image.hpp
+++ b/src/blu_cat/gra/image.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef BLUE_KITTY_BLUCAT_IMAGE_H
-#define BLUE_KITTY_BLUCAT_IMAGE_H 1
+#ifndef BLU_CAT_GRA_IMAGE_H
+#define BLU_CAT_GRA_IMAGE_H 1
#include <memory>
#include <string>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "device.hpp"
-namespace BluCat::Image
+namespace BluCat::GRA::Image
{
struct Error: public std::exception
@@ -40,7 +40,7 @@ private:
void
create(
- BluCat::Device *device,
+ BluCat::GRA::Device *device,
VkImage *image,
VkDeviceMemory *image_memory,
VkFormat format,
@@ -63,11 +63,11 @@ move_image_state(
void
create_view(
- BluCat::Device *device,
+ BluCat::GRA::Device *device,
VkImageView *image_view,
const VkImage &image,
VkFormat format,
VkImageAspectFlags image_aspect_flags);
}
-#endif /* CANDY_GEAR_BLUCAT_IMAGE_H */
+#endif /* BLU_CAT_GRA_IMAGE_H */
diff --git a/src/blucat/light.cpp b/src/blu_cat/gra/light.cpp
index 5efc6ec..403dcf4 100644
--- a/src/blucat/light.cpp
+++ b/src/blu_cat/gra/light.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -27,14 +27,14 @@ namespace
void
load_world_vert_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
try
{
- self->ub_world_vert.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->ub_world_vert.reserve(BluCat::INT::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
self->ub_world_vert.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOWorld3D_Vert));
+ BluCat::INT::core.vk_device_with_swapchain, sizeof(BluCat::GRA::UDOWorld3D_Vert));
}
catch(const std::exception& e)
{
@@ -45,7 +45,7 @@ load_world_vert_uniform_buffer(void *obj)
void
unload_world_vert_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
self->ub_world_vert.clear();
}
@@ -53,14 +53,14 @@ unload_world_vert_uniform_buffer(void *obj)
void
load_world_frag_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
try
{
- self->ub_world_frag.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->ub_world_frag.reserve(BluCat::INT::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
self->ub_world_frag.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOWorld3D_Frag));
+ BluCat::INT::core.vk_device_with_swapchain, sizeof(BluCat::GRA::UDOWorld3D_Frag));
}
catch(const std::exception& e)
{
@@ -71,7 +71,7 @@ load_world_frag_uniform_buffer(void *obj)
void
unload_world_frag_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
self->ub_world_frag.clear();
}
@@ -79,7 +79,7 @@ unload_world_frag_uniform_buffer(void *obj)
void
load_descriptor_pool(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
uint32_t uniform_buffers_count =
self->ub_world_vert.size() + self->ub_world_vert.size();
@@ -97,7 +97,7 @@ load_descriptor_pool(void *obj)
pool_info.pPoolSizes = &descriptor_pool_size;
if(vkCreateDescriptorPool(
- cg_core.vk_device_with_swapchain->device, &pool_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &pool_info, nullptr,
&self->descriptor_pool) != VK_SUCCESS)
throw CommandError{"Failed to create a Vulkan descriptor pool."};
}
@@ -105,21 +105,21 @@ load_descriptor_pool(void *obj)
void
unload_descriptor_pool(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
vkDestroyDescriptorPool(
- cg_core.vk_device_with_swapchain->device, self->descriptor_pool,
+ BluCat::INT::core.vk_device_with_swapchain->device, self->descriptor_pool,
nullptr);
}
void
load_descriptor_sets_world(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->world);
+ BluCat::INT::core.vk_swapchain->images_count,
+ BluCat::INT::core.vk_descriptor_set_layout->world);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -129,7 +129,7 @@ load_descriptor_sets_world(void *obj)
self->descriptor_sets_world.resize(layouts.size());
if(vkAllocateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, &alloc_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &alloc_info,
self->descriptor_sets_world.data()) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan world descriptor set."};
}
@@ -137,19 +137,19 @@ load_descriptor_sets_world(void *obj)
void
load_resources_to_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::Light*>(obj);
+ auto self = static_cast<BluCat::GRA::Light*>(obj);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
{
VkDescriptorBufferInfo world_vert_info{};
world_vert_info.buffer = self->ub_world_vert[i].buffer;
world_vert_info.offset = 0;
- world_vert_info.range = sizeof(BluCat::UDOWorld3D_Vert);
+ world_vert_info.range = sizeof(BluCat::GRA::UDOWorld3D_Vert);
VkDescriptorBufferInfo world_frag_info{};
world_frag_info.buffer = self->ub_world_frag[i].buffer;
world_frag_info.offset = 0;
- world_frag_info.range = sizeof(BluCat::UDOWorld3D_Frag);
+ world_frag_info.range = sizeof(BluCat::GRA::UDOWorld3D_Frag);
std::array<VkWriteDescriptorSet, 2> write_descriptors{};
write_descriptors[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
@@ -173,7 +173,7 @@ load_resources_to_descriptor_sets(void *obj)
write_descriptors[1].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -189,7 +189,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
Light::Light()
diff --git a/src/blucat/light.hpp b/src/blu_cat/gra/light.hpp
index 7e1d3a1..22a9e2d 100644
--- a/src/blucat/light.hpp
+++ b/src/blu_cat/gra/light.hpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_LIGHT_H
-#define CANDY_GEAR_BLUCAT_LIGHT_H 1
+#ifndef BLU_CAT_GRA_LIGHT_H
+#define BLU_CAT_GRA_LIGHT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
#include "uniform_buffer.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Light
@@ -38,4 +38,4 @@ struct Light
}
-#endif /* CANDY_GEAR_BLUCAT_LIGHT_H */
+#endif /* BLU_CAT_GRA_LIGHT_H */
diff --git a/src/log.cpp b/src/blu_cat/gra/log.cpp
index 78044c4..78044c4 100644
--- a/src/log.cpp
+++ b/src/blu_cat/gra/log.cpp
diff --git a/src/log.hpp b/src/blu_cat/gra/log.hpp
index 2856f20..2856f20 100644
--- a/src/log.hpp
+++ b/src/blu_cat/gra/log.hpp
diff --git a/src/blucat/qoi.cpp b/src/blu_cat/gra/qoi.cpp
index 663e4e9..40968df 100644
--- a/src/blucat/qoi.cpp
+++ b/src/blu_cat/gra/qoi.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.
@@ -19,7 +19,7 @@
#include <array>
#include <fstream>
-#include "../binary_reader.hpp"
+#include "../com/binary_reader.hpp"
namespace
{
@@ -92,7 +92,7 @@ color_hash(const RGBA &colors)
}
-namespace BluCat::QOI
+namespace BluCat::GRA::QOI
{
Image::Image(const char *file_path, uint8_t channels):
diff --git a/src/blucat/qoi.hpp b/src/blu_cat/gra/qoi.hpp
index cd33205..f8be4ec 100644
--- a/src/blucat/qoi.hpp
+++ b/src/blu_cat/gra/qoi.hpp
@@ -16,7 +16,7 @@
#include <cstdint>
-namespace BluCat::QOI
+namespace BluCat::GRA::QOI
{
struct Header
{
diff --git a/src/blucat/queue.cpp b/src/blu_cat/gra/queue.cpp
index c00d874..3f47a19 100644
--- a/src/blucat/queue.cpp
+++ b/src/blu_cat/gra/queue.cpp
@@ -18,11 +18,11 @@
#include "queue_family.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
Queue::Queue(
- BluCat::QueueFamily *queue_family, VkQueue queue, int queue_index):
+ BluCat::GRA::QueueFamily *queue_family, VkQueue queue, int queue_index):
queue_family{queue_family},
queue{queue},
queue_index{queue_index}
diff --git a/src/blucat/queue.hpp b/src/blu_cat/gra/queue.hpp
index a71dc9d..3dc9833 100644
--- a/src/blucat/queue.hpp
+++ b/src/blu_cat/gra/queue.hpp
@@ -14,18 +14,18 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_QUEUE_H
-#define CANDY_GEAR_BLUCAT_QUEUE_H 1
+#ifndef BLU_CAT_GRA_QUEUE_H
+#define BLU_CAT_GRA_QUEUE_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
class QueueFamily;
struct Queue
{
- friend class BluCat::QueueFamily;
+ friend class BluCat::GRA::QueueFamily;
Queue(const Queue &t) = delete;
Queue& operator=(const Queue &t) = delete;
@@ -42,10 +42,10 @@ struct Queue
~Queue();
private:
- BluCat::QueueFamily *queue_family;
+ BluCat::GRA::QueueFamily *queue_family;
int queue_index;
- Queue(BluCat::QueueFamily *queue_family, VkQueue queue, int queue_index);
+ Queue(BluCat::GRA::QueueFamily *queue_family, VkQueue queue, int queue_index);
};
template<typename T> void
@@ -79,4 +79,4 @@ Queue::submit_one_time_command(
}
-#endif /* CANDY_GEAR_BLUCAT_QUEUE_H */
+#endif /* BLU_CAT_GRA_QUEUE_H */
diff --git a/src/blucat/queue_family.cpp b/src/blu_cat/gra/queue_family.cpp
index 32aaf4b..59086b5 100644
--- a/src/blucat/queue_family.cpp
+++ b/src/blu_cat/gra/queue_family.cpp
@@ -20,13 +20,13 @@
#include <sstream>
#endif
-#include "../core.hpp"
+#include "../int/core.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
QueueFamily::QueueFamily(
- BluCat::Device *device, uint32_t family_index,
+ BluCat::GRA::Device *device, uint32_t family_index,
const VkQueueFamilyProperties &queue_family_properties):
queue_mutex{}
{
@@ -47,7 +47,7 @@ QueueFamily::QueueFamily(
message << "Sparse Binding: " <<
(queue_family_properties.queueFlags & VK_QUEUE_SPARSE_BINDING_BIT ?
"true" : "false") << std::endl;
- cg_core.log.message(Log::Level::Trace, message.str());
+ INT::core.log.message(Log::Level::Trace, message.str());
#endif
this->device = device;
diff --git a/src/blucat/queue_family.hpp b/src/blu_cat/gra/queue_family.hpp
index 2486316..4673058 100644
--- a/src/blucat/queue_family.hpp
+++ b/src/blu_cat/gra/queue_family.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_QUEUE_FAMILY_H
-#define CANDY_GEAR_BLUCAT_QUEUE_FAMILY_H 1
+#ifndef BLU_CAT_GRA_QUEUE_FAMILY_H
+#define BLU_CAT_GRA_QUEUE_FAMILY_H 1
#include <mutex>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "queue.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
class Device;
@@ -41,12 +41,12 @@ class QueueFamily
std::vector<QueueState> queue_states;
public:
- BluCat::Device *device;
+ BluCat::GRA::Device *device;
uint32_t family_index;
VkQueueFamilyProperties family_properties;
- QueueFamily(BluCat::Device *device, uint32_t family_index,
+ QueueFamily(BluCat::GRA::Device *device, uint32_t family_index,
const VkQueueFamilyProperties &queue_family_properties);
Queue
@@ -55,4 +55,4 @@ public:
}
-#endif /* CANDY_GEAR_BLUCAT_QUEUE_FAMILY_H */
+#endif /* BLU_CAT_GRA_QUEUE_FAMILY_H */
diff --git a/src/blucat/rectangle.cpp b/src/blu_cat/gra/rectangle.cpp
index 34f844d..ea01a04 100644
--- a/src/blucat/rectangle.cpp
+++ b/src/blu_cat/gra/rectangle.cpp
@@ -16,7 +16,7 @@
#include "rectangle.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
const int Rectangle::VertexCount{4};
diff --git a/src/blucat/rectangle.hpp b/src/blu_cat/gra/rectangle.hpp
index 876508c..cd09239 100644
--- a/src/blucat/rectangle.hpp
+++ b/src/blu_cat/gra/rectangle.hpp
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_RECTANGLE_H
-#define CANDY_GEAR_BLUCAT_RECTANGLE_H 1
+#ifndef BLU_CAT_GRA_RECTANGLE_H
+#define BLU_CAT_GRA_RECTANGLE_H 1
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Rectangle
@@ -39,4 +39,4 @@ struct Rectangle
}
-#endif /* CANDY_GEAR_BLUCAT_RECTANGLE_H */
+#endif /* BLU_CAT_GRA_RECTANGLE_H */
diff --git a/src/blucat/render_pass.cpp b/src/blu_cat/gra/render_pass.cpp
index 0eb30e3..64fdf56 100644
--- a/src/blucat/render_pass.cpp
+++ b/src/blu_cat/gra/render_pass.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
namespace
{
@@ -26,12 +26,12 @@ namespace
void
load_3d(void *obj)
{
- auto self = static_cast<BluCat::RenderPass*>(obj);
+ auto self = static_cast<BluCat::GRA::RenderPass*>(obj);
std::array<VkAttachmentDescription, 2> attachments{};
// Color attachment.
attachments[0].flags = 0;
- attachments[0].format = cg_core.vk_swapchain->image_format;
+ attachments[0].format = BluCat::INT::core.vk_swapchain->image_format;
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
@@ -95,29 +95,29 @@ load_3d(void *obj)
render_pass_info.pDependencies = &dependency;
if(vkCreateRenderPass(
- cg_core.vk_device_with_swapchain->device, &render_pass_info, nullptr,
- &self->pipeline_3d) != VK_SUCCESS)
+ BluCat::INT::core.vk_device_with_swapchain->device, &render_pass_info,
+ nullptr, &self->pipeline_3d) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Render Pass 3D."};
}
void
unload_3d(void *obj)
{
- auto self = static_cast<BluCat::RenderPass*>(obj);
+ auto self = static_cast<BluCat::GRA::RenderPass*>(obj);
vkDestroyRenderPass(
- cg_core.vk_device_with_swapchain->device, self->pipeline_3d, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->pipeline_3d, nullptr);
}
void
load_2d(void *obj)
{
- auto self = static_cast<BluCat::RenderPass*>(obj);
+ auto self = static_cast<BluCat::GRA::RenderPass*>(obj);
std::array<VkAttachmentDescription, 1> attachments{};
// Color attachment.
attachments[0].flags = 0;
- attachments[0].format = cg_core.vk_swapchain->image_format;
+ attachments[0].format = BluCat::INT::core.vk_swapchain->image_format;
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
@@ -166,7 +166,7 @@ load_2d(void *obj)
render_pass_info.pDependencies = &dependency;
if(vkCreateRenderPass(
- cg_core.vk_device_with_swapchain->device, &render_pass_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &render_pass_info,
nullptr, &self->pipeline_2d) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Render Pass 2D."};
}
@@ -174,10 +174,10 @@ load_2d(void *obj)
void
unload_2d(void *obj)
{
- auto self = static_cast<BluCat::RenderPass*>(obj);
+ auto self = static_cast<BluCat::GRA::RenderPass*>(obj);
vkDestroyRenderPass(
- cg_core.vk_device_with_swapchain->device, self->pipeline_2d, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->pipeline_2d, nullptr);
}
const CommandChain loader{
@@ -187,7 +187,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
RenderPass::RenderPass()
diff --git a/src/blucat/render_pass.hpp b/src/blu_cat/gra/render_pass.hpp
index 196ce97..4187261 100644
--- a/src/blucat/render_pass.hpp
+++ b/src/blu_cat/gra/render_pass.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_RENDER_PASS_H
-#define CANDY_GEAR_BLUCAT_RENDER_PASS_H 1
+#ifndef BLU_CAT_GRA_RENDER_PASS_H
+#define BLU_CAT_GRA_RENDER_PASS_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct RenderPass
@@ -33,4 +33,4 @@ struct RenderPass
}
-#endif /* CANDY_GEAR_BLUCAT_RENDER_PASS_H */
+#endif /* BLU_CAT_GRA_RENDER_PASS_H */
diff --git a/src/blucat/renderer.cpp b/src/blu_cat/gra/renderer.cpp
index 75822e0..36b9925 100644
--- a/src/blucat/renderer.cpp
+++ b/src/blu_cat/gra/renderer.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,22 +18,46 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
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::Renderer*>(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;
@@ -48,42 +72,97 @@ load_descriptor_pool(void *obj)
pool_info.pPoolSizes = &descriptor_pool_size;
if(vkCreateDescriptorPool(
- cg_core.vk_device_with_swapchain->device, &pool_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &pool_info, nullptr,
&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);
}
void
unload_descriptor_pool(void *obj)
{
- auto self = static_cast<BluCat::Renderer*>(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(
- cg_core.vk_device_with_swapchain->device, self->descriptor_pool,
+ BluCat::INT::core.vk_device_with_swapchain->device, self->descriptor_pool,
nullptr);
}
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::Renderer*>(obj);
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
self->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::INT::core.vk_device_with_swapchain->get_queue_family_with_presentation();
}
void
load_command_pool(void *obj)
{
- auto self = static_cast<BluCat::Renderer*>(obj);
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
VkCommandPoolCreateInfo create_info{};
create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
@@ -99,12 +178,9 @@ load_command_pool(void *obj)
void
unload_command_pool(void *obj)
{
- auto self = static_cast<BluCat::Renderer*>(obj);
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
- vkWaitForFences(cg_core.vk_device_with_swapchain->device,
- BluCat::Swapchain::max_frames_in_flight,
- cg_core.vk_swapchain->in_flight_fences.data(), VK_TRUE,
- std::numeric_limits<uint64_t>::max());
+ self->wait_frame();
vkDestroyCommandPool(
self->queue_family->device->device, self->command_pool, nullptr);
}
@@ -112,7 +188,7 @@ unload_command_pool(void *obj)
void
load_draw_command_buffer(void *obj)
{
- auto self = static_cast<BluCat::Renderer*>(obj);
+ auto self = static_cast<BluCat::GRA::Renderer*>(obj);
// FIXME: 3 is a magical number, triple buffering.
self->draw_command_buffers.resize(3);
@@ -131,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,23 +218,28 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
-Renderer::Renderer(std::vector<std::shared_ptr<View2D>> views_2d,
- std::vector<std::shared_ptr<View3D>> views_3d):
- skeletal_models_to_draw{cg_core.vk_swapchain->images_count},
- static_models_to_draw{cg_core.vk_swapchain->images_count},
- sprites_3d_to_draw{cg_core.vk_swapchain->images_count},
- views_2d{views_2d},
- views_3d{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{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)
{
}
@@ -164,32 +248,44 @@ Renderer::~Renderer()
loader.revert(this);
}
+// FIXME: this is a workaround to prevent a code to free some resource while
+// it still being rendered.
+void
+Renderer::wait_frame()
+{
+ vkWaitForFences(BluCat::INT::core.vk_device_with_swapchain->device,
+ BluCat::GRA::Swapchain::max_frames_in_flight,
+ BluCat::INT::core.vk_swapchain->in_flight_fences.data(), VK_TRUE,
+ std::numeric_limits<uint64_t>::max());
+}
+
void
Renderer::draw()
{
auto fence_status = vkGetFenceStatus(
- cg_core.vk_device_with_swapchain->device,
- cg_core.vk_swapchain->in_flight_fences[
- cg_core.vk_swapchain->current_frame]);
+ BluCat::INT::core.vk_device_with_swapchain->device,
+ BluCat::INT::core.vk_swapchain->in_flight_fences[
+ BluCat::INT::core.vk_swapchain->current_frame]);
if(fence_status == VK_SUCCESS)
{
- auto next_frame = cg_core.vk_swapchain->current_frame + 1;
+ auto next_frame = BluCat::INT::core.vk_swapchain->current_frame + 1;
if(next_frame == Swapchain::max_frames_in_flight) next_frame = 0;
- vkResetFences(cg_core.vk_device_with_swapchain->device, 1,
- &cg_core.vk_swapchain->in_flight_fences[
- cg_core.vk_swapchain->current_frame]);
+ vkResetFences(INT::core.vk_device_with_swapchain->device, 1,
+ &BluCat::INT::core.vk_swapchain->in_flight_fences[
+ BluCat::INT::core.vk_swapchain->current_frame]);
uint32_t image_index;
vkAcquireNextImageKHR(
- cg_core.vk_device_with_swapchain->device,
- cg_core.vk_swapchain->swapchain, std::numeric_limits<uint64_t>::max(),
- cg_core.vk_swapchain->image_available_semaphores[
- cg_core.vk_swapchain->current_frame], VK_NULL_HANDLE, &image_index);
+ BluCat::INT::core.vk_device_with_swapchain->device,
+ BluCat::INT::core.vk_swapchain->swapchain,
+ std::numeric_limits<uint64_t>::max(),
+ BluCat::INT::core.vk_swapchain->image_available_semaphores[
+ BluCat::INT::core.vk_swapchain->current_frame], VK_NULL_HANDLE, &image_index);
VkCommandBuffer draw_command_buffer =
- this->draw_command_buffers[cg_core.vk_swapchain->current_frame];
+ this->draw_command_buffers[BluCat::INT::core.vk_swapchain->current_frame];
vkResetCommandBuffer(draw_command_buffer, 0);
// Begin command buffer.
@@ -204,16 +300,15 @@ Renderer::draw()
// 3D drawing.
{
- // Dark gray blue.
std::array<VkClearValue, 2> clear_values{};
- clear_values[0].color = {0.12f, 0.12f, 0.18f, 1.0f};
+ clear_values[0].color = this->clear_screen_color;
clear_values[1].depthStencil = {1.0f, 0};
{ // Update world uniform buffer
UDOWorld3D_Vert ubo_world_3d_vert{};
ubo_world_3d_vert.ambient_light_color =
glm::vec4{0.25, 0.25, 0.25, 1.0};
- cg_core.vk_light->ub_world_vert[image_index].copy_data(
+ BluCat::INT::core.vk_light->ub_world_vert[image_index].copy_data(
&ubo_world_3d_vert);
UDOWorld3D_Frag ubo_world_3d_frag{};
@@ -221,20 +316,20 @@ Renderer::draw()
glm::vec3{-0.57735, 0.57735, -0.57735};
ubo_world_3d_frag.directional_light_color =
glm::vec4{0.8, 0.8, 0.8, 1.0};
- cg_core.vk_light->ub_world_frag[image_index].copy_data(
+ BluCat::INT::core.vk_light->ub_world_frag[image_index].copy_data(
&ubo_world_3d_frag);
}
VkRenderPassBeginInfo render_pass_begin{};
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
render_pass_begin.pNext = nullptr;
- render_pass_begin.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ render_pass_begin.renderPass = BluCat::INT::core.vk_render_pass->pipeline_3d;
render_pass_begin.framebuffer =
- cg_core.vk_framebuffer->pipeline_3d[image_index];
+ BluCat::INT::core.vk_framebuffer->pipeline_3d[image_index];
render_pass_begin.renderArea.offset = {0, 0};
render_pass_begin.renderArea.extent = {
- static_cast<uint32_t>(cg_core.display_width),
- static_cast<uint32_t>(cg_core.display_height)};
+ static_cast<uint32_t>(BluCat::INT::core.display_width),
+ static_cast<uint32_t>(BluCat::INT::core.display_height)};
render_pass_begin.clearValueCount = clear_values.size();
render_pass_begin.pClearValues = clear_values.data();
@@ -242,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{};
@@ -262,20 +357,21 @@ Renderer::draw()
vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
}
- cg_core.vk_graphics_pipeline_3d->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ BluCat::INT::core.vk_graphics_pipeline_3d->draw(
+ view, draw_command_buffer,
+ BluCat::INT::core.vk_swapchain->current_frame,
image_index);
- cg_core.vk_graphics_pipeline_sprite_3d->draw(
- view, draw_command_buffer, cg_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);
- cg_core.vk_graphics_pipeline_3d_skeletal->draw(
- view, draw_command_buffer, cg_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);
{ // Update view uniform buffers
- BluCat::UDOView3D ubo_view_3d{};
+ BluCat::GRA::UDOView3D ubo_view_3d{};
// View matrix.
glm::mat4 translation_matrix{1.0f};
@@ -300,13 +396,13 @@ Renderer::draw()
VkRenderPassBeginInfo render_pass_begin{};
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
render_pass_begin.pNext = nullptr;
- render_pass_begin.renderPass = cg_core.vk_render_pass->pipeline_2d;
+ render_pass_begin.renderPass = BluCat::INT::core.vk_render_pass->pipeline_2d;
render_pass_begin.framebuffer =
- cg_core.vk_framebuffer->pipeline_2d[image_index];
+ BluCat::INT::core.vk_framebuffer->pipeline_2d[image_index];
render_pass_begin.renderArea.offset = {0, 0};
render_pass_begin.renderArea.extent = {
- static_cast<uint32_t>(cg_core.display_width),
- static_cast<uint32_t>(cg_core.display_height)};
+ static_cast<uint32_t>(BluCat::INT::core.display_width),
+ static_cast<uint32_t>(BluCat::INT::core.display_height)};
render_pass_begin.clearValueCount = 0;
render_pass_begin.pClearValues = nullptr;
@@ -316,27 +412,15 @@ Renderer::draw()
}
{ // 2D solid drawing
- for(auto &view: this->views_2d)
- cg_core.vk_graphics_pipeline_2d_solid->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
- next_frame, image_index);
-
- for(auto &view: this->views_3d)
- cg_core.vk_graphics_pipeline_2d_solid->draw(
- view, draw_command_buffer, cg_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)
- cg_core.vk_graphics_pipeline_2d_wired->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
- next_frame, image_index);
-
- for(auto &view: this->views_3d)
- cg_core.vk_graphics_pipeline_2d_wired->draw(
- view, draw_command_buffer, cg_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);
@@ -350,13 +434,13 @@ Renderer::draw()
auto queue{this->queue_family->get_queue()};
VkSemaphore wait_semaphores[]{
- cg_core.vk_swapchain->image_available_semaphores[
- cg_core.vk_swapchain->current_frame]};
+ BluCat::INT::core.vk_swapchain->image_available_semaphores[
+ BluCat::INT::core.vk_swapchain->current_frame]};
VkPipelineStageFlags wait_stages[] =
{VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
VkSemaphore signal_semaphores[]{
- cg_core.vk_swapchain->render_finished_semaphores[
- cg_core.vk_swapchain->current_frame]};
+ BluCat::INT::core.vk_swapchain->render_finished_semaphores[
+ BluCat::INT::core.vk_swapchain->current_frame]};
VkSubmitInfo submit_info{};
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -370,11 +454,11 @@ Renderer::draw()
submit_info.pSignalSemaphores = signal_semaphores;
if(vkQueueSubmit(
- queue.queue, 1, &submit_info, cg_core.vk_swapchain->in_flight_fences[
- cg_core.vk_swapchain->current_frame]) != VK_SUCCESS)
+ queue.queue, 1, &submit_info, BluCat::INT::core.vk_swapchain->in_flight_fences[
+ BluCat::INT::core.vk_swapchain->current_frame]) != VK_SUCCESS)
throw std::runtime_error{"Failed to submit draw command buffer."};
- VkSwapchainKHR swap_chains[]{cg_core.vk_swapchain->swapchain};
+ VkSwapchainKHR swap_chains[]{BluCat::INT::core.vk_swapchain->swapchain};
VkPresentInfoKHR present_info{};
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
@@ -394,19 +478,20 @@ Renderer::draw()
this->skeletal_models_to_draw[next_frame].clear();
this->static_models_to_draw[next_frame].clear();
this->sprites_3d_to_draw[next_frame].clear();
- cg_core.vk_swapchain->current_frame = next_frame;
+ BluCat::INT::core.vk_swapchain->current_frame = next_frame;
}
}
else
{
// Clear images for the current frame because we are skipping this frame.
- this->skeletal_models_to_draw[cg_core.vk_swapchain->current_frame].clear();
- this->static_models_to_draw[cg_core.vk_swapchain->current_frame].clear();
- this->sprites_3d_to_draw[cg_core.vk_swapchain->current_frame].clear();
- for(auto &view: this->views_2d)
- view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear();
- for(auto &view: this->views_3d)
- view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear();
+ this->skeletal_models_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame].clear();
+ this->static_models_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame].clear();
+ this->sprites_3d_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/blucat/renderer.hpp b/src/blu_cat/gra/renderer.hpp
index d23ebe5..58b9972 100644
--- a/src/blucat/renderer.hpp
+++ b/src/blu_cat/gra/renderer.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,24 +14,25 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_RENDERER_H
-#define CANDY_GEAR_BLUCAT_RENDERER_H 1
+#ifndef BLU_CAT_GRA_RENDERER_H
+#define BLU_CAT_GRA_RENDERER_H 1
#include <initializer_list>
#include <memory>
#include <vector>
-#include "core.hpp"
+#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
+namespace BluCat::GRA
{
struct Renderer
@@ -51,22 +52,35 @@ struct Renderer
std::vector<std::vector<std::shared_ptr<Sprite3D>>> sprites_3d_to_draw;
VkDescriptorPool descriptor_pool;
- std::vector<std::shared_ptr<View2D>> views_2d;
- std::vector<std::shared_ptr<View3D>> views_3d;
+ VkClearColorValue clear_screen_color;
+
+ 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
+ wait_frame();
+
void
draw();
};
}
-#endif /* CANDY_GEAR_BLUCAT_RENDERER_H */
+#endif /* BLU_CAT_GRA_RENDERER_H */
diff --git a/src/blu_cat/gra/skeletal_mesh.cpp b/src/blu_cat/gra/skeletal_mesh.cpp
new file mode 100644
index 0000000..1515dda
--- /dev/null
+++ b/src/blu_cat/gra/skeletal_mesh.cpp
@@ -0,0 +1,252 @@
+/*
+ * 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.
+ * 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 "skeletal_mesh.hpp"
+
+#include "../com/binary_reader.hpp"
+#include "../com/command.hpp"
+#include "../int/core.hpp"
+#include "skeletal_mesh_vertex.hpp"
+
+namespace
+{
+
+struct StaticMeshHeader
+{
+ char file_magic[8];
+ UI32 version;
+ UI32 num_vertexes;
+ UI32 num_indexes;
+ UI32 num_bones;
+ UI32 num_animations;
+ UI32 num_bone_transforms; // For all animations
+ UI32 num_bone_positions; // For all animations
+ UI32 num_bone_rotations; // For all animations
+ UI32 num_bone_scales; // For all animations
+};
+
+constexpr UI64F SKELETAL_MESH_HEADER_SIZE{44};
+
+// Data that is only needed for the command chain but not for the SkeletalMesh
+// goes here.
+struct MeshBuilder
+{
+ std::string mesh_path;
+ BluCat::GRA::SkeletalMesh *mesh;
+
+ MeshBuilder(BluCat::GRA::SkeletalMesh *m, std::string mp);
+ MeshBuilder(BluCat::GRA::SkeletalMesh *m, const char* mp);
+};
+
+MeshBuilder::MeshBuilder(BluCat::GRA::SkeletalMesh *m, std::string mp):
+ mesh{m},
+ mesh_path{mp}
+{
+}
+
+MeshBuilder::MeshBuilder(BluCat::GRA::SkeletalMesh *m, const char *mp):
+ MeshBuilder{m, std::string(mp)}
+{
+}
+
+void
+load_mesh(void *obj)
+{
+ auto self = static_cast<MeshBuilder*>(obj);
+
+ StaticMeshHeader header;
+ BinaryReader input{self->mesh_path};
+
+ { // Read header
+ input.read_chars(header.file_magic, 8);
+ header.version = input.read_ui32();
+ header.num_vertexes = input.read_ui32();
+ header.num_indexes = input.read_ui32();
+ header.num_bones = input.read_ui32();
+ header.num_animations = input.read_ui32();
+ header.num_bone_transforms = input.read_ui32();
+ header.num_bone_positions = input.read_ui32();
+ header.num_bone_rotations = input.read_ui32();
+ header.num_bone_scales = input.read_ui32();
+
+ size_t total_file_size{
+ SKELETAL_MESH_HEADER_SIZE +
+ header.num_vertexes * 16 * SIZE_32_BIT +
+ header.num_indexes * SIZE_32_BIT +
+ header.num_bones * 16 * SIZE_32_BIT +
+ header.num_animations * (2 * SIZE_64_BIT + SIZE_32_BIT) +
+ header.num_bone_transforms * 4 * SIZE_32_BIT +
+ header.num_bone_positions * (3 * SIZE_32_BIT + SIZE_64_BIT) +
+ header.num_bone_rotations * (4 * SIZE_32_BIT + SIZE_64_BIT) +
+ header.num_bone_scales * (3 * SIZE_32_BIT + SIZE_64_BIT)};
+
+ if(total_file_size != input.size())
+ {
+ std::string error{"File size does not match header information: "};
+ error += self->mesh_path;
+ throw CommandError{error};
+ }
+ }
+
+ self->mesh->queue_family =
+ BluCat::INT::core.vk_device_with_swapchain->
+ get_queue_family_with_graphics();
+
+ { // Load vertexes.
+ std::vector<BluCat::GRA::SkeletalMeshVertex> vertexes{header.num_vertexes};
+
+ for(auto i{0}; i < header.num_vertexes; i++)
+ {
+ vertexes[i].position = input.read_vec3();
+ vertexes[i].normal = input.read_vec3();
+ vertexes[i].texture_coord = input.read_vec2();
+
+ for(auto ii{0};
+ ii < BluCat::GRA::SKELETAL_MESH_MAX_NUM_OF_INFLUENCING_BONES;
+ ii++)
+ vertexes[i].bone_ids[ii] = input.read_ui32();
+
+ for(auto ii{0};
+ ii < BluCat::GRA::SKELETAL_MESH_MAX_NUM_OF_INFLUENCING_BONES;
+ ii++)
+ vertexes[i].bone_weights[ii] = input.read_f32();
+ }
+
+ void *vertexes_data{vertexes.data()};
+ size_t vertexes_size = sizeof(vertexes[0]) * vertexes.size();
+ self->mesh->source_vertex_buffer = new BluCat::GRA::SourceBuffer{
+ self->mesh->queue_family->device, vertexes_data, vertexes_size};
+ self->mesh->vertex_buffer = new BluCat::GRA::DestinationBuffer{
+ self->mesh->queue_family, self->mesh->source_vertex_buffer,
+ VK_BUFFER_USAGE_VERTEX_BUFFER_BIT};
+ }
+
+ { // Load indexes.
+ self->mesh->index_count = header.num_indexes;
+ std::vector<uint32_t> indexes(self->mesh->index_count);
+
+ for(auto i{0}; i < self->mesh->index_count; i++)
+ indexes[i] = input.read_ui32();
+
+ void *indexes_data{indexes.data()};
+ size_t indexes_size{sizeof(indexes[0]) * indexes.size()};
+ BluCat::GRA::SourceBuffer source_index_buffer{
+ self->mesh->queue_family->device, indexes_data, indexes_size};
+ self->mesh->index_buffer = new BluCat::GRA::DestinationBuffer{
+ self->mesh->queue_family, &source_index_buffer,
+ VK_BUFFER_USAGE_INDEX_BUFFER_BIT};
+ }
+
+ { // Load bones
+ self->mesh->bones.reserve(header.num_bones);
+ for(int i{0}; i < header.num_bones; i++)
+ self->mesh->bones.emplace_back(input.read_mat4());
+ }
+
+ { // Load animations
+ self->mesh->animations.resize(header.num_animations);
+ for(uint32_t i{0}; i < header.num_animations; i++)
+ {
+ auto duration{input.read_f64()};
+ self->mesh->animations[i].final_time = (float)duration;
+
+ auto ticks_per_second{input.read_f64()};
+
+ auto num_bone_transforms{input.read_ui32()};
+ std::vector<BluCat::GRA::BoneTransform> *bone_transforms =
+ &(self->mesh->animations[i].bone_transforms);
+ bone_transforms->resize(num_bone_transforms);
+ for(uint32_t bone_transform_index{0};
+ bone_transform_index < num_bone_transforms; bone_transform_index++)
+ {
+ auto bone_id{input.read_ui32()};
+
+ auto num_positions{input.read_ui32()};
+ BluCat::GRA::Channel<glm::vec3> *positions =
+ &((*bone_transforms)[bone_transform_index].positions);
+ for(auto position_key_index{0}; position_key_index < num_positions;
+ position_key_index++)
+ {
+ auto vec3{input.read_vec3()};
+ auto timestamp{input.read_f64()};
+ positions->key_frames.emplace_back(
+ vec3, static_cast<float>(timestamp));
+ }
+
+ auto num_rotations{input.read_ui32()};
+ BluCat::GRA::Channel<glm::quat> *rotations =
+ &((*bone_transforms)[bone_transform_index].rotations);
+ for(auto rotation_key_index{0}; rotation_key_index < num_rotations;
+ rotation_key_index++)
+ {
+ auto quat{input.read_quat()};
+ auto timestamp{input.read_f64()};
+ rotations->key_frames.emplace_back(
+ quat, static_cast<float>(timestamp));
+ }
+
+ auto num_scales{input.read_ui32()};
+ BluCat::GRA::Channel<glm::vec3> *scales =
+ &((*bone_transforms)[bone_transform_index].scales);
+ for(auto scaling_key_index{0}; scaling_key_index < num_scales;
+ scaling_key_index++)
+ {
+ auto vec3{input.read_vec3()};
+ auto timestamp{input.read_f64()};
+ scales->key_frames.emplace_back(vec3, static_cast<float>(timestamp));
+ }
+ }
+ }
+ }
+}
+
+void
+unload_mesh(void *obj)
+{
+ auto self = static_cast<MeshBuilder*>(obj);
+
+ delete self->mesh->index_buffer;
+ delete self->mesh->vertex_buffer;
+ delete self->mesh->source_vertex_buffer;
+}
+
+static const CommandChain loader{
+ {&load_mesh, &unload_mesh}
+};
+
+}
+
+namespace BluCat::GRA
+{
+
+SkeletalMesh::SkeletalMesh(std::string mesh_path)
+{
+ MeshBuilder mesh_builder(this, mesh_path);
+ loader.execute(&mesh_builder);
+}
+
+SkeletalMesh::SkeletalMesh(const char* mesh_path):
+ SkeletalMesh{std::string(mesh_path)}
+{
+}
+
+SkeletalMesh::~SkeletalMesh()
+{
+ MeshBuilder mesh_builder(this, "");
+ loader.revert(&mesh_builder);
+}
+
+}
diff --git a/src/blucat/skeletal_mesh.hpp b/src/blu_cat/gra/skeletal_mesh.hpp
index 8b7d0fe..f586ea3 100644
--- a/src/blucat/skeletal_mesh.hpp
+++ b/src/blu_cat/gra/skeletal_mesh.hpp
@@ -14,20 +14,20 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SKELETAL_MESH_H
-#define CANDY_GEAR_BLUCAT_SKELETAL_MESH_H 1
+#ifndef BLU_CAT_GRA_SKELETAL_MESH_H
+#define BLU_CAT_GRA_SKELETAL_MESH_H 1
#include <string>
#include <vector>
#include "animation.hpp"
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
#include "texture.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct SkeletalMesh
@@ -49,4 +49,4 @@ struct SkeletalMesh
}
-#endif /* CANDY_GEAR_BLUCAT_SKELETAL_MESH_H */
+#endif /* BLU_CAT_GRA_SKELETAL_MESH_H */
diff --git a/src/blucat/skeletal_mesh_vertex.hpp b/src/blu_cat/gra/skeletal_mesh_vertex.hpp
index 533c2ab..1bd70ad 100644
--- a/src/blucat/skeletal_mesh_vertex.hpp
+++ b/src/blu_cat/gra/skeletal_mesh_vertex.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SKELETAL_MESH_VERTEX_H
-#define CANDY_GEAR_BLUCAT_SKELETAL_MESH_VERTEX_H 1
+#ifndef BLU_CAT_GRA_SKELETAL_MESH_VERTEX_H
+#define BLU_CAT_GRA_SKELETAL_MESH_VERTEX_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
// This variable define the maximum ammount of bones that can influence a
@@ -39,4 +39,4 @@ struct SkeletalMeshVertex
}
-#endif /* CANDY_GEAR_BLUCAT_SKELETAL_MESH_VERTEX_H */
+#endif /* BLU_CAT_GRA_SKELETAL_MESH_VERTEX_H */
diff --git a/src/blucat/skeletal_model.cpp b/src/blu_cat/gra/skeletal_model.cpp
index 8761bc8..4b44910 100644
--- a/src/blucat/skeletal_model.cpp
+++ b/src/blu_cat/gra/skeletal_model.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.
@@ -16,7 +16,7 @@
#include "skeletal_model.hpp"
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -25,14 +25,15 @@ namespace
void
load_uniform_buffers(void *obj)
{
- auto self = static_cast<BluCat::SkeletalModel*>(obj);
+ auto self = static_cast<BluCat::GRA::SkeletalModel*>(obj);
try
{
- self->uniform_buffers.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->uniform_buffers.reserve(BluCat::INT::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
self->uniform_buffers.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOSkeletalModel));
+ BluCat::INT::core.vk_device_with_swapchain,
+ sizeof(BluCat::GRA::UDOSkeletalModel));
}
catch(const std::exception& e)
{
@@ -43,7 +44,7 @@ load_uniform_buffers(void *obj)
void
unload_uniform_buffers(void *obj)
{
- auto self = static_cast<BluCat::SkeletalModel*>(obj);
+ auto self = static_cast<BluCat::GRA::SkeletalModel*>(obj);
self->uniform_buffers.clear();
}
@@ -51,7 +52,7 @@ unload_uniform_buffers(void *obj)
void
load_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::SkeletalModel*>(obj);
+ auto self = static_cast<BluCat::GRA::SkeletalModel*>(obj);
std::array<VkDescriptorPoolSize, 1> descriptor_pool_sizes{};
descriptor_pool_sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
@@ -75,7 +76,7 @@ load_descriptor_set_pool(void *obj)
void
unload_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::SkeletalModel*>(obj);
+ auto self = static_cast<BluCat::GRA::SkeletalModel*>(obj);
vkDestroyDescriptorPool(
self->skeletal_mesh->queue_family->device->device, self->descriptor_pool,
@@ -85,11 +86,11 @@ unload_descriptor_set_pool(void *obj)
void
load_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::SkeletalModel*>(obj);
+ auto self = static_cast<BluCat::GRA::SkeletalModel*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->model);
+ BluCat::INT::core.vk_swapchain->images_count,
+ BluCat::INT::core.vk_descriptor_set_layout->model);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -107,14 +108,14 @@ load_descriptor_sets(void *obj)
void
load_buffers_to_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::SkeletalModel*>(obj);
+ auto self = static_cast<BluCat::GRA::SkeletalModel*>(obj);
for(auto i{0}; i < self->uniform_buffers.size(); i++)
{
VkDescriptorBufferInfo buffer_info{};
buffer_info.buffer = self->uniform_buffers[i].buffer;
buffer_info.offset = 0;
- buffer_info.range = sizeof(BluCat::UDOSkeletalModel);
+ buffer_info.range = sizeof(BluCat::GRA::UDOSkeletalModel);
std::array<VkWriteDescriptorSet, 1> write_descriptors{};
write_descriptors[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
@@ -128,7 +129,7 @@ load_buffers_to_descriptor_sets(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -142,7 +143,7 @@ static const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
SkeletalModel::SkeletalModel(
@@ -171,7 +172,7 @@ SkeletalModel::~SkeletalModel()
void
SkeletalModel::tick(float delta)
{
- BluCat::Animation *current_animation =
+ BluCat::GRA::Animation *current_animation =
&this->skeletal_mesh->animations[this->animation_index];
{ // update time
@@ -179,7 +180,7 @@ SkeletalModel::tick(float delta)
if(this->animation_time > current_animation->final_time)
{
this->animation_time -= current_animation->final_time;
- for(BluCat::BoneTransform &bone_transform:
+ for(BluCat::GRA::BoneTransform &bone_transform:
current_animation->bone_transforms)
{
bone_transform.positions.current_index = 0;
@@ -191,47 +192,50 @@ SkeletalModel::tick(float delta)
for(int i{0}; i < current_animation->bone_transforms.size(); i++)
{
- BluCat::BoneTransform *bone_transform = &current_animation->bone_transforms[i];
+ BluCat::GRA::BoneTransform *bone_transform =
+ &current_animation->bone_transforms[i];
auto position{bone_transform->positions.interpolate(
- this->animation_time,
- [](glm::vec3 frame)
- {
- return glm::translate(glm::mat4(1.0f), frame);
- },
- [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
- {
- glm::vec3 final_position{glm::mix(
- previous_frame, next_frame, scale_factor)};
- return glm::translate(glm::mat4(1.0f), final_position);
- })};
+ this->animation_time,
+ [](glm::vec3 frame)
+ {
+ return glm::translate(glm::mat4(1.0f), frame);
+ },
+ [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
+ {
+ glm::vec3 final_position{glm::mix(
+ previous_frame, next_frame, scale_factor)};
+ return glm::translate(glm::mat4(1.0f), final_position);
+ })};
auto rotation{bone_transform->rotations.interpolate(
- this->animation_time,
- [](glm::quat frame)
- {
- return glm::toMat4(glm::normalize(frame));
- },
- [](glm::quat previous_frame, glm::quat next_frame, float scale_factor)
- {
- return glm::toMat4(glm::slerp(
- previous_frame, next_frame, scale_factor));
- })};
+ this->animation_time,
+ [](glm::quat frame)
+ {
+ return glm::toMat4(glm::normalize(frame));
+ },
+ [](glm::quat previous_frame, glm::quat next_frame, float scale_factor)
+ {
+ return glm::toMat4(glm::slerp(
+ previous_frame, next_frame, scale_factor));
+ })};
auto scale{bone_transform->scales.interpolate(
- this->animation_time,
- [](glm::vec3 frame)
- {
- return glm::scale(glm::mat4(1.0f), frame);
- },
- [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
- {
- glm::vec3 scale{glm::mix(
- previous_frame, next_frame, scale_factor)};
- return glm::scale(glm::mat4(1.0f), scale);
- })};
-
- this->bone_transforms[i] = position * rotation * scale;
+ this->animation_time,
+ [](glm::vec3 frame)
+ {
+ return glm::scale(glm::mat4(1.0f), frame);
+ },
+ [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
+ {
+ glm::vec3 scale{glm::mix(
+ previous_frame, next_frame, scale_factor)};
+ return glm::scale(glm::mat4(1.0f), scale);
+ })};
+
+ this->bone_transforms[i] =
+ this->skeletal_mesh->bones[i].offset_matrix *
+ (position * rotation * scale);
}
}
diff --git a/src/blucat/skeletal_model.hpp b/src/blu_cat/gra/skeletal_model.hpp
index cd3685e..73998cb 100644
--- a/src/blucat/skeletal_model.hpp
+++ b/src/blu_cat/gra/skeletal_model.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SKELETAL_MODEL_H
-#define CANDY_GEAR_BLUCAT_SKELETAL_MODEL_H 1
+#ifndef BLU_CAT_GRA_SKELETAL_MODEL_H
+#define BLU_CAT_GRA_SKELETAL_MODEL_H 1
#include <memory>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "skeletal_mesh.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct SkeletalModel
@@ -52,4 +52,4 @@ struct SkeletalModel
}
-#endif /* CANDY_GEAR_BLUCAT_SKELETAL_MODEL_H */
+#endif /* BLU_CAT_GRA_SKELETAL_MODEL_H */
diff --git a/src/blucat/source_buffer.cpp b/src/blu_cat/gra/source_buffer.cpp
index 41c40b9..18f263f 100644
--- a/src/blucat/source_buffer.cpp
+++ b/src/blu_cat/gra/source_buffer.cpp
@@ -18,7 +18,7 @@
#include <cstring>
-namespace BluCat
+namespace BluCat::GRA
{
SourceBuffer::SourceBuffer(Device *device, void *data, size_t data_size)
@@ -31,7 +31,7 @@ SourceBuffer::SourceBuffer(Device *device, void *data, size_t data_size)
try
{
- BluCat::BaseBuffer::loader.execute(static_cast<BluCat::BaseBuffer*>(this));
+ BluCat::GRA::BaseBuffer::loader.execute(static_cast<BluCat::GRA::BaseBuffer*>(this));
}
catch(const CommandError &command_error)
{
@@ -71,7 +71,7 @@ SourceBuffer::operator=(SourceBuffer &&that)
SourceBuffer::~SourceBuffer()
{
- BluCat::BaseBuffer::loader.revert(static_cast<BluCat::BaseBuffer*>(this));
+ BluCat::GRA::BaseBuffer::loader.revert(static_cast<BluCat::GRA::BaseBuffer*>(this));
}
void
diff --git a/src/blucat/source_buffer.hpp b/src/blu_cat/gra/source_buffer.hpp
index dd52acc..4eecec9 100644
--- a/src/blucat/source_buffer.hpp
+++ b/src/blu_cat/gra/source_buffer.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SOURCE_BUFFER_H
-#define CANDY_GEAR_BLUCAT_SOURCE_BUFFER_H 1
+#ifndef BLU_CAT_GRA_SOURCE_BUFFER_H
+#define BLU_CAT_GRA_SOURCE_BUFFER_H 1
#include "base_buffer.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct SourceBuffer: public BaseBuffer
@@ -42,4 +42,4 @@ struct SourceBuffer: public BaseBuffer
}
-#endif /* CANDY_GEAR_BLUCAT_SOURCE_BUFFER_H */
+#endif /* BLU_CAT_GRA_SOURCE_BUFFER_H */
diff --git a/src/blucat/sprite.cpp b/src/blu_cat/gra/sprite.cpp
index a275df8..ee64efe 100644
--- a/src/blucat/sprite.cpp
+++ b/src/blu_cat/gra/sprite.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -27,13 +27,13 @@ namespace
struct SpriteBuilder
{
- BluCat::Sprite *sprite;
- glm::vec4 &rect;
+ BluCat::GRA::Sprite *sprite;
+ const glm::vec4 &rect;
- SpriteBuilder(BluCat::Sprite *sprite, glm::vec4 &rect);
+ SpriteBuilder(BluCat::GRA::Sprite *sprite, const glm::vec4 &rect);
};
-SpriteBuilder::SpriteBuilder(BluCat::Sprite *sprite, glm::vec4 &rect):
+SpriteBuilder::SpriteBuilder(BluCat::GRA::Sprite *sprite, const glm::vec4 &rect):
sprite{sprite},
rect{rect}
{
@@ -45,9 +45,9 @@ load_mesh(void *obj)
auto self = static_cast<SpriteBuilder*>(obj);
self->sprite->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::INT::core.vk_device_with_swapchain->get_queue_family_with_graphics();
- glm::vec2 rect[BluCat::Sprite::vertex_count]{
+ glm::vec2 rect[BluCat::GRA::Sprite::vertex_count]{
glm::vec2{self->rect.x, self->rect.y},
glm::vec2{self->rect.x, self->rect.w},
glm::vec2{self->rect.z, self->rect.y},
@@ -56,10 +56,10 @@ load_mesh(void *obj)
void *vertexes_data{&rect};
static const size_t vertexes_size =
- sizeof(glm::vec2) * BluCat::Sprite::vertex_count;
- self->sprite->source_buffer = new BluCat::SourceBuffer{
+ sizeof(glm::vec2) * BluCat::GRA::Sprite::vertex_count;
+ self->sprite->source_buffer = new BluCat::GRA::SourceBuffer{
self->sprite->queue_family->device, vertexes_data, vertexes_size};
- self->sprite->vertex_buffer = new BluCat::DestinationBuffer{
+ self->sprite->vertex_buffer = new BluCat::GRA::DestinationBuffer{
self->sprite->queue_family, self->sprite->source_buffer,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT};
}
@@ -79,10 +79,10 @@ static const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
-Sprite::Sprite(std::shared_ptr<Texture> texture, glm::vec4 &rect):
+Sprite::Sprite(std::shared_ptr<Texture> texture, const glm::vec4 &rect):
texture{texture}
{
SpriteBuilder sprite_builder(this, rect);
diff --git a/src/blucat/sprite.hpp b/src/blu_cat/gra/sprite.hpp
index 6252d00..1834b22 100644
--- a/src/blucat/sprite.hpp
+++ b/src/blu_cat/gra/sprite.hpp
@@ -14,20 +14,20 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SPRITE_H
-#define CANDY_GEAR_BLUCAT_SPRITE_H 1
+#ifndef BLU_CAT_GRA_SPRITE_H
+#define BLU_CAT_GRA_SPRITE_H 1
#include <memory>
#include <unordered_map>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
#include "texture.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Sprite
@@ -41,10 +41,10 @@ struct Sprite
std::shared_ptr<Texture> texture;
- Sprite(std::shared_ptr<Texture> texture, glm::vec4 &rect);
+ Sprite(std::shared_ptr<Texture> texture, const glm::vec4 &rect);
~Sprite();
};
}
-#endif /* CANDY_GEAR_BLUCAT_SPRITE_H */
+#endif /* BLU_CAT_GRA_SPRITE_H */
diff --git a/src/blucat/sprite_3d.cpp b/src/blu_cat/gra/sprite_3d.cpp
index 6fa6d49..fc994a6 100644
--- a/src/blucat/sprite_3d.cpp
+++ b/src/blu_cat/gra/sprite_3d.cpp
@@ -16,7 +16,7 @@
#include "sprite_3d.hpp"
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -25,14 +25,14 @@ namespace
void
load_uniform_buffers(void *obj)
{
- auto self = static_cast<BluCat::Sprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::Sprite3D*>(obj);
try
{
- self->uniform_buffers.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->uniform_buffers.reserve(BluCat::INT::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
self->uniform_buffers.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOSprite3D));
+ BluCat::INT::core.vk_device_with_swapchain, sizeof(BluCat::GRA::UDOSprite3D));
}
catch(const std::exception& e)
{
@@ -43,7 +43,7 @@ load_uniform_buffers(void *obj)
void
unload_uniform_buffers(void *obj)
{
- auto self = static_cast<BluCat::Sprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::Sprite3D*>(obj);
self->uniform_buffers.clear();
}
@@ -51,7 +51,7 @@ unload_uniform_buffers(void *obj)
void
load_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::Sprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::Sprite3D*>(obj);
std::array<VkDescriptorPoolSize, 1> descriptor_pool_sizes{};
descriptor_pool_sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
@@ -75,7 +75,7 @@ load_descriptor_set_pool(void *obj)
void
unload_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::Sprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::Sprite3D*>(obj);
vkDestroyDescriptorPool(
self->queue_family->device->device, self->descriptor_pool, nullptr);
@@ -83,11 +83,11 @@ unload_descriptor_set_pool(void *obj)
void
load_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::Sprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::Sprite3D*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->model);
+ BluCat::INT::core.vk_swapchain->images_count,
+ BluCat::INT::core.vk_descriptor_set_layout->model);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -105,14 +105,14 @@ load_descriptor_sets(void *obj)
void
load_buffers_to_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::Sprite3D*>(obj);
+ auto self = static_cast<BluCat::GRA::Sprite3D*>(obj);
for(auto i{0}; i < self->uniform_buffers.size(); i++)
{
VkDescriptorBufferInfo buffer_info{};
buffer_info.buffer = self->uniform_buffers[i].buffer;
buffer_info.offset = 0;
- buffer_info.range = sizeof(BluCat::UDOSprite3D);
+ buffer_info.range = sizeof(BluCat::GRA::UDOSprite3D);
VkDescriptorImageInfo image_info{};
image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@@ -131,7 +131,7 @@ load_buffers_to_descriptor_sets(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -145,18 +145,18 @@ static const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
Sprite3D::Sprite3D(
- std::shared_ptr<BluCat::Sprite> sprite, std::shared_ptr<glm::vec3> position,
+ std::shared_ptr<BluCat::GRA::Sprite> sprite, std::shared_ptr<glm::vec3> position,
glm::vec2 size):
sprite{sprite},
position{position},
size{size}
{
this->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::INT::core.vk_device_with_swapchain->get_queue_family_with_graphics();
loader.execute(this);
}
diff --git a/src/blucat/sprite_3d.hpp b/src/blu_cat/gra/sprite_3d.hpp
index dd0f16e..0cd8c04 100644
--- a/src/blucat/sprite_3d.hpp
+++ b/src/blu_cat/gra/sprite_3d.hpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SPRITE_3D_H
-#define CANDY_GEAR_BLUCAT_SPRITE_3D_H 1
+#ifndef BLU_CAT_GRA_SPRITE_3D_H
+#define BLU_CAT_GRA_SPRITE_3D_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
#include "sprite.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Sprite3D
@@ -43,4 +43,4 @@ struct Sprite3D
}
-#endif /* CANDY_GEAR_BLUCAT_SPRITE_3D_H */
+#endif /* BLU_CAT_GRA_SPRITE_3D_H */
diff --git a/src/blucat/sprite_to_draw.cpp b/src/blu_cat/gra/sprite_to_draw.cpp
index 9013adb..7645d73 100644
--- a/src/blucat/sprite_to_draw.cpp
+++ b/src/blu_cat/gra/sprite_to_draw.cpp
@@ -16,7 +16,7 @@
#include "sprite_to_draw.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
SpriteToDraw::SpriteToDraw(
std::shared_ptr<Sprite> sprite, const glm::vec4 &position, float z_index):
diff --git a/src/blucat/sprite_to_draw.hpp b/src/blu_cat/gra/sprite_to_draw.hpp
index fb46eac..e7a23c4 100644
--- a/src/blucat/sprite_to_draw.hpp
+++ b/src/blu_cat/gra/sprite_to_draw.hpp
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SPRITES_TO_DRAW_H
-#define CANDY_GEAR_BLUCAT_SPRITES_TO_DRAW_H 1
+#ifndef BLU_CAT_GRA_SPRITES_TO_DRAW_H
+#define BLU_CAT_GRA_SPRITES_TO_DRAW_H 1
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "sprite.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct SpriteToDraw
{
@@ -41,4 +41,4 @@ namespace BluCat
operator>(const SpriteToDraw &a, const SpriteToDraw &b);
}
-#endif /* CANDY_GEAR_BLUCAT_SPRITES_TO_DRAW_H */
+#endif /* BLU_CAT_GRA_SPRITES_TO_DRAW_H */
diff --git a/src/blucat/static_mesh.cpp b/src/blu_cat/gra/static_mesh.cpp
index ab45ca9..0b6088c 100644
--- a/src/blucat/static_mesh.cpp
+++ b/src/blu_cat/gra/static_mesh.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.
@@ -16,32 +16,42 @@
#include "static_mesh.hpp"
-#include "../binary_reader.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "../com/binary_reader.hpp"
+#include "../com/command.hpp"
+#include "../int/core.hpp"
#include "static_mesh_vertex.hpp"
namespace
{
+struct StaticMeshHeader
+{
+ char file_magic[8];
+ UI32 version;
+ UI32 num_vertexes;
+ UI32 num_indexes;
+};
+
+constexpr UI64F STATIC_MESH_HEADER_SIZE{20};
+
// Data that is only needed for the command chain but not for the StaticMesh
// goes here.
struct MeshBuilder
{
std::string mesh_path;
- BluCat::StaticMesh *mesh;
+ BluCat::GRA::StaticMesh *mesh;
- MeshBuilder(BluCat::StaticMesh *m, std::string mp);
- MeshBuilder(BluCat::StaticMesh *m, const char* mp);
+ MeshBuilder(BluCat::GRA::StaticMesh *m, std::string mp);
+ MeshBuilder(BluCat::GRA::StaticMesh *m, const char* mp);
};
-MeshBuilder::MeshBuilder(BluCat::StaticMesh *m, std::string mp):
+MeshBuilder::MeshBuilder(BluCat::GRA::StaticMesh *m, std::string mp):
mesh{m},
mesh_path{mp}
{
}
-MeshBuilder::MeshBuilder(BluCat::StaticMesh *m, const char *mp):
+MeshBuilder::MeshBuilder(BluCat::GRA::StaticMesh *m, const char *mp):
MeshBuilder{m, std::string(mp)}
{
}
@@ -51,16 +61,36 @@ load_mesh(void *obj)
{
auto self = static_cast<MeshBuilder*>(obj);
+ self->mesh->queue_family =
+ BluCat::INT::core.vk_device_with_swapchain->
+ get_queue_family_with_graphics();
+
+ StaticMeshHeader header;
BinaryReader input{self->mesh_path};
- self->mesh->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ { // Read header
+ input.read_chars(header.file_magic, 8);
+ header.version = input.read_ui32();
+ header.num_vertexes = input.read_ui32();
+ header.num_indexes = input.read_ui32();
+
+ size_t total_file_size{
+ STATIC_MESH_HEADER_SIZE +
+ header.num_vertexes * 8 * SIZE_32_BIT +
+ header.num_indexes * SIZE_32_BIT};
+
+ if(total_file_size != input.size())
+ {
+ std::string error{"File size does not match header information: "};
+ error += self->mesh_path;
+ throw CommandError{error};
+ }
+ }
{ // Load vertexes.
- auto vertex_count{input.read_ui32()};
- std::vector<BluCat::StaticMeshVertex> vertexes{vertex_count};
+ std::vector<BluCat::GRA::StaticMeshVertex> vertexes{header.num_vertexes};
- for(auto i{0}; i < vertex_count; i++)
+ for(auto i{0}; i < header.num_vertexes; i++)
{
vertexes[i].position = input.read_vec3();
vertexes[i].normal = input.read_vec3();
@@ -69,15 +99,15 @@ load_mesh(void *obj)
void *vertexes_data{vertexes.data()};
size_t vertexes_size = sizeof(vertexes[0]) * vertexes.size();
- self->mesh->source_vertex_buffer = new BluCat::SourceBuffer{
+ self->mesh->source_vertex_buffer = new BluCat::GRA::SourceBuffer{
self->mesh->queue_family->device, vertexes_data, vertexes_size};
- self->mesh->vertex_buffer = new BluCat::DestinationBuffer{
+ self->mesh->vertex_buffer = new BluCat::GRA::DestinationBuffer{
self->mesh->queue_family, self->mesh->source_vertex_buffer,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT};
}
{ // Load indexes
- self->mesh->index_count = input.read_ui32();
+ self->mesh->index_count = header.num_indexes;
std::vector<uint32_t> indexes(self->mesh->index_count);
for(auto i{0}; i < self->mesh->index_count; i++)
@@ -85,9 +115,9 @@ load_mesh(void *obj)
void *indexes_data{indexes.data()};
size_t indexes_size{sizeof(indexes[0]) * indexes.size()};
- BluCat::SourceBuffer source_index_buffer{
+ BluCat::GRA::SourceBuffer source_index_buffer{
self->mesh->queue_family->device, indexes_data, indexes_size};
- self->mesh->index_buffer = new BluCat::DestinationBuffer{
+ self->mesh->index_buffer = new BluCat::GRA::DestinationBuffer{
self->mesh->queue_family, &source_index_buffer,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT};
}
@@ -109,7 +139,7 @@ static const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
StaticMesh::StaticMesh(std::string mesh_path)
diff --git a/src/blucat/static_mesh.hpp b/src/blu_cat/gra/static_mesh.hpp
index 0efcfc1..2b059fe 100644
--- a/src/blucat/static_mesh.hpp
+++ b/src/blu_cat/gra/static_mesh.hpp
@@ -14,19 +14,19 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_STATIC_MESH_H
-#define CANDY_GEAR_BLUCAT_STATIC_MESH_H 1
+#ifndef BLU_CAT_GRA_STATIC_MESH_H
+#define BLU_CAT_GRA_STATIC_MESH_H 1
#include <string>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
#include "texture.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct StaticMesh
@@ -45,4 +45,4 @@ struct StaticMesh
}
-#endif /* CANDY_GEAR_BLUCAT_STATIC_MESH_H */
+#endif /* BLU_CAT_GRA_STATIC_MESH_H */
diff --git a/src/blucat/static_mesh_vertex.hpp b/src/blu_cat/gra/static_mesh_vertex.hpp
index 025ad63..510ce40 100644
--- a/src/blucat/static_mesh_vertex.hpp
+++ b/src/blu_cat/gra/static_mesh_vertex.hpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_STATIC_MESH_VERTEX_H
-#define CANDY_GEAR_BLUCAT_STATIC_MESH_VERTEX_H 1
+#ifndef BLU_CAT_GRA_STATIC_MESH_VERTEX_H
+#define BLU_CAT_GRA_STATIC_MESH_VERTEX_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct StaticMeshVertex
@@ -31,4 +31,4 @@ struct StaticMeshVertex
}
-#endif /* CANDY_GEAR_BLUCAT_STATIC_MESH_VERTEX_H */
+#endif /* BLU_CAT_GRA_STATIC_MESH_VERTEX_H */
diff --git a/src/blucat/static_model.cpp b/src/blu_cat/gra/static_model.cpp
index e3c6482..50dc94d 100644
--- a/src/blucat/static_model.cpp
+++ b/src/blu_cat/gra/static_model.cpp
@@ -16,7 +16,7 @@
#include "static_model.hpp"
-#include "../core.hpp"
+#include "../int/core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -25,14 +25,14 @@ namespace
void
load_uniform_buffers(void *obj)
{
- auto self = static_cast<BluCat::StaticModel*>(obj);
+ auto self = static_cast<BluCat::GRA::StaticModel*>(obj);
try
{
- self->uniform_buffers.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ self->uniform_buffers.reserve(BluCat::INT::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
self->uniform_buffers.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOStaticModel));
+ BluCat::INT::core.vk_device_with_swapchain, sizeof(BluCat::GRA::UDOStaticModel));
}
catch(const std::exception& e)
{
@@ -43,7 +43,7 @@ load_uniform_buffers(void *obj)
void
unload_uniform_buffers(void *obj)
{
- auto self = static_cast<BluCat::StaticModel*>(obj);
+ auto self = static_cast<BluCat::GRA::StaticModel*>(obj);
self->uniform_buffers.clear();
}
@@ -51,7 +51,7 @@ unload_uniform_buffers(void *obj)
void
load_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::StaticModel*>(obj);
+ auto self = static_cast<BluCat::GRA::StaticModel*>(obj);
std::array<VkDescriptorPoolSize, 1> descriptor_pool_sizes{};
descriptor_pool_sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
@@ -75,7 +75,7 @@ load_descriptor_set_pool(void *obj)
void
unload_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::StaticModel*>(obj);
+ auto self = static_cast<BluCat::GRA::StaticModel*>(obj);
vkDestroyDescriptorPool(
self->static_mesh->queue_family->device->device, self->descriptor_pool,
@@ -85,11 +85,11 @@ unload_descriptor_set_pool(void *obj)
void
load_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::StaticModel*>(obj);
+ auto self = static_cast<BluCat::GRA::StaticModel*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->model);
+ BluCat::INT::core.vk_swapchain->images_count,
+ BluCat::INT::core.vk_descriptor_set_layout->model);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -107,14 +107,14 @@ load_descriptor_sets(void *obj)
void
load_buffers_to_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::StaticModel*>(obj);
+ auto self = static_cast<BluCat::GRA::StaticModel*>(obj);
for(auto i{0}; i < self->uniform_buffers.size(); i++)
{
VkDescriptorBufferInfo buffer_info{};
buffer_info.buffer = self->uniform_buffers[i].buffer;
buffer_info.offset = 0;
- buffer_info.range = sizeof(BluCat::UDOStaticModel);
+ buffer_info.range = sizeof(BluCat::GRA::UDOStaticModel);
std::array<VkWriteDescriptorSet, 1> write_descriptors{};
write_descriptors[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
@@ -128,7 +128,7 @@ load_buffers_to_descriptor_sets(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -142,7 +142,7 @@ static const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
StaticModel::StaticModel(
diff --git a/src/blucat/static_model.hpp b/src/blu_cat/gra/static_model.hpp
index 68c5ea1..0d689d0 100644
--- a/src/blucat/static_model.hpp
+++ b/src/blu_cat/gra/static_model.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_STATIC_MODEL_H
-#define CANDY_GEAR_BLUCAT_STATIC_MODEL_H 1
+#ifndef BLU_CAT_GRA_STATIC_MODEL_H
+#define BLU_CAT_GRA_STATIC_MODEL_H 1
#include <memory>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "static_mesh.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct StaticModel
@@ -46,4 +46,4 @@ struct StaticModel
}
-#endif /* CANDY_GEAR_BLUCAT_STATIC_MODEL_H */
+#endif /* BLU_CAT_GRA_STATIC_MODEL_H */
diff --git a/src/blucat/swapchain.cpp b/src/blu_cat/gra/swapchain.cpp
index 1e521e4..f57e3c2 100644
--- a/src/blucat/swapchain.cpp
+++ b/src/blu_cat/gra/swapchain.cpp
@@ -16,7 +16,7 @@
#include "swapchain.hpp"
-#include "../core.hpp"
+#include "../int/core.hpp"
#include <vector>
@@ -26,24 +26,25 @@ namespace
void
load_swapchain(void *obj)
{
- auto self = static_cast<BluCat::Swapchain*>(obj);
+ auto self = static_cast<BluCat::GRA::Swapchain*>(obj);
// Surface formats.
uint32_t vk_surface_format_count;
std::vector<VkSurfaceFormatKHR> vk_surface_formats;
vkGetPhysicalDeviceSurfaceFormatsKHR(
- cg_core.vk_device_with_swapchain->physical_device, cg_core.window_surface,
- &vk_surface_format_count, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->physical_device,
+ BluCat::INT::core.window_surface, &vk_surface_format_count, nullptr);
vk_surface_formats.resize(vk_surface_format_count);
vkGetPhysicalDeviceSurfaceFormatsKHR(
- cg_core.vk_device_with_swapchain->physical_device, cg_core.window_surface,
- &vk_surface_format_count, vk_surface_formats.data());
+ BluCat::INT::core.vk_device_with_swapchain->physical_device,
+ BluCat::INT::core.window_surface, &vk_surface_format_count,
+ vk_surface_formats.data());
VkSwapchainCreateInfoKHR swapchain_create_info = {};
swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapchain_create_info.pNext = nullptr;
swapchain_create_info.flags = 0;
- swapchain_create_info.surface = cg_core.window_surface;
+ swapchain_create_info.surface = BluCat::INT::core.window_surface;
swapchain_create_info.minImageCount = 3; // triple buffering.
self->image_format = vk_surface_formats[0].format;
@@ -51,7 +52,7 @@ load_swapchain(void *obj)
swapchain_create_info.imageColorSpace = vk_surface_formats[0].colorSpace;
swapchain_create_info.imageExtent = {
- cg_core.display_width, cg_core.display_height};
+ BluCat::INT::core.display_width, BluCat::INT::core.display_height};
swapchain_create_info.imageArrayLayers = 1;
swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
@@ -64,33 +65,33 @@ load_swapchain(void *obj)
swapchain_create_info.oldSwapchain = VK_NULL_HANDLE;
if(vkCreateSwapchainKHR(
- cg_core.vk_device_with_swapchain->device, &swapchain_create_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &swapchain_create_info,
nullptr, &self->swapchain) != VK_SUCCESS)
throw CommandError{"Vulkan failed to create swapchain."};
vkGetSwapchainImagesKHR(
- cg_core.vk_device_with_swapchain->device, self->swapchain,
+ BluCat::INT::core.vk_device_with_swapchain->device, self->swapchain,
&self->images_count, nullptr);
self->images = new VkImage[self->images_count];
vkGetSwapchainImagesKHR(
- cg_core.vk_device_with_swapchain->device, self->swapchain,
+ BluCat::INT::core.vk_device_with_swapchain->device, self->swapchain,
&self->images_count, self->images);
}
void
unload_swapchain(void *obj)
{
- auto self = static_cast<BluCat::Swapchain*>(obj);
+ auto self = static_cast<BluCat::GRA::Swapchain*>(obj);
delete[] self->images;
vkDestroySwapchainKHR(
- cg_core.vk_device_with_swapchain->device, self->swapchain, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->swapchain, nullptr);
}
void
load_image_view(void *obj)
{
- auto self = static_cast<BluCat::Swapchain*>(obj);
+ auto self = static_cast<BluCat::GRA::Swapchain*>(obj);
self->image_views = new VkImageView[self->images_count];
for(auto i{0}; i < self->images_count; i++)
@@ -111,7 +112,7 @@ load_image_view(void *obj)
create_info.subresourceRange.layerCount = 1;
if(vkCreateImageView(
- cg_core.vk_device_with_swapchain->device, &create_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &create_info, nullptr,
&self->image_views[i]))
throw CommandError{"Could no create Image View for swapchain."};
}
@@ -120,17 +121,18 @@ load_image_view(void *obj)
void
unload_image_view(void *obj)
{
- auto self = static_cast<BluCat::Swapchain*>(obj);
+ auto self = static_cast<BluCat::GRA::Swapchain*>(obj);
for(auto i{0}; i < self->images_count; i++)
vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->image_views[i], nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->image_views[i],
+ nullptr);
}
void
load_frame_sync(void *obj)
{
- auto self = static_cast<BluCat::Swapchain*>(obj);
+ auto self = static_cast<BluCat::GRA::Swapchain*>(obj);
self->image_available_semaphores.resize(self->max_frames_in_flight);
self->render_finished_semaphores.resize(self->max_frames_in_flight);
@@ -150,13 +152,14 @@ load_frame_sync(void *obj)
for(auto i{0}; i < self->max_frames_in_flight; i++)
{
if(vkCreateSemaphore(
- cg_core.vk_device_with_swapchain->device, &semaphore_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &semaphore_info,
nullptr, &self->image_available_semaphores[i]) != VK_SUCCESS ||
vkCreateSemaphore(
- cg_core.vk_device_with_swapchain->device, &semaphore_info,
+ BluCat::INT::core.vk_device_with_swapchain->device, &semaphore_info,
nullptr, &self->render_finished_semaphores[i]) != VK_SUCCESS ||
- vkCreateFence(cg_core.vk_device_with_swapchain->device, &fence_info,
- nullptr, &self->in_flight_fences[i]) != VK_SUCCESS)
+ vkCreateFence(
+ BluCat::INT::core.vk_device_with_swapchain->device, &fence_info,
+ nullptr, &self->in_flight_fences[i]) != VK_SUCCESS)
throw CommandError{"Failed to create semaphores."};
}
}
@@ -164,18 +167,18 @@ load_frame_sync(void *obj)
void
unload_frame_sync(void *obj)
{
- auto self = static_cast<BluCat::Swapchain*>(obj);
+ auto self = static_cast<BluCat::GRA::Swapchain*>(obj);
- vkDeviceWaitIdle(cg_core.vk_device_with_swapchain->device);
+ vkDeviceWaitIdle(BluCat::INT::core.vk_device_with_swapchain->device);
for(auto i{0}; i < self->max_frames_in_flight; i++)
{
- vkDestroySemaphore(cg_core.vk_device_with_swapchain->device,
+ vkDestroySemaphore(BluCat::INT::core.vk_device_with_swapchain->device,
self->render_finished_semaphores[i], nullptr);
- vkDestroySemaphore(cg_core.vk_device_with_swapchain->device,
+ vkDestroySemaphore(BluCat::INT::core.vk_device_with_swapchain->device,
self->image_available_semaphores[i], nullptr);
- vkDestroyFence(cg_core.vk_device_with_swapchain->device,
- self->in_flight_fences[i], nullptr);
+ vkDestroyFence(BluCat::INT::core.vk_device_with_swapchain->device,
+ self->in_flight_fences[i], nullptr);
}
}
@@ -187,7 +190,7 @@ const CommandChain loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
Swapchain::Swapchain():
diff --git a/src/blucat/swapchain.hpp b/src/blu_cat/gra/swapchain.hpp
index 979fe08..2b52dd6 100644
--- a/src/blucat/swapchain.hpp
+++ b/src/blu_cat/gra/swapchain.hpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_SWAPCHAIN_H
-#define CANDY_GEAR_BLUCAT_SWAPCHAIN_H 1
+#ifndef BLU_CAT_GRA_SWAPCHAIN_H
+#define BLU_CAT_GRA_SWAPCHAIN_H 1
-#include "core.hpp"
-#include "../command.hpp"
+#include "../com/command.hpp"
+#include "vulkan.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Swapchain
@@ -44,4 +44,4 @@ struct Swapchain
}
-#endif /* CANDY_GEAR_BLUCAT_SWAPCHAIN_H */
+#endif /* BLU_CAT_GRA_SWAPCHAIN_H */
diff --git a/src/blucat/texture.cpp b/src/blu_cat/gra/texture.cpp
index 1213528..7546d56 100644
--- a/src/blucat/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.
@@ -16,8 +16,8 @@
#include "texture.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "../com/command.hpp"
+#include "../int/core.hpp"
#include "image.hpp"
#include "qoi.hpp"
#include "source_buffer.hpp"
@@ -35,8 +35,8 @@ create_vulkan_image(
vk_extent3d.height = height;
vk_extent3d.depth = 1;
- BluCat::Image::create(
- cg_core.vk_device_with_swapchain,
+ BluCat::GRA::Image::create(
+ BluCat::INT::core.vk_device_with_swapchain,
image,
device_memory,
VK_FORMAT_R8G8B8A8_UNORM,
@@ -48,24 +48,25 @@ create_vulkan_image(
struct ImageBuilder
{
- BluCat::Texture *texture;
+ BluCat::GRA::Texture *texture;
};
struct ImageTextureBuilder: public ImageBuilder
{
std::string texture_path;
- ImageTextureBuilder(BluCat::Texture *t, std::string tp);
- ImageTextureBuilder(BluCat::Texture *t, const char* tp);
+ ImageTextureBuilder(BluCat::GRA::Texture *t, const std::string &tp);
+ ImageTextureBuilder(BluCat::GRA::Texture *t, const char* tp);
};
-ImageTextureBuilder::ImageTextureBuilder(BluCat::Texture *t, std::string tp):
+ImageTextureBuilder::ImageTextureBuilder(
+ BluCat::GRA::Texture *t, const std::string &tp):
texture_path{tp}
{
this->texture = t;
}
-ImageTextureBuilder::ImageTextureBuilder(BluCat::Texture *t, const char* tp):
+ImageTextureBuilder::ImageTextureBuilder(BluCat::GRA::Texture *t, const char* tp):
ImageTextureBuilder{t, std::string(tp)}
{
}
@@ -76,7 +77,7 @@ load_image(void *obj)
auto self = static_cast<ImageTextureBuilder*>(obj);
const int num_channels = 4; // all images are converted to RGBA
- BluCat::QOI::Image qoi_image(self->texture_path.c_str(), num_channels);
+ BluCat::GRA::QOI::Image qoi_image(self->texture_path.c_str(), num_channels);
uint8_t *pixels;
{ // Load file image from file.
@@ -90,8 +91,8 @@ load_image(void *obj)
// Load file image into a vulkan buffer.
size_t image_size{static_cast<size_t>(
qoi_image.header.width * qoi_image.header.height * num_channels)};
- BluCat::SourceBuffer source_image_buffer{
- cg_core.vk_device_with_swapchain, pixels, image_size};
+ BluCat::GRA::SourceBuffer source_image_buffer{
+ BluCat::INT::core.vk_device_with_swapchain, pixels, image_size};
{ // Create vulkan image.
try
@@ -103,7 +104,7 @@ load_image(void *obj)
self->texture->height,
self->texture->mip_levels);
}
- catch(BluCat::Image::Error error)
+ catch(BluCat::GRA::Image::Error error)
{
throw CommandError{error.what()};
}
@@ -113,11 +114,11 @@ load_image(void *obj)
{
auto queue_family = self->texture->queue_family;
auto queue{queue_family->get_queue()};
- BluCat::CommandPool command_pool{queue_family, 1};
+ BluCat::GRA::CommandPool command_pool{queue_family, 1};
VkCommandBuffer vk_command_buffer{command_pool.command_buffers[0]};
queue.submit_one_time_command(vk_command_buffer, [&](){
- BluCat::Image::move_image_state(
+ BluCat::GRA::Image::move_image_state(
vk_command_buffer, self->texture->image, VK_FORMAT_R8G8B8A8_UNORM,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -139,7 +140,7 @@ load_image(void *obj)
vk_command_buffer, source_image_buffer.buffer, self->texture->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy);
- BluCat::Image::move_image_state(
+ BluCat::GRA::Image::move_image_state(
vk_command_buffer, self->texture->image, VK_FORMAT_R8G8B8A8_UNORM,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -156,10 +157,11 @@ unload_image(void *obj)
auto self = static_cast<ImageBuilder*>(obj);
vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->texture->image, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->texture->image,
+ nullptr);
vkFreeMemory(
- cg_core.vk_device_with_swapchain->device, self->texture->device_memory,
- nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device,
+ self->texture->device_memory, nullptr);
}
void
@@ -171,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;
@@ -188,7 +190,7 @@ load_sampler(void *obj)
sampler_info.unnormalizedCoordinates = VK_FALSE;
if(vkCreateSampler(
- cg_core.vk_device_with_swapchain->device, &sampler_info, nullptr,
+ BluCat::INT::core.vk_device_with_swapchain->device, &sampler_info, nullptr,
&self->texture->sampler) != VK_SUCCESS)
throw CommandError{"Failed to create texture sampler."};
}
@@ -199,7 +201,8 @@ unload_sampler(void *obj)
auto self = static_cast<ImageBuilder*>(obj);
vkDestroySampler(
- cg_core.vk_device_with_swapchain->device, self->texture->sampler, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->texture->sampler,
+ nullptr);
}
void
@@ -209,12 +212,12 @@ load_view(void *obj)
try
{
- BluCat::Image::create_view(
- cg_core.vk_device_with_swapchain, &self->texture->view,
+ BluCat::GRA::Image::create_view(
+ BluCat::INT::core.vk_device_with_swapchain, &self->texture->view,
self->texture->image,
VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
}
- catch(BluCat::Image::Error error)
+ catch(BluCat::GRA::Image::Error error)
{
throw CommandError{error.what()};
}
@@ -226,7 +229,8 @@ unload_view(void *obj)
auto self = static_cast<ImageBuilder*>(obj);
vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->texture->view, nullptr);
+ BluCat::INT::core.vk_device_with_swapchain->device, self->texture->view,
+ nullptr);
}
const CommandChain image_loader{
@@ -238,9 +242,9 @@ const CommandChain image_loader{
struct CharacterToDraw
{
int pos_x;
- std::shared_ptr<BluCat::Character> character;
+ std::shared_ptr<BluCat::GRA::Character> character;
- CharacterToDraw(int x, std::shared_ptr<BluCat::Character> character):
+ CharacterToDraw(int x, std::shared_ptr<BluCat::GRA::Character> character):
pos_x{x},
character{character}
{};
@@ -248,12 +252,12 @@ struct CharacterToDraw
struct TextTextureBuilder: public ImageBuilder
{
- BluCat::Font *font;
+ BluCat::GRA::Font *font;
const char* str;
uint32_t max_bearing_y;
std::vector<CharacterToDraw> chars_to_draw;
- TextTextureBuilder(BluCat::Texture *texture, BluCat::Font *font, const char* str):
+ TextTextureBuilder(BluCat::GRA::Texture *texture, BluCat::GRA::Font *font, const char* str):
font{font},
str{str}
{
@@ -267,7 +271,7 @@ load_text_proportions(void *obj)
auto self = static_cast<TextTextureBuilder*>(obj);
uint32_t texture_width{0}, texture_descender{0};
- auto unicode_text{BluCat::Character::str_to_unicode(self->str)};
+ auto unicode_text{BluCat::GRA::Character::str_to_unicode(self->str)};
auto first_image{self->font->character(unicode_text[0])};
if(first_image->bearing_x < 0) texture_width = - first_image->bearing_x;
@@ -277,7 +281,7 @@ load_text_proportions(void *obj)
// FIXME: I need to test several different fonts to find all bugs in this
// code.
- std::shared_ptr<BluCat::Character> char_image{};
+ std::shared_ptr<BluCat::GRA::Character> char_image{};
{ // Calculate image size
int max_height;
for(auto char_code : unicode_text)
@@ -330,8 +334,8 @@ load_text_image(void *obj)
pixels[image_coord + 3] = 0; // Alpha
}
}
- BluCat::SourceBuffer source_image_buffer{
- cg_core.vk_device_with_swapchain, pixels.data(), image_size};
+ BluCat::GRA::SourceBuffer source_image_buffer{
+ BluCat::INT::core.vk_device_with_swapchain, pixels.data(), image_size};
{ // Create vulkan image.
try
@@ -343,7 +347,7 @@ load_text_image(void *obj)
self->texture->height,
self->texture->mip_levels);
}
- catch(BluCat::Image::Error error)
+ catch(BluCat::GRA::Image::Error error)
{
throw CommandError{error.what()};
}
@@ -351,13 +355,14 @@ load_text_image(void *obj)
{ // Render text
auto queue_family{
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation()};
+ BluCat::INT::core.vk_device_with_swapchain->
+ get_queue_family_with_presentation()};
auto queue{queue_family->get_queue()};
- BluCat::CommandPool command_pool{queue_family, 1};
+ BluCat::GRA::CommandPool command_pool{queue_family, 1};
VkCommandBuffer vk_command_buffer{command_pool.command_buffers[0]};
queue.submit_one_time_command(vk_command_buffer, [&](){
- BluCat::Image::move_image_state(
+ BluCat::GRA::Image::move_image_state(
vk_command_buffer, self->texture->image, VK_FORMAT_R8G8B8A8_UNORM,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -410,7 +415,7 @@ load_text_image(void *obj)
1, &image_copy);
}
- BluCat::Image::move_image_state(
+ BluCat::GRA::Image::move_image_state(
vk_command_buffer, self->texture->image, VK_FORMAT_R8G8B8A8_UNORM,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -431,18 +436,18 @@ const CommandChain text_loader{
void
load_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::Texture*>(obj);
+ auto self = static_cast<BluCat::GRA::Texture*>(obj);
std::array<VkDescriptorPoolSize, 1> descriptor_pool_sizes{};
descriptor_pool_sizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descriptor_pool_sizes[0].descriptorCount =
- cg_core.vk_swapchain->images_count;
+ BluCat::INT::core.vk_swapchain->images_count;
VkDescriptorPoolCreateInfo pool_info{};
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
pool_info.pNext = nullptr;
pool_info.flags = 0;
- pool_info.maxSets = cg_core.vk_swapchain->images_count;
+ pool_info.maxSets = BluCat::INT::core.vk_swapchain->images_count;
pool_info.poolSizeCount = descriptor_pool_sizes.size();
pool_info.pPoolSizes = descriptor_pool_sizes.data();
@@ -455,7 +460,7 @@ load_descriptor_set_pool(void *obj)
void
unload_descriptor_set_pool(void *obj)
{
- auto self = static_cast<BluCat::Texture*>(obj);
+ auto self = static_cast<BluCat::GRA::Texture*>(obj);
vkDestroyDescriptorPool(
self->queue_family->device->device, self->descriptor_pool, nullptr);
@@ -464,11 +469,11 @@ unload_descriptor_set_pool(void *obj)
void
load_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::Texture*>(obj);
+ auto self = static_cast<BluCat::GRA::Texture*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->texture);
+ BluCat::INT::core.vk_swapchain->images_count,
+ BluCat::INT::core.vk_descriptor_set_layout->texture);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -486,9 +491,9 @@ load_descriptor_sets(void *obj)
void
load_data_to_descriptor_sets(void *obj)
{
- auto self = static_cast<BluCat::Texture*>(obj);
+ auto self = static_cast<BluCat::GRA::Texture*>(obj);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ for(auto i{0}; i < BluCat::INT::core.vk_swapchain->images_count; i++)
{
VkDescriptorImageInfo image_info{};
image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@@ -508,7 +513,7 @@ load_data_to_descriptor_sets(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::INT::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -521,23 +526,25 @@ const CommandChain descriptor_loader{
}
-namespace BluCat
+namespace BluCat::GRA
{
Texture::Texture(Font *font, const char* str)
{
this->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::INT::core.vk_device_with_swapchain->
+ get_queue_family_with_presentation();
TextTextureBuilder text_builder(this, font, str);
text_loader.execute(&text_builder);
descriptor_loader.execute(this);
}
-Texture::Texture(std::string texture_path)
+Texture::Texture(const std::string &texture_path)
{
this->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::INT::core.vk_device_with_swapchain->
+ get_queue_family_with_presentation();
ImageTextureBuilder texture_builder(this, texture_path);
image_loader.execute(&texture_builder);
diff --git a/src/blucat/texture.hpp b/src/blu_cat/gra/texture.hpp
index bee61e6..c3da8cf 100644
--- a/src/blucat/texture.hpp
+++ b/src/blu_cat/gra/texture.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_TEXTURE_H
-#define CANDY_GEAR_BLUCAT_TEXTURE_H 1
+#ifndef BLU_CAT_GRA_TEXTURE_H
+#define BLU_CAT_GRA_TEXTURE_H 1
#include <string>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "font.hpp"
#include "queue_family.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
struct Texture
@@ -41,11 +41,11 @@ struct Texture
std::vector<VkDescriptorSet> descriptor_sets;
Texture(Font *font, const char *str);
- Texture(std::string texture_path);
+ Texture(const std::string &texture_path);
Texture(const char* texture_path);
~Texture();
};
}
-#endif /* CANDY_GEAR_TEXTURE_H */
+#endif /* BLU_CAT_GRA_TEXTURE_H */
diff --git a/src/blucat/uniform_buffer.cpp b/src/blu_cat/gra/uniform_buffer.cpp
index 4b6194a..b176365 100644
--- a/src/blucat/uniform_buffer.cpp
+++ b/src/blu_cat/gra/uniform_buffer.cpp
@@ -19,7 +19,7 @@
#include <cstring>
#include <stdexcept>
-namespace BluCat
+namespace BluCat::GRA
{
UniformBuffer::UniformBuffer(Device *device, VkDeviceSize data_size)
diff --git a/src/blucat/uniform_buffer.hpp b/src/blu_cat/gra/uniform_buffer.hpp
index 2131ee1..f37e100 100644
--- a/src/blucat/uniform_buffer.hpp
+++ b/src/blu_cat/gra/uniform_buffer.hpp
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_UNIFORM_BUFFER_H
-#define CANDY_GEAR_BLUCAT_UNIFORM_BUFFER_H 1
+#ifndef BLU_CAT_GRA_UNIFORM_BUFFER_H
+#define BLU_CAT_GRA_UNIFORM_BUFFER_H 1
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "base_buffer.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
// FIXME: this class need to delete or create custom copy constructors!
@@ -46,4 +46,4 @@ public:
}
-#endif /* CANDY_GEAR_BLUCAT_UNIFORM_BUFFER_H */
+#endif /* BLU_CAT_GRA_UNIFORM_BUFFER_H */
diff --git a/src/blucat/uniform_data_object.hpp b/src/blu_cat/gra/uniform_data_object.hpp
index d2292b1..68a3fbe 100644
--- a/src/blucat/uniform_data_object.hpp
+++ b/src/blu_cat/gra/uniform_data_object.hpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_BLUCAT_UNIFORM_DATA_OBJECT_H
-#define CANDY_GEAR_BLUCAT_UNIFORM_DATA_OBJECT_H 1
+#ifndef BLU_CAT_GRA_UNIFORM_DATA_OBJECT_H
+#define BLU_CAT_GRA_UNIFORM_DATA_OBJECT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
#include "skeletal_mesh_vertex.hpp"
-namespace BluCat
+namespace BluCat::GRA
{
// UDO = "uniform data object"
@@ -77,4 +77,4 @@ struct UDOSprite3D
}
-#endif /* CANDY_GEAR_BLUCAT_UNIFORM_DATA_OBJECT_H */
+#endif /* BLU_CAT_GRA_UNIFORM_DATA_OBJECT_H */
diff --git a/src/blucat/view_3d.cpp b/src/blu_cat/gra/view.cpp
index 4b7b959..26017ce 100644
--- a/src/blucat/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 "../core.hpp"
+#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::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
try
{
- self->ub_3d.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ 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(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOView3D));
+ BluCat::INT::core.vk_device_with_swapchain,
+ sizeof(BluCat::GRA::UDOView3D));
}
catch(const std::exception& e)
{
@@ -43,21 +46,21 @@ load_3d_uniform_buffer(void *obj)
}
void
-unload_3d_uniform_buffer(void *obj)
+unload_uniform_buffer(void *obj)
{
- auto self = static_cast<BluCat::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::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->view);
+ 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;
@@ -65,28 +68,28 @@ 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(
- cg_core.vk_device_with_swapchain->device, &alloc_info,
- self->descriptor_sets_3d.data()) != VK_SUCCESS)
+ BluCat::INT::core.vk_device_with_swapchain->device, &alloc_info,
+ 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::View3D*>(obj);
+ auto self = static_cast<BluCat::GRA::View*>(obj);
for(auto i{0}; i < self->ub_3d.size(); i++)
{
VkDescriptorBufferInfo view_3d_info{};
view_3d_info.buffer = self->ub_3d[i].buffer;
view_3d_info.offset = 0;
- view_3d_info.range = sizeof(BluCat::UDOView3D);
+ view_3d_info.range = sizeof(BluCat::GRA::UDOView3D);
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,60 +99,60 @@ load_resources_to_descriptor_sets_3d(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_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}
};
}
-namespace BluCat
+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::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::View2D*>(this);
this->descriptor_pool = VK_NULL_HANDLE;
::descriptor_sets_loader.revert(this);
- View2D::descriptor_sets_loader.revert(parent);
}
}
diff --git a/src/blucat/view_3d.hpp b/src/blu_cat/gra/view.hpp
index 05cae6b..a61ac34 100644
--- a/src/blucat/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 CANDY_GEAR_BLUCAT_VIEW_3D_H
-#define CANDY_GEAR_BLUCAT_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>
-namespace BluCat
+#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 /* CANDY_GEAR_BLUCAT_VIEW_3D_H */
+#endif /* BLU_CAT_GRA_VIEW_H */
diff --git a/src/blu_cat/gra/vulkan.hpp b/src/blu_cat/gra/vulkan.hpp
new file mode 100644
index 0000000..73c599f
--- /dev/null
+++ b/src/blu_cat/gra/vulkan.hpp
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ * 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_VULKAN_H
+#define BLU_CAT_GRA_VULKAN_H 1
+
+#include "../com/numbers.hpp"
+
+#include <vulkan/vulkan.h>
+
+#endif /* BLU_CAT_GRA_VULKAN_H */
diff --git a/src/blu_cat/int/core.cpp b/src/blu_cat/int/core.cpp
new file mode 100644
index 0000000..7e78b89
--- /dev/null
+++ b/src/blu_cat/int/core.cpp
@@ -0,0 +1,761 @@
+/*
+ * 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.
+ * 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 "core.hpp"
+
+namespace
+{
+
+#ifdef DEBUG
+VKAPI_ATTR VkBool32 VKAPI_CALL
+vk_debug_callback(
+ VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
+ VkDebugUtilsMessageTypeFlagsEXT message_type,
+ const VkDebugUtilsMessengerCallbackDataEXT* callback_data,
+ void* _obj)
+{
+ // Set level.
+ Log::Level log_level;
+ switch(message_severity)
+ {
+ case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
+ log_level = Log::Level::Trace;
+ break;
+ case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
+ log_level = Log::Level::Information;
+ break;
+ case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
+ log_level = Log::Level::Warning;
+ break;
+ case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT:
+ default:
+ log_level = Log::Level::Error;
+ break;
+ }
+
+ // Log message.
+ BluCat::INT::core.log.message(log_level, callback_data->pMessage);
+
+ return VK_FALSE;
+}
+#endif
+
+void
+load_sdl(void *obj)
+{
+ if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
+ {
+ std::string error{"SDL could not initialize! SDL Error → "};
+ error += SDL_GetError();
+ throw error;
+ }
+
+ if(SDL_Vulkan_LoadLibrary(nullptr) != 0)
+ {
+ SDL_Quit();
+ std::string error{"SDL could not initialize Vulkan! SDL_Error → "};
+ error += SDL_GetError();
+ throw CommandError{error};
+ }
+}
+
+void
+unload_sdl(void *obj)
+{
+ SDL_Vulkan_UnloadLibrary();
+ SDL_Quit();
+}
+
+void
+load_sdl_mixer(void *obj)
+{
+ int flags = MIX_INIT_OGG|MIX_INIT_MOD;
+ int initted = Mix_Init(flags);
+ if(initted&flags != flags)
+ {
+ std::string error{"Could not initialize SDL mixer → "};
+ error += Mix_GetError();
+ throw CommandError{error};
+ }
+}
+
+void
+unload_sdl_mixer(void *obj)
+{
+ while(Mix_Init(0)) Mix_Quit();
+}
+
+void
+load_sdl_open_audio(void *obj)
+{
+ if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
+ {
+ std::string error{"Could not open SDL mixer audio → "};
+ error += Mix_GetError();
+ throw CommandError{error};
+ }
+}
+
+void
+unload_sdl_open_audio(void *obj)
+{
+ Mix_CloseAudio();
+}
+
+void
+load_window(void *obj)
+{
+ BluCat::INT::core.window = nullptr;
+ BluCat::INT::core.window = SDL_CreateWindow(
+ BluCat::INT::core.game_name.c_str(),
+ SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ BluCat::INT::core.display_width, BluCat::INT::core.display_height,
+ SDL_WINDOW_VULKAN);
+ if(BluCat::INT::core.window == nullptr)
+ {
+ std::string error{"Window could not be created! SDL_Error → "};
+ error += SDL_GetError();
+ throw CommandError{error};
+ }
+}
+
+void
+unload_window(void *obj)
+{
+ SDL_DestroyWindow(BluCat::INT::core.window);
+}
+
+void
+load_vk_instance(void *obj)
+{
+ std::vector<const char*> vk_extensions;
+ std::vector<const char*> vk_required_layers_names;
+
+ // Get extensions.
+ {
+ uint32_t vk_extensions_count;
+ std::vector<const char*> vk_required_extensions;
+
+ // Load debuging layers.
+#ifdef DEBUG
+ vk_required_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
+ vk_required_layers_names.push_back("VK_LAYER_KHRONOS_validation");
+#endif
+
+ // Get extensions for SDL.
+ {
+ uint32_t vk_sdl_extension_count;
+ std::vector<const char*> vk_sdl_extensions;
+
+ if(!SDL_Vulkan_GetInstanceExtensions(
+ BluCat::INT::core.window, &vk_sdl_extension_count, nullptr))
+ {
+ std::string error{
+ "Vulkan extensions could not be loaded by SDL! SDL_Error: "};
+ error += SDL_GetError();
+ throw CommandError{error};
+ }
+
+ vk_sdl_extensions.resize(vk_sdl_extension_count);
+ SDL_Vulkan_GetInstanceExtensions(
+ BluCat::INT::core.window, &vk_sdl_extension_count,
+ vk_sdl_extensions.data());
+
+ // Combine all extensions.
+ vk_extensions_count = vk_sdl_extension_count +
+ vk_required_extensions.size();
+ vk_extensions.resize(vk_extensions_count);
+ for(auto i{0}; i < vk_sdl_extension_count; i++)
+ vk_extensions[i] = vk_sdl_extensions[i];
+ for(auto i{0}; i < vk_required_extensions.size(); i++)
+ vk_extensions[i + vk_sdl_extension_count] = vk_required_extensions[i];
+ }
+
+#ifdef DEBUG
+ BluCat::INT::core.log.message(Log::Level::Trace, "Enabled VK extensions.");
+ for(auto vk_extension: vk_extensions)
+ {
+ std::string message{"Extension name: "};
+ message += vk_extension;
+ BluCat::INT::core.log.message(Log::Level::Trace, message);
+ }
+#endif
+ }
+
+ // Get available instance layers.
+ {
+ uint32_t vk_available_layers_count;
+ std::vector<VkLayerProperties> vk_available_layers;
+ std::vector<const char*> vk_available_layers_names;
+
+ vkEnumerateInstanceLayerProperties(&vk_available_layers_count, nullptr);
+ vk_available_layers.resize(vk_available_layers_count);
+ vkEnumerateInstanceLayerProperties(&vk_available_layers_count,
+ vk_available_layers.data());
+ vk_available_layers_names.resize(vk_available_layers_count);
+#ifdef DEBUG
+ BluCat::INT::core.log.message(
+ Log::Level::Trace, "Available VK instance layers.");
+#endif
+ for(uint32_t i = 0; i < vk_available_layers_count; i++)
+ {
+#ifdef DEBUG
+ std::stringstream message{};
+ message << "\nname: " << vk_available_layers[i].layerName << std::endl;
+ message << "Description: " << vk_available_layers[i].description <<
+ std::endl;
+ message << "Spec version: " << vk_available_layers[i].specVersion <<
+ std::endl;
+ message << "Implementation version: " <<
+ vk_available_layers[i].implementationVersion << std::endl;
+ BluCat::INT::core.log.message(Log::Level::Trace, message.str());
+#endif
+
+ vk_available_layers_names[i] = vk_available_layers[i].layerName;
+ }
+
+ // If required layers are not all available.
+ if(!std::includes(
+ vk_available_layers_names.begin(), vk_available_layers_names.end(),
+ vk_required_layers_names.begin(), vk_required_layers_names.begin()))
+ throw CommandError{"Some required Vulkan layers are not available."};
+ }
+
+ {
+ VkApplicationInfo app_info;
+ app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
+ app_info.pNext = nullptr;
+ app_info.pApplicationName = BluCat::INT::core.game_name.c_str();
+ app_info.applicationVersion = VK_MAKE_VERSION(
+ BluCat::INT::core.game_version_major,
+ BluCat::INT::core.game_version_minor,
+ BluCat::INT::core.game_version_patch);
+ app_info.pEngineName = "BluCat::GRA";
+ app_info.engineVersion = VK_MAKE_VERSION(
+ BLU_CAT_VERSION_MAJOR,
+ BLU_CAT_VERSION_MINOR,
+ BLU_CAT_VERSION_PATCH);
+ app_info.apiVersion = VK_API_VERSION_1_0;
+
+ VkInstanceCreateInfo create_info;
+ create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
+ create_info.pNext = nullptr;
+ create_info.flags = 0;
+ create_info.pApplicationInfo = &app_info;
+ create_info.enabledExtensionCount = vk_extensions.size();
+ create_info.ppEnabledExtensionNames = vk_extensions.data();
+ create_info.enabledLayerCount = vk_required_layers_names.size();
+ create_info.ppEnabledLayerNames = vk_required_layers_names.data();
+
+ VkResult result =
+ vkCreateInstance(&create_info, nullptr, &BluCat::INT::core.vk_instance);
+ if(result != VK_SUCCESS)
+ {
+ std::string error{""};
+ switch(result)
+ {
+ case VK_ERROR_LAYER_NOT_PRESENT:
+ error = " Layer not present.";
+ break;
+ case VK_ERROR_EXTENSION_NOT_PRESENT:
+ error = " Extension not present.";
+ }
+ error = "Failed to create Vulkan instance." + error;
+ throw CommandError{error};
+ }
+ }
+}
+
+void
+unload_vk_instance(void *obj)
+{
+ vkDestroyInstance(BluCat::INT::core.vk_instance, nullptr);
+}
+
+void
+load_window_surface(void *obj)
+{
+ if(!SDL_Vulkan_CreateSurface(
+ BluCat::INT::core.window, BluCat::INT::core.vk_instance,
+ &BluCat::INT::core.window_surface))
+ {
+ std::string error{"Failed to create a window surface → "};
+ error += SDL_GetError();
+ throw CommandError{error};
+ }
+}
+
+void
+unload_window_surface(void *obj)
+{
+ vkDestroySurfaceKHR(
+ BluCat::INT::core.vk_instance, BluCat::INT::core.window_surface, nullptr);
+}
+
+void
+load_threads(void *obj)
+{
+ auto num_threads{std::thread::hardware_concurrency() - 1};
+ for(auto i{0}; i < num_threads; i++)
+ BluCat::INT::core.threads.emplace_back(
+ BluCat::INT::core.workers.emplace_back(&BluCat::INT::core.job_queue));
+}
+
+void
+unload_threads(void *obj)
+{
+ BluCat::INT::core.job_queue.stop();
+ for(auto &t: BluCat::INT::core.threads) t.join();
+}
+
+void
+load_fps(void *obj)
+{
+ using namespace std::chrono;
+
+ BluCat::INT::core.max_frame_duration =
+ duration<long long, std::milli>(1000 / BluCat::INT::core.fps);
+ // FIXME: actually calculates the real delta time.
+ BluCat::INT::core.delta_time = 1.0f / BluCat::INT::core.fps;
+}
+
+void
+load_font_library(void *obj)
+{
+ FT_Error error{FT_Init_FreeType(&BluCat::INT::core.font_library)};
+ if(error) throw CommandError{"Failed to open the FreeType library."};
+}
+
+void
+unload_font_library(void *obj)
+{
+ FT_Done_FreeType(BluCat::INT::core.font_library);
+}
+
+#ifdef DEBUG
+void
+load_vk_debug_callback(void *obj)
+{
+ PFN_vkCreateDebugUtilsMessengerEXT debug_messenger;
+
+ // A Vulkan instance extension named VK_EXT_debug_utils and a Vulkan instance
+ // layer named VK_LAYER_LUNARG_standard_validation are required to enable
+ // this callback. These instance extension and instance layer are loaded at
+ // Instance::load_blucat_instance.
+ VkDebugUtilsMessengerCreateInfoEXT create_info;
+ create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
+ create_info.pNext = nullptr;
+ create_info.messageSeverity =
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
+ create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
+ create_info.pfnUserCallback = vk_debug_callback;
+ create_info.pUserData = nullptr;
+ create_info.flags = 0;
+
+ debug_messenger = (PFN_vkCreateDebugUtilsMessengerEXT)
+ vkGetInstanceProcAddr(BluCat::INT::core.vk_instance,
+ "vkCreateDebugUtilsMessengerEXT");
+
+ if(debug_messenger(BluCat::INT::core.vk_instance, &create_info, nullptr,
+ &BluCat::INT::core.vk_callback) != VK_SUCCESS)
+ CommandError{"Failed to setup debug callback for Vulkan."};
+}
+
+void
+unload_vk_debug_callback(void *obj)
+{
+ PFN_vkDestroyDebugUtilsMessengerEXT debug_messenger;
+
+ debug_messenger = (PFN_vkDestroyDebugUtilsMessengerEXT)
+ vkGetInstanceProcAddr(BluCat::INT::core.vk_instance,
+ "vkDestroyDebugUtilsMessengerEXT");
+
+ debug_messenger(BluCat::INT::core.vk_instance, BluCat::INT::core.vk_callback, nullptr);
+}
+#endif
+
+void
+load_devices(void *obj)
+{
+ uint32_t devices_count;
+ std::vector<VkPhysicalDevice> vk_physical_devices;
+
+ // Enumerate physical devices
+ {
+ vkEnumeratePhysicalDevices(
+ BluCat::INT::core.vk_instance, &devices_count, nullptr);
+ if(devices_count < 1)
+ CommandError{"Failed to find GPUs with Vulkan support."};
+ vk_physical_devices.resize(devices_count);
+ vkEnumeratePhysicalDevices(
+ BluCat::INT::core.vk_instance, &devices_count, vk_physical_devices.data());
+ }
+
+#ifdef DEBUG
+ BluCat::INT::core.log.message(Log::Level::Trace, "Physical devices properties");
+#endif
+
+ BluCat::INT::core.vk_devices.reserve(devices_count);
+ for(auto i = 0; i < devices_count; i++)
+ {
+ // Use swapchain on first device.
+ if(i == 0)
+ {
+ BluCat::INT::core.vk_devices.emplace_back(vk_physical_devices[i], true);
+ BluCat::INT::core.vk_device_with_swapchain = &BluCat::INT::core.vk_devices[i];
+ }
+ else
+ BluCat::INT::core.vk_devices.emplace_back(vk_physical_devices[i], false);
+ }
+}
+
+void
+unload_devices(void *obj)
+{
+ BluCat::INT::core.vk_devices.clear();
+}
+
+static void
+load_swapchain(void *obj)
+{
+ try { BluCat::INT::core.vk_swapchain = new BluCat::GRA::Swapchain(); }
+ catch(const CommandError &error)
+ {
+ std::string error_message{"Failed to create swapchain → "};
+ error_message += error.what();
+ throw CommandError{error_message};
+ }
+}
+
+void
+unload_swapchain(void *obj)
+{
+ delete BluCat::INT::core.vk_swapchain;
+}
+
+void
+load_framebuffer(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_framebuffer = new BluCat::GRA::Framebuffer();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create framebuffer."};
+ }
+}
+
+void
+unload_framebuffer(void *obj)
+{
+ delete BluCat::INT::core.vk_framebuffer;
+}
+
+void
+load_render_pass(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_render_pass = new BluCat::GRA::RenderPass();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create render pass."};
+ }
+}
+
+void
+unload_render_pass(void *obj)
+{
+ delete BluCat::INT::core.vk_render_pass;
+}
+
+void
+load_descriptor_set_layout(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_descriptor_set_layout = new BluCat::GRA::DescriptorSetLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create descriptor set layouts."};
+ }
+}
+
+void
+unload_descriptor_set_layout(void *obj)
+{
+ delete BluCat::INT::core.vk_descriptor_set_layout;
+}
+
+void
+load_graphics_pipeline_3d_layout(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_3d_layout =
+ new BluCat::GRA::GraphicsPipeline3DLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 3d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_3d_layout(void *obj)
+{
+ delete BluCat::INT::core.vk_graphics_pipeline_3d_layout;
+}
+
+void
+load_graphics_pipeline_2d_solid_layout(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_2d_solid_layout =
+ new BluCat::GRA::GraphicsPipeline2DSolidLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 2d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_2d_solid_layout(void *obj)
+{
+ delete BluCat::INT::core.vk_graphics_pipeline_2d_solid_layout;
+}
+
+void
+load_graphics_pipeline_2d_wired_layout(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_2d_wired_layout =
+ new BluCat::GRA::GraphicsPipeline2DWiredLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 2d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_2d_wired_layout(void *obj)
+{
+ delete BluCat::INT::core.vk_graphics_pipeline_2d_wired_layout;
+}
+
+void
+load_light(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_light = new BluCat::GRA::Light();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to descriptor sets for light."};
+ }
+}
+
+void
+unload_light(void *obj)
+{
+ delete BluCat::INT::core.vk_light;
+}
+
+void
+load_graphics_pipeline_3d(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_3d =
+ std::make_unique<BluCat::GRA::GraphicsPipeline3D>();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 3d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_3d(void *obj)
+{
+ BluCat::INT::core.vk_graphics_pipeline_3d = nullptr;
+}
+
+void
+load_graphics_pipeline_3d_skeletal(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_3d_skeletal =
+ std::make_unique<BluCat::GRA::GraphicsPipeline3DSkeletal>();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 3d skeletal graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_3d_skeletal(void *obj)
+{
+ BluCat::INT::core.vk_graphics_pipeline_3d_skeletal = nullptr;
+}
+
+void
+load_graphics_pipeline_sprite_3d(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_sprite_3d =
+ std::make_unique<BluCat::GRA::GraphicsPipelineSprite3D>();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create sprite 3d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_sprite_3d(void *obj)
+{
+ BluCat::INT::core.vk_graphics_pipeline_sprite_3d = nullptr;
+}
+
+void
+load_graphics_pipeline_2d_solid(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_2d_solid =
+ std::make_unique<BluCat::GRA::GraphicsPipeline2DSolid>();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 2d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_2d_solid(void *obj)
+{
+ BluCat::INT::core.vk_graphics_pipeline_2d_solid = nullptr;
+}
+
+void
+load_graphics_pipeline_2d_wired(void *obj)
+{
+ try
+ {
+ BluCat::INT::core.vk_graphics_pipeline_2d_wired =
+ std::make_unique<BluCat::GRA::GraphicsPipeline2DWired>();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 2d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_2d_wired(void *obj)
+{
+ BluCat::INT::core.vk_graphics_pipeline_2d_wired = nullptr;
+}
+
+void
+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, width, height);
+ BluCat::INT::core.vk_renderer = new BluCat::GRA::Renderer(
+ {std::make_shared<BluCat::GRA::View>(region, region.z, region.w)},
+ width, height);
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create renderer."};
+ }
+}
+
+void
+unload_renderer(void *obj)
+{
+ delete BluCat::INT::core.vk_renderer;
+}
+
+}
+
+namespace BluCat::INT
+{
+
+std::random_device random_seed;
+std::mt19937 random_number_generator;
+
+const CommandChain Core::loader{
+ {&load_sdl, &unload_sdl},
+ {&load_sdl_mixer, &unload_sdl_mixer},
+ {&load_sdl_open_audio, &unload_sdl_open_audio},
+ {&load_window, &unload_window},
+ {&load_vk_instance, &unload_vk_instance},
+ {&load_window_surface, &unload_window_surface},
+ {&load_threads, &unload_threads},
+ {&load_fps, nullptr},
+ {&load_font_library, &unload_font_library},
+#ifdef DEBUG
+ {&load_vk_debug_callback, &unload_vk_debug_callback},
+#endif
+ {&load_devices, &unload_devices},
+ {&load_swapchain, &unload_swapchain},
+
+ {&load_render_pass, &unload_render_pass},
+ {&load_framebuffer, &unload_framebuffer},
+ {&load_descriptor_set_layout, &unload_descriptor_set_layout},
+ {&load_graphics_pipeline_3d_layout,
+ &unload_graphics_pipeline_3d_layout},
+ {&load_graphics_pipeline_2d_solid_layout,
+ &unload_graphics_pipeline_2d_solid_layout},
+ {&load_graphics_pipeline_2d_wired_layout,
+ &unload_graphics_pipeline_2d_wired_layout},
+ {&load_light, &unload_light},
+ {&load_graphics_pipeline_3d_skeletal,
+ &unload_graphics_pipeline_3d_skeletal},
+ {&load_graphics_pipeline_3d, &unload_graphics_pipeline_3d},
+ {&load_graphics_pipeline_sprite_3d,
+ &unload_graphics_pipeline_sprite_3d},
+ {&load_graphics_pipeline_2d_solid, &unload_graphics_pipeline_2d_solid},
+ {&load_graphics_pipeline_2d_wired, &unload_graphics_pipeline_2d_wired},
+ {&load_renderer, &unload_renderer},
+};
+
+Core core;
+
+}
diff --git a/src/blu_cat/int/core.hpp b/src/blu_cat/int/core.hpp
new file mode 100644
index 0000000..a334dfa
--- /dev/null
+++ b/src/blu_cat/int/core.hpp
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ * 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_INT_CORE_H
+#define BLU_CAT_INT_CORE_H 1
+
+#define BLU_CAT_VERSION_MAJOR 0
+#define BLU_CAT_VERSION_MINOR 1
+#define BLU_CAT_VERSION_PATCH 0
+
+#include <chrono>
+#include <cstdint>
+#include <memory>
+#include <random>
+
+#define SDL_MAIN_HANDLED
+
+#ifdef _WIN64
+#include <Windows.h>
+#endif
+
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_vulkan.h>
+#include <SDL2/SDL_mixer.h>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include "../com/command.hpp"
+#include "../com/job_queue.hpp"
+#include "../com/worker.hpp"
+#include "../gra/device.hpp"
+#include "../gra/descriptor_set_layout.hpp"
+#include "../gra/framebuffer.hpp"
+#include "../gra/graphics_pipeline_2d_solid_layout.hpp"
+#include "../gra/graphics_pipeline_2d_wired_layout.hpp"
+#include "../gra/graphics_pipeline_2d_solid.hpp"
+#include "../gra/graphics_pipeline_2d_wired.hpp"
+#include "../gra/graphics_pipeline_3d_layout.hpp"
+#include "../gra/graphics_pipeline_3d.hpp"
+#include "../gra/graphics_pipeline_3d_skeletal.hpp"
+#include "../gra/graphics_pipeline_sprite_3d.hpp"
+#include "../gra/light.hpp"
+#include "../gra/log.hpp"
+#include "../gra/render_pass.hpp"
+#include "../gra/renderer.hpp"
+#include "../gra/swapchain.hpp"
+#include "../gra/vulkan.hpp"
+
+namespace BluCat::INT
+{
+
+extern std::random_device random_seed;
+extern std::mt19937 random_number_generator;
+
+struct Core
+{
+ static const CommandChain loader;
+
+ Log::Logger log;
+
+ COM::JobQueue job_queue;
+ std::vector<COM::Worker> workers;
+ std::vector<std::thread> threads;
+
+ /// Text displayed in the game window.
+ std::string game_name{"BluCat Game"};
+
+ /**
+ * @{
+ * This is the ammount of pixel that the games uses when rendering to the
+ * screen.
+ */
+ uint32_t display_width{800};
+ uint32_t display_height{600};
+ /// @}
+
+ int game_version_major{0};
+ int game_version_minor{1};
+ int game_version_patch{0};
+
+ uint32_t fps{30};
+ std::chrono::duration<long long, std::milli> max_frame_duration;
+ float delta_time;
+
+ SDL_Window *window;
+
+ FT_Library font_library;
+
+ VkSurfaceKHR window_surface;
+ VkInstance vk_instance;
+
+#ifdef DEBUG
+ VkDebugUtilsMessengerEXT vk_callback;
+#endif
+
+ // Vulkan devices.
+ std::vector<BluCat::GRA::Device> vk_devices;
+ BluCat::GRA::Device *vk_device_with_swapchain;
+ BluCat::GRA::Swapchain *vk_swapchain;
+
+ BluCat::GRA::Framebuffer *vk_framebuffer;
+ BluCat::GRA::RenderPass *vk_render_pass;
+ BluCat::GRA::DescriptorSetLayout *vk_descriptor_set_layout;
+ BluCat::GRA::GraphicsPipeline3DLayout *vk_graphics_pipeline_3d_layout;
+ BluCat::GRA::GraphicsPipeline2DSolidLayout
+ *vk_graphics_pipeline_2d_solid_layout;
+ BluCat::GRA::GraphicsPipeline2DWiredLayout
+ *vk_graphics_pipeline_2d_wired_layout;
+ BluCat::GRA::Light *vk_light;
+ std::unique_ptr<BluCat::GRA::GraphicsPipeline3D> vk_graphics_pipeline_3d;
+ std::unique_ptr<BluCat::GRA::GraphicsPipeline3DSkeletal>
+ vk_graphics_pipeline_3d_skeletal;
+ std::unique_ptr<BluCat::GRA::GraphicsPipelineSprite3D>
+ vk_graphics_pipeline_sprite_3d;
+ std::unique_ptr<BluCat::GRA::GraphicsPipeline2DSolid>
+ vk_graphics_pipeline_2d_solid;
+ std::unique_ptr<BluCat::GRA::GraphicsPipeline2DWired>
+ vk_graphics_pipeline_2d_wired;
+
+ BluCat::GRA::Renderer *vk_renderer;
+};
+
+extern Core core;
+
+}
+
+#endif /* BLU_CAT_INT_CORE_H */
diff --git a/src/blu_cat/net/client/client.cpp b/src/blu_cat/net/client/client.cpp
new file mode 100644
index 0000000..6ee6046
--- /dev/null
+++ b/src/blu_cat/net/client/client.cpp
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ * 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 "client.hpp"
+
+namespace BluCat::NET
+{
+
+void
+Client::connect(const char *host, const UI16 port)
+{
+ if(this->connection) return;
+
+ asio::error_code error;
+ asio::ip::tcp::endpoint endpoint{asio::ip::make_address(host, error), port};
+
+ asio::ip::tcp::socket socket(this->io_context);
+ socket.connect(endpoint);
+
+ this->connection = new Connection(
+ this, this->io_context, std::move(socket), 0);
+
+ this->thread_context = std::thread([this](){this->io_context.run();});
+}
+
+void
+Client::disconnect(unsigned long index)
+{
+ if(!this->connection) return;
+
+ this->io_context.stop();
+ delete this->connection;
+ this->connection = nullptr;
+}
+
+Client::Client(const char *host, const UI16 port)
+{
+ this->connect(host, port);
+}
+
+Client::Client()
+{
+}
+
+Client::~Client()
+{
+ this->disconnect(0);
+ if(this->thread_context.joinable()) this->thread_context.join();
+}
+
+}
diff --git a/src/blu_cat/net/client/client.hpp b/src/blu_cat/net/client/client.hpp
new file mode 100644
index 0000000..ad0e298
--- /dev/null
+++ b/src/blu_cat/net/client/client.hpp
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ * 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_NET_CLIENT_CLIENT_H
+#define BLU_CAT_NET_CLIENT_CLIENT_H 1
+
+#include "../../com/numbers.hpp"
+#include "../common/connection.hpp"
+#include "../common/connection_callback.hpp"
+
+namespace BluCat::NET
+{
+
+class Client: public ConnectionCallback
+{
+ asio::io_context io_context;
+ std::thread thread_context;
+
+ Connection *connection;
+
+public:
+ inline bool
+ send(const UI32 id, std::vector<UI8> &msg)
+ {return this->connection->send(id, msg);};
+
+ inline bool
+ read_message(Message *m)
+ {return this->connection->read_message(m);};
+
+ inline bool
+ is_connected()
+ {return this->connection != nullptr;};
+
+ void
+ connect(const char *host, const UI16 port);
+
+ void
+ disconnect(unsigned long index);
+
+ Client(
+ const char *host, const UI16 port);
+ Client();
+ ~Client();
+};
+
+}
+
+#endif /* BLU_CAT_NET_CLIENT_CLIENT_H */
diff --git a/src/blu_cat/net/common/connection.cpp b/src/blu_cat/net/common/connection.cpp
new file mode 100644
index 0000000..643d30c
--- /dev/null
+++ b/src/blu_cat/net/common/connection.cpp
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ * 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 "connection.hpp"
+
+#include <iostream>
+
+namespace BluCat::NET
+{
+
+void
+Connection::read_header()
+{
+ asio::async_read(
+ this->socket, asio::buffer(
+ &this->reading_message.header, sizeof(MessageHeader)),
+ [this](std::error_code error, std::size_t length)
+ {
+ if(!error)
+ {
+ if(this->reading_message.header.size > 0)
+ {
+ this->reading_message.body.resize(this->reading_message.header.size);
+ this->read_body();
+ }
+ else
+ {
+ this->reading_message.body.resize(0);
+ this->messages.push_back(this->reading_message);
+ this->read_header();
+ }
+ }
+ else
+ {
+ std::cout << "Failed to read header: " << error.message() << std::endl;
+ this->connection_callback->disconnect(this->index);
+ }
+ });
+}
+
+void
+Connection::read_body()
+{
+ asio::async_read(
+ this->socket, asio::buffer(
+ this->reading_message.body.data(), this->reading_message.body.size()),
+ [this](std::error_code error, std::size_t length)
+ {
+ if(!error)
+ {
+ this->messages.push_back(this->reading_message);
+ this->read_header();
+ }
+ else
+ {
+ std::cout << "Failed to read body." << std::endl;
+ this->connection_callback->disconnect(this->index);
+ }
+ });
+}
+
+bool
+Connection::send(const uint32_t id, const std::vector<uint8_t> &msg)
+{
+ std::vector<uint8_t> *buffered_msg =
+ new std::vector<uint8_t>(msg.size() + 8);
+
+ { // Create header
+ std::memcpy(buffered_msg->data(), &id, 4);
+
+ uint32_t size{static_cast<uint32_t>(msg.size())};
+ std::memcpy(buffered_msg->data() + 4, &size, 4);
+ }
+
+ // Append string to buffer.
+ copy(msg.begin(), msg.end(), buffered_msg->begin() + 8);
+
+ asio::async_write(
+ this->socket, asio::buffer(buffered_msg->data(), buffered_msg->size()),
+ [this, buffered_msg](std::error_code error, std::size_t length)
+ {
+ if(error)
+ {
+ std::cout << "Failed to send message: " << error.message() <<
+ std::endl;
+ this->connection_callback->disconnect(this->index);
+ }
+ delete buffered_msg;
+ });
+
+ return true;
+}
+
+bool
+Connection::read_message(Message *m)
+{
+ if(this->messages.size() <= 0) return false;
+
+ *m = std::move(this->messages.pop_back());
+ return true;
+}
+
+Connection::Connection(
+ ConnectionCallback *connection_callback,
+ asio::io_context &io_context, asio::ip::tcp::socket socket,
+ unsigned long index):
+ connection_callback{connection_callback},
+ io_context{io_context},
+ socket{std::move(socket)},
+ index{index}
+{
+ this->read_header();
+}
+
+Connection::~Connection()
+{
+ this->socket.close();
+}
+
+}
diff --git a/src/blu_cat/net/common/connection.hpp b/src/blu_cat/net/common/connection.hpp
new file mode 100644
index 0000000..bdce8b3
--- /dev/null
+++ b/src/blu_cat/net/common/connection.hpp
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ * 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_NET_COMMON_CONNECTION_H
+#define BLU_CAT_NET_COMMON_CONNECTION_H 1
+
+#include <iostream>
+
+#define ASIO_STANDALONE
+#include <asio.hpp>
+#include <asio/ts/buffer.hpp>
+#include <asio/ts/internet.hpp>
+
+#include "connection_callback.hpp"
+#include "message.hpp"
+#include "tsqueue.hpp"
+
+namespace BluCat::NET
+{
+
+class Connection
+{
+protected:
+ unsigned long index;
+ asio::io_context &io_context;
+
+ asio::ip::tcp::socket socket;
+ TSQueue<Message> messages;
+
+ Message reading_message;
+ ConnectionCallback *connection_callback;
+
+ void
+ read_header();
+
+ void
+ read_body();
+
+public:
+ bool
+ send(const uint32_t id, const std::vector<uint8_t> &msg);
+
+ bool
+ read_message(Message *m);
+
+ Connection(ConnectionCallback *connection_callback,
+ asio::io_context &io_context, asio::ip::tcp::socket socket,
+ unsigned long index);
+
+ virtual
+ ~Connection();
+};
+
+}
+
+#endif /* BLU_CAT_NET_COMMON_CONNECTION_H */
diff --git a/src/view_2d.hpp b/src/blu_cat/net/common/connection_callback.hpp
index a18937e..5241c76 100644
--- a/src/view_2d.hpp
+++ b/src/blu_cat/net/common/connection_callback.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,20 +14,26 @@
* limitations under the License.
*/
-#ifndef CANDY_GEAR_VIEW_2D_H
-#define CANDY_GEAR_VIEW_2D_H 1
+#ifndef BLU_CAT_NET_COMMON_CONNECTION_CALLBACK_H
+#define BLU_CAT_NET_COMMON_CONNECTION_CALLBACK_H 1
-#include "core.hpp"
+#include <memory>
+#include <vector>
-extern const struct mrb_data_type cg_view_2d_type;
+namespace BluCat::NET
+{
-// 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::View2D.
-BluCat::View2D*
-cg_cView_to_view_2d(mrb_state *mrb, mrb_value view_value);
+class Connection;
-void
-cg_view_2d_init(mrb_state *mrb);
+struct ConnectionCallback
+{
+ virtual void
+ disconnect(unsigned long index)=0;
-#endif /* CANDY_GEAR_VIEW_2D_H */
+ virtual
+ ~ConnectionCallback(){};
+};
+
+}
+
+#endif /* BLU_CAT_NET_COMMON_CONNECTION_CALLBACK_H */
diff --git a/src/blu_cat/net/common/message.hpp b/src/blu_cat/net/common/message.hpp
new file mode 100644
index 0000000..286a3bc
--- /dev/null
+++ b/src/blu_cat/net/common/message.hpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ * 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_NET_COMMON_MESSAGE_H
+#define BLU_CAT_NET_COMMON_MESSAGE_H 1
+
+#include <cstdint>
+#include <vector>
+
+namespace BluCat::NET
+{
+
+struct MessageHeader
+{
+ uint32_t id;
+ uint32_t size;
+};
+
+struct Message
+{
+ MessageHeader header{};
+ std::vector<uint8_t> body;
+};
+
+}
+
+#endif /* BLU_CAT_NET_COMMON_MESSAGE_H */
diff --git a/src/blu_cat/net/common/tsqueue.hpp b/src/blu_cat/net/common/tsqueue.hpp
new file mode 100644
index 0000000..673fe3c
--- /dev/null
+++ b/src/blu_cat/net/common/tsqueue.hpp
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ * 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_NET_COMMON_TSQUEUE_H
+#define BLU_CAT_NET_COMMON_TSQUEUE_H 1
+
+#include <deque>
+#include <mutex>
+
+namespace BluCat::NET
+{
+
+template<typename T>
+class TSQueue
+{
+protected:
+ std::mutex mut;
+ std::deque<T> deq_queue;
+
+public:
+ TSQueue() = default;
+ TSQueue(const TSQueue<T>&) = delete;
+
+ const T&
+ front()
+ {
+ std::scoped_lock lock(this->mut);
+ return this->deq_queue.front();
+ }
+
+ const T&
+ back()
+ {
+ std::scoped_lock lock(this->mut);
+ return this->deq_queue.back();
+ }
+
+ void
+ push_front(const T& item)
+ {
+ std::scoped_lock lock(this->mut);
+ this->deq_queue.emplace_front(std::move(item));
+ }
+
+ void
+ push_back(const T& item)
+ {
+ std::scoped_lock lock(this->mut);
+ this->deq_queue.emplace_back(std::move(item));
+ }
+
+ size_t
+ size()
+ {
+ std::scoped_lock lock(this->mut);
+ return this->deq_queue.size();
+ }
+
+ void
+ clear()
+ {
+ std::scoped_lock lock(this->mut);
+ return this->deq_queue.clear();
+ }
+
+ T
+ pop_front()
+ {
+ std::scoped_lock lock(this->mut);
+ auto t = std::move(this->deq_queue.front());
+ deq_queue.pop_front();
+ return t;
+ }
+
+ T
+ pop_back()
+ {
+ std::scoped_lock lock(this->mut);
+ auto t = std::move(this->deq_queue.back());
+ deq_queue.pop_back();
+ return t;
+ }
+
+ virtual
+ ~TSQueue()
+ {
+ this->clear();
+ }
+};
+
+}
+
+#endif /* BLU_CAT_NET_COMMON_TSQUEUE_H */
diff --git a/src/blu_cat/net/server/server.cpp b/src/blu_cat/net/server/server.cpp
new file mode 100644
index 0000000..b9d007e
--- /dev/null
+++ b/src/blu_cat/net/server/server.cpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ * 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 "server.hpp"
+
+#include <iostream>
+
+namespace BluCat::NET
+{
+
+void
+Server::wait_for_client_connections()
+{
+ acceptor.async_accept(
+ [this](std::error_code error, asio::ip::tcp::socket socket)
+ {
+ if(!error)
+ {
+ std::scoped_lock lock(this->mut);
+
+ std::cout << "[SERVER] New connection: " << socket.remote_endpoint() <<
+ std::endl;
+
+ if(this->free_connection_slots.size() > 0)
+ {
+ unsigned long pos{this->free_connection_slots.front()};
+ this->free_connection_slots.pop();
+ std::cout << "Working " << pos << std::endl;
+ std::unique_ptr<Connection> new_connection(
+ std::make_unique<Connection>(
+ this, this->io_context, std::move(socket), pos));
+ this->connections[pos] = new_connection.get();
+ this->get_new_connection(std::move(new_connection));
+ }
+ else
+ {
+ unsigned long pos{this->connections.size()};
+ std::unique_ptr<Connection> new_connection(
+ std::make_unique<Connection>(
+ this, this->io_context, std::move(socket), pos));
+ this->connections.push_back(new_connection.get());
+ this->get_new_connection(std::move(new_connection));
+ }
+ }
+ else
+ {
+ std::cout << "error connecting to client." << std::endl;
+ }
+
+ std::cout << "num clients: " << connections.size() << std::endl;
+
+ this->wait_for_client_connections();
+ });
+}
+
+void
+Server::disconnect(unsigned long index)
+{
+ std::scoped_lock lock(this->mut);
+ delete this->connections[index];
+ this->connections[index] = nullptr;
+ this->free_connection_slots.push(index);
+}
+
+Server::Server(void (*get_new_connection)(std::unique_ptr<Connection> c),
+ const uint16_t port):
+ get_new_connection{get_new_connection},
+ acceptor{io_context, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)}
+{
+ this->thread_context = std::thread([this](){this->io_context.run();});
+ this->wait_for_client_connections();
+}
+
+Server::~Server()
+{
+ this->connections.clear();
+ this->io_context.stop();
+ if(this->thread_context.joinable()) thread_context.join();
+}
+
+}
diff --git a/src/blu_cat/net/server/server.hpp b/src/blu_cat/net/server/server.hpp
new file mode 100644
index 0000000..00b277f
--- /dev/null
+++ b/src/blu_cat/net/server/server.hpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ * 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_SERVER_SERVER_H
+#define BLU_CAT_SERVER_SERVER_H 1
+
+#include <queue>
+
+#include "../common/connection.hpp"
+#include "../common/connection_callback.hpp"
+
+namespace BluCat::NET
+{
+
+class Server: public ConnectionCallback
+{
+ std::mutex mut;
+ asio::io_context io_context;
+ std::thread thread_context;
+ asio::ip::tcp::acceptor acceptor;
+ void (*get_new_connection)(std::unique_ptr<Connection> c);
+
+ std::queue<unsigned long> free_connection_slots;
+ std::vector<Connection*> connections;
+
+ void
+ wait_for_client_connections();
+
+public:
+ void
+ disconnect(unsigned long index);
+
+ Server(void (*get_new_connection)(std::unique_ptr<Connection> c),
+ const uint16_t port);
+ ~Server();
+};
+
+}
+
+#endif /* BLU_CAT_SERVER_SERVER_H */
diff --git a/src/blucat/skeletal_mesh.cpp b/src/blucat/skeletal_mesh.cpp
deleted file mode 100644
index baea635..0000000
--- a/src/blucat/skeletal_mesh.cpp
+++ /dev/null
@@ -1,204 +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 "skeletal_mesh.hpp"
-
-#include "../binary_reader.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
-#include "skeletal_mesh_vertex.hpp"
-
-namespace
-{
-
-// Data that is only needed for the command chain but not for the SkeletalMesh
-// goes here.
-struct MeshBuilder
-{
- std::string mesh_path;
- BluCat::SkeletalMesh *mesh;
-
- MeshBuilder(BluCat::SkeletalMesh *m, std::string mp);
- MeshBuilder(BluCat::SkeletalMesh *m, const char* mp);
-};
-
-MeshBuilder::MeshBuilder(BluCat::SkeletalMesh *m, std::string mp):
- mesh{m},
- mesh_path{mp}
-{
-}
-
-MeshBuilder::MeshBuilder(BluCat::SkeletalMesh *m, const char *mp):
- MeshBuilder{m, std::string(mp)}
-{
-}
-
-void
-load_mesh(void *obj)
-{
- auto self = static_cast<MeshBuilder*>(obj);
-
- BinaryReader input{self->mesh_path};
-
- self->mesh->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
-
- { // Load vertexes.
- auto vertex_count{input.read_ui32()};
- std::vector<BluCat::SkeletalMeshVertex> vertexes{vertex_count};
-
- for(auto i{0}; i < vertex_count; i++)
- {
- vertexes[i].position = input.read_vec3();
- vertexes[i].normal = input.read_vec3();
- vertexes[i].texture_coord = input.read_vec2();
-
- for(auto ii{0}; ii < BluCat::SKELETAL_MESH_MAX_NUM_OF_INFLUENCING_BONES;
- ii++)
- vertexes[i].bone_ids[ii] = input.read_ui32();
-
- for(auto ii{0}; ii < BluCat::SKELETAL_MESH_MAX_NUM_OF_INFLUENCING_BONES;
- ii++)
- vertexes[i].bone_weights[ii] = input.read_float();
- }
-
- void *vertexes_data{vertexes.data()};
- size_t vertexes_size = sizeof(vertexes[0]) * vertexes.size();
- self->mesh->source_vertex_buffer = new BluCat::SourceBuffer{
- self->mesh->queue_family->device, vertexes_data, vertexes_size};
- self->mesh->vertex_buffer = new BluCat::DestinationBuffer{
- self->mesh->queue_family, self->mesh->source_vertex_buffer,
- VK_BUFFER_USAGE_VERTEX_BUFFER_BIT};
- }
-
- { // Load indexes.
- self->mesh->index_count = input.read_ui32();
- std::vector<uint32_t> indexes(self->mesh->index_count);
-
- for(auto i{0}; i < self->mesh->index_count; i++)
- indexes[i] = input.read_ui32();
-
- void *indexes_data{indexes.data()};
- size_t indexes_size{sizeof(indexes[0]) * indexes.size()};
- BluCat::SourceBuffer source_index_buffer{
- self->mesh->queue_family->device, indexes_data, indexes_size};
- self->mesh->index_buffer = new BluCat::DestinationBuffer{
- self->mesh->queue_family, &source_index_buffer,
- VK_BUFFER_USAGE_INDEX_BUFFER_BIT};
- }
-
- { // Load bones
- auto bone_count{input.read_ui32()};
- self->mesh->bones.reserve(bone_count);
- for(int i{0}; i < bone_count; i++)
- self->mesh->bones.emplace_back(input.read_mat4());
- }
-
- { // Load animations
- auto num_animations{input.read_ui32()};
- self->mesh->animations.resize(num_animations);
- for(uint32_t i{0}; i < num_animations; i++)
- {
- auto duration{input.read_double()};
- self->mesh->animations[i].final_time = (float)duration;
-
- auto ticks_per_second{input.read_double()};
-
- auto num_bone_transforms{input.read_ui32()};
- std::vector<BluCat::BoneTransform> *bone_transforms =
- &(self->mesh->animations[i].bone_transforms);
- bone_transforms->resize(num_bone_transforms);
- for(uint32_t bone_transform_index{0};
- bone_transform_index < num_bone_transforms; bone_transform_index++)
- {
- auto bone_id{input.read_ui32()};
-
- auto num_positions{input.read_ui32()};
- BluCat::Channel<glm::vec3> *positions =
- &((*bone_transforms)[bone_transform_index].positions);
- for(auto position_key_index{0}; position_key_index < num_positions;
- position_key_index++)
- {
- auto vec3{input.read_vec3()};
- auto timestamp{input.read_double()};
- positions->key_frames.emplace_back(
- vec3, static_cast<float>(timestamp));
- }
-
- auto num_rotations{input.read_ui32()};
- BluCat::Channel<glm::quat> *rotations =
- &((*bone_transforms)[bone_transform_index].rotations);
- for(auto rotation_key_index{0}; rotation_key_index < num_rotations;
- rotation_key_index++)
- {
- auto quat{input.read_quat()};
- auto timestamp{input.read_double()};
- rotations->key_frames.emplace_back(
- quat, static_cast<float>(timestamp));
- }
-
- auto num_scales{input.read_ui32()};
- BluCat::Channel<glm::vec3> *scales =
- &((*bone_transforms)[bone_transform_index].scales);
- for(auto scaling_key_index{0}; scaling_key_index < num_scales;
- scaling_key_index++)
- {
- auto vec3{input.read_vec3()};
- auto timestamp{input.read_double()};
- scales->key_frames.emplace_back(vec3, static_cast<float>(timestamp));
- }
- }
- }
- }
-}
-
-void
-unload_mesh(void *obj)
-{
- auto self = static_cast<MeshBuilder*>(obj);
-
- delete self->mesh->index_buffer;
- delete self->mesh->vertex_buffer;
- delete self->mesh->source_vertex_buffer;
-}
-
-static const CommandChain loader{
- {&load_mesh, &unload_mesh}
-};
-
-}
-
-namespace BluCat
-{
-
-SkeletalMesh::SkeletalMesh(std::string mesh_path)
-{
- MeshBuilder mesh_builder(this, mesh_path);
- loader.execute(&mesh_builder);
-}
-
-SkeletalMesh::SkeletalMesh(const char* mesh_path):
- SkeletalMesh{std::string(mesh_path)}
-{
-}
-
-SkeletalMesh::~SkeletalMesh()
-{
- MeshBuilder mesh_builder(this, "");
- loader.revert(&mesh_builder);
-}
-
-}
diff --git a/src/blucat/view_2d.cpp b/src/blucat/view_2d.cpp
deleted file mode 100644
index f27b4c4..0000000
--- a/src/blucat/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 "../core.hpp"
-#include "uniform_data_object.hpp"
-
-namespace
-{
-
-void
-load_2d_uniform_buffer(void *obj)
-{
- auto self = static_cast<BluCat::View2D*>(obj);
-
- try
- {
- self->ub_2d.reserve(cg_core.vk_swapchain->images_count);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
- self->ub_2d.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOView2D));
- }
- catch(const std::exception& e)
- {
- throw CommandError{e.what()};
- }
-}
-
-void
-unload_2d_uniform_buffer(void *obj)
-{
- auto self = static_cast<BluCat::View2D*>(obj);
-
- self->ub_2d.clear();
-}
-
-void
-load_descriptor_sets_2d(void *obj)
-{
- auto self = static_cast<BluCat::View2D*>(obj);
-
- std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_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(
- cg_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::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::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(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
- write_descriptors.data(), 0, nullptr);
-
- BluCat::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
-{
-
-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{cg_core.vk_swapchain->images_count},
- sprites_to_draw{cg_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/blucat/view_2d.hpp b/src/blucat/view_2d.hpp
deleted file mode 100644
index b369334..0000000
--- a/src/blucat/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 CANDY_GEAR_BLUCAT_VIEW_2D_H
-#define CANDY_GEAR_BLUCAT_VIEW_2D_H 1
-
-#include <memory>
-#include <unordered_map>
-#include <vector>
-
-#include "core.hpp"
-#include "sprite_to_draw.hpp"
-#include "rectangle.hpp"
-
-namespace BluCat
-{
-
-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 /* CANDY_GEAR_BLUCAT_VIEW_2D_H */
diff --git a/src/candy_gear.cpp b/src/candy_gear/candy_gear.cpp
index 78bb716..7b5a9d9 100644
--- a/src/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)
@@ -30,46 +29,34 @@ cg_mCandyGear_set_game_name(mrb_state *mrb, mrb_value self)
mrb_value name;
mrb_get_args(mrb, "S", &name);
- cg_core.game_name = RSTRING_PTR(name);
+ BluCat::INT::core.game_name = RSTRING_PTR(name);
return 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::View2D>> views_2d;
- std::vector<std::shared_ptr<BluCat::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::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::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 cg_core.vk_renderer;
- cg_core.vk_renderer = new BluCat::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;
}
@@ -96,7 +83,7 @@ cg_mCandyGear_log(mrb_state *mrb, mrb_value self)
else
log_lvl = Log::Level::Fatal;
- cg_core.log.message(log_lvl, message);
+ BluCat::INT::core.log.message(log_lvl, message);
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.hpp b/src/candy_gear/candy_gear.hpp
index 3ec92b3..3ec92b3 100644
--- a/src/candy_gear.hpp
+++ b/src/candy_gear/candy_gear.hpp
diff --git a/src/candy_gear/core.cpp b/src/candy_gear/core.cpp
new file mode 100644
index 0000000..0f5330c
--- /dev/null
+++ b/src/candy_gear/core.cpp
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ * 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 "core.hpp"
+
+#include "candy_gear.hpp"
+#include "font.hpp"
+#include "graphic.hpp"
+#include "key.hpp"
+#include "orientation_3d.hpp"
+#include "skeletal_model.hpp"
+#include "skeletal_mesh.hpp"
+#include "static_model.hpp"
+#include "static_mesh.hpp"
+#include "sound.hpp"
+#include "sprite.hpp"
+#include "sprite_3d.hpp"
+#include "texture.hpp"
+#include "vector_3d.hpp"
+#include "vector_4d.hpp"
+#include "view.hpp"
+
+#ifdef DEBUG
+#include <sstream>
+#endif
+
+namespace
+{
+
+void
+load_mruby_symbols(void *obj)
+{
+ cg_core.sym_config = mrb_intern_cstr(cg_core.mrb, "config");
+ cg_core.sym_debug = mrb_intern_cstr(cg_core.mrb, "debug");
+ cg_core.sym_error = mrb_intern_cstr(cg_core.mrb, "error");
+ cg_core.sym_fatal = mrb_intern_cstr(cg_core.mrb, "fatal");
+ cg_core.sym_information = mrb_intern_cstr(cg_core.mrb, "information");
+ cg_core.sym_init = mrb_intern_cstr(cg_core.mrb, "init");
+ cg_core.sym_key_down = mrb_intern_cstr(cg_core.mrb, "key_down");
+ cg_core.sym_key_up = mrb_intern_cstr(cg_core.mrb, "key_up");
+ cg_core.sym_quit = mrb_intern_cstr(cg_core.mrb, "quit");
+ cg_core.sym_tick = mrb_intern_cstr(cg_core.mrb, "tick");
+ cg_core.sym_trace = mrb_intern_cstr(cg_core.mrb, "trace");
+ cg_core.sym_warning = mrb_intern_cstr(cg_core.mrb, "warning");
+}
+
+void
+load_game(void *obj)
+{
+ FILE *fp;
+ mrb_value main_obj{mrb_top_self(cg_core.mrb)};
+
+ mrb_define_module(cg_core.mrb, "CandyGear");
+ cg_candy_gear_init_config(cg_core.mrb);
+ cg_graphic_init_config(cg_core.mrb);
+
+ fp = fopen(cg_core.game_file.c_str(), "rb");
+ mrb_load_irep_file(cg_core.mrb, fp);
+ fclose(fp);
+ if (cg_core.mrb->exc)
+ {
+ mrb_print_error(cg_core.mrb);
+ throw CommandError{"Error loading game."};
+ }
+
+ mrb_funcall_id(cg_core.mrb, main_obj, cg_core.sym_config, 0);
+ if (cg_core.mrb->exc)
+ {
+ mrb_print_error(cg_core.mrb);
+ throw CommandError{"Error configuring game."};
+ }
+
+ cg_candy_gear_finish_config(cg_core.mrb);
+ cg_graphic_finish_config(cg_core.mrb);
+}
+
+void
+load_blucat(void *obj)
+{
+ BluCat::INT::core.loader.execute(nullptr);
+}
+
+void
+unload_blucat(void *obj)
+{
+ BluCat::INT::core.loader.revert(nullptr);
+}
+
+void
+load_mruby_interface(void *obj)
+{
+ cg_candy_gear_init(cg_core.mrb);
+ cg_font_init(cg_core.mrb);
+ cg_key_init(cg_core.mrb);
+ cg_orientation_3d_init(cg_core.mrb);
+ cg_skeletal_model_init(cg_core.mrb);
+ cg_skeletal_mesh_init(cg_core.mrb);
+ cg_static_model_init(cg_core.mrb);
+ cg_static_mesh_init(cg_core.mrb);
+ cg_sound_init(cg_core.mrb);
+ cg_sprite_init(cg_core.mrb);
+ cg_sprite_3d_init(cg_core.mrb);
+ cg_texture_init(cg_core.mrb);
+ cg_vector_3d_init(cg_core.mrb);
+ cg_vector_4d_init(cg_core.mrb);
+ cg_view_init(cg_core.mrb);
+}
+
+}
+
+const CommandChain cg_sCore::loader{
+ {&load_mruby_symbols, nullptr},
+ {&load_game, nullptr},
+ {&load_blucat, &unload_blucat},
+ {&load_mruby_interface, nullptr}
+};
diff --git a/src/candy_gear/core.hpp b/src/candy_gear/core.hpp
new file mode 100644
index 0000000..e3288b4
--- /dev/null
+++ b/src/candy_gear/core.hpp
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ * 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_CORE_H
+#define CANDY_GEAR_CORE_H 1
+
+#include <mruby.h>
+#include <mruby/class.h>
+#include <mruby/compile.h>
+#include <mruby/data.h>
+#include <mruby/dump.h>
+#include <mruby/variable.h>
+
+#include "../blu_cat/int/core.hpp"
+
+/**
+ * The Core class stores all global states that the engine needs to work.
+ * Global variables are not evil if you use them carefully.
+ */
+struct cg_sCore
+{
+ static const CommandChain loader;
+
+ mrb_state *mrb;
+
+ std::string game_file;
+
+ /// mruby symbols
+ mrb_sym sym_config, sym_debug, sym_error, sym_fatal, sym_information,
+ sym_init, sym_key_down, sym_key_up, sym_quit, sym_tick, sym_trace,
+ sym_warning;
+
+ bool quit_game;
+};
+
+extern cg_sCore cg_core;
+
+#endif /* CANDY_GEAR_CORE_H */
diff --git a/src/font.cpp b/src/candy_gear/font.cpp
index 919d271..f9cbf44 100644
--- a/src/font.cpp
+++ b/src/candy_gear/font.cpp
@@ -16,12 +16,12 @@
#include "font.hpp"
-#include "blucat/font.hpp"
+#include "../blu_cat/gra/font.hpp"
void
cg_free_font(mrb_state *mrb, void *obj)
{
- auto ptr = static_cast<BluCat::Font*>(obj);
+ auto ptr = static_cast<BluCat::GRA::Font*>(obj);
ptr->~Font();
mrb_free(mrb, ptr);
@@ -33,18 +33,18 @@ cg_font_type = {"CG_Font", cg_free_font};
static mrb_value
cg_cFont_initialize(mrb_state *mrb, mrb_value self)
{
- BluCat::Font *ptr;
+ BluCat::GRA::Font *ptr;
const char *font_path;
mrb_int font_size;
mrb_get_args(mrb, "zi", &font_path, &font_size);
- ptr = (BluCat::Font*)DATA_PTR(self);
+ ptr = (BluCat::GRA::Font*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (BluCat::Font*)mrb_malloc(mrb, sizeof(BluCat::Font));
+ ptr = (BluCat::GRA::Font*)mrb_malloc(mrb, sizeof(BluCat::GRA::Font));
try
{
- new(ptr)BluCat::Font(font_path, font_size);
+ new(ptr)BluCat::GRA::Font(font_path, font_size);
}
catch(const std::invalid_argument &e)
{
diff --git a/src/font.hpp b/src/candy_gear/font.hpp
index 0128ea0..0128ea0 100644
--- a/src/font.hpp
+++ b/src/candy_gear/font.hpp
diff --git a/src/graphic.cpp b/src/candy_gear/graphic.cpp
index f27fff7..ad701d1 100644
--- a/src/graphic.cpp
+++ b/src/candy_gear/graphic.cpp
@@ -24,7 +24,7 @@ cg_mCandyGear_set_display_width(mrb_state *mrb, mrb_value self)
mrb_int width;
mrb_get_args(mrb, "i", &width);
- cg_core.display_width = width;
+ BluCat::INT::core.display_width = width;
return self;
}
@@ -35,7 +35,7 @@ cg_mCandyGear_set_display_height(mrb_state *mrb, mrb_value self)
mrb_int height;
mrb_get_args(mrb, "i", &height);
- cg_core.display_height = height;
+ BluCat::INT::core.display_height = height;
return self;
}
@@ -46,7 +46,7 @@ cg_mCandyGear_set_fps(mrb_state *mrb, mrb_value self)
mrb_int fps;
mrb_get_args(mrb, "i", &fps);
- cg_core.fps = fps;
+ BluCat::INT::core.fps = fps;
return self;
}
diff --git a/src/graphic.hpp b/src/candy_gear/graphic.hpp
index fbd9df8..fbd9df8 100644
--- a/src/graphic.hpp
+++ b/src/candy_gear/graphic.hpp
diff --git a/src/key.cpp b/src/candy_gear/key.cpp
index 615119c..615119c 100644
--- a/src/key.cpp
+++ b/src/candy_gear/key.cpp
diff --git a/src/key.hpp b/src/candy_gear/key.hpp
index d3f4f5f..d3f4f5f 100644
--- a/src/key.hpp
+++ b/src/candy_gear/key.hpp
diff --git a/src/main.cpp b/src/candy_gear/main.cpp
index f99e8ca..353b6bf 100644
--- a/src/main.cpp
+++ b/src/candy_gear/main.cpp
@@ -18,6 +18,7 @@
#include <thread>
#include "core.hpp"
+
cg_sCore cg_core;
int main(int argc, char *argv[])
@@ -28,7 +29,7 @@ int main(int argc, char *argv[])
SDL_Event event;
// Random numbers
- random_number_generator.seed(random_seed());
+ BluCat::INT::random_number_generator.seed(BluCat::INT::random_seed());
cg_core.game_file = argv[1];
cg_core.mrb = mrb_open();
@@ -36,7 +37,7 @@ int main(int argc, char *argv[])
try{ cg_sCore::loader.execute(nullptr); }
catch(const CommandError &error)
{
- cg_core.log.message(Log::Level::Fatal, error.what());
+ BluCat::INT::core.log.message(Log::Level::Fatal, error.what());
mrb_close(cg_core.mrb);
return 1;
}
@@ -92,16 +93,15 @@ int main(int argc, char *argv[])
}
else
{
- cg_core.vk_renderer->draw();
+ BluCat::INT::core.vk_renderer->draw();
- // Timer
- {
+ { // Timer
auto frame_stop = steady_clock::now();
auto frame_duration = frame_stop - frame_start;
// If frame take less time than maximum allowed.
- if(cg_core.max_frame_duration > frame_duration)
- sleep_for(cg_core.max_frame_duration - frame_duration);
+ if(BluCat::INT::core.max_frame_duration > frame_duration)
+ sleep_for(BluCat::INT::core.max_frame_duration - frame_duration);
frame_start = frame_stop;
}
diff --git a/src/orientation_3d.cpp b/src/candy_gear/orientation_3d.cpp
index cb42984..cb42984 100644
--- a/src/orientation_3d.cpp
+++ b/src/candy_gear/orientation_3d.cpp
diff --git a/src/orientation_3d.hpp b/src/candy_gear/orientation_3d.hpp
index 45a8ab2..45a8ab2 100644
--- a/src/orientation_3d.hpp
+++ b/src/candy_gear/orientation_3d.hpp
diff --git a/src/skeletal_mesh.cpp b/src/candy_gear/skeletal_mesh.cpp
index 90cbeee..4af4419 100644
--- a/src/skeletal_mesh.cpp
+++ b/src/candy_gear/skeletal_mesh.cpp
@@ -18,12 +18,12 @@
#include "orientation_3d.hpp"
#include "vector_3d.hpp"
-#include "blucat/skeletal_mesh.hpp"
+#include "../blu_cat/gra/skeletal_mesh.hpp"
void
cg_free_skeletal_mesh(mrb_state *mrb, void* obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::SkeletalMesh>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::SkeletalMesh>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -37,16 +37,16 @@ cg_cSkeletalMesh_initialize(mrb_state *mrb, mrb_value self)
{
const char *file_path;
- std::shared_ptr<BluCat::SkeletalMesh> *ptr;
+ std::shared_ptr<BluCat::GRA::SkeletalMesh> *ptr;
mrb_get_args(mrb, "z", &file_path);
- ptr = (std::shared_ptr<BluCat::SkeletalMesh>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::SkeletalMesh>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::SkeletalMesh>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::SkeletalMesh>));
+ ptr = (std::shared_ptr<BluCat::GRA::SkeletalMesh>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::SkeletalMesh>));
- new(ptr)std::shared_ptr<BluCat::SkeletalMesh>(
- std::make_shared<BluCat::SkeletalMesh>(file_path));
+ new(ptr)std::shared_ptr<BluCat::GRA::SkeletalMesh>(
+ std::make_shared<BluCat::GRA::SkeletalMesh>(file_path));
mrb_data_init(self, ptr, &cg_skeletal_mesh_type);
return self;
diff --git a/src/skeletal_mesh.hpp b/src/candy_gear/skeletal_mesh.hpp
index 476aa9b..476aa9b 100644
--- a/src/skeletal_mesh.hpp
+++ b/src/candy_gear/skeletal_mesh.hpp
diff --git a/src/skeletal_model.cpp b/src/candy_gear/skeletal_model.cpp
index 3a3596e..41d0c9a 100644
--- a/src/skeletal_model.cpp
+++ b/src/candy_gear/skeletal_model.cpp
@@ -20,12 +20,12 @@
#include "vector_3d.hpp"
#include "skeletal_mesh.hpp"
#include "texture.hpp"
-#include "blucat/skeletal_model.hpp"
+#include "../blu_cat/gra/skeletal_model.hpp"
void
cg_free_skeletal_model(mrb_state *mrb, void *obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::SkeletalModel>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::SkeletalModel>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -37,23 +37,23 @@ const struct mrb_data_type cg_skeletal_model_type = {
static mrb_value
cg_cSkeletalModel_initialize(mrb_state *mrb, mrb_value self)
{
- std::shared_ptr<BluCat::SkeletalMesh> *skeletal_mesh;
- std::shared_ptr<BluCat::Texture> *texture;
+ std::shared_ptr<BluCat::GRA::SkeletalMesh> *skeletal_mesh;
+ std::shared_ptr<BluCat::GRA::Texture> *texture;
std::shared_ptr<glm::vec3> *position;
std::shared_ptr<glm::quat> *orientation;
- std::shared_ptr<BluCat::SkeletalModel> *ptr;
+ std::shared_ptr<BluCat::GRA::SkeletalModel> *ptr;
mrb_get_args(
mrb, "dddd", &skeletal_mesh, &cg_skeletal_mesh_type, &texture,
&cg_texture_type, &position, &cg_vector_3d_type, &orientation,
&cg_orientation_3d_type);
- ptr = (std::shared_ptr<BluCat::SkeletalModel>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::SkeletalModel>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::SkeletalModel>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::SkeletalModel>));
+ ptr = (std::shared_ptr<BluCat::GRA::SkeletalModel>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::SkeletalModel>));
- new(ptr)std::shared_ptr<BluCat::SkeletalModel>(
- std::make_shared<BluCat::SkeletalModel>(
+ new(ptr)std::shared_ptr<BluCat::GRA::SkeletalModel>(
+ std::make_shared<BluCat::GRA::SkeletalModel>(
*skeletal_mesh, *texture, *position, *orientation));
mrb_data_init(self, ptr, &cg_skeletal_model_type);
@@ -63,7 +63,7 @@ cg_cSkeletalModel_initialize(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cSkeletalModel_set_orientation(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::SkeletalModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::SkeletalModel>*)DATA_PTR(self);
std::shared_ptr<glm::quat> *orientation;
mrb_get_args(mrb, "d", &orientation, &cg_orientation_3d_type);
@@ -75,7 +75,7 @@ cg_cSkeletalModel_set_orientation(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cSkeletalModel_set_position(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::SkeletalModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::SkeletalModel>*)DATA_PTR(self);
std::shared_ptr<glm::vec3> *position;
mrb_get_args(mrb, "d", &position, &cg_vector_3d_type);
@@ -87,7 +87,7 @@ cg_cSkeletalModel_set_position(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cSkeletalModel_set_animation(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::SkeletalModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::SkeletalModel>*)DATA_PTR(self);
mrb_int animation_index;
mrb_get_args(mrb, "i", &animation_index);
@@ -99,10 +99,10 @@ cg_cSkeletalModel_set_animation(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cSkeletalModel_draw(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::SkeletalModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::SkeletalModel>*)DATA_PTR(self);
- auto &instances = cg_core.vk_renderer->skeletal_models_to_draw[
- cg_core.vk_swapchain->current_frame][(*ptr)->skeletal_mesh];
+ auto &instances = BluCat::INT::core.vk_renderer->skeletal_models_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame][(*ptr)->skeletal_mesh];
instances.push_back(*ptr);
return self;
diff --git a/src/skeletal_model.hpp b/src/candy_gear/skeletal_model.hpp
index 05f9c2e..05f9c2e 100644
--- a/src/skeletal_model.hpp
+++ b/src/candy_gear/skeletal_model.hpp
diff --git a/src/sound.cpp b/src/candy_gear/sound.cpp
index 0b3518f..0b3518f 100644
--- a/src/sound.cpp
+++ b/src/candy_gear/sound.cpp
diff --git a/src/sound.hpp b/src/candy_gear/sound.hpp
index 2f483e3..2f483e3 100644
--- a/src/sound.hpp
+++ b/src/candy_gear/sound.hpp
diff --git a/src/sprite.cpp b/src/candy_gear/sprite.cpp
index 65a49f7..2847d76 100644
--- a/src/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,13 +18,12 @@
#include "texture.hpp"
#include "vector_4d.hpp"
-#include "view_2d.hpp"
-#include "blucat/sprite.hpp"
+#include "../blu_cat/gra/sprite.hpp"
void
cg_free_sprite(mrb_state *mrb, void* obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::Sprite>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::Sprite>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -37,22 +36,22 @@ cg_cSprite_initialize(mrb_state *mrb, mrb_value self)
{
mrb_float x, y, w, h;
glm::vec4 vector_4d;
- std::shared_ptr<BluCat::Texture> *texture;
- std::shared_ptr<BluCat::Sprite> *ptr;
+ std::shared_ptr<BluCat::GRA::Texture> *texture;
+ std::shared_ptr<BluCat::GRA::Sprite> *ptr;
mrb_get_args(
mrb, "dffff", &texture, &cg_texture_type, &x, &y, &w, &h);
- ptr = (std::shared_ptr<BluCat::Sprite>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::Sprite>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::Sprite>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::Sprite>));
+ ptr = (std::shared_ptr<BluCat::GRA::Sprite>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::Sprite>));
vector_4d.x = x;
vector_4d.y = y;
vector_4d.z = w;
vector_4d.w = h;
- new(ptr)std::shared_ptr<BluCat::Sprite>(
- std::make_shared<BluCat::Sprite>(*texture, vector_4d));
+ new(ptr)std::shared_ptr<BluCat::GRA::Sprite>(
+ std::make_shared<BluCat::GRA::Sprite>(*texture, vector_4d));
mrb_data_init(self, ptr, &cg_sprite_type);
return self;
@@ -61,18 +60,14 @@ 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::View2D *view_2d;
mrb_float x, y, w, h, z_index{0.0};
- auto ptr = (std::shared_ptr<BluCat::Sprite>*)DATA_PTR(self);
+ 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[
- cg_core.vk_swapchain->current_frame];
+ 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);
return self;
diff --git a/src/sprite.hpp b/src/candy_gear/sprite.hpp
index 528f2f7..528f2f7 100644
--- a/src/sprite.hpp
+++ b/src/candy_gear/sprite.hpp
diff --git a/src/sprite_3d.cpp b/src/candy_gear/sprite_3d.cpp
index d0e3319..d03b585 100644
--- a/src/sprite_3d.cpp
+++ b/src/candy_gear/sprite_3d.cpp
@@ -22,7 +22,7 @@
void
cg_free_sprite_3d(mrb_state *mrb, void *obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::Sprite3D>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::Sprite3D>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -34,21 +34,21 @@ const struct mrb_data_type cg_sprite_3d_type = {
static mrb_value
cg_cSprite3D_initialize(mrb_state *mrb, mrb_value self)
{
- std::shared_ptr<BluCat::Sprite> *sprite;
+ std::shared_ptr<BluCat::GRA::Sprite> *sprite;
std::shared_ptr<glm::vec3> *position;
mrb_float w, h;
- std::shared_ptr<BluCat::Sprite3D> *ptr;
+ std::shared_ptr<BluCat::GRA::Sprite3D> *ptr;
mrb_get_args(mrb, "ddff", &sprite, &cg_sprite_type,
&position, &cg_vector_3d_type, &w, &h);
- ptr = (std::shared_ptr<BluCat::Sprite3D>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::Sprite3D>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::Sprite3D>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::Sprite3D>));
+ ptr = (std::shared_ptr<BluCat::GRA::Sprite3D>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::Sprite3D>));
glm::vec3 size{w, h, 0.0};
- new(ptr)std::shared_ptr<BluCat::Sprite3D>(
- std::make_shared<BluCat::Sprite3D>(*sprite, *position, size));
+ new(ptr)std::shared_ptr<BluCat::GRA::Sprite3D>(
+ std::make_shared<BluCat::GRA::Sprite3D>(*sprite, *position, size));
mrb_data_init(self, ptr, &cg_sprite_3d_type);
return self;
@@ -57,10 +57,10 @@ cg_cSprite3D_initialize(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cSprite3D_draw(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::Sprite3D>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::Sprite3D>*)DATA_PTR(self);
- auto &sprites_3d_to_draw = cg_core.vk_renderer->sprites_3d_to_draw[
- cg_core.vk_swapchain->current_frame];
+ auto &sprites_3d_to_draw = BluCat::INT::core.vk_renderer->sprites_3d_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame];
sprites_3d_to_draw.emplace_back(*ptr);
return self;
diff --git a/src/sprite_3d.hpp b/src/candy_gear/sprite_3d.hpp
index 526c23a..526c23a 100644
--- a/src/sprite_3d.hpp
+++ b/src/candy_gear/sprite_3d.hpp
diff --git a/src/static_mesh.cpp b/src/candy_gear/static_mesh.cpp
index 3ae616e..9cb79ef 100644
--- a/src/static_mesh.cpp
+++ b/src/candy_gear/static_mesh.cpp
@@ -18,12 +18,12 @@
#include "orientation_3d.hpp"
#include "vector_3d.hpp"
-#include "blucat/static_mesh.hpp"
+#include "../blu_cat/gra/static_mesh.hpp"
void
cg_free_static_mesh(mrb_state *mrb, void* obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::StaticMesh>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::StaticMesh>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -37,16 +37,16 @@ cg_cStaticMesh_initialize(mrb_state *mrb, mrb_value self)
{
const char *file_path;
- std::shared_ptr<BluCat::StaticMesh> *ptr;
+ std::shared_ptr<BluCat::GRA::StaticMesh> *ptr;
mrb_get_args(mrb, "z", &file_path);
- ptr = (std::shared_ptr<BluCat::StaticMesh>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::StaticMesh>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::StaticMesh>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::StaticMesh>));
+ ptr = (std::shared_ptr<BluCat::GRA::StaticMesh>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::StaticMesh>));
- new(ptr)std::shared_ptr<BluCat::StaticMesh>(
- std::make_shared<BluCat::StaticMesh>(file_path));
+ new(ptr)std::shared_ptr<BluCat::GRA::StaticMesh>(
+ std::make_shared<BluCat::GRA::StaticMesh>(file_path));
mrb_data_init(self, ptr, &cg_static_mesh_type);
return self;
diff --git a/src/static_mesh.hpp b/src/candy_gear/static_mesh.hpp
index 8f3b2d6..8f3b2d6 100644
--- a/src/static_mesh.hpp
+++ b/src/candy_gear/static_mesh.hpp
diff --git a/src/static_model.cpp b/src/candy_gear/static_model.cpp
index 3dd0c10..1a6eabe 100644
--- a/src/static_model.cpp
+++ b/src/candy_gear/static_model.cpp
@@ -20,12 +20,12 @@
#include "static_mesh.hpp"
#include "texture.hpp"
#include "vector_3d.hpp"
-#include "blucat/static_model.hpp"
+#include "../blu_cat/gra/static_model.hpp"
void
cg_free_static_model(mrb_state *mrb, void *obj)
{
- auto ptr = static_cast<std::shared_ptr<BluCat::StaticModel>*>(obj);
+ auto ptr = static_cast<std::shared_ptr<BluCat::GRA::StaticModel>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -37,23 +37,23 @@ const struct mrb_data_type cg_static_model_type = {
static mrb_value
cg_cStaticModel_initialize(mrb_state *mrb, mrb_value self)
{
- std::shared_ptr<BluCat::StaticMesh> *static_mesh;
- std::shared_ptr<BluCat::Texture> *texture;
+ std::shared_ptr<BluCat::GRA::StaticMesh> *static_mesh;
+ std::shared_ptr<BluCat::GRA::Texture> *texture;
std::shared_ptr<glm::vec3> *position;
std::shared_ptr<glm::quat> *orientation;
- std::shared_ptr<BluCat::StaticModel> *ptr;
+ std::shared_ptr<BluCat::GRA::StaticModel> *ptr;
mrb_get_args(
mrb, "dddd", &static_mesh, &cg_static_mesh_type, &texture,
&cg_texture_type, &position, &cg_vector_3d_type, &orientation,
&cg_orientation_3d_type);
- ptr = (std::shared_ptr<BluCat::StaticModel>*)DATA_PTR(self);
+ ptr = (std::shared_ptr<BluCat::GRA::StaticModel>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::StaticModel>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::StaticModel>));
+ ptr = (std::shared_ptr<BluCat::GRA::StaticModel>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::StaticModel>));
- new(ptr)std::shared_ptr<BluCat::StaticModel>(
- std::make_shared<BluCat::StaticModel>(
+ new(ptr)std::shared_ptr<BluCat::GRA::StaticModel>(
+ std::make_shared<BluCat::GRA::StaticModel>(
*static_mesh, *texture, *position, *orientation));
mrb_data_init(self, ptr, &cg_static_model_type);
@@ -63,7 +63,7 @@ cg_cStaticModel_initialize(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cStaticModel_set_orientation(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::StaticModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::StaticModel>*)DATA_PTR(self);
std::shared_ptr<glm::quat> *orientation;
mrb_get_args(mrb, "d", &orientation, &cg_orientation_3d_type);
@@ -75,7 +75,7 @@ cg_cStaticModel_set_orientation(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cStaticModel_set_position(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::StaticModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::StaticModel>*)DATA_PTR(self);
std::shared_ptr<glm::vec3> *position;
mrb_get_args(mrb, "d", &position, &cg_vector_3d_type);
@@ -87,8 +87,8 @@ cg_cStaticModel_set_position(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cStaticModel_set_texture(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::StaticModel>*)DATA_PTR(self);
- std::shared_ptr<BluCat::Texture> *texture;
+ auto ptr = (std::shared_ptr<BluCat::GRA::StaticModel>*)DATA_PTR(self);
+ std::shared_ptr<BluCat::GRA::Texture> *texture;
mrb_get_args(mrb, "d", &texture, &cg_texture_type);
(*ptr)->texture = *texture;
@@ -99,10 +99,10 @@ cg_cStaticModel_set_texture(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cStaticModel_draw(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::StaticModel>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::StaticModel>*)DATA_PTR(self);
- auto &instances = cg_core.vk_renderer->static_models_to_draw[
- cg_core.vk_swapchain->current_frame][(*ptr)->static_mesh];
+ auto &instances = BluCat::INT::core.vk_renderer->static_models_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame][(*ptr)->static_mesh];
instances.push_back(*ptr);
return self;
diff --git a/src/static_model.hpp b/src/candy_gear/static_model.hpp
index dfb7054..dfb7054 100644
--- a/src/static_model.hpp
+++ b/src/candy_gear/static_model.hpp
diff --git a/src/texture.cpp b/src/candy_gear/texture.cpp
index 0bfac25..355a622 100644
--- a/src/texture.cpp
+++ b/src/candy_gear/texture.cpp
@@ -18,12 +18,12 @@
#include "core.hpp"
#include "font.hpp"
-#include "blucat/texture.hpp"
+#include "../blu_cat/gra/texture.hpp"
void
cg_free_texture(mrb_state *mrb, void* obj)
{
- auto *ptr = static_cast<std::shared_ptr<BluCat::Texture>*>(obj);
+ auto *ptr = static_cast<std::shared_ptr<BluCat::GRA::Texture>*>(obj);
ptr->~shared_ptr();
mrb_free(mrb, ptr);
@@ -48,15 +48,15 @@ cg_cTexture_from_image(mrb_state *mrb, mrb_value self)
{
struct mrb_value texture = texture_alloc(mrb, self);
const char *file_path;
- std::shared_ptr<BluCat::Texture> *ptr;
+ std::shared_ptr<BluCat::GRA::Texture> *ptr;
mrb_get_args(mrb, "z", &file_path);
- ptr = (std::shared_ptr<BluCat::Texture>*)DATA_PTR(texture);
+ ptr = (std::shared_ptr<BluCat::GRA::Texture>*)DATA_PTR(texture);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::Texture>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::Texture>));
- new(ptr)std::shared_ptr<BluCat::Texture>(
- std::make_shared<BluCat::Texture>(file_path));
+ ptr = (std::shared_ptr<BluCat::GRA::Texture>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::Texture>));
+ new(ptr)std::shared_ptr<BluCat::GRA::Texture>(
+ std::make_shared<BluCat::GRA::Texture>(file_path));
mrb_data_init(texture, ptr, &cg_texture_type);
return texture;
@@ -68,17 +68,17 @@ cg_cTexture_from_text(mrb_state *mrb, mrb_value self)
const char *text;
unsigned int width, height;
struct mrb_value texture = texture_alloc(mrb, self);
- BluCat::Font *font_ptr;
- std::shared_ptr<BluCat::Texture> *ptr;
+ BluCat::GRA::Font *font_ptr;
+ std::shared_ptr<BluCat::GRA::Texture> *ptr;
mrb_get_args(mrb, "dz", &font_ptr, &cg_font_type, &text);
- ptr = (std::shared_ptr<BluCat::Texture>*)DATA_PTR(texture);
+ ptr = (std::shared_ptr<BluCat::GRA::Texture>*)DATA_PTR(texture);
if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::Texture>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::Texture>));
- new(ptr)std::shared_ptr<BluCat::Texture>(
- std::make_shared<BluCat::Texture>(font_ptr, text));
+ ptr = (std::shared_ptr<BluCat::GRA::Texture>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::Texture>));
+ new(ptr)std::shared_ptr<BluCat::GRA::Texture>(
+ std::make_shared<BluCat::GRA::Texture>(font_ptr, text));
mrb_data_init(texture, ptr, &cg_texture_type);
return texture;
@@ -87,14 +87,14 @@ cg_cTexture_from_text(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cTexture_width(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::Texture>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::Texture>*)DATA_PTR(self);
return mrb_int_value(mrb, (*ptr)->width);
}
static mrb_value
cg_cTexture_height(mrb_state *mrb, mrb_value self)
{
- auto ptr = (std::shared_ptr<BluCat::Texture>*)DATA_PTR(self);
+ auto ptr = (std::shared_ptr<BluCat::GRA::Texture>*)DATA_PTR(self);
return mrb_int_value(mrb, (*ptr)->height);
}
diff --git a/src/texture.hpp b/src/candy_gear/texture.hpp
index b20244d..cd96026 100644
--- a/src/texture.hpp
+++ b/src/candy_gear/texture.hpp
@@ -18,7 +18,7 @@
#define CANDY_GEAR_TEXTURE_H 1
#include "core.hpp"
-#include "command.hpp"
+#include "../blu_cat/com/command.hpp"
extern const struct mrb_data_type cg_texture_type;
diff --git a/src/vector_3d.cpp b/src/candy_gear/vector_3d.cpp
index fc5d186..fc5d186 100644
--- a/src/vector_3d.cpp
+++ b/src/candy_gear/vector_3d.cpp
diff --git a/src/vector_3d.hpp b/src/candy_gear/vector_3d.hpp
index 2827813..2827813 100644
--- a/src/vector_3d.hpp
+++ b/src/candy_gear/vector_3d.hpp
diff --git a/src/vector_4d.cpp b/src/candy_gear/vector_4d.cpp
index ba46bda..5ee674d 100644
--- a/src/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,20 +347,16 @@ 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::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::Rectangle rect{position, (**color)};
- auto &rectangles = view_2d->rectangles_to_draw[
- cg_core.vk_swapchain->current_frame];
+ BluCat::GRA::Rectangle rect{position, (**color)};
+ auto &rectangles = BluCat::INT::core.vk_renderer->rectangles_to_draw[
+ BluCat::INT::core.vk_swapchain->current_frame];
rectangles.push_back(rect);
return self;
diff --git a/src/vector_4d.hpp b/src/candy_gear/vector_4d.hpp
index 2797d53..2797d53 100644
--- a/src/vector_4d.hpp
+++ b/src/candy_gear/vector_4d.hpp
diff --git a/src/view_3d.cpp b/src/candy_gear/view.cpp
index ddaa3eb..40a03a8 100644
--- a/src/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 "blucat/sprite.hpp"
-#include "blucat/view_3d.hpp"
+#include "../blu_cat/gra/sprite.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::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::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::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::View3D>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::View3D>));
+ ptr = (std::shared_ptr<BluCat::GRA::View>*)mrb_malloc(
+ mrb, sizeof(std::shared_ptr<BluCat::GRA::View>));
- new(ptr)std::shared_ptr<BluCat::View3D>(
- std::make_shared<BluCat::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::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::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::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::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/view_3d.hpp b/src/candy_gear/view.hpp
index 22aa084..ce1b556 100644
--- a/src/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/core.cpp b/src/core.cpp
deleted file mode 100644
index f524e36..0000000
--- a/src/core.cpp
+++ /dev/null
@@ -1,850 +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 "core.hpp"
-
-#include "candy_gear.hpp"
-#include "font.hpp"
-#include "graphic.hpp"
-#include "key.hpp"
-#include "orientation_3d.hpp"
-#include "skeletal_model.hpp"
-#include "skeletal_mesh.hpp"
-#include "static_model.hpp"
-#include "static_mesh.hpp"
-#include "sound.hpp"
-#include "sprite.hpp"
-#include "sprite_3d.hpp"
-#include "texture.hpp"
-#include "vector_3d.hpp"
-#include "vector_4d.hpp"
-#include "view_2d.hpp"
-#include "view_3d.hpp"
-
-#ifdef DEBUG
-#include <sstream>
-#endif
-
-std::random_device random_seed;
-std::mt19937 random_number_generator;
-
-namespace
-{
-
-#ifdef DEBUG
-VKAPI_ATTR VkBool32 VKAPI_CALL
-vk_debug_callback(
- VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
- VkDebugUtilsMessageTypeFlagsEXT message_type,
- const VkDebugUtilsMessengerCallbackDataEXT* callback_data,
- void* _obj)
-{
- // Set level.
- Log::Level log_level;
- switch(message_severity)
- {
- case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
- log_level = Log::Level::Trace;
- break;
- case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
- log_level = Log::Level::Information;
- break;
- case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
- log_level = Log::Level::Warning;
- break;
- case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT:
- default:
- log_level = Log::Level::Error;
- break;
- }
-
- // Log message.
- cg_core.log.message(log_level, callback_data->pMessage);
-
- return VK_FALSE;
-}
-#endif
-
-void
-load_threads(void *obj)
-{
- auto num_threads{std::thread::hardware_concurrency() - 1};
- for(auto i{0}; i < num_threads; i++)
- cg_core.threads.emplace_back(
- cg_core.workers.emplace_back(&cg_core.job_queue));
-}
-
-void
-unload_threads(void *obj)
-{
- cg_core.job_queue.stop();
- for(auto &t: cg_core.threads) t.join();
-}
-
-void
-load_mruby_symbols(void *obj)
-{
- cg_core.sym_config = mrb_intern_cstr(cg_core.mrb, "config");
- cg_core.sym_debug = mrb_intern_cstr(cg_core.mrb, "debug");
- cg_core.sym_error = mrb_intern_cstr(cg_core.mrb, "error");
- cg_core.sym_fatal = mrb_intern_cstr(cg_core.mrb, "fatal");
- cg_core.sym_information = mrb_intern_cstr(cg_core.mrb, "information");
- cg_core.sym_init = mrb_intern_cstr(cg_core.mrb, "init");
- cg_core.sym_key_down = mrb_intern_cstr(cg_core.mrb, "key_down");
- cg_core.sym_key_up = mrb_intern_cstr(cg_core.mrb, "key_up");
- cg_core.sym_quit = mrb_intern_cstr(cg_core.mrb, "quit");
- cg_core.sym_tick = mrb_intern_cstr(cg_core.mrb, "tick");
- cg_core.sym_trace = mrb_intern_cstr(cg_core.mrb, "trace");
- cg_core.sym_warning = mrb_intern_cstr(cg_core.mrb, "warning");
-}
-
-void
-load_game(void *obj)
-{
- using namespace std::chrono;
-
- FILE *fp;
- mrb_value main_obj{mrb_top_self(cg_core.mrb)};
-
- cg_core.game_name = "CandyGear Game";
-
- cg_core.display_width = 800;
- cg_core.display_height = 600;
-
- cg_core.game_version_major = 0;
- cg_core.game_version_minor = 1;
- cg_core.game_version_patch = 0;
-
- cg_core.fps = 30;
-
- mrb_define_module(cg_core.mrb, "CandyGear");
- cg_candy_gear_init_config(cg_core.mrb);
- cg_graphic_init_config(cg_core.mrb);
-
-
- fp = fopen(cg_core.game_file.c_str(), "rb");
- mrb_load_irep_file(cg_core.mrb, fp);
- fclose(fp);
- if (cg_core.mrb->exc)
- {
- mrb_print_error(cg_core.mrb);
- throw CommandError{"Error loading game."};
- }
-
- mrb_funcall_id(cg_core.mrb, main_obj, cg_core.sym_config, 0);
- if (cg_core.mrb->exc)
- {
- mrb_print_error(cg_core.mrb);
- throw CommandError{"Error configuring game."};
- }
-
- cg_candy_gear_finish_config(cg_core.mrb);
- cg_graphic_finish_config(cg_core.mrb);
-
- cg_core.max_frame_duration =
- duration<long long, std::milli>(1000 / cg_core.fps);
- // FIXME: actually calculates the real delta time.
- cg_core.delta_time = 1.0f / cg_core.fps;
-}
-
-void
-load_sdl(void *obj)
-{
- if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
- {
- std::string error{"SDL could not initialize! SDL Error → "};
- error += SDL_GetError();
- throw error;
- }
-
- if(SDL_Vulkan_LoadLibrary(nullptr) != 0)
- {
- SDL_Quit();
- std::string error{"SDL could not initialize Vulkan! SDL_Error → "};
- error += SDL_GetError();
- throw CommandError{error};
- }
-}
-
-void
-unload_sdl(void *obj)
-{
- SDL_Vulkan_UnloadLibrary();
- SDL_Quit();
-}
-
-void
-load_sdl_mixer(void *obj)
-{
- int flags = MIX_INIT_OGG|MIX_INIT_MOD;
- int initted = Mix_Init(flags);
- if(initted&flags != flags)
- {
- std::string error{"Could not initialize SDL mixer → "};
- error += Mix_GetError();
- throw CommandError{error};
- }
-}
-
-void
-unload_sdl_mixer(void *obj)
-{
- while(Mix_Init(0)) Mix_Quit();
-}
-
-void
-load_sdl_open_audio(void *obj)
-{
- if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
- {
- std::string error{"Could not open SDL mixer audio → "};
- error += Mix_GetError();
- throw CommandError{error};
- }
-}
-
-void
-unload_sdl_open_audio(void *obj)
-{
- Mix_CloseAudio();
-}
-
-void
-load_window(void *obj)
-{
- cg_core.window = NULL;
- cg_core.window = SDL_CreateWindow(
- cg_core.game_name.c_str(), SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, cg_core.display_width, cg_core.display_height,
- SDL_WINDOW_VULKAN);
- if(cg_core.window == NULL)
- {
- std::string error{"Window could not be created! SDL_Error → "};
- error += SDL_GetError();
- throw CommandError{error};
- }
-}
-
-void
-unload_window(void *obj)
-{
- SDL_DestroyWindow(cg_core.window);
-}
-
-void
-load_font_library(void *obj)
-{
- FT_Error error{FT_Init_FreeType(&cg_core.font_library)};
- if(error) throw CommandError{"Failed to open the FreeType library."};
-}
-
-void
-unload_font_library(void *obj)
-{
- FT_Done_FreeType(cg_core.font_library);
-}
-
-void
-load_blucat_instance(void *obj)
-{
- std::vector<const char*> vk_extensions;
- std::vector<const char*> vk_required_layers_names;
-
- // Get extensions.
- {
- uint32_t vk_extensions_count;
- std::vector<const char*> vk_required_extensions;
-
- // Load debuging layers.
-#ifdef DEBUG
- vk_required_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
- vk_required_layers_names.push_back("VK_LAYER_KHRONOS_validation");
-#endif
-
- // Get extensions for SDL.
- {
- uint32_t vk_sdl_extension_count;
- std::vector<const char*> vk_sdl_extensions;
-
- if(!SDL_Vulkan_GetInstanceExtensions(
- cg_core.window, &vk_sdl_extension_count, nullptr))
- {
- std::string error{
- "Vulkan extensions could not be loaded by SDL! SDL_Error: "};
- error += SDL_GetError();
- throw CommandError{error};
- }
-
- vk_sdl_extensions.resize(vk_sdl_extension_count);
- SDL_Vulkan_GetInstanceExtensions(
- cg_core.window, &vk_sdl_extension_count, vk_sdl_extensions.data());
-
- // Combine all extensions.
- vk_extensions_count = vk_sdl_extension_count +
- vk_required_extensions.size();
- vk_extensions.resize(vk_extensions_count);
- for(auto i{0}; i < vk_sdl_extension_count; i++)
- vk_extensions[i] = vk_sdl_extensions[i];
- for(auto i{0}; i < vk_required_extensions.size(); i++)
- vk_extensions[i + vk_sdl_extension_count] = vk_required_extensions[i];
- }
-
-#ifdef DEBUG
- cg_core.log.message(Log::Level::Trace, "Enabled VK extensions.");
- for(auto vk_extension: vk_extensions)
- {
- std::string message{"Extension name: "};
- message += vk_extension;
- cg_core.log.message(Log::Level::Trace, message);
- }
-#endif
- }
-
- // Get available instance layers.
- {
- uint32_t vk_available_layers_count;
- std::vector<VkLayerProperties> vk_available_layers;
- std::vector<const char*> vk_available_layers_names;
-
- vkEnumerateInstanceLayerProperties(&vk_available_layers_count, nullptr);
- vk_available_layers.resize(vk_available_layers_count);
- vkEnumerateInstanceLayerProperties(&vk_available_layers_count,
- vk_available_layers.data());
- vk_available_layers_names.resize(vk_available_layers_count);
-#ifdef DEBUG
- cg_core.log.message(Log::Level::Trace, "Available VK instance layers.");
-#endif
- for(uint32_t i = 0; i < vk_available_layers_count; i++)
- {
-#ifdef DEBUG
- std::stringstream message{};
- message << "\nname: " << vk_available_layers[i].layerName << std::endl;
- message << "Description: " << vk_available_layers[i].description <<
- std::endl;
- message << "Spec version: " << vk_available_layers[i].specVersion <<
- std::endl;
- message << "Implementation version: " <<
- vk_available_layers[i].implementationVersion << std::endl;
- cg_core.log.message(Log::Level::Trace, message.str());
-#endif
-
- vk_available_layers_names[i] = vk_available_layers[i].layerName;
- }
-
- // If required layers are not all available.
- if(!std::includes(
- vk_available_layers_names.begin(), vk_available_layers_names.end(),
- vk_required_layers_names.begin(), vk_required_layers_names.begin()))
- throw CommandError{"Some required Vulkan layers are not available."};
- }
-
- {
- VkApplicationInfo app_info;
- app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- app_info.pNext = nullptr;
- app_info.pApplicationName = cg_core.game_name.c_str();
- app_info.applicationVersion = VK_MAKE_VERSION(
- cg_core.game_version_major,
- cg_core.game_version_minor,
- cg_core.game_version_patch);
- app_info.pEngineName = "CandyGear";
- app_info.engineVersion = VK_MAKE_VERSION(
- CANDY_GEAR_VERSION_MAJOR,
- CANDY_GEAR_VERSION_MINOR,
- CANDY_GEAR_VERSION_PATCH);
- app_info.apiVersion = VK_API_VERSION_1_0;
-
- VkInstanceCreateInfo create_info;
- create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- create_info.pNext = nullptr;
- create_info.flags = 0;
- create_info.pApplicationInfo = &app_info;
- create_info.enabledExtensionCount = vk_extensions.size();
- create_info.ppEnabledExtensionNames = vk_extensions.data();
- create_info.enabledLayerCount = vk_required_layers_names.size();
- create_info.ppEnabledLayerNames = vk_required_layers_names.data();
-
- VkResult result =
- vkCreateInstance(&create_info, nullptr, &cg_core.vk_instance);
- if(result != VK_SUCCESS)
- {
- std::string error{""};
- switch(result)
- {
- case VK_ERROR_LAYER_NOT_PRESENT:
- error = " Layer not present.";
- break;
- case VK_ERROR_EXTENSION_NOT_PRESENT:
- error = " Extension not present.";
- }
- error = "Failed to create Vulkan instance." + error;
- throw CommandError{error};
- }
- }
-}
-
-void
-unload_blucat_instance(void *obj)
-{
- vkDestroyInstance(cg_core.vk_instance, nullptr);
-}
-
-void
-load_window_surface(void *obj)
-{
- if(!SDL_Vulkan_CreateSurface(
- cg_core.window, cg_core.vk_instance, &cg_core.window_surface))
- {
- std::string error{"Failed to create a window surface → "};
- error += SDL_GetError();
- throw CommandError{error};
- }
-}
-
-void
-unload_window_surface(void *obj)
-{
- vkDestroySurfaceKHR(cg_core.vk_instance, cg_core.window_surface, nullptr);
-}
-
-#ifdef DEBUG
-void
-load_blucat_debug_callback(void *obj)
-{
- PFN_vkCreateDebugUtilsMessengerEXT debug_messenger;
-
- // A Vulkan instance extension named VK_EXT_debug_utils and a Vulkan instance
- // layer named VK_LAYER_LUNARG_standard_validation are required to enable
- // this callback. These instance extension and instance layer are loaded at
- // Instance::load_blucat_instance.
- VkDebugUtilsMessengerCreateInfoEXT create_info;
- create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
- create_info.pNext = nullptr;
- create_info.messageSeverity =
- VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
- VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
- VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
- VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
- create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
- VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
- VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
- create_info.pfnUserCallback = vk_debug_callback;
- create_info.pUserData = nullptr;
- create_info.flags = 0;
-
- debug_messenger = (PFN_vkCreateDebugUtilsMessengerEXT)
- vkGetInstanceProcAddr(cg_core.vk_instance,
- "vkCreateDebugUtilsMessengerEXT");
-
- if(debug_messenger(cg_core.vk_instance, &create_info, nullptr,
- &cg_core.vk_callback) != VK_SUCCESS)
- CommandError{"Failed to setup debug callback for Vulkan."};
-}
-
-void
-unload_blucat_debug_callback(void *obj)
-{
- PFN_vkDestroyDebugUtilsMessengerEXT debug_messenger;
-
- debug_messenger = (PFN_vkDestroyDebugUtilsMessengerEXT)
- vkGetInstanceProcAddr(cg_core.vk_instance,
- "vkDestroyDebugUtilsMessengerEXT");
-
- debug_messenger(cg_core.vk_instance, cg_core.vk_callback, nullptr);
-}
-#endif
-
-void
-load_blucat_devices(void *obj)
-{
- uint32_t devices_count;
- std::vector<VkPhysicalDevice> vk_physical_devices;
-
- // Enumerate physical devices
- {
- vkEnumeratePhysicalDevices(cg_core.vk_instance, &devices_count, nullptr);
- if(devices_count < 1)
- CommandError{"Failed to find GPUs with Vulkan support."};
- vk_physical_devices.resize(devices_count);
- vkEnumeratePhysicalDevices(
- cg_core.vk_instance, &devices_count, vk_physical_devices.data());
- }
-
-#ifdef DEBUG
- cg_core.log.message(Log::Level::Trace, "Physical devices properties");
-#endif
-
- cg_core.vk_devices.reserve(devices_count);
- for(auto i = 0; i < devices_count; i++)
- {
- // Use swapchain on first device.
- if(i == 0)
- {
- cg_core.vk_devices.emplace_back(vk_physical_devices[i], true);
- cg_core.vk_device_with_swapchain = &cg_core.vk_devices[i];
- }
- else
- cg_core.vk_devices.emplace_back(vk_physical_devices[i], false);
- }
-}
-
-void
-unload_blucat_devices(void *obj)
-{
- cg_core.vk_devices.clear();
-}
-
-static void
-load_blucat_swapchain(void *obj)
-{
- try { cg_core.vk_swapchain = new BluCat::Swapchain(); }
- catch(const CommandError &error)
- {
- std::string error_message{"Failed to create swapchain → "};
- error_message += error.what();
- throw CommandError{error_message};
- }
-}
-
-void
-unload_blucat_swapchain(void *obj)
-{
- delete cg_core.vk_swapchain;
-}
-
-void
-load_blucat_framebuffer(void *obj)
-{
- try
- {
- cg_core.vk_framebuffer = new BluCat::Framebuffer();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create framebuffer."};
- }
-}
-
-void
-unload_blucat_framebuffer(void *obj)
-{
- delete cg_core.vk_framebuffer;
-}
-
-void
-load_blucat_render_pass(void *obj)
-{
- try
- {
- cg_core.vk_render_pass = new BluCat::RenderPass();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create render pass."};
- }
-}
-
-void
-unload_blucat_render_pass(void *obj)
-{
- delete cg_core.vk_render_pass;
-}
-
-void
-load_blucat_descriptor_set_layout(void *obj)
-{
- try
- {
- cg_core.vk_descriptor_set_layout = new BluCat::DescriptorSetLayout();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create descriptor set layouts."};
- }
-}
-
-void
-unload_blucat_descriptor_set_layout(void *obj)
-{
- delete cg_core.vk_descriptor_set_layout;
-}
-
-void
-load_blucat_graphics_pipeline_3d_layout(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_3d_layout =
- new BluCat::GraphicsPipeline3DLayout();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 3d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_3d_layout(void *obj)
-{
- delete cg_core.vk_graphics_pipeline_3d_layout;
-}
-
-void
-load_blucat_graphics_pipeline_2d_solid_layout(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_2d_solid_layout =
- new BluCat::GraphicsPipeline2DSolidLayout();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 2d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_2d_solid_layout(void *obj)
-{
- delete cg_core.vk_graphics_pipeline_2d_solid_layout;
-}
-
-void
-load_blucat_graphics_pipeline_2d_wired_layout(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_2d_wired_layout =
- new BluCat::GraphicsPipeline2DWiredLayout();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 2d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_2d_wired_layout(void *obj)
-{
- delete cg_core.vk_graphics_pipeline_2d_wired_layout;
-}
-
-void
-load_blucat_light(void *obj)
-{
- try
- {
- cg_core.vk_light = new BluCat::Light();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to descriptor sets for light."};
- }
-}
-
-void
-unload_blucat_light(void *obj)
-{
- delete cg_core.vk_light;
-}
-
-void
-load_blucat_graphics_pipeline_3d(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_3d =
- std::make_unique<BluCat::GraphicsPipeline3D>();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 3d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_3d(void *obj)
-{
- cg_core.vk_graphics_pipeline_3d = nullptr;
-}
-
-void
-load_blucat_graphics_pipeline_3d_skeletal(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_3d_skeletal =
- std::make_unique<BluCat::GraphicsPipeline3DSkeletal>();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 3d skeletal graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_3d_skeletal(void *obj)
-{
- cg_core.vk_graphics_pipeline_3d_skeletal = nullptr;
-}
-
-void
-load_blucat_graphics_pipeline_sprite_3d(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_sprite_3d =
- std::make_unique<BluCat::GraphicsPipelineSprite3D>();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create sprite 3d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_sprite_3d(void *obj)
-{
- cg_core.vk_graphics_pipeline_sprite_3d = nullptr;
-}
-
-void
-load_blucat_graphics_pipeline_2d_solid(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_2d_solid =
- std::make_unique<BluCat::GraphicsPipeline2DSolid>();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 2d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_2d_solid(void *obj)
-{
- cg_core.vk_graphics_pipeline_2d_solid = nullptr;
-}
-
-void
-load_blucat_graphics_pipeline_2d_wired(void *obj)
-{
- try
- {
- cg_core.vk_graphics_pipeline_2d_wired =
- std::make_unique<BluCat::GraphicsPipeline2DWired>();
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create 2d graphics pipeline."};
- }
-}
-
-void
-unload_blucat_graphics_pipeline_2d_wired(void *obj)
-{
- cg_core.vk_graphics_pipeline_2d_wired = nullptr;
-}
-
-void
-load_blucat_renderer(void *obj)
-{
- try
- {
- glm::vec4 region(
- 0.f, 0.f,
- static_cast<float>(cg_core.display_width),
- static_cast<float>(cg_core.display_height));
- cg_core.vk_renderer = new BluCat::Renderer(
- {},
- {std::make_shared<BluCat::View3D>(region, region.z, region.w)});
- }
- catch(const CommandError &e)
- {
- throw CommandError{"Failed to create renderer."};
- }
-}
-
-void
-unload_blucat_renderer(void *obj)
-{
- delete cg_core.vk_renderer;
-}
-
-void
-load_mruby_interface(void *obj)
-{
- cg_candy_gear_init(cg_core.mrb);
- cg_font_init(cg_core.mrb);
- cg_key_init(cg_core.mrb);
- cg_orientation_3d_init(cg_core.mrb);
- cg_skeletal_model_init(cg_core.mrb);
- cg_skeletal_mesh_init(cg_core.mrb);
- cg_static_model_init(cg_core.mrb);
- cg_static_mesh_init(cg_core.mrb);
- cg_sound_init(cg_core.mrb);
- cg_sprite_init(cg_core.mrb);
- cg_sprite_3d_init(cg_core.mrb);
- 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);
-}
-
-}
-
-const CommandChain cg_sCore::loader{
- {&load_threads, &unload_threads},
- {&load_mruby_symbols, nullptr},
- {&load_game, nullptr},
- {&load_sdl, &unload_sdl},
- {&load_sdl_mixer, &unload_sdl_mixer},
- {&load_sdl_open_audio, &unload_sdl_open_audio},
- {&load_window, &unload_window},
- {&load_font_library, &unload_font_library},
- {&load_blucat_instance, &unload_blucat_instance},
- {&load_window_surface, &unload_window_surface},
-#ifdef DEBUG
- {&load_blucat_debug_callback, &unload_blucat_debug_callback},
-#endif
- {&load_blucat_devices, &unload_blucat_devices},
- {&load_blucat_swapchain, &unload_blucat_swapchain},
-
- {&load_blucat_render_pass, &unload_blucat_render_pass},
- {&load_blucat_framebuffer, &unload_blucat_framebuffer},
- {&load_blucat_descriptor_set_layout, &unload_blucat_descriptor_set_layout},
- {&load_blucat_graphics_pipeline_3d_layout,
- &unload_blucat_graphics_pipeline_3d_layout},
- {&load_blucat_graphics_pipeline_2d_solid_layout,
- &unload_blucat_graphics_pipeline_2d_solid_layout},
- {&load_blucat_graphics_pipeline_2d_wired_layout,
- &unload_blucat_graphics_pipeline_2d_wired_layout},
- {&load_blucat_light, &unload_blucat_light},
- // TODO: finish skeletal mesh animation
- {&load_blucat_graphics_pipeline_3d_skeletal,
- &unload_blucat_graphics_pipeline_3d_skeletal},
- {&load_blucat_graphics_pipeline_3d, &unload_blucat_graphics_pipeline_3d},
- {&load_blucat_graphics_pipeline_sprite_3d,
- &unload_blucat_graphics_pipeline_sprite_3d},
- {&load_blucat_graphics_pipeline_2d_solid, &unload_blucat_graphics_pipeline_2d_solid},
- {&load_blucat_graphics_pipeline_2d_wired, &unload_blucat_graphics_pipeline_2d_wired},
-
- {&load_blucat_renderer, &unload_blucat_renderer},
- {&load_mruby_interface, nullptr}
-};
diff --git a/src/core.hpp b/src/core.hpp
deleted file mode 100644
index c351917..0000000
--- a/src/core.hpp
+++ /dev/null
@@ -1,148 +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_CORE_H
-#define CANDY_GEAR_CORE_H 1
-
-#define CANDY_GEAR_VERSION_MAJOR 0
-#define CANDY_GEAR_VERSION_MINOR 1
-#define CANDY_GEAR_VERSION_PATCH 0
-
-#include <chrono>
-#include <random>
-
-#include <mruby.h>
-#include <mruby/class.h>
-#include <mruby/compile.h>
-#include <mruby/data.h>
-#include <mruby/dump.h>
-#include <mruby/variable.h>
-
-#define SDL_MAIN_HANDLED
-
-#ifdef _WIN64
-#include <Windows.h>
-#endif
-
-#include <SDL2/SDL.h>
-#include <SDL2/SDL_vulkan.h>
-#include <SDL2/SDL_mixer.h>
-
-#include <ft2build.h>
-#include FT_FREETYPE_H
-
-#include "command.hpp"
-#include "job_queue.hpp"
-#include "log.hpp"
-#include "worker.hpp"
-
-#include "blucat/device.hpp"
-#include "blucat/descriptor_set_layout.hpp"
-#include "blucat/render_pass.hpp"
-#include "blucat/framebuffer.hpp"
-#include "blucat/graphics_pipeline_2d_solid_layout.hpp"
-#include "blucat/graphics_pipeline_2d_wired_layout.hpp"
-#include "blucat/light.hpp"
-#include "blucat/graphics_pipeline_2d_solid.hpp"
-#include "blucat/graphics_pipeline_2d_wired.hpp"
-#include "blucat/graphics_pipeline_3d_layout.hpp"
-#include "blucat/graphics_pipeline_3d.hpp"
-#include "blucat/graphics_pipeline_3d_skeletal.hpp"
-#include "blucat/graphics_pipeline_sprite_3d.hpp"
-#include "blucat/renderer.hpp"
-#include "blucat/swapchain.hpp"
-
-extern std::random_device random_seed;
-extern std::mt19937 random_number_generator;
-
-/**
- * The Core class stores all global states that the engine needs to work.
- * Global variables are not evil if you use them carefully.
- */
-struct cg_sCore
-{
- static const CommandChain loader;
-
- Log::Logger log;
-
- JobQueue job_queue;
- std::vector<Worker> workers;
- std::vector<std::thread> threads;
-
- mrb_state *mrb;
-
- std::string game_file;
-
- /// mruby symbols
- mrb_sym sym_config, sym_debug, sym_error, sym_fatal, sym_information,
- sym_init, sym_key_down, sym_key_up, sym_quit, sym_tick, sym_trace,
- sym_warning;
-
- /// Text displayed in the game window.
- std::string game_name;
-
- /**
- * @{
- * This is the ammount of pixel that the games uses when rendering to the
- * screen.
- */
- uint32_t display_width, display_height;
- /// @}
-
- int game_version_major, game_version_minor, game_version_patch;
-
- Uint32 fps;
- std::chrono::duration<long long, std::milli> max_frame_duration;
- float delta_time;
-
- SDL_Window *window;
-
- FT_Library font_library;
-
- VkSurfaceKHR window_surface;
- VkInstance vk_instance;
-
-#ifdef DEBUG
- VkDebugUtilsMessengerEXT vk_callback;
-#endif
-
- // Vulkan devices.
- std::vector<BluCat::Device> vk_devices;
- BluCat::Device *vk_device_with_swapchain;
- BluCat::Swapchain *vk_swapchain;
-
- BluCat::Framebuffer *vk_framebuffer;
- BluCat::RenderPass *vk_render_pass;
- BluCat::DescriptorSetLayout *vk_descriptor_set_layout;
- BluCat::GraphicsPipeline3DLayout *vk_graphics_pipeline_3d_layout;
- BluCat::GraphicsPipeline2DSolidLayout *vk_graphics_pipeline_2d_solid_layout;
- BluCat::GraphicsPipeline2DWiredLayout *vk_graphics_pipeline_2d_wired_layout;
- BluCat::Light *vk_light;
- std::unique_ptr<BluCat::GraphicsPipeline3D> vk_graphics_pipeline_3d;
- std::unique_ptr<BluCat::GraphicsPipeline3DSkeletal>
- vk_graphics_pipeline_3d_skeletal;
- std::unique_ptr<BluCat::GraphicsPipelineSprite3D> vk_graphics_pipeline_sprite_3d;
- std::unique_ptr<BluCat::GraphicsPipeline2DSolid> vk_graphics_pipeline_2d_solid;
- std::unique_ptr<BluCat::GraphicsPipeline2DWired> vk_graphics_pipeline_2d_wired;
-
- BluCat::Renderer *vk_renderer;
-
- bool quit_game;
-};
-
-extern cg_sCore cg_core;
-
-#endif /* CANDY_GEAR_CORE_H */
diff --git a/src/view_2d.cpp b/src/view_2d.cpp
deleted file mode 100644
index 09cbac1..0000000
--- a/src/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 "blucat/sprite.hpp"
-#include "blucat/view_2d.hpp"
-
-void
-cg_free_view_2d(mrb_state *mrb, void* obj)
-{
- auto ptr = static_cast<std::shared_ptr<BluCat::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::View2D> *ptr;
-
- mrb_get_args(mrb, "dff", &region, &cg_vector_4d_type,
- &projection_width, &projection_height);
- ptr = (std::shared_ptr<BluCat::View2D>*)DATA_PTR(self);
- if(ptr) mrb_free(mrb, ptr);
- ptr = (std::shared_ptr<BluCat::View2D>*)mrb_malloc(
- mrb, sizeof(std::shared_ptr<BluCat::View2D>));
-
- new(ptr)std::shared_ptr<BluCat::View2D>(
- std::make_shared<BluCat::View2D>(
- *region->get(), projection_width, projection_height));
-
- mrb_data_init(self, ptr, &cg_view_2d_type);
- return self;
-}
-
-BluCat::View2D*
-cg_cView_to_view_2d(mrb_state *mrb, mrb_value view_value)
-{
- BluCat::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::View2D>*>(
- DATA_PTR(view_value))->get();
- else if (type == &cg_view_3d_type)
- view_2d = static_cast<BluCat::View2D*>(
- static_cast<std::shared_ptr<BluCat::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));
-}