Mipmap level parameter 07/133307/1
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 15:08:55 +0000 (15:08 +0000)
Implementation of GL_TEXTURE_MAX_LEVEL for GLES3x,
to upload mipmaps without full level.

Change-Id: I8dbd3a30b47da02ec598cf8df1bc6444d361e232
(cherry picked from commit c884e36da8820f0c156d88d045874dd6785452f5)

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

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 );
 }
index 6d10c2a..526a690 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.
@@ -230,6 +230,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
 };