mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 12:18:30 +09:00
34 lines
1.2 KiB
C++
34 lines
1.2 KiB
C++
#include "ShaderObject.h"
|
|
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
|
|
|
namespace MobileGL {
|
|
namespace MG_State {
|
|
namespace GLState {
|
|
void ShaderObject::SetShaderSource(const std::string& source) {
|
|
m_source = source;
|
|
}
|
|
|
|
void ShaderObject::Compile() {
|
|
using namespace MG_Util::ShaderTranspiler;
|
|
ShaderAttrib attrib{
|
|
.shaderType = GetGLShaderTypeByMGLShaderStage(m_stage),
|
|
.sourceStr = m_source,
|
|
.flags = 0
|
|
};
|
|
|
|
auto result = ShaderCompiler::CompileShader(attrib);
|
|
if (result) {
|
|
m_compileStatus = true;
|
|
m_shader = result.value();
|
|
} else {
|
|
m_compileStatus = false;
|
|
m_infoLog = result.error().log;
|
|
|
|
const std::string e = std::format("Shader compilation failed: \nerrc: {}\nmsg: {}\n",
|
|
result.error().errc, result.error().log);
|
|
THROW_EXCEPTION(e);
|
|
}
|
|
}
|
|
} // namespace GLState
|
|
} // namespace MG_State
|
|
} // namespace MobileGL
|