vrchess

annotate src/vr/vr.c @ 6:3c36bc28c6c2

more stuff in the vr test
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 21 Aug 2014 01:08:03 +0300
parents e6948e131526
children bd8202d6d28d
rev   line source
nuclear@4 1 #include <stdio.h>
nuclear@4 2 #include <string.h>
nuclear@4 3 #include "vr.h"
nuclear@4 4 #include "vr_impl.h"
nuclear@4 5
nuclear@4 6
nuclear@4 7 static struct vr_module *vrm;
nuclear@4 8 static float idmat[] = {
nuclear@4 9 1, 0, 0, 0,
nuclear@4 10 0, 1, 0, 0,
nuclear@4 11 0, 0, 1, 0,
nuclear@4 12 0, 0, 0, 1
nuclear@4 13 };
nuclear@4 14 static float fbtex_rect[] = {
nuclear@4 15 0, 0, 1, 1
nuclear@4 16 };
nuclear@4 17
nuclear@4 18 int vr_init(void)
nuclear@4 19 {
nuclear@4 20 int i, nmodules;
nuclear@4 21
nuclear@4 22 if(vrm) {
nuclear@4 23 vr_shutdown();
nuclear@4 24 }
nuclear@4 25
nuclear@4 26 vr_init_modules();
nuclear@4 27
nuclear@4 28 nmodules = vr_get_num_modules();
nuclear@4 29 for(i=0; i<nmodules; i++) {
nuclear@4 30 struct vr_module *m = vr_get_module(i);
nuclear@4 31 if(m->init() != -1) {
nuclear@4 32 /* add to the active modules array */
nuclear@4 33 vr_activate_module(i);
nuclear@4 34 if(!vrm) {
nuclear@4 35 vr_use_module(0);
nuclear@4 36 }
nuclear@4 37 }
nuclear@4 38 }
nuclear@4 39
nuclear@4 40 if(!vrm) {
nuclear@4 41 return -1;
nuclear@4 42 }
nuclear@4 43 return 0;
nuclear@4 44 }
nuclear@4 45
nuclear@4 46 void vr_shutdown(void)
nuclear@4 47 {
nuclear@4 48 vr_clear_modules();
nuclear@4 49 vrm = 0;
nuclear@4 50 fbtex_rect[0] = fbtex_rect[1] = 0;
nuclear@4 51 fbtex_rect[2] = fbtex_rect[3] = 1;
nuclear@4 52 }
nuclear@4 53
nuclear@4 54 int vr_module_count(void)
nuclear@4 55 {
nuclear@4 56 return vr_get_num_active_modules();
nuclear@4 57 }
nuclear@4 58
nuclear@4 59 const char *vr_module_name(int idx)
nuclear@4 60 {
nuclear@4 61 struct vr_module *m = vr_get_active_module(idx);
nuclear@4 62 if(!m) {
nuclear@4 63 return 0;
nuclear@4 64 }
nuclear@4 65 return m->name;
nuclear@4 66 }
nuclear@4 67
nuclear@4 68 int vr_use_module(int idx)
nuclear@4 69 {
nuclear@4 70 if(idx >= 0 && idx < vr_get_num_active_modules()) {
nuclear@4 71 vrm = vr_get_active_module(idx);
nuclear@4 72 printf("using vr module: %s\n", vrm->name);
nuclear@4 73 return 0;
nuclear@4 74 }
nuclear@4 75 return -1;
nuclear@4 76 }
nuclear@4 77
nuclear@4 78 int vr_use_module_named(const char *name)
nuclear@4 79 {
nuclear@4 80 int i, count = vr_get_num_active_modules();
nuclear@4 81
nuclear@4 82 for(i=0; i<count; i++) {
nuclear@4 83 struct vr_module *m = vr_get_active_module(i);
nuclear@4 84 if(strcmp(m->name, name) == 0) {
nuclear@4 85 return vr_use_module(i);
nuclear@4 86 }
nuclear@4 87 }
nuclear@4 88 return -1;
nuclear@4 89 }
nuclear@4 90
nuclear@4 91 int vr_view_matrix(int eye, float *mat)
nuclear@4 92 {
nuclear@4 93 if(vrm && vrm->view_matrix) {
nuclear@4 94 vrm->view_matrix(eye, mat);
nuclear@4 95 return 1;
nuclear@4 96 }
nuclear@4 97 memcpy(mat, idmat, sizeof idmat);
nuclear@4 98 return 0;
nuclear@4 99 }
nuclear@4 100
nuclear@4 101 int vr_proj_matrix(int eye, float *mat)
nuclear@4 102 {
nuclear@4 103 if(vrm && vrm->proj_matrix) {
nuclear@4 104 vrm->proj_matrix(eye, mat);
nuclear@4 105 return 1;
nuclear@4 106 }
nuclear@4 107 memcpy(mat, idmat, sizeof idmat);
nuclear@4 108 return 0;
nuclear@4 109 }
nuclear@4 110
nuclear@6 111 void vr_begin(int eye)
nuclear@4 112 {
nuclear@6 113 if(vrm && vrm->begin) {
nuclear@6 114 vrm->begin(eye);
nuclear@4 115 }
nuclear@4 116 }
nuclear@4 117
nuclear@6 118 void vr_end(void)
nuclear@4 119 {
nuclear@6 120 if(vrm && vrm->end) {
nuclear@6 121 vrm->end();
nuclear@6 122 }
nuclear@4 123 }
nuclear@6 124
nuclear@6 125 int vr_swap_buffers(void)
nuclear@6 126 {
nuclear@6 127 if(vrm && vrm->present) {
nuclear@6 128 vrm->present();
nuclear@6 129 return 1;
nuclear@6 130 }
nuclear@6 131 return 0;
nuclear@6 132 }