

def draw(self):
    if self._glsl:
        fragment = (fragment_template % self._glsl)
        self._glsl = None
        frag_handle = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
        gl.glShaderSource(frag_handle, fragment)
        gl.glCompileShader(frag_handle)
        status = gl.glGetShaderParameter(frag_handle, gl.GL_COMPILE_STATUS)
        if (not status):
            errors = gl.glGetShaderInfoLog(frag_handle)
            errors = self.process_errors(errors)
            print('Shader failed to compile:', file=sys.stderr)
            print(errors, file=sys.stderr)
            self._glsl = error_shader
            self.update()
        else:
            self.program.set_shaders(vertex, fragment)
        gl.glDeleteShader(frag_handle)
    if self._interactive:
        self.program.draw()
        if (self._ffmpeg_pipe is not None):
            img = _screenshot()
            self.write_video_frame(img)
        self._render_frame_index += 1
        if ((self._render_frame_count is not None) and (self._render_frame_index >= self._render_frame_count)):
            app.quit()
            return
        self.advance_time()
    else:
        with self._fbo:
            rs = list(self._render_size)
            if ((self._tile_coord[0] + rs[0]) > self._output_size[0]):
                rs[0] = (self._output_size[0] - self._tile_coord[0])
            if ((self._tile_coord[1] + rs[1]) > self._output_size[1]):
                rs[1] = (self._output_size[1] - self._tile_coord[1])
            gloo.set_viewport(0, 0, *rs)
            self.program['iOffset'] = self._tile_coord
            self.program.draw()
            img = _screenshot()
            row = ((self._output_size[1] - self._tile_coord[1]) - rs[1])
            col = self._tile_coord[0]
            self._img[row:(row + rs[1]), col:(col + rs[0]), :] = img

dataset/ETHPy150Open alexjc/shadertoy-render/shadertoy-render.py RenderingCanvas.draw/original