/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
// CLASS HEADER
#include <dali/internal/render/renderers/render-texture.h>
-#include <dali/devel-api/images/native-image-interface-extension.h>
// EXTERNAL INCLUDES
#include <math.h> //floor, log2
+// INTERNAL INCLUDES
+#include <dali/devel-api/images/native-image-interface-extension.h>
+
namespace Dali
{
namespace Internal
}
/**
- * @brief Retrive GL internal format and pixel data type from a Pixel::Format
- * @param[in] pixelFormat The pixel format
- * @param[out] pixelDataType The data type of the pixel data
- * @param[out] internalFormat The internal format
+ * @brief Retrives the GL format, GL internal format and pixel data type from a Pixel::Format
+ * @param[in] pixelFormat The pixel format.
+ * @param[out] glFormat The gl format.
+ * @param[out] glInternalFormat The gl internal format.
+ * @param[out] pixelDataType The data type of the pixel data.
*/
-void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
+void PixelFormatToGl( Pixel::Format pixelFormat, GLenum& glFormat, GLint& glInternalFormat, GLenum& pixelDataType )
{
// Compressed textures have no pixelDataType, so init to an invalid value:
pixelDataType = -1;
- switch( pixelformat )
+ switch( pixelFormat )
{
case Pixel::A8:
{
pixelDataType = GL_UNSIGNED_BYTE;
- internalFormat= GL_ALPHA;
+ glFormat= GL_ALPHA;
break;
}
case Pixel::L8:
{
pixelDataType = GL_UNSIGNED_BYTE;
- internalFormat= GL_LUMINANCE;
+ glFormat= GL_LUMINANCE;
break;
}
case Pixel::LA88:
{
pixelDataType = GL_UNSIGNED_BYTE;
- internalFormat= GL_LUMINANCE_ALPHA;
+ glFormat= GL_LUMINANCE_ALPHA;
break;
}
case Pixel::RGB565:
{
pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
- internalFormat= GL_RGB;
+ glFormat= GL_RGB;
break;
}
DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
#ifdef _ARCH_ARM_
- internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+ glFormat= GL_BGRA_EXT; // alpha is reserved but not used
#else
- internalFormat= GL_RGBA; // alpha is reserved but not used
+ glFormat= GL_RGBA; // alpha is reserved but not used
#endif
break;
}
case Pixel::RGBA4444:
{
pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
- internalFormat= GL_RGBA;
+ glFormat= GL_RGBA;
break;
}
DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
#ifdef _ARCH_ARM_
- internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+ glFormat= GL_BGRA_EXT; // alpha is reserved but not used
#else
- internalFormat= GL_RGBA; // alpha is reserved but not used
+ glFormat= GL_RGBA; // alpha is reserved but not used
#endif
break;
}
case Pixel::RGBA5551:
{
pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
- internalFormat= GL_RGBA;
+ glFormat= GL_RGBA;
break;
}
DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
#ifdef _ARCH_ARM_
- internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+ glFormat= GL_BGRA_EXT; // alpha is reserved but not used
#else
- internalFormat= GL_RGBA; // alpha is reserved but not used
+ glFormat= GL_RGBA; // alpha is reserved but not used
#endif
break;
}
case Pixel::RGB888:
{
pixelDataType = GL_UNSIGNED_BYTE;
- internalFormat= GL_RGB;
+ glFormat= GL_RGB;
break;
}
case Pixel::RGB8888:
{
pixelDataType = GL_UNSIGNED_BYTE;
- internalFormat= GL_RGBA; // alpha is reserved but not used
+ glFormat= GL_RGBA; // alpha is reserved but not used
break;
}
{
pixelDataType = GL_UNSIGNED_BYTE;
#ifdef GL_BGRA_EXT
- internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+ glFormat= GL_BGRA_EXT; // alpha is reserved but not used
#else
- internalFormat= GL_RGBA; // alpha is reserved but not used
+ glFormat= GL_RGBA; // alpha is reserved but not used
#endif
break;
}
case Pixel::RGBA8888:
{
pixelDataType = GL_UNSIGNED_BYTE;
- internalFormat= GL_RGBA;
+ glFormat= GL_RGBA;
break;
}
{
pixelDataType = GL_UNSIGNED_BYTE;
#ifdef GL_BGRA_EXT
- internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+ glFormat= GL_BGRA_EXT; // alpha is reserved but not used
#else
- internalFormat= GL_RGBA; // alpha is reserved but not used
+ glFormat= GL_RGBA; // alpha is reserved but not used
#endif
break;
}
case Pixel::COMPRESSED_RGB8_ETC1:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
- internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
+ glFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
break;
}
case Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
- internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
+ glFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
break;
}
case Pixel::COMPRESSED_R11_EAC:
{
DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
- internalFormat = GL_COMPRESSED_R11_EAC;
+ glFormat = GL_COMPRESSED_R11_EAC;
break;
}
case Pixel::COMPRESSED_SIGNED_R11_EAC:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
- internalFormat = GL_COMPRESSED_SIGNED_R11_EAC;
+ glFormat = GL_COMPRESSED_SIGNED_R11_EAC;
break;
}
case Pixel::COMPRESSED_RG11_EAC:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
- internalFormat = GL_COMPRESSED_RG11_EAC;
+ glFormat = GL_COMPRESSED_RG11_EAC;
break;
}
case Pixel::COMPRESSED_SIGNED_RG11_EAC:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
- internalFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
+ glFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
break;
}
case Pixel::COMPRESSED_RGB8_ETC2:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
- internalFormat = GL_COMPRESSED_RGB8_ETC2;
+ glFormat = GL_COMPRESSED_RGB8_ETC2;
break;
}
case Pixel::COMPRESSED_SRGB8_ETC2:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ETC2;
+ glFormat = GL_COMPRESSED_SRGB8_ETC2;
break;
}
case Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
- internalFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
+ glFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
break;
}
case Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
+ glFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
break;
}
case Pixel::COMPRESSED_RGBA8_ETC2_EAC:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
- internalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
+ glFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_4x4_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x4_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x6_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x6_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x8_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x6_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x8_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x10_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x10_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
break;
}
case Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x12_KHR.\n" );
- internalFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
+ glFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
break;
}
case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
{
DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR.\n" );
- internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
+ glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
+ break;
+ }
+
+ // GLES 3.0 floating point formats.
+ case Pixel::RGB16F:
+ {
+ glFormat = GL_RGB;
+ pixelDataType = GL_HALF_FLOAT;
+ break;
+ }
+ case Pixel::RGB32F:
+ {
+ glFormat = GL_RGB;
+ pixelDataType = GL_FLOAT;
break;
}
case Pixel::INVALID:
{
DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
- internalFormat = 0;
+ glFormat = 0;
break;
}
}
+
+ switch( pixelFormat )
+ {
+ case Pixel::RGB16F:
+ case Pixel::RGB32F: // FALL THROUGH
+ {
+ glInternalFormat = GL_R11F_G11F_B10F;
+ break;
+ }
+ default:
+ {
+ glInternalFormat = glFormat;
+ }
+ }
+
}
+
/**
* @brief Whether specified pixel format is compressed.
*
case Pixel::BGR8888:
case Pixel::RGBA8888:
case Pixel::BGRA8888:
+ case Pixel::RGB16F:
+ case Pixel::RGB32F:
case Pixel::INVALID:
{
return false;
} //Unnamed namespace
-Texture::Texture( Type type, Pixel::Format format, unsigned int width, unsigned int height )
-:mId( 0 ),
- mTarget( (type == TextureType::TEXTURE_2D)? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
- mType( type ),
- mSampler(),
- mNativeImage(),
- mInternalFormat(GL_RGB),
- mPixelDataType(GL_UNSIGNED_BYTE),
- mWidth( width ),
- mHeight( height ),
- mMaxMipMapLevel(0),
- mHasAlpha( HasAlpha( format ) ),
- mIsCompressed( IsCompressedFormat( format ) )
+Texture::Texture( Type type, Pixel::Format format, ImageDimensions size )
+: mNativeImage(),
+ mSampler(),
+ mId( 0 ),
+ mTarget( ( type == TextureType::TEXTURE_2D ) ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
+ mGlInternalFormat( GL_RGB ),
+ mGlFormat( GL_RGB ),
+ mPixelDataType( GL_UNSIGNED_BYTE ),
+ mWidth( size.GetWidth() ),
+ mHeight( size.GetHeight() ),
+ mMaxMipMapLevel( 0 ),
+ mType( type ),
+ mHasAlpha( HasAlpha( format ) ),
+ mIsCompressed( IsCompressedFormat( format ) )
{
- PixelFormatToGl( format, mPixelDataType, mInternalFormat );
+ PixelFormatToGl( format,
+ mGlFormat,
+ mGlInternalFormat,
+ mPixelDataType );
}
Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
-:mId( 0 ),
- mTarget( GL_TEXTURE_2D ),
- mType( TextureType::TEXTURE_2D ),
- mSampler(),
- mNativeImage( nativeImageInterface ),
- mInternalFormat(GL_RGB),
- mPixelDataType(GL_UNSIGNED_BYTE),
- mWidth( nativeImageInterface->GetWidth() ),
- mHeight( nativeImageInterface->GetHeight() ),
- mMaxMipMapLevel(0),
- mHasAlpha( nativeImageInterface->RequiresBlending() ),
- mIsCompressed( false )
+: mNativeImage( nativeImageInterface ),
+ mSampler(),
+ mId( 0 ),
+ mTarget( GL_TEXTURE_2D ),
+ mGlInternalFormat( GL_RGB ),
+ mGlFormat( GL_RGB ),
+ mPixelDataType( GL_UNSIGNED_BYTE ),
+ mWidth( static_cast<uint16_t >( nativeImageInterface->GetWidth() ) ), // ignoring overflow, not happening in practice
+ mHeight( static_cast<uint16_t >( nativeImageInterface->GetHeight() ) ), // ignoring overflow, not happening in practice
+ mMaxMipMapLevel( 0 ),
+ mType( TextureType::TEXTURE_2D ),
+ mHasAlpha( nativeImageInterface->RequiresBlending() ),
+ mIsCompressed( false )
{
}
{
if( !mIsCompressed )
{
- context.TexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+ context.TexImage2D(GL_TEXTURE_2D, 0, mGlInternalFormat, mWidth, mHeight, 0, mGlFormat, mPixelDataType, 0 );
}
else
{
- context.CompressedTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
+ context.CompressedTexImage2D(GL_TEXTURE_2D, 0, mGlInternalFormat, mWidth, mHeight, 0, 0, 0 );
}
}
else if( mType == TextureType::TEXTURE_CUBE )
{
if( !mIsCompressed )
{
- for( unsigned int i(0); i<6; ++i )
+ for( uint32_t i(0); i<6; ++i )
{
- context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+ context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, mWidth, mHeight, 0, mGlFormat, mPixelDataType, 0 );
}
}
else
{
- for( unsigned int i(0); i<6; ++i )
+ for( uint32_t i(0); i<6; ++i )
{
- context.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
+ context.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, mWidth, mHeight, 0, 0, 0 );
}
}
context.TexParameteri( mTarget, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT );
DALI_ASSERT_ALWAYS( mNativeImage == NULL );
//Get pointer to the data of the PixelData object
- unsigned char* buffer( pixelData->GetBuffer() );
+ uint8_t* buffer( pixelData->GetBuffer() );
//This buffer is only used if manually converting from RGB to RGBA
- unsigned char* tempBuffer(0);
+ std::vector< uint8_t > tempBuffer;
- //Get pixel format and data type of the data contained in the PixelData object
- GLenum pixelDataFormat, pixelDataElementType;
- PixelFormatToGl( pixelData->GetPixelFormat(), pixelDataElementType, pixelDataFormat );
+ //Retrieves the pixel data element type, the gl format and gl internal format of the data contained in the PixelData object.
+ GLenum glFormat;
+ GLint glInternalFormat;
+ GLenum pixelDataElementType;
+ PixelFormatToGl( pixelData->GetPixelFormat(), glFormat, glInternalFormat, pixelDataElementType );
//Get the maximum mipmap level to set GL_TEXTURE_MAX_LEVEL parameter in GLES3x because is not
//necessary to upload all the mipmap levels
( params.width != ( mWidth / ( 1 << params.mipmap ) ) ) ||
( params.height != ( mHeight / ( 1 << params.mipmap ) ) ) );
- bool convert = ( ( pixelDataFormat == GL_RGB ) && ( mInternalFormat == GL_RGBA ) );
-#if DALI_GLES_VERSION >= 30
- // Don't convert manually from RGB to RGBA if GLES >= 3.0 and a sub-image is uploaded.
- convert = convert && !isSubImage;
-#endif
-
- if( convert )
+ if( context.TextureRequiresConverting( glFormat, mGlFormat, isSubImage ) )
{
- size_t dataSize = static_cast< size_t >( params.width ) * params.height;
- tempBuffer = new unsigned char[dataSize*4u];
- for( size_t i(0u); i<dataSize; i++ )
+ uint32_t dataSize = static_cast< uint32_t >( params.width ) * params.height;
+ //reserve() does not allocate the memory on some systems so can crash if not populated using push_back
+ tempBuffer.resize( dataSize * 4u );
+ for( uint32_t i = 0u; i < dataSize; ++i )
{
tempBuffer[i*4u] = buffer[i*3u];
tempBuffer[i*4u+1] = buffer[i*3u+1];
tempBuffer[i*4u+3] = 0xFF;
}
- buffer = tempBuffer;
- pixelDataFormat = mInternalFormat;
+ buffer = &tempBuffer[0];
+ glFormat = mGlFormat; // Set the glFormat to GL_RGBA
}
//Upload data to the texture
//Specifying the whole image for the mipmap. We cannot assume that storage for that mipmap has been created so we need to use TexImage2D
if( !mIsCompressed )
{
- context.TexImage2D( target, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelDataFormat, pixelDataElementType, buffer );
+ context.TexImage2D( target, params.mipmap, mGlInternalFormat, params.width, params.height, 0, glFormat, pixelDataElementType, buffer );
}
else
{
- context.CompressedTexImage2D( target, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelData->GetBufferSize(), buffer );
+ context.CompressedTexImage2D( target, params.mipmap, mGlInternalFormat, params.width, params.height, 0, static_cast<GLsizei>( pixelData->GetBufferSize() ), buffer );
}
}
else
{
context.TexSubImage2D( target, params.mipmap,
params.xOffset, params.yOffset, params.width, params.height,
- pixelDataFormat, pixelDataElementType, buffer );
+ glFormat, pixelDataElementType, buffer );
}
else
{
context.CompressedTexSubImage2D( target, params.mipmap,
params.xOffset, params.yOffset, params.width, params.height,
- pixelDataFormat, pixelData->GetBufferSize(), buffer );
+ glFormat, static_cast<GLsizei>( pixelData->GetBufferSize() ), buffer );
}
}
-
-
- //Destroy temp buffer used for conversion RGB->RGBA
- delete[] tempBuffer;
}
-bool Texture::Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler )
+bool Texture::Bind( Context& context, uint32_t textureUnit, Render::Sampler* sampler )
{
if( mNativeImage && mId == 0 )
{
if( mId != 0 )
{
- context.ActiveTexture( static_cast<TextureUnit>(textureUnit) );
- context.BindTexture( mTarget, mId );
+ context.BindTextureForUnit( static_cast<TextureUnit>( textureUnit ), mTarget, mId );
ApplySampler( context, sampler );
if( mNativeImage )
}
}
-#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
-
}
}