Skip to content

Commit

Permalink
[#128]: Working preview of Texture in Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Jul 9, 2023
1 parent 268add2 commit 00caf55
Show file tree
Hide file tree
Showing 13 changed files with 1,698 additions and 1,612 deletions.
2 changes: 0 additions & 2 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ class Editor : public Application
ActionOnObject(ACTION action);

private:


// [[nodiscard]] std::shared_ptr< EditorObject >
// GetEditorObjectByID(Object::ID ID);

Expand Down
367 changes: 204 additions & 163 deletions editor/gui/editor_gui.cpp

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions editor/gui/editor_gui.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "input/input_listener.hpp"
#include "object.hpp"
#include "renderer/buffer.hpp"
#include "input/input_listener.hpp"

#include <glm/glm.hpp>
#include <vulkan/vulkan.h>
Expand Down Expand Up @@ -106,37 +106,37 @@ class EditorGUI : public InputListener
static void
PreparePipeline();

Editor& m_parent;
Editor& parent_;

// EditorObjectWindow m_editorObjectWindow;
std::shared_ptr< GameObject > m_currentlySelectedGameObject;
std::shared_ptr< Level > m_currentLevel;
std::shared_ptr< GameObject > currentlySelectedGameObject_;
std::shared_ptr< Level > currentLevel_;

glm::vec2 m_windowSize = {};
float m_windowWidth = 0.0f;
float m_toolsWindowHeight = 0.0f;
float m_gameObjectWindowHeight = 0.0f;
float m_levelWindowHeight = 0.0f;
float m_debugWindowHeight = 0.0f;
float m_debugWindowWidth = 0.0f;
glm::vec2 windowSize_ = {};
float windowWidth_ = 0.0f;
float toolsWindowHeight_ = 0.0f;
float gameObjectWindowHeight_ = 0.0f;
float levelWindowHeight_ = 0.0f;
float debugWindowHeight_ = 0.0f;
float debugWindowWidth_ = 0.0f;

bool m_createPushed = false;
bool createPushed_ = false;

inline static VkImage m_fontImage = {};
inline static VkDeviceMemory m_fontMemory = {};
inline static VkImage fontImage_ = {};
inline static VkDeviceMemory fontMemory_ = {};
inline static VkImageView m_fontView = {};
inline static VkSampler m_sampler = {};
inline static VkDescriptorPool m_descriptorPool = {};
inline static VkDescriptorSetLayout m_descriptorSetLayout = {};
inline static VkDescriptorSet m_descriptorSet = {};

inline static VkPipeline m_pipeline = {};
inline static VkPipelineLayout m_pipelineLayout = {};
inline static uint32_t m_subpass = 0;

inline static PushConstBlock m_pushConstant = {};
inline static std::vector< renderer::Buffer > m_vertexBuffer = {};
inline static std::vector< renderer::Buffer > m_indexBuffer = {};
inline static VkSampler sampler_ = {};
inline static VkDescriptorPool descriptorPool_ = {};
inline static VkDescriptorSetLayout descriptorSetLayout_ = {};
inline static VkDescriptorSet descriptorSet_ = {};

inline static VkPipeline pipeline_ = {};
inline static VkPipelineLayout pipelineLayout_ = {};
inline static uint32_t subpass_ = 0;

inline static PushConstBlock pushConstant_ = {};
inline static std::vector< renderer::Buffer > vertexBuffer_ = {};
inline static std::vector< renderer::Buffer > indexBuffer_ = {};
inline static std::vector< int32_t > vertexCount_ = {};
inline static std::vector< int32_t > indexCount_ = {};
};
Expand Down
2,788 changes: 1,395 additions & 1,393 deletions editor/gui/icons.hpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion engine/game/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class Player : public GameObject
/*void
CreateSprite(const glm::vec2& position, const glm::ivec2& size, const std::string& fileName);*/

