Skip to content

Commit

Permalink
Fix iOS mode change glitch.
Browse files Browse the repository at this point in the history
  • Loading branch information
borismus committed Mar 26, 2016
1 parent f7d045b commit 0d933e2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
27 changes: 22 additions & 5 deletions build/webvr-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,8 @@ function CardboardDistorter(gl) {
this.realColorMask = gl.colorMask;
this.realClearColor = gl.clearColor;
this.realViewport = gl.viewport;
this.realCanvasWidth = Object.getOwnPropertyDescriptor(gl.canvas.__proto__, 'width');
this.realCanvasWidth.configurable = true;
this.realCanvasHeight = Object.getOwnPropertyDescriptor(gl.canvas.__proto__, 'height');
this.realCanvasHeight.configurable = true;
this.realCanvasWidth = this.getOwnPropertyDescriptor_(gl.canvas.__proto__, 'width');
this.realCanvasHeight = this.getOwnPropertyDescriptor_(gl.canvas.__proto__, 'height');

this.isPatched = false;

Expand Down Expand Up @@ -914,7 +912,26 @@ CardboardDistorter.prototype.computeMeshIndices_ = function(width, height) {
}
}
return indices;
}
};

CardboardDistorter.prototype.getOwnPropertyDescriptor_ = function(proto, attrName) {
var descriptor = Object.getOwnPropertyDescriptor(proto, attrName);
// In some cases (ahem... Safari), the descriptor returns undefined get and
// set fields. In this case, we need to create a synthetic property
// descriptor. This works around some of the issues in
// https://github.com/borismus/webvr-polyfill/issues/46
if (descriptor.get === undefined || descriptor.set === undefined) {
descriptor.configurable = true;
descriptor.enumerable = true;
descriptor.get = function() {
return this.getAttribute(attrName);
};
descriptor.set = function(val) {
this.setAttribute(attrName, val);
};
}
return descriptor;
};

module.exports = CardboardDistorter;

Expand Down
27 changes: 22 additions & 5 deletions src/cardboard-distorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ function CardboardDistorter(gl) {
this.realColorMask = gl.colorMask;
this.realClearColor = gl.clearColor;
this.realViewport = gl.viewport;
this.realCanvasWidth = Object.getOwnPropertyDescriptor(gl.canvas.__proto__, 'width');
this.realCanvasWidth.configurable = true;
this.realCanvasHeight = Object.getOwnPropertyDescriptor(gl.canvas.__proto__, 'height');
this.realCanvasHeight.configurable = true;
this.realCanvasWidth = this.getOwnPropertyDescriptor_(gl.canvas.__proto__, 'width');
this.realCanvasHeight = this.getOwnPropertyDescriptor_(gl.canvas.__proto__, 'height');

this.isPatched = false;

Expand Down Expand Up @@ -591,6 +589,25 @@ CardboardDistorter.prototype.computeMeshIndices_ = function(width, height) {
}
}
return indices;
}
};

CardboardDistorter.prototype.getOwnPropertyDescriptor_ = function(proto, attrName) {
var descriptor = Object.getOwnPropertyDescriptor(proto, attrName);
// In some cases (ahem... Safari), the descriptor returns undefined get and
// set fields. In this case, we need to create a synthetic property
// descriptor. This works around some of the issues in
// https://github.com/borismus/webvr-polyfill/issues/46
if (descriptor.get === undefined || descriptor.set === undefined) {
descriptor.configurable = true;
descriptor.enumerable = true;
descriptor.get = function() {
return this.getAttribute(attrName);
};
descriptor.set = function(val) {
this.setAttribute(attrName, val);
};
}
return descriptor;
};

module.exports = CardboardDistorter;

0 comments on commit 0d933e2

Please sign in to comment.