}
// generate mipmaps for last FB if needed
if (lastFb != null) {
for (int i = 0; i < lastFb.getNumColorBuffers(); i++) {
RenderBuffer rb = lastFb.getColorBuffer(i);
Texture tex = rb.getTexture();
if (tex != null
&& tex.getMinFilter().usesMipMapLevels()) {
setTexture(0, rb.getTexture());
int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace());
glEnable(textureType);
glGenerateMipmapEXT(textureType);
glDisable(textureType);
}
}
}
if (fb == null) {
// unbind any fbos
if (context.boundFBO != 0) {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
statistics.onFrameBufferUse(null, true);
context.boundFBO = 0;
}
// select back buffer
if (context.boundDrawBuf != -1) {
glDrawBuffer(initialDrawBuf);
context.boundDrawBuf = -1;
}
if (context.boundReadBuf != -1) {
glReadBuffer(initialReadBuf);
context.boundReadBuf = -1;
}
lastFb = null;
} else {
if (fb.getNumColorBuffers() == 0 && fb.getDepthBuffer() == null) {
throw new IllegalArgumentException("The framebuffer: " + fb
+ "\nDoesn't have any color/depth buffers");
}
if (fb.isUpdateNeeded()) {
updateFrameBuffer(fb);
}
if (context.boundFBO != fb.getId()) {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb.getId());
statistics.onFrameBufferUse(fb, true);
// update viewport to reflect framebuffer's resolution
setViewPort(0, 0, fb.getWidth(), fb.getHeight());
context.boundFBO = fb.getId();
} else {
statistics.onFrameBufferUse(fb, false);
}
if (fb.getNumColorBuffers() == 0) {
// make sure to select NONE as draw buf
// no color buffer attached. select NONE
if (context.boundDrawBuf != -2) {
glDrawBuffer(GL_NONE);
context.boundDrawBuf = -2;
}
if (context.boundReadBuf != -2) {
glReadBuffer(GL_NONE);
context.boundReadBuf = -2;
}
} else {
if (fb.getNumColorBuffers() > maxFBOAttachs) {
throw new RendererException("Framebuffer has more color "
+ "attachments than are supported"
+ " by the video hardware!");
}
if (fb.isMultiTarget()) {
if (fb.getNumColorBuffers() > maxMRTFBOAttachs) {
throw new RendererException("Framebuffer has more"
+ " multi targets than are supported"
+ " by the video hardware!");
}
if (context.boundDrawBuf != 100 + fb.getNumColorBuffers()) {
intBuf16.clear();
for (int i = 0; i < fb.getNumColorBuffers(); i++) {
intBuf16.put(GL_COLOR_ATTACHMENT0_EXT + i);
}
intBuf16.flip();
glDrawBuffers(intBuf16);
context.boundDrawBuf = 100 + fb.getNumColorBuffers();
}
} else {
RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex());
// select this draw buffer
if (context.boundDrawBuf != rb.getSlot()) {
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
context.boundDrawBuf = rb.getSlot();
}
}
}
assert fb.getId() >= 0;