diff options
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLLights.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 60 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.h | 3 |
5 files changed, 76 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 0025649cf3..2c15a30ffe 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -588,6 +588,8 @@ GLAPI void glGetFloatv(GLenum pname, GLfloat* params); GLAPI void glGetIntegerv(GLenum pname, GLint* data); GLAPI void glGetLightfv(GLenum light, GLenum pname, GLfloat* params); GLAPI void glGetLightiv(GLenum light, GLenum pname, GLint* params); +GLAPI void glGetMaterialfv(GLenum face, GLenum pname, GLfloat* params); +GLAPI void glGetMaterialiv(GLenum face, GLenum pname, GLint* params); GLAPI void glDepthMask(GLboolean flag); GLAPI void glEnableClientState(GLenum cap); GLAPI void glDisableClientState(GLenum cap); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 3c15c1f360..e14df5adbd 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -120,6 +120,7 @@ public: virtual void gl_materialfv(GLenum face, GLenum pname, GLfloat 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; virtual void present() = 0; }; diff --git a/Userland/Libraries/LibGL/GLLights.cpp b/Userland/Libraries/LibGL/GLLights.cpp index a7472671c6..78b9050019 100644 --- a/Userland/Libraries/LibGL/GLLights.cpp +++ b/Userland/Libraries/LibGL/GLLights.cpp @@ -72,3 +72,13 @@ void glGetLightiv(GLenum light, GLenum pname, GLint* params) { g_gl_context->gl_get_light(light, pname, params, GL_INT); } + +void glGetMaterialfv(GLenum face, GLenum pname, GLfloat* params) +{ + g_gl_context->gl_get_material(face, pname, params, GL_FLOAT); +} + +void glGetMaterialiv(GLenum face, GLenum pname, GLint* params) +{ + g_gl_context->gl_get_material(face, pname, params, GL_INT); +} diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index ec4aa6ed8a..4f73aba1f4 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -3577,4 +3577,64 @@ void SoftwareGLContext::get_light_param(GLenum light, GLenum pname, T* params) } } +void SoftwareGLContext::gl_get_material(GLenum face, GLenum pname, void* params, GLenum type) +{ + APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_get_material, face, pname, params, type); + RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); + RETURN_WITH_ERROR_IF(!(pname == GL_AMBIENT || pname == GL_DIFFUSE || pname == GL_SPECULAR || pname == GL_EMISSION), GL_INVALID_ENUM); + RETURN_WITH_ERROR_IF(!(face == GL_FRONT || face == GL_BACK), GL_INVALID_ENUM); + + Face material_face = Front; + switch (face) { + case GL_FRONT: + material_face = Front; + break; + case GL_BACK: + material_face = Back; + break; + } + + if (type == GL_FLOAT) + get_material_param<GLfloat>(material_face, pname, static_cast<GLfloat*>(params)); + else if (type == GL_INT) + get_material_param<GLint>(material_face, pname, static_cast<GLint*>(params)); + else + VERIFY_NOT_REACHED(); +} + +template<typename T> +void SoftwareGLContext::get_material_param(Face face, GLenum pname, T* params) +{ + auto const& material = m_material_states[face]; + switch (pname) { + case GL_AMBIENT: + params[0] = static_cast<T>(material.ambient.x()); + params[1] = static_cast<T>(material.ambient.y()); + params[2] = static_cast<T>(material.ambient.z()); + params[3] = static_cast<T>(material.ambient.w()); + break; + case GL_DIFFUSE: + params[0] = static_cast<T>(material.diffuse.x()); + params[1] = static_cast<T>(material.diffuse.y()); + params[2] = static_cast<T>(material.diffuse.z()); + params[3] = static_cast<T>(material.diffuse.w()); + break; + case GL_SPECULAR: + params[0] = static_cast<T>(material.specular.x()); + params[1] = static_cast<T>(material.specular.y()); + params[2] = static_cast<T>(material.specular.z()); + params[3] = static_cast<T>(material.specular.w()); + break; + case GL_EMISSION: + params[0] = static_cast<T>(material.emissive.x()); + params[1] = static_cast<T>(material.emissive.y()); + params[2] = static_cast<T>(material.emissive.z()); + params[3] = static_cast<T>(material.emissive.w()); + break; + case GL_SHININESS: + *params = material.shininess; + break; + } +} + } diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index a29acf3ab6..00ecdd1941 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -151,6 +151,7 @@ public: virtual void gl_materialfv(GLenum face, GLenum pname, GLfloat 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; virtual void present() override; private: @@ -184,6 +185,8 @@ private: void get_floating_point(GLenum pname, T* params); template<typename T> void get_light_param(GLenum light, GLenum pname, T* params); + template<typename T> + void get_material_param(Face face, GLenum pname, T* params); void invoke_list(size_t list_index); [[nodiscard]] bool should_append_to_listing() const { return m_current_listing_index.has_value(); } |