X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fgl-resources%2Fnative-texture.cpp;h=8110880d31176a0a8bb13a5f45df58dada69c197;hb=2b10280985738c74efa2aa0fb956a837c69acee6;hp=ab3288ad7acf3d29b1d08dbb64193490cbee1ddf;hpb=7c6f8ed43521c52d6cc46a7e3e3e40069514f818;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/gl-resources/native-texture.cpp b/dali/internal/render/gl-resources/native-texture.cpp index ab3288a..8110880 100644 --- a/dali/internal/render/gl-resources/native-texture.cpp +++ b/dali/internal/render/gl-resources/native-texture.cpp @@ -18,17 +18,11 @@ // CLASS HEADER #include -// EXTERNAL INCLUDES -#include -#include - // INTERNAL INCLUDES -#include -#include #include -#include #include -#include +#include +#include namespace Dali { @@ -36,13 +30,12 @@ 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 ); @@ -51,57 +44,58 @@ NativeTexture::NativeTexture(NativeImage* nativeImg, Context& context) 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 ); + if( result ) + { + // Bind the texture id + mContext.ActiveTexture( textureunit ); + mContext.Bind2dTexture(mId); - mNativeImage->PrepareTexture(); + 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( GL_TEXTURE7 ); // bind in unused unit so rebind works the first time + mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD ); // bind in unused unit so rebind works the first time mContext.Bind2dTexture( mId ); mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data - mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); @@ -110,7 +104,7 @@ bool NativeTexture::CreateGlTexture() } else { - DALI_LOG_ERROR( "Error creating native image!" ); + DALI_LOG_ERROR( "Error creating native image!\n" ); } return mId != 0; @@ -120,10 +114,9 @@ void NativeTexture::GlCleanup() { Texture::GlCleanup(); - DALI_ASSERT_DEBUG(mNativeImage); + DALI_ASSERT_DEBUG( mNativeImage ); mNativeImage->GlExtensionDestroy(); - mNativeImage.Reset(); }