Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
- Added unit tests for the shaders module
- Cleaned up Program
- Cleaned up Buffer
- Buffer now has an easy to use read and write method
- Buffer.orphan now takes a size
- Context now stores commonly used enums such as texture parameters and primitivs modes

- Added Buffer.copy_from_buffer() to have a common place for this operation. buffered_draw_commands will now use this.
- Updated experimental examples
  • Loading branch information
einarf committed Apr 9, 2020
1 parent 323b8ab commit f112343
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 83 deletions.
11 changes: 3 additions & 8 deletions arcade/buffered_draw_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ def __init__(self):
"""
Initialize the sprite list
"""
# The context this shape list belongs to
self.ctx = get_window().ctx
# List of sprites in the sprite list
self.shape_list = []
Expand Down Expand Up @@ -603,19 +604,13 @@ def remove(self, item: TShape):
def _refresh_shape(self, group):
# Create a buffer large enough to hold all the shapes buffers
batch = self.batches[group]

total_vbo_bytes = sum(s.vbo.size for s in batch.items)
vbo = self.ctx.buffer(reserve=total_vbo_bytes)
offset = 0
gl.glBindBuffer(gl.GL_COPY_WRITE_BUFFER, vbo.buffer_id)
# Copy all the shapes buffer in our own vbo
for shape in batch.items:
gl.glBindBuffer(gl.GL_COPY_READ_BUFFER, shape.vbo.buffer_id)
gl.glCopyBufferSubData(
gl.GL_COPY_READ_BUFFER,
gl.GL_COPY_WRITE_BUFFER,
gl.GLintptr(0),
gl.GLintptr(offset),
shape.vbo.size)
vbo.copy_from_buffer(shape.vbo, offset=offset)
offset += shape.vbo.size

# Create an index buffer object. It should count starting from 0. We need to
Expand Down
4 changes: 2 additions & 2 deletions arcade/experimental/shapes_buffered_2_glow.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def __init__(self, width, height, title):

arcade.set_background_color(arcade.color.BLACK)

self.offscreen = shader.Framebuffer(
color_attachments=shader.Texture((SCREEN_WIDTH, SCREEN_HEIGHT), 4, wrap_x=gl.GL_CLAMP_TO_EDGE, wrap_y=gl.GL_CLAMP_TO_EDGE))
self.offscreen = self.ctx.framebuffer(
color_attachments=self.ctx.texture((SCREEN_WIDTH, SCREEN_HEIGHT), 4, wrap_x=gl.GL_CLAMP_TO_EDGE, wrap_y=gl.GL_CLAMP_TO_EDGE))
self.glow = postprocessing.Glow((SCREEN_WIDTH // 8, SCREEN_HEIGHT // 8))

def on_draw(self):
Expand Down
6 changes: 3 additions & 3 deletions arcade/experimental/sprite_collect_coins_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def on_draw(self):
self.blur_fs.program['blur'] = 1
self.blur_fs.render()

# self.color_attachment.use(0)
# self.quad_fs.program['blur'] = 0
# self.quad_fs.render()
self.color_attachment.use(0)
self.quad_fs.program['blur'] = 0
self.quad_fs.render()

self.player_list.draw()

Expand Down
Loading

0 comments on commit f112343

Please sign in to comment.