# HG changeset patch # User John Tsiombikas # Date 1408717483 -10800 # Node ID 90abf4b93cc9a7557a5ebe7a32d9f238172a3634 # Parent bd8202d6d28d828d52c2e388da328615d1fe614b fixed line endings fixed viewport when returning to original framebuffer diff -r bd8202d6d28d -r 90abf4b93cc9 src/game.cc --- a/src/game.cc Fri Aug 22 16:55:16 2014 +0300 +++ b/src/game.cc Fri Aug 22 17:24:43 2014 +0300 @@ -102,6 +102,8 @@ vr_end(); glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(0, 0, fb_width, fb_height); + vr_output_texture(rtarg->get_texture_id(), 0, 0, (float)rtwidth / (float)rtarg->get_width(), (float)rtheight / (float)rtarg->get_height()); } diff -r bd8202d6d28d -r 90abf4b93cc9 src/vr/opt.c --- a/src/vr/opt.c Fri Aug 22 16:55:16 2014 +0300 +++ b/src/vr/opt.c Fri Aug 22 17:24:43 2014 +0300 @@ -1,81 +1,77 @@ -#include -#include -#include -#include -#include "opt.h" -#include "rbtree.h" - -static void opt_del_func(void *opt, void *cls) -{ - free(opt); -} - -void *create_options(void) -{ - struct rbtree *db = rb_create(RB_KEY_STRING); - rb_set_delete_func(db, opt_del_func, 0); - return db; -} - -void destroy_options(void *optdb) -{ - rb_destroy(optdb); -} - -void set_option_int(void *optdb, const char *key, int val) -{ - struct option *opt = malloc(sizeof *opt); - if(!opt) { - fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno)); - return; - } - opt->type = OTYPE_INT; - opt->ival = val; - opt->fval = (float)val; - - if(rb_insert(optdb, (void*)key, opt) == -1) { - fprintf(stderr, "failed to set option: %s\n", key); - } - printf("stored %s -> %p\n", key, opt); -} - -void set_option_float(void *optdb, const char *key, float val) -{ - struct option *opt = malloc(sizeof *opt); - if(!opt) { - fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno)); - return; - } - opt->type = OTYPE_FLOAT; - opt->fval = val; - opt->ival = (int)val; - - if(rb_insert(optdb, (void*)key, opt) == -1) { - fprintf(stderr, "failed to set option: %s\n", key); - } - printf("stored %s -> %p\n", key, opt); -} - -int get_option_int(void *optdb, const char *key, int *val) -{ - struct option *opt = rb_find(optdb, (void*)key); - if(!opt) { - *val = 0; - return -1; - } - printf("got %s -> %p\n", key, opt); - *val = opt->ival; - return 0; -} - -int get_option_float(void *optdb, const char *key, float *val) -{ - struct option *opt = rb_find(optdb, (void*)key); - if(!opt) { - *val = 0.0f; - return -1; - } - printf("got %s -> %p\n", key, opt); - *val = opt->fval; - return 0; -} +#include +#include +#include +#include +#include "opt.h" +#include "rbtree.h" + +static void opt_del_func(void *opt, void *cls) +{ + free(opt); +} + +void *create_options(void) +{ + struct rbtree *db = rb_create(RB_KEY_STRING); + rb_set_delete_func(db, opt_del_func, 0); + return db; +} + +void destroy_options(void *optdb) +{ + rb_destroy(optdb); +} + +void set_option_int(void *optdb, const char *key, int val) +{ + struct option *opt = malloc(sizeof *opt); + if(!opt) { + fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno)); + return; + } + opt->type = OTYPE_INT; + opt->ival = val; + opt->fval = (float)val; + + if(rb_insert(optdb, (void*)key, opt) == -1) { + fprintf(stderr, "failed to set option: %s\n", key); + } +} + +void set_option_float(void *optdb, const char *key, float val) +{ + struct option *opt = malloc(sizeof *opt); + if(!opt) { + fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno)); + return; + } + opt->type = OTYPE_FLOAT; + opt->fval = val; + opt->ival = (int)val; + + if(rb_insert(optdb, (void*)key, opt) == -1) { + fprintf(stderr, "failed to set option: %s\n", key); + } +} + +int get_option_int(void *optdb, const char *key, int *val) +{ + struct option *opt = rb_find(optdb, (void*)key); + if(!opt) { + *val = 0; + return -1; + } + *val = opt->ival; + return 0; +} + +int get_option_float(void *optdb, const char *key, float *val) +{ + struct option *opt = rb_find(optdb, (void*)key); + if(!opt) { + *val = 0.0f; + return -1; + } + *val = opt->fval; + return 0; +} diff -r bd8202d6d28d -r 90abf4b93cc9 src/vr/opt.h --- a/src/vr/opt.h Fri Aug 22 16:55:16 2014 +0300 +++ b/src/vr/opt.h Fri Aug 22 17:24:43 2014 +0300 @@ -1,21 +1,21 @@ -#ifndef OPT_H_ -#define OPT_H_ - -enum opt_type { OTYPE_INT, OTYPE_FLOAT }; - -struct option { - enum opt_type type; - int ival; - float fval; -}; - -void *create_options(void); -void destroy_options(void *optdb); - -void set_option_int(void *optdb, const char *key, int val); -void set_option_float(void *optdb, const char *key, float val); - -int get_option_int(void *optdb, const char *key, int *val); -int get_option_float(void *optdb, const char *key, float *val); - -#endif /* OPT_H_ */ \ No newline at end of file +#ifndef OPT_H_ +#define OPT_H_ + +enum opt_type { OTYPE_INT, OTYPE_FLOAT }; + +struct option { + enum opt_type type; + int ival; + float fval; +}; + +void *create_options(void); +void destroy_options(void *optdb); + +void set_option_int(void *optdb, const char *key, int val); +void set_option_float(void *optdb, const char *key, float val); + +int get_option_int(void *optdb, const char *key, int *val); +int get_option_float(void *optdb, const char *key, float *val); + +#endif /* OPT_H_ */ diff -r bd8202d6d28d -r 90abf4b93cc9 src/vr/vr.c --- a/src/vr/vr.c Fri Aug 22 16:55:16 2014 +0300 +++ b/src/vr/vr.c Fri Aug 22 17:24:43 2014 +0300 @@ -4,6 +4,9 @@ #include "vr_impl.h" +static void swap_buffers(void); + + static struct vr_module *vrm; static float idmat[] = { 1, 0, 0, 0, @@ -176,13 +179,18 @@ int vr_swap_buffers(void) { + int res = 0; + if(vrm && vrm->present) { - vrm->present(); - return 1; + res = vrm->present(); + } + + if(!res) { + swap_buffers(); } return 0; } - + void vr_output_texture(unsigned int tex, float umin, float vmin, float umax, float vmax) { float halfu = (umax + umin) * 0.5f; @@ -203,4 +211,24 @@ if(vrm && vrm->recenter) { vrm->recenter(); } -} \ No newline at end of file +} + + +#ifdef __unix__ +#include + +static void swap_buffers(void) +{ + glXSwapBuffers(glXGetCurrentDisplay(), glXGetCurrentDrawable()); +} + +#endif + +#ifdef WIN32 +#include + +static void swap_buffers(void) +{ + SwapBuffers(wglGetCurrentDC()); +} +#endif diff -r bd8202d6d28d -r 90abf4b93cc9 src/vr/vr_impl.h --- a/src/vr/vr_impl.h Fri Aug 22 16:55:16 2014 +0300 +++ b/src/vr/vr_impl.h Fri Aug 22 17:24:43 2014 +0300 @@ -20,7 +20,7 @@ void (*begin)(int eye); void (*end)(void); - void (*present)(void); + int (*present)(void); void (*set_eye_texture)(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax); diff -r bd8202d6d28d -r 90abf4b93cc9 src/vr/vr_libovr.c --- a/src/vr/vr_libovr.c Fri Aug 22 16:55:16 2014 +0300 +++ b/src/vr/vr_libovr.c Fri Aug 22 17:24:43 2014 +0300 @@ -205,12 +205,14 @@ } } -static void present(void) +static int present(void) { if(!hmd) return; ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture); new_frame = 1; + + return 1; } static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax) diff -r bd8202d6d28d -r 90abf4b93cc9 src/vr/vr_null.c --- a/src/vr/vr_null.c Fri Aug 22 16:55:16 2014 +0300 +++ b/src/vr/vr_null.c Fri Aug 22 17:24:43 2014 +0300 @@ -2,13 +2,11 @@ #define WIN32_LEAN_AND_MEAN #include #endif - #ifdef __APPLE__ #include #else #include #endif - #include "vr_impl.h" static unsigned int eye_tex[2]; @@ -20,7 +18,7 @@ return 0; } -static void present(void) +static int present(void) { int i; @@ -61,10 +59,7 @@ glPopMatrix(); glPopAttrib(); - -#ifdef WIN32 - SwapBuffers(wglGetCurrentDC()); -#endif + return 0; } static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)