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
232
233
234
235
236
237
238
|
/*
* $RCSfile$
*
* Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved.
*
* Use is subject to license terms.
*
* $Revision$
* $Date$
* $State$
*/
/*
* Portions of this code were derived from work done by the Blackdown
* group (www.blackdown.org), who did the initial Linux implementation
* of the Java 3D API.
*/
#if defined(LINUX)
#define _GNU_SOURCE 1
#endif
#include <jni.h>
#include <math.h>
#include <stdio.h>
#include "gldefs.h"
#if defined(UNIX)
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <dlfcn.h>
#endif
#ifdef WIN32
#include <windows.h>
#endif
#if defined(UNIX)
/*
* Class: javax_media_j3d_NativeScreenInfo
* Method: openDisplay
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_javax_media_j3d_NativeScreenInfo_openDisplay(
JNIEnv *env,
jclass cls)
{
Display* dpy;
dpy = XOpenDisplay(NULL);
return (jlong)dpy;
}
/*
* Class: javax_media_j3d_NativeScreenInfo
* Method: getDefaultScreen
* Signature: (J)I
*/
JNIEXPORT jint JNICALL
Java_javax_media_j3d_NativeScreenInfo_getDefaultScreen(
JNIEnv *env,
jclass cls,
jlong display)
{
Display* dpy = (Display*)display;
return (jint)DefaultScreen(dpy);
}
/*
* Class: javax_media_j3d_NativeScreenInfo
* Method: queryGLX13
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL
Java_javax_media_j3d_NativeScreenInfo_queryGLX13(
JNIEnv *env,
jclass cls,
jlong display)
{
/* Fix for Issue 20 */
MYPFNGLXCHOOSEFBCONFIG tmpfp;
int major, minor;
int errorBase, eventBase;
Display* dpy = (Display*)display;
/* It should be cleaner to return both the major and minor to the caller. */
if (!glXQueryExtension(dpy, &errorBase, &eventBase)) {
fprintf(stderr, "Java 3D ERROR : GLX extension is not supported\n");
fprintf(stderr, " GLX version 1.3 or higher is required\n");
return JNI_FALSE;
}
/* Query the GLX version number */
if (!glXQueryVersion(dpy, &major, &minor)) {
fprintf(stderr, "Java 3D ERROR : Unable to query GLX version\n");
fprintf(stderr, " GLX version 1.3 or higher is required\n");
return JNI_FALSE;
}
/*fprintf(stderr, "Checking GLX version : %d.%d\n", major, minor);*/
tmpfp = (MYPFNGLXCHOOSEFBCONFIG)dlsym(RTLD_DEFAULT, "glXChooseFBConfig");
if (tmpfp == NULL) {
fprintf(stderr, "Java 3D ERROR : glXChooseFBConfig not found\n");
fprintf(stderr, " GLX version = %d.%d\n", major, minor);
fprintf(stderr, " GLX version 1.3 or higher is required\n");
return JNI_FALSE;
}
/* Check for GLX 1.3 and higher */
if (!(major == 1 && minor >= 3)) {
fprintf(stderr, "Java 3D WARNING : reported GLX version = %d.%d\n", major, minor);
fprintf(stderr, " GLX version 1.3 or higher is required\n");
fprintf(stderr,
" The reported version number may be incorrect. There is a known\n");
fprintf(stderr,
" ATI driver bug in glXQueryVersion that incorrectly reports the GLX\n");
fprintf(stderr,
" version as 1.2 when it really is 1.3, so Java 3D will attempt to\n");
fprintf(stderr,
" run anyway.\n");
/*return JNI_FALSE;*/
}
return JNI_TRUE;
}
#endif /* Solaris and Linux */
#ifdef WIN32
extern HWND createDummyWindow(const char* szAppName);
extern void printErrorMessage(char *message);
extern PIXELFORMATDESCRIPTOR getDummyPFD();
extern BOOL isSupportedWGL(const char *extensions, const char *extension_string);
/*
* Class: javax_media_j3d_NativeScreenInfo
* Method: queryWglARB
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL
Java_javax_media_j3d_NativeScreenInfo_queryWglARB(
JNIEnv *env,
jclass cls)
{
static const BOOL debug = TRUE;
static char szAppName[] = "Choose Pixel Format";
PIXELFORMATDESCRIPTOR dummy_pfd = getDummyPFD();
HWND hwnd;
HGLRC hrc;
HDC hdc;
int pixelFormat;
const char* supportedExtensions;
/* declare function pointers for WGL functions */
PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = NULL;
/*
* Select any pixel format and bound current context to
* it so that we can get the wglChoosePixelFormatARB entry point.
* Otherwise wglxxx entry point will always return null.
* That's why we need to create a dummy window also.
*/
hwnd = createDummyWindow((const char *)szAppName);
if (!hwnd) {
return JNI_FALSE;
}
hdc = GetDC(hwnd);
pixelFormat = ChoosePixelFormat(hdc, &dummy_pfd);
if (pixelFormat<1) {
printErrorMessage("Failed in ChoosePixelFormat");
DestroyWindow(hwnd);
UnregisterClass(szAppName, (HINSTANCE)NULL);
return JNI_FALSE;
}
SetPixelFormat(hdc, pixelFormat, NULL);
hrc = wglCreateContext(hdc);
if (!hrc) {
printErrorMessage("Failed in wglCreateContext");
DestroyWindow(hwnd);
UnregisterClass(szAppName, (HINSTANCE)NULL);
return JNI_FALSE;
}
if (!wglMakeCurrent(hdc, hrc)) {
printErrorMessage("Failed in wglMakeCurrent");
ReleaseDC(hwnd, hdc);
wglDeleteContext(hrc);
DestroyWindow(hwnd);
UnregisterClass(szAppName, (HINSTANCE)NULL);
return JNI_FALSE;
}
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
wglGetProcAddress("wglGetExtensionsStringARB");
if (wglGetExtensionsStringARB == NULL) {
/* printErrorMessage("wglGetExtensionsStringARB not support !\n"); */
return JNI_FALSE;
}
else {
/* get the list of supported extensions */
supportedExtensions = (const char *)wglGetExtensionsStringARB(hdc);
if (debug) {
fprintf(stderr, "WGL Supported extensions: %s.\n", supportedExtensions);
}
if(!isSupportedWGL(supportedExtensions, "WGL_ARB_pixel_format")) {
fprintf(stderr, "WGL_ARB_pixel_format not supported.\n");
return JNI_FALSE;
}
}
ReleaseDC(hwnd, hdc);
wglDeleteContext(hrc);
DestroyWindow(hwnd);
UnregisterClass(szAppName, (HINSTANCE)NULL);
return JNI_TRUE;
}
#endif /* WIN32 */
|