Skip to content

Commit 9c49135

Browse files
committed
bgfx_interface changed
1 parent ac9f0fa commit 9c49135

File tree

6 files changed

+14
-59
lines changed

6 files changed

+14
-59
lines changed

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ $(ODIR)/luabgfximgui.o : luabgfximgui.cpp | $(ODIR)
3232
$(ODIR)/bgfx_alloc.o : bgfx_alloc.cpp | $(ODIR)
3333
$(CXX) $(CFLAGS) -c -DLUA_BUILD_AS_DLL -o $@ $^ $(LUAINC) $(BGFXINC) $(BGFXUTILINC)
3434

35+
$(ODIR)/bgfx_interface.o : bgfx_interface.cpp | $(ODIR)
36+
$(CXX) $(CFLAGS) -c -DLUA_BUILD_AS_DLL -o $@ $^ $(LUAINC) $(BGFXINC) $(BGFXUTILINC)
37+
3538
bin :
3639
mkdir $@
3740

38-
bin/bgfx.dll : $(ODIR)/luabgfx.o $(ODIR)/luabgfxutil.o $(ODIR)/luabgfximgui.o $(ODIR)/bgfx_alloc.o | bin
41+
bin/bgfx.dll : $(ODIR)/luabgfx.o $(ODIR)/luabgfxutil.o $(ODIR)/luabgfximgui.o $(ODIR)/bgfx_alloc.o $(ODIR)/bgfx_interface.o | bin
3942
$(CC) $(CFLAGS) --shared -o $@ $^ $(LUALIB) $(BGFXUTILLIB) $(BIMGLIB) $(BGFXLIB)
4043

4144
math :

bgfx_alloc.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "bgfx_alloc.h"
22
#include <bx/allocator.h>
33
#include <atomic>
4-
#include <malloc.h>
4+
#include <stdlib.h>
55

66
#ifndef BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT
77
# define BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 8
@@ -15,8 +15,10 @@ static std::atomic<int64_t> allocator_memory (0);
1515
#elif BX_PLATFORM_LINUX
1616
#define bx_malloc_size malloc_usable_size
1717
#elif BX_PLATFORM_OSX
18+
#include <malloc/malloc.h>
1819
#define bx_malloc_size malloc_size
1920
#elif BX_PLATFORM_IOS
21+
#include <malloc/malloc.h>
2022
#define bx_malloc_size malloc_size
2123
#else
2224
# error "Unknown PLATFORM!"

bgfx_interface.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "bgfx_interface.h"
2+
3+
bgfx_interface_vtbl_t* bgfx_inf_ = bgfx_get_interface(BGFX_API_VERSION);

bgfx_interface.h

+4-39
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,14 @@
55
#include <lauxlib.h>
66
#include <bgfx/c99/bgfx.h>
77

8-
extern bgfx_interface_vtbl_t* bgfx_inf_;
9-
10-
#ifndef BGFX_INTERFACE_IMPORT
11-
bgfx_interface_vtbl_t* bgfx_inf_ = 0;
12-
#endif
13-
14-
static inline void
15-
init_interface(lua_State* L) {
16-
if (bgfx_inf_) {
17-
return;
18-
}
19-
#ifdef BGFX_STATIC_LINK
20-
bgfx_interface_vtbl_t* inf = bgfx_get_interface(BGFX_API_VERSION);
21-
if (inf == NULL) {
22-
luaL_error(L, "BGFX_API_VERSION (%d) mismatch.", BGFX_API_VERSION);
23-
return;
24-
}
25-
bgfx_inf_ = inf;
8+
#if defined(__cplusplus)
9+
extern "C"
2610
#else
27-
if (LUA_TFUNCTION != lua_getfield(L, LUA_REGISTRYINDEX, "BGFX_GET_INTERFACE")) {
28-
luaL_error(L, "BGFX_GET_INTERFACE is missing.");
29-
return;
30-
}
31-
lua_CFunction fn = lua_tocfunction(L, -1);
32-
if (fn == NULL) {
33-
luaL_error(L, "BGFX_GET_INTERFACE is not a C function.");
34-
return;
35-
}
36-
bgfx_interface_vtbl_t* inf = ((PFN_BGFX_GET_INTERFACE)fn)(BGFX_API_VERSION);
37-
if (inf == NULL) {
38-
luaL_error(L, "BGFX_API_VERSION (%d) mismatch.", BGFX_API_VERSION);
39-
return;
40-
}
41-
bgfx_inf_ = inf;
42-
lua_pop(L, 1);
11+
extern
4312
#endif
44-
}
13+
bgfx_interface_vtbl_t* bgfx_inf_;
4514

4615
#define BGFX(api) bgfx_inf_->api
4716
#define BGFX_ENCODER(api, encoder, ...) (encoder ? (BGFX(encoder_##api)( encoder, ## __VA_ARGS__ )) : BGFX(api)( __VA_ARGS__ ))
4817

49-
#ifdef EXPORT_BGFX_INTERFACE
50-
bgfx_interface_vtbl_t* ibgfx(){return bgfx_inf_;}
51-
#endif //EXPORT_BGFX_INTERFACE
52-
5318
#endif

luabgfx.c

-1
Original file line numberDiff line numberDiff line change
@@ -5113,7 +5113,6 @@ linitEncoder(lua_State *L) {
51135113
LUAMOD_API int
51145114
luaopen_bgfx(lua_State *L) {
51155115
luaL_checkversion(L);
5116-
init_interface(L);
51175116

51185117
int tfn = sizeof(c_texture_formats) / sizeof(c_texture_formats[0]);
51195118
lua_createtable(L, 0, tfn);

luabgfxutil.c

-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <stdint.h>
66
#include <math.h>
77

8-
#define BGFX_INTERFACE_IMPORT
98
#include "bgfx_interface.h"
109

1110
static inline float
@@ -56,29 +55,13 @@ lencodeNormalRgba8(lua_State *L) {
5655
return 1;
5756
}
5857

59-
static void
60-
update_char_texture(uint16_t texid,
61-
uint16_t _layer, uint8_t _mip,
62-
uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, uint16_t _pitch,
63-
const uint8_t *mem, void (*release_fn)(void*, void*)){
64-
65-
bgfx_texture_handle_t th = {texid};
66-
const bgfx_memory_t *m = BGFX(make_ref_release)(mem, _width * _height, release_fn, NULL);
67-
BGFX(update_texture_2d)(th, _layer, _mip, _x, _y, _width, _height, m, _pitch);
68-
}
69-
7058
LUAMOD_API int
7159
luaopen_bgfx_util(lua_State *L) {
7260
luaL_checkversion(L);
73-
init_interface(L);
7461
luaL_Reg l[] = {
75-
{ "update_char_texture", NULL},
7662
{ "encodeNormalRgba8", lencodeNormalRgba8 },
7763
{ NULL, NULL },
7864
};
7965
luaL_newlib(L, l);
80-
81-
lua_pushlightuserdata(L, update_char_texture);
82-
lua_setfield(L, -2, "update_char_texture");
8366
return 1;
8467
}

0 commit comments

Comments
 (0)