_parentRenderer.clearBuffers(clear);
}
@Override
protected void activate() {
final GL gl = GLContext.getCurrentGL();
// Lazy init
if (_fboID == 0) {
final IntBuffer buffer = BufferUtils.createIntBuffer(1);
// Create our texture binding FBO
gl.glGenFramebuffers(1, buffer); // generate id
_fboID = buffer.get(0);
// Create a depth renderbuffer to use for RTT use
gl.glGenRenderbuffers(1, buffer); // generate id
_depthRBID = buffer.get(0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, _depthRBID);
int format = GL2ES2.GL_DEPTH_COMPONENT;
if (_supportsDepthTexture && _depthBits > 0) {
switch (_depthBits) {
case 16:
format = GL.GL_DEPTH_COMPONENT16;
break;
case 24:
format = GL.GL_DEPTH_COMPONENT24;
break;
case 32:
format = GL.GL_DEPTH_COMPONENT32;
break;
default:
// stick with the "undefined" GL_DEPTH_COMPONENT
}
}
gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, format, _width, _height);
// unbind...
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, 0);
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
// If we support it, rustle up a multisample framebuffer + renderbuffers
if (_samples != 0 && _supportsMultisample) {
// create ms framebuffer object
gl.glGenFramebuffers(1, buffer);
_msfboID = buffer.get(0);
// create ms renderbuffers
gl.glGenRenderbuffers(1, buffer); // generate id
_mscolorRBID = buffer.get(0);
gl.glGenRenderbuffers(1, buffer); // generate id
_msdepthRBID = buffer.get(0);
// set up renderbuffer properties
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, _mscolorRBID);
gl.getGL2GL3().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, _samples, GL.GL_RGBA, _width,
_height);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, _msdepthRBID);
gl.getGL2GL3().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, _samples, format, _width, _height);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, 0);
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, _msfboID);
gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_RENDERBUFFER,
_mscolorRBID);
gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER,
_msdepthRBID);
// check for errors
checkFBOComplete(_msfboID);
// release
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
}
}
if (_active == 0) {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord record = context.getRendererRecord();
// needed as FBOs do not share this flag it seems
record.setClippingTestValid(false);
// push a delimiter onto the clip stack
_neededClip = _parentRenderer.isClipTestEnabled();
if (_neededClip) {
_parentRenderer.pushEmptyClip();
}
gl.glClearColor(_backgroundColor.getRed(), _backgroundColor.getGreen(), _backgroundColor.getBlue(),
_backgroundColor.getAlpha());
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, _fboID);
ContextManager.getCurrentContext().pushEnforcedStates();
ContextManager.getCurrentContext().clearEnforcedStates();
ContextManager.getCurrentContext().enforceStates(_enforcedStates);
}
_active++;