mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 08:50:37 +00:00
LibGL: Simplify transposing input matrices
We do not need to templatize the output type - it's always `float`. Also, the input type can be inferred. Finally, use template specialization instead of a conditional to deal with same type input and output matrices.
This commit is contained in:
parent
0ca1247a7f
commit
7c4bbdc398
Notes:
sideshowbarker
2024-07-17 02:57:48 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/7c4bbdc398 Pull-request: https://github.com/SerenityOS/serenity/pull/16543 Issue: https://github.com/SerenityOS/serenity/issues/15814 Reviewed-by: https://github.com/FalseHonesty Reviewed-by: https://github.com/sunverwerth ✅
1 changed files with 21 additions and 19 deletions
|
@ -15,23 +15,12 @@
|
|||
extern GL::GLContext* g_gl_context;
|
||||
|
||||
// Transposes input matrices (column-major) to our Matrix (row-major).
|
||||
template<typename I, typename O>
|
||||
static constexpr Matrix4x4<O> transpose_input_matrix(I const* matrix)
|
||||
template<typename I>
|
||||
constexpr FloatMatrix4x4 transpose_input_matrix(I const* matrix)
|
||||
{
|
||||
if constexpr (IsSame<I, O>) {
|
||||
// clang-format off
|
||||
return {
|
||||
matrix[0], matrix[4], matrix[8], matrix[12],
|
||||
matrix[1], matrix[5], matrix[9], matrix[13],
|
||||
matrix[2], matrix[6], matrix[10], matrix[14],
|
||||
matrix[3], matrix[7], matrix[11], matrix[15],
|
||||
};
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
Array<O, 16> elements;
|
||||
Array<float, 16> elements;
|
||||
for (size_t i = 0; i < 16; ++i)
|
||||
elements[i] = static_cast<O>(matrix[i]);
|
||||
elements[i] = static_cast<float>(matrix[i]);
|
||||
// clang-format off
|
||||
return {
|
||||
elements[0], elements[4], elements[8], elements[12],
|
||||
|
@ -42,6 +31,19 @@ static constexpr Matrix4x4<O> transpose_input_matrix(I const* matrix)
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr FloatMatrix4x4 transpose_input_matrix(float const* matrix)
|
||||
{
|
||||
// clang-format off
|
||||
return {
|
||||
matrix[0], matrix[4], matrix[8], matrix[12],
|
||||
matrix[1], matrix[5], matrix[9], matrix[13],
|
||||
matrix[2], matrix[6], matrix[10], matrix[14],
|
||||
matrix[3], matrix[7], matrix[11], matrix[15],
|
||||
};
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void glActiveTexture(GLenum texture)
|
||||
{
|
||||
g_gl_context->gl_active_texture(texture);
|
||||
|
@ -620,12 +622,12 @@ void glLoadIdentity()
|
|||
|
||||
void glLoadMatrixd(GLdouble const* matrix)
|
||||
{
|
||||
g_gl_context->gl_load_matrix(transpose_input_matrix<double, float>(matrix));
|
||||
g_gl_context->gl_load_matrix(transpose_input_matrix(matrix));
|
||||
}
|
||||
|
||||
void glLoadMatrixf(GLfloat const* matrix)
|
||||
{
|
||||
g_gl_context->gl_load_matrix(transpose_input_matrix<float, float>(matrix));
|
||||
g_gl_context->gl_load_matrix(transpose_input_matrix(matrix));
|
||||
}
|
||||
|
||||
void glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, GLdouble const* points)
|
||||
|
@ -738,12 +740,12 @@ void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q
|
|||
|
||||
void glMultMatrixd(GLdouble const* matrix)
|
||||
{
|
||||
g_gl_context->gl_mult_matrix(transpose_input_matrix<double, float>(matrix));
|
||||
g_gl_context->gl_mult_matrix(transpose_input_matrix(matrix));
|
||||
}
|
||||
|
||||
void glMultMatrixf(GLfloat const* matrix)
|
||||
{
|
||||
g_gl_context->gl_mult_matrix(transpose_input_matrix<float, float>(matrix));
|
||||
g_gl_context->gl_mult_matrix(transpose_input_matrix(matrix));
|
||||
}
|
||||
|
||||
void glNewList(GLuint list, GLenum mode)
|
||||
|
|
Loading…
Reference in a new issue