vinjn / articles

Everything is possible
8 stars 0 forks source link

pitfalls_of_OpenGL #2

Open vinjn opened 11 years ago

vinjn commented 11 years ago

Some of them might be by design, but when it comes to real coding, it causes problems.

vinjn commented 11 years ago

http://stackoverflow.com/questions/2621013/how-to-create-a-fbo-with-stencil-buffer-in-opengl-es-2-0

In OpenGL ES 2.0 on iOS, you have to create a combined depth and stencil renderbuffer using GL_DEPTH24_STENCIL8_OES, and then attach it to the bound framebuffer as both GL_DEPTH_ATTACHMENT and GL_STENCIL_ATTACHMENT.

glGenRenderbuffers(1, &depthStencilRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRenderbuffer);
vinjn commented 11 years ago

http://luugiathuy.com/2011/09/create-frame-buffer-object-opengl/

On PC

fbo+rbo

glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, inScreenWidth, inScreenHeight); ... glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRBO);

fbo+texture

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, inScreenWidth, inScreenHeight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); ... glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthStencilTexture, 0);