Skip to content

Commit 3650bc7

Browse files
committed
Add bgfx.memory_buffer bgfx.vertex_convert bgfx.calc_tangent
1 parent 3a8d065 commit 3650bc7

16 files changed

+485
-599
lines changed

Diff for: 01-cubes.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ function ctx.init()
4747
{ "POSITION", 3, "FLOAT" },
4848
{ "COLOR0", 4, "UINT8", true },
4949
}
50-
ctx.vb = bgfx.create_vertex_buffer({
51-
"fffd",
50+
ctx.vb = bgfx.create_vertex_buffer(bgfx.memory_buffer("fffd", {
5251
-1.0, 1.0, 1.0, 0xff000000,
5352
1.0, 1.0, 1.0, 0xff0000ff,
5453
-1.0, -1.0, 1.0, 0xff00ff00,
@@ -57,8 +56,7 @@ function ctx.init()
5756
1.0, 1.0, -1.0, 0xffff00ff,
5857
-1.0, -1.0, -1.0, 0xffffff00,
5958
1.0, -1.0, -1.0, 0xffffffff,
60-
},
61-
ctx.vdecl)
59+
}), ctx.vdecl)
6260
ctx.ib = bgfx.create_index_buffer{
6361
0, 1, 2, 3, 7, 1, 5, 0, 4, 2, 6, 7, 4, 5,
6462
}

Diff for: 05-instancing.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ function ctx.init()
6161
{ "POSITION", 3, "FLOAT" },
6262
{ "COLOR0", 4, "UINT8", true },
6363
}
64-
ctx.vb = bgfx.create_vertex_buffer({
65-
"fffd",
64+
ctx.vb = bgfx.create_vertex_buffer(bgfx.memory_buffer("fffd", {
6665
-1.0, 1.0, 1.0, 0xff000000,
6766
1.0, 1.0, 1.0, 0xff0000ff,
6867
-1.0, -1.0, 1.0, 0xff00ff00,
@@ -71,8 +70,7 @@ function ctx.init()
7170
1.0, 1.0, -1.0, 0xffff00ff,
7271
-1.0, -1.0, -1.0, 0xffffff00,
7372
1.0, -1.0, -1.0, 0xffffffff,
74-
},
75-
ctx.vdecl)
73+
}), ctx.vdecl)
7674
ctx.ib = bgfx.create_index_buffer{
7775
0, 1, 2, -- 0
7876
1, 3, 2,

Diff for: 06-bump.lua

+32-30
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function ctx.init()
9191
MSAA = true,
9292
}
9393

94-
local s_cubeIndices = {
94+
local s_cubeIndices = bgfx.memory_buffer( "s", {
9595
0, 2, 1,
9696
1, 2, 3,
9797
4, 5, 6,
@@ -106,38 +106,40 @@ function ctx.init()
106106
17, 18, 19,
107107
20, 21, 22,
108108
21, 23, 22,
109-
}
109+
} )
110110

111111
local encodeNormalRgba8 = bgfxu.encodeNormalRgba8
112112

