From 76eb355aff437a20d0209ce488db3801444337f1 Mon Sep 17 00:00:00 2001 From: Prabindh Sundareson Date: Wed, 29 Jan 2014 16:34:17 +0530 Subject: [PATCH] WebGLRenderer: Modify to take in existing WebGL context This patch modifies WebGLRenderer to take in an existing WebGL context, and adds an unit test to test the behaviour. Signed-off-by: Prabindh Sundareson --- examples/context_assignment_test.html | 73 +++++++++++++++++++++++++++ src/renderers/WebGLRenderer.js | 3 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 examples/context_assignment_test.html diff --git a/examples/context_assignment_test.html b/examples/context_assignment_test.html new file mode 100644 index 0000000000..7fcd0927c4 --- /dev/null +++ b/examples/context_assignment_test.html @@ -0,0 +1,73 @@ + + + Pre-created Context Assignment Test + + + + + + + + + +
+This test checks if Three.js successfully used the pre-created GL context passed from framework outside of Three.js.
For more information refer to this issue list in Three.js github
The screen should show 2 square boxes of size 256x256, one filled by CSS in green color, and the other filled by WebGL in red color. If the red box is shown and same in size to the green box, it indicates that the test is successful. +
+ +
+The above is the CSS filled box, not GL, in Green color. +

+The below is the GL filled box, not CSS, in Red color. +
+ + +
+
+Prabindh Sundareson + + + diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 505b5b2d91..4793eed49a 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -12,6 +12,7 @@ THREE.WebGLRenderer = function ( parameters ) { parameters = parameters || {}; var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ), + _givenGLContext = parameters.givenGLContext !== undefined ? parameters.givenGLContext : null, _precision = parameters.precision !== undefined ? parameters.precision : 'highp', @@ -6517,7 +6518,7 @@ THREE.WebGLRenderer = function ( parameters ) { preserveDrawingBuffer: _preserveDrawingBuffer }; - _gl = _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes ); + _gl = _givenGLContext || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes ); if ( _gl === null ) { -- GitLab