Skip to content

Commit 25d78f7

Browse files
committed
LibWeb: Implement WebGL2's readPixels with a byte offset argument
We pass it in as a `void*` since that's what this API expects when you have bound the GL_PIXEL_PACK_BUFFER buffer.
1 parent 7b5940d commit 25d78f7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,19 @@ void WebGL2RenderingContextImpl::read_pixels(WebIDL::Long x, WebIDL::Long y, Web
14961496
glReadPixelsRobustANGLE(x, y, width, height, format, type, span.size(), nullptr, nullptr, nullptr, span.data());
14971497
}
14981498

1499+
void WebGL2RenderingContextImpl::read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height,
1500+
WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, WebIDL::LongLong offset)
1501+
{
1502+
m_context->make_current();
1503+
1504+
if (!m_pixel_pack_buffer_binding) {
1505+
set_error(GL_INVALID_OPERATION);
1506+
return;
1507+
}
1508+
1509+
glReadPixelsRobustANGLE(x, y, width, height, format, type, 0, nullptr, nullptr, nullptr, reinterpret_cast<void*>(offset));
1510+
}
1511+
14991512
void WebGL2RenderingContextImpl::active_texture(WebIDL::UnsignedLong texture)
15001513
{
15011514
m_context->make_current();

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class WebGL2RenderingContextImpl : public WebGLRenderingContextBase {
132132
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
133133
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
134134
void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
135+
void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, WebIDL::LongLong offset);
135136
void active_texture(WebIDL::UnsignedLong texture);
136137
void attach_shader(GC::Root<WebGLProgram> program, GC::Root<WebGLShader> shader);
137138
void bind_attrib_location(GC::Root<WebGLProgram> program, WebIDL::UnsignedLong index, String name);

Libraries/LibWeb/WebGL/WebGL2RenderingContextOverloads.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ interface mixin WebGL2RenderingContextOverloads {
6262
// WebGL1:
6363
undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels);
6464
// WebGL2:
65-
[FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLintptr offset);
65+
undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLintptr offset);
6666
[FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView dstData, unsigned long long dstOffset);
6767
};

0 commit comments

Comments
 (0)