Add ability to set texture filtering modes per RenderableActor.
Change-Id: I1d0572a27cb75226b095a4cb31b21197539959d7
#include <dali/internal/render/renderers/render-material.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/shaders/program.h>
+#include <dali/internal/common/image-sampler.h>
namespace
{
application.Render(); //Process render Q stores & processes mat
renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
- renderMaterial->BindTextures( testProgram.GetProgram() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
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() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
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() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION );
application.Render(); // Update & Prepare material
application.Render(); // Process render Q
- renderMaterial->BindTextures( testProgram.GetProgram() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) );
END_TEST;
}
application.Render(); // Update & Prepare material
application.Render(); // Process render Q
- renderMaterial->BindTextures( testProgram.GetProgram() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION );
application.Render(); // Process LoadComplete
application.SendNotification(); // Process event messages
- renderMaterial->BindTextures( testProgram.GetProgram() );
+ renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::DefaultOptions() );
DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) );
END_TEST;
}
inline void TexParameterf(GLenum target, GLenum pname, GLfloat param)
{
+ std::stringstream out;
+ out << target << ", " << pname << ", " << param;
+ mTexParamaterTrace.PushCall("TexParameterf", out.str());
}
inline void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
{
+ std::stringstream out;
+ out << target << ", " << pname << ", " << params[0];
+ mTexParamaterTrace.PushCall("TexParameterfv", out.str());
}
inline void TexParameteri(GLenum target, GLenum pname, GLint param)
{
+ std::stringstream out;
+ out << target << ", " << pname << ", " << param;
+ mTexParamaterTrace.PushCall("TexParameteri", out.str());
}
inline void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
{
+ std::stringstream out;
+ out << target << ", " << pname << ", " << params[0];
+ mTexParamaterTrace.PushCall("TexParameteriv", out.str());
}
inline void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
inline void ResetTextureCallStack() { mTextureTrace.Reset(); }
inline TraceCallStack& GetTextureTrace() { return mTextureTrace; }
+ //Methods for Texture verification
+ inline void EnableTexParameterCallTrace(bool enable) { mTexParamaterTrace.Enable(enable); }
+ inline void ResetTexParameterCallStack() { mTexParamaterTrace.Reset(); }
+ inline TraceCallStack& GetTexParameterTrace() { return mTexParamaterTrace; }
+
//Methods for Draw verification
inline void EnableDrawCallTrace(bool enable) { mDrawTrace.Enable(enable); }
inline void ResetDrawCallStack() { mDrawTrace.Reset(); }
TraceCallStack mCullFaceTrace;
TraceCallStack mShaderTrace;
TraceCallStack mTextureTrace;
+ TraceCallStack mTexParamaterTrace;
TraceCallStack mDrawTrace;
// Shaders & Uniforms
delete ractor;
END_TEST;
}
+
+int UtcDaliRenderableActorSetGetFilterModes(void)
+{
+ TestApplication application;
+
+ tet_infoline("Testing Dali::RenderableActor::SetFilterMode() / Dali::RenderableActor::GetFilterMode()");
+
+ TextActor actor = TextActor::New(TestTextHelloWorld);
+
+ FilterMode::Type minifyFilter = FilterMode::NEAREST;
+ FilterMode::Type magnifyFilter = FilterMode::NEAREST;
+
+ // Default test
+ actor.GetFilterMode( minifyFilter, magnifyFilter );
+ DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
+ DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
+
+ // Default/Default
+ actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
+ actor.GetFilterMode( minifyFilter, magnifyFilter );
+ DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
+ DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
+
+ // Nearest/Nearest
+ actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+ actor.GetFilterMode( minifyFilter, magnifyFilter );
+ DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
+ DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
+
+ // Linear/Linear
+ actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
+ actor.GetFilterMode( minifyFilter, magnifyFilter );
+ DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
+ DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
+
+ // Nearest/Linear
+ actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
+ actor.GetFilterMode( minifyFilter, magnifyFilter );
+ DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
+ DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
+
+ // Linear/Nearest
+ actor.SetFilterMode( FilterMode::LINEAR, FilterMode::NEAREST );
+ actor.GetFilterMode( minifyFilter, magnifyFilter );
+ DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
+ DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
+
+ END_TEST;
+}
+
+int UtcDaliRenderableActorSetFilterMode(void)
+{
+ TestApplication application;
+
+ tet_infoline("Testing Dali::RenderableActor::SetFilterMode()");
+
+ BitmapImage img = BitmapImage::New( 1,1 );
+ ImageActor actor = ImageActor::New( img );
+
+ actor.SetSize(100.0f, 100.0f);
+ actor.SetParentOrigin(ParentOrigin::CENTER);
+ actor.SetAnchorPoint(AnchorPoint::CENTER);
+
+ Stage::GetCurrent().Add(actor);
+
+ /**************************************************************/
+
+ // Default/Default
+ TraceCallStack& 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 );
+
+ std::stringstream out;
+
+ // 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
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
+
+ out.str("");
+ out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
+ DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
+
+ /**************************************************************/
+
+ // Nearest/Nearest
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+
+ actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+
+ // Flush the queue and render once
+ application.SendNotification();
+ application.Render();
+
+ texParameterTrace.Enable( false );
+
+ // Verify actor gl state
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, 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);
+
+ out.str("");
+ out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
+ DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
+
+ /**************************************************************/
+
+ // Linear/Linear
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+
+ actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
+
+ // Flush the queue and render once
+ application.SendNotification();
+ application.Render();
+
+ texParameterTrace.Enable( false );
+
+ // Verify actor gl state
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
+
+ out.str("");
+ out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
+ DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, 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);
+
+
+ /**************************************************************/
+
+ // Nearest/Linear
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+
+ actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
+
+ // Flush the queue and render once
+ application.SendNotification();
+ application.Render();
+
+ texParameterTrace.Enable( false );
+
+ // Verify actor gl state
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, 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);
+
+ out.str("");
+ out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
+ DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
+
+ /**************************************************************/
+
+ Stage::GetCurrent().Remove(actor);
+
+ END_TEST;
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/common/image-sampler.h>
+
+#include <iostream>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace ImageSampler
+{
+
+namespace
+{
+
+// 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 MASK_MINIFY_FILTER = 0x0000000F;
+const int MASK_MAGNIFY_FILTER = 0x000000F0;
+
+const unsigned int FILTER_MODE_COUNT = 3;
+
+FilterMode::Type FILTER_MODE_OPTIONS[ FILTER_MODE_COUNT ] =
+ { 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
+
+/**
+ * Utility to store one of the FilterMode values.
+ * @param[out] options A bitmask used to store the FilterMode values.
+ * @param[in] factor The FilterMode value.
+ * @param[in] bitshift Used to shift to the correct part of options.
+ */
+void StoreFilterMode( unsigned int& options, FilterMode::Type mode, int bitShift )
+{
+ // Start shifting from 1 as 0 is the unassigned state
+ switch ( mode )
+ {
+ case FilterMode::DEFAULT:
+ {
+ options |= ( 1u << bitShift );
+ break;
+ }
+ case FilterMode::NEAREST:
+ {
+ options |= ( 2u << bitShift );
+ break;
+ }
+ case FilterMode::LINEAR:
+ {
+ options |= ( 3u << bitShift );
+ break;
+ }
+ }
+}
+
+/**
+ * Utility to retrieve one of the FilterMode values.
+ * @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.
+ */
+bool RetrieveFilterMode( unsigned int options, int mask, int bitShift, FilterMode::Type& filterModeOut )
+{
+ 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;
+}
+
+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;
+}
+
+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 );
+}
+
+unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify )
+{
+ unsigned int bitfield = 0;
+ StoreFilterMode( bitfield, minify, MINIFY_BIT_SHIFT );
+ StoreFilterMode( bitfield, magnify, MAGNIFY_BIT_SHIFT );
+ return bitfield;
+}
+
+FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
+{
+ FilterMode::Type filterMode = FilterMode::NEAREST;
+ RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT, filterMode );
+ return filterMode;
+}
+
+FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
+{
+ FilterMode::Type filterMode = FilterMode::NEAREST;
+ RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT, filterMode );
+ return filterMode;
+}
+
+} // namespace ImageSampler
+
+} // namespace Internal
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_IMAGE_SAMPLER_H__
+#define __DALI_IMAGE_SAMPLER_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/actors/sampling.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+/**
+ * ImageSampler represents a set of sampling settings that can be applied to a texture.
+ */
+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.
+ *
+ * @param[in] minify The minification filter.
+ * @param[in] magnify The magnification filter.
+ * @return Return the packed bitfield.
+ */
+ unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify );
+
+ /**
+ * @brief Return the minification filter from a packed bitfield.
+ *
+ * @return Return the minification filter.
+ */
+ FilterMode::Type GetMinifyFilterMode( unsigned int bitfield );
+
+ /**
+ * @brief Return the magnification filter from a packed bitfield.
+ *
+ * @return Return the magnification filter.
+ */
+ FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield );
+
+} // namespace ImageSampler
+
+} // namespace Internal
+
+} // namespace Dali
+
+
+#endif // __DALI_INTERNAL_IMAGE_SAMPLER_H__
+
+
+
: ActorAttachment( stage ),
mSortModifier( 0.0f ),
mCullFaceMode( CullNone ),
- mBlendingMode( BlendingMode::AUTO )
+ mBlendingMode( BlendingMode::AUTO ),
+ mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) )
{
}
return Vector4::ZERO;
}
+void RenderableAttachment::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
+{
+ mSamplerBitfield = ImageSampler::PackBitfield( minFilter, magFilter );
+
+ SetSamplerMessage( mStage->GetUpdateInterface(), GetSceneObject(), mSamplerBitfield );
+}
+
+void RenderableAttachment::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
+{
+ minFilter = ImageSampler::GetMinifyFilterMode( mSamplerBitfield );
+ magFilter = ImageSampler::GetMagnifyFilterMode( mSamplerBitfield );
+}
+
+
void RenderableAttachment::OnStageConnection()
{
// For derived classes
#include <dali/public-api/actors/renderable-actor.h>
#include <dali/public-api/actors/blending.h>
#include <dali/internal/common/blending-options.h>
+#include <dali/internal/common/image-sampler.h>
#include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
namespace Dali
*/
const Vector4& GetBlendColor() const;
+ /**
+ * @copydoc Dali::RenderableActor::SetFilterMode()
+ */
+ void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
+
+ /**
+ * @copydoc Dali::RenderableActor::GetFilterMode()
+ */
+ void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
+
protected:
/**
CullFaceMode mCullFaceMode;
BlendingMode::Type mBlendingMode;
BlendingOptions mBlendingOptions;
+ unsigned int mSamplerBitfield;
};
} // namespace Internal
return GetRenderableAttachment().GetBlendColor();
}
+void RenderableActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
+{
+ GetRenderableAttachment().SetFilterMode( minFilter, magFilter );
+}
+
+void RenderableActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
+{
+ return GetRenderableAttachment().GetFilterMode( minFilter, magFilter );
+}
+
RenderableActor::RenderableActor()
: Actor( Actor::RENDERABLE )
{
*/
const Vector4& GetBlendColor() const;
+ /**
+ * @copydoc Dali::RenderableActor::SetFilterMode()
+ */
+ void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
+
+ /**
+ * @copydoc Dali::RenderableActor::GetFilterMode()
+ */
+ void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
+
protected:
/**
$(internal_src_dir)/common/internal-constants.cpp \
$(internal_src_dir)/common/message-buffer.cpp \
$(internal_src_dir)/common/text-parameters.cpp \
+ $(internal_src_dir)/common/image-sampler.cpp \
\
$(internal_src_dir)/event/actor-attachments/actor-attachment-impl.cpp \
$(internal_src_dir)/event/actor-attachments/camera-attachment-impl.cpp \
mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
mContext.TexImage2D(GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, pixelFormat, pixelDataType, pixels);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
mContext.CompressedTexImage2D(GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, bufferSize, pixels);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// set texture parameters
mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
- mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
mContext.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
#include <dali/integration-api/debug.h>
#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/common/image-sampler.h>
namespace Dali
{
namespace Internal
{
+/**
+ * Convert a FilterMode to it's corresponding GL type.
+ *
+ * @param[in] filterMode The FilterMode type.
+ * @return Return the equivalent GL type.
+ */
+GLint FilterModeToGL( FilterMode::Type filterMode )
+{
+ switch( filterMode )
+ {
+ case FilterMode::NEAREST:
+ {
+ return GL_NEAREST;
+ }
+ case FilterMode::LINEAR:
+ {
+ return GL_LINEAR;
+ }
+ case FilterMode::DEFAULT:
+ {
+ // Do nothing
+ }
+ }
+
+ return GL_LINEAR;
+}
+
using Dali::Internal::Vertex2D;
using Dali::Internal::Vertex3D;
Pixel::Format pixelFormat)
: mContext(context),
mId(0),
+ mSamplerBitfield( 0 ),
mWidth(width),
mHeight(height),
mImageWidth(imageWidth),
}
+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() ) ) );
+ }
+
+ mSamplerBitfield = samplerBitfield;
+ }
+}
+
} // namespace Internal
} // namespace Dali
*/
void GetTextureCoordinates(UvRect& uv, const PixelArea* pixelArea = NULL);
+ /**
+ * @brief Apply the given sampler to the texture.
+ *
+ * @param[in] samplerBitfield A bitfield with packed sampler options.
+ */
+ void ApplySampler( unsigned int samplerBitfield );
+
protected:
/**
GLuint mId; ///< Texture id
+ unsigned int mSamplerBitfield; ///< The packed bitfield of the current sampler
+
unsigned int mWidth; ///< texture width, may be scaled power of 2 (if not in an atlas)
unsigned int mHeight; ///< texture width, may be scaled power of 2 (if not in an atlas)
}
}
-void RenderMaterial::BindTextures( Program& program )
+void RenderMaterial::BindTextures( Program& program, unsigned int textureSampler )
{
DALI_ASSERT_DEBUG( NULL != mTextureCache );
}
}
- BindTexture( program, mDiffuseTextureId,mDiffuseTexture, 0, Program::UNIFORM_SAMPLER );
+ BindTexture( program, mDiffuseTextureId, mDiffuseTexture, 0, Program::UNIFORM_SAMPLER );
+
+ if( mDiffuseTexture )
+ {
+ mDiffuseTexture->ApplySampler( textureSampler );
+ }
+
// GL_TEXTURE1 is used by shader effect texture
BindTexture( program, mOpacityTextureId, mOpacityTexture, 2, Program::UNIFORM_SAMPLER_OPACITY );
+
+ if( mOpacityTexture )
+ {
+ mOpacityTexture->ApplySampler( textureSampler );
+ }
+
BindTexture( program, mNormalMapTextureId, mNormalMapTexture, 3, Program::UNIFORM_SAMPLER_NORMAL_MAP );
+
+ if( mNormalMapTexture )
+ {
+ mNormalMapTexture->ApplySampler( textureSampler );
+ }
}
void RenderMaterial::TextureDiscarded( unsigned int textureId )
/**
* Bind all the valid textures. Will also store valid texture pointer
* @param[in] program The shader program with which to bind the textures
+ * @param[in] textureSampler The texture sampling parameters for the diffuse, opacity and normal textures
*/
- void BindTextures( Program& program );
+ void BindTextures( Program& program, unsigned int textureSampler );
protected: // TextureObserver implementation
/**
DALI_ASSERT_DEBUG( mVertexBuffer );
mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, GL_TEXTURE0 );
+ mTexture->ApplySampler( mSamplerBitfield );
// make sure the vertex is bound, this has to be done before
// we call VertexAttribPointer otherwise you get weird output on the display
if( material.HasTexture() )
{
- material.BindTextures( program );
+ material.BindTextures( program, mSamplerBitfield );
}
// Always use UV's - may be being used for another purpose by a custom shader!
texCoordLoc = program.GetAttribLocation(Program::ATTRIB_TEXCOORD);
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/renderers/render-data-provider.h>
#include <dali/public-api/actors/blending.h>
+#include <dali/internal/common/image-sampler.h>
namespace Dali
{
mCullFaceMode = mode;
}
+void Renderer::SetSampler( unsigned int samplerBitfield )
+{
+ mSamplerBitfield = samplerBitfield;
+}
+
void Renderer::Render( BufferIndex bufferIndex,
const Matrix& modelViewMatrix,
const Matrix& viewMatrix,
mContext( NULL ),
mTextureCache( NULL ),
mShader( NULL ),
+ mSamplerBitfield( ImageSampler::DefaultOptions() ),
mUseBlend( false ),
mCullFaceMode( CullNone )
{
*/
void SetCullFace( CullFaceMode mode );
+ /**
+ * Set the sampler used to render the set texture.
+ * @param[in] samplerBitfield The packed sampler options used to render.
+ */
+ void SetSampler( unsigned int samplerBitfield );
+
/**
* Query whether the derived type of Renderer requires depth testing.
* @return True if the renderer requires depth testing.
Context* mContext;
TextureCache* mTextureCache;
Shader* mShader;
+ unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
private:
const GLint texCoordLoc = program.GetAttribLocation(Program::ATTRIB_TEXCOORD);
mTexture->Bind(GL_TEXTURE_2D, GL_TEXTURE0);
+ mTexture->ApplySampler( mSamplerBitfield );
mContext->EnableVertexAttributeArray( positionLoc );
mContext->EnableVertexAttributeArray( texCoordLoc );
#include <dali/internal/render/gl-resources/texture-cache.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/shaders/uniform-meta.h>
+#include <dali/internal/common/image-sampler.h>
// See render-debug.h
#ifdef DALI_PRINT_RENDER_INFO
{
// 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() );
+
// get effect sampler uniform
const GLint loc = program.GetUniformLocation( Program::UNIFORM_EFFECT_SAMPLER );
if( Program::UNIFORM_UNKNOWN != loc )
#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/render/renderers/scene-graph-renderer.h>
#include <dali/internal/render/shaders/shader.h>
+#include <dali/internal/common/image-sampler.h>
using namespace std;
new (slot) DerivedType( &GetRenderer(), &Renderer::SetCullFace, mode );
}
+void RenderableAttachment::SetSampler( BufferIndex updateBufferIndex, unsigned int samplerBitfield )
+{
+ DALI_ASSERT_DEBUG(mSceneController);
+
+ typedef MessageValue1< Renderer, unsigned int > DerivedType;
+
+ // Reserve some memory inside the render queue
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+
+ // Construct message in the render queue memory; note that delete should not be called on the return value
+ new (slot) DerivedType( &GetRenderer(), &Renderer::SetSampler, samplerBitfield );
+}
+
void RenderableAttachment::SetRecalculateScaleForSize()
{
mScaleForSizeDirty = true;
*/
void SetCullFace( BufferIndex updateBufferIndex, CullFaceMode mode );
+ /**
+ * Set the sampler used to render the texture for this renderable.
+ * @param[in] updateBufferIndex The current update buffer index.
+ * @param[in] samplerBitfield The image sampler packed options to set.
+ */
+ void SetSampler( BufferIndex updateBufferIndex, unsigned int samplerBitfield );
+
/**
* Flag to check if any geometry scaling is needed, inlined as called from update algorithm often
* @return true if the derived renderable uses geometry scaling
new (slot) LocalType( &attachment, &RenderableAttachment::SetBlendColor, color );
}
+inline void SetSamplerMessage( EventToUpdate& eventToUpdate, const RenderableAttachment& attachment, unsigned int samplerBitfield )
+{
+ typedef MessageDoubleBuffered1< RenderableAttachment, unsigned int > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &attachment, &RenderableAttachment::SetSampler, samplerBitfield );
+}
+
} // namespace SceneGraph
} // namespace Internal
return GetImplementation(*this).GetBlendColor();
}
+void RenderableActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
+{
+ GetImplementation(*this).SetFilterMode( minFilter, magFilter );
+}
+
+void RenderableActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
+{
+ GetImplementation(*this).GetFilterMode( minFilter, magFilter );
+}
+
RenderableActor::RenderableActor(Internal::RenderableActor* internal)
: Actor(internal)
{
// INTERNAL INCLUDES
#include <dali/public-api/actors/actor.h>
#include <dali/public-api/actors/blending.h>
+#include <dali/public-api/actors/sampling.h>
namespace Dali DALI_IMPORT_API
{
*/
const Vector4& GetBlendColor() const;
+ /**
+ * @brief Sets the filtering mode.
+ *
+ * Possible values are: FilterMode::NEAREST and FilterMode::LINEAR. Default is FilterMode::LINEAR.
+ *
+ * <ul>
+ * <li> \e NEAREST Use nearest filtering
+ * <li> \e LINEAR Use linear filtering
+ * </ul>
+ *
+ * @param[in] minFilter The minification filtering mode.
+ * @param[in] magFilter The magnification filtering mode.
+ */
+ void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
+
+ /**
+ * @brief Retrieves the filtering mode.
+ *
+ * @param[out] minFilter The return minification value
+ * @param[out] magFilter The return magnification value
+ */
+ void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter) const;
+
public: // Not intended for application developers
/**
--- /dev/null
+#ifndef __DALI_SAMPLING_H__
+#define __DALI_SAMPLING_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+
+namespace Dali DALI_IMPORT_API
+{
+
+namespace FilterMode
+{
+/**
+ * @brief Texture filtering mode.
+ * @see Dali::RenderableActor::SetFilterMode() and Dali::RenderableActor::GetFilterMode()
+ */
+enum Type
+{
+ DEFAULT,
+ NEAREST, ///< Filter nearest
+ LINEAR ///< Filter linear
+};
+
+} //namespace FilterMode
+
+} // namespace Dali
+
+#endif // __DALI_SAMPLING_H__
#include <dali/public-api/actors/model-actor-factory.h>
#include <dali/public-api/actors/renderable-actor.h>
#include <dali/public-api/actors/text-actor.h>
+#include <dali/public-api/actors/sampling.h>
#include <dali/public-api/animation/active-constraint-declarations.h>
#include <dali/public-api/animation/active-constraint.h>
$(public_api_src_dir)/actors/mesh-actor.h \
$(public_api_src_dir)/actors/model-actor-factory.h \
$(public_api_src_dir)/actors/text-actor.h \
- $(public_api_src_dir)/actors/renderable-actor.h
+ $(public_api_src_dir)/actors/renderable-actor.h \
+ $(public_api_src_dir)/actors/sampling.h
public_api_core_animation_header_files = \
$(public_api_src_dir)/animation/active-constraint.h \