Skip to content

Commit

Permalink
feat: update support up to threejs r127
Browse files Browse the repository at this point in the history
  • Loading branch information
lojjic committed Apr 19, 2021
1 parent 8ebf59d commit 5b512f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/troika-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react": "^16.5.2",
"react-dat-gui": "^4.0.0",
"react-dom": "^16.5.2",
"three": "^0.125.2",
"three": "^0.127.0",
"three-instanced-uniforms-mesh": "^0.40.0",
"three-line-2d": "^1.1.6",
"troika-2d": "^0.40.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-three-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"module": "dist/troika-three-utils.esm.js",
"module:src": "src/index.js",
"peerDependencies": {
"three": "0.103.x - 0.125.x"
"three": "0.103.x - 0.127.x"
}
}
15 changes: 12 additions & 3 deletions packages/troika-xr/src/facade/WorldXRFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WorldXRFacade extends World3DFacade {
// If the session has an existing valid XRWebGLLayer, just grab its framebuffer.
// Otherwise, create a new XRWebGLLayer
if (baseLayer && baseLayer._glContext === gl) {
renderer.setFramebuffer(baseLayer.framebuffer)
bindFramebuffer(renderer, baseLayer.framebuffer)
} else {
const promise = gl.makeXRCompatible ? gl.makeXRCompatible() : Promise.resolve() //not always implemented?
promise.then(() => {
Expand All @@ -54,13 +54,13 @@ class WorldXRFacade extends World3DFacade {
})
baseLayer._glContext = gl
xrSession.updateRenderState({ baseLayer })
renderer.setFramebuffer(baseLayer.framebuffer)
bindFramebuffer(renderer, baseLayer.framebuffer)
this._queueRender()
}
})
}
} else {
renderer.setFramebuffer(null)
bindFramebuffer(renderer, null)
renderer.setRenderTarget(renderer.getRenderTarget()) //see https://github.com/mrdoob/three.js/pull/15830
// reset canvas/viewport size in case something changed it (cough cough polyfill)
renderer.getSize(tempVec2)
Expand Down Expand Up @@ -176,4 +176,13 @@ function parseFramebufferScaleFactor(value, xrSession) {
return scale
}

// Smooth out r127 framebuffer state refactor
function bindFramebuffer(renderer, framebuffer) {
if (renderer.setFramebuffer) { //pre-r127
renderer.setFramebuffer(framebuffer)
} else {
renderer.state.bindFramebuffer(framebuffer)
}
}

export default WorldXRFacade

0 comments on commit 5b512f0

Please sign in to comment.