#define DALI_INTERNAL_RENDER_TEXTURE_H
/*
- * 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.
* limitations under the License.
*/
-#include <dali/devel-api/rendering/sampler.h>
-#include <dali/integration-api/resource-declarations.h>
+// EXTERNAL INCLUDES
#include <string>
+// INTERNAL INCLUDES
+#include <dali/public-api/rendering/sampler.h>
+#include <dali/public-api/rendering/texture.h>
+#include <dali/internal/event/rendering/texture-impl.h>
+#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/renderers/render-sampler.h>
+#include <dali/integration-api/gl-defines.h>
+
namespace Dali
{
namespace Internal
{
namespace Render
{
-class Sampler;
+struct Sampler;
class Texture
{
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
*/
- Texture()
- :mUniformName(),
- mSampler(0),
- mTextureId(Integration::InvalidResourceId)
- {}
+ Texture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
/**
- * Constructor
+ * Constructor from native image
+ * @param[in] nativeImageInterface The native image
*/
- Texture( const std::string& samplerName, Integration::ResourceId textureId, Render::Sampler* sampler )
- :mUniformName( samplerName ),
- mSampler( sampler ),
- mTextureId( textureId)
- {}
+ Texture( NativeImageInterfacePtr nativeImageInterface );
/**
* Destructor
*/
- ~Texture()
- {}
+ ~Texture();
+
+ /**
+ * Creates the texture in the GPU.
+ * Creates the texture and reserves memory for the first mipmap level
+ * @param[in] context The GL context
+ */
+ void Initialize(Context& context);
+
+ /**
+ * Deletes the texture from the GPU
+ * @param[in] context The GL context
+ */
+ void Destroy( Context& context );
+
+ /**
+ * Called by RenderManager to inform the texture that the context has been destroyed
+ */
+ void GlContextDestroyed();
+
+ /**
+ * 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::Texture::UploadParams& params );
- /*
- * Get the Render::Sampler used by the texture
- * @Return The Render::Sampler being used or 0 if using the default
+ /**
+ * 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
*/
- inline const Render::Sampler* GetSampler() const
+ 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 mSampler;
+ return mId;
}
-public: // called from RenderThread
+ /**
+ * Get the width of the texture
+ * @return Width of the texture
+ */
+ unsigned int GetWidth() const
+ {
+ return mWidth;
+ }
/**
- * Get the texture unit uniform name
- * @return the name of the texture unit uniform
+ * Get the height of the texture
+ * @return Height of the texture
*/
- inline const std::string& GetUniformName() const
+ unsigned int GetHeight() const
{
- return mUniformName;
+ return mHeight;
}
/**
- * Get the texture ID
- * @param[in] bufferIndex The buffer index to use
- * @return the identity of the associated texture
+ * Get the type of the texture
+ * @return Type of the texture
*/
- inline Integration::ResourceId GetTextureId() const
+ Type GetType() const
{
- return mTextureId;
+ return mType;
+ }
+
+ /**
+ * Check if the texture is a native image
+ * @return if the texture is a native image
+ */
+ bool IsNativeImage() const
+ {
+ return mNativeImage;
}
private:
- std::string mUniformName;
- Render::Sampler* mSampler;
- Integration::ResourceId mTextureId;
+
+ /**
+ * 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
+ GLuint mTarget; ///< Specifies the target to which the texture is bound.
+ 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; ///< Width 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
};
-} // namespace SceneGraph
+
+} // namespace Render
} // namespace Internal
+
} // namespace Dali