blob: 4f668887995da4f72b49b37d0efcfd944bb2c154 (
plain)
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
|
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
*/
package javax.media.opengl.sub.fixed;
import javax.media.opengl.*;
import javax.media.opengl.sub.*;
import com.sun.nativewindow.impl.NWReflection;
import java.lang.reflect.*;
/**
* Tool to pipeline GL2ES2 into a fixed function emulation,
* implementing GL2ES1.
* The implementation is retrieved by reflection.
*/
public class GLFixedFuncUtil {
static final Constructor fFuncHookCstr;
static final Constructor fFuncImplCstr;
static {
if(NWReflection.isClassAvailable("com.sun.opengl.util.glsl.fixed.FixedFuncHook") &&
NWReflection.isClassAvailable("com.sun.opengl.util.glsl.fixed.FixedFuncImpl")) {
Class argsHook[] = { javax.media.opengl.GL2ES2.class };
Class argsImpl[] = { javax.media.opengl.GL2ES2.class, NWReflection.getClass("com.sun.opengl.util.glsl.fixed.FixedFuncHook") };
fFuncHookCstr = NWReflection.getConstructor("com.sun.opengl.util.glsl.fixed.FixedFuncHook", argsHook);
fFuncImplCstr = NWReflection.getConstructor("com.sun.opengl.util.glsl.fixed.FixedFuncImpl", argsImpl);
} else {
fFuncHookCstr=null;
fFuncImplCstr=null;
}
}
/**
* @return If gl is a GL2ES1, return the type cast object,
* otherwise create a FixedFuncImpl pipeline with the GL2ES2 impl.
* @throws GLException If this GL Object is neither GL2ES1 nor GL2ES2
*/
public static final GL2ES1 getFixedFuncImpl(GL gl) {
if(gl instanceof GL2ES1) {
return (GL2ES1)gl;
} else if(gl instanceof GL2ES2) {
if(null!=fFuncImplCstr) {
try {
GL2ES2 es2 = (GL2ES2)gl;
Object fFuncHook = fFuncHookCstr.newInstance( new Object[] { es2 } );
GL2ES1 fFuncImpl = (GL2ES1) fFuncImplCstr.newInstance( new Object[] { es2, fFuncHook } );
gl.getContext().setGL(fFuncImpl);
return fFuncImpl;
} catch (Exception e) {
throw new GLException(e);
}
} else {
throw new GLException("GL Object is GL2ES2, but no fixed function impl. available");
}
}
throw new GLException("GL Object is neither GL2ES1 nor GL2ES2");
}
}
|