iOS开发-OpenGLES 入门的大杂烩
熊猫镇楼
理解下上图的元素,总共有6个顶点,一张贴图。
纹理贴上去的规则是什么?
每个顶点都有纹理坐标,按照纹理坐标对应在图片上面有一个点,三个点形成一个三角形,从纹理(图片)上面切下来。
表示顶点可以用 (x、y、z、w)
表示纹理坐标用 (s、t、p、q)
glActiveTexture(GL_TEXTURE0); glBindTexture(tex0); glActiveTexture(GL_TEXTURE1); glBindTexture(tex1); 对应shader: "uniform sampler2D sTexture2;\n" "uniform sampler2D sTexture1;\n" 为uniform赋值的时候 l = glGetUniformLocation(u, "sTexture1"); glUniform1i(l, 0);// 代表GL_TEXTURE0 l = glGetUniformLocation(u, "sTexture2"); glUniform1i(l, 1);
这样使用sTexture1的时候用的就是tex0,使用sTexture2的时候用的就是tex1。
【颜色缓冲区】
颜色缓冲区(COLOR_BUFFER)就是帧缓冲区(FRAME_BUFFER),你需要渲染的场景最终每一个像素都要写入该缓冲区,然后由它在渲染到屏幕上显示.
【深度缓冲区】
深度缓冲区(DEPTH_BUFFER)与帧缓冲区对应,用于记录上面每个像素的深度值,通过深度缓冲区,我们可以进行深度测试,从而确定像素的遮挡关系,保证渲染正确.
【模板缓冲区】
OC代码 GLuint position = glGetAttribLocation(self.myProgram, "position3"); position = glGetAttribLocation(self.myProgram, "position"); position = glGetAttribLocation(self.myProgram, "position3"); position = glGetAttribLocation(self.myProgram, "position2"); position = glGetAttribLocation(self.myProgram, "position1"); position = glGetAttribLocation(self.myProgram, "position"); glsl文件 attribute vec4 position; attribute vec4 position1; attribute vec4 position2; attribute vec4 position3; void main() { gl_Position = position3 + vec4(0.1, 0.1, 0.1, 0); gl_Position = position2 + vec4(0.1, 0.1, 0.1, 0); // gl_Position = position1 + vec4(0.1, 0.1, 0.1, 0); gl_Position = position + vec4(0.1, 0.1, 0.1, 0); }
position的数值,如果有用到那么会那么会有对应的顶点的编号;如果没用到(position1),那么返回值为-1.
If you are reusing the same data in multiple frames, using glBufferData
as part of your setup/initialization will transfer data from the CPU to the GPU only once. Whereas glVertexAttribPointer
must be called every frame, so using it to transfer data results in using a lot more bus bandwidth.
If you're updating the attribute array every frame, there's not much advantage one way or the other.
顶点属性就是顶点shader里面声明的一个attribute变量,有两种类型的attribute变量,一种是const属性,一种是顶点属性数组