1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
package gl4java.drawable;
import java.awt.*;
import gl4java.*;
import gl4java.awt.*;
import gl4java.swing.*;
import java.security.*;
/** <P> Provides a VM- and OS-independent mechanism for creating
{@link gl4java.awt.GLAnimCanvas},
{@link gl4java.awt.GLCanvas},
{@link gl4java.swing.GLAnimJPanel}
and {@link gl4java.swing.GLJPanel}
objects. Most useful when used in conjunction with the {@link
gl4java.drawable.GLEventListener} model, where subclassing is not
required. </P>
<P> The {@link gl4java.GLCapabilities} objects passed in to the
various factory methods are used as a minimum specification for
the properties of the returned GLCanvas. The canvas will either
meet or exceed all of the integer properties such as color and
accumulation buffer depth and will match all of the boolean
properties such as enabling or disabling of stereo. The selection
algorithm in general attempts to select the most minimal window
type to meet the criteria, but is otherwise left loosely
specified.
</P>
<P> The implementing class of this abstract factory methods
does clone your given GLCapabilities. So your version is unchanged.
The GLContext's GLCapabilites instance is changed to
the used capabilities, so you can query GLContext's GLCapabilites!
</P>
<P> It is currently not possible to specify GLCapabilities for
lightweight components. </P>
*/
public abstract class GLDrawableFactory {
static {
GLContext.doLoadNativeLibraries(null, null, null);
}
private static GLDrawableFactory soleInstance;
/** Returns the sole instance of the GLCanvasFactory (singleton
pattern). */
public static GLDrawableFactory getFactory() {
GLContext.doLoadNativeLibraries(null, null, null);
String jvmVendor = GLContext.getJVMVendor();
boolean isIBMJvm = jvmVendor!=null && jvmVendor.indexOf("IBM")>=0 ;
boolean isMicrosoftJvm =
jvmVendor!=null && jvmVendor.indexOf("Microsoft")>=0 ;
if (soleInstance == null) {
if( GLContext.getJVMVersionMajor()>=2 ||
( GLContext.getJVMVersionMajor()==1 &&
GLContext.getJVMVersionMinor()>=4
) ||
( GLContext.getJVMVersionMajor()==1 &&
GLContext.getJVMVersionMinor()>=3 &&
!isIBMJvm && !isMicrosoftJvm
)
)
{
String clazzName = null;
switch(GLContext.getNativeOSType())
{
case GLContext.OsWindoof:
clazzName =
"gl4java.drawable.Win32SunJDK13GLDrawableFactory";
break;
case GLContext.OsMac9:
case GLContext.OsMacX:
clazzName =
"gl4java.drawable.MacSunJDK13GLDrawableFactory";
break;
case GLContext.OsX11:
clazzName =
"gl4java.drawable.X11SunJDK13GLDrawableFactory";
break;
default:
System.out.println("GLDrawableFactory: Unsupported OS: "+
GLContext.getNativeOSName() + ", using DummyGLDrawableFactory");
}
if(clazzName!=null)
{
final String f_clazzName = clazzName;
soleInstance = (GLDrawableFactory)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run()
{
try {
return Class.forName(f_clazzName).newInstance();
} catch (Exception ex) {
System.out.println("GLDrawableFactory: could not create instance of: "+ f_clazzName + ", using DummyGLDrawableFactory");
}
return null;
}});
}
}
if( soleInstance == null )
{
soleInstance = new DummyGLDrawableFactory();
}
}
return soleInstance;
}
/** Create a new GLAnimCanvas given the specified GLCapabilities.
@param capabilities the requested set of OpenGL capabilities of
the canvas
@param width the canvas's initial width
@param height the canvas's initial height
@return a GLAnimCanvas supporting the set of specified capabilities,
or null if there was no matching visual */
public GLAnimCanvas createGLAnimCanvas(GLCapabilities capabilities,
int width,
int height)
{
return createGLAnimCanvas(capabilities, width, height, null, null);
}
/** Create a new GLAnimCanvas given the specified GLCapabilities.
@param capabilities the requested set of OpenGL capabilities of
the canvas
@param width the canvas's initial width
@param height the canvas's initial height
@param glName the name of the GLFunc implementation.
If null, the default class will be used
@param gluName the name of the GLUFunc implementation.
If null, the default class will be used
@return a GLAnimCanvas supporting the set of specified capabilities,
or null if there was no matching visual */
public abstract GLAnimCanvas createGLAnimCanvas(GLCapabilities capabilities,
int width,
int height,
String glName,
String gluName);
/** Create a new GLCanvas given the specified GLCapabilities.
@param capabilities the requested set of OpenGL capabilities of
the canvas
@param width the canvas's initial width
@param height the canvas's initial height
@return a GLCanvas supporting the set of specified capabilities,
or null if there was no matching visual */
public GLCanvas createGLCanvas(GLCapabilities capabilities,
int width,
int height)
{
return createGLCanvas(capabilities, width, height, null, null);
}
/** Create a new GLCanvas given the specified GLCapabilities.
@param capabilities the requested set of OpenGL capabilities of
the canvas
@param width the canvas's initial width
@param height the canvas's initial height
@param glName the name of the GLFunc implementation.
If null, the default class will be used
@param gluName the name of the GLUFunc implementation.
If null, the default class will be used
@return a GLCanvas supporting the set of specified capabilities,
or null if there was no matching visual */
public abstract GLCanvas createGLCanvas(GLCapabilities capabilities,
int width,
int height,
String glName,
String gluName);
/** Create a new GLAnimJPanel. */
public GLAnimJPanel createGLAnimJPanel() {
return new GLAnimJPanel();
}
/** Create a new GLAnimJPanel with the specified GL/GLU library names,
LayoutManager, and double buffering specification.
@param glName the name of the GLFunc implementation.
If null, the default class will be used
@param gluName the name of the GLUFunc implementation.
If null, the default class will be used
@param layout the layout manager
@param isDoubleBuffered indicates if double buffering should be used
*/
public GLAnimJPanel createGLAnimJPanel(String glName,
String gluName,
LayoutManager layout,
boolean isDoubleBuffered) {
return new GLAnimJPanel(glName, gluName, layout, isDoubleBuffered);
}
/** Create a new GLJPanel. */
public GLJPanel createGLJPanel() {
return new GLJPanel();
}
/** Create a new GLJPanel with the specified GL/GLU library names,
LayoutManager, and double buffering specification.
@param glName the name of the GLFunc implementation.
If null, the default class will be used
@param gluName the name of the GLUFunc implementation.
If null, the default class will be used
@param layout the layout manager
@param isDoubleBuffered indicates if double buffering should be used
*/
public GLJPanel createGLJPanel(String glName,
String gluName,
LayoutManager layout,
boolean isDoubleBuffered) {
return new GLJPanel(glName, gluName, layout, isDoubleBuffered);
}
}
|