mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
LibGL+LibGPU+LibSoftGPU: Move Vertex.h to LibGPU
This commit is contained in:
parent
5bf224708f
commit
5d2740217f
Notes:
sideshowbarker
2024-07-17 14:22:56 +09:00
Author: https://github.com/sunverwerth Commit: https://github.com/SerenityOS/serenity/commit/5d2740217f Pull-request: https://github.com/SerenityOS/serenity/pull/13294 Reviewed-by: https://github.com/Quaker762 ✅ Reviewed-by: https://github.com/creator1creeper1 Reviewed-by: https://github.com/gmta
11 changed files with 37 additions and 34 deletions
|
@ -577,7 +577,7 @@ void GLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
|
|||
{
|
||||
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_vertex, x, y, z, w);
|
||||
|
||||
SoftGPU::Vertex vertex;
|
||||
GPU::Vertex vertex;
|
||||
|
||||
vertex.position = { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(w) };
|
||||
vertex.color = m_current_vertex_color;
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
#include <LibGL/Tex/TextureUnit.h>
|
||||
#include <LibGPU/DeviceInfo.h>
|
||||
#include <LibGPU/Light.h>
|
||||
#include <LibGPU/Vertex.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Matrix4x4.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/Vector3.h>
|
||||
#include <LibSoftGPU/Clipper.h>
|
||||
#include <LibSoftGPU/Device.h>
|
||||
#include <LibSoftGPU/Vertex.h>
|
||||
|
||||
namespace GL {
|
||||
|
||||
|
@ -219,7 +219,7 @@ private:
|
|||
Vector<FloatVector4> m_current_vertex_tex_coord;
|
||||
FloatVector3 m_current_vertex_normal { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
Vector<SoftGPU::Vertex> m_vertex_list;
|
||||
Vector<GPU::Vertex> m_vertex_list;
|
||||
|
||||
GLenum m_error = GL_NO_ERROR;
|
||||
bool m_in_draw_state = false;
|
||||
|
|
|
@ -16,4 +16,8 @@ using ColorType = u32; // BGRA:8888
|
|||
using DepthType = float;
|
||||
using StencilType = u8;
|
||||
|
||||
// FIXME: This constant was originally introduced in LibSoftGPU and is currently used in the Vertex struct.
|
||||
// Once we refactor the interface this should move back into LibSoftGPU.
|
||||
static constexpr int NUM_SAMPLERS = 2;
|
||||
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <LibGPU/Config.h>
|
||||
#include <LibGfx/Vector3.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
#include <LibSoftGPU/Config.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
namespace GPU {
|
||||
|
||||
struct Vertex {
|
||||
FloatVector4 position;
|
||||
|
@ -20,7 +20,7 @@ struct Vertex {
|
|||
FloatVector4 clip_coordinates;
|
||||
FloatVector4 window_coordinates;
|
||||
FloatVector4 color;
|
||||
Array<FloatVector4, NUM_SAMPLERS> tex_coords;
|
||||
Array<FloatVector4, GPU::NUM_SAMPLERS> tex_coords;
|
||||
FloatVector3 normal;
|
||||
};
|
||||
|
|
@ -7,9 +7,9 @@
|
|||
*/
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGPU/Vertex.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
#include <LibSoftGPU/Clipper.h>
|
||||
#include <LibSoftGPU/Vertex.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
|
||||
|
@ -33,7 +33,7 @@ static constexpr bool point_within_clip_plane(FloatVector4 const& vertex)
|
|||
}
|
||||
|
||||
template<Clipper::ClipPlane plane>
|
||||
static constexpr Vertex clip_intersection_point(Vertex const& p1, Vertex const& p2)
|
||||
static constexpr GPU::Vertex clip_intersection_point(GPU::Vertex const& p1, GPU::Vertex const& p2)
|
||||
{
|
||||
constexpr FloatVector4 clip_plane_normals[] = {
|
||||
{ 1, 0, 0, 0 }, // Left Plane
|
||||
|
@ -54,19 +54,19 @@ static constexpr Vertex clip_intersection_point(Vertex const& p1, Vertex const&
|
|||
float const x2 = clip_plane_normal.dot(p2.clip_coordinates);
|
||||
float const a = (w1 + x1) / ((w1 + x1) - (w2 + x2));
|
||||
|
||||
Vertex out;
|
||||
GPU::Vertex out;
|
||||
out.position = mix(p1.position, p2.position, a);
|
||||
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);
|
||||
for (size_t i = 0; i < NUM_SAMPLERS; ++i)
|
||||
for (size_t i = 0; i < GPU::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;
|
||||
}
|
||||
|
||||
template<Clipper::ClipPlane plane>
|
||||
FLATTEN static constexpr void clip_plane(Vector<Vertex>& read_list, Vector<Vertex>& write_list)
|
||||
FLATTEN static constexpr void clip_plane(Vector<GPU::Vertex>& read_list, Vector<GPU::Vertex>& write_list)
|
||||
{
|
||||
auto read_from = &read_list;
|
||||
auto write_to = &write_list;
|
||||
|
@ -89,7 +89,7 @@ FLATTEN static constexpr void clip_plane(Vector<Vertex>& read_list, Vector<Verte
|
|||
swap(write_list, read_list);
|
||||
}
|
||||
|
||||
void Clipper::clip_triangle_against_frustum(Vector<Vertex>& input_verts)
|
||||
void Clipper::clip_triangle_against_frustum(Vector<GPU::Vertex>& input_verts)
|
||||
{
|
||||
list_a = input_verts;
|
||||
list_b.clear_with_capacity();
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGPU/Vertex.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
#include <LibSoftGPU/Vertex.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
|
||||
|
@ -26,11 +26,11 @@ public:
|
|||
|
||||
Clipper() = default;
|
||||
|
||||
void clip_triangle_against_frustum(Vector<Vertex>& input_vecs);
|
||||
void clip_triangle_against_frustum(Vector<GPU::Vertex>& input_vecs);
|
||||
|
||||
private:
|
||||
Vector<Vertex> list_a;
|
||||
Vector<Vertex> list_b;
|
||||
Vector<GPU::Vertex> list_a;
|
||||
Vector<GPU::Vertex> list_b;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
namespace SoftGPU {
|
||||
|
||||
static constexpr bool ENABLE_STATISTICS_OVERLAY = false;
|
||||
static constexpr int NUM_SAMPLERS = 2;
|
||||
static constexpr int MILLISECONDS_PER_STATISTICS_PERIOD = 500;
|
||||
static constexpr int NUM_LIGHTS = 8;
|
||||
|
||||
|
|
|
@ -184,9 +184,9 @@ void Device::rasterize_triangle(Triangle const& triangle)
|
|||
return;
|
||||
|
||||
// Vertices
|
||||
Vertex const& vertex0 = triangle.vertices[0];
|
||||
Vertex const& vertex1 = triangle.vertices[1];
|
||||
Vertex const& vertex2 = triangle.vertices[2];
|
||||
GPU::Vertex const& vertex0 = triangle.vertices[0];
|
||||
GPU::Vertex const& vertex1 = triangle.vertices[1];
|
||||
GPU::Vertex const& vertex2 = triangle.vertices[2];
|
||||
|
||||
// Calculate area of the triangle for later tests
|
||||
FloatVector2 const v0 = vertex0.window_coordinates.xy();
|
||||
|
@ -510,7 +510,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
|
|||
else
|
||||
quad.vertex_color = expand4(vertex0.color);
|
||||
|
||||
for (size_t i = 0; i < NUM_SAMPLERS; ++i)
|
||||
for (size_t i = 0; i < GPU::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)
|
||||
|
@ -582,14 +582,14 @@ GPU::DeviceInfo Device::info() const
|
|||
return {
|
||||
.vendor_name = "SerenityOS",
|
||||
.device_name = "SoftGPU",
|
||||
.num_texture_units = NUM_SAMPLERS,
|
||||
.num_texture_units = GPU::NUM_SAMPLERS,
|
||||
.num_lights = NUM_LIGHTS,
|
||||
.stencil_bits = sizeof(GPU::StencilType) * 8,
|
||||
.supports_npot_textures = true,
|
||||
};
|
||||
}
|
||||
|
||||
static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const& options)
|
||||
static void generate_texture_coordinates(GPU::Vertex& vertex, RasterizerOptions const& options)
|
||||
{
|
||||
auto generate_coordinate = [&](size_t texcoord_index, size_t config_index) -> float {
|
||||
auto mode = options.texcoord_generation_config[texcoord_index][config_index].mode;
|
||||
|
@ -640,7 +640,7 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
|
|||
}
|
||||
|
||||
void Device::draw_primitives(GPU::PrimitiveType primitive_type, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform,
|
||||
FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
|
||||
FloatMatrix4x4 const& texture_transform, Vector<GPU::Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
|
||||
{
|
||||
// At this point, the user has effectively specified that they are done with defining the geometry
|
||||
// of what they want to draw. We now need to do a few things (https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview):
|
||||
|
@ -954,7 +954,7 @@ void Device::draw_primitives(GPU::PrimitiveType primitive_type, FloatMatrix4x4 c
|
|||
}
|
||||
|
||||
// Apply texture transformation
|
||||
for (size_t i = 0; i < NUM_SAMPLERS; ++i) {
|
||||
for (size_t i = 0; i < GPU::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];
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <LibGPU/SamplerConfig.h>
|
||||
#include <LibGPU/StencilConfiguration.h>
|
||||
#include <LibGPU/TexCoordGenerationConfig.h>
|
||||
#include <LibGPU/Vertex.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Matrix3x3.h>
|
||||
#include <LibGfx/Matrix4x4.h>
|
||||
|
@ -34,7 +35,6 @@
|
|||
#include <LibSoftGPU/Image.h>
|
||||
#include <LibSoftGPU/Sampler.h>
|
||||
#include <LibSoftGPU/Triangle.h>
|
||||
#include <LibSoftGPU/Vertex.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
|
||||
|
@ -71,8 +71,8 @@ struct RasterizerOptions {
|
|||
GPU::WindingOrder front_face { GPU::WindingOrder::CounterClockwise };
|
||||
bool cull_back { true };
|
||||
bool cull_front { false };
|
||||
Array<u8, NUM_SAMPLERS> texcoord_generation_enabled_coordinates {};
|
||||
Array<Array<GPU::TexCoordGenerationConfig, 4>, NUM_SAMPLERS> texcoord_generation_config {};
|
||||
Array<u8, GPU::NUM_SAMPLERS> texcoord_generation_enabled_coordinates {};
|
||||
Array<Array<GPU::TexCoordGenerationConfig, 4>, GPU::NUM_SAMPLERS> texcoord_generation_config {};
|
||||
Gfx::IntRect viewport;
|
||||
bool lighting_enabled { false };
|
||||
bool color_material_enabled { false };
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
|
||||
GPU::DeviceInfo info() const;
|
||||
|
||||
void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
|
||||
void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<GPU::Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
|
||||
void resize(Gfx::IntSize const& min_size);
|
||||
void clear_color(FloatVector4 const&);
|
||||
void clear_depth(GPU::DepthType);
|
||||
|
@ -129,8 +129,8 @@ private:
|
|||
Clipper m_clipper;
|
||||
Vector<Triangle> m_triangle_list;
|
||||
Vector<Triangle> m_processed_triangles;
|
||||
Vector<Vertex> m_clipped_vertices;
|
||||
Array<Sampler, NUM_SAMPLERS> m_samplers;
|
||||
Vector<GPU::Vertex> m_clipped_vertices;
|
||||
Array<Sampler, GPU::NUM_SAMPLERS> m_samplers;
|
||||
Vector<size_t> m_enabled_texture_units;
|
||||
AlphaBlendFactors m_alpha_blend_factors;
|
||||
Array<GPU::Light, NUM_LIGHTS> m_lights;
|
||||
|
|
|
@ -19,7 +19,7 @@ struct PixelQuad final {
|
|||
Vector3<AK::SIMD::f32x4> barycentrics;
|
||||
AK::SIMD::f32x4 depth;
|
||||
Vector4<AK::SIMD::f32x4> vertex_color;
|
||||
Array<Vector4<AK::SIMD::f32x4>, NUM_SAMPLERS> texture_coordinates;
|
||||
Array<Vector4<AK::SIMD::f32x4>, GPU::NUM_SAMPLERS> texture_coordinates;
|
||||
Vector4<AK::SIMD::f32x4> out_color;
|
||||
AK::SIMD::f32x4 fog_depth;
|
||||
AK::SIMD::i32x4 mask;
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibSoftGPU/Vertex.h>
|
||||
#include <LibGPU/Vertex.h>
|
||||
|
||||
namespace SoftGPU {
|
||||
|
||||
struct Triangle {
|
||||
Vertex vertices[3];
|
||||
GPU::Vertex vertices[3];
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue