mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
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:
parent
e21ba0cd12
commit
3287709df9
3 changed files with 16 additions and 5 deletions
|
@ -255,16 +255,22 @@ void SoftwareGLContext::gl_end()
|
||||||
vertex.g = vertexa.g;
|
vertex.g = vertexa.g;
|
||||||
vertex.b = vertexa.b;
|
vertex.b = vertexa.b;
|
||||||
vertex.a = vertexa.a;
|
vertex.a = vertexa.a;
|
||||||
|
vertex.u = vertexa.u;
|
||||||
|
vertex.v = vertexa.v;
|
||||||
} else if (vec_idx == 1) {
|
} else if (vec_idx == 1) {
|
||||||
vertex.r = vertexb.r;
|
vertex.r = vertexb.r;
|
||||||
vertex.g = vertexb.g;
|
vertex.g = vertexb.g;
|
||||||
vertex.b = vertexb.b;
|
vertex.b = vertexb.b;
|
||||||
vertex.a = vertexb.a;
|
vertex.a = vertexb.a;
|
||||||
|
vertex.u = vertexb.u;
|
||||||
|
vertex.v = vertexb.v;
|
||||||
} else {
|
} else {
|
||||||
vertex.r = vertexc.r;
|
vertex.r = vertexc.r;
|
||||||
vertex.g = vertexc.g;
|
vertex.g = vertexc.g;
|
||||||
vertex.b = vertexc.b;
|
vertex.b = vertexc.b;
|
||||||
vertex.a = vertexc.a;
|
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!?
|
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;
|
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();
|
triangle_list.clear();
|
||||||
|
|
|
@ -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 {
|
rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [&texture](const FloatVector2& uv, const FloatVector4& color) -> FloatVector4 {
|
||||||
return color;
|
// 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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "DepthBuffer.h"
|
#include "DepthBuffer.h"
|
||||||
#include "GL/gl.h"
|
#include "GL/gl.h"
|
||||||
#include "GLStruct.h"
|
#include "GLStruct.h"
|
||||||
|
#include "Tex/Texture.h"
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Vector4.h>
|
#include <LibGfx/Vector4.h>
|
||||||
|
@ -30,7 +31,7 @@ class SoftwareRasterizer final {
|
||||||
public:
|
public:
|
||||||
SoftwareRasterizer(const Gfx::IntSize& min_size);
|
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 resize(const Gfx::IntSize& min_size);
|
||||||
void clear_color(const FloatVector4&);
|
void clear_color(const FloatVector4&);
|
||||||
void clear_depth(float);
|
void clear_depth(float);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue