From 8d88b3be741a3907eae18b7274406a22f2fdad9c Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 28 Jul 2016 14:11:57 +0100 Subject: [PATCH] FrameBuffer::Format changed to bit-mask Attachment: Core Change-Id: I894a703dc8de36cc052fc958693842fc33b208f8 --- automated-tests/src/dali/utc-Dali-CameraActor.cpp | 1 - automated-tests/src/dali/utc-Dali-FrameBuffer.cpp | 64 ++++++++++++++++++---- automated-tests/src/dali/utc-Dali-RenderTask.cpp | 4 +- .../internal/event/rendering/frame-buffer-impl.cpp | 24 ++++---- dali/internal/event/rendering/frame-buffer-impl.h | 24 ++++---- .../render/renderers/render-frame-buffer.cpp | 29 +++++----- .../render/renderers/render-frame-buffer.h | 10 ++-- dali/public-api/rendering/frame-buffer.cpp | 4 +- dali/public-api/rendering/frame-buffer.h | 33 +++++++---- 9 files changed, 120 insertions(+), 73 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-CameraActor.cpp b/automated-tests/src/dali/utc-Dali-CameraActor.cpp index 78072fe..6c639fc 100644 --- a/automated-tests/src/dali/utc-Dali-CameraActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CameraActor.cpp @@ -349,7 +349,6 @@ int UtcDaliCameraActorGetFieldOfViewN(void) END_TEST; } -//todor int UtcDaliCameraActorSetAspectRatioP(void) { TestApplication application; diff --git a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp index 3eac9ab..f0e295b 100644 --- a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp @@ -38,7 +38,7 @@ int UtcDaliFrameBufferNew01(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); DALI_TEST_CHECK( frameBuffer ); @@ -58,7 +58,7 @@ int UtcDaliFrameBufferNew02(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH ); DALI_TEST_CHECK( frameBuffer ); @@ -78,7 +78,7 @@ int UtcDaliFrameBufferNew03(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_STENCIL ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::STENCIL ); DALI_TEST_CHECK( frameBuffer ); @@ -98,7 +98,7 @@ int UtcDaliFrameBufferNew04(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH_STENCIL ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL ); DALI_TEST_CHECK( frameBuffer ); @@ -120,13 +120,33 @@ int UtcDaliFrameBufferNew05(void) END_TEST; } +int UtcDaliFrameBufferNew06(void) +{ + TestApplication application; + + unsigned int width(64); + unsigned int height(64); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL ); + + DALI_TEST_CHECK( frameBuffer ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION); + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION); + + END_TEST; +} + int UtcDaliFrameBufferCopyConstructor(void) { TestApplication application; unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); FrameBuffer frameBufferCopy( frameBuffer ); @@ -141,7 +161,7 @@ int UtcDaliFrameBufferAssignmentOperator(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); FrameBuffer frameBuffer2; DALI_TEST_CHECK( !frameBuffer2 ); @@ -157,7 +177,7 @@ int UtcDaliFrameBufferDownCast01(void) TestApplication application; unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); BaseHandle handle(frameBuffer); FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle); @@ -182,7 +202,7 @@ int UtcDaliFrameBufferAttachColorTexture01(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH_STENCIL ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL ); Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); frameBuffer.AttachColorTexture( texture ); @@ -202,7 +222,7 @@ int UtcDaliFrameBufferAttachColorTexture02(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); texture.GenerateMipmaps(); @@ -225,7 +245,7 @@ int UtcDaliFrameBufferAttachColorTexture03(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height ); texture.GenerateMipmaps(); @@ -242,13 +262,33 @@ int UtcDaliFrameBufferAttachColorTexture03(void) END_TEST; } +int UtcDaliFrameBufferAttachColorTexture04(void) +{ + TestApplication application; + + unsigned int width(64); + unsigned int height(64); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL ); + Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); + frameBuffer.AttachColorTexture( texture ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION); + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION); + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION); + + END_TEST; +} + int UtcDaliFrameBufferGetColorTexture01(void) { TestApplication application; unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); frameBuffer.AttachColorTexture( texture ); @@ -263,7 +303,7 @@ int UtcDaliFrameBufferGetColorTexture02(void) unsigned int width(64); unsigned int height(64); - FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR ); + FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); frameBuffer.AttachColorTexture( texture, 0u, 1u ); diff --git a/automated-tests/src/dali/utc-Dali-RenderTask.cpp b/automated-tests/src/dali/utc-Dali-RenderTask.cpp index d71463c..647594f 100644 --- a/automated-tests/src/dali/utc-Dali-RenderTask.cpp +++ b/automated-tests/src/dali/utc-Dali-RenderTask.cpp @@ -1144,7 +1144,7 @@ int UtcDaliRenderTaskSetFrameBufferP(void) RenderTask task = taskList.GetTask( 0u ); - FrameBuffer newFrameBuffer = FrameBuffer::New( 128u, 128u, FrameBuffer::COLOR ); + FrameBuffer newFrameBuffer = FrameBuffer::New( 128u, 128u, FrameBuffer::Attachment::NONE ); task.SetFrameBuffer( newFrameBuffer ); DALI_TEST_CHECK( task.GetFrameBuffer() == newFrameBuffer ); END_TEST; @@ -1175,7 +1175,7 @@ int UtcDaliRenderTaskGetFrameBufferP(void) RenderTask task = taskList.GetTask( 0u ); - FrameBuffer newFrameBuffer = FrameBuffer::New( 1u, 1u, FrameBuffer::COLOR ); + FrameBuffer newFrameBuffer = FrameBuffer::New( 1u, 1u, FrameBuffer::Attachment::NONE ); task.SetFrameBuffer( newFrameBuffer ); DALI_TEST_CHECK( task.GetFrameBuffer() == newFrameBuffer ); END_TEST; diff --git a/dali/internal/event/rendering/frame-buffer-impl.cpp b/dali/internal/event/rendering/frame-buffer-impl.cpp index 366a8cb..e9a1819 100644 --- a/dali/internal/event/rendering/frame-buffer-impl.cpp +++ b/dali/internal/event/rendering/frame-buffer-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,9 @@ namespace Dali namespace Internal { -FrameBufferPtr FrameBuffer::New( unsigned int width, unsigned int height, Format format ) +FrameBufferPtr FrameBuffer::New( unsigned int width, unsigned int height, unsigned int attachments ) { - FrameBufferPtr frameBuffer( new FrameBuffer( width, height, format ) ); + FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) ); frameBuffer->Initialize(); return frameBuffer; } @@ -41,33 +41,33 @@ Render::FrameBuffer* FrameBuffer::GetRenderObject() const return mRenderObject; } -FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, Format format ) +FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments ) : mEventThreadServices( *Stage::GetCurrent() ), mRenderObject( NULL ), - mColor(NULL), + mColor( NULL ), mWidth( width ), mHeight( height ), - mFormat( format ) + mAttachments( attachments ) { } void FrameBuffer::Initialize() { - mRenderObject = new Render::FrameBuffer( mWidth, mHeight, mFormat ); + mRenderObject = new Render::FrameBuffer( mWidth, mHeight, mAttachments ); AddFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject ); } void FrameBuffer::AttachColorTexture( NewTexturePtr texture, unsigned int mipmapLevel, unsigned int layer ) { - if( (unsigned int)(texture->GetWidth() / (1<GetHeight() / (1<GetWidth() / ( 1 << mipmapLevel ) ) == mWidth && + (unsigned int)( texture->GetHeight() / ( 1 << mipmapLevel ) ) == mHeight ) { - DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" ); + mColor = texture; + AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer ); } else { - mColor = texture; - AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer ); + DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" ); } } diff --git a/dali/internal/event/rendering/frame-buffer-impl.h b/dali/internal/event/rendering/frame-buffer-impl.h index f15b4bd..bf7f42f 100644 --- a/dali/internal/event/rendering/frame-buffer-impl.h +++ b/dali/internal/event/rendering/frame-buffer-impl.h @@ -42,17 +42,15 @@ class FrameBuffer : public BaseObject { public: - typedef Dali::FrameBuffer::Format Format; - /** * @brief Create a new FrameBuffer * - * @param[in] width The width of the FrameBuffer - * @param[in] height The height of the FrameBuffer - * @param[in] format The format of the FrameBuffer + * @param[in] width The width of the FrameBuffer + * @param[in] height The height of the FrameBuffer + * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask) * @return A smart-pointer to the newly allocated Texture. */ - static FrameBufferPtr New( unsigned int width, unsigned int height, Format format ); + static FrameBufferPtr New( unsigned int width, unsigned int height, unsigned int attachments ); /** * @brief Get the FrameBuffer render object @@ -75,11 +73,11 @@ private: // implementation /** * Constructor - * @param[in] width The width of the FrameBuffer - * @param[in] height The height of the FrameBuffer - * @param[in] format The format of the FrameBuffer + * @param[in] width The width of the FrameBuffer + * @param[in] height The height of the FrameBuffer + * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask) */ - FrameBuffer( unsigned int width, unsigned int height, Format format ); + FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments ); /** * Second stage initialization of the Texture @@ -99,13 +97,13 @@ private: // unimplemented methods private: // data - Internal::EventThreadServices& mEventThreadServices; /// -//INTERNAL INCLUDES +// INTERNAL INCLUDES #include namespace Dali @@ -27,10 +27,10 @@ namespace Internal namespace Render { -FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, Format format ) +FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments ) :mId( 0u ), - mDepthBuffer( (format == Dali::FrameBuffer::COLOR_DEPTH || format == Dali::FrameBuffer::COLOR_DEPTH_STENCIL ) ? 1u : 0u ), - mStencilBuffer( (format == Dali::FrameBuffer::COLOR_STENCIL || format == Dali::FrameBuffer::COLOR_DEPTH_STENCIL ) ? 1u : 0u ), + mDepthBuffer( attachments & Dali::FrameBuffer::Attachment::DEPTH ), + mStencilBuffer( attachments & Dali::FrameBuffer::Attachment::STENCIL ), mWidth( width ), mHeight( height ) { @@ -54,20 +54,20 @@ void FrameBuffer::Initialize(Context& context) if( mDepthBuffer ) { - //Create a depth render target - context.GenRenderbuffers(1, &mDepthBuffer ); - context.BindRenderbuffer(GL_RENDERBUFFER, mDepthBuffer); - context.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, mWidth, mHeight); - context.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthBuffer); + // Create a depth render target. + context.GenRenderbuffers( 1, &mDepthBuffer ); + context.BindRenderbuffer( GL_RENDERBUFFER, mDepthBuffer ); + context.RenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, mWidth, mHeight ); + context.FramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthBuffer ); } if( mStencilBuffer ) { - //Create a stencil render target - context.GenRenderbuffers(1, &mStencilBuffer ); - context.BindRenderbuffer(GL_RENDERBUFFER, mStencilBuffer); - context.RenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, mWidth, mHeight); - context.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mStencilBuffer ); + // Create a stencil render target. + context.GenRenderbuffers( 1, &mStencilBuffer ); + context.BindRenderbuffer( GL_RENDERBUFFER, mStencilBuffer ); + context.RenderbufferStorage( GL_RENDERBUFFER, GL_STENCIL_INDEX8, mWidth, mHeight ); + context.FramebufferRenderbuffer( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mStencilBuffer ); } context.BindFramebuffer( GL_FRAMEBUFFER, 0 ); @@ -77,6 +77,7 @@ void FrameBuffer::AttachColorTexture( Context& context, Render::NewTexture* text { context.BindFramebuffer( GL_FRAMEBUFFER, mId ); + // Create a color attachment. if( texture->GetType() == TextureType::TEXTURE_2D ) { context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->GetId(), mipmapLevel ); diff --git a/dali/internal/render/renderers/render-frame-buffer.h b/dali/internal/render/renderers/render-frame-buffer.h index 3c43453..e27e072 100644 --- a/dali/internal/render/renderers/render-frame-buffer.h +++ b/dali/internal/render/renderers/render-frame-buffer.h @@ -36,15 +36,13 @@ class FrameBuffer { public: - typedef Dali::FrameBuffer::Format Format; - /** * Constructor * @param[in] width The width of the FrameBuffer * @param[in] height The height of the FrameBuffer - * @param[in] format The format of the FrameBuffer + * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask) */ - FrameBuffer( unsigned int width, unsigned int height, Format format ); + FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments ); /** * Destructor @@ -64,7 +62,7 @@ public: void Destroy( Context& context ); /** - * @brief Attach a texture for color rendering + * @brief Attach a texture for color rendering. Valid only for Framebuffers with COLOR attachments. * param[in] context The GL context * @param[in] texture The texture that will be used as output when rendering * @param[in] mipmapLevel The mipmap of the texture to be attached @@ -107,4 +105,4 @@ private: } // namespace Dali -#endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H +#endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H diff --git a/dali/public-api/rendering/frame-buffer.cpp b/dali/public-api/rendering/frame-buffer.cpp index e6a2405..66d9976 100644 --- a/dali/public-api/rendering/frame-buffer.cpp +++ b/dali/public-api/rendering/frame-buffer.cpp @@ -25,9 +25,9 @@ namespace Dali { -FrameBuffer FrameBuffer::New( unsigned int width, unsigned int height, Format format ) +FrameBuffer FrameBuffer::New( unsigned int width, unsigned int height, unsigned int attachments ) { - Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, format ); + Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, attachments ); return FrameBuffer( frameBuffer.Get() ); } diff --git a/dali/public-api/rendering/frame-buffer.h b/dali/public-api/rendering/frame-buffer.h index 6e826de..8eb5e0e 100644 --- a/dali/public-api/rendering/frame-buffer.h +++ b/dali/public-api/rendering/frame-buffer.h @@ -39,15 +39,24 @@ class DALI_IMPORT_API FrameBuffer : public BaseHandle public: /** - * @brief Format of the FrameBuffer to be created. - * @SINCE_1_1.43 + * @brief The initial attachments to create the FrameBuffer with. + * @note The color attachment is created on calling AttachColorTexture(). If a color attachment is not required, omit this call. + * @note With "NONE", no attachments are created initially. However color attachments can still be added as described above. + * + * @SINCE_1_1.45 */ - enum Format + struct Attachment { - COLOR, ///< Framebuffer will be created with color buffer @SINCE_1_1.43 - COLOR_DEPTH, ///< Framebuffer will be created with color and depth buffer @SINCE_1_1.43 - COLOR_STENCIL, ///< Framebuffer will be created with color and stencil buffer @SINCE_1_1.43 - COLOR_DEPTH_STENCIL ///< Framebuffer will be created with color, depth and stencil buffer. @note May be not supported in all devices @SINCE_1_1.43 + enum Mask + { + NONE = 0, ///< No attachments are created initially @SINCE_1_1.45 + + DEPTH = 1 << 0, ///< Depth buffer bit-mask value @SINCE_1_1.45 + STENCIL = 1 << 1, ///< Stencil buffer bit-mask value @SINCE_1_1.45 + + // Preset bit-mask combinations: + DEPTH_STENCIL = DEPTH | STENCIL ///< The Framebuffer will be created with depth and stencil buffer @SINCE_1_1.45 + }; }; /** @@ -56,10 +65,10 @@ public: * @SINCE_1_1.43 * @param[in] width The width of the FrameBuffer * @param[in] height The height of the FrameBuffer - * @param[in] format The format of the FrameBuffer + * @param[in] attachments The attachments comprising the format of the FrameBuffer (the type is int to allow multiple bitmasks to be ORd). * @return A handle to a newly allocated FrameBuffer */ - static FrameBuffer New( unsigned int width, unsigned int height, Format format ); + static FrameBuffer New( unsigned int width, unsigned int height, unsigned int attachments ); /** * @brief Default constructor, creates an empty handle @@ -100,7 +109,8 @@ public: FrameBuffer& operator=( const FrameBuffer& handle ); /** - * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering + * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering. + * @note This causes a color attachment to be added. * * @SINCE_1_1.43 * @param[in] texture The texture that will be used as output when rendering @@ -110,7 +120,8 @@ public: void AttachColorTexture( Texture& texture ); /** - * @brief Attach a texture to the framebuffer for color rendering + * @brief Attach a texture to the framebuffer for color rendering. + * @note This causes a color attachment to be added. * * @SINCE_1_1.43 * @param[in] texture The texture that will be used as output when rendering -- 2.7.4