【问题标题】:Android - OpenGL FloatBuffer vs IntBufferAndroid - OpenGL FloatBuffer 与 IntBuffer
【发布时间】:2012-05-02 14:50:17
【问题描述】:

在大多数 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);

注意这两个例子中的计算是完全等价的,只是后面的版本只是简单地将结果四舍五入到最接近的整数。

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

【问题讨论】:

标签: android performance opengl-es


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多