X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-texture.h;h=d9192e0a945a1f78b70941cb05d7f7166289ad27;hb=649ec06daecb510fb84fe4642a6af957f127e7ab;hp=b9446b364d7753f859b74abdc38e5a8ee3e90c8f;hpb=6e055775829d43797b4e6935f0be4d1d5b501b32;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-texture.h b/dali/internal/render/renderers/render-texture.h index b9446b3..d9192e0 100644 --- a/dali/internal/render/renderers/render-texture.h +++ b/dali/internal/render/renderers/render-texture.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_RENDER_TEXTURE_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -21,8 +21,13 @@ #include // INTERNAL INCLUDES -#include -#include +#include // Dali::ImageDimensions +#include +#include +#include +#include +#include +#include namespace Dali { @@ -30,105 +35,133 @@ namespace Internal { namespace Render { -class Sampler; +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 - }; + 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] size The size of the texture */ - Texture() - : mSampler( 0 ), - mUniformName(), - mTextureId( Integration::InvalidResourceId ), - mUniformUniqueIndex( NOT_INITIALIZED ) - {} + Texture( Type type, Pixel::Format format, ImageDimensions size ); /** - * Constructor + * Constructor from native image + * @param[in] nativeImageInterface The native image */ - Texture( const std::string& samplerName, Integration::ResourceId textureId, Render::Sampler* sampler ) - : mSampler( sampler ), - mUniformName( samplerName ), - mTextureId( textureId), - mUniformUniqueIndex( NOT_INITIALIZED ) - {} + Texture( NativeImageInterfacePtr nativeImageInterface ); /** * Destructor */ - ~Texture() - {} + ~Texture(); - /* - * Get the Render::Sampler used by the texture - * @Return The Render::Sampler being used or 0 if using the default + /** + * Creates the texture in the GPU. + * Creates the texture and reserves memory for the first mipmap level + * @param[in] context The GL context */ - inline const Render::Sampler* GetSampler() const - { - return mSampler; - } + void Initialize( Context& context ); -public: // called from RenderThread + /** + * Deletes the texture from the GPU + * @param[in] context The GL context + */ + void Destroy( Context& context ); /** - * Get the texture unit uniform name - * @return the name of the texture unit uniform + * Called by RenderManager to inform the texture that the context has been destroyed */ - inline const std::string& GetUniformName() const - { - return mUniformName; - } + void GlContextDestroyed(); /** - * Get the texture ID - * @return the id of the associated texture + * 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 */ - inline Integration::ResourceId GetTextureId() const + void Upload( Context& context, PixelDataPtr pixelData, const Internal::Texture::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 ); + + /** + * Auto generates mipmaps for the texture + * @param[in] context The GL context + */ + void GenerateMipmaps( Context& context ); + + /** + * Retrieve wheter the texture has an alpha channel + * @return True if the texture has alpha channel, false otherwise + */ + bool HasAlphaChannel(); + + /** + * Get the id of the texture + * @return Id of the texture + */ + GLuint GetId() { - return mTextureId; + return mId; } /** - * Get the Uniform unique index - * @return the identity of the associated texture + * Get the type of the texture + * @return Type of the texture */ - inline void SetUniformUniqueIndex( int32_t index ) + Type GetType() const { - mUniformUniqueIndex = index; + return mType; } /** - * Get the Uniform unique index - * @return the identity of the associated texture + * Check if the texture is a native image + * @return if the texture is a native image */ - inline int32_t GetUniformUniqueIndex() const + bool IsNativeImage() const { - return mUniformUniqueIndex; + return mNativeImage; } private: - Render::Sampler* mSampler; - std::string mUniformName; - Integration::ResourceId mTextureId; - int32_t mUniformUniqueIndex; + /** + * 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 ); + + NativeImageInterfacePtr mNativeImage; ///< Pointer to native image + Render::Sampler mSampler; ///< The current sampler state + GLuint mId; ///< Id of the texture + GLuint mTarget; ///< Specifies the target to which the texture is bound. + GLint mGlInternalFormat; ///< The gl internal format of the pixel data + GLenum mGlFormat; ///< The gl format of the pixel data + GLenum mPixelDataType; ///< The data type of the pixel data + uint16_t mWidth; ///< Width of the texture + uint16_t mHeight; ///< Height of the texture + uint16_t mMaxMipMapLevel; ///< Maximum mipmap level + Type mType:2; ///< Type of the texture + bool mHasAlpha : 1; ///< Whether the format has an alpha channel + bool mIsCompressed : 1; ///< Whether the format is compressed }; + } // namespace Render } // namespace Internal