mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-04-21 10:58:44 +00:00
chore: make sure shader compiler uses std expected
This commit is contained in:
@@ -122,7 +122,7 @@ namespace shader
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
result::Expected<std::optional<CompiledShader>, std::string> CompileShader(const std::string& shaderFile,
|
std::expected<std::optional<CompiledShader>, std::string> CompileShader(const std::string& shaderFile,
|
||||||
const std::string& entryPoint,
|
const std::string& entryPoint,
|
||||||
const std::string& target,
|
const std::string& target,
|
||||||
const bool debug,
|
const bool debug,
|
||||||
@@ -133,7 +133,7 @@ namespace shader
|
|||||||
if (!initialized)
|
if (!initialized)
|
||||||
InitializeShaderCompilation();
|
InitializeShaderCompilation();
|
||||||
if (!compilationAvailable)
|
if (!compilationAvailable)
|
||||||
return result::Unexpected<std::string>("Shader compilation unavailable");
|
return std::unexpected("Shader compilation unavailable");
|
||||||
|
|
||||||
const auto fileName = GetSourceFileNameForShaderAssetName(shaderFile);
|
const auto fileName = GetSourceFileNameForShaderAssetName(shaderFile);
|
||||||
auto file = searchPath.Open(fileName);
|
auto file = searchPath.Open(fileName);
|
||||||
@@ -141,7 +141,7 @@ namespace shader
|
|||||||
return std::optional<CompiledShader>(std::nullopt);
|
return std::optional<CompiledShader>(std::nullopt);
|
||||||
|
|
||||||
if (std::cmp_greater(file.m_length, MAX_SHADER_SIZE))
|
if (std::cmp_greater(file.m_length, MAX_SHADER_SIZE))
|
||||||
return result::Unexpected(std::format("File too big: {}", file.m_length));
|
return std::unexpected(std::format("File too big: {}", file.m_length));
|
||||||
|
|
||||||
const auto shaderSize = file.m_length;
|
const auto shaderSize = file.m_length;
|
||||||
const auto shaderData = std::make_unique<char[]>(static_cast<size_t>(shaderSize));
|
const auto shaderData = std::make_unique<char[]>(static_cast<size_t>(shaderSize));
|
||||||
@@ -185,7 +185,7 @@ namespace shader
|
|||||||
if (shaderBlob)
|
if (shaderBlob)
|
||||||
shaderBlob->Release();
|
shaderBlob->Release();
|
||||||
|
|
||||||
return result::Unexpected(std::move(errorMessage));
|
return std::unexpected(std::move(errorMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto shaderBlobSize = static_cast<size_t>(shaderBlob->GetBufferSize());
|
const auto shaderBlobSize = static_cast<size_t>(shaderBlob->GetBufferSize());
|
||||||
@@ -199,7 +199,7 @@ namespace shader
|
|||||||
.m_shader_size = shaderBlobSize,
|
.m_shader_size = shaderBlobSize,
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
return result::Unexpected<std::string>("Shader compilation unavailable");
|
return std::unexpected("Shader compilation unavailable");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace shader
|
} // namespace shader
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include "SearchPath/ISearchPath.h"
|
#include "SearchPath/ISearchPath.h"
|
||||||
#include "Utils/MemoryManager.h"
|
#include "Utils/MemoryManager.h"
|
||||||
#include "Utils/Result.h"
|
|
||||||
|
|
||||||
|
#include <expected>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -18,6 +18,6 @@ namespace shader
|
|||||||
|
|
||||||
bool ShaderCompilationAvailable();
|
bool ShaderCompilationAvailable();
|
||||||
|
|
||||||
result::Expected<std::optional<CompiledShader>, std::string> CompileShader(
|
std::expected<std::optional<CompiledShader>, std::string> CompileShader(
|
||||||
const std::string& shaderFile, const std::string& entryPoint, const std::string& target, bool debug, ISearchPath& searchPath, MemoryManager& memory);
|
const std::string& shaderFile, const std::string& entryPoint, const std::string& target, bool debug, ISearchPath& searchPath, MemoryManager& memory);
|
||||||
} // namespace shader
|
} // namespace shader
|
||||||
|
|||||||
Reference in New Issue
Block a user