Ejemplo n.º 1
0
 def on_draw(self):
     self.clear()
     self.enable_3d()
     self.gamestate.draw_3d()
     self.enable_2d()
     self.gamestate.draw_2d()
     gl.glFinish()
Ejemplo n.º 2
0
    def on_draw(self):
        gl.glEnable(gl.GL_DEPTH_TEST)
        self.shader.use()
        self.player.update_matrices()

        while len(self.fences) > self.options.MAX_CPU_AHEAD_FRAMES:
            fence = self.fences.popleft()
            gl.glClientWaitSync(fence, gl.GL_SYNC_FLUSH_COMMANDS_BIT,
                                2147483647)
            gl.glDeleteSync(fence)

        self.window.clear()
        self.world.prepare_rendering()
        self.world.draw()

        # Draw the F3 Debug screen
        if self.show_f3:
            self.draw_f3()

        # Draw pause menu
        if self.show_pause:
            self.draw_pause()

        # CPU - GPU Sync
        if not self.options.SMOOTH_FPS:
            self.fences.append(
                gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
        else:
            gl.glFinish()
Ejemplo n.º 3
0
 def on_draw():
     window.clear()
     gl.glLoadIdentity()
     gl.gluLookAt(0, 8, 8, 0, 0, 0, 0, 1, 0)
     gl.glRotatef(rot, 1, 0, 0)
     gl.glRotatef(rot/2, 0, 1, 0)
     batch.draw()
     gl.glFinish()
Ejemplo n.º 4
0
def updateStimText(stim,text=None):
    stime=core.getTime()*1000.0
    if text:    
        stim.setText(text)
    stim.draw()
    gl.glFinish()
    etime=core.getTime()*1000.0 
    return etime-stime
Ejemplo n.º 5
0
def updateStimText(stim,text=None):
    """
    Function used by all text stim types for redrawing the stim.
    
    Update the text for the stim type assigned to 'stim', call stim.draw(),
    and ensure that all graphics card operations are complete before returning
    the time (in msec) taken to run the update logic. If 'text' is None, just 
    time the call to stim.draw(). 
    """
    stime=core.getTime()*1000.0
    if text:    
        stim.setText(text)
    stim.draw()
    gl.glFinish()
    etime=core.getTime()*1000.0 
    return etime-stime
Ejemplo n.º 6
0
def updateStimText(stim,text=None):
    """
    Function used by all text stim types for redrawing the stim.
    
    Update the text for the stim type assigned to 'stim', call stim.draw(),
    and ensure that all graphics card operations are complete before returning
    the time (in msec) taken to run the update logic. If 'text' is None, just 
    time the call to stim.draw(). 
    """
    stime=core.getTime()*1000.0
    if text:    
        stim.setText(text)
    stim.draw()
    gl.glFinish()
    etime=core.getTime()*1000.0 
    return etime-stime
Ejemplo n.º 7
0
	def on_draw(self):
		self.camera.update_matrices()

		# bind textures

		gl.glActiveTexture(gl.GL_TEXTURE0)
		gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.world.texture_manager.texture_array)
		gl.glUniform1i(self.shader_sampler_location, 0)

		# draw stuff

		gl.glEnable(gl.GL_DEPTH_TEST)
		gl.glEnable(gl.GL_CULL_FACE)

		gl.glClearColor(0.0, 0.0, 0.0, 1.0)
		self.clear()
		self.world.draw()

		gl.glFinish()
