LibWeb/WebGL: Implement getBufferParameter

This commit is contained in:
Luke Wilde 2024-12-05 13:16:47 +00:00 committed by Alexander Kalenik
parent a65a981a6b
commit 4c0872ea1b
Notes: github-actions[bot] 2024-12-05 20:43:05 +00:00
2 changed files with 48 additions and 9 deletions

View file

@ -109,7 +109,7 @@ interface mixin WebGLRenderingContextBase {
GLint getAttribLocation(WebGLProgram program, DOMString name);
[FIXME] any getBufferParameter(GLenum target, GLenum pname);
any getBufferParameter(GLenum target, GLenum pname);
any getParameter(GLenum pname);
GLenum getError();

View file

@ -63,8 +63,6 @@ static ByteString idl_to_gl_function_name(StringView function_name)
return gl_function_name_builder.to_byte_string();
}
static void generate_get_parameter(SourceGenerator& generator)
{
struct NameAndType {
StringView name;
struct {
@ -73,6 +71,8 @@ static void generate_get_parameter(SourceGenerator& generator)
} return_type;
};
static void generate_get_parameter(SourceGenerator& generator)
{
Vector<NameAndType> const name_to_type = {
{ "ACTIVE_TEXTURE"sv, { "GLenum"sv } },
{ "ALIASED_LINE_WIDTH_RANGE"sv, { "Float32Array"sv, 2 } },
@ -232,6 +232,40 @@ static void generate_get_parameter(SourceGenerator& generator)
})~~~");
}
static void generate_get_buffer_parameter(SourceGenerator& generator)
{
Vector<NameAndType> const name_to_type = {
{ "BUFFER_SIZE"sv, { "GLint"sv } },
{ "BUFFER_USAGE"sv, { "GLenum"sv } },
};
generator.append(" switch (pname) {");
for (auto const& name_and_type : name_to_type) {
auto const& parameter_name = name_and_type.name;
auto const& type_name = name_and_type.return_type.type;
StringBuilder string_builder;
SourceGenerator impl_generator { string_builder };
impl_generator.set("parameter_name", parameter_name);
impl_generator.set("type_name", type_name);
impl_generator.append(R"~~~(
case GL_@parameter_name@: {
GLint result;
glGetBufferParameteriv(target, GL_@parameter_name@, &result);
return JS::Value(result);
}
)~~~");
generator.append(string_builder.string_view());
}
generator.appendln(R"~~~(
default:
TODO();
})~~~");
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
StringView generated_header_path;
@ -604,6 +638,11 @@ public:
continue;
}
if (function.name == "getBufferParameter"sv) {
generate_get_buffer_parameter(function_impl_generator);
continue;
}
if (function.name == "getActiveUniform"sv) {
function_impl_generator.append(R"~~~(
GLint size = 0;