1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-06 02:07:35 +00:00

LibGL: Use Texture Units in Rasterizer and Context

The Context and Software Rasterizer now gets the array of texture units
instead of a single texture object. _Technically_, we now support some
primitive form of multi-texturing, though I'm not entirely sure how well
it will work in its current state.
This commit is contained in:
Jesse Buhagiar 2021-05-30 21:39:31 +10:00 committed by Linus Groh
parent 573c1c82f7
commit 8298e406a4
5 changed files with 38 additions and 27 deletions

View file

@ -421,13 +421,24 @@ void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle)
});
}
void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle, const Texture2D& texture)
void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle, const Array<TextureUnit, 32>& texture_units)
{
rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [&texture](const FloatVector2& uv, const FloatVector4& color) -> FloatVector4 {
rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [&texture_units](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;
FloatVector4 texel = color;
for (const auto& texture_unit : texture_units) {
// No texture is bound to this texture unit
if (!texture_unit.is_bound())
continue;
// FIXME: Don't assume Texture2D, _and_ work out how we blend/do multitexturing properly.....
texel = texel * static_ptr_cast<Texture2D>(texture_unit.bound_texture())->sample_texel(uv);
}
return texel;
});
}