From 192befa84bbe1885957ecd22bc6309f8b008bead Mon Sep 17 00:00:00 2001 From: Jesse Buhagiar Date: Fri, 7 Jan 2022 22:32:32 +1100 Subject: [PATCH] LibGL+LibSoftGPU: Add `GL_MAX_LIGHTS` to get_context_parameter This is required to allow lighting to work properly in the GL. We currently have the maximum number of lights in the software GL context set to 8, as this is the minimum that OpenGL mandates according to the spec. --- Userland/Libraries/LibGL/SoftwareGLContext.cpp | 2 ++ Userland/Libraries/LibGL/SoftwareGLContext.h | 1 + Userland/Libraries/LibSoftGPU/Config.h | 1 + Userland/Libraries/LibSoftGPU/Device.cpp | 3 ++- Userland/Libraries/LibSoftGPU/DeviceInfo.h | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 7f8f3452a8..53d68cf1dc 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -98,6 +98,8 @@ Optional SoftwareGLContext::get_context_parameter(GLenum name) return ContextParameter { .type = GL_INT, .value = { .integer_value = sizeof(float) * 8 } }; case GL_LIGHTING: return ContextParameter { .type = GL_BOOL, .is_capability = true, .value = { .boolean_value = m_lighting_enabled } }; + case GL_MAX_LIGHTS: + return ContextParameter { .type = GL_INT, .value = { .integer_value = static_cast(m_device_info.num_lights) } }; case GL_MAX_MODELVIEW_STACK_DEPTH: return ContextParameter { .type = GL_INT, .value = { .integer_value = MODELVIEW_MATRIX_STACK_LIMIT } }; case GL_MAX_PROJECTION_STACK_DEPTH: diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 7f153c617c..4248743b67 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Stephan Unverwerth + * Copyright (c) 2021-2022, Jesse Buhagiar * * SPDX-License-Identifier: BSD-2-Clause */ diff --git a/Userland/Libraries/LibSoftGPU/Config.h b/Userland/Libraries/LibSoftGPU/Config.h index c31f7a554a..e9b54f6d2a 100644 --- a/Userland/Libraries/LibSoftGPU/Config.h +++ b/Userland/Libraries/LibSoftGPU/Config.h @@ -17,6 +17,7 @@ namespace SoftGPU { static constexpr bool ENABLE_STATISTICS_OVERLAY = false; static constexpr int NUM_SAMPLERS = 32; static constexpr int SUBPIXEL_BITS = 5; +static constexpr int NUM_LIGHTS = 8; // See: https://www.khronos.org/opengl/wiki/Common_Mistakes#Texture_edge_color_problem // FIXME: make this dynamically configurable through ConfigServer diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 23d15ce1dd..741a3283d5 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -476,7 +476,8 @@ DeviceInfo Device::info() const return { .vendor_name = "SerenityOS", .device_name = "SoftGPU", - .num_texture_units = NUM_SAMPLERS + .num_texture_units = NUM_SAMPLERS, + .num_lights = NUM_LIGHTS }; } diff --git a/Userland/Libraries/LibSoftGPU/DeviceInfo.h b/Userland/Libraries/LibSoftGPU/DeviceInfo.h index 75e3051df2..41038aa2a7 100644 --- a/Userland/Libraries/LibSoftGPU/DeviceInfo.h +++ b/Userland/Libraries/LibSoftGPU/DeviceInfo.h @@ -14,6 +14,7 @@ struct DeviceInfo final { String vendor_name; String device_name; unsigned num_texture_units; + unsigned num_lights; }; }