#include #include #include #include #include "util/util.h" #define GL_DRAWING_FUNCTIONS \ X("ClearColor", glClearColor_bind) \ X("Clear", glClear_bind) \ X("DrawArrays", glDrawArrays_bind) \ X("DrawElements", glDrawElements_bind) \ X("Viewport", glViewport_bind) \ X("GenFramebuffers", glGenFramebuffers_bind) \ X("BindFramebuffer", glBindFramebuffer_bind) \ X("FramebufferTexture2D", glFramebufferTexture2D_bind) \ X("CullFace", glCullFace_bind) \ X("BlendFunc", glBlendFunc_bind) \ #define X(name, func) int func(lua_State *L); GL_DRAWING_FUNCTIONS #undef X void setup_drawing(lua_State *L, int gl_index) { struct honey_tbl_t tbl[] = { /* functions */ #define X(name, func) H_FUNC(name, func), GL_DRAWING_FUNCTIONS #undef X /******** enums ********/ /* rendering primitives */ H_INT("POINTS", GL_POINTS), H_INT("LINES", GL_LINES), H_INT("TRIANGLES", GL_TRIANGLES), /* clear bitmasks */ H_INT("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT), H_INT("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), H_INT("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT), H_INT("FRONT", GL_FRONT), H_INT("BACK", GL_BACK), H_INT("FRONT_AND_BACK", GL_FRONT_AND_BACK), /* BlendFunc factors */ H_INT("ZERO", GL_ZERO), H_INT("ONE", GL_ONE), H_INT("SRC_COLOR", GL_SRC_COLOR), H_INT("ONE_MINUS_SRC_COLOR", GL_ONE_MINUS_SRC_COLOR), H_INT("DST_COLOR", GL_DST_COLOR), H_INT("ONE_MINUS_DST_COLOR", GL_ONE_MINUS_DST_COLOR), H_INT("SRC_ALPHA", GL_SRC_ALPHA), H_INT("ONE_MINUS_SRC_ALPHA", GL_ONE_MINUS_SRC_ALPHA), H_INT("DST_ALPHA", GL_DST_ALPHA), H_INT("ONE_MINUS_DST_ALPHA", GL_ONE_MINUS_DST_ALPHA), H_INT("CONSTANT_COLOR", GL_CONSTANT_COLOR), H_INT("ONE_MINUS_CONSTANT_COLOR", GL_ONE_MINUS_CONSTANT_COLOR), H_INT("CONSTANT_ALPHA", GL_CONSTANT_ALPHA), H_INT("ONE_MINUS_CONSTANT_ALPHA", GL_ONE_MINUS_CONSTANT_ALPHA), H_INT("FRAMEBUFFER", GL_FRAMEBUFFER), H_END }; create_table(L, tbl); append_table(L, gl_index, lua_gettop(L)); lua_pop(L, 1); } int glClearColor_bind(lua_State *L) { lua_Number r, g, b, a; r = luaL_checknumber(L, 1); g = luaL_checknumber(L, 2); b = luaL_checknumber(L, 3); a = luaL_checknumber(L, 4); glClearColor(r, g, b, a); return 0; } int glClear_bind(lua_State *L) { lua_Integer mask = luaL_checkinteger(L, 1); glClear(mask); return 0; } int glDrawArrays_bind(lua_State *L) { lua_Integer mode, first, count; mode = luaL_checkinteger(L, 1); first = luaL_checkinteger(L, 2); count = luaL_checkinteger(L, 3); glDrawArrays(mode, first, count); return 0; } int glDrawElements_bind(lua_State *L) { lua_Integer mode, count, type, offset; mode = luaL_checkinteger(L, 1); count = luaL_checkinteger(L, 2); type = luaL_checkinteger(L, 3); offset = luaL_checkinteger(L, 4); glDrawElements(mode, count, type, (const void*)offset); return 0; } int glViewport_bind(lua_State *L) { lua_Integer x, y, w, h; x = luaL_checkinteger(L, 1); y = luaL_checkinteger(L, 2); w = luaL_checkinteger(L, 3); h = luaL_checkinteger(L, 4); glViewport(x, y, w, h); return 0; } int glGenFramebuffers_bind(lua_State *L) { int framebuffer; glGenFramebuffers(1, &framebuffer); lua_pushinteger(L, framebuffer); return 1; } int glBindFramebuffer_bind(lua_State *L) { int target = luaL_checkinteger(L, 1); int framebuffer = luaL_checkinteger(L, 2); glBindFramebuffer(target, framebuffer); return 0; } int glFramebufferTexture2D_bind(lua_State *L) { int target = luaL_checkinteger(L, 1); int attachment = luaL_checkinteger(L, 2); int textarget = luaL_checkinteger(L, 3); int texture = luaL_checkinteger(L, 4); int level = luaL_checkinteger(L, 5); glFramebufferTexture2D(target, attachment, textarget, texture, level); return 0; } int glCullFace_bind(lua_State *L) { int mode = luaL_checkinteger(L, 1); glCullFace(mode); return 0; } int glBlendFunc_bind(lua_State *L) { int sfactor = luaL_checkinteger(L, 1); int dfactor = luaL_checkinteger(L, 1); glBlendFunc(sfactor, dfactor); return 0; }