[Feat] (MG_Impl/Program): glAttachShader

This commit is contained in:
2025-08-11 15:50:24 +08:00
parent 4ec815a383
commit 429618a00a
3 changed files with 27 additions and 3 deletions
+13 -1
View File
@@ -57,7 +57,19 @@ namespace MobileGL {
}
void AttachShader_State(GLuint program, GLuint shader) {
THROW_UNIMPL_EXCEPTION;
auto programObject = TryToGetProgramObject(program);
if (!programObject)
return;
auto shaderObject = TryToGetShaderObject(shader);
if (!shaderObject)
return;
if (!programObject->AttachShader(shaderObject)) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"`shader` is already attached to `program`."));
return;
}
}
void BindAttribLocation_State(GLuint program, GLuint index, const GLchar* name) {
@@ -4,8 +4,19 @@
namespace MobileGL {
namespace MG_State {
namespace GLState {
void ProgramObject::AttachShader(SharedPtr<ShaderObject> shader) {
bool ProgramObject::ShaderIsAttached(SharedPtr<ShaderObject> shader) {
auto it = std::find_if(m_shaders.begin(), m_shaders.end(),
[shader](const SharedPtr<ShaderObject>& s) {
return s.get() == shader.get();
});
return it != m_shaders.end();
}
bool ProgramObject::AttachShader(SharedPtr<ShaderObject> shader) {
if (ShaderIsAttached(shader))
return false;
m_shaders.emplace_back(shader);
return true;
}
SizeT ProgramObject::DetachShader(SharedPtr<ShaderObject> shader) {
@@ -7,7 +7,8 @@ namespace MobileGL {
namespace GLState {
class ProgramObject {
public:
void AttachShader(SharedPtr<ShaderObject> shader);
bool ShaderIsAttached(SharedPtr<ShaderObject> shader);
bool AttachShader(SharedPtr<ShaderObject> shader);
SizeT DetachShader(SharedPtr<ShaderObject> shader);
void Link();
void MarkAsDeleted();