From 4e95de703aecc7d1527302fac52076adec717b97 Mon Sep 17 00:00:00 2001 From: Francisco Santos Date: Mon, 18 May 2015 14:07:37 +0100 Subject: [PATCH] Added test cases and fix bug in property buffer reupload. Change-Id: Ibe695e96183396ee9fdf3d81a3fe78d395dcbd83 --- .../dali-test-suite-utils/test-gl-abstraction.h | 12 ++ .../src/dali/utc-Dali-PropertyBuffer.cpp | 140 +++++++++++++++++++++ .../renderers/render-renderer-property-buffer.cpp | 2 +- .../update/common/scene-graph-property-buffer.cpp | 1 + 4 files changed, 154 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index eb8baf7..9fe6697 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -214,10 +214,12 @@ public: inline void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage) { + mBufferDataCalls.push_back(size); } inline void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data) { + mBufferSubDataCalls.push_back(size); } inline GLenum CheckFramebufferStatus(GLenum target) @@ -1696,9 +1698,19 @@ public: // TEST FUNCTIONS inline unsigned int GetClearCountCalled() const { return mClearCount; } + typedef std::vector BufferDataCalls; + inline const BufferDataCalls& GetBufferDataCalls() const { return mBufferDataCalls; } + inline void ResetBufferDataCalls() { mBufferDataCalls.clear(); } + + typedef std::vector BufferSubDataCalls; + inline const BufferSubDataCalls& GetBufferSubDataCalls() const { return mBufferSubDataCalls; } + inline void ResetBufferSubDataCalls() { mBufferSubDataCalls.clear(); } + private: GLuint mCurrentProgram; GLuint mCompileStatus; + BufferDataCalls mBufferDataCalls; + BufferSubDataCalls mBufferSubDataCalls; GLuint mLinkStatus; GLint mGetAttribLocationResult; GLenum mGetErrorResult; diff --git a/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp b/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp index d21677e..7e69a5e 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp @@ -81,3 +81,143 @@ int UtcDaliPropertyBufferDownCast02(void) DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION ); END_TEST; } + +int UtcDaliPropertyBufferSetData01(void) +{ + TestApplication application; + + Property::Map texturedQuadVertexFormat; + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; + texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2; + + PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC, + texturedQuadVertexFormat, 4 ); + DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION ); + + const float halfQuadSize = .5f; + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + TexturedQuadVertex texturedQuadVertexData[4] = { + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; + + propertyBuffer.SetData( texturedQuadVertexData ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( propertyBuffer ); + + Material material = CreateMaterial(1.f); + Renderer renderer = Renderer::New(geometry, material); + Actor actor = Actor::New(); + actor.SetSize(Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + + DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliPropertyBufferSetData02(void) +{ + TestApplication application; + + Property::Map texturedQuadVertexFormat; + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; + texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2; + + PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC, + texturedQuadVertexFormat, 4 ); + DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION ); + + const float halfQuadSize = .5f; + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + TexturedQuadVertex texturedQuadVertexData[4] = { + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; + + propertyBuffer.SetData( texturedQuadVertexData ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( propertyBuffer ); + + Material material = CreateMaterial(1.f); + Renderer renderer = Renderer::New(geometry, material); + Actor actor = Actor::New(); + actor.SetSize(Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + { + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + + DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION ); + } + + // Re-upload the data on the propertyBuffer + propertyBuffer.SetData( texturedQuadVertexData ); + + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + { + const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls = + application.GetGlAbstraction().GetBufferSubDataCalls(); + + DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION ); + + if ( bufferSubDataCalls.size() ) + { + DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION ); + } + } + + END_TEST; +} + +int UtcDaliPropertyBufferSetSize01(void) +{ + TestApplication application; + + Property::Map texturedQuadVertexFormat; + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; + texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2; + + PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC, + texturedQuadVertexFormat, + 4u ); + DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION ); + + size_t size = propertyBuffer.GetSize(); + DALI_TEST_EQUALS( size, 4u, TEST_LOCATION ); + + propertyBuffer.SetSize( 10u ); + size = propertyBuffer.GetSize(); + DALI_TEST_EQUALS( size, 10u, TEST_LOCATION ); + + END_TEST; +} + diff --git a/dali/internal/render/renderers/render-renderer-property-buffer.cpp b/dali/internal/render/renderers/render-renderer-property-buffer.cpp index aed0cdf..3dfd6e5 100644 --- a/dali/internal/render/renderers/render-renderer-property-buffer.cpp +++ b/dali/internal/render/renderers/render-renderer-property-buffer.cpp @@ -158,7 +158,7 @@ void RenderPropertyBuffer::Upload( Context& context, BufferIndex bufferIndex ) } // Update the GpuBuffer - if ( mGpuBuffer || mDataProvider.HasDataChanged( bufferIndex ) ) + if ( mGpuBuffer && mDataProvider.HasDataChanged( bufferIndex ) ) { std::size_t dataSize = mDataProvider.GetDataSize( bufferIndex ); DALI_ASSERT_DEBUG( dataSize && "No data in the property buffer!" ); diff --git a/dali/internal/update/common/scene-graph-property-buffer.cpp b/dali/internal/update/common/scene-graph-property-buffer.cpp index af55f1b..c3fd74b 100644 --- a/dali/internal/update/common/scene-graph-property-buffer.cpp +++ b/dali/internal/update/common/scene-graph-property-buffer.cpp @@ -25,6 +25,7 @@ namespace SceneGraph PropertyBuffer::PropertyBuffer() : mBufferData(NULL), + mDataChanged(false), mSize(0u) { } -- 2.7.4