#define DALI_INTERNAL_RENDER_TEXTURE_H
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
*/
// EXTERNAL INCLUDES
+#include <cstdint> // uint16_t, uint32_t
#include <string>
// INTERNAL INCLUDES
-#include <dali/devel-api/rendering/sampler.h>
-#include <dali/devel-api/rendering/texture.h>
+#include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
+#include <dali/public-api/rendering/sampler.h>
+#include <dali/public-api/rendering/texture.h>
+
+#include <dali/graphics-api/graphics-controller.h>
+#include <dali/graphics-api/graphics-texture-create-info.h>
+#include <dali/graphics-api/graphics-texture.h>
+#include <dali/graphics-api/graphics-types.h>
#include <dali/internal/event/rendering/texture-impl.h>
-#include <dali/integration-api/resource-declarations.h>
-
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/integration-api/gl-defines.h>
#include <dali/internal/render/renderers/render-sampler.h>
namespace Dali
{
struct Sampler;
-/**
- * This class is the mapping between texture id, sampler and sampler uniform name
- */
class Texture
{
public:
-
- /**
- * Enumeration to tell that this sampler does not have a unique index yet
- */
- enum
- {
- NOT_INITIALIZED = -1
- };
+ using Type = Dali::TextureType::Type;
/**
* Constructor
+ * @param[in] type The type of the texture
+ * @param[in] format The format of the pixel data
+ * @param[in] size The size of the texture
*/
- Texture()
- : mSampler( 0 ),
- mTextureId( Integration::InvalidResourceId )
- {}
+ Texture(Type type, Pixel::Format format, ImageDimensions size);
/**
- * Constructor
+ * Constructor from native image
+ * @param[in] nativeImageInterface The native image
*/
- Texture( Integration::ResourceId textureId, Render::Sampler* sampler )
- : mSampler( sampler ),
- mTextureId( textureId)
- {}
+ explicit Texture(NativeImageInterfacePtr nativeImageInterface);
/**
* Destructor
*/
- ~Texture()
- {}
-
- /*
- * Get the Render::Sampler used by the texture
- * @Return The Render::Sampler being used or 0 if using the default
- */
- inline const Render::Sampler* GetSampler() const
- {
- return mSampler;
- }
-
-public: // called from RenderThread
-
- /**
- * @param[in] buffer A vector wit
- * Get the texture ID
- * @return the id of the associated texture
- */
- inline Integration::ResourceId GetTextureId() const
- {
- return mTextureId;
- }
-
-private:
-
- Render::Sampler* mSampler;
- Integration::ResourceId mTextureId;
-};
-
-
-//TODO : Remove the old Render::Texture class (see above) once it is no longer needed by Image
-class NewTexture
-{
-public:
-
- typedef Dali::TextureType::Type Type;
-
- /**
- * Constructor
- * @param[in] type The type of the texture
- * @param[in] format The format of the pixel data
- * @param[in] width The width of the texture
- * @param[in] height The height of the texture
- */
- NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
+ ~Texture();
/**
- * Constructor from native image
- * @param[in] nativeImageInterface The native image
+ * Stores the graphics controller for use when required.
+ *
+ * @param[in] graphicsController The graphics controller to use
*/
- NewTexture( NativeImageInterfacePtr nativeImageInterface );
+ void Initialize(Graphics::Controller& graphicsController);
/**
- * Destructor
+ * Create the texture without a buffer
+ * @param[in] usage How texture will be used
*/
- ~NewTexture();
+ void Create(Graphics::TextureUsageFlags usage);
/**
- * Creates the texture in the GPU.
- * Creates the texture and reserves memory for the first mipmap level
- * @param[in] context The GL context
+ * Create a texture with a buffer if non-null
+ * @param[in] usage How texture will be used
+ * @param[in] buffer Buffer to copy
*/
- void Initialize(Context& context);
+ void CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* buffer, uint32_t bufferSize);
/**
* Deletes the texture from the GPU
- * @param[in] context The GL context
*/
- void Destroy( Context& context );
+ void Destroy();
/**
* Uploads data to the texture.
- * @param[in] context The GL context
* @param[in] pixelData A pixel data object
* @param[in] params Upload parameters. See UploadParams
*/
- void Upload( Context& context, PixelDataPtr pixelData, const Internal::NewTexture::UploadParams& params );
-
- /**
- * Bind the texture to the given texture unit and applies the given sampler
- * @param[in] context The GL context
- * @param[in] textureUnit the texture unit
- * @param[in] sampler The sampler to be used with the texture
- * @return true if the bind succeeded, false otherwise
- */
- bool Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
+ void Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params);
/**
* Auto generates mipmaps for the texture
- * @param[in] context The GL context
*/
- void GenerateMipmaps( Context& context );
+ void GenerateMipmaps();
/**
- * Retrieve wheter the texture has an alpha channel
+ * Retrieve whether the texture has an alpha channel
* @return True if the texture has alpha channel, false otherwise
*/
- bool HasAlphaChannel();
+ [[nodiscard]] bool HasAlphaChannel() const;
/**
- * Get the id of the texture
- * @return Id of the texture
+ * Get the graphics object associated with this texture
*/
- GLuint GetId()
- {
- return mId;
- }
+ [[nodiscard]] Graphics::Texture* GetGraphicsObject() const;
/**
- * Get the width of the texture
- * @return Width of the texture
- */
- unsigned int GetWidth() const
- {
- return mWidth;
- }
-
- /**
- * Get the height of the texture
- * @return Height of the texture
+ * Get the type of the texture
+ * @return Type of the texture
*/
- unsigned int GetHeight() const
+ [[nodiscard]] Type GetType() const
{
- return mHeight;
+ return mType;
}
/**
- * Get the type of the texture
- * @return Type of the texture
+ * Check if the texture is a native image
+ * @return if the texture is a native image
*/
- Type GetType() const
+ [[nodiscard]] bool IsNativeImage() const
{
- return mType;
+ return static_cast<bool>(mNativeImage);
}
private:
-
/**
* Helper method to apply a sampler to the texture
- * @param[in] context The GL context
* @param[in] sampler The sampler
*/
- void ApplySampler( Context& context, Render::Sampler* sampler );
-
- GLuint mId; ///<Id of the texture
- Type mType; ///<Type of the texture
- Render::Sampler mSampler; ///<The current sampler state
- NativeImageInterfacePtr mNativeImage; ///<Pointer to native image
- GLenum mInternalFormat; ///<The format of the pixel data
- GLenum mPixelDataType; ///<The data type of the pixel data
- unsigned int mWidth; ///<Widht of the texture
- unsigned int mHeight; ///<Height of the texture
- bool mHasAlpha : 1; ///<Whether the format has an alpha channel
- bool mIsCompressed : 1; ///<Whether the format is compressed
-};
+ void ApplySampler(Render::Sampler* sampler);
+
+private:
+ Graphics::Controller* mGraphicsController;
+ Graphics::UniquePtr<Graphics::Texture> mGraphicsTexture;
+ NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
+ Render::Sampler mSampler; ///< The current sampler state
+
+ Pixel::Format mPixelFormat; ///< Pixel format of the texture
+ uint16_t mWidth; ///< Width of the texture
+ uint16_t mHeight; ///< Height of the texture
+ Type mType : 3; ///< Type of the texture
+ bool mHasAlpha : 1; ///< Whether the format has an alpha channel
+};
} // namespace Render
} // namespace Dali
-
#endif // DALI_INTERNAL_RENDER_TEXTURE_H