1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:47:34 +00:00

LibGL+Lib*GPU: Set model view and projection matrices separately

LibSoftGPU used to calculate the normal transformation based on the
model view transformation for every primitive, because that's when we
sent over the matrix. By making LibGL a bit smarter and only update the
matrices when they could have changed, we only need to calculate the
normal transformation once on every matrix update.

When viewing `Tuba.obj` in 3DFileViewer, this brings the percentage of
time spent in `FloatMatrix4x4::inverse()` down from 15% to 0%. :^)
This commit is contained in:
Jelle Raaijmakers 2023-10-05 22:01:35 +02:00
parent 126adfc392
commit edcb6176ce
8 changed files with 75 additions and 24 deletions

View file

@ -26,7 +26,7 @@ public:
virtual GPU::DeviceInfo info() const override;
virtual void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, Vector<GPU::Vertex>& vertices) override;
virtual void draw_primitives(GPU::PrimitiveType, Vector<GPU::Vertex>& vertices) override;
virtual void resize(Gfx::IntSize min_size) override;
virtual void clear_color(FloatVector4 const&) override;
virtual void clear_depth(GPU::DepthType) override;
@ -46,6 +46,8 @@ public:
virtual NonnullRefPtr<GPU::Image> create_image(GPU::PixelFormat const&, u32 width, u32 height, u32 depth, u32 max_levels) override;
virtual ErrorOr<NonnullRefPtr<GPU::Shader>> create_shader(GPU::IR::Shader const&) override;
virtual void set_model_view_transform(FloatMatrix4x4 const&) override;
virtual void set_projection_transform(FloatMatrix4x4 const&) override;
virtual void set_sampler_config(unsigned, GPU::SamplerConfig const&) override;
virtual void set_light_state(unsigned, GPU::Light const&) override;
virtual void set_material_state(GPU::Face, GPU::Material const&) override;
@ -55,7 +57,7 @@ public:
virtual GPU::RasterPosition raster_position() const override;
virtual void set_raster_position(GPU::RasterPosition const& raster_position) override;
virtual void set_raster_position(FloatVector4 const& position, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform) override;
virtual void set_raster_position(FloatVector4 const& position) override;
virtual void bind_fragment_shader(RefPtr<GPU::Shader>) override;
@ -67,6 +69,9 @@ private:
NonnullOwnPtr<Core::File> m_gpu_file;
FloatMatrix4x4 m_model_view_transform;
FloatMatrix4x4 m_projection_transform;
Protocol::ResourceID m_vbo_resource_id { 0 };
Protocol::ResourceID m_drawtarget { 0 };
Protocol::ResourceID m_depthbuffer_surface { 0 };