diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 5d209c703b..f038f330eb 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -224,14 +224,14 @@ void SoftwareGLContext::gl_end() RETURN_WITH_ERROR_IF(true, GL_INVALID_ENUM); } - m_bound_texture_units.clear(); - for (auto& texture_unit : m_texture_units) { - if (texture_unit.is_bound()) - m_bound_texture_units.append(texture_unit); + Vector enabled_texture_units; + for (size_t i = 0; i < m_texture_units.size(); ++i) { + if (m_texture_units[i].texture_2d_enabled()) + enabled_texture_units.append(i); } sync_device_config(); - m_rasterizer.draw_primitives(m_current_draw_mode, m_projection_matrix * m_model_view_matrix, m_texture_matrix, m_vertex_list, m_bound_texture_units); + m_rasterizer.draw_primitives(m_current_draw_mode, m_projection_matrix * m_model_view_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units); m_vertex_list.clear_with_capacity(); } diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 9121959701..cde187e80d 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -235,7 +235,6 @@ private: HashMap> m_allocated_textures; Array m_texture_units; TextureUnit* m_active_texture_unit { &m_texture_units[0] }; - TextureUnit::BoundList m_bound_texture_units; SoftGPU::Device m_rasterizer; bool m_sampler_config_is_dirty { true }; diff --git a/Userland/Libraries/LibGL/Tex/TextureUnit.h b/Userland/Libraries/LibGL/Tex/TextureUnit.h index 8d52e86d4b..f7ec122047 100644 --- a/Userland/Libraries/LibGL/Tex/TextureUnit.h +++ b/Userland/Libraries/LibGL/Tex/TextureUnit.h @@ -36,9 +36,6 @@ public: bool texture_cube_map_enabled() const { return m_texture_cube_map_enabled; }; void set_texture_cube_map_enabled(bool texture_cube_map_enabled) { m_texture_cube_map_enabled = texture_cube_map_enabled; } - IntrusiveListNode m_bound_node; - using BoundList = IntrusiveList<&TextureUnit::m_bound_node>; - private: mutable RefPtr m_texture_target_2d { nullptr }; mutable RefPtr m_currently_bound_texture { nullptr }; diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 8440e0c88c..cb46865f5a 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -495,7 +495,7 @@ Device::Device(const Gfx::IntSize& min_size) m_options.scissor_box = m_render_target->rect(); } -void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector const& vertices, GL::TextureUnit::BoundList const& bound_texture_units) +void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector const& vertices, Vector const& enabled_texture_units) { // At this point, the user has effectively specified that they are done with defining the geometry // of what they want to draw. We now need to do a few things (https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview): @@ -644,38 +644,31 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf swap(triangle.vertices[0], triangle.vertices[1]); } - submit_triangle(triangle, bound_texture_units); + submit_triangle(triangle, enabled_texture_units); } } -void Device::submit_triangle(const Triangle& triangle, GL::TextureUnit::BoundList const& bound_texture_units) +void Device::submit_triangle(const Triangle& triangle, Vector const& enabled_texture_units) { - rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [this, &bound_texture_units](FloatVector4 const& uv, FloatVector4 const& color, float z) -> FloatVector4 { + rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [this, &enabled_texture_units](FloatVector4 const& uv, FloatVector4 const& color, float z) -> FloatVector4 { FloatVector4 fragment = color; - for (auto const& texture_unit : bound_texture_units) { + for (size_t i : enabled_texture_units) { // FIXME: implement GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_CUBE_MAP - FloatVector4 texel; - switch (texture_unit.currently_bound_target()) { - case GL_TEXTURE_2D: - if (!texture_unit.texture_2d_enabled() || texture_unit.texture_3d_enabled() || texture_unit.texture_cube_map_enabled()) - continue; - texel = texture_unit.bound_texture_2d()->sampler().sample(uv); - break; - default: - VERIFY_NOT_REACHED(); - } + auto const& sampler = m_samplers[i]; + + FloatVector4 texel = sampler.sample_2d({ uv.x(), uv.y() }); // FIXME: Implement more blend modes - switch (texture_unit.env_mode()) { - case GL_MODULATE: + switch (sampler.config().fixed_function_texture_env_mode) { + case TextureEnvMode::Modulate: default: fragment = fragment * texel; break; - case GL_REPLACE: + case TextureEnvMode::Replace: fragment = texel; break; - case GL_DECAL: { + case TextureEnvMode::Decal: { float src_alpha = fragment.w(); float one_minus_src_alpha = 1 - src_alpha; fragment.set_x(texel.x() * src_alpha + fragment.x() * one_minus_src_alpha); diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index 0ea13f47df..a0cd4a9f37 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -68,7 +68,7 @@ class Device final { public: Device(const Gfx::IntSize& min_size); - void draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector const& vertices, GL::TextureUnit::BoundList const& bound_texture_units); + void draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector const& vertices, Vector const& enabled_texture_units); void resize(const Gfx::IntSize& min_size); void clear_color(const FloatVector4&); void clear_depth(float); @@ -85,7 +85,7 @@ public: void set_sampler_config(unsigned, SamplerConfig const&); private: - void submit_triangle(Triangle const& triangle, GL::TextureUnit::BoundList const& bound_texture_units); + void submit_triangle(Triangle const& triangle, Vector const& enabled_texture_units); private: RefPtr m_render_target;