Skip to content

Commit

Permalink
refine buffer view check (cocos#3578)
Browse files Browse the repository at this point in the history
  • Loading branch information
2youyou2 authored and pandamicro committed Nov 30, 2018
1 parent eee77f8 commit 218af3b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cocos2d/core/renderer/render-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8086,8 +8086,6 @@ function _createShader(gl, type, src) {
return shader;
}

const ArrayBufferView = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array)).constructor;

var Texture = function Texture(device) {
this._device = device;

Expand Down Expand Up @@ -8286,7 +8284,7 @@ var Texture2D = (function (Texture$$1) {
var premultiplyAlpha = options.premultiplyAlpha;
var img = options.image;

if (!(img instanceof ArrayBufferView)) {
if (!ArrayBuffer.isView(img) && !(img instanceof ArrayBuffer)) {
if (flipY === undefined) {
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
} else {
Expand Down Expand Up @@ -8345,7 +8343,7 @@ var Texture2D = (function (Texture$$1) {
var premultiplyAlpha = options.premultiplyAlpha;
var img = options.image;

if (!(img instanceof ArrayBufferView)) {
if (!ArrayBuffer.isView(img) && !(img instanceof ArrayBuffer)) {
if (flipY === undefined) {
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
} else {
Expand Down Expand Up @@ -8634,7 +8632,7 @@ var TextureCube = (function (Texture$$1) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplyAlpha);
}

if (!(img instanceof ArrayBufferView)) {
if (!ArrayBuffer.isView(img) && !(img instanceof ArrayBuffer)) {
gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, options.level, options.x, options.y, glFmt.format, glFmt.pixelType, img);
} else {
if (this._compressed) {
Expand Down Expand Up @@ -8681,7 +8679,7 @@ var TextureCube = (function (Texture$$1) {
} else {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplyAlpha);
}
if (!(img instanceof ArrayBufferView)) {
if (!ArrayBuffer.isView(img) && !(img instanceof ArrayBuffer)) {
gl.texImage2D(
gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex,
options.level,
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require('./polyfill/string');
require('./polyfill/misc');
require('./polyfill/array');
require('./polyfill/object');
require('./polyfill/array-buffer');
if (!(CC_EDITOR && Editor.isMainProcess)) {
require('./polyfill/typescript');
}
Expand Down
6 changes: 6 additions & 0 deletions polyfill/array-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (!ArrayBuffer.isView) {
const ArrayBufferView = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array)).constructor;
ArrayBuffer.isView = function (view) {
return view instanceof ArrayBufferView;
};
}

0 comments on commit 218af3b

Please sign in to comment.