Drawable2d.java
2.53 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
92
package com.cnlive.demo.stream.gles;
import java.nio.FloatBuffer;
/**
* Created by jerikc on 16/2/23.
*/
public class Drawable2d {
private static final int SIZEOF_FLOAT = 4;
private static final float FULL_RECTANGLE_COORDS[] = {
-1.0f, -1.0f, // 0 bottom left
1.0f, -1.0f, // 1 bottom right
-1.0f, 1.0f, // 2 top left
1.0f, 1.0f, // 3 top right
};
private static final float FULL_RECTANGLE_TEX_COORDS[] = {
0.0f, 0.0f, // 0 bottom left
1.0f, 0.0f, // 1 bottom right
0.0f, 1.0f, // 2 top left
1.0f, 1.0f // 3 top right
};
private static final FloatBuffer FULL_RECTANGLE_BUF =
GlUtil.createFloatBuffer(FULL_RECTANGLE_COORDS);
private static final FloatBuffer FULL_RECTANGLE_TEX_BUF =
GlUtil.createFloatBuffer(FULL_RECTANGLE_TEX_COORDS);
private FloatBuffer mVertexArray;
private FloatBuffer mTexCoordArray;
private int mVertexCount;
private int mCoordsPerVertex;
private int mVertexStride;
private int mTexCoordStride;
public Drawable2d() {
mVertexArray = FULL_RECTANGLE_BUF;
mTexCoordArray = FULL_RECTANGLE_TEX_BUF;
mCoordsPerVertex = 2;
mVertexStride = mCoordsPerVertex * SIZEOF_FLOAT;
mVertexCount = FULL_RECTANGLE_COORDS.length / mCoordsPerVertex;
mTexCoordStride = 2 * SIZEOF_FLOAT;
}
/**
* Returns the array of vertices.
* <p>
* To avoid allocations, this returns internal state. The caller must not modify it.
*/
public FloatBuffer getVertexArray() {
return mVertexArray;
}
/**
* Returns the array of texture coordinates.
* <p>
* To avoid allocations, this returns internal state. The caller must not modify it.
*/
public FloatBuffer getTexCoordArray() {
return mTexCoordArray;
}
/**
* Returns the number of vertices stored in the vertex array.
*/
public int getVertexCount() {
return mVertexCount;
}
/**
* Returns the width, in bytes, of the data for each vertex.
*/
public int getVertexStride() {
return mVertexStride;
}
/**
* Returns the width, in bytes, of the data for each texture coordinate.
*/
public int getTexCoordStride() {
return mTexCoordStride;
}
/**
* Returns the number of position coordinates per vertex. This will be 2 or 3.
*/
public int getCoordsPerVertex() {
return mCoordsPerVertex;
}
}