1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:37:35 +00:00

LibGL: Implement glLightf{v} and fix gl.h prototype

This implements the `glLightf{v}` family of functions used to set
lighting parameters per light in the GL. It also fixes an incorrect
prototype for the user exposed version of `glLightf{v}` in which
`params` was not marked as `const`.
This commit is contained in:
Jesse Buhagiar 2022-01-08 01:41:46 +11:00 committed by Linus Groh
parent 192befa84b
commit bf294612a7
8 changed files with 185 additions and 7 deletions

View file

@ -1004,4 +1004,9 @@ void Device::set_sampler_config(unsigned sampler, SamplerConfig const& config)
m_samplers[sampler].set_config(config);
}
void Device::set_light_state(unsigned int light_id, Light const& light)
{
m_lights.at(light_id) = light;
}
}

View file

@ -22,6 +22,7 @@
#include <LibSoftGPU/Enums.h>
#include <LibSoftGPU/Image.h>
#include <LibSoftGPU/ImageFormat.h>
#include <LibSoftGPU/Light/Light.h>
#include <LibSoftGPU/Sampler.h>
#include <LibSoftGPU/Triangle.h>
#include <LibSoftGPU/Vertex.h>
@ -92,6 +93,7 @@ public:
NonnullRefPtr<Image> create_image(ImageFormat, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers);
void set_sampler_config(unsigned, SamplerConfig const&);
void set_light_state(unsigned, Light const&);
private:
void draw_statistics_overlay(Gfx::Bitmap&);
@ -112,6 +114,7 @@ private:
Array<Sampler, NUM_SAMPLERS> m_samplers;
Vector<size_t> m_enabled_texture_units;
AlphaBlendFactors m_alpha_blend_factors;
Array<Light, NUM_LIGHTS> m_lights;
};
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2022, Jesse Buhagiar <jooster669@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/Vector3.h>
#include <LibGfx/Vector4.h>
namespace SoftGPU {
struct Light {
bool is_enabled { false };
// According to the OpenGL 1.5 specification, page 56, all of the parameters
// for the following data members (positions, colors, and reals) are all
// floating point.
Vector4<float> ambient_intensity { 0.0f, 0.0f, 0.0f, 1.0f };
Vector4<float> diffuse_intensity { 0.0f, 0.0f, 0.0f, 1.0f };
Vector4<float> specular_intensity { 0.0f, 0.0f, 0.0f, 1.0f };
Vector4<float> position { 0.0f, 0.0f, 1.0f, 0.0f };
Vector3<float> spotlight_direction { 0.0f, 0.0f, -1.0f };
float spotlight_exponent { 0.0f };
float spotlight_cutoff_angle { 180.0f };
float constant_attenuation { 1.0f }; // This is referred to `k0i` in the OpenGL spec
float linear_attenuation { 0.0f }; // This is referred to `k1i` in the OpenGL spec
float quadratic_attenuation { 0.0f }; // This is referred to `k2i` in the OpenGL spec
float spotlight_cutoff_angle_rads { AK::Pi<float> / 180.0f };
};
}