Android:OpenGL ES 2.0顶点缓冲区对象怪异问题??一种方法的速度是另一种方法的两倍
所以,我的代码运行得很好,除了一件事之外,一切都很好。我有两种方法可以设置相同的VBO。一个是构建VBO的简单循环,秒做同样的事情,但VBO是从对象属性构建的 两者都使用相同的渲染调用等。奇怪的是,方法一给出了两倍的FPS!他们都制造了27000件物品 快速方法Android:OpenGL ES 2.0顶点缓冲区对象怪异问题??一种方法的速度是另一种方法的两倍,android,opengl-es-2.0,vbo,vertex-buffer,Android,Opengl Es 2.0,Vbo,Vertex Buffer,所以,我的代码运行得很好,除了一件事之外,一切都很好。我有两种方法可以设置相同的VBO。一个是构建VBO的简单循环,秒做同样的事情,但VBO是从对象属性构建的 两者都使用相同的渲染调用等。奇怪的是,方法一给出了两倍的FPS!他们都制造了27000件物品 快速方法 public CubeVBOVBA(int generatedCubeFactor) { mActualCubeFactor = generatedCubeFactor; final float[] c
public CubeVBOVBA(int generatedCubeFactor) {
mActualCubeFactor = generatedCubeFactor;
final float[] cubePositionData = new float[108 * generatedCubeFactor * generatedCubeFactor * generatedCubeFactor];
int cubePositionDataOffset = 0;
final int segments = 1; //generatedCubeFactor + (generatedCubeFactor - 1);
final float minPosition = -1.0f;
final float maxPosition = 1.0f;
final float positionRange = maxPosition - minPosition;
final float space = 1.0f;
int c = 0;
for (int x = 0; x < generatedCubeFactor; x++) {
for (int y = 0; y < generatedCubeFactor; y++) {
for (int z = 0; z < generatedCubeFactor; z++) {
final float x1 = minPosition + ((positionRange / segments) * (x * space));
final float x2 = minPosition + ((positionRange / segments) * ((x * space) + 1));
final float y1 = minPosition + ((positionRange / segments) * (y * space));
final float y2 = minPosition + ((positionRange / segments) * ((y * space) + 1));
final float z1 = minPosition + ((positionRange / segments) * (z * space));
final float z2 = minPosition + ((positionRange / segments) * ((z * space) + 1));
// Define points for a cube.
// X, Y, Z
final float[] p1p = {x1, y2, z2};
final float[] p2p = {x2, y2, z2};
final float[] p3p = {x1, y1, z2};
final float[] p4p = {x2, y1, z2};
final float[] p5p = {x1, y2, z1};
final float[] p6p = {x2, y2, z1};
final float[] p7p = {x1, y1, z1};
final float[] p8p = {x2, y1, z1};
final float[] thisCubePositionData = ShapeBuilder.generateCubeData(p1p, p2p, p3p, p4p, p5p, p6p, p7p, p8p,
p1p.length);
System.arraycopy(thisCubePositionData, 0, cubePositionData, cubePositionDataOffset, thisCubePositionData.length);
cubePositionDataOffset += thisCubePositionData.length;
}
}
}
FloatBuffer[] floatBuffers = getBuffers(cubePositionData, cubeNormalData, textureCoordinateData, generatedCubeFactor * generatedCubeFactor * generatedCubeFactor);
FloatBuffer cubePositionsBuffer = floatBuffers[0];
FloatBuffer cubeNormalsBuffer = floatBuffers[1];
FloatBuffer cubeTextureCoordinatesBuffer = floatBuffers[2];
// Second, copy these buffers into OpenGL's memory. After, we don't need to keep the client-side buffers around.
final int buffers[] = new int[3];
GLES20.glGenBuffers(3, buffers, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubePositionsBuffer.capacity() * BYTES_PER_FLOAT, cubePositionsBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeNormalsBuffer.capacity() * BYTES_PER_FLOAT, cubeNormalsBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[2]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeTextureCoordinatesBuffer.capacity() * BYTES_PER_FLOAT, cubeTextureCoordinatesBuffer,
GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
mCubePositionsBufferIdx = buffers[0];
mCubeNormalsBufferIdx = buffers[1];
mCubeTexCoordsBufferIdx = buffers[2];
cubePositionsBuffer.limit(0);
cubePositionsBuffer = null;
cubeNormalsBuffer.limit(0);
cubeNormalsBuffer = null;
cubeTextureCoordinatesBuffer.limit(0);
cubeTextureCoordinatesBuffer = null;
}
public cubevba(int-generatedCubeFactor){
mActualCubeFactor=生成的立方因数;
最终浮点[]立方位置数据=新浮点[108*生成的立方因数*生成的立方因数*生成的立方因数];
int-cubePositionDataOffset=0;
final int segments=1;//generatedCubeFactor+(generatedCubeFactor-1);
最终浮动最小位置=-1.0f;
最终浮动最大位置=1.0f;
最终浮动位置范围=最大位置-最小位置;
最终浮动空间=1.0f;
int c=0;
对于(int x=0;x
第二种方法
public CubeVBOVBA(List<Vector3> cubeList) {
final float[] cubePositionData = new float[108 * cubeList.size()];
int cubePositionDataOffset = 0;
for (Vector3 placeMarker : cubeList) {
final float x1 = placeMarker.x - 1;
final float x2 = placeMarker.x + 1;
final float y1 = placeMarker.y - 1;
final float y2 = placeMarker.y + 1;
final float z1 = placeMarker.z - 1;
final float z2 = placeMarker.z + 1;
final float[] p1p = {x1, y2, z2};
final float[] p2p = {x2, y2, z2};
final float[] p3p = {x1, y1, z2};
final float[] p4p = {x2, y1, z2};
final float[] p5p = {x1, y2, z1};
final float[] p6p = {x2, y2, z1};
final float[] p7p = {x1, y1, z1};
final float[] p8p = {x2, y1, z1};
final float[] thisCubePositionData = ShapeBuilder.generateCubeData(p1p, p2p, p3p, p4p, p5p, p6p, p7p, p8p,
p1p.length);
System.arraycopy(thisCubePositionData, 0, cubePositionData, cubePositionDataOffset, thisCubePositionData.length);
cubePositionDataOffset += thisCubePositionData.length;
}
FloatBuffer[] floatBuffers = getBuffers(cubePositionData, cubeNormalData, textureCoordinateData, cubeList.size());
FloatBuffer cubePositionsBuffer = floatBuffers[0];
FloatBuffer cubeNormalsBuffer = floatBuffers[1];
FloatBuffer cubeTextureCoordinatesBuffer = floatBuffers[2];
// Second, copy these buffers into OpenGL's memory. After, we don't need to keep the client-side buffers around.
final int buffers[] = new int[3];
GLES20.glGenBuffers(3, buffers, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubePositionsBuffer.capacity() * BYTES_PER_FLOAT, cubePositionsBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeNormalsBuffer.capacity() * BYTES_PER_FLOAT, cubeNormalsBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[2]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeTextureCoordinatesBuffer.capacity() * BYTES_PER_FLOAT, cubeTextureCoordinatesBuffer,
GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
mCubePositionsBufferIdx = buffers[0];
mCubeNormalsBufferIdx = buffers[1];
mCubeTexCoordsBufferIdx = buffers[2];
cubePositionsBuffer.limit(0);
cubePositionsBuffer = null;
cubeNormalsBuffer.limit(0);
cubeNormalsBuffer = null;
cubeTextureCoordinatesBuffer.limit(0);
cubeTextureCoordinatesBuffer = null;
}
public void createText() {
cubeList2 = new CopyOnWriteArrayList<Vector3>();
int c = 0;
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
for (int k = 0; k < 30; k++) {
c ++;
Vector3 v = new Vector3(i, j, k);
cubeList2.add(v);
}
}
}
public cubevba(列表cubeList){
最终浮点[]立方位置数据=新浮点[108*cubeList.size()];
int-cubePositionDataOffset=0;
用于(矢量3位置标记:立方体列表){
最终浮点数x1=placeMarker.x-1;
最终浮点数x2=placeMarker.x+1;
最终浮点数y1=placeMarker.y-1;
最终浮点数y2=placeMarker.y+1;
最终浮点数z1=placeMarker.z-1;
最终浮点数z2=placeMarker.z+1;
最终浮点[]p1p={x1,y2,z2};
最终浮点[]p2p={x2,y2,z2};
最终浮点[]p3p={x1,y1,z2};
最终浮点[]p4p={x2,y1,z2};
最终浮点[]p5p={x1,y2,z1};
最终浮点[]p6p={x2,y2,z1};
最终浮点[]p7p={x1,y1,z1};
最终浮点[]p8p={x2,y1,z1};
最终浮点[]thisCubePositionData=ShapeBuilder.generateCubeData(p1p、p2p、p3p、p4p、p5p、p6p、p7p、p8p、,
p1p.长度);
System.arraycopy(thisCubePositionData,0,cubePositionData,cubePositionDataOffset,thisCubePositionData.length);
cubePositionDataOffset+=此CubePositionData.length;
}
FloatBuffer[]floatBuffers=getBuffers(cubePositionData、cubeNormalData、texturecoordinateddata、cubeList.size());
FloatBuffer立方位置buffer=floatBuffers[0];
FloatBuffer cubeNormalsBuffer=floatBuffers[1];
FloatBuffer CubeTextRecodationsBuffer=浮动缓冲区[2];
//其次,将这些缓冲区复制到OpenGL的内存中