mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:57:34 +00:00
LibGL+LibSoftGPU: Move rendering related code to LibSoftGPU library
This introduces a new library, LibSoftGPU, that incorporates all rendering related features that formerly resided within LibGL itself. Going forward we will make both libraries completely independent from each other allowing LibGL to load different, possibly accelerated, rendering backends.
This commit is contained in:
parent
46b1c2d609
commit
ad3d5d43bd
12 changed files with 58 additions and 45 deletions
|
@ -317,7 +317,7 @@ if (BUILD_LAGOM)
|
||||||
file(GLOB LIBGL_TEX_SCOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGL/Tex/*.cpp")
|
file(GLOB LIBGL_TEX_SCOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGL/Tex/*.cpp")
|
||||||
lagom_lib(GL gl
|
lagom_lib(GL gl
|
||||||
SOURCES ${LIBGL_SOURCES} ${LIBGL_TEX_SCOURCES}
|
SOURCES ${LIBGL_SOURCES} ${LIBGL_TEX_SCOURCES}
|
||||||
LIBS m LagomGfx)
|
LIBS m LagomGfx LagomSoftGPU)
|
||||||
|
|
||||||
# GUI-GML
|
# GUI-GML
|
||||||
file(GLOB LIBGUI_GML_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGUI/GML*.cpp")
|
file(GLOB LIBGUI_GML_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGUI/GML*.cpp")
|
||||||
|
@ -394,6 +394,13 @@ if (BUILD_LAGOM)
|
||||||
LIBS LagomLine LagomRegex
|
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
|
# SQL
|
||||||
file(GLOB_RECURSE LIBSQL_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibSQL/*.cpp")
|
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")
|
list(REMOVE_ITEM LIBSQL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibSQL/AST/SyntaxHighlighter.cpp")
|
||||||
|
|
|
@ -38,6 +38,7 @@ add_subdirectory(LibProtocol)
|
||||||
add_subdirectory(LibPthread)
|
add_subdirectory(LibPthread)
|
||||||
add_subdirectory(LibRegex)
|
add_subdirectory(LibRegex)
|
||||||
add_subdirectory(LibSanitizer)
|
add_subdirectory(LibSanitizer)
|
||||||
|
add_subdirectory(LibSoftGPU)
|
||||||
add_subdirectory(LibSQL)
|
add_subdirectory(LibSQL)
|
||||||
add_subdirectory(LibSymbolication)
|
add_subdirectory(LibSymbolication)
|
||||||
add_subdirectory(LibSyntax)
|
add_subdirectory(LibSyntax)
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
Tex/NameAllocator.cpp
|
|
||||||
Tex/Sampler2D.cpp
|
|
||||||
Tex/Texture2D.cpp
|
|
||||||
Tex/TextureUnit.cpp
|
|
||||||
Clipper.cpp
|
|
||||||
GLBlend.cpp
|
GLBlend.cpp
|
||||||
GLColor.cpp
|
GLColor.cpp
|
||||||
GLContext.cpp
|
GLContext.cpp
|
||||||
|
@ -18,9 +13,11 @@ set(SOURCES
|
||||||
GLVert.cpp
|
GLVert.cpp
|
||||||
GLVertexArrays.cpp
|
GLVertexArrays.cpp
|
||||||
SoftwareGLContext.cpp
|
SoftwareGLContext.cpp
|
||||||
SoftwareRasterizer.cpp
|
Tex/NameAllocator.cpp
|
||||||
DepthBuffer.cpp
|
Tex/Sampler2D.cpp
|
||||||
|
Tex/Texture2D.cpp
|
||||||
|
Tex/TextureUnit.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibGL gl)
|
serenity_lib(LibGL gl)
|
||||||
target_link_libraries(LibGL LibM LibCore LibGfx)
|
target_link_libraries(LibGL LibM LibCore LibGfx LibSoftGPU)
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SoftwareGLContext.h"
|
|
||||||
#include "GLStruct.h"
|
|
||||||
#include "SoftwareRasterizer.h"
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
@ -15,9 +12,12 @@
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibGL/GLStruct.h>
|
||||||
|
#include <LibGL/SoftwareGLContext.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Painter.h>
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibGfx/Vector4.h>
|
#include <LibGfx/Vector4.h>
|
||||||
|
#include <LibSoftGPU/SoftwareRasterizer.h>
|
||||||
|
|
||||||
using AK::dbgln;
|
using AK::dbgln;
|
||||||
|
|
||||||
|
|
|
@ -6,23 +6,23 @@
|
||||||
|
|
||||||
#pragma once
|
#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 <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Tuple.h>
|
#include <AK/Tuple.h>
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibGL/GLContext.h>
|
||||||
|
#include <LibGL/GLStruct.h>
|
||||||
|
#include <LibGL/Tex/NameAllocator.h>
|
||||||
|
#include <LibGL/Tex/Texture.h>
|
||||||
|
#include <LibGL/Tex/TextureUnit.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Matrix4x4.h>
|
#include <LibGfx/Matrix4x4.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGfx/Vector3.h>
|
#include <LibGfx/Vector3.h>
|
||||||
|
#include <LibSoftGPU/Clipper.h>
|
||||||
|
#include <LibSoftGPU/SoftwareRasterizer.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace GL {
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ private:
|
||||||
|
|
||||||
NonnullRefPtr<Gfx::Bitmap> m_frontbuffer;
|
NonnullRefPtr<Gfx::Bitmap> m_frontbuffer;
|
||||||
|
|
||||||
Clipper m_clipper;
|
SoftGPU::Clipper m_clipper;
|
||||||
|
|
||||||
// Texture objects
|
// Texture objects
|
||||||
TextureNameAllocator m_name_allocator;
|
TextureNameAllocator m_name_allocator;
|
||||||
|
@ -238,7 +238,7 @@ private:
|
||||||
TextureUnit* m_active_texture_unit { &m_texture_units[0] };
|
TextureUnit* m_active_texture_unit { &m_texture_units[0] };
|
||||||
TextureUnit::BoundList m_bound_texture_units;
|
TextureUnit::BoundList m_bound_texture_units;
|
||||||
|
|
||||||
SoftwareRasterizer m_rasterizer;
|
SoftGPU::SoftwareRasterizer m_rasterizer;
|
||||||
|
|
||||||
struct Listing {
|
struct Listing {
|
||||||
|
|
||||||
|
|
8
Userland/Libraries/LibSoftGPU/CMakeLists.txt
Normal file
8
Userland/Libraries/LibSoftGPU/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
set(SOURCES
|
||||||
|
Clipper.cpp
|
||||||
|
DepthBuffer.cpp
|
||||||
|
SoftwareRasterizer.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
serenity_lib(LibSoftGPU softgpu)
|
||||||
|
target_link_libraries(LibSoftGPU LibM LibCore LibGfx)
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <LibGL/Clipper.h>
|
#include <LibSoftGPU/Clipper.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace SoftGPU {
|
||||||
|
|
||||||
bool Clipper::point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane)
|
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;
|
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
|
// See https://www.microsoft.com/en-us/research/wp-content/uploads/1978/01/p245-blinn.pdf
|
||||||
// "Clipping Using Homogeneous Coordinates" Blinn/Newell, 1978
|
// "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 x2 = clip_plane_normals[plane_index].dot(p2.position);
|
||||||
float a = (w1 + x1) / ((w1 + x1) - (w2 + x2));
|
float a = (w1 + x1) / ((w1 + x1) - (w2 + x2));
|
||||||
|
|
||||||
GLVertex out;
|
GL::GLVertex out;
|
||||||
out.position = p1.position * (1 - a) + p2.position * a;
|
out.position = p1.position * (1 - a) + p2.position * a;
|
||||||
out.color = p1.color * (1 - a) + p2.color * a;
|
out.color = p1.color * (1 - a) + p2.color * a;
|
||||||
out.tex_coord = p1.tex_coord * (1 - a) + p2.tex_coord * a;
|
out.tex_coord = p1.tex_coord * (1 - a) + p2.tex_coord * a;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clipper::clip_triangle_against_frustum(Vector<GLVertex>& input_verts)
|
void Clipper::clip_triangle_against_frustum(Vector<GL::GLVertex>& input_verts)
|
||||||
{
|
{
|
||||||
list_a = input_verts;
|
list_a = input_verts;
|
||||||
list_b.clear_with_capacity();
|
list_b.clear_with_capacity();
|
|
@ -10,7 +10,7 @@
|
||||||
#include <LibGL/GLStruct.h>
|
#include <LibGL/GLStruct.h>
|
||||||
#include <LibGfx/Vector4.h>
|
#include <LibGfx/Vector4.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace SoftGPU {
|
||||||
|
|
||||||
class Clipper final {
|
class Clipper final {
|
||||||
enum ClipPlane : u8 {
|
enum ClipPlane : u8 {
|
||||||
|
@ -46,13 +46,13 @@ class Clipper final {
|
||||||
public:
|
public:
|
||||||
Clipper() { }
|
Clipper() { }
|
||||||
|
|
||||||
void clip_triangle_against_frustum(Vector<GLVertex>& input_vecs);
|
void clip_triangle_against_frustum(Vector<GL::GLVertex>& input_vecs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane);
|
bool point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane);
|
||||||
GLVertex clip_intersection_point(const GLVertex& vec, const GLVertex& prev_vec, ClipPlane plane_index);
|
GL::GLVertex clip_intersection_point(const GL::GLVertex& vec, const GL::GLVertex& prev_vec, ClipPlane plane_index);
|
||||||
Vector<GLVertex> list_a;
|
Vector<GL::GLVertex> list_a;
|
||||||
Vector<GLVertex> list_b;
|
Vector<GL::GLVertex> list_b;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,9 +4,9 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DepthBuffer.h"
|
#include <LibSoftGPU/DepthBuffer.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace SoftGPU {
|
||||||
|
|
||||||
DepthBuffer::DepthBuffer(Gfx::IntSize const& size)
|
DepthBuffer::DepthBuffer(Gfx::IntSize const& size)
|
||||||
: m_size(size)
|
: m_size(size)
|
|
@ -9,7 +9,7 @@
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGfx/Size.h>
|
#include <LibGfx/Size.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace SoftGPU {
|
||||||
|
|
||||||
class DepthBuffer final {
|
class DepthBuffer final {
|
||||||
public:
|
public:
|
|
@ -4,13 +4,13 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SoftwareRasterizer.h"
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <LibGfx/Painter.h>
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibGfx/Vector2.h>
|
#include <LibGfx/Vector2.h>
|
||||||
#include <LibGfx/Vector3.h>
|
#include <LibGfx/Vector3.h>
|
||||||
|
#include <LibSoftGPU/SoftwareRasterizer.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace SoftGPU {
|
||||||
|
|
||||||
using IntVector2 = Gfx::Vector2<int>;
|
using IntVector2 = Gfx::Vector2<int>;
|
||||||
using IntVector3 = Gfx::Vector3<int>;
|
using IntVector3 = Gfx::Vector3<int>;
|
||||||
|
@ -110,7 +110,7 @@ static constexpr void setup_blend_factors(GLenum mode, FloatVector4& constant, f
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PS>
|
template<typename PS>
|
||||||
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
|
// 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
|
// 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();
|
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 {
|
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;
|
FloatVector4 fragment = color;
|
|
@ -6,18 +6,18 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "DepthBuffer.h"
|
|
||||||
#include "GL/gl.h"
|
|
||||||
#include "GLStruct.h"
|
|
||||||
#include "Tex/Texture2D.h"
|
|
||||||
#include "Tex/TextureUnit.h"
|
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
#include <LibGL/GL/gl.h>
|
||||||
|
#include <LibGL/GLStruct.h>
|
||||||
|
#include <LibGL/Tex/Texture2D.h>
|
||||||
|
#include <LibGL/Tex/TextureUnit.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGfx/Vector4.h>
|
#include <LibGfx/Vector4.h>
|
||||||
|
#include <LibSoftGPU/DepthBuffer.h>
|
||||||
|
|
||||||
namespace GL {
|
namespace SoftGPU {
|
||||||
|
|
||||||
struct RasterizerOptions {
|
struct RasterizerOptions {
|
||||||
bool shade_smooth { true };
|
bool shade_smooth { true };
|
||||||
|
@ -56,7 +56,7 @@ class SoftwareRasterizer final {
|
||||||
public:
|
public:
|
||||||
SoftwareRasterizer(const Gfx::IntSize& min_size);
|
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 resize(const Gfx::IntSize& min_size);
|
||||||
void clear_color(const FloatVector4&);
|
void clear_color(const FloatVector4&);
|
||||||
void clear_depth(float);
|
void clear_depth(float);
|
Loading…
Add table
Add a link
Reference in a new issue