LibWeb: Ensure WebGL buffers don't mix between index and other data

The spec mandates that a buffer during its lifetime can only get bound
to either an index buffer or any other type.
This commit is contained in:
Undefine 2025-11-06 22:39:51 +01:00 committed by Jelle Raaijmakers
parent 85478c9215
commit 7d6212ae71
Notes: github-actions[bot] 2025-11-27 18:21:19 +00:00
4 changed files with 38 additions and 0 deletions

View file

@ -2,10 +2,12 @@
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
* Copyright (c) 2025, Undefine <undefine@undefine.pl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <GLES2/gl2.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/WebGLBufferPrototype.h>
@ -33,4 +35,18 @@ void WebGLBuffer::initialize(JS::Realm& realm)
Base::initialize(realm);
}
bool WebGLBuffer::is_compatible_with(GLenum target)
{
// https://registry.khronos.org/webgl/specs/latest/2.0/#5.1
if (!m_target.has_value()) {
m_target = target;
return true;
}
if (target == GL_ELEMENT_ARRAY_BUFFER)
return m_target.value() == GL_ELEMENT_ARRAY_BUFFER;
return m_target.value() != GL_ELEMENT_ARRAY_BUFFER;
}
}