diff options
-rw-r--r-- | src/main.c | 14 | ||||
-rw-r--r-- | src/opengl/drawing.c | 87 | ||||
-rw-r--r-- | src/opengl/gl.c | 2 | ||||
-rw-r--r-- | src/options/options.c | 46 | ||||
-rw-r--r-- | src/options/options.h | 2 |
5 files changed, 130 insertions, 21 deletions
@@ -2,9 +2,17 @@ #include <lauxlib.h> #include <lualib.h> #include "options/options.h" +#include "logging/logging.h" #include "util/util.h" #include "common.h" +#ifdef _WIN32 +# include <direct.h> +# define chdir _chdir +#else +# include <unistd.h> +#endif + void print_load_error(lua_State *L, const char *script_file, int error_type); void setup_version(lua_State *L, int honey_tbl); @@ -16,6 +24,12 @@ int main(int argc, char **argv) int result = parse_options(&options, argc, argv); if (result == EXIT_FAILURE) return 1; else if (result == EXIT_SUCCESS) return 0; + honey_set_log_level(options.log_level); + + /* configure working directory */ + if (options.working_dir != NULL) { + chdir(options.working_dir); + } /* set up lua state */ lua_State *L = luaL_newstate(); diff --git a/src/opengl/drawing.c b/src/opengl/drawing.c index eeb0496..cdab5ae 100644 --- a/src/opengl/drawing.c +++ b/src/opengl/drawing.c @@ -4,24 +4,30 @@ #include <lauxlib.h> #include "util/util.h" -int gl_set_viewport(lua_State *L); -int gl_draw_arrays(lua_State *L); -int gl_draw_elements(lua_State *L); -int gl_set_clear_color(lua_State *L); -int gl_clear(lua_State *L); -int gl_gen_framebuffers(lua_State *L); -int gl_bind_framebuffer(lua_State *L); -int gl_framebuffer_texture_2d(lua_State *L); +#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 */ - H_FUNC("DrawArrays", gl_draw_arrays), - H_FUNC("DrawElements", gl_draw_elements), - H_FUNC("ClearColor", gl_set_clear_color), - H_FUNC("Clear", gl_clear), - H_FUNC("Viewport", gl_set_viewport), + #define X(name, func) H_FUNC(name, func), + GL_DRAWING_FUNCTIONS + #undef X /******** enums ********/ /* rendering primitives */ @@ -34,6 +40,28 @@ void setup_drawing(lua_State *L, int gl_index) 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); @@ -41,7 +69,7 @@ void setup_drawing(lua_State *L, int gl_index) lua_pop(L, 1); } -int gl_set_clear_color(lua_State *L) +int glClearColor_bind(lua_State *L) { lua_Number r, g, b, a; r = luaL_checknumber(L, 1); @@ -53,7 +81,7 @@ int gl_set_clear_color(lua_State *L) } -int gl_clear(lua_State *L) +int glClear_bind(lua_State *L) { lua_Integer mask = luaL_checkinteger(L, 1); glClear(mask); @@ -61,7 +89,7 @@ int gl_clear(lua_State *L) } -int gl_draw_arrays(lua_State *L) +int glDrawArrays_bind(lua_State *L) { lua_Integer mode, first, count; mode = luaL_checkinteger(L, 1); @@ -72,7 +100,7 @@ int gl_draw_arrays(lua_State *L) } -int gl_draw_elements(lua_State *L) +int glDrawElements_bind(lua_State *L) { lua_Integer mode, count, type, offset; mode = luaL_checkinteger(L, 1); @@ -84,7 +112,7 @@ int gl_draw_elements(lua_State *L) } -int gl_set_viewport(lua_State *L) +int glViewport_bind(lua_State *L) { lua_Integer x, y, w, h; x = luaL_checkinteger(L, 1); @@ -96,7 +124,7 @@ int gl_set_viewport(lua_State *L) } -int gl_gen_framebuffers(lua_State *L) +int glGenFramebuffers_bind(lua_State *L) { int framebuffer; glGenFramebuffers(1, &framebuffer); @@ -105,7 +133,7 @@ int gl_gen_framebuffers(lua_State *L) } -int gl_bind_framebuffer(lua_State *L) +int glBindFramebuffer_bind(lua_State *L) { int target = luaL_checkinteger(L, 1); int framebuffer = luaL_checkinteger(L, 2); @@ -114,7 +142,7 @@ int gl_bind_framebuffer(lua_State *L) } -int gl_framebuffer_texture_2d(lua_State *L) +int glFramebufferTexture2D_bind(lua_State *L) { int target = luaL_checkinteger(L, 1); int attachment = luaL_checkinteger(L, 2); @@ -125,3 +153,20 @@ int gl_framebuffer_texture_2d(lua_State *L) 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; +} diff --git a/src/opengl/gl.c b/src/opengl/gl.c index 6643f5f..bbbb07d 100644 --- a/src/opengl/gl.c +++ b/src/opengl/gl.c @@ -48,6 +48,8 @@ void setup_gl(lua_State *L, int honey_index) /* opengl capabilities */ H_INT("DEPTH_TEST", GL_DEPTH_TEST), H_INT("CULL_FACE", GL_CULL_FACE), + H_INT("BLEND", GL_BLEND), + H_INT("SCISSOR_TEST", GL_SCISSOR_TEST), /* strings */ H_INT("VENDOR", GL_VENDOR), diff --git a/src/options/options.c b/src/options/options.c index cf2ae49..d2221aa 100644 --- a/src/options/options.c +++ b/src/options/options.c @@ -1,10 +1,18 @@ #include <stdio.h> #include <cargs.h> #include <common.h> +#include "logging/logging.h" #include "options.h" static struct cag_option opts[] = { { + .identifier = 'd', + .access_letters = "d", + .access_name = "directory", + .value_name = "WORKING_DIRECTORY", + .description = "Set the working directory for honey. (default: .)", + }, + { .identifier = 's', .access_letters = "s", .access_name = "script", @@ -25,6 +33,20 @@ static struct cag_option opts[] = { .value_name = NULL, .description = "Shows this help message" }, + { + .identifier = 'v', + .access_letters = "v", + .access_name = NULL, + .value_name = NULL, + .description = "Increase verbosity (-vvv shows all messages)" + }, + { + .identifier = 'q', + .access_letters = "q", + .access_name = NULL, + .value_name = NULL, + .description = "Decrease verbosity (-qqq hides all messages)" + }, }; @@ -38,7 +60,9 @@ void print_help(char *program_name) enum outcomes_t parse_options(struct honey_options *options, int argc, char **argv) { /* default values */ + options->working_dir = NULL; options->script_file = "main.lua"; + options->log_level = HONEY_WARN; /* parse options */ char id; @@ -49,12 +73,22 @@ enum outcomes_t parse_options(struct honey_options *options, int argc, char **ar while(cag_option_fetch(&context)) { id = cag_option_get(&context); switch(id) { + /* set working directory */ + case 'd': + options->working_dir = cag_option_get_value(&context); + break; + + /* set main script */ case 's': options->script_file = cag_option_get_value(&context); break; + + /* print help information & exit */ case 'h': print_help(argv[0]); return EXIT_SUCCESS; + + /* print version information & exit */ case 'e': printf( "honey v%d.%d.%d -- %s\n", @@ -64,7 +98,19 @@ enum outcomes_t parse_options(struct honey_options *options, int argc, char **ar HONEY_VERSION_STR ); return EXIT_SUCCESS; + + /* verbosity options */ + case 'q': + options->log_level -= 1; + break; + case 'v': + options->log_level += 1; + break; + default: + int index = cag_option_get_index(&context); + fprintf(stderr, "unknown option: %s\n", argv[index-1]); + print_help(argv[0]); return EXIT_FAILURE; } } diff --git a/src/options/options.h b/src/options/options.h index cb07b1a..a7444f6 100644 --- a/src/options/options.h +++ b/src/options/options.h @@ -2,7 +2,9 @@ #define HONEY_OPTIONS_H struct honey_options { + const char *working_dir; const char *script_file; // main entry point + int log_level; }; enum outcomes_t { |