$(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 \
+++ /dev/null
-#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
#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
{
{
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.
--- /dev/null
+#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
const MaterialDataProvider& materialDataProvider,
const UniformMapDataProvider& uniformMapDataProvider,
Shader& shader,
- const PropertyBuffer* indexBuffer,
+ const PropertyBufferDataProvider* indexBuffer,
const VertexBuffers& vertexBuffers,
const Samplers& samplers )
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;
}
#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
class RenderDataProvider
{
public:
- typedef Dali::Vector< const PropertyBuffer* > VertexBuffers;
+ typedef Dali::Vector< const PropertyBufferDataProvider* > VertexBuffers;
typedef Dali::Vector< const SamplerDataProvider* > Samplers;
/**
const MaterialDataProvider& mMaterialDataProvider,
const UniformMapDataProvider& mUniformMapDataProvider,
Shader& mShader,
- const PropertyBuffer* mIndexBuffer,
+ const PropertyBufferDataProvider* mIndexBuffer,
const VertexBuffers& mVertexBuffers,
const Samplers& mSamplers );
* 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
const MaterialDataProvider* mMaterialDataProvider;
const UniformMapDataProvider* mUniformMapDataProvider;
Shader* mShader;
- const PropertyBuffer* mIndexBuffer;
+ const PropertyBufferDataProvider* mIndexBuffer;
VertexBuffers mVertexBuffers;
Samplers mSamplers;
};
* 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>
{
RenderGeometry::RenderGeometry()
-: mDataNeedsUploading( true )
+: mDataNeedsUploading( true ),
+ mShaderChanged( true )
{
}
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(
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()
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 );
}
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;
}
* 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
{
class RenderGeometry
{
public:
- typedef OwnerContainer< GpuBuffer* > GpuBuffers;
/**
* Constructor. Creates a render geometry object with no GPU buffers.
/**
* 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
const RenderDataProvider* dataProviders );
private:
- GpuBuffers mVertexBuffers;
- OwnerPointer< GpuBuffer > mIndexBuffer;
+ // PropertyBuffers
+ OwnerPointer< RenderPropertyBuffer > mIndexBuffer;
+ OwnerContainer< RenderPropertyBuffer* > mVertexBuffers;
+ // Booleans
bool mDataNeedsUploading;
+ bool mShaderChanged;
};
} // namespace SceneGraph
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#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
--- /dev/null
+#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
*/
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
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.
{
}
-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
#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
{
} // 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
*/
*/
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
* 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
*
*/
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
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 )
iter != end ;
++iter )
{
- AddMappings( localMap, (*iter)->GetUniformMap() );
+ const SceneGraph::PropertyBuffer* vertexBuffer = static_cast<const SceneGraph::PropertyBuffer*>( *iter );
+ AddMappings( localMap, vertexBuffer->GetUniformMap() );
}
mUniformMapChanged[updateBufferIndex] = true;