001: /*
002: * $RCSfile: Win32NativeConfigTemplate3D.java,v $
003: *
004: * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.2 $
028: * $Date: 2008/02/28 20:17:57 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.awt.GraphicsDevice;
035: import java.awt.GraphicsConfiguration;
036: import sun.awt.Win32GraphicsDevice;
037: import sun.awt.Win32GraphicsConfig;
038: import java.awt.GraphicsConfigTemplate;
039:
040: /**
041: * Native config template class. A singleton instance of this class is
042: * created by a factory method in the base class using reflection.
043: */
044: class Win32NativeConfigTemplate3D extends NativeConfigTemplate3D {
045: private final static boolean debug = false;
046:
047: Win32NativeConfigTemplate3D() {
048: }
049:
050: /**
051: * selects the proper visual
052: */
053: native int choosePixelFormat(long ctx, int screen, int[] attrList,
054: long[] pFormatInfo);
055:
056: // Native method to free an PixelFormatInfo struct. This is static since it
057: // may need to be called to clean up the Canvas3D graphicsConfigTable after the
058: // Win32NativeConfigTemplate3D has been disposed of.
059: static native void freePixelFormatInfo(long pFormatInfo);
060:
061: // Native methods to return whether a particular attribute is available
062: native boolean isStereoAvailable(long pFormatInfo, boolean offScreen);
063:
064: native boolean isDoubleBufferAvailable(long pFormatInfo,
065: boolean offScreen);
066:
067: native boolean isSceneAntialiasingAccumAvailable(long pFormatInfo,
068: boolean offScreen);
069:
070: native boolean isSceneAntialiasingMultisampleAvailable(
071: long pFormatInfo, boolean offScreen, int screen);
072:
073: native int getStencilSize(long pFormatInfo, boolean offScreen);
074:
075: /**
076: * Chooses the best PixelFormat for Java 3D apps.
077: */
078: @Override
079: GraphicsConfiguration getBestConfiguration(
080: GraphicsConfigTemplate3D template,
081: GraphicsConfiguration[] gc) {
082:
083: Win32GraphicsDevice gd = (Win32GraphicsDevice) ((Win32GraphicsConfig) gc[0])
084: .getDevice();
085:
086: /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to
087: do so in J3D 1.4.
088: System.out.println("getBestConfiguration : Checking WGL ARB support\n");
089:
090: if (!Win32NativeScreenInfo.isWglARB()) {
091: Thread.dumpStack();
092: System.out.println("getBestConfiguration : WGL ARB support fail\n");
093: return null;
094: }
095: */
096:
097: // holds the list of attributes to be tramslated
098: // for glxChooseVisual call
099: int attrList[] = new int[NUM_ITEMS];
100: // assign template values to array
101: attrList[RED_SIZE] = template.getRedSize();
102: attrList[GREEN_SIZE] = template.getGreenSize();
103: attrList[BLUE_SIZE] = template.getBlueSize();
104:
105: attrList[DEPTH_SIZE] = template.getDepthSize();
106: attrList[DOUBLEBUFFER] = template.getDoubleBuffer();
107: attrList[STEREO] = template.getStereo();
108: attrList[ANTIALIASING] = template.getSceneAntialiasing();
109: attrList[STENCIL_SIZE] = template.getStencilSize();
110: // System.out.println("Win32NativeConfigTemplate3D : getStencilSize " +
111: // attrList[STENCIL_SIZE]);
112:
113: int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(
114: gd);
115:
116: long[] pFormatInfo = new long[1];
117:
118: /* Deliberately set this to -1. pFormatInfo is not use in
119: D3D, so this value will be unchange in the case of D3D.
120: In the case of OGL, the return value should be 0 or a
121: positive valid address.
122: */
123: pFormatInfo[0] = -1;
124:
125: int pixelFormat = choosePixelFormat(0, screen, attrList,
126: pFormatInfo);
127: if (debug) {
128: System.out.println(" choosePixelFormat() returns "
129: + pixelFormat);
130: System.out.println(" pFormatInfo is " + pFormatInfo[0]);
131: System.out.println();
132: }
133:
134: if (pixelFormat < 0) {
135: // current mode don't support the minimum config
136: return null;
137: }
138:
139: // Fix to issue 104 --
140: // Pass in 0 for pixel format to the AWT.
141: // ATI driver will lockup pixelFormat, if it is passed to AWT.
142: GraphicsConfiguration gc1 = Win32GraphicsConfig
143: .getConfig(gd, 0);
144:
145: // We need to cache the GraphicsTemplate3D and the private
146: // pixel format info.
147: synchronized (Canvas3D.graphicsConfigTable) {
148: if (Canvas3D.graphicsConfigTable.get(gc1) == null) {
149: GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(
150: template);
151: gcInfo.setPrivateData(new Long(pFormatInfo[0]));
152: Canvas3D.graphicsConfigTable.put(gc1, gcInfo);
153: } else {
154: freePixelFormatInfo(pFormatInfo[0]);
155: }
156: }
157:
158: return gc1;
159: }
160:
161: /**
162: * Determine if a given GraphicsConfiguration object can be used
163: * by Java 3D.
164: */
165: @Override
166: boolean isGraphicsConfigSupported(
167: GraphicsConfigTemplate3D template, GraphicsConfiguration gc) {
168:
169: Win32GraphicsDevice gd = (Win32GraphicsDevice) ((Win32GraphicsConfig) gc)
170: .getDevice();
171:
172: /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to
173: do so in J3D 1.4.
174: System.out.println("isGraphicsConfigSupported : Checking WGL ARB support\n");
175:
176: if (!Win32NativeScreenInfo.isWglARB()) {
177: Thread.dumpStack();
178: System.out.println("isGraphicsConfigSupported : WGL ARB support fail\n");
179: return false;
180: }
181: */
182:
183: // holds the list of attributes to be tramslated
184: // for glxChooseVisual call
185: int attrList[] = new int[NUM_ITEMS];
186: // assign template values to array
187: attrList[RED_SIZE] = template.getRedSize();
188: attrList[GREEN_SIZE] = template.getGreenSize();
189: attrList[BLUE_SIZE] = template.getBlueSize();
190:
191: attrList[DEPTH_SIZE] = template.getDepthSize();
192: attrList[DOUBLEBUFFER] = template.getDoubleBuffer();
193: attrList[STEREO] = template.getStereo();
194: attrList[ANTIALIASING] = template.getSceneAntialiasing();
195: attrList[STENCIL_SIZE] = template.getStencilSize();
196: // System.out.println("Win32NativeConfigTemplate3D : getStencilSize " +
197: // attrList[STENCIL_SIZE]);
198:
199: int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(
200: gd);
201:
202: long[] pFormatInfo = new long[1];
203:
204: int pixelFormat = choosePixelFormat(0, screen, attrList,
205: pFormatInfo);
206: if (debug) {
207: System.out.println(" choosePixelFormat() returns "
208: + pixelFormat);
209: System.out.println(" pFormatInfo is " + pFormatInfo[0]);
210: System.out.println();
211: }
212:
213: if (pixelFormat < 0) {
214: // current mode don't support the minimum config
215: return false;
216: } else
217: return true;
218: }
219:
220: // Return whether stereo is available.
221: @Override
222: boolean hasStereo(Canvas3D c3d) {
223: return isStereoAvailable(c3d.fbConfig, c3d.offScreen);
224: }
225:
226: // Return the stencil of this canvas.
227: @Override
228: int getStencilSize(Canvas3D c3d) {
229: return getStencilSize(c3d.fbConfig, c3d.offScreen);
230: }
231:
232: // Return whether a double buffer is available.
233: @Override
234: boolean hasDoubleBuffer(Canvas3D c3d) {
235: return isDoubleBufferAvailable(c3d.fbConfig, c3d.offScreen);
236: }
237:
238: // Return whether scene antialiasing is available.
239: @Override
240: boolean hasSceneAntialiasingAccum(Canvas3D c3d) {
241: return isSceneAntialiasingAccumAvailable(c3d.fbConfig,
242: c3d.offScreen);
243: }
244:
245: // Return whether scene antialiasing is available.
246: @Override
247: boolean hasSceneAntialiasingMultisample(Canvas3D c3d) {
248: GraphicsConfiguration gc = c3d.graphicsConfiguration;
249:
250: Win32GraphicsDevice gd = (Win32GraphicsDevice) ((Win32GraphicsConfig) gc)
251: .getDevice();
252: int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(
253: gd);
254: /* Fix to issue 77 */
255: return isSceneAntialiasingMultisampleAvailable(c3d.fbConfig,
256: c3d.offScreen, screen);
257: }
258:
259: // Ensure that the native libraries are loaded
260: static {
261: VirtualUniverse.loadLibraries();
262: }
263: }
|