Mipmap level parameter 98/132798/5
authorgreynaga <g.reynaga@samsung.com>
Wed, 7 Jun 2017 14:24:31 +0000 (15:24 +0100)
committerGonzalo Reynaga Garcia <g.reynaga@samsung.com>
Fri, 9 Jun 2017 12:50:25 +0000 (12:50 +0000)
Implementation of GL_TEXTURE_MAX_LEVEL for GLES3x,
to upload mipmaps without full level.

Change-Id: I8dbd3a30b47da02ec598cf8df1bc6444d361e232

dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h

index d0d655b..39c07fa 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 @@ Texture::Texture( Type type, Pixel::Format format, unsigned int width, unsigned
  mPixelDataType(GL_UNSIGNED_BYTE),
  mWidth( width ),
  mHeight( height ),
+ mMaxMipMapLevel(0),
  mHasAlpha( HasAlpha( format ) ),
  mIsCompressed( IsCompressedFormat( format ) )
 {
@@ -615,6 +616,7 @@ Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
  mPixelDataType(GL_UNSIGNED_BYTE),
  mWidth( nativeImageInterface->GetWidth() ),
  mHeight( nativeImageInterface->GetHeight() ),
+ mMaxMipMapLevel(0),
  mHasAlpha( nativeImageInterface->RequiresBlending() ),
  mIsCompressed( false )
 {
@@ -731,6 +733,10 @@ void Texture::Upload( Context& context, PixelDataPtr pixelData, const Internal::
   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 )
   {
@@ -860,6 +866,15 @@ void Texture::ApplySampler( Context& context, Render::Sampler* sampler )
         context.TexParameteri( mTarget, GL_TEXTURE_WRAP_R, mode );
       }
     }
+
+#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
+
   }
 }
 
@@ -870,6 +885,8 @@ bool Texture::HasAlphaChannel()
 
 void Texture::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 );
 }
index e50ec3d..1ae9a3c 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_RENDER_TEXTURE_H
 
 /*
- * 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.
@@ -172,6 +172,7 @@ private:
   GLenum mPixelDataType;                ///< The data type of the pixel data
   unsigned int mWidth;                  ///< Width of the texture
   unsigned int mHeight;                 ///< Height of the texture
+  unsigned int mMaxMipMapLevel;         ///< Maximum mipmap level
   bool mHasAlpha : 1;                   ///< Whether the format has an alpha channel
   bool mIsCompressed : 1;               ///< Whether the format is compressed
 };