From 648a1f586b4620e23334c865cf1d688b4868308f Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Mon, 29 Nov 2021 13:29:26 +0900 Subject: [PATCH] Use a proper projection matrix Change-Id: I6bed10bc639a838918919c5621d6f399db5cebe3 --- automated-tests/src/dali/utc-Dali-Scene.cpp | 127 ++++++++++++++++++++- dali/internal/render/common/render-manager.cpp | 4 +- .../update/render-tasks/scene-graph-camera.cpp | 6 +- 3 files changed, 127 insertions(+), 10 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Scene.cpp b/automated-tests/src/dali/utc-Dali-Scene.cpp index fc19ea7..a65463e 100644 --- a/automated-tests/src/dali/utc-Dali-Scene.cpp +++ b/automated-tests/src/dali/utc-Dali-Scene.cpp @@ -33,6 +33,27 @@ namespace { const std::string DEFAULT_DEVICE_NAME("hwKeyboard"); +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( + attribute mediump vec2 aPosition;\n + uniform mediump mat4 uModelView;\n + uniform mediump mat4 uProjection;\n + uniform mediump vec3 uSize;\n void main()\n { + \n + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + \n + vertexPosition.xyz *= uSize; + \n + gl_Position = uProjection * uModelView * vertexPosition; + \n + }\n); + +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( + uniform lowp vec4 uColor;\n void main()\n { + \n + gl_FragColor = uColor; + \n + }\n); + // Functor for EventProcessingFinished signal struct EventProcessingFinishedFunctor { @@ -1107,7 +1128,8 @@ int UtcDaliSceneSurfaceRotatedWithAngle0(void) clippingRect = TestApplication::DEFAULT_SURFACE_RECT; application.RenderWithPartialUpdate(damagedRects, clippingRect); - Actor actor = CreateRenderableActor(); + Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u); + Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER); actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f)); actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f)); @@ -1115,6 +1137,11 @@ int UtcDaliSceneSurfaceRotatedWithAngle0(void) application.GetScene().Add(actor); application.SendNotification(); + application.Render(0); + + Matrix projection; + CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor(); + camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection); damagedRects.clear(); application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH, @@ -1146,6 +1173,24 @@ int UtcDaliSceneSurfaceRotatedWithAngle0(void) // It should be changed. DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION); + // Check uniform + Quaternion rotationAngle(Dali::ANGLE_0, Vector3::ZAXIS); + Matrix rotation, newProjection; + rotation.SetIdentity(); + rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f)); + Matrix::Multiply(newProjection, projection, rotation); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + + // Change actor size to trigger rendering + actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f)); + + // Render again + application.SendNotification(); + application.Render(0); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + END_TEST; } @@ -1173,7 +1218,8 @@ int UtcDaliSceneSurfaceRotatedWithAngle90(void) clippingRect = TestApplication::DEFAULT_SURFACE_RECT; application.RenderWithPartialUpdate(damagedRects, clippingRect); - Actor actor = CreateRenderableActor(); + Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u); + Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER); actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f)); actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f)); @@ -1181,6 +1227,11 @@ int UtcDaliSceneSurfaceRotatedWithAngle90(void) application.GetScene().Add(actor); application.SendNotification(); + application.Render(0); + + Matrix projection; + CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor(); + camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection); damagedRects.clear(); application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH, @@ -1219,6 +1270,24 @@ int UtcDaliSceneSurfaceRotatedWithAngle90(void) // It should be changed. DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION); + // Check uniform + Quaternion rotationAngle(Dali::ANGLE_90, Vector3::ZAXIS); + Matrix rotation, newProjection; + rotation.SetIdentity(); + rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f)); + Matrix::Multiply(newProjection, projection, rotation); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + + // Change actor size to trigger rendering + actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f)); + + // Render again + application.SendNotification(); + application.Render(0); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + END_TEST; } @@ -1246,7 +1315,8 @@ int UtcDaliSceneSurfaceRotatedWithAngle180(void) clippingRect = TestApplication::DEFAULT_SURFACE_RECT; application.RenderWithPartialUpdate(damagedRects, clippingRect); - Actor actor = CreateRenderableActor(); + Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u); + Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER); actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f)); actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f)); @@ -1254,6 +1324,11 @@ int UtcDaliSceneSurfaceRotatedWithAngle180(void) application.GetScene().Add(actor); application.SendNotification(); + application.Render(0); + + Matrix projection; + CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor(); + camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection); damagedRects.clear(); application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH, @@ -1292,6 +1367,24 @@ int UtcDaliSceneSurfaceRotatedWithAngle180(void) // It should be changed. DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION); + // Check uniform + Quaternion rotationAngle(Dali::ANGLE_180, Vector3::ZAXIS); + Matrix rotation, newProjection; + rotation.SetIdentity(); + rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f)); + Matrix::Multiply(newProjection, projection, rotation); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + + // Change actor size to trigger rendering + actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f)); + + // Render again + application.SendNotification(); + application.Render(0); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + END_TEST; } @@ -1319,7 +1412,8 @@ int UtcDaliSceneSurfaceRotatedWithAngle270(void) clippingRect = TestApplication::DEFAULT_SURFACE_RECT; application.RenderWithPartialUpdate(damagedRects, clippingRect); - Actor actor = CreateRenderableActor(); + Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 4u, 4u); + Actor actor = CreateRenderableActor(image, VERTEX_SHADER, FRAGMENT_SHADER); actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f)); actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f)); @@ -1327,6 +1421,11 @@ int UtcDaliSceneSurfaceRotatedWithAngle270(void) application.GetScene().Add(actor); application.SendNotification(); + application.Render(0); + + Matrix projection; + CameraActor camera = application.GetScene().GetRenderTaskList().GetTask(0u).GetCameraActor(); + camera.GetProperty(CameraActor::CameraActor::Property::PROJECTION_MATRIX).Get(projection); damagedRects.clear(); application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH, @@ -1365,6 +1464,24 @@ int UtcDaliSceneSurfaceRotatedWithAngle270(void) // It should be changed. DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION); + // Check uniform + Quaternion rotationAngle(Dali::ANGLE_270, Vector3::ZAXIS); + Matrix rotation, newProjection; + rotation.SetIdentity(); + rotation.SetTransformComponents(Vector3(1.0f, 1.0f, 1.0f), rotationAngle, Vector3(0.0f, 0.0f, 0.0f)); + Matrix::Multiply(newProjection, projection, rotation); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + + // Change actor size to trigger rendering + actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f)); + + // Render again + application.SendNotification(); + application.Render(0); + + DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uProjection", newProjection)); + END_TEST; } @@ -1444,8 +1561,6 @@ int UtcDaliSceneSetRotationCompletedAcknowledgementWithAngle90(void) END_TEST; } - - int UtcDaliSceneKeyEventGeneratedSignalP(void) { TestApplication application; diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index 3c9f87c..2d63a0a 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -707,7 +707,9 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo) { - Rect clippingRect; + SceneGraph::Scene* sceneObject = GetImplementation(scene).GetSceneObject(); + Rect clippingRect = sceneObject->GetSurfaceRect(); + RenderScene(status, scene, renderToFbo, clippingRect); } diff --git a/dali/internal/update/render-tasks/scene-graph-camera.cpp b/dali/internal/update/render-tasks/scene-graph-camera.cpp index 5d3bab8..f7b2b1c 100644 --- a/dali/internal/update/render-tasks/scene-graph-camera.cpp +++ b/dali/internal/update/render-tasks/scene-graph-camera.cpp @@ -328,8 +328,8 @@ void Camera::SetReflectByPlane(const Vector4& plane) void Camera::RotateProjection(int rotationAngle) { - mProjectionRotation = rotationAngle; - mUpdateViewFlag = UPDATE_COUNT; + mProjectionRotation = rotationAngle; + mUpdateProjectionFlag = UPDATE_COUNT; } const Matrix& Camera::GetProjectionMatrix(BufferIndex bufferIndex) const @@ -609,7 +609,7 @@ uint32_t Camera::UpdateProjection(BufferIndex updateBufferIndex) // The projection matrix was updated in the previous frame; copy it mProjectionMatrix.CopyPrevious(updateBufferIndex); - finalProjection = mProjectionMatrix[updateBufferIndex]; + finalProjection = mFinalProjection[updateBufferIndex ? 0 : 1]; } else // UPDATE_COUNT == mUpdateProjectionFlag { -- 2.7.4