summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2023-01-30 16:08:50 +0100
committerTim Flynn <trflynn89@pm.me>2023-01-30 13:49:52 -0500
commite3f8ac2c05423da784e2925b358d2df859414db2 (patch)
treeabfe9c5656754d601480cf2530be8171d0868b34 /Userland/Libraries
parent6a50fb465c5c0778513872dbe5c0b1956aecb062 (diff)
downloadserenity-e3f8ac2c05423da784e2925b358d2df859414db2.zip
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 :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGL/GLContext.cpp31
-rw-r--r--Userland/Libraries/LibGL/GLContext.h7
2 files changed, 23 insertions, 15 deletions
diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp
index 95e3bc107a..4b6e8ae3f4 100644
--- a/Userland/Libraries/LibGL/GLContext.cpp
+++ b/Userland/Libraries/LibGL/GLContext.cpp
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
- * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
+ * Copyright (c) 2022-2023, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Debug.h>
+#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibGL/GLContext.h>
#include <LibGL/Image.h>
@@ -69,7 +70,7 @@ GLContext::GLContext(RefPtr<GPU::Driver> driver, NonnullOwnPtr<GPU::Device> 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<GLubyte const*>("1.5");
case GL_EXTENSIONS:
- return reinterpret_cast<GLubyte const*>(m_extensions.characters());
+ return reinterpret_cast<GLubyte const*>(m_extensions.data());
case GL_SHADING_LANGUAGE_VERSION:
return reinterpret_cast<GLubyte const*>("0.0");
default:
@@ -923,31 +924,37 @@ void GLContext::sync_device_config()
sync_clip_planes();
}
-void GLContext::build_extension_string()
+ErrorOr<ByteBuffer> GLContext::build_extension_string()
{
- Vector<StringView> extensions;
+ Vector<StringView, 6> 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<NonnullOwnPtr<GLContext>> create_context(Gfx::Bitmap& bitmap)
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index 5a75ab99a2..9ead5e60fa 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -1,13 +1,14 @@
/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
* Copyright (c) 2021-2022, Jesse Buhagiar <jooster669@gmail.com>
- * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
+ * Copyright (c) 2022-2023, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
+#include <AK/ByteBuffer.h>
#include <AK/Debug.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>
@@ -248,7 +249,7 @@ private:
void sync_stencil_configuration();
void sync_clip_planes();
- void build_extension_string();
+ ErrorOr<ByteBuffer> build_extension_string();
template<typename T>
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;