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 a3a0fee..e5db6ed 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 1d93bfa..1c62119 100644 (file)
@@ -162,6 +162,12 @@ public:
                       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?
    */
   bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) override;
index 0830661..b278b8c 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 db672a0..024b0da 100644 (file)
@@ -136,6 +136,12 @@ public:
                               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
    *
    * @param[in] enableDepth True to enable depth
@@ -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 5d7a53f..1e74ce3 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 d38bc81..5d9704b 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