VBO:顶点缓冲,也就是说把顶点的存储在 显卡中开辟内存,提高传递的效率。也可以说叫顶点坐标的 缓冲区。
//创建vboglGenBuffers(1,&_vbo);//绑定vboglBindBuffer(GL_ARRAY_BUFFER,_vbo);//copy数据到显存//// GL_STREAM_DRAW 不经常变化//GL_STATIC_DRAW 常量//GL_DYNAMIC_DRAW 经常变化glBufferData(GL_ARRAY_BUFFER,sizeof(vertexs),vertexs,GL_STATIC_DRAW);//修改部分数据//glBufferSubData() //绑定完之后 恢复状态glBindBuffer(GL_ARRAY_BUFFER,0);
使用:
//使用绑定的vboglBindBuffer(GL_ARRAY_BUFFER,_vbo);//绘制过程//关闭vbo glBindBuffer(GL_ARRAY_BUFFER,0);
IBO:索引缓冲,按照索引进行连接,提高效率。按照索引去
画 图形。创建
glGenBuffers(1,&_indexbo);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_indexbo);glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(indexBuf),indexBuf,GL_STATIC_DRAW);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
使用
//开启 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_indexbo);//绘制 使用 glDrawElements进行索引绘制//关闭glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
FBO:帧缓存,将我们需要绘制的物体,会知道纹理上,最后在把纹理绘制一遍。这也叫离屏渲染。
FBO创建/开始使用/结束使用
virtual void beginFBO(unsigned FBOID,unsigned textureId){ glBindFramebuffer(GL_FRAMEBUFFER,FBOID); //把数据渲染到纹理 的0级上 glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,textureId,0);}virtual void endFBO(unsigned FBOID,unsigned textureId){ glBindFramebuffer(GL_FRAMEBUFFER,0);}virtual std::pair(unsigned,unsigned) createFBO(int width ,int height) { std::pair(unsigned,unsigned) buf; //unsigned FBOID; //unsigned RBOID; //生产1个帧buffer glGenFramebuffers(1,&buf.first); //绑定framebuffer glBindFramebuffer(GL_FRAMEBUFFER,buf.first); //产生render buffer glGenRenderbuffers(1,&buf.second); //绑定render buffer glBindFramebuffer(GL_RENDERBUFFER,buf.second); //指明缓冲区存储内容 glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,width,height); //关闭render buffer glBindFramebuffer(GL_RENDERBUFFER,0); //关联 glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,buf.second); //关闭frame buffer glBindFramebuffer(GL_FRAMEBUFFER,0); return buf; }
使用的伪代码
createFBO(); onrender { beginFBO(); { //所有的绘制都 绘制到了纹理上 } endFBO(); shader.bgein(); //画FBO纹理 shader.end(); }