浏览代码

LibGL: Track multiple current texture coordinates in GLContext

Previously we only had a single current texture coordinate, set by
the glTexCoord family of functions. Since we now can have multiple
texture coordinates we track a vector of current texture coordinates
and set the requested one in glMultiTexCoord(). glTexCoord() Always sets
the first texture coordinate.
Stephan Unverwerth 3 年之前
父节点
当前提交
9627576d9c
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 8 3
      Userland/Libraries/LibGL/SoftwareGLContext.cpp
  2. 2 2
      Userland/Libraries/LibGL/SoftwareGLContext.h

+ 8 - 3
Userland/Libraries/LibGL/SoftwareGLContext.cpp

@@ -79,6 +79,9 @@ SoftwareGLContext::SoftwareGLContext(Gfx::Bitmap& frontbuffer)
 
     m_client_side_texture_coord_array_enabled.resize(m_device_info.num_texture_units);
     m_client_tex_coord_pointer.resize(m_device_info.num_texture_units);
+    m_current_vertex_tex_coord.resize(m_device_info.num_texture_units);
+    for (auto& tex_coord : m_current_vertex_tex_coord)
+        tex_coord = { 0.0f, 0.0f, 0.0f, 1.0f };
 
     build_extension_string();
 }
@@ -619,7 +622,7 @@ void SoftwareGLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w
     vertex.position = { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(w) };
     vertex.color = m_current_vertex_color;
     for (size_t i = 0; i < m_device_info.num_texture_units; ++i)
-        vertex.tex_coords[i] = m_current_vertex_tex_coord;
+        vertex.tex_coords[i] = m_current_vertex_tex_coord[i];
     vertex.normal = m_current_vertex_normal;
 
     m_vertex_list.append(vertex);
@@ -629,14 +632,16 @@ void SoftwareGLContext::gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q)
 {
     APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_tex_coord, s, t, r, q);
 
-    m_current_vertex_tex_coord = { s, t, r, q };
+    m_current_vertex_tex_coord[0] = { s, t, r, q };
 }
 
 void SoftwareGLContext::gl_multi_tex_coord(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
 {
     APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_multi_tex_coord, target, s, t, r, q);
 
-    m_current_vertex_tex_coord = { s, t, r, q };
+    RETURN_WITH_ERROR_IF(target < GL_TEXTURE0 || target >= GL_TEXTURE0 + m_device_info.num_texture_units, GL_INVALID_ENUM);
+
+    m_current_vertex_tex_coord[target - GL_TEXTURE0] = { s, t, r, q };
 }
 
 void SoftwareGLContext::gl_viewport(GLint x, GLint y, GLsizei width, GLsizei height)

+ 2 - 2
Userland/Libraries/LibGL/SoftwareGLContext.h

@@ -204,7 +204,7 @@ private:
     u8 m_clear_stencil { 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, 1.0f };
+    Vector<FloatVector4> m_current_vertex_tex_coord;
     FloatVector3 m_current_vertex_normal = { 0.0f, 0.0f, 1.0f };
 
     Vector<SoftGPU::Vertex> m_vertex_list;
@@ -262,7 +262,7 @@ private:
     // Texture objects
     TextureNameAllocator m_name_allocator;
     HashMap<GLuint, RefPtr<Texture>> m_allocated_textures;
-    Vector<TextureUnit, 32> m_texture_units;
+    Vector<TextureUnit> m_texture_units;
     TextureUnit* m_active_texture_unit;
 
     // Texture coordinate generation state