Created
July 16, 2025 03:40
-
-
Save KonnorRogers/6337311772ee53733d14a520d79ca4d5 to your computer and use it in GitHub Desktop.
Draw Buffering for Dragon Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DrawBuffer | |
attr_accessor :primitives, :outputs, :render_targets | |
def initialize | |
@primitives = [] | |
@render_targets = {} | |
end | |
def [](key) | |
@render_targets[key] = [] if !@render_targets.has_key?(key) | |
@render_targets[key] | |
end | |
def []=(key, value) | |
@render_targets[key] = value | |
end | |
def flush | |
@render_targets.each do |key, value| | |
@outputs[key].primitives.concat(value) | |
end | |
@outputs.primitives.concat(@primitives) | |
@primitives = [] | |
@render_targets = {} | |
end | |
end | |
def tick(args) | |
args.state.draw_buffer ||= DrawBuffer.new | |
draw_buffer = args.state.draw_buffer | |
draw_buffer.outputs = args.outputs | |
draw_buffer.primitives << { | |
x: args.grid.w / 2, | |
y: args.grid.h / 2, | |
text: "Hello World" | |
}.label! | |
render_target = args.outputs[:render_target] | |
render_target.w = 200 | |
render_target.h = 40 | |
draw_buffer.primitives << { | |
x: args.grid.w / 2, | |
y: (args.grid.h / 2) - 80, | |
w: 200, | |
h: render_target.h, | |
path: :render_target | |
} | |
draw_buffer[:render_target] << { | |
x: 0, | |
y: 0, | |
anchor_y: -0.5, | |
text: "Hello from a render target" | |
}.label! | |
draw_buffer.flush | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment