-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVbo.java
More file actions
91 lines (73 loc) · 2.77 KB
/
Copy pathVbo.java
File metadata and controls
91 lines (73 loc) · 2.77 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package designer.nakata.lightseeker;
import android.opengl.GLES20;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
public class Vbo {
final private int vbos[] = new int[1];
public int usage = GLES20.GL_STATIC_DRAW;
public Vbo(){
//Generate VBO
GLES20.glGenBuffers(1, vbos, 0);
}
public void ChangeVbo(float[] data, int offset){
//Load array to ByteBuffer
ByteBuffer bb = ByteBuffer.allocateDirect(
// (# of coordinate values * 4 bytes per float)
(data.length * 4));
bb.order(ByteOrder.nativeOrder());
FloatBuffer Buffer = bb.asFloatBuffer();
Buffer.put(data);
Buffer.position(0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbos[0]);
GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, offset*4, Buffer.capacity() * 4, Buffer);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
public void LoadVbo(float[] data){
//Load array to ByteBuffer
ByteBuffer bb = ByteBuffer.allocateDirect(
// (# of coordinate values * 4 bytes per float)
(data.length * 4));
bb.order(ByteOrder.nativeOrder());
FloatBuffer Buffer = bb.asFloatBuffer();
Buffer.put(data);
Buffer.position(0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbos[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, Buffer.capacity() * 4,
Buffer, usage);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
public void LoadVbo(short[] data){
ByteBuffer bb = ByteBuffer.allocateDirect(
// (# of coordinate values * 2 bytes per short)
(data.length * 2));
bb.order(ByteOrder.nativeOrder());
ShortBuffer indexBuffer = bb.asShortBuffer();
indexBuffer.put(data);
indexBuffer.position(0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, vbos[0]);
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.capacity() * 2,
indexBuffer, usage);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
}
public void getAttribute(int handle, int stride){
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbos[0]);
GLES20.glVertexAttribPointer(
handle, stride,
GLES20.GL_FLOAT, false,
0,0);
GLES20.glEnableVertexAttribArray(handle);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
public void bind(int type){
GLES20.glBindBuffer(type, vbos[0]);
}
public void unbind(int type){
GLES20.glBindBuffer(type, 0);
}
public void delete(){
GLES20.glDeleteBuffers(1, vbos, 0);
}
}