
from UM.Application import Application
from UM.Resources import Resources

from UM.Math.Matrix import Matrix

from UM.View.RenderPass import RenderPass
from UM.View.GL.OpenGL import OpenGL

class CompositePass(RenderPass):
    def __init__(self, width, height):
        super().__init__("composite", width, height)

        self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
        self._gl = OpenGL.getInstance().getBindingsObject()
        self._renderer = Application.getInstance().getRenderer()

    def setCompositeShader(self, shader):
        self._shader = shader

    def renderContents(self):
        pass

    def renderOutput(self):
        self._shader.bind()

        texture_unit = 0
        for render_pass in self._renderer.getRenderPasses():
            self._gl.glActiveTexture(texture_unit)
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, render_pass.getTextureId())
            texture_unit += 1

        self._renderer.renderQuad(self._shader)

        for i in range(texture_unit):
            self._gl.glActiveTexture(texture_unit)
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, 0)

        self._shader.release()


from UM.Application import Application
from UM.Resources import Resources

from UM.Math.Matrix import Matrix

from UM.View.RenderPass import RenderPass
from UM.View.GL.OpenGL import OpenGL

class CompositePass(RenderPass):
    def __init__(self, width, height):
        super().__init__("composite", width, height, 999)

        self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
        self._gl = OpenGL.getInstance().getBindingsObject()
        self._renderer = Application.getInstance().getRenderer()

        self._layer_bindings = [ "default", "selection" ]

    def setCompositeShader(self, shader):
        self._shader = shader

    def setLayerBindings(self, bindings):
        self._layer_bindings = bindings

    def render(self):
        self._shader.bind()

        texture_unit = 0
        for binding in self._layer_bindings:
            render_pass = self._renderer.getRenderPass(binding)
            if not render_pass:
                continue

            self._gl.glActiveTexture(getattr(self._gl, "GL_TEXTURE{0}".format(texture_unit)))
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, render_pass.getTextureId())
            texture_unit += 1

        self._renderer.renderFullScreenQuad(self._shader)

        for i in range(texture_unit):
            self._gl.glActiveTexture(getattr(self._gl, "GL_TEXTURE{0}".format(i)))
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, 0)

        self._shader.release()

Add explicit render layer binding instead of assuming all render passes can be used for compositing
Add explicit render layer binding instead of assuming all render passes can be used for compositing

  
  from UM.Application import Application
  from UM.Resources import Resources
  
  from UM.Math.Matrix import Matrix
  
  from UM.View.RenderPass import RenderPass
  from UM.View.GL.OpenGL import OpenGL
  
  class CompositePass(RenderPass):
      def __init__(self, width, height):
-         super().__init__("composite", width, height)
+         super().__init__("composite", width, height, 999)
  
          self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
          self._gl = OpenGL.getInstance().getBindingsObject()
          self._renderer = Application.getInstance().getRenderer()
  
+         self._layer_bindings = [ "default", "selection" ]
+ 
      def setCompositeShader(self, shader):
          self._shader = shader
  
-     def renderContents(self):
-         pass
+     def setLayerBindings(self, bindings):
+         self._layer_bindings = bindings
  
-     def renderOutput(self):
+     def render(self):
          self._shader.bind()
  
          texture_unit = 0
+         for binding in self._layer_bindings:
-         for render_pass in self._renderer.getRenderPasses():
+             render_pass = self._renderer.getRenderPass(binding)
-             self._gl.glActiveTexture(texture_unit)
+             if not render_pass:
+                 continue
+ 
+             self._gl.glActiveTexture(getattr(self._gl, "GL_TEXTURE{0}".format(texture_unit)))
              self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, render_pass.getTextureId())
              texture_unit += 1
  
-         self._renderer.renderQuad(self._shader)
+         self._renderer.renderFullScreenQuad(self._shader)
  
          for i in range(texture_unit):
-             self._gl.glActiveTexture(texture_unit)
+             self._gl.glActiveTexture(getattr(self._gl, "GL_TEXTURE{0}".format(i)))
              self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, 0)
  
          self._shader.release()
  
Add explicit render layer binding instead of assuming all render passes can be used for compositing
## Code Before:

from UM.Application import Application
from UM.Resources import Resources

from UM.Math.Matrix import Matrix

from UM.View.RenderPass import RenderPass
from UM.View.GL.OpenGL import OpenGL

class CompositePass(RenderPass):
    def __init__(self, width, height):
        super().__init__("composite", width, height)

        self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
        self._gl = OpenGL.getInstance().getBindingsObject()
        self._renderer = Application.getInstance().getRenderer()

    def setCompositeShader(self, shader):
        self._shader = shader

    def renderContents(self):
        pass

    def renderOutput(self):
        self._shader.bind()

        texture_unit = 0
        for render_pass in self._renderer.getRenderPasses():
            self._gl.glActiveTexture(texture_unit)
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, render_pass.getTextureId())
            texture_unit += 1

        self._renderer.renderQuad(self._shader)

        for i in range(texture_unit):
            self._gl.glActiveTexture(texture_unit)
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, 0)

        self._shader.release()

## Instruction:
Add explicit render layer binding instead of assuming all render passes can be used for compositing
## Code After:

from UM.Application import Application
from UM.Resources import Resources

from UM.Math.Matrix import Matrix

from UM.View.RenderPass import RenderPass
from UM.View.GL.OpenGL import OpenGL

class CompositePass(RenderPass):
    def __init__(self, width, height):
        super().__init__("composite", width, height, 999)

        self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "composite.shader"))
        self._gl = OpenGL.getInstance().getBindingsObject()
        self._renderer = Application.getInstance().getRenderer()

        self._layer_bindings = [ "default", "selection" ]

    def setCompositeShader(self, shader):
        self._shader = shader

    def setLayerBindings(self, bindings):
        self._layer_bindings = bindings

    def render(self):
        self._shader.bind()

        texture_unit = 0
        for binding in self._layer_bindings:
            render_pass = self._renderer.getRenderPass(binding)
            if not render_pass:
                continue

            self._gl.glActiveTexture(getattr(self._gl, "GL_TEXTURE{0}".format(texture_unit)))
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, render_pass.getTextureId())
            texture_unit += 1

        self._renderer.renderFullScreenQuad(self._shader)

        for i in range(texture_unit):
            self._gl.glActiveTexture(getattr(self._gl, "GL_TEXTURE{0}".format(i)))
            self._gl.glBindTexture(self._gl.GL_TEXTURE_2D, 0)

        self._shader.release()
