From 371d49c0f6d9927ac1a1729a63714a66eb4ea51e Mon Sep 17 00:00:00 2001 From: Jesse Buhagiar Date: Mon, 24 Jan 2022 18:20:46 +1100 Subject: LibGL: Implement `glMateriali{v}` --- Userland/Libraries/LibGL/GL/gl.h | 2 ++ Userland/Libraries/LibGL/GLContext.h | 1 + Userland/Libraries/LibGL/GLLights.cpp | 10 ++++++ Userland/Libraries/LibGL/SoftwareGLContext.cpp | 47 ++++++++++++++++++++++++++ Userland/Libraries/LibGL/SoftwareGLContext.h | 2 ++ 5 files changed, 62 insertions(+) (limited to 'Userland/Libraries/LibGL') diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 8cc867eeb0..ec4b83b0f7 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -631,6 +631,8 @@ GLAPI void glNormalPointer(GLenum type, GLsizei stride, void const* pointer); GLAPI void glRasterPos2i(GLint x, GLint y); GLAPI void glMaterialf(GLenum face, GLenum pname, GLfloat param); GLAPI void glMaterialfv(GLenum face, GLenum pname, GLfloat const* params); +GLAPI void glMateriali(GLenum face, GLenum pname, GLint param); +GLAPI void glMaterialiv(GLenum face, GLenum pname, GLint const* params); GLAPI void glLineWidth(GLfloat width); GLAPI void glPushAttrib(GLbitfield mask); GLAPI void glPopAttrib(); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index d56033f193..c8c3324cfb 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -119,6 +119,7 @@ public: virtual void gl_lightiv(GLenum light, GLenum pname, GLint const* params) = 0; virtual void gl_materialf(GLenum face, GLenum pname, GLfloat param) = 0; virtual void gl_materialfv(GLenum face, GLenum pname, GLfloat const* params) = 0; + virtual void gl_materialiv(GLenum face, GLenum pname, GLint const* params) = 0; virtual void gl_color_material(GLenum face, GLenum mode) = 0; virtual void gl_get_light(GLenum light, GLenum pname, void* params, GLenum type) = 0; virtual void gl_get_material(GLenum face, GLenum pname, void* params, GLenum type) = 0; diff --git a/Userland/Libraries/LibGL/GLLights.cpp b/Userland/Libraries/LibGL/GLLights.cpp index 5035a45f79..5a797dfd4b 100644 --- a/Userland/Libraries/LibGL/GLLights.cpp +++ b/Userland/Libraries/LibGL/GLLights.cpp @@ -81,6 +81,16 @@ void glMaterialfv(GLenum face, GLenum pname, GLfloat const* params) g_gl_context->gl_materialfv(face, pname, params); } +void glMateriali(GLenum face, GLenum pname, GLint param) +{ + g_gl_context->gl_materialf(face, pname, param); +} + +void glMaterialiv(GLenum face, GLenum pname, GLint const* params) +{ + g_gl_context->gl_materialiv(face, pname, params); +} + void glShadeModel(GLenum mode) { g_gl_context->gl_shade_model(mode); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 1147a7831d..c7d82b3c09 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -3549,6 +3549,53 @@ void SoftwareGLContext::gl_materialfv(GLenum face, GLenum pname, GLfloat const* m_light_state_is_dirty = true; } +void SoftwareGLContext::gl_materialiv(GLenum face, GLenum pname, GLint const* params) +{ + APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_materialiv, face, pname, params); + RETURN_WITH_ERROR_IF(!(face == GL_FRONT || face == GL_BACK || face == GL_FRONT_AND_BACK), GL_INVALID_ENUM); + RETURN_WITH_ERROR_IF(!(pname == GL_AMBIENT || pname == GL_DIFFUSE || pname == GL_SPECULAR || pname == GL_EMISSION || pname == GL_SHININESS || pname == GL_AMBIENT_AND_DIFFUSE), GL_INVALID_ENUM); + RETURN_WITH_ERROR_IF((pname == GL_SHININESS && *params > 128), GL_INVALID_VALUE); + + auto update_material = [](SoftGPU::Material& material, GLenum pname, GLint const* params) { + switch (pname) { + case GL_AMBIENT: + material.ambient = { static_cast(params[0]), static_cast(params[1]), static_cast(params[2]), static_cast(params[3]) }; + break; + case GL_DIFFUSE: + material.diffuse = { static_cast(params[0]), static_cast(params[1]), static_cast(params[2]), static_cast(params[3]) }; + break; + case GL_SPECULAR: + material.specular = { static_cast(params[0]), static_cast(params[1]), static_cast(params[2]), static_cast(params[3]) }; + break; + case GL_EMISSION: + material.emissive = { static_cast(params[0]), static_cast(params[1]), static_cast(params[2]), static_cast(params[3]) }; + break; + case GL_SHININESS: + material.shininess = static_cast(params[0]); + break; + case GL_AMBIENT_AND_DIFFUSE: + material.ambient = { static_cast(params[0]), static_cast(params[1]), static_cast(params[2]), static_cast(params[3]) }; + material.diffuse = { static_cast(params[0]), static_cast(params[1]), static_cast(params[2]), static_cast(params[3]) }; + break; + } + }; + + switch (face) { + case GL_FRONT: + update_material(m_material_states[Face::Front], pname, params); + break; + case GL_BACK: + update_material(m_material_states[Face::Back], pname, params); + break; + case GL_FRONT_AND_BACK: + update_material(m_material_states[Face::Front], pname, params); + update_material(m_material_states[Face::Back], pname, params); + break; + } + + m_light_state_is_dirty = true; +} + void SoftwareGLContext::gl_color_material(GLenum face, GLenum mode) { APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_color_material, face, mode); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 0f58554d9a..ae7bc6981e 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -150,6 +150,7 @@ public: virtual void gl_lightiv(GLenum light, GLenum pname, GLint const* params) override; virtual void gl_materialf(GLenum face, GLenum pname, GLfloat param) override; virtual void gl_materialfv(GLenum face, GLenum pname, GLfloat const* params) override; + virtual void gl_materialiv(GLenum face, GLenum pname, GLint const* params) override; virtual void gl_color_material(GLenum face, GLenum mode) override; virtual void gl_get_light(GLenum light, GLenum pname, void* params, GLenum type) override; virtual void gl_get_material(GLenum face, GLenum pname, void* params, GLenum type) override; @@ -378,6 +379,7 @@ private: decltype(&SoftwareGLContext::gl_lightiv), decltype(&SoftwareGLContext::gl_materialf), decltype(&SoftwareGLContext::gl_materialfv), + decltype(&SoftwareGLContext::gl_materialiv), decltype(&SoftwareGLContext::gl_color_material), decltype(&SoftwareGLContext::gl_get_light)>; -- cgit v1.2.3