[Tizen] Using Depth and Stencil buffer & texture
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-texture.cpp
index c993e67..d6783a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -517,6 +517,28 @@ void PixelFormatToGl( Pixel::Format pixelFormat, GLenum& glFormat, GLint& glInte
       break;
     }
 
+    // GLES 3.0 depth and stencil formats
+    case Pixel::DEPTH_UNSIGNED_INT:
+    {
+      glFormat = GL_DEPTH_COMPONENT;
+      pixelDataType = GL_UNSIGNED_INT;
+      break;
+    }
+
+    case Pixel::DEPTH_FLOAT:
+    {
+      glFormat = GL_DEPTH_COMPONENT;
+      pixelDataType = GL_FLOAT;
+      break;
+    }
+
+    case Pixel::DEPTH_STENCIL:
+    {
+      glFormat = GL_DEPTH_STENCIL;
+      pixelDataType = GL_UNSIGNED_INT_24_8;
+      break;
+    }
+
     case Pixel::INVALID:
     {
       DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
@@ -533,6 +555,16 @@ void PixelFormatToGl( Pixel::Format pixelFormat, GLenum& glFormat, GLint& glInte
       glInternalFormat = GL_R11F_G11F_B10F;
       break;
     }
+    case Pixel::DEPTH_FLOAT:
+    {
+      glInternalFormat = GL_DEPTH_COMPONENT32F;
+      break;
+    }
+    case Pixel::DEPTH_STENCIL:
+    {
+      glInternalFormat = GL_DEPTH24_STENCIL8;
+      break;
+    }
     default:
     {
       glInternalFormat = glFormat;
@@ -568,6 +600,9 @@ bool IsCompressedFormat(Pixel::Format pixelFormat)
     case Pixel::BGRA8888:
     case Pixel::RGB16F:
     case Pixel::RGB32F:
+    case Pixel::DEPTH_UNSIGNED_INT:
+    case Pixel::DEPTH_FLOAT:
+    case Pixel::DEPTH_STENCIL:
     case Pixel::INVALID:
     {
       return false;
@@ -766,6 +801,9 @@ void Texture::Upload( Context& context, PixelDataPtr pixelData, const Internal::
   //Get pointer to the data of the PixelData object
   uint8_t* buffer( pixelData->GetBuffer() );
 
+  //This buffer is only used if manually converting from RGB to RGBA
+  std::vector< uint8_t > tempBuffer;
+
   //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;
@@ -781,8 +819,22 @@ void Texture::Upload( Context& context, PixelDataPtr pixelData, const Internal::
                             ( params.width  != ( mWidth  / ( 1 << params.mipmap ) ) ) ||
                             ( params.height != ( mHeight / ( 1 << params.mipmap ) ) ) );
 
-  uint32_t dataSize = static_cast< uint32_t >( params.width ) * params.height;
-  context.ConvertTexture( buffer, glFormat, dataSize, mGlFormat, isSubImage );
+  if( context.TextureRequiresConverting( glFormat, mGlFormat, isSubImage ) )
+  {
+    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+2] = buffer[i*3u+2];
+      tempBuffer[i*4u+3] = 0xFF;
+    }
+
+    buffer = &tempBuffer[0];
+    glFormat = mGlFormat; // Set the glFormat to GL_RGBA
+  }
 
   //Upload data to the texture
 
@@ -895,7 +947,7 @@ void Texture::ApplySampler( Context& context, Render::Sampler* sampler )
   }
 }
 
-bool Texture::HasAlphaChannel()
+bool Texture::HasAlphaChannel() const
 {
   return mHasAlpha;
 }