Texture mipmap support 20/257920/1
authorRichard Huang <r.huang@samsung.com>
Thu, 6 May 2021 10:32:26 +0000 (11:32 +0100)
committerRichard Huang <r.huang@samsung.com>
Thu, 6 May 2021 10:32:26 +0000 (11:32 +0100)
Change-Id: Ib4976689df8f51a15f6bc3899c9064970bd6baf2

automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h
automated-tests/src/dali/utc-Dali-Texture.cpp
dali/graphics-api/graphics-controller.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h

index a3a0feef74fb43501547271093e959e9495eacb4..e5db6ed8937637331d60224c254660f4fbb3200d 100644 (file)
@@ -996,6 +996,15 @@ void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureU
   }
 }
 
+void TestGraphicsController::GenerateTextureMipmaps(const Graphics::Texture& texture)
+{
+  mCallStack.PushCall("GenerateTextureMipmaps", "");
+
+  auto gfxTexture = Uncast<TestGraphicsTexture>(&texture);
+  mGl.BindTexture(gfxTexture->GetTarget(), 0);
+  mGl.GenerateMipmap(gfxTexture->GetTarget());
+}
+
 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
 {
   TraceCallStack::NamedParams namedParams;
index 1d93bfa33965033b00ec5e44f74f53a19b7b4168..1c62119ae979ae49ce07f51b39cc1e75296dcde8 100644 (file)
@@ -161,6 +161,12 @@ public:
   void UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>&       updateInfoList,
                       const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList) override;
 
+  /**
+   * Auto generates mipmaps for the texture
+   * @param[in] texture The texture
+   */
+  void GenerateTextureMipmaps(const Graphics::Texture& texture) override;
+
   /**
    * TBD: do we need those functions in the new implementation?
    */
index 083066194d26033bbee3710175821347c6ddcc76..b278b8c2b40441ccc49785f59273bb6f339f22ca 100644 (file)
@@ -757,7 +757,6 @@ int UtcDaliTextureUploadSmallerThanSize(void)
 
 int UtcDaliTextureGenerateMipmaps(void)
 {
-#ifdef OLD_GRAPHICS_TEST
   TestApplication application;
   unsigned int    width(64);
   unsigned int    height(64);
@@ -783,9 +782,6 @@ int UtcDaliTextureGenerateMipmaps(void)
     out << GL_TEXTURE_CUBE_MAP;
     DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
   }
-#else
-  DALI_TEST_CHECK(1);
-#endif
 
   END_TEST;
 }
index db672a05f1a1a096d439c2327ce681929228144f..024b0da00ef9ae51e670d38c1790d9cb2d7839ff 100644 (file)
@@ -135,6 +135,12 @@ public:
   virtual void UpdateTextures(const std::vector<TextureUpdateInfo>&       updateInfoList,
                               const std::vector<TextureUpdateSourceInfo>& sourceList) = 0;
 
+  /**
+   * Auto generates mipmaps for the texture
+   * @param[in] texture The texture
+   */
+  virtual void GenerateTextureMipmaps(const Texture& texture) = 0;
+
   /**
    * @brief Enables depth/stencil buffer
    *
@@ -362,7 +368,7 @@ public:
    * @param[out] outData Pointer to output memory
    * @return True on success
    */
-  virtual bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData ) = 0;
+  virtual bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) = 0;
 
 protected:
   /**
index 5d7a53f2510a9750cd6a1bfa3b6da593c51dd9b4..1e74ce38278f364afeb49b4af42e57a3d2fe90c0 100644 (file)
@@ -206,7 +206,6 @@ Texture::Texture(Type type, Pixel::Format format, ImageDimensions size)
   mPixelFormat(format),
   mWidth(size.GetWidth()),
   mHeight(size.GetHeight()),
-  mMaxMipMapLevel(0),
   mType(type),
   mHasAlpha(HasAlpha(format))
 {
@@ -220,7 +219,6 @@ Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
   mPixelFormat(Pixel::RGBA8888),
   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())
 {
@@ -310,9 +308,12 @@ bool Texture::HasAlphaChannel() const
 
 void Texture::GenerateMipmaps()
 {
-  mMaxMipMapLevel = 0;
-  DALI_LOG_ERROR("FIXME: GRAPHICS");
-  //@todo Implement with Graphics API
+  if(!mGraphicsTexture)
+  {
+    Create(static_cast<Graphics::TextureUsageFlags>(Graphics::TextureUsageFlagBits::SAMPLE));
+  }
+
+  mGraphicsController->GenerateTextureMipmaps(*mGraphicsTexture.get());
 }
 
 } // namespace Render
index d38bc817730943ce1f1cbca897e5a786a04fad1c..5d9704b28fcc6f0d035602ac5812c2819f336040 100644 (file)
@@ -146,12 +146,11 @@ private:
   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
   Render::Sampler         mSampler;     ///< The current sampler state
 
-  Pixel::Format mPixelFormat;    ///< Pixel format of the texture
-  uint16_t      mWidth;          ///< Width of the texture
-  uint16_t      mHeight;         ///< Height of the texture
-  uint16_t      mMaxMipMapLevel; ///< Maximum mipmap level
-  Type          mType : 3;       ///< Type of the texture
-  bool          mHasAlpha : 1;   ///< Whether the format has an alpha channel
+  Pixel::Format mPixelFormat;  ///< Pixel format of the texture
+  uint16_t      mWidth;        ///< Width of the texture
+  uint16_t      mHeight;       ///< Height of the texture
+  Type          mType : 3;     ///< Type of the texture
+  bool          mHasAlpha : 1; ///< Whether the format has an alpha channel
 };
 
 } // namespace Render