2013-07-31 24 views
1

這就是我OpenGL的文檔中找到:什麼是opengl當前頂點?

void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); 

GL_CURRENT_VERTEX_ATTRIB 
      params returns four 
     values that represent the current value for the 
     generic vertex attribute specified by index. Generic 
     vertex attribute 0 is unique in that it has no 
     current state, so an error will be generated if 
     index is 0. The initial value 
     for all other generic vertex attributes is 
     (0,0,0,1). 
      glGetVertexAttribdv and glGetVertexAttribfv 
      return the current attribute values as four single-precision floating-point values; 
      glGetVertexAttribiv reads them as floating-point values and 
      converts them to four integer values; glGetVertexAttribIiv and 
      glGetVertexAttribIuiv read and return them as signed or unsigned 
      integer values, respectively; glGetVertexAttribLdv reads and returns 
      them as four double-precision floating-point values. 

但我的問題是,我不知道當前頂點是什麼。我如何設置當前頂點?我可以用它來測試天氣我發送給opengl的屬性是否包含正確的數據?

+0

您使用的是桌面OpenGL還是OpenGL ES? –

+0

我認爲你有一些語義混淆。沒有當前的「頂點」,而是頂點屬性狀態。所以如果寫成英文句子,這將是「OpenGL,請給我一個通用頂點屬性的當前狀態(一個字,而不是兩個)。」 – datenwolf

+0

實際上我使用Desktop OpenGl。但這裏有關係嗎?我不得不添加一些標籤,但是失去了更多的創意。 @datenwolf不,我很舒服我的問題是正確的,因爲這是一個問題。給我一個答案,告訴我如何正確的定義是有效的。 – Arne

回答

2

glGetVertexAttrib返回與通用頂點屬性相關聯的值,該值可以使用glVertexAttrib函數進行設置。

更詳細地,有兩種類型的屬性可用在OpenGL:

  1. 那些從繪圖調用(例如,glDrawArrays)被執行時所處理的啓用頂點數組更新的每一個頂點。
  2. 那些類似於着色器制服,它們用於爲沒有關聯的,啓用的集合頂點數組的屬性提供值。

例如,假設您啓用兩個數組用於使用glVertexAttribPointer,並glEnableVertexAttribArray作爲頂點屬性,然後通過調用glDrawArrays(GL_POINTS, 0, NumPoints)渲染。在這種情況下,綁定的頂點着色器將被執行NumPoints次,每次從兩個數組中的每一箇中讀取一個新值。但是,如果只在數組上啓用(例如,頂點數組爲零),則可以使用glVertexAttrib函數爲屬性1設置屬性值。如果您再次通過調用glDrawArrays(GL_POINTS, 0, NumPoints)進行渲染,頂點着色器將再次執行NumPoints次,其中屬性零的值將使用啓用的頂點屬性數組中的值進行更新,但屬性值的值爲「常量」,並設置爲由glVertexAttrib

+0

所以這意味着我總是可以使用屬性而不是制服?那麼,制服特別是什麼呢? – Arne

+0

統一體可用於着色器程序中定義的所有着色器(即,頂點,細分控制,曲面細分評估,幾何,計算和片段)。這些屬性僅在頂點着色器階段中可用。 – radical7

+0

謝謝。我還發現,制服綁定到當前活動的程序,而頂點屬性數組綁定到頂點數組對象。 glVertexAttrib是否也綁定到VertexArrayObject? – Arne