113-
ctx.vb = bgfx.create_vertex_buffer({
114-
"fffddss",
115-
-1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0, 0 ,
116-
1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0x7fff, 0 ,
117-
-1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0, 0x7fff ,
118-
1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0x7fff, 0x7fff ,
119-
-1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0, 0 ,
120-
1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0x7fff, 0 ,
121-
-1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0, 0x7fff ,
122-
1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0x7fff, 0x7fff ,
123-
-1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0, 0 ,
124-
1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0x7fff, 0 ,
125-
-1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0, 0x7fff ,
126-
1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0x7fff, 0x7fff ,
127-
-1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0, 0 ,
128-
1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0x7fff, 0 ,
129-
-1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0, 0x7fff ,
130-
1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0x7fff, 0x7fff ,
131-
1.0, -1.0, 1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0, 0 ,
132-
1.0, 1.0, 1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0x7fff, 0 ,
133-
1.0, -1.0, -1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0, 0x7fff ,
134-
1.0, 1.0, -1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0x7fff, 0x7fff ,
135-
-1.0, -1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0, 0 ,
136-
-1.0, 1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0x7fff, 0 ,
137-
-1.0, -1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0, 0x7fff ,
138-
-1.0, 1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0x7fff, 0x7fff ,
139-
},
140-
ctx.vdecl , "t" , s_cubeIndices)
113+
local s_cubeVertices = bgfx.memory_buffer( "fffddss" , {
114+
-1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0, 0 ,
115+
1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0x7fff, 0 ,
116+
-1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0, 0x7fff ,
117+
1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0x7fff, 0x7fff ,
118+
-1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0, 0 ,
119+
1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0x7fff, 0 ,
120+
-1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0, 0x7fff ,
121+
1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, 0.0, -1.0), 0, 0x7fff, 0x7fff ,
122+
-1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0, 0 ,
123+
1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0x7fff, 0 ,
124+
-1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0, 0x7fff ,
125+
1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0, 0x7fff, 0x7fff ,
126+
-1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0, 0 ,
127+
1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0x7fff, 0 ,
128+
-1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0, 0x7fff ,
129+
1.0, -1.0, -1.0, encodeNormalRgba8( 0.0, -1.0, 0.0), 0, 0x7fff, 0x7fff ,
130+
1.0, -1.0, 1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0, 0 ,
131+
1.0, 1.0, 1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0x7fff, 0 ,
132+
1.0, -1.0, -1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0, 0x7fff ,
133+
1.0, 1.0, -1.0, encodeNormalRgba8( 1.0, 0.0, 0.0), 0, 0x7fff, 0x7fff ,
134+
-1.0, -1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0, 0 ,
135+
-1.0, 1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0x7fff, 0 ,
136+
-1.0, -1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0, 0x7fff ,
137+
-1.0, 1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0x7fff, 0x7fff ,
138+
} )
139+
140+
bgfx.calc_tangent(s_cubeVertices, ctx.vdecl, s_cubeIndices)
141+
142+
ctx.vb = bgfx.create_vertex_buffer(s_cubeVertices, ctx.vdecl)
141143
ctx.ib = bgfx.create_index_buffer(s_cubeIndices)
142144
ctx.s_texColor = bgfx.create_uniform("s_texColor", "s")
143145
ctx.s_texNormal = bgfx.create_uniform("s_texNormal", "s")

Diff for: 13-stencil.lua

+6-9
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,7 @@ function ctx.init()
674674

675675
local encodeNormalRgba8 = bgfxu.encodeNormalRgba8
676676

677-
local s_cubeVertices = {
678-
"fffdff",
677+
local s_cubeVertices = bgfx.memory_buffer("fffdff", {
679678
-1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 1.0, 1.0 ,
680679
1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 0.0, 1.0 ,
681680
-1.0, 1.0, -1.0, encodeNormalRgba8( 0.0, 1.0, 0.0), 1.0, 0.0 ,
@@ -700,7 +699,7 @@ function ctx.init()
700699
-1.0, 1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0.0, 1.0 ,
701700
-1.0, -1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 1.0, 0.0 ,
702701
-1.0, -1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0.0, 0.0 ,
703-
}
702+
})
704703

