Remove mContext and mTextureCache from Renderer. 77/37877/1
authorFrancisco Santos <f1.santos@samsung.com>
Tue, 7 Apr 2015 16:43:17 +0000 (17:43 +0100)
committerFrancisco Santos <f1.santos@samsung.com>
Tue, 7 Apr 2015 17:11:39 +0000 (18:11 +0100)
Change-Id: I2bea3efe887a7d176139f88fa7e11c9e0883c8c2

13 files changed:
dali/internal/render/common/render-algorithms.cpp
dali/internal/render/common/render-algorithms.h
dali/internal/render/common/render-manager.cpp
dali/internal/render/renderers/render-geometry.cpp
dali/internal/render/renderers/render-geometry.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/render/renderers/scene-graph-image-renderer.cpp
dali/internal/render/renderers/scene-graph-image-renderer.h
dali/internal/render/renderers/scene-graph-renderer.cpp
dali/internal/render/renderers/scene-graph-renderer.h
dali/internal/render/renderers/scene-graph-text-renderer.cpp
dali/internal/render/renderers/scene-graph-text-renderer.h

index 27abfb6..30fd6b4 100644 (file)
@@ -52,6 +52,7 @@ namespace Render
  */
 inline void ProcessRenderList( const RenderList& renderList,
                                Context& context,
+                               SceneGraph::TextureCache& textureCache,
                                SceneGraph::Shader& defaultShader,
                                BufferIndex bufferIndex,
                                float frameTime,
@@ -119,12 +120,13 @@ inline void ProcessRenderList( const RenderList& renderList,
     SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( item.GetRenderer() );
     const Matrix& modelViewMatrix = item.GetModelViewMatrix();
 
-    renderer->Render( bufferIndex, defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
+    renderer->Render( context, textureCache, bufferIndex, defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
   }
 }
 
 void ProcessRenderInstruction( const RenderInstruction& instruction,
                                Context& context,
+                               SceneGraph::TextureCache& textureCache,
                                SceneGraph::Shader& defaultShader,
                                BufferIndex bufferIndex,
                                float frameTime )
@@ -148,7 +150,7 @@ void ProcessRenderInstruction( const RenderInstruction& instruction,
       if(  renderList &&
           !renderList->IsEmpty() )
       {
-        ProcessRenderList( *renderList, context, defaultShader, bufferIndex, frameTime, *viewMatrix, *projectionMatrix, instruction.mCullMode );
+        ProcessRenderList( *renderList, context, textureCache, defaultShader, bufferIndex, frameTime, *viewMatrix, *projectionMatrix, instruction.mCullMode );
       }
     }
   }
index 6a3d8e9..f06ceca 100644 (file)
@@ -31,6 +31,7 @@ namespace SceneGraph
 {
 class RenderInstruction;
 class Shader;
+class TextureCache;
 }
 
 namespace Render
@@ -40,12 +41,14 @@ namespace Render
  * Process a render-instruction.
  * @param[in] instruction The render-instruction to process.
  * @param[in] context The GL context.
+ * @param[in] textureCache The texture cache used to get textures.
  * @param[in] defaultShader The default shader.
  * @param[in] buffer The current render buffer index (previous update buffer)
  * @param[in] frameTime The elapsed time between the last two updates.
  */
 void ProcessRenderInstruction( const SceneGraph::RenderInstruction& instruction,
                                Context& context,
+                               SceneGraph::TextureCache& textureCache,
                                SceneGraph::Shader& defaultShader,
                                BufferIndex bufferIndex,
                                float frameTime );
index b2a442b..a226306 100644 (file)
@@ -479,6 +479,7 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha
 
   Render::ProcessRenderInstruction( instruction,
                                     mImpl->context,
+                                    mImpl->textureCache,
                                     defaultShader,
                                     mImpl->renderBufferIndex,
                                     elapsedTime );
index 0c91482..7a3c3b9 100644 (file)
@@ -62,7 +62,7 @@ void RenderGeometry::GlContextDestroyed()
 }
 
 void RenderGeometry::UploadAndDraw(
-  Context* context,
+  Context& context,
   Program& program,
   BufferIndex bufferIndex,
   const GeometryDataProvider& geometryDataProvider )