Ejemplo n.º 8
0
def render_to_texture(in_size, out_size, view_z=None):
    z0, z1 = (0, in_size[2]) if view_z == None else view_z
    vertices = (VERTEX * 6)(((-1, -1), (0, 0)), ((1, -1), (1, 0)),
                            ((1, 1), (1, 1)), ((1, 1), (1, 1)),
                            ((-1, 1), (0, 1)), ((-1, -1), (0, 0)))
    gl.glBindTexture(gl.GL_TEXTURE_3D, rendered_texture)
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, framebuffer)
    draw_buffers = (gl.GLenum * 1)(gl.GL_COLOR_ATTACHMENT0)
    gl.glDrawBuffers(1, draw_buffers)
    gl.glViewport(0, 0, out_size[0], out_size[1])
    gl.glUseProgram(render_program)
    loc_depth = gl.glGetUniformLocation(render_program,
                                        ctypes.create_string_buffer(b'depth'))
    loc_texelSize = gl.glGetUniformLocation(
        render_program, ctypes.create_string_buffer(b'texelSize'))
    gl.glUniform3f(loc_texelSize, 1 / in_size[0], 1 / in_size[1],
                   1 / in_size[2])
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, render_vertexbuffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(vertices), vertices,
                    gl.GL_DYNAMIC_DRAW)
    gl.glBindVertexArray(render_vao)
    gl.glClearColor(0.0, 0.0, 0.0, 0.0)
    for z in range(out_size[2]):
        gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER, gl.GL_COLOR_ATTACHMENT0,
                                  gl.GL_TEXTURE_3D, rendered_texture, 0, z)
        fbs = gl.glCheckFramebufferStatus(gl.GL_FRAMEBUFFER)
        assert fbs == gl.GL_FRAMEBUFFER_COMPLETE, 'FramebufferStatus is {}'.format(
            fbs)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glUniform1f(loc_depth,
                       (z0 + z * (z1 - z0)) / in_size[2] / out_size[2])
        gl.glBindTexture(gl.GL_TEXTURE_3D, input_texture)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
        if z % 10 == 0:
            gl.glFinish()
            print('\033[K{}/{}'.format(z, out_size[2] - 1), end='\r')
    gl.glFinish()

    gl.glBindVertexArray(0)
Ejemplo n.º 9
0
 def evolve(self, window):
     self.draw()
     gl.glFinish()
     self.current_approx.mutate()
     self.evolutions += 1
     self.current_approx.draw()
     gl.glFinish()
     if self.current_approx.fitness() >= self.best.fitness():
         self.best = self.current_approx.clone(start=self.best.start)
         self.best.draw()
         gl.glFinish()
         self.bene_evolutions += 1
     else:
         self.current_approx = self.best.clone(start=self.current_approx.start)
         self.current_approx.draw()
         gl.glFinish()
     logging.info("%s / %s" % (self.bene_evolutions, self.evolutions))
Ejemplo n.º 10
0
 def finish(self) -> None:
     """Wait until all OpenGL rendering commands are completed"""
     gl.glFinish()
Ejemplo n.º 11
0
    stim2_no_change_draw_times.clear()    
    demo_start=window.flip()     
    event.clearEvents()
    fcount=0

    stim1_type=stim1.__class__.__name__+u' '
    stim2_type=stim2.__class__.__name__+u' '
    while True:
        # For the textBox and TextStim resource, change the text every
        # chng_txt_each_flips, and record the time it takes to update the text
        # and redraw() each resource type.
        #
    
        # Make sure timing of stim is for the time taken for that stim alone. ;)
        gl.glFlush()
        gl.glFinish()
    
        if fcount==0 or fcount%chng_txt_each_flips==0:
            t=getRandomString(text_length)
            
            stim1_dur=updateStimText(stim1,stim1_type+t)
            stim1_txt_change_draw_times.append(stim1_dur)
            t=getRandomString(text_length)
            stim2_dur=updateStimText(stim2,stim2_type+t)
            stim2_txt_change_draw_times.append(stim2_dur)
        else:
            stim1_dur=updateStimText(stim1)
            stim1_no_change_draw_times.append(stim1_dur)
            stim2_dur=updateStimText(stim2)
            stim2_no_change_draw_times.append(stim2_dur)
            
