aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEhsan Akhgari <ehsan.akhgari@gmail.com>2012-04-09 18:25:32 -0400
committerEhsan Akhgari <ehsan.akhgari@gmail.com>2012-04-13 18:17:51 -0400
commitc8a8ef54f911ee80a5ee0ffa23b5b4a0490c8121 (patch)
tree4c21e7c6e3892cb874d5978da1a57fadde28e6f0
parent33c14175559dd1fb889d953e430f02a13bda8f94 (diff)
Take the unpack alignment into consideration when determining the number of bytes to upload to the GPU
Conflicts: src/library_gl.js
-rw-r--r--src/library_gl.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index 2ab3afb2..82f05cd3 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -66,6 +66,16 @@ var LibraryGL = {
return true;
} while (true);
return false;
+ },
+
+ computeImageSize: function(width, height, sizePerPixel, alignment) {
+ function roundedToNextMultipleOf(x, y) {
+ return Math.floor((x + y - 1) / y) * y
+ }
+ var plainRowSize = width * sizePerPixel;
+ var alignedRowSize = roundedToNextMultipleOf(plainRowSize, alignment);
+ return (height <= 0) ? 0 :
+ ((height - 1) * alignedRowSize + plainRowSize);
}
},
@@ -260,17 +270,17 @@ var LibraryGL = {
default:
throw 'Invalid format (' + format + ') passed to glTexImage2D';
}
- pixels = {{{ makeHEAPView('U8', 'pixels', 'pixels+width*height*sizePerPixel') }}};
break;
case 0x8363 /* GL_UNSIGNED_SHORT_5_6_5 */:
case 0x8033 /* GL_UNSIGNED_SHORT_4_4_4_4 */:
case 0x8034 /* GL_UNSIGNED_SHORT_5_5_5_1 */:
sizePerPixel = 2;
- pixels = {{{ makeHEAPView('U16', 'pixels', 'pixels+width*height*sizePerPixel') }}};
break;
default:
throw 'Invalid type (' + type + ') passed to glTexImage2D';
}
+ var bytes = GL.computeImageSize(width, height, sizePerPixel, GL.unpackAlignment);
+ pixels = {{{ makeHEAPView('U8', 'pixels', 'pixels+bytes') }}};
} else {
pixels = null;
}
@@ -299,17 +309,17 @@ var LibraryGL = {
default:
throw 'Invalid format (' + format + ') passed to glTexSubImage2D';
}
- pixels = {{{ makeHEAPView('U8', 'pixels', 'pixels+width*height*sizePerPixel') }}};
break;
case 0x8363 /* GL_UNSIGNED_SHORT_5_6_5 */:
case 0x8033 /* GL_UNSIGNED_SHORT_4_4_4_4 */:
case 0x8034 /* GL_UNSIGNED_SHORT_5_5_5_1 */:
sizePerPixel = 2;
- pixels = {{{ makeHEAPView('U16', 'pixels', 'pixels+width*height*sizePerPixel') }}};
break;
default:
throw 'Invalid type (' + type + ') passed to glTexSubImage2D';
}
+ var bytes = GL.computeImageSize(width, height, sizePerPixel, GL.unpackAlignment);
+ pixels = {{{ makeHEAPView('U8', 'pixels', 'pixels+bytes') }}};
} else {
pixels = null;
}