Bug 31948 - texImage2D should allow null pixel data
Summary: texImage2D should allow null pixel data
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-27 19:41 PST by Ben Vanik
Modified: 2010-06-03 17:04 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Vanik 2009-11-27 19:41:41 PST
As per the spec of glTexImage2D, the last argument (data) is allowed to be NULL to indicate that an empty texture should be created.
It looks like right now GraphicsContext3D::texImage2D does no checking on pixels, which may be NULL so an error is thrown if you try.

Spec: http://www.khronos.org/opengles/sdk/docs/man/glTexImage2D.xml

Workaround:
function emptyTexImage2D(gl, internalFormat, width, height, format, type) {
    try {
        gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, null);
    } catch (e) {
        console.warn("browser texImage2D does not accept null - sending up a real blank texture");
        var pixels = new WebGLUnsignedByteArray(width * height * ( internalFormat == gl.RGBA ? 4 : 3 ) );
        gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, pixels);
    }
}
Comment 1 Zhenyao Mo 2010-06-03 17:04:00 PDT
fast/canvas/tex-sub-image-2d.html covers the case where pixels set to null.