SummerDay/addons/summer_day/data/document/table.gd

47 lines
964 B
GDScript

tool
extends Resource
class_name SummerDayTable
export(int) var allocation_size # How many matrices per frame.
export(ImageTexture) var texture
export(Image) var image
var dirty_flag = false
func create():
var row_size = allocation_size * 4
image.create(row_size, 1, false, Image.FORMAT_RGBAF)
texture.create_from_image(image, 0)
_presage_changes()
for i in range(row_size):
image.set_pixel(i, 0,
Color(1.0, 0.0, 0.0))
flush()
# Position in matrix-indices, not in pixels.
func apply_matrix(matrix: SummerDayMatrix4, row: int, position: int):
_presage_changes()
var color_list = matrix.get_values_as_colors()
for i in range(4):
image.set_pixel(
position * 4 + i,
row, color_list[i]
)
func flush():
if dirty_flag:
image.unlock()
texture.set_data(image)
dirty_flag = false
# This needs to be called BEFORE anything, that makes changes to the image!
func _presage_changes():
if !dirty_flag:
image.lock()
dirty_flag = true