PropertyBuffer Attributes. 46/37946/4
authorFrancisco Santos <f1.santos@samsung.com>
Wed, 8 Apr 2015 16:38:06 +0000 (17:38 +0100)
committerFrancisco Santos <f1.santos@samsung.com>
Tue, 14 Apr 2015 12:34:40 +0000 (13:34 +0100)
Change-Id: I6e2766d3f1726a04c49b463c0f7c2ed62fcbdf38

15 files changed:
dali/internal/file.list
dali/internal/render/data-providers/attribute-data-provider.h [deleted file]
dali/internal/render/data-providers/geometry-data-provider.h
dali/internal/render/data-providers/property-buffer-data-provider.h [new file with mode: 0644]
dali/internal/render/data-providers/render-data-provider.cpp
dali/internal/render/data-providers/render-data-provider.h
dali/internal/render/renderers/render-geometry.cpp
dali/internal/render/renderers/render-geometry.h
dali/internal/render/renderers/render-renderer-property-buffer.cpp [new file with mode: 0644]
dali/internal/render/renderers/render-renderer-property-buffer.h [new file with mode: 0644]
dali/internal/render/renderers/render-renderer.h
dali/internal/update/common/scene-graph-property-buffer.cpp
dali/internal/update/common/scene-graph-property-buffer.h
dali/internal/update/geometry/scene-graph-geometry.cpp
dali/internal/update/node-attachments/scene-graph-renderer-attachment.cpp

index d53acc76f6a7c5b1a0d2d163fc101411a43e5a1e..f0c1d7d7e28886bbc7498f7f43500edcf0d93936 100644 (file)
@@ -148,6 +148,7 @@ internal_src_files = \
   $(internal_src_dir)/render/queue/render-queue.cpp \
   $(internal_src_dir)/render/renderers/render-geometry.cpp \
   $(internal_src_dir)/render/renderers/render-renderer.cpp \
+  $(internal_src_dir)/render/renderers/render-renderer-property-buffer.cpp \
   $(internal_src_dir)/render/renderers/scene-graph-image-renderer.cpp \
   $(internal_src_dir)/render/renderers/scene-graph-renderer.cpp \
   $(internal_src_dir)/render/renderers/scene-graph-renderer-debug.cpp \
diff --git a/dali/internal/render/data-providers/attribute-data-provider.h b/dali/internal/render/data-providers/attribute-data-provider.h
deleted file mode 100644 (file)
index cb3f680..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef DALI_INTERNAL_SCENE_GRAPH_ATTRIBUTE_DATA_PROVIDER_H
-#define DALI_INTERNAL_SCENE_GRAPH_ATTRIBUTE_DATA_PROVIDER_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.
- */
-
-#include <dali/public-api/shader-effects/attribute.h>
-#include <dali/integration-api/resource-declarations.h>
-#include <dali/internal/common/buffer-index.h>
-
-namespace Dali
-{
-namespace Internal
-{
-namespace SceneGraph
-{
-
-class AttributeDataProvider
-{
-public:
-  /**
-   * Constructor
-   */
-  AttributeDataProvider()
-  {
-  }
-
-  virtual const AttributeList& GetAttributeList() = 0;
-
-protected:
-  /**
-   * No deletion through this interface
-   */
-  virtual ~AttributeDataProvider()
-  {
-  }
-};
-
-} // namespace SceneGraph
-} // namespace Internal
-} // namespace Dali
-
-#endif // DALI_INTERNAL_SCENE_GRAPH_ATTRIBUTE_DATA_PROVIDER_H
index 30637387f9fae7ceee69240e081cd7297c3f0124..60abb726dab93d83fadabf694be2e9ca2c3ac285 100644 (file)
@@ -20,6 +20,7 @@
 #include <dali/public-api/geometry/geometry.h>
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/common/owner-container.h>
+#include <dali/internal/render/data-providers/property-buffer-data-provider.h>
 
 namespace Dali
 {
@@ -39,7 +40,7 @@ class GeometryDataProvider
 {
 public:
   typedef Dali::Geometry::GeometryType GeometryType;
-  typedef Dali::Vector< const PropertyBuffer* > VertexBuffers;
+  typedef Dali::Vector< const PropertyBufferDataProvider* > VertexBuffers;
 
   /**
    * Constructor. Nothing to do as a pure interface.
diff --git a/dali/internal/render/data-providers/property-buffer-data-provider.h b/dali/internal/render/data-providers/property-buffer-data-provider.h
new file mode 100644 (file)
index 0000000..2ae1862
--- /dev/null
@@ -0,0 +1,137 @@
+#ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_DATA_PROVIDER_H
+#define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_DATA_PROVIDER_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/integration-api/resource-declarations.h>
+#include <dali/internal/common/buffer-index.h>
+
+namespace Dali
+{
+namespace Internal
+{
+namespace SceneGraph
+{
+
+class PropertyBufferDataProvider
+{
+public:
+
+  /**
+   * Type for the data contained in the buffer
+   */
+  typedef Dali::Vector< char > BufferType;
+
+public:
+  /**
+   * Constructor
+   */
+  PropertyBufferDataProvider()
+  {
+  }
+
+  /**
+   * Check if the data has changed
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return true if the data has changed
+   */
+  virtual bool HasDataChanged( BufferIndex bufferIndex ) const = 0;
+
+  /**
+   * Get the number of attributes
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return the number of attributes
+   */
+  virtual unsigned int GetAttributeCount( BufferIndex bufferIndex ) const = 0;
+
+  /**
+   * Get the name of an attribute
+   * @param[in] bufferIndex Index to access double buffered values
+   * @param[in] index Index of the attribute
+   * @return the name of the attribute
+   */
+  virtual const std::string& GetAttributeName( BufferIndex bufferIndex, unsigned int index ) const = 0;
+
+  /**
+   * Get the byte size of an attribute
+   * @param[in] bufferIndex Index to access double buffered values
+   * @param[in] index Index of the attribute
+   * @return the byte size of the attribute
+   */
+  virtual size_t GetAttributeSize( BufferIndex bufferIndex, unsigned int index ) const = 0;
+
+  /**
+   * Get the byte offset of an attribute
+   * @param[in] bufferIndex Index to access double buffered values
+   * @param[in] index Index of the attribute
+   * @return the byte offset of the attribute
+   */
+  virtual size_t GetAttributeOffset( BufferIndex bufferIndex, unsigned int index ) const = 0;
+
+  /**
+   * Get the property buffer data
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return the property buffer's data array
+   */
+  virtual const BufferType& GetData( BufferIndex bufferIndex ) const = 0;
+
+  /**
+   * Get the size of the property buffer in bytes
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return the size in bytes
+   */
+  virtual size_t GetDataSize( BufferIndex bufferIndex ) const = 0;
+
+  /**
+   * Get the size of an element of the buffer in bytes
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return the element size in bytes
+   */
+  virtual size_t GetElementSize( BufferIndex bufferIndex ) const = 0;
+
+  /**
+   * Get the number of elements
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return the number of elements
+   */
+  virtual unsigned int GetElementCount( BufferIndex bufferIndex ) const = 0;
+
+  /**
+   * Get if of the GPU buffer associated with this propertyBuffer
+   * @param[in] bufferIndex Index to access double buffered values
+   * @return the element size in bytes
+   */
+  virtual unsigned int GetGpuBufferId( BufferIndex bufferIndex ) const = 0;
+
+protected:
+  /**
+   * No deletion through this interface
+   */
+  virtual ~PropertyBufferDataProvider()
+  {
+  }
+};
+
+} // namespace SceneGraph
+} // namespace Internal
+} // namespace Dali
+
+#endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_DATA_PROVIDER_H
index 0fa8f333f2090438af1cd11dfa95f6b2abb0abb9..eb4d4628b78f6295a99e8e816ecf224d780c9033 100644 (file)
@@ -29,7 +29,7 @@ RenderDataProvider::RenderDataProvider(
   const MaterialDataProvider&   materialDataProvider,
   const UniformMapDataProvider& uniformMapDataProvider,
   Shader&                       shader,
-  const PropertyBuffer*         indexBuffer,
+  const PropertyBufferDataProvider* indexBuffer,
   const VertexBuffers&          vertexBuffers,
   const Samplers&               samplers )
 
