From d1a5064d7469bd814913ad303fd676f21bdfbae2 Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Mon, 19 Oct 2015 09:53:02 +0100 Subject: [PATCH] Remove scene graph property buffer -Removed scene graph copy of PropertyBuffer -Added render thread copy of PropertyBuffer -Send message from event to render thread when data, size or format changes -PropertyBuffers can now be shared between multiple geometries and it is guaranteed that there is only going to be one copy of the buffer in gpu memory Change-Id: I67ccefb456a80ba833f870568ba7a0627d3b0182 --- .../src/dali-devel/utc-Dali-PropertyBuffer.cpp | 210 +----------------- .../src/dali-devel/utc-Dali-Renderer.cpp | 146 +----------- dali/devel-api/object/property-buffer.cpp | 5 +- dali/devel-api/object/property-buffer.h | 16 +- dali/integration-api/profiling.cpp | 3 +- .../internal/event/common/property-buffer-impl.cpp | 247 ++------------------- dali/internal/event/common/property-buffer-impl.h | 137 +----------- dali/internal/event/rendering/geometry-impl.cpp | 48 +--- dali/internal/event/rendering/geometry-impl.h | 7 +- dali/internal/file.list | 3 +- dali/internal/render/common/render-manager.cpp | 47 +++- dali/internal/render/common/render-manager.h | 43 +++- dali/internal/render/gl-resources/gpu-buffer.cpp | 61 ++--- dali/internal/render/gl-resources/gpu-buffer.h | 22 +- dali/internal/render/renderers/render-geometry.cpp | 68 +++--- dali/internal/render/renderers/render-geometry.h | 25 +-- .../render/renderers/render-image-renderer.cpp | 12 +- .../render/renderers/render-new-renderer.cpp | 1 + .../render/renderers/render-new-renderer.h | 2 + .../render/renderers/render-property-buffer.cpp | 218 ++++++++++++++++++ .../render/renderers/render-property-buffer.h | 176 +++++++++++++++ .../renderers/render-renderer-property-buffer.cpp | 245 -------------------- .../renderers/render-renderer-property-buffer.h | 122 ---------- dali/internal/update/common/discard-queue.cpp | 16 -- dali/internal/update/common/discard-queue.h | 10 - .../update/common/scene-graph-property-buffer.cpp | 146 ------------ .../update/common/scene-graph-property-buffer.h | 227 ------------------- .../controllers/render-message-dispatcher.cpp | 10 +- .../update/controllers/render-message-dispatcher.h | 8 +- dali/internal/update/manager/update-manager.cpp | 66 +++++- dali/internal/update/manager/update-manager.h | 95 ++++++++ .../update/rendering/scene-graph-geometry.cpp | 166 ++------------ .../update/rendering/scene-graph-geometry.h | 44 ++-- .../update/rendering/scene-graph-renderer.cpp | 16 +- .../update/rendering/scene-graph-renderer.h | 1 - 35 files changed, 816 insertions(+), 1853 deletions(-) create mode 100644 dali/internal/render/renderers/render-property-buffer.cpp create mode 100644 dali/internal/render/renderers/render-property-buffer.h delete mode 100644 dali/internal/render/renderers/render-renderer-property-buffer.cpp delete mode 100644 dali/internal/render/renderers/render-renderer-property-buffer.h delete mode 100644 dali/internal/update/common/scene-graph-property-buffer.cpp delete mode 100644 dali/internal/update/common/scene-graph-property-buffer.h diff --git a/automated-tests/src/dali-devel/utc-Dali-PropertyBuffer.cpp b/automated-tests/src/dali-devel/utc-Dali-PropertyBuffer.cpp index 55b3d10..89014df 100644 --- a/automated-tests/src/dali-devel/utc-Dali-PropertyBuffer.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-PropertyBuffer.cpp @@ -119,210 +119,6 @@ int UtcDaliPropertyBufferAssignmentOperator(void) END_TEST; } -int UtcDaliPropertyBufferConstraint01(void) -{ - TestApplication application; - - tet_infoline("Test that a non-uniform propertyBuffer property can be constrained"); - - Shader shader = Shader::New("VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - PropertyBuffer propertyBuffer = CreatePropertyBuffer(); - Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), initialColor, TEST_LOCATION ); - - // Apply constraint - Constraint constraint = Constraint::New( propertyBuffer, colorIndex, TestConstraintNoBlue ); - constraint.Apply(); - application.SendNotification(); - application.Render(0); - - // Expect no blue component in either buffer - yellow - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), Color::YELLOW, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), Color::YELLOW, TEST_LOCATION ); - - propertyBuffer.RemoveConstraints(); - propertyBuffer.SetProperty(colorIndex, Color::WHITE ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), Color::WHITE, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliPropertyBufferConstraint02(void) -{ - TestApplication application; - - tet_infoline("Test that a uniform map propertyBuffer property can be constrained"); - - Shader shader = Shader::New( "VertexSource", "FragmentSource" ); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - PropertyBuffer propertyBuffer = CreatePropertyBuffer(); - Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); - - application.SendNotification(); - application.Render(0); - - Vector4 actualValue(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION ); - - // Apply constraint - Constraint constraint = Constraint::New( propertyBuffer, colorIndex, TestConstraintNoBlue ); - constraint.Apply(); - application.SendNotification(); - application.Render(0); - - // Expect no blue component in either buffer - yellow - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - - application.Render(0); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - - propertyBuffer.RemoveConstraints(); - propertyBuffer.SetProperty(colorIndex, Color::WHITE ); - application.SendNotification(); - application.Render(0); - - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION ); - - END_TEST; -} - - - -int UtcDaliPropertyBufferAnimatedProperty01(void) -{ - TestApplication application; - - tet_infoline("Test that a non-uniform propertyBuffer property can be animated"); - - Shader shader = Shader::New("VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - PropertyBuffer propertyBuffer = CreatePropertyBuffer(); - Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor ); - - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), initialColor, TEST_LOCATION ); - - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, initialColor); - keyFrames.Add(1.0f, Color::TRANSPARENT); - animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames ); - animation.Play(); - - application.SendNotification(); - application.Render(500); - - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION ); - - application.Render(500); - - DALI_TEST_EQUALS( propertyBuffer.GetProperty(colorIndex), Color::TRANSPARENT, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliPropertyBufferAnimatedProperty02(void) -{ - TestApplication application; - - tet_infoline("Test that a uniform map propertyBuffer property can be animated"); - - Shader shader = Shader::New("VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - PropertyBuffer propertyBuffer = CreatePropertyBuffer(); - Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); - - application.SendNotification(); - application.Render(0); - - Vector4 actualValue(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION ); - - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, initialColor); - keyFrames.Add(1.0f, Color::TRANSPARENT); - animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames ); - animation.Play(); - - application.SendNotification(); - application.Render(500); - - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION ); - - application.Render(500); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION ); - - END_TEST; -} - int UtcDaliPropertyBufferSetData01(void) { TestApplication application; @@ -474,16 +270,16 @@ int UtcDaliPropertyBufferSetGetSize02(void) int size = 5u; PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, size ); - DALI_TEST_EQUALS( propertyBuffer.GetProperty(PropertyBuffer::Property::SIZE), size, TEST_LOCATION ); + DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION ); DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION ); size += 3u; propertyBuffer.SetSize( size ); - DALI_TEST_EQUALS( propertyBuffer.GetProperty(PropertyBuffer::Property::SIZE), size, TEST_LOCATION ); + DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION ); DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION ); size += 2u; - propertyBuffer.SetProperty(PropertyBuffer::Property::SIZE, size ); + propertyBuffer.SetSize( size ); DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION ); END_TEST; diff --git a/automated-tests/src/dali-devel/utc-Dali-Renderer.cpp b/automated-tests/src/dali-devel/utc-Dali-Renderer.cpp index ee82c5e..784762a 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Renderer.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Renderer.cpp @@ -479,9 +479,6 @@ int UtcDaliRendererUniformMapPrecendence01(void) geometry.RegisterProperty( "uFadeColor", Color::YELLOW ); - vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); application.SendNotification(); @@ -547,8 +544,6 @@ int UtcDaliRendererUniformMapPrecendence02(void) geometry.RegisterProperty( "uFadeColor", Color::YELLOW ); - vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); - TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -614,7 +609,7 @@ int UtcDaliRendererUniformMapPrecendence03(void) Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW ); - vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); + geometry.RegisterProperty( "uFadeColor", Color::BLACK ); TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -678,7 +673,7 @@ int UtcDaliRendererUniformMapPrecendence04(void) Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW ); - vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); + geometry.RegisterProperty( "uFadeColor", Color::BLACK ); TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -741,7 +736,7 @@ int UtcDaliRendererUniformMapPrecendence05(void) Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW ); - vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); + geometry.RegisterProperty( "uFadeColor", Color::BLACK ); TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -775,126 +770,6 @@ int UtcDaliRendererUniformMapPrecendence05(void) END_TEST; } -int UtcDaliRendererUniformMapPrecendence06(void) -{ - TestApplication application; - - tet_infoline("Test the uniform map precedence is applied properly"); - - Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - - Shader shader = Shader::New("VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - PropertyBuffer vertexBuffer = CreatePropertyBuffer(); - Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Don't add property / uniform map to renderer/actor/material/sampler/shader - - geometry.RegisterProperty( "uFadeColor", Color::YELLOW ); - - Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); - - - TestGlAbstraction& gl = application.GetGlAbstraction(); - - application.SendNotification(); - application.Render(0); - - // Expect that the geometry's fade color property is accessed - Vector4 actualValue(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - - // Animate vertex buffer's fade color property. Should be no change to uniform - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, Color::WHITE); - keyFrames.Add(1.0f, Color::TRANSPARENT); - animation.AnimateBetween( Property( vertexBuffer, vertexFadeColorIndex ), keyFrames ); - animation.Play(); - - application.SendNotification(); - application.Render(500); - - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - - application.Render(500); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliRendererUniformMapPrecendence07(void) -{ - TestApplication application; - - tet_infoline("Test the uniform map precedence is applied properly"); - - Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - - Shader shader = Shader::New("VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - PropertyBuffer vertexBuffer = CreatePropertyBuffer(); - Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - // Don't add property / uniform map to renderer/actor/material/sampler/shader/geometry - - Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); - - application.SendNotification(); - application.Render(0); - - // Expect that the vertex buffer's fade color property is accessed - Vector4 actualValue(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION ); - - // Animate vertex buffer's fade color property. Should change the uniform - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, Color::WHITE); - keyFrames.Add(1.0f, Color::TRANSPARENT); - animation.AnimateBetween( Property( vertexBuffer, vertexFadeColorIndex ), keyFrames ); - animation.Play(); - - application.SendNotification(); - application.Render(500); - - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::WHITE*0.5f, TEST_LOCATION ); - - application.Render(500); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION ); - - END_TEST; -} - - int UtcDaliRendererUniformMapMultipleUniforms01(void) { TestApplication application; @@ -923,8 +798,6 @@ int UtcDaliRendererUniformMapMultipleUniforms01(void) material.RegisterProperty( "uUniform3", Color::BLUE ); shader.RegisterProperty( "uUniform4", Color::MAGENTA ); geometry.RegisterProperty( "uUniform5", Color::YELLOW ); - vertexBuffer.RegisterProperty( "uUniform6", Color::BLACK ); - TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -952,11 +825,6 @@ int UtcDaliRendererUniformMapMultipleUniforms01(void) DALI_TEST_CHECK( gl.GetUniformValue( "uUniform5", uniform6Value ) ); DALI_TEST_EQUALS( uniform6Value, Color::YELLOW, TEST_LOCATION ); - Vector4 uniform7Value(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uUniform6", uniform7Value ) ); - DALI_TEST_EQUALS( uniform7Value, Color::BLACK, TEST_LOCATION ); - - END_TEST; } @@ -999,10 +867,6 @@ int UtcDaliRendererUniformMapMultipleUniforms02(void) Property::Value value6(Matrix::IDENTITY); geometry.RegisterProperty( "uAWorldMatrix", value6 ); - Property::Value value7(7); - vertexBuffer.RegisterProperty( "uAnotherFadeColor", value7 ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); application.SendNotification(); @@ -1029,9 +893,5 @@ int UtcDaliRendererUniformMapMultipleUniforms02(void) DALI_TEST_CHECK( gl.GetUniformValue( "uAWorldMatrix", uniform6Value ) ); DALI_TEST_EQUALS( uniform6Value, value6.Get(), TEST_LOCATION ); - int uniform7Value = 0; - DALI_TEST_CHECK( gl.GetUniformValue( "uAnotherFadeColor", uniform7Value ) ); - DALI_TEST_EQUALS( uniform7Value, value7.Get(), TEST_LOCATION ); - END_TEST; } diff --git a/dali/devel-api/object/property-buffer.cpp b/dali/devel-api/object/property-buffer.cpp index 8ee2830..4b8b4e4 100644 --- a/dali/devel-api/object/property-buffer.cpp +++ b/dali/devel-api/object/property-buffer.cpp @@ -20,7 +20,6 @@ // INTERNAL INCLUDES #include // Dali::Property::Map -#include // Dali::Internal::ObjectHelper #include // Dali::Internal::PropertyBuffer namespace Dali @@ -45,7 +44,7 @@ PropertyBuffer::~PropertyBuffer() } PropertyBuffer::PropertyBuffer( const PropertyBuffer& handle ) -: Handle( handle ) +: BaseHandle( handle ) { } @@ -76,7 +75,7 @@ void PropertyBuffer::SetData( const void* data ) } PropertyBuffer::PropertyBuffer( Internal::PropertyBuffer* pointer ) -: Handle( pointer ) +: BaseHandle( pointer ) { } diff --git a/dali/devel-api/object/property-buffer.h b/dali/devel-api/object/property-buffer.h index d3544ee..350c1ce 100644 --- a/dali/devel-api/object/property-buffer.h +++ b/dali/devel-api/object/property-buffer.h @@ -24,8 +24,6 @@ // INTERNAL INCLUDES #include // Dali::Handle -#include // Dali::Property::Index -#include // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX #include // Dali::Property::Map namespace Dali @@ -70,23 +68,11 @@ class PropertyBuffer; * texturedQuadGeometry.SetIndexBuffer( indices ); * */ -class DALI_IMPORT_API PropertyBuffer : public Handle +class DALI_IMPORT_API PropertyBuffer : public BaseHandle { public: /** - * @brief An enumeration of properties belonging to the PropertyBuffer class. - */ - struct Property - { - enum - { - SIZE = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "size", type INTEGER - BUFFER_FORMAT, ///< name "buffer-format", type MAP - }; - }; - - /** * @brief Create a PropertyBuffer * * Static property buffers use less memory. diff --git a/dali/integration-api/profiling.cpp b/dali/integration-api/profiling.cpp index 5158f74..d01d274 100644 --- a/dali/integration-api/profiling.cpp +++ b/dali/integration-api/profiling.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -140,7 +141,7 @@ const int GEOMETRY_MEMORY_SIZE( sizeof( Internal::SceneGraph::RenderGeometry) ); const int PROPERTY_BUFFER_MEMORY_SIZE( sizeof( Internal::PropertyBuffer ) + - sizeof( Internal::SceneGraph::PropertyBuffer ) ); + sizeof( Internal::Render::PropertyBuffer ) ); const int MATERIAL_MEMORY_SIZE( sizeof( Internal::Material ) + sizeof( Internal::SceneGraph::Material ) ); diff --git a/dali/internal/event/common/property-buffer-impl.cpp b/dali/internal/event/common/property-buffer-impl.cpp index 384e136..30f1ed5 100644 --- a/dali/internal/event/common/property-buffer-impl.cpp +++ b/dali/internal/event/common/property-buffer-impl.cpp @@ -22,12 +22,8 @@ #include // std::sort // INTERNAL INCLUDES -#include #include // Dali::Internal::PropertyBuffer - -#include // Dali::Internal::ObjectHelper -#include // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END -#include +#include #include namespace Dali @@ -35,30 +31,10 @@ namespace Dali namespace Internal { -using SceneGraph::PropertyBufferMetadata::Format; -using SceneGraph::PropertyBufferMetadata::Component; - namespace { /** - * |name |type |writable|animatable|constraint-input|enum for index-checking| - */ -DALI_PROPERTY_TABLE_BEGIN -DALI_PROPERTY( "size", INTEGER, true, false, true, Dali::PropertyBuffer::Property::SIZE ) -DALI_PROPERTY( "buffer-format", MAP, false, false, false, Dali::PropertyBuffer::Property::BUFFER_FORMAT ) -DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX ) - -const ObjectImplHelper PROPERTY_BUFFER_IMPL = { DEFAULT_PROPERTY_DETAILS }; - -BaseHandle Create() -{ - return Dali::BaseHandle(); -} - -TypeRegistration mType( typeid( Dali::PropertyBuffer ), typeid( Dali::Handle ), Create ); - -/** * Calculate the alignment requirements of a type * * This is used to calculate the memory alignment requirements of a type @@ -162,9 +138,7 @@ void PropertyBuffer::SetSize( std::size_t size ) SizeChanged(); - SceneGraph::SetSizeMessage( GetEventThreadServices(), - *mSceneObject, - mSize ); + SceneGraph::SetPropertyBufferSize(mEventThreadServices.GetUpdateManager(),*mRenderObject, mSize ); } std::size_t PropertyBuffer::GetSize() const @@ -181,14 +155,7 @@ void PropertyBuffer::SetData( const void* data ) const char* source = static_cast( data ); std::copy( source, source + mBuffer.Size(), &mBuffer[0] ); - SceneGraph::SetDataMessage( GetEventThreadServices(), - *mSceneObject, - new SceneGraph::PropertyBuffer::BufferType( mBuffer ) ); -} - -const SceneGraph::PropertyBuffer* PropertyBuffer::GetPropertyBufferSceneObject() const -{ - return mSceneObject; + SceneGraph::SetPropertyBufferData(mEventThreadServices.GetUpdateManager(),*mRenderObject,new Dali::Vector( mBuffer )); } void PropertyBuffer::SetFormat( Dali::Property::Map& format ) @@ -202,198 +169,31 @@ void PropertyBuffer::SetFormat( Dali::Property::Map& format ) FormatChanged(); } -unsigned int PropertyBuffer::GetDefaultPropertyCount() const +const Render::PropertyBuffer* PropertyBuffer::GetRenderObject() const { - return PROPERTY_BUFFER_IMPL.GetDefaultPropertyCount(); -} - -void PropertyBuffer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const -{ - PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndices( indices ); -} - -const char* PropertyBuffer::GetDefaultPropertyName(Property::Index index) const -{ - return PROPERTY_BUFFER_IMPL.GetDefaultPropertyName( index ); -} - -Property::Index PropertyBuffer::GetDefaultPropertyIndex( const std::string& name ) const -{ - return PROPERTY_BUFFER_IMPL.GetDefaultPropertyIndex( name ); -} - -bool PropertyBuffer::IsDefaultPropertyWritable( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.IsDefaultPropertyWritable( index ); -} - -bool PropertyBuffer::IsDefaultPropertyAnimatable( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAnimatable( index ); -} - -bool PropertyBuffer::IsDefaultPropertyAConstraintInput( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.IsDefaultPropertyAConstraintInput( index ); -} - -Property::Type PropertyBuffer::GetDefaultPropertyType( Property::Index index ) const -{ - return PROPERTY_BUFFER_IMPL.GetDefaultPropertyType( index ); -} - -void PropertyBuffer::SetDefaultProperty( Property::Index index, - const Property::Value& propertyValue ) -{ - switch( index ) - { - case Dali::PropertyBuffer::Property::SIZE: - { - SetSize( propertyValue.Get() ); - break; - } - case Dali::PropertyBuffer::Property::BUFFER_FORMAT: - { - DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" ); - break; - } - } -} - -void PropertyBuffer::SetSceneGraphProperty( Property::Index index, - const PropertyMetadata& entry, - const Property::Value& value ) -{ - PROPERTY_BUFFER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value ); -} - -Property::Value PropertyBuffer::GetDefaultProperty( Property::Index index ) const -{ - Property::Value value; - - switch( index ) - { - case Dali::PropertyBuffer::Property::SIZE: - { - value = static_cast( GetSize() ); - break; - } - case Dali::PropertyBuffer::Property::BUFFER_FORMAT: - { - DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" ); - break; - } - } - return value; -} - -const SceneGraph::PropertyOwner* PropertyBuffer::GetPropertyOwner() const -{ - return mSceneObject; -} - -const SceneGraph::PropertyOwner* PropertyBuffer::GetSceneObject() const -{ - return mSceneObject; -} - -const SceneGraph::PropertyBase* PropertyBuffer::GetSceneObjectAnimatableProperty( Property::Index index ) const -{ - DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" ); - const SceneGraph::PropertyBase* property = NULL; - - if( OnStage() ) - { - property = PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( - this, - &PropertyBuffer::FindAnimatableProperty, - &PropertyBuffer::FindCustomProperty, - index ); - - if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT ) - { - DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" ); - } - } - - return property; -} - -const PropertyInputImpl* PropertyBuffer::GetSceneObjectInputProperty( Property::Index index ) const -{ - const PropertyInputImpl* property = NULL; - - if( OnStage() ) - { - const SceneGraph::PropertyBase* baseProperty = - PROPERTY_BUFFER_IMPL.GetRegisteredSceneGraphProperty( this, - &PropertyBuffer::FindAnimatableProperty, - &PropertyBuffer::FindCustomProperty, - index ); - property = static_cast( baseProperty ); - - if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT ) - { - if( index == Dali::PropertyBuffer::Property::SIZE ) - { - // @todo MESH_REWORK - DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" ); - } - } - } - - return property; -} - -int PropertyBuffer::GetPropertyComponentIndex( Property::Index index ) const -{ - return Property::INVALID_COMPONENT_INDEX; -} - -bool PropertyBuffer::OnStage() const -{ - return mOnStage; -} - -void PropertyBuffer::Connect() -{ - mOnStage = true; -} - -void PropertyBuffer::Disconnect() -{ - mOnStage = false; + return mRenderObject; } PropertyBuffer::~PropertyBuffer() { - if( EventThreadServices::IsCoreRunning() ) + if( EventThreadServices::IsCoreRunning() && mRenderObject) { - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - RemoveMessage( updateManager, updateManager.GetPropertyBufferOwner(), *mSceneObject ); - - eventThreadServices.UnregisterObject( this ); + SceneGraph::RemovePropertyBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject ); } } PropertyBuffer::PropertyBuffer() -: mSceneObject( NULL ), - mBufferFormat( NULL ), - mSize( 0 ), - mOnStage( false ) +:mEventThreadServices( *Stage::GetCurrent() ) +,mRenderObject(NULL) +,mBufferFormat( NULL ) +,mSize( 0 ) { } void PropertyBuffer::Initialize() { - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - - mSceneObject = new SceneGraph::PropertyBuffer(); - AddMessage( updateManager, updateManager.GetPropertyBufferOwner(), *mSceneObject ); - - eventThreadServices.RegisterObject( this ); + mRenderObject = new Render::PropertyBuffer(); + SceneGraph::AddPropertyBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject ); } void PropertyBuffer::FormatChanged() @@ -402,8 +202,8 @@ void PropertyBuffer::FormatChanged() // Create the format DALI_ASSERT_DEBUG( mBufferFormat == NULL && "PropertyFormat should not be set yet" ); - Format* bufferFormat = new Format(); - bufferFormat->components.resize( numComponents ); + Render::PropertyBuffer::Format* format = new Render::PropertyBuffer::Format(); + format->components.resize( numComponents ); unsigned int currentAlignment = 0u; unsigned int maxAlignmentRequired = 0u; @@ -413,7 +213,7 @@ void PropertyBuffer::FormatChanged() StringValuePair component = mFormat.GetPair( i ); // Get the name - bufferFormat->components[i].name = component.first; + format->components[i].name = component.first; // enums are stored in the map as int Property::Type type = Property::Type( component.second.Get() ); @@ -430,9 +230,9 @@ void PropertyBuffer::FormatChanged() } // write to the format - bufferFormat->components[i].size = elementSize; - bufferFormat->components[i].offset = currentAlignment; - bufferFormat->components[i].type = type; + format->components[i].size = elementSize; + format->components[i].offset = currentAlignment; + format->components[i].type = type; // update offset currentAlignment += elementSize; @@ -456,14 +256,11 @@ void PropertyBuffer::FormatChanged() } // Set the format size - bufferFormat->size = currentAlignment; - - mBufferFormat = bufferFormat; + format->size = currentAlignment; - SceneGraph::SetFormatMessage( GetEventThreadServices(), - *mSceneObject, - bufferFormat ); + mBufferFormat = format; + SceneGraph::SetPropertyBufferFormat(mEventThreadServices.GetUpdateManager(), *mRenderObject, format ); if( mSize ) { SizeChanged(); diff --git a/dali/internal/event/common/property-buffer-impl.h b/dali/internal/event/common/property-buffer-impl.h index 3c08271..9148856 100644 --- a/dali/internal/event/common/property-buffer-impl.h +++ b/dali/internal/event/common/property-buffer-impl.h @@ -18,32 +18,19 @@ * */ -// EXTERNAL INCLUDES -#include // std::pair - // INTERNAL INCLUDES #include // DALI_ASSERT_ALWAYS #include // Dali::IntrusivePtr +#include #include // Dali::Property::Map #include // Dali::PropertyBuffer -#include // Dali::Internal::Connectable -#include // Dali::Internal::ObjectConnector -#include // Dali::Internal::Object +#include +#include namespace Dali { namespace Internal { -namespace SceneGraph -{ -class PropertyBuffer; - -namespace PropertyBufferMetadata -{ -struct Format; -} // namespace PropertyBufferMetadata - -} // namespace SceneGraph class PropertyBuffer; typedef IntrusivePtr PropertyBufferPtr; @@ -52,7 +39,7 @@ typedef IntrusivePtr PropertyBufferPtr; * PropertyBuffer is an object that contains an array of structures of values that * can be accessed as properties. */ -class PropertyBuffer : public Object, public Connectable +class PropertyBuffer : public BaseObject { public: @@ -77,18 +64,6 @@ public: void SetData( const void* data ); /** - * @copydoc PropertBuffer::GetPropertyIndex() - */ - Dali::Property::Index GetPropertyIndex( const std::string name, std::size_t index ); - - /** - * @brief Get the propertyBuffer scene object - * - * @return the propertyBuffer scene object - */ - const SceneGraph::PropertyBuffer* GetPropertyBufferSceneObject() const; - - /** * @brief Set the format of the PropertyBuffer * * @pre Has not been set yet @@ -100,100 +75,11 @@ public: public: // Default property extensions from Object /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyCount() - */ - virtual unsigned int GetDefaultPropertyCount() const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices() - */ - virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyName() - */ - virtual const char* GetDefaultPropertyName(Property::Index index) const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex() - */ - virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const; - - /** - * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable() - */ - virtual bool IsDefaultPropertyWritable(Property::Index index) const; - - /** - * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable() - */ - virtual bool IsDefaultPropertyAnimatable(Property::Index index) const; - - /** - * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput() - */ - virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetDefaultPropertyType() - */ - virtual Property::Type GetDefaultPropertyType(Property::Index index) const; - - /** - * @copydoc Dali::Internal::Object::SetDefaultProperty() - */ - virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue); - - /** - * @copydoc Dali::Internal::Object::SetSceneGraphProperty() - */ - virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value ); - - /** - * @copydoc Dali::Internal::Object::GetDefaultProperty() - */ - virtual Property::Value GetDefaultProperty( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetPropertyOwner() - */ - virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const; - - /** - * @copydoc Dali::Internal::Object::GetSceneObject() - */ - virtual const SceneGraph::PropertyOwner* GetSceneObject() const; - - /** - * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty() - */ - virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty() - */ - virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const; - - /** - * @copydoc Dali::Internal::Object::GetPropertyComponentIndex() - */ - virtual int GetPropertyComponentIndex( Property::Index index ) const; - -public: // Functions from Connectable - /** - * @copydoc Dali::Internal::Connectable::OnStage() - */ - virtual bool OnStage() const; - - /** - * @copydoc Dali::Internal::Connectable::Contnect() - */ - virtual void Connect(); - - /** - * @copydoc Dali::Internal::Connectable::Disconnect() + * @brief Get the render thread side of the PropertyBuffer + * + * @return The render thread side of this PropertyBuffer */ - virtual void Disconnect(); + const Render::PropertyBuffer* GetRenderObject() const; protected: /** @@ -227,14 +113,13 @@ private: // unimplemented methods PropertyBuffer& operator=( const PropertyBuffer& ); private: // data - SceneGraph::PropertyBuffer* mSceneObject; ///< Update side object + EventThreadServices& mEventThreadServices; /// mBuffer; // Data of the property-buffer - - bool mOnStage; ///< Flag to know if the object is on stage }; /** diff --git a/dali/internal/event/rendering/geometry-impl.cpp b/dali/internal/event/rendering/geometry-impl.cpp index 5e90873..1759c79 100644 --- a/dali/internal/event/rendering/geometry-impl.cpp +++ b/dali/internal/event/rendering/geometry-impl.cpp @@ -63,37 +63,28 @@ GeometryPtr Geometry::New() std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer ) { - PropertyBufferConnector connector; - connector.Set( vertexBuffer, OnStage() ); - mVertexBufferConnectors.push_back( connector ); - - const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = static_cast( *vertexBuffer.GetSceneObject() ); - - SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer ); - - return mVertexBufferConnectors.size() - 1u; + mVertexBuffers.push_back( &vertexBuffer ); + SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, *vertexBuffer.GetRenderObject() ); + return mVertexBuffers.size() - 1u; } std::size_t Geometry::GetNumberOfVertexBuffers() const { - return mVertexBufferConnectors.size(); + return mVertexBuffers.size(); } void Geometry::RemoveVertexBuffer( std::size_t index ) { - const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = static_cast( *(mVertexBufferConnectors[index].Get()->GetSceneObject()) ); - SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer ); + const Render::PropertyBuffer& renderPropertyBuffer = static_cast( *(mVertexBuffers[index]->GetRenderObject()) ); + SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, renderPropertyBuffer ); - mVertexBufferConnectors.erase( mVertexBufferConnectors.begin() + index ); + mVertexBuffers.erase( mVertexBuffers.begin() + index ); } void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer ) { - mIndexBufferConnector.Set( indexBuffer, OnStage() ); - - const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = dynamic_cast( *indexBuffer.GetSceneObject() ); - - SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer ); + mIndexBuffer = &indexBuffer; + SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, *indexBuffer.GetRenderObject() ); } void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType ) @@ -344,33 +335,16 @@ bool Geometry::OnStage() const void Geometry::Connect() { mOnStage = true; - - PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end(); - for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin(); - it < end; - ++it ) - { - it->OnStageConnect(); - } - mIndexBufferConnector.OnStageConnect(); } void Geometry::Disconnect() { mOnStage = false; - - PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end(); - for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin(); - it < end; - ++it ) - { - it->OnStageDisconnect(); - } - mIndexBufferConnector.OnStageDisconnect(); } Geometry::Geometry() -: mSceneObject( NULL ), +: mIndexBuffer( NULL ), + mSceneObject( NULL ), mOnStage( false ) { } diff --git a/dali/internal/event/rendering/geometry-impl.h b/dali/internal/event/rendering/geometry-impl.h index 1ec3832..c8636fa 100644 --- a/dali/internal/event/rendering/geometry-impl.h +++ b/dali/internal/event/rendering/geometry-impl.h @@ -220,10 +220,9 @@ private: // unimplemented methods Geometry& operator=( const Geometry& ); private: // data - typedef ObjectConnector PropertyBufferConnector; - typedef std::vector< PropertyBufferConnector > PropertyBufferConnectorContainer; - PropertyBufferConnectorContainer mVertexBufferConnectors; ///< Vector of connectors that hold the property buffers used by this geometry - PropertyBufferConnector mIndexBufferConnector; ///< Connector that holds the index buffer used by this geometry + + std::vector mVertexBuffers; ///< Vector of intrusive pointers to vertex buffers + PropertyBufferPtr mIndexBuffer; ///< Intrusive pointer to index buffer SceneGraph::Geometry* mSceneObject; bool mOnStage; }; diff --git a/dali/internal/file.list b/dali/internal/file.list index 48e2c43..d5b4d8b 100644 --- a/dali/internal/file.list +++ b/dali/internal/file.list @@ -118,7 +118,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-new-renderer.cpp \ - $(internal_src_dir)/render/renderers/render-renderer-property-buffer.cpp \ + $(internal_src_dir)/render/renderers/render-property-buffer.cpp \ $(internal_src_dir)/render/renderers/render-image-renderer.cpp \ $(internal_src_dir)/render/renderers/render-renderer.cpp \ $(internal_src_dir)/render/shaders/custom-uniform.cpp \ @@ -137,7 +137,6 @@ internal_src_files = \ $(internal_src_dir)/update/common/property-owner.cpp \ $(internal_src_dir)/update/common/scene-graph-buffers.cpp \ $(internal_src_dir)/update/common/scene-graph-connection-change-propagator.cpp \ - $(internal_src_dir)/update/common/scene-graph-property-buffer.cpp \ $(internal_src_dir)/update/common/scene-graph-property-notification.cpp \ $(internal_src_dir)/update/common/uniform-map.cpp \ $(internal_src_dir)/update/controllers/render-message-dispatcher.cpp \ diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index 83c2546..c6aa9b9 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -78,6 +78,9 @@ typedef RenderGeometryOwnerContainer::Iterator RenderGeometryOwnerIter; typedef OwnerContainer< Render::Sampler* > SamplerOwnerContainer; typedef SamplerOwnerContainer::Iterator SamplerOwnerIter; +typedef OwnerContainer< Render::PropertyBuffer* > PropertyBufferOwnerContainer; +typedef PropertyBufferOwnerContainer::Iterator PropertyBufferOwnerIter; + typedef OwnerContainer< RenderTracker* > RenderTrackerContainer; typedef RenderTrackerContainer::Iterator RenderTrackerIter; typedef RenderTrackerContainer::ConstIterator RenderTrackerConstIter; @@ -159,6 +162,7 @@ struct RenderManager::Impl RendererOwnerContainer rendererContainer; ///< List of owned renderers SamplerOwnerContainer samplerContainer; ///< List of owned samplers + PropertyBufferOwnerContainer propertyBufferContainer; ///< List of owned property buffers RenderGeometryOwnerContainer renderGeometryContainer; ///< List of owned RenderGeometries bool renderersAdded; @@ -314,6 +318,43 @@ void RenderManager::SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMod sampler->SetWrapMode( (Dali::WrapMode::Type)uWrapMode, (Dali::WrapMode::Type)vWrapMode ); } +void RenderManager::AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer ) +{ + mImpl->propertyBufferContainer.PushBack( propertyBuffer ); +} + +void RenderManager::RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer ) +{ + DALI_ASSERT_DEBUG( NULL != propertyBuffer ); + + PropertyBufferOwnerContainer& propertyBuffers = mImpl->propertyBufferContainer; + + // Find the sampler + for ( PropertyBufferOwnerIter iter = propertyBuffers.Begin(); iter != propertyBuffers.End(); ++iter ) + { + if ( *iter == propertyBuffer ) + { + propertyBuffers.Erase( iter ); // Property buffer found; now destroy it + break; + } + } +} + +void RenderManager::SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format ) +{ + propertyBuffer->SetFormat( format ); +} + +void RenderManager::SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector* data) +{ + propertyBuffer->SetData( data ); +} + +void RenderManager::SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size ) +{ + propertyBuffer->SetSize( size ); +} + void RenderManager::AddGeometry( RenderGeometry* renderGeometry ) { mImpl->renderGeometryContainer.PushBack( renderGeometry ); @@ -336,7 +377,7 @@ void RenderManager::RemoveGeometry( RenderGeometry* renderGeometry ) } } -void RenderManager::AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage ) +void RenderManager::AddPropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer ) { DALI_ASSERT_DEBUG( NULL != renderGeometry ); @@ -347,13 +388,13 @@ void RenderManager::AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyB { if ( *iter == renderGeometry ) { - (*iter)->AddPropertyBuffer( propertyBuffer, target, usage ); + (*iter)->AddPropertyBuffer( propertyBuffer, isIndexBuffer ); break; } } } -void RenderManager::RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer ) +void RenderManager::RemovePropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer ) { DALI_ASSERT_DEBUG( NULL != renderGeometry ); diff --git a/dali/internal/render/common/render-manager.h b/dali/internal/render/common/render-manager.h index 91e2cc6..e04b252 100644 --- a/dali/internal/render/common/render-manager.h +++ b/dali/internal/render/common/render-manager.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace Dali { @@ -185,6 +186,20 @@ public: void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode ); /** + * Add a property buffer to the render manager. + * @param[in] propertyBuffer The property buffer to add. + * @post propertBuffer is owned by RenderManager + */ + void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer ); + + /** + * Remove a property buffer from the render manager. + * @param[in] propertyBuffer The property buffer to remove. + * @post propertyBuffer is destroyed. + */ + void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer ); + + /** * Add a geometry to the render manager. * @param[in] geometry The geometry to add. * @post geometry is owned by RenderManager @@ -202,10 +217,9 @@ public: * Adds a property buffer to a RenderGeometry from the render manager. * @param[in] geometry The geometry * @param[in] propertyBuffer The property buffer to remove. - * @param[in] target Specifies the type of the buffer - * @param[in] usage Specifies how will the buffer be used + * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer */ - void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage ); + void AddPropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer ); /** * Remove a property buffer from a RenderGeometry from the render manager. @@ -213,7 +227,28 @@ public: * @param[in] propertyBuffer The property buffer to remove. * @post property buffer is destroyed. */ - void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer ); + void RemovePropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer ); + + /** + * Sets the format of an existing property buffer + * @param[in] propertyBuffer The property buffer. + * @param[in] format The new format of the buffer + */ + void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format ); + + /** + * Sets the data of an existing property buffer + * @param[in] propertyBuffer The property buffer. + * @param[in] data The new data of the buffer + */ + void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector* data); + + /** + * Sets the size of an existing property buffer + * @param[in] propertyBuffer The property buffer. + * @param[in] size The new size of the buffer + */ + void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size ); /** * Adds a render tracker to the RenderManager. RenderManager takes ownership of the diff --git a/dali/internal/render/gl-resources/gpu-buffer.cpp b/dali/internal/render/gl-resources/gpu-buffer.cpp index f7bcad5..a18cbe2 100644 --- a/dali/internal/render/gl-resources/gpu-buffer.cpp +++ b/dali/internal/render/gl-resources/gpu-buffer.cpp @@ -89,13 +89,11 @@ inline GLenum ModeAsGlEnum( GpuBuffer::Usage type ) } -GpuBuffer::GpuBuffer( Context& context, Target target, Usage usage ) +GpuBuffer::GpuBuffer( Context& context ) : mContext( context ), mCapacity( 0 ), mSize( 0 ), mBufferId( 0 ), - mTarget( target ), - mUsage( usage ), mBufferCreated( false ) { } @@ -115,7 +113,7 @@ GpuBuffer::~GpuBuffer() * Creates or updates the buffer data depending on whether it * already exists or not. */ -void GpuBuffer::UpdateDataBuffer(GLsizeiptr size,const GLvoid *data) +void GpuBuffer::UpdateDataBuffer(GLsizeiptr size,const GLvoid *data, Usage usage) { DALI_ASSERT_DEBUG( size > 0 ); mSize = size; @@ -127,7 +125,7 @@ void GpuBuffer::UpdateDataBuffer(GLsizeiptr size,const GLvoid *data) } // make sure the buffer is bound, don't perform any checks because size may be zero - BindNoChecks(mBufferId); + mContext.BindArrayBuffer( mBufferId ); // if the buffer has already been created, just update the data providing it fits if (mBufferCreated ) @@ -135,49 +133,39 @@ void GpuBuffer::UpdateDataBuffer(GLsizeiptr size,const GLvoid *data) // if the data will fit in the existing buffer, just update it if (size <= mCapacity ) { - mContext.BufferSubData( TypeAsGlEnum(mTarget), 0, size, data ); + mContext.BufferSubData( GL_ARRAY_BUFFER, 0, size, data ); } else { // create a new buffer of the larger size, // gl should automatically deallocate the old buffer - mContext.BufferData( TypeAsGlEnum(mTarget), size, data, ModeAsGlEnum( mUsage ) ); + mContext.BufferData( GL_ARRAY_BUFFER, size, data, ModeAsGlEnum( usage ) ); mCapacity = size; } } else { // create the buffer - mContext.BufferData( TypeAsGlEnum(mTarget), size, data, ModeAsGlEnum( mUsage ) ); + mContext.BufferData( GL_ARRAY_BUFFER, size, data, ModeAsGlEnum( usage ) ); mBufferCreated = true; mCapacity = size; } - switch (mTarget) - { - case ARRAY_BUFFER: - { - mContext.BindArrayBuffer(0); - break; - } - case ELEMENT_ARRAY_BUFFER: - { - mContext.BindElementArrayBuffer(0); - break; - } - case TRANSFORM_FEEDBACK_BUFFER: - { - mContext.BindTransformFeedbackBuffer(0); - break; - } - } + mContext.BindArrayBuffer(0); } -void GpuBuffer::Bind() const +void GpuBuffer::Bind(Target target) const { DALI_ASSERT_DEBUG(mCapacity); - BindNoChecks(mBufferId); + if (target == ARRAY_BUFFER) + { + mContext.BindArrayBuffer(mBufferId); + } + else + { + mContext.BindElementArrayBuffer(mBufferId); + } } bool GpuBuffer::BufferIsValid() const @@ -194,23 +182,6 @@ void GpuBuffer::GlContextDestroyed() mBufferCreated = false; } -void GpuBuffer::BindNoChecks(GLuint bufferId) const -{ - // context currently only supports two targets, element and array - // and it caches both of them (as in it won't bind them if the - // buffer id is already bound). - - if (mTarget == ARRAY_BUFFER) - { - mContext.BindArrayBuffer(bufferId); - } - else - { - mContext.BindElementArrayBuffer(bufferId); - } -} - - } // namespace Internal } //namespace Dali diff --git a/dali/internal/render/gl-resources/gpu-buffer.h b/dali/internal/render/gl-resources/gpu-buffer.h index 04b24f4..3c97171 100644 --- a/dali/internal/render/gl-resources/gpu-buffer.h +++ b/dali/internal/render/gl-resources/gpu-buffer.h @@ -66,10 +66,8 @@ public: /** * constructor * @param context drawing context - * @param target the type of buffer to create @see Type - * @param usage how the buffer will be used @see DrawMode */ - GpuBuffer( Context& context, Target target, Usage usage ); + GpuBuffer( Context& context ); /** * Destructor, non virtual as no virtual methods or inheritance @@ -81,14 +79,15 @@ public: * Creates or updates a buffer object and binds it to the target. * @param size Specifies the size in bytes of the buffer object's new data store. * @param data pointer to the data to load + * @param usage How the buffer will be used */ - void UpdateDataBuffer(GLsizeiptr size, const GLvoid *data); + void UpdateDataBuffer(GLsizeiptr size, const GLvoid *data, Usage usage); /** * Bind the buffer object to the target * Will assert if the buffer size is zero */ - void Bind() const; + void Bind(Target target) const; /** * @return true if the GPU buffer is valid, i.e. its created and not empty @@ -104,16 +103,6 @@ public: return mSize; } - void SetStride( GLuint stride ) - { - mStride = stride; - } - - GLuint GetStride() - { - return mStride; - } - /** * Needs to be called when GL context is destroyed */ @@ -133,10 +122,7 @@ private: // Data GLsizeiptr mCapacity; ///< buffer capacity GLsizeiptr mSize; ///< buffer size GLuint mBufferId; ///< buffer object name(id) - GLuint mStride; ///< stride of data in buffer object - Target mTarget:2; ///< type of buffer (array/element), 2 bits are enough - Usage mUsage:2; ///< how the buffer is used (read, read/write etc), 2 bits are enough bool mBufferCreated:1; ///< whether buffer has been created }; diff --git a/dali/internal/render/renderers/render-geometry.cpp b/dali/internal/render/renderers/render-geometry.cpp index 77ca794..f48bee0 100644 --- a/dali/internal/render/renderers/render-geometry.cpp +++ b/dali/internal/render/renderers/render-geometry.cpp @@ -17,11 +17,11 @@ #include #include -#include #include #include #include #include +#include #include namespace Dali @@ -33,6 +33,7 @@ namespace SceneGraph RenderGeometry::RenderGeometry( const GeometryDataProvider& geometryDataProvider ) : mGeometryDataProvider( geometryDataProvider ), + mIndexBuffer(0), mHasBeenUpdated(false), mAttributesChanged(true) { @@ -50,35 +51,34 @@ void RenderGeometry::GlContextDestroyed() { } -void RenderGeometry::AddPropertyBuffer( const PropertyBufferDataProvider* dataProvider, GpuBuffer::Target gpuBufferTarget, GpuBuffer::Usage gpuBufferUsage ) +void RenderGeometry::AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer ) { - if( gpuBufferTarget == GpuBuffer::ELEMENT_ARRAY_BUFFER ) + if( isIndexBuffer ) { - RenderPropertyBuffer* renderPropertyBuffer = new RenderPropertyBuffer( *dataProvider, gpuBufferTarget, gpuBufferUsage ); - mIndexBuffer = renderPropertyBuffer; + mIndexBuffer = propertyBuffer; } - else if( gpuBufferTarget == GpuBuffer::ARRAY_BUFFER ) + else { - RenderPropertyBuffer* renderPropertyBuffer = new RenderPropertyBuffer( *dataProvider, gpuBufferTarget, gpuBufferUsage ); - mVertexBuffers.PushBack( renderPropertyBuffer ); + mVertexBuffers.PushBack( propertyBuffer ); mAttributesChanged = true; } } -void RenderGeometry::RemovePropertyBuffer( const PropertyBufferDataProvider* dataProvider ) +void RenderGeometry::RemovePropertyBuffer( const Render::PropertyBuffer* propertyBuffer ) { - if( dataProvider == &mIndexBuffer->GetDataProvider() ) + if( propertyBuffer == mIndexBuffer ) { - mIndexBuffer.Reset(); + mIndexBuffer = 0; } else { - for( RenderPropertyBufferIter iter( mVertexBuffers.Begin() ); iter != mVertexBuffers.End(); ++iter ) + size_t bufferCount = mVertexBuffers.Size(); + for( size_t i(0); iGetDataProvider() ) + if( propertyBuffer == mVertexBuffers[i] ) { //This will delete the gpu buffer associated to the RenderPropertyBuffer if there is one - mVertexBuffers.Remove( iter ); + mVertexBuffers.Remove( mVertexBuffers.Begin()+i); mAttributesChanged = true; break; } @@ -92,10 +92,10 @@ void RenderGeometry::GetAttributeLocationFromProgram( Vector& attributeLo for( size_t i(0); i< mVertexBuffers.Size(); ++i ) { - unsigned int attributeCount = mVertexBuffers[i]->GetDataProvider().GetAttributeCount( bufferIndex ); + unsigned int attributeCount = mVertexBuffers[i]->GetAttributeCount(); for( unsigned int j = 0; j < attributeCount; ++j ) { - const std::string& attributeName = mVertexBuffers[i]->GetDataProvider().GetAttributeName( bufferIndex, j ); + const std::string& attributeName = mVertexBuffers[i]->GetAttributeName( j ); unsigned int index = program.RegisterCustomAttribute( attributeName ); GLint location = program.GetCustomAttributeLocation( index ); @@ -125,11 +125,19 @@ void RenderGeometry::UploadAndDraw( //Update buffers if( mIndexBuffer ) { - mIndexBuffer->Update( context, bufferIndex ); + if(!mIndexBuffer->Update( context, true ) ) + { + //Index buffer is not ready ( Size, data or format has not been specified yet ) + return; + } } for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i ) { - mVertexBuffers[i]->Update( context, bufferIndex ); + if( !mVertexBuffers[i]->Update( context, false ) ) + { + //Vertex buffer is not ready ( Size, data or format has not been specified yet ) + return; + } } mHasBeenUpdated = true; } @@ -138,21 +146,20 @@ void RenderGeometry::UploadAndDraw( unsigned int base = 0; for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i ) { - mVertexBuffers[i]->BindBuffer( context ); - base += mVertexBuffers[i]->EnableVertexAttributes( context, bufferIndex, attributeLocation, base ); + mVertexBuffers[i]->BindBuffer( GpuBuffer::ARRAY_BUFFER ); + base += mVertexBuffers[i]->EnableVertexAttributes( context, attributeLocation, base ); } if( mIndexBuffer ) { - mIndexBuffer->BindBuffer( context ); + mIndexBuffer->BindBuffer( GpuBuffer::ELEMENT_ARRAY_BUFFER ); } //Bind index buffer unsigned int numIndices(0u); if( mIndexBuffer ) { - const PropertyBufferDataProvider& indexBuffer = mIndexBuffer->GetDataProvider(); - numIndices = mIndexBuffer->GetDataProvider().GetDataSize(bufferIndex) / indexBuffer.GetElementSize(bufferIndex); + numIndices = mIndexBuffer->GetDataSize() / mIndexBuffer->GetElementSize(); } //Draw call @@ -167,8 +174,7 @@ void RenderGeometry::UploadAndDraw( } else { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + unsigned int numVertices = mVertexBuffers[0]->GetElementCount(); context.DrawArrays( GL_TRIANGLES, 0, numVertices ); } break; @@ -181,16 +187,14 @@ void RenderGeometry::UploadAndDraw( } else { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + unsigned int numVertices = mVertexBuffers[0]->GetElementCount(); context.DrawArrays( GL_LINES, 0, numVertices ); } break; } case Dali::Geometry::POINTS: { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + unsigned int numVertices = mVertexBuffers[0]->GetElementCount(); context.DrawArrays(GL_POINTS, 0, numVertices ); break; } @@ -202,8 +206,7 @@ void RenderGeometry::UploadAndDraw( } else { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + unsigned int numVertices = mVertexBuffers[0]->GetElementCount(); context.DrawArrays(GL_TRIANGLE_STRIP, 0, numVertices ); } break; @@ -216,8 +219,7 @@ void RenderGeometry::UploadAndDraw( } else { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + unsigned int numVertices = mVertexBuffers[0]->GetElementCount(); context.DrawArrays(GL_TRIANGLE_FAN, 0, numVertices ); } break; diff --git a/dali/internal/render/renderers/render-geometry.h b/dali/internal/render/renderers/render-geometry.h index cb15d40..c8878cb 100644 --- a/dali/internal/render/renderers/render-geometry.h +++ b/dali/internal/render/renderers/render-geometry.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace Dali { @@ -33,16 +33,16 @@ class Context; class Program; class GpuBuffer; +namespace Render +{ +class PropertyBuffer; +} + namespace SceneGraph { class RenderDataProvider; class GeometryDataProvider; -typedef OwnerPointer< RenderPropertyBuffer > RenderPropertyBufferPtr; -typedef OwnerContainer< RenderPropertyBuffer* > RenderPropertyBufferContainer; -typedef RenderPropertyBufferContainer::Iterator RenderPropertyBufferIter; - - /** * 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 @@ -75,16 +75,15 @@ public: /** * Adds a property buffer to the geometry * @param[in] dataProvider The PropertyBuffer data provider - * @param[in] gpuBufferTarget target Specifies the type of the buffer - * @param[in] gpuBufferUsage usage Specifies how will the buffer be used + * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer */ - void AddPropertyBuffer( const PropertyBufferDataProvider* dataProvider, GpuBuffer::Target gpuBufferTarget, GpuBuffer::Usage gpuBufferUsage ); + void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer ); /** * Removes a PropertyBuffer from the geometry - * @param[in] dataProvider The property buffer to be removed + * @param[in] propertyBuffer The property buffer to be removed */ - void RemovePropertyBuffer( const PropertyBufferDataProvider* dataProvider ); + void RemovePropertyBuffer( const Render::PropertyBuffer* propertyBuffer ); /** * Gets the attribute locations on the shader for the attributes defined in the geometry RenderBuffers @@ -124,8 +123,8 @@ private: const GeometryDataProvider& mGeometryDataProvider; //Reference to update thread object // PropertyBuffers - RenderPropertyBufferPtr mIndexBuffer; - RenderPropertyBufferContainer mVertexBuffers; + Render::PropertyBuffer* mIndexBuffer; + Vector mVertexBuffers; // Booleans bool mHasBeenUpdated : 1; diff --git a/dali/internal/render/renderers/render-image-renderer.cpp b/dali/internal/render/renderers/render-image-renderer.cpp index 14f2cd4..6df5ebc 100644 --- a/dali/internal/render/renderers/render-image-renderer.cpp +++ b/dali/internal/render/renderers/render-image-renderer.cpp @@ -295,7 +295,7 @@ void ImageRenderer::DoRender( Context& context, SceneGraph::TextureCache& textur // make sure the vertex is bound, this has to be done before // we call VertexAttribPointer otherwise you get weird output on the display - mVertexBuffer->Bind(); + mVertexBuffer->Bind(GpuBuffer::ARRAY_BUFFER); samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER_RECT ); if( -1 != samplerLoc ) @@ -350,7 +350,7 @@ void ImageRenderer::DoRender( Context& context, SceneGraph::TextureCache& textur case GRID_NINE_PATCH_NO_CENTER: { const GLsizei indexCount = mIndexBuffer->GetBufferSize() / sizeof(GLushort); // compiler will optimize this to >> if possible - mIndexBuffer->Bind(); + mIndexBuffer->Bind(GpuBuffer::ELEMENT_ARRAY_BUFFER); context.DrawElements( GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0 ); break; } @@ -400,7 +400,7 @@ void ImageRenderer::UpdateVertexBuffer( Context& context, GLsizeiptr size, const // create/destroy if needed/not needed. if ( size && !mVertexBuffer ) { - mVertexBuffer = new GpuBuffer( context, GpuBuffer::ARRAY_BUFFER, GpuBuffer::DYNAMIC_DRAW ); + mVertexBuffer = new GpuBuffer( context ); } else if ( !size && mVertexBuffer ) { @@ -410,7 +410,7 @@ void ImageRenderer::UpdateVertexBuffer( Context& context, GLsizeiptr size, const // update if ( mVertexBuffer ) { - mVertexBuffer->UpdateDataBuffer( size, data ); + mVertexBuffer->UpdateDataBuffer( size, data, GpuBuffer::DYNAMIC_DRAW); } } @@ -419,7 +419,7 @@ void ImageRenderer::UpdateIndexBuffer( Context& context, GLsizeiptr size, const // create/destroy if needed/not needed. if ( size && !mIndexBuffer ) { - mIndexBuffer = new GpuBuffer( context, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW ); + mIndexBuffer = new GpuBuffer( context ); } else if ( !size && mIndexBuffer ) { @@ -429,7 +429,7 @@ void ImageRenderer::UpdateIndexBuffer( Context& context, GLsizeiptr size, const // update if ( mIndexBuffer ) { - mIndexBuffer->UpdateDataBuffer(size,data); + mIndexBuffer->UpdateDataBuffer(size,data,GpuBuffer::STATIC_DRAW); } } diff --git a/dali/internal/render/renderers/render-new-renderer.cpp b/dali/internal/render/renderers/render-new-renderer.cpp index 4a32245..ae500f7 100644 --- a/dali/internal/render/renderers/render-new-renderer.cpp +++ b/dali/internal/render/renderers/render-new-renderer.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/dali/internal/render/renderers/render-new-renderer.h b/dali/internal/render/renderers/render-new-renderer.h index 84a5ed6..96f1661 100644 --- a/dali/internal/render/renderers/render-new-renderer.h +++ b/dali/internal/render/renderers/render-new-renderer.h @@ -26,10 +26,12 @@ #include #include + namespace Dali { namespace Internal { +class Context; class PropertyInputImpl; namespace Render diff --git a/dali/internal/render/renderers/render-property-buffer.cpp b/dali/internal/render/renderers/render-property-buffer.cpp new file mode 100644 index 0000000..d4fe418 --- /dev/null +++ b/dali/internal/render/renderers/render-property-buffer.cpp @@ -0,0 +1,218 @@ + +#include +#include // Dali::Internal::PropertyBuffer + +namespace +{ + +using namespace Dali; +using Dali::Property; +using Dali::Internal::PropertyImplementationType; + +Dali::GLenum GetPropertyImplementationGlType( Property::Type& propertyType ) +{ + Dali::GLenum type = GL_BYTE; + + switch( propertyType ) + { + case Property::NONE: + case Property::STRING: + case Property::ARRAY: + case Property::MAP: + case Property::RECTANGLE: + case Property::ROTATION: + { + // types not supported by gl + break; + } + case Property::BOOLEAN: + { + type = GL_BYTE; + break; + } + case Property::INTEGER: + { + type = GL_SHORT; + break; + } + case Property::FLOAT: + case Property::VECTOR2: + case Property::VECTOR3: + case Property::VECTOR4: + case Property::MATRIX3: + case Property::MATRIX: + { + type = GL_FLOAT; + break; + } + } + + return type; +} + +size_t GetPropertyImplementationGlSize( Property::Type& propertyType ) +{ + size_t size = 1u; + + switch( propertyType ) + { + case Property::NONE: + case Property::STRING: + case Property::ARRAY: + case Property::MAP: + case Property::RECTANGLE: + case Property::ROTATION: + { + // types not supported by gl + break; + } + case Property::BOOLEAN: + { + size = 1u; + break; + } + case Property::INTEGER: + { + size = 2u; + break; + } + case Property::FLOAT: + case Property::VECTOR2: + case Property::VECTOR3: + case Property::VECTOR4: + case Property::MATRIX3: + case Property::MATRIX: + { + size = 4u; + break; + } + } + + return size; +} +} //Unnamed namespace + +namespace Dali +{ +namespace Internal +{ +namespace Render +{ + +PropertyBuffer::PropertyBuffer() +:mFormat(NULL), + mData(NULL), + mGpuBuffer(NULL), + mSize(0), + mDataChanged(true) +{ +} + +PropertyBuffer::~PropertyBuffer() +{ +} + +void PropertyBuffer::SetFormat( PropertyBuffer::Format* format ) +{ + mFormat = format; + mDataChanged = true; +} + +void PropertyBuffer::SetData( Dali::Vector* data ) +{ + mData = data; + mDataChanged = true; +} + +void PropertyBuffer::SetSize( unsigned int size ) +{ + mSize = size; + mDataChanged = true; +} + + +bool PropertyBuffer::Update( Context& context, bool isIndexBuffer ) +{ + if( !mData || !mFormat || !mSize ) + { + return false; + } + + if( !mGpuBuffer || mDataChanged ) + { + if ( ! mGpuBuffer ) + { + mGpuBuffer = new GpuBuffer( context ); + } + + // Update the GpuBuffer + if ( mGpuBuffer ) + { + DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" ); + + const void *data = &((*mData)[0]); + + // Index buffer needs to be unsigned short which is not supported by the property system + Vector ushortData; + if( isIndexBuffer ) + { + ushortData.Resize(mSize); + const unsigned int* unsignedData = static_cast(data); + for( unsigned int i = 0; i < mSize; ++i ) + { + ushortData[i] = unsignedData[i]; + } + data = &(ushortData[0]); + } + + mGpuBuffer->UpdateDataBuffer( GetDataSize(), data, GpuBuffer::STATIC_DRAW ); + } + + mDataChanged = false; + } + + return true; +} + +void PropertyBuffer::BindBuffer(GpuBuffer::Target target) +{ + if(mGpuBuffer) + { + mGpuBuffer->Bind(target); + } +} + +unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector& vAttributeLocation, unsigned int locationBase ) +{ + + unsigned int attributeCount = mFormat->components.size(); + + GLsizei elementSize = mFormat->size; + + for( unsigned int i = 0; i < attributeCount; ++i ) + { + GLint attributeLocation = vAttributeLocation[i+locationBase]; + if( attributeLocation != -1 ) + { + context.EnableVertexAttributeArray( attributeLocation ); + + GLint attributeSize = mFormat->components[i].size; + size_t attributeOffset = mFormat->components[i].offset; + Property::Type attributeType = mFormat->components[i].type; + + context.VertexAttribPointer( attributeLocation, + attributeSize / GetPropertyImplementationGlSize(attributeType), + GetPropertyImplementationGlType(attributeType), + GL_FALSE, // Not normalized + elementSize, + (void*)attributeOffset ); + } + } + + return attributeCount; + +} + +} //Render +} //Internal +} //Dali diff --git a/dali/internal/render/renderers/render-property-buffer.h b/dali/internal/render/renderers/render-property-buffer.h new file mode 100644 index 0000000..ce2fef9 --- /dev/null +++ b/dali/internal/render/renderers/render-property-buffer.h @@ -0,0 +1,176 @@ +#ifndef DALI_INTERNAL_RENDER_PROPERTY_BUFFER_H +#define DALI_INTERNAL_RENDER_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 +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Render +{ + +class PropertyBuffer +{ +public: + + struct Component + { + std::string name; + unsigned int offset; + unsigned int size; + Property::Type type; + }; + + /** + * Structure that holds the meta-data of the format of PropertyBuffer. + */ + struct Format + { + std::vector components; + unsigned int size; + }; + + /** + * @brief Default constructor + */ + PropertyBuffer(); + + /** + * @brief Destructor + */ + ~PropertyBuffer(); + + /** + * @brief Set the format of the buffer + * + * This function takes ownership of the pointer + * + * @param[in] format The format for the PropertyBuffer + */ + void SetFormat( PropertyBuffer::Format* format ); + + /** + * @brief Set the data of the PropertyBuffer + * + * This function takes ownership of the pointer + * @param[in] data The new data of the PropertyBuffer + */ + void SetData( Dali::Vector* data ); + + /** + * @brief Set the number of elements + * @param[in] size The number of elements + */ + void SetSize( unsigned int size ); + + /** + * @brief Bind the property buffer + * @param[in] target The binding point + */ + void BindBuffer(GpuBuffer::Target target); + + /** + * Perform the upload of the buffer only when requiered + * @param[in] context The GL context + * @param[in] isIndexBuffer True if the buffer is used as an index buffer + */ + bool Update( Context& context, bool isIndexBuffer ); + + /** + * Enable the vertex attributes for each vertex buffer from the corresponding + * shader program. + * @param[in] context The GL context + * @param[in] vAttributeLocation Vector containing attributes location for current program + * @param[in] locationBase Index in vAttributeLocation corresponding to the first attribute defined by this buffer + */ + unsigned int EnableVertexAttributes( Context& context, Vector& vAttributeLocation, unsigned int locationBase ); + + /** + * Get the number of attributes present in the buffer + * @return The number of attributes stored in this buffer + */ + inline unsigned int GetAttributeCount() const + { + DALI_ASSERT_DEBUG( mFormat && "Format should be set "); + return mFormat->components.size(); + } + + /** + * Retrieve the i-essim attribute name + * @param[in] index The index of the attribute + * @return The name of the attribute + */ + inline const std::string& GetAttributeName(unsigned int index ) const + { + DALI_ASSERT_DEBUG( mFormat && "Format should be set "); + return mFormat->components[index].name; + } + + /** + * Retrieve the size of the buffer in bytes + * @return The total size of the buffer + */ + inline std::size_t GetDataSize() const + { + DALI_ASSERT_DEBUG( mFormat && "Format should be set "); + return mFormat->size * mSize; + } + + /** + * Retrieve the size of one element of the buffer + * @return The size of one element + */ + inline std::size_t GetElementSize() const + { + DALI_ASSERT_DEBUG( mFormat && "Format should be set "); + return mFormat->size; + } + + /** + * Retrieve the number of elements in the buffer + * @return The total number of elements + */ + inline unsigned int GetElementCount() const + { + return mSize; + } + +private: + OwnerPointer< PropertyBuffer::Format > mFormat; ///< Format of the buffer + OwnerPointer< Dali::Vector< char > > mData; ///< Data + OwnerPointer mGpuBuffer; ///< Pointer to the GpuBuffer associated with this RenderPropertyBuffer + + size_t mSize; ///< Number of Elements in the buffer + bool mDataChanged; ///< Flag to know if data has changed in a frame + +}; + +} // namespace Render + + + +} // namespace Internal +} // namespace Dali + + +#endif // DALI_INTERNAL_RENDER_PROPERTY_BUFFER_H diff --git a/dali/internal/render/renderers/render-renderer-property-buffer.cpp b/dali/internal/render/renderers/render-renderer-property-buffer.cpp deleted file mode 100644 index dfceae9..0000000 --- a/dali/internal/render/renderers/render-renderer-property-buffer.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * 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. - */ - -// CLASS HEADERS -#include - -// INTERNAL INCLUDES -#include // Dali::Internal::PropertyBuffer -#include -#include - -namespace -{ - -using namespace Dali; -using Dali::Property; -using Dali::Internal::PropertyImplementationType; - -Dali::GLenum GetPropertyImplementationGlType( Property::Type& propertyType ) -{ - Dali::GLenum type = GL_BYTE; - - switch( propertyType ) - { - case Property::NONE: - case Property::STRING: - case Property::ARRAY: - case Property::MAP: - case Property::RECTANGLE: - case Property::ROTATION: - { - // types not supported by gl - break; - } - case Property::BOOLEAN: - { - type = GL_BYTE; - break; - } - case Property::INTEGER: - { - type = GL_SHORT; - break; - } - case Property::FLOAT: - case Property::VECTOR2: - case Property::VECTOR3: - case Property::VECTOR4: - case Property::MATRIX3: - case Property::MATRIX: - { - type = GL_FLOAT; - break; - } - } - - return type; -} - -size_t GetPropertyImplementationGlSize( Property::Type& propertyType ) -{ - size_t size = 1u; - - switch( propertyType ) - { - case Property::NONE: - case Property::STRING: - case Property::ARRAY: - case Property::MAP: - case Property::RECTANGLE: - case Property::ROTATION: - { - // types not supported by gl - break; - } - case Property::BOOLEAN: - { - size = 1u; - break; - } - case Property::INTEGER: - { - size = 2u; - break; - } - case Property::FLOAT: - case Property::VECTOR2: - case Property::VECTOR3: - case Property::VECTOR4: - case Property::MATRIX3: - case Property::MATRIX: - { - size = 4u; - break; - } - } - - return size; -} - -void UploadAttribute( Dali::Internal::Context& context, - Dali::GLint attributeLocation, - Dali::GLint attributeSize, - size_t attributeOffset, - Dali::Property::Type attributeType, - Dali::GLsizei elementSize ) -{ - // TODO: MESH_REWORK Matrices need multiple calls to this function - context.VertexAttribPointer( attributeLocation, - attributeSize / GetPropertyImplementationGlSize(attributeType), - GetPropertyImplementationGlType(attributeType), - GL_FALSE, // Not normalized - elementSize, - (void*)attributeOffset ); -} - -} // unnamed namespace - -namespace Dali -{ -namespace Internal -{ -namespace SceneGraph -{ - -RenderPropertyBuffer::RenderPropertyBuffer( const PropertyBufferDataProvider& propertyBufferDataProvider, - GpuBuffer::Target gpuBufferTarget, - GpuBuffer::Usage gpuBufferUsage ) -: mDataProvider( propertyBufferDataProvider ), - mGpuBuffer( NULL ), - mGpuBufferTarget( gpuBufferTarget ), - mGpuBufferUsage( gpuBufferUsage ) -{ -} - -RenderPropertyBuffer::~RenderPropertyBuffer() -{ -} - -void RenderPropertyBuffer::Update( Context& context, BufferIndex bufferIndex ) -{ - if( !mGpuBuffer || mDataProvider.HasDataChanged( bufferIndex ) ) - { - if ( ! mGpuBuffer ) - { - mGpuBuffer = new GpuBuffer( context, mGpuBufferTarget, mGpuBufferUsage ); - } - - // Update the GpuBuffer - if ( mGpuBuffer ) - { - std::size_t dataSize = mDataProvider.GetDataSize( bufferIndex ); - DALI_ASSERT_DEBUG( dataSize && "No data in the property buffer!" ); - - const void *data = &(mDataProvider.GetData( bufferIndex )[0]); - Vector ushortData; - - // Index buffer needs to be unsigned short which is not supported by the property system - if( mGpuBufferTarget == GpuBuffer::ELEMENT_ARRAY_BUFFER ) - { - ushortData.Resize( dataSize ); - const unsigned int* unsignedData = static_cast(data); - unsigned int numberOfElements = dataSize / sizeof(unsigned int); - for( unsigned int i = 0; i < numberOfElements; ++i ) - { - ushortData[i] = unsignedData[i]; - } - data = &(ushortData[0]); - } - - mGpuBuffer->UpdateDataBuffer( dataSize, data ); - mGpuBuffer->SetStride( mDataProvider.GetElementSize( bufferIndex ) ); - } - } -} - -void RenderPropertyBuffer::BindBuffer( Context& context ) -{ - mGpuBuffer->Bind(); -} - -unsigned int RenderPropertyBuffer::EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Vector& vAttributeLocation, unsigned int locationBase ) -{ - unsigned int attributeCount = mDataProvider.GetAttributeCount( bufferIndex ); - - GLsizei elementSize = mDataProvider.GetElementSize( bufferIndex ); - - for( unsigned int i = 0; i < attributeCount; ++i ) - { - GLint attributeLocation = vAttributeLocation[i+locationBase]; - if( attributeLocation != -1 ) - { - context.EnableVertexAttributeArray( attributeLocation ); - - GLint attributeSize = mDataProvider.GetAttributeSize( bufferIndex, i ); - size_t attributeOffset = mDataProvider.GetAttributeOffset( bufferIndex, i ); - Property::Type attributeType = mDataProvider.GetAttributeType( bufferIndex, i ); - - UploadAttribute( context, - attributeLocation, - attributeSize, - attributeOffset, - attributeType, - elementSize ); - } - } - - return attributeCount; -} - -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 deleted file mode 100644 index f779cd7..0000000 --- a/dali/internal/render/renderers/render-renderer-property-buffer.h +++ /dev/null @@ -1,122 +0,0 @@ -#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 -#include -#include -#include -#include -#include - -namespace Dali -{ -namespace Internal -{ -class Context; -class Program; - -namespace Render -{ -class NewRenderer; -} - -namespace SceneGraph -{ - -/** - * 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) - * @param[in] gpuBufferTarget Type of target for the gpu-buffer - * @param[in] gpuBufferUsage Type of target for the gpu-buffer - */ - RenderPropertyBuffer( const PropertyBufferDataProvider& propertyBufferDataProvider, - GpuBuffer::Target gpuBufferTarget, - GpuBuffer::Usage gpuBufferUsage ); - - /** - * Destructor - */ - ~RenderPropertyBuffer(); - - /** - * Perform the upload of the buffer only when requiered - * @param[in] context The GL context - * @param[in] bufferIndex The current buffer index - */ - void Update( Context& context, BufferIndex bufferIndex ); - - /** - * Bind the geometry buffers - * @param[in] context The GL context - */ - void BindBuffer( Context& context ); - - /** - * 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 - * @param[in] vAttributeLocation Vector containing attributes location for current program - * @param[in] locationBase Index in vAttributeLocation corresponding to the first attribute defined by this buffer - */ - unsigned int EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Vector& vAttributeLocation, unsigned int locationBase); - - /** - * Get the data provider for the buffer - */ - const PropertyBufferDataProvider& GetDataProvider() const - { - return mDataProvider; - } - -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 mAttributesLocation; ///< Location of the attributes for the property buffer in this renderer. - - OwnerPointer mGpuBuffer; ///< Pointer to the GpuBuffer associated with this RenderPropertyBuffer - GpuBuffer::Target mGpuBufferTarget; ///< The type of GPU buffer to create - GpuBuffer::Usage mGpuBufferUsage; ///< The type of usage the GPU buffer will have -}; - -} // namespace SceneGraph -} // namespace Internal -} // namespace Dali - -#endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_H diff --git a/dali/internal/update/common/discard-queue.cpp b/dali/internal/update/common/discard-queue.cpp index bec6936..5f731a2 100644 --- a/dali/internal/update/common/discard-queue.cpp +++ b/dali/internal/update/common/discard-queue.cpp @@ -150,20 +150,6 @@ void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader ) } } -void DiscardQueue::Add( BufferIndex updateBufferIndex, PropertyBuffer* propertyBuffer ) -{ - DALI_ASSERT_DEBUG( NULL != propertyBuffer ); - - if ( 0u == updateBufferIndex ) - { - mPropertyBufferQueue0.PushBack( propertyBuffer ); - } - else - { - mPropertyBufferQueue1.PushBack( propertyBuffer ); - } -} - void DiscardQueue::Clear( BufferIndex updateBufferIndex ) { // Destroy some discarded objects; these should no longer own any GL resources @@ -175,7 +161,6 @@ void DiscardQueue::Clear( BufferIndex updateBufferIndex ) mShaderQueue0.Clear(); mGeometryQueue0.Clear(); mMaterialQueue0.Clear(); - mPropertyBufferQueue0.Clear(); mRendererQueue0.Clear(); } else @@ -185,7 +170,6 @@ void DiscardQueue::Clear( BufferIndex updateBufferIndex ) mShaderQueue1.Clear(); mGeometryQueue1.Clear(); mMaterialQueue1.Clear(); - mPropertyBufferQueue1.Clear(); mRendererQueue1.Clear(); } } diff --git a/dali/internal/update/common/discard-queue.h b/dali/internal/update/common/discard-queue.h index 96c4dbc..c4d7cc9 100644 --- a/dali/internal/update/common/discard-queue.h +++ b/dali/internal/update/common/discard-queue.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -59,7 +58,6 @@ public: typedef OwnerContainer< Shader* > ShaderQueue; typedef OwnerContainer< Geometry* > GeometryQueue; typedef OwnerContainer< Material* > MaterialQueue; - typedef OwnerContainer< PropertyBuffer* > PropertyBufferQueue; typedef OwnerContainer< Renderer* > RendererQueue; /** @@ -101,12 +99,6 @@ public: * Adds an unwanted material to the discard queue. * A message will be sent to clean up GL resources in the next Render. */ - void Add( BufferIndex updateBufferIndex, PropertyBuffer* material ); - - /** - * Adds an unwanted material to the discard queue. - * A message will be sent to clean up GL resources in the next Render. - */ void Add( BufferIndex updateBufferIndex, Material* material ); /** @@ -151,7 +143,6 @@ private: ShaderQueue mShaderQueue0; GeometryQueue mGeometryQueue0; MaterialQueue mMaterialQueue0; - PropertyBufferQueue mPropertyBufferQueue0; RendererQueue mRendererQueue0; // Messages are queued here when the update buffer index == 1 @@ -160,7 +151,6 @@ private: ShaderQueue mShaderQueue1; GeometryQueue mGeometryQueue1; MaterialQueue mMaterialQueue1; - PropertyBufferQueue mPropertyBufferQueue1; RendererQueue mRendererQueue1; }; diff --git a/dali/internal/update/common/scene-graph-property-buffer.cpp b/dali/internal/update/common/scene-graph-property-buffer.cpp deleted file mode 100644 index c3fd74b..0000000 --- a/dali/internal/update/common/scene-graph-property-buffer.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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 - -namespace Dali -{ -namespace Internal -{ -namespace SceneGraph -{ - -PropertyBuffer::PropertyBuffer() -: mBufferData(NULL), - mDataChanged(false), - mSize(0u) -{ -} - -PropertyBuffer::~PropertyBuffer() -{ -} - -void PropertyBuffer::SetFormat( PropertyBufferMetadata::Format* format ) -{ - mFormat = format; -} - -void PropertyBuffer::SetSize( BufferIndex bufferIndex, unsigned int size ) -{ - mSize.Set(bufferIndex, size); -} - -void PropertyBuffer::SetData( BufferIndex bufferIndex, PropertyBufferDataProvider::BufferType* data ) -{ - mBufferData[bufferIndex] = data; - mDataChanged[bufferIndex] = true; -} - -void PropertyBuffer::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex ) -{ -} - -void PropertyBuffer::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex ) -{ -} - -bool PropertyBuffer::HasDataChanged( BufferIndex bufferIndex ) const -{ - return mDataChanged[ bufferIndex ]; -} - -unsigned int PropertyBuffer::GetAttributeCount( BufferIndex bufferIndex ) const -{ - DALI_ASSERT_DEBUG( mFormat && "Format should be set "); - return mFormat->components.size(); -} - -const std::string& PropertyBuffer::GetAttributeName( BufferIndex bufferIndex, unsigned int index ) const -{ - DALI_ASSERT_DEBUG( mFormat && "Format should be set "); - return mFormat->components[index].name; -} - -size_t PropertyBuffer::GetAttributeSize( BufferIndex bufferIndex, unsigned int index ) const -{ - DALI_ASSERT_DEBUG( mFormat && "Format should be set "); - - return mFormat->components[index].size; -} - -Property::Type PropertyBuffer::GetAttributeType( BufferIndex bufferIndex, unsigned int index ) const -{ - DALI_ASSERT_DEBUG( mFormat && "Format should be set "); - - return mFormat->components[index].type; -} - -size_t PropertyBuffer::GetAttributeOffset( BufferIndex bufferIndex, unsigned int index ) const -{ - DALI_ASSERT_DEBUG( mFormat && "Format should be set "); - - return mFormat->components[index].offset; -} - -const PropertyBufferDataProvider::BufferType& PropertyBuffer::GetData( BufferIndex bufferIndex ) const -{ - DALI_ASSERT_DEBUG( mBufferData[bufferIndex] && "Should have some data."); - - return *mBufferData[bufferIndex]; -} - -std::size_t PropertyBuffer::GetDataSize( BufferIndex bufferIndex ) const -{ - DALI_ASSERT_DEBUG( mFormat && "Format should be set "); - - return mFormat->size * mSize[ bufferIndex ]; -} - - -std::size_t PropertyBuffer::GetElementSize( BufferIndex bufferIndex ) const -{ - return mFormat->size; -} - -unsigned int PropertyBuffer::GetElementCount( BufferIndex bufferIndex ) const -{ - return mSize[bufferIndex]; -} - -unsigned int PropertyBuffer::GetGpuBufferId( BufferIndex bufferIndex ) const -{ - //TODO: MESH_REWORK fix this - DALI_ASSERT_DEBUG(false && "FIX THIS"); - - return 0; -} - -void PropertyBuffer::ResetDefaultProperties( BufferIndex updateBufferIndex ) -{ - // Age the double buffered properties - mSize.CopyPrevious(updateBufferIndex); - - // Update double buffered value - mBufferData.CopyPrevious(updateBufferIndex); - - // The flag should be reset each frame - mDataChanged[updateBufferIndex] = false; -} - -} // namespace SceneGraph -} // namespace Internal -} // namespace Dali diff --git a/dali/internal/update/common/scene-graph-property-buffer.h b/dali/internal/update/common/scene-graph-property-buffer.h deleted file mode 100644 index 0f82433..0000000 --- a/dali/internal/update/common/scene-graph-property-buffer.h +++ /dev/null @@ -1,227 +0,0 @@ -#ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_H -#define DALI_INTERNAL_SCENE_GRAPH_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 -#include -#include -#include -#include - -namespace Dali -{ -namespace Internal -{ -namespace SceneGraph -{ -class SceneController; - -namespace PropertyBufferMetadata -{ -/** - * Structure that holds name and size of a component in the PropertyBuffer. - */ -struct Component -{ - std::string name; - unsigned int offset; - unsigned int size; - Property::Type type; -}; - -/** - * Structure that holds the meta-data of the format of PropertyBuffer. - */ -struct Format -{ - std::vector components; - unsigned int size; -}; - -} // PropertyBufferMetadata - -class PropertyBuffer : public PropertyOwner, public PropertyBufferDataProvider -{ -public: - - /** - * Constructor - */ - PropertyBuffer(); - - /** - * Destructor - */ - virtual ~PropertyBuffer(); - - /** - * @brief Set the format of the buffer - * - * This function takes ownership of the pointer - * - * @param[in] format The format for the PropertyBuffer - */ - void SetFormat( PropertyBufferMetadata::Format* format ); - - /** - * @brief Set the data of the PropertyBuffer - * - * This function takes ownership of the pointer - * - * @param[in] bufferIndex Index for double buffered values - * @param[in] data The new data of the PropertyBuffer - */ - void SetData( BufferIndex bufferIndex, PropertyBufferDataProvider::BufferType* data ); - - /** - * @brief Set the number of elements - * - * @param[in] bufferIndex Index for double buffered values - * @param[in] size The number of elements - */ - void SetSize( BufferIndex bufferIndex, unsigned int size ); - - /** - * @brief Connect the object to the scene graph - * - * @param[in] sceneController The scene controller - used for sending messages to render thread - * @param[in] bufferIndex The current buffer index - used for sending messages to render thread - */ - void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex ); - - /** - * @brief Disconnect the object from 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::GetAttributeType( BufferIndex bufferIndex, unsigned int index ) - */ - virtual Property::Type GetAttributeType( 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; - -protected: // From PropertyOwner - /** - * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties() - */ - virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ); - -private: - OwnerPointer mFormat; ///< Format of the buffer - - DoubleBuffered< OwnerPointer > mBufferData; ///< Data - DoubleBuffered< bool > mDataChanged; ///< Flag to know if data has changed in a frame - - DoubleBufferedProperty mSize; ///< Number of Elements in the buffer -}; - -inline void SetFormatMessage( EventThreadServices& eventThreadServices, - const PropertyBuffer& propertyBuffer, - PropertyBufferMetadata::Format* format ) -{ - typedef MessageValue1< PropertyBuffer, OwnerPointer > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &propertyBuffer, &PropertyBuffer::SetFormat, format ); -} - -inline void SetSizeMessage( EventThreadServices& eventThreadServices, - const PropertyBuffer& propertyBuffer, - unsigned int size ) -{ - typedef MessageDoubleBuffered1 < PropertyBuffer, unsigned int > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &propertyBuffer, &PropertyBuffer::SetSize, size ); -} - -inline void SetDataMessage( EventThreadServices& eventThreadServices, - const PropertyBuffer& propertyBuffer, - PropertyBuffer::BufferType* data ) -{ - typedef MessageDoubleBuffered1< PropertyBuffer, OwnerPointer > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &propertyBuffer, &PropertyBuffer::SetData, data ); -} - -} // namespace SceneGraph -} // namespace Internal -} // namespace Dali - -#endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_H diff --git a/dali/internal/update/controllers/render-message-dispatcher.cpp b/dali/internal/update/controllers/render-message-dispatcher.cpp index 4e881aa..0c49a26 100644 --- a/dali/internal/update/controllers/render-message-dispatcher.cpp +++ b/dali/internal/update/controllers/render-message-dispatcher.cpp @@ -87,20 +87,20 @@ void RenderMessageDispatcher::RemoveGeometry( RenderGeometry& renderGeometry ) new (slot) DerivedType( &mRenderManager, &RenderManager::RemoveGeometry, &renderGeometry ); } -void RenderMessageDispatcher::AddPropertyBuffer( RenderGeometry& renderGeometry, PropertyBufferDataProvider* propertyBuffer, GpuBuffer::Target target, GpuBuffer::Usage usage ) +void RenderMessageDispatcher::AddPropertyBuffer( RenderGeometry& renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer ) { - typedef MessageValue4< RenderManager, RenderGeometry*, PropertyBufferDataProvider*, GpuBuffer::Target, GpuBuffer::Usage > DerivedType; + typedef MessageValue3< RenderManager, RenderGeometry*, Render::PropertyBuffer*, bool > DerivedType; // Reserve some memory inside the render queue unsigned int* slot = mRenderQueue.ReserveMessageSlot( mBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( &mRenderManager, &RenderManager::AddPropertyBuffer, &renderGeometry, propertyBuffer, target, usage ); + new (slot) DerivedType( &mRenderManager, &RenderManager::AddPropertyBuffer, &renderGeometry, propertyBuffer, isIndexBuffer); } -void RenderMessageDispatcher::RemovePropertyBuffer( RenderGeometry& renderGeometry, PropertyBufferDataProvider* propertyBuffer ) +void RenderMessageDispatcher::RemovePropertyBuffer( RenderGeometry& renderGeometry, Render::PropertyBuffer* propertyBuffer ) { - typedef MessageValue2< RenderManager, RenderGeometry*, PropertyBufferDataProvider* > DerivedType; + typedef MessageValue2< RenderManager, RenderGeometry*, Render::PropertyBuffer* > DerivedType; // Reserve some memory inside the render queue unsigned int* slot = mRenderQueue.ReserveMessageSlot( mBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); diff --git a/dali/internal/update/controllers/render-message-dispatcher.h b/dali/internal/update/controllers/render-message-dispatcher.h index 06d3cfd..92c2164 100644 --- a/dali/internal/update/controllers/render-message-dispatcher.h +++ b/dali/internal/update/controllers/render-message-dispatcher.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { @@ -90,10 +91,9 @@ public: * Add a PropertyBuffer. * @param[in] renderGeometry The geometry * @param[in] propertyBuffer The PropertyBuffer - * @param[in] target Specifies the type of the buffer - * @param[in] usage Specifies how will the buffer be used + * @param[in] isIndexBuffer True if the buffer is intended to be used as an index buffer */ - void AddPropertyBuffer( RenderGeometry& renderGeometry, PropertyBufferDataProvider* propertyBuffer, GpuBuffer::Target target, GpuBuffer::Usage usage ); + void AddPropertyBuffer( RenderGeometry& renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer ); /** * Remove a PropertyBuffer. @@ -101,7 +101,7 @@ public: * @param[in] propertyBuffer The PropertyBuffer * @post PropertyBuffer will be destroyed in the next Render. */ - void RemovePropertyBuffer( RenderGeometry& renderGeometry, PropertyBufferDataProvider* propertyBuffer ); + void RemovePropertyBuffer( RenderGeometry& renderGeometry, Render::PropertyBuffer* propertyBuffer ); /** * Add a Render tracker. diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index f03be4f..cc4f379 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -178,7 +177,6 @@ struct UpdateManager::Impl renderers( sceneGraphBuffers, discardQueue ), geometries( sceneGraphBuffers, discardQueue ), materials( sceneGraphBuffers, discardQueue ), - propertyBuffers( sceneGraphBuffers, discardQueue ), messageQueue( renderController, sceneGraphBuffers ), keepRenderingSeconds( 0.0f ), animationFinishedDuringUpdate( false ), @@ -193,7 +191,6 @@ struct UpdateManager::Impl renderers.SetSceneController( *sceneController ); geometries.SetSceneController( *sceneController ); materials.SetSceneController( *sceneController ); - propertyBuffers.SetSceneController( *sceneController ); } ~Impl() @@ -275,7 +272,6 @@ struct UpdateManager::Impl ObjectOwnerContainer renderers; ObjectOwnerContainer geometries; ///< A container of geometries ObjectOwnerContainer materials; ///< A container of materials - ObjectOwnerContainer propertyBuffers; ///< A container of property buffers ShaderContainer shaders; ///< A container of owned shaders @@ -552,11 +548,6 @@ ObjectOwnerContainer& UpdateManager::GetMaterialOwner() return mImpl->materials; } -ObjectOwnerContainer& UpdateManager::GetPropertyBufferOwner() -{ - return mImpl->propertyBuffers; -} - void UpdateManager::AddShader( Shader* shader ) { DALI_ASSERT_DEBUG( NULL != shader ); @@ -748,7 +739,6 @@ void UpdateManager::ResetProperties( BufferIndex bufferIndex ) mImpl->materials.ResetToBaseValues( bufferIndex ); mImpl->geometries.ResetToBaseValues( bufferIndex ); - mImpl->propertyBuffers.ResetToBaseValues( bufferIndex ); mImpl->renderers.ResetToBaseValues( bufferIndex ); @@ -866,7 +856,6 @@ void UpdateManager::ApplyConstraints( BufferIndex bufferIndex ) // Constrain Materials and geometries mImpl->materials.ConstrainObjects( bufferIndex ); mImpl->geometries.ConstrainObjects( bufferIndex ); - mImpl->propertyBuffers.ConstrainObjects( bufferIndex ); mImpl->renderers.ConstrainObjects( bufferIndex ); // constrain shaders... (in construction order) @@ -1258,6 +1247,61 @@ void UpdateManager::SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMod new (slot) DerivedType( &mImpl->renderManager, &RenderManager::SetWrapMode, sampler, uWrapMode, vWrapMode ); } +void UpdateManager::AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer ) +{ + typedef MessageValue1< RenderManager, Render::PropertyBuffer* > DerivedType; + + // Reserve some memory inside the render queue + unsigned int* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new (slot) DerivedType( &mImpl->renderManager, &RenderManager::AddPropertyBuffer, propertyBuffer ); +} + +void UpdateManager::RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer ) +{ + typedef MessageValue1< RenderManager, Render::PropertyBuffer* > DerivedType; + + // Reserve some memory inside the render queue + unsigned int* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new (slot) DerivedType( &mImpl->renderManager, &RenderManager::RemovePropertyBuffer, propertyBuffer ); +} + +void UpdateManager::SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format ) +{ + typedef MessageValue2< RenderManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format* > DerivedType; + + // Reserve some memory inside the render queue + unsigned int* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new (slot) DerivedType( &mImpl->renderManager, &RenderManager::SetPropertyBufferFormat, propertyBuffer, format ); +} + +void UpdateManager::SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector* data) +{ + typedef MessageValue2< RenderManager, Render::PropertyBuffer*, Dali::Vector* > DerivedType; + + // Reserve some memory inside the render queue + unsigned int* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new (slot) DerivedType( &mImpl->renderManager, &RenderManager::SetPropertyBufferData, propertyBuffer, data ); +} + +void UpdateManager::SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size ) +{ + typedef MessageValue2< RenderManager, Render::PropertyBuffer*, size_t > DerivedType; + + // Reserve some memory inside the render queue + unsigned int* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) ); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new (slot) DerivedType( &mImpl->renderManager, &RenderManager::SetPropertyBufferSize, propertyBuffer, size ); +} + } // namespace SceneGraph } // namespace Internal diff --git a/dali/internal/update/manager/update-manager.h b/dali/internal/update/manager/update-manager.h index f1cb9ae..2385265 100644 --- a/dali/internal/update/manager/update-manager.h +++ b/dali/internal/update/manager/update-manager.h @@ -37,6 +37,7 @@ #include #include #include +#include namespace Dali { @@ -397,6 +398,45 @@ public: */ void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode ); + /** + * Add a new sampler to RenderManager + * @param[in] propertryBuffer The property buffer to add + * @post Sends a message to RenderManager to add the property buffer. + * The property buffer will be owned by RenderManager + */ + void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer ); + + /** + * Removes an existing PropertyBuffer from RenderManager + * @param[in] propertryBuffer The property buffer to remove + * @post The property buffer will be destroyed in the render thread + */ + void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer ); + + /** + * Sets the format of an existing property buffer + * @param[in] propertyBuffer The property buffer. + * @param[in] format The new format of the buffer + * @post Sends a message to RenderManager to set the new format to the property buffer. + */ + void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format ); + + /** + * Sets the data of an existing property buffer + * @param[in] propertyBuffer The property buffer. + * @param[in] data The new data of the buffer + * @post Sends a message to RenderManager to set the new data to the property buffer. + */ + void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector* data); + + /** + * Sets the size of an existing property buffer + * @param[in] propertyBuffer The property buffer. + * @param[in] size The new size of the buffer + * @post Sends a message to RenderManager to set the new size to the property buffer. + */ + void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size ); + public: /** @@ -888,6 +928,61 @@ inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, uWrapMode, vWrapMode ); } +inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer ) +{ + typedef MessageValue1< UpdateManager, Render::PropertyBuffer* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer ); +} + +inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer ) +{ + typedef MessageValue1< UpdateManager, Render::PropertyBuffer* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer ); +} + +inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format ) +{ + typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format ); +} + +inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector* data ) +{ + typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Vector* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data ); +} + +inline void SetPropertyBufferSize( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, size_t size ) +{ + typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, size_t > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferSize, &propertyBuffer, size ); +} + } // namespace SceneGraph diff --git a/dali/internal/update/rendering/scene-graph-geometry.cpp b/dali/internal/update/rendering/scene-graph-geometry.cpp index 5d6cb1a..7271343 100644 --- a/dali/internal/update/rendering/scene-graph-geometry.cpp +++ b/dali/internal/update/rendering/scene-graph-geometry.cpp @@ -20,6 +20,7 @@ // INTERNAL HEADERS #include #include +#include #include namespace Dali @@ -48,54 +49,48 @@ Geometry::~Geometry() mConnectionObservers.Destroy( *this ); } -void Geometry::AddVertexBuffer( PropertyBuffer* vertexBuffer ) +void Geometry::AddVertexBuffer( Render::PropertyBuffer* vertexBuffer ) { mVertexBuffers.PushBack( vertexBuffer ); - CalculateExtents( vertexBuffer ); - vertexBuffer->AddUniformMapObserver(*this); mConnectionObservers.ConnectionsChanged(*this); if( mRenderGeometry ) { - mSceneController->GetRenderMessageDispatcher().AddPropertyBuffer( *mRenderGeometry, vertexBuffer, GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW ); + mSceneController->GetRenderMessageDispatcher().AddPropertyBuffer( *mRenderGeometry, vertexBuffer, false); } } -void Geometry::RemoveVertexBuffer( PropertyBuffer* vertexBuffer ) +void Geometry::RemoveVertexBuffer( Render::PropertyBuffer* vertexBuffer ) { DALI_ASSERT_DEBUG( NULL != vertexBuffer ); // Find the object and destroy it - Vector::Iterator match = std::find( - mVertexBuffers.Begin(), - mVertexBuffers.End(), - vertexBuffer ); - - DALI_ASSERT_DEBUG( mVertexBuffers.End() != match ); - if( mVertexBuffers.End() != match ) + size_t bufferCount(mVertexBuffers.Size()); + for( size_t i(0); iRemoveUniformMapObserver(*this); - mVertexBuffers.Erase( match ); - mConnectionObservers.ConnectionsChanged(*this); - - if( mRenderGeometry ) + if( vertexBuffer == mVertexBuffers[i] ) { - mSceneController->GetRenderMessageDispatcher().RemovePropertyBuffer( *mRenderGeometry, vertexBuffer ); + mVertexBuffers.Erase( mVertexBuffers.Begin()+i ); + mConnectionObservers.ConnectionsChanged(*this); + + if( mRenderGeometry ) + { + mSceneController->GetRenderMessageDispatcher().RemovePropertyBuffer( *mRenderGeometry, vertexBuffer ); + } } } } -void Geometry::SetIndexBuffer( PropertyBuffer* indexBuffer ) +void Geometry::SetIndexBuffer( Render::PropertyBuffer* indexBuffer ) { if( mIndexBuffer != indexBuffer ) { mIndexBuffer = indexBuffer; - indexBuffer->AddUniformMapObserver(*this); mConnectionObservers.ConnectionsChanged(*this); if( mRenderGeometry ) { - mSceneController->GetRenderMessageDispatcher().AddPropertyBuffer( *mRenderGeometry, indexBuffer, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW ); + mSceneController->GetRenderMessageDispatcher().AddPropertyBuffer( *mRenderGeometry, indexBuffer, true ); } } } @@ -104,8 +99,6 @@ void Geometry::ClearIndexBuffer() { if( mIndexBuffer ) { - mIndexBuffer->RemoveUniformMapObserver(*this); - if( mRenderGeometry ) { mSceneController->GetRenderMessageDispatcher().RemovePropertyBuffer( *mRenderGeometry, mIndexBuffer ); @@ -120,12 +113,12 @@ void Geometry::SetGeometryType( BufferIndex bufferIndex, Geometry::GeometryType mGeometryType.Set( bufferIndex, geometryType); } -Vector& Geometry::GetVertexBuffers() +Vector& Geometry::GetVertexBuffers() { return mVertexBuffers; } -PropertyBuffer* Geometry::GetIndexBuffer() +Render::PropertyBuffer* Geometry::GetIndexBuffer() { return mIndexBuffer; } @@ -151,123 +144,6 @@ void Geometry::ResetDefaultProperties( BufferIndex updateBufferIndex ) mRequiresDepthTest.CopyPrevious(updateBufferIndex); } -void Geometry::CalculateExtents( PropertyBuffer* vertexBuffer ) -{ - unsigned int elementIndex = 0; - unsigned int elementCount = vertexBuffer->GetElementCount( 0 ); - unsigned int elementCount1 = vertexBuffer->GetElementCount( 1 ); - - // Select the double buffered element list that is the largest... - if ( elementCount < elementCount1 ) - { - elementCount = elementCount1; - elementIndex = 1; - } - - unsigned int attributeCount = vertexBuffer->GetAttributeCount( elementIndex ); - unsigned int elementSize = vertexBuffer->GetElementSize( elementIndex ); - - std::string posName( "aPos" ); - std::size_t found; - - float left = 0.0f; - float right = 0.0f; - float top = 0.0f; - float bottom = 0.0f; - - // Find the position attribute index - for ( unsigned int i = 0; i < attributeCount; ++i ) - { - found = vertexBuffer->GetAttributeName( 0, i ).find( posName ); - if ( found != std::string::npos ) - { - unsigned int offset = vertexBuffer->GetAttributeOffset( elementIndex, i ); - const PropertyBufferDataProvider::BufferType& data = vertexBuffer->GetData( elementIndex ); - - // Check attribute type to determine correct position type - Property::Type positionType = vertexBuffer->GetAttributeType( elementIndex, i ); - Vector3 halfExtents; - Vector3 center; - switch ( positionType ) - { - case Property::VECTOR2: - { - for ( unsigned int j = 0; j < elementCount; ++j ) - { - const Vector2* position = reinterpret_cast< const Vector2* >( &data[ offset ] ); - offset += elementSize; - - if ( position->x < left ) - { - left = position->x; - } - if ( position->x > right ) - { - right = position->x; - } - if ( position->y < top ) - { - top = position->y; - } - if ( position->y > bottom ) - { - bottom = position->y; - } - } - - halfExtents = Vector3( ( right - left ) * 0.5f, ( bottom - top ) * 0.5f, 0.0f ); - center = Vector3( halfExtents.x + left , halfExtents.y + top, 0.0f ); - break; - } - case Property::VECTOR3: - { - float near = 0.0f; - float far = 0.0f; - for ( unsigned int j = 0; j < elementCount; ++j ) - { - const Vector3* position = reinterpret_cast< const Vector3* >( &data[ offset ] ); - offset += elementSize; - - if ( position->x < left ) - { - left = position->x; - } - if ( position->x > right ) - { - right = position->x; - } - if ( position->y < top ) - { - top = position->y; - } - if ( position->y > bottom ) - { - bottom = position->y; - } - if ( position->z > far ) - { - far = position->z; - } - if ( position->z < near ) - { - near = position->z; - } - } - halfExtents = Vector3( ( right - left ) * 0.5f, ( bottom - top ) * 0.5f, ( far - near ) * 0.5f ); - center = Vector3( halfExtents.x + left , halfExtents.y + top, halfExtents.z + near ); - break; - } - default: - { - break; - } - } - mCenter.Bake( 0, center ); - mCenter.Bake( 1, center ); - } - } -} - void Geometry::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex ) { } @@ -295,7 +171,7 @@ void Geometry::UniformMappingsChanged( const UniformMap& mappings ) RenderGeometry* Geometry::GetRenderGeometry(SceneController* sceneController) { - if(!mRenderGeometry) + if(!mRenderGeometry ) { //Create RenderGeometry mSceneController = sceneController; @@ -304,12 +180,12 @@ RenderGeometry* Geometry::GetRenderGeometry(SceneController* sceneController) size_t vertexBufferCount( mVertexBuffers.Size() ); for( size_t i(0); iAddPropertyBuffer( mVertexBuffers[i], GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW ); + mRenderGeometry->AddPropertyBuffer( mVertexBuffers[i], false ); } if( mIndexBuffer ) { - mRenderGeometry->AddPropertyBuffer( mIndexBuffer, GpuBuffer::ELEMENT_ARRAY_BUFFER, GpuBuffer::STATIC_DRAW ); + mRenderGeometry->AddPropertyBuffer( mIndexBuffer, true ); } //Transfer ownership to RenderManager diff --git a/dali/internal/update/rendering/scene-graph-geometry.h b/dali/internal/update/rendering/scene-graph-geometry.h index c457f6c..36e2083 100644 --- a/dali/internal/update/rendering/scene-graph-geometry.h +++ b/dali/internal/update/rendering/scene-graph-geometry.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -34,6 +33,10 @@ namespace Dali { namespace Internal { +namespace Render +{ +class PropertyBuffer; +} namespace SceneGraph { class SceneController; @@ -60,19 +63,19 @@ public: /** * Add a property buffer to be used as a vertex buffer */ - void AddVertexBuffer( PropertyBuffer* vertexBuffer ); + void AddVertexBuffer( Render::PropertyBuffer* vertexBuffer ); /** * Remove a property buffer to be used as a vertex buffer * @param[in] vertexBuffer the associated vertex buffer to remove */ - void RemoveVertexBuffer( PropertyBuffer* vertexBuffer ); + void RemoveVertexBuffer( Render::PropertyBuffer* vertexBuffer ); /** * Set the buffer to be used as a source of indices for the geometry * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes. */ - void SetIndexBuffer( PropertyBuffer* indexBuffer ); + void SetIndexBuffer( Render::PropertyBuffer* indexBuffer ); /** * Clear the index buffer if it is no longer required, e.g. if changing geometry type @@ -122,13 +125,13 @@ public: // UniformMap::Observer * Get the vertex buffers of the geometry * @return A const reference to the vertex buffers */ - Vector& GetVertexBuffers(); + Vector& GetVertexBuffers(); /** * Get the index buffer of the geometry * @return A pointer to the index buffer if it exists, or NULL if it doesn't. */ - PropertyBuffer* GetIndexBuffer(); + Render::PropertyBuffer* GetIndexBuffer(); /** * Gets the associated RenderGeometry @@ -165,15 +168,8 @@ protected: // From PropertyOwner private: - /** - * @brief Calculate the extents of geometry contained in a vertex buffer. - * - * @param[in] vertexBuffer pointer to a vertex buffer. - */ - void CalculateExtents( PropertyBuffer* vertexBuffer ); - - Vector mVertexBuffers; ///< The vertex buffers - PropertyBuffer* mIndexBuffer; ///< The index buffer if required + Vector mVertexBuffers; ///< The vertex buffers + Render::PropertyBuffer* mIndexBuffer; ///< The index buffer if required ConnectionChangePropagator mConnectionObservers; RenderGeometry* mRenderGeometry; @@ -186,37 +182,37 @@ public: // Properties DoubleBufferedProperty mRequiresDepthTest; }; -inline void AddVertexBufferMessage( EventThreadServices& eventThreadServices , const Geometry& geometry, const PropertyBuffer& vertexBuffer ) +inline void AddVertexBufferMessage( EventThreadServices& eventThreadServices , const Geometry& geometry, const Render::PropertyBuffer& vertexBuffer ) { - typedef MessageValue1< Geometry, PropertyBuffer* > LocalType; + typedef MessageValue1< Geometry, Render::PropertyBuffer* > LocalType; // Reserve some memory inside the message queue unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, const_cast(&vertexBuffer) ); + new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, const_cast(&vertexBuffer) ); } -inline void RemoveVertexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& vertexBuffer ) +inline void RemoveVertexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const Render::PropertyBuffer& vertexBuffer ) { - typedef MessageValue1< Geometry, PropertyBuffer* > LocalType; + typedef MessageValue1< Geometry, Render::PropertyBuffer* > LocalType; // Reserve some memory inside the message queue unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, const_cast(&vertexBuffer) ); + new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, const_cast(&vertexBuffer) ); } -inline void SetIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const PropertyBuffer& indexBuffer ) +inline void SetIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry, const Render::PropertyBuffer& indexBuffer ) { - typedef MessageValue1< Geometry, PropertyBuffer* > LocalType; + typedef MessageValue1< Geometry, Render::PropertyBuffer* > LocalType; // Reserve some memory inside the message queue unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, const_cast(&indexBuffer) ); + new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, const_cast(&indexBuffer) ); } inline void ClearIndexBufferMessage( EventThreadServices& eventThreadServices, const Geometry& geometry ) diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index f061514..d7dce43 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-renderer.cpp @@ -150,18 +150,6 @@ void Renderer::PrepareRender( BufferIndex updateBufferIndex ) AddMappings( localMap, mMaterial->GetShader()->GetUniformMap() ); AddMappings( localMap, mGeometry->GetUniformMap() ); - Vector& vertexBuffers = mGeometry->GetVertexBuffers(); - unsigned int vertexBufferCount( vertexBuffers.Size() ); - for( unsigned int i(0); iGetUniformMap() ); - } - - PropertyBuffer* indexBuffer = mGeometry->GetIndexBuffer(); - if( indexBuffer ) - { - AddMappings( localMap, indexBuffer->GetUniformMap() ); - } } else if( mRegenerateUniformMap == COPY_UNIFORM_MAP ) { @@ -266,6 +254,10 @@ void Renderer::OnStageDisconnect() if( mReferenceCount == 0 ) { mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mRenderer ); + if( mGeometry ) + { + mGeometry->OnRendererDisconnect(); + } mRenderer = NULL; } } diff --git a/dali/internal/update/rendering/scene-graph-renderer.h b/dali/internal/update/rendering/scene-graph-renderer.h index 6eb64ea..d714a86 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.h +++ b/dali/internal/update/rendering/scene-graph-renderer.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include -- 2.7.4