diff --git a/src/systems/material.js b/src/systems/material.js index 2c985991dab..12045b255d7 100755 --- a/src/systems/material.js +++ b/src/systems/material.js @@ -145,12 +145,14 @@ module.exports.System = registerSystem('material', { texture.minFilter = THREE.LinearFilter; setTextureProperties(texture, data); - // if we're on iOS, and the video is HLS, we currently need to do some hacks - if (this.sceneEl.isIOS && isHLS(videoEl.src || videoEl.getAttribute('src'), videoEl.type || videoEl.getAttribute('type'))) { - // really it's BGRA, so this needs correction in shader + // If iOS and video is HLS, do some hacks. + if (this.sceneEl.isIOS && + isHLS(videoEl.src || videoEl.getAttribute('src'), + videoEl.type || videoEl.getAttribute('type'))) { + // Actually BGRA. Tell shader to correct later. texture.format = THREE.RGBAFormat; texture.needsCorrectionBGRA = true; - // apparently this is needed for HLS, so this needs correction in shader + // Apparently needed for HLS. Tell shader to correct later. texture.flipY = false; texture.needsCorrectionFlipY = true; } diff --git a/src/utils/material.js b/src/utils/material.js index 2f9ae9d16c0..8ff4e5ddb3e 100644 --- a/src/utils/material.js +++ b/src/utils/material.js @@ -125,7 +125,7 @@ function handleTextureEvents (el, texture) { // Check to see if we need to use iOS 10 HLS shader. // Only override the shader if it is a stock (or test) shader that we know doesn't correct. if (texture.needsCorrectionBGRA && texture.needsCorrectionFlipY && - ['standard', 'flat', 'testShader'].indexOf(el.components.material.data.shader) !== -1) { + ['standard', 'flat'].indexOf(el.components.material.data.shader) !== -1) { el.setAttribute('material', 'shader', 'ios10hls'); } diff --git a/tests/shaders/ios10hls.test.js b/tests/shaders/ios10hls.test.js new file mode 100644 index 00000000000..4ac6f9cc656 --- /dev/null +++ b/tests/shaders/ios10hls.test.js @@ -0,0 +1,34 @@ +/* global AFRAME, CustomEvent, assert, process, setup, suite, test */ +var entityFactory = require('../helpers').entityFactory; + +var VIDEO = 'base/tests/assets/test.mp4'; + +suite('ios10hls', function () { + setup(function (done) { + this.el = entityFactory(); + if (this.el.hasLoaded) { + done(); + } else { + this.el.addEventListener('loaded', function () { done(); }); + } + }); + + test('iOS HLS video uses appropriate shader', function (done) { + var el = this.el; + el.sceneEl.isIOS = true; + + // Set up and verify video element to be treated as HLS. + var videoEl = document.createElement('video'); + videoEl.src = VIDEO; + videoEl.type = 'application/x-mpegurl'; + assert.equal(AFRAME.utils.material.isHLS(videoEl.src, videoEl.type), true); + + el.setAttribute('material', {src: videoEl}); + videoEl.dispatchEvent(new CustomEvent('loadeddata')); + + setTimeout(function () { + assert.equal(el.getAttribute('material').shader, 'ios10hls'); + done(); + }); + }); +});