1 //////////////////////////////////////////////////////////////////////
2 //
3 // Pixie
4 //
5 // Copyright � 1999 - 2003, Okan Arikan
6 //
7 // Contact: okan@cs.utexas.edu
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 ///////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////
25 //
26 // File : sdrinfo.cpp
27 // Classes : -
28 // Description : sdr info probram
29 //
30 ////////////////////////////////////////////////////////////////////////
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "common/global.h"
36 #include "common/os.h"
37 #include "sdr/sdr.h"
38
39 ///////////////////////////////////////////////////////////////////////
40 // Function : main
41 // Description : The god
42 // Return Value : -
43 // Comments :
main(int argc,char * argv[])44 int main(int argc, char* argv[]) {
45 char tmp[1024];
46
47 if (argc > 1) {
48 TSdrShader *cShader;
49 TSdrParameter *cParameter;
50 const char *pixieHome = osEnvironment("PIXIEHOME");
51 const char *shaders = osEnvironment("SHADERS");
52
53 sprintf(tmp,".");
54
55 if (pixieHome != NULL) {
56 strcat(tmp,":");
57 strcat(tmp,pixieHome);
58 strcat(tmp,"/shaders");
59 }
60
61 if (shaders != NULL) {
62 strcat(tmp,":");
63 strcat(tmp,shaders);
64 }
65
66
67 osFixSlashes(tmp);
68 cShader = sdrGet(argv[1],tmp);
69
70 if (cShader == NULL) {
71 fprintf(stderr,"Failed to find shader \"%s\"\n",argv[1]);
72 exit(1);
73 }
74
75 switch(cShader->type) {
76 case SHADER_SURFACE:
77 fprintf(stdout,"surface ");
78 break;
79 case SHADER_DISPLACEMENT:
80 fprintf(stdout,"displacement ");
81 break;
82 case SHADER_VOLUME:
83 fprintf(stdout,"volume ");
84 break;
85 case SHADER_LIGHT:
86 fprintf(stdout,"light ");
87 break;
88 case SHADER_IMAGER:
89 fprintf(stdout,"imager ");
90 break;
91 }
92
93 fprintf(stdout,"\"%s\"\n",cShader->name);
94
95 for (cParameter=cShader->parameters;cParameter!=NULL;cParameter=cParameter->next) {
96 fprintf(stdout,"\t\"%s\" ",cParameter->name);
97
98 if (cParameter->writable) {
99 fprintf(stdout,"\"output ");
100 } else {
101 fprintf(stdout,"\"");
102 }
103
104 switch(cParameter->container) {
105 case CONTAINER_CONSTANT:
106 fprintf(stdout,"constant ");
107 break;
108 case CONTAINER_UNIFORM:
109 fprintf(stdout,"uniform ");
110 break;
111 case CONTAINER_VARYING:
112 fprintf(stdout,"varying ");
113 break;
114 case CONTAINER_VERTEX:
115 fprintf(stdout,"vertex ");
116 break;
117 }
118
119 switch(cParameter->type) {
120 case TYPE_FLOAT:
121 fprintf(stdout,"float");
122 break;
123 case TYPE_VECTOR:
124 fprintf(stdout,"vector");
125 break;
126 case TYPE_NORMAL:
127 fprintf(stdout,"normal");
128 break;
129 case TYPE_POINT:
130 fprintf(stdout,"point");
131 break;
132 case TYPE_COLOR:
133 fprintf(stdout,"color");
134 break;
135 case TYPE_MATRIX:
136 fprintf(stdout,"matrix");
137 break;
138 case TYPE_STRING:
139 fprintf(stdout,"string");
140 break;
141 }
142
143 if (cParameter->numItems > 1) {
144 fprintf(stdout,"[%d]",cParameter->numItems);
145 }
146
147 fprintf(stdout,"\"\n");
148
149 fprintf(stdout,"\t\tDefault value: ");
150
151 UDefaultVal *currentDefault = &cParameter->defaultValue;
152 if (cParameter->numItems > 1)
153 currentDefault = currentDefault->array;
154
155 for(int i=0;i<cParameter->numItems;i++){
156 switch(cParameter->type) {
157 case TYPE_FLOAT:
158 fprintf(stdout,"%g ",currentDefault->scalar);
159 break;
160 case TYPE_VECTOR:
161 case TYPE_NORMAL:
162 case TYPE_POINT:
163 case TYPE_COLOR:
164 if (cParameter->space != NULL) {
165 fprintf(stdout,"\"%s\" ",cParameter->space);
166 }
167
168 if (currentDefault->vector != NULL) {
169 fprintf(stdout,"[%g %g %g] ",currentDefault->vector[0],currentDefault->vector[1],currentDefault->vector[2]);
170 } else {
171 fprintf(stdout,"[0 0 0] ");
172 }
173 break;
174 case TYPE_MATRIX:
175 if (currentDefault->matrix != NULL) {
176 fprintf(stdout,"[%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g] "
177 ,currentDefault->matrix[0]
178 ,currentDefault->matrix[1]
179 ,currentDefault->matrix[2]
180 ,currentDefault->matrix[3]
181 ,currentDefault->matrix[4]
182 ,currentDefault->matrix[5]
183 ,currentDefault->matrix[6]
184 ,currentDefault->matrix[7]
185 ,currentDefault->matrix[8]
186 ,currentDefault->matrix[9]
187 ,currentDefault->matrix[10]
188 ,currentDefault->matrix[11]
189 ,currentDefault->matrix[12]
190 ,currentDefault->matrix[13]
191 ,currentDefault->matrix[14]
192 ,currentDefault->matrix[15]);
193 } else {
194 fprintf(stdout,"[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ");
195 }
196 break;
197 case TYPE_STRING:
198 if (currentDefault->string != NULL) {
199 fprintf(stdout,"\"%s\" ",currentDefault->string);
200 } else {
201 fprintf(stdout,"NULL ");
202 }
203 break;
204 }
205 currentDefault++;
206 }
207 fprintf(stdout,"\n");
208 }
209
210 sdrDelete(cShader);
211 }
212
213 return 0;
214 }
215
216