LibGL: Add texture sampling to SW Rasterizer

The software rasterizer now samples a texture passed to us from the
GL context. This is currently a bit of a hack, as we should be
scanning from a list of texture units and checking if they are
enabled. For now, this at least gives some visual confirmation
that texturing is working as it should
This commit is contained in:
Jesse Buhagiar 2021-05-23 23:33:33 +10:00 committed by Ali Mohammad Pur
parent e21ba0cd12
commit 3287709df9
Notes: sideshowbarker 2024-07-18 17:22:03 +09:00
3 changed files with 16 additions and 5 deletions

View file

@ -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();

View file

@ -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;
});
}

View file

@ -9,6 +9,7 @@
#include "DepthBuffer.h"
#include "GL/gl.h"
#include "GLStruct.h"
#include "Tex/Texture.h"
#include <AK/OwnPtr.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Vector4.h>
@ -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);