@@ -87,12 +87,12 @@ Shader& RenderDataProvider::GetShader() const
   return *mShader;
 }
 
-void RenderDataProvider::SetIndexBuffer( const PropertyBuffer* indexBuffer )
+void RenderDataProvider::SetIndexBuffer( const PropertyBufferDataProvider* indexBuffer )
 {
   mIndexBuffer = indexBuffer;
 }
 
-const PropertyBuffer* RenderDataProvider::GetIndexBuffer() const
+const PropertyBufferDataProvider* RenderDataProvider::GetIndexBuffer() const
 {
   return mIndexBuffer;
 }
index 47170e39cbdce620f766ca7256cf696c8b8c86a5..a068a575a349c3c1142c27ef49bc3d99a42b2513 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/internal/render/data-providers/material-data-provider.h>
 #include <dali/internal/render/data-providers/node-data-provider.h>
 #include <dali/internal/render/data-providers/sampler-data-provider.h>
+#include <dali/internal/render/data-providers/property-buffer-data-provider.h>
 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
 
 namespace Dali
@@ -45,7 +46,7 @@ class Shader;
 class RenderDataProvider
 {
 public:
-  typedef Dali::Vector< const PropertyBuffer* > VertexBuffers;
+  typedef Dali::Vector< const PropertyBufferDataProvider* > VertexBuffers;
   typedef Dali::Vector< const SamplerDataProvider* > Samplers;
 
   /**
@@ -55,7 +56,7 @@ public:
                       const MaterialDataProvider&   mMaterialDataProvider,
                       const UniformMapDataProvider& mUniformMapDataProvider,
                       Shader&                       mShader,
-                      const PropertyBuffer*         mIndexBuffer,
+                      const PropertyBufferDataProvider* mIndexBuffer,
                       const VertexBuffers&          mVertexBuffers,
                       const Samplers&               mSamplers );
 
@@ -116,13 +117,13 @@ public:
    * Set the index buffer
    * @param[in] indexBuffer the index buffer to set
    */
-  void SetIndexBuffer( const PropertyBuffer* indexBuffer );
+  void SetIndexBuffer( const PropertyBufferDataProvider* indexBuffer );
 
   /**
    * Get the index buffer of the geometry
    * @return A const reference to the index buffer
    */
-  const PropertyBuffer* GetIndexBuffer() const;
+  const PropertyBufferDataProvider* GetIndexBuffer() const;
 
   /**
    * Set the vertex buffers
@@ -153,7 +154,7 @@ private:
   const MaterialDataProvider*   mMaterialDataProvider;
   const UniformMapDataProvider* mUniformMapDataProvider;
   Shader*                       mShader;
-  const PropertyBuffer*         mIndexBuffer;
+  const PropertyBufferDataProvider* mIndexBuffer;
   VertexBuffers                 mVertexBuffers;
   Samplers                      mSamplers;
 };
index c7b07a801e7c5331a80d688a11fa1273511d9aa9..c5b7ec690fe396a3f16e6dd7a201e3fdba1f4df5 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "render-geometry.h"
+#include <dali/internal/render/renderers/render-geometry.h>
 
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/update/geometry/scene-graph-geometry.h>
@@ -32,7 +32,8 @@ namespace SceneGraph
 {
 
 RenderGeometry::RenderGeometry()
-: mDataNeedsUploading( true )
+: mDataNeedsUploading( true ),
+  mShaderChanged( true )
 {
 }
 
@@ -47,19 +48,6 @@ void RenderGeometry::GlContextCreated( Context& context )
 
 void RenderGeometry::GlContextDestroyed()
 {
-  for( GpuBuffers::Iterator iter=mVertexBuffers.Begin(); iter != mVertexBuffers.End(); ++iter )
-  {
-    GpuBuffer* gpuBuffer = *iter;
-    if( gpuBuffer )
-    {
-      gpuBuffer->GlContextDestroyed();
-    }
-  }
-
-  if( mIndexBuffer )
-  {
-    mIndexBuffer->GlContextDestroyed();
-  }
 }
 
 void RenderGeometry::UploadAndDraw(
@@ -69,10 +57,27 @@ void RenderGeometry::UploadAndDraw(
   const RenderDataProvider* dataProviders )
 {
   UploadVertexData( context, bufferIndex, dataProviders );
-  BindBuffers();
-  EnableVertexAttributes( context, program );
+
+  for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i )
+  {
+    mVertexBuffers[i]->BindBuffer( context, program );
+    mVertexBuffers[i]->EnableVertexAttributes( context, bufferIndex, program );
+  }
+
+  if( mIndexBuffer )
+  {
+    mIndexBuffer->BindBuffer( context, program );
+  }
+
+//  BindBuffers( context, bufferIndex, program );
+//  EnableVertexAttributes( context, bufferIndex, program );
   Draw( context, bufferIndex, dataProviders );
-  DisableVertexAttributes( context, program );
+
+  for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i )
+  {
+    mVertexBuffers[i]->DisableVertexAttributes( context, bufferIndex, program );
+  }
+  //DisableVertexAttributes( context, bufferIndex, program );
 }
 
 void RenderGeometry::GeometryUpdated()
@@ -105,88 +110,62 @@ void RenderGeometry::DoUpload(
 
   for( unsigned int i=0; i<vertexBuffers.Count(); ++i)
   {
-    const PropertyBuffer* vertexBuffer = vertexBuffers[i];
+    const PropertyBufferDataProvider* 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 );
+    RenderPropertyBuffer* propertyBuffer = new RenderPropertyBuffer( *vertexBuffer, false );
 
-    std::size_t dataSize = vertexBuffer->GetDataSize( bufferIndex );
-    vertexGpuBuffer->UpdateDataBuffer( dataSize, vertexBuffer->GetData( bufferIndex ) );
-    vertexGpuBuffer->SetStride( vertexBuffer->GetElementSize( bufferIndex ) );
+    propertyBuffer->DoUpload( context, bufferIndex );
 
-    mVertexBuffers.PushBack( vertexGpuBuffer );
+    mVertexBuffers.PushBack( propertyBuffer );
   }
 
   // Index buffer
-  const PropertyBuffer* indexBuffer = dataProvider->GetIndexBuffer();
+  const PropertyBufferDataProvider* indexBuffer = dataProvider->GetIndexBuffer();
   if( indexBuffer )
   {
-    GpuBuffer* indexGpuBuffer = new GpuBuffer( context, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+    mIndexBuffer = new RenderPropertyBuffer( *indexBuffer, true );
 
-    unsigned int dataSize = indexBuffer->GetDataSize( bufferIndex );
-    indexGpuBuffer->UpdateDataBuffer( dataSize, indexBuffer->GetData( bufferIndex ) );
-
-    mIndexBuffer.Reset();
-    mIndexBuffer = indexGpuBuffer;
+    mIndexBuffer->DoUpload( context, bufferIndex );
   }
 }
 
-void RenderGeometry::BindBuffers()
+void RenderGeometry::BindBuffers( Context& context, BufferIndex bufferIndex, Program& program )
 {
-  for( GpuBuffers::Iterator iter=mVertexBuffers.Begin(); iter != mVertexBuffers.End(); ++iter )
+  for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i )
   {
-    (*iter)->Bind();
+    mVertexBuffers[i]->BindBuffer( context, program );
   }
 
   if( mIndexBuffer )
   {
-    mIndexBuffer->Bind();
+    mIndexBuffer->BindBuffer( context, program );
   }
 }
 
-void RenderGeometry::EnableVertexAttributes( Context& context, Program& program )
+void RenderGeometry::EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program )
 {
-  // @todo Loop thru the array of vertex buffers
-  // @todo Use AttributeDataProvider to get the attrs and enable them
-  // Need mapping from gpu buffers index to a particular attributes
-  Vector4 *vertex=0;
-
-  unsigned int gpuBufferIndex = 0;
-
-  GLint positionLoc = program.GetAttribLocation( Program::ATTRIB_POSITION );
-  context.VertexAttribPointer( positionLoc,
-                                2,         // 2D position
-                                GL_FLOAT,
-                                GL_FALSE,  // Not normalized
-                                mVertexBuffers[gpuBufferIndex]->GetStride(),
-                                &vertex->x );
-
-  context.EnableVertexAttributeArray( positionLoc );
-
-  GLint textureCoordsLoc = program.GetAttribLocation( Program::ATTRIB_TEXCOORD );
-  context.VertexAttribPointer( textureCoordsLoc,
-                                2,         // Texture Coords = U, V
-                                GL_FLOAT,
-                                GL_FALSE,
-                                mVertexBuffers[gpuBufferIndex]->GetStride(),
-                                &vertex->z );
-  context.EnableVertexAttributeArray( textureCoordsLoc );
+  OwnerContainer< RenderPropertyBuffer* >::Iterator it = mVertexBuffers.Begin();
+  OwnerContainer< RenderPropertyBuffer* >::ConstIterator end = mVertexBuffers.End();
+  for( ; it != end; ++it )
+  {
+    (*it)->EnableVertexAttributes( context, bufferIndex, program );
+  }
 }
 
-void RenderGeometry::DisableVertexAttributes( Context& context, Program& program )
+void RenderGeometry::DisableVertexAttributes( Context& context, BufferIndex bufferIndex, 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 );
+  OwnerContainer< RenderPropertyBuffer* >::Iterator it = mVertexBuffers.Begin();
+  OwnerContainer< RenderPropertyBuffer* >::ConstIterator end = mVertexBuffers.End();
+  for( ; it != end; ++it )
+  {
+    (*it)->DisableVertexAttributes( context, bufferIndex, program );
+  }
 }
 
 void RenderGeometry::Draw( Context& context, BufferIndex bufferIndex, const RenderDataProvider* dataProvider )
 {
   const GeometryDataProvider& geometry = dataProvider->GetGeometry();
-  const PropertyBuffer* indexBuffer = dataProvider->GetIndexBuffer();
+  const PropertyBufferDataProvider* indexBuffer = dataProvider->GetIndexBuffer();
 
   GeometryDataProvider::GeometryType type = geometry.GetGeometryType( bufferIndex );
 
@@ -210,15 +189,9 @@ void RenderGeometry::Draw( Context& context, BufferIndex bufferIndex, const Rend
     }
     case Dali::Geometry::POINTS:
     {
-      GpuBuffer* firstVertexBuffer = mVertexBuffers[0];
-
-      unsigned int numVertices = 0;
-      GLuint stride = firstVertexBuffer->GetStride();
-      if( stride != 0 )
-      {
-        numVertices = firstVertexBuffer->GetBufferSize() / stride;
-      }
+      const PropertyBufferDataProvider* firstVertexBuffer = dataProvider->GetVertexBuffers()[0];
 
+      unsigned int numVertices = firstVertexBuffer->GetElementCount( bufferIndex );
       context.DrawArrays(GL_POINTS, 0, numVertices );
       break;
     }
index eada45f1dde9e06e24b0d7cca6004baf5f5292d4..f4c7a1999a142cf1ce73f59cfcf83e092cbd7952 100644 (file)
  * limitations under the License.
  */
 
+#include <dali/public-api/common/dali-vector.h>
+#include <dali/integration-api/gl-defines.h>
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/common/owner-container.h>
 #include <dali/internal/common/owner-pointer.h>
 #include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/render/renderers/render-renderer-property-buffer.h>
 
 namespace Dali
 {
@@ -43,7 +46,6 @@ class GeometryDataProvider;
 class RenderGeometry
 {
 public:
-  typedef OwnerContainer< GpuBuffer* > GpuBuffers;
 
   /**
    * Constructor. Creates a render geometry object with no GPU buffers.
@@ -107,24 +109,31 @@ private:
 
   /**
    * Bind the geometry buffers
+   * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
+   * @param[in] program The shader program to query for attribute locations
    */
-  void BindBuffers();
+  void BindBuffers( Context& context,
+                    BufferIndex bufferIndex,
+                    Program& program );
 
   /**
    * Enable the vertex attributes for each vertex buffer from the corresponding
    * shader program.
    * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
    * @param[in] program The shader program to query for attribute locations
    */
-  void EnableVertexAttributes( Context& context, Program& progam );
+  void EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& progam );
 
   /**
    * Disable the vertex attributes for each vertex buffer from the corresponding
    * shader program.
    * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
    * @param[in] program The shader program to query for attribute locations
    */
-  void DisableVertexAttributes( Context& context, Program& program );
+  void DisableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program );
 
   /**
    * Perform the correct draw call corresponding to the geometry type
@@ -137,10 +146,13 @@ private:
              const RenderDataProvider* dataProviders );
 
 private:
-  GpuBuffers mVertexBuffers;
-  OwnerPointer< GpuBuffer > mIndexBuffer;
+  // PropertyBuffers
+  OwnerPointer< RenderPropertyBuffer > mIndexBuffer;
+  OwnerContainer< RenderPropertyBuffer* > mVertexBuffers;
 
+  // Booleans
   bool mDataNeedsUploading;
+  bool mShaderChanged;
 };
 
 } // namespace SceneGraph
diff --git a/dali/internal/render/renderers/render-renderer-property-buffer.cpp b/dali/internal/render/renderers/render-renderer-property-buffer.cpp
new file mode 100644 (file)
index 0000000..9be59e2
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+
+#include <dali/internal/render/renderers/render-renderer-property-buffer.h>
+
+#include <dali/internal/render/gl-resources/gpu-buffer.h>
+#include <dali/internal/render/shaders/program.h>
+
+namespace Dali
+{
+namespace Internal
+{
+namespace SceneGraph
+{
+
+RenderPropertyBuffer::RenderPropertyBuffer( const PropertyBufferDataProvider& propertyBufferDataProvider, bool isIndexBuffer )
+: mDataProvider( propertyBufferDataProvider ),
+  mGpuBuffer( NULL ),
+  mIsIndexBuffer( isIndexBuffer )
+{
+}
+
+RenderPropertyBuffer::~RenderPropertyBuffer()
+{
+}
+
+void RenderPropertyBuffer::DoUpload( Context& context, BufferIndex bufferIndex )
+{
+  bool hasGpuBuffer = NULL != mGpuBuffer;
+
+  // Check if we have a gpu-buffer
+  unsigned int gpuBufferId = 0; // TODO: MESH_REWORK FIX THIS  mDataProvider.GetGpuBufferId( bufferIndex );
+  if ( ! hasGpuBuffer )
+  {
+    // TODO: MESH_REWORK
+//    mGpuBuffer /*= gpuBufferCache.GetGpuBuffer( gpuBufferId ) */;
+    (void )gpuBufferId;
+
+    if( mIsIndexBuffer )
+    {
+      mGpuBuffer = new GpuBuffer( context, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+    }
+    else
+    {
+      mGpuBuffer = new GpuBuffer( context, GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW );
+    }
+  }
+
+  // Update the GpuBuffer
+  if ( ! hasGpuBuffer || mDataProvider.HasDataChanged( bufferIndex ) )
+  {
+    if( mIsIndexBuffer )
+    {
+      unsigned int dataSize = mDataProvider.GetDataSize( bufferIndex );
+      mGpuBuffer->UpdateDataBuffer( dataSize, &(mDataProvider.GetData( bufferIndex )[0]) );
+    }
+    else
+    {
+      std::size_t dataSize = mDataProvider.GetDataSize( bufferIndex );
+      mGpuBuffer->UpdateDataBuffer( dataSize, &(mDataProvider.GetData( bufferIndex )[0]) );
+      mGpuBuffer->SetStride( mDataProvider.GetElementSize( bufferIndex ) );
+    }
+  }
+}
+
+void RenderPropertyBuffer::BindBuffer( Context& context, Program& progam )
+{
+  mGpuBuffer->Bind();
+}
+
+void RenderPropertyBuffer::EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program )
+{
+
+  // Check if attribute locations are cached already
+  if( mAttributesLocation.Size() == 0 )
+  {
+    UpdateAttributeLocations( context, bufferIndex, program );
+  }
+
+  unsigned int attributeCount = mDataProvider.GetAttributeCount( bufferIndex );
+  DALI_ASSERT_DEBUG( attributeCount == mAttributesLocation.Size() && "Incorrect number of attributes!" );
+
+  GLsizei elementSize = mDataProvider.GetElementSize( bufferIndex );
+
+  for( unsigned int i = 0; i < attributeCount; ++i )
+  {
+    GLint attributeLocation = mAttributesLocation[i];
+    if( attributeLocation != -1 )
+    {
+      context.EnableVertexAttributeArray( attributeLocation );
+
+      GLint attributeSize = mDataProvider.GetAttributeSize( bufferIndex, i );
+      size_t attributeOffset = mDataProvider.GetAttributeOffset( bufferIndex, i );
+
+      // TODO: MESH_REWORK  Matrices need multiple calls to this function
+      context.VertexAttribPointer( attributeLocation,
+                                   attributeSize  / sizeof(float), // TODO: MESH_REWORK get the correct type
+                                   GL_FLOAT, // TODO: MESH_REWORK get the correct type
+                                   GL_FALSE,  // Not normalized
+                                   elementSize,
+                                   (void*)attributeOffset );
+    }
+  }
+}
+
+void RenderPropertyBuffer::DisableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program )
+{
+  unsigned int attributeCount = mDataProvider.GetAttributeCount( bufferIndex );
+  for( unsigned int i = 0; i < attributeCount; ++i )
+  {
+    GLint attributeLocation = mAttributesLocation[i];
+    if( attributeLocation != -1 )
+    {
+      context.DisableVertexAttributeArray( attributeLocation );
+    }
+  }
+}
+
+void RenderPropertyBuffer::UpdateAttributeLocations( Context& context, BufferIndex bufferIndex, Program& program )
+{
+  unsigned int attributeCount = mDataProvider.GetAttributeCount( bufferIndex );
+  mAttributesLocation.Resize( attributeCount );
+
+  for( unsigned int i = 0; i < attributeCount; ++i )
+  {
+    const std::string& attributeName = mDataProvider.GetAttributeName( bufferIndex, i );
+    unsigned int index = program.RegisterCustomAttribute( attributeName );
+    GLint attributeLocation = program.GetCustomAttributeLocation( index );
+
+    if( -1 == attributeLocation )
+    {
+      DALI_LOG_WARNING( "Attribute not found in the shader: %s\n", attributeName.c_str() );
+    }
+    mAttributesLocation[i] = attributeLocation;
+  }
+}
+
+} // namespace SceneGraph
+} // namespace Internal
+} // namespace Dali
diff --git a/dali/internal/render/renderers/render-renderer-property-buffer.h b/dali/internal/render/renderers/render-renderer-property-buffer.h
new file mode 100644 (file)
index 0000000..b4d170d
--- /dev/null
@@ -0,0 +1,112 @@
+#ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_H
+#define DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_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.
+ */
+
+#include <dali/integration-api/gl-abstraction.h>
+#include <dali/internal/common/buffer-index.h>
+#include <dali/internal/common/owner-container.h>
+#include <dali/internal/common/owner-pointer.h>
+#include <dali/internal/render/data-providers/property-buffer-data-provider.h>
+
+namespace Dali
+{
+namespace Internal
+{
+class Context;
+class Program;
+class GpuBuffer;
+
+namespace SceneGraph
+{
+class NewRenderer;
+/**
+ * This class encapsulates the GPU buffers. It is used to upload vertex data
+ * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
+ * bindings
+ */
+class RenderPropertyBuffer
+{
+public:
+  typedef OwnerContainer< GpuBuffer* > GpuBuffers;
+
+  /**
+   * Constructor. Creates a render geometry object with no GPU buffers.
+   * @param[in] propertyBufferDataProvider The property-buffer  data provider (to fetch geometry from)
+   */
+  RenderPropertyBuffer( const PropertyBufferDataProvider& propertyBufferDataProvider, bool isIndexBuffer );
+
+  /**
+   * Destructor
+   */
+  ~RenderPropertyBuffer();
+
+  /**
+   * Perform the upload of the buffer
+   * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
+   */
+  void DoUpload( Context& context, BufferIndex bufferIndex );
+
+  /**
+   * Bind the geometry buffers
+   * @param[in] context The GL context
+   * @param[in] program The shader program to query for attribute locations
+   */
+  void BindBuffer( Context& context, Program& progam );
+
+  /**
+   * Enable the vertex attributes for each vertex buffer from the corresponding
+   * shader program.
+   * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
+   * @param[in] program The shader program to query for attribute locations
+   */
+  void EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program );
+
+  /**
+   * Disable the vertex attributes for each vertex buffer from the corresponding
+   * shader program.
+   * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
+   * @param[in] program The shader program to query for attribute locations
+   */
+  void DisableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program );
+
+private: // implementation
+
+  /**
+   * Update attribute locations
+   * @param[in] context The GL context
+   * @param[in] bufferIndex The current buffer index
+   * @param[in] program The shader program to query for attribute locations
+   */
+  void UpdateAttributeLocations( Context& context, BufferIndex bufferIndex, Program& program );
+
+private:
+  const PropertyBufferDataProvider& mDataProvider;  ///< Data provider used by this property buffer
+  Vector<GLint> mAttributesLocation;                ///< Location of the attributes for the property buffer in this renderer.
+  GpuBuffer* mGpuBuffer;                            ///< Pointer to the GpuBuffer associated with this RenderPropertyBuffer
+
+  bool mIsIndexBuffer;
+};
+
+} // namespace SceneGraph
+} // namespace Internal
+} // namespace Dali
+
+#endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_H
index d17b3e0611f1951e7cb678032ba2e416a80adea6..107c003f6e7e0a165ee7252a5519d212ec84866a 100644 (file)
@@ -41,12 +41,10 @@ namespace SceneGraph
  */
 class NewRenderer : public Renderer
 {
-private:
-  struct UniformIndexMap;
-
 public:
   typedef Integration::ResourceId ResourceId;
 
+public:
   /**
    * Create a new renderer instance
    * @param[in] nodeDataProvider The node data provider
@@ -121,6 +119,8 @@ public: // Implementation of GlResourceOwner
   virtual void GlCleanup();
 
 private:
+  struct UniformIndexMap;
+
   /**
    * Set the uniforms from properties according to the uniform map
    * @param[in] program The shader program on which to set the uniforms.
index f405202eb128dbde43cc3aa32224cbfef6a836c8..4f22dec703af13df0c7b0a843606a68d1b0e1df0 100644 (file)
@@ -51,52 +51,115 @@ PropertyBuffer::~PropertyBuffer()
 {
 }
 
-std::size_t PropertyBuffer::GetDataSize( BufferIndex bufferIndex ) const
+void PropertyBuffer::SetFormat( PropertyBufferMetadata::Format* format )
 {
-  DALI_ASSERT_DEBUG( mFormat && "Format must have been set!" );
+  mFormat = format;
+}
 
-  // @todo MESH_REWORK mData should be double buffered?
-  return mFormat->components.back().accumulatedSize * mSize;
+//TODO:: MESH_REWORK  Remove this, should be a property
+void PropertyBuffer::SetSize( unsigned int size )
+{
+  mSize = size;
 }
 
-std::size_t PropertyBuffer::GetElementSize( BufferIndex bufferIndex ) const
+void PropertyBuffer::SetData( PropertyBufferDataProvider::BufferType* data )
 {
-  DALI_ASSERT_DEBUG( mFormat && "Format must have been set!" );
+  mBufferData = data;
 
-  // @todo MESH_REWORK mData should be double buffered?
-  return mFormat->GetElementSize();
+  // TODO: MESH_REWORK FIX THIS, should go through aging or message
+  mRenderBufferData = data;
 }
 
-void PropertyBuffer::SetFormat( PropertyBufferMetadata::Format* format )
+void PropertyBuffer::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
 {
-  mFormat = format;
 }
 
-//TODO:: MESH_REWORK  Remove this, should be a property
-void PropertyBuffer::SetSize( unsigned int size )
+void PropertyBuffer::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
 {
-  mSize = size;
 }
 
-void PropertyBuffer::SetData( BufferType* data )
+bool PropertyBuffer::HasDataChanged( BufferIndex bufferIndex ) const
 {
-  mBufferData = data;
+  //TODO: MESH_REWORK fix this
+  DALI_ASSERT_DEBUG(false && "FIX THIS");
+  return true;
 }
 
-const void* PropertyBuffer::GetData( BufferIndex bufferIndex ) const
+unsigned int PropertyBuffer::GetAttributeCount( BufferIndex bufferIndex ) const
 {
-  // @todo MESH_REWORK mData should be double buffered
-  return reinterpret_cast< const void* >(&(*mBufferData.Get())[0]);
+  DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
+  return mFormat->components.size();
 }
 
-void PropertyBuffer::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
+const std::string& PropertyBuffer::GetAttributeName( BufferIndex bufferIndex, unsigned int index ) const
 {
+  DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
+  return mFormat->components[index].name;
 }
 
-void PropertyBuffer::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
+size_t PropertyBuffer::GetAttributeSize( BufferIndex bufferIndex, unsigned int index ) const
+{
+  DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
+
+  size_t size = mFormat->components[index].accumulatedSize;
+
+  if ( index > 0 )
+  {
+    size -= mFormat->components[index - 1].accumulatedSize;
+  }
+
+  return size;
+}
+
+size_t PropertyBuffer::GetAttributeOffset( BufferIndex bufferIndex, unsigned int index ) const
+{
+  DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
+
+  size_t offset = 0;
+
+  if ( index > 0 )
+  {
+    offset = mFormat->components[index - 1].accumulatedSize;
+  }
+
+  return offset;
+}
+
+const PropertyBufferDataProvider::BufferType& PropertyBuffer::GetData( BufferIndex bufferIndex ) const
+{
+  DALI_ASSERT_DEBUG( mRenderBufferData && "Should have some data.");
+
+  //TODO: MESH_REWORK Should check the correct buffer index
+  return *mRenderBufferData;
+}
+
+std::size_t PropertyBuffer::GetDataSize( BufferIndex bufferIndex ) const
+{
+  DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
+
+  //TODO: MESH_REWORK mSize should be double buffered
+  return mFormat->GetElementSize() * mSize;
+}
+
+std::size_t PropertyBuffer::GetElementSize( BufferIndex bufferIndex ) const
 {
+  return mFormat->GetElementSize();
 }
 
+unsigned int PropertyBuffer::GetElementCount( BufferIndex bufferIndex ) const
+{
+  return mSize;
+}
+
+unsigned int PropertyBuffer::GetGpuBufferId( BufferIndex bufferIndex ) const
+{
+  //TODO: MESH_REWORK fix this
+  DALI_ASSERT_DEBUG(false && "FIX THIS");
+
+  return 0;
+}
+
+
 } // namespace SceneGraph
 } // namespace Internal
 } // namespace Dali
index 06e0781ad87b13831e145bf8d9a7ae092f51f586..96d84669627ce2d564124cb6b1fdb756c4557a22 100644 (file)
@@ -20,6 +20,7 @@
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/event/common/event-thread-services.h>
+#include <dali/internal/render/data-providers/property-buffer-data-provider.h>
 
 namespace Dali
 {
@@ -66,15 +67,10 @@ struct Format
 
 } // PropertyBufferMetadata
 
-class PropertyBuffer : public PropertyOwner
+class PropertyBuffer : public PropertyOwner, public PropertyBufferDataProvider
 {
 public:
 
-  /**
-   * Type for the data contained in the buffer
-   */
-  typedef Dali::Vector< char > BufferType;
-
   /**
    * Constructor
    */
@@ -85,18 +81,6 @@ public:
    */
   virtual ~PropertyBuffer();
 
-  /**
-   * Get the size of the property buffer in bytes
-   * @return the size in bytes
-   */
-  std::size_t GetDataSize( BufferIndex bufferIndex ) const;
-
-  /**
-   * Get the size of an element of the buffer in bytes
-   * @return the element size in bytes
-   */
-  std::size_t GetElementSize( BufferIndex bufferIndex ) const;
-
   /**
    * Set the format of the buffer
    * @param[in] format The format for the PropertyBuffer
@@ -107,17 +91,11 @@ public:
    * Set the data of the PropertyBuffer
    * @param[in] data The new data of the PropertyBuffer
    */
-  void SetData( BufferType* data );
+  void SetData( PropertyBufferDataProvider::BufferType* data );
 
   //TODO:: MESH_REWORK  Remove this, should be a property
   void SetSize( unsigned int size );
 
-  /**
-   * Get the property buffer data
-   * @return the property buffer's data array
-   */
-  const void* GetData( BufferIndex bufferIndex ) const;
-
   /**
    * Connect the object to the scene graph
    *
@@ -131,10 +109,62 @@ public:
    */
   void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
 
+public: // PropertyBufferDataProvider
+
+  /**
+   * @copydoc PropertyBufferDataProvider::HasDataChanged( BufferIndex bufferIndex )
+   */
+  virtual bool HasDataChanged( BufferIndex bufferIndex ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::HasDataChanged( BufferIndex bufferIndex )
+   */
+  virtual unsigned int GetAttributeCount( BufferIndex bufferIndex ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetAttributeName( BufferIndex bufferIndex, unsigned int index )
+   */
+  virtual const std::string& GetAttributeName( BufferIndex bufferIndex, unsigned int index ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetAttributeSize( BufferIndex bufferIndex, unsigned int index )
+   */
+  virtual size_t GetAttributeSize( BufferIndex bufferIndex, unsigned int index ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetAttributeOffset( BufferIndex bufferIndex, unsigned int index )
+   */
+  virtual size_t GetAttributeOffset( BufferIndex bufferIndex, unsigned int index ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetData( BufferIndex bufferIndex )
+   */
+  virtual const PropertyBufferDataProvider::BufferType& GetData( BufferIndex bufferIndex ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetDataSize( BufferIndex bufferIndex )
+   */
+  virtual size_t GetDataSize( BufferIndex bufferIndex ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetElementSize( BufferIndex bufferIndex )
+   */
+  virtual size_t GetElementSize( BufferIndex bufferIndex ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetElementCount( BufferIndex bufferIndex )
+   */
+  virtual unsigned int GetElementCount( BufferIndex bufferIndex ) const;
+
+  /**
+   * @copydoc PropertyBufferDataProvider::GetGpuBufferId
+   */
+  virtual unsigned int GetGpuBufferId( BufferIndex bufferIndex ) const;
+
 private:
   OwnerPointer<PropertyBufferMetadata::Format> mFormat; ///< Format of the buffer
-  OwnerPointer<BufferType> mBufferData; ///< Data
-  BufferType* mRenderBufferData;
+  OwnerPointer<PropertyBufferDataProvider::BufferType> mBufferData; ///< Data
+  PropertyBufferDataProvider::BufferType* mRenderBufferData;
 
   //TODO: MESH_REWORK should be double buffered property
   unsigned int mSize; ///< Size of the buffer
index c951fb72e6fed527b9748e3719fe23f8e1f39bb5..e4cf29d59d1b9bacb724f18d787471107850e528 100644 (file)
@@ -54,20 +54,18 @@ void Geometry::RemoveVertexBuffer( const PropertyBuffer* vertexBuffer )
   DALI_ASSERT_DEBUG( NULL != vertexBuffer );
 
   // Find the object and destroy it
-  for ( VertexBuffers::Iterator iter = mVertexBuffers.Begin(); iter != mVertexBuffers.End(); ++iter )
+  VertexBuffers::Iterator match = std::find( mVertexBuffers.Begin(),
+                                             mVertexBuffers.End(),
+                                             vertexBuffer );
+
+  DALI_ASSERT_DEBUG( mVertexBuffers.End() != match );
+  if( mVertexBuffers.End() != match )
   {
-    const PropertyBuffer* current = *iter;
-    if ( current == vertexBuffer )
-    {
-      PropertyBuffer* theVertexBuffer = const_cast<PropertyBuffer*>(vertexBuffer);
-      theVertexBuffer->RemoveUniformMapObserver(*this);
-      mVertexBuffers.Erase( iter );
-      mConnectionObservers.ConnectionsChanged(*this);
-      return;
-    }
+    PropertyBuffer* theVertexBuffer = const_cast<PropertyBuffer*>(vertexBuffer);
+    theVertexBuffer->RemoveUniformMapObserver(*this);
+    mVertexBuffers.Erase( match );
+    mConnectionObservers.ConnectionsChanged(*this);
   }
-
-  DALI_ASSERT_DEBUG(false);
 }
 
 void Geometry::SetIndexBuffer( const PropertyBuffer* indexBuffer )
index 841fcf9af24bb7a6f91b65c2e5f99eff9a8ad7ea..ec076502bc24fec9a440a8bd89ec696c4d9ccc5c 100644 (file)
@@ -217,7 +217,8 @@ void RendererAttachment::DoPrepareRender( BufferIndex updateBufferIndex )
            iter != end ;
            ++iter )
       {
-        AddMappings( localMap, (*iter)->GetUniformMap() );
+        const SceneGraph::PropertyBuffer* vertexBuffer = static_cast<const SceneGraph::PropertyBuffer*>( *iter );
+        AddMappings( localMap, vertexBuffer->GetUniformMap() );
       }
 
       mUniformMapChanged[updateBufferIndex] = true;