summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2022-01-15 17:22:59 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-19 19:57:49 +0100
commitd3d12c2fe7e396edfc41780c404768a48d495ccc (patch)
treed3dbf90b3831df66ee6921e7adf1dce546d0e165 /Userland
parent5505f353e8bf3cebdec4e332adf93cbcb923a890 (diff)
downloadserenity-d3d12c2fe7e396edfc41780c404768a48d495ccc.zip
LibGL: Generate GL extension string dynamically during construction
LibGL will now generate the GL extension string in the constructor and refer to it later on when the string is queried via glGetString(). Currently we only check whether the device supports non-power-of-two textures and add GL_ARB_texture_non_power_of_two to the supported extensions in that case.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp24
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h5
2 files changed, 26 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 1186d4faf4..f7e777235b 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -9,6 +9,7 @@
#include <AK/Debug.h>
#include <AK/Format.h>
#include <AK/QuickSort.h>
+#include <AK/StringBuilder.h>
#include <AK/TemporaryChange.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
@@ -75,6 +76,8 @@ SoftwareGLContext::SoftwareGLContext(Gfx::Bitmap& frontbuffer)
light0.diffuse_intensity = { 1.0f, 1.0f, 1.0f, 1.0f };
light0.specular_intensity = { 1.0f, 1.0f, 1.0f, 1.0f };
m_light_state_is_dirty = true;
+
+ build_extension_string();
}
Optional<ContextParameter> SoftwareGLContext::get_context_parameter(GLenum name)
@@ -431,7 +434,7 @@ GLubyte* SoftwareGLContext::gl_get_string(GLenum name)
case GL_VERSION:
return reinterpret_cast<GLubyte*>(const_cast<char*>("1.5"));
case GL_EXTENSIONS:
- return reinterpret_cast<GLubyte*>(const_cast<char*>(""));
+ return reinterpret_cast<GLubyte*>(const_cast<char*>(m_extensions.characters()));
case GL_SHADING_LANGUAGE_VERSION:
return reinterpret_cast<GLubyte*>(const_cast<char*>("0.0"));
default:
@@ -924,8 +927,10 @@ void SoftwareGLContext::gl_tex_image_2d(GLenum target, GLint level, GLint intern
RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + Texture2D::MAX_TEXTURE_SIZE) || height > (2 + Texture2D::MAX_TEXTURE_SIZE), GL_INVALID_VALUE);
// Check if width and height are a power of 2
- RETURN_WITH_ERROR_IF((width & (width - 1)) != 0, GL_INVALID_VALUE);
- RETURN_WITH_ERROR_IF((height & (height - 1)) != 0, GL_INVALID_VALUE);
+ if (!m_device_info.supports_npot_textures) {
+ RETURN_WITH_ERROR_IF((width & (width - 1)) != 0, GL_INVALID_VALUE);
+ RETURN_WITH_ERROR_IF((height & (height - 1)) != 0, GL_INVALID_VALUE);
+ }
RETURN_WITH_ERROR_IF(border != 0, GL_INVALID_VALUE);
if (level == 0) {
@@ -3249,6 +3254,19 @@ void SoftwareGLContext::sync_stencil_configuration()
set_device_stencil(SoftGPU::Face::Back, m_stencil_function[Face::Back], m_stencil_operation[Face::Back]);
}
+void SoftwareGLContext::build_extension_string()
+{
+ Vector<StringView> 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");
+
+ m_extensions = String::join(" ", extensions);
+}
+
void SoftwareGLContext::gl_lightf(GLenum light, GLenum pname, GLfloat param)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_lightf, light, pname, param);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index ff5ea056be..8448098990 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -157,6 +157,8 @@ private:
void sync_light_state();
void sync_stencil_configuration();
+ void build_extension_string();
+
template<typename T>
T* store_in_listing(T value)
{
@@ -432,6 +434,9 @@ private:
bool m_color_material_enabled { false };
GLenum m_color_material_face { GL_FRONT_AND_BACK };
GLenum m_color_material_mode { GL_AMBIENT_AND_DIFFUSE };
+
+ // GL Extension string
+ String m_extensions;
};
}