Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: gl4java/GLCapabilities.java


1   package gl4java;
2   
3   /** Specifies a set of OpenGL capabilities that a rendering context
4       must support, such as color depth and whether stereo is
5       enabled. It currently contains the minimal number of routines
6       which allow configuration on all supported window systems. */
7   
8   public class GLCapabilities 
9     implements Cloneable
10  {
11  
12    private static final int BUFFER_SINGLE = 0;
13    private static final int BUFFER_DOUBLE = 1;
14  
15    private static final int COLOR_INDEX = 0;
16    private static final int COLOR_RGBA  = 1;
17  
18    private static final int STEREO_OFF = 0;
19    private static final int STEREO_ON  = 1;
20  
21    private static final int FULLSCREEN_OFF = 0;
22    private static final int FULLSCREEN_ON  = 1;
23  
24    // Boolean attributes
25    // NOTE that we do not specify on- or off-screen visuals here --
26    // that will be taken care of by the factory.
27  
28    /* x11: exact value 
29       w32: exact value
30     */
31    private int buffer     = BUFFER_DOUBLE;
32  
33    /* x11: exact value 
34       w32: exact value
35     */
36    private int color      = COLOR_RGBA;
37  
38    /* x11: exact value 
39       w32: exact value
40     */
41    private int stereo    = STEREO_OFF;
42  
43    /* x11: exact value 
44       w32: exact value
45  
46       since JDK 1.4
47     */
48    private int fullscreen  = FULLSCREEN_OFF;
49  
50    /* x11: getting the largest regardless the value if >0, set to max
51       w32: getting the best from it's max
52     */
53    private int depthBits    = 24;
54  
55    /* x11: getting the best from it's max
56       w32: getting the best from it's max
57     */
58    private int stencilBits  = 0;
59  
60    /* x11: getting the largest regardless the value if >0, set to max
61  
62       w32: getting the best from it's max
63            cColorBits := redBits + greenBits + blueBits
64     */
65    private int redBits    = 8;
66    private int greenBits    = 8;
67    private int blueBits    = 8;
68    private int alphaBits    = 0;
69  
70    /* x11: getting the largest regardless the value if >0, set to max
71  
72       w32: getting the best from it's max
73            cAccumBits := accumRedBits + accumGreenBits + accumBlueBits +
74                    accumAlphaBits
75     */
76    private int accumRedBits  = 0;
77    private int accumGreenBits  = 0;
78    private int accumBlueBits  = 0;
79    private int accumAlphaBits  = 0;
80  
81    /**
82     * this is the holder for the native visualID,
83     * e.g. Win32's number of the PIXELFORMATDESC,
84     *      or X11's VisualID
85     */
86    private long nativeVisualID   = -1;
87  
88    // Shift bits from PIXELFORMATDESCRIPTOR not present because they
89    // are unlikely to be supported on Windows anyway
90  
91    /** Creates a GLCapabilities object. All attributes are in
92        a default state, they can be configured by the client.
93        The arguments are the usual user defined capabilities,
94        which can be set here for construction.
95      */
96    public GLCapabilities(boolean doubleBuffer, boolean stereoView, 
97                          boolean rgba, 
98        int stencilBits, 
99        int accumRedSize, int accumGreenSize, 
100       int accumBlueSize, int accumAlphaSize)
101   {
102   setDoubleBuffered(doubleBuffer);
103   setStereo(stereoView);
104   setTrueColor(rgba);
105   setStencilBits(stencilBits);
106   setAccumRedBits(accumRedSize);
107   setAccumGreenBits(accumGreenSize);
108   setAccumBlueBits(accumBlueSize);
109   setAccumAlphaBits(accumAlphaSize);
110   }
111 
112   /** Creates a GLCapabilities object. All attributes are in
113       a default state, they can be configured by the client.
114     */
115   public GLCapabilities() {}
116 
117   public Object clone()
118           throws CloneNotSupportedException
119   {
120   GLCapabilities nobj = new GLCapabilities();
121   nobj.buffer=buffer;
122   nobj.color=color;
123   nobj.stereo=stereo;
124   nobj.depthBits=depthBits;
125   nobj.stencilBits=stencilBits;
126   nobj.redBits=redBits;
127   nobj.greenBits=greenBits;
128   nobj.blueBits=blueBits;
129   nobj.alphaBits=alphaBits;
130   nobj.accumRedBits=accumRedBits;
131   nobj.accumGreenBits=accumGreenBits;
132   nobj.accumBlueBits=accumBlueBits;
133   nobj.accumAlphaBits=accumAlphaBits;
134         nobj.nativeVisualID=nativeVisualID;
135   return nobj;
136   }
137 
138   /** Indicates whether double-buffering is enabled. */
139   public boolean getDoubleBuffered() { return buffer == BUFFER_DOUBLE; }
140 
141   /** Indicates whether true color (as opposed to indexed color) is
142       enabled. */
143   public boolean getTrueColor()      { return color == COLOR_RGBA;    }
144   
145   /** Indicates whether stereo is enabled. */
146   public boolean getStereo()         { return stereo == STEREO_ON;     }
147   
148   /** Enables or disables double buffering. */
149   public void setDoubleBuffered(boolean onOrOff) {
150     buffer = (onOrOff ? BUFFER_DOUBLE : BUFFER_SINGLE);
151   }
152 
153   /** Enables or disables true color (RGBA mode). */
154   public void setTrueColor(boolean onOrOff) {
155     color = (onOrOff ? COLOR_RGBA : COLOR_INDEX);
156   }
157   
158   /** Enables or disables stereo viewing. */
159   public void setStereo(boolean onOrOff) {
160     stereo = (onOrOff ? STEREO_ON : STEREO_OFF);
161   }
162 
163   /** Returns number of bits requested for depth buffer */
164   public int getDepthBits()                         { return depthBits; }
165 
166   /** Sets number of bits requested for depth buffer */
167   public void setDepthBits(int depthBits)           { this.depthBits = depthBits; }
168   
169   /** Returns number of bits requested for stencil buffer */
170   public int getStencilBits()                       { return stencilBits; }
171 
172   /** Sets number of bits requested for stencil buffer */
173   public void setStencilBits(int stencilBits)       { this.stencilBits = stencilBits; }
174   
175   /** Returns number of bits requested for color buffer's red
176       component. On some systems and in color index mode only the
177       color depth, which is the sum of the red, green, and blue bits,
178       is considered. */
179   public int getRedBits()                           { return redBits; }
180 
181   /** Sets number of bits requested for color buffer's red
182       component. On some systems and in color index mode only the
183       color depth, which is the sum of the red, green, and blue bits,
184       is considered. */
185   public void setRedBits(int redBits)               { this.redBits = redBits; }
186 
187   /** Returns number of bits requested for color buffer's green
188       component. On some systems and in color index mode only the
189       color depth, which is the sum of the red, green, and blue bits,
190       is considered. */
191   public int getGreenBits()                         { return greenBits; }
192 
193   /** Sets number of bits requested for color buffer's green
194       component. On some systems and in color index mode only the
195       color depth, which is the sum of the red, green, and blue bits,
196       is considered. */
197   public void setGreenBits(int greenBits)           { this.greenBits = greenBits; }
198 
199   /** Returns number of bits requested for color buffer's blue
200       component. On some systems and in color index mode only the
201       color depth, which is the sum of the red, green, and blue bits,
202       is considered. */
203   public int getBlueBits()                          { return blueBits; }
204 
205   /** Sets number of bits requested for color buffer's blue
206       component. On some systems and in color index mode only the
207       color depth, which is the sum of the red, green, and blue bits,
208       is considered. */
209   public void setBlueBits(int blueBits)             { this.blueBits = blueBits; }
210   
211   /** Returns number of bits requested for color buffer's alpha
212       component. On some systems and in color index mode only the
213       color depth, which is the sum of the red, green, and blue bits,
214       is considered. */
215   public int getAlphaBits()                         { return alphaBits; }
216 
217   /** Sets number of bits requested for color buffer's alpha
218       component. On some systems and in color index mode only the
219       color depth, which is the sum of the red, green, and blue bits,
220       is considered. */
221   public void setAlphaBits(int alphaBits)           { this.alphaBits = alphaBits; }
222   
223   /** Returns number of bits requested for accumulation buffer's red
224       component. On some systems only the accumulation buffer depth,
225       which is the sum of the red, green, and blue bits, is
226       considered. */
227   public int getAccumRedBits()                      { return accumRedBits; }
228 
229   /** Sets number of bits requested for accumulation buffer's red
230       component. On some systems only the accumulation buffer depth,
231       which is the sum of the red, green, and blue bits, is
232       considered. */
233   public void setAccumRedBits(int accumRedBits)     { this.accumRedBits = accumRedBits; }
234 
235   /** Returns number of bits requested for accumulation buffer's green
236       component. On some systems only the accumulation buffer depth,
237       which is the sum of the red, green, and blue bits, is
238       considered. */
239   public int getAccumGreenBits()                    { return accumGreenBits; }
240 
241   /** Sets number of bits requested for accumulation buffer's green
242       component. On some systems only the accumulation buffer depth,
243       which is the sum of the red, green, and blue bits, is
244       considered. */
245   public void setAccumGreenBits(int accumGreenBits) { this.accumGreenBits = accumGreenBits; }
246 
247   /** Returns number of bits requested for accumulation buffer's blue
248       component. On some systems only the accumulation buffer depth,
249       which is the sum of the red, green, and blue bits, is
250       considered. */
251   public int getAccumBlueBits()                     { return accumBlueBits; }
252 
253   /** Sets number of bits requested for accumulation buffer's blue
254       component. On some systems only the accumulation buffer depth,
255       which is the sum of the red, green, and blue bits, is
256       considered. */
257   public void setAccumBlueBits(int accumBlueBits)   { this.accumBlueBits = accumBlueBits; }
258 
259   /** Returns number of bits requested for accumulation buffer's alpha
260       component. On some systems only the accumulation buffer depth,
261       which is the sum of the red, green, and blue bits, is
262       considered. */
263   public int getAccumAlphaBits()                    { return accumAlphaBits; }
264 
265   /** Sets number of bits requested for accumulation buffer's alpha
266       component. On some systems only the accumulation buffer depth,
267       which is the sum of the red, green, and blue bits, is
268       considered. */
269   public void setAccumAlphaBits(int accumAlphaBits) { this.accumAlphaBits = accumAlphaBits; }
270 
271   /**
272    * Set the fetched native VisualID.
273    * This is an interface for the Factory and GLContext.
274    *
275    * Because the GLCapabilities are copied through 
276    * the handling between the Factory and GLContext,
277    * you cannot missuse it ..
278    *
279    * this is the holder for the native visualID,
280    * e.g. Win32's number of the PIXELFORMATDESC,
281    *      or X11's VisualID
282    */
283   public void setNativeVisualID(long id)
284   { nativeVisualID = id; }
285 
286   /**
287    * Get the fetched native VisualID.
288    * This is an interface for the Factory and GLContext.
289    *
290    * this is the holder for the native visualID,
291    * e.g. Win32's number of the PIXELFORMATDESC,
292    *      or X11's VisualID
293    */
294   public long getNativeVisualID()
295   { return nativeVisualID ; }
296 
297   public String toString()
298   {
299     return "GLCapabilities ["+
300       "DoubleBuffer: "+buffer+", "+
301       "RGBA: "+ color+", "+
302       "Stereo: "+ stereo+",\n\t"+
303       "DepthSize: "+ depthBits+", "+
304       "StencilSize: "+ stencilBits+",\n\t"+
305       "Red: "+ redBits+", "+
306       "Green: "+ greenBits+", "+
307       "Blue: "+ blueBits+", "+
308       "Alpha: "+ alphaBits+",\n\t"+
309       "Red Accum: "+ accumRedBits+", "+
310       "Green Accum: "+ accumGreenBits+", "+
311       "Blue Accum: "+ accumBlueBits+", "+
312       "Alpha Accum: "+ accumAlphaBits+",\n\t"+
313       "NativeVisualID: "+nativeVisualID+
314       "] ";
315   }
316 
317   public static void main( String args[] ) 
318   {
319     GLCapabilities glCaps = new GLCapabilities();
320   System.out.println("Default GLCapabilities:\n"+glCaps);
321   }
322 }