conworlds

changeset 8:90abf4b93cc9

fixed line endings fixed viewport when returning to original framebuffer
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Aug 2014 17:24:43 +0300
parents bd8202d6d28d
children c2eecf764daa
files src/game.cc src/vr/opt.c src/vr/opt.h src/vr/vr.c src/vr/vr_impl.h src/vr/vr_libovr.c src/vr/vr_null.c
diffstat 7 files changed, 138 insertions(+), 115 deletions(-) [+]
line diff
     1.1 --- a/src/game.cc	Fri Aug 22 16:55:16 2014 +0300
     1.2 +++ b/src/game.cc	Fri Aug 22 17:24:43 2014 +0300
     1.3 @@ -102,6 +102,8 @@
     1.4  	vr_end();
     1.5  
     1.6  	glBindFramebuffer(GL_FRAMEBUFFER, 0);
     1.7 +	glViewport(0, 0, fb_width, fb_height);
     1.8 +
     1.9  	vr_output_texture(rtarg->get_texture_id(), 0, 0, (float)rtwidth / (float)rtarg->get_width(),
    1.10  		(float)rtheight / (float)rtarg->get_height());
    1.11  }
     2.1 --- a/src/vr/opt.c	Fri Aug 22 16:55:16 2014 +0300
     2.2 +++ b/src/vr/opt.c	Fri Aug 22 17:24:43 2014 +0300
     2.3 @@ -1,81 +1,77 @@
     2.4 -#include <stdio.h>
     2.5 -#include <stdlib.h>
     2.6 -#include <string.h>
     2.7 -#include <errno.h>
     2.8 -#include "opt.h"
     2.9 -#include "rbtree.h"
    2.10 -
    2.11 -static void opt_del_func(void *opt, void *cls)
    2.12 -{
    2.13 -	free(opt);
    2.14 -}
    2.15 -
    2.16 -void *create_options(void)
    2.17 -{
    2.18 -	struct rbtree *db = rb_create(RB_KEY_STRING);
    2.19 -	rb_set_delete_func(db, opt_del_func, 0);
    2.20 -	return db;
    2.21 -}
    2.22 -
    2.23 -void destroy_options(void *optdb)
    2.24 -{
    2.25 -	rb_destroy(optdb);
    2.26 -}
    2.27 -
    2.28 -void set_option_int(void *optdb, const char *key, int val)
    2.29 -{
    2.30 -	struct option *opt = malloc(sizeof *opt);
    2.31 -	if(!opt) {
    2.32 -		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    2.33 -		return;
    2.34 -	}
    2.35 -	opt->type = OTYPE_INT;
    2.36 -	opt->ival = val;
    2.37 -	opt->fval = (float)val;
    2.38 -
    2.39 -	if(rb_insert(optdb, (void*)key, opt) == -1) {
    2.40 -		fprintf(stderr, "failed to set option: %s\n", key);
    2.41 -	}
    2.42 -	printf("stored %s -> %p\n", key, opt);
    2.43 -}
    2.44 -
    2.45 -void set_option_float(void *optdb, const char *key, float val)
    2.46 -{
    2.47 -	struct option *opt = malloc(sizeof *opt);
    2.48 -	if(!opt) {
    2.49 -		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    2.50 -		return;
    2.51 -	}
    2.52 -	opt->type = OTYPE_FLOAT;
    2.53 -	opt->fval = val;
    2.54 -	opt->ival = (int)val;
    2.55 -
    2.56 -	if(rb_insert(optdb, (void*)key, opt) == -1) {
    2.57 -		fprintf(stderr, "failed to set option: %s\n", key);
    2.58 -	}
    2.59 -	printf("stored %s -> %p\n", key, opt);
    2.60 -}
    2.61 -
    2.62 -int get_option_int(void *optdb, const char *key, int *val)
    2.63 -{
    2.64 -	struct option *opt = rb_find(optdb, (void*)key);
    2.65 -	if(!opt) {
    2.66 -		*val = 0;
    2.67 -		return -1;
    2.68 -	}
    2.69 -	printf("got %s -> %p\n", key, opt);
    2.70 -	*val = opt->ival;
    2.71 -	return 0;
    2.72 -}
    2.73 -
    2.74 -int get_option_float(void *optdb, const char *key, float *val)
    2.75 -{
    2.76 -	struct option *opt = rb_find(optdb, (void*)key);
    2.77 -	if(!opt) {
    2.78 -		*val = 0.0f;
    2.79 -		return -1;
    2.80 -	}
    2.81 -	printf("got %s -> %p\n", key, opt);
    2.82 -	*val = opt->fval;
    2.83 -	return 0;
    2.84 -}
    2.85 +#include <stdio.h>
    2.86 +#include <stdlib.h>
    2.87 +#include <string.h>
    2.88 +#include <errno.h>
    2.89 +#include "opt.h"
    2.90 +#include "rbtree.h"
    2.91 +
    2.92 +static void opt_del_func(void *opt, void *cls)
    2.93 +{
    2.94 +	free(opt);
    2.95 +}
    2.96 +
    2.97 +void *create_options(void)
    2.98 +{
    2.99 +	struct rbtree *db = rb_create(RB_KEY_STRING);
   2.100 +	rb_set_delete_func(db, opt_del_func, 0);
   2.101 +	return db;
   2.102 +}
   2.103 +
   2.104 +void destroy_options(void *optdb)
   2.105 +{
   2.106 +	rb_destroy(optdb);
   2.107 +}
   2.108 +
   2.109 +void set_option_int(void *optdb, const char *key, int val)
   2.110 +{
   2.111 +	struct option *opt = malloc(sizeof *opt);
   2.112 +	if(!opt) {
   2.113 +		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
   2.114 +		return;
   2.115 +	}
   2.116 +	opt->type = OTYPE_INT;
   2.117 +	opt->ival = val;
   2.118 +	opt->fval = (float)val;
   2.119 +
   2.120 +	if(rb_insert(optdb, (void*)key, opt) == -1) {
   2.121 +		fprintf(stderr, "failed to set option: %s\n", key);
   2.122 +	}
   2.123 +}
   2.124 +
   2.125 +void set_option_float(void *optdb, const char *key, float val)
   2.126 +{
   2.127 +	struct option *opt = malloc(sizeof *opt);
   2.128 +	if(!opt) {
   2.129 +		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
   2.130 +		return;
   2.131 +	}
   2.132 +	opt->type = OTYPE_FLOAT;
   2.133 +	opt->fval = val;
   2.134 +	opt->ival = (int)val;
   2.135 +
   2.136 +	if(rb_insert(optdb, (void*)key, opt) == -1) {
   2.137 +		fprintf(stderr, "failed to set option: %s\n", key);
   2.138 +	}
   2.139 +}
   2.140 +
   2.141 +int get_option_int(void *optdb, const char *key, int *val)
   2.142 +{
   2.143 +	struct option *opt = rb_find(optdb, (void*)key);
   2.144 +	if(!opt) {
   2.145 +		*val = 0;
   2.146 +		return -1;
   2.147 +	}
   2.148 +	*val = opt->ival;
   2.149 +	return 0;
   2.150 +}
   2.151 +
   2.152 +int get_option_float(void *optdb, const char *key, float *val)
   2.153 +{
   2.154 +	struct option *opt = rb_find(optdb, (void*)key);
   2.155 +	if(!opt) {
   2.156 +		*val = 0.0f;
   2.157 +		return -1;
   2.158 +	}
   2.159 +	*val = opt->fval;
   2.160 +	return 0;
   2.161 +}
     3.1 --- a/src/vr/opt.h	Fri Aug 22 16:55:16 2014 +0300
     3.2 +++ b/src/vr/opt.h	Fri Aug 22 17:24:43 2014 +0300
     3.3 @@ -1,21 +1,21 @@
     3.4 -#ifndef OPT_H_
     3.5 -#define OPT_H_
     3.6 -
     3.7 -enum opt_type { OTYPE_INT, OTYPE_FLOAT };
     3.8 -
     3.9 -struct option {
    3.10 -	enum opt_type type;
    3.11 -	int ival;
    3.12 -	float fval;
    3.13 -};
    3.14 -
    3.15 -void *create_options(void);
    3.16 -void destroy_options(void *optdb);
    3.17 -
    3.18 -void set_option_int(void *optdb, const char *key, int val);
    3.19 -void set_option_float(void *optdb, const char *key, float val);
    3.20 -
    3.21 -int get_option_int(void *optdb, const char *key, int *val);
    3.22 -int get_option_float(void *optdb, const char *key, float *val);
    3.23 -
    3.24 -#endif	/* OPT_H_ */
    3.25 \ No newline at end of file
    3.26 +#ifndef OPT_H_
    3.27 +#define OPT_H_
    3.28 +
    3.29 +enum opt_type { OTYPE_INT, OTYPE_FLOAT };
    3.30 +
    3.31 +struct option {
    3.32 +	enum opt_type type;
    3.33 +	int ival;
    3.34 +	float fval;
    3.35 +};
    3.36 +
    3.37 +void *create_options(void);
    3.38 +void destroy_options(void *optdb);
    3.39 +
    3.40 +void set_option_int(void *optdb, const char *key, int val);
    3.41 +void set_option_float(void *optdb, const char *key, float val);
    3.42 +
    3.43 +int get_option_int(void *optdb, const char *key, int *val);
    3.44 +int get_option_float(void *optdb, const char *key, float *val);
    3.45 +
    3.46 +#endif	/* OPT_H_ */
     4.1 --- a/src/vr/vr.c	Fri Aug 22 16:55:16 2014 +0300
     4.2 +++ b/src/vr/vr.c	Fri Aug 22 17:24:43 2014 +0300
     4.3 @@ -4,6 +4,9 @@
     4.4  #include "vr_impl.h"
     4.5  
     4.6  
     4.7 +static void swap_buffers(void);
     4.8 +
     4.9 +
    4.10  static struct vr_module *vrm;
    4.11  static float idmat[] = {
    4.12  	1, 0, 0, 0,
    4.13 @@ -176,13 +179,18 @@
    4.14  
    4.15  int vr_swap_buffers(void)
    4.16  {
    4.17 +	int res = 0;
    4.18 +
    4.19  	if(vrm && vrm->present) {
    4.20 -		vrm->present();
    4.21 -		return 1;
    4.22 +		res = vrm->present();
    4.23 +	}
    4.24 +
    4.25 +	if(!res) {
    4.26 +		swap_buffers();
    4.27  	}
    4.28  	return 0;
    4.29  }
    4.30 -
    4.31 +
    4.32  void vr_output_texture(unsigned int tex, float umin, float vmin, float umax, float vmax)
    4.33  {
    4.34  	float halfu = (umax + umin) * 0.5f;
    4.35 @@ -203,4 +211,24 @@
    4.36  	if(vrm && vrm->recenter) {
    4.37  		vrm->recenter();
    4.38  	}
    4.39 -}
    4.40 \ No newline at end of file
    4.41 +}
    4.42 +
    4.43 +
    4.44 +#ifdef __unix__
    4.45 +#include <GL/glx.h>
    4.46 +
    4.47 +static void swap_buffers(void)
    4.48 +{
    4.49 +	glXSwapBuffers(glXGetCurrentDisplay(), glXGetCurrentDrawable());
    4.50 +}
    4.51 +
    4.52 +#endif
    4.53 +
    4.54 +#ifdef WIN32
    4.55 +#include <windows.h>
    4.56 +
    4.57 +static void swap_buffers(void)
    4.58 +{
    4.59 +	SwapBuffers(wglGetCurrentDC());
    4.60 +}
    4.61 +#endif
     5.1 --- a/src/vr/vr_impl.h	Fri Aug 22 16:55:16 2014 +0300
     5.2 +++ b/src/vr/vr_impl.h	Fri Aug 22 17:24:43 2014 +0300
     5.3 @@ -20,7 +20,7 @@
     5.4  
     5.5  	void (*begin)(int eye);
     5.6  	void (*end)(void);
     5.7 -	void (*present)(void);
     5.8 +	int (*present)(void);
     5.9  
    5.10  	void (*set_eye_texture)(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax);
    5.11  
     6.1 --- a/src/vr/vr_libovr.c	Fri Aug 22 16:55:16 2014 +0300
     6.2 +++ b/src/vr/vr_libovr.c	Fri Aug 22 17:24:43 2014 +0300
     6.3 @@ -205,12 +205,14 @@
     6.4  	}
     6.5  }
     6.6  
     6.7 -static void present(void)
     6.8 +static int present(void)
     6.9  {
    6.10  	if(!hmd) return;
    6.11  
    6.12  	ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture);
    6.13  	new_frame = 1;
    6.14 +
    6.15 +	return 1;
    6.16  }
    6.17  
    6.18  static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
     7.1 --- a/src/vr/vr_null.c	Fri Aug 22 16:55:16 2014 +0300
     7.2 +++ b/src/vr/vr_null.c	Fri Aug 22 17:24:43 2014 +0300
     7.3 @@ -2,13 +2,11 @@
     7.4  #define WIN32_LEAN_AND_MEAN
     7.5  #include <windows.h>
     7.6  #endif
     7.7 -
     7.8  #ifdef __APPLE__
     7.9  #include <OpenGL/gl.h>
    7.10  #else
    7.11  #include <GL/gl.h>
    7.12  #endif
    7.13 -
    7.14  #include "vr_impl.h"
    7.15  
    7.16  static unsigned int eye_tex[2];
    7.17 @@ -20,7 +18,7 @@
    7.18  	return 0;
    7.19  }
    7.20  
    7.21 -static void present(void)
    7.22 +static int present(void)
    7.23  {
    7.24  	int i;
    7.25  
    7.26 @@ -61,10 +59,7 @@
    7.27  	glPopMatrix();
    7.28  
    7.29  	glPopAttrib();
    7.30 -
    7.31 -#ifdef WIN32
    7.32 -	SwapBuffers(wglGetCurrentDC());
    7.33 -#endif
    7.34 +	return 0;
    7.35  }
    7.36  
    7.37  static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)