Exemplo n.º 1
0
 def on_paint(self, event):
     
     w,h = W, H
     scale = 1
     aakernel = None
     if self._technique == 'ssaa':
         scale = 3  # Make this 2, 3, 4 ... for 4x, 9x, 16x aa
         w, h = W*scale, H*scale
     
     # Set up FBO
     fb = FrameBuffer(w, h)
     tex = RenderTexture(2)
     tex.create_empty_texture(w, h) # Must match depth buffer!
     fb.attach_texture(tex)
     fb.add_depth_buffer()
     fb.check()
     
     # Draw scene off-screen
     fb.enable()
     gl.glClearColor(1,1,1,1);
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     self.setup_scene(0, 0, w, h)
     if self._preaa:
         render_scene(True, scale)
     else:
         render_scene(False, scale)
     fb.disable()
     
     # Pergorm aa
     if self._technique == 'ssaa':
         self._pass_ssaa(tex, w, h, scale)
     elif self._technique == 'smaa':
         self._pass_smaa(tex)
     else:
         self._pass_aa(tex)
     
     # Draw original to screen too
     self.setup_scene(W, 0, W, H)
     render_scene()
     
     # And original but smoothed
     self.setup_scene(2*W, 0, W, H)
     render_scene(smooth=True)
     
     # Now blit texture to backbuffer
     self._backend._vispy_swap_buffers() # todo: private attr!
Exemplo n.º 2
0
    def on_paint(self, event):

        w, h = W, H
        scale = 1
        aakernel = None
        if self._technique == 'ssaa':
            scale = 3  # Make this 2, 3, 4 ... for 4x, 9x, 16x aa
            w, h = W * scale, H * scale

        # Set up FBO
        fb = FrameBuffer(w, h)
        tex = RenderTexture(2)
        tex.create_empty_texture(w, h)  # Must match depth buffer!
        fb.attach_texture(tex)
        fb.add_depth_buffer()
        fb.check()

        # Draw scene off-screen
        fb.enable()
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        self.setup_scene(0, 0, w, h)
        if self._preaa:
            render_scene(True, scale)
        else:
            render_scene(False, scale)
        fb.disable()

        # Pergorm aa
        if self._technique == 'ssaa':
            self._pass_ssaa(tex, w, h, scale)
        elif self._technique == 'smaa':
            self._pass_smaa(tex)
        else:
            self._pass_aa(tex)

        # Draw original to screen too
        self.setup_scene(W, 0, W, H)
        render_scene()

        # And original but smoothed
        self.setup_scene(2 * W, 0, W, H)
        render_scene(smooth=True)

        # Now blit texture to backbuffer
        self._backend._vispy_swap_buffers()  # todo: private attr!
Exemplo n.º 3
0
    def paintGL(self):
#         self._paint()
#         return
        
        W, H = self.width(), self.height()
        
        # Set up FBO
        fb = FrameBuffer(W, H)
        tex = RenderTexture(2)
        tex.create_empty_texture(W, H) # Must match depth buffer!
        fb.attach_texture(tex)
        fb.add_depth_buffer()
        fb.check()
        
        # Draw scene to off-screen buffer
        fb.enable()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        self._setup_scene(0,0,W,H)
        self._paint()
        fb.disable()
        
    
        # Draw texture to screen
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        self._setup_scene(0,0,W,H)
        tex.Enable(0)
        self._aaShader.bind()
        #shader.uniformi('texture', tex._texId)
        self._aaShader.uniformf('shape', W, H)
        self._aaShader.uniformi('texture', 0)
        
        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord(0,0); gl.glVertex(0,0); 
        gl.glTexCoord(0,1); gl.glVertex(0,1); 
        gl.glTexCoord(1,1); gl.glVertex(1,1); 
        gl.glTexCoord(1,0); gl.glVertex(1,0); 
        gl.glEnd()
        self._aaShader.unbind()
        tex.Disable()
