3

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

我最近从使用 0:width、0:height 而不是 -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);

这可以通过更改为类似的东西来加速吗

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);

请注意,这两个示例中的计算将完全等效,只是后面的版本会将结果简单地四舍五入到最接近的 int。

一个相关的问题是,如果我的视口是从 0 到宽度,从 0 到高度(以像素为单位),我是否会通过这种舍入来降低渲染的平滑度。也就是说,如果我用浮点值绘制一条线,OpenGL 将浮点数“四舍五入”到最近的像素是否会产生与四舍五入到最近的 int 然后渲染类似的结果?

4

1 回答 1

6

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

不,你不会看到任何区别。GPU 专为浮点运算而设计。最有可能发生的情况是,您的 int 在上传到 GPU 之前就已转换为浮点数。整数函数是为了方便起见,但在渲染端都是浮点数。

于 2012-04-21T06:15:03.017 回答