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 | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLLights.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 61 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.h | 6 |
5 files changed, 79 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 23be6f111d..0025649cf3 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -586,6 +586,8 @@ GLAPI void glGetBooleanv(GLenum pname, GLboolean* data); GLAPI void glGetDoublev(GLenum pname, GLdouble* params); 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 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 d4949d1123..3c15c1f360 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -119,7 +119,7 @@ public: 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_color_material(GLenum face, GLenum mode) = 0; - + virtual void gl_get_light(GLenum light, 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 06851f9d5e..a7472671c6 100644 --- a/Userland/Libraries/LibGL/GLLights.cpp +++ b/Userland/Libraries/LibGL/GLLights.cpp @@ -62,3 +62,13 @@ void glShadeModel(GLenum mode) { g_gl_context->gl_shade_model(mode); } + +void glGetLightfv(GLenum light, GLenum pname, GLfloat* params) +{ + g_gl_context->gl_get_light(light, pname, params, GL_FLOAT); +} + +void glGetLightiv(GLenum light, GLenum pname, GLint* params) +{ + g_gl_context->gl_get_light(light, pname, params, GL_INT); +} diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index a07ff21600..ec4aa6ed8a 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -3516,4 +3516,65 @@ void SoftwareGLContext::gl_color_material(GLenum face, GLenum mode) m_light_state_is_dirty = true; } +void SoftwareGLContext::gl_get_light(GLenum light, GLenum pname, void* params, GLenum type) +{ + APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_get_light, light, pname, params, type); + RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); + RETURN_WITH_ERROR_IF(light < GL_LIGHT0 || light > GL_LIGHT0 + m_device_info.num_lights, GL_INVALID_ENUM); + RETURN_WITH_ERROR_IF(!(pname == GL_AMBIENT || pname == GL_DIFFUSE || pname == GL_SPECULAR || pname == GL_SPOT_DIRECTION || pname == GL_SPOT_EXPONENT || pname == GL_SPOT_CUTOFF || pname == GL_CONSTANT_ATTENUATION || pname == GL_LINEAR_ATTENUATION || pname == GL_QUADRATIC_ATTENUATION), GL_INVALID_ENUM); + + if (type == GL_FLOAT) + get_light_param<GLfloat>(light, pname, static_cast<GLfloat*>(params)); + else if (type == GL_INT) + get_light_param<GLint>(light, pname, static_cast<GLint*>(params)); + else + VERIFY_NOT_REACHED(); +} + +template<typename T> +void SoftwareGLContext::get_light_param(GLenum light, GLenum pname, T* params) +{ + auto const& light_state = m_light_states[light - GL_LIGHT0]; + switch (pname) { + case GL_AMBIENT: + params[0] = light_state.ambient_intensity.x(); + params[1] = light_state.ambient_intensity.y(); + params[2] = light_state.ambient_intensity.z(); + params[3] = light_state.ambient_intensity.w(); + break; + case GL_DIFFUSE: + params[0] = light_state.diffuse_intensity.x(); + params[1] = light_state.diffuse_intensity.y(); + params[2] = light_state.diffuse_intensity.z(); + params[3] = light_state.diffuse_intensity.w(); + break; + case GL_SPECULAR: + params[0] = light_state.specular_intensity.x(); + params[1] = light_state.specular_intensity.y(); + params[2] = light_state.specular_intensity.z(); + params[3] = light_state.specular_intensity.w(); + break; + case GL_SPOT_DIRECTION: + params[0] = light_state.spotlight_direction.x(); + params[1] = light_state.spotlight_direction.y(); + params[2] = light_state.spotlight_direction.z(); + break; + case GL_SPOT_EXPONENT: + *params = light_state.spotlight_exponent; + break; + case GL_SPOT_CUTOFF: + *params = light_state.spotlight_cutoff_angle; + break; + case GL_CONSTANT_ATTENUATION: + *params = light_state.constant_attenuation; + break; + case GL_LINEAR_ATTENUATION: + *params = light_state.linear_attenuation; + break; + case GL_QUADRATIC_ATTENUATION: + *params = light_state.quadratic_attenuation; + break; + } +} + } diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index bd0b5fb579..a29acf3ab6 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -150,6 +150,7 @@ public: 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_color_material(GLenum face, GLenum mode) override; + virtual void gl_get_light(GLenum light, GLenum pname, void* params, GLenum type) override; virtual void present() override; private: @@ -181,6 +182,8 @@ private: template<typename T> void get_floating_point(GLenum pname, T* params); + template<typename T> + void get_light_param(GLenum light, 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(); } @@ -370,7 +373,8 @@ private: decltype(&SoftwareGLContext::gl_lightfv), decltype(&SoftwareGLContext::gl_materialf), decltype(&SoftwareGLContext::gl_materialfv), - decltype(&SoftwareGLContext::gl_color_material)>; + decltype(&SoftwareGLContext::gl_color_material), + decltype(&SoftwareGLContext::gl_get_light)>; using ExtraSavedArguments = Variant< FloatMatrix4x4>; |