-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathUVMap.java
More file actions
67 lines (59 loc) · 1.51 KB
/
Copy pathUVMap.java
File metadata and controls
67 lines (59 loc) · 1.51 KB
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
package javaforce.gl;
import javaforce.*;
import static javaforce.gl.GL.*;
/**
* UV Map - 2D Texture coordinates (see Object3)
*
* @author pquiring
*/
public class UVMap {
public JFArrayFloat uvl; //texture coords list (UV)
public String name;
public int textureIndex = -1;
public boolean texloaded = false;
public int uvb = -1; //GL buffer
public int idx; //map index
public UVMap(int idx) {
uvl = new JFArrayFloat();
this.idx = idx;
if (idx > 1) {
System.out.println("GLUVMap:Warning:More than 2 UVMaps not supported");
}
}
public void addText(float[] uv) {
uvl.append(uv);
}
public void copyBuffers() {
GL gl = GL.getInstance();
int[] ids = new int[1];
if (uvb == -1) {
gl.glGenBuffers(1, ids);
uvb = ids[0];
if (debug) {
JFLog.log("GLUVMap:uvb=" + uvb);
}
}
if (debug) {
JFLog.log("GLUVMap.copyBuffer:" + uvb + "," + idx);
}
gl.glBindBuffer(GL_ARRAY_BUFFER, uvb);
gl.glBufferData(GL_ARRAY_BUFFER, uvl.size() * 4, uvl.toArray(), GL_STATIC_DRAW);
}
public void bindBuffers(Scene scene) {
GL gl = GL.getInstance();
if (debug) {
JFLog.log("GLUVMap.bindBuffer:" + uvb + "," + idx);
}
gl.glBindBuffer(GL_ARRAY_BUFFER, uvb);
gl.glVertexAttribPointer(scene.tca[idx], 2, GL_FLOAT, GL_FALSE, 0, 0);
}
public void freeBuffers() {
GL gl = GL.getInstance();
int[] ids = new int[1];
if (uvb != -1) {
ids[0] = uvb;
gl.glDeleteBuffers(1, ids);
uvb = -1;
}
}
}