diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 567cc2ddc79..c7d97ee17ff 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -255,16 +255,22 @@ void SoftwareGLContext::gl_end() vertex.g = vertexa.g; vertex.b = vertexa.b; vertex.a = vertexa.a; + vertex.u = vertexa.u; + vertex.v = vertexa.v; } else if (vec_idx == 1) { vertex.r = vertexb.r; vertex.g = vertexb.g; vertex.b = vertexb.b; vertex.a = vertexb.a; + vertex.u = vertexb.u; + vertex.v = vertexb.v; } else { vertex.r = vertexc.r; vertex.g = vertexc.g; vertex.b = vertexc.b; vertex.a = vertexc.a; + vertex.u = vertexc.u; + vertex.v = vertexc.v; } vertex.x = (vec.x() + 1.0f) * (scr_width / 2.0f) + 0.0f; // TODO: 0.0f should be something!? @@ -322,7 +328,8 @@ void SoftwareGLContext::gl_end() continue; } - m_rasterizer.submit_triangle(triangle); + // FIXME: Change this when we have texture units/multi-texturing + m_rasterizer.submit_triangle(triangle, *m_allocated_textures.find(1)->value); } triangle_list.clear(); diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp index 9acca22a139..b794a04e8ed 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp @@ -414,10 +414,13 @@ SoftwareRasterizer::SoftwareRasterizer(const Gfx::IntSize& min_size) { } -void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle) +void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle, const Texture& texture) { - rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [](const FloatVector2&, const FloatVector4& color) -> FloatVector4 { - return color; + rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [&texture](const FloatVector2& uv, const FloatVector4& color) -> FloatVector4 { + // TODO: We'd do some kind of multitexturing/blending here + // Construct a vector for the texel we want to sample + FloatVector4 texel = texture.sample_texel(uv); + return texel * color; }); } diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibGL/SoftwareRasterizer.h index 841bbc5f559..884d94cb4c3 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.h +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.h @@ -9,6 +9,7 @@ #include "DepthBuffer.h" #include "GL/gl.h" #include "GLStruct.h" +#include "Tex/Texture.h" #include #include #include @@ -30,7 +31,7 @@ class SoftwareRasterizer final { public: SoftwareRasterizer(const Gfx::IntSize& min_size); - void submit_triangle(const GLTriangle& triangle); + void submit_triangle(const GLTriangle& triangle, const Texture& texture); void resize(const Gfx::IntSize& min_size); void clear_color(const FloatVector4&); void clear_depth(float);