opengl紋理單元_OpenGL

來源:互聯網
上載者:User

可以這樣簡單的理解為:顯卡中有N個紋理單元(具體數目依賴你的顯卡能力),每個紋理單元(GL_TEXTURE0、GL_TEXTURE1等)都有GL_TEXTURE_1D、GL_TEXTURE_2D等,如下代碼:

[cpp]  view plain  copy  print ? struct TextureUnit   {       GLuint targetTexture1D;       GLuint targetTexture2D;       GLuint targetTexture3D;       GLuint targetTextureCube;       ...   };       TextureUnit textureUnits[GL_MAX_TEXTURE_IMAGE_UNITS]   GLuint currentTextureUnit = 0;  

預設情況下當前活躍的紋理單元為0.

 

[cpp]  view plain  copy  print ? void glActiveTexture(GLenum textureUnit)   {       currentTextureUnit = textureUnit  - GL_TEXTURE0 ;   }  

glActiveTextue 並不是啟用紋理單元,而是選擇當前活躍的紋理單元。


[cpp]  view plain  copy  print ? void glBindTexture(GLenum textureTarget, GLuint textureObject)   {       TextureUnit *texUnit = &textureUnits[currentTextureUnit];       switch(textureTarget)       {       case GL_TEXTURE_1D: texUnit->targetTexture1D = textureObject; break;       case GL_TEXTURE_2D: texUnit->targetTexture2D = textureObject; break;       case GL_TEXTURE_3D: texUnit->targetTexture3D = textureObject; break;       case GL_TEXTURE_CUBEMAP: texUnit->targetTextureCube = textureObject; break;       }   }  
從範例程式碼中可以看到:當綁定紋理目標時,所作用的是當前活躍的紋理單元。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.