禁用顶点属性数组后 glDrawArrays() 如何工作?
After disabling Vertex Attribute Array how glDrawArrays() works?
我已经开始学习 android 的 Opengl ES 2.0。我正在使用从以下站点获取的代码段:
http://www.learnopengles.com/android-lesson-two-ambient-and-diffuse-lighting/
这是一个有 4 个数字的亮点:
private final float[] mLightPosInModelSpace = new float[] {0.0f, 0.0f, 0.0f, 1.0f};
这个灯点在模型 space 中。以下函数用于绘制禁用顶点属性数组的点。
private void drawLight()
{
final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");
// Pass in the position.
GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);
// Since we are not using a buffer object, disable vertex arrays for this attribute.
GLES20.glDisableVertexAttribArray(pointPositionHandle);
// Pass in the transformation matrix.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the point.
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
我从这里阅读了文档:https://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
并看到在启用顶点属性数组 glDrawArrays()
后从该启用的数组中获取点。但我的问题是 glDrawArrays()
从哪里得到积分?在此示例中,从 mLightPosInModelSpace
中获取观点可以正常工作。提前致谢。
参见 OpenGL ES 2.0 规范的第 2.7 节,“当前顶点状态”:
Current generic attribute values define generic attributes for a vertex when a
vertex array defining that data is not enabled, as described in section 2.8.
A current
value may be changed at any time by issuing one of the commands
void VertexAttrib{1234}{f}( uint index, T values );
void VertexAttrib{1234}{f}v( uint index, T values );
to load the given value(s) into the current generic attribute for slot index, whose
components are named x, y, z, and w.
然后在第 21 页,规范解释了它们是如何被拉动的:
If
an array corresponding to a generic attribute required by a vertex shader is not enabled,
then the corresponding element is taken from the current generic attribute
state (see section 2.7).
我已经开始学习 android 的 Opengl ES 2.0。我正在使用从以下站点获取的代码段: http://www.learnopengles.com/android-lesson-two-ambient-and-diffuse-lighting/ 这是一个有 4 个数字的亮点:
private final float[] mLightPosInModelSpace = new float[] {0.0f, 0.0f, 0.0f, 1.0f};
这个灯点在模型 space 中。以下函数用于绘制禁用顶点属性数组的点。
private void drawLight()
{
final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");
// Pass in the position.
GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);
// Since we are not using a buffer object, disable vertex arrays for this attribute.
GLES20.glDisableVertexAttribArray(pointPositionHandle);
// Pass in the transformation matrix.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the point.
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
我从这里阅读了文档:https://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
并看到在启用顶点属性数组 glDrawArrays()
后从该启用的数组中获取点。但我的问题是 glDrawArrays()
从哪里得到积分?在此示例中,从 mLightPosInModelSpace
中获取观点可以正常工作。提前致谢。
参见 OpenGL ES 2.0 规范的第 2.7 节,“当前顶点状态”:
Current generic attribute values define generic attributes for a vertex when a vertex array defining that data is not enabled, as described in section 2.8.
A current value may be changed at any time by issuing one of the commands
void VertexAttrib{1234}{f}( uint index, T values );
void VertexAttrib{1234}{f}v( uint index, T values );
to load the given value(s) into the current generic attribute for slot index, whose components are named x, y, z, and w.
然后在第 21 页,规范解释了它们是如何被拉动的:
If an array corresponding to a generic attribute required by a vertex shader is not enabled, then the corresponding element is taken from the current generic attribute state (see section 2.7).