mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb/WebGL: Implement readPixels()
This commit is contained in:
parent
c199be061a
commit
4e8ec1e793
Notes:
github-actions[bot]
2024-12-13 08:21:02 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/4e8ec1e793c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2878 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/gmta
3 changed files with 24 additions and 2 deletions
|
@ -59,7 +59,7 @@ interface mixin WebGL2RenderingContextOverloads {
|
|||
|
||||
// Reading back pixels
|
||||
// WebGL1:
|
||||
[FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? dstData);
|
||||
undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels);
|
||||
// WebGL2:
|
||||
[FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLintptr offset);
|
||||
[FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView dstData, unsigned long long dstOffset);
|
||||
|
|
|
@ -25,7 +25,7 @@ interface mixin WebGLRenderingContextOverloads {
|
|||
[FIXME] undefined compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, [AllowShared] ArrayBufferView data);
|
||||
[FIXME] undefined compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, [AllowShared] ArrayBufferView data);
|
||||
|
||||
[FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels);
|
||||
undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels);
|
||||
|
||||
undefined texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels);
|
||||
undefined texImage2D(GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type, TexImageSource source); // May throw DOMException
|
||||
|
|
|
@ -621,6 +621,28 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
if (function.name == "readPixels"sv) {
|
||||
function_impl_generator.append(R"~~~(
|
||||
if (!pixels) {
|
||||
return;
|
||||
}
|
||||
|
||||
void *ptr = nullptr;
|
||||
if (pixels->is_data_view()) {
|
||||
auto& data_view = static_cast<JS::DataView&>(*pixels->raw_object());
|
||||
ptr = data_view.viewed_array_buffer()->buffer().data();
|
||||
} else if (pixels->is_typed_array_base()) {
|
||||
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*pixels->raw_object());
|
||||
ptr = typed_array_base.viewed_array_buffer()->buffer().data();
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
glReadPixels(x, y, width, height, format, type, ptr);
|
||||
)~~~");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (function.name == "drawElements"sv) {
|
||||
function_impl_generator.append(R"~~~(
|
||||
glDrawElements(mode, count, type, reinterpret_cast<void*>(offset));
|
||||
|
|
Loading…
Add table
Reference in a new issue