在大多数安卓设备上,如果我用整数(而不是浮点数)进行所有OpenGL顶点的计算/呈现,我是否应该期待性能的提高?
最近,我从使用0:宽度、0:高度(而不是-1:1,-1:1)的OpenGL视图端口切换,这样,如果性能需要,我可以将所有绘图计算/缓冲区转换为Ints,而不是浮点数。
例如,如果我在我的应用程序中执行以下许多类型的计算和呈现。
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,然后呈现出来的结果相似吗?
发布于 2012-04-21 06:15:03
在大多数安卓设备上,如果我用整数(而不是浮点数)进行所有的
顶点计算/呈现,我是否应该期待性能的提高?
不,你不会有什么区别的。GPU是专为浮点加工而制作的。最有可能发生的情况是,您的ints在上传到GPU之前就被转换为浮点数。整数函数是为了方便起见而存在的,但它都是呈现端的浮点。
https://stackoverflow.com/questions/10256041
复制相似问题