summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGL
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-12-01 16:10:17 +0100
committerAndreas Kling <kling@serenityos.org>2021-12-12 21:51:08 +0100
commit9dbc8d7e3ca134f81f348cf898b32496e30afaf8 (patch)
tree7f3b5d88c716176a09f8e47389a3528b66f43977 /Userland/Libraries/LibGL
parent4eb6295a57a99aec5323f6dbb0402e60442e0dd5 (diff)
downloadserenity-9dbc8d7e3ca134f81f348cf898b32496e30afaf8.zip
LibGL: Add stubs for `glMaterialf` and `glMaterialfv`
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h9
-rw-r--r--Userland/Libraries/LibGL/GLContext.h1
-rw-r--r--Userland/Libraries/LibGL/GLLights.cpp12
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp41
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h4
5 files changed, 66 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index b7325b9aee..20d9d183d5 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -170,6 +170,13 @@ extern "C" {
// Lighting related defines
#define GL_FLAT 0x1D00
#define GL_SMOOTH 0x1D01
+#define GL_AMBIENT 0x1200
+#define GL_DIFFUSE 0x1201
+#define GL_SPECULAR 0x1202
+#define GL_EMISSION 0x1600
+#define GL_SHININESS 0x1601
+#define GL_AMBIENT_AND_DIFFUSE 0x1602
+#define GL_COLOR_INDEXES 0x1603
// More blend factors
#define GL_CONSTANT_COLOR 0x8001
@@ -452,6 +459,8 @@ GLAPI void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum
GLAPI void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
GLAPI void glNormal3fv(GLfloat const* v);
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);
#ifdef __cplusplus
}
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index 576539e9c1..6ab2238c36 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -95,6 +95,7 @@ public:
virtual void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) = 0;
virtual void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz) = 0;
virtual void gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w) = 0;
+ virtual void gl_materialv(GLenum face, GLenum pname, GLfloat const* params) = 0;
virtual void present() = 0;
};
diff --git a/Userland/Libraries/LibGL/GLLights.cpp b/Userland/Libraries/LibGL/GLLights.cpp
index 6aa9c2ab0b..cdbcd16e26 100644
--- a/Userland/Libraries/LibGL/GLLights.cpp
+++ b/Userland/Libraries/LibGL/GLLights.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
+ * Copyright (c) 2021, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -22,6 +23,17 @@ void glLightfv(GLenum light, GLenum pname, GLfloat* param)
dbgln_if(GL_DEBUG, "glLightfv({}, {}, {}): unimplemented", light, pname, param);
}
+void glMaterialf(GLenum face, GLenum pname, GLfloat param)
+{
+ VERIFY(face == GL_SHININESS);
+ g_gl_context->gl_materialv(face, pname, &param);
+}
+
+void glMaterialfv(GLenum face, GLenum pname, GLfloat const* params)
+{
+ g_gl_context->gl_materialv(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 ebce348c6e..ed83822ce8 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -2257,6 +2257,47 @@ void SoftwareGLContext::gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w
m_current_raster_position.clip_coordinate_value = w;
}
+void SoftwareGLContext::gl_materialv(GLenum face, GLenum pname, GLfloat const* params)
+{
+ APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_materialv, 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
+ || pname == GL_COLOR_INDEXES),
+ GL_INVALID_ENUM);
+
+ GLfloat x, y, z, w;
+
+ switch (pname) {
+ case GL_SHININESS:
+ x = params[0];
+ y = 0.0f;
+ z = 0.0f;
+ w = 0.0f;
+ break;
+ case GL_COLOR_INDEXES:
+ x = params[0];
+ y = params[1];
+ z = params[2];
+ w = 0.0f;
+ break;
+ default:
+ x = params[0];
+ y = params[1];
+ z = params[2];
+ w = params[3];
+ }
+
+ // FIXME: implement this method
+ dbgln_if(GL_DEBUG, "SoftwareGLContext FIXME: gl_materialv({}, {}, {}, {}, {}, {})", face, pname, x, y, z, w);
+}
+
void SoftwareGLContext::present()
{
m_rasterizer.blit_to(*m_frontbuffer);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index a8869571e4..935ca0f76d 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -106,6 +106,7 @@ public:
virtual void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) override;
virtual void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz) override;
virtual void gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w) override;
+ virtual void gl_materialv(GLenum face, GLenum pname, GLfloat const* params) override;
virtual void present() override;
private:
@@ -271,7 +272,8 @@ private:
decltype(&SoftwareGLContext::gl_stencil_func_separate),
decltype(&SoftwareGLContext::gl_stencil_op_separate),
decltype(&SoftwareGLContext::gl_normal),
- decltype(&SoftwareGLContext::gl_raster_pos)>;
+ decltype(&SoftwareGLContext::gl_raster_pos),
+ decltype(&SoftwareGLContext::gl_materialv)>;
using ExtraSavedArguments = Variant<
FloatMatrix4x4>;