@@ -80,7 +80,7 @@ void RenderGeometry::GeometryUpdated()
 }
 
 void RenderGeometry::UploadVertexData(
-  Context* context,
+  Context& context,
   BufferIndex bufferIndex,
   const GeometryDataProvider& geometry )
 {
@@ -93,7 +93,7 @@ void RenderGeometry::UploadVertexData(
 }
 
 void RenderGeometry::DoUpload(
-  Context* context,
+  Context& context,
   BufferIndex bufferIndex,
   const GeometryDataProvider& geometry)
 {
@@ -106,7 +106,7 @@ void RenderGeometry::DoUpload(
     const PropertyBuffer* vertexBuffer = vertexBuffers[i];
 
     // @todo MESH_REWORK STATIC_DRAW or DYNAMIC_DRAW depends on property buffer type (static / animated)
-    GpuBuffer* vertexGpuBuffer = new GpuBuffer( *context, GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+    GpuBuffer* vertexGpuBuffer = new GpuBuffer( context, GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
 
     std::size_t dataSize = vertexBuffer->GetDataSize( bufferIndex );
     vertexGpuBuffer->UpdateDataBuffer( dataSize, vertexBuffer->GetData( bufferIndex ) );
@@ -119,7 +119,7 @@ void RenderGeometry::DoUpload(
   const PropertyBuffer* indexBuffer = geometry.GetIndexBuffer();
   if( indexBuffer )
   {
-    GpuBuffer* indexGpuBuffer = new GpuBuffer( *context, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+    GpuBuffer* indexGpuBuffer = new GpuBuffer( context, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
 
     unsigned int dataSize = indexBuffer->GetDataSize( bufferIndex );
     indexGpuBuffer->UpdateDataBuffer( dataSize, indexBuffer->GetData( bufferIndex ) );
@@ -142,7 +142,7 @@ void RenderGeometry::BindBuffers()
   }
 }
 
-void RenderGeometry::EnableVertexAttributes( Context* context, Program& program )
+void RenderGeometry::EnableVertexAttributes( Context& context, Program& program )
 {
   // @todo Loop thru the array of vertex buffers
   // @todo Use AttributeDataProvider to get the attrs and enable them
@@ -152,36 +152,36 @@ void RenderGeometry::EnableVertexAttributes( Context* context, Program& program
   unsigned int gpuBufferIndex = 0;
 
   GLint positionLoc = program.GetAttribLocation( Program::ATTRIB_POSITION );
-  context->VertexAttribPointer( positionLoc,
+  context.VertexAttribPointer( positionLoc,
                                 2,         // 2D position
                                 GL_FLOAT,
                                 GL_FALSE,  // Not normalized
                                 mVertexBuffers[gpuBufferIndex]->GetStride(),
                                 &vertex->x );
 
-  context->EnableVertexAttributeArray( positionLoc );
+  context.EnableVertexAttributeArray( positionLoc );
 
   GLint textureCoordsLoc = program.GetAttribLocation( Program::ATTRIB_TEXCOORD );
-  context->VertexAttribPointer( textureCoordsLoc,
+  context.VertexAttribPointer( textureCoordsLoc,
                                 2,         // Texture Coords = U, V
                                 GL_FLOAT,
                                 GL_FALSE,
                                 mVertexBuffers[gpuBufferIndex]->GetStride(),
                                 &vertex->z );
-  context->EnableVertexAttributeArray( textureCoordsLoc );
+  context.EnableVertexAttributeArray( textureCoordsLoc );
 }
 
-void RenderGeometry::DisableVertexAttributes( Context* context, Program& program )
+void RenderGeometry::DisableVertexAttributes( Context& context, Program& program )
 {
   // @todo Loop thru the array of vertex buffers
   // @todo Use AttributeDataProvider to get the attrs and disable them
   GLint positionLoc = program.GetAttribLocation( Program::ATTRIB_POSITION );
   GLint textureCoordsLoc = program.GetAttribLocation( Program::ATTRIB_TEXCOORD );
-  context->DisableVertexAttributeArray( positionLoc );
-  context->DisableVertexAttributeArray( textureCoordsLoc );
+  context.DisableVertexAttributeArray( positionLoc );
+  context.DisableVertexAttributeArray( textureCoordsLoc );
 }
 
-void RenderGeometry::Draw( Context* context, BufferIndex bufferIndex, const GeometryDataProvider& geometry )
+void RenderGeometry::Draw( Context& context, BufferIndex bufferIndex, const GeometryDataProvider& geometry )
 {
   GeometryDataProvider::GeometryType type = geometry.GetGeometryType( bufferIndex );
 
@@ -197,12 +197,12 @@ void RenderGeometry::Draw( Context* context, BufferIndex bufferIndex, const Geom
   {
     case Dali::Geometry::TRIANGLES:
     {
-      context->DrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
+      context.DrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
       break;
     }
     case Dali::Geometry::LINES:
     {
-      context->DrawElements(GL_LINES, numIndices, GL_UNSIGNED_SHORT, 0);
+      context.DrawElements(GL_LINES, numIndices, GL_UNSIGNED_SHORT, 0);
       break;
     }
     case Dali::Geometry::POINTS:
@@ -216,7 +216,7 @@ void RenderGeometry::Draw( Context* context, BufferIndex bufferIndex, const Geom
         numVertices = firstVertexBuffer->GetBufferSize() / stride;
       }
 
-      context->DrawArrays(GL_POINTS, 0, numVertices );
+      context.DrawArrays(GL_POINTS, 0, numVertices );
       break;
     }
     default:
index 4cb7377..829c51b 100644 (file)
@@ -71,7 +71,7 @@ public:
    * @param[in] bufferIndex The current buffer index
    * @param[in] geometryDataProvider The geometry data provider (to fetch geometry from)
    */
-  void UploadAndDraw(Context* context,
+  void UploadAndDraw(Context& context,
                      Program& program,
                      BufferIndex bufferIndex,
                      const GeometryDataProvider& geometryDataProvider );
@@ -88,7 +88,7 @@ public:
    * @param[in] bufferIndex The current buffer index
    * @param[in] geometryDataProvider The geometry data provider (to fetch geometry from)
    */
-  void UploadVertexData( Context* context,
+  void UploadVertexData( Context& context,
                          BufferIndex bufferIndex,
                          const GeometryDataProvider& geometryDataProvider );
 
@@ -100,7 +100,7 @@ private:
    * @param[in] bufferIndex The current buffer index
    * @param[in] geometryDataProvider The geometry data provider (to fetch geometry from)
    */
-  void DoUpload( Context* context,
+  void DoUpload( Context& context,
                  BufferIndex bufferIndex,
                  const GeometryDataProvider& geometryDataProvider );
 
@@ -115,7 +115,7 @@ private:
    * @param[in] context The GL context
    * @param[in] program The shader program to query for attribute locations
    */
-  void EnableVertexAttributes( Context* context, Program& progam );
+  void EnableVertexAttributes( Context& context, Program& progam );
 
   /**
    * Disable the vertex attributes for each vertex buffer from the corresponding
@@ -123,7 +123,7 @@ private:
    * @param[in] context The GL context
    * @param[in] program The shader program to query for attribute locations
    */
-  void DisableVertexAttributes( Context* context, Program& program );
+  void DisableVertexAttributes( Context& context, Program& program );
 
   /**
    * Perform the correct draw call corresponding to the geometry type
@@ -131,7 +131,7 @@ private:
    * @param[in] bufferIndex The current buffer index
    * @param[in] geometryDataProvider The geometry data provider (to fetch geometry from)
    */
-  void Draw( Context* context,
+  void Draw( Context& context,
              BufferIndex bufferIndex,
              const GeometryDataProvider& geometry );
 
index 8b3672a..de1203c 100644 (file)
@@ -100,25 +100,25 @@ void NewRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& o
   // Do nothing
 }
 
-bool NewRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
+bool NewRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
 {
   // @todo MESH_REWORK Add clipping
   return false;
 }
 
-void NewRenderer::DoSetUniforms( Shader* shader, Context* context, Program* program, BufferIndex bufferIndex, unsigned int programIndex, ShaderSubTypes subType )
+void NewRenderer::DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType )
 {
   // Do nothing, we're going to set up the uniforms with our own code instead
 }
 
 
-void NewRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+void NewRenderer::DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
 {
-  BindTextures( bufferIndex, program, mMaterialDataProvider->GetSamplers() );
+  BindTextures( textureCache, bufferIndex, program, mMaterialDataProvider->GetSamplers() );
 
   SetUniforms( bufferIndex, program );
 
-  mRenderGeometry.UploadAndDraw( mContext, program, bufferIndex, *mGeometryDataProvider );
+  mRenderGeometry.UploadAndDraw( context, program, bufferIndex, *mGeometryDataProvider );
 }
 
 void NewRenderer::GlContextDestroyed()
@@ -239,9 +239,10 @@ void NewRenderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& prog
 }
 
 void NewRenderer::BindTextures(
-  BufferIndex bufferIndex,
-  Program& program,
-  const MaterialDataProvider::Samplers& samplers )
+    TextureCache& textureCache,
+    BufferIndex bufferIndex,
+    Program& program,
+    const MaterialDataProvider::Samplers& samplers )
 {
   // @todo MESH_REWORK Write a cache of texture units to commonly used sampler textures
   unsigned int textureUnit = 0;
@@ -252,12 +253,12 @@ void NewRenderer::BindTextures(
   {
     const SamplerDataProvider* sampler = *iter;
     ResourceId textureId = sampler->GetTextureId(bufferIndex);
-    Texture* texture = mTextureCache->GetTexture( textureId );
+    Texture* texture = textureCache.GetTexture( textureId );
     if( texture != NULL )
     {
       unsigned int textureUnitUniformIndex = GetTextureUnitUniformIndex( program, *sampler );
       TextureUnit theTextureUnit = static_cast<TextureUnit>(textureUnit);
-      BindTexture( program, textureId, texture, theTextureUnit, textureUnitUniformIndex );
+      BindTexture( textureCache, program, textureId, texture, theTextureUnit, textureUnitUniformIndex );
       ApplySampler( bufferIndex, texture, theTextureUnit, *sampler );
     }
 
@@ -266,17 +267,16 @@ void NewRenderer::BindTextures(
 }
 
 void NewRenderer::BindTexture(
-  Program& program,
-  ResourceId id,
-  Texture* texture,
-  TextureUnit textureUnit,
-  unsigned int textureUnitUniformIndex )
+    TextureCache& textureCache,
+    Program& program,
+    ResourceId id,
+    Texture* texture,
+    TextureUnit textureUnit,
+    unsigned int textureUnitUniformIndex )
 {
-  DALI_ASSERT_DEBUG( NULL != mTextureCache );
-
   if( texture != NULL )
   {
-    mTextureCache->BindTexture( texture, id, GL_TEXTURE_2D, textureUnit );
+    textureCache.BindTexture( texture, id, GL_TEXTURE_2D, textureUnit );
 
     // Set sampler uniform location for the texture
     GLint textureUnitLoc = program.GetUniformLocation( textureUnitUniformIndex );
index 8ce5c76..8110568 100644 (file)
@@ -112,18 +112,21 @@ public: // Implementation of Renderer
   /**
    * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
    */
-  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix,
+  virtual bool IsOutsideClipSpace( Context& context,
+                                   const Matrix& modelMatrix,
                                    const Matrix& modelViewProjectionMatrix );
 
   /**
    * @copydoc SceneGraph::Renderer::DoSetUniforms()
    */
-  virtual void DoSetUniforms(Shader* shader, Context* context, Program* program, BufferIndex bufferIndex, unsigned int programIndex, ShaderSubTypes subType );
+  virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
 
   /**
    * @copydoc SceneGraph::Renderer::DoRender()
    */
-  virtual void DoRender( BufferIndex bufferIndex,
+  virtual void DoRender( Context& context,
+                         TextureCache& textureCache,
+                         BufferIndex bufferIndex,
                          Program& program,
                          const Matrix& modelViewMatrix,
                          const Matrix& viewMatrix );
@@ -154,24 +157,28 @@ private:
 
   /**
    * Bind the material textures in the samplers and setup the samplers
+   * @param[in] textureCache The texture cache
    * @param[in] bufferIndex The buffer index
    * @param[in] program The shader program
    * @param[in] samplers The samplers to bind
    */
-  void BindTextures( BufferIndex bufferIndex,
+  void BindTextures( TextureCache& textureCache,
+                     BufferIndex bufferIndex,
                      Program& program,
                      const MaterialDataProvider::Samplers& samplers );
 
   /**
    * Bind a material texture to a texture unit, and set the sampler's texture uniform
    * to that texture unit.
+   * @param[in] textureCache The texture cache
    * @param[in] program The shader program
    * @param[in] id The resource id of the texture to bind
    * @param[in] texture The texture to bind
    * @param[in] textureUnit The texture unit index to use
    * @param[in] nameIndex The index of the texture uniform in the program
    */
-  void BindTexture( Program& program,
+  void BindTexture( TextureCache& textureCache,
+                    Program& program,
                     ResourceId id,
                     Texture* texture,
                     TextureUnit textureUnit,
index 1fb845c..c7c4f8d 100644 (file)
@@ -123,7 +123,7 @@ ImageRenderer::~ImageRenderer()
 {
   if ( mTextureId > 0 )
   {
-    mTextureCache->RemoveObserver(mTextureId, this);
+    mTextureCacheDELETEME->RemoveObserver(mTextureId, this);
   }
 
   GlCleanup();
@@ -133,7 +133,7 @@ void ImageRenderer::SetTextureId( ResourceId textureId )
 {
   if ( mTextureId > 0 )
   {
-    mTextureCache->RemoveObserver(mTextureId, this);
+    mTextureCacheDELETEME->RemoveObserver(mTextureId, this);
   }
 
   mTextureId = textureId;
@@ -141,7 +141,7 @@ void ImageRenderer::SetTextureId( ResourceId textureId )
 
   if ( textureId > 0 )
   {
-    mTextureCache->AddObserver(textureId, this);
+    mTextureCacheDELETEME->AddObserver(textureId, this);
   }
 }
 
@@ -206,7 +206,7 @@ bool ImageRenderer::CheckResources()
 {
   if( mTexture == NULL )
   {
-    mTexture = mTextureCache->GetTexture( mTextureId );
+    mTexture = mTextureCacheDELETEME->GetTexture( mTextureId );
   }
 
   if( mTexture == NULL )
@@ -222,7 +222,7 @@ bool ImageRenderer::CheckResources()
 
   Integration::ResourceId shaderTextureId =  mShader->GetTextureIdToRender() ;
 
-  if( shaderTextureId &&  mTextureCache->GetTexture( shaderTextureId ) == NULL )
+  if( shaderTextureId &&  mTextureCacheDELETEME->GetTexture( shaderTextureId ) == NULL )
   {
     return false;
   }
@@ -236,9 +236,9 @@ void ImageRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType&
   outSubType = SHADER_DEFAULT;
 }
 
-bool ImageRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
+bool ImageRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
 {
-  mContext->IncrementRendererCount();
+  context.IncrementRendererCount();
 
   Rect<float> boundingBox( mGeometrySize.x * -0.5f, mGeometrySize.y * -0.5f, mGeometrySize.x, mGeometrySize.y );
 
@@ -246,13 +246,13 @@ bool ImageRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix&
 
   if(Is2dBoxOutsideClipSpace( modelMatrix, modelViewProjectionMatrix, boundingBox ) )
   {
-    mContext->IncrementCulledCount();
+    context.IncrementCulledCount();
     return true;
   }
   return false;
 }
 
-void ImageRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+void ImageRenderer::DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
 {
   DALI_LOG_INFO( gImageRenderFilter, Debug::Verbose, "DoRender() textureId=%d  texture:%p\n", mTextureId, mTexture);
 
@@ -266,7 +266,7 @@ void ImageRenderer::DoRender( BufferIndex bufferIndex, Program& program, const M
 
   DALI_ASSERT_DEBUG( mVertexBuffer );
 
-  mTextureCache->BindTexture( mTexture, mTextureId,  GL_TEXTURE_2D, TEXTURE_UNIT_IMAGE );
+  mTextureCacheDELETEME->BindTexture( mTexture, mTextureId,  GL_TEXTURE_2D, TEXTURE_UNIT_IMAGE );
 
   if( mTexture->GetTextureId() == 0 )
   {
@@ -311,18 +311,18 @@ void ImageRenderer::DoRender( BufferIndex bufferIndex, Program& program, const M
 
   if ( positionLoc != -1 )
   {
-    mContext->EnableVertexAttributeArray( positionLoc );
+    context.EnableVertexAttributeArray( positionLoc );
 
     const int stride = 4 * sizeof(float);
-    mContext->VertexAttribPointer( positionLoc, 2, GL_FLOAT, GL_FALSE, stride, 0 );
+    context.VertexAttribPointer( positionLoc, 2, GL_FLOAT, GL_FALSE, stride, 0 );
   }
 
   if ( texCoordLoc != -1 )
   {
-    mContext->EnableVertexAttributeArray( texCoordLoc );
+    context.EnableVertexAttributeArray( texCoordLoc );
 
     const int stride = 4 * sizeof(float);
-    mContext->VertexAttribPointer( texCoordLoc, 2, GL_FLOAT, GL_FALSE, stride, (const void*) (sizeof(float)*2) );
+    context.VertexAttribPointer( texCoordLoc, 2, GL_FLOAT, GL_FALSE, stride, (const void*) (sizeof(float)*2) );
   }
 
   switch(mMeshType)
@@ -332,7 +332,7 @@ void ImageRenderer::DoRender( BufferIndex bufferIndex, Program& program, const M
     case NINE_PATCH_NO_CENTER:
     {
       const GLsizei vertexCount = mVertexBuffer->GetBufferSize() / sizeof(Vertex2D); // compiler will optimize this to >> if possible
-      mContext->DrawArrays( GL_TRIANGLE_STRIP, 0, vertexCount );
+      context.DrawArrays( GL_TRIANGLE_STRIP, 0, vertexCount );
       break;
     }
     case GRID_QUAD:
@@ -341,28 +341,28 @@ void ImageRenderer::DoRender( BufferIndex bufferIndex, Program& program, const M
     {
       const GLsizei indexCount = mIndexBuffer->GetBufferSize() / sizeof(GLushort); // compiler will optimize this to >> if possible
       mIndexBuffer->Bind();
-      mContext->DrawElements( GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0 );
+      context.DrawElements( GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0 );
       break;
     }
   }
 
   if ( positionLoc != -1 )
   {
-    mContext->DisableVertexAttributeArray( positionLoc );
+    context.DisableVertexAttributeArray( positionLoc );
   }
 
   if ( texCoordLoc != -1 )
   {
-    mContext->DisableVertexAttributeArray( texCoordLoc );
+    context.DisableVertexAttributeArray( texCoordLoc );
   }
 }
 
-void ImageRenderer::UpdateVertexBuffer( GLsizeiptr size, const GLvoid *data )
+void ImageRenderer::UpdateVertexBuffer( Context& context, GLsizeiptr size, const GLvoid *data )
 {
   // create/destroy if needed/not needed.
   if ( size && !mVertexBuffer )
   {
-    mVertexBuffer = new GpuBuffer( *mContext, GpuBuffer::ARRAY_BUFFER, GpuBuffer::DYNAMIC_DRAW );
+    mVertexBuffer = new GpuBuffer( context, GpuBuffer::ARRAY_BUFFER, GpuBuffer::DYNAMIC_DRAW );
   }
   else if ( !size && mVertexBuffer )
   {
@@ -376,12 +376,12 @@ void ImageRenderer::UpdateVertexBuffer( GLsizeiptr size, const GLvoid *data )
   }
 }
 
-void ImageRenderer::UpdateIndexBuffer( GLsizeiptr size, const GLvoid *data )
+void ImageRenderer::UpdateIndexBuffer( Context& context, GLsizeiptr size, const GLvoid *data )
 {
   // create/destroy if needed/not needed.
   if ( size && !mIndexBuffer )
   {
-    mIndexBuffer = new GpuBuffer( *mContext, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+    mIndexBuffer = new GpuBuffer( context, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
   }
   else if ( !size && mIndexBuffer )
   {
@@ -479,8 +479,8 @@ void ImageRenderer::SetQuadMeshData( Texture* texture, const Vector2& size, cons
 
   texture->MapUV( sizeof(verts)/sizeof(Vertex2D), verts, pixelArea );
 
-  UpdateVertexBuffer( sizeof(verts), verts );
-  UpdateIndexBuffer( 0, NULL );
+  UpdateVertexBuffer( *mContextDELETEME, sizeof(verts), verts );
+  UpdateIndexBuffer( *mContextDELETEME, 0, NULL );
 }
 
 void ImageRenderer::SetNinePatchMeshData( Texture* texture, const Vector2& size, const Vector4& border, bool borderInPixels, const PixelArea* pixelArea, bool noCenter )
@@ -620,7 +620,7 @@ void ImageRenderer::SetNinePatchMeshData( Texture* texture, const Vector2& size,
     const size_t vertsSize = sizeof( vertsWithCenter );
     const unsigned int vertexCount = vertsSize / sizeof( vertsWithCenter[0] );
     texture->MapUV( vertexCount, vertsWithCenter, pixelArea );
-    UpdateVertexBuffer( vertsSize, vertsWithCenter );
+    UpdateVertexBuffer( *mContextDELETEME, vertsSize, vertsWithCenter );
   }
   else
   {
@@ -701,10 +701,10 @@ void ImageRenderer::SetNinePatchMeshData( Texture* texture, const Vector2& size,
     const size_t vertsSize = sizeof( vertsWithNoCenter );
     const unsigned int vertexCount = vertsSize / sizeof( vertsWithNoCenter[0] );
     texture->MapUV( vertexCount, vertsWithNoCenter, pixelArea );
-    UpdateVertexBuffer( vertsSize, vertsWithNoCenter );
+    UpdateVertexBuffer( *mContextDELETEME, vertsSize, vertsWithNoCenter );
   }
   // not using an index buffer
-  UpdateIndexBuffer( 0, NULL );
+  UpdateIndexBuffer( *mContextDELETEME, 0, NULL );
 
 }
 
@@ -893,8 +893,8 @@ void ImageRenderer::SetGridMeshData( Texture* texture, const Vector2& size, cons
 
   texture->MapUV( totalVertices, vertices, pixelArea );
 
-  UpdateVertexBuffer( totalVertices * sizeof(Vertex2D) , vertices );
-  UpdateIndexBuffer( totalIndices * sizeof(GLushort), indices );
+  UpdateVertexBuffer( *mContextDELETEME, totalVertices * sizeof(Vertex2D) , vertices );
+  UpdateIndexBuffer( *mContextDELETEME, totalIndices * sizeof(GLushort), indices );
 
   delete[] vertices;
   delete[] indices;
index ee8c20f..3d9e27a 100644 (file)
@@ -123,12 +123,12 @@ public:
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
    */
-  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
+  virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
 
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
    */
-  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
+  virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
 
 protected: // TextureObserver implementation
 
@@ -141,12 +141,12 @@ private:
   /**
    * Helper to update the vertex buffer.
    */
-  void UpdateVertexBuffer( GLsizeiptr size, const GLvoid *data );
+  void UpdateVertexBuffer( Context& context, GLsizeiptr size, const GLvoid *data );
 
   /**
    * Helper to update the index buffer.
    */
-  void UpdateIndexBuffer( GLsizeiptr size, const GLvoid *data );
+  void UpdateIndexBuffer( Context& context, GLsizeiptr size, const GLvoid *data );
 
   /**
    * Helper to generate mesh data when required
index 5041c94..c48a359 100644 (file)
@@ -110,8 +110,8 @@ namespace SceneGraph
 
 void Renderer::Initialize( Context& context, TextureCache& textureCache )
 {
-  mContext = &context;
-  mTextureCache = &textureCache;
+  mContextDELETEME = &context;
+  mTextureCacheDELETEME = &textureCache;
 }
 
 Renderer::~Renderer()
@@ -149,7 +149,9 @@ void Renderer::SetSampler( unsigned int samplerBitfield )
   mSamplerBitfield = samplerBitfield;
 }
 
-void Renderer::Render( BufferIndex bufferIndex,
+void Renderer::Render( Context& context,
+                       TextureCache& textureCache,
+                       BufferIndex bufferIndex,
                        Shader& defaultShader,
                        const Matrix& modelViewMatrix,
                        const Matrix& viewMatrix,
@@ -157,8 +159,6 @@ void Renderer::Render( BufferIndex bufferIndex,
                        float frametime,
                        bool cull )
 {
-  DALI_ASSERT_DEBUG( mContext && "Renderer::Render. Renderer not initialised!! (mContext == NULL)." );
-
   // @todo MESH_REWORK Fix when merging! :D
   NewRenderer* renderer = dynamic_cast<NewRenderer*>(this);
   if( renderer )
@@ -189,18 +189,18 @@ void Renderer::Render( BufferIndex bufferIndex,
   ShaderSubTypes subType=SHADER_DEFAULT;
   ResolveGeometryTypes( bufferIndex, geometryType, subType );
   unsigned int programIndex = 0;
-  Program* program = mShader->GetProgram( *mContext, geometryType, subType, programIndex );
+  Program* program = mShader->GetProgram( context, geometryType, subType, programIndex );
   if( !program )
   {
     // if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program
-    program = defaultShader.GetProgram( *mContext, geometryType, subType, programIndex );
+    program = defaultShader.GetProgram( context, geometryType, subType, programIndex );
     DALI_ASSERT_ALWAYS( program && "Default shader is missing a geometry type!!" );
   }
 
   // Check culling (does not need the program to be in use)
   if( cull && ! program->ModifiesGeometry() )
   {
-    if( IsOutsideClipSpace( modelMatrix, gModelViewProjectionMatrix ) )
+    if( IsOutsideClipSpace( context, modelMatrix, gModelViewProjectionMatrix ) )
     {
       // don't do any further gl state changes as this renderer is not visible
       return;
@@ -211,30 +211,30 @@ void Renderer::Render( BufferIndex bufferIndex,
   program->Use();
 
   // Enables/disables blending mode.
-  mContext->SetBlend( mUseBlend );
+  context.SetBlend( mUseBlend );
 
   // Set face culling mode
-  mContext->CullFace( mCullFaceMode );
+  context.CullFace( mCullFaceMode );
 
   // Set the blend color
   const Vector4* const customColor = mBlendingOptions.GetBlendColor();
   if( customColor )
   {
-    mContext->SetCustomBlendColor( *customColor );
+    context.SetCustomBlendColor( *customColor );
   }
   else
   {
-    mContext->SetDefaultBlendColor();
+    context.SetDefaultBlendColor();
   }
 
   // Set blend source & destination factors
-  mContext->BlendFuncSeparate( mBlendingOptions.GetBlendSrcFactorRgb(),
+  context.BlendFuncSeparate( mBlendingOptions.GetBlendSrcFactorRgb(),
                                mBlendingOptions.GetBlendDestFactorRgb(),
                                mBlendingOptions.GetBlendSrcFactorAlpha(),
                                mBlendingOptions.GetBlendDestFactorAlpha() );
 
   // Set blend equations
-  mContext->BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
+  context.BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
                                    mBlendingOptions.GetBlendEquationAlpha() );
 
   // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
@@ -254,23 +254,22 @@ void Renderer::Render( BufferIndex bufferIndex,
     program->SetUniform1f( loc, frametime );
   }
 
-  DoSetUniforms(mShader, mContext, program, bufferIndex, programIndex, subType );
+  DoSetUniforms(context, bufferIndex, mShader, program, programIndex, subType );
 
   // subclass rendering and actual draw call
-  DoRender( bufferIndex, *program, modelViewMatrix, viewMatrix );
+  DoRender( context, textureCache, bufferIndex, *program, modelViewMatrix, viewMatrix );
 }
 
 // can be overridden by deriving class
-void Renderer::DoSetUniforms(Shader* shader, Context* context, Program* program, BufferIndex bufferIndex, unsigned int programIndex, ShaderSubTypes subType )
+void Renderer::DoSetUniforms(Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType )
 {
-  shader->SetUniforms( *context, *program, bufferIndex, programIndex, subType );
+  shader->SetUniforms( context, *program, bufferIndex, programIndex, subType );
 }
 
 Renderer::Renderer( NodeDataProvider& dataprovider )
 : mDataProvider( dataprovider ),
-  mContext( NULL ),
-
-  mTextureCache( NULL ),
+  mContextDELETEME(NULL),
+  mTextureCacheDELETEME( NULL ),
   mShader( NULL ),
   mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
   mUseBlend( false ),
index 3d54d25..3e02b4d 100644 (file)
@@ -57,7 +57,6 @@ public:
   /**
    * Second-phase construction.
    * This is called when the renderer is inside render thread
-   * @param[in] context to use
    * @param[in] textureCache to use
    */
   void Initialize( Context& context, TextureCache& textureCache );
@@ -111,6 +110,8 @@ public:
 
   /**
    * Called to render during RenderManager::Render().
+   * @param[in] context The context used for rendering
+   * @param[in] textureCache The texture cache used to get textures
    * @param[in] bufferIndex The index of the previous update buffer.
    * @param[in] defaultShader in case there is no custom shader
    * @param[in] modelViewMatrix The model-view matrix.
@@ -119,7 +120,9 @@ public:
    * @param[in] frametime The elapsed time between the last two updates.
    * @param[in] cull Whether to frustum cull this renderer
    */
-  void Render( BufferIndex bufferIndex,
+  void Render( Context& context,
+               TextureCache& textureCache,
+               BufferIndex bufferIndex,
                Shader& defaultShader,
                const Matrix& modelViewMatrix,
                const Matrix& viewMatrix,
@@ -166,28 +169,31 @@ private:
    * @param[in] modelViewProjectionMatrix The MVP matrix.
    * @return \e true if it is. Otherwise \e false.
    */
-  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
+  virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
 
   /**
    * Called from Render prior to DoRender().
    * @todo MESH_REWORK Remove after merge
    */
-  virtual void DoSetUniforms(Shader* shader, Context* context, Program* program, BufferIndex bufferIndex, unsigned int programIndex, ShaderSubTypes subType );
+  virtual void DoSetUniforms(Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
 
   /**
    * Called from Render; implemented in derived classes.
+   * @param[in] context The context used for rendering
+   * @param[in] textureCache The texture cache used to get textures
    * @param[in] bufferIndex The index of the previous update buffer.
    * @param[in] program to use.
    * @param[in] modelViewMatrix The model-view matrix.
    * @param[in] viewMatrix The view matrix.
    */
-  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
+  virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
 
 protected:
 
   NodeDataProvider& mDataProvider;
-  Context* mContext;
-  TextureCache* mTextureCache;
+
+  Context* mContextDELETEME; // TODO: MESH_REWORK DELETE THIS
+  TextureCache* mTextureCacheDELETEME; // TODO: MESH_REWORK DELETE THIS
   Shader* mShader;
   unsigned int mSamplerBitfield;          ///< Sampler options used for texture filtering
 
index 63f65b1..9379db7 100644 (file)
@@ -61,7 +61,7 @@ TextRenderer::~TextRenderer()
 {
   if(mTextureId > 0)
   {
-    mTextureCache->RemoveObserver(mTextureId, this);
+    mTextureCacheDELETEME->RemoveObserver(mTextureId, this);
   }
 
   GlCleanup();
@@ -91,7 +91,7 @@ void TextRenderer::SetTextureId( ResourceId textureId )
 
   if(mTextureId > 0)
   {
-    mTextureCache->RemoveObserver(mTextureId, this);
+    mTextureCacheDELETEME->RemoveObserver(mTextureId, this);
   }
 
   mTextureId = textureId;
@@ -99,7 +99,7 @@ void TextRenderer::SetTextureId( ResourceId textureId )
 
   if(textureId > 0)
   {
-    mTextureCache->AddObserver(textureId, this);
+    mTextureCacheDELETEME->AddObserver(textureId, this);
   }
 }
 
@@ -164,14 +164,15 @@ void TextRenderer::SetVertexData( TextVertexBuffer* vertexData )
   {
     SetTextureId(vertexData->mTextureId);
 
+    DALI_ASSERT_DEBUG(mContextDELETEME);
     if ( !mVertexBuffer )
     {
-      mVertexBuffer = new GpuBuffer( *mContext, GpuBuffer::ARRAY_BUFFER, GpuBuffer::DYNAMIC_DRAW );
+      mVertexBuffer = new GpuBuffer( *mContextDELETEME, GpuBuffer::ARRAY_BUFFER, GpuBuffer::DYNAMIC_DRAW );
     }
 
     if ( !mIndexBuffer )
     {
-      mIndexBuffer = new GpuBuffer( *mContext, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+      mIndexBuffer = new GpuBuffer( *mContextDELETEME, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
     }
 
     mVertexBuffer->UpdateDataBuffer( vertexData->mVertices.size() * sizeof(TextVertex2D), &vertexData->mVertices[0] );
@@ -280,7 +281,7 @@ bool TextRenderer::CheckResources()
 
   if( mTexture == NULL )
   {
-    mTexture = mTextureCache->GetTexture( mTextureId );
+    mTexture = mTextureCacheDELETEME->GetTexture( mTextureId );
 
     if( mTexture == NULL )
     {
@@ -331,22 +332,22 @@ void TextRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType&
   }
 }
 
-bool TextRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
+bool TextRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
 {
-  mContext->IncrementRendererCount();
+  context.IncrementRendererCount();
 
   Rect<float> boundingBox(mGeometryExtent.width*-0.5f, mGeometryExtent.height*-0.5f, mGeometryExtent.width, mGeometryExtent.height);
   DEBUG_BOUNDING_BOX( *mContext, boundingBox, modelViewProjectionMatrix );
 
   if(Is2dBoxOutsideClipSpace( modelMatrix, modelViewProjectionMatrix, boundingBox ) )
   {
-    mContext->IncrementCulledCount();
+    context.IncrementCulledCount();
     return true;
   }
   return false;
 }
 
-void TextRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+void TextRenderer::DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
 {
   DALI_ASSERT_DEBUG( NULL != mTexture && "TextRenderer::DoRender. mTexture == NULL." );
   if( NULL == mTexture )
@@ -357,7 +358,7 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Ma
 
   DALI_LOG_INFO( gTextFilter, Debug::General, "TextRenderer::DoRender(this: %p) textureId:%d\n", this, mTextureId );
 
-  mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TEXTURE_UNIT_TEXT );
+  mTextureCacheDELETEME->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TEXTURE_UNIT_TEXT );
   if( mTexture->GetTextureId() == 0 )
   {
     return; // early out if we haven't got a GL texture yet (e.g. due to context loss)
@@ -501,8 +502,8 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Ma
   const GLint positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
   const GLint texCoordLoc = program.GetAttribLocation(Program::ATTRIB_TEXCOORD);
 
-  mContext->EnableVertexAttributeArray( positionLoc );
-  mContext->EnableVertexAttributeArray( texCoordLoc );
+  context.EnableVertexAttributeArray( positionLoc );
+  context.EnableVertexAttributeArray( texCoordLoc );
 
   // bind the buffers
   DALI_ASSERT_DEBUG( mVertexBuffer->BufferIsValid() );
@@ -511,14 +512,14 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Ma
   mIndexBuffer->Bind();
 
   TextVertex2D* v = 0;
-  mContext->VertexAttribPointer(positionLoc,  2, GL_FLOAT, GL_FALSE, sizeof(TextVertex2D), &v->mX);
-  mContext->VertexAttribPointer(texCoordLoc,  4, GL_FLOAT, GL_FALSE, sizeof(TextVertex2D), &v->mU);
+  context.VertexAttribPointer(positionLoc,  2, GL_FLOAT, GL_FALSE, sizeof(TextVertex2D), &v->mX);
+  context.VertexAttribPointer(texCoordLoc,  4, GL_FLOAT, GL_FALSE, sizeof(TextVertex2D), &v->mU);
 
   const GLsizei indexCount = mIndexBuffer->GetBufferSize() / sizeof(GLushort); // compiler will optimize this to >> if possible
-  mContext->DrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *) 0);
+  context.DrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *) 0);
 
-  mContext->DisableVertexAttributeArray( positionLoc );
-  mContext->DisableVertexAttributeArray( texCoordLoc );
+  context.DisableVertexAttributeArray( positionLoc );
+  context.DisableVertexAttributeArray( texCoordLoc );
 
 }
 
index 8bb1e22..d6d2b17 100644 (file)
@@ -133,12 +133,12 @@ public:
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
    */
-  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
+  virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
 
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
    */
-  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
+  virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
 
 protected: // TextureObserver implementation
   /**