TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
{
- TexturePtr texture( new Texture( type, format, width, height ) );
+ constexpr auto max_value = std::numeric_limits< uint16_t >::max();
+ DALI_ASSERT_ALWAYS( ( width < max_value )&&( height < max_value )&& "Size out of range" );
+ TexturePtr texture( new Texture( type, format, ImageDimensions( width, height) ) );
texture->Initialize();
return texture;
}
return mRenderObject;
}
-Texture::Texture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
+Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size )
: mEventThreadServices( *Stage::GetCurrent() ),
mRenderObject( NULL ),
mNativeImage(),
+ mSize( size ),
mType( type ),
- mFormat( format ),
- mWidth( width ),
- mHeight( height )
+ mFormat( format )
{
}
: mEventThreadServices( *Stage::GetCurrent() ),
mRenderObject( NULL ),
mNativeImage( nativeImageInterface ),
+ mSize( nativeImageInterface->GetWidth(), nativeImageInterface->GetHeight() ),
mType( TextureType::TEXTURE_2D ),
- mFormat( Pixel::RGB888 ),
- mWidth( nativeImageInterface->GetWidth() ),
- mHeight( nativeImageInterface->GetHeight() )
+ mFormat( Pixel::RGB888 )
{
}
}
else
{
- mRenderObject = new Render::Texture( mType, mFormat, mWidth, mHeight );
+ mRenderObject = new Render::Texture( mType, mFormat, mSize );
}
OwnerPointer< Render::Texture > transferOwnership( mRenderObject );
}
bool Texture::Upload( PixelDataPtr pixelData,
- unsigned int layer, unsigned int mipmap,
- unsigned int xOffset, unsigned int yOffset,
- unsigned int width, unsigned int height )
+ unsigned int layer, unsigned int mipmap,
+ unsigned int xOffset, unsigned int yOffset,
+ unsigned int width, unsigned int height )
{
+ constexpr auto max_value = std::numeric_limits< uint16_t >::max();
+ DALI_ASSERT_ALWAYS( layer < max_value &&
+ mipmap < max_value &&
+ xOffset < max_value &&
+ yOffset < max_value &&
+ width < max_value &&
+ height < max_value &&
+ "Parameter value out of range" );
+
bool result(false);
if( EventThreadServices::IsCoreRunning() && mRenderObject )
{
{
DALI_LOG_ERROR( "PixelData of an incorrect size when trying to update texture\n");
}
- else if( ( xOffset + width > ( mWidth / (1<<mipmap) ) ) ||
- ( yOffset + height > ( mHeight / (1<<mipmap) ) ) )
+ else if( ( xOffset + width > ( mSize.GetWidth() / (1u << mipmap) ) ) ||
+ ( yOffset + height > ( mSize.GetHeight() / (1u << mipmap) ) ) )
{
DALI_LOG_ERROR( "Texture update area out of bounds\n");
}
else
{
//Parameters are correct. Send message to upload data to the texture
- UploadParams params = { layer, mipmap, xOffset, yOffset, width, height };
+ UploadParams params = { static_cast< uint16_t >( layer ),
+ static_cast< uint16_t >( mipmap ),
+ static_cast< uint16_t >( xOffset ),
+ static_cast< uint16_t >( yOffset ),
+ static_cast< uint16_t >( width ),
+ static_cast< uint16_t >( height ) };
UploadTextureMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, pixelData, params );
result = true;
}
unsigned int Texture::GetWidth() const
{
- return mWidth;
+ return mSize.GetWidth();
}
unsigned int Texture::GetHeight() const
{
- return mHeight;
+ return mSize.GetHeight();
}
} // namespace Internal
#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
#include <dali/public-api/object/base-object.h>
#include <dali/public-api/images/pixel.h>
+#include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
#include <dali/public-api/rendering/texture.h> // Dali::Internal::Render::Texture
#include <dali/internal/event/common/event-thread-services.h>
#include <dali/internal/event/images/pixel-data-impl.h>
*/
struct UploadParams
{
- unsigned int layer; ///< Specifies the layer of a cube map or array texture
- unsigned int mipmap; ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
- unsigned int xOffset; ///< Specifies a texel offset in the x direction within the texture array.
- unsigned int yOffset; ///< Specifies a texel offset in the y direction within the texture array.
- unsigned int width; ///< Specifies the width of the texture subimage
- unsigned int height; ///< Specifies the height of the texture subimage.
+ uint16_t layer; ///< Specifies the layer of a cube map or array texture
+ uint16_t mipmap; ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
+ uint16_t xOffset; ///< Specifies a texel offset in the x direction within the texture array.
+ uint16_t yOffset; ///< Specifies a texel offset in the y direction within the texture array.
+ uint16_t width; ///< Specifies the width of the texture subimage
+ uint16_t height; ///< Specifies the height of the texture subimage.
};
/**
* 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
+ * @param[in] size The size of the texture
*/
- Texture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
+ Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size );
/**
* Constructor from native image
Internal::Render::Texture* 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
- unsigned int mHeight; ///< Height of the texture
+ ImageDimensions mSize; ///< Size of the texture
+ Dali::TextureType::Type mType; ///< Texture type (cached)
+ Pixel::Format mFormat; ///< Pixel format
+
};
} // namespace Internal
} //Unnamed namespace
-Texture::Texture( Type type, Pixel::Format format, unsigned int width, unsigned int height )
-:mId( 0 ),
- mTarget( ( type == TextureType::TEXTURE_2D ) ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
- mType( type ),
- mSampler(),
- mNativeImage(),
- mGlFormat( GL_RGB ),
- mGlInternalFormat( GL_RGB ),
- mPixelDataType( GL_UNSIGNED_BYTE ),
- mWidth( width ),
- mHeight( height ),
- mMaxMipMapLevel( 0 ),
- mHasAlpha( HasAlpha( format ) ),
- mIsCompressed( IsCompressedFormat( format ) )
+Texture::Texture( Type type, Pixel::Format format, ImageDimensions size )
+: mNativeImage(),
+ mSampler(),
+ mId( 0 ),
+ mTarget( ( type == TextureType::TEXTURE_2D ) ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
+ mGlInternalFormat( GL_RGB ),
+ mGlFormat( GL_RGB ),
+ mPixelDataType( GL_UNSIGNED_BYTE ),
+ mWidth( size.GetWidth() ),
+ mHeight( size.GetHeight() ),
+ mMaxMipMapLevel( 0 ),
+ mType( type ),
+ mHasAlpha( HasAlpha( format ) ),
+ mIsCompressed( IsCompressedFormat( format ) )
{
PixelFormatToGl( static_cast<DevelPixel::Format>( format ),
mGlFormat,
}
Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
-:mId( 0 ),
- mTarget( GL_TEXTURE_2D ),
- mType( TextureType::TEXTURE_2D ),
- mSampler(),
- mNativeImage( nativeImageInterface ),
- mGlFormat( GL_RGB ),
- mGlInternalFormat( GL_RGB ),
- mPixelDataType( GL_UNSIGNED_BYTE ),
- mWidth( nativeImageInterface->GetWidth() ),
- mHeight( nativeImageInterface->GetHeight() ),
- mMaxMipMapLevel( 0 ),
- mHasAlpha( nativeImageInterface->RequiresBlending() ),
- mIsCompressed( false )
+: mNativeImage( nativeImageInterface ),
+ mSampler(),
+ mId( 0 ),
+ mTarget( GL_TEXTURE_2D ),
+ mGlInternalFormat( GL_RGB ),
+ mGlFormat( GL_RGB ),
+ mPixelDataType( GL_UNSIGNED_BYTE ),
+ mWidth( nativeImageInterface->GetWidth() ),
+ mHeight( nativeImageInterface->GetHeight() ),
+ mMaxMipMapLevel( 0 ),
+ mType( TextureType::TEXTURE_2D ),
+ mHasAlpha( nativeImageInterface->RequiresBlending() ),
+ mIsCompressed( false )
{
}
* 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
+ * @param[in] size The size of the texture
*/
- Texture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
+ Texture( Type type, Pixel::Format format, ImageDimensions size );
/**
* Constructor from native image
* Creates the texture and reserves memory for the first mipmap level
* @param[in] context The GL context
*/
- void Initialize(Context& context);
+ void Initialize( Context& context );
/**
* Deletes the texture from the GPU
return mId;
}
- /**
- * 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
- */
- unsigned int GetHeight() const
- {
- return mHeight;
- }
-
/**
* Get the type of the texture
* @return Type of the texture
*/
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.
- Type mType; ///< Type of the texture
- Render::Sampler mSampler; ///< The current sampler state
- NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
- GLenum mGlFormat; ///< The gl format of the pixel data
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
- unsigned int mWidth; ///< Width of the texture
- unsigned int mHeight; ///< Height of the texture
- unsigned int mMaxMipMapLevel; ///< Maximum mipmap level
+ 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
+
};