[Problem] There was a bug in the image filtering code that was setting default filtering to nearest mode
[Solution] The default will now be linear
Change-Id: Ibdf52b0ffbf55cb3d9885efc03c30579fb04228e
application.Render(); //Process render Q stores & processes mat
renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
- renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
DALI_TEST_CHECK( boundTextures.GetNumBoundTextures() == 0 );
DALI_TEST_EQUALS( testProgram.GetOpacity(), TEST_PROPS.mOpacity, TEST_LOCATION);
application.Render(); //Process render Q stores & processes mat
renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
- renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
DALI_TEST_CHECK( boundTextures.GetNumBoundTextures() == 0 );
DALI_TEST_EQUALS( testProgram.GetOpacity(), 0.4f, TEST_LOCATION);
Internal::SceneGraph::RenderMaterialUniforms materialUniforms;
renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
- renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION );
application.Render(); // Update & Prepare material
application.Render(); // Process render Q
- renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) );
END_TEST;
}
application.Render(); // Update & Prepare material
application.Render(); // Process render Q
- renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION );
application.Render(); // Process LoadComplete
application.SendNotification(); // Process event messages
- renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) );
END_TEST;
}
// Verify actor gl state
- // The first one should be true as we don't want to use the GL default
- // The second one should be false as we want to use the GL default, therefore the TexParameter function should not be called
// There are two calls to TexParameteri when the texture is first created
+ // Texture mag filter is not called as the first time set it uses the system default
DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
out.str("");
/**************************************************************/
+ // Default/Default
+ texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+
+ actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
+
+ // Flush the queue and render once
+ application.SendNotification();
+ application.Render();
+
+ texParameterTrace.Enable( false );
+
+ // Verify actor gl state
+
+ // Should not make any calls when settings are the same
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
+
+ /**************************************************************/
+
// Nearest/Nearest
texParameterTrace.Reset();
texParameterTrace.Enable( true );
texParameterTrace.Enable( false );
// Verify actor gl state
- DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
out.str("");
out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
+ /**************************************************************/
+
+ // Default/Default
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+
+ actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
+
+ // Flush the queue and render once
+ application.SendNotification();
+ application.Render();
+
+ texParameterTrace.Enable( false );
+
+ // Verify actor gl state
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
+
out.str("");
- out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
- DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
+ out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
+ DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
+
+ /**************************************************************/
+
+ // None/None
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+
+ actor.SetFilterMode( FilterMode::NONE, FilterMode::NONE );
+
+ // Flush the queue and render once
+ application.SendNotification();
+ application.Render();
+
+ texParameterTrace.Enable( false );
+
+ // Verify actor gl state
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
+
+ out.str("");
+ out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
+ DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
/**************************************************************/
const int MASK_MINIFY_FILTER = 0x0000000F;
const int MASK_MAGNIFY_FILTER = 0x000000F0;
-const unsigned int FILTER_MODE_COUNT = 3;
+const unsigned int FILTER_MODE_COUNT = 4;
FilterMode::Type FILTER_MODE_OPTIONS[ FILTER_MODE_COUNT ] =
- { FilterMode::DEFAULT,
+ { FilterMode::NONE,
+ FilterMode::DEFAULT,
FilterMode::NEAREST,
FilterMode::LINEAR };
-// These are the default sampling options - must match what is in GL
-const FilterMode::Type DEFAULT_MINIFY = FilterMode::LINEAR;
-const FilterMode::Type DEFAULT_MAGNIFY = FilterMode::LINEAR;
-
} // namespace
/**
// Start shifting from 1 as 0 is the unassigned state
switch ( mode )
{
+ case FilterMode::NONE:
+ {
+ // Nothing to do
+ break;
+ }
case FilterMode::DEFAULT:
{
options |= ( 1u << bitShift );
* @param[in] options A bitmask of filter values.
* @param[in] mask The used to mask unwanted values.
* @param[in] bitshift Used to shift to the correct part of options.
- * @return The filter mode.
+ * @return Return the filter mode.
*/
-bool RetrieveFilterMode( unsigned int options, int mask, int bitShift, FilterMode::Type& filterModeOut )
+FilterMode::Type RetrieveFilterMode( unsigned int options, int mask, int bitShift )
{
unsigned int index = options & mask;
- if( index != 0 )
- {
- index = ( index >> bitShift ) - 1; // Zero based index for array
-
- DALI_ASSERT_DEBUG( index < FILTER_MODE_COUNT );
-
- filterModeOut = FILTER_MODE_OPTIONS[ index ];
- return true;
- }
-
- return false;
-}
+ index = ( index >> bitShift ); // Zero based index for array
-unsigned int DefaultOptions()
-{
- // Only initialise min filter as mag filter will use the system default
- unsigned int bitfield = 0;
- StoreFilterMode( bitfield, DEFAULT_MINIFY, MINIFY_BIT_SHIFT );
- return bitfield;
-}
+ DALI_ASSERT_DEBUG( index < FILTER_MODE_COUNT );
-bool IsMinifyAssigned( unsigned int bitfield )
-{
- FilterMode::Type filterModeDummy = FilterMode::NEAREST;
- return RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT, filterModeDummy );
-}
-
-bool IsMagnifyAssigned( unsigned int bitfield )
-{
- FilterMode::Type filterModeDummy = FilterMode::NEAREST;
- return RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT, filterModeDummy );
+ return FILTER_MODE_OPTIONS[ index ];
}
unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify )
FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
{
- FilterMode::Type filterMode = FilterMode::NEAREST;
- RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT, filterMode );
- return filterMode;
+ return RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT );
}
FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
{
- FilterMode::Type filterMode = FilterMode::NEAREST;
- RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT, filterMode );
- return filterMode;
+ return RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT );
}
} // namespace ImageSampler
*/
namespace ImageSampler
{
-
- /**
- * Determine if the minify component of the bitfield is assigned.
- *
- * @param[in] bitfield The packed sampler bitfield pattern.
- * @return Return if the minify component is assigned or not.
- */
- bool IsMinifyAssigned( unsigned int bitfield );
-
- /**
- * Determine if the magnify component of the bitfield is assigned.
- *
- * @param[in] bitfield The packed sampler bitfield pattern.
- * @return Return if the magnify component is assigned or not.
- */
- bool IsMagnifyAssigned( unsigned int bitfield );
-
- /**
- * @brief Return a sampler bitfield with default settings.
- *
- * @return Return the default sampler bit pattern.
- */
- unsigned int DefaultOptions();
-
/**
* @brief Pack the filter mode into a bitfield.
*
namespace Internal
{
+namespace
+{
+
+// These match the GL specification
+const GLint SYSTEM_MINIFY_DEFAULT = GL_NEAREST_MIPMAP_LINEAR;
+const GLint SYSTEM_MAGNIFY_DEFAULT = GL_LINEAR;
+
+// These are the Dali defaults
+const GLint DALI_MINIFY_DEFAULT = GL_LINEAR;
+const GLint DALI_MAGNIFY_DEFAULT = GL_LINEAR;
+
+} // namespace
+
/**
- * Convert a FilterMode to it's corresponding GL type.
+ * @brief Convert a FilterMode to it's corresponding GL type.
*
* @param[in] filterMode The FilterMode type.
+ * @param[in] defaultfilterMode The filter mode to use if filterMode is DEFAULT.
+ * @param[in] defaultSystemFilterMode The filter mode to use if filterMode is NONE.
* @return Return the equivalent GL type.
*/
-GLint FilterModeToGL( FilterMode::Type filterMode )
+GLint FilterModeToGL( FilterMode::Type filterMode, GLint defaultfilterMode, GLint defaultSystemFilterMode )
{
switch( filterMode )
{
{
return GL_LINEAR;
}
+ case FilterMode::NONE:
+ {
+ return defaultSystemFilterMode;
+ }
case FilterMode::DEFAULT:
{
- // Do nothing
+ return defaultfilterMode;
}
}
}
+void Texture::ApplyTextureParameter( GLint filterType, FilterMode::Type currentFilterMode, FilterMode::Type newFilterMode, GLint daliDefault, GLint systemDefault )
+{
+ GLint newFilterModeGL = FilterModeToGL( newFilterMode, daliDefault, systemDefault );
+ GLint currentFilterModeGL = FilterModeToGL( currentFilterMode, daliDefault, systemDefault );
+
+ if( newFilterModeGL != currentFilterModeGL )
+ {
+ mContext.TexParameteri( GL_TEXTURE_2D, filterType, newFilterModeGL );
+ }
+}
+
void Texture::ApplySampler( unsigned int samplerBitfield )
{
if( mSamplerBitfield != samplerBitfield )
{
- // Only set the tex parameters if they have been set in the sampler bitfield
- FilterMode::Type filterMode = ImageSampler::GetMinifyFilterMode( samplerBitfield );
- if( filterMode != FilterMode::DEFAULT )
- {
- mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilterModeToGL( filterMode ) );
- }
- else // We don't want to use the GL default
- {
- // Reset to system default option
- mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilterModeToGL( ImageSampler::GetMinifyFilterMode( ImageSampler::DefaultOptions() ) ) );
- }
-
- filterMode = ImageSampler::GetMagnifyFilterMode( samplerBitfield );
- if( filterMode != FilterMode::DEFAULT )
- {
- mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FilterModeToGL( filterMode ) );
- }
- else if( ImageSampler::IsMagnifyAssigned( mSamplerBitfield ) ) // We want to use the GL default
- {
- // Reset to system default option
- mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FilterModeToGL( ImageSampler::GetMagnifyFilterMode( ImageSampler::DefaultOptions() ) ) );
- }
+ ApplyTextureParameter( GL_TEXTURE_MIN_FILTER,
+ ImageSampler::GetMinifyFilterMode( mSamplerBitfield ),
+ ImageSampler::GetMinifyFilterMode( samplerBitfield ),
+ DALI_MINIFY_DEFAULT,
+ SYSTEM_MINIFY_DEFAULT );
+
+ ApplyTextureParameter( GL_TEXTURE_MAG_FILTER,
+ ImageSampler::GetMagnifyFilterMode( mSamplerBitfield ),
+ ImageSampler::GetMagnifyFilterMode( samplerBitfield ),
+ DALI_MAGNIFY_DEFAULT,
+ SYSTEM_MAGNIFY_DEFAULT );
mSamplerBitfield = samplerBitfield;
}
#include <dali/public-api/images/pixel.h>
#include <dali/public-api/images/native-image.h>
#include <dali/public-api/math/rect.h>
+#include <dali/public-api/actors/sampling.h>
namespace Dali
{
*/
void GetDefaultTextureCoordinates(UvRect& uv) const;
+ /**
+ * @brief Apply the given texture parameters.
+ *
+ * @param[in] filterType Minification or magnification.
+ * @param[in] currentFilterMode The current filter mode.
+ * @param[in] newFilterMode The new filter mode.
+ * @param[in] daliDefault The default dali filter mode for the given filterType.
+ * @param[in] systemDefault The default system filter mode for the given filterType.
+ */
+ void ApplyTextureParameter( GLint filterType, FilterMode::Type currentFilterMode, FilterMode::Type newFilterMode, GLint daliDefault, GLint systemDefault );
+
protected:
Context& mContext; ///< The GL Context
mTextureCache( NULL ),
mShader( NULL ),
- mSamplerBitfield( ImageSampler::DefaultOptions() ),
+ mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
mUseBlend( false ),
mCullFaceMode( CullNone )
{
// got effect texture, bind it to texture unit 1
mTexture->Bind( GL_TEXTURE_2D, GL_TEXTURE1 );
// Just apply the default sampling options for now
- mTexture->ApplySampler( ImageSampler::DefaultOptions() );
+ mTexture->ApplySampler( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
// get effect sampler uniform
const GLint loc = program.GetUniformLocation( Program::UNIFORM_EFFECT_SAMPLER );
*/
enum Type
{
- DEFAULT,
+ NONE, ///< Use GL system defaults (minification NEAREST_MIPMAP_LINEAR, magnification LINEAR)
+ DEFAULT, ///< Use dali defaults (minification LINEAR, magnification LINEAR)
NEAREST, ///< Filter nearest
LINEAR ///< Filter linear
};