Add ShaderModule
This commit is contained in:
parent
bfacea2bd4
commit
92af78a6b0
@ -1,5 +1,5 @@
|
||||
# NF library CMakeLists.txt
|
||||
add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/config.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp" "src/client/render/RenderEngine.h" "src/client/render/RenderEngine.cpp")
|
||||
add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/config.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp" "src/client/render/RenderEngine.h" "src/client/render/RenderEngine.cpp" "src/client/render/ShaderModule.h" "src/client/render/ShaderModule.cpp")
|
||||
|
||||
# Use C++20
|
||||
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "RenderEngine.h"
|
||||
#include "util.h"
|
||||
#include "ShaderModule.h"
|
||||
|
||||
namespace nf::client::render {
|
||||
RenderEngine::RenderEngine(std::shared_ptr<Window> window, DisplayConfig display)
|
||||
@ -287,20 +288,10 @@ namespace nf::client::render {
|
||||
if (!util::readFile("shaders/output.vert.glsl.spv", outputShaderVertex) || !util::readFile("shaders/output.frag.glsl.spv", outputShaderFragment))
|
||||
NFError("Could not read output shader binaries.");
|
||||
|
||||
VkShaderModule outputShaderVertexModule = VK_NULL_HANDLE, outputShaderFragmentModule = VK_NULL_HANDLE;
|
||||
VkShaderModuleCreateInfo outputShaderModulesCI = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO };
|
||||
outputShaderModulesCI.codeSize = outputShaderVertex.size();
|
||||
outputShaderModulesCI.pCode = reinterpret_cast<uint32_t*>(outputShaderVertex.data());
|
||||
vkCreateShaderModule(m_device, &outputShaderModulesCI, nullptr, &outputShaderVertexModule);
|
||||
outputShaderModulesCI.codeSize = outputShaderFragment.size();
|
||||
outputShaderModulesCI.pCode = reinterpret_cast<uint32_t*>(outputShaderFragment.data());
|
||||
vkCreateShaderModule(m_device, &outputShaderModulesCI, nullptr, &outputShaderFragmentModule);
|
||||
if (!outputShaderVertexModule || !outputShaderFragmentModule)
|
||||
NFError("Could not create output shader modules.");
|
||||
ShaderModule outputShaderVertexModule(m_device, outputShaderVertex);
|
||||
ShaderModule outputShaderFragmentModule(m_device, outputShaderFragment);
|
||||
|
||||
// And cleanup shader modules
|
||||
vkDestroyShaderModule(m_device, outputShaderVertexModule, nullptr);
|
||||
vkDestroyShaderModule(m_device, outputShaderFragmentModule, nullptr);
|
||||
}
|
||||
|
||||
RenderEngine::~RenderEngine() {
|
||||
|
26
NothinFancy/src/client/render/ShaderModule.cpp
Normal file
26
NothinFancy/src/client/render/ShaderModule.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// ShaderModule class implementation
|
||||
#include "pch.h"
|
||||
|
||||
#include "ShaderModule.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace nf::client::render {
|
||||
ShaderModule::ShaderModule(const VkDevice& device, const std::string& shaderBinary)
|
||||
: m_device(device)
|
||||
, m_shaderModule()
|
||||
{
|
||||
VkShaderModuleCreateInfo shaderModuleCI = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO };
|
||||
shaderModuleCI.codeSize = shaderBinary.size();
|
||||
shaderModuleCI.pCode = reinterpret_cast<const uint32_t*>(shaderBinary.data());
|
||||
if (vkCreateShaderModule(device, &shaderModuleCI, nullptr, &m_shaderModule) != VK_SUCCESS)
|
||||
NFError("Could not create shader module.");
|
||||
}
|
||||
|
||||
VkShaderModule& ShaderModule::getHandle() {
|
||||
return m_shaderModule;
|
||||
}
|
||||
|
||||
ShaderModule::~ShaderModule() {
|
||||
vkDestroyShaderModule(m_device, m_shaderModule, nullptr);
|
||||
}
|
||||
}
|
17
NothinFancy/src/client/render/ShaderModule.h
Normal file
17
NothinFancy/src/client/render/ShaderModule.h
Normal file
@ -0,0 +1,17 @@
|
||||
// ShaderModule class header
|
||||
#pragma once
|
||||
|
||||
namespace nf::client::render {
|
||||
class ShaderModule {
|
||||
public:
|
||||
ShaderModule(const VkDevice& device, const std::string& shaderBinary);
|
||||
|
||||
VkShaderModule& getHandle();
|
||||
|
||||
~ShaderModule();
|
||||
private:
|
||||
const VkDevice& m_device;
|
||||
|
||||
VkShaderModule m_shaderModule;
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user