Skip to content

Commit f958779

Browse files
committed
update bgfx 127
1 parent acdde15 commit f958779

File tree

7 files changed

+291
-122
lines changed

7 files changed

+291
-122
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ BGFXSRC = ../bgfx
33
BXSRC = ../bx
44
BIMGSRC = ../bimg
55
LUAINC = -I/usr/local/include
6-
LUALIB = -L/usr/local/bin -llua54
6+
LUALIB = -L/usr/local/bin -L$(MINGW)/bin -llua54
77
SDLINC = -I../SDL/include
88
SDLLIB = -Lbin -lSDL2
99

ant/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function ant.init(args)
1616
reset = args.reset,
1717
debug = args.debug,
1818
profile = args.profile,
19-
getlog = args.getlog,
19+
pushlog = args.pushlog,
20+
pushlog_context = args.pushlog_context,
2021
numBackBuffers = args.numBackBuffers,
2122
maxFrameLatency = args.maxFrameLatency,
2223

luabgfx.c

+41-82
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <android/log.h>
2222
#endif
2323

24-
#if BGFX_API_VERSION != 122
24+
#if BGFX_API_VERSION != 127
2525
# error BGFX_API_VERSION mismatch
2626
#endif
2727

@@ -101,12 +101,14 @@ struct log_cache {
101101
char log[MAX_LOGBUFFER];
102102
};
103103

104+
typedef void (*bgfx_pushlog)(void* context, const char *file, uint16_t line, const char *format, va_list ap);
105+
104106
struct callback {
105107
bgfx_callback_interface_t base;
106108
struct screenshot_queue ss;
107-
struct log_cache lc;
108109
uint32_t filterlog;
109-
bool getlog;
110+
bgfx_pushlog pushlog;
111+
void* pushlog_context;
110112
};
111113

112114
static int
@@ -272,6 +274,14 @@ getfield(lua_State *L, const char *key) {
272274
return ud;
273275
}
274276

