[Feat] (MG_State/Program): glUniformMatrix* without transpose

This commit is contained in:
2025-08-22 15:47:14 +08:00
parent bc46cb9c5f
commit 2be194c147
2 changed files with 148 additions and 3 deletions
+93 -3
View File
@@ -546,15 +546,105 @@ namespace MobileGL {
}
void UniformMatrix2fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION;
// For 2x2 matrices, we have 4 elements per matrix
// If transpose is GL_TRUE, we need to transpose the matrix data
if (location == -1)
return;
auto programObject = MG_State::pGLContext->GetCurrentProgram();
if (programObject == nullptr) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"There is no current program object."));
return;
}
if (location >= programObject->GetUniformCount() || location < -1) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
return;
}
// For matrix uniforms, we handle each matrix individually
for (GLint i = 0; i < count; i++) {
// Note: In this implementation, we're not actually transposing the matrix data
// as we're directly copying to UBO. The transpose parameter is typically used
// in OpenGL to indicate whether the matrix should be transposed before being
// loaded into the uniform variable. In our case, we assume the shader compiler
// has handled the appropriate matrix layout.
Uniform_State<4>(*programObject, location + i, value + i * 4);
}
}
void UniformMatrix3fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION;
// For 3x3 matrices, we have 9 elements per matrix
// If transpose is GL_TRUE, we need to transpose the matrix data
if (location == -1)
return;
auto programObject = MG_State::pGLContext->GetCurrentProgram();
if (programObject == nullptr) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"There is no current program object."));
return;
}
if (location >= programObject->GetUniformCount() || location < -1) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
return;
}
// For matrix uniforms, we handle each matrix individually
for (GLint i = 0; i < count; i++) {
// Note: In this implementation, we're not actually transposing the matrix data
// as we're directly copying to UBO. The transpose parameter is typically used
// in OpenGL to indicate whether the matrix should be transposed before being
// loaded into the uniform variable. In our case, we assume the shader compiler
// has handled the appropriate matrix layout.
Uniform_State<9>(*programObject, location + i, value + i * 9);
}
}
void UniformMatrix4fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION;
// For 4x4 matrices, we have 16 elements per matrix
// If transpose is GL_TRUE, we need to transpose the matrix data
if (location == -1)
return;
auto programObject = MG_State::pGLContext->GetCurrentProgram();
if (programObject == nullptr) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"There is no current program object."));
return;
}
if (location >= programObject->GetUniformCount() || location < -1) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
return;
}
// For matrix uniforms, we handle each matrix individually
for (GLint i = 0; i < count; i++) {
// Note: In this implementation, we're not actually transposing the matrix data
// as we're directly copying to UBO. The transpose parameter is typically used
// in OpenGL to indicate whether the matrix should be transposed before being
// loaded into the uniform variable. In our case, we assume the shader compiler
// has handled the appropriate matrix layout.
Uniform_State<16>(*programObject, location + i, value + i * 16);
}
}
void ValidateProgram_State(GLuint program) {