From 5e27da20f43643d4e2ec01af5c1de423cef06cd3 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Mon, 16 Aug 2021 15:13:19 +0200 Subject: [PATCH] LibGL: Fix glTexCoord behaviour glTexCoord should behave like glColor. It only updates a gl context variable that contains the current texture coordinates. The vertex is only actually created once glVertex is called. --- Userland/Applications/3DFileViewer/Mesh.cpp | 10 +++++----- Userland/Libraries/LibGL/SoftwareGLContext.cpp | 11 +++++------ Userland/Libraries/LibGL/SoftwareGLContext.h | 1 + 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Applications/3DFileViewer/Mesh.cpp b/Userland/Applications/3DFileViewer/Mesh.cpp index 20e8cec61a4..0bae181b072 100644 --- a/Userland/Applications/3DFileViewer/Mesh.cpp +++ b/Userland/Applications/3DFileViewer/Mesh.cpp @@ -69,6 +69,9 @@ void Mesh::draw(float uv_scale) glBegin(GL_TRIANGLES); glColor4f(color.x(), color.y(), color.z(), color.w()); + if (is_textured()) + glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index0).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index0).v) * uv_scale); + // Vertex 1 glVertex3f( m_vertex_list.at(m_triangle_list[i].a).x, @@ -76,7 +79,7 @@ void Mesh::draw(float uv_scale) m_vertex_list.at(m_triangle_list[i].a).z); if (is_textured()) - glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index0).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index0).v) * uv_scale); + glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index1).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index1).v) * uv_scale); // Vertex 2 glVertex3f( @@ -85,7 +88,7 @@ void Mesh::draw(float uv_scale) m_vertex_list.at(m_triangle_list[i].b).z); if (is_textured()) - glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index1).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index1).v) * uv_scale); + glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index2).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index2).v) * uv_scale); // Vertex 3 glVertex3f( @@ -93,9 +96,6 @@ void Mesh::draw(float uv_scale) m_vertex_list.at(m_triangle_list[i].c).y, m_vertex_list.at(m_triangle_list[i].c).z); - if (is_textured()) - glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index2).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index2).v) * uv_scale); - glEnd(); } } diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 323955520c8..be2e8151fdc 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -555,19 +555,18 @@ void SoftwareGLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w // FIXME: This is to suppress any -Wunused errors vertex.w = 0.0f; - vertex.u = 0.0f; - vertex.v = 0.0f; + vertex.u = m_current_vertex_tex_coord.x(); + vertex.v = m_current_vertex_tex_coord.y(); vertex_list.append(vertex); } // FIXME: We need to add `r` and `q` to our GLVertex?! -void SoftwareGLContext::gl_tex_coord(GLfloat s, GLfloat t, GLfloat, GLfloat) +void SoftwareGLContext::gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q) { - auto& vertex = vertex_list.last(); // Get the last created vertex + APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_tex_coord, s, t, r, q); - vertex.u = s; - vertex.v = t; + m_current_vertex_tex_coord = { s, t, r, q }; } void SoftwareGLContext::gl_viewport(GLint x, GLint y, GLsizei width, GLsizei height) diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index abcdf7f19e2..7875ac38443 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -119,6 +119,7 @@ private: FloatVector4 m_clear_color = { 0.0f, 0.0f, 0.0f, 0.0f }; double m_clear_depth = { 1.0 }; FloatVector4 m_current_vertex_color = { 1.0f, 1.0f, 1.0f, 1.0f }; + FloatVector4 m_current_vertex_tex_coord = { 0.0f, 0.0f, 0.0f, 0.0f }; Vector vertex_list; Vector triangle_list;