Stop calculating default filter and wrap modes every frame for every sampler 47/50047/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 23 Oct 2015 10:39:55 +0000 (11:39 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 23 Oct 2015 12:18:42 +0000 (13:18 +0100)
Change-Id: I1b21ca06abc140252dbc7db6bd6b9b5959620a88

dali/internal/common/image-sampler.cpp
dali/internal/common/image-sampler.h
dali/internal/render/renderers/render-new-renderer.cpp
dali/internal/render/renderers/render-sampler.h
dali/internal/render/renderers/render-texture.h
dali/internal/update/rendering/scene-graph-material.h
dali/public-api/actors/sampling.h

index f008580..4401507 100644 (file)
@@ -30,24 +30,6 @@ namespace Internal
 namespace ImageSampler
 {
 
-namespace
-{
-
-// @todo MESH_REWORK Remove file after image removal
-
-// Adjust these shift sizes if the FilterMode enum grows
-const int MINIFY_BIT_SHIFT  = 0;    // Room for 16
-const int MAGNIFY_BIT_SHIFT = 4;
-const int UWRAP_BIT_SHIFT   = 8;
-const int VWRAP_BIT_SHIFT   = 12;
-
-const int MASK_MINIFY_FILTER    = 0x0000000F;
-const int MASK_MAGNIFY_FILTER   = 0x000000F0;
-const int MASK_UWRAP_MODE       = 0x00000F00;
-const int MASK_VWRAP_MODE       = 0x0000F000;
-
-} // namespace
-
 /**
  * Utility to store one of the sampling parameters values.
  * @param[out] options A bitmask used to store the FilterMode values.
index 53c3f0b..836253e 100644 (file)
@@ -32,6 +32,36 @@ namespace Internal
  */
 namespace ImageSampler
 {
+   /**
+    * Bitshift values
+    */
+   enum
+   {
+     MINIFY_BIT_SHIFT  = 0,
+     MAGNIFY_BIT_SHIFT = 4,
+     UWRAP_BIT_SHIFT   = 8,
+     VWRAP_BIT_SHIFT   = 12
+   };
+
+   /**
+    * Mask values
+    */
+   enum
+   {
+     MASK_MINIFY_FILTER  = 0x000F,
+     MASK_MAGNIFY_FILTER = 0x00F0,
+     MASK_UWRAP_MODE     = 0x0F00,
+     MASK_VWRAP_MODE     = 0xF000,
+   };
+
+   /**
+    * Precalculate default sampler bitfield
+    */
+   enum
+   {
+     DEFAULT_BITFIELD = (Dali::FilterMode::DEFAULT<<MINIFY_BIT_SHIFT) | (Dali::FilterMode::DEFAULT<<MAGNIFY_BIT_SHIFT) | (Dali::WrapMode::DEFAULT<<UWRAP_BIT_SHIFT) | (Dali::WrapMode::DEFAULT<<VWRAP_BIT_SHIFT)
+   };
+
   /**
    * @brief Pack the filter mode into a bitfield.
    *
index ae500f7..aa2ea2c 100644 (file)
@@ -286,7 +286,6 @@ void NewRenderer::BindTextures(
   SceneGraph::TextureCache& textureCache,
   Program& program )
 {
-  // @todo MESH_REWORK Write a cache of texture units to commonly used sampler textures
   int textureUnit = 0;
 
   const std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures());
@@ -319,7 +318,7 @@ void NewRenderer::BindTextures(
       }
       else
       {
-        samplerBitfield = ImageSampler::PackBitfield(FilterMode::DEFAULT, FilterMode::DEFAULT, WrapMode::DEFAULT, WrapMode::DEFAULT);
+        samplerBitfield = ImageSampler::DEFAULT_BITFIELD;
       }
 
       texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
index d5c94ba..5754e13 100644 (file)
@@ -37,7 +37,7 @@ public:
    * Constructor
    */
   Sampler()
-  : mMinFilter( Dali::FilterMode::DEFAULT),
+  : mMinFilter( Dali::FilterMode::DEFAULT ),
     mMagFilter( Dali::FilterMode::DEFAULT ),
     mUWrapMode( Dali::WrapMode::DEFAULT ),
     mVWrapMode( Dali::WrapMode::DEFAULT )
@@ -46,7 +46,8 @@ public:
   /**
    * Destructor
    */
-  virtual ~Sampler(){}
+  ~Sampler()
+  {}
 
   /**
    * Set the filter modes for minify and magnify filters
@@ -75,7 +76,7 @@ public:
    * Get the filter mode
    * @return The minify filter mode
    */
-  virtual FilterMode GetMinifyFilterMode() const
+  FilterMode GetMinifyFilterMode() const
   {
     return mMinFilter;
   }
@@ -84,7 +85,7 @@ public:
    * Get the filter mode
    * @return The magnify filter mode
    */
-  virtual FilterMode GetMagnifyFilterMode() const
+  FilterMode GetMagnifyFilterMode() const
   {
     return mMagFilter;
   }
@@ -93,7 +94,7 @@ public:
    * Get the horizontal wrap mode
    * @return The horizontal wrap mode
    */
-  virtual WrapMode GetUWrapMode() const
+  WrapMode GetUWrapMode() const
   {
     return mUWrapMode;
   }
@@ -102,7 +103,7 @@ public:
    * Get the vertical wrap mode
    * @return The vertical wrap mode
    */
-  virtual WrapMode GetVWrapMode() const
+  WrapMode GetVWrapMode() const
   {
     return mVWrapMode;
   }
@@ -113,13 +114,13 @@ private:
   FilterMode  mMagFilter;    ///< The magnify filter
   WrapMode  mUWrapMode;    ///< The horizontal wrap mode
   WrapMode  mVWrapMode;    ///< The vertical wrap mode
+
 };
 
 } // namespace Render
 
-
-
 } // namespace Internal
