return Texture( texture.Get() );
}
+Texture Texture::New( NativeImageInterface& nativeImageInterface )
+{
+ Internal::NewTexturePtr texture = Internal::NewTexture::New( nativeImageInterface );
+ return Texture( texture.Get() );
+}
+
Texture::Texture()
{
}
// INTERNAL INCLUDES
#include <dali/public-api/object/base-handle.h>
+#include <dali/public-api/images/native-image-interface.h>
#include <dali/public-api/images/pixel.h>
#include <dali/devel-api/images/pixel-data.h>
static Texture New( TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
/**
+ * @brief Creates a new Texture object from a native image
+ * @param[in] nativeImageInterface A native image
+ * @return A handle to a newly allocated Texture
+ * @note It is not possible to upload data to textures created from a native image using Upload methods
+ * although there might be platform specific APIs to upload data to a native image.
+ */
+ static Texture New( NativeImageInterface& nativeImageInterface );
+
+ /**
* @brief Default constructor, creates an empty handle
*/
Texture();
return texture;
}
+NewTexturePtr NewTexture::New( NativeImageInterface& nativeImageInterface )
+{
+ NewTexturePtr texture( new NewTexture( &nativeImageInterface ) );
+ texture->Initialize();
+ return texture;
+}
Render::NewTexture* NewTexture::GetRenderObject() const
{
NewTexture::NewTexture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
: mEventThreadServices( *Stage::GetCurrent() ),
mRenderObject( NULL ),
+ mNativeImage(),
mType( type ),
mFormat( format ),
mWidth( width ),
{
}
+NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
+: mEventThreadServices( *Stage::GetCurrent() ),
+ mRenderObject( NULL ),
+ mNativeImage( nativeImageInterface ),
+ mType( TextureType::TEXTURE_2D ),
+ mFormat( Pixel::RGB888 ),
+ mWidth( nativeImageInterface->GetWidth() ),
+ mHeight( nativeImageInterface->GetHeight() )
+{
+}
+
void NewTexture::Initialize()
{
- mRenderObject = new Render::NewTexture( mType, mFormat, mWidth, mHeight );
+ if( mNativeImage )
+ {
+ mRenderObject = new Render::NewTexture( mNativeImage );
+ }
+ else
+ {
+ mRenderObject = new Render::NewTexture( mType, mFormat, mWidth, mHeight );
+ }
+
AddTexture( mEventThreadServices.GetUpdateManager(), *mRenderObject );
}
bool NewTexture::CheckUploadParametres( const Vector<unsigned char>& buffer, const UploadParams& parameters ) const
{
- if( buffer.Size() < GetBytesPerPixel( mFormat ) * parameters.width * parameters.height )
+ if( mNativeImage )
+ {
+ DALI_LOG_ERROR( "Error: Uploading data to a native texture");
+ return false;
+ }
+ else if( buffer.Size() < GetBytesPerPixel( mFormat ) * parameters.width * parameters.height )
{
DALI_LOG_ERROR( "Error: Buffer of an incorrect size when trying to update texture");
return false;
static NewTexturePtr New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height);
/**
+ * @brief Creates a new Texture from a native image
+ * @param[in] nativeImageInterface The native image
+ * @return A smart-pointer to the newly allocated Texture.
+ */
+ static NewTexturePtr New( NativeImageInterface& nativeImageInterface );
+
+ /**
* @brief Get the texture render object
*
* @return the texture render object
/**
* 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(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
/**
+ * Constructor from native image
+ * @param[in] nativeImageInterface The native image
+ */
+ NewTexture( NativeImageInterfacePtr nativeImageInterface );
+
+ /**
* Second stage initialization of the Texture
*/
void Initialize();
Internal::EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
Internal::Render::NewTexture* mRenderObject; ///<The Render::Texture associated to this texture
+ NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
Dali::TextureType::Type mType; ///< Texture type (cached)
Pixel::Format mFormat; ///< Pixel format
unsigned int mWidth; ///< Width of the texture
std::vector<Render::Sampler*>& samplers( mRenderDataProvider->GetSamplers() );
std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
+ GLint uniformLocation(-1);
for( size_t i(0); result && i<textures.size(); ++i )
{
ResourceId textureId = textures[i].GetTextureId();
Internal::Texture* texture = textureCache.GetTexture( textureId );
if( texture )
{
- result = textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
+ result = program.GetSamplerUniformLocation( i, uniformLocation ) &&
+ textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
- if( result )
+ if( result && Program::UNIFORM_UNKNOWN != uniformLocation )
{
- GLint uniformLocation;
+ program.SetUniform1i( uniformLocation, textureUnit );
- bool result = program.GetSamplerUniformLocation( i, uniformLocation );
- if( result && Program::UNIFORM_UNKNOWN != uniformLocation )
+ unsigned int samplerBitfield(ImageSampler::DEFAULT_BITFIELD);
+ const Render::Sampler* sampler( samplers[i] );
+ if( sampler )
{
- program.SetUniform1i( uniformLocation, textureUnit );
-
- unsigned int samplerBitfield(ImageSampler::DEFAULT_BITFIELD);
- const Render::Sampler* sampler( samplers[i] );
- if( sampler )
- {
- samplerBitfield = sampler->mBitfield;
- }
+ samplerBitfield = sampler->mBitfield;
+ }
- texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
+ texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
- ++textureUnit;
- }
+ ++textureUnit;
}
}
}
std::vector<Render::NewTexture*>& newTextures( mRenderDataProvider->GetNewTextures() );
- GLint uniformLocation(0);
for( size_t i(0); result && i<newTextures.size(); ++i )
{
if( newTextures[i] )
{
- bool result = program.GetSamplerUniformLocation( i, uniformLocation );
+ result = program.GetSamplerUniformLocation( i, uniformLocation ) &&
+ newTextures[i]->Bind(context, textureUnit, samplers[i] );
+
if( result )
{
- newTextures[i]->Bind(context, textureUnit, samplers[i] );
program.SetUniform1i( uniformLocation, textureUnit );
++textureUnit;
}
NewTexture::NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height )
:mId( 0 ),
mType( type ),
+ mSampler(),
+ mNativeImage(),
mInternalFormat(GL_RGB),
mPixelDataType(GL_UNSIGNED_BYTE),
mWidth( width ),
mHeight( height ),
- mSampler(),
mHasAlpha( HasAlpha( format ) )
{
PixelFormatToGl( format, mPixelDataType, mInternalFormat );
}
+NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
+:mId( 0 ),
+ mType( TextureType::TEXTURE_2D ),
+ mSampler(),
+ mNativeImage( nativeImageInterface ),
+ mInternalFormat(GL_RGB),
+ mPixelDataType(GL_UNSIGNED_BYTE),
+ mWidth( nativeImageInterface->GetWidth() ),
+ mHeight( nativeImageInterface->GetHeight() ),
+ mHasAlpha( nativeImageInterface->RequiresBlending() )
+{
+}
+
NewTexture::~NewTexture()
{}
void NewTexture::Initialize(Context& context)
{
- context.GenTextures( 1, &mId );
-
- if( mType == TextureType::TEXTURE_2D )
+ if( mNativeImage )
{
- //Creates the texture and reserves memory for the first mipmap level.
- context.Bind2dTexture( mId );
- context.TexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+ if( mNativeImage->GlExtensionCreate() )
+ {
+ context.GenTextures( 1, &mId );
+ context.Bind2dTexture( mId );
+ context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
- //Apply default sampling parameters
- context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
- context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
- context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
- context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
+ //Apply default sampling parameters
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
+ // platform specific implementation decides on what GL extension to use
+ mNativeImage->TargetTexture();
+ }
}
- else if( mType == TextureType::TEXTURE_CUBE )
+ else
{
- //Creates the texture and reserves memory for the first mipmap level.
- context.BindCubeMapTexture( mId );
- for( unsigned int i(0); i<6; ++i )
+ context.GenTextures( 1, &mId );
+
+ if( mType == TextureType::TEXTURE_2D )
{
- context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+ //Creates the texture and reserves memory for the first mipmap level.
+ context.Bind2dTexture( mId );
+ context.TexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+
+ //Apply default sampling parameters
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
}
+ else if( mType == TextureType::TEXTURE_CUBE )
+ {
+ //Creates the texture and reserves memory for the first mipmap level.
+ context.BindCubeMapTexture( mId );
+ for( unsigned int i(0); i<6; ++i )
+ {
+ context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+ }
- //Apply default sampling parameters
- context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
- context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
- context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT );
- context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
- context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
+ //Apply default sampling parameters
+ context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
+ context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
+ }
}
}
void NewTexture::Upload( Context& context, Vector<unsigned char>& buffer, const Internal::NewTexture::UploadParams& params )
{
+ DALI_ASSERT_ALWAYS( mNativeImage == NULL );
+
if( mType == TextureType::TEXTURE_2D )
{
context.Bind2dTexture( mId );
}
}
-void NewTexture::Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler )
+bool NewTexture::Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler )
{
- context.ActiveTexture( static_cast<TextureUnit>(textureUnit) );
-
- if( mType == TextureType::TEXTURE_2D )
- {
- context.Bind2dTexture( mId );
- }
- else if( mType == TextureType::TEXTURE_CUBE )
+ if( mId != 0 )
{
- context.BindCubeMapTexture( mId );
+ context.ActiveTexture( static_cast<TextureUnit>(textureUnit) );
+
+ if( mType == TextureType::TEXTURE_2D )
+ {
+ context.Bind2dTexture( mId );
+ }
+ else if( mType == TextureType::TEXTURE_CUBE )
+ {
+ context.BindCubeMapTexture( mId );
+ }
+
+ ApplySampler( context, sampler );
+
+ return true;
}
- ApplySampler( context, sampler );
+ return false;
}
void NewTexture::ApplySampler( Context& context, Render::Sampler* sampler )
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 );
/**
+ * Constructor from native image
+ * @param[in] nativeImageInterface The native image
+ */
+ NewTexture( NativeImageInterfacePtr nativeImageInterface );
+
+ /**
* Destructor
*/
~NewTexture();
* @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
*/
- void Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
+ bool Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
/**
* Auto generates mipmaps for the texture
*/
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
- Render::Sampler mSampler; ///<The current sampler state
bool mHasAlpha : 1; ///<Whether the format has an alpha channel
};