2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/render/gl-resources/native-texture.h>
25 #include <dali/public-api/math/rect.h>
26 #include <dali/public-api/math/math-utils.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/internal/render/common/vertex.h>
29 #include <dali/internal/render/gl-resources/context.h>
30 #include <dali/internal/render/gl-resources/texture.h>
38 NativeTexture::NativeTexture(NativeImage* nativeImg, Context& context)
40 nativeImg->GetWidth(),
41 nativeImg->GetHeight(),
42 nativeImg->GetWidth(),
43 nativeImg->GetHeight(),
44 nativeImg->GetPixelFormat()),
45 mNativeImage(nativeImg)
47 DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "NativeTexture created 0x%x\n", &nativeImg );
50 NativeTexture::~NativeTexture()
52 DALI_LOG_INFO (Debug::Filter::gImage, Debug::General, "NativeTexture destroyed\n");
53 // GlCleanup() should already have been called by TextureCache ensuring the resource is destroyed
54 // on the render thread. (And avoiding a potentially problematic virtual call in the destructor)
57 bool NativeTexture::Bind(GLenum target, GLenum textureunit )
67 // Bind the texture id
68 mContext.ActiveTexture( textureunit );
69 mContext.Bind2dTexture( mId );
71 mNativeImage->PrepareTexture();
76 bool NativeTexture::IsFullyOpaque() const
78 // TODO - Should test actual texture...
79 return !HasAlphaChannel();
82 bool NativeTexture::HasAlphaChannel() const
84 return Pixel::HasAlpha( mNativeImage->GetPixelFormat() );
87 Pixel::Format NativeTexture::GetPixelFormat() const
89 return mNativeImage->GetPixelFormat();
92 bool NativeTexture::CreateGlTexture()
94 if( mNativeImage->GlExtensionCreate() )
96 mContext.GenTextures( 1, &mId );
97 mContext.ActiveTexture( GL_TEXTURE7 ); // bind in unused unit so rebind works the first time
98 mContext.Bind2dTexture( mId );
100 mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
102 mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
103 mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
104 mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
105 mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
107 // platform specific implementation decides on what GL extension to use
108 mNativeImage->TargetTexture();
112 DALI_LOG_ERROR( "Error creating native image!" );
118 void NativeTexture::GlCleanup()
120 Texture::GlCleanup();
122 DALI_ASSERT_DEBUG(mNativeImage);
124 mNativeImage->GlExtensionDestroy();
126 mNativeImage.Reset();
129 bool NativeTexture::Init()
134 } //namespace Internal