void Hit(int32_t /*dmg*/) override
void
Hit(int32_t /*dmg*/) override
{
}

Expand Down
22 changes: 13 additions & 9 deletions engine/renderer/shader.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "shader.hpp"
#include "vulkan_common.hpp"
#include "logger/logger.hpp"
#include "renderer.hpp"
#include "texture.hpp"
#include "logger/logger.hpp"
#include "utils/assert.hpp"
#include "utils/file_manager.hpp"
#include "vulkan_common.hpp"

#include <algorithm>

Expand All @@ -16,23 +16,23 @@ CreateShaderModule(VkDevice device, std::vector< char >&& shaderByteCode)
VkShaderModuleCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
createInfo.codeSize = shaderByteCode.size();
//NOLINTNEXTLINE
// NOLINTNEXTLINE
createInfo.pCode = reinterpret_cast< const uint32_t* >(shaderByteCode.data());

VkShaderModule shaderModule = {};
vk_check_error(vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule),
"Failed to create shader module!");
"Failed to create shader module!");

return shaderModule;
}

std::pair< VertexShaderInfo, FragmentShaderInfo >
VulkanShader::CreateShader(VkDevice device, std::string_view vertex, std::string_view fragment)
{
auto* vertShaderModule = CreateShaderModule(
device, FileManager::ReadBinaryFile(SHADERS_DIR / vertex));
auto* fragShaderModule = CreateShaderModule(
device, FileManager::ReadBinaryFile(SHADERS_DIR / fragment));
auto* vertShaderModule =
CreateShaderModule(device, FileManager::ReadBinaryFile(SHADERS_DIR / vertex));
auto* fragShaderModule =
CreateShaderModule(device, FileManager::ReadBinaryFile(SHADERS_DIR / fragment));

VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Expand Down Expand Up @@ -228,6 +228,10 @@ QuadShader::UpdateDescriptorSets()
}
}

///////////////////////////////////////////////////////////////////
/////////////////////// LINE SHADER ///////////////////////
///////////////////////////////////////////////////////////////////

void
LineShader::CreateDescriptorPool()
{
Expand Down Expand Up @@ -310,4 +314,4 @@ LineShader::CreateDescriptorSets()
}
}

} // namespace shady::renderer
} // namespace looper::renderer
5 changes: 2 additions & 3 deletions engine/renderer/shader.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <vulkan/vulkan.h>
#include <glm/glm.hpp>
#include <vulkan/vulkan.h>

#include <string_view>
#include <utility>
Expand Down Expand Up @@ -91,5 +91,4 @@ struct LineShader
CreateDescriptorSets();
};


} // namespace shady::renderer
} // namespace looper::renderer
2 changes: 1 addition & 1 deletion engine/renderer/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "common.hpp"
#include "texture.hpp"
#include "vertex.hpp"
#include "types.hpp"
#include "vertex.hpp"
#include "vulkan_common.hpp"

#include <deque>
Expand Down
38 changes: 35 additions & 3 deletions engine/renderer/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include "buffer.hpp"
#include "command.hpp"
#include "logger/logger.hpp"
#include "renderer.hpp"
#include "utils/assert.hpp"
#include "utils/file_manager.hpp"
#include "vulkan_common.hpp"
#include "renderer.hpp"

#include <string_view>
#include <ranges>
#include <string_view>

namespace looper::renderer {

Expand Down Expand Up @@ -245,6 +245,38 @@ Texture::GenerateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth,
Command::EndSingleTimeCommands(commandBuffer);
}