705704
local s_cubeIndices = {
706705
0, 1, 2,
@@ -722,26 +721,24 @@ function ctx.init()
722721
ctx.m_cubeMesh = mesh(s_cubeVertices,s_cubeIndices)
723722

724723
local s_texcoord = 5.0
725-
local s_hplaneVertices = {
726-
"fffdff",
724+
local s_hplaneVertices = bgfx.memory_buffer("fffdff", {
727725
-1.0, 0.0, 1.0, encodeNormalRgba8(0.0, 1.0, 0.0), s_texcoord, s_texcoord ,
728726
1.0, 0.0, 1.0, encodeNormalRgba8(0.0, 1.0, 0.0), s_texcoord, 0.0 ,
729727
-1.0, 0.0, -1.0, encodeNormalRgba8(0.0, 1.0, 0.0), 0.0, s_texcoord ,
730728
1.0, 0.0, -1.0, encodeNormalRgba8(0.0, 1.0, 0.0), 0.0, 0.0 ,
731-
}
729+
})
732730

733731
local s_planeIndices = {
734732
0, 1, 2,
735733
1, 3, 2,
736734
}
737735

738-
local s_vplaneVertices = {
739-
"fffdff",
736+
local s_vplaneVertices = bgfx.memory_buffer("fffdff", {
740737
-1.0, 1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 1.0, 1.0 ,
741738
1.0, 1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 1.0, 0.0 ,
742739
-1.0, -1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 0.0, 1.0 ,
743740
1.0, -1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 0.0, 0.0 ,
744-
}
741+
})
745742

746743
ctx.m_hplaneMesh = mesh(s_hplaneVertices, s_planeIndices)
747744
ctx.m_vplaneMesh = mesh(s_vplaneVertices, s_planeIndices)

Diff for: 15-shadowmaps_simple.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,13 @@ function ctx.init()
132132

133133
local encodeNormalRgba8 = bgfxu.encodeNormalRgba8
134134

135-
ctx.m_vbh = bgfx.create_vertex_buffer(
136-
{ "fffd",
135+
ctx.m_vbh = bgfx.create_vertex_buffer( bgfx.memory_buffer( "fffd",
136+
{
137137
-1.0, 0.0, 1.0, encodeNormalRgba8(0.0, 1.0, 0.0),
138138
1.0, 0.0, 1.0, encodeNormalRgba8(0.0, 1.0, 0.0),
139139
-1.0, 0.0, -1.0, encodeNormalRgba8(0.0, 1.0, 0.0),
140140
1.0, 0.0, -1.0, encodeNormalRgba8(0.0, 1.0, 0.0),
141-
}
142-
, ctx.vdecl)
141+
} ) , ctx.vdecl)
143142

144143
ctx.m_ibh = bgfx.create_index_buffer {
145144
0, 1, 2,

Diff for: 16-shadowmaps.lua

+4-6
Original file line numberDiff line numberDiff line change
@@ -2061,20 +2061,18 @@ function ctx.init()
20612061

20622062
local s_texcoord = 5.0
20632063

2064-
local s_hplaneVertices = {
2065-
"fffdff",
2064+
local s_hplaneVertices = bgfx.memory_buffer ("fffdff", {
20662065
-1.0, 0.0, 1.0, encodeNormalRgba8(0.0, 1.0, 0.0), s_texcoord, s_texcoord,
20672066
1.0, 0.0, 1.0, encodeNormalRgba8(0.0, 1.0, 0.0), s_texcoord, 0.0 ,
20682067
-1.0, 0.0, -1.0, encodeNormalRgba8(0.0, 1.0, 0.0), 0.0, s_texcoord,
20692068
1.0, 0.0, -1.0, encodeNormalRgba8(0.0, 1.0, 0.0), 0.0, 0.0 ,
2070-
}
2071-
local s_vplaneVertices = {
2072-
"fffdff",
2069+
})
2070+
local s_vplaneVertices = bgfx.memory_buffer ("fffdff", {
20732071
-1.0, 1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 1.0, 1.0 ,
20742072
1.0, 1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 1.0, 0.0 ,
20752073
-1.0, -1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 0.0, 1.0 ,
20762074
1.0, -1.0, 0.0, encodeNormalRgba8(0.0, 0.0, -1.0), 0.0, 0.0 ,
2077-
}
2075+
})
20782076
local s_planeIndices = {
20792077
0, 1, 2,
20802078
1, 3, 2,

Diff for: 19-oit.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ function ctx.init()
214214
}
215215
ctx.tvb = bgfx.transient_buffer "fffdff"
216216

217-
ctx.vb = bgfx.create_vertex_buffer({
218-
"fffd",
217+
ctx.vb = bgfx.create_vertex_buffer(bgfx.memory_buffer("fffd", {
219218
-1.0, 1.0, 1.0, 0xff000000,
220219
1.0, 1.0, 1.0, 0xff0000ff,
221220
-1.0, -1.0, 1.0, 0xff00ff00,
@@ -224,8 +223,7 @@ function ctx.init()
224223
1.0, 1.0, -1.0, 0xffff00ff,
225224
-1.0, -1.0, -1.0, 0xffffff00,
226225
1.0, -1.0, -1.0, 0xffffffff,
227-
},
228-
ctx.PosColorVertex)
226+
}), ctx.PosColorVertex)
229227
ctx.ib = bgfx.create_index_buffer{
230228
0, 1, 2, -- 0
231229
1, 3, 2,

Diff for: 21-defered.lua

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local bgfxu = require "bgfx.util"
66
local util = require "util"
77
local math3d = require "math3d"
88

9+
local GC = function() collectgarbage() collectgarbage() end
10+
911
local ctx = {
1012
canvas = iup.canvas {},
1113
}
@@ -327,6 +329,8 @@ local function mainloop()
327329
end
328330
end
329331

332+
GC()
333+
330334
bgfx.frame()
331335
end
332336

@@ -366,8 +370,7 @@ function ctx.init()
366370

367371
local encodeNormalRgba8 = bgfxu.encodeNormalRgba8
368372

369-
local s_cubeVertices = {
370-
"fffddss",
373+
local s_cubeVertices = bgfx.memory_buffer("fffddss", {
371374
-1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0, 0,
372375
1.0, 1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0x7fff, 0,
373376
-1.0, -1.0, 1.0, encodeNormalRgba8( 0.0, 0.0, 1.0), 0, 0, 0x7fff,
@@ -392,8 +395,8 @@ function ctx.init()
392395
-1.0, 1.0, 1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0x7fff, 0,
393396
-1.0, -1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0, 0x7fff,
394397
-1.0, 1.0, -1.0, encodeNormalRgba8(-1.0, 0.0, 0.0), 0, 0x7fff, 0x7fff,
395-
}
396-
local s_cubeIndices = {
398+
})
399+
local s_cubeIndices = bgfx.memory_buffer("s", {
397400
0, 2, 1,
398401
1, 2, 3,
399402
4, 5, 6,
@@ -408,10 +411,12 @@ function ctx.init()
408411
17, 18, 19,
409412
20, 21, 22,
410413
21, 23, 22,
411-
}
414+
})
415+
416+
bgfx.calc_tangent(s_cubeVertices, ctx.PosNormalTangentTexcoordVertex, s_cubeIndices)
412417

413418
-- Create static vertex buffer.
414-
ctx.m_vbh = bgfx.create_vertex_buffer(s_cubeVertices, ctx.PosNormalTangentTexcoordVertex, "t", s_cubeIndices)
419+
ctx.m_vbh = bgfx.create_vertex_buffer(s_cubeVertices, ctx.PosNormalTangentTexcoordVertex)
415420
-- Create static index buffer.
416421
ctx.m_ibh = bgfx.create_index_buffer(s_cubeIndices)
417422

@@ -495,7 +500,7 @@ function ctx.resize(w,h)
495500
]]
496501
ctx.m_gbufferTex[1] = bgfx.create_texture2d(w, h, false, 1, "BGRA8" , samplerFlags)
497502
ctx.m_gbufferTex[2] = bgfx.create_texture2d(w, h, false, 1, "BGRA8" , samplerFlags)
498-
ctx.m_gbufferTex[3] = bgfx.create_texture2d(w, h, false, 1, "D24S8" , samplerFlags)
503+
ctx.m_gbufferTex[3] = bgfx.create_texture2d(w, h, false, 1, "D24S8" , samplerFlags)
499504
ctx.m_gbuffer = bgfx.create_frame_buffer(ctx.m_gbufferTex, true)
500505

501506
bgfx.destroy(ctx.m_lightBuffer)
@@ -517,4 +522,5 @@ end
517522
util.init(ctx)
518523
dlg:showxy(iup.CENTER,iup.CENTER)
519524
dlg.usersize = nil
525+
GC()
520526
util.run(mainloop)

Diff for: 22-windows.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ function ctx.init()
7272
{ "POSITION", 3, "FLOAT" },
7373
{ "COLOR0", 4, "UINT8", true },
7474
}
75-
ctx.vb = bgfx.create_vertex_buffer({
76-
"fffd",
75+
ctx.vb = bgfx.create_vertex_buffer(bgfx.memory_buffer("fffd", {
7776
-1.0, 1.0, 1.0, 0xff000000,
7877
1.0, 1.0, 1.0, 0xff0000ff,
7978
-1.0, -1.0, 1.0, 0xff00ff00,
@@ -82,8 +81,7 @@ function ctx.init()
8281
1.0, 1.0, -1.0, 0xffff00ff,
8382
-1.0, -1.0, -1.0, 0xffffff00,
8483
1.0, -1.0, -1.0, 0xffffffff,
85-
},
86-
ctx.vdecl)
84+
}) , ctx.vdecl)
8785
ctx.ib = bgfx.create_index_buffer{
8886
0, 1, 2, 3, 7, 1, 5, 0, 4, 2, 6, 7, 4, 5,
8987
}

