From e3f8ac2c05423da784e2925b358d2df859414db2 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 30 Jan 2023 16:08:50 +0100 Subject: [PATCH] LibGL: Remove DeprecatedString usage We only use it for the extension string, which we now convert into a `ByteBuffer` object containing the null-terminated bytes :^) --- Userland/Libraries/LibGL/GLContext.cpp | 31 ++++++++++++++++---------- Userland/Libraries/LibGL/GLContext.h | 7 +++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp index 95e3bc107a1..4b6e8ae3f45 100644 --- a/Userland/Libraries/LibGL/GLContext.cpp +++ b/Userland/Libraries/LibGL/GLContext.cpp @@ -1,12 +1,13 @@ /* * Copyright (c) 2021, Jesse Buhagiar * Copyright (c) 2021, Stephan Unverwerth - * Copyright (c) 2022, Jelle Raaijmakers + * Copyright (c) 2022-2023, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include #include @@ -69,7 +70,7 @@ GLContext::GLContext(RefPtr driver, NonnullOwnPtr devi texture_coordinate_generation[3].eye_plane_coefficients = { 0.f, 0.f, 0.f, 0.f }; } - build_extension_string(); + m_extensions = build_extension_string().release_value_but_fixme_should_propagate_errors(); } GLContext::~GLContext() @@ -194,7 +195,7 @@ GLubyte const* GLContext::gl_get_string(GLenum name) case GL_VERSION: return reinterpret_cast("1.5"); case GL_EXTENSIONS: - return reinterpret_cast(m_extensions.characters()); + return reinterpret_cast(m_extensions.data()); case GL_SHADING_LANGUAGE_VERSION: return reinterpret_cast("0.0"); default: @@ -923,31 +924,37 @@ void GLContext::sync_device_config() sync_clip_planes(); } -void GLContext::build_extension_string() +ErrorOr GLContext::build_extension_string() { - Vector extensions; + Vector extensions; // FIXME: npot texture support became a required core feature starting with OpenGL 2.0 (https://www.khronos.org/opengl/wiki/NPOT_Texture) // Ideally we would verify if the selected device adheres to the requested OpenGL context version before context creation // and refuse to create a context if it doesn't. if (m_device_info.supports_npot_textures) - extensions.append("GL_ARB_texture_non_power_of_two"sv); + TRY(extensions.try_append("GL_ARB_texture_non_power_of_two"sv)); if (m_device_info.num_texture_units > 1) - extensions.append("GL_ARB_multitexture"sv); + TRY(extensions.try_append("GL_ARB_multitexture"sv)); if (m_device_info.supports_texture_clamp_to_edge) - extensions.append("GL_EXT_texture_edge_clamp"sv); + TRY(extensions.try_append("GL_EXT_texture_edge_clamp"sv)); if (m_device_info.supports_texture_env_add) { - extensions.append("GL_ARB_texture_env_add"sv); - extensions.append("GL_EXT_texture_env_add"sv); + TRY(extensions.try_append("GL_ARB_texture_env_add"sv)); + TRY(extensions.try_append("GL_EXT_texture_env_add"sv)); } if (m_device_info.max_texture_lod_bias > 0.f) - extensions.append("GL_EXT_texture_lod_bias"sv); + TRY(extensions.try_append("GL_EXT_texture_lod_bias"sv)); - m_extensions = DeprecatedString::join(' ', extensions); + StringBuilder string_builder {}; + TRY(string_builder.try_join(' ', extensions)); + + // Create null-terminated string + auto extensions_bytes = string_builder.to_byte_buffer(); + TRY(extensions_bytes.try_append(0)); + return extensions_bytes; } ErrorOr> create_context(Gfx::Bitmap& bitmap) diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 5a75ab99a2d..9ead5e60fab 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -1,13 +1,14 @@ /* * Copyright (c) 2021, Stephan Unverwerth * Copyright (c) 2021-2022, Jesse Buhagiar - * Copyright (c) 2022, Jelle Raaijmakers + * Copyright (c) 2022-2023, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include #include #include @@ -248,7 +249,7 @@ private: void sync_stencil_configuration(); void sync_clip_planes(); - void build_extension_string(); + ErrorOr build_extension_string(); template T* store_in_listing(T value) @@ -562,7 +563,7 @@ private: GLenum m_color_material_mode { GL_AMBIENT_AND_DIFFUSE }; // GL Extension string - DeprecatedString m_extensions; + ByteBuffer m_extensions; // Buffer objects NameAllocator m_buffer_name_allocator;