diff --git a/src/gl/quadFeature.js b/src/gl/quadFeature.js index 660fb9fe4f..fe96fd34a6 100644 --- a/src/gl/quadFeature.js +++ b/src/gl/quadFeature.js @@ -147,7 +147,7 @@ var gl_quadFeature = function (arg) { * Build this feature. */ this._build = function () { - var mapper, mat, prog, srctex, unicrop, geom; + var mapper, mat, prog, srctex, unicrop, geom, context; if (!m_this.position()) { return; @@ -174,10 +174,11 @@ var gl_quadFeature = function (arg) { unicrop = new vgl.uniform(vgl.GL.FLOAT_VEC2, 'crop'); unicrop.set([1.0, 1.0]); prog.addUniform(unicrop); + context = m_this.renderer()._glContext(); prog.addShader(vgl.getCachedShader( - vgl.GL.VERTEX_SHADER, vgl.GL, vertexShaderImageSource)); + vgl.GL.VERTEX_SHADER, context, vertexShaderImageSource)); prog.addShader(vgl.getCachedShader( - vgl.GL.FRAGMENT_SHADER, vgl.GL, fragmentShaderImageSource)); + vgl.GL.FRAGMENT_SHADER, context, fragmentShaderImageSource)); mat.addAttribute(prog); mat.addAttribute(new vgl.blend()); /* This is similar to vgl.planeSource */ @@ -214,9 +215,10 @@ var gl_quadFeature = function (arg) { prog.addUniform(new vgl.projectionUniform('projectionMatrix')); prog.addUniform(new vgl.floatUniform('opacity', 1.0)); prog.addUniform(new vgl.uniform(vgl.GL.FLOAT_VEC3, 'vertexColor')); + context = m_this.renderer()._glContext(); prog.addShader(vgl.getCachedShader( - vgl.GL.VERTEX_SHADER, vgl.GL, vertexShaderColorSource)); - prog.addShader(vgl.utils.createFragmentShader(vgl.GL)); + vgl.GL.VERTEX_SHADER, context, vertexShaderColorSource)); + prog.addShader(vgl.utils.createFragmentShader(context)); mat.addAttribute(prog); mat.addAttribute(new vgl.blend()); /* This is similar to vgl.planeSource */ diff --git a/src/gl/vglRenderer.js b/src/gl/vglRenderer.js index bfceb91055..7e16f5eb85 100644 --- a/src/gl/vglRenderer.js +++ b/src/gl/vglRenderer.js @@ -178,6 +178,19 @@ var vglRenderer = function (arg) { } }; + /** + * Get the GL context for this renderer. + * + * @returns {WebGLRenderingContext} The current context. If unavailable, + * falls back to the vgl generic context. + */ + this._glContext = function () { + if (m_viewer && m_viewer.renderWindow()) { + return m_viewer.renderWindow().context(); + } + return vgl.GL; + }; + /** * Exit. */ @@ -187,9 +200,14 @@ var vglRenderer = function (arg) { if (m_viewer) { var renderState = new vgl.renderState(); renderState.m_renderer = m_viewer; - renderState.m_context = m_viewer.renderWindow().context(); + renderState.m_context = this._glContext(); m_viewer.exit(renderState); + if (this._glContext() !== vgl.GL && this._glContext().getExtension('WEBGL_lose_context') && this._glContext().getExtension('WEBGL_lose_context').loseContext) { + this._glContext().getExtension('WEBGL_lose_context').loseContext(); + } } + // make sure we clear shaders associated with the generate context, too + vgl.clearCachedShaders(vgl.GL); m_viewer = null; s_exit(); };