1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
6 lua_render_context
* saved
= NULL
;
7 lua_render_context
* last
= NULL
;
10 struct render_queue_obj
12 render_queue_obj(uint32_t width
, uint32_t height
) throw()
14 lctx
.left_gap
= std::numeric_limits
<uint32_t>::max();
15 lctx
.right_gap
= std::numeric_limits
<uint32_t>::max();
16 lctx
.bottom_gap
= std::numeric_limits
<uint32_t>::max();
17 lctx
.top_gap
= std::numeric_limits
<uint32_t>::max();
22 ~render_queue_obj() throw() {}
23 lua_render_context
* get() { return &lctx
; }
26 lua_render_context lctx
;
29 function_ptr_luafun
gui_rq_run(LS
, "gui.renderq_run", [](lua_state
& L
, const std::string
& fname
) -> int {
32 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
33 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
34 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
35 lua_render_context
* ptr
= q
->object()->get();
36 if(ptr
->top_gap
!= std::numeric_limits
<uint32_t>::max())
37 lua_render_ctx
->top_gap
= ptr
->top_gap
;
38 if(ptr
->right_gap
!= std::numeric_limits
<uint32_t>::max())
39 lua_render_ctx
->right_gap
= ptr
->right_gap
;
40 if(ptr
->bottom_gap
!= std::numeric_limits
<uint32_t>::max())
41 lua_render_ctx
->bottom_gap
= ptr
->bottom_gap
;
42 if(ptr
->left_gap
!= std::numeric_limits
<uint32_t>::max())
43 lua_render_ctx
->left_gap
= ptr
->left_gap
;
44 lua_render_ctx
->queue
->copy_from(*ptr
->queue
);
46 L
.pushstring("Expected RENDERCTX as argument 1 for gui.renderq_run.");
52 function_ptr_luafun
gui_rq_clear(LS
, "gui.renderq_clear", [](lua_state
& L
, const std::string
& fname
) -> int {
53 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
54 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
55 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
56 lua_render_context
* ptr
= q
->object()->get();
57 ptr
->top_gap
= std::numeric_limits
<uint32_t>::max();
58 ptr
->right_gap
= std::numeric_limits
<uint32_t>::max();
59 ptr
->bottom_gap
= std::numeric_limits
<uint32_t>::max();
60 ptr
->left_gap
= std::numeric_limits
<uint32_t>::max();
63 L
.pushstring("Expected RENDERCTX as argument 1 for gui.renderq_clear.");
69 function_ptr_luafun
gui_rq_new(LS
, "gui.renderq_new", [](lua_state
& L
, const std::string
& fname
) -> int {
70 int32_t x
= L
.get_numeric_argument
<int32_t>(1, fname
.c_str());
71 int32_t y
= L
.get_numeric_argument
<int32_t>(2, fname
.c_str());
72 lua_class
<render_queue_obj
>::create(L
, x
, y
);
76 function_ptr_luafun
gui_rq_set(LS
, "gui.renderq_set", [](lua_state
& L
, const std::string
& fname
) -> int {
77 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
78 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
79 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
80 lua_render_context
* ptr
= q
->object()->get();
81 if(!redirect
|| last
!= lua_render_ctx
)
82 saved
= lua_render_ctx
;
83 lua_render_ctx
= last
= ptr
;
85 } else if(L
.type(1) == LUA_TNIL
) {
86 if(redirect
&& last
== lua_render_ctx
)
87 //If there is valid redirect, undo it.
88 lua_render_ctx
= saved
;
93 L
.pushstring("Expected RENDERCTX or nil as argument 1 for gui.renderq_set.");
100 DECLARE_LUACLASS(render_queue_obj
, "RENDERCTX");