tags:

views:

142

answers:

2

It is possible to retrieve the bitmap data HTML Canvas 2D element, is it also possible to access the rendered content of a Canvas 3D / WebGL element as bitmap data?

A: 

From the working draft of the WebGL Specification:

ArrayBufferView readPixels(GLint x, GLint y, 
    GLsizei width, GLsizei height, GLenum format, GLenum type)

Return a ArrayBufferView with pixels within the passed rectangle. The data returned from readPixels must be up-to-date as of the most recently sent drawing command. Any unprocessed drawing commands must be completed and their results presented to the current drawing buffers before readPixels accesses the drawing buffer.

The specific subclass of ArrayBufferView returned depends on the passed type. If it is UNSIGNED_BYTE, a Uint8Array is returned, otherwise a Uint16Array is returned.

Liam
A: 

The signature of WebGL's readPixels has changed in a later draft.

Instead of returning a new array with the pixel data everytime, you pass an array to fill as last argument :

void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView pixels)

This allows to reuse the same array for multiple readPixels operations.

neonux
Sounds like a good change.
Liam