2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/render/gl-resources/native-texture.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/render/gl-resources/context.h>
24 #include <dali/internal/render/gl-resources/texture.h>
25 #include <dali/internal/render/gl-resources/texture-units.h>
33 NativeTexture::NativeTexture(NativeImageInterface* nativeImg, Context& context)
35 nativeImg->GetWidth(),
36 nativeImg->GetHeight(),
37 nativeImg->GetWidth(),
38 nativeImg->GetHeight()),
39 mNativeImage(nativeImg)
41 DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "NativeTexture created 0x%x\n", &nativeImg );
44 NativeTexture::~NativeTexture()
46 DALI_LOG_INFO (Debug::Filter::gImage, Debug::General, "NativeTexture destroyed\n");
47 // GlCleanup() should already have been called by TextureCache ensuring the resource is destroyed
48 // on the render thread. (And avoiding a potentially problematic virtual call in the destructor)
51 bool NativeTexture::Bind(GLenum target, TextureUnit textureunit )
61 // Bind the texture id
62 mContext.ActiveTexture( textureunit );
63 mContext.Bind2dTexture( mId );
65 mNativeImage->PrepareTexture();
70 bool NativeTexture::IsFullyOpaque() const
72 return !HasAlphaChannel();
75 bool NativeTexture::HasAlphaChannel() const
77 return mNativeImage->RequiresBlending();
80 bool NativeTexture::CreateGlTexture()
84 DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "GL texture creation duplicate for GL id: %d\n", &mId );
88 if( mNativeImage->GlExtensionCreate() )
90 mContext.GenTextures( 1, &mId );
91 mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD ); // bind in unused unit so rebind works the first time
92 mContext.Bind2dTexture( mId );
94 mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
96 mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
97 mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
99 // platform specific implementation decides on what GL extension to use
100 mNativeImage->TargetTexture();
104 DALI_LOG_ERROR( "Error creating native image!" );
110 void NativeTexture::GlCleanup()
112 Texture::GlCleanup();
114 DALI_ASSERT_DEBUG( mNativeImage );
116 mNativeImage->GlExtensionDestroy();
117 mNativeImage.Reset();
120 bool NativeTexture::Init()
125 } //namespace Internal