mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat] (MG_State/Program): GetAttachedShaders
This commit is contained in:
@@ -140,7 +140,23 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GetAttachedShaders_State(GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders) {
|
void GetAttachedShaders_State(GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders) {
|
||||||
THROW_UNIMPL_EXCEPTION;
|
if (maxCount < 0) {
|
||||||
|
MG_State::pGLContext->RecordError(
|
||||||
|
ErrorCode::InvalidValue,
|
||||||
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||||
|
"`maxCount` is less than 0."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto programObject = TryToGetProgramObject(program);
|
||||||
|
if (!programObject)
|
||||||
|
return;
|
||||||
|
const auto& s = programObject->GetAttachedShaders();
|
||||||
|
GLsizei c = std::min((GLsizei)s.size(), maxCount);
|
||||||
|
if (count)
|
||||||
|
*count = c;
|
||||||
|
for (GLsizei i = 0; i < c; ++i) {
|
||||||
|
shaders[i] = s[i]->GetId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLint GetAttribLocation_State(GLuint program, const GLchar* name) {
|
GLint GetAttribLocation_State(GLuint program, const GLchar* name) {
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ namespace MobileGL {
|
|||||||
void ProgramObject::MarkAsDeleted() {
|
void ProgramObject::MarkAsDeleted() {
|
||||||
m_deleteStatus = true;
|
m_deleteStatus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<SharedPtr<ShaderObject>>& ProgramObject::GetAttachedShaders() {
|
||||||
|
return m_shaders;
|
||||||
|
}
|
||||||
} // namespace GLState
|
} // namespace GLState
|
||||||
} // namespace MG_State
|
} // namespace MG_State
|
||||||
} // namespace MobileGL
|
} // namespace MobileGL
|
||||||
@@ -7,12 +7,15 @@ namespace MobileGL {
|
|||||||
namespace GLState {
|
namespace GLState {
|
||||||
class ProgramObject {
|
class ProgramObject {
|
||||||
public:
|
public:
|
||||||
|
ProgramObject(const Uint id): m_id(id) {}
|
||||||
bool ShaderIsAttached(SharedPtr<ShaderObject> shader);
|
bool ShaderIsAttached(SharedPtr<ShaderObject> shader);
|
||||||
bool AttachShader(SharedPtr<ShaderObject> shader);
|
bool AttachShader(SharedPtr<ShaderObject> shader);
|
||||||
SizeT DetachShader(SharedPtr<ShaderObject> shader);
|
SizeT DetachShader(SharedPtr<ShaderObject> shader);
|
||||||
void Link();
|
void Link();
|
||||||
void MarkAsDeleted();
|
void MarkAsDeleted();
|
||||||
|
Vector<SharedPtr<ShaderObject>>& GetAttachedShaders();
|
||||||
private:
|
private:
|
||||||
|
const Uint m_id = 0;
|
||||||
Vector<SharedPtr<ShaderObject>> m_shaders;
|
Vector<SharedPtr<ShaderObject>> m_shaders;
|
||||||
// basically this contains SPIR-V in binary format
|
// basically this contains SPIR-V in binary format
|
||||||
Vector<Vector<Uint>> m_programBinary;
|
Vector<Vector<Uint>> m_programBinary;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace MobileGL {
|
|||||||
Uint programId = 0;
|
Uint programId = 0;
|
||||||
m_programIndexGenerator.Generate(1, &programId);
|
m_programIndexGenerator.Generate(1, &programId);
|
||||||
EnsureIndexAvail(programId, m_programObjects);
|
EnsureIndexAvail(programId, m_programObjects);
|
||||||
auto programObject = MakeShared<ProgramObject>();
|
auto programObject = MakeShared<ProgramObject>(programId);
|
||||||
if (programObject == nullptr)
|
if (programObject == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
m_programObjects[programId] = programObject;
|
m_programObjects[programId] = programObject;
|
||||||
@@ -45,7 +45,7 @@ namespace MobileGL {
|
|||||||
Uint shaderId = 0;
|
Uint shaderId = 0;
|
||||||
m_shaderIndexGenerator.Generate(1, &shaderId);
|
m_shaderIndexGenerator.Generate(1, &shaderId);
|
||||||
EnsureIndexAvail(shaderId, m_shaderObjects);
|
EnsureIndexAvail(shaderId, m_shaderObjects);
|
||||||
auto shaderObject = MakeShared<ShaderObject>(stage);
|
auto shaderObject = MakeShared<ShaderObject>(stage, shaderId);
|
||||||
if (shaderObject == nullptr)
|
if (shaderObject == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
m_shaderObjects[shaderId] = shaderObject;
|
m_shaderObjects[shaderId] = shaderObject;
|
||||||
|
|||||||
@@ -56,16 +56,18 @@ namespace MobileGL {
|
|||||||
|
|
||||||
class ShaderObject {
|
class ShaderObject {
|
||||||
public:
|
public:
|
||||||
ShaderObject(const ShaderStage stage) : m_stage(stage) {}
|
ShaderObject(const ShaderStage stage, const Uint id) : m_stage(stage), m_id(id) {}
|
||||||
void SetShaderSource(const std::string& source);
|
void SetShaderSource(const std::string& source);
|
||||||
void SetShaderSource(std::string&& source);
|
void SetShaderSource(std::string&& source);
|
||||||
void Compile();
|
void Compile();
|
||||||
void MarkAsDeleted();
|
void MarkAsDeleted();
|
||||||
|
|
||||||
|
Uint GetId() const { return m_id; }
|
||||||
ShaderStage GetShaderStage() const { return m_stage; }
|
ShaderStage GetShaderStage() const { return m_stage; }
|
||||||
const std::string& GetShaderSource() const { return m_source; }
|
const std::string& GetShaderSource() const { return m_source; }
|
||||||
SharedPtr<glslang::TShader> GetCompiledShader() const { return m_shader; }
|
SharedPtr<glslang::TShader> GetCompiledShader() const { return m_shader; }
|
||||||
private:
|
private:
|
||||||
|
const Uint m_id = 0;
|
||||||
const ShaderStage m_stage;
|
const ShaderStage m_stage;
|
||||||
std::string m_source;
|
std::string m_source;
|
||||||
SharedPtr<glslang::TShader> m_shader;
|
SharedPtr<glslang::TShader> m_shader;
|
||||||
|
|||||||
Reference in New Issue
Block a user