mController.AddFramebuffer(*this);
}
+Framebuffer::~Framebuffer() = default;
+
bool Framebuffer::InitializeResource()
{
- if(!mInitialized)
+ auto context = mController.GetCurrentContext();
+ auto gl = mController.GetGL();
+ if(gl && context && !mInitialized)
{
mInitialized = true;
- auto gl = mController.GetGL();
- gl->GenFramebuffers(1, &mFramebufferId);
- gl->BindFramebuffer(GL_FRAMEBUFFER, mFramebufferId);
+ context->GenFramebuffers(1, &mFramebufferId);
+ context->BindFrameBuffer(GL_FRAMEBUFFER, mFramebufferId);
for(Graphics::ColorAttachment& attachment : mCreateInfo.colorAttachments)
{
}
// @todo is this per framebuffer, or more immediate state that needs setting when framebuffer changed?
- gl->DrawBuffers(mCreateInfo.colorAttachments.size(), COLOR_ATTACHMENTS);
+ context->DrawBuffers(mCreateInfo.colorAttachments.size(), COLOR_ATTACHMENTS);
if(mCreateInfo.depthStencilAttachment.depthTexture)
{
AttachTexture(stencilTexture, attachmentId, 0, mCreateInfo.depthStencilAttachment.stencilLevel);
}
- gl->BindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ context->BindFrameBuffer(GL_FRAMEBUFFER, 0);
}
return mInitialized;
void Framebuffer::DestroyResource()
{
- auto gl = mController.GetGL();
- if(mInitialized)
+ auto context = mController.GetCurrentContext();
+ auto gl = mController.GetGL();
+ if(gl && context && mInitialized)
{
if(mDepthBufferId)
{
gl->DeleteRenderbuffers(1, &mStencilBufferId);
}
- gl->DeleteFramebuffers(1, &mFramebufferId);
+ context->DeleteFramebuffers(1, &mFramebufferId);
+
mFramebufferId = 0u;
mInitialized = false;
}
void Framebuffer::Bind() const
{
- auto gl = mController.GetGL();
- gl->BindFramebuffer(GL_FRAMEBUFFER, mFramebufferId);
+ auto context = mController.GetCurrentContext();
+ auto gl = mController.GetGL();
+
+ if(gl && context)
+ {
+ context->BindFrameBuffer(GL_FRAMEBUFFER, mFramebufferId);
+ }
}
void Framebuffer::AttachTexture(const Graphics::Texture* texture, uint32_t attachmentId, uint32_t layerId, uint32_t levelId)
{
- auto gl = mController.GetGL();
- auto graphicsTexture = static_cast<const GLES::Texture*>(texture);
- if(graphicsTexture->GetCreateInfo().textureType == Graphics::TextureType::TEXTURE_2D)
- {
- gl->FramebufferTexture2D(GL_FRAMEBUFFER, attachmentId, graphicsTexture->GetGlTarget(), graphicsTexture->GetGLTexture(), levelId);
- }
- else
+ auto gl = mController.GetGL();
+ if(gl)
{
- gl->FramebufferTexture2D(GL_FRAMEBUFFER, attachmentId, GL_TEXTURE_CUBE_MAP_POSITIVE_X + layerId, graphicsTexture->GetGLTexture(), levelId);
+ auto graphicsTexture = static_cast<const GLES::Texture*>(texture);
+ if(graphicsTexture->GetCreateInfo().textureType == Graphics::TextureType::TEXTURE_2D)
+ {
+ gl->FramebufferTexture2D(GL_FRAMEBUFFER, attachmentId, graphicsTexture->GetGlTarget(), graphicsTexture->GetGLTexture(), levelId);
+ }
+ else
+ {
+ gl->FramebufferTexture2D(GL_FRAMEBUFFER, attachmentId, GL_TEXTURE_CUBE_MAP_POSITIVE_X + layerId, graphicsTexture->GetGLTexture(), levelId);
+ }
}
}
+uint32_t Framebuffer::GetGlFramebufferId() const
+{
+ return mFramebufferId;
+}
+
+uint32_t Framebuffer::GetGlDepthBufferId() const
+{
+ return mDepthBufferId;
+}
+
+uint32_t Framebuffer::GetGlStencilBufferId() const
+{
+ return mStencilBufferId;
+}
+
} //namespace Dali::Graphics::GLES