Exemplo n.º 4
0
 def on_paint(self, event):
     
     w,h = W, H
     scale = 1
     aakernel = None
     if self._technique == 'ssaa':
         scale = 3  # Make this 2, 3, 4 ... for 4x, 9x, 16x aa
         w, h = W*scale, H*scale
     
     # Set up FBO
     if hasattr(self, '_fb'):
         fb = self._fb
         tex = self._tex
     else:
         fb = FrameBuffer(w, h)
         tex = RenderTexture(2)
         tex.create_empty_texture(w, h) # Must match depth buffer!
         fb.attach_texture(tex)
         fb.add_depth_buffer()
         fb.check()
         #
         self._fb = fb
         self._tex = tex
     
     # Draw scene off-screen
     fb.enable()
     gl.glClearColor(1,1,1,1);
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     self.setup_scene(0, 0, w, h)
     if self._preaa:
         self._draw_stars(True, scale)
     else:
         self._draw_stars(False, scale)
     fb.disable()
     
     # Pergorm aa
     if self._raw:
         # Prepare for drawing texture to screen
         gl.glClearColor(1,1,1,1);
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         self.setup_scene(0, 0, W, H)
         tex.Enable(0)
         # Draw texture to screen
         gl.glBegin(gl.GL_QUADS)
         gl.glTexCoord(0,0); gl.glVertex(0,0); 
         gl.glTexCoord(0,1); gl.glVertex(0,1); 
         gl.glTexCoord(1,1); gl.glVertex(1,1); 
         gl.glTexCoord(1,0); gl.glVertex(1,0); 
         gl.glEnd()
         tex.Disable()
     elif self._technique == 'ssaa':
         self._pass_ssaa(tex, w, h, scale)
     elif self._technique == 'smaa':
         self._pass_smaa(tex)
     else:
         self._pass_aa(tex)
     
     # Now blit texture to backbuffer
     self._backend._vispy_swap_buffers()
     
     # Prepare for next round
     self._a += 0.005
     self.update()
Exemplo n.º 5
0
    def on_paint(self, event):

        w, h = W, H
        scale = 1
        aakernel = None
        if self._technique == 'ssaa':
            scale = 3  # Make this 2, 3, 4 ... for 4x, 9x, 16x aa
            w, h = W * scale, H * scale

        # Set up FBO
        if hasattr(self, '_fb'):
            fb = self._fb
            tex = self._tex
        else:
            fb = FrameBuffer(w, h)
            tex = RenderTexture(2)
            tex.create_empty_texture(w, h)  # Must match depth buffer!
            fb.attach_texture(tex)
            fb.add_depth_buffer()
            fb.check()
            #
            self._fb = fb
            self._tex = tex

        # Draw scene off-screen
        fb.enable()
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        self.setup_scene(0, 0, w, h)
        if self._preaa:
            self._draw_stars(True, scale)
        else:
            self._draw_stars(False, scale)
        fb.disable()

        # Pergorm aa
        if self._raw:
            # Prepare for drawing texture to screen
            gl.glClearColor(1, 1, 1, 1)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            self.setup_scene(0, 0, W, H)
            tex.Enable(0)
            # Draw texture to screen
            gl.glBegin(gl.GL_QUADS)
            gl.glTexCoord(0, 0)
            gl.glVertex(0, 0)
            gl.glTexCoord(0, 1)
            gl.glVertex(0, 1)
            gl.glTexCoord(1, 1)
            gl.glVertex(1, 1)
            gl.glTexCoord(1, 0)
            gl.glVertex(1, 0)
            gl.glEnd()
            tex.Disable()
        elif self._technique == 'ssaa':
            self._pass_ssaa(tex, w, h, scale)
        elif self._technique == 'smaa':
            self._pass_smaa(tex)
        else:
            self._pass_aa(tex)

        # Now blit texture to backbuffer
        self._backend._vispy_swap_buffers()

        # Prepare for next round
        self._a += 0.005
        self.update()