001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wpvs/configuration/RenderingConfiguration.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/exse/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstrasse 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Jens Fitzke
035 lat/lon GmbH
036 Aennchenstrasse 19
037 53177 Bonn
038 Germany
039 E-Mail: jens.fitzke@uni-bonn.de
040
041 ---------------------------------------------------------------------------*/
042
043 package org.deegree.ogcwebservices.wpvs.configuration;
044
045 import java.awt.image.BufferedImage;
046 import java.io.IOException;
047 import java.io.InputStream;
048 import java.util.Properties;
049
050 import javax.media.j3d.ColoringAttributes;
051 import javax.media.j3d.PolygonAttributes;
052 import javax.media.j3d.Texture;
053 import javax.media.j3d.TextureAttributes;
054 import javax.media.j3d.Transform3D;
055 import javax.vecmath.Color4f;
056
057 import org.deegree.framework.log.ILogger;
058 import org.deegree.framework.log.LoggerFactory;
059 import org.deegree.i18n.Messages;
060
061 import com.sun.j3d.utils.image.TextureLoader;
062
063 /**
064 * The <code>RenderingConfiguration</code> class is a simple wrapper to retrieve the configuration
065 * of the rendering options.
066 *
067 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
068 *
069 * @author last edited by: $Author: bezema $
070 *
071 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
072 *
073 */
074
075 public final class RenderingConfiguration {
076 private static ILogger LOG = LoggerFactory.getLogger( RenderingConfiguration.class );
077
078 private static RenderingConfiguration renderConfig;
079
080 private final TextureAttributes textureAttributes;
081
082 private final ColoringAttributes coloringAttributes;
083
084 private final PolygonAttributes terrainPolygonAttributes;
085
086 private final PolygonAttributes surfacePolygonAttributes;
087
088 /**
089 * The renderingOptions defined in a file called rendering_options.properties
090 */
091 private final Properties renderingOptions;
092
093 private final String propertieFile = "rendering_options.properties";
094
095 private RenderingConfiguration() {
096 // Singleton pattern
097 renderingOptions = new Properties();
098 try {
099 InputStream renderingProps = RenderingConfiguration.class.getResourceAsStream( "/"
100 + propertieFile );
101 if ( renderingProps == null ) {
102 renderingProps = RenderingConfiguration.class.getResourceAsStream( propertieFile );
103 }
104 renderingOptions.load( renderingProps );
105 } catch ( IOException e ) {
106 LOG.logError( e.getMessage(), e );
107 }
108
109 this.textureAttributes = createTextureAttributes();
110 this.coloringAttributes = createColoringAttributes();
111 this.terrainPolygonAttributes = createTerrainPolygonAttributes();
112 this.surfacePolygonAttributes = createSurfacePolygonAttributes();
113 }
114
115 /**
116 * @return the configured PolygonAttributes for surfaces
117 */
118 private PolygonAttributes createSurfacePolygonAttributes() {
119 PolygonAttributes targetPolyAttr = new PolygonAttributes();
120 targetPolyAttr.setCapability( PolygonAttributes.ALLOW_MODE_READ );
121 targetPolyAttr.setCapability( PolygonAttributes.ALLOW_CULL_FACE_READ );
122 targetPolyAttr.setCapability( PolygonAttributes.ALLOW_NORMAL_FLIP_READ );
123 targetPolyAttr.setPolygonMode( PolygonAttributes.POLYGON_FILL );
124
125 // finding a configured backface flip property
126 String configuredProperty = (String) renderingOptions.get( "surface_backflip" );
127 if ( configuredProperty != null ) {
128 configuredProperty = configuredProperty.trim();
129 if ( "TRUE".equalsIgnoreCase( configuredProperty )
130 || "1".equalsIgnoreCase( configuredProperty )
131 || "yes".equalsIgnoreCase( configuredProperty ) ) {
132 targetPolyAttr.setBackFaceNormalFlip( true );
133 } else if ( "false".equalsIgnoreCase( configuredProperty )
134 || "0".equalsIgnoreCase( configuredProperty )
135 || "no".equalsIgnoreCase( configuredProperty ) ) {
136 targetPolyAttr.setBackFaceNormalFlip( false );
137 } else {
138 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
139 "surface_backflip", configuredProperty,
140 "false" ) );
141 targetPolyAttr.setBackFaceNormalFlip( false );
142 }
143
144 }
145
146 int configuredValue = PolygonAttributes.CULL_NONE;
147 // finding a configured surface culling
148 configuredProperty = (String) renderingOptions.get( "surface_culling" );
149 if ( configuredProperty != null ) {
150 configuredProperty = configuredProperty.trim();
151 if ( "BACK".equalsIgnoreCase( configuredProperty ) ) {
152 configuredValue = PolygonAttributes.CULL_BACK;
153 } else if ( "FRONT".equalsIgnoreCase( configuredProperty ) ) {
154 configuredValue = PolygonAttributes.CULL_FRONT;
155 } else if ( "NONE".equalsIgnoreCase( configuredProperty ) ) {
156 configuredValue = PolygonAttributes.CULL_NONE;
157 } else {
158 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
159 "surface_culling", configuredProperty, "NONE" ) );
160 }
161 }
162 targetPolyAttr.setCullFace( configuredValue );
163 return targetPolyAttr;
164
165 }
166
167 /**
168 * @return the configured Polygon Attributes for the dgm (terrain)
169 */
170 private PolygonAttributes createTerrainPolygonAttributes() {
171 // what kind of drawing
172 PolygonAttributes targetPolyAttr = new PolygonAttributes();
173 targetPolyAttr.setPolygonMode( PolygonAttributes.POLYGON_FILL );
174
175 // finding a configured backface flip property
176 String configuredProperty = (String) renderingOptions.get( "terrain_backflip" );
177 if ( configuredProperty != null ) {
178 configuredProperty = configuredProperty.trim();
179 if ( "true".equalsIgnoreCase( configuredProperty )
180 || "1".equalsIgnoreCase( configuredProperty )
181 || "yes".equalsIgnoreCase( configuredProperty ) ) {
182 targetPolyAttr.setBackFaceNormalFlip( true );
183 } else if ( "false".equalsIgnoreCase( configuredProperty )
184 || "0".equalsIgnoreCase( configuredProperty )
185 || "no".equalsIgnoreCase( configuredProperty ) ) {
186 targetPolyAttr.setBackFaceNormalFlip( false );
187 } else {
188 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
189 "terrain_backflip", configuredProperty,
190 "false" ) );
191
192 }
193 }
194
195 int configuredValue = PolygonAttributes.CULL_NONE;
196 // finding a configured surface culling
197 configuredProperty = (String) renderingOptions.get( "terrain_culling" );
198 if ( configuredProperty != null ) {
199 configuredProperty = configuredProperty.trim();
200 if ( "BACK".equalsIgnoreCase( configuredProperty ) ) {
201 configuredValue = PolygonAttributes.CULL_BACK;
202 } else if ( "FRONT".equalsIgnoreCase( configuredProperty ) ) {
203 configuredValue = PolygonAttributes.CULL_FRONT;
204 } else if ( "NONE".equalsIgnoreCase( configuredProperty ) ) {
205 configuredValue = PolygonAttributes.CULL_NONE;
206 } else {
207 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
208 "terrain_culling", configuredProperty, "NONE" ) );
209 }
210 }
211 targetPolyAttr.setCullFace( configuredValue );
212 return targetPolyAttr;
213 }
214
215 /**
216 * @return the conifured coloring attributes
217 */
218 private ColoringAttributes createColoringAttributes() {
219 // and some Coloring attribs
220 // the coloring attributes
221 ColoringAttributes ca = new ColoringAttributes();
222 int configuredValue = ColoringAttributes.SHADE_GOURAUD;
223 // finding a configured shading model
224 String configuredProperty = (String) renderingOptions.get( "shading_model" );
225 if ( configuredProperty != null ) {
226 configuredProperty = configuredProperty.trim();
227 if ( "SHADE_FLAT".equalsIgnoreCase( configuredProperty ) ) {
228 configuredValue = ColoringAttributes.SHADE_FLAT;
229 } else if ( "SHADE_GOURAUD".equalsIgnoreCase( configuredProperty ) ) {
230 configuredValue = ColoringAttributes.SHADE_GOURAUD;
231 } else {
232 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
233 "shading_model", configuredProperty,
234 "SHADE_GOURAUD" ) );
235
236 }
237
238 }
239 ca.setShadeModel( configuredValue );
240
241 configuredValue = ColoringAttributes.NICEST;
242 // finding a configured shading model quality
243 configuredProperty = (String) renderingOptions.get( "shading_quality" );
244 if ( configuredProperty != null ) {
245 configuredProperty = configuredProperty.trim();
246 if ( "FASTEST".equalsIgnoreCase( configuredProperty ) ) {
247 configuredValue = ColoringAttributes.FASTEST;
248 } else if ( "NICEST".equalsIgnoreCase( configuredProperty ) ) {
249 configuredValue = ColoringAttributes.NICEST;
250 } else {
251 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
252 "shading_quality", configuredProperty,
253 "NICEST" ) );
254 }
255 }
256 ca.setCapability( configuredValue );
257 return ca;
258 }
259
260 /**
261 * @return the configured textureAttributes
262 */
263 private TextureAttributes createTextureAttributes() {
264 int blendFunc = TextureAttributes.MODULATE;
265 // finding a configured blending function
266 String configuredProperty = (String) renderingOptions.get( "blend_function" );
267 if ( configuredProperty != null ) {
268 configuredProperty = configuredProperty.trim();
269 if ( "BLEND".equalsIgnoreCase( configuredProperty ) ) {
270 blendFunc = TextureAttributes.BLEND;
271 } else if ( "DECAL".equalsIgnoreCase( configuredProperty ) ) {
272 blendFunc = TextureAttributes.DECAL;
273 } else if ( "COMBINE".equalsIgnoreCase( configuredProperty ) ) {
274 blendFunc = TextureAttributes.COMBINE;
275 } else if ( "MODULATE".equalsIgnoreCase( configuredProperty ) ) {
276 blendFunc = TextureAttributes.MODULATE;
277 } else {
278 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
279 "blend_function", configuredProperty,
280 "MODULATE" ) );
281 }
282 }
283 Color4f blendColor = new Color4f( 0, 0, 0, 0 );
284 if ( blendFunc == TextureAttributes.BLEND ) {
285 configuredProperty = (String) renderingOptions.get( "blend_color" );
286 if ( configuredProperty != null ) {
287 String[] split = configuredProperty.trim().split( "," );
288 if ( split != null && split.length == 4 ) {
289 try {
290 float r = Float.parseFloat( split[0] );
291 float g = Float.parseFloat( split[1] );
292 float b = Float.parseFloat( split[2] );
293 float a = Float.parseFloat( split[3] );
294 blendColor = new Color4f( r, g, b, a );
295 } catch ( NumberFormatException nfe ) {
296 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
297 "blend_color", configuredProperty,
298 "0,0,0,0" ) );
299 }
300 } else {
301 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
302 "blend_color", configuredProperty,
303 "0,0,0,0" ) );
304 }
305 }
306 }
307
308 int persCorrection = TextureAttributes.NICEST;
309 configuredProperty = (String) renderingOptions.get( "terrain_texture_perspective_correction" );
310 if ( configuredProperty != null ) {
311 configuredProperty = configuredProperty.trim();
312 if ( "FASTEST".equalsIgnoreCase( configuredProperty ) ) {
313 persCorrection = TextureAttributes.FASTEST;
314 } else if ( "NICEST".equalsIgnoreCase( configuredProperty ) ) {
315 persCorrection = TextureAttributes.NICEST;
316 } else {
317 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
318 "terrain_texture_perspective_correction",
319 configuredProperty, "NICEST" ) );
320 }
321 }
322
323 TextureAttributes textureAttribs = new TextureAttributes( blendFunc, new Transform3D(),
324 blendColor, persCorrection );
325
326 if ( TextureAttributes.COMBINE == blendFunc ) {
327 /*
328 * Get the configured Combine parametersof the texture attributes. first rgb then alpha
329 */
330 // combineFunction type
331 int combineFunctionRGB = TextureAttributes.COMBINE_MODULATE;
332 configuredProperty = (String) renderingOptions.get( "combine_function_rgb" );
333 if ( configuredProperty != null ) {
334 configuredProperty = configuredProperty.trim();
335 if ( "COMBINE_REPLACE".equalsIgnoreCase( configuredProperty ) ) {
336 combineFunctionRGB = TextureAttributes.COMBINE_REPLACE;
337 } else if ( "COMBINE_ADD".equalsIgnoreCase( configuredProperty ) ) {
338 combineFunctionRGB = TextureAttributes.COMBINE_ADD;
339 } else if ( "COMBINE_ADD_SIGNED".equalsIgnoreCase( configuredProperty ) ) {
340 combineFunctionRGB = TextureAttributes.COMBINE_ADD_SIGNED;
341 } else if ( "COMBINE_SUBTRACT".equalsIgnoreCase( configuredProperty ) ) {
342 combineFunctionRGB = TextureAttributes.COMBINE_SUBTRACT;
343 } else if ( "COMBINE_INTERPOLATE".equalsIgnoreCase( configuredProperty ) ) {
344 combineFunctionRGB = TextureAttributes.COMBINE_INTERPOLATE;
345 } else if ( "COMBINE_DOT3".equalsIgnoreCase( configuredProperty ) ) {
346 combineFunctionRGB = TextureAttributes.COMBINE_DOT3;
347 } else if ( "COMBINE_MODULATE".equalsIgnoreCase( configuredProperty ) ) {
348 combineFunctionRGB = TextureAttributes.COMBINE_MODULATE;
349 } else {
350 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
351 "combine_function_rbg",
352 configuredProperty, "COMBINE_MODULATE" ) );
353 }
354 }
355 textureAttribs.setCombineRgbMode( combineFunctionRGB );
356
357 int combineFunctionAlpha = TextureAttributes.COMBINE_MODULATE;
358 configuredProperty = (String) renderingOptions.get( "combine_function_alpha" );
359 if ( configuredProperty != null ) {
360 configuredProperty = configuredProperty.trim();
361 if ( "COMBINE_REPLACE".equalsIgnoreCase( configuredProperty ) ) {
362 combineFunctionAlpha = TextureAttributes.COMBINE_REPLACE;
363 } else if ( "COMBINE_ADD".equalsIgnoreCase( configuredProperty ) ) {
364 combineFunctionAlpha = TextureAttributes.COMBINE_ADD;
365 } else if ( "COMBINE_ADD_SIGNED".equalsIgnoreCase( configuredProperty ) ) {
366 combineFunctionAlpha = TextureAttributes.COMBINE_ADD_SIGNED;
367 } else if ( "COMBINE_SUBTRACT".equalsIgnoreCase( configuredProperty ) ) {
368 combineFunctionAlpha = TextureAttributes.COMBINE_SUBTRACT;
369 } else if ( "COMBINE_INTERPOLATE".equalsIgnoreCase( configuredProperty ) ) {
370 combineFunctionAlpha = TextureAttributes.COMBINE_INTERPOLATE;
371 } else if ( "COMBINE_DOT3".equalsIgnoreCase( configuredProperty ) ) {
372 combineFunctionAlpha = TextureAttributes.COMBINE_DOT3;
373 } else if ( "COMBINE_MODULATE".equalsIgnoreCase( configuredProperty ) ) {
374 combineFunctionAlpha = TextureAttributes.COMBINE_MODULATE;
375 } else {
376 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
377 "combine_function_alpha",
378 configuredProperty, "COMBINE_MODULATE" ) );
379 }
380 }
381 textureAttribs.setCombineAlphaMode( combineFunctionAlpha );
382
383 // Combine source Color configuration
384 int combineColorSourceRGB = TextureAttributes.COMBINE_TEXTURE_COLOR;
385 for ( int i = 0; ++i < 3; ) {
386 if ( i == 1 ) {
387 combineColorSourceRGB = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;
388 } else if ( i == 2 ) {
389 combineColorSourceRGB = TextureAttributes.COMBINE_CONSTANT_COLOR;
390 }
391 String propertyString = "combine_color_source_rgb_" + i;
392 configuredProperty = (String) renderingOptions.get( propertyString );
393 if ( configuredProperty != null ) {
394 configuredProperty = configuredProperty.trim();
395 if ( "COMBINE_TEXTURE_COLOR".equalsIgnoreCase( configuredProperty ) ) {
396 combineColorSourceRGB = TextureAttributes.COMBINE_TEXTURE_COLOR;
397 } else if ( "COMBINE_CONSTANT_COLOR".equalsIgnoreCase( configuredProperty ) ) {
398 combineColorSourceRGB = TextureAttributes.COMBINE_CONSTANT_COLOR;
399 } else if ( "COMBINE_PREVIOUS_TEXTURE_UNIT_STATE".equalsIgnoreCase( configuredProperty ) ) {
400 combineColorSourceRGB = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;
401 } else if ( "COMBINE_OBJECT_COLOR".equalsIgnoreCase( configuredProperty ) ) {
402 combineColorSourceRGB = TextureAttributes.COMBINE_OBJECT_COLOR;
403 } else {
404 LOG.logWarning( Messages.getMessage(
405 "WPVS_UNKNOWN_RENDERING_PROPERTY",
406 propertyString,
407 configuredProperty,
408 ( ( i == 0 ) ? "COMBINE_MODULATE"
409 : ( ( i == 1 ) ? "COMBINE_PREVIOUS_TEXTURE_UNIT_STATE"
410 : "COMBINE_CONSTANT_COLOR" ) ) ) );
411 }
412
413 }
414 textureAttribs.setCombineRgbSource( i, combineColorSourceRGB );
415 }
416
417 int combineColorSourceAlpha = TextureAttributes.COMBINE_TEXTURE_COLOR;
418 for ( int i = 0; ++i < 3; ) {
419 if ( i == 1 ) {
420 combineColorSourceAlpha = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;
421 } else if ( i == 2 ) {
422 combineColorSourceAlpha = TextureAttributes.COMBINE_CONSTANT_COLOR;
423 }
424
425 String propertyString = "combine_color_source_alpha_" + i;
426 configuredProperty = (String) renderingOptions.get( propertyString );
427 if ( configuredProperty != null ) {
428 configuredProperty = configuredProperty.trim();
429 if ( "COMBINE_TEXTURE_COLOR".equalsIgnoreCase( configuredProperty ) ) {
430 combineColorSourceAlpha = TextureAttributes.COMBINE_TEXTURE_COLOR;
431 } else if ( "COMBINE_CONSTANT_COLOR".equalsIgnoreCase( configuredProperty ) ) {
432 combineColorSourceAlpha = TextureAttributes.COMBINE_CONSTANT_COLOR;
433 } else if ( "COMBINE_PREVIOUS_TEXTURE_UNIT_STATE".equalsIgnoreCase( configuredProperty ) ) {
434 combineColorSourceAlpha = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;
435 } else if ( "COMBINE_OBJECT_COLOR".equalsIgnoreCase( configuredProperty ) ) {
436 combineColorSourceAlpha = TextureAttributes.COMBINE_OBJECT_COLOR;
437 } else {
438 LOG.logWarning( Messages.getMessage(
439 "WPVS_UNKNOWN_RENDERING_PROPERTY",
440 propertyString,
441 configuredProperty,
442 ( ( i == 0 ) ? "COMBINE_MODULATE"
443 : ( ( i == 1 ) ? "COMBINE_PREVIOUS_TEXTURE_UNIT_STATE"
444 : "COMBINE_CONSTANT_COLOR" ) ) ) );
445 }
446 }
447 textureAttribs.setCombineAlphaSource( i, combineColorSourceAlpha );
448 }
449
450 // Combine color function to use
451 int combineColorFunctionRGB = TextureAttributes.COMBINE_SRC_COLOR;
452 configuredProperty = (String) renderingOptions.get( "combine_color_function_rgb" );
453 if ( configuredProperty != null ) {
454 configuredProperty = configuredProperty.trim();
455 if ( "COMBINE_ONE_MINUS_SRC_COLOR".equalsIgnoreCase( configuredProperty ) ) {
456 combineColorFunctionRGB = TextureAttributes.COMBINE_ONE_MINUS_SRC_COLOR;
457 } else if ( "COMBINE_SRC_COLOR".equalsIgnoreCase( configuredProperty ) ) {
458 combineColorFunctionRGB = TextureAttributes.COMBINE_SRC_COLOR;
459 } else {
460 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
461 "combine_color_function_rgb",
462 configuredProperty, "COMBINE_SRC_COLOR" ) );
463 }
464
465 }
466 textureAttribs.setCombineRgbFunction( 0, combineColorFunctionRGB );
467 textureAttribs.setCombineRgbFunction( 1, combineColorFunctionRGB );
468 textureAttribs.setCombineRgbFunction( 2, combineColorFunctionRGB );
469
470 int combineColorFunctionAlpha = TextureAttributes.COMBINE_SRC_ALPHA;
471 configuredProperty = (String) renderingOptions.get( "combine_color_function_alpha" );
472 if ( configuredProperty != null ) {
473 configuredProperty = configuredProperty.trim();
474 if ( "COMBINE_ONE_MINUS_SRC_ALPHA".equalsIgnoreCase( configuredProperty ) ) {
475 combineColorFunctionAlpha = TextureAttributes.COMBINE_ONE_MINUS_SRC_ALPHA;
476 } else if ( "COMBINE_SRC_ALPHA".equalsIgnoreCase( configuredProperty ) ) {
477 combineColorFunctionAlpha = TextureAttributes.COMBINE_SRC_ALPHA;
478 } else {
479 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
480 "combine_color_function_alpha",
481 configuredProperty, "COMBINE_SRC_ALPHA" ) );
482 }
483 }
484 textureAttribs.setCombineAlphaFunction( 0, combineColorFunctionAlpha );
485 textureAttribs.setCombineAlphaFunction( 1, combineColorFunctionAlpha );
486 textureAttribs.setCombineAlphaFunction( 2, combineColorFunctionAlpha );
487
488 // And the scale of the output color
489 int combineScaleFactorRGB = 1;
490 configuredProperty = (String) renderingOptions.get( "combine_scale_factor_rgb" );
491 if ( configuredProperty != null ) {
492 configuredProperty = configuredProperty.trim();
493 try {
494 combineScaleFactorRGB = Integer.parseInt( configuredProperty );
495 } catch ( NumberFormatException nfe ) {
496 combineScaleFactorRGB = 1;
497 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
498 "combine_scale_factor_rgb",
499 configuredProperty, "1" ) );
500 }
501 if ( combineScaleFactorRGB != 1 && combineScaleFactorRGB != 2
502 && combineScaleFactorRGB != 4 ) {
503 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
504 "combine_scale_factor_rgb",
505 configuredProperty, "1" ) );
506 combineScaleFactorRGB = 1;
507
508 }
509 }
510 textureAttribs.setCombineRgbScale( combineScaleFactorRGB );
511
512 int combineScaleFactorAlpha = 1;
513 configuredProperty = (String) renderingOptions.get( "combine_scale_factor_alpha" );
514 if ( configuredProperty != null ) {
515 configuredProperty = configuredProperty.trim();
516 try {
517 combineScaleFactorAlpha = Integer.parseInt( configuredProperty );
518 } catch ( NumberFormatException nfe ) {
519 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
520 "combine_scale_factor_alpha",
521 configuredProperty, "1" ) );
522
523 combineScaleFactorAlpha = 1;
524 }
525 if ( combineScaleFactorAlpha != 1 && combineScaleFactorAlpha != 2
526 && combineScaleFactorAlpha != 4 ) {
527 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
528 "combine_scale_factor_alpha",
529 configuredProperty, "1" ) );
530 combineScaleFactorAlpha = 1;
531 }
532 }
533 textureAttribs.setCombineAlphaScale( combineScaleFactorAlpha );
534 }
535 return textureAttribs;
536 }
537
538 /**
539 * @return gets a RenderingConfiguration as a singleton pattern.
540 */
541 public static synchronized RenderingConfiguration getInstance() {
542 if ( renderConfig == null ) {
543 renderConfig = new RenderingConfiguration();
544 }
545 return renderConfig;
546 }
547
548 /**
549 * @return the coloringAttributes, Configured rendering properties valid for all rendered
550 * primitives.
551 */
552 public final ColoringAttributes getColoringAttributes() {
553 return coloringAttributes;
554 }
555
556 /**
557 * @return the TextureAttributes, Configured rendering properties valid for all rendered
558 * textured primitives.
559 */
560 public final TextureAttributes getTextureAttributes() {
561 return textureAttributes;
562 }
563
564 /**
565 * @return the surfacePolygonAttributes, Configured rendering properties for the rendered
566 * surfaces.
567 */
568 public final PolygonAttributes getSurfacePolygonAttributes() {
569 return surfacePolygonAttributes;
570 }
571
572 /**
573 * @return the terrainPolygonAttributes, Configured rendering properties for the rendered
574 * terrain.
575 */
576 public final PolygonAttributes getTerrainPolygonAttributes() {
577 return terrainPolygonAttributes;
578 }
579
580 /**
581 * @param textureImage
582 * the image to load as a texture
583 * @return a Texture with loaded according the configured mipmap properties.
584 */
585 public final Texture getTexture( BufferedImage textureImage ) {
586 TextureLoader tl = null;
587 boolean isMipMapped = true;
588 String configuredProperty = (String) renderingOptions.get( "terrain_texture_mipmapping" );
589 if ( configuredProperty != null ) {
590 configuredProperty = configuredProperty.trim();
591 if ( "TRUE".equalsIgnoreCase( configuredProperty )
592 || "1".equalsIgnoreCase( configuredProperty )
593 || "yes".equalsIgnoreCase( configuredProperty ) ) {
594 tl = new TextureLoader( textureImage, TextureLoader.GENERATE_MIPMAP );
595 } else if ( "false".equalsIgnoreCase( configuredProperty )
596 || "0".equalsIgnoreCase( configuredProperty )
597 || "no".equalsIgnoreCase( configuredProperty ) ) {
598 tl = new TextureLoader( textureImage );
599 } else {
600 LOG.logWarning( Messages.getMessage( "WPVS_UNKNOWN_RENDERING_PROPERTY",
601 "terrain_texture_mipmapping",
602 configuredProperty, "false" ) );
603 tl = new TextureLoader( textureImage );
604 }
605 } else {
606 tl = new TextureLoader( textureImage, TextureLoader.GENERATE_MIPMAP );
607 }
608 Texture texture = tl.getTexture();
609 texture.setEnable( true );
610 // texture.setAnisotropicFilterMode( Texture.ANISOTROPIC_SINGLE_VALUE );
611 texture.setCapability( Texture.ALLOW_ENABLE_READ
612 | ( ( isMipMapped ) ? Texture.ALLOW_MIPMAP_MODE_READ : 0 )
613 | Texture.NICEST | Texture.CLAMP_TO_EDGE );
614 return texture;
615 }
616
617 }
618
619 /***************************************************************************************************
620 * Changes to this class. What the people have been up to: <code>
621 * $Log$
622 * Revision 1.1 2006/12/20 14:31:19 bezema
623 * Added a configuration for Rendering options
624 *
625 * </code>
626 **************************************************************************************************/
627