diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index e8da5471432..ce379532587 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -263,6 +263,9 @@ extern "C" { #define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 #define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 #define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA #define GL_FLAT 0x1D00 #define GL_SMOOTH 0x1D01 diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp index 44e81f7f471..09004eacb67 100644 --- a/Userland/Libraries/LibGL/GLContext.cpp +++ b/Userland/Libraries/LibGL/GLContext.cpp @@ -2724,36 +2724,38 @@ void GLContext::gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GL { APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_light_model, pname, x, y, z, w); - RETURN_WITH_ERROR_IF(pname != GL_LIGHT_MODEL_LOCAL_VIEWER - && pname != GL_LIGHT_MODEL_TWO_SIDE - && pname != GL_LIGHT_MODEL_AMBIENT, + RETURN_WITH_ERROR_IF(pname != GL_LIGHT_MODEL_AMBIENT + && pname != GL_LIGHT_MODEL_COLOR_CONTROL + && pname != GL_LIGHT_MODEL_LOCAL_VIEWER + && pname != GL_LIGHT_MODEL_TWO_SIDE, GL_INVALID_ENUM); auto lighting_params = m_rasterizer.light_model(); - bool update_lighting_model = false; switch (pname) { case GL_LIGHT_MODEL_AMBIENT: lighting_params.scene_ambient_color = { x, y, z, w }; - update_lighting_model = true; break; - case GL_LIGHT_MODEL_TWO_SIDE: - VERIFY(y == 0.0f && z == 0.0f && w == 0.0f); - lighting_params.two_sided_lighting = x; - update_lighting_model = true; + case GL_LIGHT_MODEL_COLOR_CONTROL: { + GLenum color_control = static_cast(x); + RETURN_WITH_ERROR_IF(color_control != GL_SINGLE_COLOR && color_control != GL_SEPARATE_SPECULAR_COLOR, GL_INVALID_ENUM); + lighting_params.color_control = (color_control == GL_SINGLE_COLOR) ? SoftGPU::ColorControl::SingleColor : SoftGPU::ColorControl::SeparateSpecularColor; break; + } case GL_LIGHT_MODEL_LOCAL_VIEWER: // 0 means the viewer is at infinity // 1 means they're in local (eye) space lighting_params.viewer_at_infinity = (x != 1.0f); - update_lighting_model = true; + break; + case GL_LIGHT_MODEL_TWO_SIDE: + VERIFY(y == 0.0f && z == 0.0f && w == 0.0f); + lighting_params.two_sided_lighting = x; break; default: VERIFY_NOT_REACHED(); } - if (update_lighting_model) - m_rasterizer.set_light_model_params(lighting_params); + m_rasterizer.set_light_model_params(lighting_params); } void GLContext::gl_bitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, GLubyte const* bitmap) diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 16e9bbb2e9d..669d18a30f7 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -813,7 +813,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& } // FIXME: The spec allows for splitting the colors calculated here into multiple different colors (primary/secondary color). Investigate what this means. - (void)m_lighting_model.single_color; + (void)m_lighting_model.color_control; // FIXME: Two sided lighting should be implemented eventually (I believe this is where the normals are -ve and then lighting is calculated with the BACK material) (void)m_lighting_model.two_sided_lighting; diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index ad1aa0b8c9b..af5e1cb0c55 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -83,7 +83,7 @@ struct RasterizerOptions { struct LightModelParameters { FloatVector4 scene_ambient_color { 0.2f, 0.2f, 0.2f, 1.0f }; bool viewer_at_infinity { false }; - unsigned int single_color { 0x81F9 }; // This is the value of `GL_SINGLE_COLOR`. Considering we definitely don't leak gl.h stuff into here, we fix it to the gl.h macro value. + ColorControl color_control { ColorControl::SingleColor }; bool two_sided_lighting { false }; }; diff --git a/Userland/Libraries/LibSoftGPU/Enums.h b/Userland/Libraries/LibSoftGPU/Enums.h index cde69a998ab..9f228b15e51 100644 --- a/Userland/Libraries/LibSoftGPU/Enums.h +++ b/Userland/Libraries/LibSoftGPU/Enums.h @@ -39,6 +39,11 @@ enum class BlendFactor { SrcAlphaSaturate, }; +enum class ColorControl { + SingleColor, + SeparateSpecularColor, +}; + enum class ColorMaterialFace { Front, Back,