summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorJesse Buhagiar <jooster669@gmail.com>2022-01-24 18:15:40 +1100
committerAndreas Kling <kling@serenityos.org>2022-01-26 16:44:11 +0100
commit170739fe3905ed40603bd08af436fa31ef56cdbc (patch)
tree4ea1b7f2895a704b7a8c6750111827d80d5ae8a3 /Userland/Libraries
parentf885e01875532e5647f547a9e9ec82d7f5bd2920 (diff)
downloadserenity-170739fe3905ed40603bd08af436fa31ef56cdbc.zip
LibGL: Implement `glLighti{v}`
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h4
-rw-r--r--Userland/Libraries/LibGL/GLContext.h1
-rw-r--r--Userland/Libraries/LibGL/GLLights.cpp10
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp55
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h2
5 files changed, 71 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index a178b88f78..8cc867eeb0 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -612,7 +612,9 @@ GLAPI void glFogi(GLenum pname, GLint param);
GLAPI void glPixelStorei(GLenum pname, GLint param);
GLAPI void glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
GLAPI void glLightf(GLenum light, GLenum pname, GLfloat param);
-GLAPI void glLightfv(GLenum light, GLenum pname, GLfloat const* param);
+GLAPI void glLightfv(GLenum light, GLenum pname, GLfloat const* params);
+GLAPI void glLighti(GLenum light, GLenum pname, GLint param);
+GLAPI void glLightiv(GLenum light, GLenum pname, GLint const* params);
GLAPI void glLightModelf(GLenum pname, GLfloat param);
GLAPI void glLightModelfv(GLenum pname, GLfloat const* params);
GLAPI void glLightModeli(GLenum pname, GLint param);
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index e14df5adbd..d56033f193 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -116,6 +116,7 @@ public:
virtual void gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat const* params) = 0;
virtual void gl_lightf(GLenum light, GLenum pname, GLfloat param) = 0;
virtual void gl_lightfv(GLenum light, GLenum pname, GLfloat const* params) = 0;
+ 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_color_material(GLenum face, GLenum mode) = 0;
diff --git a/Userland/Libraries/LibGL/GLLights.cpp b/Userland/Libraries/LibGL/GLLights.cpp
index 2f161182c5..5035a45f79 100644
--- a/Userland/Libraries/LibGL/GLLights.cpp
+++ b/Userland/Libraries/LibGL/GLLights.cpp
@@ -27,6 +27,16 @@ void glLightfv(GLenum light, GLenum pname, GLfloat const* param)
g_gl_context->gl_lightfv(light, pname, param);
}
+void glLighti(GLenum light, GLenum pname, GLint param)
+{
+ g_gl_context->gl_lightf(light, pname, param);
+}
+
+void glLightiv(GLenum light, GLenum pname, GLint const* params)
+{
+ g_gl_context->gl_lightiv(light, pname, params);
+}
+
void glLightModelf(GLenum pname, GLfloat param)
{
g_gl_context->gl_light_model(pname, param, 0.0f, 0.0f, 0.0f);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 4f73aba1f4..1147a7831d 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -3422,6 +3422,61 @@ void SoftwareGLContext::gl_lightfv(GLenum light, GLenum pname, GLfloat const* pa
m_light_state_is_dirty = true;
}
+void SoftwareGLContext::gl_lightiv(GLenum light, GLenum pname, GLint const* params)
+{
+ APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_lightiv, light, pname, params);
+ 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_POSITION || pname == GL_CONSTANT_ATTENUATION || pname == GL_LINEAR_ATTENUATION || pname == GL_QUADRATIC_ATTENUATION || pname == GL_SPOT_CUTOFF || pname == GL_SPOT_EXPONENT || pname == GL_SPOT_DIRECTION), GL_INVALID_ENUM);
+
+ auto& light_state = m_light_states[light - GL_LIGHT0];
+
+ auto const to_float_vector = [](GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
+ return FloatVector4(x, y, z, w);
+ };
+
+ switch (pname) {
+ case GL_AMBIENT:
+ light_state.ambient_intensity = to_float_vector(params[0], params[1], params[2], params[3]);
+ break;
+ case GL_DIFFUSE:
+ light_state.diffuse_intensity = to_float_vector(params[0], params[1], params[2], params[3]);
+ break;
+ case GL_SPECULAR:
+ light_state.specular_intensity = to_float_vector(params[0], params[1], params[2], params[3]);
+ break;
+ case GL_POSITION:
+ light_state.position = to_float_vector(params[0], params[1], params[2], params[3]);
+ light_state.position = m_model_view_matrix * light_state.position;
+ break;
+ case GL_CONSTANT_ATTENUATION:
+ light_state.constant_attenuation = static_cast<float>(params[0]);
+ break;
+ case GL_LINEAR_ATTENUATION:
+ light_state.linear_attenuation = static_cast<float>(params[0]);
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ light_state.quadratic_attenuation = static_cast<float>(params[0]);
+ break;
+ case GL_SPOT_EXPONENT:
+ light_state.spotlight_exponent = static_cast<float>(params[0]);
+ break;
+ case GL_SPOT_CUTOFF:
+ light_state.spotlight_cutoff_angle = static_cast<float>(params[0]);
+ break;
+ case GL_SPOT_DIRECTION: {
+ FloatVector4 direction_vector = to_float_vector(params[0], params[1], params[2], 0.0f);
+ direction_vector = m_model_view_matrix * direction_vector;
+ light_state.spotlight_direction = direction_vector.xyz();
+ break;
+ }
+ default:
+ VERIFY_NOT_REACHED();
+ }
+
+ m_light_state_is_dirty = true;
+}
+
void SoftwareGLContext::gl_materialf(GLenum face, GLenum pname, GLfloat param)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_materialf, face, pname, param);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index 00ecdd1941..0f58554d9a 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -147,6 +147,7 @@ public:
virtual void gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat const* params) override;
virtual void gl_lightf(GLenum light, GLenum pname, GLfloat param) override;
virtual void gl_lightfv(GLenum light, GLenum pname, GLfloat const* params) override;
+ 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_color_material(GLenum face, GLenum mode) override;
@@ -374,6 +375,7 @@ private:
decltype(&SoftwareGLContext::gl_fogi),
decltype(&SoftwareGLContext::gl_lightf),
decltype(&SoftwareGLContext::gl_lightfv),
+ decltype(&SoftwareGLContext::gl_lightiv),
decltype(&SoftwareGLContext::gl_materialf),
decltype(&SoftwareGLContext::gl_materialfv),
decltype(&SoftwareGLContext::gl_color_material),