Ejemplo n.º 12
0
    stim2_no_change_draw_times.clear()    
    demo_start=window.flip()     
    event.clearEvents()
    fcount=0

    stim1_type=stim1.__class__.__name__+u' '
    stim2_type=stim2.__class__.__name__+u' '
    while True:
        # For the textBox and TextStim resource, change the text every
        # chng_txt_each_flips, and record the time it takes to update the text
        # and redraw() each resource type.
        #
    
        # Make sure timing of stim is for the time taken for that stim alone. ;)
        gl.glFlush()
        gl.glFinish()
    
        if fcount==0 or fcount%chng_txt_each_flips==0:
            t=getRandomString(text_length)
            
            stim1_dur=updateStimText(stim1,stim1_type+t)
            stim1_txt_change_draw_times.append(stim1_dur)
            t=getRandomString(text_length)
            stim2_dur=updateStimText(stim2,stim2_type+t)
            stim2_txt_change_draw_times.append(stim2_dur)
        else:
            stim1_dur=updateStimText(stim1)
            stim1_no_change_draw_times.append(stim1_dur)
            stim2_dur=updateStimText(stim2)
            stim2_no_change_draw_times.append(stim2_dur)
            
Ejemplo n.º 13
0
 def on_draw(self,):
     self.clear()
     self.game.space.debug_draw()
     gl.glFinish()  # instead we should disable vsync
Ejemplo n.º 14
0
    def on_draw(self):

        gl.glClearBufferfv(gl.GL_COLOR, 0, BG_COLOR)

        if self.drawing:

            window_size = self.get_pixel_aligned_size()
            w, h = self.drawing.size

            vm = (gl.GLfloat * 16)(*make_view_matrix(
                window_size, self.drawing.size, self.zoom, self.offset))
            offscreen_buffer = render_drawing(self.drawing,
                                              self.highlighted_layer)

            ww, wh = window_size
            gl.glViewport(0, 0, int(ww), int(wh))

            # Draw a background rectangle
            with self.vao, self.copy_program:
                gl.glUniformMatrix4fv(0, 1, gl.GL_FALSE,
                                      (gl.GLfloat * 16)(*vm))
                if self.drawing and self.drawing.grid:
                    with self.get_background_texture(
                            self.drawing.palette.colors[0], 0.9):
                        gw, gh = self.drawing.grid_size
                        gl.glUniform2f(1, w / (gw * 2), h / (gh * 2))
                        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
                        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
                else:
                    #gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
                    # r, g, b, _ = self.drawing.palette.get_color_as_float(self.drawing.palette.colors[0])
                    # gl.glClearColor(r, g, b, 1)
                    # TODO should fill with color 0 here!
                    # gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
                    with self.get_background_texture(
                            self.drawing.palette.colors[0], 1):
                        gw, gh = self.drawing.grid_size
                        gl.glUniform2f(1, w / (gw * 2), h / (gh * 2))
                        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
                        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)

                with offscreen_buffer["color"]:
                    gl.glUniform2f(1, 1, 1)
                    gl.glEnable(gl.GL_BLEND)
                    gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
                    gl.glUniformMatrix4fv(0, 1, gl.GL_FALSE, vm)
                    gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)

            with self.line_program:
                with self.border_vao:
                    self.update_border(self.drawing.current.rect)
                    gl.glUniformMatrix4fv(0, 1, gl.GL_FALSE, vm)
                    # r, g, b, _ = self.drawing.palette.get_color_as_float(self.drawing.palette.colors[0])
                    # gl.glUniform3f(1, r, g, b)
                    # gl.glDrawArrays(gl.GL_TRIANGLE_FAN, 0, 4)
                    gl.glUniform3f(1, 0., 0., 0.)
                    gl.glLineWidth(1)
                    gl.glDrawArrays(gl.GL_LINE_LOOP, 0, 4)

                # Selection rectangle
                if self.stroke:
                    tool = self.stroke.tool
                    selection = ((tool and tool.show_rect and tool.rect)
                                 or self.selection)
                    if selection:
                        self.set_selection(selection)
                        with self.selection_vao:
                            gl.glUniformMatrix4fv(0, 1, gl.GL_FALSE, vm)
                            gl.glUniform3f(1, 1., 1., 0.)
                            gl.glLineWidth(1)
                            gl.glDrawArrays(gl.GL_LINE_LOOP, 0, 4)

        if not self.tablet.active:
            self._draw_mouse_cursor()

        ui.draw_ui(self)

        gl.glFinish(
        )  # No double buffering, to minimize latency (does this work?)
Ejemplo n.º 15
0
 def on_draw(self):
     self._render_view()
     self._render_gui()
     gl.glFinish(
     )  # TODO This seems important; figure out why and if it's the best way.