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
|
#include "gl4java_drawable_X11SunJDK13GLDrawableFactory.h"
#include "OpenGL_X11_common.h"
JNIEXPORT jlong JNICALL
Java_gl4java_drawable_X11SunJDK13GLDrawableFactory_glXChooseVisualID
(JNIEnv *env,
jclass unused,
jint screen,
jlong display,
jobject capsObj, jboolean verbose)
{
Display *disp = (Display *) ( (PointerHolder)display );
XVisualInfo * visual=NULL;
int visualAttribList[32];
int done=0;
GLCapabilities glCaps;
jboolean ok = javaGLCapabilities2NativeGLCapabilities ( env,
capsObj, &glCaps );
if(JNI_TRUE!=ok)
{
fprintf(stderr,"GL4Java X11SunJDK13GLDrawableFactory ERROR: gl4java/GLCapabilities fields not accessible\n");
fflush(stderr);
return JNI_FALSE;
}
/* JAU: What the hell ..
The java given display is not alway functional .. ?
If running without this ugly thing,
the derived SimpleGLAnimApplet1 get's an X11 async reply
if the thing is initialized by the applet's init method !
*/
disp = XOpenDisplay( NULL );
screen = DefaultScreen( disp );
if(JNI_TRUE==verbose)
fprintf(stdout," display=%p, screen=%d\n", disp, (int)screen);
while(!done && visual==NULL)
{
(void) setVisualAttribListByGLCapabilities( visualAttribList, &glCaps);
if(JNI_TRUE==verbose)
{
fprintf(stdout, "X11DrawableFactory.glXChooseVisual: try capabilities:\n");
printGLCapabilities ( &glCaps );
}
visual = glXChooseVisual( disp, screen, visualAttribList );
if(JNI_TRUE==verbose)
{
if(visual!=NULL)
{
fprintf(stdout, "X11DrawableFactory.glXChooseVisual: found visual(ID:%d(0x%X)):\n",
(int) visual->visualid,
(int) visual->visualid);
printVisualInfo ( disp, visual);
}
fflush(stdout);
}
/**
* Falling-Back the exact (min. requirement) parameters ..
*/
if(visual==NULL && glCaps.stereo==STEREO_ON) {
glCaps.stereo=STEREO_OFF;
} else if(visual==NULL && glCaps.stencilBits>32) {
glCaps.stencilBits=32;
} else if(visual==NULL && glCaps.stencilBits>16) {
glCaps.stencilBits=16;
} else if(visual==NULL && glCaps.stencilBits>8) {
glCaps.stencilBits=8;
} else if(visual==NULL && glCaps.stencilBits>0) {
glCaps.stencilBits=0;
} else if(visual==NULL && glCaps.buffer==BUFFER_DOUBLE) {
glCaps.buffer=BUFFER_SINGLE;
} else done=1; /* forget it .. */
}
if(visual==NULL)
{
fprintf(stdout, "X11DrawableFactory.glXChooseVisual: no visual\n");
return 0;
}
(void ) setGLCapabilities ( disp, visual, &glCaps );
if(JNI_TRUE==verbose)
{
fprintf(stdout,"X11DrawableFactory.glXChooseVisual: writing capabilities to GLContext's java object\n");
fflush(stdout);
}
(void) nativeGLCapabilities2JavaGLCapabilities
(env, capsObj, &glCaps);
/* JAU: see above .. */
XCloseDisplay( disp );
return (jlong) (visual->visualid);
}
|