Skip to content

Commit

Permalink
LibWeb/WebGL: Implement vertex array calls for WebGL2
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenikaliaksandr committed Dec 6, 2024
1 parent eec4b71 commit 86c230c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ class WebGLShader;
class WebGLShaderPrecisionFormat;
class WebGLTexture;
class WebGLUniformLocation;
class WebGLVertexArrayObject;
}

namespace Web::WebIDL {
Expand Down
8 changes: 4 additions & 4 deletions Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -325,6 +326,18 @@ ErrorOr<int> 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 <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
)~~~");
} else {
implementation_file_generator.append(R"~~~(
#include <GLES3/gl3.h>
)~~~");
}

implementation_file_generator.append(R"~~~(
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/DataView.h>
Expand All @@ -345,11 +358,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
#include <LibWeb/WebGL/WebGLShaderPrecisionFormat.h>
#include <LibWeb/WebGL/WebGLTexture.h>
#include <LibWeb/WebGL/WebGLUniformLocation.h>
#include <LibWeb/WebGL/WebGLVertexArrayObject.h>
#include <LibWeb/WebIDL/Buffers.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
namespace Web::WebGL {
static Vector<GLchar> null_terminated_string(StringView string)
Expand Down Expand Up @@ -488,6 +499,15 @@ class @class_name@ {
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<GLchar*> strings;
Expand Down Expand Up @@ -783,6 +803,14 @@ class @class_name@ {
continue;
}

if (function.name == "deleteVertexArray"sv) {
function_impl_generator.append(R"~~~(
auto handle = vertexArray ? vertexArray->handle() : 0;
glDeleteVertexArrays(1, &handle);
)~~~");
continue;
}

Vector<ByteString> gl_call_arguments;
for (size_t i = 0; i < function.parameters.size(); ++i) {
auto const& parameter = function.parameters[i];
Expand Down

0 comments on commit 86c230c

Please sign in to comment.