-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnisotropicConfig.java
61 lines (50 loc) · 1.5 KB
/
AnisotropicConfig.java
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
package sk.yin.yngine.render.config;
import javax.media.opengl.GL;
import sk.yin.yngine.util.Log;
/**
* Setups anisotropic filtering for the renderer.
*
* @author Matej 'Yin' Gagyi <[email protected]>
*/
public class AnisotropicConfig {
private static AnisotropicConfig instance;
public static AnisotropicConfig instance() {
if (instance == null) {
instance = new AnisotropicConfig();
}
return instance;
}
private AnisotropicConfig() {
}
public float anisotropy(GL gl) {
if (isSupported(gl)) {
return getMaxAnisotropy(gl);
} else {
return 0;
}
}
public void anisotropy(GL gl, float anisotropy) {
if (isSupported(gl)) {
setAnisotropy(gl, anisotropy);
}
}
public void setMaxAnisotropy(GL gl) {
if (isSupported(gl)) {
setAnisotropy(gl, getMaxAnisotropy(gl));
}
}
public boolean isSupported(GL gl) {
return gl.isExtensionAvailable("GL_EXT_texture_filter_anisotropic");
}
private void setAnisotropy(GL gl, float anisotropy) {
Log.log("Enabling anisotropic filtering: " + anisotropy + "X");
gl.glTexParameterf(GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MAX_ANISOTROPY_EXT,
anisotropy);
}
private float getMaxAnisotropy(GL gl) {
float max[] = new float[1];
gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max, 0);
return max[0];
}
}