Revert bug fix in renderer
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.cpp
index f87cfbb..5400c12 100644 (file)
@@ -27,9 +27,9 @@
 #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.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
 {
@@ -114,20 +114,24 @@ Renderer* Renderer::New( SceneGraph::RenderDataProvider* dataProvider,
                          Render::Geometry* geometry,
                          unsigned int blendingBitmask,
                          const Vector4* blendColor,
-                         Dali::Renderer::FaceCullingMode faceCullingMode,
+                         FaceCullingMode::Type faceCullingMode,
                          bool preMultipliedAlphaEnabled,
-                         Dali::Renderer::DepthWriteMode depthWriteMode )
+                         DepthWriteMode::Type depthWriteMode,
+                         DepthTestMode::Type depthTestMode,
+                         DepthFunction::Type depthFunction )
 {
-  return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode );
+  return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction );
 }
 
 Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
                     Render::Geometry* geometry,
                     unsigned int blendingBitmask,
                     const Vector4* blendColor,
-                    Dali::Renderer::FaceCullingMode faceCullingMode,
+                    FaceCullingMode::Type faceCullingMode,
                     bool preMultipliedAlphaEnabled,
-                    Dali::Renderer::DepthWriteMode depthWriteMode )
+                    DepthWriteMode::Type depthWriteMode,
+                    DepthTestMode::Type depthTestMode,
+                    DepthFunction::Type depthFunction )
 : mRenderDataProvider( dataProvider ),
   mContext(NULL),
   mTextureCache( NULL ),
@@ -136,10 +140,12 @@ Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
   mUniformIndexMap(),
   mAttributesLocation(),
   mBlendingOptions(),
-  mFaceCullingMode( faceCullingMode  ),
-  mDepthWriteMode( depthWriteMode ),
+  mFaceCullingMode( faceCullingMode ),
+  mDepthFunction( depthFunction ),
   mIndexedDrawFirstElement( 0 ),
   mIndexedDrawElementsCount( 0 ),
+  mDepthWriteMode( depthWriteMode ),
+  mDepthTestMode( depthTestMode ),
   mUpdateAttributesLocation( true ),
   mPremultipledAlphaEnabled( preMultipliedAlphaEnabled )
 {
@@ -348,12 +354,15 @@ void Renderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program
   }
 }
 
-bool Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& program )
+bool Renderer::BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program )
 {
-  int textureUnit = 0;
+  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();
@@ -366,26 +375,17 @@ bool Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& pr
       {
         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(0);
-          Render::Texture& textureMapping = textures[i];
-          const Render::Sampler* sampler( textureMapping.GetSampler() );
+          unsigned int samplerBitfield(ImageSampler::DEFAULT_BITFIELD);
+          const Render::Sampler* sampler(  samplers[i] );
           if( sampler )
           {
-            samplerBitfield = ImageSampler::PackBitfield(
-              static_cast< FilterMode::Type >(sampler->GetMinifyFilterMode()),
-              static_cast< FilterMode::Type >(sampler->GetMagnifyFilterMode()),
-              static_cast< WrapMode::Type >(sampler->GetUWrapMode()),
-              static_cast< WrapMode::Type >(sampler->GetVWrapMode())
-                                                         );
-          }
-          else
-          {
-            samplerBitfield = ImageSampler::DEFAULT_BITFIELD;
+            samplerBitfield = sampler->mBitfield;
           }
 
           texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
@@ -395,10 +395,27 @@ bool Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& pr
       }
     }
   }
+
+  std::vector<Render::NewTexture*>& newTextures( mRenderDataProvider->GetNewTextures() );
+  for( size_t i(0); result && i<newTextures.size(); ++i )
+  {
+    if( newTextures[i] )
+    {
+      result = program.GetSamplerUniformLocation( i, uniformLocation ) &&
+               newTextures[i]->Bind(context, textureUnit, samplers[i] );
+
+      if( result )
+      {
+        program.SetUniform1i( uniformLocation, textureUnit );
+        ++textureUnit;
+      }
+    }
+  }
+
   return result;
 }
 
-void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode )
+void Renderer::SetFaceCullingMode( FaceCullingMode::Type mode )
 {
   mFaceCullingMode =  mode;
 }
@@ -428,21 +445,42 @@ void Renderer::EnablePreMultipliedAlpha( bool enable )
   mPremultipledAlphaEnabled = enable;
 }
 
-void Renderer::SetDepthWriteMode( Dali::Renderer::DepthWriteMode depthWriteMode )
+void Renderer::SetDepthWriteMode( DepthWriteMode::Type depthWriteMode )
 {
   mDepthWriteMode = depthWriteMode;
 }
 
-Dali::Renderer::DepthWriteMode Renderer::GetDepthWriteMode() const
+void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode )
+{
+  mDepthTestMode = depthTestMode;
+}
+
+DepthWriteMode::Type Renderer::GetDepthWriteMode() const
 {
   return mDepthWriteMode;
 }
 
+DepthTestMode::Type Renderer::GetDepthTestMode() const
+{
+  return mDepthTestMode;
+}
+
+void Renderer::SetDepthFunction( DepthFunction::Type depthFunction )
+{
+  mDepthFunction = depthFunction;
+}
+
+DepthFunction::Type Renderer::GetDepthFunction() const
+{
+  return mDepthFunction;
+}
+
 void Renderer::Render( Context& context,
                        SceneGraph::TextureCache& textureCache,
                        BufferIndex bufferIndex,
                        const SceneGraph::NodeDataProvider& node,
                        SceneGraph::Shader& defaultShader,
+                       const Matrix& modelMatrix,
                        const Matrix& modelViewMatrix,
                        const Matrix& viewMatrix,
                        const Matrix& projectionMatrix,
@@ -472,12 +510,12 @@ void Renderer::Render( Context& context,
   // Take the program into use so we can send uniforms to it
   program->Use();
 
-  if( DALI_LIKELY( BindTextures( textureCache, *program ) ) )
+  if( DALI_LIKELY( BindTextures( context, textureCache, *program ) ) )
   {
     // Only set up and draw if we have textures and they are all valid
 
     // set projection and view matrix if program has not yet received them yet this frame
-    SetMatrices( *program, node.GetModelMatrix( bufferIndex ), viewMatrix, projectionMatrix, modelViewMatrix );
+    SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix );
 
     // set color uniform
     GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );