diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp index 33142e86e9..0b9ab8d379 100644 --- a/Userland/Libraries/LibGL/GLContext.cpp +++ b/Userland/Libraries/LibGL/GLContext.cpp @@ -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(x), static_cast(y), static_cast(z), static_cast(w) }; vertex.color = m_current_vertex_color; diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 5ff2ef2c4c..957b02f497 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -19,13 +19,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include namespace GL { @@ -219,7 +219,7 @@ private: Vector m_current_vertex_tex_coord; FloatVector3 m_current_vertex_normal { 0.0f, 0.0f, 1.0f }; - Vector m_vertex_list; + Vector m_vertex_list; GLenum m_error = GL_NO_ERROR; bool m_in_draw_state = false; diff --git a/Userland/Libraries/LibGPU/Config.h b/Userland/Libraries/LibGPU/Config.h index e080a95e0b..4a61826025 100644 --- a/Userland/Libraries/LibGPU/Config.h +++ b/Userland/Libraries/LibGPU/Config.h @@ -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; + } diff --git a/Userland/Libraries/LibSoftGPU/Vertex.h b/Userland/Libraries/LibGPU/Vertex.h similarity index 82% rename from Userland/Libraries/LibSoftGPU/Vertex.h rename to Userland/Libraries/LibGPU/Vertex.h index 323d6b95dc..5307dd083c 100644 --- a/Userland/Libraries/LibSoftGPU/Vertex.h +++ b/Userland/Libraries/LibGPU/Vertex.h @@ -8,11 +8,11 @@ #pragma once #include +#include #include #include -#include -namespace SoftGPU { +namespace GPU { struct Vertex { FloatVector4 position; @@ -20,7 +20,7 @@ struct Vertex { FloatVector4 clip_coordinates; FloatVector4 window_coordinates; FloatVector4 color; - Array tex_coords; + Array tex_coords; FloatVector3 normal; }; diff --git a/Userland/Libraries/LibSoftGPU/Clipper.cpp b/Userland/Libraries/LibSoftGPU/Clipper.cpp index 51e021f37e..b4739d834b 100644 --- a/Userland/Libraries/LibSoftGPU/Clipper.cpp +++ b/Userland/Libraries/LibSoftGPU/Clipper.cpp @@ -7,9 +7,9 @@ */ #include +#include #include #include -#include namespace SoftGPU { @@ -33,7 +33,7 @@ static constexpr bool point_within_clip_plane(FloatVector4 const& vertex) } template -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 -FLATTEN static constexpr void clip_plane(Vector& read_list, Vector& write_list) +FLATTEN static constexpr void clip_plane(Vector& read_list, Vector& write_list) { auto read_from = &read_list; auto write_to = &write_list; @@ -89,7 +89,7 @@ FLATTEN static constexpr void clip_plane(Vector& read_list, Vector& input_verts) +void Clipper::clip_triangle_against_frustum(Vector& input_verts) { list_a = input_verts; list_b.clear_with_capacity(); diff --git a/Userland/Libraries/LibSoftGPU/Clipper.h b/Userland/Libraries/LibSoftGPU/Clipper.h index 14063d18a8..108626462c 100644 --- a/Userland/Libraries/LibSoftGPU/Clipper.h +++ b/Userland/Libraries/LibSoftGPU/Clipper.h @@ -8,8 +8,8 @@ #pragma once #include +#include #include -#include namespace SoftGPU { @@ -26,11 +26,11 @@ public: Clipper() = default; - void clip_triangle_against_frustum(Vector& input_vecs); + void clip_triangle_against_frustum(Vector& input_vecs); private: - Vector list_a; - Vector list_b; + Vector list_a; + Vector list_b; }; } diff --git a/Userland/Libraries/LibSoftGPU/Config.h b/Userland/Libraries/LibSoftGPU/Config.h index 7bcda1446b..2f164a8eef 100644 --- a/Userland/Libraries/LibSoftGPU/Config.h +++ b/Userland/Libraries/LibSoftGPU/Config.h @@ -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; diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index ebfdaa3210..fae9c4756d 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -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 const& vertices, Vector const& enabled_texture_units) + FloatMatrix4x4 const& texture_transform, Vector const& vertices, Vector 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]; diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index 356d3bb4b2..76870833e5 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -34,7 +35,6 @@ #include #include #include -#include namespace SoftGPU { @@ -71,8 +71,8 @@ struct RasterizerOptions { GPU::WindingOrder front_face { GPU::WindingOrder::CounterClockwise }; bool cull_back { true }; bool cull_front { false }; - Array texcoord_generation_enabled_coordinates {}; - Array, NUM_SAMPLERS> texcoord_generation_config {}; + Array texcoord_generation_enabled_coordinates {}; + Array, 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 const& vertices, Vector const& enabled_texture_units); + void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector const& vertices, Vector 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 m_triangle_list; Vector m_processed_triangles; - Vector m_clipped_vertices; - Array m_samplers; + Vector m_clipped_vertices; + Array m_samplers; Vector m_enabled_texture_units; AlphaBlendFactors m_alpha_blend_factors; Array m_lights; diff --git a/Userland/Libraries/LibSoftGPU/PixelQuad.h b/Userland/Libraries/LibSoftGPU/PixelQuad.h index 25ccea04bf..f8a5725960 100644 --- a/Userland/Libraries/LibSoftGPU/PixelQuad.h +++ b/Userland/Libraries/LibSoftGPU/PixelQuad.h @@ -19,7 +19,7 @@ struct PixelQuad final { Vector3 barycentrics; AK::SIMD::f32x4 depth; Vector4 vertex_color; - Array, NUM_SAMPLERS> texture_coordinates; + Array, GPU::NUM_SAMPLERS> texture_coordinates; Vector4 out_color; AK::SIMD::f32x4 fog_depth; AK::SIMD::i32x4 mask; diff --git a/Userland/Libraries/LibSoftGPU/Triangle.h b/Userland/Libraries/LibSoftGPU/Triangle.h index bf7a27e761..29cf3e037d 100644 --- a/Userland/Libraries/LibSoftGPU/Triangle.h +++ b/Userland/Libraries/LibSoftGPU/Triangle.h @@ -7,12 +7,12 @@ #pragma once -#include +#include namespace SoftGPU { struct Triangle { - Vertex vertices[3]; + GPU::Vertex vertices[3]; }; }