Bug 1316245 - In ZeroTextureData, bind texture before cleaning it. r=jgilbert
authorEthan Lin <ethlin@mozilla.com>
Fri, 18 Nov 2016 00:16:00 -0500
changeset 323508 339c60ab68e4e56aa3e772cb680ea8c7d548aaa8
parent 323507 5f357188ef27dd26d0e267786e9e6d4da9dec102
child 323509 a524931c115bd49b76786d29e9231be458d95d78
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersjgilbert
bugs1316245
milestone53.0a1
Bug 1316245 - In ZeroTextureData, bind texture before cleaning it. r=jgilbert
dom/canvas/WebGLContext.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -2297,16 +2297,31 @@ ZeroTextureData(WebGLContext* webgl, con
     // "Doctor, it hurts when I do this!" "Well don't do that!"
     webgl->GenerateWarning("%s: This operation requires zeroing texture data. This is"
                            " slow.",
                            funcName);
 
     gl::GLContext* gl = webgl->GL();
     gl->MakeCurrent();
 
+    GLenum scopeBindTarget;
+    switch (target.get()) {
+    case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+    case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+    case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+    case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+    case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+    case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+        scopeBindTarget = LOCAL_GL_TEXTURE_CUBE_MAP;
+        break;
+    default:
+        scopeBindTarget = target.get();
+        break;
+    }
+    ScopedBindTexture scopeBindTexture(gl, tex, scopeBindTarget);
     auto compression = usage->format->compression;
     if (compression) {
         MOZ_RELEASE_ASSERT(!xOffset && !yOffset && !zOffset, "GFX: Can't zero compressed texture with offsets.");
 
         auto sizedFormat = usage->format->sizedFormat;
         MOZ_RELEASE_ASSERT(sizedFormat, "GFX: texture sized format not set");
 
         const auto fnSizeInBlocks = [](CheckedUint32 pixels, uint8_t pixelsPerBlock) {
@@ -2375,17 +2390,16 @@ ZeroTextureData(WebGLContext* webgl, con
     const size_t byteCount = checkedByteCount.value();
 
     UniqueBuffer zeros = calloc(1, byteCount);
     if (!zeros)
         return false;
 
     ScopedUnpackReset scopedReset(webgl);
     gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 1); // Don't bother with striding it well.
-
     const auto error = DoTexSubImage(gl, target, level, xOffset, yOffset, zOffset, width,
                                      height, depth, packing, zeros.get());
     if (error)
         return false;
 
     return true;
 }