mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:57:35 +00:00
LibGL+LibSoftGPU: Add multiple texture coordinates to vertex struct
We now have one set of texture coordinates per texture unit. Texture coordinate generation and texture coordinate assignment is currently only stubbed. This will be rectified in another commit.
This commit is contained in:
parent
044582b0ce
commit
7571ef0343
5 changed files with 22 additions and 15 deletions
|
@ -615,7 +615,8 @@ void SoftwareGLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w
|
|||
|
||||
vertex.position = { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(w) };
|
||||
vertex.color = m_current_vertex_color;
|
||||
vertex.tex_coord = m_current_vertex_tex_coord;
|
||||
for (size_t i = 0; i < m_device_info.num_texture_units; ++i)
|
||||
vertex.tex_coords[i] = m_current_vertex_tex_coord;
|
||||
vertex.normal = m_current_vertex_normal;
|
||||
|
||||
m_vertex_list.append(vertex);
|
||||
|
|
|
@ -47,7 +47,8 @@ Vertex Clipper::clip_intersection_point(const Vertex& p1, const Vertex& p2, Clip
|
|||
out.eye_coordinates = mix(p1.eye_coordinates, p2.eye_coordinates, a);
|
||||
out.clip_coordinates = mix(p1.clip_coordinates, p2.clip_coordinates, a);
|
||||
out.color = mix(p1.color, p2.color, a);
|
||||
out.tex_coord = mix(p1.tex_coord, p2.tex_coord, a);
|
||||
for (size_t i = 0; i < NUM_SAMPLERS; ++i)
|
||||
out.tex_coords[i] = mix(p1.tex_coords[i], p2.tex_coords[i], a);
|
||||
out.normal = mix(p1.normal, p2.normal, a);
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -522,7 +522,8 @@ void Device::rasterize_triangle(const Triangle& triangle)
|
|||
quad.vertex_color = expand4(vertex0.color);
|
||||
}
|
||||
|
||||
quad.uv = interpolate(expand4(vertex0.tex_coord), expand4(vertex1.tex_coord), expand4(vertex2.tex_coord), quad.barycentrics);
|
||||
for (size_t i = 0; i < NUM_SAMPLERS; ++i)
|
||||
quad.texture_coordinates[i] = interpolate(expand4(vertex0.tex_coords[i]), expand4(vertex1.tex_coords[i]), expand4(vertex2.tex_coords[i]), quad.barycentrics);
|
||||
|
||||
if (m_options.fog_enabled) {
|
||||
// Calculate depth of fragment for fog
|
||||
|
@ -667,11 +668,11 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
|
|||
};
|
||||
|
||||
auto const enabled_coords = options.texcoord_generation_enabled_coordinates;
|
||||
vertex.tex_coord = {
|
||||
((enabled_coords & TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(0) : vertex.tex_coord.x(),
|
||||
((enabled_coords & TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(1) : vertex.tex_coord.y(),
|
||||
((enabled_coords & TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(2) : vertex.tex_coord.z(),
|
||||
((enabled_coords & TexCoordGenerationCoordinate::Q) > 0) ? generate_coordinate(3) : vertex.tex_coord.w(),
|
||||
vertex.tex_coords[0] = {
|
||||
((enabled_coords & TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(0) : vertex.tex_coords[0].x(),
|
||||
((enabled_coords & TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(1) : vertex.tex_coords[0].y(),
|
||||
((enabled_coords & TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(2) : vertex.tex_coords[0].z(),
|
||||
((enabled_coords & TexCoordGenerationCoordinate::Q) > 0) ? generate_coordinate(3) : vertex.tex_coords[0].w(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -994,10 +995,11 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
|
|||
}
|
||||
|
||||
// Apply texture transformation
|
||||
// FIXME: implement multi-texturing: texcoords should be stored per texture unit
|
||||
triangle.vertices[0].tex_coord = texture_transform * triangle.vertices[0].tex_coord;
|
||||
triangle.vertices[1].tex_coord = texture_transform * triangle.vertices[1].tex_coord;
|
||||
triangle.vertices[2].tex_coord = texture_transform * triangle.vertices[2].tex_coord;
|
||||
for (size_t i = 0; i < NUM_SAMPLERS; ++i) {
|
||||
triangle.vertices[0].tex_coords[i] = texture_transform * triangle.vertices[0].tex_coords[i];
|
||||
triangle.vertices[1].tex_coords[i] = texture_transform * triangle.vertices[1].tex_coords[i];
|
||||
triangle.vertices[2].tex_coords[i] = texture_transform * triangle.vertices[2].tex_coords[i];
|
||||
}
|
||||
|
||||
rasterize_triangle(triangle);
|
||||
}
|
||||
|
@ -1011,7 +1013,7 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
|
|||
// FIXME: implement GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_CUBE_MAP
|
||||
auto const& sampler = m_samplers[i];
|
||||
|
||||
auto texel = sampler.sample_2d({ quad.uv.x(), quad.uv.y() });
|
||||
auto texel = sampler.sample_2d({ quad.texture_coordinates[i].x(), quad.texture_coordinates[i].y() });
|
||||
INCREASE_STATISTICS_COUNTER(g_num_sampler_calls, 1);
|
||||
|
||||
// FIXME: Implement more blend modes
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <LibGfx/Vector2.h>
|
||||
#include <LibGfx/Vector3.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
#include <LibSoftGPU/Config.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
|
||||
|
@ -18,7 +19,7 @@ struct PixelQuad final {
|
|||
Vector3<AK::SIMD::f32x4> barycentrics;
|
||||
AK::SIMD::f32x4 depth;
|
||||
Vector4<AK::SIMD::f32x4> vertex_color;
|
||||
Vector4<AK::SIMD::f32x4> uv;
|
||||
Array<Vector4<AK::SIMD::f32x4>, NUM_SAMPLERS> texture_coordinates;
|
||||
Vector4<AK::SIMD::f32x4> out_color;
|
||||
AK::SIMD::f32x4 fog_depth;
|
||||
AK::SIMD::i32x4 mask;
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <LibGfx/Vector3.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
#include <LibSoftGPU/Config.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
|
||||
|
@ -18,7 +20,7 @@ struct Vertex {
|
|||
FloatVector4 clip_coordinates;
|
||||
FloatVector4 window_coordinates;
|
||||
FloatVector4 color;
|
||||
FloatVector4 tex_coord;
|
||||
Array<FloatVector4, NUM_SAMPLERS> tex_coords;
|
||||
FloatVector3 normal;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue