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
|
#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;
jboolean ok;
GLCapabilities glCaps;
int accumTestDone=0;
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 = disp__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)
{
if(glCaps.stereo==STEREO_ON) {
glCaps.stereo=STEREO_OFF;
} else if(glCaps.stencilBits>32) {
glCaps.stencilBits=32;
} else if(glCaps.stencilBits>16) {
glCaps.stencilBits=16;
} else if(glCaps.stencilBits>8) {
glCaps.stencilBits=8;
} else if(glCaps.stencilBits>0) {
glCaps.stencilBits=0;
} else if( glCaps.alphaBits>0 ||
glCaps.accumAlphaBits>0
)
{
glCaps.alphaBits=0;
glCaps.accumAlphaBits=0;
} else if( accumTestDone==0 &&
( glCaps.accumRedBits==0 ||
glCaps.accumGreenBits==0 ||
glCaps.accumBlueBits==0
)
)
{
glCaps.accumRedBits=1;
glCaps.accumGreenBits=1;
glCaps.accumBlueBits=1;
} else if( glCaps.accumRedBits>0 ||
glCaps.accumGreenBits>0 ||
glCaps.accumBlueBits>0
)
{
glCaps.accumRedBits=0;
glCaps.accumGreenBits=0;
glCaps.accumBlueBits=0;
accumTestDone=1;
} else if(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);
}
|