1 #include <osg/Texture>
2 #include <osg/Notify>
3 #include <osg/io_utils>
4 
5 #include <osgDB/Registry>
6 #include <osgDB/Input>
7 #include <osgDB/Output>
8 
9 #include <stdlib.h>
10 #include <string.h>
11 
12 using namespace osg;
13 using namespace osgDB;
14 
15 // forward declare functions to use later.
16 bool Texture_readLocalData(Object& obj, Input& fr);
17 bool Texture_writeLocalData(const Object& obj, Output& fw);
18 
19 bool Texture_matchWrapStr(const char* str,Texture::WrapMode& wrap);
20 const char* Texture_getWrapStr(Texture::WrapMode wrap);
21 bool Texture_matchFilterStr(const char* str,Texture::FilterMode& filter);
22 const char* Texture_getFilterStr(Texture::FilterMode filter);
23 bool Texture_matchInternalFormatModeStr(const char* str,Texture::InternalFormatMode& mode);
24 const char* Texture_getInternalFormatModeStr(Texture::InternalFormatMode mode);
25 bool Texture_matchInternalFormatStr(const char* str,int& value);
26 const char* Texture_getInternalFormatStr(int value);
27 bool Texture_matchSourceTypeStr(const char* str,int& value);
28 const char* Texture_getSourceTypeStr(int value);
29 bool Texture_matchShadowCompareFuncStr(const char* str,Texture::ShadowCompareFunc& value);
30 const char* Texture_getShadowCompareFuncStr(Texture::ShadowCompareFunc value);
31 bool Texture_matchShadowTextureModeStr(const char* str,Texture::ShadowTextureMode& value);
32 const char* Texture_getShadowTextureModeStr(Texture::ShadowTextureMode value);
33 
34 // register the read and write functions with the osgDB::Registry.
35 REGISTER_DOTOSGWRAPPER(Texture)
36 (
37     0,
38     "TextureBase",
39     "Object StateAttribute TextureBase",
40     &Texture_readLocalData,
41     &Texture_writeLocalData
42 );
43 
44 
Texture_readLocalData(Object & obj,Input & fr)45 bool Texture_readLocalData(Object& obj, Input& fr)
46 {
47     bool iteratorAdvanced = false;
48 
49     Texture& texture = static_cast<Texture&>(obj);
50 
51     Texture::WrapMode wrap;
52     if (fr[0].matchWord("wrap_s") && Texture_matchWrapStr(fr[1].getStr(),wrap))
53     {
54         texture.setWrap(Texture::WRAP_S,wrap);
55         fr+=2;
56         iteratorAdvanced = true;
57     }
58 
59     if (fr[0].matchWord("wrap_t") && Texture_matchWrapStr(fr[1].getStr(),wrap))
60     {
61         texture.setWrap(Texture::WRAP_T,wrap);
62         fr+=2;
63         iteratorAdvanced = true;
64     }
65 
66     if (fr[0].matchWord("wrap_r") && Texture_matchWrapStr(fr[1].getStr(),wrap))
67     {
68         texture.setWrap(Texture::WRAP_R,wrap);
69         fr+=2;
70         iteratorAdvanced = true;
71     }
72 
73     Texture::FilterMode filter;
74     if (fr[0].matchWord("min_filter") && Texture_matchFilterStr(fr[1].getStr(),filter))
75     {
76         texture.setFilter(Texture::MIN_FILTER,filter);
77         fr+=2;
78         iteratorAdvanced = true;
79     }
80 
81     if (fr[0].matchWord("mag_filter") && Texture_matchFilterStr(fr[1].getStr(),filter))
82     {
83         texture.setFilter(Texture::MAG_FILTER,filter);
84         fr+=2;
85         iteratorAdvanced = true;
86     }
87 
88     if (fr.matchSequence("maxAnisotropy %f"))
89     {
90         float anis=1.0f;
91         fr[1].getFloat(anis);
92         texture.setMaxAnisotropy(anis);
93         fr +=2 ;
94         iteratorAdvanced = true;
95     }
96 
97     if (fr.matchSequence("borderColor %f %f %f %f"))
98     {
99         Vec4 color;
100         fr[1].getFloat(color[0]);
101         fr[2].getFloat(color[1]);
102         fr[3].getFloat(color[2]);
103         fr[4].getFloat(color[3]);
104         texture.setBorderColor(color);
105         fr +=5 ;
106         iteratorAdvanced = true;
107     }
108 
109     if (fr.matchSequence("borderWidth %i"))
110     {
111         int width=0;
112         fr[1].getInt(width);
113         texture.setBorderWidth(width);
114         fr +=2 ;
115         iteratorAdvanced = true;
116     }
117 
118     if (fr[0].matchWord("useHardwareMipMapGeneration"))
119     {
120         if (fr[1].matchWord("TRUE"))
121         {
122             texture.setUseHardwareMipMapGeneration(true);
123             fr +=2 ;
124             iteratorAdvanced = true;
125         }
126         else if (fr[1].matchWord("FALSE"))
127         {
128             texture.setUseHardwareMipMapGeneration(false);
129             fr +=2 ;
130             iteratorAdvanced = true;
131         }
132     }
133 
134     if (fr[0].matchWord("unRefImageDataAfterApply"))
135     {
136         if (fr[1].matchWord("TRUE"))
137         {
138             texture.setUnRefImageDataAfterApply(true);
139             fr +=2 ;
140             iteratorAdvanced = true;
141         }
142         else if (fr[1].matchWord("FALSE"))
143         {
144             texture.setUnRefImageDataAfterApply(false);
145             fr +=2 ;
146             iteratorAdvanced = true;
147         }
148     }
149 
150 
151     Texture::InternalFormatMode mode;
152     if (fr[0].matchWord("internalFormatMode") && Texture_matchInternalFormatModeStr(fr[1].getStr(),mode))
153     {
154         texture.setInternalFormatMode(mode);
155         fr+=2;
156         iteratorAdvanced = true;
157     }
158 
159     if (fr[0].matchWord("internalFormat"))
160     {
161         int value;
162         if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))
163         {
164             texture.setInternalFormat(value);
165             fr+=2;
166             iteratorAdvanced = true;
167         }
168     }
169 
170     if (fr[0].matchWord("sourceFormat"))
171     {
172         int value;
173         if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))
174         {
175             texture.setSourceFormat(value);
176             fr+=2;
177             iteratorAdvanced = true;
178         }
179     }
180 
181     if (fr[0].matchWord("sourceType"))
182     {
183         int value;
184         if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))
185         {
186             texture.setSourceType(value);
187             fr+=2;
188             iteratorAdvanced = true;
189         }
190     }
191 
192     if (fr[0].matchWord("resizeNonPowerOfTwo"))
193     {
194         if (fr[1].matchWord("TRUE"))
195         {
196             texture.setResizeNonPowerOfTwoHint(true);
197             fr +=2 ;
198             iteratorAdvanced = true;
199         }
200         else if (fr[1].matchWord("FALSE"))
201         {
202             texture.setResizeNonPowerOfTwoHint(false);
203             fr +=2 ;
204             iteratorAdvanced = true;
205         }
206     }
207 
208     if (fr[0].matchWord("shadowComparison"))
209     {
210         if (fr[1].matchWord("TRUE"))
211         {
212             texture.setShadowComparison(true);
213             fr +=2 ;
214             iteratorAdvanced = true;
215         }
216         else if (fr[1].matchWord("FALSE"))
217         {
218             texture.setShadowComparison(false);
219             fr +=2 ;
220             iteratorAdvanced = true;
221         }
222     }
223 
224     if (fr[0].matchWord("shadowCompareFunc"))
225     {
226         Texture::ShadowCompareFunc value;
227         if (Texture_matchShadowCompareFuncStr(fr[1].getStr(),value))
228         {
229             texture.setShadowCompareFunc(value);
230             fr+=2;
231             iteratorAdvanced = true;
232         }
233     }
234 
235     if (fr[0].matchWord("shadowTextureMode"))
236     {
237         Texture::ShadowTextureMode value;
238         if (Texture_matchShadowTextureModeStr(fr[1].getStr(),value))
239         {
240             texture.setShadowTextureMode(value);
241             fr+=2;
242             iteratorAdvanced = true;
243         }
244     }
245 
246     return iteratorAdvanced;
247 }
248 
249 
Texture_writeLocalData(const Object & obj,Output & fw)250 bool Texture_writeLocalData(const Object& obj, Output& fw)
251 {
252     const Texture& texture = static_cast<const Texture&>(obj);
253 
254     fw.indent() << "wrap_s " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_S)) << std::endl;
255     fw.indent() << "wrap_t " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_T)) << std::endl;
256     fw.indent() << "wrap_r " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_R)) << std::endl;
257 
258     fw.indent() << "min_filter " << Texture_getFilterStr(texture.getFilter(Texture::MIN_FILTER)) << std::endl;
259     fw.indent() << "mag_filter " << Texture_getFilterStr(texture.getFilter(Texture::MAG_FILTER)) << std::endl;
260     fw.indent() << "maxAnisotropy " << texture.getMaxAnisotropy() << std::endl;
261 
262     fw.indent() << "borderColor " << texture.getBorderColor() << std::endl;
263     fw.indent() << "borderWidth " << texture.getBorderWidth() << std::endl;
264 
265     fw.indent() << "useHardwareMipMapGeneration "<< (texture.getUseHardwareMipMapGeneration()?"TRUE":"FALSE") << std::endl;
266     fw.indent() << "unRefImageDataAfterApply "<< (texture.getUnRefImageDataAfterApply()?"TRUE":"FALSE") << std::endl;
267 
268     fw.indent() << "internalFormatMode " << Texture_getInternalFormatModeStr(texture.getInternalFormatMode()) << std::endl;
269     if (texture.getInternalFormatMode()==Texture::USE_USER_DEFINED_FORMAT)
270     {
271 
272         const char* str = Texture_getInternalFormatStr(texture.getInternalFormat());
273 
274         if (str) fw.indent() << "internalFormat " << str << std::endl;
275         else fw.indent() << "internalFormat " << texture.getInternalFormat() << std::endl;
276 
277     }
278 
279     if (texture.getSourceFormat())
280     {
281         const char* str = Texture_getInternalFormatStr(texture.getSourceFormat());
282 
283         if (str) fw.indent() << "sourceFormat " << str << std::endl;
284         else fw.indent() << "sourceFormat " << texture.getSourceFormat() << std::endl;
285 
286     }
287 
288     if (texture.getSourceType())
289     {
290         const char* str = Texture_getSourceTypeStr(texture.getSourceType());
291 
292         if (str) fw.indent() << "sourceType " << str << std::endl;
293         else fw.indent() << "sourceType " << texture.getSourceType() << std::endl;
294 
295     }
296 
297     fw.indent() << "resizeNonPowerOfTwo "<< (texture.getResizeNonPowerOfTwoHint()?"TRUE":"FALSE") << std::endl;
298 
299     fw.indent() << "shadowComparison "<< (texture.getShadowComparison()?"TRUE":"FALSE") << std::endl;
300 
301     fw.indent() << "shadowCompareFunc " << Texture_getShadowCompareFuncStr(texture.getShadowCompareFunc()) << std::endl;
302 
303     fw.indent() << "shadowTextureMode " << Texture_getShadowTextureModeStr(texture.getShadowTextureMode()) << std::endl;
304 
305     return true;
306 }
307 
308 
Texture_matchWrapStr(const char * str,Texture::WrapMode & wrap)309 bool Texture_matchWrapStr(const char* str,Texture::WrapMode& wrap)
310 {
311     if (strcmp(str,"CLAMP")==0) wrap = Texture::CLAMP;
312     else if (strcmp(str,"CLAMP_TO_EDGE")==0) wrap = Texture::CLAMP_TO_EDGE;
313     else if (strcmp(str,"CLAMP_TO_BORDER")==0) wrap = Texture::CLAMP_TO_BORDER;
314     else if (strcmp(str,"REPEAT")==0) wrap = Texture::REPEAT;
315     else if (strcmp(str,"MIRROR")==0) wrap = Texture::MIRROR;
316     else return false;
317     return true;
318 }
319 
320 
Texture_getWrapStr(Texture::WrapMode wrap)321 const char* Texture_getWrapStr(Texture::WrapMode wrap)
322 {
323     switch(wrap)
324     {
325         case(Texture::CLAMP): return "CLAMP";
326         case(Texture::CLAMP_TO_EDGE): return "CLAMP_TO_EDGE";
327         case(Texture::CLAMP_TO_BORDER): return "CLAMP_TO_BORDER";
328         case(Texture::REPEAT): return "REPEAT";
329         case(Texture::MIRROR): return "MIRROR";
330     }
331     return "";
332 }
333 
334 
Texture_matchFilterStr(const char * str,Texture::FilterMode & filter)335 bool Texture_matchFilterStr(const char* str,Texture::FilterMode& filter)
336 {
337     if (strcmp(str,"NEAREST")==0) filter = Texture::NEAREST;
338     else if (strcmp(str,"LINEAR")==0) filter = Texture::LINEAR;
339     else if (strcmp(str,"NEAREST_MIPMAP_NEAREST")==0) filter = Texture::NEAREST_MIPMAP_NEAREST;
340     else if (strcmp(str,"LINEAR_MIPMAP_NEAREST")==0) filter = Texture::LINEAR_MIPMAP_NEAREST;
341     else if (strcmp(str,"NEAREST_MIPMAP_LINEAR")==0) filter = Texture::NEAREST_MIPMAP_LINEAR;
342     else if (strcmp(str,"LINEAR_MIPMAP_LINEAR")==0) filter = Texture::LINEAR_MIPMAP_LINEAR;
343     else if (strcmp(str,"ANISOTROPIC")==0) filter = Texture::LINEAR;
344     else return false;
345     return true;
346 }
347 
348 
Texture_getFilterStr(Texture::FilterMode filter)349 const char* Texture_getFilterStr(Texture::FilterMode filter)
350 {
351     switch(filter)
352     {
353         case(Texture::NEAREST): return "NEAREST";
354         case(Texture::LINEAR): return "LINEAR";
355         case(Texture::NEAREST_MIPMAP_NEAREST): return "NEAREST_MIPMAP_NEAREST";
356         case(Texture::LINEAR_MIPMAP_NEAREST): return "LINEAR_MIPMAP_NEAREST";
357         case(Texture::NEAREST_MIPMAP_LINEAR): return "NEAREST_MIPMAP_LINEAR";
358         case(Texture::LINEAR_MIPMAP_LINEAR): return "LINEAR_MIPMAP_LINEAR";
359     }
360     return "";
361 }
362 
Texture_matchInternalFormatModeStr(const char * str,Texture::InternalFormatMode & mode)363 bool Texture_matchInternalFormatModeStr(const char* str,Texture::InternalFormatMode& mode)
364 {
365     if (strcmp(str,"USE_IMAGE_DATA_FORMAT")==0)          mode = Texture::USE_IMAGE_DATA_FORMAT;
366     else if (strcmp(str,"USE_USER_DEFINED_FORMAT")==0)   mode = Texture::USE_USER_DEFINED_FORMAT;
367     else if (strcmp(str,"USE_ARB_COMPRESSION")==0)       mode = Texture::USE_ARB_COMPRESSION;
368     else if (strcmp(str,"USE_S3TC_DXT1_COMPRESSION")==0) mode = Texture::USE_S3TC_DXT1_COMPRESSION;
369     else if (strcmp(str,"USE_S3TC_DXT3_COMPRESSION")==0) mode = Texture::USE_S3TC_DXT3_COMPRESSION;
370     else if (strcmp(str,"USE_S3TC_DXT5_COMPRESSION")==0) mode = Texture::USE_S3TC_DXT5_COMPRESSION;
371     else if (strcmp(str,"USE_PVRTC_2BPP_COMPRESSION")==0) mode = Texture::USE_PVRTC_2BPP_COMPRESSION;
372     else if (strcmp(str,"USE_PVRTC_4BPP_COMPRESSION")==0) mode = Texture::USE_PVRTC_4BPP_COMPRESSION;
373     else if (strcmp(str,"USE_ETC_COMPRESSION")==0)        mode = Texture::USE_ETC_COMPRESSION;
374     else if (strcmp(str,"USE_RGTC1_COMPRESSION")==0)      mode = Texture::USE_RGTC1_COMPRESSION;
375     else if (strcmp(str,"USE_RGTC2_COMPRESSION")==0)      mode = Texture::USE_RGTC2_COMPRESSION;
376     else if (strcmp(str,"USE_S3TC_DXT1c_COMPRESSION")==0) mode = Texture::USE_S3TC_DXT1c_COMPRESSION;
377     else if (strcmp(str,"USE_S3TC_DXT1a_COMPRESSION")==0) mode = Texture::USE_S3TC_DXT1a_COMPRESSION;
378     else if (strcmp(str,"USE_ETC2_COMPRESSION")==0)       mode = Texture::USE_ETC2_COMPRESSION;
379     else return false;
380     return true;
381 }
382 
383 
Texture_getInternalFormatModeStr(Texture::InternalFormatMode mode)384 const char* Texture_getInternalFormatModeStr(Texture::InternalFormatMode mode)
385 {
386     switch(mode)
387     {
388         case(Texture::USE_IMAGE_DATA_FORMAT):        return "USE_IMAGE_DATA_FORMAT";
389         case(Texture::USE_USER_DEFINED_FORMAT):      return "USE_USER_DEFINED_FORMAT";
390         case(Texture::USE_ARB_COMPRESSION):          return "USE_ARB_COMPRESSION";
391         case(Texture::USE_S3TC_DXT1_COMPRESSION):    return "USE_S3TC_DXT1_COMPRESSION";
392         case(Texture::USE_S3TC_DXT3_COMPRESSION):    return "USE_S3TC_DXT3_COMPRESSION";
393         case(Texture::USE_S3TC_DXT5_COMPRESSION):    return "USE_S3TC_DXT5_COMPRESSION";
394         case(Texture::USE_PVRTC_2BPP_COMPRESSION):   return "USE_PVRTC_2BPP_COMPRESSION";
395         case(Texture::USE_PVRTC_4BPP_COMPRESSION):   return "USE_PVRTC_4BPP_COMPRESSION";
396         case(Texture::USE_ETC_COMPRESSION):          return "USE_ETC_COMPRESSION";
397         case(Texture::USE_RGTC1_COMPRESSION):        return "USE_RGTC1_COMPRESSION";
398         case(Texture::USE_RGTC2_COMPRESSION):        return "USE_RGTC2_COMPRESSION";
399         case(Texture::USE_S3TC_DXT1c_COMPRESSION):   return "USE_S3TC_DXT1c_COMPRESSION";
400         case(Texture::USE_S3TC_DXT1a_COMPRESSION):   return "USE_S3TC_DXT1a_COMPRESSION";
401         case(Texture::USE_ETC2_COMPRESSION):         return "USE_ETC2_COMPRESSION";
402     }
403     return "";
404 }
405 
406 
Texture_matchInternalFormatStr(const char * str,int & value)407 bool Texture_matchInternalFormatStr(const char* str,int& value)
408 {
409     if (     strcmp(str,"GL_INTENSITY")==0) value = GL_INTENSITY;
410     else if (strcmp(str,"GL_LUMINANCE")==0) value = GL_LUMINANCE;
411     else if (strcmp(str,"GL_ALPHA")==0) value = GL_ALPHA;
412     else if (strcmp(str,"GL_LUMINANCE_ALPHA")==0) value = GL_LUMINANCE_ALPHA;
413     else if (strcmp(str,"GL_RGB")==0) value = GL_RGB;
414     else if (strcmp(str,"GL_RGBA")==0) value = GL_RGBA;
415     else if (strcmp(str,"GL_COMPRESSED_ALPHA_ARB")==0) value = GL_COMPRESSED_ALPHA_ARB;
416     else if (strcmp(str,"GL_COMPRESSED_LUMINANCE_ARB")==0) value = GL_COMPRESSED_LUMINANCE_ARB;
417     else if (strcmp(str,"GL_COMPRESSED_INTENSITY_ARB")==0) value = GL_COMPRESSED_INTENSITY_ARB;
418     else if (strcmp(str,"GL_COMPRESSED_LUMINANCE_ALPHA_ARB")==0) value = GL_COMPRESSED_LUMINANCE_ALPHA_ARB;
419     else if (strcmp(str,"GL_COMPRESSED_RGB_ARB")==0) value = GL_COMPRESSED_RGB_ARB;
420     else if (strcmp(str,"GL_COMPRESSED_RGBA_ARB")==0) value = GL_COMPRESSED_RGBA_ARB;
421     else if (strcmp(str,"GL_COMPRESSED_RGB_S3TC_DXT1_EXT")==0) value = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
422     else if (strcmp(str,"GL_COMPRESSED_RGBA_S3TC_DXT1_EXT")==0) value = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
423     else if (strcmp(str,"GL_COMPRESSED_RGBA_S3TC_DXT3_EXT")==0) value = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
424     else if (strcmp(str,"GL_COMPRESSED_RGBA_S3TC_DXT5_EXT")==0) value = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
425     else
426     {
427         osgDB::Field::FieldType type = osgDB::Field::calculateFieldType(str);
428         if (type==osgDB::Field::INTEGER)
429         {
430             value = atoi(str);
431             return true;
432         }
433         else
434         {
435             return false;
436         }
437     }
438 
439     return true;
440 }
441 
442 
Texture_getInternalFormatStr(int value)443 const char* Texture_getInternalFormatStr(int value)
444 {
445     switch(value)
446     {
447         case(GL_INTENSITY): return "GL_INTENSITY";
448         case(GL_LUMINANCE): return "GL_LUMINANCE";
449         case(GL_ALPHA): return "GL_ALPHA";
450         case(GL_LUMINANCE_ALPHA): return "GL_LUMINANCE_ALPHA";
451         case(GL_RGB): return "GL_RGB";
452         case(GL_RGBA): return "GL_RGBA";
453         case(GL_COMPRESSED_ALPHA_ARB): return "GL_COMPRESSED_ALPHA_ARB";
454         case(GL_COMPRESSED_LUMINANCE_ARB): return "GL_COMPRESSED_LUMINANCE_ARB";
455         case(GL_COMPRESSED_INTENSITY_ARB): return "GL_COMPRESSED_INTENSITY_ARB";
456         case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB): return "GL_COMPRESSED_LUMINANCE_ALPHA_ARB";
457         case(GL_COMPRESSED_RGB_ARB): return "GL_COMPRESSED_RGB_ARB";
458         case(GL_COMPRESSED_RGBA_ARB): return "GL_COMPRESSED_RGBA_ARB";
459         case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): return "GL_COMPRESSED_RGB_S3TC_DXT1_EXT";
460         case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): return "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT";
461         case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): return "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT";
462         case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): return "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT";
463     }
464     return NULL;
465 }
466 
Texture_matchSourceTypeStr(const char * str,int & value)467 bool Texture_matchSourceTypeStr(const char* str,int& value)
468 {
469     if (     strcmp(str,"GL_BYTE")==0) value = GL_BYTE;
470     else if (strcmp(str,"GL_SHORT")==0) value = GL_SHORT;
471     else if (strcmp(str,"GL_INT")==0) value = GL_INT;
472     else if (strcmp(str,"GL_UNSIGNED_BYTE")==0) value = GL_UNSIGNED_BYTE;
473     else if (strcmp(str,"GL_UNSIGNED_SHORT")==0) value = GL_UNSIGNED_SHORT;
474     else if (strcmp(str,"GL_UNSIGNED_INT")==0) value = GL_UNSIGNED_INT;
475     else if (strcmp(str,"GL_FLOAT")==0) value = GL_FLOAT;
476     else
477     {
478         osgDB::Field::FieldType type = osgDB::Field::calculateFieldType(str);
479         if (type==osgDB::Field::INTEGER)
480         {
481             value = atoi(str);
482             return true;
483         }
484         else
485         {
486             return false;
487         }
488     }
489 
490     return true;
491 }
492 
Texture_getSourceTypeStr(int value)493 const char* Texture_getSourceTypeStr(int value)
494 {
495     switch(value)
496     {
497         case(GL_BYTE): return "GL_BYTE";
498         case(GL_SHORT): return "GL_SHORT";
499         case(GL_INT): return "GL_INT";
500         case(GL_FLOAT): return "GL_FLOAT";
501         case(GL_UNSIGNED_BYTE): return "GL_UNSIGNED_BYTE";
502         case(GL_UNSIGNED_SHORT): return "GL_UNSIGNED_SHORT";
503         case(GL_UNSIGNED_INT): return "GL_UNSIGNED_INT";
504     }
505     return NULL;
506 }
507 
Texture_matchShadowCompareFuncStr(const char * str,Texture::ShadowCompareFunc & value)508 bool Texture_matchShadowCompareFuncStr(const char* str, Texture::ShadowCompareFunc& value)
509 {
510     if (     strcmp(str,"GL_NEVER")==0) value = Texture::NEVER;
511     else if (strcmp(str,"GL_LESS")==0) value = Texture::LESS;
512     else if (strcmp(str,"GL_EQUAL")==0) value = Texture::EQUAL;
513     else if (strcmp(str,"GL_LEQUAL")==0) value = Texture::LEQUAL;
514     else if (strcmp(str,"GL_GREATER")==0) value = Texture::GREATER;
515     else if (strcmp(str,"GL_NOTEQUAL")==0) value = Texture::NOTEQUAL;
516     else if (strcmp(str,"GL_GEQUAL")==0) value = Texture::GEQUAL;
517     else if (strcmp(str,"GL_ALWAYS")==0) value = Texture::ALWAYS;
518     else return false;
519 
520     return true;
521 }
522 
Texture_getShadowCompareFuncStr(Texture::ShadowCompareFunc value)523 const char* Texture_getShadowCompareFuncStr(Texture::ShadowCompareFunc value)
524 {
525     switch(value)
526     {
527         case(Texture::NEVER): return "GL_NEVER";
528         case(Texture::LESS): return "GL_LESS";
529         case(Texture::EQUAL): return "GL_EQUAL";
530         case(Texture::LEQUAL): return "GL_LEQUAL";
531         case(Texture::GREATER): return "GL_GREATER";
532         case(Texture::NOTEQUAL): return "GL_NOTEQUAL";
533         case(Texture::GEQUAL): return "GL_GEQUAL";
534         case(Texture::ALWAYS): return "GL_ALWAYS";
535     }
536     return NULL;
537 }
538 
Texture_matchShadowTextureModeStr(const char * str,Texture::ShadowTextureMode & value)539 bool Texture_matchShadowTextureModeStr(const char* str,Texture::ShadowTextureMode& value)
540 {
541     if (     strcmp(str,"GL_LUMINANCE")==0) value = Texture::LUMINANCE;
542     else if (strcmp(str,"GL_INTENSITY")==0) value = Texture::INTENSITY;
543     else if (strcmp(str,"GL_ALPHA")==0) value = Texture::ALPHA;
544     else if (strcmp(str,"GL_NONE")==0) value = Texture::NONE;
545     else return false;
546 
547     return true;
548 }
549 
Texture_getShadowTextureModeStr(Texture::ShadowTextureMode value)550 const char* Texture_getShadowTextureModeStr(Texture::ShadowTextureMode value)
551 {
552     switch(value)
553     {
554         case( Texture::LUMINANCE ): return "GL_LUMINANCE";
555         case( Texture::INTENSITY ): return "GL_INTENSITY";
556         case( Texture::ALPHA ): return "GL_ALPHA";
557         case( Texture::NONE ): return "GL_NONE";
558     }
559     return NULL;
560 }
561