1 /* 2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * - Redistribution of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * - Redistribution in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * Neither the name of Sun Microsystems, Inc. or the names of 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * This software is provided "AS IS," without a warranty of any kind. ALL 20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN 23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR 24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR 26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR 27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE 28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, 29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF 30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 31 * 32 * You acknowledge that this software is not designed or intended for use 33 * in the design, construction, operation or maintenance of any nuclear 34 * facility. 35 * 36 * Sun gratefully acknowledges that this software was originally authored 37 * and developed by Kenneth Bradley Russell and Christopher John Kline. 38 */ 39 40 package javax.media.opengl; 41 42 /** Specifies a set of OpenGL capabilities that a rendering context 43 must support, such as color depth and whether stereo is enabled. 44 It currently contains the minimal number of routines which allow 45 configuration on all supported window systems. */ 46 47 public class GLCapabilities implements Cloneable { 48 private boolean doubleBuffered = true; 49 private boolean stereo = false; 50 private boolean hardwareAccelerated = true; 51 private int depthBits = 24; 52 private int stencilBits = 0; 53 private int redBits = 8; 54 private int greenBits = 8; 55 private int blueBits = 8; 56 private int alphaBits = 0; 57 private int accumRedBits = 0; 58 private int accumGreenBits = 0; 59 private int accumBlueBits = 0; 60 private int accumAlphaBits = 0; 61 // Shift bits from PIXELFORMATDESCRIPTOR not present because they 62 // are unlikely to be supported on Windows anyway 63 64 // Support for full-scene antialiasing (FSAA) 65 private boolean sampleBuffers = false; 66 private int numSamples = 2; 67 68 // Bits for pbuffer creation 69 private boolean pbufferFloatingPointBuffers; 70 private boolean pbufferRenderToTexture; 71 private boolean pbufferRenderToTextureRectangle; 72 73 /** Creates a GLCapabilities object. All attributes are in a default 74 state. 75 */ GLCapabilities()76 public GLCapabilities() {} 77 clone()78 public Object clone() { 79 try { 80 return super.clone(); 81 } catch (CloneNotSupportedException e) { 82 throw new GLException(e); 83 } 84 } 85 86 /** Indicates whether double-buffering is enabled. */ getDoubleBuffered()87 public boolean getDoubleBuffered() { 88 return doubleBuffered; 89 } 90 91 /** Enables or disables double buffering. */ setDoubleBuffered(boolean onOrOff)92 public void setDoubleBuffered(boolean onOrOff) { 93 doubleBuffered = onOrOff; 94 } 95 96 /** Indicates whether stereo is enabled. */ getStereo()97 public boolean getStereo() { 98 return stereo; 99 } 100 101 /** Enables or disables stereo viewing. */ setStereo(boolean onOrOff)102 public void setStereo(boolean onOrOff) { 103 stereo = onOrOff; 104 } 105 106 /** Indicates whether hardware acceleration is enabled. */ getHardwareAccelerated()107 public boolean getHardwareAccelerated() { 108 return hardwareAccelerated; 109 } 110 111 /** Enables or disables hardware acceleration. */ setHardwareAccelerated(boolean onOrOff)112 public void setHardwareAccelerated(boolean onOrOff) { 113 hardwareAccelerated = onOrOff; 114 } 115 116 /** Returns the number of bits requested for the depth buffer. */ getDepthBits()117 public int getDepthBits() { 118 return depthBits; 119 } 120 121 /** Sets the number of bits requested for the depth buffer. */ setDepthBits(int depthBits)122 public void setDepthBits(int depthBits) { 123 this.depthBits = depthBits; 124 } 125 126 /** Returns the number of bits requested for the stencil buffer. */ getStencilBits()127 public int getStencilBits() { 128 return stencilBits; 129 } 130 131 /** Sets the number of bits requested for the stencil buffer. */ setStencilBits(int stencilBits)132 public void setStencilBits(int stencilBits) { 133 this.stencilBits = stencilBits; 134 } 135 136 /** Returns the number of bits requested for the color buffer's red 137 component. On some systems only the color depth, which is the 138 sum of the red, green, and blue bits, is considered. */ getRedBits()139 public int getRedBits() { 140 return redBits; 141 } 142 143 /** Sets the number of bits requested for the color buffer's red 144 component. On some systems only the color depth, which is the 145 sum of the red, green, and blue bits, is considered. */ setRedBits(int redBits)146 public void setRedBits(int redBits) { 147 this.redBits = redBits; 148 } 149 150 /** Returns the number of bits requested for the color buffer's 151 green component. On some systems only the color depth, which is 152 the sum of the red, green, and blue bits, is considered. */ getGreenBits()153 public int getGreenBits() { 154 return greenBits; 155 } 156 157 /** Sets the number of bits requested for the color buffer's green 158 component. On some systems only the color depth, which is the 159 sum of the red, green, and blue bits, is considered. */ setGreenBits(int greenBits)160 public void setGreenBits(int greenBits) { 161 this.greenBits = greenBits; 162 } 163 164 /** Returns the number of bits requested for the color buffer's blue 165 component. On some systems only the color depth, which is the 166 sum of the red, green, and blue bits, is considered. */ getBlueBits()167 public int getBlueBits() { 168 return blueBits; 169 } 170 171 /** Sets the number of bits requested for the color buffer's blue 172 component. On some systems only the color depth, which is the 173 sum of the red, green, and blue bits, is considered. */ setBlueBits(int blueBits)174 public void setBlueBits(int blueBits) { 175 this.blueBits = blueBits; 176 } 177 178 /** Returns the number of bits requested for the color buffer's 179 alpha component. On some systems only the color depth, which is 180 the sum of the red, green, and blue bits, is considered. */ getAlphaBits()181 public int getAlphaBits() { 182 return alphaBits; 183 } 184 185 /** Sets the number of bits requested for the color buffer's alpha 186 component. On some systems only the color depth, which is the 187 sum of the red, green, and blue bits, is considered. */ setAlphaBits(int alphaBits)188 public void setAlphaBits(int alphaBits) { 189 this.alphaBits = alphaBits; 190 } 191 192 /** Returns the number of bits requested for the accumulation 193 buffer's red component. On some systems only the accumulation 194 buffer depth, which is the sum of the red, green, and blue bits, 195 is considered. */ getAccumRedBits()196 public int getAccumRedBits() { 197 return accumRedBits; 198 } 199 200 /** Sets the number of bits requested for the accumulation buffer's 201 red component. On some systems only the accumulation buffer 202 depth, which is the sum of the red, green, and blue bits, is 203 considered. */ setAccumRedBits(int accumRedBits)204 public void setAccumRedBits(int accumRedBits) { 205 this.accumRedBits = accumRedBits; 206 } 207 208 /** Returns the number of bits requested for the accumulation 209 buffer's green component. On some systems only the accumulation 210 buffer depth, which is the sum of the red, green, and blue bits, 211 is considered. */ getAccumGreenBits()212 public int getAccumGreenBits() { 213 return accumGreenBits; 214 } 215 216 /** Sets the number of bits requested for the accumulation buffer's 217 green component. On some systems only the accumulation buffer 218 depth, which is the sum of the red, green, and blue bits, is 219 considered. */ setAccumGreenBits(int accumGreenBits)220 public void setAccumGreenBits(int accumGreenBits) { 221 this.accumGreenBits = accumGreenBits; 222 } 223 224 /** Returns the number of bits requested for the accumulation 225 buffer's blue component. On some systems only the accumulation 226 buffer depth, which is the sum of the red, green, and blue bits, 227 is considered. */ getAccumBlueBits()228 public int getAccumBlueBits() { 229 return accumBlueBits; 230 } 231 232 /** Sets the number of bits requested for the accumulation buffer's 233 blue component. On some systems only the accumulation buffer 234 depth, which is the sum of the red, green, and blue bits, is 235 considered. */ setAccumBlueBits(int accumBlueBits)236 public void setAccumBlueBits(int accumBlueBits) { 237 this.accumBlueBits = accumBlueBits; 238 } 239 240 /** Returns the number of bits requested for the accumulation 241 buffer's alpha component. On some systems only the accumulation 242 buffer depth, which is the sum of the red, green, and blue bits, 243 is considered. */ getAccumAlphaBits()244 public int getAccumAlphaBits() { 245 return accumAlphaBits; 246 } 247 248 /** Sets number of bits requested for accumulation buffer's alpha 249 component. On some systems only the accumulation buffer depth, 250 which is the sum of the red, green, and blue bits, is 251 considered. */ setAccumAlphaBits(int accumAlphaBits)252 public void setAccumAlphaBits(int accumAlphaBits) { 253 this.accumAlphaBits = accumAlphaBits; 254 } 255 256 /** Indicates whether sample buffers for full-scene antialiasing 257 (FSAA) should be allocated for this drawable. Defaults to 258 false. */ setSampleBuffers(boolean onOrOff)259 public void setSampleBuffers(boolean onOrOff) { 260 sampleBuffers = onOrOff; 261 } 262 263 /** Returns whether sample buffers for full-scene antialiasing 264 (FSAA) should be allocated for this drawable. Defaults to 265 false. */ getSampleBuffers()266 public boolean getSampleBuffers() { 267 return sampleBuffers; 268 } 269 270 /** If sample buffers are enabled, indicates the number of buffers 271 to be allocated. Defaults to 2. */ setNumSamples(int numSamples)272 public void setNumSamples(int numSamples) { 273 this.numSamples = numSamples; 274 } 275 276 /** Returns the number of sample buffers to be allocated if sample 277 buffers are enabled. Defaults to 2. */ getNumSamples()278 public int getNumSamples() { 279 return numSamples; 280 } 281 282 /** For pbuffers only, indicates whether floating-point buffers 283 should be used if available. Defaults to false. */ setPbufferFloatingPointBuffers(boolean onOrOff)284 public void setPbufferFloatingPointBuffers(boolean onOrOff) { 285 pbufferFloatingPointBuffers = onOrOff; 286 } 287 288 /** For pbuffers only, returns whether floating-point buffers should 289 be used if available. Defaults to false. */ getPbufferFloatingPointBuffers()290 public boolean getPbufferFloatingPointBuffers() { 291 return pbufferFloatingPointBuffers; 292 } 293 294 /** For pbuffers only, indicates whether the render-to-texture 295 extension should be used if available. Defaults to false. */ setPbufferRenderToTexture(boolean onOrOff)296 public void setPbufferRenderToTexture(boolean onOrOff) { 297 pbufferRenderToTexture = onOrOff; 298 } 299 300 /** For pbuffers only, returns whether the render-to-texture 301 extension should be used if available. Defaults to false. */ getPbufferRenderToTexture()302 public boolean getPbufferRenderToTexture() { 303 return pbufferRenderToTexture; 304 } 305 306 /** For pbuffers only, indicates whether the 307 render-to-texture-rectangle extension should be used if 308 available. Defaults to false. */ setPbufferRenderToTextureRectangle(boolean onOrOff)309 public void setPbufferRenderToTextureRectangle(boolean onOrOff) { 310 pbufferRenderToTextureRectangle = onOrOff; 311 } 312 313 /** For pbuffers only, returns whether the render-to-texture 314 extension should be used. Defaults to false. */ getPbufferRenderToTextureRectangle()315 public boolean getPbufferRenderToTextureRectangle() { 316 return pbufferRenderToTextureRectangle; 317 } 318 319 /** Returns a textual representation of this GLCapabilities 320 object. */ toString()321 public String toString() { 322 return ("GLCapabilities [" + 323 "DoubleBuffered: " + doubleBuffered + 324 ", Stereo: " + stereo + 325 ", HardwareAccelerated: " + hardwareAccelerated + 326 ", DepthBits: " + depthBits + 327 ", StencilBits: " + stencilBits + 328 ", Red: " + redBits + 329 ", Green: " + greenBits + 330 ", Blue: " + blueBits + 331 ", Alpha: " + alphaBits + 332 ", Red Accum: " + accumRedBits + 333 ", Green Accum: " + accumGreenBits + 334 ", Blue Accum: " + accumBlueBits + 335 ", Alpha Accum: " + accumAlphaBits + 336 ", Multisample: " + sampleBuffers + 337 (sampleBuffers ? ", Num samples: " + numSamples : "") + 338 " ]"); 339 } 340 } 341