فهرست منبع

LibWeb/WebGL2: Implement fenceSync

Luke Wilde 7 ماه پیش
والد
کامیت
135ceb387e

+ 1 - 0
Libraries/LibWeb/Forward.h

@@ -845,6 +845,7 @@ class WebGLRenderingContext;
 class WebGLSampler;
 class WebGLShader;
 class WebGLShaderPrecisionFormat;
+class WebGLSync;
 class WebGLTexture;
 class WebGLUniformLocation;
 class WebGLVertexArrayObject;

+ 4 - 0
Libraries/LibWeb/WebGL/Types.h

@@ -15,4 +15,8 @@ using GLenum = unsigned int;
 using GLuint = unsigned int;
 using GLint = int;
 
+// FIXME: This should really be "struct __GLsync*", but the linker doesn't recognise it.
+//        Since this conflicts with the original definition of GLsync, the suffix "Internal" has been added.
+using GLsyncInternal = void*;
+
 }

+ 1 - 1
Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl

@@ -396,7 +396,7 @@ interface mixin WebGL2RenderingContextBase {
     [FIXME] any getSamplerParameter(WebGLSampler sampler, GLenum pname);
 
     // Sync objects
-    [FIXME] WebGLSync? fenceSync(GLenum condition, GLbitfield flags);
+    WebGLSync? fenceSync(GLenum condition, GLbitfield flags);
     [FIXME] GLboolean isSync(WebGLSync? sync); // [WebGLHandlesContextLoss]
     [FIXME] undefined deleteSync(WebGLSync? sync);
     [FIXME] GLenum clientWaitSync(WebGLSync sync, GLbitfield flags, GLuint64 timeout);

+ 4 - 3
Libraries/LibWeb/WebGL/WebGLSync.cpp

@@ -13,13 +13,14 @@ namespace Web::WebGL {
 
 GC_DEFINE_ALLOCATOR(WebGLSync);
 
-GC::Ref<WebGLSync> WebGLSync::create(JS::Realm& realm, GLuint handle)
+GC::Ref<WebGLSync> WebGLSync::create(JS::Realm& realm, GLsyncInternal handle)
 {
     return realm.create<WebGLSync>(realm, handle);
 }
 
-WebGLSync::WebGLSync(JS::Realm& realm, GLuint handle)
-    : WebGLObject(realm, handle)
+WebGLSync::WebGLSync(JS::Realm& realm, GLsyncInternal handle)
+    : WebGLObject(realm, 0)
+    , m_sync_handle(handle)
 {
 }
 

+ 6 - 2
Libraries/LibWeb/WebGL/WebGLSync.h

@@ -16,14 +16,18 @@ class WebGLSync : public WebGLObject {
     GC_DECLARE_ALLOCATOR(WebGLSync);
 
 public:
-    static GC::Ref<WebGLSync> create(JS::Realm& realm, GLuint handle);
+    static GC::Ref<WebGLSync> create(JS::Realm& realm, GLsyncInternal handle);
 
     virtual ~WebGLSync() override;
 
+    GLsyncInternal sync_handle() const { return m_sync_handle; }
+
 protected:
-    explicit WebGLSync(JS::Realm&, GLuint handle);
+    explicit WebGLSync(JS::Realm&, GLsyncInternal handle);
 
     virtual void initialize(JS::Realm&) override;
+
+    GLsyncInternal m_sync_handle { nullptr };
 };
 
 }

+ 1 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp

@@ -116,6 +116,7 @@ static bool is_platform_object(Type const& type)
         "WebGLSampler"sv,
         "WebGLShader"sv,
         "WebGLShaderPrecisionFormat"sv,
+        "WebGLSync"sv,
         "WebGLTexture"sv,
         "WebGLUniformLocation"sv,
         "WebGLVertexArrayObject"sv,

+ 9 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp

@@ -357,6 +357,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 #include <LibWeb/WebGL/@class_name@.h>
 #include <LibWeb/WebGL/WebGLSampler.h>
 #include <LibWeb/WebGL/WebGLShader.h>
+#include <LibWeb/WebGL/WebGLSync.h>
 #include <LibWeb/WebGL/WebGLShaderPrecisionFormat.h>
 #include <LibWeb/WebGL/WebGLTexture.h>
 #include <LibWeb/WebGL/WebGLUniformLocation.h>
@@ -519,6 +520,14 @@ public:
             continue;
         }
 
+        if (function.name == "fenceSync"sv) {
+            function_impl_generator.append(R"~~~(
+    GLsync handle = glFenceSync(condition, flags);
+    return WebGLSync::create(m_realm, handle);
+)~~~");
+            continue;
+        }
+
         if (function.name == "shaderSource"sv) {
             function_impl_generator.append(R"~~~(
     Vector<GLchar*> strings;