diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index fd3b54cb361..85a98c717d2 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -317,7 +317,7 @@ if (BUILD_LAGOM) file(GLOB LIBGL_TEX_SCOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGL/Tex/*.cpp") lagom_lib(GL gl SOURCES ${LIBGL_SOURCES} ${LIBGL_TEX_SCOURCES} - LIBS m LagomGfx) + LIBS m LagomGfx LagomSoftGPU) # GUI-GML file(GLOB LIBGUI_GML_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGUI/GML*.cpp") @@ -394,6 +394,13 @@ if (BUILD_LAGOM) LIBS LagomLine LagomRegex ) + # SoftGPU + file(GLOB_RECURSE LIBSOFTGPU_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibSoftGPU/*.cpp") + lagom_lib(SoftGPU softgpu + SOURCES ${LIBSOFTGPU_SOURCES} + LIBS m LagomGfx + ) + # SQL file(GLOB_RECURSE LIBSQL_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibSQL/*.cpp") list(REMOVE_ITEM LIBSQL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibSQL/AST/SyntaxHighlighter.cpp") diff --git a/Userland/Libraries/CMakeLists.txt b/Userland/Libraries/CMakeLists.txt index ff35c42f146..d4b07ee80ef 100644 --- a/Userland/Libraries/CMakeLists.txt +++ b/Userland/Libraries/CMakeLists.txt @@ -38,6 +38,7 @@ add_subdirectory(LibProtocol) add_subdirectory(LibPthread) add_subdirectory(LibRegex) add_subdirectory(LibSanitizer) +add_subdirectory(LibSoftGPU) add_subdirectory(LibSQL) add_subdirectory(LibSymbolication) add_subdirectory(LibSyntax) diff --git a/Userland/Libraries/LibGL/CMakeLists.txt b/Userland/Libraries/LibGL/CMakeLists.txt index 5d402d5642a..9894558b101 100644 --- a/Userland/Libraries/LibGL/CMakeLists.txt +++ b/Userland/Libraries/LibGL/CMakeLists.txt @@ -1,9 +1,4 @@ set(SOURCES - Tex/NameAllocator.cpp - Tex/Sampler2D.cpp - Tex/Texture2D.cpp - Tex/TextureUnit.cpp - Clipper.cpp GLBlend.cpp GLColor.cpp GLContext.cpp @@ -18,9 +13,11 @@ set(SOURCES GLVert.cpp GLVertexArrays.cpp SoftwareGLContext.cpp - SoftwareRasterizer.cpp - DepthBuffer.cpp + Tex/NameAllocator.cpp + Tex/Sampler2D.cpp + Tex/Texture2D.cpp + Tex/TextureUnit.cpp ) serenity_lib(LibGL gl) -target_link_libraries(LibGL LibM LibCore LibGfx) +target_link_libraries(LibGL LibM LibCore LibGfx LibSoftGPU) diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 6ce37ad3654..876fad17834 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -5,9 +5,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "SoftwareGLContext.h" -#include "GLStruct.h" -#include "SoftwareRasterizer.h" #include #include #include @@ -15,9 +12,12 @@ #include #include #include +#include +#include #include #include #include +#include using AK::dbgln; diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index ab34b61d4c5..9e53812534c 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -6,23 +6,23 @@ #pragma once -#include "Clipper.h" -#include "GLContext.h" -#include "GLStruct.h" -#include "SoftwareRasterizer.h" -#include "Tex/NameAllocator.h" -#include "Tex/Texture.h" -#include "Tex/TextureUnit.h" #include #include #include #include #include #include +#include +#include +#include +#include +#include #include #include #include #include +#include +#include namespace GL { @@ -229,7 +229,7 @@ private: NonnullRefPtr m_frontbuffer; - Clipper m_clipper; + SoftGPU::Clipper m_clipper; // Texture objects TextureNameAllocator m_name_allocator; @@ -238,7 +238,7 @@ private: TextureUnit* m_active_texture_unit { &m_texture_units[0] }; TextureUnit::BoundList m_bound_texture_units; - SoftwareRasterizer m_rasterizer; + SoftGPU::SoftwareRasterizer m_rasterizer; struct Listing { diff --git a/Userland/Libraries/LibSoftGPU/CMakeLists.txt b/Userland/Libraries/LibSoftGPU/CMakeLists.txt new file mode 100644 index 00000000000..2fc4891e772 --- /dev/null +++ b/Userland/Libraries/LibSoftGPU/CMakeLists.txt @@ -0,0 +1,8 @@ +set(SOURCES + Clipper.cpp + DepthBuffer.cpp + SoftwareRasterizer.cpp +) + +serenity_lib(LibSoftGPU softgpu) +target_link_libraries(LibSoftGPU LibM LibCore LibGfx) diff --git a/Userland/Libraries/LibGL/Clipper.cpp b/Userland/Libraries/LibSoftGPU/Clipper.cpp similarity index 90% rename from Userland/Libraries/LibGL/Clipper.cpp rename to Userland/Libraries/LibSoftGPU/Clipper.cpp index a85e6233ba7..e32a0e73617 100644 --- a/Userland/Libraries/LibGL/Clipper.cpp +++ b/Userland/Libraries/LibSoftGPU/Clipper.cpp @@ -7,9 +7,9 @@ #include #include -#include +#include -namespace GL { +namespace SoftGPU { bool Clipper::point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane) { @@ -31,7 +31,7 @@ bool Clipper::point_within_clip_plane(const FloatVector4& vertex, ClipPlane plan return false; } -GLVertex Clipper::clip_intersection_point(const GLVertex& p1, const GLVertex& p2, ClipPlane plane_index) +GL::GLVertex Clipper::clip_intersection_point(const GL::GLVertex& p1, const GL::GLVertex& p2, ClipPlane plane_index) { // See https://www.microsoft.com/en-us/research/wp-content/uploads/1978/01/p245-blinn.pdf // "Clipping Using Homogeneous Coordinates" Blinn/Newell, 1978 @@ -42,14 +42,14 @@ GLVertex Clipper::clip_intersection_point(const GLVertex& p1, const GLVertex& p2 float x2 = clip_plane_normals[plane_index].dot(p2.position); float a = (w1 + x1) / ((w1 + x1) - (w2 + x2)); - GLVertex out; + GL::GLVertex out; out.position = p1.position * (1 - a) + p2.position * a; out.color = p1.color * (1 - a) + p2.color * a; out.tex_coord = p1.tex_coord * (1 - a) + p2.tex_coord * a; return out; } -void Clipper::clip_triangle_against_frustum(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/LibGL/Clipper.h b/Userland/Libraries/LibSoftGPU/Clipper.h similarity index 80% rename from Userland/Libraries/LibGL/Clipper.h rename to Userland/Libraries/LibSoftGPU/Clipper.h index 36452a6e214..4be38b963f2 100644 --- a/Userland/Libraries/LibGL/Clipper.h +++ b/Userland/Libraries/LibSoftGPU/Clipper.h @@ -10,7 +10,7 @@ #include #include -namespace GL { +namespace SoftGPU { class Clipper final { enum ClipPlane : u8 { @@ -46,13 +46,13 @@ class Clipper final { public: Clipper() { } - void clip_triangle_against_frustum(Vector& input_vecs); + void clip_triangle_against_frustum(Vector& input_vecs); private: bool point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane); - GLVertex clip_intersection_point(const GLVertex& vec, const GLVertex& prev_vec, ClipPlane plane_index); - Vector list_a; - Vector list_b; + GL::GLVertex clip_intersection_point(const GL::GLVertex& vec, const GL::GLVertex& prev_vec, ClipPlane plane_index); + Vector list_a; + Vector list_b; }; } diff --git a/Userland/Libraries/LibGL/DepthBuffer.cpp b/Userland/Libraries/LibSoftGPU/DepthBuffer.cpp similarity index 94% rename from Userland/Libraries/LibGL/DepthBuffer.cpp rename to Userland/Libraries/LibSoftGPU/DepthBuffer.cpp index a45812133fd..e2507545a94 100644 --- a/Userland/Libraries/LibGL/DepthBuffer.cpp +++ b/Userland/Libraries/LibSoftGPU/DepthBuffer.cpp @@ -4,9 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "DepthBuffer.h" +#include -namespace GL { +namespace SoftGPU { DepthBuffer::DepthBuffer(Gfx::IntSize const& size) : m_size(size) diff --git a/Userland/Libraries/LibGL/DepthBuffer.h b/Userland/Libraries/LibSoftGPU/DepthBuffer.h similarity index 95% rename from Userland/Libraries/LibGL/DepthBuffer.h rename to Userland/Libraries/LibSoftGPU/DepthBuffer.h index bdb6d4563bc..4fb6f078b5c 100644 --- a/Userland/Libraries/LibGL/DepthBuffer.h +++ b/Userland/Libraries/LibSoftGPU/DepthBuffer.h @@ -9,7 +9,7 @@ #include #include -namespace GL { +namespace SoftGPU { class DepthBuffer final { public: diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibSoftGPU/SoftwareRasterizer.cpp similarity index 99% rename from Userland/Libraries/LibGL/SoftwareRasterizer.cpp rename to Userland/Libraries/LibSoftGPU/SoftwareRasterizer.cpp index aa175786e97..2214a89b652 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp +++ b/Userland/Libraries/LibSoftGPU/SoftwareRasterizer.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "SoftwareRasterizer.h" #include #include #include #include +#include -namespace GL { +namespace SoftGPU { using IntVector2 = Gfx::Vector2; using IntVector3 = Gfx::Vector3; @@ -110,7 +110,7 @@ static constexpr void setup_blend_factors(GLenum mode, FloatVector4& constant, f } template -static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& render_target, DepthBuffer& depth_buffer, const GLTriangle& triangle, PS pixel_shader) +static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& render_target, DepthBuffer& depth_buffer, const GL::GLTriangle& triangle, PS pixel_shader) { // Since the algorithm is based on blocks of uniform size, we need // to ensure that our render_target size is actually a multiple of the block size @@ -494,7 +494,7 @@ SoftwareRasterizer::SoftwareRasterizer(const Gfx::IntSize& min_size) m_options.scissor_box = m_render_target->rect(); } -void SoftwareRasterizer::submit_triangle(GLTriangle const& triangle, TextureUnit::BoundList const& bound_texture_units) +void SoftwareRasterizer::submit_triangle(GL::GLTriangle const& triangle, GL::TextureUnit::BoundList const& bound_texture_units) { rasterize_triangle(m_options, *m_render_target, *m_depth_buffer, triangle, [this, &bound_texture_units](FloatVector4 const& uv, FloatVector4 const& color, float z) -> FloatVector4 { FloatVector4 fragment = color; diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibSoftGPU/SoftwareRasterizer.h similarity index 86% rename from Userland/Libraries/LibGL/SoftwareRasterizer.h rename to Userland/Libraries/LibSoftGPU/SoftwareRasterizer.h index 320e168c0bf..94efddd0f3e 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.h +++ b/Userland/Libraries/LibSoftGPU/SoftwareRasterizer.h @@ -6,18 +6,18 @@ #pragma once -#include "DepthBuffer.h" -#include "GL/gl.h" -#include "GLStruct.h" -#include "Tex/Texture2D.h" -#include "Tex/TextureUnit.h" #include #include +#include +#include +#include +#include #include #include #include +#include -namespace GL { +namespace SoftGPU { struct RasterizerOptions { bool shade_smooth { true }; @@ -56,7 +56,7 @@ class SoftwareRasterizer final { public: SoftwareRasterizer(const Gfx::IntSize& min_size); - void submit_triangle(GLTriangle const& triangle, TextureUnit::BoundList const& bound_texture_units); + void submit_triangle(GL::GLTriangle const& triangle, GL::TextureUnit::BoundList const& bound_texture_units); void resize(const Gfx::IntSize& min_size); void clear_color(const FloatVector4&); void clear_depth(float);