Mipmap level parameter
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-texture.cpp
index 7e32f92..9025a31 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -599,6 +599,7 @@ NewTexture::NewTexture( Type type, Pixel::Format format, unsigned int width, uns
  mPixelDataType(GL_UNSIGNED_BYTE),
  mWidth( width ),
  mHeight( height ),
+ mMaxMipMapLevel(0),
  mHasAlpha( HasAlpha( format ) ),
  mIsCompressed( IsCompressedFormat( format ) )
 {
@@ -615,6 +616,7 @@ NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
  mPixelDataType(GL_UNSIGNED_BYTE),
  mWidth( nativeImageInterface->GetWidth() ),
  mHeight( nativeImageInterface->GetHeight() ),
+ mMaxMipMapLevel(0),
  mHasAlpha( nativeImageInterface->RequiresBlending() ),
  mIsCompressed( false )
 {
@@ -731,6 +733,10 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
   GLenum pixelDataFormat, pixelDataElementType;
   PixelFormatToGl( pixelData->GetPixelFormat(), pixelDataElementType, pixelDataFormat );
 
+  //Get the maximum mipmap level to set GL_TEXTURE_MAX_LEVEL parameter in GLES3x because is not
+  //necessary to upload all the mipmap levels
+  mMaxMipMapLevel = ( mMaxMipMapLevel > params.mipmap ) ? mMaxMipMapLevel : params.mipmap;
+
 #if DALI_GLES_VERSION < 30
   if( pixelDataFormat == GL_RGB && mInternalFormat == GL_RGBA )
   {
@@ -852,6 +858,15 @@ void NewTexture::ApplySampler( Context& context, Render::Sampler* sampler )
       GLint glWrapMode = WrapModeToGL( mSampler.mRWrapMode, GL_WRAP_DEFAULT );
       context.TexParameteri( mTarget, GL_TEXTURE_WRAP_R, glWrapMode );
     }
+
+#if DALI_GLES_VERSION >= 30
+    //In GLES 3.0 we do not need to upload all of the mipmap levels, but GL_TEXTURE_MAX_LEVEL must be set
+    if(mMaxMipMapLevel)
+    {
+      context.TexParameteri( mTarget, GL_TEXTURE_MAX_LEVEL, mMaxMipMapLevel );
+    }
+#endif
+
   }
 }
 
@@ -862,6 +877,8 @@ bool NewTexture::HasAlphaChannel()
 
 void NewTexture::GenerateMipmaps( Context& context )
 {
+  //GL_TEXTURE_MAX_LEVEL does not need to be set when mipmaps are generated by GL
+  mMaxMipMapLevel = 0;
   context.BindTexture( mTarget, mId );
   context.GenerateMipmap( mTarget );
 }