From a81e5af4557c29c7783677ca8ff2cbfdcbcd4b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Mon, 7 Sep 2015 18:27:33 +0200 Subject: [PATCH] Add support of gl-react-core "childrenContext" for #5 --- src/GLCanvas.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/GLCanvas.js b/src/GLCanvas.js index 59dd6ec..2642e6a 100644 --- a/src/GLCanvas.js +++ b/src/GLCanvas.js @@ -163,7 +163,9 @@ class GLCanvas extends Component { // traverseTree compute renderData from the data. // frameIndex is the framebuffer index of a node. (root is -1) function traverseTree (data) { - const { shader: s, uniforms: dataUniforms, children: dataChildren, width, height, fboId } = data; + const { shader: s, uniforms: dataUniforms, children: dataChildren, contextChildren: dataContextChildren, width, height, fboId } = data; + + const contextChildren = dataContextChildren.map(traverseTree); // Traverse children and compute children renderData. // We build a framebuffer mapping (from child index to fbo index) @@ -242,7 +244,7 @@ class GLCanvas extends Component { const notProvided = Object.keys(shader.uniforms).filter(u => !(u in uniforms)); invariant(notProvided.length===0, "Shader '%s': All defined uniforms must be provided. Missing: '"+notProvided.join("', '")+"'", shader.name); - return { shader, uniforms, textures, children, width, height, fboId }; + return { shader, uniforms, textures, children, contextChildren, width, height, fboId }; } this._renderData = traverseTree(data); @@ -267,10 +269,13 @@ class GLCanvas extends Component { const buffer = this._buffer; function recDraw (renderData) { - const { shader, uniforms, textures, children, width, height, fboId } = renderData; + const { shader, uniforms, textures, children, contextChildren, width, height, fboId } = renderData; const w = width * scale, h = height * scale; + // contextChildren are rendered BEFORE children and parent because are contextual to them + contextChildren.forEach(recDraw); + // children are rendered BEFORE the parent children.forEach(recDraw);