void Cube::bindColor(vec3 color) { bindColor(color, color, color, color, color, color); }
void GLframebuffer::bind(GLtarget* target) { m_boundTarget = target; if (!target) { unbind(); return; } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_object); if (m_boundTarget->isColorFormat()) { Sequence<GLenum> buffers; GLenum b = bindColor(m_boundTarget); buffers.push_back(b + GL_COLOR_ATTACHMENT0_EXT); for (int i = 0; i < Target::MAX_COLOR_ATTACHMENT; i++) { GLtarget* attached = m_boundTarget->getColorAttachedGL(i); if (!attached) { continue; } b = bindColor(attached); buffers.push_back(b + GL_COLOR_ATTACHMENT0_EXT); } if (buffers.size() == 1) { glDrawBuffer(buffers[0]); } else { glDrawBuffers(s2i(buffers.size()), &buffers[0]); } // attach depth and stencil GLtarget* depth = m_boundTarget->getDepthAttachedGL(); if (!depth) { depth = allocTarget(Target::TemporalAlloc, TexFormat::D24); } TexFormat tf = depth->getTextureGL()->getFormat(); bindDepth(depth); if (tf.isStencil()) { bindStencil(depth); } else { bindStencil(0); } #if 0 // attach color0 GLtexture* tex = m_boundTarget->getTextureGL(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, tex->getTarget(), tex->getObject(), 0); buffers.push_back(GL_COLOR_ATTACHMENT0_EXT); // attach color0~N for (int i = 0; i < Target::MAX_COLOR_ATTACHMENT; i++) { GLtarget* attached = m_boundTarget->getColorAttachedGL(i); if (!attached) { continue; } buffers.push_back(GL_COLOR_ATTACHMENT0_EXT + i + 1); GLtexture* tex = attached->getTextureGL(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i + 1, tex->getTarget(), tex->getObject(), 0); } glDrawBuffers(s2i(buffers.size()), &buffers[0]); // attach depth and stencil m_boundDepth = m_boundTarget->getDepthAttachedGL(); if (!m_boundDepth) { m_boundDepth = allocTarget(Target::TemporalAlloc, TexFormat::D24S8); } tex = m_boundDepth->getTextureGL(); TexFormat tf = tex->getFormat(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, tex->getTarget(), tex->getObject(), 0); if (tf.isStencil()) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, tex->getTarget(), tex->getObject(), 0); } else { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, tex->getTarget(), 0, 0); } #endif } else { // no color attach glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); // attach depth and stencil GLtarget* depth = m_boundTarget; TexFormat tf = depth->getTextureGL()->getFormat(); bindDepth(depth); if (tf.isStencil()) { bindStencil(depth); } else { bindStencil(0); } } // checkStatus(GL_FRAMEBUFFER_EXT); }