[Feat]: Implement glBindFragDataLocation and glGetFragDataLocation

This commit is contained in:
2025-11-13 13:23:37 +08:00
parent 5b2d18fdff
commit b3b304e9e6
5 changed files with 138 additions and 11 deletions
@@ -837,6 +837,39 @@ namespace MobileGL {
MGLOG_D("%s: \"%s\" at uniformBlockIndex %02d, length = %d", __func__, uniformBlockName, uniformBlockIndex, *length);
}
void BindFragDataLocation_State(GLuint program, GLuint colorNumber, const char* name) {
auto programObject = TryToGetProgramObject(program);
if (programObject == nullptr) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`program` is not the name of a program object."));
return;
}
if (strncmp(name, "gl_", 3) == 0) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"`name` starts with the reserved prefix `gl_`."));
return;
}
// TODO: Emit error "if `colorNumber` is greater than or equal to `GL_MAX_DRAW_BUFFERS`"
MGLOG_D("%s: loc %02d = \"%s\"", __func__, index, name);
programObject->SetExplicitFragmentOutLocation(colorNumber, name);
}
GLint GetFragDataLocation_State(GLuint program, const char* name) {
auto programObject = TryToGetProgramObject(program);
if (programObject == nullptr) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`program` is not the name of a program object."));
return -1;
}
return programObject->GetFragmentDataLocation(name);
}
void ValidateProgram_State(GLuint program) {
// THROW_UNIMPL_EXCEPTION;
}
@@ -1039,6 +1072,14 @@ namespace MobileGL {
GetActiveUniformBlockName_State(program, uniformBlockIndex, bufSize, length, uniformBlockName);
}
void BindFragDataLocation(GLuint program, GLuint colorNumber, const char* name) {
BindFragDataLocation_State(program, colorNumber, name);
}
GLint GetFragDataLocation(GLuint program, const char* name) {
return GetFragDataLocation_State(program, name);
}
void ValidateProgram(GLuint program) {
ValidateProgram_State(program);
}
@@ -53,6 +53,8 @@ namespace MobileGL {
void UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
void GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params);
void GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName);
void BindFragDataLocation(GLuint program, GLuint colorNumber, const char* name);
GLint GetFragDataLocation(GLuint program, const char* name);
void ValidateProgram(GLuint program);
} // namespace MG_Impl::GLImpl
} // namespace MobileGL