2012-04-21 28 views
3

在大多數Android設備上,如果我使用整數而不是浮點數進行所有OpenGL頂點計算/渲染,我應該期望性能提高嗎?寬度,0:高度,而不是1:1,-1:Android - OpenGL FloatBuffer vs IntBuffer

我最近使用的0 OpenGL的視口轉換1,這樣我就可以用我所有的繪圖運算/緩衝器轉換成int類型,而不是浮動脫身如果它是可取的表現。

例如,如果我在我的應用程序中執行以下許多計算和渲染操作。

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類似的結果,然後渲染?

+0

見[這裏](http://stackoverflow.com/questions/4364879/integer-calculations-on-gpu)或[有](http://stackoverflow.com/questions/8683720/performance-of-integer - 和 - 按位操作上-GPU)。 – 2012-04-21 07:06:56

回答

5

大多數Android設備上,我應該期待的性能提升,如果我盡我的OpenGL頂點計算/在整數代替花車渲染?

不,你會看到沒有什麼區別。 GPU用於浮點運算。最有可能發生的是,您的整數在被上傳到GPU之前會轉換爲浮點數。整數函數在那裏是爲了方便,但它在渲染方面都是浮點數。