#define DALI_INTERNAL_RENDER_FRAME_BUFFER_H
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
* limitations under the License.
*/
-
// INTERNAL INCLUDES
-#include <dali/devel-api/rendering/frame-buffer.h>
-#include <dali/integration-api/resource-declarations.h>
-
+#include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/devel-api/rendering/frame-buffer-devel.h>
#include <dali/internal/render/gl-resources/context.h>
-#include <dali/integration-api/gl-defines.h>
#include <dali/internal/render/renderers/render-sampler.h>
+#include <dali/integration-api/gl-defines.h>
namespace Dali
{
+using Mask = Dali::FrameBuffer::Attachment::Mask;
+
namespace Internal
{
namespace Render
{
-class NewTexture;
+class Texture;
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
*/
- FrameBuffer( unsigned int width, unsigned int height, Format format );
+ FrameBuffer( uint32_t width, uint32_t height, Mask attachments );
/**
* Destructor
*/
- ~FrameBuffer();
+ virtual ~FrameBuffer();
/**
* Creates a FrameBuffer object in the GPU.
* @param[in] context The GL context
*/
- void Initialize(Context& context);
+ virtual void Initialize( Context& context );
/**
* Deletes the framebuffer object from the GPU
* @param[in] context The GL context
*/
- void Destroy( Context& context );
+ virtual void Destroy( Context& context );
/**
- * @brief Attach a texture for color rendering
- * 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
- * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
+ * Called by RenderManager to inform the framebuffer that the context has been destroyed
*/
- void AttachColorTexture( Context& context, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer );
+ virtual void GlContextDestroyed();
/**
* @brief Bind the framebuffer
* @param[in] context The GL context
*/
- void Bind( Context& context );
+ virtual void Bind( Context& context );
/**
* @brief Get the width of the FrameBuffer
* @return The width of the framebuffer
*/
- unsigned int GetWidth() const;
+ virtual uint32_t GetWidth() const;
/**
* @brief Get the height of the FrameBuffer
* @return The height of the framebuffer
*/
- unsigned int GetHeight() const;
+ virtual uint32_t GetHeight() const;
+
+ /**
+ * @brief Attaches a texture for the color rendering. This API is valid only for frame buffer 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
+ * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
+ * @note A maximum of Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS are supported.
+ */
+ void AttachColorTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
+
+ /**
+ * @brief Attaches a texture for the depth rendering. This API is valid only for frame buffer with DEPTH 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
+ */
+ void AttachDepthTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel );
+
+ /**
+ * @brief Attaches a texture for the depth/stencil rendering. This API is valid only for frame buffer with DEPTH_STENCIL 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
+ */
+ void AttachDepthStencilTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel );
+
+ /**
+ * @brief Get the number of textures bound to this frame buffer as color attachments.
+ * @return The number of color attachments.
+ */
+ uint8_t GetColorAttachmentCount() const { return mColorAttachmentCount; }
+
+ /**
+ * @brief Get the id (OpenGL handle) of the texture bound to this frame buffer as color attachment @a index.
+ * @return The texture id.
+ */
+ GLuint GetTextureId(uint8_t index) { return mTextureId[index]; };
+
+private:
+
+ /**
+ * @brief Undefined copy constructor. FrameBuffer cannot be copied
+ */
+ FrameBuffer( const FrameBuffer& rhs ) = delete;
+
+ /**
+ * @brief Undefined assignment operator. FrameBuffer cannot be copied
+ */
+ FrameBuffer& operator=( const FrameBuffer& rhs ) = delete;
private:
GLuint mId;
+ GLuint mTextureId[ Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS ];
GLuint mDepthBuffer;
GLuint mStencilBuffer;
- unsigned int mWidth;
- unsigned int mHeight;
+ uint32_t mWidth;
+ uint32_t mHeight;
+ uint8_t mColorAttachmentCount;
};
-
} // namespace Render
} // namespace Internal
} // namespace Dali
-#endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H
+#endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H