277+
static int
278+
getfield_int(lua_State *L, const char *key) {
279+
lua_getfield(L, 1, key);
280+
int v = lua_tointeger(L, -1);
281+
lua_pop(L, 1);
282+
return v;
283+
}
284+
275285
static int
276286
lsetPlatformData(lua_State *L) {
277287
luaL_checktype(L, 1, LUA_TTABLE);
@@ -283,6 +293,7 @@ lsetPlatformData(lua_State *L) {
283293
bpdt.context = getfield(L, "context");
284294
bpdt.backBuffer = getfield(L, "backBuffer");
285295
bpdt.backBufferDS = getfield(L, "backBufferDS");
296+
bpdt.type = (bgfx_native_window_handle_type_t)getfield_int(L, "type");
286297

287298
BGFX(set_platform_data)(&bpdt);
288299

@@ -296,40 +307,15 @@ renderer_type_id(lua_State *L, int index) {
296307
#define RENDERER_TYPE_ID(x) else if (strcmp(type, #x) == 0) id = BGFX_RENDERER_TYPE_##x
297308
if (0) ;
298309
RENDERER_TYPE_ID(NOOP);
299-
RENDERER_TYPE_ID(DIRECT3D9);
300310
RENDERER_TYPE_ID(DIRECT3D11);
301311
RENDERER_TYPE_ID(DIRECT3D12);
302-
RENDERER_TYPE_ID(GNM);
303312
RENDERER_TYPE_ID(METAL);
304-
RENDERER_TYPE_ID(NVN);
305-
RENDERER_TYPE_ID(OPENGLES);
306-
RENDERER_TYPE_ID(OPENGL);
307313
RENDERER_TYPE_ID(VULKAN);
308314
else return luaL_error(L, "Invalid renderer type %s", type);
309315

310316
return id;
311317
}
312318

313-
static void
314-
append_log(struct log_cache *lc, const char * buffer, int n) {
315-
spin_lock(lc);
316-
int sz = (int)(lc->tail - lc->head); // sz must less than MAX_LOGBUFFER
317-
if (sz + n > MAX_LOGBUFFER)
318-
n = MAX_LOGBUFFER - sz;
319-
int offset = lc->tail % MAX_LOGBUFFER;
320-
int part = MAX_LOGBUFFER - offset;
321-
if (part >= n) {
322-
// only one part
323-
memcpy(lc->log + offset, buffer, n);
324-
} else {
325-
// ring buffer rewind
326-
memcpy(lc->log + offset, buffer, part);
327-
memcpy(lc->log, buffer + part, n - part);
328-
}
329-
lc->tail += n;
330-
spin_unlock(lc);
331-
}
332-
333319
static const char*
334320
fatal_code_str(bgfx_fatal_t code) {
335321
switch (code) {
@@ -385,19 +371,20 @@ trace_filter(const char *format, int level) {
385371

386372
static void
387373
cb_trace_vargs(bgfx_callback_interface_t *self, const char *file, uint16_t line, const char *format, va_list ap) {
388-
char tmp[MAX_LOGBUFFER];
389-
int n = sprintf(tmp, "%s (%d): ", file, line);
390-
391-
n += vsnprintf(tmp+n, sizeof(tmp)-n, format, ap);
392-
if (n > MAX_LOGBUFFER) {
393-
// truncated
394-
n = MAX_LOGBUFFER;
395-
}
396374
struct callback * cb = (struct callback *)self;
397-
if (cb->getlog) {
398-
append_log(&(cb->lc), tmp, n);
399-
}
400375
if (cb->filterlog > 0 && trace_filter(format, cb->filterlog)) {
376+
if (cb->pushlog) {
377+
cb->pushlog(cb->pushlog_context, file, line, format, ap);
378+
return;
379+
}
380+
char tmp[MAX_LOGBUFFER];
381+
int n = sprintf(tmp, "%s (%d): ", file, line);
382+
383+
n += vsnprintf(tmp+n, sizeof(tmp)-n, format, ap);
384+
if (n > MAX_LOGBUFFER) {
385+
// truncated
386+
n = MAX_LOGBUFFER;
387+
}
401388
#if BX_PLATFORM_ANDROID
402389
__android_log_write(ANDROID_LOG_INFO, "bgfx", tmp);
403390
#else
@@ -634,6 +621,7 @@ linit(lua_State *L) {
634621
init.platformData.context = NULL;
635622
init.platformData.backBuffer = NULL;
636623
init.platformData.backBufferDS = NULL;
624+
init.platformData.type = BGFX_NATIVE_WINDOW_HANDLE_TYPE_DEFAULT;
637625

638626
if (!lua_isnoneornil(L, 1)) {
639627
luaL_checktype(L, 1, LUA_TTABLE);
@@ -673,19 +661,17 @@ linit(lua_State *L) {
673661
read_uint32(L, 1, "transientIbSize", &init.limits.transientIbSize);
674662
read_boolean(L, 1, "debug", &init.debug);
675663
read_boolean(L, 1, "profile", &init.profile);
676-
read_boolean(L, 1, "getlog", &cb->getlog);
677-
if (cb->getlog) {
678-
cb->filterlog = 0; // log none
679-
} else {
680-
cb->filterlog = 255; // log all
681-
}
664+
682665
read_uint32(L, 1, "loglevel", &cb->filterlog);
666+
cb->pushlog = getfield(L, "pushlog");
667+
cb->pushlog_context = getfield(L, "pushlog_context");
683668

684669
init.platformData.ndt = getfield(L, "ndt");
685670
init.platformData.nwh = getfield(L, "nwh");
686671
init.platformData.context = getfield(L, "context");
687672
init.platformData.backBuffer = getfield(L, "backBuffer");
688673
init.platformData.backBufferDS = getfield(L, "backBufferDS");
674+
init.platformData.type = (bgfx_native_window_handle_type_t)getfield_int(L, "type");
689675

690676
//if (init.debug) {
691677
luabgfx_getalloc(&init.allocator);
@@ -704,13 +690,9 @@ push_renderer_type(lua_State *L, bgfx_renderer_type_t t) {
704690
#define RENDERER_TYPE(x) case BGFX_RENDERER_TYPE_##x : st = #x; break
705691
switch(t) {
706692
RENDERER_TYPE(NOOP);
707-
RENDERER_TYPE(DIRECT3D9);
708693
RENDERER_TYPE(DIRECT3D11);
709694
RENDERER_TYPE(DIRECT3D12);
710-
RENDERER_TYPE(GNM);
711695
RENDERER_TYPE(METAL);
712-
RENDERER_TYPE(OPENGLES);
713-
RENDERER_TYPE(OPENGL);
714696
RENDERER_TYPE(VULKAN);
715697
default: {
716698
luaL_error(L, "Unknown renderer type %d", t);
@@ -1112,7 +1094,7 @@ lgetStats(lua_State *L) {
11121094
break;
11131095
}
11141096
default:
1115-
return luaL_error(L, "Unkown stat format %c", what[i]);
1097+
return luaL_error(L, "Unknown stat format %c", what[i]);
11161098
}}
11171099
return 1;
11181100
}
@@ -3271,7 +3253,12 @@ ldbgTextImage(lua_State *L) {
32713253
int y = luaL_checkinteger(L, 2);
32723254
int w = luaL_checkinteger(L, 3);
32733255
int h = luaL_checkinteger(L, 4);
3274-
const char * image = luaL_checkstring(L, 5);
3256+
const char * image;
3257+
if (lua_isuserdata(L, 5)) {
3258+
image = (const char *)lua_touserdata(L, 5);
3259+
} else {
3260+
image = luaL_checkstring(L, 5);
3261+
}
32753262
int pitch = luaL_optinteger(L, 6, 2 * w);
32763263
BGFX(dbg_text_image)(x,y,w,h,image, pitch);
32773264
return 0;
@@ -4505,8 +4492,9 @@ lsetViewRect(lua_State *L) {
45054492
static int
45064493
lsetViewName(lua_State *L) {
45074494
bgfx_view_id_t viewid = luaL_checkinteger(L, 1);
4508-
const char *name = luaL_checkstring(L, 2);
4509-
BGFX(set_view_name)(viewid, name);
4495+
size_t sz;
4496+
const char *name = luaL_checklstring(L, 2, &sz);
4497+
BGFX(set_view_name)(viewid, name, sz);
45104498
return 0;
45114499
}
45124500

@@ -5061,34 +5049,6 @@ lgetScreenshot(lua_State *L) {
50615049
return memptr ? 6 : 5;
50625050
}
50635051

5064-
static int
5065-
lgetLog(lua_State *L) {
5066-
if (lua_getfield(L, LUA_REGISTRYINDEX, "bgfx_cb") != LUA_TUSERDATA) {
5067-
return luaL_error(L, "get_log failed!");
5068-
}
5069-
struct callback *cb = lua_touserdata(L, -1);
5070-
struct log_cache *lc = &cb->lc;
5071-
spin_lock(lc);
5072-
int offset = lc->head % MAX_LOGBUFFER;
5073-
int sz = (int)(lc->tail - lc->head);
5074-
5075-
int part = MAX_LOGBUFFER - offset;
5076-
5077-
if (part >= sz) {
5078-
// only one part
5079-
lua_pushlstring(L, lc->log + offset, sz);
5080-
} else {
5081-
char tmp[MAX_LOGBUFFER];
5082-
memcpy(tmp, lc->log + offset, part);
5083-
memcpy(tmp + part, lc->log, sz - part);
5084-
lua_pushlstring(L, tmp, sz);
5085-
}
5086-
lc->head = lc->tail;
5087-
5088-
spin_unlock(lc);
5089-
return 1;
5090-
}
5091-
50925052
#define SET_UNIFORM 0
50935053
#define SET_TEXTURE 1
50945054
#define SET_BUFFER 2
@@ -5481,7 +5441,6 @@ luaopen_bgfx(lua_State *L) {
54815441
{ "init", linit },
54825442
{ "shutdown", lshutdown },
54835443

5484-
{ "get_log", lgetLog },
54855444
{ "get_screenshot", lgetScreenshot },
54865445
{ "request_screenshot", lrequestScreenshot },
54875446

luabgfximgui.cpp

+17-35
Original file line numberDiff line numberDiff line change
@@ -1294,34 +1294,7 @@ wEndListBox(lua_State *L) {
12941294
return 0;
12951295
}
12961296

1297-
static int
1298-
get_listitem_func(lua_State *L) {
1299-
int n = lua_tointeger(L, 2);
1300-
lua_geti(L, 1, n);
1301-
return 1;
1302-
}
1303-
1304-
static bool
1305-
get_listitem(void* data, int idx, const char **out_text) {
1306-
struct lua_args *args = (struct lua_args *)data;
1307-
lua_State *L = args->L;
1308-
if (args->err)
1309-
return 0;
1310-
lua_pushcfunction(L, get_listitem_func);
1311-
lua_pushvalue(L, INDEX_ARGS);
1312-
lua_pushinteger(L, idx+1);
1313-
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
1314-
args->err = true;
1315-
return 0;
1316-
}
1317-
if (lua_type(L, -1) == LUA_TSTRING) {
1318-
*out_text = lua_tostring(L, -1);
1319-
return true;
1320-
}
1321-
lua_pop(L, 1);
1322-
*out_text = NULL;
1323-
return false;
1324-
}
1297+
#define MAX_ITEM 4096
13251298

13261299
static int
13271300
wListBox(lua_State *L) {
@@ -1331,9 +1304,19 @@ wListBox(lua_State *L) {
13311304
int n = lua_tointeger(L, -1);
13321305
lua_pop(L, 1);
13331306
int height_in_items = read_field_int(L, "height", -1);
1334-
struct lua_args args = { L, false };
13351307
int current = read_field_int(L, "current", 0) - 1;
1336-
bool change = ImGui::ListBox(label, &current, get_listitem, &args, n, height_in_items);
1308+
const char * items[MAX_ITEM];
1309+
if (n > MAX_ITEM)
1310+
n = MAX_ITEM;
1311+
int i;
1312+
for (i=1;i<=n;i++) {
1313+
if (lua_geti(L, INDEX_ARGS, i) != LUA_TSTRING)
1314+
return luaL_error(L, "Invalid item at %d", i);
1315+
items[i-1] = lua_tostring(L, -1);
1316+
lua_pop(L, 1);
1317+
}
1318+
1319+
bool change = ImGui::ListBox(label, &current, items, n, height_in_items);
13371320
if (change) {
13381321
lua_pushinteger(L, current+1);
13391322
lua_setfield(L, INDEX_ARGS, "current");
@@ -1958,8 +1941,8 @@ uGetItemRectSize(lua_State *L) {
19581941
}
19591942

19601943
static int
1961-
uSetItemAllowOverlap(lua_State *L) {
1962-
ImGui::SetItemAllowOverlap();
1944+
uSetNextItemAllowOverlap(lua_State *L) {
1945+
ImGui::SetNextItemAllowOverlap();
19631946
return 0;
19641947
}
19651948

@@ -2066,7 +2049,7 @@ static struct enum_pair eSelectableFlags[] = {
20662049
static struct enum_pair eTreeNodeFlags[] = {
20672050
ENUM(ImGuiTreeNodeFlags, Selected),
20682051
ENUM(ImGuiTreeNodeFlags, Framed),
2069-
ENUM(ImGuiTreeNodeFlags, AllowItemOverlap),
2052+
ENUM(ImGuiTreeNodeFlags, AllowOverlap),
20702053
ENUM(ImGuiTreeNodeFlags, NoTreePushOnOpen),
20712054
ENUM(ImGuiTreeNodeFlags, NoAutoOpenOnLog),
20722055
ENUM(ImGuiTreeNodeFlags, DefaultOpen),
@@ -2097,7 +2080,6 @@ static struct enum_pair eWindowFlags[] = {
20972080
ENUM(ImGuiWindowFlags, NoBringToFrontOnFocus),
20982081
ENUM(ImGuiWindowFlags, AlwaysVerticalScrollbar),
20992082
ENUM(ImGuiWindowFlags, AlwaysHorizontalScrollbar),
2100-
ENUM(ImGuiWindowFlags, AlwaysUseWindowPadding),
21012083
ENUM(ImGuiWindowFlags, NoNavInputs),
21022084
ENUM(ImGuiWindowFlags, NoNavFocus),
21032085
ENUM(ImGuiWindowFlags, UnsavedDocument),
@@ -2305,7 +2287,7 @@ luaopen_bgfx_imgui(lua_State *L) {
23052287
{ "GetItemRectMin", uGetItemRectMin },
23062288
{ "GetItemRectMax", uGetItemRectMax },
23072289
{ "GetItemRectSize", uGetItemRectSize },
2308-
{ "SetItemAllowOverlap", uSetItemAllowOverlap },
2290+
{ "SetNextItemAllowOverlap", uSetNextItemAllowOverlap },
23092291
{ "LoadIniSettings", uLoadIniSettings },
23102292
{ "SaveIniSettings", uSaveIniSettings },
23112293
{ NULL, NULL },

0 commit comments

Comments
 (0)