Diff for: 24-nbody.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,12 @@ function ctx.init()
277277
}
278278

279279
-- Create static vertex buffer.
280-
ctx.m_vbh = bgfx.create_vertex_buffer( {
281-
"ff",
280+
ctx.m_vbh = bgfx.create_vertex_buffer(bgfx.memory_buffer("ff", {
282281
1.0, 1.0,
283282
-1.0, 1.0,
284283
-1.0, -1.0,
285284
1.0, -1.0,
286-
}, quadVertexDecl)
285+
}) , quadVertexDecl)
287286

288287
-- Create static index buffer.
289288
ctx.m_ibh = bgfx.create_index_buffer { 0, 1, 2, 2, 3, 0, }

Diff for: 26-occlusion.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ function ctx.init()
8787
{ "COLOR0", 4, "UINT8", true },
8888
}
8989

90-
ctx.vb = bgfx.create_vertex_buffer({
91-
"fffd",
90+
ctx.vb = bgfx.create_vertex_buffer(bgfx.memory_buffer("fffd", {
9291
-1.0, 1.0, 1.0, 0xff000000,
9392
1.0, 1.0, 1.0, 0xff0000ff,
9493
-1.0, -1.0, 1.0, 0xff00ff00,
@@ -97,8 +96,7 @@ function ctx.init()
9796
1.0, 1.0, -1.0, 0xffff00ff,
9897
-1.0, -1.0, -1.0, 0xffffff00,
9998
1.0, -1.0, -1.0, 0xffffffff,
100-
},
101-
ctx.VertexDecl)
99+
}), ctx.VertexDecl)
102100

103101
ctx.ib = bgfx.create_index_buffer{
104102
0, 1, 2, -- 0

Diff for: 30-picking.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ local function mainloop()
9999
local maxread = 0
100100
local ids, idc
101101
idc = 0
102-
for x = 1, ID_DIM * ID_DIM do
103-
local rgba = ctx.m_blitData[x]
102+
for x = 1, ID_DIM * ID_DIM * 4, 4 do
103+
local r = ctx.m_blitData[x]
104+
local g = ctx.m_blitData[x+1]
105+
local b = ctx.m_blitData[x+2]
106+
local a = ctx.m_blitData[x+3]
107+
local rgba = r | g << 8 | b << 16 | a << 24
104108
-- todo : Direct3D9 is BGRA
105109
if rgba ~= 0 then
106110
local num = (tmp[rgba] or 0) + 1

0 commit comments

Comments
 (0)