Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.cpp
index 82e4a69..d271c71 100644 (file)
@@ -26,7 +26,6 @@
 #include <dali/internal/render/shaders/program.h>
 #include <dali/internal/render/data-providers/node-data-provider.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>
 
 namespace Dali
@@ -117,12 +116,11 @@ Renderer* Renderer::New( SceneGraph::RenderDataProvider* dataProvider,
                          DepthWriteMode::Type depthWriteMode,
                          DepthTestMode::Type depthTestMode,
                          DepthFunction::Type depthFunction,
-                         StencilParameters& stencilParameters,
-                         bool writeToColorBuffer )
+                         StencilParameters& stencilParameters )
 {
   return new Renderer( dataProvider, geometry, blendingBitmask, blendColor,
                        faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode,
-                       depthFunction, stencilParameters, writeToColorBuffer );
+                       depthFunction, stencilParameters );
 }
 
 Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
@@ -134,8 +132,7 @@ Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
                     DepthWriteMode::Type depthWriteMode,
                     DepthTestMode::Type depthTestMode,
                     DepthFunction::Type depthFunction,
-                    StencilParameters& stencilParameters,
-                    bool writeToColorBuffer )
+                    StencilParameters& stencilParameters )
 : mRenderDataProvider( dataProvider ),
   mContext( NULL),
   mTextureCache( NULL ),
@@ -150,7 +147,6 @@ Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
   mFaceCullingMode( faceCullingMode ),
   mDepthWriteMode( depthWriteMode ),
   mDepthTestMode( depthTestMode ),
-  mWriteToColorBuffer( writeToColorBuffer ),
   mUpdateAttributesLocation( true ),
   mPremultipledAlphaEnabled( preMultipliedAlphaEnabled )
 {
@@ -179,6 +175,16 @@ void Renderer::SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProvid
 {
   mRenderDataProvider = dataProvider;
   mUpdateAttributesLocation = true;
+
+  //Check that the number of textures match the number of samplers in the shader
+  size_t textureCount =  dataProvider->GetNewTextures().size();
+  Program* program = dataProvider->GetShader().GetProgram();
+  if( program && program->GetActiveSamplerCount() != textureCount )
+  {
+    DALI_LOG_WARNING("The number of active samplers in the shader(%lu) does not match the number of textures in the TextureSet(%lu)\n",
+                   program->GetActiveSamplerCount(),
+                   textureCount );
+  }
 }
 
 void Renderer::SetGeometry( Render::Geometry* geometry )
@@ -363,52 +369,15 @@ bool Renderer::BindTextures( Context& context, SceneGraph::TextureCache& texture
   unsigned int textureUnit = 0;
   bool result = true;
 
-  std::vector<Render::Sampler*>& samplers( mRenderDataProvider->GetSamplers() );
-
-  std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
   GLint uniformLocation(-1);
-  for( size_t i(0); result && i<textures.size(); ++i )
-  {
-    ResourceId textureId = textures[i].GetTextureId();
-    Internal::Texture* texture = textureCache.GetTexture( textureId );
-    if( texture )
-    {
-      result = textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
-
-      if( result )
-      {
-        GLint uniformLocation;
-
-        //TODO : This is a bug, result variable is being shadowed. Fix it!
-        bool result = program.GetSamplerUniformLocation( i, uniformLocation );
-        if( result && Program::UNIFORM_UNKNOWN != uniformLocation )
-        {
-          program.SetUniform1i( uniformLocation, textureUnit );
-
-          unsigned int samplerBitfield(ImageSampler::DEFAULT_BITFIELD);
-          const Render::Sampler* sampler(  samplers[i] );
-          if( sampler )
-          {
-            samplerBitfield = sampler->mBitfield;
-          }
-
-          texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
-
-          ++textureUnit;
-        }
-      }
-    }
-  }
-
+  std::vector<Render::Sampler*>& samplers( mRenderDataProvider->GetSamplers() );
   std::vector<Render::NewTexture*>& newTextures( mRenderDataProvider->GetNewTextures() );
-  for( size_t i(0); result && i<newTextures.size(); ++i )
+  for( size_t i(0); i<newTextures.size() && result; ++i )
   {
     if( newTextures[i] )
     {
-      result = program.GetSamplerUniformLocation( i, uniformLocation ) &&
-               newTextures[i]->Bind(context, textureUnit, samplers[i] );
-
-      if( result )
+      result = newTextures[i]->Bind(context, textureUnit, samplers[i] );
+      if( result && program.GetSamplerUniformLocation( i, uniformLocation ) )
       {
         program.SetUniform1i( uniformLocation, textureUnit );
         ++textureUnit;
@@ -479,14 +448,14 @@ DepthFunction::Type Renderer::GetDepthFunction() const
   return mDepthFunction;
 }
 
-void Renderer::SetStencilMode( StencilMode::Type stencilMode )
+void Renderer::SetRenderMode( RenderMode::Type renderMode )
 {
-  mStencilParameters.stencilMode = stencilMode;
+  mStencilParameters.renderMode = renderMode;
 }
 
-StencilMode::Type Renderer::GetStencilMode() const
+RenderMode::Type Renderer::GetRenderMode() const
 {
-  return mStencilParameters.stencilMode;
+  return mStencilParameters.renderMode;
 }
 
 void Renderer::SetStencilFunction( StencilFunction::Type stencilFunction )
@@ -559,16 +528,6 @@ StencilOperation::Type Renderer::GetStencilOperationOnZPass() const
   return mStencilParameters.stencilOperationOnZPass;
 }
 
-void Renderer::SetWriteToColorBuffer( bool writeToColorBuffer )
-{
-  mWriteToColorBuffer = writeToColorBuffer;
-}
-
-bool Renderer::GetWriteToColorBuffer() const
-{
-  return mWriteToColorBuffer;
-}
-
 void Renderer::Render( Context& context,
                        SceneGraph::TextureCache& textureCache,
                        BufferIndex bufferIndex,
@@ -634,23 +593,18 @@ void Renderer::Render( Context& context,
       mUpdateAttributesLocation = false;
     }
 
-    mGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation, mIndexedDrawFirstElement, mIndexedDrawElementsCount );
+    mGeometry->UploadAndDraw( context,
+                              bufferIndex,
+                              mAttributesLocation,
+                              mIndexedDrawFirstElement,
+                              mIndexedDrawElementsCount );
   }
 }
 
-void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
+void Renderer::SetSortAttributes( BufferIndex bufferIndex,
+                                  SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes ) const
 {
   sortAttributes.shader = &( mRenderDataProvider->GetShader() );
-  const std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
-  if( !textures.empty() )
-  {
-    sortAttributes.textureResourceId = textures[0].GetTextureId();
-  }
-  else
-  {
-    sortAttributes.textureResourceId = Integration::InvalidResourceId;
-  }
-
   sortAttributes.geometry = mGeometry;
 }