$(internal_src_dir)/render/common/render-tracker.cpp \
$(internal_src_dir)/render/common/render-manager.cpp \
$(internal_src_dir)/render/data-providers/render-data-provider.cpp \
+ $(internal_src_dir)/render/data-providers/uniform-name-cache.cpp \
$(internal_src_dir)/render/gl-resources/bitmap-texture.cpp \
$(internal_src_dir)/render/gl-resources/context.cpp \
$(internal_src_dir)/render/gl-resources/frame-buffer-state-cache.cpp \
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
#include <dali/internal/render/common/render-tracker.h>
#include <dali/internal/render/common/render-instruction-container.h>
#include <dali/internal/render/common/render-instruction.h>
+#include <dali/internal/render/data-providers/uniform-name-cache.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/gl-resources/frame-buffer-texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
Integration::GlSyncAbstraction& glSyncAbstraction; ///< GL sync abstraction
RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread.
TextureCache textureCache; ///< Cache for all GL textures
+ Render::UniformNameCache uniformNameCache; ///< Cache to provide unique indices for uniforms
LockedResourceQueue& textureUploadedQueue; ///< A queue for requesting resource post processing in update thread
// Render instructions describe what should be rendered during RenderManager::Render()
void RenderManager::AddRenderer( Render::Renderer* renderer )
{
// Initialize the renderer as we are now in render thread
- renderer->Initialize( mImpl->context, mImpl->textureCache );
+ renderer->Initialize( mImpl->context, mImpl->textureCache, mImpl->uniformNameCache );
mImpl->rendererContainer.PushBack( renderer );
--- /dev/null
+/*
+ * Copyright (c) 2015 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/render/data-providers/uniform-name-cache.h>
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/common/hash.h>
+
+namespace Dali
+{
+namespace Internal
+{
+namespace Render
+{
+
+UniformNameCache::UniformNameCache()
+{}
+
+UniformNameCache::~UniformNameCache()
+{ // OwnerContainer cleans up
+}
+
+int32_t UniformNameCache::GetSamplerUniformUniqueIndex( const std::string& uniformName )
+{
+ OwnerContainer< UniformEntry* >::SizeType index = 0;
+ const OwnerContainer< UniformEntry* >::SizeType end = mSamplerUniformCache.Size();
+
+ const std::size_t hash = Dali::CalculateHash( uniformName );
+
+ for( ;index < end; ++index )
+ {
+ // check hash first
+ if( hash == mSamplerUniformCache[ index ]->nameHash )
+ {
+ // check full name in case of collision
+ if( mSamplerUniformCache[ index ]->uniformName == uniformName )
+ {
+ // match, return the index
+ return index;
+ }
+ }
+ }
+ // no match found, add new entry to cache
+ mSamplerUniformCache.PushBack( new UniformEntry( uniformName, hash ) );
+
+ return end;
+}
+
+} // namespace Render
+
+} // namespace Internal
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_INTERNAL_UNIFORM_NAME_CACHE_H
+#define DALI_INTERNAL_UNIFORM_NAME_CACHE_H
+
+/*
+ * Copyright (c) 2015 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.
+ */
+
+// EXTERNAL INCLUDES
+#include <string>
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/common/owner-container.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Render
+{
+
+/**
+ * This class maps uniform names to unique indices that can be used to cache the GL uniform
+ * index values in programs and only do the costly string lookup once
+ */
+class UniformNameCache
+{
+public:
+
+ /**
+ * Constructor
+ */
+ UniformNameCache();
+
+ /**
+ * Destructor
+ */
+ ~UniformNameCache();
+
+ /**
+ * This method can be used to query a cache for the unique index for a sampler uniform
+ * @param uniformName to get the index for
+ * @return a unique index for this sampler uniform
+ */
+ int32_t GetSamplerUniformUniqueIndex( const std::string& uniformName );
+
+private: // Data
+
+ struct UniformEntry
+ {
+ UniformEntry( const std::string& name, std::size_t hash )
+ : uniformName( name ),
+ nameHash( hash )
+ { }
+ std::string uniformName;
+ std::size_t nameHash;
+ };
+
+ OwnerContainer< UniformEntry* > mSamplerUniformCache;
+
+};
+
+} // namespace Render
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif // DALI_INTERNAL_UNIFORM_NAME_CACHE_H
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/data-providers/node-data-provider.h>
+#include <dali/internal/render/data-providers/uniform-name-cache.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
#include <dali/public-api/actors/blending.h>
#include <dali/internal/render/gl-resources/gl-texture.h>
: mRenderDataProvider( dataProvider ),
mContext( NULL),
mTextureCache( NULL ),
+ mUniformNameCache( NULL ),
mGeometry( geometry ),
mUniformIndexMap(),
mAttributesLocation(),
}
}
-void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache )
+void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache )
{
mContext = &context;
mTextureCache = &textureCache;
+ mUniformNameCache = &uniformNameCache;
}
Renderer::~Renderer()
namespace Render
{
+class UniformNameCache;
/**
* Renderers are used to render meshes
/**
* Second-phase construction.
* This is called when the renderer is inside render thread
- * @param[in] context Context used by the renderer
- * @param[in] textureCache The texture cache to use
+ * @param[in] context to use
+ * @param[in] textureCache to use
+ * @param[in] uniformNameCache to use
*/
- void Initialize( Context& context, SceneGraph::TextureCache& textureCache );
+ void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
/**
* Destructor
Context* mContext;
SceneGraph::TextureCache* mTextureCache;
+ Render::UniformNameCache* mUniformNameCache;
Render::Geometry* mGeometry;
struct UniformIndexMap
{
public:
+ /**
+ * Enumeration to tell that this sampler does not have a unique index yet
+ */
+ enum
+ {
+ NOT_INITIALIZED = -1
+ };
+
/**
* Constructor
*/
public: // called from RenderThread
/**
+ * @param[in] buffer A vector wit
* Get the texture ID
* @return the id of the associated texture
*/