diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-03-23 12:36:53 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-03-27 09:19:43 -0700 |
commit | 74de8e4224e1e883dac71c399b86bfd499f811c8 (patch) | |
tree | ebd52b085a3a1af9a1353d0280d9777e4b26e391 /Userland | |
parent | bc5e5afc7be272d04f8b1767895dfec6d3dbc455 (diff) | |
download | serenity-74de8e4224e1e883dac71c399b86bfd499f811c8.zip |
LibGL: Always normalize vertex attribute data
We were normalizing data read from vertex attribute pointers based on
their usage, but there is nothing written about this behavior in the
spec or in man pages.
When we implement `glVertexAttribPointer` however, the user can
optionally enable normalization per vertex attribute pointer. This
refactors the `VertexAttribPointer` to have a `normalize` field so we
can support that future implementation.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 3 |
2 files changed, 12 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp index 09004eacb6..009c765436 100644 --- a/Userland/Libraries/LibGL/GLContext.cpp +++ b/Userland/Libraries/LibGL/GLContext.cpp @@ -2101,26 +2101,26 @@ void GLContext::gl_draw_arrays(GLenum mode, GLint first, GLsizei count) for (int i = first; i < last; i++) { if (m_client_side_color_array_enabled) { float color[4] { 0, 0, 0, 1 }; - read_from_vertex_attribute_pointer(m_client_color_pointer, i, color, true); + read_from_vertex_attribute_pointer(m_client_color_pointer, i, color); gl_color(color[0], color[1], color[2], color[3]); } for (size_t t = 0; t < m_client_tex_coord_pointer.size(); ++t) { if (m_client_side_texture_coord_array_enabled[t]) { float tex_coords[4] { 0, 0, 0, 0 }; - read_from_vertex_attribute_pointer(m_client_tex_coord_pointer[t], i, tex_coords, false); + read_from_vertex_attribute_pointer(m_client_tex_coord_pointer[t], i, tex_coords); gl_multi_tex_coord(GL_TEXTURE0 + t, tex_coords[0], tex_coords[1], tex_coords[2], tex_coords[3]); } } if (m_client_side_normal_array_enabled) { float normal[3]; - read_from_vertex_attribute_pointer(m_client_normal_pointer, i, normal, false); + read_from_vertex_attribute_pointer(m_client_normal_pointer, i, normal); gl_normal(normal[0], normal[1], normal[2]); } float vertex[4] { 0, 0, 0, 1 }; - read_from_vertex_attribute_pointer(m_client_vertex_pointer, i, vertex, false); + read_from_vertex_attribute_pointer(m_client_vertex_pointer, i, vertex); gl_vertex(vertex[0], vertex[1], vertex[2], vertex[3]); } gl_end(); @@ -2168,26 +2168,26 @@ void GLContext::gl_draw_elements(GLenum mode, GLsizei count, GLenum type, const if (m_client_side_color_array_enabled) { float color[4] { 0, 0, 0, 1 }; - read_from_vertex_attribute_pointer(m_client_color_pointer, i, color, true); + read_from_vertex_attribute_pointer(m_client_color_pointer, i, color); gl_color(color[0], color[1], color[2], color[3]); } for (size_t t = 0; t < m_client_tex_coord_pointer.size(); ++t) { if (m_client_side_texture_coord_array_enabled[t]) { float tex_coords[4] { 0, 0, 0, 0 }; - read_from_vertex_attribute_pointer(m_client_tex_coord_pointer[t], i, tex_coords, false); + read_from_vertex_attribute_pointer(m_client_tex_coord_pointer[t], i, tex_coords); gl_multi_tex_coord(GL_TEXTURE0 + t, tex_coords[0], tex_coords[1], tex_coords[2], tex_coords[3]); } } if (m_client_side_normal_array_enabled) { float normal[3]; - read_from_vertex_attribute_pointer(m_client_normal_pointer, i, normal, false); + read_from_vertex_attribute_pointer(m_client_normal_pointer, i, normal); gl_normal(normal[0], normal[1], normal[2]); } float vertex[4] { 0, 0, 0, 1 }; - read_from_vertex_attribute_pointer(m_client_vertex_pointer, i, vertex, false); + read_from_vertex_attribute_pointer(m_client_vertex_pointer, i, vertex); gl_vertex(vertex[0], vertex[1], vertex[2], vertex[3]); } gl_end(); @@ -2342,9 +2342,10 @@ void GLContext::gl_depth_func(GLenum func) } // General helper function to read arbitrary vertex attribute data into a float array -void GLContext::read_from_vertex_attribute_pointer(VertexAttribPointer const& attrib, int index, float* elements, bool normalize) +void GLContext::read_from_vertex_attribute_pointer(VertexAttribPointer const& attrib, int index, float* elements) { auto byte_ptr = reinterpret_cast<const char*>(attrib.pointer); + auto normalize = attrib.normalize; size_t stride = attrib.stride; switch (attrib.type) { diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 943d0c4b80..c4704973fb 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -417,11 +417,12 @@ private: struct VertexAttribPointer { GLint size { 4 }; GLenum type { GL_FLOAT }; + bool normalize { true }; GLsizei stride { 0 }; const void* pointer { 0 }; }; - static void read_from_vertex_attribute_pointer(VertexAttribPointer const&, int index, float* elements, bool normalize); + static void read_from_vertex_attribute_pointer(VertexAttribPointer const&, int index, float* elements); VertexAttribPointer m_client_vertex_pointer; VertexAttribPointer m_client_color_pointer; |