ios - glGetAttribLocation 与 glBindAttribLocation
<p><p>在 iOS 设备上绑定(bind)属性是否明智(以及如何选择要绑定(bind)的索引号)?在我的应用程序中,我有几个着色器,跟踪所有属性/制服变得很麻烦。但我读过 <a href="http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php" rel="noreferrer noopener nofollow">nVidia imposes restrictions</a>关于索引,这让我认为 <code>glBindAttribLocation</code> 通常应该避免。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我发现管理属性和制服的最佳方法是拥有一个枚举</p>
<pre><code>enum
{
UNIFORM_MODELVIEWPROJECTION_MATRIX,
UNIFORM_NORMAL_MATRIX,
UNIFORM_VEC3_lightPosition,
UNIFORM_VEC4_lightDiffuseColour,
UNIFORM_VEC4_lightSpecularColour,
UNIFORM_VEC4_lightAmbientColour,
UNIFORM_VEC3_lightHalfVector,
UNIFORM_Texture,
UNIFORM_VEC4_NumberColour,
UNIFORM_VEC4_FaceColour,
UNIFORM_VEC4_camerPosition,
NUM_UNIFORMS
};
GLint uniforms;
</code></pre>
<p>然后当你初始化你的着色器时</p>
<pre><code>// Get uniform locations.
uniforms = glGetUniformLocation(Program, "modelViewProjectionMatrix");
uniforms = glGetUniformLocation(Program, "normalMatrix");
uniforms = glGetUniformLocation(Program, "lightPosition");
//etc
</code></pre>
<p>然后在使用它们时</p>
<pre><code>glUniformMatrix4fv(uniforms, 1, 0, modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms, 1, 0, normalMatrix.m);
//etc
</code></pre>
<p>不确定这是否是您真正要问的,但它仍然很有用。</p></p>
<p style="font-size: 20px;">关于ios - glGetAttribLocation 与 glBindAttribLocation,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13740147/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13740147/
</a>
</p>
页:
[1]