+
 } // namespace Dali
 
 
index bb79d83..35ed3a1 100644 (file)
@@ -37,18 +37,18 @@ public:
    * Constructor
    */
   Texture()
-  :mUniformName(""),
-   mTextureId(Integration::InvalidResourceId),
-   mSampler(0)
+  :mUniformName(),
+   mSampler(0),
+   mTextureId(Integration::InvalidResourceId)
   {}
 
   /**
    * Constructor
    */
-  Texture( const char* samplerName, Integration::ResourceId textureId, Render::Sampler* sampler )
-  :mUniformName(samplerName),
-   mTextureId( textureId),
-   mSampler(sampler)
+  Texture( const std::string& samplerName, Integration::ResourceId textureId, Render::Sampler* sampler )
+  :mUniformName( samplerName ),
+   mSampler( sampler ),
+   mTextureId( textureId)
   {}
 
   /**
@@ -66,7 +66,8 @@ public:
     return mSampler;
   }
 
-public: // SamplerDataProvider interface - called from RenderThread
+public: // called from RenderThread
+
   /**
    * Get the texture unit uniform name
    * @return the name of the texture unit uniform
@@ -87,9 +88,9 @@ public: // SamplerDataProvider interface - called from RenderThread
   }
 
 private:
-  std::string               mUniformName;
-  Integration::ResourceId   mTextureId;
-  Render::Sampler*          mSampler;
+  std::string             mUniformName;
+  Render::Sampler*        mSampler;
+  Integration::ResourceId mTextureId;
 };
 
 } // namespace SceneGraph
index e4a7bc2..3f13d1e 100644 (file)
@@ -227,9 +227,9 @@ public:
    * @param[in] index The index of the texture in the textures array
    * @return the uniform name
    */
-  const char* GetTextureUniformName( size_t index )
+  const std::string& GetTextureUniformName( size_t index )
   {
-    return mUniformName[index].c_str();
+    return mUniformName[index];
   }
 
   /**
index 4cf7a48..233442b 100644 (file)
@@ -36,8 +36,8 @@ namespace FilterMode
  */
 enum Type
 {
-  NONE = 0,       ///< Use GL system defaults (minification NEAREST_MIPMAP_LINEAR, magnification LINEAR)
-  DEFAULT,    ///< Use dali defaults (minification LINEAR, magnification LINEAR)
+  NONE = 0,   ///< Use GL defaults (minification NEAREST_MIPMAP_LINEAR, magnification LINEAR)
+  DEFAULT,    ///< Use Dali defaults (minification LINEAR, magnification LINEAR)
   NEAREST,    ///< Filter nearest
   LINEAR      ///< Filter linear
 };