1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

LibGL+LibSoftGPU: Add method to query device info

This adds a method `info()` to SoftGPU that returns the name of the
hardware vendor and device name, as well as the number of texture untis.

LibGL uses the returned texture unit count to initialize its internal
texture unit array.
This commit is contained in:
Stephan Unverwerth 2021-12-23 02:38:20 +01:00 committed by Brian Gianforcaro
parent 1a758d7bf2
commit 39995548e4
5 changed files with 40 additions and 7 deletions

View file

@ -58,7 +58,10 @@ static constexpr size_t TEXTURE_MATRIX_STACK_LIMIT = 8;
SoftwareGLContext::SoftwareGLContext(Gfx::Bitmap& frontbuffer)
: m_frontbuffer(frontbuffer)
, m_rasterizer(frontbuffer.size())
, m_device_info(m_rasterizer.info())
{
m_texture_units.resize(m_device_info.num_texture_units);
m_active_texture_unit = &m_texture_units[0];
}
Optional<ContextParameter> SoftwareGLContext::get_context_parameter(GLenum name)
@ -333,9 +336,9 @@ GLubyte* SoftwareGLContext::gl_get_string(GLenum name)
switch (name) {
case GL_VENDOR:
return reinterpret_cast<GLubyte*>(const_cast<char*>("The SerenityOS Developers"));
return reinterpret_cast<GLubyte*>(const_cast<char*>(m_device_info.vendor_name.characters()));
case GL_RENDERER:
return reinterpret_cast<GLubyte*>(const_cast<char*>("SerenityOS OpenGL"));
return reinterpret_cast<GLubyte*>(const_cast<char*>(m_device_info.device_name.characters()));
case GL_VERSION:
return reinterpret_cast<GLubyte*>(const_cast<char*>("1.5"));
case GL_EXTENSIONS:

View file

@ -233,10 +233,11 @@ private:
// Texture objects
TextureNameAllocator m_name_allocator;
HashMap<GLuint, RefPtr<Texture>> m_allocated_textures;
Array<TextureUnit, 32> m_texture_units;
TextureUnit* m_active_texture_unit { &m_texture_units[0] };
Vector<TextureUnit, 32> m_texture_units;
TextureUnit* m_active_texture_unit;
SoftGPU::Device m_rasterizer;
SoftGPU::DeviceInfo const m_device_info;
bool m_sampler_config_is_dirty { true };
struct Listing {

View file

@ -498,6 +498,15 @@ Device::Device(const Gfx::IntSize& min_size)
m_options.scissor_box = m_render_target->rect();
}
DeviceInfo Device::info() const
{
return {
.vendor_name = "SerenityOS",
.device_name = "SoftGPU",
.num_texture_units = num_samplers
};
}
void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
{
// At this point, the user has effectively specified that they are done with defining the geometry
@ -810,8 +819,6 @@ NonnullRefPtr<Image> Device::create_image(ImageFormat format, unsigned width, un
void Device::set_sampler_config(unsigned sampler, SamplerConfig const& config)
{
VERIFY(sampler < num_samplers);
m_samplers[sampler].set_config(config);
}

View file

@ -15,6 +15,7 @@
#include <LibGfx/Vector4.h>
#include <LibSoftGPU/Clipper.h>
#include <LibSoftGPU/DepthBuffer.h>
#include <LibSoftGPU/DeviceInfo.h>
#include <LibSoftGPU/Enums.h>
#include <LibSoftGPU/Image.h>
#include <LibSoftGPU/ImageFormat.h>
@ -62,6 +63,8 @@ class Device final {
public:
Device(const Gfx::IntSize& min_size);
DeviceInfo info() const;
void draw_primitives(PrimitiveType, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
void resize(const Gfx::IntSize& min_size);
void clear_color(const FloatVector4&);
@ -89,7 +92,7 @@ private:
Vector<Triangle> m_triangle_list;
Vector<Triangle> m_processed_triangles;
Vector<Vertex> m_clipped_vertices;
Sampler m_samplers[num_samplers];
Array<Sampler, num_samplers> m_samplers;
};
}

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
namespace SoftGPU {
struct DeviceInfo final {
String vendor_name;
String device_name;
unsigned num_texture_units;
};
}