VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c@ 43233

最後變更 在這個檔案從43233是 40691,由 vboxsync 提交於 13 年 前

crOpenGL: basics for using multiple contexts on host

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 9.9 KB
 
1 /* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include <string.h>
8#include "cr_mem.h"
9#include "cr_environment.h"
10#include "cr_string.h"
11#include "cr_error.h"
12#include "cr_glstate.h"
13#include "server.h"
14
15#ifdef WINDOWS
16#pragma warning( disable: 4706 )
17#endif
18
19static void
20setDefaults(void)
21{
22 if (!cr_server.tcpip_port)
23 cr_server.tcpip_port = DEFAULT_SERVER_PORT;
24 cr_server.run_queue = NULL;
25 cr_server.optimizeBucket = 1;
26 cr_server.useL2 = 0;
27 cr_server.maxBarrierCount = 0;
28 cr_server.ignore_papi = 0;
29 cr_server.only_swap_once = 0;
30 cr_server.overlapBlending = 0;
31 cr_server.debug_barriers = 0;
32 cr_server.sharedDisplayLists = 0;
33 cr_server.sharedTextureObjects = 0;
34 cr_server.sharedPrograms = 0;
35 cr_server.sharedWindows = 0;
36 cr_server.useDMX = 0;
37 cr_server.vpProjectionMatrixParameter = -1;
38 cr_server.vpProjectionMatrixVariable = NULL;
39 cr_server.currentProgram = 0;
40
41 cr_server.num_overlap_intens = 0;
42 cr_server.overlap_intens = 0;
43 crMemset(&cr_server.MainContextInfo, 0, sizeof (cr_server.MainContextInfo));
44
45 crMatrixInit(&cr_server.viewMatrix[0]);
46 crMatrixInit(&cr_server.viewMatrix[1]);
47 crMatrixInit(&cr_server.projectionMatrix[0]);
48 crMatrixInit(&cr_server.projectionMatrix[1]);
49 cr_server.currentEye = -1;
50
51 cr_server.uniqueWindows = 0;
52
53 cr_server.idsPool.freeWindowID = 1;
54 cr_server.idsPool.freeContextID = 1;
55 cr_server.idsPool.freeClientID = 1;
56
57 cr_server.screenCount = 0;
58 cr_server.bForceOffscreenRendering = GL_FALSE;
59 cr_server.bUsePBOForReadback = GL_FALSE;
60 cr_server.bUseOutputRedirect = GL_FALSE;
61}
62
63void crServerSetVBoxConfiguration()
64{
65 CRMuralInfo *defaultMural;
66 char response[8096];
67
68 char **spuchain;
69 int num_spus;
70 int *spu_ids;
71 char **spu_names;
72 char *spu_dir = NULL;
73 int i;
74 /* Quadrics defaults */
75 int my_rank = 0;
76 int low_context = CR_QUADRICS_DEFAULT_LOW_CONTEXT;
77 int high_context = CR_QUADRICS_DEFAULT_HIGH_CONTEXT;
78 unsigned char key[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
79 char hostname[1024];
80 char **clientchain, **clientlist;
81 GLint dims[4];
82
83 defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
84 CRASSERT(defaultMural);
85
86 setDefaults();
87
88 /*
89 * Get my hostname
90 */
91 if (crGetHostname(hostname, sizeof(hostname)))
92 {
93 crError("CRServer: Couldn't get my own hostname?");
94 }
95
96 strcpy(response, "1 0 render");
97 crDebug("CRServer: my SPU chain: %s", response);
98
99 /* response will describe the SPU chain.
100 * Example "2 5 wet 6 render"
101 */
102 spuchain = crStrSplit(response, " ");
103 num_spus = crStrToInt(spuchain[0]);
104 spu_ids = (int *) crAlloc(num_spus * sizeof(*spu_ids));
105 spu_names = (char **) crAlloc((num_spus + 1) * sizeof(*spu_names));
106 for (i = 0; i < num_spus; i++)
107 {
108 spu_ids[i] = crStrToInt(spuchain[2 * i + 1]);
109 spu_names[i] = crStrdup(spuchain[2 * i + 2]);
110 crDebug("SPU %d/%d: (%d) \"%s\"", i + 1, num_spus, spu_ids[i],
111 spu_names[i]);
112 }
113 spu_names[i] = NULL;
114
115 //spu_dir = crStrdup(response);
116 crNetSetRank(0);
117 crNetSetContextRange(32, 35);
118 crNetSetNodeRange("iam0", "iamvis20");
119 crNetSetKey(key,sizeof(key));
120 crNetSetKey(key,sizeof(key));
121 cr_server.tcpip_port = 7000;
122
123 /*cr_server.optimizeBucket = crStrToInt(response);
124 cr_server.localTileSpec = crStrToInt(response);
125 cr_server.useL2 = crStrToInt(response);
126 cr_server.ignore_papi = crStrToInt(response);
127 if (crMothershipGetServerParam(conn, response, "overlap_blending"))
128 {
129 if (!crStrcmp(response, "blend"))
130 cr_server.overlapBlending = 1;
131 else if (!crStrcmp(response, "knockout"))
132 cr_server.overlapBlending = 2;
133 }
134 if (crMothershipGetServerParam(conn, response, "overlap_levels"))
135 cr_server.only_swap_once = crStrToInt(response);
136 cr_server.debug_barriers = crStrToInt(response);
137 cr_server.sharedDisplayLists = crStrToInt(response);
138 cr_server.sharedTextureObjects = crStrToInt(response);
139 cr_server.sharedPrograms = crStrToInt(response);
140 cr_server.sharedWindows = crStrToInt(response);
141 cr_server.uniqueWindows = crStrToInt(response);
142 cr_server.useDMX = crStrToInt(response);
143 if (crMothershipGetServerParam(conn, response, "vertprog_projection_param"))
144 if (crMothershipGetServerParam(conn, response, "stereo_view"))
145 if (crMothershipGetServerParam(conn, response, "view_matrix"))
146 if (crMothershipGetServerParam(conn, response, "right_view_matrix"))
147 if (crMothershipGetServerParam(conn, response, "projection_matrix"))
148 if (crMothershipGetServerParam(conn, response, "right_projection_matrix"))*/
149
150 crDebug("CRServer: my port number is %d", cr_server.tcpip_port);
151
152 /*
153 * Load the SPUs
154 */
155 cr_server.head_spu =
156 crSPULoadChain(num_spus, spu_ids, spu_names, spu_dir, &cr_server);
157
158 /* Need to do this as early as possible */
159
160 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
161 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
162
163 defaultMural->gX = dims[0];
164 defaultMural->gY = dims[1];
165 defaultMural->width = dims[2];
166 defaultMural->height = dims[3];
167
168 crFree(spu_ids);
169 crFreeStrings(spu_names);
170 crFreeStrings(spuchain);
171 if (spu_dir)
172 crFree(spu_dir);
173
174 cr_server.mtu = 1024 * 30;
175
176 /*
177 * Get a list of all the clients talking to me.
178 */
179 if (cr_server.vncMode) {
180 /* we're inside a vnc viewer */
181 /*if (!crMothershipSendString( conn, response, "getvncclient %s", hostname ))
182 crError( "Bad Mothership response: %s", response );*/
183 }
184 else {
185 //crMothershipGetClients(conn, response);
186 strcpy(response, "1 tcpip 1");
187 }
188
189 crDebug("CRServer: my clients: %s", response);
190
191 /*
192 * 'response' will now contain a number indicating the number of clients
193 * of this server, followed by a comma-separated list of protocol/SPU ID
194 * pairs.
195 * Example: "3 tcpip 1,gm 2,via 10"
196 */
197 clientchain = crStrSplitn(response, " ", 1);
198 cr_server.numClients = crStrToInt(clientchain[0]);
199 if (cr_server.numClients == 0)
200 {
201 crError("I have no clients! What's a poor server to do?");
202 }
203 clientlist = crStrSplit(clientchain[1], ",");
204
205 /*
206 * Connect to initial set of clients.
207 * Call crNetAcceptClient() for each client.
208 * Also, look for a client that's _not_ using the file: protocol.
209 */
210 for (i = 0; i < cr_server.numClients; i++)
211 {
212 CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
213#ifdef VBOX
214 sscanf(clientlist[i], "%1023s %d", cr_server.protocol, &(newClient->spu_id));
215#else
216 sscanf(clientlist[i], "%s %d", cr_server.protocol, &(newClient->spu_id));
217#endif
218 newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
219 cr_server.tcpip_port,
220 cr_server.mtu, 0);
221 newClient->currentCtxInfo = &cr_server.MainContextInfo;
222 crServerAddToRunQueue(newClient);
223
224 cr_server.clients[i] = newClient;
225 }
226
227 /* set default client and mural */
228 if (cr_server.numClients > 0) {
229 cr_server.curClient = cr_server.clients[0];
230 cr_server.curClient->currentMural = defaultMural;
231 cr_server.client_spu_id =cr_server.clients[0]->spu_id;
232 }
233
234 crFreeStrings(clientchain);
235 crFreeStrings(clientlist);
236
237 /* Ask the mothership for the tile info */
238 //crServerGetTileInfoFromMothership(conn, defaultMural);
239
240 if (cr_server.vncMode) {
241 /* In vnc mode, we reset the mothership configuration so that it can be
242 * used by subsequent OpenGL apps without having to spawn a new mothership
243 * on a new port.
244 */
245 crDebug("CRServer: Resetting mothership to initial state");
246 //crMothershipReset(conn);
247 }
248
249 //crMothershipDisconnect(conn);
250}
251
252void crServerSetVBoxConfigurationHGCM()
253{
254 CRMuralInfo *defaultMural;
255
256 int spu_ids[1] = {0};
257 char *spu_names[1] = {"render"};
258 char *spu_dir = NULL;
259 int i;
260 GLint dims[4];
261
262 defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
263 CRASSERT(defaultMural);
264
265 //@todo should be moved to addclient so we have a chain for each client
266
267 setDefaults();
268
269 /* Load the SPUs */
270 cr_server.head_spu = crSPULoadChain(1, spu_ids, spu_names, spu_dir, &cr_server);
271
272 if (!cr_server.head_spu)
273 return;
274
275 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_POSITION_CR, 0, GL_INT, 2, &dims[0]);
276 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, &dims[2]);
277
278 defaultMural->gX = dims[0];
279 defaultMural->gY = dims[1];
280 defaultMural->width = dims[2];
281 defaultMural->height = dims[3];
282
283 cr_server.mtu = 1024 * 250;
284
285 cr_server.numClients = 0;
286 strcpy(cr_server.protocol, "vboxhgcm");
287
288 for (i = 0; i < cr_server.numClients; i++)
289 {
290 CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient));
291 newClient->spu_id = 0;
292 newClient->conn = crNetAcceptClient(cr_server.protocol, NULL,
293 cr_server.tcpip_port,
294 cr_server.mtu, 0);
295 newClient->currentCtxInfo = &cr_server.MainContextInfo;
296 crServerAddToRunQueue(newClient);
297
298 cr_server.clients[i] = newClient;
299 }
300
301 /* set default client and mural */
302 if (cr_server.numClients > 0) {
303 cr_server.curClient = cr_server.clients[0];
304 cr_server.curClient->currentMural = defaultMural;
305 cr_server.client_spu_id =cr_server.clients[0]->spu_id;
306 }
307}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette