diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index b4332cf8850..f8b43334711 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -845,6 +845,7 @@ class WebGLShader; class WebGLShaderPrecisionFormat; class WebGLTexture; class WebGLUniformLocation; +class WebGLVertexArrayObject; } namespace Web::WebIDL { diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl b/Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl index db151c24ec9..be1b583442c 100644 --- a/Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl +++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl @@ -426,8 +426,8 @@ interface mixin WebGL2RenderingContextBase { [FIXME] undefined uniformBlockBinding(WebGLProgram program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); // Vertex Array Objects - [FIXME] WebGLVertexArrayObject createVertexArray(); - [FIXME] undefined deleteVertexArray(WebGLVertexArrayObject? vertexArray); - [FIXME] GLboolean isVertexArray(WebGLVertexArrayObject? vertexArray); // [WebGLHandlesContextLoss] - [FIXME] undefined bindVertexArray(WebGLVertexArrayObject? array); + WebGLVertexArrayObject createVertexArray(); + undefined deleteVertexArray(WebGLVertexArrayObject? vertexArray); + GLboolean isVertexArray(WebGLVertexArrayObject? vertexArray); // [WebGLHandlesContextLoss] + undefined bindVertexArray(WebGLVertexArrayObject? array); }; diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 036b241f779..748e2ba241f 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -117,6 +117,7 @@ static bool is_platform_object(Type const& type) "WebGLShaderPrecisionFormat"sv, "WebGLTexture"sv, "WebGLUniformLocation"sv, + "WebGLVertexArrayObject"sv, "Window"sv, "WindowProxy"sv, "WritableStream"sv, diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp index 17d5f6123c5..e582415c6d8 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp @@ -23,7 +23,8 @@ static bool is_webgl_object_type(StringView type_name) || type_name == "WebGLRenderbuffer"sv || type_name == "WebGLShader"sv || type_name == "WebGLTexture"sv - || type_name == "WebGLUniformLocation"sv; + || type_name == "WebGLUniformLocation"sv + || type_name == "WebGLVertexArrayObject"sv; } static bool gl_function_modifies_framebuffer(StringView function_name) @@ -325,6 +326,18 @@ ErrorOr serenity_main(Main::Arguments arguments) SourceGenerator implementation_file_generator { implementation_file_string_builder }; implementation_file_generator.set("class_name", class_name); + auto webgl_version = class_name == "WebGLRenderingContext" ? 1 : 2; + if (webgl_version == 1) { + implementation_file_generator.append(R"~~~( +#include +#include +)~~~"); + } else { + implementation_file_generator.append(R"~~~( +#include +)~~~"); + } + implementation_file_generator.append(R"~~~( #include #include @@ -345,11 +358,9 @@ ErrorOr serenity_main(Main::Arguments arguments) #include #include #include +#include #include -#include -#include - namespace Web::WebGL { static Vector null_terminated_string(StringView string) @@ -488,6 +499,15 @@ public: continue; } + if (function.name == "createVertexArray"sv) { + function_impl_generator.append(R"~~~( + GLuint handle = 0; + glGenVertexArrays(1, &handle); + return WebGLVertexArrayObject::create(m_realm, handle); +)~~~"); + continue; + } + if (function.name == "shaderSource"sv) { function_impl_generator.append(R"~~~( Vector strings; @@ -783,6 +803,14 @@ public: continue; } + if (function.name == "deleteVertexArray"sv) { + function_impl_generator.append(R"~~~( + auto handle = vertexArray ? vertexArray->handle() : 0; + glDeleteVertexArrays(1, &handle); +)~~~"); + continue; + } + Vector gl_call_arguments; for (size_t i = 0; i < function.parameters.size(); ++i) { auto const& parameter = function.parameters[i];