[Tizen] Fix SVACE issue (initialize in constructor)
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-frame-buffer.cpp
index 44c00b0..61e043c 100644 (file)
@@ -48,12 +48,19 @@ FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
   mStencilBuffer( attachments & Dali::FrameBuffer::Attachment::STENCIL ),
   mWidth( width ),
   mHeight( height ),
-  mColorAttachmentCount( 0u )
+  mColorAttachmentCount( 0u ),
+  mRenderedBuffer( nullptr ),
+  mCaptureRenderedResult(false),
+  mCaptured(false)
 {
 }
 
 FrameBuffer::~FrameBuffer()
 {
+  if(mCaptured)
+  {
+    delete[] mRenderedBuffer;
+  }
 }
 
 void FrameBuffer::Destroy( Context& context )
@@ -120,6 +127,32 @@ void FrameBuffer::AttachColorTexture( Context& context, Render::Texture* texture
   context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
 }
 
+void FrameBuffer::AttachDepthTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  context.BindFramebuffer( GL_FRAMEBUFFER, mId );
+
+  // Create a depth attachment.
+  if( texture->GetType() == TextureType::TEXTURE_2D )
+  {
+    context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture->GetId(), mipmapLevel );
+  }
+
+  context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
+}
+
+void FrameBuffer::AttachDepthStencilTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  context.BindFramebuffer( GL_FRAMEBUFFER, mId );
+
+  // Create a depth/stencil attachment.
+  if( texture->GetType() == TextureType::TEXTURE_2D )
+  {
+    context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture->GetId(), mipmapLevel );
+  }
+
+  context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
+}
+
 void FrameBuffer::Bind( Context& context )
 {
   context.BindFramebuffer( GL_FRAMEBUFFER, mId );
@@ -135,6 +168,43 @@ uint32_t FrameBuffer::GetHeight() const
   return mHeight;
 }
 
+void FrameBuffer::DrawRenderedBuffer(Context& context)
+{
+  if(!mCaptureRenderedResult)
+  {
+    return;
+  }
+
+  if(mCaptured)
+  {
+    delete[] mRenderedBuffer;
+  }
+
+  context.BindFramebuffer(GL_FRAMEBUFFER, mId);
+  mRenderedBuffer = new GLubyte[mWidth * mHeight * sizeof(GL_UNSIGNED_BYTE)];
+  context.ReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, mRenderedBuffer);
+  context.BindFramebuffer(GL_FRAMEBUFFER, 0);
+  mCaptureRenderedResult = false;
+  mCaptured = true;
+}
+
+GLubyte* FrameBuffer::GetRenderedBuffer()
+{
+  if(mCaptured)
+  {
+    return mRenderedBuffer;
+  }
+  else
+  {
+    return nullptr;
+  }
+}
+
+void FrameBuffer::CaptureRenderingResult()
+{
+  mCaptureRenderedResult = true;
+}
+
 
 } //Render