Renderer: Add ShaderStage class
This commit is contained in:
@@ -3,9 +3,32 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
RenderDevice::~RenderDevice() = default;
|
||||
|
||||
std::shared_ptr<ShaderStageImpl> RenderDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const std::filesystem::path& sourcePath)
|
||||
{
|
||||
File file(sourcePath);
|
||||
if (!file.Open(OpenMode_ReadOnly | OpenMode_Text))
|
||||
{
|
||||
NazaraError("Failed to open \"" + sourcePath.generic_u8string() + '"');
|
||||
return {};
|
||||
}
|
||||
|
||||
std::size_t length = static_cast<std::size_t>(file.GetSize());
|
||||
|
||||
std::vector<Nz::UInt8> source(length);
|
||||
if (file.Read(&source[0], length) != length)
|
||||
{
|
||||
NazaraError("Failed to read program file");
|
||||
return {};
|
||||
}
|
||||
|
||||
return InstantiateShaderStage(type, lang, source.data(), source.size());
|
||||
}
|
||||
}
|
||||
|
||||
11
src/Nazara/Renderer/ShaderStageImpl.cpp
Normal file
11
src/Nazara/Renderer/ShaderStageImpl.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/ShaderStageImpl.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ShaderStageImpl::~ShaderStageImpl() = default;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderPipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderStage.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -19,4 +20,13 @@ namespace Nz
|
||||
{
|
||||
return std::make_unique<VulkanRenderPipeline>(shared_from_this(), std::move(pipelineInfo));
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStageImpl> VulkanDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
auto stage = std::make_shared<VulkanShaderStage>();
|
||||
if (!stage->Create(shared_from_this(), type, lang, source, sourceSize))
|
||||
return {};
|
||||
|
||||
return stage;
|
||||
}
|
||||
}
|
||||
|
||||
27
src/Nazara/VulkanRenderer/VulkanShaderStage.cpp
Normal file
27
src/Nazara/VulkanRenderer/VulkanShaderStage.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderStage.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool VulkanShaderStage::Create(const Vk::DeviceHandle& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
if (lang != ShaderLanguage::SpirV)
|
||||
{
|
||||
NazaraError("Only Spir-V is supported for now");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_shaderModule.Create(device, reinterpret_cast<const Nz::UInt32*>(source), sourceSize))
|
||||
{
|
||||
NazaraError("Failed to create shader module");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_stage = type;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user