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@7
|
91 void vr_set_opti(const char *optname, int val)
|
nuclear@7
|
92 {
|
nuclear@7
|
93 if(vrm && vrm->set_option) {
|
nuclear@7
|
94 vrm->set_option(optname, OTYPE_INT, &val);
|
nuclear@7
|
95 }
|
nuclear@7
|
96 }
|
nuclear@7
|
97
|
nuclear@7
|
98 void vr_set_optf(const char *optname, float val)
|
nuclear@7
|
99 {
|
nuclear@7
|
100 if(vrm && vrm->set_option) {
|
nuclear@7
|
101 vrm->set_option(optname, OTYPE_FLOAT, &val);
|
nuclear@7
|
102 }
|
nuclear@7
|
103 }
|
nuclear@7
|
104
|
nuclear@7
|
105 int vr_get_opti(const char *optname)
|
nuclear@7
|
106 {
|
nuclear@7
|
107 int res = 0;
|
nuclear@7
|
108
|
nuclear@7
|
109 if(vrm && vrm->get_option) {
|
nuclear@7
|
110 vrm->get_option(optname, OTYPE_INT, &res);
|
nuclear@7
|
111 }
|
nuclear@7
|
112 return res;
|
nuclear@7
|
113 }
|
nuclear@7
|
114
|
nuclear@7
|
115 float vr_get_optf(const char *optname)
|
nuclear@7
|
116 {
|
nuclear@7
|
117 float res = 0.0f;
|
nuclear@7
|
118
|
nuclear@7
|
119 if(vrm && vrm->get_option) {
|
nuclear@7
|
120 vrm->get_option(optname, OTYPE_FLOAT, &res);
|
nuclear@7
|
121 }
|
nuclear@7
|
122 return res;
|
nuclear@7
|
123 }
|
nuclear@7
|
124
|
nuclear@7
|
125
|
nuclear@7
|
126 int vr_view_translation(int eye, float *vec)
|
nuclear@7
|
127 {
|
nuclear@7
|
128 if(vrm && vrm->translation) {
|
nuclear@7
|
129 vrm->translation(eye, vec);
|
nuclear@7
|
130 return 0;
|
nuclear@7
|
131 }
|
nuclear@7
|
132 vec[0] = vec[1] = vec[2] = 0.0f;
|
nuclear@7
|
133 return -1;
|
nuclear@7
|
134 }
|
nuclear@7
|
135
|
nuclear@7
|
136 int vr_view_rotation(int eye, float *quat)
|
nuclear@7
|
137 {
|
nuclear@7
|
138 if(vrm && vrm->rotation) {
|
nuclear@7
|
139 vrm->rotation(eye, quat);
|
nuclear@7
|
140 return 0;
|
nuclear@7
|
141 }
|
nuclear@7
|
142 quat[0] = quat[1] = quat[2] = 0.0f;
|
nuclear@7
|
143 quat[3] = 1.0f;
|
nuclear@7
|
144 return -1;
|
nuclear@7
|
145 }
|
nuclear@7
|
146
|
nuclear@4
|
147 int vr_view_matrix(int eye, float *mat)
|
nuclear@4
|
148 {
|
nuclear@7
|
149 /* TODO combine vr_view_translation and vr_view_rotation */
|
nuclear@4
|
150 return 0;
|
nuclear@4
|
151 }
|
nuclear@4
|
152
|
nuclear@7
|
153 int vr_proj_matrix(int eye, float znear, float zfar, float *mat)
|
nuclear@4
|
154 {
|
nuclear@4
|
155 if(vrm && vrm->proj_matrix) {
|
nuclear@7
|
156 vrm->proj_matrix(eye, znear, zfar, mat);
|
nuclear@4
|
157 return 1;
|
nuclear@4
|
158 }
|
nuclear@4
|
159 memcpy(mat, idmat, sizeof idmat);
|
nuclear@4
|
160 return 0;
|
nuclear@4
|
161 }
|
nuclear@4
|
162
|
nuclear@6
|
163 void vr_begin(int eye)
|
nuclear@4
|
164 {
|
nuclear@6
|
165 if(vrm && vrm->begin) {
|
nuclear@6
|
166 vrm->begin(eye);
|
nuclear@4
|
167 }
|
nuclear@4
|
168 }
|
nuclear@4
|
169
|
nuclear@6
|
170 void vr_end(void)
|
nuclear@4
|
171 {
|
nuclear@6
|
172 if(vrm && vrm->end) {
|
nuclear@6
|
173 vrm->end();
|
nuclear@6
|
174 }
|
nuclear@4
|
175 }
|
nuclear@6
|
176
|
nuclear@6
|
177 int vr_swap_buffers(void)
|
nuclear@6
|
178 {
|
nuclear@6
|
179 if(vrm && vrm->present) {
|
nuclear@6
|
180 vrm->present();
|
nuclear@6
|
181 return 1;
|
nuclear@6
|
182 }
|
nuclear@6
|
183 return 0;
|
nuclear@6
|
184 }
|
nuclear@7
|
185
|
nuclear@7
|
186 void vr_output_texture(unsigned int tex, float umin, float vmin, float umax, float vmax)
|
nuclear@7
|
187 {
|
nuclear@7
|
188 float halfu = (umax + umin) * 0.5f;
|
nuclear@7
|
189
|
nuclear@7
|
190 vr_output_texture_eye(VR_EYE_LEFT, tex, umin, vmin, halfu, vmax);
|
nuclear@7
|
191 vr_output_texture_eye(VR_EYE_RIGHT, tex, halfu, vmin, umax, vmax);
|
nuclear@7
|
192 }
|
nuclear@7
|
193
|
nuclear@7
|
194 void vr_output_texture_eye(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
|
nuclear@7
|
195 {
|
nuclear@7
|
196 if(vrm && vrm->set_eye_texture) {
|
nuclear@7
|
197 vrm->set_eye_texture(eye, tex, umin, vmin, umax, vmax);
|
nuclear@7
|
198 }
|
nuclear@7
|
199 }
|
nuclear@7
|
200
|
nuclear@7
|
201 void vr_recenter(void)
|
nuclear@7
|
202 {
|
nuclear@7
|
203 if(vrm && vrm->recenter) {
|
nuclear@7
|
204 vrm->recenter();
|
nuclear@7
|
205 }
|
nuclear@7
|
206 } |