[Vulkan] L8 texture support
authoradam.b <jsr184@gmail.com>
Fri, 18 May 2018 12:14:10 +0000 (13:14 +0100)
committeradam.b <jsr184@gmail.com>
Fri, 25 May 2018 14:00:50 +0000 (15:00 +0100)
- Fixes issue of not displaying single color
text visuals.
- Texture format is passed all the way from the
  RenderCommand

Change-Id: I0fb5eefc5e2c59e6f98e814b6de71368daadffcc

dali/graphics/vulkan/vulkan-graphics-texture.cpp
dali/graphics/vulkan/vulkan-graphics-texture.h
dali/internal/update/rendering/scene-graph-texture.cpp

index 59d1aa8..39c6d0a 100644 (file)
@@ -35,52 +35,22 @@ namespace Vulkan
 {
 using namespace Dali::Graphics::Vulkan;
 
-/**
- * Helper structure, temporary
- */
-struct Pixel
-{
-  Pixel() = default;
-
-  explicit Pixel( uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a )
-  {
-    components.r = _r;
-    components.g = _g;
-    components.b = _b;
-    components.a = _a;
-  }
-
-    struct
-    {
-      uint8_t r, g, b, a;
-    } components;
-
-  /*
-  uint8_t& r = components.r;
-  uint8_t& g = components.g;
-  uint8_t& b = components.b;
-  uint8_t& a = components.a;
-   */
-};
-
 struct Pixmap
 {
-  explicit Pixmap( std::vector<Pixel> _data, uint32_t _width, uint32_t _height )
-  : data( _data ), width( _width ), height( _height ), bytesPerPixel( 4 ), pixelFormat( vk::Format::eR8G8B8A8Unorm )
+  explicit Pixmap( uint32_t _width, uint32_t _height, vk::Format format  )
+    : width( _width ), height( _height ), bytesPerPixel(1), pixelFormat( format )
   {
-  }
+    totalSizeInBytes = width*height*bytesPerPixel;
+    data.resize( totalSizeInBytes );
 
-  explicit Pixmap( uint32_t _width, uint32_t _height )
-  : width( _width ), height( _height ), bytesPerPixel( 4 ), pixelFormat( vk::Format::eR8G8B8A8Unorm )
-  {
-    data.resize( _width * _height );
   }
 
-  std::vector<Pixel> data;
-  uint32_t           width;
-  uint32_t           height;
-  uint32_t           bytesPerPixel;
-  vk::Format         pixelFormat;
+  std::vector<uint8_t>  data;
+  uint32_t              width;
+  uint32_t              height;
+  uint32_t              bytesPerPixel;
+  uint32_t              totalSizeInBytes;
+  vk::Format            pixelFormat;
 };
 
 /**
@@ -91,23 +61,23 @@ struct Pixmap
  */
 struct Texture::Impl
 {
-  Impl( Graphics& graphics, Pixmap pixmap ) : mGraphics( graphics ), mPixmap( pixmap )
-  {
-  }
-
-  Impl( Texture& owner, Graphics& graphics, uint32_t width, uint32_t height, vk::Format format ) : mGraphics( graphics ),
-                                                                                                   mPixmap( width, height )
+  Impl( Texture& owner,
+        Graphics& graphics,
+        uint32_t width,
+        uint32_t height,
+        vk::Format format ) : mGraphics( graphics ),
+        mPixmap( width, height, format )
   {
     mWidth = width;
     mHeight = height;
+    mFormat = format;
   }
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
+
   bool UploadData( const void* data, uint32_t offsetInBytes, uint32_t sizeInBytes )
   {
     // create buffer
     auto& allocator = mGraphics.GetDeviceMemoryManager().GetDefaultAllocator();
-    auto size   = mPixmap.data.size() * sizeof( mPixmap.data[0] );
+    auto size   = sizeInBytes;
     auto buffer = Buffer::New( mGraphics,
                                vk::BufferCreateInfo{}
                                  .setUsage( vk::BufferUsageFlagBits::eTransferSrc )
@@ -207,7 +177,7 @@ struct Texture::Impl
 
     return true;
   }
-#pragma GCC diagnostic pop
+
   void CreateSampler()
   {
     // mutable sampler creation will be deferred until it's used
@@ -243,6 +213,7 @@ struct Texture::Impl
   vk::ImageLayout mNewLayout;
 
   uint32_t mWidth { 0u }, mHeight { 0u };
+  vk::Format mFormat {};
   // Command pool
   Pixmap mPixmap;
 };
index b9d4668..d53bba2 100644 (file)
@@ -20,7 +20,6 @@
 
 // INTERNAL INCLUDES
 #include <dali/graphics/vulkan/vulkan-types.h>
-#include <dali/graphics/graphics-controller.h>
 
 namespace Dali
 {
index 2d48974..a7921ed 100644 (file)
@@ -172,8 +172,16 @@ void Texture::UploadTexture( PixelDataPtr pixelData, const Internal::Texture::Up
   {
     auto& controller = mGraphics->GetController();
 
+    auto format = Graphics::API::TextureDetails::Format::RGBA8;
+    auto pixelFormat = pixelData->GetPixelFormat();
+    if( pixelFormat == Dali::Pixel::Format::L8 )
+    {
+      format = Graphics::API::TextureDetails::Format::L8;
+    }
+
+
     mGraphicsTexture = controller.CreateTexture( controller.GetTextureFactory()
-                                                 .SetFormat( Graphics::API::TextureDetails::Format::RGBA8 )
+                                                 .SetFormat( format )
                                                  .SetSize( { pixelData->GetWidth(), pixelData->GetHeight() } )
                                                  .SetType( Graphics::API::TextureDetails::Type::TEXTURE_2D )
                                                  .SetMipMapFlag( Graphics::API::TextureDetails::MipMapFlag::DISABLED )