From 145bb0f84923f12716afdb14dbc87d7f6f04f4fb Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 10 Dec 2024 05:49:33 +0100 Subject: [PATCH] LibWeb/WebGL: Implement getSupportedExtensions() --- Libraries/LibWeb/WebGL/OpenGLContext.cpp | 82 +++++++++++++++++++ Libraries/LibWeb/WebGL/OpenGLContext.h | 2 + .../LibWeb/WebGL/WebGL2RenderingContext.cpp | 4 +- .../LibWeb/WebGL/WebGL2RenderingContext.h | 2 +- .../LibWeb/WebGL/WebGLRenderingContext.cpp | 4 +- .../LibWeb/WebGL/WebGLRenderingContext.h | 2 +- 6 files changed, 90 insertions(+), 6 deletions(-) diff --git a/Libraries/LibWeb/WebGL/OpenGLContext.cpp b/Libraries/LibWeb/WebGL/OpenGLContext.cpp index 95a6504c112..2067d901a1b 100644 --- a/Libraries/LibWeb/WebGL/OpenGLContext.cpp +++ b/Libraries/LibWeb/WebGL/OpenGLContext.cpp @@ -204,4 +204,86 @@ RefPtr OpenGLContext::surface() return m_painting_surface; } +Vector s_available_webgl_extensions { + // Khronos ratified WebGL Extensions + "ANGLE_instanced_arrays"sv, + "EXT_blend_minmax"sv, + "EXT_frag_depth"sv, + "EXT_shader_texture_lod"sv, + "EXT_texture_filter_anisotropic"sv, + "OES_element_index_uint"sv, + "OES_standard_derivatives"sv, + "OES_texture_float"sv, + "OES_texture_float_linear"sv, + "OES_texture_half_float"sv, + "OES_texture_half_float_linear"sv, + "OES_vertex_array_object"sv, + "WEBGL_compressed_texture_s3tc"sv, + "WEBGL_debug_renderer_info"sv, + "WEBGL_debug_shaders"sv, + "WEBGL_depth_texture"sv, + "WEBGL_draw_buffers"sv, + "WEBGL_lose_context"sv, + + // Community approved WebGL Extensions + "EXT_clip_control"sv, + "EXT_color_buffer_float"sv, + "EXT_color_buffer_half_float"sv, + "EXT_conservative_depth"sv, + "EXT_depth_clamp"sv, + "EXT_disjoint_timer_query"sv, + "EXT_disjoint_timer_query_webgl2"sv, + "EXT_float_blend"sv, + "EXT_polygon_offset_clamp"sv, + "EXT_render_snorm"sv, + "EXT_sRGB"sv, + "EXT_texture_compression_bptc"sv, + "EXT_texture_compression_rgtc"sv, + "EXT_texture_mirror_clamp_to_edge"sv, + "EXT_texture_norm16"sv, + "KHR_parallel_shader_compile"sv, + "NV_shader_noperspective_interpolation"sv, + "OES_draw_buffers_indexed"sv, + "OES_fbo_render_mipmap"sv, + "OES_sample_variables"sv, + "OES_shader_multisample_interpolation"sv, + "OVR_multiview2"sv, + "WEBGL_blend_func_extended"sv, + "WEBGL_clip_cull_distance"sv, + "WEBGL_color_buffer_float"sv, + "WEBGL_compressed_texture_astc"sv, + "WEBGL_compressed_texture_etc"sv, + "WEBGL_compressed_texture_etc1"sv, + "WEBGL_compressed_texture_pvrtc"sv, + "WEBGL_compressed_texture_s3tc_srgb"sv, + "WEBGL_multi_draw"sv, + "WEBGL_polygon_mode"sv, + "WEBGL_provoking_vertex"sv, + "WEBGL_render_shared_exponent"sv, + "WEBGL_stencil_texturing"sv, +}; + +Vector OpenGLContext::get_supported_extensions() +{ +#ifdef AK_OS_MACOS + make_current(); + + auto const* extensions_string = reinterpret_cast(glGetString(GL_EXTENSIONS)); + StringView extensions_view(extensions_string, strlen(extensions_string)); + + Vector extensions; + for (auto const& extension : extensions_view.split_view(' ')) { + auto extension_name_without_gl_prefix = extension.substring_view(3); + // FIXME: WebGL 1 and WebGL 2 have different sets of available extensions, but for now we simply + // filter out everything that is not listed in https://registry.khronos.org/webgl/extensions/ + if (s_available_webgl_extensions.contains_slow(extension_name_without_gl_prefix)) + extensions.append(MUST(String::from_utf8(extension_name_without_gl_prefix))); + } + + return extensions; +#else + return {}; +#endif +} + } diff --git a/Libraries/LibWeb/WebGL/OpenGLContext.h b/Libraries/LibWeb/WebGL/OpenGLContext.h index d9c15601d89..f76c25da6af 100644 --- a/Libraries/LibWeb/WebGL/OpenGLContext.h +++ b/Libraries/LibWeb/WebGL/OpenGLContext.h @@ -30,6 +30,8 @@ public: RefPtr surface(); + Vector get_supported_extensions(); + private: NonnullRefPtr m_skia_backend_context; Gfx::IntSize m_size; diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp index 9576416dd84..32a82000097 100644 --- a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp @@ -145,9 +145,9 @@ void WebGL2RenderingContext::allocate_painting_surface_if_needed() context().allocate_painting_surface_if_needed(); } -Optional> WebGL2RenderingContext::get_supported_extensions() const +Optional> WebGL2RenderingContext::get_supported_extensions() { - return {}; + return context().get_supported_extensions(); } JS::Object* WebGL2RenderingContext::get_extension(String const&) diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h index 0740a182072..5eb4dd64c7d 100644 --- a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h +++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h @@ -41,7 +41,7 @@ public: void set_size(Gfx::IntSize const&); void reset_to_default_state(); - Optional> get_supported_extensions() const; + Optional> get_supported_extensions(); JS::Object* get_extension(String const& name); WebIDL::Long drawing_buffer_width() const; diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp index b40b9ab74da..42245ddf0ed 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp @@ -161,9 +161,9 @@ void WebGLRenderingContext::allocate_painting_surface_if_needed() context().allocate_painting_surface_if_needed(); } -Optional> WebGLRenderingContext::get_supported_extensions() const +Optional> WebGLRenderingContext::get_supported_extensions() { - return {}; + return context().get_supported_extensions(); } JS::Object* WebGLRenderingContext::get_extension(String const&) diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h index d0fa4ed82e4..55f0abc4fb8 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h @@ -40,7 +40,7 @@ public: void set_size(Gfx::IntSize const&); void reset_to_default_state(); - Optional> get_supported_extensions() const; + Optional> get_supported_extensions(); JS::Object* get_extension(String const& name); WebIDL::Long drawing_buffer_width() const;