mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-09 12:48:32 +09:00
[Refactor] (All): Restructure include system.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "ProgramObject.h"
|
||||
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -8,10 +9,8 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void ProgramObject::DetachShader(SharedPtr<ShaderObject> shader) {
|
||||
auto count = std::erase_if(m_shaders,
|
||||
[shader](const SharedPtr<ShaderObject>& s) {
|
||||
return s.get() == shader.get();
|
||||
});
|
||||
auto count = std::erase_if(
|
||||
m_shaders, [shader](const SharedPtr<ShaderObject>& s) { return s.get() == shader.get(); });
|
||||
|
||||
if (count == 0) {
|
||||
// FIXME: handle error here
|
||||
@@ -27,7 +26,7 @@ namespace MobileGL {
|
||||
shaders[i] = m_shaders[i]->m_shader;
|
||||
}
|
||||
|
||||
MG_Util::ShaderTranspiler::ProgramAttrib attrib {
|
||||
MG_Util::ShaderTranspiler::ProgramAttrib attrib{
|
||||
.shaderTypes = Move(shaderTypes),
|
||||
.shaders = Move(shaders),
|
||||
};
|
||||
@@ -40,12 +39,11 @@ namespace MobileGL {
|
||||
m_linkStatus = false;
|
||||
m_infoLog = result.error().log;
|
||||
|
||||
const std::string e =
|
||||
std::format("Shader link failed: \nerrc: {}\nmsg: {}\n",
|
||||
result.error().errc, result.error().log);
|
||||
const std::string e = std::format("Shader link failed: \nerrc: {}\nmsg: {}\n", result.error().errc,
|
||||
result.error().log);
|
||||
THROW_EXCEPTION(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,23 +1,25 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Includes.h>
|
||||
#include "ShaderObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class ProgramObject {
|
||||
public:
|
||||
void AttachShader(SharedPtr<ShaderObject> shader);
|
||||
void DetachShader(SharedPtr<ShaderObject> shader);
|
||||
void Link();
|
||||
private:
|
||||
Vector<SharedPtr<ShaderObject>> m_shaders;
|
||||
// basically this contains SPIR-V in binary format
|
||||
Vector<Vector<Uint>> m_programBinary;
|
||||
String m_infoLog;
|
||||
bool m_deleteStatus = false;
|
||||
bool m_linkStatus = true;
|
||||
bool m_validateStatus = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class ProgramObject {
|
||||
public:
|
||||
void AttachShader(SharedPtr<ShaderObject> shader);
|
||||
void DetachShader(SharedPtr<ShaderObject> shader);
|
||||
void Link();
|
||||
|
||||
private:
|
||||
Vector<SharedPtr<ShaderObject>> m_shaders;
|
||||
// basically this contains SPIR-V in binary format
|
||||
Vector<Vector<Uint>> m_programBinary;
|
||||
String m_infoLog;
|
||||
bool m_deleteStatus = false;
|
||||
bool m_linkStatus = true;
|
||||
bool m_validateStatus = true;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "ProgramState.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -12,16 +12,14 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
SharedPtr<ProgramObject> ProgramState::GetProgramObject(Uint id) {
|
||||
if (!CheckIndexAvail(id))
|
||||
return nullptr; // FIXME: add error reporting here
|
||||
if (!CheckIndexAvail(id)) return nullptr; // FIXME: add error reporting here
|
||||
return m_programObjects[id];
|
||||
}
|
||||
|
||||
void ProgramState::DeleteProgram(Uint id) {
|
||||
if (!CheckIndexAvail(id))
|
||||
return; // FIXME: add error reporting here
|
||||
if (!CheckIndexAvail(id)) return; // FIXME: add error reporting here
|
||||
m_programObjects[id].reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include <MG_Util/Miscellany/IndexGenerator.h>
|
||||
#include "ProgramObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -10,10 +13,9 @@ namespace MobileGL {
|
||||
Uint CreateProgram();
|
||||
SharedPtr<ProgramObject> GetProgramObject(Uint id);
|
||||
void DeleteProgram(Uint program);
|
||||
|
||||
private:
|
||||
bool CheckIndexAvail(SizeT idx) {
|
||||
return idx < m_programObjects.size();
|
||||
}
|
||||
bool CheckIndexAvail(SizeT idx) { return idx < m_programObjects.size(); }
|
||||
|
||||
void EnsureIndexAvail(SizeT idx) {
|
||||
if (CheckIndexAvail(idx)) return;
|
||||
@@ -25,6 +27,6 @@ namespace MobileGL {
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
Vector<SharedPtr<ProgramObject>> m_programObjects;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "ShaderObject.h"
|
||||
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -9,11 +10,8 @@ namespace MobileGL {
|
||||
|
||||
void ShaderObject::Compile() {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib attrib {
|
||||
.sourceStr = m_source,
|
||||
.shaderType = GetGLShaderTypeByMGLShaderStage(m_stage),
|
||||
.flags = 0
|
||||
};
|
||||
ShaderAttrib attrib{
|
||||
.sourceStr = m_source, .shaderType = GetGLShaderTypeByMGLShaderStage(m_stage), .flags = 0};
|
||||
|
||||
auto result = ShaderCompiler::CompileShader(attrib);
|
||||
if (result) {
|
||||
@@ -23,12 +21,11 @@ namespace MobileGL {
|
||||
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);
|
||||
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
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -15,27 +15,27 @@ namespace MobileGL {
|
||||
|
||||
inline static GLenum GetGLShaderTypeByMGLShaderStage(ShaderStage stage) {
|
||||
switch (stage) {
|
||||
case ShaderStage::Vertex:
|
||||
return GL_VERTEX_SHADER;
|
||||
case ShaderStage::TessControl:
|
||||
return GL_TESS_CONTROL_SHADER;
|
||||
case ShaderStage::TessEval:
|
||||
return GL_TESS_EVALUATION_SHADER;
|
||||
case ShaderStage::Geometry:
|
||||
return GL_GEOMETRY_SHADER;
|
||||
case ShaderStage::Fragment:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
case ShaderStage::Compute:
|
||||
return GL_COMPUTE_SHADER;
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
case ShaderStage::Vertex:
|
||||
return GL_VERTEX_SHADER;
|
||||
case ShaderStage::TessControl:
|
||||
return GL_TESS_CONTROL_SHADER;
|
||||
case ShaderStage::TessEval:
|
||||
return GL_TESS_EVALUATION_SHADER;
|
||||
case ShaderStage::Geometry:
|
||||
return GL_GEOMETRY_SHADER;
|
||||
case ShaderStage::Fragment:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
case ShaderStage::Compute:
|
||||
return GL_COMPUTE_SHADER;
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class ShaderObject {
|
||||
public:
|
||||
ShaderObject(const ShaderStage stage): m_stage(stage) {}
|
||||
ShaderObject(const ShaderStage stage) : m_stage(stage) {}
|
||||
void SetShaderSource(const std::string& source);
|
||||
void Compile();
|
||||
|
||||
@@ -47,6 +47,6 @@ namespace MobileGL {
|
||||
bool m_deleteStatus = false;
|
||||
bool m_compileStatus = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
Reference in New Issue
Block a user