// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
-#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/render/gl-resources/texture-units.h>
+#include <dali/internal/render/gl-resources/gl-texture.h>
+#include <dali/devel-api/images/native-image-interface-extension.h>
namespace Dali
{
namespace Internal
{
-NativeTexture::NativeTexture(NativeImage* nativeImg, Context& context)
+NativeTexture::NativeTexture(NativeImageInterface* nativeImg, Context& context)
: Texture(context,
nativeImg->GetWidth(),
nativeImg->GetHeight(),
nativeImg->GetWidth(),
- nativeImg->GetHeight(),
- nativeImg->GetPixelFormat()),
+ nativeImg->GetHeight()),
mNativeImage(nativeImg)
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "NativeTexture created 0x%x\n", &nativeImg );
NativeTexture::~NativeTexture()
{
DALI_LOG_INFO (Debug::Filter::gImage, Debug::General, "NativeTexture destroyed\n");
+
// GlCleanup() should already have been called by TextureCache ensuring the resource is destroyed
// on the render thread. (And avoiding a potentially problematic virtual call in the destructor)
}
-bool NativeTexture::Bind(GLenum target, GLenum textureunit )
+bool NativeTexture::Bind( GLenum target, TextureUnit textureunit )
{
- bool created = false;
+ bool result = true;
- if( mId==0 )
+ if( mId == 0 )
{
- CreateGlTexture();
- created = true;
+ result = CreateGlTexture();
}
- // Bind the texture id
- mContext.ActiveTexture( textureunit );
- mContext.Bind2dTexture( mId );
-
- mNativeImage->PrepareTexture();
+ if( result )
+ {
+ // Bind the texture id
+ mContext.ActiveTexture( textureunit );
+
+ int textureTarget = GL_TEXTURE_2D;
+ NativeImageInterface::Extension* extension = mNativeImage->GetExtension();
+ if( extension )
+ {
+ textureTarget = extension->GetEglImageTextureTarget();
+ }
+
+ mContext.BindTexture( textureTarget, mId );
+ mNativeImage->PrepareTexture();
+ }
- return created;
+ return result;
}
bool NativeTexture::IsFullyOpaque() const
{
- // TODO - Should test actual texture...
return !HasAlphaChannel();
}
bool NativeTexture::HasAlphaChannel() const
{
- return Pixel::HasAlpha( mNativeImage->GetPixelFormat() );
-}
-
-Pixel::Format NativeTexture::GetPixelFormat() const
-{
- return mNativeImage->GetPixelFormat();
+ return mNativeImage->RequiresBlending();
}
bool NativeTexture::CreateGlTexture()
{
+ if( mId != 0 )
+ {
+ DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "GL texture creation duplicate for GL id: %d\n", &mId );
+ return true;
+ }
+
if( mNativeImage->GlExtensionCreate() )
{
mContext.GenTextures( 1, &mId );
- mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
- mContext.Bind2dTexture( mId );
+ mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD ); // bind in unused unit so rebind works the first time
+
+ int textureTarget = GL_TEXTURE_2D;
+ NativeImageInterface::Extension* extension = mNativeImage->GetExtension();
+ if( extension )
+ {
+ textureTarget = extension->GetEglImageTextureTarget();
+ }
+
+ mContext.BindTexture( textureTarget, mId );
mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
}
else
{
- DALI_LOG_ERROR( "Error creating native image!" );
+ DALI_LOG_ERROR( "Error creating native image!\n" );
}
return mId != 0;
{
Texture::GlCleanup();
- DALI_ASSERT_DEBUG(mNativeImage);
+ DALI_ASSERT_DEBUG( mNativeImage );
mNativeImage->GlExtensionDestroy();
-
mNativeImage.Reset();
}