mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:37:34 +00:00
LibGL: Implement glLightModel
integer normalization
For the ambient light model, integers need to be remapped to a range of `-1.` through `1.`. Add the `+` and `-` operators to `VectorN` to make it a bit easier to normalize 4 values at once.
This commit is contained in:
parent
a074b7e871
commit
8c094699db
2 changed files with 36 additions and 19 deletions
|
@ -193,26 +193,23 @@ void GLContext::gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GL
|
||||||
|
|
||||||
void GLContext::gl_light_modelv(GLenum pname, void const* params, GLenum type)
|
void GLContext::gl_light_modelv(GLenum pname, void const* params, GLenum type)
|
||||||
{
|
{
|
||||||
auto invoke_implementation = [&](auto const* params) {
|
VERIFY(type == GL_FLOAT || type == GL_INT);
|
||||||
switch (pname) {
|
|
||||||
case GL_LIGHT_MODEL_AMBIENT:
|
auto parameters_to_vector = [&]<typename T>(T const* params) -> FloatVector4 {
|
||||||
gl_light_model(pname, params[0], params[1], params[2], params[3]);
|
return (pname == GL_LIGHT_MODEL_AMBIENT)
|
||||||
return;
|
? Vector4<T> { params[0], params[1], params[2], params[3] }.template to_type<float>()
|
||||||
default:
|
: Vector4<T> { params[0], 0, 0, 0 }.template to_type<float>();
|
||||||
gl_light_model(pname, params[0], 0.f, 0.f, 0.f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
switch (type) {
|
|
||||||
case GL_FLOAT:
|
auto light_model_parameters = (type == GL_FLOAT)
|
||||||
invoke_implementation(reinterpret_cast<GLfloat const*>(params));
|
? parameters_to_vector(reinterpret_cast<GLfloat const*>(params))
|
||||||
break;
|
: parameters_to_vector(reinterpret_cast<GLint const*>(params));
|
||||||
case GL_INT:
|
|
||||||
invoke_implementation(reinterpret_cast<GLint const*>(params));
|
// Normalize integers to -1..1
|
||||||
break;
|
if (pname == GL_LIGHT_MODEL_AMBIENT && type == GL_INT)
|
||||||
default:
|
light_model_parameters = (light_model_parameters + 2147483648.f) / 2147483647.5f - 1.f;
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
gl_light_model(pname, light_model_parameters[0], light_model_parameters[1], light_model_parameters[2], light_model_parameters[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext::gl_lightf(GLenum light, GLenum pname, GLfloat param)
|
void GLContext::gl_lightf(GLenum light, GLenum pname, GLfloat param)
|
||||||
|
|
|
@ -158,6 +158,26 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
[[nodiscard]] constexpr VectorN operator+(U f) const
|
||||||
|
{
|
||||||
|
VectorN result;
|
||||||
|
UNROLL_LOOP
|
||||||
|
for (auto i = 0u; i < N; ++i)
|
||||||
|
result.m_data[i] = m_data[i] + f;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
[[nodiscard]] constexpr VectorN operator-(U f) const
|
||||||
|
{
|
||||||
|
VectorN result;
|
||||||
|
UNROLL_LOOP
|
||||||
|
for (auto i = 0u; i < N; ++i)
|
||||||
|
result.m_data[i] = m_data[i] - f;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
[[nodiscard]] constexpr VectorN operator*(U f) const
|
[[nodiscard]] constexpr VectorN operator*(U f) const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue