2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali/internal/render/renderers/render-frame-buffer.h>
21 #include <dali/internal/render/renderers/render-texture.h>
30 FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, Format format )
32 mDepthBuffer( (format == Dali::FrameBuffer::COLOR_DEPTH || format == Dali::FrameBuffer::COLOR_DEPTH_STENCIL ) ? 1u : 0u ),
33 mStencilBuffer( (format == Dali::FrameBuffer::COLOR_STENCIL || format == Dali::FrameBuffer::COLOR_DEPTH_STENCIL ) ? 1u : 0u ),
39 FrameBuffer::~FrameBuffer()
42 void FrameBuffer::Destroy( Context& context )
46 context.DeleteFramebuffers( 1, &mId );
50 void FrameBuffer::Initialize(Context& context)
52 context.GenFramebuffers( 1, &mId );
53 context.BindFramebuffer( GL_FRAMEBUFFER, mId );
57 //Create a depth render target
58 context.GenRenderbuffers(1, &mDepthBuffer );
59 context.BindRenderbuffer(GL_RENDERBUFFER, mDepthBuffer);
60 context.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, mWidth, mHeight);
61 context.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthBuffer);
66 //Create a stencil render target
67 context.GenRenderbuffers(1, &mStencilBuffer );
68 context.BindRenderbuffer(GL_RENDERBUFFER, mStencilBuffer);
69 context.RenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, mWidth, mHeight);
70 context.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mStencilBuffer );
73 context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
76 void FrameBuffer::AttachColorTexture( Context& context, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer )
78 context.BindFramebuffer( GL_FRAMEBUFFER, mId );
80 if( texture->GetType() == TextureType::TEXTURE_2D )
82 context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->GetId(), mipmapLevel );
86 context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer, texture->GetId(), mipmapLevel );
89 context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
92 void FrameBuffer::Bind( Context& context )
94 context.BindFramebuffer( GL_FRAMEBUFFER, mId );
97 unsigned int FrameBuffer::GetWidth() const
102 unsigned int FrameBuffer::GetHeight() const