From d6d5c095521429daf3151e4bb4b968aa15235927 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 7 Dec 2020 12:19:42 +0000 Subject: [PATCH] The `Shader` Game Object now supports being able to use a Render Texture as a `sampler2D` texture on the shader. Fix #5423 --- src/gameobjects/shader/Shader.js | 10 ++++++++-- src/renderer/webgl/PipelineManager.js | 12 +++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/gameobjects/shader/Shader.js b/src/gameobjects/shader/Shader.js index a610a2acd..2947689d0 100644 --- a/src/gameobjects/shader/Shader.js +++ b/src/gameobjects/shader/Shader.js @@ -728,6 +728,12 @@ var Shader = new Class({ if (textureManager.exists(textureKey)) { var frame = textureManager.getFrame(textureKey); + + if (frame.glTexture && frame.glTexture.isRenderTexture) + { + return this.setSampler2DBuffer(uniformKey, frame.glTexture, frame.width, frame.height, textureIndex, textureData); + } + var uniform = this.uniforms[uniformKey]; var source = frame.source; @@ -908,7 +914,7 @@ var Shader = new Class({ var data = uniform.textureData; - if (data) + if (data && !uniform.value.isRenderTexture) { // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texImage2D @@ -1017,7 +1023,7 @@ var Shader = new Class({ } else if (uniform.type === 'sampler2D') { - gl.activeTexture(gl['TEXTURE' + textureCount]); + gl.activeTexture(gl.TEXTURE0 + textureCount); gl.bindTexture(gl.TEXTURE_2D, value); diff --git a/src/renderer/webgl/PipelineManager.js b/src/renderer/webgl/PipelineManager.js index 34da62524..8f6b92ccc 100644 --- a/src/renderer/webgl/PipelineManager.js +++ b/src/renderer/webgl/PipelineManager.js @@ -967,11 +967,6 @@ var PipelineManager = new Class({ pipeline = this.previous; } - if (!pipeline) - { - return; - } - var renderer = this.renderer; var gl = renderer.gl; @@ -995,9 +990,12 @@ var PipelineManager = new Class({ renderer.setBlendMode(0, true); - this.current = pipeline; + if (pipeline) + { + this.current = pipeline; - pipeline.rebind(); + pipeline.rebind(); + } renderer.resetTextures(); },