LibWeb/WebGL: Request GL_ANGLE_instanced_arrays extension when required

This commit is contained in:
Luke Wilde 2025-01-10 12:55:47 +00:00 committed by Andreas Kling
parent 1156fe483d
commit 58942e1137
Notes: github-actions[bot] 2025-01-21 20:38:07 +00:00
4 changed files with 32 additions and 5 deletions

View file

@ -8,6 +8,8 @@
#include <LibWeb/Bindings/ANGLEInstancedArraysPrototype.h> #include <LibWeb/Bindings/ANGLEInstancedArraysPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/WebGL/ANGLEInstancedArrays.h> #include <LibWeb/WebGL/ANGLEInstancedArrays.h>
#include <LibWeb/WebGL/OpenGLContext.h>
#include <LibWeb/WebGL/WebGLRenderingContext.h>
#define GL_GLEXT_PROTOTYPES 1 #define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
@ -17,28 +19,33 @@ namespace Web::WebGL {
GC_DEFINE_ALLOCATOR(ANGLEInstancedArrays); GC_DEFINE_ALLOCATOR(ANGLEInstancedArrays);
JS::ThrowCompletionOr<GC::Ptr<ANGLEInstancedArrays>> ANGLEInstancedArrays::create(JS::Realm& realm) JS::ThrowCompletionOr<GC::Ptr<ANGLEInstancedArrays>> ANGLEInstancedArrays::create(JS::Realm& realm, GC::Ref<WebGLRenderingContext> context)
{ {
return realm.create<ANGLEInstancedArrays>(realm); return realm.create<ANGLEInstancedArrays>(realm, context);
} }
ANGLEInstancedArrays::ANGLEInstancedArrays(JS::Realm& realm) ANGLEInstancedArrays::ANGLEInstancedArrays(JS::Realm& realm, GC::Ref<WebGLRenderingContext> context)
: PlatformObject(realm) : PlatformObject(realm)
, m_context(context)
{ {
m_context->context().request_extension("GL_ANGLE_instanced_arrays");
} }
void ANGLEInstancedArrays::vertex_attrib_divisor_angle(GLuint index, GLuint divisor) void ANGLEInstancedArrays::vertex_attrib_divisor_angle(GLuint index, GLuint divisor)
{ {
m_context->context().make_current();
glVertexAttribDivisorANGLE(index, divisor); glVertexAttribDivisorANGLE(index, divisor);
} }
void ANGLEInstancedArrays::draw_arrays_instanced_angle(GLenum mode, GLint first, GLsizei count, GLsizei primcount) void ANGLEInstancedArrays::draw_arrays_instanced_angle(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
{ {
m_context->context().make_current();
glDrawArraysInstancedANGLE(mode, first, count, primcount); glDrawArraysInstancedANGLE(mode, first, count, primcount);
} }
void ANGLEInstancedArrays::draw_elements_instanced_angle(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount) void ANGLEInstancedArrays::draw_elements_instanced_angle(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount)
{ {
m_context->context().make_current();
glDrawElementsInstancedANGLE(mode, count, type, reinterpret_cast<void*>(offset), primcount); glDrawElementsInstancedANGLE(mode, count, type, reinterpret_cast<void*>(offset), primcount);
} }
@ -48,4 +55,10 @@ void ANGLEInstancedArrays::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(ANGLEInstancedArrays); WEB_SET_PROTOTYPE_FOR_INTERFACE(ANGLEInstancedArrays);
} }
void ANGLEInstancedArrays::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_context);
}
} }

View file

@ -17,7 +17,7 @@ class ANGLEInstancedArrays : public Bindings::PlatformObject {
GC_DECLARE_ALLOCATOR(ANGLEInstancedArrays); GC_DECLARE_ALLOCATOR(ANGLEInstancedArrays);
public: public:
static JS::ThrowCompletionOr<GC::Ptr<ANGLEInstancedArrays>> create(JS::Realm&); static JS::ThrowCompletionOr<GC::Ptr<ANGLEInstancedArrays>> create(JS::Realm&, GC::Ref<WebGLRenderingContext>);
void draw_arrays_instanced_angle(GLenum mode, GLint first, GLsizei count, GLsizei primcount); void draw_arrays_instanced_angle(GLenum mode, GLint first, GLsizei count, GLsizei primcount);
void draw_elements_instanced_angle(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount); void draw_elements_instanced_angle(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount);
@ -25,9 +25,12 @@ public:
protected: protected:
void initialize(JS::Realm&) override; void initialize(JS::Realm&) override;
void visit_edges(Visitor&) override;
private: private:
ANGLEInstancedArrays(JS::Realm&); ANGLEInstancedArrays(JS::Realm&, GC::Ref<WebGLRenderingContext>);
GC::Ref<WebGLRenderingContext> m_context;
}; };
} }

View file

@ -313,4 +313,14 @@ Vector<String> OpenGLContext::get_supported_extensions()
#endif #endif
} }
void OpenGLContext::request_extension(char const* extension_name)
{
#ifdef AK_OS_MACOS
make_current();
glRequestExtensionANGLE(extension_name);
#else
(void)extension_name;
#endif
}
} }

View file

@ -34,6 +34,7 @@ public:
u32 default_renderbuffer() const; u32 default_renderbuffer() const;
Vector<String> get_supported_extensions(); Vector<String> get_supported_extensions();
void request_extension(char const* extension_name);
private: private:
NonnullRefPtr<Gfx::SkiaBackendContext> m_skia_backend_context; NonnullRefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;