diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-03-27 15:43:51 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-06 11:32:24 +0200 |
commit | 5d2740217fbc0f62f46480f85c142a340580f679 (patch) | |
tree | 564b274a5fd7ce246e51d4cb0e0efe8c648f3665 | |
parent | 5bf224708ff7ef0166153ef0f94ec15f4e95f232 (diff) | |
download | serenity-5d2740217fbc0f62f46480f85c142a340580f679.zip |
LibGL+LibGPU+LibSoftGPU: Move Vertex.h to LibGPU
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGPU/Config.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGPU/Vertex.h (renamed from Userland/Libraries/LibSoftGPU/Vertex.h) | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Clipper.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Clipper.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Config.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.h | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/PixelQuad.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Triangle.h | 4 |
11 files changed, 37 insertions, 34 deletions
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<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(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 <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; 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 index 323d6b95dc..5307dd083c 100644 --- a/Userland/Libraries/LibSoftGPU/Vertex.h +++ b/Userland/Libraries/LibGPU/Vertex.h @@ -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; }; 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 <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(); 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 <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; }; } 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<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]; 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 <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; 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<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; 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 <LibSoftGPU/Vertex.h> +#include <LibGPU/Vertex.h> namespace SoftGPU { struct Triangle { - Vertex vertices[3]; + GPU::Vertex vertices[3]; }; } |