conworlds

changeset 22:5f53272ff612 tip

removed the vr wrapper and added an external dependency to libgoatvr
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 29 Aug 2014 07:44:26 +0300
parents 2da585428507
children
files conworlds.vcxproj conworlds.vcxproj.filters src/vr/mathutil.c src/vr/mathutil.h src/vr/opt.c src/vr/opt.h src/vr/rbtree.c src/vr/rbtree.h src/vr/vr.c src/vr/vr.h src/vr/vr_impl.h src/vr/vr_libovr.c src/vr/vr_modules.c src/vr/vr_null.c src/vr/vr_openhmd.c
diffstat 15 files changed, 2 insertions(+), 1886 deletions(-) [+]
line diff
     1.1 --- a/conworlds.vcxproj	Wed Aug 27 04:16:22 2014 +0300
     1.2 +++ b/conworlds.vcxproj	Fri Aug 29 07:44:26 2014 +0300
     1.3 @@ -58,7 +58,7 @@
     1.4      <Link>
     1.5        <SubSystem>Console</SubSystem>
     1.6        <GenerateDebugInformation>true</GenerateDebugInformation>
     1.7 -      <AdditionalDependencies>opengl32.lib;freeglutd.lib;glew32.lib;libvmath.lib;libanim.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovrd.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.8 +      <AdditionalDependencies>opengl32.lib;libgoatvr.lib;freeglutd.lib;glew32.lib;libvmath.lib;libanim.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.9      </Link>
    1.10    </ItemDefinitionGroup>
    1.11    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    1.12 @@ -78,7 +78,7 @@
    1.13        <GenerateDebugInformation>true</GenerateDebugInformation>
    1.14        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    1.15        <OptimizeReferences>true</OptimizeReferences>
    1.16 -      <AdditionalDependencies>opengl32.lib;freeglut.lib;glew32.lib;libvmath.lib;libanim.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovr.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.17 +      <AdditionalDependencies>opengl32.lib;libgoatvr.lib;freeglut.lib;glew32.lib;libvmath.lib;libanim.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.18      </Link>
    1.19    </ItemDefinitionGroup>
    1.20    <ItemGroup>
    1.21 @@ -101,14 +101,6 @@
    1.22      <ClCompile Include="src\shader.cc" />
    1.23      <ClCompile Include="src\texture.cc" />
    1.24      <ClCompile Include="src\unistate.cc" />
    1.25 -    <ClCompile Include="src\vr\mathutil.c" />
    1.26 -    <ClCompile Include="src\vr\opt.c" />
    1.27 -    <ClCompile Include="src\vr\rbtree.c" />
    1.28 -    <ClCompile Include="src\vr\vr.c" />
    1.29 -    <ClCompile Include="src\vr\vr_libovr.c" />
    1.30 -    <ClCompile Include="src\vr\vr_modules.c" />
    1.31 -    <ClCompile Include="src\vr\vr_null.c" />
    1.32 -    <ClCompile Include="src\vr\vr_openhmd.c" />
    1.33      <ClCompile Include="src\xform_node.cc" />
    1.34    </ItemGroup>
    1.35    <ItemGroup>
    1.36 @@ -130,11 +122,6 @@
    1.37      <ClInclude Include="src\shader.h" />
    1.38      <ClInclude Include="src\texture.h" />
    1.39      <ClInclude Include="src\unistate.h" />
    1.40 -    <ClInclude Include="src\vr\mathutil.h" />
    1.41 -    <ClInclude Include="src\vr\opt.h" />
    1.42 -    <ClInclude Include="src\vr\rbtree.h" />
    1.43 -    <ClInclude Include="src\vr\vr.h" />
    1.44 -    <ClInclude Include="src\vr\vr_impl.h" />
    1.45      <ClInclude Include="src\xform_node.h" />
    1.46    </ItemGroup>
    1.47    <ItemGroup>
     2.1 --- a/conworlds.vcxproj.filters	Wed Aug 27 04:16:22 2014 +0300
     2.2 +++ b/conworlds.vcxproj.filters	Fri Aug 29 07:44:26 2014 +0300
     2.3 @@ -5,9 +5,6 @@
     2.4        <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     2.5        <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;inl</Extensions>
     2.6      </Filter>
     2.7 -    <Filter Include="src\vr">
     2.8 -      <UniqueIdentifier>{e881ab02-1a45-43f6-a15d-ee7f77256a1e}</UniqueIdentifier>
     2.9 -    </Filter>
    2.10      <Filter Include="src\sdl">
    2.11        <UniqueIdentifier>{4b658839-b773-4d11-9744-27a21bb1312c}</UniqueIdentifier>
    2.12      </Filter>
    2.13 @@ -34,30 +31,6 @@
    2.14      <ClCompile Include="src\texture.cc">
    2.15        <Filter>src</Filter>
    2.16      </ClCompile>
    2.17 -    <ClCompile Include="src\vr\vr.c">
    2.18 -      <Filter>src\vr</Filter>
    2.19 -    </ClCompile>
    2.20 -    <ClCompile Include="src\vr\vr_libovr.c">
    2.21 -      <Filter>src\vr</Filter>
    2.22 -    </ClCompile>
    2.23 -    <ClCompile Include="src\vr\vr_modules.c">
    2.24 -      <Filter>src\vr</Filter>
    2.25 -    </ClCompile>
    2.26 -    <ClCompile Include="src\vr\vr_null.c">
    2.27 -      <Filter>src\vr</Filter>
    2.28 -    </ClCompile>
    2.29 -    <ClCompile Include="src\vr\rbtree.c">
    2.30 -      <Filter>src\vr</Filter>
    2.31 -    </ClCompile>
    2.32 -    <ClCompile Include="src\vr\opt.c">
    2.33 -      <Filter>src\vr</Filter>
    2.34 -    </ClCompile>
    2.35 -    <ClCompile Include="src\vr\vr_openhmd.c">
    2.36 -      <Filter>src\vr</Filter>
    2.37 -    </ClCompile>
    2.38 -    <ClCompile Include="src\vr\mathutil.c">
    2.39 -      <Filter>src\vr</Filter>
    2.40 -    </ClCompile>
    2.41      <ClCompile Include="src\assload.cc">
    2.42        <Filter>src</Filter>
    2.43      </ClCompile>
    2.44 @@ -120,21 +93,6 @@
    2.45      <ClInclude Include="src\texture.h">
    2.46        <Filter>src</Filter>
    2.47      </ClInclude>
    2.48 -    <ClInclude Include="src\vr\vr.h">
    2.49 -      <Filter>src\vr</Filter>
    2.50 -    </ClInclude>
    2.51 -    <ClInclude Include="src\vr\vr_impl.h">
    2.52 -      <Filter>src\vr</Filter>
    2.53 -    </ClInclude>
    2.54 -    <ClInclude Include="src\vr\rbtree.h">
    2.55 -      <Filter>src\vr</Filter>
    2.56 -    </ClInclude>
    2.57 -    <ClInclude Include="src\vr\opt.h">
    2.58 -      <Filter>src\vr</Filter>
    2.59 -    </ClInclude>
    2.60 -    <ClInclude Include="src\vr\mathutil.h">
    2.61 -      <Filter>src\vr</Filter>
    2.62 -    </ClInclude>
    2.63      <ClInclude Include="src\assload.h">
    2.64        <Filter>src</Filter>
    2.65      </ClInclude>
     3.1 --- a/src/vr/mathutil.c	Wed Aug 27 04:16:22 2014 +0300
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,78 +0,0 @@
     3.4 -#include <stdio.h>
     3.5 -#include <string.h>
     3.6 -#include "mathutil.h"
     3.7 -
     3.8 -#define M(i, j)	((i) * 4 + (j))
     3.9 -
    3.10 -static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
    3.11 -
    3.12 -void rotation_matrix(const float *quat, float *matrix)
    3.13 -{
    3.14 -	matrix[0] = 1.0 - 2.0 * quat[1] * quat[1] - 2.0 * quat[2] * quat[2];
    3.15 -	matrix[1] = 2.0 * quat[0] * quat[1] + 2.0 * quat[3] * quat[2];
    3.16 -	matrix[2] = 2.0 * quat[2] * quat[0] - 2.0 * quat[3] * quat[1];
    3.17 -	matrix[3] = 0.0f;
    3.18 -
    3.19 -	matrix[4] = 2.0 * quat[0] * quat[1] - 2.0 * quat[3] * quat[2];
    3.20 -	matrix[5] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[2]*quat[2];
    3.21 -	matrix[6] = 2.0 * quat[1] * quat[2] + 2.0 * quat[3] * quat[0];
    3.22 -	matrix[7] = 0.0f;
    3.23 -
    3.24 -	matrix[8] = 2.0 * quat[2] * quat[0] + 2.0 * quat[3] * quat[1];
    3.25 -	matrix[9] = 2.0 * quat[1] * quat[2] - 2.0 * quat[3] * quat[0];
    3.26 -	matrix[10] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[1]*quat[1];
    3.27 -	matrix[11] = 0.0f;
    3.28 -
    3.29 -	matrix[12] = matrix[13] = matrix[14] = 0.0f;
    3.30 -	matrix[15] = 1.0f;
    3.31 -
    3.32 -	transpose_matrix(matrix);
    3.33 -}
    3.34 -
    3.35 -void translation_matrix(const float *vec, float *matrix)
    3.36 -{
    3.37 -	memcpy(matrix, idmat, sizeof idmat);
    3.38 -	matrix[12] = vec[0];
    3.39 -	matrix[13] = vec[1];
    3.40 -	matrix[14] = vec[2];
    3.41 -}
    3.42 -
    3.43 -void mult_matrix(float *dest, const float *m1, const float *m2)
    3.44 -{
    3.45 -	int i, j;
    3.46 -	float tmp[16];
    3.47 -
    3.48 -	for(i=0; i<4; i++) {
    3.49 -		for(j=0; j<4; j++) {
    3.50 -			tmp[M(i, j)] = m1[M(i, 0)] * m2[M(0, j)] + m1[M(i, 1)] * m2[M(1, j)] +
    3.51 -				m1[M(i, 2)] * m2[M(2, j)] + m1[M(i, 3)] * m2[M(3, j)];
    3.52 -		}
    3.53 -	}
    3.54 -	memcpy(dest, tmp, sizeof tmp);
    3.55 -}
    3.56 -
    3.57 -void transpose_matrix(float *matrix)
    3.58 -{
    3.59 -	int i, j;
    3.60 -	float tmp[16];
    3.61 -
    3.62 -	for(i=0; i<4; i++) {
    3.63 -		for(j=0; j<4; j++) {
    3.64 -			tmp[M(i, j)] = matrix[M(j, i)];
    3.65 -		}
    3.66 -	}
    3.67 -	memcpy(matrix, tmp, sizeof tmp);
    3.68 -}
    3.69 -
    3.70 -void print_matrix(const float *matrix)
    3.71 -{
    3.72 -	int i, j;
    3.73 -
    3.74 -	for(i=0; i<4; i++) {
    3.75 -		putchar('[');
    3.76 -		for(j=0; j<4; j++) {
    3.77 -			printf("%6.3f ", matrix[M(i, j)]);
    3.78 -		}
    3.79 -		printf("]\n");
    3.80 -	}
    3.81 -}
     4.1 --- a/src/vr/mathutil.h	Wed Aug 27 04:16:22 2014 +0300
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,13 +0,0 @@
     4.4 -#ifndef MATHUTIL_H_
     4.5 -#define MATHUTIL_H_
     4.6 -
     4.7 -void rotation_matrix(const float *quat, float *matrix);
     4.8 -void translation_matrix(const float *vec, float *matrix);
     4.9 -
    4.10 -void mult_matrix(float *dest, const float *m1, const float *m2);
    4.11 -
    4.12 -void transpose_matrix(float *matrix);
    4.13 -
    4.14 -void print_matrix(const float *matrix);
    4.15 -
    4.16 -#endif	/* MATHUTIL_H_ */
     5.1 --- a/src/vr/opt.c	Wed Aug 27 04:16:22 2014 +0300
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,77 +0,0 @@
     5.4 -#include <stdio.h>
     5.5 -#include <stdlib.h>
     5.6 -#include <string.h>
     5.7 -#include <errno.h>
     5.8 -#include "opt.h"
     5.9 -#include "rbtree.h"
    5.10 -
    5.11 -static void opt_del_func(struct rbnode *opt, void *cls)
    5.12 -{
    5.13 -	free(opt);
    5.14 -}
    5.15 -
    5.16 -void *create_options(void)
    5.17 -{
    5.18 -	struct rbtree *db = rb_create(RB_KEY_STRING);
    5.19 -	rb_set_delete_func(db, opt_del_func, 0);
    5.20 -	return db;
    5.21 -}
    5.22 -
    5.23 -void destroy_options(void *optdb)
    5.24 -{
    5.25 -	rb_destroy(optdb);
    5.26 -}
    5.27 -
    5.28 -void set_option_int(void *optdb, const char *key, int val)
    5.29 -{
    5.30 -	struct option *opt = malloc(sizeof *opt);
    5.31 -	if(!opt) {
    5.32 -		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    5.33 -		return;
    5.34 -	}
    5.35 -	opt->type = OTYPE_INT;
    5.36 -	opt->ival = val;
    5.37 -	opt->fval = (float)val;
    5.38 -
    5.39 -	if(rb_insert(optdb, (void*)key, opt) == -1) {
    5.40 -		fprintf(stderr, "failed to set option: %s\n", key);
    5.41 -	}
    5.42 -}
    5.43 -
    5.44 -void set_option_float(void *optdb, const char *key, float val)
    5.45 -{
    5.46 -	struct option *opt = malloc(sizeof *opt);
    5.47 -	if(!opt) {
    5.48 -		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    5.49 -		return;
    5.50 -	}
    5.51 -	opt->type = OTYPE_FLOAT;
    5.52 -	opt->fval = val;
    5.53 -	opt->ival = (int)val;
    5.54 -
    5.55 -	if(rb_insert(optdb, (void*)key, opt) == -1) {
    5.56 -		fprintf(stderr, "failed to set option: %s\n", key);
    5.57 -	}
    5.58 -}
    5.59 -
    5.60 -int get_option_int(void *optdb, const char *key, int *val)
    5.61 -{
    5.62 -	struct option *opt = rb_find(optdb, (void*)key);
    5.63 -	if(!opt) {
    5.64 -		*val = 0;
    5.65 -		return -1;
    5.66 -	}
    5.67 -	*val = opt->ival;
    5.68 -	return 0;
    5.69 -}
    5.70 -
    5.71 -int get_option_float(void *optdb, const char *key, float *val)
    5.72 -{
    5.73 -	struct option *opt = rb_find(optdb, (void*)key);
    5.74 -	if(!opt) {
    5.75 -		*val = 0.0f;
    5.76 -		return -1;
    5.77 -	}
    5.78 -	*val = opt->fval;
    5.79 -	return 0;
    5.80 -}
     6.1 --- a/src/vr/opt.h	Wed Aug 27 04:16:22 2014 +0300
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,21 +0,0 @@
     6.4 -#ifndef OPT_H_
     6.5 -#define OPT_H_
     6.6 -
     6.7 -enum opt_type { OTYPE_INT, OTYPE_FLOAT };
     6.8 -
     6.9 -struct option {
    6.10 -	enum opt_type type;
    6.11 -	int ival;
    6.12 -	float fval;
    6.13 -};
    6.14 -
    6.15 -void *create_options(void);
    6.16 -void destroy_options(void *optdb);
    6.17 -
    6.18 -void set_option_int(void *optdb, const char *key, int val);
    6.19 -void set_option_float(void *optdb, const char *key, float val);
    6.20 -
    6.21 -int get_option_int(void *optdb, const char *key, int *val);
    6.22 -int get_option_float(void *optdb, const char *key, float *val);
    6.23 -
    6.24 -#endif	/* OPT_H_ */
     7.1 --- a/src/vr/rbtree.c	Wed Aug 27 04:16:22 2014 +0300
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,501 +0,0 @@
     7.4 -/*
     7.5 -rbtree - simple balanced binary search tree (red-black tree) library.
     7.6 -Copyright (C) 2011-2014  John Tsiombikas <nuclear@member.fsf.org>
     7.7 -
     7.8 -rbtree is free software, feel free to use, modify, and redistribute it, under
     7.9 -the terms of the 3-clause BSD license. See COPYING for details.
    7.10 - */
    7.11 -#include <stdio.h>
    7.12 -#include <stdlib.h>
    7.13 -#include <stdint.h>
    7.14 -#include <string.h>
    7.15 -#include "rbtree.h"
    7.16 -
    7.17 -#define INT2PTR(x)	((void*)(intptr_t)(x))
    7.18 -#define PTR2INT(x)	((int)(intptr_t)(x))
    7.19 -
    7.20 -struct rbtree {
    7.21 -	struct rbnode *root;
    7.22 -
    7.23 -	rb_alloc_func_t alloc;
    7.24 -	rb_free_func_t free;
    7.25 -
    7.26 -	rb_cmp_func_t cmp;
    7.27 -	rb_del_func_t del;
    7.28 -	void *del_cls;
    7.29 -
    7.30 -	struct rbnode *rstack, *iter;
    7.31 -};
    7.32 -
    7.33 -static int cmpaddr(const void *ap, const void *bp);
    7.34 -static int cmpint(const void *ap, const void *bp);
    7.35 -
    7.36 -static int count_nodes(struct rbnode *node);
    7.37 -static void del_tree(struct rbnode *node, void (*delfunc)(struct rbnode*, void*), void *cls);
    7.38 -static struct rbnode *insert(struct rbtree *rb, struct rbnode *tree, void *key, void *data);
    7.39 -static struct rbnode *delete(struct rbtree *rb, struct rbnode *tree, void *key);
    7.40 -/*static struct rbnode *find(struct rbtree *rb, struct rbnode *node, void *key);*/
    7.41 -static void traverse(struct rbnode *node, void (*func)(struct rbnode*, void*), void *cls);
    7.42 -
    7.43 -struct rbtree *rb_create(rb_cmp_func_t cmp_func)
    7.44 -{
    7.45 -	struct rbtree *rb;
    7.46 -
    7.47 -	if(!(rb = malloc(sizeof *rb))) {
    7.48 -		return 0;
    7.49 -	}
    7.50 -	if(rb_init(rb, cmp_func) == -1) {
    7.51 -		free(rb);
    7.52 -		return 0;
    7.53 -	}
    7.54 -	return rb;
    7.55 -}
    7.56 -
    7.57 -void rb_free(struct rbtree *rb)
    7.58 -{
    7.59 -	rb_destroy(rb);
    7.60 -	free(rb);
    7.61 -}
    7.62 -
    7.63 -
    7.64 -int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func)
    7.65 -{
    7.66 -	memset(rb, 0, sizeof *rb);
    7.67 -
    7.68 -	if(cmp_func == RB_KEY_INT) {
    7.69 -		rb->cmp = cmpint;
    7.70 -	} else if(cmp_func == RB_KEY_STRING) {
    7.71 -		rb->cmp = (rb_cmp_func_t)strcmp;
    7.72 -	} else {
    7.73 -		rb->cmp = cmpaddr;
    7.74 -	}
    7.75 -
    7.76 -	rb->alloc = malloc;
    7.77 -	rb->free = free;
    7.78 -	return 0;
    7.79 -}
    7.80 -
    7.81 -void rb_destroy(struct rbtree *rb)
    7.82 -{
    7.83 -	del_tree(rb->root, rb->del, rb->del_cls);
    7.84 -}
    7.85 -
    7.86 -void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free)
    7.87 -{
    7.88 -	rb->alloc = alloc;
    7.89 -	rb->free = free;
    7.90 -}
    7.91 -
    7.92 -
    7.93 -void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func)
    7.94 -{
    7.95 -	rb->cmp = func;
    7.96 -}
    7.97 -
    7.98 -void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls)
    7.99 -{
   7.100 -	rb->del = func;
   7.101 -	rb->del_cls = cls;
   7.102 -}
   7.103 -
   7.104 -
   7.105 -void rb_clear(struct rbtree *rb)
   7.106 -{
   7.107 -	del_tree(rb->root, rb->del, rb->del_cls);
   7.108 -	rb->root = 0;
   7.109 -}
   7.110 -
   7.111 -int rb_copy(struct rbtree *dest, struct rbtree *src)
   7.112 -{
   7.113 -	struct rbnode *node;
   7.114 -
   7.115 -	rb_clear(dest);
   7.116 -	rb_begin(src);
   7.117 -	while((node = rb_next(src))) {
   7.118 -		if(rb_insert(dest, node->key, node->data) == -1) {
   7.119 -			return -1;
   7.120 -		}
   7.121 -	}
   7.122 -	return 0;
   7.123 -}
   7.124 -
   7.125 -int rb_size(struct rbtree *rb)
   7.126 -{
   7.127 -	return count_nodes(rb->root);
   7.128 -}
   7.129 -
   7.130 -int rb_insert(struct rbtree *rb, void *key, void *data)
   7.131 -{
   7.132 -	rb->root = insert(rb, rb->root, key, data);
   7.133 -	rb->root->red = 0;
   7.134 -	return 0;
   7.135 -}
   7.136 -
   7.137 -int rb_inserti(struct rbtree *rb, int key, void *data)
   7.138 -{
   7.139 -	rb->root = insert(rb, rb->root, INT2PTR(key), data);
   7.140 -	rb->root->red = 0;
   7.141 -	return 0;
   7.142 -}
   7.143 -
   7.144 -
   7.145 -int rb_delete(struct rbtree *rb, void *key)
   7.146 -{
   7.147 -	rb->root = delete(rb, rb->root, key);
   7.148 -	rb->root->red = 0;
   7.149 -	return 0;
   7.150 -}
   7.151 -
   7.152 -int rb_deletei(struct rbtree *rb, int key)
   7.153 -{
   7.154 -	rb->root = delete(rb, rb->root, INT2PTR(key));
   7.155 -	rb->root->red = 0;
   7.156 -	return 0;
   7.157 -}
   7.158 -
   7.159 -
   7.160 -void *rb_find(struct rbtree *rb, void *key)
   7.161 -{
   7.162 -	struct rbnode *node = rb->root;
   7.163 -
   7.164 -	while(node) {
   7.165 -		int cmp = rb->cmp(key, node->key);
   7.166 -		if(cmp == 0) {
   7.167 -			return node->data;
   7.168 -		}
   7.169 -		node = cmp < 0 ? node->left : node->right;
   7.170 -	}
   7.171 -	return 0;
   7.172 -}
   7.173 -
   7.174 -void *rb_findi(struct rbtree *rb, int key)
   7.175 -{
   7.176 -	return rb_find(rb, INT2PTR(key));
   7.177 -}
   7.178 -
   7.179 -
   7.180 -void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls)
   7.181 -{
   7.182 -	traverse(rb->root, func, cls);
   7.183 -}
   7.184 -
   7.185 -
   7.186 -struct rbnode *rb_root(struct rbtree *rb)
   7.187 -{
   7.188 -	return rb->root;
   7.189 -}
   7.190 -
   7.191 -void rb_begin(struct rbtree *rb)
   7.192 -{
   7.193 -	rb->rstack = 0;
   7.194 -	rb->iter = rb->root;
   7.195 -}
   7.196 -
   7.197 -#define push(sp, x)		((x)->next = (sp), (sp) = (x))
   7.198 -#define pop(sp)			((sp) = (sp)->next)
   7.199 -#define top(sp)			(sp)
   7.200 -
   7.201 -struct rbnode *rb_next(struct rbtree *rb)
   7.202 -{
   7.203 -	struct rbnode *res = 0;
   7.204 -
   7.205 -	while(rb->rstack || rb->iter) {
   7.206 -		if(rb->iter) {
   7.207 -			push(rb->rstack, rb->iter);
   7.208 -			rb->iter = rb->iter->left;
   7.209 -		} else {
   7.210 -			rb->iter = top(rb->rstack);
   7.211 -			pop(rb->rstack);
   7.212 -			res = rb->iter;
   7.213 -			rb->iter = rb->iter->right;
   7.214 -			break;
   7.215 -		}
   7.216 -	}
   7.217 -	return res;
   7.218 -}
   7.219 -
   7.220 -void *rb_node_key(struct rbnode *node)
   7.221 -{
   7.222 -	return node ? node->key : 0;
   7.223 -}
   7.224 -
   7.225 -int rb_node_keyi(struct rbnode *node)
   7.226 -{
   7.227 -	return node ? PTR2INT(node->key) : 0;
   7.228 -}
   7.229 -
   7.230 -void *rb_node_data(struct rbnode *node)
   7.231 -{
   7.232 -	return node ? node->data : 0;
   7.233 -}
   7.234 -
   7.235 -static int cmpaddr(const void *ap, const void *bp)
   7.236 -{
   7.237 -	return ap < bp ? -1 : (ap > bp ? 1 : 0);
   7.238 -}
   7.239 -
   7.240 -static int cmpint(const void *ap, const void *bp)
   7.241 -{
   7.242 -	return PTR2INT(ap) - PTR2INT(bp);
   7.243 -}
   7.244 -
   7.245 -
   7.246 -/* ---- left-leaning 2-3 red-black implementation ---- */
   7.247 -
   7.248 -/* helper prototypes */
   7.249 -static int is_red(struct rbnode *tree);
   7.250 -static void color_flip(struct rbnode *tree);
   7.251 -static struct rbnode *rot_left(struct rbnode *a);
   7.252 -static struct rbnode *rot_right(struct rbnode *a);
   7.253 -static struct rbnode *find_min(struct rbnode *tree);
   7.254 -static struct rbnode *del_min(struct rbtree *rb, struct rbnode *tree);
   7.255 -/*static struct rbnode *move_red_right(struct rbnode *tree);*/
   7.256 -static struct rbnode *move_red_left(struct rbnode *tree);
   7.257 -static struct rbnode *fix_up(struct rbnode *tree);
   7.258 -
   7.259 -static int count_nodes(struct rbnode *node)
   7.260 -{
   7.261 -	if(!node)
   7.262 -		return 0;
   7.263 -
   7.264 -	return 1 + count_nodes(node->left) + count_nodes(node->right);
   7.265 -}
   7.266 -
   7.267 -static void del_tree(struct rbnode *node, rb_del_func_t delfunc, void *cls)
   7.268 -{
   7.269 -	if(!node)
   7.270 -		return;
   7.271 -
   7.272 -	del_tree(node->left, delfunc, cls);
   7.273 -	del_tree(node->right, delfunc, cls);
   7.274 -
   7.275 -	if(delfunc) {
   7.276 -		delfunc(node, cls);
   7.277 -	}
   7.278 -	free(node);
   7.279 -}
   7.280 -
   7.281 -static struct rbnode *insert(struct rbtree *rb, struct rbnode *tree, void *key, void *data)
   7.282 -{
   7.283 -	int cmp;
   7.284 -
   7.285 -	if(!tree) {
   7.286 -		struct rbnode *node = rb->alloc(sizeof *node);
   7.287 -		node->red = 1;
   7.288 -		node->key = key;
   7.289 -		node->data = data;
   7.290 -		node->left = node->right = 0;
   7.291 -		return node;
   7.292 -	}
   7.293 -
   7.294 -	cmp = rb->cmp(key, tree->key);
   7.295 -
   7.296 -	if(cmp < 0) {
   7.297 -		tree->left = insert(rb, tree->left, key, data);
   7.298 -	} else if(cmp > 0) {
   7.299 -		tree->right = insert(rb, tree->right, key, data);
   7.300 -	} else {
   7.301 -		tree->data = data;
   7.302 -	}
   7.303 -
   7.304 -	/* fix right-leaning reds */
   7.305 -	if(is_red(tree->right)) {
   7.306 -		tree = rot_left(tree);
   7.307 -	}
   7.308 -	/* fix two reds in a row */
   7.309 -	if(is_red(tree->left) && is_red(tree->left->left)) {
   7.310 -		tree = rot_right(tree);
   7.311 -	}
   7.312 -
   7.313 -	/* if 4-node, split it by color inversion */
   7.314 -	if(is_red(tree->left) && is_red(tree->right)) {
   7.315 -		color_flip(tree);
   7.316 -	}
   7.317 -
   7.318 -	return tree;
   7.319 -}
   7.320 -
   7.321 -static struct rbnode *delete(struct rbtree *rb, struct rbnode *tree, void *key)
   7.322 -{
   7.323 -	int cmp;
   7.324 -
   7.325 -	if(!tree) {
   7.326 -		return 0;
   7.327 -	}
   7.328 -
   7.329 -	cmp = rb->cmp(key, tree->key);
   7.330 -
   7.331 -	if(cmp < 0) {
   7.332 -		if(!is_red(tree->left) && !is_red(tree->left->left)) {
   7.333 -			tree = move_red_left(tree);
   7.334 -		}
   7.335 -		tree->left = delete(rb, tree->left, key);
   7.336 -	} else {
   7.337 -		/* need reds on the right */
   7.338 -		if(is_red(tree->left)) {
   7.339 -			tree = rot_right(tree);
   7.340 -		}
   7.341 -
   7.342 -		/* found it at the bottom (XXX what certifies left is null?) */
   7.343 -		if(cmp == 0 && !tree->right) {
   7.344 -			if(rb->del) {
   7.345 -				rb->del(tree, rb->del_cls);
   7.346 -			}
   7.347 -			rb->free(tree);
   7.348 -			return 0;
   7.349 -		}
   7.350 -
   7.351 -		if(!is_red(tree->right) && !is_red(tree->right->left)) {
   7.352 -			tree = move_red_left(tree);
   7.353 -		}
   7.354 -
   7.355 -		if(key == tree->key) {
   7.356 -			struct rbnode *rmin = find_min(tree->right);
   7.357 -			tree->key = rmin->key;
   7.358 -			tree->data = rmin->data;
   7.359 -			tree->right = del_min(rb, tree->right);
   7.360 -		} else {
   7.361 -			tree->right = delete(rb, tree->right, key);
   7.362 -		}
   7.363 -	}
   7.364 -
   7.365 -	return fix_up(tree);
   7.366 -}
   7.367 -
   7.368 -/*static struct rbnode *find(struct rbtree *rb, struct rbnode *node, void *key)
   7.369 -{
   7.370 -	int cmp;
   7.371 -
   7.372 -	if(!node)
   7.373 -		return 0;
   7.374 -
   7.375 -	if((cmp = rb->cmp(key, node->key)) == 0) {
   7.376 -		return node;
   7.377 -	}
   7.378 -	return find(rb, cmp < 0 ? node->left : node->right, key);
   7.379 -}*/
   7.380 -
   7.381 -static void traverse(struct rbnode *node, void (*func)(struct rbnode*, void*), void *cls)
   7.382 -{
   7.383 -	if(!node)
   7.384 -		return;
   7.385 -
   7.386 -	traverse(node->left, func, cls);
   7.387 -	func(node, cls);
   7.388 -	traverse(node->right, func, cls);
   7.389 -}
   7.390 -
   7.391 -/* helpers */
   7.392 -
   7.393 -static int is_red(struct rbnode *tree)
   7.394 -{
   7.395 -	return tree && tree->red;
   7.396 -}
   7.397 -
   7.398 -static void color_flip(struct rbnode *tree)
   7.399 -{
   7.400 -	tree->red = !tree->red;
   7.401 -	tree->left->red = !tree->left->red;
   7.402 -	tree->right->red = !tree->right->red;
   7.403 -}
   7.404 -
   7.405 -static struct rbnode *rot_left(struct rbnode *a)
   7.406 -{
   7.407 -	struct rbnode *b = a->right;
   7.408 -	a->right = b->left;
   7.409 -	b->left = a;
   7.410 -	b->red = a->red;
   7.411 -	a->red = 1;
   7.412 -	return b;
   7.413 -}
   7.414 -
   7.415 -static struct rbnode *rot_right(struct rbnode *a)
   7.416 -{
   7.417 -	struct rbnode *b = a->left;
   7.418 -	a->left = b->right;
   7.419 -	b->right = a;
   7.420 -	b->red = a->red;
   7.421 -	a->red = 1;
   7.422 -	return b;
   7.423 -}
   7.424 -
   7.425 -static struct rbnode *find_min(struct rbnode *tree)
   7.426 -{
   7.427 -	struct rbnode *node = tree;
   7.428 -
   7.429 -	if(!tree)
   7.430 -		return 0;
   7.431 -
   7.432 -	while(node->left) {
   7.433 -		node = node->left;
   7.434 -	}
   7.435 -	return node;
   7.436 -}
   7.437 -
   7.438 -static struct rbnode *del_min(struct rbtree *rb, struct rbnode *tree)
   7.439 -{
   7.440 -	if(!tree->left) {
   7.441 -		if(rb->del) {
   7.442 -			rb->del(tree->left, rb->del_cls);
   7.443 -		}
   7.444 -		rb->free(tree->left);
   7.445 -		return 0;
   7.446 -	}
   7.447 -
   7.448 -	/* make sure we've got red (3/4-nodes) at the left side so we can delete at the bottom */
   7.449 -	if(!is_red(tree->left) && !is_red(tree->left->left)) {
   7.450 -		tree = move_red_left(tree);
   7.451 -	}
   7.452 -	tree->left = del_min(rb, tree->left);
   7.453 -
   7.454 -	/* fix right-reds, red-reds, and split 4-nodes on the way up */
   7.455 -	return fix_up(tree);
   7.456 -}
   7.457 -
   7.458 -#if 0
   7.459 -/* push a red link on this node to the right */
   7.460 -static struct rbnode *move_red_right(struct rbnode *tree)
   7.461 -{
   7.462 -	/* flipping it makes both children go red, so we have a red to the right */
   7.463 -	color_flip(tree);
   7.464 -
   7.465 -	/* if after the flip we've got a red-red situation to the left, fix it */
   7.466 -	if(is_red(tree->left->left)) {
   7.467 -		tree = rot_right(tree);
   7.468 -		color_flip(tree);
   7.469 -	}
   7.470 -	return tree;
   7.471 -}
   7.472 -#endif
   7.473 -
   7.474 -/* push a red link on this node to the left */
   7.475 -static struct rbnode *move_red_left(struct rbnode *tree)
   7.476 -{
   7.477 -	/* flipping it makes both children go red, so we have a red to the left */
   7.478 -	color_flip(tree);
   7.479 -
   7.480 -	/* if after the flip we've got a red-red on the right-left, fix it */
   7.481 -	if(is_red(tree->right->left)) {
   7.482 -		tree->right = rot_right(tree->right);
   7.483 -		tree = rot_left(tree);
   7.484 -		color_flip(tree);
   7.485 -	}
   7.486 -	return tree;
   7.487 -}
   7.488 -
   7.489 -static struct rbnode *fix_up(struct rbnode *tree)
   7.490 -{
   7.491 -	/* fix right-leaning */
   7.492 -	if(is_red(tree->right)) {
   7.493 -		tree = rot_left(tree);
   7.494 -	}
   7.495 -	/* change invalid red-red pairs into a proper 4-node */
   7.496 -	if(is_red(tree->left) && is_red(tree->left->left)) {
   7.497 -		tree = rot_right(tree);
   7.498 -	}
   7.499 -	/* split 4-nodes */
   7.500 -	if(is_red(tree->left) && is_red(tree->right)) {
   7.501 -		color_flip(tree);
   7.502 -	}
   7.503 -	return tree;
   7.504 -}
     8.1 --- a/src/vr/rbtree.h	Wed Aug 27 04:16:22 2014 +0300
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,78 +0,0 @@
     8.4 -/*
     8.5 -rbtree - simple balanced binary search tree (red-black tree) library.
     8.6 -Copyright (C) 2011-2014  John Tsiombikas <nuclear@member.fsf.org>
     8.7 -
     8.8 -rbtree is free software, feel free to use, modify, and redistribute it, under
     8.9 -the terms of the 3-clause BSD license. See COPYING for details.
    8.10 - */
    8.11 -#ifndef RBTREE_H_
    8.12 -#define RBTREE_H_
    8.13 -
    8.14 -struct rbtree;
    8.15 -
    8.16 -
    8.17 -struct rbnode {
    8.18 -	void *key, *data;
    8.19 -	int red;
    8.20 -	struct rbnode *left, *right;
    8.21 -	struct rbnode *next;	/* for iterator stack */
    8.22 -};
    8.23 -
    8.24 -
    8.25 -typedef void *(*rb_alloc_func_t)(size_t);
    8.26 -typedef void (*rb_free_func_t)(void*);
    8.27 -
    8.28 -typedef int (*rb_cmp_func_t)(const void*, const void*);
    8.29 -typedef void (*rb_del_func_t)(struct rbnode*, void*);
    8.30 -
    8.31 -#define RB_KEY_ADDR		(rb_cmp_func_t)(0)
    8.32 -#define RB_KEY_INT		(rb_cmp_func_t)(1)
    8.33 -#define RB_KEY_STRING	(rb_cmp_func_t)(3)
    8.34 -
    8.35 -
    8.36 -#ifdef __cplusplus
    8.37 -extern "C" {
    8.38 -#endif
    8.39 -
    8.40 -struct rbtree *rb_create(rb_cmp_func_t cmp_func);
    8.41 -void rb_free(struct rbtree *rb);
    8.42 -
    8.43 -int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func);
    8.44 -void rb_destroy(struct rbtree *rb);
    8.45 -
    8.46 -void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free);
    8.47 -void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func);
    8.48 -void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls);
    8.49 -/* TODO add user deep copy function */
    8.50 -
    8.51 -void rb_clear(struct rbtree *rb);
    8.52 -int rb_copy(struct rbtree *dest, struct rbtree *src);
    8.53 -
    8.54 -int rb_size(struct rbtree *rb);
    8.55 -
    8.56 -int rb_insert(struct rbtree *rb, void *key, void *data);
    8.57 -int rb_inserti(struct rbtree *rb, int key, void *data);
    8.58 -
    8.59 -int rb_delete(struct rbtree *rb, void *key);
    8.60 -int rb_deletei(struct rbtree *rb, int key);
    8.61 -
    8.62 -void *rb_find(struct rbtree *rb, void *key);
    8.63 -void *rb_findi(struct rbtree *rb, int key);
    8.64 -
    8.65 -void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
    8.66 -
    8.67 -struct rbnode *rb_root(struct rbtree *rb);
    8.68 -
    8.69 -void rb_begin(struct rbtree *rb);
    8.70 -struct rbnode *rb_next(struct rbtree *rb);
    8.71 -
    8.72 -void *rb_node_key(struct rbnode *node);
    8.73 -int rb_node_keyi(struct rbnode *node);
    8.74 -void *rb_node_data(struct rbnode *node);
    8.75 -
    8.76 -#ifdef __cplusplus
    8.77 -}
    8.78 -#endif
    8.79 -
    8.80 -
    8.81 -#endif	/* RBTREE_H_ */
     9.1 --- a/src/vr/vr.c	Wed Aug 27 04:16:22 2014 +0300
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,260 +0,0 @@
     9.4 -#include <stdio.h>
     9.5 -#include <string.h>
     9.6 -#include "vr.h"
     9.7 -#include "vr_impl.h"
     9.8 -#include "mathutil.h"
     9.9 -
    9.10 -
    9.11 -static void swap_buffers(void);
    9.12 -
    9.13 -
    9.14 -static struct vr_module *vrm;
    9.15 -static float idmat[] = {
    9.16 -	1, 0, 0, 0,
    9.17 -	0, 1, 0, 0,
    9.18 -	0, 0, 1, 0,
    9.19 -	0, 0, 0, 1
    9.20 -};
    9.21 -static float fbtex_rect[] = {
    9.22 -	0, 0, 1, 1
    9.23 -};
    9.24 -
    9.25 -int vr_init(void)
    9.26 -{
    9.27 -	int i, nmodules;
    9.28 -
    9.29 -	if(vrm) {
    9.30 -		vr_shutdown();
    9.31 -	}
    9.32 -
    9.33 -	vr_init_modules();
    9.34 -
    9.35 -	nmodules = vr_get_num_modules();
    9.36 -	for(i=0; i<nmodules; i++) {
    9.37 -		struct vr_module *m = vr_get_module(i);
    9.38 -		if(m->init() != -1) {
    9.39 -			/* add to the active modules array */
    9.40 -			vr_activate_module(i);
    9.41 -			if(!vrm) {
    9.42 -				vr_use_module(0);
    9.43 -			}
    9.44 -		}
    9.45 -	}
    9.46 -
    9.47 -	if(!vrm) {
    9.48 -		return -1;
    9.49 -	}
    9.50 -	return 0;
    9.51 -}
    9.52 -
    9.53 -void vr_shutdown(void)
    9.54 -{
    9.55 -	vr_clear_modules();
    9.56 -	vrm = 0;
    9.57 -	fbtex_rect[0] = fbtex_rect[1] = 0;
    9.58 -	fbtex_rect[2] = fbtex_rect[3] = 1;
    9.59 -}
    9.60 -
    9.61 -int vr_module_count(void)
    9.62 -{
    9.63 -	return vr_get_num_active_modules();
    9.64 -}
    9.65 -
    9.66 -const char *vr_module_name(int idx)
    9.67 -{
    9.68 -	struct vr_module *m = vr_get_active_module(idx);
    9.69 -	if(!m) {
    9.70 -		return 0;
    9.71 -	}
    9.72 -	return m->name;
    9.73 -}
    9.74 -
    9.75 -int vr_use_module(int idx)
    9.76 -{
    9.77 -	if(idx >= 0 && idx < vr_get_num_active_modules()) {
    9.78 -		struct vr_module *m = vr_get_active_module(idx);
    9.79 -		if(m != vrm) {
    9.80 -			vrm = m;
    9.81 -			printf("using vr module: %s\n", vrm->name);
    9.82 -		}
    9.83 -		return 0;
    9.84 -	}
    9.85 -	return -1;
    9.86 -}
    9.87 -
    9.88 -int vr_use_module_named(const char *name)
    9.89 -{
    9.90 -	int i, count = vr_get_num_active_modules();
    9.91 -
    9.92 -	for(i=0; i<count; i++) {
    9.93 -		struct vr_module *m = vr_get_active_module(i);
    9.94 -		if(strcmp(m->name, name) == 0) {
    9.95 -			return vr_use_module(i);
    9.96 -		}
    9.97 -	}
    9.98 -	return -1;
    9.99 -}
   9.100 -
   9.101 -void vr_set_opti(const char *optname, int val)
   9.102 -{
   9.103 -	if(vrm && vrm->set_option) {
   9.104 -		vrm->set_option(optname, OTYPE_INT, &val);
   9.105 -	}
   9.106 -}
   9.107 -
   9.108 -void vr_set_optf(const char *optname, float val)
   9.109 -{
   9.110 -	if(vrm && vrm->set_option) {
   9.111 -		vrm->set_option(optname, OTYPE_FLOAT, &val);
   9.112 -	}
   9.113 -}
   9.114 -
   9.115 -int vr_get_opti(const char *optname)
   9.116 -{
   9.117 -	int res = 0;
   9.118 -
   9.119 -	if(vrm && vrm->get_option) {
   9.120 -		vrm->get_option(optname, OTYPE_INT, &res);
   9.121 -	}
   9.122 -	return res;
   9.123 -}
   9.124 -
   9.125 -float vr_get_optf(const char *optname)
   9.126 -{
   9.127 -	float res = 0.0f;
   9.128 -
   9.129 -	if(vrm && vrm->get_option) {
   9.130 -		vrm->get_option(optname, OTYPE_FLOAT, &res);
   9.131 -	}
   9.132 -	return res;
   9.133 -}
   9.134 -
   9.135 -
   9.136 -int vr_view_translation(int eye, float *vec)
   9.137 -{
   9.138 -	if(vrm && vrm->translation) {
   9.139 -		vrm->translation(eye, vec);
   9.140 -		return 1;
   9.141 -	}
   9.142 -	vec[0] = vec[1] = vec[2] = 0.0f;
   9.143 -	return 0;
   9.144 -}
   9.145 -
   9.146 -int vr_view_rotation(int eye, float *quat)
   9.147 -{
   9.148 -	if(vrm && vrm->rotation) {
   9.149 -		vrm->rotation(eye, quat);
   9.150 -		return 1;
   9.151 -	}
   9.152 -	quat[0] = quat[1] = quat[2] = 0.0f;
   9.153 -	quat[3] = 1.0f;
   9.154 -	return 0;
   9.155 -}
   9.156 -
   9.157 -int vr_view_matrix(int eye, float *mat)
   9.158 -{
   9.159 -	int have_trans, have_rot;
   9.160 -	float offs[3], quat[4];
   9.161 -	float rmat[16], tmat[16];
   9.162 -
   9.163 -	if(vrm && vrm->view_matrix) {
   9.164 -		vrm->view_matrix(eye, mat);
   9.165 -		return 1;
   9.166 -	}
   9.167 -
   9.168 -	have_trans = vr_view_translation(eye, offs);
   9.169 -	have_rot = vr_view_rotation(eye, quat);
   9.170 -
   9.171 -	if(!have_trans && !have_rot) {
   9.172 -		return 0;
   9.173 -	}
   9.174 -
   9.175 -	offs[0] = -offs[0];
   9.176 -	offs[1] = -offs[1];
   9.177 -	offs[2] = -offs[2];
   9.178 -
   9.179 -	translation_matrix(offs, tmat);
   9.180 -	rotation_matrix(quat, rmat);
   9.181 -	mult_matrix(mat, tmat, rmat);
   9.182 -	return 1;
   9.183 -}
   9.184 -
   9.185 -int vr_proj_matrix(int eye, float znear, float zfar, float *mat)
   9.186 -{
   9.187 -	if(vrm && vrm->proj_matrix) {
   9.188 -		vrm->proj_matrix(eye, znear, zfar, mat);
   9.189 -		return 1;
   9.190 -	}
   9.191 -	memcpy(mat, idmat, sizeof idmat);
   9.192 -	return 0;
   9.193 -}
   9.194 -
   9.195 -void vr_begin(int eye)
   9.196 -{
   9.197 -	if(vrm && vrm->begin) {
   9.198 -		vrm->begin(eye);
   9.199 -	}
   9.200 -}
   9.201 -
   9.202 -void vr_end(void)
   9.203 -{
   9.204 -	if(vrm && vrm->end) {
   9.205 -		vrm->end();
   9.206 -	}
   9.207 -}
   9.208 -
   9.209 -int vr_swap_buffers(void)
   9.210 -{
   9.211 -	int res = 0;
   9.212 -
   9.213 -	if(vrm && vrm->present) {
   9.214 -		res = vrm->present();
   9.215 -	}
   9.216 -
   9.217 -	if(!res) {
   9.218 -		swap_buffers();
   9.219 -	}
   9.220 -	return 0;
   9.221 -}
   9.222 -
   9.223 -void vr_output_texture(unsigned int tex, float umin, float vmin, float umax, float vmax)
   9.224 -{
   9.225 -	float halfu = (umax + umin) * 0.5f;
   9.226 -
   9.227 -	vr_output_texture_eye(VR_EYE_LEFT, tex, umin, vmin, halfu, vmax);
   9.228 -	vr_output_texture_eye(VR_EYE_RIGHT, tex, halfu, vmin, umax, vmax);
   9.229 -}
   9.230 -
   9.231 -void vr_output_texture_eye(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
   9.232 -{
   9.233 -	if(vrm && vrm->set_eye_texture) {
   9.234 -		vrm->set_eye_texture(eye, tex, umin, vmin, umax, vmax);
   9.235 -	}
   9.236 -}
   9.237 -
   9.238 -void vr_recenter(void)
   9.239 -{
   9.240 -	if(vrm && vrm->recenter) {
   9.241 -		vrm->recenter();
   9.242 -	}
   9.243 -}
   9.244 -
   9.245 -
   9.246 -#ifdef __unix__
   9.247 -#include <GL/glx.h>
   9.248 -
   9.249 -static void swap_buffers(void)
   9.250 -{
   9.251 -	glXSwapBuffers(glXGetCurrentDisplay(), glXGetCurrentDrawable());
   9.252 -}
   9.253 -
   9.254 -#endif
   9.255 -
   9.256 -#ifdef WIN32
   9.257 -#include <windows.h>
   9.258 -
   9.259 -static void swap_buffers(void)
   9.260 -{
   9.261 -	SwapBuffers(wglGetCurrentDC());
   9.262 -}
   9.263 -#endif
    10.1 --- a/src/vr/vr.h	Wed Aug 27 04:16:22 2014 +0300
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,61 +0,0 @@
    10.4 -#ifndef VR_H_
    10.5 -#define VR_H_
    10.6 -
    10.7 -#define VR_OPT_DISPLAY_WIDTH	"display-xres"
    10.8 -#define VR_OPT_DISPLAY_HEIGHT	"display-yres"
    10.9 -#define VR_OPT_LEYE_XRES	"left-eye-xres"
   10.10 -#define VR_OPT_LEYE_YRES	"left-eye-yres"
   10.11 -#define VR_OPT_REYE_XRES	"right-eye-xres"
   10.12 -#define VR_OPT_REYE_YRES	"right-eye-yres"
   10.13 -#define VR_OPT_EYE_HEIGHT	"eye-height"
   10.14 -#define VR_OPT_IPD			"ipd"
   10.15 -#define VR_OPT_WIN_XOFFS	"win-xoffset"
   10.16 -#define VR_OPT_WIN_YOFFS	"win-yoffset"
   10.17 -
   10.18 -enum {
   10.19 -	VR_EYE_LEFT,
   10.20 -	VR_EYE_RIGHT
   10.21 -};
   10.22 -
   10.23 -#ifdef __cplusplus
   10.24 -extern "C" {
   10.25 -#endif
   10.26 -
   10.27 -int vr_init(void);
   10.28 -void vr_shutdown(void);
   10.29 -
   10.30 -int vr_module_count(void);
   10.31 -const char *vr_module_name(int idx);
   10.32 -
   10.33 -int vr_use_module(int idx);
   10.34 -int vr_use_module_named(const char *name);
   10.35 -
   10.36 -void vr_set_opti(const char *optname, int val);
   10.37 -void vr_set_optf(const char *optname, float val);
   10.38 -int vr_get_opti(const char *optname);
   10.39 -float vr_get_optf(const char *optname);
   10.40 -
   10.41 -int vr_view_translation(int eye, float *vec);
   10.42 -int vr_view_rotation(int eye, float *quat);
   10.43 -
   10.44 -/* returns non-zero if the active vr module provides this kind of matrix
   10.45 - * information, otherwise it returns zero, and sets mat to identity
   10.46 - */
   10.47 -int vr_view_matrix(int eye, float *mat);
   10.48 -int vr_proj_matrix(int eye, float znear, float zfar, float *mat);
   10.49 -
   10.50 -void vr_begin(int eye);
   10.51 -void vr_end(void);
   10.52 -int vr_swap_buffers(void);
   10.53 -
   10.54 -/* set the output texture or separate textures for each eye */
   10.55 -void vr_output_texture(unsigned int tex, float umin, float vmin, float umax, float vmax);
   10.56 -void vr_output_texture_eye(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax);
   10.57 -
   10.58 -void vr_recenter(void);
   10.59 -
   10.60 -#ifdef __cplusplus
   10.61 -}
   10.62 -#endif
   10.63 -
   10.64 -#endif	/* VR_H_ */
    11.1 --- a/src/vr/vr_impl.h	Wed Aug 27 04:16:22 2014 +0300
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,44 +0,0 @@
    11.4 -#ifndef VR_IMPL_H_
    11.5 -#define VR_IMPL_H_
    11.6 -
    11.7 -#include "vr.h"
    11.8 -#include "opt.h"
    11.9 -
   11.10 -struct vr_module {
   11.11 -	char *name;
   11.12 -
   11.13 -	int (*init)(void);
   11.14 -	void (*cleanup)(void);
   11.15 -
   11.16 -	int (*set_option)(const char *opt, enum opt_type type, void *valp);
   11.17 -	int (*get_option)(const char *opt, enum opt_type type, void *valp);
   11.18 -
   11.19 -	void (*translation)(int eye, float *vec);
   11.20 -	void (*rotation)(int eye, float *quat);
   11.21 -
   11.22 -	void (*view_matrix)(int eye, float *mat);
   11.23 -	void (*proj_matrix)(int eye, float znear, float zfar, float *mat);
   11.24 -
   11.25 -	void (*begin)(int eye);
   11.26 -	void (*end)(void);
   11.27 -	int (*present)(void);
   11.28 -
   11.29 -	void (*set_eye_texture)(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax);
   11.30 -
   11.31 -	void (*recenter)(void);
   11.32 -};
   11.33 -
   11.34 -void vr_init_modules(void);
   11.35 -
   11.36 -void vr_clear_modules(void);
   11.37 -void vr_register_module(struct vr_module *mod);
   11.38 -
   11.39 -int vr_get_num_modules(void);
   11.40 -struct vr_module *vr_get_module(int idx);
   11.41 -
   11.42 -void vr_activate_module(int idx);
   11.43 -
   11.44 -int vr_get_num_active_modules(void);
   11.45 -struct vr_module *vr_get_active_module(int idx);
   11.46 -
   11.47 -#endif	/* VR_IMPL_H_ */
    12.1 --- a/src/vr/vr_libovr.c	Wed Aug 27 04:16:22 2014 +0300
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,307 +0,0 @@
    12.4 -#ifdef WIN32
    12.5 -#define OVR_OS_WIN32
    12.6 -#endif
    12.7 -
    12.8 -#include "vr_impl.h"
    12.9 -
   12.10 -#ifdef USE_LIBOVR
   12.11 -#include <stdio.h>
   12.12 -#include <stdlib.h>
   12.13 -#include <assert.h>
   12.14 -#include "opt.h"
   12.15 -
   12.16 -#include <OVR_CAPI.h>
   12.17 -#include <OVR_CAPI_GL.h>
   12.18 -
   12.19 -#define DISABLE_RETARDED_HEALTH_WARNING
   12.20 -
   12.21 -/* just dropping the prototype here to avoid including CAPI_HSWDisplay.h */
   12.22 -OVR_EXPORT void ovrhmd_EnableHSWDisplaySDKRender(ovrHmd hmd, ovrBool enabled);
   12.23 -
   12.24 -static ovrHmd hmd;
   12.25 -static void *optdb;
   12.26 -static ovrEyeRenderDesc eye_render_desc[2];
   12.27 -static ovrSizei eye_res[2];
   12.28 -static ovrGLTexture eye_tex[2];
   12.29 -static ovrFovPort eye_fov[2];
   12.30 -static ovrPosef pose[2];
   12.31 -static int deferred_init_done;
   12.32 -
   12.33 -static int init(void)
   12.34 -{
   12.35 -	int i, num_hmds;
   12.36 -
   12.37 -	if(!ovr_Initialize()) {
   12.38 -		return -1;
   12.39 -	}
   12.40 -	printf("initialized LibOVR %s\n", ovr_GetVersionString());
   12.41 -
   12.42 -	if(!(num_hmds = ovrHmd_Detect())) {
   12.43 -		ovr_Shutdown();
   12.44 -		return -1;
   12.45 -	}
   12.46 -	printf("%d Oculus HMD(s) found\n", num_hmds);
   12.47 -
   12.48 -	hmd = 0;
   12.49 -	for(i=0; i<num_hmds; i++) {
   12.50 -		ovrHmd h;
   12.51 -		if(!(h = ovrHmd_Create(i))) {
   12.52 -			break;
   12.53 -		}
   12.54 -		printf(" [%d]: %s - %s\n", i, h->Manufacturer, h->ProductName);
   12.55 -
   12.56 -		if(!hmd) {
   12.57 -			hmd = h;
   12.58 -		} else {
   12.59 -			ovrHmd_Destroy(h);
   12.60 -		}
   12.61 -	}
   12.62 -
   12.63 -	if(!hmd) {
   12.64 -		fprintf(stderr, "failed to initialize any Oculus HMDs\n");
   12.65 -		return -1;
   12.66 -	}
   12.67 -
   12.68 -	ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0);
   12.69 -
   12.70 -	eye_fov[0] = hmd->DefaultEyeFov[0];
   12.71 -	eye_fov[1] = hmd->DefaultEyeFov[1];
   12.72 -
   12.73 -	eye_res[0] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, eye_fov[0], 1.0);
   12.74 -	eye_res[1] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, eye_fov[1], 1.0);
   12.75 -
   12.76 -	/* create the options database */
   12.77 -	if((optdb = create_options())) {
   12.78 -		set_option_int(optdb, VR_OPT_DISPLAY_WIDTH, hmd->Resolution.w);
   12.79 -		set_option_int(optdb, VR_OPT_DISPLAY_HEIGHT, hmd->Resolution.h);
   12.80 -		set_option_int(optdb, VR_OPT_LEYE_XRES, eye_res[0].w);
   12.81 -		set_option_int(optdb, VR_OPT_LEYE_YRES, eye_res[0].h);
   12.82 -		set_option_int(optdb, VR_OPT_REYE_XRES, eye_res[1].w);
   12.83 -		set_option_int(optdb, VR_OPT_REYE_YRES, eye_res[1].h);
   12.84 -		set_option_float(optdb, VR_OPT_EYE_HEIGHT, ovrHmd_GetFloat(hmd, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT));
   12.85 -		set_option_float(optdb, VR_OPT_IPD, ovrHmd_GetFloat(hmd, OVR_KEY_IPD, OVR_DEFAULT_IPD));
   12.86 -		set_option_int(optdb, VR_OPT_WIN_XOFFS, hmd->WindowsPos.x);
   12.87 -		set_option_int(optdb, VR_OPT_WIN_YOFFS, hmd->WindowsPos.y);
   12.88 -	}
   12.89 -
   12.90 -	deferred_init_done = 0;
   12.91 -	return 0;
   12.92 -}
   12.93 -
   12.94 -static void deferred_init(void)
   12.95 -{
   12.96 -	union ovrGLConfig glcfg;
   12.97 -	unsigned int dcaps;
   12.98 -	void *win = 0;
   12.99 -
  12.100 -	deferred_init_done = 1;
  12.101 -
  12.102 -	memset(&glcfg, 0, sizeof glcfg);
  12.103 -	glcfg.OGL.Header.API = ovrRenderAPI_OpenGL;
  12.104 -	glcfg.OGL.Header.RTSize = hmd->Resolution;
  12.105 -	glcfg.OGL.Header.Multisample = 1;
  12.106 -#ifdef WIN32
  12.107 -	win = GetActiveWindow();
  12.108 -	/*glcfg.OGL.Window = win;
  12.109 -	glcfg.OGL.DC = wglGetCurrentDC();
  12.110 -	assert(glcfg.OGL.Window);
  12.111 -	assert(glcfg.OGL.DC);*/
  12.112 -#endif
  12.113 -
  12.114 -	if(!(hmd->HmdCaps & ovrHmdCap_ExtendDesktop)) {
  12.115 -		ovrHmd_AttachToWindow(hmd, win, 0, 0);
  12.116 -		printf("running in \"direct-to-rift\" mode\n");
  12.117 -	} else {
  12.118 -		printf("running in \"extended desktop\" mode\n");
  12.119 -	}
  12.120 -	ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);
  12.121 -
  12.122 -	dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp |
  12.123 -		ovrDistortionCap_Overdrive | ovrDistortionCap_NoRestore;
  12.124 -
  12.125 -	if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, eye_fov, eye_render_desc)) {
  12.126 -		fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
  12.127 -	}
  12.128 -
  12.129 -#ifdef DISABLE_RETARDED_HEALTH_WARNING
  12.130 -	ovrhmd_EnableHSWDisplaySDKRender(hmd, 0);
  12.131 -#endif
  12.132 -}
  12.133 -
  12.134 -static void cleanup(void)
  12.135 -{
  12.136 -	if(hmd) {
  12.137 -		ovrHmd_Destroy(hmd);
  12.138 -		ovr_Shutdown();
  12.139 -	}
  12.140 -}
  12.141 -
  12.142 -static int set_option(const char *opt, enum opt_type type, void *valp)
  12.143 -{
  12.144 -	switch(type) {
  12.145 -	case OTYPE_INT:
  12.146 -		set_option_int(optdb, opt, *(int*)valp);
  12.147 -		break;
  12.148 -
  12.149 -	case OTYPE_FLOAT:
  12.150 -		set_option_float(optdb, opt, *(float*)valp);
  12.151 -		break;
  12.152 -	}
  12.153 -	return 0;
  12.154 -}
  12.155 -
  12.156 -static int get_option(const char *opt, enum opt_type type, void *valp)
  12.157 -{
  12.158 -	switch(type) {
  12.159 -	case OTYPE_INT:
  12.160 -		return get_option_int(optdb, opt, valp);
  12.161 -	case OTYPE_FLOAT:
  12.162 -		return get_option_float(optdb, opt, valp);
  12.163 -	}
  12.164 -	return -1;
  12.165 -}
  12.166 -
  12.167 -static int translation(int eye, float *vec)
  12.168 -{
  12.169 -	if(!hmd) {
  12.170 -		vec[0] = vec[1] = vec[2] = 0;
  12.171 -		return 0;
  12.172 -	}
  12.173 -
  12.174 -	pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
  12.175 -	vec[0] = pose[eye].Position.x;
  12.176 -	vec[1] = pose[eye].Position.y;
  12.177 -	vec[2] = pose[eye].Position.z;
  12.178 -	return 1;
  12.179 -}
  12.180 -
  12.181 -static int rotation(int eye, float *quat)
  12.182 -{
  12.183 -	if(!hmd) {
  12.184 -		quat[0] = quat[1] = quat[2] = 0.0f;
  12.185 -		quat[3] = 1.0f;
  12.186 -		return 0;
  12.187 -	}
  12.188 -
  12.189 -	pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
  12.190 -	quat[0] = pose[eye].Orientation.x;
  12.191 -	quat[1] = pose[eye].Orientation.y;
  12.192 -	quat[2] = pose[eye].Orientation.z;
  12.193 -	quat[3] = pose[eye].Orientation.w;
  12.194 -	return 1;
  12.195 -}
  12.196 -
  12.197 -static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
  12.198 -
  12.199 -static void proj_matrix(int eye, float znear, float zfar, float *mat)
  12.200 -{
  12.201 -	int i, j;
  12.202 -	ovrMatrix4f vmat;
  12.203 -
  12.204 -	if(!hmd) {
  12.205 -		memcpy(mat, idmat, sizeof idmat);
  12.206 -		return;
  12.207 -	}
  12.208 -
  12.209 -	vmat = ovrMatrix4f_Projection(eye_render_desc[eye].Fov, znear, zfar, 1);
  12.210 -
  12.211 -	for(i=0; i<4; i++) {
  12.212 -		for(j=0; j<4; j++) {
  12.213 -			*mat++ = vmat.M[j][i];
  12.214 -		}
  12.215 -	}
  12.216 -}
  12.217 -
  12.218 -static int new_frame = 1;
  12.219 -
  12.220 -static void begin(int eye)
  12.221 -{
  12.222 -	if(!hmd) return;
  12.223 -
  12.224 -	if(!deferred_init_done) {
  12.225 -		deferred_init();
  12.226 -	}
  12.227 -
  12.228 -	if(new_frame) {
  12.229 -		ovrHmd_BeginFrame(hmd, 0);
  12.230 -		new_frame = 0;
  12.231 -	}
  12.232 -}
  12.233 -
  12.234 -static int present(void)
  12.235 -{
  12.236 -	if(!hmd) return 0;
  12.237 -
  12.238 -	ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture);
  12.239 -	new_frame = 1;
  12.240 -
  12.241 -	return 1;
  12.242 -}
  12.243 -
  12.244 -static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
  12.245 -{
  12.246 -	ovrSizei texsz;
  12.247 -	ovrRecti rect;
  12.248 -
  12.249 -	glBindTexture(GL_TEXTURE_2D, tex);
  12.250 -	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texsz.w);
  12.251 -	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texsz.h);
  12.252 -
  12.253 -	rect.Pos.x = (int)(umin * texsz.w);
  12.254 -	rect.Pos.y = (int)((vmin + 1.0 - vmax) * texsz.h);
  12.255 -	rect.Size.w = (int)((umax - umin) * texsz.w);
  12.256 -	rect.Size.h = (int)((vmax - vmin) * texsz.h);
  12.257 -
  12.258 -	eye_tex[eye].OGL.Header.API = ovrRenderAPI_OpenGL;
  12.259 -	eye_tex[eye].OGL.Header.TextureSize = texsz;
  12.260 -	eye_tex[eye].OGL.Header.RenderViewport = rect;
  12.261 -	eye_tex[eye].OGL.TexId = tex;
  12.262 -}
  12.263 -
  12.264 -static void recenter(void)
  12.265 -{
  12.266 -	if(hmd) {
  12.267 -		ovrHmd_RecenterPose(hmd);
  12.268 -	}
  12.269 -}
  12.270 -
  12.271 -struct vr_module *vr_module_libovr(void)
  12.272 -{
  12.273 -	static struct vr_module m;
  12.274 -
  12.275 -	if(!m.init) {
  12.276 -		m.name = "libovr";
  12.277 -		m.init = init;
  12.278 -		m.cleanup = cleanup;
  12.279 -		m.set_option = set_option;
  12.280 -		m.get_option = get_option;
  12.281 -		m.translation = translation;
  12.282 -		m.rotation = rotation;
  12.283 -		m.proj_matrix = proj_matrix;
  12.284 -		m.begin = begin;
  12.285 -		m.present = present;
  12.286 -		m.set_eye_texture = set_eye_texture;
  12.287 -		m.recenter = recenter;
  12.288 -	}
  12.289 -	return &m;
  12.290 -}
  12.291 -
  12.292 -#else	/* no libovr */
  12.293 -
  12.294 -static int init(void)
  12.295 -{
  12.296 -	return -1;
  12.297 -}
  12.298 -
  12.299 -struct vr_module *vr_module_libovr(void)
  12.300 -{
  12.301 -	static struct vr_module m;
  12.302 -
  12.303 -	if(!m.init) {
  12.304 -		m.name = "libovr";
  12.305 -		m.init = init;
  12.306 -	}
  12.307 -	return &m;
  12.308 -}
  12.309 -
  12.310 -#endif	/* USE_LIBOVR */
    13.1 --- a/src/vr/vr_modules.c	Wed Aug 27 04:16:22 2014 +0300
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,94 +0,0 @@
    13.4 -/* XXX this might become partly auto-generated in the future */
    13.5 -#include <stdio.h>
    13.6 -#include <stdlib.h>
    13.7 -#include "vr_impl.h"
    13.8 -
    13.9 -struct vr_module *vr_module_libovr(void);
   13.10 -struct vr_module *vr_module_openhmd(void);
   13.11 -struct vr_module *vr_module_null(void);
   13.12 -
   13.13 -static struct vr_module *modules;
   13.14 -static int num_modules, modules_max_size;
   13.15 -
   13.16 -static int *active_modules;
   13.17 -static int num_act_modules, act_modules_max_size;
   13.18 -
   13.19 -
   13.20 -void vr_init_modules(void)
   13.21 -{
   13.22 -	struct vr_module *m;
   13.23 -
   13.24 -	vr_clear_modules();
   13.25 -
   13.26 -	if((m = vr_module_libovr())) {
   13.27 -		vr_register_module(m);
   13.28 -	}
   13.29 -
   13.30 -	if((m = vr_module_openhmd())) {
   13.31 -		vr_register_module(m);
   13.32 -	}
   13.33 -
   13.34 -	if((m = vr_module_null())) {
   13.35 -		vr_register_module(m);
   13.36 -	}
   13.37 -}
   13.38 -
   13.39 -void vr_clear_modules(void)
   13.40 -{
   13.41 -	free(modules);
   13.42 -	free(active_modules);
   13.43 -	modules = 0;
   13.44 -	num_modules = modules_max_size = 0;
   13.45 -	active_modules = 0;
   13.46 -	num_act_modules = act_modules_max_size = 0;
   13.47 -}
   13.48 -
   13.49 -void vr_register_module(struct vr_module *mod)
   13.50 -{
   13.51 -	if(num_modules >= modules_max_size) {
   13.52 -		int newsz = modules_max_size ? modules_max_size * 2 : 2;
   13.53 -		struct vr_module *newmods = realloc(modules, newsz * sizeof *newmods);
   13.54 -		if(!newmods) {
   13.55 -			fprintf(stderr, "failed to resize modules array up to %d\n", newsz);
   13.56 -			return;
   13.57 -		}
   13.58 -		modules = newmods;
   13.59 -		modules_max_size = newsz;
   13.60 -	}
   13.61 -	modules[num_modules++] = *mod;
   13.62 -}
   13.63 -
   13.64 -int vr_get_num_modules(void)
   13.65 -{
   13.66 -	return num_modules;
   13.67 -}
   13.68 -
   13.69 -struct vr_module *vr_get_module(int idx)
   13.70 -{
   13.71 -	return modules + idx;
   13.72 -}
   13.73 -
   13.74 -void vr_activate_module(int idx)
   13.75 -{
   13.76 -	if(num_act_modules >= act_modules_max_size) {
   13.77 -		int newsz = act_modules_max_size ? act_modules_max_size * 2 : 2;
   13.78 -		int *newact = realloc(active_modules, newsz * sizeof *newact);
   13.79 -		if(!newact) {
   13.80 -			fprintf(stderr, "failed to resize active modules array up to %d\n", newsz);
   13.81 -			return;
   13.82 -		}
   13.83 -		active_modules = newact;
   13.84 -		act_modules_max_size = newsz;
   13.85 -	}
   13.86 -	active_modules[num_act_modules++] = idx;
   13.87 -}
   13.88 -
   13.89 -int vr_get_num_active_modules(void)
   13.90 -{
   13.91 -	return num_act_modules;
   13.92 -}
   13.93 -
   13.94 -struct vr_module *vr_get_active_module(int idx)
   13.95 -{
   13.96 -	return modules + active_modules[idx];
   13.97 -}
    14.1 --- a/src/vr/vr_null.c	Wed Aug 27 04:16:22 2014 +0300
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,85 +0,0 @@
    14.4 -#ifdef WIN32
    14.5 -#define WIN32_LEAN_AND_MEAN
    14.6 -#include <windows.h>
    14.7 -#endif
    14.8 -#ifdef __APPLE__
    14.9 -#include <OpenGL/gl.h>
   14.10 -#else
   14.11 -#include <GL/gl.h>
   14.12 -#endif
   14.13 -#include "vr_impl.h"
   14.14 -
   14.15 -static unsigned int eye_tex[2];
   14.16 -static float tex_umin[2], tex_umax[2];
   14.17 -static float tex_vmin[2], tex_vmax[2];
   14.18 -
   14.19 -static int init(void)
   14.20 -{
   14.21 -	return 0;
   14.22 -}
   14.23 -
   14.24 -static int present(void)
   14.25 -{
   14.26 -	int i;
   14.27 -
   14.28 -	glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
   14.29 -
   14.30 -	glDisable(GL_LIGHTING);
   14.31 -	glDisable(GL_DEPTH_TEST);
   14.32 -	glDisable(GL_FOG);
   14.33 -	glDisable(GL_CULL_FACE);
   14.34 -
   14.35 -	glEnable(GL_TEXTURE_2D);
   14.36 -
   14.37 -	glMatrixMode(GL_MODELVIEW);
   14.38 -	glLoadIdentity();
   14.39 -	glMatrixMode(GL_PROJECTION);
   14.40 -	glLoadIdentity();
   14.41 -
   14.42 -	for(i=0; i<2; i++) {
   14.43 -		float x0 = i == 0 ? -1 : 0;
   14.44 -		float x1 = i == 0 ? 0 : 1;
   14.45 -
   14.46 -		glBindTexture(GL_TEXTURE_2D, eye_tex[i]);
   14.47 -
   14.48 -		glBegin(GL_QUADS);
   14.49 -		glTexCoord2f(tex_umin[i], tex_vmin[i]);
   14.50 -		glVertex2f(x0, -1);
   14.51 -		glTexCoord2f(tex_umax[i], tex_vmin[i]);
   14.52 -		glVertex2f(x1, -1);
   14.53 -		glTexCoord2f(tex_umax[i], tex_vmax[i]);
   14.54 -		glVertex2f(x1, 1);
   14.55 -		glTexCoord2f(tex_umin[i], tex_vmax[i]);
   14.56 -		glVertex2f(x0, 1);
   14.57 -		glEnd();
   14.58 -	}
   14.59 -
   14.60 -	glPopMatrix();
   14.61 -	glMatrixMode(GL_MODELVIEW);
   14.62 -	glPopMatrix();
   14.63 -
   14.64 -	glPopAttrib();
   14.65 -	return 0;
   14.66 -}
   14.67 -
   14.68 -static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
   14.69 -{
   14.70 -	eye_tex[eye] = tex;
   14.71 -	tex_umin[eye] = umin;
   14.72 -	tex_umax[eye] = umax;
   14.73 -	tex_vmin[eye] = vmin;
   14.74 -	tex_vmax[eye] = vmax;
   14.75 -}
   14.76 -
   14.77 -struct vr_module *vr_module_null(void)
   14.78 -{
   14.79 -	static struct vr_module m;
   14.80 -
   14.81 -	if(!m.init) {
   14.82 -		m.name = "null";
   14.83 -		m.init = init;
   14.84 -		m.set_eye_texture = set_eye_texture;
   14.85 -		m.present = present;
   14.86 -	}
   14.87 -	return &m;
   14.88 -}
    15.1 --- a/src/vr/vr_openhmd.c	Wed Aug 27 04:16:22 2014 +0300
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,210 +0,0 @@
    15.4 -#include "vr_impl.h"
    15.5 -
    15.6 -#ifdef USE_OPENHMD
    15.7 -#include <stdio.h>
    15.8 -#include <stdlib.h>
    15.9 -#include <openhmd/openhmd.h>
   15.10 -#include "opt.h"
   15.11 -
   15.12 -/* a noble spirit embiggens the framebuffer to avoid aliasing in the middle */
   15.13 -#define EMBIGGEN	1.5
   15.14 -
   15.15 -static ohmd_context *ctx;
   15.16 -static ohmd_device *dev;
   15.17 -static void *optdb;
   15.18 -static int new_frame = 1;
   15.19 -
   15.20 -static int disp_width, disp_height;
   15.21 -static float ipd;
   15.22 -
   15.23 -static struct {
   15.24 -	unsigned int id;
   15.25 -	float umin, umax;
   15.26 -	float vmin, vmax;
   15.27 -} eye_tex[2];
   15.28 -
   15.29 -
   15.30 -static int init(void)
   15.31 -{
   15.32 -	int i, num_hmds;
   15.33 -
   15.34 -	if(!(ctx = ohmd_ctx_create())) {
   15.35 -		fprintf(stderr, "failed to create OpenHMD context\n");
   15.36 -		ohmd_ctx_destroy(ctx);
   15.37 -		return -1;
   15.38 -	}
   15.39 -	if(!(num_hmds = ohmd_ctx_probe(ctx))) {
   15.40 -		fprintf(stderr, "no HMDs detected\n");
   15.41 -		return -1;
   15.42 -	}
   15.43 -
   15.44 -	for(i=0; i<num_hmds; i++) {
   15.45 -		const char *vendor = ohmd_list_gets(ctx, i, OHMD_VENDOR);
   15.46 -		const char *product = ohmd_list_gets(ctx, i, OHMD_PRODUCT);
   15.47 -		const char *devpath = ohmd_list_gets(ctx, i, OHMD_PATH);
   15.48 -
   15.49 -		printf("[%d] %s - %s (path: %s)\n", i, vendor, product, devpath);
   15.50 -	}
   15.51 -
   15.52 -	printf("opening device 0\n");
   15.53 -
   15.54 -	if(!(dev = ohmd_list_open_device(ctx, 0))) {
   15.55 -		fprintf(stderr, "failed to open device 0: %s\n", ohmd_ctx_get_error(ctx));
   15.56 -		return -1;
   15.57 -	}
   15.58 -
   15.59 -	ohmd_device_geti(dev, OHMD_SCREEN_HORIZONTAL_SIZE, &disp_width);
   15.60 -	ohmd_device_geti(dev, OHMD_SCREEN_VERTICAL_SIZE, &disp_height);
   15.61 -	ohmd_device_getf(dev, OHMD_EYE_IPD, &ipd);
   15.62 -
   15.63 -	if((optdb = create_options())) {
   15.64 -		set_option_int(optdb, VR_OPT_DISPLAY_WIDTH, disp_width);
   15.65 -		set_option_int(optdb, VR_OPT_DISPLAY_HEIGHT, disp_height);
   15.66 -		set_option_float(optdb, VR_OPT_IPD, ipd);
   15.67 -
   15.68 -		set_option_int(optdb, VR_OPT_LEYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
   15.69 -		set_option_int(optdb, VR_OPT_LEYE_YRES, (int)(disp_height * FB_EMBIGGEN));
   15.70 -		set_option_int(optdb, VR_OPT_REYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
   15.71 -		set_option_int(optdb, VR_OPT_REYE_YRES, (int)(disp_height * FB_EMBIGGEN));
   15.72 -	}
   15.73 -
   15.74 -	return 0;
   15.75 -}
   15.76 -
   15.77 -static void cleanup(void)
   15.78 -{
   15.79 -	if(ctx) {
   15.80 -		ohmd_ctx_destroy(ctx);
   15.81 -	}
   15.82 -}
   15.83 -
   15.84 -
   15.85 -static int set_option(const char *opt, enum opt_type type, void *valp)
   15.86 -{
   15.87 -	switch(type) {
   15.88 -	case OTYPE_INT:
   15.89 -		set_option_int(optdb, opt, *(int*)valp);
   15.90 -		break;
   15.91 -
   15.92 -	case OTYPE_FLOAT:
   15.93 -		set_option_float(optdb, opt, *(float*)valp);
   15.94 -		break;
   15.95 -	}
   15.96 -	return 0;
   15.97 -}
   15.98 -
   15.99 -static int get_option(const char *opt, enum opt_type type, void *valp)
  15.100 -{
  15.101 -	switch(type) {
  15.102 -	case OTYPE_INT:
  15.103 -		return get_option_int(optdb, opt, valp);
  15.104 -	case OTYPE_FLOAT:
  15.105 -		return get_option_float(optdb, opt, valp);
  15.106 -	}
  15.107 -	return -1;
  15.108 -}
  15.109 -
  15.110 -static int translation(int eye, float *vec)
  15.111 -{
  15.112 -	float xform[16];
  15.113 -
  15.114 -	view_matrix(eye, xform);
  15.115 -
  15.116 -	vec[0] = xform[3];
  15.117 -	vec[1] = xform[7];
  15.118 -	vec[2] = xform[11];
  15.119 -	return 0;
  15.120 -}
  15.121 -
  15.122 -static int rotation(int eye, float *quat)
  15.123 -{
  15.124 -	if(!dev) {
  15.125 -		quat[0] = quat[1] = quat[2] = 0.0f;
  15.126 -		quat[3] = 1.0f;
  15.127 -		return -1;
  15.128 -	}
  15.129 -
  15.130 -	ohmd_device_getf(dev, OHMD_ROTATION_QUAT, quat);
  15.131 -	return 0;
  15.132 -}
  15.133 -
  15.134 -
  15.135 -static void view_matrix(int eye, float *mat)
  15.136 -{
  15.137 -	ohmd_device_getf(dev, OHMD_LEFT_EYE_GL_MODELVIEW_MATRIX + eye, mat);
  15.138 -}
  15.139 -
  15.140 -static void proj_matrix(int eye, float znear, float zfar, float *mat)
  15.141 -{
  15.142 -	ohmd_device_setf(dev, OHMD_PROJECTION_ZNEAR, znear);
  15.143 -	ohmd_device_setf(dev, OHMD_PROJECTION_ZFAR, zfar);
  15.144 -	ohmd_device_getf(dev, OHMD_LEFT_EYE_GL_PROJECTION_MATRIX + eye, mat);
  15.145 -}
  15.146 -
  15.147 -static void begin(int eye)
  15.148 -{
  15.149 -	if(new_frame) {
  15.150 -		ohmd_ctx_update(ctx);
  15.151 -		new_frame = 0;
  15.152 -	}
  15.153 -}
  15.154 -
  15.155 -static int present(void)
  15.156 -{
  15.157 -	new_frame = 1;
  15.158 -	return 0;
  15.159 -}
  15.160 -
  15.161 -static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
  15.162 -{
  15.163 -	eye_tex[eye].id = tex;
  15.164 -	eye_tex[eye].umin = umin;
  15.165 -	eye_tex[eye].umax = umax;
  15.166 -	eye_tex[eye].vmin = vmin;
  15.167 -	eye_tex[eye].vmax = vmax;
  15.168 -}
  15.169 -
  15.170 -static void recenter(void)
  15.171 -{
  15.172 -	/* TODO does OHMD support the magnetometer? */
  15.173 -}
  15.174 -
  15.175 -
  15.176 -struct vr_module *vr_module_openhmd(void)
  15.177 -{
  15.178 -	static struct vr_module m;
  15.179 -
  15.180 -	if(!m.init) {
  15.181 -		m.name = "openhmd";
  15.182 -		m.init = init;
  15.183 -		m.cleanup = cleanup;
  15.184 -		m.set_option = set_option;
  15.185 -		m.get_option = get_option;
  15.186 -		m.view_matrix = view_matrix;
  15.187 -		m.proj_matrix = proj_matrix;
  15.188 -		m.begin = begin;
  15.189 -		m.present = present;
  15.190 -		m.set_eye_texture = set_eye_texture;
  15.191 -		m.recenter = recenter;
  15.192 -	}
  15.193 -}
  15.194 -
  15.195 -#else	/* don't use OpenHMD */
  15.196 -
  15.197 -static int init(void)
  15.198 -{
  15.199 -	return -1;
  15.200 -}
  15.201 -
  15.202 -struct vr_module *vr_module_openhmd(void)
  15.203 -{
  15.204 -	static struct vr_module m;
  15.205 -
  15.206 -	if(!m.init) {
  15.207 -		m.name = "openhmd";
  15.208 -		m.init = init;
  15.209 -	}
  15.210 -	return &m;
  15.211 -}
  15.212 -
  15.213 -#endif	/* USE_OPENHMD */