Use master state for trampolines
[lsnes.git] / src / lua / gui-pixel.cpp
blob8a92f1a24708bb711b10767b92aeb95baa974ca0
1 #include "core/instance.hpp"
2 #include "lua/internal.hpp"
3 #include "library/framebuffer.hpp"
4 #include "library/lua-framebuffer.hpp"
6 namespace
8 struct render_object_pixel : public framebuffer::object
10 render_object_pixel(int32_t _x, int32_t _y, framebuffer::color _color) throw()
11 : x(_x), y(_y), color(_color) {}
12 ~render_object_pixel() throw() {}
13 template<bool X> void op(struct framebuffer::fb<X>& scr) throw()
15 int32_t _x = x + scr.get_origin_x();
16 int32_t _y = y + scr.get_origin_y();
17 if(_x < 0 || static_cast<uint32_t>(_x) >= scr.get_width())
18 return;
19 if(_y < 0 || static_cast<uint32_t>(_y) >= scr.get_height())
20 return;
21 color.apply(scr.rowptr(_y)[_x]);
23 void operator()(struct framebuffer::fb<true>& scr) throw() { op(scr); }
24 void operator()(struct framebuffer::fb<false>& scr) throw() { op(scr); }
25 void clone(framebuffer::queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
26 private:
27 int32_t x;
28 int32_t y;
29 framebuffer::color color;
32 int pixel(lua::state& L, lua::parameters& P)
34 auto& core = CORE();
35 int32_t x, y;
36 framebuffer::color pcolor;
38 if(!core.lua2->render_ctx) return 0;
40 P(x, y, P.optional(pcolor, 0xFFFFFFU));
42 core.lua2->render_ctx->queue->create_add<render_object_pixel>(x, y, pcolor);
43 return 0;
46 lua::functions LUA_pixel_fns(lua_func_misc, "gui", {
47 {"pixel", pixel},
48 });