Skip to content

Commit dd8aa41

Browse files
committed
sprites pack would generate multiple textures. WIP
1 parent b875ea8 commit dd8aa41

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

src/entry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,8 @@ sokol_main(int argc, char* argv[]) {
851851
d.cleanup_cb = app_cleanup;
852852
d.event_cb = app_event;
853853
d.logger.func = log_func;
854-
d.win32_console_utf8 = 1;
855-
d.win32_console_attach = 1;
854+
d.win32.console_utf8 = 1;
855+
d.win32.console_attach = 1;
856856
d.alpha = 0;
857857

858858
// init L

src/service/loader.lua

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,26 @@ function S.loadbundle(filename)
4949
return b
5050
end
5151

52-
-- todo: packing should be out of loader
5352
function S.pack()
5453
local texid, n = sprite_bank:pack()
55-
56-
local r = sprite_bank:altas(texid)
57-
for id,v in pairs(r) do
58-
local x = v >> 32
59-
local y = v & 0xffffffff
60-
local obj = sprite[id]
61-
local c = filecache[obj.filename]
62-
local data = image.canvas(c.data, c.w, c.h, obj.cx, obj.cy, obj.cw, obj.ch)
63-
local w, h, ptr = image.canvas_size(data)
64-
r[id] = { id = id, data = ptr, x = x, y = y, w = w, h = h, stride = c.w * 4, dx = obj.x, dy = obj.y }
54+
-- upload rects into n textures, [texid, texid + n)
55+
local results = {}
56+
local texid_from = texid
57+
for i = 1, n do
58+
local r = sprite_bank:altas(texid)
59+
for id,v in pairs(r) do
60+
local x = v >> 32
61+
local y = v & 0xffffffff
62+
local obj = sprite[id]
63+
local c = filecache[obj.filename]
64+
local data = image.canvas(c.data, c.w, c.h, obj.cx, obj.cy, obj.cw, obj.ch)
65+
local w, h, ptr = image.canvas_size(data)
66+
r[id] = { id = id, data = ptr, x = x, y = y, w = w, h = h, stride = c.w * 4, dx = obj.x, dy = obj.y }
67+
end
68+
texid = texid + 1
69+
results[i] = r
6570
end
66-
return r
71+
return results, texid_from
6772
end
6873

6974
function S.write(id, filename)

src/service/render.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function S.app(settings)
141141
end
142142
end
143143

144+
-- todo: update mutiple images
144145
local update_image
145146
local function delay_update_image(imgmem)
146147
function update_image()
@@ -229,7 +230,9 @@ end
229230
function S.load_sprites(name)
230231
local loader = ltask.uniqueservice "loader"
231232
local spr = ltask.call(loader, "loadbundle", name)
232-
local rect = ltask.call(loader, "pack")
233+
local rects = ltask.call(loader, "pack")
234+
-- todo : load multiple textures
235+
local rect = rects[1]
233236

234237
local imgmem = image.new(setting.texture_size, setting.texture_size)
235238
local canvas = imgmem:canvas()

0 commit comments

Comments
 (0)