ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo4.c
Revision: 3.23
Committed: Fri Dec 18 11:56:11 1998 UTC (25 years, 3 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.22: +17 -11 lines
Log Message:
created new ogl driver with direct geometry rendering

File Contents

# User Rev Content
1 gwlarson 3.19 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2 gregl 3.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Holodeck display process communication
9     */
10    
11     #include "rholo.h"
12     #include "rhdisp.h"
13 gregl 3.2 #include <sys/uio.h>
14 gregl 3.1
15 gregl 3.2 #ifndef HDSUF
16 gregl 3.16 #define HDSUF ".hdi"
17 gregl 3.2 #endif
18 gregl 3.1
19 gwlarson 3.21 #ifndef FNONBLK
20     #define FNONBLK O_NONBLOCK
21     #endif
22    
23 gregl 3.2 static int inp_flags;
24     static int dpd[3];
25 gregl 3.5 static FILE *dpout;
26 gregl 3.2
27    
28     disp_open(dname) /* open the named display driver */
29 gregl 3.1 char *dname;
30     {
31 gwlarson 3.23 char buf[128], fd0[8], fd1[8], *cmd[5], *ofn;
32     int i, n;
33 gregl 3.11 /* get full display program name */
34 gregl 3.2 #ifdef DEVPATH
35 gwlarson 3.23 sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF);
36 gregl 3.2 #else
37 gwlarson 3.23 sprintf(buf, "dev/%s%s", dname, HDSUF);
38 gregl 3.2 #endif
39 gregl 3.11 /* dup stdin and stdout */
40     if (readinp)
41     sprintf(fd0, "%d", dup(0));
42     else
43     strcpy(fd0, "-1");
44     sprintf(fd1, "%d", dup(1));
45     /* start the display process */
46 gwlarson 3.23 cmd[0] = buf;
47 gregl 3.11 cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
48     cmd[4] = NULL;
49     i = open_process(dpd, cmd);
50 gregl 3.6 if (i <= 0)
51 gregl 3.2 error(USER, "cannot start display process");
52 gregl 3.11 if ((dpout = fdopen(dpd[1], "w")) == NULL)
53 gregl 3.5 error(SYSTEM, "cannot associate FILE with display pipe");
54 gregl 3.11 dpd[1] = -1; /* causes ignored error in close_process() */
55 gregl 3.2 inp_flags = 0;
56 gregl 3.11 /* close dup'ed stdin and stdout */
57     if (readinp)
58     close(atoi(fd0));
59     close(atoi(fd1));
60 gregl 3.17 /* check if outside */
61     if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS))
62     disp_result(DS_OUTSECT, 0, NULL);
63 gwlarson 3.18 /* send eye separation if specified */
64     if (vdef(EYESEP)) {
65 gwlarson 3.23 sprintf(buf, "%.9e", vflt(EYESEP));
66     disp_result(DS_EYESEP, strlen(buf)+1, buf);
67 gwlarson 3.18 }
68 gwlarson 3.23 /* write out hologram grids & octrees */
69     for (i = 0; hdlist[i] != NULL; i++) {
70     bcopy((char *)hdlist[i], buf, sizeof(HDGRID));
71     n = vdef(OSECTION);
72     ofn = i<n ? nvalue(OSECTION,i) :
73     n ? nvalue(OSECTION,n-1) : vval(OCTREE);
74     strcpy(buf+sizeof(HDGRID), ofn);
75     disp_result(DS_ADDHOLO, sizeof(HDGRID)+1+strlen(ofn), buf);
76     }
77 gregl 3.5 disp_flush();
78 gregl 3.1 }
79    
80    
81 gregl 3.2 disp_packet(p) /* display a packet */
82 gregl 3.4 register PACKHEAD *p;
83 gregl 3.2 {
84 gregl 3.4 disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
85 gregl 3.2 }
86    
87    
88 gregl 3.1 disp_check(block) /* check display process */
89     int block;
90     {
91 gregl 3.2 MSGHEAD msg;
92     int n;
93     char *buf = NULL;
94    
95 gregl 3.6 if (dpout == NULL)
96 gregl 3.2 return(-1);
97 gregl 3.5 /* flush display output */
98     disp_flush();
99 gregl 3.3 /* check read blocking */
100 gregl 3.2 if (block != (inp_flags == 0)) {
101     inp_flags = block ? 0 : FNONBLK;
102     if (fcntl(dpd[0], F_SETFL, inp_flags) < 0)
103     goto fcntlerr;
104     }
105     /* read message header */
106     n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD));
107     if (n != sizeof(MSGHEAD)) {
108 gregl 3.10 if (n >= 0) {
109     dpout = NULL;
110 gregl 3.2 error(USER, "display process died");
111 gregl 3.10 }
112 gregl 3.2 if (errno != EAGAIN & errno != EINTR)
113     goto readerr;
114 gregl 3.3 return(2); /* acceptable failure */
115 gregl 3.2 }
116     if (msg.nbytes) { /* get the message body */
117 gwlarson 3.20 if (msg.nbytes < 0)
118     error(INTERNAL, "anti-message from display process");
119 gregl 3.2 buf = (char *)malloc(msg.nbytes);
120     if (buf == NULL)
121     error(SYSTEM, "out of memory in disp_check");
122 gwlarson 3.19 if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0)
123 gregl 3.2 goto fcntlerr;
124     if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes)
125     goto readerr;
126     }
127     switch (msg.type) { /* take appropriate action */
128 gregl 3.12 case DR_BUNDLE: /* new bundle to calculate */
129 gregl 3.2 if (msg.nbytes != sizeof(PACKHEAD))
130     error(INTERNAL, "bad DR_BUNDLE from display process");
131     bundle_set(BS_ADD, (PACKHEAD *)buf, 1);
132     break;
133 gregl 3.12 case DR_NEWSET: /* new calculation set */
134 gregl 3.2 if (msg.nbytes % sizeof(PACKHEAD))
135     error(INTERNAL, "bad DR_NEWSET from display process");
136 gwlarson 3.19 if (msg.nbytes)
137     disp_result(DS_STARTIMM, 0, NULL);
138 gregl 3.2 bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
139 gwlarson 3.19 if (msg.nbytes) {
140     disp_result(DS_ENDIMM, 0, NULL);
141     disp_flush();
142     }
143 gregl 3.2 break;
144 gregl 3.12 case DR_ADDSET: /* add to calculation set */
145 gwlarson 3.19 if (!msg.nbytes)
146     break;
147 gregl 3.2 if (msg.nbytes % sizeof(PACKHEAD))
148     error(INTERNAL, "bad DR_ADDSET from display process");
149     disp_result(DS_STARTIMM, 0, NULL);
150     bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
151     disp_result(DS_ENDIMM, 0, NULL);
152 gregl 3.15 disp_flush();
153 gregl 3.2 break;
154 gregl 3.12 case DR_ADJSET: /* adjust calculation set members */
155 gwlarson 3.19 if (!msg.nbytes)
156     break;
157 gregl 3.9 if (msg.nbytes % sizeof(PACKHEAD))
158     error(INTERNAL, "bad DR_ADJSET from display process");
159     disp_result(DS_STARTIMM, 0, NULL);
160     bundle_set(BS_ADJ, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
161     disp_result(DS_ENDIMM, 0, NULL);
162     disp_flush();
163     break;
164 gregl 3.12 case DR_DELSET: /* delete from calculation set */
165 gwlarson 3.19 if (!msg.nbytes)
166     break;
167 gregl 3.2 if (msg.nbytes % sizeof(PACKHEAD))
168     error(INTERNAL, "bad DR_DELSET from display process");
169     bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
170     break;
171 gwlarson 3.22 case DR_VIEWPOINT: /* set target eye position */
172     if (msg.nbytes != sizeof(VIEWPOINT))
173     error(INTERNAL, "bad DR_VIEWPOINT from display process");
174     copystruct(&myeye, (VIEWPOINT *)buf);
175     break;
176 gregl 3.12 case DR_ATTEN: /* block for priority request */
177 gregl 3.2 if (msg.nbytes)
178     error(INTERNAL, "bad DR_ATTEN from display process");
179     /* send acknowledgement */
180     disp_result(DS_ACKNOW, 0, NULL);
181 gregl 3.3 return(disp_check(1)); /* block on following request */
182 gregl 3.13 case DR_KILL: /* kill computation process(es) */
183     if (msg.nbytes)
184     error(INTERNAL, "bad DR_KILL from display process");
185 gregl 3.14 if (nprocs > 0)
186     done_rtrace();
187     else
188 gregl 3.13 error(WARNING, "no rtrace process to kill");
189     break;
190     case DR_RESTART: /* restart computation process(es) */
191     if (msg.nbytes)
192     error(INTERNAL, "bad DR_RESTART from display process");
193 gregl 3.14 if (ncprocs > nprocs)
194     new_rtrace();
195     else if (nprocs > 0)
196 gregl 3.13 error(WARNING, "rtrace already runnning");
197     else
198     error(WARNING, "holodeck not open for writing");
199     break;
200     case DR_CLOBBER: /* clobber holodeck */
201     if (msg.nbytes)
202     error(INTERNAL, "bad DR_CLOBBER from display process");
203     if (!force || !ncprocs)
204     error(WARNING, "request to clobber holodeck denied");
205     else {
206     error(WARNING, "clobbering holodeck contents");
207     hdclobber(NULL);
208     }
209     break;
210 gregl 3.12 case DR_SHUTDOWN: /* shut down program */
211 gregl 3.2 if (msg.nbytes)
212     error(INTERNAL, "bad DR_SHUTDOWN from display process");
213     return(0); /* zero return signals shutdown */
214 gregl 3.12 case DR_NOOP: /* do nothing */
215 gregl 3.7 break;
216 gregl 3.2 default:
217     error(INTERNAL, "unrecognized request from display process");
218     }
219 gregl 3.3 if (msg.nbytes) /* clean up */
220 gregl 3.2 free(buf);
221     return(1); /* normal return value */
222     fcntlerr:
223     error(SYSTEM, "cannot change display blocking mode");
224     readerr:
225     error(SYSTEM, "error reading from display process");
226 gregl 3.1 }
227    
228    
229 gregl 3.2 int
230     disp_close() /* close our display process */
231 gregl 3.1 {
232 gregl 3.2 int rval;
233    
234 gregl 3.6 if (dpout == NULL)
235 gregl 3.2 return(-1);
236 gwlarson 3.23 myeye.rng = 0;
237 gregl 3.2 disp_result(DS_SHUTDOWN, 0, NULL);
238 gregl 3.5 fclose(dpout);
239     dpout = NULL;
240 gregl 3.2 return(close_process(dpd));
241     }
242    
243    
244 gregl 3.5 disp_result(type, nbytes, p) /* queue result message to display process */
245 gregl 3.2 int type, nbytes;
246     char *p;
247     {
248     MSGHEAD msg;
249 gwlarson 3.20 /* consistency checks */
250     #ifdef DEBUG
251     if (nbytes < 0 || nbytes > 0 & p == NULL)
252     error(CONSISTENCY, "bad buffer handed to disp_result");
253     #endif
254 gregl 3.6 if (dpout == NULL)
255     return;
256 gregl 3.2 msg.type = type;
257     msg.nbytes = nbytes;
258 gregl 3.5 fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout);
259     if (nbytes > 0)
260     fwrite(p, 1, nbytes, dpout);
261     }
262    
263    
264     disp_flush() /* flush output to display */
265     {
266     if (fflush(dpout) < 0)
267     error(SYSTEM, "error writing to the display process");
268 gregl 3.1 }