2 * Copyright (c) 2019 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-texture-frame-buffer.h>
21 #include <dali/internal/render/renderers/render-texture.h>
30 TextureFrameBuffer::TextureFrameBuffer( uint32_t width, uint32_t height, Mask attachments )
33 mDepthBuffer( attachments & Dali::FrameBuffer::Attachment::DEPTH ),
34 mStencilBuffer( attachments & Dali::FrameBuffer::Attachment::STENCIL ),
40 TextureFrameBuffer::~TextureFrameBuffer()
43 void TextureFrameBuffer::Destroy( Context& context )
47 context.DeleteFramebuffers( 1, &mId );
51 void TextureFrameBuffer::GlContextDestroyed()
56 void TextureFrameBuffer::Initialize(Context& context)
58 context.GenFramebuffers( 1, &mId );
59 context.BindFramebuffer( GL_FRAMEBUFFER, mId );
63 // Create a depth render target.
64 context.GenRenderbuffers( 1, &mDepthBuffer );
65 context.BindRenderbuffer( GL_RENDERBUFFER, mDepthBuffer );
66 context.RenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, mWidth, mHeight );
67 context.FramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthBuffer );
72 // Create a stencil render target.
73 context.GenRenderbuffers( 1, &mStencilBuffer );
74 context.BindRenderbuffer( GL_RENDERBUFFER, mStencilBuffer );
75 context.RenderbufferStorage( GL_RENDERBUFFER, GL_STENCIL_INDEX8, mWidth, mHeight );
76 context.FramebufferRenderbuffer( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mStencilBuffer );
79 context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
82 void TextureFrameBuffer::AttachColorTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer )
84 context.BindFramebuffer( GL_FRAMEBUFFER, mId );
86 // Create a color attachment.
87 if( texture->GetType() == TextureType::TEXTURE_2D )
89 if( !texture->IsNativeImage() )
91 context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->GetId(), mipmapLevel );
95 // If it's a native image we need to use GL_TEXTURE_EXTERNAL_OES as the texture target parameter
96 context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_EXTERNAL_OES, texture->GetId(), mipmapLevel );
101 context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer, texture->GetId(), mipmapLevel );
104 context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
107 void TextureFrameBuffer::Bind( Context& context )
109 context.BindFramebuffer( GL_FRAMEBUFFER, mId );
112 uint32_t TextureFrameBuffer::GetWidth() const
117 uint32_t TextureFrameBuffer::GetHeight() const