summaryrefslogtreecommitdiff
path: root/src/blucat
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 /src/blucat
parent43821b0cffc5aa419c0218992f06f8962ae54a13 (diff)
refa Move BluCan initialization to BluCat folderHEADmaster
Diffstat (limited to 'src/blucat')
-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.cpp156
-rw-r--r--src/blucat/binary_reader.hpp69
-rw-r--r--src/blucat/character.cpp17
-rw-r--r--src/blucat/character.hpp2
-rw-r--r--src/blucat/command.cpp78
-rw-r--r--src/blucat/command.hpp92
-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.cpp61
-rw-r--r--src/blucat/job_queue.hpp52
-rw-r--r--src/blucat/light.cpp28
-rw-r--r--src/blucat/light.hpp2
-rw-r--r--src/blucat/log.cpp53
-rw-r--r--src/blucat/log.hpp54
-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.cpp34
-rw-r--r--src/blucat/worker.hpp33
80 files changed, 1680 insertions, 361 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/blucat/binary_reader.cpp b/src/blucat/binary_reader.cpp
new file mode 100644
index 0000000..14fc39c
--- /dev/null
+++ b/src/blucat/binary_reader.cpp
@@ -0,0 +1,156 @@
+/*
+ * 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 "binary_reader.hpp"
+
+#include <fstream>
+
+namespace
+{
+
+union IntAndFloat32bit{
+ uint32_t i;
+ float f;
+};
+
+union IntAndFloat64bit{
+ uint64_t i;
+ double f;
+};
+
+}
+
+BinaryReader::BinaryReader(std::string file_path):
+ _pointer{0}
+{
+ std::ifstream file(file_path, std::ios::binary | std::ios::ate);
+ if(!file.is_open())
+ {
+ std::string error{"failed to open file: "};
+ error += file_path;
+ throw std::runtime_error{error};
+ }
+
+ this->_size = file.tellg();
+ file.seekg(0);
+ this->data = new uint8_t[this->_size];
+ file.read((char*)data, this->_size);
+}
+
+BinaryReader::BinaryReader(const char *file_path):
+ BinaryReader{std::string(file_path)}
+{
+}
+
+BinaryReader::~BinaryReader()
+{
+ delete[] this->data;
+}
+
+uint8_t
+BinaryReader::read_ui8()
+{
+ return this->data[this->_pointer++];
+}
+
+uint32_t
+BinaryReader::read_ui32()
+{
+ uint8_t b1{this->data[_pointer++]}, b2{this->data[_pointer++]},
+ b3{this->data[_pointer++]}, b4{this->data[_pointer++]};
+
+ return b1 << 24 | b2 << 16 | b3 << 8 | b4;
+}
+
+uint64_t
+BinaryReader::read_ui64()
+{
+ uint8_t b1{this->data[_pointer++]}, b2{this->data[_pointer++]},
+ b3{this->data[_pointer++]}, b4{this->data[_pointer++]},
+ b5{this->data[_pointer++]}, b6{this->data[_pointer++]},
+ b7{this->data[_pointer++]}, b8{this->data[_pointer++]};
+
+ return (uint64_t)b1 << 56 | (uint64_t)b2 << 48 | (uint64_t)b3 << 40 |
+ (uint64_t)b4 << 32 | (uint64_t)b5 << 24 | (uint64_t)b6 << 16 |
+ (uint64_t)b7 << 8 | (uint64_t)b8;
+}
+
+float
+BinaryReader::read_float()
+{
+ IntAndFloat32bit num;
+ num.i = read_ui32();
+
+ return num.f;
+}
+
+double
+BinaryReader::read_double()
+{
+ IntAndFloat64bit num;
+ num.i = read_ui64();
+
+ return num.f;
+}
+
+glm::vec2
+BinaryReader::read_vec2()
+{
+ IntAndFloat32bit x{read_ui32()}, y{read_ui32()};
+
+ return glm::vec2{x.f, y.f};
+}
+
+glm::vec3
+BinaryReader::read_vec3()
+{
+ IntAndFloat32bit x{read_ui32()}, y{read_ui32()}, z{read_ui32()};
+
+ return glm::vec3{x.f, y.f, z.f};
+}
+
+glm::quat
+BinaryReader::read_quat()
+{
+ IntAndFloat32bit w{read_ui32()}, x{read_ui32()}, y{read_ui32()},
+ z{read_ui32()};
+
+ return glm::quat{w.f, x.f, y.f, z.f};
+}
+
+glm::mat4
+BinaryReader::read_mat4()
+{
+ glm::mat4 matrix;
+ float *offset_matrix_data{glm::value_ptr(matrix)};
+
+ for(int i{0}; i < 16; i++)
+ {
+ IntAndFloat32bit num;
+ num.i = read_ui32();
+ offset_matrix_data[i] = num.f;
+ }
+
+ return matrix;
+}
+
+void
+BinaryReader::read_chars(char *str, int size)
+{
+ for(int i{0}; i < size; i++)
+ str[i] = (char)data[this->_pointer++];
+}
+
diff --git a/src/blucat/binary_reader.hpp b/src/blucat/binary_reader.hpp
new file mode 100644
index 0000000..1995402
--- /dev/null
+++ b/src/blucat/binary_reader.hpp
@@ -0,0 +1,69 @@
+/*
+ * 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 <cstdint>
+#include <string>
+
+#include "vulkan.hpp"
+
+class BinaryReader
+{
+ int _pointer;
+ int _size;
+ uint8_t *data;
+
+public:
+
+ BinaryReader(const std::string file_path);
+ BinaryReader(const char *file_path);
+ ~BinaryReader();
+
+ inline int
+ pointer(){return this->_pointer;};
+
+ inline int
+ size(){return this->_size;};
+
+ uint8_t
+ read_ui8();
+
+ uint32_t
+ read_ui32();
+
+ uint64_t
+ read_ui64();
+
+ float
+ read_float();
+
+ double
+ read_double();
+
+ glm::vec2
+ read_vec2();
+
+ glm::vec3
+ read_vec3();
+
+ glm::quat
+ read_quat();
+
+ glm::mat4
+ read_mat4();
+
+ void
+ read_chars(char *str, int size);
+};
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/blucat/command.cpp b/src/blucat/command.cpp
new file mode 100644
index 0000000..a1d3240
--- /dev/null
+++ b/src/blucat/command.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2022 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 <stdlib.h>
+
+#include "command.hpp"
+
+CommandError::CommandError(const std::string &m):
+ error(m)
+{
+}
+
+CommandError::CommandError(const char &m):
+ CommandError{std::string{m}}
+{
+}
+
+const char* CommandError::what() const noexcept
+{
+ return this->error.c_str();
+}
+
+CommandChain::CommandChain(std::initializer_list<Command> commands)
+{
+ for(auto c: commands) this->add(c);
+}
+
+void
+CommandChain::partial_revert(void *obj, int32_t step) const
+{
+ // Already unloaded, nothing to do.
+ if(step <= 0) return;
+
+ for(; step > 0; step--)
+ {
+ auto command = this->_commands[step -1].undo_command;
+ if(command != nullptr) command(obj);
+ }
+}
+
+void
+CommandChain::add(const Command &c)
+{
+ this->_commands.push_back(c);
+}
+
+void
+CommandChain::execute(void *obj) const
+{
+ for(auto i{0}; i < this->_commands.size(); i++)
+ {
+ try { this->_commands[i].do_command(obj); }
+ catch(const CommandError &error)
+ {
+ this->partial_revert(obj, i);
+ throw;
+ }
+ }
+}
+
+void
+CommandChain::revert(void *obj) const
+{
+ this->partial_revert(obj, this->_commands.size());
+}
diff --git a/src/blucat/command.hpp b/src/blucat/command.hpp
new file mode 100644
index 0000000..47552a5
--- /dev/null
+++ b/src/blucat/command.hpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2022 Frederico de Oliveira Linhares
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CANDY_GEAR_COMMAND_CHAIN_H
+#define CANDY_GEAR_COMMAND_CHAIN_H 1
+
+#include <cstdint>
+#include <initializer_list>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+class CommandChain;
+
+struct CommandError: public std::exception
+{
+ CommandError(const std::string &m);
+ CommandError(const char &m);
+
+ const char* what() const noexcept;
+
+private:
+ std::string error;
+};
+
+/**
+ * Stores a reversible action.
+ */
+struct Command
+{
+ void (*do_command)(void *obj);
+ void (*undo_command)(void *obj);
+};
+
+/**
+ * Stores a sequence of functions that must be executed and rolled back in
+ * order.
+ *
+ * For example, if the variable _commands contain A→B→C→D→E, it will load A,
+ * then B, then C, etc. If D fails, it unloads C, then B, then A.
+ */
+class CommandChain
+{
+ std::vector<Command> _commands;
+
+ void
+ partial_revert(void *obj, int32_t step) const;
+
+public:
+ CommandChain(std::initializer_list<Command> commands);
+
+/**
+ * Adds a reversible action to the command. The first action added is the first
+ * to de executed the last rolled back, and so on. Those functions are stored
+ * inside _commands.
+ *
+ * @param[unload] the undo/rollback action, if the action do not need a
+ * rollback, this pointer can be set to null.
+ */
+ void
+ add(const Command &c);
+
+/**
+ * Execute all of the load functions in the _commands. If one of them fails,
+ * roll back everything inside _commands.
+ * @return true on success and false on fail.
+ */
+ void
+ execute(void *obj) const;
+
+/**
+ * Roll back all loaded function inside commands, if there are any.
+ */
+ void
+ revert(void *obj) const;
+
+};
+
+#endif /* CANDY_GEAR_COMMAND_CHAIN_H */
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/blucat/job_queue.cpp b/src/blucat/job_queue.cpp
new file mode 100644
index 0000000..49bf34f
--- /dev/null
+++ b/src/blucat/job_queue.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2022 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 "job_queue.hpp"
+
+#include <chrono>
+
+JobQueue::JobQueue():
+ jobs{},
+ _stop{false}
+{
+}
+
+void
+JobQueue::stop()
+{
+ using namespace std::chrono_literals;
+
+ while(!this->jobs.empty()) std::this_thread::sleep_for(1000ms);
+ this->_stop = true;
+ this->condition.notify_all();
+}
+
+void
+JobQueue::push(Job job)
+{
+ std::unique_lock<std::mutex> lock{this->access};
+ this->jobs.push_back(job);
+ this->condition.notify_one();
+}
+
+Job
+JobQueue::pop()
+{
+ std::unique_lock<std::mutex> lock{this->access};
+ this->condition.wait(lock, [this]{
+ return !this->jobs.empty() || this->_stop;});
+ if(!this->jobs.empty())
+ {
+ auto job{std::move(this->jobs.front())};
+ this->jobs.pop_front();
+ return job;
+ }
+ else
+ {
+ return Job{nullptr};
+ }
+}
diff --git a/src/blucat/job_queue.hpp b/src/blucat/job_queue.hpp
new file mode 100644
index 0000000..2a7735b
--- /dev/null
+++ b/src/blucat/job_queue.hpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2022 Frederico de Oliveira Linhares
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CANDY_GEAR_JOB_QUEUE_H
+#define CANDY_GEAR_JOB_QUEUE_H 1
+
+#include <atomic>
+#include <condition_variable>
+#include <deque>
+#include <functional>
+#include <mutex>
+
+class Worker;
+
+typedef std::function<void(void)> Job;
+
+class JobQueue
+{
+ friend Worker;
+
+ std::mutex access;
+ std::condition_variable condition;
+ std::atomic<bool> _stop;
+ std::deque<Job> jobs;
+
+ Job
+ pop();
+
+public:
+ JobQueue();
+
+ void
+ stop();
+
+ void
+ push(Job job);
+};
+
+#endif /* CANDY_GEAR_JOB_QUEUE_H */
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/blucat/log.cpp b/src/blucat/log.cpp
new file mode 100644
index 0000000..78044c4
--- /dev/null
+++ b/src/blucat/log.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2022 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 "log.hpp"
+
+#include <iostream>
+
+namespace Log
+{
+
+void
+Logger::message(Level lvl, const char* text)
+{
+ std::cout << "[";
+ switch(lvl)
+ {
+ case Level::Fatal:
+ std::cout << "\e[1;35mFatal\e[0;0m";
+ break;
+ case Level::Error:
+ std::cout << "\e[1;31mError\e[0;0m";
+ break;
+ case Level::Warning:
+ std::cout << "\e[1;33mWarning\e[0;0m";
+ break;
+ case Level::Information:
+ std::cout << "\e[1;32mInformation\e[0;0m";
+ break;
+ case Level::Debug:
+ std::cout << "\e[1;36mDebug\e[0;0m";
+ break;
+ case Level::Trace:
+ std::cout << "\e[1;34mTrace\e[0;0m";
+ break;
+ }
+ std::cout << "] ";
+ std::cout << text << std::endl;
+}
+
+}
diff --git a/src/blucat/log.hpp b/src/blucat/log.hpp
new file mode 100644
index 0000000..2856f20
--- /dev/null
+++ b/src/blucat/log.hpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2022 Frederico de Oliveira Linhares
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CANDY_GEAR_LOG_H
+#define CANDY_GEAR_LOG_H 1
+
+#include <string>
+
+#define CANDY_GEAR_LOG_LEVEL_FATAL 0
+#define CANDY_GEAR_LOG_LEVEL_ERROR 1
+#define CANDY_GEAR_LOG_LEVEL_WARNING 2
+#define CANDY_GEAR_LOG_LEVEL_INFORMATION 3
+#define CANDY_GEAR_LOG_LEVEL_DEBUG 4
+#define CANDY_GEAR_LOG_LEVEL_TRACE 5
+
+namespace Log
+{
+
+enum class Level
+{
+ Fatal = CANDY_GEAR_LOG_LEVEL_FATAL,
+ Error = CANDY_GEAR_LOG_LEVEL_ERROR,
+ Warning = CANDY_GEAR_LOG_LEVEL_WARNING,
+ Information = CANDY_GEAR_LOG_LEVEL_INFORMATION,
+ Debug = CANDY_GEAR_LOG_LEVEL_DEBUG,
+ Trace = CANDY_GEAR_LOG_LEVEL_TRACE
+};
+
+struct Logger
+{
+
+ void
+ message(Level lvl, const char* text);
+
+ inline void
+ message(Level lvl, const std::string &text) {message(lvl, text.c_str());}
+};
+
+}
+
+#endif /* CANDY_GEAR_LOG_H */
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/blucat/worker.cpp b/src/blucat/worker.cpp
new file mode 100644
index 0000000..bcf654e
--- /dev/null
+++ b/src/blucat/worker.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2022 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 "worker.hpp"
+
+#include <thread>
+
+Worker::Worker(JobQueue *job_queue):
+ job_queue{job_queue}
+{
+}
+
+void
+Worker::operator()()
+{
+ while(!this->job_queue->_stop)
+ {
+ auto job{this->job_queue->pop()};
+ if(job) job();
+ }
+}
diff --git a/src/blucat/worker.hpp b/src/blucat/worker.hpp
new file mode 100644
index 0000000..449e1b0
--- /dev/null
+++ b/src/blucat/worker.hpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2022 Frederico de Oliveira Linhares
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CANDY_GEAR_WORKER_H
+#define CANDY_GEAR_WORKER_H 1
+
+#include "job_queue.hpp"
+
+class Worker
+{
+ JobQueue *job_queue;
+
+public:
+ Worker(JobQueue *job_queue);
+
+ void
+ operator()();
+};
+
+#endif /* CANDY_GEAR_WORKER_H */