LibGL: Support glLightModel inside lists

We now dereference the pointer given to us before adding the arguments
to an active list. This also factors out the switching logic from the
API wrappers, which helps us with a future commit where we autogenerate
all API wrapper functions.
This commit is contained in:
Jelle Raaijmakers 2022-12-09 16:25:15 +01:00 committed by Andreas Kling
parent 403c560a7a
commit a074b7e871
Notes: sideshowbarker 2024-07-17 05:05:51 +09:00
3 changed files with 30 additions and 19 deletions

View file

@ -568,36 +568,22 @@ void glLightiv(GLenum light, GLenum pname, GLint const* params)
void glLightModelf(GLenum pname, GLfloat param)
{
g_gl_context->gl_light_model(pname, param, 0.0f, 0.0f, 0.0f);
g_gl_context->gl_light_model(pname, param, 0.f, 0.f, 0.f);
}
void glLightModelfv(GLenum pname, GLfloat const* params)
{
switch (pname) {
case GL_LIGHT_MODEL_AMBIENT:
g_gl_context->gl_light_model(pname, params[0], params[1], params[2], params[3]);
break;
default:
g_gl_context->gl_light_model(pname, params[0], 0.0f, 0.0f, 0.0f);
break;
}
g_gl_context->gl_light_modelv(pname, params, GL_FLOAT);
}
void glLightModeliv(GLenum pname, GLint const* params)
{
switch (pname) {
case GL_LIGHT_MODEL_AMBIENT:
g_gl_context->gl_light_model(pname, params[0], params[1], params[2], params[3]);
break;
default:
g_gl_context->gl_light_model(pname, params[0], 0.0f, 0.0f, 0.0f);
break;
}
g_gl_context->gl_light_modelv(pname, params, GL_INT);
}
void glLightModeli(GLenum pname, GLint param)
{
g_gl_context->gl_light_model(pname, param, 0.0f, 0.0f, 0.0f);
g_gl_context->gl_light_model(pname, static_cast<float>(param), 0.f, 0.f, 0.f);
}
void glLineWidth(GLfloat width)

View file

@ -203,6 +203,7 @@ public:
void gl_push_attrib(GLbitfield mask);
void gl_pop_attrib();
void gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void gl_light_modelv(GLenum pname, void const* params, GLenum type);
void gl_bitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, GLubyte const* bitmap);
void gl_copy_tex_image_2d(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
void gl_get_tex_image(GLenum target, GLint level, GLenum format, GLenum type, void* pixels);

View file

@ -171,7 +171,7 @@ void GLContext::gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GL
lighting_params.scene_ambient_color = { x, y, z, w };
break;
case GL_LIGHT_MODEL_COLOR_CONTROL: {
GLenum color_control = static_cast<GLenum>(x);
auto color_control = static_cast<GLenum>(x);
RETURN_WITH_ERROR_IF(color_control != GL_SINGLE_COLOR && color_control != GL_SEPARATE_SPECULAR_COLOR, GL_INVALID_ENUM);
lighting_params.color_control = (color_control == GL_SINGLE_COLOR) ? GPU::ColorControl::SingleColor : GPU::ColorControl::SeparateSpecularColor;
break;
@ -191,6 +191,30 @@ void GLContext::gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GL
m_rasterizer->set_light_model_params(lighting_params);
}
void GLContext::gl_light_modelv(GLenum pname, void const* params, GLenum type)
{
auto invoke_implementation = [&](auto const* params) {
switch (pname) {
case GL_LIGHT_MODEL_AMBIENT:
gl_light_model(pname, params[0], params[1], params[2], params[3]);
return;
default:
gl_light_model(pname, params[0], 0.f, 0.f, 0.f);
return;
}
};
switch (type) {
case GL_FLOAT:
invoke_implementation(reinterpret_cast<GLfloat const*>(params));
break;
case GL_INT:
invoke_implementation(reinterpret_cast<GLint const*>(params));
break;
default:
VERIFY_NOT_REACHED();
}
}
void GLContext::gl_lightf(GLenum light, GLenum pname, GLfloat param)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_lightf, light, pname, param);