VkDescriptorSet
Texture::CreateDescriptorSet(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout,
VkDescriptorPool pool, VkDescriptorSetLayout layout)
{
// Create Descriptor Set:
VkDescriptorSet descriptor_set;
{
VkDescriptorSetAllocateInfo alloc_info = {};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
alloc_info.descriptorPool = pool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &layout;
vk_check_error(vkAllocateDescriptorSets(Data::vk_device, &alloc_info, &descriptor_set), "");
}

// Update the Descriptor Set:
{
VkDescriptorImageInfo desc_image[1] = {};
desc_image[0].sampler = sampler;
desc_image[0].imageView = image_view;
desc_image[0].imageLayout = image_layout;
VkWriteDescriptorSet write_desc[1] = {};
write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write_desc[0].dstSet = descriptor_set;
write_desc[0].descriptorCount = 1;
write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
write_desc[0].pImageInfo = desc_image;
vkUpdateDescriptorSets(Data::vk_device, 1, write_desc, 0, nullptr);
}
return descriptor_set;
}

std::pair< VkImageView, VkSampler >
Texture::GetImageViewAndSampler() const
{
Expand Down Expand Up @@ -482,7 +514,7 @@ TextureLibrary::GetTextureViews()
uint32_t
TextureLibrary::GetNumTextures()
{
return static_cast<uint32_t>(currentID_);
return static_cast< uint32_t >(currentID_);
}

} // namespace looper::renderer
9 changes: 6 additions & 3 deletions engine/renderer/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
#include "texture.hpp"
#include "types.hpp"

#include <vector>
#include <unordered_map>
#include <vector>
#include <vulkan/vulkan.h>

namespace looper::renderer {

class Texture
{
public:

Texture(TextureType type, std::string_view textureName, TextureID id);

Texture() = default;
Expand Down Expand Up @@ -49,6 +48,10 @@ class Texture
static void
CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t texHeight, uint8_t* data);

static VkDescriptorSet
CreateDescriptorSet(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout,
VkDescriptorPool pool, VkDescriptorSetLayout layout);

[[nodiscard]] std::pair< VkImageView, VkSampler >
GetImageViewAndSampler() const;

Expand Down Expand Up @@ -125,4 +128,4 @@ class TextureLibrary
static inline TextureID currentID_ = 0;
};

} // namespace shady::renderer
} // namespace looper::renderer
3 changes: 3 additions & 0 deletions engine/renderer/vulkan_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ struct RenderData
std::vector< VkImage > swapChainImages = {MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE};
std::vector< VkImageView > swapChainImageViews = {MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE};
std::vector< VkFramebuffer > swapChainFramebuffers = {MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE};

// Quads and non UI stuff
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
std::vector< VkDescriptorSet > descriptorSets = {MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE};

VkFormat swapChainImageFormat = VK_FORMAT_UNDEFINED;

VkRenderPass renderPass = VK_NULL_HANDLE;
Expand Down
8 changes: 5 additions & 3 deletions engine/utils/time/scoped_timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ namespace looper::time {
class ScopedTimer
{
public:
ScopedTimer& operator=(const ScopedTimer&) = delete;
ScopedTimer& operator=(ScopedTimer&&) = delete;
ScopedTimer&
operator=(const ScopedTimer&) = delete;
ScopedTimer&
operator=(ScopedTimer&&) = delete;
ScopedTimer(ScopedTimer&&) = delete;
ScopedTimer(const ScopedTimer&) = delete;

Expand All @@ -22,7 +24,7 @@ class ScopedTimer
Stopwatch m_timer;
};

//NOLINTNEXTLINE
// NOLINTNEXTLINE
#define SCOPED_TIMER(str) looper::time::ScopedTimer t(std::move(str));

} // namespace looper::time
11 changes: 6 additions & 5 deletions engine/utils/time/stopwatch.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "utils/time/timer.hpp"
#include "time_step.hpp"
#include "utils/time/timer.hpp"

#include <string>

Expand All @@ -10,13 +10,14 @@ namespace looper::time {
class Stopwatch
{
public:
void Start();
void
Start();

[[nodiscard]]
TimeStep Stop();
[[nodiscard]] TimeStep
Stop();

private:
Timer m_timer;
};

} // namespace shady::time
} // namespace looper::time

0 comments on commit 00caf55

Please sign in to comment.