Android - OpenGL FloatBuffer与IntBuffer

khi*_*ner 3 performance android opengl-es

在大多数Android设备上,如果我用Integers而不是Floats进行所有OpenGL顶点计算/渲染,我是否应该期望性能提升?

我最近从使用0:宽度,0:高度而不是-1:1,-1:1的OpenGL视口切换,所以如果需要,我可以将所有绘图计算/缓冲区转换为Ints而不是Floats为了表现.

例如,如果我在我的应用程序中执行以下许多类型的计算和渲染.

float x1 = someFloatCalculation(foo);
float x2 = someFloatCalculation(bar);
float y1 = someOtherFloatCalculation(foo);
float y2 = someOtherFloatCalculation(bar);
// the float buffer for the coordinates
FloatBuffer buf = makeFloatBuffer(new float[] { x1, y1, x2, y1, x1,
                                                y2, x2, y2 });
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, buf);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
Run Code Online (Sandbox Code Playgroud)

可以通过改变类似的东西来加快速度

int x1 = someIntCalculation(foo);
int x2 = someIntCalculation(bar);
int y1 = someOtherIntCalculation(foo);
int y2 = someOtherIntCalculation(bar);
// the float buffer for the coordinates
IntBuffer buf = makeIntBuffer(new int[] { x1, y1, x2, y1, x1,
                                            y2, x2, y2 });
// GL10.GL_INT is not an existing GL10 constant.  What to use instead?
gl.glVertexPointer(2, ???GL10.GL_INT???, 0, buf);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
Run Code Online (Sandbox Code Playgroud)

请注意,两个示例中的计算完全相同,只是后者版本只是将结果舍入到最近的int.

一个相关的问题是,如果我的视口是从0到0和从0到高(以像素为单位),我是否会通过舍入来消除渲染中的任何平滑度.也就是说,如果我使用浮点值绘制一条直线,OpenGL将浮点数"舍入"到最近的像素会产生类似于舍入到最近的int然后渲染的结果吗?

Tim*_*Tim 6

在大多数Android设备上,如果我用Integers而不是Floats进行所有OpenGL顶点计算/渲染,我是否应该期望性能提升?

不,你会发现没有区别.GPU用于浮点运算.最有可能发生的是,在将整数上传到GPU之前,您的整数会转换为浮点数.整数函数是为了方便起见,但它在渲染方面都是浮点数.