mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb/WebGL: Use WebGL version to determine ES version and extensions
This commit is contained in:
parent
e3b23e6f73
commit
0c2dd57d62
Notes:
github-actions[bot]
2025-06-09 21:42:00 +00:00
Author: https://github.com/Lubrsi
Commit: 0c2dd57d62
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4056
Reviewed-by: https://github.com/ADKaster
4 changed files with 60 additions and 47 deletions
|
@ -36,9 +36,10 @@ struct OpenGLContext::Impl {
|
|||
#endif
|
||||
};
|
||||
|
||||
OpenGLContext::OpenGLContext(NonnullRefPtr<Gfx::SkiaBackendContext> skia_backend_context, Impl impl)
|
||||
OpenGLContext::OpenGLContext(NonnullRefPtr<Gfx::SkiaBackendContext> skia_backend_context, Impl impl, WebGLVersion webgl_version)
|
||||
: m_skia_backend_context(move(skia_backend_context))
|
||||
, m_impl(make<Impl>(impl))
|
||||
, m_webgl_version(webgl_version)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ static EGLConfig get_egl_config(EGLDisplay display)
|
|||
}
|
||||
#endif
|
||||
|
||||
OwnPtr<OpenGLContext> OpenGLContext::create(NonnullRefPtr<Gfx::SkiaBackendContext> skia_backend_context)
|
||||
OwnPtr<OpenGLContext> OpenGLContext::create(NonnullRefPtr<Gfx::SkiaBackendContext> skia_backend_context, WebGLVersion webgl_version)
|
||||
{
|
||||
#ifdef AK_OS_MACOS
|
||||
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
|
@ -98,9 +99,11 @@ OwnPtr<OpenGLContext> OpenGLContext::create(NonnullRefPtr<Gfx::SkiaBackendContex
|
|||
|
||||
EGLint context_attributes[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION,
|
||||
2,
|
||||
webgl_version == WebGLVersion::WebGL1 ? 2 : 3,
|
||||
EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE,
|
||||
EGL_TRUE,
|
||||
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE,
|
||||
EGL_FALSE,
|
||||
EGL_NONE,
|
||||
EGL_NONE,
|
||||
};
|
||||
|
@ -110,9 +113,10 @@ OwnPtr<OpenGLContext> OpenGLContext::create(NonnullRefPtr<Gfx::SkiaBackendContex
|
|||
return {};
|
||||
}
|
||||
|
||||
return make<OpenGLContext>(skia_backend_context, Impl { .display = display, .config = config, .context = context });
|
||||
return make<OpenGLContext>(skia_backend_context, Impl { .display = display, .config = config, .context = context }, webgl_version);
|
||||
#else
|
||||
(void)skia_backend_context;
|
||||
(void)webgl_version;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
@ -259,56 +263,56 @@ u32 OpenGLContext::default_framebuffer() const
|
|||
struct Extension {
|
||||
String webgl_extension_name;
|
||||
Vector<StringView> required_angle_extensions;
|
||||
Optional<u32> only_for_webgl_version { OptionalNone {} };
|
||||
Optional<OpenGLContext::WebGLVersion> only_for_webgl_version { OptionalNone {} };
|
||||
};
|
||||
|
||||
Vector<Extension> s_available_webgl_extensions {
|
||||
// Khronos ratified WebGL Extensions
|
||||
{ "ANGLE_instanced_arrays"_string, { "GL_ANGLE_instanced_arrays"sv }, 1 },
|
||||
{ "EXT_blend_minmax"_string, { "GL_EXT_blend_minmax"sv }, 1 },
|
||||
{ "EXT_frag_depth"_string, { "GL_EXT_frag_depth"sv }, 1 },
|
||||
{ "EXT_shader_texture_lod"_string, { "GL_EXT_shader_texture_lod"sv }, 1 },
|
||||
{ "ANGLE_instanced_arrays"_string, { "GL_ANGLE_instanced_arrays"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "EXT_blend_minmax"_string, { "GL_EXT_blend_minmax"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "EXT_frag_depth"_string, { "GL_EXT_frag_depth"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "EXT_shader_texture_lod"_string, { "GL_EXT_shader_texture_lod"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "EXT_texture_filter_anisotropic"_string, { "GL_EXT_texture_filter_anisotropic"sv } },
|
||||
{ "OES_element_index_uint"_string, { "GL_OES_element_index_uint"sv }, 1 },
|
||||
{ "OES_standard_derivatives"_string, { "GL_OES_standard_derivatives"sv }, 1 },
|
||||
{ "OES_texture_float"_string, { "GL_OES_texture_float"sv }, 1 },
|
||||
{ "OES_element_index_uint"_string, { "GL_OES_element_index_uint"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "OES_standard_derivatives"_string, { "GL_OES_standard_derivatives"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "OES_texture_float"_string, { "GL_OES_texture_float"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "OES_texture_float_linear"_string, { "GL_OES_texture_float_linear"sv } },
|
||||
{ "OES_texture_half_float"_string, { "GL_OES_texture_half_float"sv }, 1 },
|
||||
{ "OES_texture_half_float_linear"_string, { "GL_OES_texture_half_float_linear"sv }, 1 },
|
||||
{ "OES_vertex_array_object"_string, { "GL_OES_vertex_array_object"sv }, 1 },
|
||||
{ "OES_texture_half_float"_string, { "GL_OES_texture_half_float"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "OES_texture_half_float_linear"_string, { "GL_OES_texture_half_float_linear"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "OES_vertex_array_object"_string, { "GL_OES_vertex_array_object"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "WEBGL_compressed_texture_s3tc"_string, { "GL_EXT_texture_compression_dxt1"sv, "GL_ANGLE_texture_compression_dxt3"sv, "GL_ANGLE_texture_compression_dxt5"sv } },
|
||||
{ "WEBGL_debug_renderer_info"_string, {} },
|
||||
{ "WEBGL_debug_shaders"_string, {} },
|
||||
{ "WEBGL_depth_texture"_string, { "GL_ANGLE_depth_texture"sv }, 1 },
|
||||
{ "WEBGL_draw_buffers"_string, { "GL_EXT_draw_buffers"sv }, 1 },
|
||||
{ "WEBGL_depth_texture"_string, { "GL_ANGLE_depth_texture"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "WEBGL_draw_buffers"_string, { "GL_EXT_draw_buffers"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "WEBGL_lose_context"_string, {} },
|
||||
|
||||
// Community approved WebGL Extensions
|
||||
{ "EXT_clip_control"_string, { "GL_EXT_clip_control"sv } },
|
||||
{ "EXT_color_buffer_float"_string, { "GL_EXT_color_buffer_float"sv }, 2 },
|
||||
{ "EXT_color_buffer_float"_string, { "GL_EXT_color_buffer_float"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "EXT_color_buffer_half_float"_string, { "GL_EXT_color_buffer_half_float"sv } },
|
||||
{ "EXT_conservative_depth"_string, { "GL_EXT_conservative_depth"sv }, 2 },
|
||||
{ "EXT_conservative_depth"_string, { "GL_EXT_conservative_depth"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "EXT_depth_clamp"_string, { "GL_EXT_depth_clamp"sv } },
|
||||
{ "EXT_disjoint_timer_query"_string, { "GL_EXT_disjoint_timer_query"sv }, 1 },
|
||||
{ "EXT_disjoint_timer_query_webgl2"_string, { "GL_EXT_disjoint_timer_query"sv }, 2 },
|
||||
{ "EXT_disjoint_timer_query"_string, { "GL_EXT_disjoint_timer_query"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "EXT_disjoint_timer_query_webgl2"_string, { "GL_EXT_disjoint_timer_query"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "EXT_float_blend"_string, { "GL_EXT_float_blend"sv } },
|
||||
{ "EXT_polygon_offset_clamp"_string, { "GL_EXT_polygon_offset_clamp"sv } },
|
||||
{ "EXT_render_snorm"_string, { "GL_EXT_render_snorm"sv }, 2 },
|
||||
{ "EXT_sRGB"_string, { "GL_EXT_sRGB"sv }, 1 },
|
||||
{ "EXT_render_snorm"_string, { "GL_EXT_render_snorm"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "EXT_sRGB"_string, { "GL_EXT_sRGB"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "EXT_texture_compression_bptc"_string, { "GL_EXT_texture_compression_bptc"sv } },
|
||||
{ "EXT_texture_compression_rgtc"_string, { "GL_EXT_texture_compression_rgtc"sv } },
|
||||
{ "EXT_texture_mirror_clamp_to_edge"_string, { "GL_EXT_texture_mirror_clamp_to_edge"sv } },
|
||||
{ "EXT_texture_norm16"_string, { "GL_EXT_texture_norm16"sv }, 2 },
|
||||
{ "EXT_texture_norm16"_string, { "GL_EXT_texture_norm16"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "KHR_parallel_shader_compile"_string, { "GL_KHR_parallel_shader_compile"sv } },
|
||||
{ "NV_shader_noperspective_interpolation"_string, { "GL_NV_shader_noperspective_interpolation"sv }, 2 },
|
||||
{ "NV_shader_noperspective_interpolation"_string, { "GL_NV_shader_noperspective_interpolation"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "OES_draw_buffers_indexed"_string, { "GL_OES_draw_buffers_indexed"sv } },
|
||||
{ "OES_fbo_render_mipmap"_string, { "GL_OES_fbo_render_mipmap"sv }, 1 },
|
||||
{ "OES_sample_variables"_string, { "GL_OES_sample_variables"sv }, 2 },
|
||||
{ "OES_shader_multisample_interpolation"_string, { "GL_OES_shader_multisample_interpolation"sv }, 2 },
|
||||
{ "OVR_multiview2"_string, { "GL_OVR_multiview2"sv }, 2 },
|
||||
{ "OES_fbo_render_mipmap"_string, { "GL_OES_fbo_render_mipmap"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "OES_sample_variables"_string, { "GL_OES_sample_variables"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "OES_shader_multisample_interpolation"_string, { "GL_OES_shader_multisample_interpolation"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "OVR_multiview2"_string, { "GL_OVR_multiview2"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "WEBGL_blend_func_extended"_string, { "GL_EXT_blend_func_extended"sv } },
|
||||
{ "WEBGL_clip_cull_distance"_string, { "GL_EXT_clip_cull_distance"sv }, 2 },
|
||||
{ "WEBGL_color_buffer_float"_string, { "EXT_color_buffer_half_float"sv, "OES_texture_float"sv }, 1 },
|
||||
{ "WEBGL_clip_cull_distance"_string, { "GL_EXT_clip_cull_distance"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "WEBGL_color_buffer_float"_string, { "EXT_color_buffer_half_float"sv, "OES_texture_float"sv }, OpenGLContext::WebGLVersion::WebGL1 },
|
||||
{ "WEBGL_compressed_texture_astc"_string, { "KHR_texture_compression_astc_hdr"sv, "KHR_texture_compression_astc_ldr"sv } },
|
||||
{ "WEBGL_compressed_texture_etc"_string, { "GL_ANGLE_compressed_texture_etc"sv } },
|
||||
{ "WEBGL_compressed_texture_etc1"_string, { "GL_OES_compressed_ETC1_RGB8_texture"sv } },
|
||||
|
@ -316,9 +320,9 @@ Vector<Extension> s_available_webgl_extensions {
|
|||
{ "WEBGL_compressed_texture_s3tc_srgb"_string, { "GL_EXT_texture_compression_s3tc_srgb"sv } },
|
||||
{ "WEBGL_multi_draw"_string, { "GL_ANGLE_multi_draw"sv } },
|
||||
{ "WEBGL_polygon_mode"_string, { "GL_ANGLE_polygon_mode"sv } },
|
||||
{ "WEBGL_provoking_vertex"_string, { "GL_ANGLE_provoking_vertex"sv }, 2 },
|
||||
{ "WEBGL_render_shared_exponent"_string, { "GL_QCOM_render_shared_exponent"sv }, 2 },
|
||||
{ "WEBGL_stencil_texturing"_string, { "GL_ANGLE_stencil_texturing"sv }, 2 },
|
||||
{ "WEBGL_provoking_vertex"_string, { "GL_ANGLE_provoking_vertex"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "WEBGL_render_shared_exponent"_string, { "GL_QCOM_render_shared_exponent"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
{ "WEBGL_stencil_texturing"_string, { "GL_ANGLE_stencil_texturing"sv }, OpenGLContext::WebGLVersion::WebGL2 },
|
||||
};
|
||||
|
||||
Vector<String> OpenGLContext::get_supported_extensions()
|
||||
|
@ -335,9 +339,10 @@ Vector<String> OpenGLContext::get_supported_extensions()
|
|||
|
||||
Vector<String> extensions;
|
||||
for (auto const& available_extension : s_available_webgl_extensions) {
|
||||
// FIXME: Check WebGL version.
|
||||
bool supported = true;
|
||||
bool supported = !available_extension.only_for_webgl_version.has_value()
|
||||
|| m_webgl_version == available_extension.only_for_webgl_version;
|
||||
|
||||
if (supported) {
|
||||
for (auto const& required_extension : available_extension.required_angle_extensions) {
|
||||
auto maybe_required_extension = requestable_extensions.find_if([&](StringView requestable_extension) {
|
||||
return required_extension == requestable_extension;
|
||||
|
@ -348,6 +353,7 @@ Vector<String> OpenGLContext::get_supported_extensions()
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (supported)
|
||||
extensions.append(available_extension.webgl_extension_name);
|
||||
|
@ -359,6 +365,7 @@ Vector<String> OpenGLContext::get_supported_extensions()
|
|||
m_requestable_extensions = extensions;
|
||||
return extensions;
|
||||
#else
|
||||
(void)m_webgl_version;
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -13,14 +13,19 @@ namespace Web::WebGL {
|
|||
|
||||
class OpenGLContext {
|
||||
public:
|
||||
static OwnPtr<OpenGLContext> create(NonnullRefPtr<Gfx::SkiaBackendContext>);
|
||||
enum class WebGLVersion {
|
||||
WebGL1,
|
||||
WebGL2,
|
||||
};
|
||||
|
||||
static OwnPtr<OpenGLContext> create(NonnullRefPtr<Gfx::SkiaBackendContext>, WebGLVersion);
|
||||
|
||||
void notify_content_will_change();
|
||||
void clear_buffer_to_default_values();
|
||||
void allocate_painting_surface_if_needed();
|
||||
|
||||
struct Impl;
|
||||
OpenGLContext(NonnullRefPtr<Gfx::SkiaBackendContext>, Impl);
|
||||
OpenGLContext(NonnullRefPtr<Gfx::SkiaBackendContext>, Impl, WebGLVersion);
|
||||
|
||||
~OpenGLContext();
|
||||
|
||||
|
@ -42,6 +47,7 @@ private:
|
|||
RefPtr<Gfx::PaintingSurface> m_painting_surface;
|
||||
NonnullOwnPtr<Impl> m_impl;
|
||||
Optional<Vector<String>> m_requestable_extensions;
|
||||
WebGLVersion m_webgl_version;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ JS::ThrowCompletionOr<GC::Ptr<WebGL2RenderingContext>> WebGL2RenderingContext::c
|
|||
fire_webgl_context_creation_error(canvas_element);
|
||||
return GC::Ptr<WebGL2RenderingContext> { nullptr };
|
||||
}
|
||||
auto context = OpenGLContext::create(*skia_backend_context);
|
||||
auto context = OpenGLContext::create(*skia_backend_context, OpenGLContext::WebGLVersion::WebGL2);
|
||||
if (!context) {
|
||||
fire_webgl_context_creation_error(canvas_element);
|
||||
return GC::Ptr<WebGL2RenderingContext> { nullptr };
|
||||
|
|
|
@ -60,7 +60,7 @@ JS::ThrowCompletionOr<GC::Ptr<WebGLRenderingContext>> WebGLRenderingContext::cre
|
|||
fire_webgl_context_creation_error(canvas_element);
|
||||
return GC::Ptr<WebGLRenderingContext> { nullptr };
|
||||
}
|
||||
auto context = OpenGLContext::create(*skia_backend_context);
|
||||
auto context = OpenGLContext::create(*skia_backend_context, OpenGLContext::WebGLVersion::WebGL1);
|
||||
if (!context) {
|
||||
fire_webgl_context_creation_error(canvas_element);
|
||||
return GC::Ptr<WebGLRenderingContext> { nullptr };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue