Skip to content

Commit a2c659e

Browse files
cqundefinegmta
authored andcommitted
LibWeb: Implement WebGL getVertexAttrib
This also implements all allowed parameter name values for this function.
1 parent 2d8b393 commit a2c659e

10 files changed

+134
-1
lines changed

Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ bool WebGL2RenderingContext::ext_texture_filter_anisotropic_extension_enabled()
256256
return !!m_ext_texture_filter_anisotropic;
257257
}
258258

259+
bool WebGL2RenderingContext::angle_instanced_arrays_extension_enabled() const
260+
{
261+
return false;
262+
}
263+
259264
ReadonlySpan<WebIDL::UnsignedLong> WebGL2RenderingContext::enabled_compressed_texture_formats() const
260265
{
261266
return m_enabled_compressed_texture_formats;

Libraries/LibWeb/WebGL/WebGL2RenderingContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class WebGL2RenderingContext final : public Bindings::PlatformObject
5252
WebIDL::Long drawing_buffer_height() const;
5353

5454
virtual bool ext_texture_filter_anisotropic_extension_enabled() const override;
55+
virtual bool angle_instanced_arrays_extension_enabled() const override;
5556
virtual ReadonlySpan<WebIDL::UnsignedLong> enabled_compressed_texture_formats() const override;
5657

5758
private:

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,65 @@ GC::Root<WebGLUniformLocation> WebGL2RenderingContextImpl::get_uniform_location(
31283128
return WebGLUniformLocation::create(m_realm, location);
31293129
}
31303130

3131+
JS::Value WebGL2RenderingContextImpl::get_vertex_attrib(WebIDL::UnsignedLong index, WebIDL::UnsignedLong pname)
3132+
{
3133+
switch (pname) {
3134+
case GL_CURRENT_VERTEX_ATTRIB: {
3135+
Array<GLfloat, 4> result;
3136+
result.fill(0);
3137+
glGetVertexAttribfvRobustANGLE(index, GL_CURRENT_VERTEX_ATTRIB, result.size(), nullptr, result.data());
3138+
3139+
auto byte_buffer = MUST(ByteBuffer::copy(result.span().reinterpret<u8>()));
3140+
auto array_buffer = JS::ArrayBuffer::create(m_realm, move(byte_buffer));
3141+
return JS::Float32Array::create(m_realm, result.size(), array_buffer);
3142+
}
3143+
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: {
3144+
GLint handle { 0 };
3145+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, 1, nullptr, &handle);
3146+
return WebGLBuffer::create(m_realm, *this, handle);
3147+
}
3148+
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: {
3149+
GLint result { 0 };
3150+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, 1, nullptr, &result);
3151+
return JS::Value(result);
3152+
}
3153+
case GL_VERTEX_ATTRIB_ARRAY_ENABLED: {
3154+
GLint result { 0 };
3155+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, 1, nullptr, &result);
3156+
return JS::Value(result == GL_TRUE);
3157+
}
3158+
case GL_VERTEX_ATTRIB_ARRAY_INTEGER: {
3159+
GLint result { 0 };
3160+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_INTEGER, 1, nullptr, &result);
3161+
return JS::Value(result == GL_TRUE);
3162+
}
3163+
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: {
3164+
GLint result { 0 };
3165+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, 1, nullptr, &result);
3166+
return JS::Value(result == GL_TRUE);
3167+
}
3168+
case GL_VERTEX_ATTRIB_ARRAY_SIZE: {
3169+
GLint result { 0 };
3170+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, 1, nullptr, &result);
3171+
return JS::Value(result);
3172+
}
3173+
case GL_VERTEX_ATTRIB_ARRAY_STRIDE: {
3174+
GLint result { 0 };
3175+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, 1, nullptr, &result);
3176+
return JS::Value(result);
3177+
}
3178+
case GL_VERTEX_ATTRIB_ARRAY_TYPE: {
3179+
GLint result { 0 };
3180+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, 1, nullptr, &result);
3181+
return JS::Value(result);
3182+
}
3183+
default:
3184+
dbgln("Unknown WebGL vertex attrib name: 0x{:04x}", pname);
3185+
set_error(GL_INVALID_ENUM);
3186+
return JS::js_null();
3187+
}
3188+
}
3189+
31313190
void WebGL2RenderingContextImpl::hint(WebIDL::UnsignedLong target, WebIDL::UnsignedLong mode)
31323191
{
31333192
m_context->make_current();

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class WebGL2RenderingContextImpl : public WebGLRenderingContextBase {
198198
Optional<String> get_shader_info_log(GC::Root<WebGLShader> shader);
199199
Optional<String> get_shader_source(GC::Root<WebGLShader> shader);
200200
GC::Root<WebGLUniformLocation> get_uniform_location(GC::Root<WebGLProgram> program, String name);
201+
JS::Value get_vertex_attrib(WebIDL::UnsignedLong index, WebIDL::UnsignedLong pname);
201202
void hint(WebIDL::UnsignedLong target, WebIDL::UnsignedLong mode);
202203
bool is_buffer(GC::Root<WebGLBuffer> buffer);
203204
bool is_enabled(WebIDL::UnsignedLong cap);

Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ bool WebGLRenderingContext::ext_texture_filter_anisotropic_extension_enabled() c
283283
return !!m_ext_texture_filter_anisotropic;
284284
}
285285

286+
bool WebGLRenderingContext::angle_instanced_arrays_extension_enabled() const
287+
{
288+
return !!m_angle_instanced_arrays_extension;
289+
}
290+
286291
ReadonlySpan<WebIDL::UnsignedLong> WebGLRenderingContext::enabled_compressed_texture_formats() const
287292
{
288293
return m_enabled_compressed_texture_formats;

Libraries/LibWeb/WebGL/WebGLRenderingContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class WebGLRenderingContext final : public Bindings::PlatformObject
5151
WebIDL::Long drawing_buffer_height() const;
5252

5353
virtual bool ext_texture_filter_anisotropic_extension_enabled() const override;
54+
virtual bool angle_instanced_arrays_extension_enabled() const override;
5455
virtual ReadonlySpan<WebIDL::UnsignedLong> enabled_compressed_texture_formats() const override;
5556

5657
private:

Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class WebGLRenderingContextBase {
3333
virtual void visit_edges(JS::Cell::Visitor&) = 0;
3434
virtual OpenGLContext& context() = 0;
3535
virtual bool ext_texture_filter_anisotropic_extension_enabled() const = 0;
36+
virtual bool angle_instanced_arrays_extension_enabled() const = 0;
3637
virtual ReadonlySpan<WebIDL::UnsignedLong> enabled_compressed_texture_formats() const = 0;
3738

3839
template<typename T>

Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ interface mixin WebGLRenderingContextBase {
131131

132132
WebGLUniformLocation? getUniformLocation(WebGLProgram program, DOMString name);
133133

134-
[FIXME] any getVertexAttrib(GLuint index, GLenum pname);
134+
any getVertexAttrib(GLuint index, GLenum pname);
135135

136136
[FIXME] GLintptr getVertexAttribOffset(GLuint index, GLenum pname);
137137

Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,65 @@ GC::Root<WebGLUniformLocation> WebGLRenderingContextImpl::get_uniform_location(G
16921692
return WebGLUniformLocation::create(m_realm, location);
16931693
}
16941694

1695+
JS::Value WebGLRenderingContextImpl::get_vertex_attrib(WebIDL::UnsignedLong index, WebIDL::UnsignedLong pname)
1696+
{
1697+
switch (pname) {
1698+
case GL_CURRENT_VERTEX_ATTRIB: {
1699+
Array<GLfloat, 4> result;
1700+
result.fill(0);
1701+
glGetVertexAttribfvRobustANGLE(index, GL_CURRENT_VERTEX_ATTRIB, result.size(), nullptr, result.data());
1702+
1703+
auto byte_buffer = MUST(ByteBuffer::copy(result.span().reinterpret<u8>()));
1704+
auto array_buffer = JS::ArrayBuffer::create(m_realm, move(byte_buffer));
1705+
return JS::Float32Array::create(m_realm, result.size(), array_buffer);
1706+
}
1707+
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: {
1708+
GLint handle { 0 };
1709+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, 1, nullptr, &handle);
1710+
return WebGLBuffer::create(m_realm, *this, handle);
1711+
}
1712+
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: {
1713+
if (angle_instanced_arrays_extension_enabled()) {
1714+
GLint result { 0 };
1715+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, 1, nullptr, &result);
1716+
return JS::Value(result);
1717+
}
1718+
1719+
set_error(GL_INVALID_ENUM);
1720+
return JS::js_null();
1721+
}
1722+
case GL_VERTEX_ATTRIB_ARRAY_ENABLED: {
1723+
GLint result { 0 };
1724+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, 1, nullptr, &result);
1725+
return JS::Value(result == GL_TRUE);
1726+
}
1727+
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: {
1728+
GLint result { 0 };
1729+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, 1, nullptr, &result);
1730+
return JS::Value(result == GL_TRUE);
1731+
}
1732+
case GL_VERTEX_ATTRIB_ARRAY_SIZE: {
1733+
GLint result { 0 };
1734+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, 1, nullptr, &result);
1735+
return JS::Value(result);
1736+
}
1737+
case GL_VERTEX_ATTRIB_ARRAY_STRIDE: {
1738+
GLint result { 0 };
1739+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, 1, nullptr, &result);
1740+
return JS::Value(result);
1741+
}
1742+
case GL_VERTEX_ATTRIB_ARRAY_TYPE: {
1743+
GLint result { 0 };
1744+
glGetVertexAttribivRobustANGLE(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, 1, nullptr, &result);
1745+
return JS::Value(result);
1746+
}
1747+
default:
1748+
dbgln("Unknown WebGL vertex attrib name: 0x{:04x}", pname);
1749+
set_error(GL_INVALID_ENUM);
1750+
return JS::js_null();
1751+
}
1752+
}
1753+
16951754
void WebGLRenderingContextImpl::hint(WebIDL::UnsignedLong target, WebIDL::UnsignedLong mode)
16961755
{
16971756
m_context->make_current();

Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class WebGLRenderingContextImpl : public WebGLRenderingContextBase {
113113
Optional<String> get_shader_info_log(GC::Root<WebGLShader> shader);
114114
Optional<String> get_shader_source(GC::Root<WebGLShader> shader);
115115
GC::Root<WebGLUniformLocation> get_uniform_location(GC::Root<WebGLProgram> program, String name);
116+
JS::Value get_vertex_attrib(WebIDL::UnsignedLong index, WebIDL::UnsignedLong pname);
116117
void hint(WebIDL::UnsignedLong target, WebIDL::UnsignedLong mode);
117118
bool is_buffer(GC::Root<WebGLBuffer> buffer);
118119
bool is_enabled(WebIDL::UnsignedLong cap);

0 commit comments

Comments
 (0)