summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2024-05-16 14:22:35 -0300
committerFrederico Linhares <fred@linhares.blue>2024-05-16 14:22:35 -0300
commitd5a2b6bca9f9cc57dcca19962d5ba9b83d26da3e (patch)
treefa4decb441b0cc5cd189183166a324079f37c45a
parent43821b0cffc5aa419c0218992f06f8962ae54a13 (diff)
refa Move BluCan initialization to BluCat folderHEADmaster
-rw-r--r--src/blucat/animation.hpp2
-rw-r--r--src/blucat/animation/frame.hpp2
-rw-r--r--src/blucat/base_buffer.hpp4
-rw-r--r--src/blucat/binary_reader.cpp (renamed from src/binary_reader.cpp)2
-rw-r--r--src/blucat/binary_reader.hpp (renamed from src/binary_reader.hpp)2
-rw-r--r--src/blucat/character.cpp17
-rw-r--r--src/blucat/character.hpp2
-rw-r--r--src/blucat/command.cpp (renamed from src/command.cpp)0
-rw-r--r--src/blucat/command.hpp (renamed from src/command.hpp)0
-rw-r--r--src/blucat/command_pool.hpp4
-rw-r--r--src/blucat/core.cpp503
-rw-r--r--src/blucat/core.hpp106
-rw-r--r--src/blucat/descriptor_set_layout.cpp18
-rw-r--r--src/blucat/descriptor_set_layout.hpp2
-rw-r--r--src/blucat/destination_buffer.hpp2
-rw-r--r--src/blucat/device.cpp6
-rw-r--r--src/blucat/device.hpp2
-rw-r--r--src/blucat/font.cpp4
-rw-r--r--src/blucat/framebuffer.cpp52
-rw-r--r--src/blucat/framebuffer.hpp2
-rw-r--r--src/blucat/graphics_pipeline_2d_solid.cpp25
-rw-r--r--src/blucat/graphics_pipeline_2d_solid.hpp2
-rw-r--r--src/blucat/graphics_pipeline_2d_solid_layout.cpp10
-rw-r--r--src/blucat/graphics_pipeline_2d_solid_layout.hpp2
-rw-r--r--src/blucat/graphics_pipeline_2d_wired.cpp29
-rw-r--r--src/blucat/graphics_pipeline_2d_wired.hpp2
-rw-r--r--src/blucat/graphics_pipeline_2d_wired_layout.cpp8
-rw-r--r--src/blucat/graphics_pipeline_2d_wired_layout.hpp2
-rw-r--r--src/blucat/graphics_pipeline_3d.cpp27
-rw-r--r--src/blucat/graphics_pipeline_3d.hpp2
-rw-r--r--src/blucat/graphics_pipeline_3d_layout.cpp14
-rw-r--r--src/blucat/graphics_pipeline_3d_layout.hpp2
-rw-r--r--src/blucat/graphics_pipeline_3d_skeletal.cpp28
-rw-r--r--src/blucat/graphics_pipeline_3d_skeletal.hpp2
-rw-r--r--src/blucat/graphics_pipeline_sprite_3d.cpp28
-rw-r--r--src/blucat/graphics_pipeline_sprite_3d.hpp2
-rw-r--r--src/blucat/image.cpp2
-rw-r--r--src/blucat/image.hpp2
-rw-r--r--src/blucat/job_queue.cpp (renamed from src/job_queue.cpp)0
-rw-r--r--src/blucat/job_queue.hpp (renamed from src/job_queue.hpp)0
-rw-r--r--src/blucat/light.cpp28
-rw-r--r--src/blucat/light.hpp2
-rw-r--r--src/blucat/log.cpp (renamed from src/log.cpp)0
-rw-r--r--src/blucat/log.hpp (renamed from src/log.hpp)0
-rw-r--r--src/blucat/qoi.cpp2
-rw-r--r--src/blucat/queue.hpp2
-rw-r--r--src/blucat/queue_family.cpp4
-rw-r--r--src/blucat/queue_family.hpp2
-rw-r--r--src/blucat/rectangle.hpp2
-rw-r--r--src/blucat/render_pass.cpp16
-rw-r--r--src/blucat/render_pass.hpp2
-rw-r--r--src/blucat/renderer.cpp120
-rw-r--r--src/blucat/renderer.hpp2
-rw-r--r--src/blucat/skeletal_mesh.cpp8
-rw-r--r--src/blucat/skeletal_mesh.hpp2
-rw-r--r--src/blucat/skeletal_mesh_vertex.hpp2
-rw-r--r--src/blucat/skeletal_model.cpp15
-rw-r--r--src/blucat/skeletal_model.hpp2
-rw-r--r--src/blucat/sprite.cpp4
-rw-r--r--src/blucat/sprite.hpp2
-rw-r--r--src/blucat/sprite_3d.cpp16
-rw-r--r--src/blucat/sprite_3d.hpp2
-rw-r--r--src/blucat/sprite_to_draw.hpp2
-rw-r--r--src/blucat/static_mesh.cpp8
-rw-r--r--src/blucat/static_mesh.hpp2
-rw-r--r--src/blucat/static_mesh_vertex.hpp2
-rw-r--r--src/blucat/static_model.cpp14
-rw-r--r--src/blucat/static_model.hpp2
-rw-r--r--src/blucat/swapchain.cpp47
-rw-r--r--src/blucat/swapchain.hpp4
-rw-r--r--src/blucat/texture.cpp48
-rw-r--r--src/blucat/texture.hpp2
-rw-r--r--src/blucat/uniform_buffer.hpp2
-rw-r--r--src/blucat/uniform_data_object.hpp2
-rw-r--r--src/blucat/view_2d.cpp20
-rw-r--r--src/blucat/view_2d.hpp2
-rw-r--r--src/blucat/view_3d.cpp16
-rw-r--r--src/blucat/vulkan.hpp34
-rw-r--r--src/blucat/worker.cpp (renamed from src/worker.cpp)0
-rw-r--r--src/blucat/worker.hpp (renamed from src/worker.hpp)0
-rw-r--r--src/candy_gear.cpp8
-rw-r--r--src/core.cpp748
-rw-r--r--src/core.hpp82
-rw-r--r--src/graphic.cpp6
-rw-r--r--src/main.cpp14
-rw-r--r--src/skeletal_model.cpp4
-rw-r--r--src/sprite.cpp2
-rw-r--r--src/sprite_3d.cpp4
-rw-r--r--src/static_model.cpp4
-rw-r--r--src/texture.hpp2
-rw-r--r--src/vector_4d.cpp2
91 files changed, 1173 insertions, 1066 deletions
diff --git a/src/blucat/animation.hpp b/src/blucat/animation.hpp
index c789c5e..b1ddd06 100644
--- a/src/blucat/animation.hpp
+++ b/src/blucat/animation.hpp
@@ -19,7 +19,7 @@
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "animation/frame.hpp"
namespace BluCat
diff --git a/src/blucat/animation/frame.hpp b/src/blucat/animation/frame.hpp
index a1d5f39..663483d 100644
--- a/src/blucat/animation/frame.hpp
+++ b/src/blucat/animation/frame.hpp
@@ -19,7 +19,7 @@
#include <vector>
-#include "../core.hpp"
+#include "../vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/base_buffer.hpp b/src/blucat/base_buffer.hpp
index 03b838c..cdc9f9c 100644
--- a/src/blucat/base_buffer.hpp
+++ b/src/blucat/base_buffer.hpp
@@ -17,8 +17,8 @@
#ifndef CANDY_GEAR_BLUCAT_BASE_BUFFER_H
#define CANDY_GEAR_BLUCAT_BASE_BUFFER_H 1
-#include "../command.hpp"
-#include "core.hpp"
+#include "command.hpp"
+#include "vulkan.hpp"
#include "device.hpp"
namespace BluCat
diff --git a/src/binary_reader.cpp b/src/blucat/binary_reader.cpp
index 0727703..14fc39c 100644
--- a/src/binary_reader.cpp
+++ b/src/blucat/binary_reader.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2023 Frederico de Oliveira Linhares
+ * 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.
diff --git a/src/binary_reader.hpp b/src/blucat/binary_reader.hpp
index e09c13a..1995402 100644
--- a/src/binary_reader.hpp
+++ b/src/blucat/binary_reader.hpp
@@ -17,7 +17,7 @@
#include <cstdint>
#include <string>
-#include "blucat/core.hpp"
+#include "vulkan.hpp"
class BinaryReader
{
diff --git a/src/blucat/character.cpp b/src/blucat/character.cpp
index c13ffef..220295d 100644
--- a/src/blucat/character.cpp
+++ b/src/blucat/character.cpp
@@ -16,8 +16,8 @@
#include "character.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "command.hpp"
+#include "core.hpp"
#include "font.hpp"
#include "image.hpp"
#include "source_buffer.hpp"
@@ -105,7 +105,7 @@ load_image(void *obj)
}
BluCat::SourceBuffer source_image_buffer{
- cg_core.vk_device_with_swapchain, source_image_raw.data(),
+ BluCat::core.vk_device_with_swapchain, source_image_raw.data(),
image_size};
{ // Create Vulkan image.
@@ -117,7 +117,7 @@ load_image(void *obj)
vk_extent3d.depth = 1;
BluCat::Image::create(
- cg_core.vk_device_with_swapchain,
+ BluCat::core.vk_device_with_swapchain,
&self->character->image,
&self->character->device_memory,
VK_FORMAT_R8G8B8A8_UNORM,
@@ -133,7 +133,7 @@ load_image(void *obj)
}
{ // Copy image from buffer into image.
- auto queue_family{cg_core.vk_device_with_swapchain->
+ auto queue_family{BluCat::core.vk_device_with_swapchain->
get_queue_family_with_presentation()};
auto queue{queue_family->get_queue()};
BluCat::CommandPool command_pool{queue_family, 1};
@@ -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::core.vk_device_with_swapchain->device, self->character->image,
+ nullptr);
vkFreeMemory(
- cg_core.vk_device_with_swapchain->device, self->character->device_memory,
- nullptr);
+ BluCat::core.vk_device_with_swapchain->device,
+ self->character->device_memory, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/character.hpp b/src/blucat/character.hpp
index 43cc765..9d0829f 100644
--- a/src/blucat/character.hpp
+++ b/src/blucat/character.hpp
@@ -20,7 +20,7 @@
#include <ft2build.h>
#include FT_FREETYPE_H
-#include "core.hpp"
+#include "vulkan.hpp"
#include <vector>
diff --git a/src/command.cpp b/src/blucat/command.cpp
index a1d3240..a1d3240 100644
--- a/src/command.cpp
+++ b/src/blucat/command.cpp
diff --git a/src/command.hpp b/src/blucat/command.hpp
index 47552a5..47552a5 100644
--- a/src/command.hpp
+++ b/src/blucat/command.hpp
diff --git a/src/blucat/command_pool.hpp b/src/blucat/command_pool.hpp
index aa23387..92451d8 100644
--- a/src/blucat/command_pool.hpp
+++ b/src/blucat/command_pool.hpp
@@ -19,9 +19,9 @@
#include <vector>
-#include "../command.hpp"
-#include "core.hpp"
+#include "command.hpp"
#include "device.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/core.cpp b/src/blucat/core.cpp
new file mode 100644
index 0000000..8478f86
--- /dev/null
+++ b/src/blucat/core.cpp
@@ -0,0 +1,503 @@
+/*
+ * 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"
+
+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::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++)
+ BluCat::core.threads.emplace_back(
+ BluCat::core.workers.emplace_back(&BluCat::core.job_queue));
+}
+
+void
+unload_threads(void *obj)
+{
+ BluCat::core.job_queue.stop();
+ for(auto &t: BluCat::core.threads) t.join();
+}
+
+void
+load_fps(void *obj)
+{
+ using namespace std::chrono;
+
+ BluCat::core.max_frame_duration =
+ duration<long long, std::milli>(1000 / BluCat::core.fps);
+ // FIXME: actually calculates the real delta time.
+ BluCat::core.delta_time = 1.0f / BluCat::core.fps;
+}
+
+void
+load_font_library(void *obj)
+{
+ FT_Error error{FT_Init_FreeType(&BluCat::core.font_library)};
+ if(error) throw CommandError{"Failed to open the FreeType library."};
+}
+
+void
+unload_font_library(void *obj)
+{
+ FT_Done_FreeType(BluCat::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::core.vk_instance,
+ "vkCreateDebugUtilsMessengerEXT");
+
+ if(debug_messenger(BluCat::core.vk_instance, &create_info, nullptr,
+ &BluCat::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::core.vk_instance,
+ "vkDestroyDebugUtilsMessengerEXT");
+
+ debug_messenger(BluCat::core.vk_instance, BluCat::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::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::core.vk_instance, &devices_count, vk_physical_devices.data());
+ }
+
+#ifdef DEBUG
+ BluCat::core.log.message(Log::Level::Trace, "Physical devices properties");
+#endif
+
+ BluCat::core.vk_devices.reserve(devices_count);
+ for(auto i = 0; i < devices_count; i++)
+ {
+ // Use swapchain on first device.
+ if(i == 0)
+ {
+ BluCat::core.vk_devices.emplace_back(vk_physical_devices[i], true);
+ BluCat::core.vk_device_with_swapchain = &BluCat::core.vk_devices[i];
+ }
+ else
+ BluCat::core.vk_devices.emplace_back(vk_physical_devices[i], false);
+ }
+}
+
+void
+unload_devices(void *obj)
+{
+ BluCat::core.vk_devices.clear();
+}
+
+static void
+load_swapchain(void *obj)
+{
+ try { BluCat::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_swapchain(void *obj)
+{
+ delete BluCat::core.vk_swapchain;
+}
+
+void
+load_framebuffer(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_framebuffer = new BluCat::Framebuffer();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create framebuffer."};
+ }
+}
+
+void
+unload_framebuffer(void *obj)
+{
+ delete BluCat::core.vk_framebuffer;
+}
+
+void
+load_render_pass(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_render_pass = new BluCat::RenderPass();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create render pass."};
+ }
+}
+
+void
+unload_render_pass(void *obj)
+{
+ delete BluCat::core.vk_render_pass;
+}
+
+void
+load_descriptor_set_layout(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_descriptor_set_layout = new BluCat::DescriptorSetLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create descriptor set layouts."};
+ }
+}
+
+void
+unload_descriptor_set_layout(void *obj)
+{
+ delete BluCat::core.vk_descriptor_set_layout;
+}
+
+void
+load_graphics_pipeline_3d_layout(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_graphics_pipeline_3d_layout =
+ new BluCat::GraphicsPipeline3DLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 3d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_3d_layout(void *obj)
+{
+ delete BluCat::core.vk_graphics_pipeline_3d_layout;
+}
+
+void
+load_graphics_pipeline_2d_solid_layout(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_graphics_pipeline_2d_solid_layout =
+ new BluCat::GraphicsPipeline2DSolidLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 2d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_2d_solid_layout(void *obj)
+{
+ delete BluCat::core.vk_graphics_pipeline_2d_solid_layout;
+}
+
+void
+load_graphics_pipeline_2d_wired_layout(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_graphics_pipeline_2d_wired_layout =
+ new BluCat::GraphicsPipeline2DWiredLayout();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 2d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_2d_wired_layout(void *obj)
+{
+ delete BluCat::core.vk_graphics_pipeline_2d_wired_layout;
+}
+
+void
+load_light(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_light = new BluCat::Light();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to descriptor sets for light."};
+ }
+}
+
+void
+unload_light(void *obj)
+{
+ delete BluCat::core.vk_light;
+}
+
+void
+load_graphics_pipeline_3d(void *obj)
+{
+ try
+ {
+ BluCat::core.vk_graphics_pipeline_3d =
+ std::make_unique<BluCat::GraphicsPipeline3D>();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create 3d graphics pipeline."};
+ }
+}
+
+void
+unload_graphics_pipeline_3d(void *obj)
+{
+ BluCat::core.vk_graphics_pipeline_3d = nullptr;
+}
+
+void
+load_graphics_pipeline_3d_skeletal(void *obj)
+{
+ try
+ {
+ BluCat::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_graphics_pipeline_3d_skeletal(void *obj)
+{
+ BluCat::core.vk_graphics_pipeline_3d_skeletal = nullptr;
+}
+
+void
+load_graphics_pipeline_sprite_3d(void *obj)
+{
+ try
+ {
+ BluCat::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_graphics_pipeline_sprite_3d(void *obj)
+{
+ BluCat::core.vk_graphics_pipeline_sprite_3d = nullptr;
+}
+
+void
+load_graphics_pipeline_2d_solid(void *obj)
+{
+ try
+ {
+ BluCat::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_graphics_pipeline_2d_solid(void *obj)
+{
+ BluCat::core.vk_graphics_pipeline_2d_solid = nullptr;
+}
+
+void
+load_graphics_pipeline_2d_wired(void *obj)
+{
+ try
+ {
+ BluCat::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_graphics_pipeline_2d_wired(void *obj)
+{
+ BluCat::core.vk_graphics_pipeline_2d_wired = nullptr;
+}
+
+void
+load_renderer(void *obj)
+{
+ try
+ {
+ glm::vec4 region(
+ 0.f, 0.f,
+ static_cast<float>(BluCat::core.display_width),
+ static_cast<float>(BluCat::core.display_height));
+ BluCat::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_renderer(void *obj)
+{
+ delete BluCat::core.vk_renderer;
+}
+
+}
+
+namespace BluCat
+{
+
+std::random_device random_seed;
+std::mt19937 random_number_generator;
+
+const CommandChain Core::loader{
+ {&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/blucat/core.hpp b/src/blucat/core.hpp
index 169e3bc..c1924b9 100644
--- a/src/blucat/core.hpp
+++ b/src/blucat/core.hpp
@@ -17,18 +17,98 @@
#ifndef CANDY_GEAR_BLUCAT_CORE_H
#define CANDY_GEAR_BLUCAT_CORE_H 1
-// GLM uses some definitions to control their behavior, so you should not
-// include it directly. Instead, use this header.
-#define GLM_ENABLE_EXPERIMENTAL
-#define GLM_FORCE_RADIANS
-#define GLM_FORCE_DEPTH_ZERO_TO_ONE
-
-#include <glm/ext/vector_float3.hpp>
-#include <glm/ext.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/gtx/quaternion.hpp>
-#include <glm/vec3.hpp>
-
-#include <vulkan/vulkan.h>
+#include <chrono>
+#include <cstdint>
+#include <memory>
+#include <random>
+
+#include "command.hpp"
+#include "device.hpp"
+#include "descriptor_set_layout.hpp"
+#include "framebuffer.hpp"
+#include "graphics_pipeline_2d_solid_layout.hpp"
+#include "graphics_pipeline_2d_wired_layout.hpp"
+#include "graphics_pipeline_2d_solid.hpp"
+#include "graphics_pipeline_2d_wired.hpp"
+#include "graphics_pipeline_3d_layout.hpp"
+#include "graphics_pipeline_3d.hpp"
+#include "graphics_pipeline_3d_skeletal.hpp"
+#include "graphics_pipeline_sprite_3d.hpp"
+#include "job_queue.hpp"
+#include "light.hpp"
+#include "log.hpp"
+#include "render_pass.hpp"
+#include "renderer.hpp"
+#include "swapchain.hpp"
+#include "vulkan.hpp"
+#include "worker.hpp"
+
+namespace BluCat
+{
+
+extern std::random_device random_seed;
+extern std::mt19937 random_number_generator;
+
+struct Core
+{
+ static const CommandChain loader;
+
+ Log::Logger log;
+
+ JobQueue job_queue;
+ std::vector<Worker> workers;
+ std::vector<std::thread> threads;
+
+ /// 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_t fps;
+ std::chrono::duration<long long, std::milli> max_frame_duration;
+ float delta_time;
+
+ FT_Library font_library;
+
+ VkSurfaceKHR window_surface;
+ VkInstance vk_instance;
+
+#ifdef DEBUG
+ VkDebugUtilsMessengerEXT vk_callback;
+#endif
+
+ // Vulkan devices.
+ std::vector<Device> vk_devices;
+ Device *vk_device_with_swapchain;
+ Swapchain *vk_swapchain;
+
+ Framebuffer *vk_framebuffer;
+ RenderPass *vk_render_pass;
+ DescriptorSetLayout *vk_descriptor_set_layout;
+ GraphicsPipeline3DLayout *vk_graphics_pipeline_3d_layout;
+ GraphicsPipeline2DSolidLayout *vk_graphics_pipeline_2d_solid_layout;
+ GraphicsPipeline2DWiredLayout *vk_graphics_pipeline_2d_wired_layout;
+ Light *vk_light;
+ std::unique_ptr<GraphicsPipeline3D> vk_graphics_pipeline_3d;
+ std::unique_ptr<GraphicsPipeline3DSkeletal>
+ vk_graphics_pipeline_3d_skeletal;
+ std::unique_ptr<GraphicsPipelineSprite3D> vk_graphics_pipeline_sprite_3d;
+ std::unique_ptr<GraphicsPipeline2DSolid> vk_graphics_pipeline_2d_solid;
+ std::unique_ptr<GraphicsPipeline2DWired> vk_graphics_pipeline_2d_wired;
+
+ Renderer *vk_renderer;
+};
+
+extern Core core;
+
+}
#endif /* CANDY_GEAR_BLUCAT_CORE_H */
diff --git a/src/blucat/descriptor_set_layout.cpp b/src/blucat/descriptor_set_layout.cpp
index 0fc5208..7d32346 100644
--- a/src/blucat/descriptor_set_layout.cpp
+++ b/src/blucat/descriptor_set_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
namespace
{
@@ -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::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."};
@@ -61,7 +61,7 @@ unload_world(void *obj)
auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->world, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->world, nullptr);
}
void
@@ -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::core.vk_device_with_swapchain->device, &layout_info, nullptr,
&self->view) != VK_SUCCESS)
throw CommandError{
"Failed to create Vulkan descriptor set layout for view."};
@@ -97,7 +97,7 @@ unload_view(void *obj)
auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->view, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->view, nullptr);
}
void
@@ -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::core.vk_device_with_swapchain->device, &layout_info, nullptr,
&self->texture) != VK_SUCCESS)
throw CommandError{
"Failed to create Vulkan descriptor set layout for textures."};
@@ -134,7 +134,7 @@ unload_texture(void *obj)
auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->texture, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->texture, nullptr);
}
void
@@ -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::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."};
@@ -169,7 +169,7 @@ unload_model(void *obj)
auto self = static_cast<BluCat::DescriptorSetLayout*>(obj);
vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->model, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->model, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/descriptor_set_layout.hpp b/src/blucat/descriptor_set_layout.hpp
index 144a137..0724e40 100644
--- a/src/blucat/descriptor_set_layout.hpp
+++ b/src/blucat/descriptor_set_layout.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_DESCRIPTOR_SET_LAYOUT_H
#define CANDY_GEAR_BLUCAT_DESCRIPTOR_SET_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/destination_buffer.hpp b/src/blucat/destination_buffer.hpp
index 8c098ab..7f5fb4b 100644
--- a/src/blucat/destination_buffer.hpp
+++ b/src/blucat/destination_buffer.hpp
@@ -18,7 +18,7 @@
#define CANDY_GEAR_BLUCAT_DESTINATION_BUFFER_H 1
#include "base_buffer.hpp"
-#include "core.hpp"
+#include "vulkan.hpp"
#include "source_buffer.hpp"
#include "queue_family.hpp"
diff --git a/src/blucat/device.cpp b/src/blucat/device.cpp
index cf21fa4..8ce6d17 100644
--- a/src/blucat/device.cpp
+++ b/src/blucat/device.cpp
@@ -23,7 +23,7 @@
#include <sstream>
#endif
-#include "../core.hpp"
+#include "core.hpp"
namespace
{
@@ -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());
+ core.log.message(Log::Level::Trace, message.str());
#endif
std::vector<VkDeviceQueueCreateInfo> device_queue_create_infos;
@@ -300,7 +300,7 @@ 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, core.window_surface, &present_supported);
if(present_supported)
this->queue_families_with_presentation.push_back(
&this->queue_families[i]);
diff --git a/src/blucat/device.hpp b/src/blucat/device.hpp
index bcfca4d..61e87a4 100644
--- a/src/blucat/device.hpp
+++ b/src/blucat/device.hpp
@@ -20,7 +20,7 @@
#include <cstdlib>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "queue_family.hpp"
namespace BluCat
diff --git a/src/blucat/font.cpp b/src/blucat/font.cpp
index 4195b57..603dda1 100644
--- a/src/blucat/font.cpp
+++ b/src/blucat/font.cpp
@@ -16,7 +16,7 @@
#include "font.hpp"
-#include "../core.hpp"
+#include "core.hpp"
namespace BluCat
{
@@ -24,7 +24,7 @@ namespace BluCat
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(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/framebuffer.cpp b/src/blucat/framebuffer.cpp
index e761ff2..c4d3230 100644
--- a/src/blucat/framebuffer.cpp
+++ b/src/blucat/framebuffer.cpp
@@ -16,7 +16,8 @@
#include "framebuffer.hpp"
-#include "../core.hpp"
+#include "command.hpp"
+#include "core.hpp"
#include "image.hpp"
namespace
@@ -27,14 +28,14 @@ load_depth_image(void *obj)
auto self = static_cast<BluCat::Framebuffer*>(obj);
VkExtent3D extent3d{};
- extent3d.width = cg_core.display_width;
- extent3d.height = cg_core.display_height;
+ extent3d.width = BluCat::core.display_width;
+ extent3d.height = BluCat::core.display_height;
extent3d.depth = 1;
try
{
BluCat::Image::create(
- cg_core.vk_device_with_swapchain,
+ BluCat::core.vk_device_with_swapchain,
&self->depth_image,
&self->depth_image_memory,
VK_FORMAT_D32_SFLOAT,
@@ -58,10 +59,10 @@ unload_depth_image(void *obj)
auto self = static_cast<BluCat::Framebuffer*>(obj);
vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->depth_image,
+ BluCat::core.vk_device_with_swapchain->device, self->depth_image,
nullptr);
vkFreeMemory(
- cg_core.vk_device_with_swapchain->device,
+ BluCat::core.vk_device_with_swapchain->device,
self->depth_image_memory, nullptr);
}
@@ -73,7 +74,7 @@ load_depth_image_view(void *obj)
try
{
BluCat::Image::create_view(
- cg_core.vk_device_with_swapchain, &self->depth_image_view,
+ BluCat::core.vk_device_with_swapchain, &self->depth_image_view,
self->depth_image,
VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_DEPTH_BIT);
}
@@ -91,7 +92,8 @@ unload_depth_image_view(void *obj)
auto self = static_cast<BluCat::Framebuffer*>(obj);
vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->depth_image_view, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->depth_image_view,
+ nullptr);
}
void
@@ -99,26 +101,26 @@ load_3d(void *obj)
{
auto self = static_cast<BluCat::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::core.vk_swapchain->images_count);
+ for (auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
{
std::array<VkImageView, 2> attachments = {
- cg_core.vk_swapchain->image_views[i],
+ BluCat::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::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::core.display_width;
+ framebuffer_info.height = BluCat::core.display_height;
framebuffer_info.layers = 1;
if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
+ BluCat::core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
&self->pipeline_3d[i]) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Framebuffer."};
}
@@ -131,7 +133,7 @@ unload_3d(void *obj)
for(auto framebuffer: self->pipeline_3d)
vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, framebuffer, nullptr);
}
void
@@ -139,25 +141,25 @@ load_2d(void *obj)
{
auto self = static_cast<BluCat::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::core.vk_swapchain->images_count);
+ for (auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
{
std::array<VkImageView, 1> attachments = {
- cg_core.vk_swapchain->image_views[i]
+ BluCat::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::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::core.display_width;
+ framebuffer_info.height = BluCat::core.display_height;
framebuffer_info.layers = 1;
if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
- &self->pipeline_2d[i])
+ BluCat::core.vk_device_with_swapchain->device, &framebuffer_info,
+ nullptr, &self->pipeline_2d[i])
!= VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Framebuffer."};
}
@@ -170,7 +172,7 @@ unload_2d(void *obj)
for(auto framebuffer: self->pipeline_2d)
vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, framebuffer, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/framebuffer.hpp b/src/blucat/framebuffer.hpp
index 32968a6..e9303f8 100644
--- a/src/blucat/framebuffer.hpp
+++ b/src/blucat/framebuffer.hpp
@@ -19,7 +19,7 @@
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/graphics_pipeline_2d_solid.cpp b/src/blucat/graphics_pipeline_2d_solid.cpp
index 28b19b6..afd8a2e 100644
--- a/src/blucat/graphics_pipeline_2d_solid.cpp
+++ b/src/blucat/graphics_pipeline_2d_solid.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -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::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::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::core.display_width;
+ viewport.height = BluCat::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::core.display_width, BluCat::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::core.vk_graphics_pipeline_2d_solid_layout->pipeline;
+ pipeline_info.renderPass = BluCat::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::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."};
@@ -210,7 +210,8 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DSolid*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -276,7 +277,7 @@ GraphicsPipeline2DSolid::draw(
vkCmdBindDescriptorSets(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline, 0,
+ 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,7 +286,7 @@ GraphicsPipeline2DSolid::draw(
UDOVector4D position{sprite_to_draw.position};
vkCmdPushConstants(
draw_command_buffer,
- cg_core.vk_graphics_pipeline_2d_solid_layout->pipeline,
+ 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);
}
diff --git a/src/blucat/graphics_pipeline_2d_solid.hpp b/src/blucat/graphics_pipeline_2d_solid.hpp
index eae54ae..753e9d8 100644
--- a/src/blucat/graphics_pipeline_2d_solid.hpp
+++ b/src/blucat/graphics_pipeline_2d_solid.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
#include "view_2d.hpp"
diff --git a/src/blucat/graphics_pipeline_2d_solid_layout.cpp b/src/blucat/graphics_pipeline_2d_solid_layout.cpp
index 7b537a2..666556d 100644
--- a/src/blucat/graphics_pipeline_2d_solid_layout.cpp
+++ b/src/blucat/graphics_pipeline_2d_solid_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -30,8 +30,8 @@ load_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DSolidLayout*>(obj);
std::array<VkDescriptorSetLayout, 2> set_layouts{
- cg_core.vk_descriptor_set_layout->view,
- cg_core.vk_descriptor_set_layout->texture
+ BluCat::core.vk_descriptor_set_layout->view,
+ BluCat::core.vk_descriptor_set_layout->texture
};
std::array<VkPushConstantRange, 1> push_constants;
@@ -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::core.vk_device_with_swapchain->device, &pipeline_layout_info,
nullptr, &self->pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan pipeline layout."};
}
@@ -58,7 +58,7 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DSolidLayout*>(obj);
vkDestroyPipelineLayout(
- cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/graphics_pipeline_2d_solid_layout.hpp b/src/blucat/graphics_pipeline_2d_solid_layout.hpp
index 77172be..f6a8960 100644
--- a/src/blucat/graphics_pipeline_2d_solid_layout.hpp
+++ b/src/blucat/graphics_pipeline_2d_solid_layout.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_LAYOUT_H
#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/graphics_pipeline_2d_wired.cpp b/src/blucat/graphics_pipeline_2d_wired.cpp
index 192a9d6..9cd3a86 100644
--- a/src/blucat/graphics_pipeline_2d_wired.cpp
+++ b/src/blucat/graphics_pipeline_2d_wired.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "rectangle.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -32,7 +32,7 @@ load_indexes(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DWired*>(obj);
self->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::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()};
@@ -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::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::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::core.display_width;
+ viewport.height = BluCat::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::core.display_width, BluCat::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::core.vk_graphics_pipeline_2d_wired_layout->pipeline;
+ pipeline_info.renderPass = BluCat::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::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."};
}
@@ -221,7 +221,8 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DWired*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -277,7 +278,7 @@ GraphicsPipeline2DWired::draw(
vkCmdBindDescriptorSets(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
- cg_core.vk_graphics_pipeline_2d_wired_layout->pipeline, 0,
+ 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,
@@ -294,11 +295,11 @@ GraphicsPipeline2DWired::draw(
UDOVector3D color{rect.color};
vkCmdPushConstants(
draw_command_buffer,
- cg_core.vk_graphics_pipeline_2d_wired_layout->pipeline,
+ 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,
+ core.vk_graphics_pipeline_2d_wired_layout->pipeline,
VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(UDOVector4D), sizeof(UDOVector3D),
&color);
vkCmdDrawIndexed(
diff --git a/src/blucat/graphics_pipeline_2d_wired.hpp b/src/blucat/graphics_pipeline_2d_wired.hpp
index 32d965b..a351aee 100644
--- a/src/blucat/graphics_pipeline_2d_wired.hpp
+++ b/src/blucat/graphics_pipeline_2d_wired.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "view_2d.hpp"
namespace BluCat
diff --git a/src/blucat/graphics_pipeline_2d_wired_layout.cpp b/src/blucat/graphics_pipeline_2d_wired_layout.cpp
index eaa6af7..104c599 100644
--- a/src/blucat/graphics_pipeline_2d_wired_layout.cpp
+++ b/src/blucat/graphics_pipeline_2d_wired_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "graphics_pipeline_2d_solid_layout.hpp"
#include "uniform_data_object.hpp"
@@ -31,7 +31,7 @@ load_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DWiredLayout*>(obj);
std::array<VkDescriptorSetLayout, 1> set_layouts{
- cg_core.vk_descriptor_set_layout->view
+ BluCat::core.vk_descriptor_set_layout->view
};
std::array<VkPushConstantRange, 2> push_constants;
@@ -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::core.vk_device_with_swapchain->device, &pipeline_layout_info,
nullptr, &self->pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan pipeline layout."};
}
@@ -62,7 +62,7 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline2DWiredLayout*>(obj);
vkDestroyPipelineLayout(
- cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/graphics_pipeline_2d_wired_layout.hpp b/src/blucat/graphics_pipeline_2d_wired_layout.hpp
index d447230..402e7dc 100644
--- a/src/blucat/graphics_pipeline_2d_wired_layout.hpp
+++ b/src/blucat/graphics_pipeline_2d_wired_layout.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_LAYOUT_H
#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_2D_WIRED_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/graphics_pipeline_3d.cpp b/src/blucat/graphics_pipeline_3d.cpp
index c1b60a6..bd64ebc 100644
--- a/src/blucat/graphics_pipeline_3d.cpp
+++ b/src/blucat/graphics_pipeline_3d.cpp
@@ -19,8 +19,8 @@
#include <array>
#include <stdexcept>
-#include "../core.hpp"
#include "core.hpp"
+#include "vulkan.hpp"
#include "static_mesh_vertex.hpp"
#include "uniform_data_object.hpp"
@@ -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::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::core.vk_device_with_swapchain->frag3d_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -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::core.display_width;
+ viewport.height = BluCat::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::core.display_width, BluCat::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::core.vk_graphics_pipeline_3d_layout->pipeline;
+ pipeline_info.renderPass = BluCat::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::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."};
@@ -232,7 +232,8 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline3D*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -265,7 +266,7 @@ GraphicsPipeline3D::draw(
// Draw models
for(auto& [static_mesh, instances]:
- cg_core.vk_renderer->static_models_to_draw[current_frame])
+ core.vk_renderer->static_models_to_draw[current_frame])
{
VkBuffer vertex_buffers[]{static_mesh->vertex_buffer->buffer};
VkDeviceSize offsets[]{0};
@@ -284,14 +285,14 @@ 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],
+ core.vk_light->descriptor_sets_world[image_index],
view->descriptor_sets_3d[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,
+ core.vk_graphics_pipeline_3d_layout->pipeline, 0,
vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr);
vkCmdDrawIndexed(
diff --git a/src/blucat/graphics_pipeline_3d.hpp b/src/blucat/graphics_pipeline_3d.hpp
index de0c422..6942955 100644
--- a/src/blucat/graphics_pipeline_3d.hpp
+++ b/src/blucat/graphics_pipeline_3d.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
#include "view_3d.hpp"
diff --git a/src/blucat/graphics_pipeline_3d_layout.cpp b/src/blucat/graphics_pipeline_3d_layout.cpp
index b2a54d6..6bac1bb 100644
--- a/src/blucat/graphics_pipeline_3d_layout.cpp
+++ b/src/blucat/graphics_pipeline_3d_layout.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -30,10 +30,10 @@ load_pipeline(void *obj)
auto self = static_cast<BluCat::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::core.vk_descriptor_set_layout->world,
+ BluCat::core.vk_descriptor_set_layout->view,
+ BluCat::core.vk_descriptor_set_layout->model,
+ BluCat::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::core.vk_device_with_swapchain->device,
&pipeline_layout_info, nullptr, &self->pipeline) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan pipeline layout."};
}
@@ -54,7 +54,7 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline3DLayout*>(obj);
vkDestroyPipelineLayout(
- cg_core.vk_device_with_swapchain->device, self->pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->pipeline, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/graphics_pipeline_3d_layout.hpp b/src/blucat/graphics_pipeline_3d_layout.hpp
index 2b44dac..bc86646 100644
--- a/src/blucat/graphics_pipeline_3d_layout.hpp
+++ b/src/blucat/graphics_pipeline_3d_layout.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_LAYOUT_H
#define CANDY_GEAR_BLUCAT_GRAPHICS_PIPELINE_3D_LAYOUT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/graphics_pipeline_3d_skeletal.cpp b/src/blucat/graphics_pipeline_3d_skeletal.cpp
index b039c00..6b56221 100644
--- a/src/blucat/graphics_pipeline_3d_skeletal.cpp
+++ b/src/blucat/graphics_pipeline_3d_skeletal.cpp
@@ -19,7 +19,6 @@
#include <array>
#include <stdexcept>
-#include "../core.hpp"
#include "core.hpp"
#include "skeletal_mesh_vertex.hpp"
#include "uniform_data_object.hpp"
@@ -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::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::core.vk_device_with_swapchain->frag3d_shader_module;
frag_shader_stage_info.pName = "main";
frag_shader_stage_info.pSpecializationInfo = nullptr;
@@ -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::core.display_width;
+ viewport.height = BluCat::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::core.display_width, BluCat::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::core.vk_graphics_pipeline_3d_layout->pipeline;
+ pipeline_info.renderPass = BluCat::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::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."};
@@ -242,7 +241,8 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipeline3DSkeletal*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -275,7 +275,7 @@ GraphicsPipeline3DSkeletal::draw(
// Draw models
for(auto& [skeletal_mesh, instances]:
- cg_core.vk_renderer->skeletal_models_to_draw[current_frame])
+ 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],
+ core.vk_light->descriptor_sets_world[image_index],
view->descriptor_sets_3d[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,
+ 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);
+ instance->tick(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/blucat/graphics_pipeline_3d_skeletal.hpp
index 430d2ec..52810f6 100644
--- a/src/blucat/graphics_pipeline_3d_skeletal.hpp
+++ b/src/blucat/graphics_pipeline_3d_skeletal.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
#include "view_3d.hpp"
diff --git a/src/blucat/graphics_pipeline_sprite_3d.cpp b/src/blucat/graphics_pipeline_sprite_3d.cpp
index a71e8bc..f87b7e1 100644
--- a/src/blucat/graphics_pipeline_sprite_3d.cpp
+++ b/src/blucat/graphics_pipeline_sprite_3d.cpp
@@ -18,7 +18,6 @@
#include <array>
-#include "../core.hpp"
#include "core.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -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::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::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::core.display_width;
+ viewport.height = BluCat::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::core.display_width, BluCat::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::core.vk_graphics_pipeline_3d_layout->pipeline;
+ pipeline_info.renderPass = BluCat::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::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."};
@@ -241,7 +240,8 @@ unload_pipeline(void *obj)
auto self = static_cast<BluCat::GraphicsPipelineSprite3D*>(obj);
vkDestroyPipeline(
- cg_core.vk_device_with_swapchain->device, self->graphic_pipeline, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->graphic_pipeline,
+ nullptr);
}
const CommandChain loader{
@@ -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());
+ 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])
+ core.vk_renderer->sprites_3d_to_draw[current_frame])
sprite_3d_order.emplace_back(
sprite, glm::distance(*view->camera_position, *sprite->position));
@@ -289,7 +289,7 @@ GraphicsPipelineSprite3D::draw(
for(auto& sprite: sprite_3d_order)
{
std::array<VkDescriptorSet, 4> vk_descriptor_sets{
- cg_core.vk_light->descriptor_sets_world[image_index],
+ core.vk_light->descriptor_sets_world[image_index],
view->descriptor_sets_3d[image_index],
sprite.sprite_3d->descriptor_sets[image_index],
sprite.sprite_3d->sprite->texture->descriptor_sets[image_index]};
@@ -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,
+ 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/blucat/graphics_pipeline_sprite_3d.hpp
index 969f905..237094d 100644
--- a/src/blucat/graphics_pipeline_sprite_3d.hpp
+++ b/src/blucat/graphics_pipeline_sprite_3d.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "command_pool.hpp"
#include "sprite_3d.hpp"
#include "view_3d.hpp"
diff --git a/src/blucat/image.cpp b/src/blucat/image.cpp
index 7f8633f..81b1563 100644
--- a/src/blucat/image.cpp
+++ b/src/blucat/image.cpp
@@ -16,7 +16,7 @@
#include "image.hpp"
-#include "../core.hpp"
+#include "core.hpp"
namespace BluCat::Image
{
diff --git a/src/blucat/image.hpp b/src/blucat/image.hpp
index cb6cfd4..67c1933 100644
--- a/src/blucat/image.hpp
+++ b/src/blucat/image.hpp
@@ -20,7 +20,7 @@
#include <memory>
#include <string>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "device.hpp"
namespace BluCat::Image
diff --git a/src/job_queue.cpp b/src/blucat/job_queue.cpp
index 49bf34f..49bf34f 100644
--- a/src/job_queue.cpp
+++ b/src/blucat/job_queue.cpp
diff --git a/src/job_queue.hpp b/src/blucat/job_queue.hpp
index 2a7735b..2a7735b 100644
--- a/src/job_queue.hpp
+++ b/src/blucat/job_queue.hpp
diff --git a/src/blucat/light.cpp b/src/blucat/light.cpp
index 5efc6ec..43611a1 100644
--- a/src/blucat/light.cpp
+++ b/src/blucat/light.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -31,10 +31,10 @@ load_world_vert_uniform_buffer(void *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::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->ub_world_vert.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOWorld3D_Vert));
+ BluCat::core.vk_device_with_swapchain, sizeof(BluCat::UDOWorld3D_Vert));
}
catch(const std::exception& e)
{
@@ -57,10 +57,10 @@ load_world_frag_uniform_buffer(void *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::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->ub_world_frag.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOWorld3D_Frag));
+ BluCat::core.vk_device_with_swapchain, sizeof(BluCat::UDOWorld3D_Frag));
}
catch(const std::exception& e)
{
@@ -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::core.vk_device_with_swapchain->device, &pool_info, nullptr,
&self->descriptor_pool) != VK_SUCCESS)
throw CommandError{"Failed to create a Vulkan descriptor pool."};
}
@@ -108,7 +108,7 @@ unload_descriptor_pool(void *obj)
auto self = static_cast<BluCat::Light*>(obj);
vkDestroyDescriptorPool(
- cg_core.vk_device_with_swapchain->device, self->descriptor_pool,
+ BluCat::core.vk_device_with_swapchain->device, self->descriptor_pool,
nullptr);
}
@@ -118,8 +118,8 @@ load_descriptor_sets_world(void *obj)
auto self = static_cast<BluCat::Light*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->world);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::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::core.vk_device_with_swapchain->device, &alloc_info,
self->descriptor_sets_world.data()) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan world descriptor set."};
}
@@ -139,7 +139,7 @@ load_resources_to_descriptor_sets(void *obj)
{
auto self = static_cast<BluCat::Light*>(obj);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
{
VkDescriptorBufferInfo world_vert_info{};
world_vert_info.buffer = self->ub_world_vert[i].buffer;
@@ -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::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
diff --git a/src/blucat/light.hpp b/src/blucat/light.hpp
index 7e1d3a1..f5f153e 100644
--- a/src/blucat/light.hpp
+++ b/src/blucat/light.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_LIGHT_H
#define CANDY_GEAR_BLUCAT_LIGHT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
#include "uniform_buffer.hpp"
namespace BluCat
diff --git a/src/log.cpp b/src/blucat/log.cpp
index 78044c4..78044c4 100644
--- a/src/log.cpp
+++ b/src/blucat/log.cpp
diff --git a/src/log.hpp b/src/blucat/log.hpp
index 2856f20..2856f20 100644
--- a/src/log.hpp
+++ b/src/blucat/log.hpp
diff --git a/src/blucat/qoi.cpp b/src/blucat/qoi.cpp
index 663e4e9..3169ecc 100644
--- a/src/blucat/qoi.cpp
+++ b/src/blucat/qoi.cpp
@@ -19,7 +19,7 @@
#include <array>
#include <fstream>
-#include "../binary_reader.hpp"
+#include "binary_reader.hpp"
namespace
{
diff --git a/src/blucat/queue.hpp b/src/blucat/queue.hpp
index a71dc9d..3be1a94 100644
--- a/src/blucat/queue.hpp
+++ b/src/blucat/queue.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_QUEUE_H
#define CANDY_GEAR_BLUCAT_QUEUE_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/queue_family.cpp b/src/blucat/queue_family.cpp
index 32aaf4b..da799c0 100644
--- a/src/blucat/queue_family.cpp
+++ b/src/blucat/queue_family.cpp
@@ -20,7 +20,7 @@
#include <sstream>
#endif
-#include "../core.hpp"
+#include "core.hpp"
namespace BluCat
{
@@ -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());
+ core.log.message(Log::Level::Trace, message.str());
#endif
this->device = device;
diff --git a/src/blucat/queue_family.hpp b/src/blucat/queue_family.hpp
index 2486316..988748f 100644
--- a/src/blucat/queue_family.hpp
+++ b/src/blucat/queue_family.hpp
@@ -20,7 +20,7 @@
#include <mutex>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "queue.hpp"
namespace BluCat
diff --git a/src/blucat/rectangle.hpp b/src/blucat/rectangle.hpp
index 876508c..57c9d4f 100644
--- a/src/blucat/rectangle.hpp
+++ b/src/blucat/rectangle.hpp
@@ -19,7 +19,7 @@
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
diff --git a/src/blucat/render_pass.cpp b/src/blucat/render_pass.cpp
index 0eb30e3..2effe6b 100644
--- a/src/blucat/render_pass.cpp
+++ b/src/blucat/render_pass.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
namespace
{
@@ -31,7 +31,7 @@ load_3d(void *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::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,8 +95,8 @@ 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::core.vk_device_with_swapchain->device, &render_pass_info,
+ nullptr, &self->pipeline_3d) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Render Pass 3D."};
}
@@ -106,7 +106,7 @@ unload_3d(void *obj)
auto self = static_cast<BluCat::RenderPass*>(obj);
vkDestroyRenderPass(
- cg_core.vk_device_with_swapchain->device, self->pipeline_3d, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->pipeline_3d, nullptr);
}
void
@@ -117,7 +117,7 @@ load_2d(void *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::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::core.vk_device_with_swapchain->device, &render_pass_info,
nullptr, &self->pipeline_2d) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan Render Pass 2D."};
}
@@ -177,7 +177,7 @@ unload_2d(void *obj)
auto self = static_cast<BluCat::RenderPass*>(obj);
vkDestroyRenderPass(
- cg_core.vk_device_with_swapchain->device, self->pipeline_2d, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->pipeline_2d, nullptr);
}
const CommandChain loader{
diff --git a/src/blucat/render_pass.hpp b/src/blucat/render_pass.hpp
index 196ce97..d55f908 100644
--- a/src/blucat/render_pass.hpp
+++ b/src/blucat/render_pass.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_RENDER_PASS_H
#define CANDY_GEAR_BLUCAT_RENDER_PASS_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/renderer.cpp b/src/blucat/renderer.cpp
index 75822e0..5777203 100644
--- a/src/blucat/renderer.cpp
+++ b/src/blucat/renderer.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -48,7 +48,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::core.vk_device_with_swapchain->device, &pool_info, nullptr,
&self->descriptor_pool) != VK_SUCCESS)
throw CommandError{"Failed to create a Vulkan descriptor pool."};
@@ -67,7 +67,7 @@ unload_descriptor_pool(void *obj)
for(auto &view : self->views_2d) view->unload_descriptor_sets();
vkDestroyDescriptorPool(
- cg_core.vk_device_with_swapchain->device, self->descriptor_pool,
+ BluCat::core.vk_device_with_swapchain->device, self->descriptor_pool,
nullptr);
}
@@ -77,7 +77,7 @@ load_queue_family(void *obj)
auto self = static_cast<BluCat::Renderer*>(obj);
self->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::core.vk_device_with_swapchain->get_queue_family_with_presentation();
}
void
@@ -101,9 +101,9 @@ unload_command_pool(void *obj)
{
auto self = static_cast<BluCat::Renderer*>(obj);
- vkWaitForFences(cg_core.vk_device_with_swapchain->device,
+ vkWaitForFences(BluCat::core.vk_device_with_swapchain->device,
BluCat::Swapchain::max_frames_in_flight,
- cg_core.vk_swapchain->in_flight_fences.data(), VK_TRUE,
+ BluCat::core.vk_swapchain->in_flight_fences.data(), VK_TRUE,
std::numeric_limits<uint64_t>::max());
vkDestroyCommandPool(
self->queue_family->device->device, self->command_pool, nullptr);
@@ -144,9 +144,9 @@ namespace BluCat
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},
+ skeletal_models_to_draw{BluCat::core.vk_swapchain->images_count},
+ static_models_to_draw{BluCat::core.vk_swapchain->images_count},
+ sprites_3d_to_draw{BluCat::core.vk_swapchain->images_count},
views_2d{views_2d},
views_3d{views_3d}
{
@@ -168,28 +168,29 @@ 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::core.vk_device_with_swapchain->device,
+ BluCat::core.vk_swapchain->in_flight_fences[
+ BluCat::core.vk_swapchain->current_frame]);
if(fence_status == VK_SUCCESS)
{
- auto next_frame = cg_core.vk_swapchain->current_frame + 1;
+ auto next_frame = BluCat::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(core.vk_device_with_swapchain->device, 1,
+ &BluCat::core.vk_swapchain->in_flight_fences[
+ BluCat::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::core.vk_device_with_swapchain->device,
+ BluCat::core.vk_swapchain->swapchain,
+ std::numeric_limits<uint64_t>::max(),
+ BluCat::core.vk_swapchain->image_available_semaphores[
+ BluCat::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::core.vk_swapchain->current_frame];
vkResetCommandBuffer(draw_command_buffer, 0);
// Begin command buffer.
@@ -213,7 +214,7 @@ Renderer::draw()
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::core.vk_light->ub_world_vert[image_index].copy_data(
&ubo_world_3d_vert);
UDOWorld3D_Frag ubo_world_3d_frag{};
@@ -221,20 +222,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::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::core.vk_render_pass->pipeline_3d;
render_pass_begin.framebuffer =
- cg_core.vk_framebuffer->pipeline_3d[image_index];
+ BluCat::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::core.display_width),
+ static_cast<uint32_t>(BluCat::core.display_height)};
render_pass_begin.clearValueCount = clear_values.size();
render_pass_begin.pClearValues = clear_values.data();
@@ -262,16 +263,16 @@ 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::core.vk_graphics_pipeline_3d->draw(
+ view, draw_command_buffer, BluCat::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,
+ BluCat::core.vk_graphics_pipeline_sprite_3d->draw(
+ view, draw_command_buffer, BluCat::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,
+ BluCat::core.vk_graphics_pipeline_3d_skeletal->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
image_index);
{ // Update view uniform buffers
@@ -300,13 +301,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::core.vk_render_pass->pipeline_2d;
render_pass_begin.framebuffer =
- cg_core.vk_framebuffer->pipeline_2d[image_index];
+ BluCat::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::core.display_width),
+ static_cast<uint32_t>(BluCat::core.display_height)};
render_pass_begin.clearValueCount = 0;
render_pass_begin.pClearValues = nullptr;
@@ -317,25 +318,25 @@ 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,
+ BluCat::core.vk_graphics_pipeline_2d_solid->draw(
+ view, draw_command_buffer, BluCat::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,
+ BluCat::core.vk_graphics_pipeline_2d_solid->draw(
+ view, draw_command_buffer, BluCat::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,
+ BluCat::core.vk_graphics_pipeline_2d_wired->draw(
+ view, draw_command_buffer, BluCat::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,
+ BluCat::core.vk_graphics_pipeline_2d_wired->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
next_frame, image_index);
}
@@ -350,13 +351,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::core.vk_swapchain->image_available_semaphores[
+ BluCat::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::core.vk_swapchain->render_finished_semaphores[
+ BluCat::core.vk_swapchain->current_frame]};
VkSubmitInfo submit_info{};
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -370,11 +371,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::core.vk_swapchain->in_flight_fences[
+ BluCat::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::core.vk_swapchain->swapchain};
VkPresentInfoKHR present_info{};
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
@@ -394,19 +395,22 @@ 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::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();
+ this->skeletal_models_to_draw[
+ BluCat::core.vk_swapchain->current_frame].clear();
+ this->static_models_to_draw[
+ BluCat::core.vk_swapchain->current_frame].clear();
+ this->sprites_3d_to_draw[
+ BluCat::core.vk_swapchain->current_frame].clear();
for(auto &view: this->views_2d)
- view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear();
+ view->sprites_to_draw[BluCat::core.vk_swapchain->current_frame].clear();
for(auto &view: this->views_3d)
- view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear();
+ view->sprites_to_draw[BluCat::core.vk_swapchain->current_frame].clear();
}
}
diff --git a/src/blucat/renderer.hpp b/src/blucat/renderer.hpp
index d23ebe5..2da6ae9 100644
--- a/src/blucat/renderer.hpp
+++ b/src/blucat/renderer.hpp
@@ -21,7 +21,7 @@
#include <memory>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "skeletal_mesh.hpp"
#include "skeletal_model.hpp"
#include "sprite_3d.hpp"
diff --git a/src/blucat/skeletal_mesh.cpp b/src/blucat/skeletal_mesh.cpp
index baea635..d4fbfe7 100644
--- a/src/blucat/skeletal_mesh.cpp
+++ b/src/blucat/skeletal_mesh.cpp
@@ -16,9 +16,9 @@
#include "skeletal_mesh.hpp"
-#include "../binary_reader.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "binary_reader.hpp"
+#include "command.hpp"
+#include "core.hpp"
#include "skeletal_mesh_vertex.hpp"
namespace
@@ -54,7 +54,7 @@ load_mesh(void *obj)
BinaryReader input{self->mesh_path};
self->mesh->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::core.vk_device_with_swapchain->get_queue_family_with_graphics();
{ // Load vertexes.
auto vertex_count{input.read_ui32()};
diff --git a/src/blucat/skeletal_mesh.hpp b/src/blucat/skeletal_mesh.hpp
index 8b7d0fe..98506d7 100644
--- a/src/blucat/skeletal_mesh.hpp
+++ b/src/blucat/skeletal_mesh.hpp
@@ -21,7 +21,7 @@
#include <vector>
#include "animation.hpp"
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
diff --git a/src/blucat/skeletal_mesh_vertex.hpp b/src/blucat/skeletal_mesh_vertex.hpp
index 533c2ab..2e8a56f 100644
--- a/src/blucat/skeletal_mesh_vertex.hpp
+++ b/src/blucat/skeletal_mesh_vertex.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_SKELETAL_MESH_VERTEX_H
#define CANDY_GEAR_BLUCAT_SKELETAL_MESH_VERTEX_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/skeletal_model.cpp b/src/blucat/skeletal_model.cpp
index 8761bc8..fa46044 100644
--- a/src/blucat/skeletal_model.cpp
+++ b/src/blucat/skeletal_model.cpp
@@ -16,7 +16,7 @@
#include "skeletal_model.hpp"
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -29,10 +29,11 @@ load_uniform_buffers(void *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::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->uniform_buffers.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOSkeletalModel));
+ BluCat::core.vk_device_with_swapchain,
+ sizeof(BluCat::UDOSkeletalModel));
}
catch(const std::exception& e)
{
@@ -88,8 +89,8 @@ load_descriptor_sets(void *obj)
auto self = static_cast<BluCat::SkeletalModel*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->model);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::core.vk_descriptor_set_layout->model);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -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::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
diff --git a/src/blucat/skeletal_model.hpp b/src/blucat/skeletal_model.hpp
index cd3685e..03be8e5 100644
--- a/src/blucat/skeletal_model.hpp
+++ b/src/blucat/skeletal_model.hpp
@@ -20,7 +20,7 @@
#include <memory>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "skeletal_mesh.hpp"
namespace BluCat
diff --git a/src/blucat/sprite.cpp b/src/blucat/sprite.cpp
index a275df8..506d87a 100644
--- a/src/blucat/sprite.cpp
+++ b/src/blucat/sprite.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "sprite.hpp"
#include "uniform_data_object.hpp"
@@ -45,7 +45,7 @@ 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::core.vk_device_with_swapchain->get_queue_family_with_graphics();
glm::vec2 rect[BluCat::Sprite::vertex_count]{
glm::vec2{self->rect.x, self->rect.y},
diff --git a/src/blucat/sprite.hpp b/src/blucat/sprite.hpp
index 6252d00..68b6420 100644
--- a/src/blucat/sprite.hpp
+++ b/src/blucat/sprite.hpp
@@ -21,7 +21,7 @@
#include <unordered_map>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
diff --git a/src/blucat/sprite_3d.cpp b/src/blucat/sprite_3d.cpp
index 6fa6d49..dab97e2 100644
--- a/src/blucat/sprite_3d.cpp
+++ b/src/blucat/sprite_3d.cpp
@@ -16,7 +16,7 @@
#include "sprite_3d.hpp"
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -29,10 +29,10 @@ load_uniform_buffers(void *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::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->uniform_buffers.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOSprite3D));
+ BluCat::core.vk_device_with_swapchain, sizeof(BluCat::UDOSprite3D));
}
catch(const std::exception& e)
{
@@ -86,8 +86,8 @@ load_descriptor_sets(void *obj)
auto self = static_cast<BluCat::Sprite3D*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->model);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::core.vk_descriptor_set_layout->model);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -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::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -156,7 +156,7 @@ Sprite3D::Sprite3D(
size{size}
{
this->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::core.vk_device_with_swapchain->get_queue_family_with_graphics();
loader.execute(this);
}
diff --git a/src/blucat/sprite_3d.hpp b/src/blucat/sprite_3d.hpp
index dd0f16e..03a13f4 100644
--- a/src/blucat/sprite_3d.hpp
+++ b/src/blucat/sprite_3d.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_SPRITE_3D_H
#define CANDY_GEAR_BLUCAT_SPRITE_3D_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
#include "sprite.hpp"
namespace BluCat
diff --git a/src/blucat/sprite_to_draw.hpp b/src/blucat/sprite_to_draw.hpp
index fb46eac..c122437 100644
--- a/src/blucat/sprite_to_draw.hpp
+++ b/src/blucat/sprite_to_draw.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "sprite.hpp"
namespace BluCat
diff --git a/src/blucat/static_mesh.cpp b/src/blucat/static_mesh.cpp
index ab45ca9..a7c1c53 100644
--- a/src/blucat/static_mesh.cpp
+++ b/src/blucat/static_mesh.cpp
@@ -16,9 +16,9 @@
#include "static_mesh.hpp"
-#include "../binary_reader.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "binary_reader.hpp"
+#include "command.hpp"
+#include "core.hpp"
#include "static_mesh_vertex.hpp"
namespace
@@ -54,7 +54,7 @@ load_mesh(void *obj)
BinaryReader input{self->mesh_path};
self->mesh->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_graphics();
+ BluCat::core.vk_device_with_swapchain->get_queue_family_with_graphics();
{ // Load vertexes.
auto vertex_count{input.read_ui32()};
diff --git a/src/blucat/static_mesh.hpp b/src/blucat/static_mesh.hpp
index 0efcfc1..04c5e3b 100644
--- a/src/blucat/static_mesh.hpp
+++ b/src/blucat/static_mesh.hpp
@@ -20,7 +20,7 @@
#include <string>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "destination_buffer.hpp"
#include "queue_family.hpp"
#include "uniform_buffer.hpp"
diff --git a/src/blucat/static_mesh_vertex.hpp b/src/blucat/static_mesh_vertex.hpp
index 025ad63..4f7c6d4 100644
--- a/src/blucat/static_mesh_vertex.hpp
+++ b/src/blucat/static_mesh_vertex.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_STATIC_MESH_VERTEX_H
#define CANDY_GEAR_BLUCAT_STATIC_MESH_VERTEX_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/static_model.cpp b/src/blucat/static_model.cpp
index e3c6482..60c2536 100644
--- a/src/blucat/static_model.cpp
+++ b/src/blucat/static_model.cpp
@@ -16,7 +16,7 @@
#include "static_model.hpp"
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -29,10 +29,10 @@ load_uniform_buffers(void *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::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->uniform_buffers.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOStaticModel));
+ BluCat::core.vk_device_with_swapchain, sizeof(BluCat::UDOStaticModel));
}
catch(const std::exception& e)
{
@@ -88,8 +88,8 @@ load_descriptor_sets(void *obj)
auto self = static_cast<BluCat::StaticModel*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->model);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::core.vk_descriptor_set_layout->model);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -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::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
diff --git a/src/blucat/static_model.hpp b/src/blucat/static_model.hpp
index 68c5ea1..c300c8f 100644
--- a/src/blucat/static_model.hpp
+++ b/src/blucat/static_model.hpp
@@ -20,7 +20,7 @@
#include <memory>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "static_mesh.hpp"
namespace BluCat
diff --git a/src/blucat/swapchain.cpp b/src/blucat/swapchain.cpp
index 1e521e4..613cf9b 100644
--- a/src/blucat/swapchain.cpp
+++ b/src/blucat/swapchain.cpp
@@ -16,7 +16,7 @@
#include "swapchain.hpp"
-#include "../core.hpp"
+#include "core.hpp"
#include <vector>
@@ -32,18 +32,19 @@ load_swapchain(void *obj)
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::core.vk_device_with_swapchain->physical_device,
+ BluCat::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::core.vk_device_with_swapchain->physical_device,
+ BluCat::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::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::core.display_width, BluCat::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,16 +65,16 @@ load_swapchain(void *obj)
swapchain_create_info.oldSwapchain = VK_NULL_HANDLE;
if(vkCreateSwapchainKHR(
- cg_core.vk_device_with_swapchain->device, &swapchain_create_info,
+ BluCat::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::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::core.vk_device_with_swapchain->device, self->swapchain,
&self->images_count, self->images);
}
@@ -84,7 +85,7 @@ unload_swapchain(void *obj)
delete[] self->images;
vkDestroySwapchainKHR(
- cg_core.vk_device_with_swapchain->device, self->swapchain, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->swapchain, nullptr);
}
void
@@ -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::core.vk_device_with_swapchain->device, &create_info, nullptr,
&self->image_views[i]))
throw CommandError{"Could no create Image View for swapchain."};
}
@@ -124,7 +125,8 @@ unload_image_view(void *obj)
for(auto i{0}; i < self->images_count; i++)
vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->image_views[i], nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->image_views[i],
+ nullptr);
}
void
@@ -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::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::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::core.vk_device_with_swapchain->device, &fence_info,
+ nullptr, &self->in_flight_fences[i]) != VK_SUCCESS)
throw CommandError{"Failed to create semaphores."};
}
}
@@ -166,16 +169,16 @@ unload_frame_sync(void *obj)
{
auto self = static_cast<BluCat::Swapchain*>(obj);
- vkDeviceWaitIdle(cg_core.vk_device_with_swapchain->device);
+ vkDeviceWaitIdle(BluCat::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::core.vk_device_with_swapchain->device,
self->render_finished_semaphores[i], nullptr);
- vkDestroySemaphore(cg_core.vk_device_with_swapchain->device,
+ vkDestroySemaphore(BluCat::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::core.vk_device_with_swapchain->device,
+ self->in_flight_fences[i], nullptr);
}
}
diff --git a/src/blucat/swapchain.hpp b/src/blucat/swapchain.hpp
index 979fe08..a6f588d 100644
--- a/src/blucat/swapchain.hpp
+++ b/src/blucat/swapchain.hpp
@@ -17,8 +17,8 @@
#ifndef CANDY_GEAR_BLUCAT_SWAPCHAIN_H
#define CANDY_GEAR_BLUCAT_SWAPCHAIN_H 1
-#include "core.hpp"
-#include "../command.hpp"
+#include "command.hpp"
+#include "vulkan.hpp"
namespace BluCat
{
diff --git a/src/blucat/texture.cpp b/src/blucat/texture.cpp
index 1213528..4c94945 100644
--- a/src/blucat/texture.cpp
+++ b/src/blucat/texture.cpp
@@ -16,8 +16,8 @@
#include "texture.hpp"
-#include "../command.hpp"
-#include "../core.hpp"
+#include "command.hpp"
+#include "core.hpp"
#include "image.hpp"
#include "qoi.hpp"
#include "source_buffer.hpp"
@@ -36,7 +36,7 @@ create_vulkan_image(
vk_extent3d.depth = 1;
BluCat::Image::create(
- cg_core.vk_device_with_swapchain,
+ BluCat::core.vk_device_with_swapchain,
image,
device_memory,
VK_FORMAT_R8G8B8A8_UNORM,
@@ -91,7 +91,7 @@ load_image(void *obj)
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::core.vk_device_with_swapchain, pixels, image_size};
{ // Create vulkan image.
try
@@ -156,10 +156,11 @@ unload_image(void *obj)
auto self = static_cast<ImageBuilder*>(obj);
vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->texture->image, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->texture->image,
+ nullptr);
vkFreeMemory(
- cg_core.vk_device_with_swapchain->device, self->texture->device_memory,
- nullptr);
+ BluCat::core.vk_device_with_swapchain->device,
+ self->texture->device_memory, nullptr);
}
void
@@ -188,7 +189,7 @@ load_sampler(void *obj)
sampler_info.unnormalizedCoordinates = VK_FALSE;
if(vkCreateSampler(
- cg_core.vk_device_with_swapchain->device, &sampler_info, nullptr,
+ BluCat::core.vk_device_with_swapchain->device, &sampler_info, nullptr,
&self->texture->sampler) != VK_SUCCESS)
throw CommandError{"Failed to create texture sampler."};
}
@@ -199,7 +200,8 @@ unload_sampler(void *obj)
auto self = static_cast<ImageBuilder*>(obj);
vkDestroySampler(
- cg_core.vk_device_with_swapchain->device, self->texture->sampler, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->texture->sampler,
+ nullptr);
}
void
@@ -210,7 +212,7 @@ load_view(void *obj)
try
{
BluCat::Image::create_view(
- cg_core.vk_device_with_swapchain, &self->texture->view,
+ BluCat::core.vk_device_with_swapchain, &self->texture->view,
self->texture->image,
VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
}
@@ -226,7 +228,8 @@ unload_view(void *obj)
auto self = static_cast<ImageBuilder*>(obj);
vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->texture->view, nullptr);
+ BluCat::core.vk_device_with_swapchain->device, self->texture->view,
+ nullptr);
}
const CommandChain image_loader{
@@ -331,7 +334,7 @@ load_text_image(void *obj)
}
}
BluCat::SourceBuffer source_image_buffer{
- cg_core.vk_device_with_swapchain, pixels.data(), image_size};
+ BluCat::core.vk_device_with_swapchain, pixels.data(), image_size};
{ // Create vulkan image.
try
@@ -351,7 +354,8 @@ load_text_image(void *obj)
{ // Render text
auto queue_family{
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation()};
+ BluCat::core.vk_device_with_swapchain->
+ get_queue_family_with_presentation()};
auto queue{queue_family->get_queue()};
BluCat::CommandPool command_pool{queue_family, 1};
VkCommandBuffer vk_command_buffer{command_pool.command_buffers[0]};
@@ -436,13 +440,13 @@ load_descriptor_set_pool(void *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::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::core.vk_swapchain->images_count;
pool_info.poolSizeCount = descriptor_pool_sizes.size();
pool_info.pPoolSizes = descriptor_pool_sizes.data();
@@ -467,8 +471,8 @@ load_descriptor_sets(void *obj)
auto self = static_cast<BluCat::Texture*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->texture);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::core.vk_descriptor_set_layout->texture);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -488,7 +492,7 @@ load_data_to_descriptor_sets(void *obj)
{
auto self = static_cast<BluCat::Texture*>(obj);
- for(auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
{
VkDescriptorImageInfo image_info{};
image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@@ -508,7 +512,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::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
@@ -527,7 +531,8 @@ namespace BluCat
Texture::Texture(Font *font, const char* str)
{
this->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::core.vk_device_with_swapchain->
+ get_queue_family_with_presentation();
TextTextureBuilder text_builder(this, font, str);
text_loader.execute(&text_builder);
@@ -537,7 +542,8 @@ Texture::Texture(Font *font, const char* str)
Texture::Texture(std::string texture_path)
{
this->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::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/blucat/texture.hpp
index bee61e6..5d076dc 100644
--- a/src/blucat/texture.hpp
+++ b/src/blucat/texture.hpp
@@ -19,7 +19,7 @@
#include <string>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "font.hpp"
#include "queue_family.hpp"
diff --git a/src/blucat/uniform_buffer.hpp b/src/blucat/uniform_buffer.hpp
index 2131ee1..1dd7788 100644
--- a/src/blucat/uniform_buffer.hpp
+++ b/src/blucat/uniform_buffer.hpp
@@ -19,7 +19,7 @@
#include <memory>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "base_buffer.hpp"
diff --git a/src/blucat/uniform_data_object.hpp b/src/blucat/uniform_data_object.hpp
index d2292b1..0549e4e 100644
--- a/src/blucat/uniform_data_object.hpp
+++ b/src/blucat/uniform_data_object.hpp
@@ -17,7 +17,7 @@
#ifndef CANDY_GEAR_BLUCAT_UNIFORM_DATA_OBJECT_H
#define CANDY_GEAR_BLUCAT_UNIFORM_DATA_OBJECT_H 1
-#include "core.hpp"
+#include "vulkan.hpp"
#include "skeletal_mesh_vertex.hpp"
namespace BluCat
diff --git a/src/blucat/view_2d.cpp b/src/blucat/view_2d.cpp
index f27b4c4..de764ce 100644
--- a/src/blucat/view_2d.cpp
+++ b/src/blucat/view_2d.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -31,10 +31,10 @@ load_2d_uniform_buffer(void *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.reserve(BluCat::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->ub_2d.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOView2D));
+ BluCat::core.vk_device_with_swapchain, sizeof(BluCat::UDOView2D));
}
catch(const std::exception& e)
{
@@ -56,8 +56,8 @@ 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);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::core.vk_descriptor_set_layout->view);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -67,7 +67,7 @@ load_descriptor_sets_2d(void *obj)
self->descriptor_sets_2d.resize(layouts.size());
if(vkAllocateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, &alloc_info,
+ BluCat::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."};
}
@@ -96,7 +96,7 @@ load_resources_to_descriptor_sets_2d(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
BluCat::UDOView2D ubo_view_2d;
@@ -128,8 +128,8 @@ View2D::View2D(
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}
+ rectangles_to_draw{BluCat::core.vk_swapchain->images_count},
+ sprites_to_draw{BluCat::core.vk_swapchain->images_count}
{
loader.execute(this);
}
diff --git a/src/blucat/view_2d.hpp b/src/blucat/view_2d.hpp
index b369334..b798f19 100644
--- a/src/blucat/view_2d.hpp
+++ b/src/blucat/view_2d.hpp
@@ -21,7 +21,7 @@
#include <unordered_map>
#include <vector>
-#include "core.hpp"
+#include "vulkan.hpp"
#include "sprite_to_draw.hpp"
#include "rectangle.hpp"
diff --git a/src/blucat/view_3d.cpp b/src/blucat/view_3d.cpp
index 4b7b959..be9970c 100644
--- a/src/blucat/view_3d.cpp
+++ b/src/blucat/view_3d.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -31,10 +31,10 @@ load_3d_uniform_buffer(void *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::core.vk_swapchain->images_count);
+ for(auto i{0}; i < BluCat::core.vk_swapchain->images_count; i++)
self->ub_3d.emplace_back(
- cg_core.vk_device_with_swapchain, sizeof(BluCat::UDOView3D));
+ BluCat::core.vk_device_with_swapchain, sizeof(BluCat::UDOView3D));
}
catch(const std::exception& e)
{
@@ -56,8 +56,8 @@ load_descriptor_sets_3d(void *obj)
auto self = static_cast<BluCat::View3D*>(obj);
std::vector<VkDescriptorSetLayout> layouts(
- cg_core.vk_swapchain->images_count,
- cg_core.vk_descriptor_set_layout->view);
+ BluCat::core.vk_swapchain->images_count,
+ BluCat::core.vk_descriptor_set_layout->view);
VkDescriptorSetAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -67,7 +67,7 @@ load_descriptor_sets_3d(void *obj)
self->descriptor_sets_3d.resize(layouts.size());
if(vkAllocateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, &alloc_info,
+ BluCat::core.vk_device_with_swapchain->device, &alloc_info,
self->descriptor_sets_3d.data()) != VK_SUCCESS)
throw CommandError{"Failed to create Vulkan descriptor sets for view."};
}
@@ -96,7 +96,7 @@ load_resources_to_descriptor_sets_3d(void *obj)
write_descriptors[0].pTexelBufferView = nullptr;
vkUpdateDescriptorSets(
- cg_core.vk_device_with_swapchain->device, write_descriptors.size(),
+ BluCat::core.vk_device_with_swapchain->device, write_descriptors.size(),
write_descriptors.data(), 0, nullptr);
}
}
diff --git a/src/blucat/vulkan.hpp b/src/blucat/vulkan.hpp
new file mode 100644
index 0000000..24c35f5
--- /dev/null
+++ b/src/blucat/vulkan.hpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2022-2024 Frederico de Oliveira Linhares
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BLU_CAT_VULKAN_H
+#define BLU_CAT_VULKAN_H 1
+
+// GLM uses some definitions to control their behavior, so you should not
+// include it directly. Instead, use this header.
+#define GLM_ENABLE_EXPERIMENTAL
+#define GLM_FORCE_RADIANS
+#define GLM_FORCE_DEPTH_ZERO_TO_ONE
+
+#include <glm/ext/vector_float3.hpp>
+#include <glm/ext.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtx/quaternion.hpp>
+#include <glm/vec3.hpp>
+
+#include <vulkan/vulkan.h>
+
+#endif /* BLU_CAT_VULKAN_H */
diff --git a/src/worker.cpp b/src/blucat/worker.cpp
index bcf654e..bcf654e 100644
--- a/src/worker.cpp
+++ b/src/blucat/worker.cpp
diff --git a/src/worker.hpp b/src/blucat/worker.hpp
index 449e1b0..449e1b0 100644
--- a/src/worker.hpp
+++ b/src/blucat/worker.hpp
diff --git a/src/candy_gear.cpp b/src/candy_gear.cpp
index 78bb716..e8add70 100644
--- a/src/candy_gear.cpp
+++ b/src/candy_gear.cpp
@@ -30,7 +30,7 @@ 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::core.game_name = RSTRING_PTR(name);
return self;
}
@@ -67,8 +67,8 @@ cg_mCandyGear_set_views(mrb_state *mrb, mrb_value self)
// 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::core.vk_renderer;
+ BluCat::core.vk_renderer = new BluCat::Renderer({views_2d, views_3d});
}
return self;
@@ -96,7 +96,7 @@ cg_mCandyGear_log(mrb_state *mrb, mrb_value self)
else
log_lvl = Log::Level::Fatal;
- cg_core.log.message(log_lvl, message);
+ BluCat::core.log.message(log_lvl, message);
return self;
}
diff --git a/src/core.cpp b/src/core.cpp
index f524e36..7e5253b 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -38,62 +38,9 @@
#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)
{
@@ -114,27 +61,24 @@ load_mruby_symbols(void *obj)
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";
+ BluCat::core.game_name = "CandyGear Game";
- cg_core.display_width = 800;
- cg_core.display_height = 600;
+ BluCat::core.display_width = 800;
+ BluCat::core.display_height = 600;
- cg_core.game_version_major = 0;
- cg_core.game_version_minor = 1;
- cg_core.game_version_patch = 0;
+ BluCat::core.game_version_major = 0;
+ BluCat::core.game_version_minor = 1;
+ BluCat::core.game_version_patch = 0;
- cg_core.fps = 30;
+ BluCat::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);
@@ -153,11 +97,6 @@ load_game(void *obj)
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
@@ -227,8 +166,9 @@ 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,
+ BluCat::core.game_name.c_str(),
+ SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ BluCat::core.display_width, BluCat::core.display_height,
SDL_WINDOW_VULKAN);
if(cg_core.window == NULL)
{
@@ -245,168 +185,156 @@ unload_window(void *obj)
}
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)
+load_vk_instance(void *obj)
{
- std::vector<const char*> vk_extensions;
- std::vector<const char*> vk_required_layers_names;
+ 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;
+ // Get extensions.
+ {
+ uint32_t vk_extensions_count;
+ std::vector<const char*> vk_required_extensions;
- // Load debuging layers.
+ // 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");
+ 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];
- }
+ // 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);
- }
+ BluCat::core.log.message(Log::Level::Trace, "Enabled VK extensions.");
+ for(auto vk_extension: vk_extensions)
+ {
+ std::string message{"Extension name: "};
+ message += vk_extension;
+ BluCat::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);
+ }
+
+ // 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.");
+ BluCat::core.log.message(
+ Log::Level::Trace, "Available VK instance layers.");
#endif
- for(uint32_t i = 0; i < vk_available_layers_count; i++)
- {
+ 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());
+ 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::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);
+ 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::core.game_name.c_str();
+ app_info.applicationVersion = VK_MAKE_VERSION(
+ BluCat::core.game_version_major,
+ BluCat::core.game_version_minor,
+ BluCat::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, &BluCat::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::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))
+ cg_core.window, BluCat::core.vk_instance, &BluCat::core.window_surface))
{
std::string error{"Failed to create a window surface → "};
error += SDL_GetError();
@@ -417,373 +345,20 @@ load_window_surface(void *obj)
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."};
- }
+ vkDestroySurfaceKHR(
+ BluCat::core.vk_instance, BluCat::core.window_surface, nullptr);
}
void
-unload_blucat_graphics_pipeline_2d_wired_layout(void *obj)
+load_blucat(void *obj)
{
- delete cg_core.vk_graphics_pipeline_2d_wired_layout;
+ BluCat::core.loader.execute(nullptr);
}
void
-load_blucat_light(void *obj)
+unload_blucat(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;
+ BluCat::core.loader.revert(nullptr);
}
void
@@ -810,41 +385,14 @@ load_mruby_interface(void *obj)
}
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_vk_instance, &unload_vk_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_blucat, &unload_blucat},
{&load_mruby_interface, nullptr}
};
diff --git a/src/core.hpp b/src/core.hpp
index c351917..e7caf8b 100644
--- a/src/core.hpp
+++ b/src/core.hpp
@@ -21,9 +21,6 @@
#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>
@@ -44,29 +41,7 @@
#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;
+#include "blucat/core.hpp"
/**
* The Core class stores all global states that the engine needs to work.
@@ -76,12 +51,6 @@ 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;
@@ -91,56 +60,9 @@ struct cg_sCore
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;
+ bool quit_game;
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;
diff --git a/src/graphic.cpp b/src/graphic.cpp
index f27fff7..a991130 100644
--- a/src/graphic.cpp
+++ b/src/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::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::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::core.fps = fps;
return self;
}
diff --git a/src/main.cpp b/src/main.cpp
index f99e8ca..3627c9c 100644
--- a/src/main.cpp
+++ b/src/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::random_number_generator.seed(BluCat::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::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::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::core.max_frame_duration > frame_duration)
+ sleep_for(BluCat::core.max_frame_duration - frame_duration);
frame_start = frame_stop;
}
diff --git a/src/skeletal_model.cpp b/src/skeletal_model.cpp
index 3a3596e..f42306b 100644
--- a/src/skeletal_model.cpp
+++ b/src/skeletal_model.cpp
@@ -101,8 +101,8 @@ cg_cSkeletalModel_draw(mrb_state *mrb, mrb_value self)
{
auto ptr = (std::shared_ptr<BluCat::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::core.vk_renderer->skeletal_models_to_draw[
+ BluCat::core.vk_swapchain->current_frame][(*ptr)->skeletal_mesh];
instances.push_back(*ptr);
return self;
diff --git a/src/sprite.cpp b/src/sprite.cpp
index 65a49f7..0041107 100644
--- a/src/sprite.cpp
+++ b/src/sprite.cpp
@@ -72,7 +72,7 @@ cg_cSprite_draw(mrb_state *mrb, mrb_value self)
glm::vec4 rect(x, y, x + w, y + h);
auto &sprites_to_draw = view_2d->sprites_to_draw[
- cg_core.vk_swapchain->current_frame];
+ BluCat::core.vk_swapchain->current_frame];
sprites_to_draw.emplace_back(*ptr, rect, z_index);
return self;
diff --git a/src/sprite_3d.cpp b/src/sprite_3d.cpp
index d0e3319..6e6759f 100644
--- a/src/sprite_3d.cpp
+++ b/src/sprite_3d.cpp
@@ -59,8 +59,8 @@ cg_cSprite3D_draw(mrb_state *mrb, mrb_value self)
{
auto ptr = (std::shared_ptr<BluCat::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::core.vk_renderer->sprites_3d_to_draw[
+ BluCat::core.vk_swapchain->current_frame];
sprites_3d_to_draw.emplace_back(*ptr);
return self;
diff --git a/src/static_model.cpp b/src/static_model.cpp
index 3dd0c10..f9a1039 100644
--- a/src/static_model.cpp
+++ b/src/static_model.cpp
@@ -101,8 +101,8 @@ cg_cStaticModel_draw(mrb_state *mrb, mrb_value self)
{
auto ptr = (std::shared_ptr<BluCat::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::core.vk_renderer->static_models_to_draw[
+ BluCat::core.vk_swapchain->current_frame][(*ptr)->static_mesh];
instances.push_back(*ptr);
return self;
diff --git a/src/texture.hpp b/src/texture.hpp
index b20244d..36f23db 100644
--- a/src/texture.hpp
+++ b/src/texture.hpp
@@ -18,7 +18,7 @@
#define CANDY_GEAR_TEXTURE_H 1
#include "core.hpp"
-#include "command.hpp"
+#include "blucat/command.hpp"
extern const struct mrb_data_type cg_texture_type;
diff --git a/src/vector_4d.cpp b/src/vector_4d.cpp
index ba46bda..dedda2f 100644
--- a/src/vector_4d.cpp
+++ b/src/vector_4d.cpp
@@ -360,7 +360,7 @@ cg_cVector4D_draw_rectangle(mrb_state *mrb, mrb_value self)
(*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::core.vk_swapchain->current_frame];
rectangles.push_back(rect);
return self;