Skip to content

Commit

Permalink
Preload ShapeElementList program
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Apr 8, 2020
1 parent 00e32b6 commit 2aa7ae9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
31 changes: 1 addition & 30 deletions arcade/buffered_draw_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,36 +577,7 @@ def __init__(self):
self._center_x = 0
self._center_y = 0
self._angle = 0
self.program = self.ctx.program(
vertex_shader='''
#version 330
uniform mat4 Projection;
uniform vec2 Position;
uniform float Angle;
in vec2 in_vert;
in vec4 in_color;
out vec4 v_color;
void main() {
float angle = radians(Angle);
mat2 rotate = mat2(
cos(angle), sin(angle),
-sin(angle), cos(angle)
);
gl_Position = Projection * vec4(Position + (rotate * in_vert), 0.0, 1.0);
v_color = in_color;
}
''',
fragment_shader='''
#version 330
in vec4 v_color;
out vec4 f_color;
void main() {
f_color = v_color;
}
''',
)
self.program = self.ctx.shape_element_list_program
# Could do much better using just one vbo and glDrawElementsBaseVertex
self.batches = defaultdict(_Batch)
self.dirties = set()
Expand Down
8 changes: 8 additions & 0 deletions arcade/resources/shaders/shape_element_list_fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 330

in vec4 v_color;
out vec4 f_color;

void main() {
f_color = v_color;
}
20 changes: 20 additions & 0 deletions arcade/resources/shaders/shape_element_list_vs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#version 330

uniform mat4 Projection;
uniform vec2 Position;
uniform float Angle;

in vec2 in_vert;
in vec4 in_color;

out vec4 v_color;

void main() {
float angle = radians(Angle);
mat2 rotate = mat2(
cos(angle), sin(angle),
-sin(angle), cos(angle)
);
gl_Position = Projection * vec4(Position + (rotate * in_vert), 0.0, 1.0);
v_color = in_color;
}
4 changes: 4 additions & 0 deletions arcade/shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,10 @@ def __init__(self, window):
self.resource_root / 'shaders/line_generic_with_colors_vs.glsl',
self.resource_root / 'shaders/line_generic_with_colors_fs.glsl',
)
self.shape_element_list_program = self.load_program(
self.resource_root / 'shaders/shape_element_list_vs.glsl',
self.resource_root / 'shaders/shape_element_list_fs.glsl',
)

@property
def gl_version(self):
Expand Down

0 comments on commit 2aa7ae9

Please sign in to comment.