Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-OpenGL浮动缓冲区与IntBuffer_Android_Performance_Opengl Es - Fatal编程技术网

Android-OpenGL浮动缓冲区与IntBuffer

Android-OpenGL浮动缓冲区与IntBuffer,android,performance,opengl-es,Android,Performance,Opengl Es,在大多数Android设备上,如果我用整数而不是浮点数进行OpenGL顶点计算/渲染,我是否应该期望性能提高 我最近从使用0:width、0:height而不是-1:1、-1:1的OpenGL视口切换过来,因此如果性能需要,我可以将所有图形计算/缓冲区转换为int而不是float 例如,如果我在我的应用程序中执行以下许多类型的计算和渲染 float x1 = someFloatCalculation(foo); float x2 = someFloatCalculation(bar); floa

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

我最近从使用0:width、0:height而不是-1:1、-1:1的OpenGL视口切换过来,因此如果性能需要,我可以将所有图形计算/缓冲区转换为int而不是float

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

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将浮点值“舍入”到最近的像素是否会产生与舍入到最近的整数然后进行渲染类似的结果

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

不,你看不出有什么不同。GPU是为浮点运算而设计的。最有可能发生的情况是,你的整数在上传到GPU之前就被转换成浮点数。整数函数是为了方便起见而存在的,但它在渲染端都是浮点函数

看到或看到。