8000 Remove geo shader for points and rectangles by einarf · Pull Request #2713 · pythonarcade/arcade · GitHub
[go: up one dir, main page]

Skip to content

Remove geo shader for points and rectangles #2713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions arcade/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def __init__(
self.shape_rectangle_filled_unbuffered_program = self.load_program(
vertex_shader=":system:shaders/shapes/rectangle/filled_unbuffered_vs.glsl",
fragment_shader=":system:shaders/shapes/rectangle/filled_unbuffered_fs.glsl",
geometry_shader=":system:shaders/shapes/rectangle/filled_unbuffered_geo.glsl",
)

# Atlas shaders
self.atlas_resize_program: Program = self.load_program(
# NOTE: This is the geo shader version of the atlas resize program.
Expand Down Expand Up @@ -253,9 +253,36 @@ def __init__(
)
# rectangle filled
self.shape_rectangle_filled_unbuffered_buffer = self.buffer(reserve=8)
# fmt: off
self.shape_rectangle_filled_unbuffered_geometry: Geometry = self.geometry(
[BufferDescription(self.shape_rectangle_filled_unbuffered_buffer, "2f", ["in_vert"])]
[
# Instanced quad (triangle strip)
BufferDescription(
self.buffer(
data=array(
"f",
[
-0.5, +0.5, # Upper left
-0.5, -0.5, # lower left
+0.5, +0.5, # upper right
+0.5, -0.5, # lower right
],
)
),
"2f",
["in_vert"],
),
# Per instance data
BufferDescription(
self.shape_rectangle_filled_unbuffered_buffer,
"2f",
["in_instance_pos"],
instanced=True
),
],
mode=self.TRIANGLE_STRIP,
)
# fmt: on
self.geometry_empty: Geometry = self.geometry()

self._atlas: TextureAtlasBase | None = None
Expand Down
3 changes: 1 addition & 2 deletions arcade/draw/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def draw_points(point_list: Point2List, color: RGBOrA255, size: float = 1.0) ->

# Resize buffer
data_size = num_points * 8
# if data_size > buffer.size:
buffer.orphan(size=data_size)

ctx.enable(ctx.BLEND)
Expand All @@ -79,6 +78,6 @@ def draw_points(point_list: Point2List, color: RGBOrA255, size: float = 1.0) ->
buffer.write(data=point_array)

# Only render the # of points we have complete data for
geometry.render(program, mode=ctx.POINTS, vertices=data_size // 8)
geometry.render(program, instances=num_points)

ctx.disable(ctx.BLEND)
2 changes: 1 addition & 1 deletion arcade/draw/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def draw_rect_filled(rect: Rect, color: RGBOrA255, tilt_angle: float = 0) -> Non
buffer.orphan()
buffer.write(data=array.array("f", (rect.x, rect.y)))

geometry.render(program, mode=ctx.POINTS, vertices=1)
geometry.render(program, instances=1)

ctx.disable(ctx.BLEND)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
#version 330

uniform WindowBlock {
mat4 projection;
mat4 view;
} window;

// [w, h, tilt]
uniform vec3 shape;

in vec2 in_vert;
in vec2 in_instance_pos;

void main() {
gl_Position = vec4(in_vert, 0.0, 1.0);
float angle = radians(shape.z);
mat2 rot = mat2(
cos(angle), -sin(angle),
sin(angle), cos(angle)
);
// vec2 size = shape.xy / 2.0;
mat4 mvp = window.projection * window.view;
vec2 pos = in_instance_pos + (in_vert * shape.xy);
gl_Position = mvp * vec4(rot * pos, 0.0, 1.0);
}
Loading
0