LibGL+LibSoftGPU: Move lighting model parameters to SoftGPU
Most of the T&L stuff is, like on an actual GPU, now done inside of LibSoftGPU. As such, it no longer makes sense to have specific values like the scene ambient color inside of LibGL as part of the GL context. These have now been moved into LibSoftGPU and use the same pattern as the render options to set/get.
This commit is contained in:
parent
92373ab0b6
commit
775ef000e0
Notes:
sideshowbarker
2024-07-17 21:06:34 +09:00
Author: https://github.com/Quaker762 Commit: https://github.com/SerenityOS/serenity/commit/775ef000e0c Pull-request: https://github.com/SerenityOS/serenity/pull/11764 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/sunverwerth ✅
4 changed files with 29 additions and 4 deletions
Userland/Libraries
|
@ -2684,17 +2684,25 @@ void SoftwareGLContext::gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLflo
|
|||
|| pname == GL_LIGHT_MODEL_TWO_SIDE),
|
||||
GL_INVALID_ENUM);
|
||||
|
||||
auto lighting_params = m_rasterizer.light_model();
|
||||
bool update_lighting_model = false;
|
||||
|
||||
switch (pname) {
|
||||
case GL_LIGHT_MODEL_AMBIENT:
|
||||
m_light_model_ambient = { x, y, z, w };
|
||||
lighting_params.scene_ambient_color = { x, y, z, w };
|
||||
update_lighting_model = true;
|
||||
break;
|
||||
case GL_LIGHT_MODEL_TWO_SIDE:
|
||||
VERIFY(y == 0.0f && z == 0.0f && w == 0.0f);
|
||||
m_light_model_two_side = x;
|
||||
lighting_params.two_sided_lighting = x;
|
||||
update_lighting_model = true;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (update_lighting_model)
|
||||
m_rasterizer.set_light_model_params(lighting_params);
|
||||
}
|
||||
|
||||
void SoftwareGLContext::gl_bitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, GLubyte const* bitmap)
|
||||
|
|
|
@ -430,8 +430,6 @@ private:
|
|||
|
||||
// Lighting configuration
|
||||
bool m_lighting_enabled { false };
|
||||
FloatVector4 m_light_model_ambient { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
GLfloat m_light_model_two_side { 0.0f };
|
||||
|
||||
Vector<SoftGPU::Light> m_light_states;
|
||||
Array<SoftGPU::Material, 2u> m_material_states;
|
||||
|
|
|
@ -970,6 +970,15 @@ void Device::set_options(const RasterizerOptions& options)
|
|||
// FIXME: Recreate or reinitialize render threads here when multithreading is being implemented
|
||||
}
|
||||
|
||||
void Device::set_light_model_params(const LightModelParameters& lighting_model)
|
||||
{
|
||||
wait_for_all_threads();
|
||||
|
||||
m_lighting_model = lighting_model;
|
||||
|
||||
// FIXME: Recreate or reinitialize render threads here when multithreading is being implemented
|
||||
}
|
||||
|
||||
Gfx::RGBA32 Device::get_backbuffer_pixel(int x, int y)
|
||||
{
|
||||
// FIXME: Reading individual pixels is very slow, rewrite this to transfer whole blocks
|
||||
|
|
|
@ -71,6 +71,13 @@ struct RasterizerOptions {
|
|||
Gfx::IntRect viewport;
|
||||
};
|
||||
|
||||
struct LightModelParameters {
|
||||
FloatVector4 scene_ambient_color { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
bool viewer_at_infinity { false };
|
||||
unsigned int single_color { 0x81F9 }; // This is the value of `GL_SINGLE_COLOR`. Considering we definitely don't leak gl.h stuff into here, we fix it to the gl.h macro value.
|
||||
bool two_sided_lighting { false };
|
||||
};
|
||||
|
||||
struct PixelQuad;
|
||||
|
||||
class Device final {
|
||||
|
@ -87,7 +94,9 @@ public:
|
|||
void blit_to(Gfx::Bitmap&);
|
||||
void wait_for_all_threads() const;
|
||||
void set_options(const RasterizerOptions&);
|
||||
void set_light_model_params(const LightModelParameters&);
|
||||
RasterizerOptions options() const { return m_options; }
|
||||
LightModelParameters light_model() const { return m_lighting_model; }
|
||||
Gfx::RGBA32 get_backbuffer_pixel(int x, int y);
|
||||
float get_depthbuffer_value(int x, int y);
|
||||
|
||||
|
@ -109,6 +118,7 @@ private:
|
|||
RefPtr<Gfx::Bitmap> m_render_target;
|
||||
OwnPtr<DepthBuffer> m_depth_buffer;
|
||||
RasterizerOptions m_options;
|
||||
LightModelParameters m_lighting_model;
|
||||
Clipper m_clipper;
|
||||
Vector<Triangle> m_triangle_list;
|
||||
Vector<Triangle> m_processed_triangles;
|
||||
|
|
Loading…
Add table
Reference in a new issue