From 9625aef01ddb5517ca39825c216c1b58289d7eaa Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Mon, 7 Jul 2014 13:58:15 +0100 Subject: [PATCH] Stop using raw matrix pointers directly in render thread as that can cause matrix from wrong frame to being used Change-Id: Ie956986f048786657cc6055b87f39113bb55a54d Signed-off-by: Adeel Kazmi --- dali/internal/render/common/render-algorithms.cpp | 6 ++-- dali/internal/render/common/render-debug.cpp | 4 +-- dali/internal/render/common/render-debug.h | 7 +++-- dali/internal/render/common/render-instruction.cpp | 17 +++++------ dali/internal/render/common/render-instruction.h | 33 ++++++++++++++++++---- .../render-tasks/scene-graph-render-task.cpp | 10 ++----- .../update/render-tasks/scene-graph-render-task.h | 6 ---- 7 files changed, 46 insertions(+), 37 deletions(-) diff --git a/dali/internal/render/common/render-algorithms.cpp b/dali/internal/render/common/render-algorithms.cpp index e18e9e2..0821279 100644 --- a/dali/internal/render/common/render-algorithms.cpp +++ b/dali/internal/render/common/render-algorithms.cpp @@ -125,10 +125,10 @@ void ProcessRenderInstruction( const RenderInstruction& instruction, BufferIndex bufferIndex, float frameTime ) { - DALI_PRINT_RENDER_INSTRUCTION( instruction ); + DALI_PRINT_RENDER_INSTRUCTION( instruction, bufferIndex ); - const Matrix* viewMatrix = instruction.mViewMatrix; - const Matrix* projectionMatrix = instruction.mProjectionMatrix; + const Matrix* viewMatrix = instruction.GetViewMatrix( bufferIndex ); + const Matrix* projectionMatrix = instruction.GetProjectionMatrix( bufferIndex ); DALI_ASSERT_DEBUG( NULL != viewMatrix ); DALI_ASSERT_DEBUG( NULL != projectionMatrix ); diff --git a/dali/internal/render/common/render-debug.cpp b/dali/internal/render/common/render-debug.cpp index f2e5637..d5995d4 100644 --- a/dali/internal/render/common/render-debug.cpp +++ b/dali/internal/render/common/render-debug.cpp @@ -48,12 +48,12 @@ void PrintFrameEnd() DALI_LOG_RENDER_INFO( "RENDER END\n\n" ); } -void PrintRenderInstruction( const SceneGraph::RenderInstruction& instruction ) +void PrintRenderInstruction( const SceneGraph::RenderInstruction& instruction, BufferIndex index ) { const char* target = (0 != instruction.mOffscreenTextureId) ? "FrameBuffer" : "Screen"; std::stringstream debugStream; - debugStream << "Rendering to " << target << ", View: " << *(instruction.mViewMatrix) << " Projection: " << *(instruction.mProjectionMatrix); + debugStream << "Rendering to " << target << ", View: " << *(instruction.GetViewMatrix(index)) << " Projection: " << *(instruction.GetProjectionMatrix(index)); if( instruction.mIsViewportSet ) { diff --git a/dali/internal/render/common/render-debug.h b/dali/internal/render/common/render-debug.h index d37deaf..59dbf66 100644 --- a/dali/internal/render/common/render-debug.h +++ b/dali/internal/render/common/render-debug.h @@ -28,7 +28,7 @@ #define DALI_PRINT_RENDER_START(x) Render::PrintFrameStart(x); #define DALI_PRINT_RENDER_END() Render::PrintFrameEnd(); -#define DALI_PRINT_RENDER_INSTRUCTION(x) Render::PrintRenderInstruction(x); +#define DALI_PRINT_RENDER_INSTRUCTION(x,index) Render::PrintRenderInstruction(x,index); #define DALI_PRINT_RENDER_LIST(x) Render::PrintRenderList(x); #define DALI_PRINT_RENDER_ITEM(x) Render::PrintRenderItem(x); @@ -36,7 +36,7 @@ #define DALI_PRINT_RENDER_START(x) #define DALI_PRINT_RENDER_END() -#define DALI_PRINT_RENDER_INSTRUCTION(x) +#define DALI_PRINT_RENDER_INSTRUCTION(x,index) #define DALI_PRINT_RENDER_LIST(x) #define DALI_PRINT_RENDER_ITEM(x) @@ -88,8 +88,9 @@ void PrintFrameEnd(); /** * Print some information about a render-instruction. * @param[in] instruction The render-instruction. + * @param[in] index to use */ -void PrintRenderInstruction( const SceneGraph::RenderInstruction& instruction ); +void PrintRenderInstruction( const SceneGraph::RenderInstruction& instruction, BufferIndex index ); /** * Print some information about a render-list. diff --git a/dali/internal/render/common/render-instruction.cpp b/dali/internal/render/common/render-instruction.cpp index 714177e..5e38169 100644 --- a/dali/internal/render/common/render-instruction.cpp +++ b/dali/internal/render/common/render-instruction.cpp @@ -32,14 +32,13 @@ namespace SceneGraph { RenderInstruction::RenderInstruction() -: mViewMatrix( 0 ), - mProjectionMatrix( 0 ), - mRenderTracker( NULL ), +: mRenderTracker( NULL ), mClearColor(), mIsViewportSet( false ), mIsClearColorSet( false ), mCullMode(false), mOffscreenTextureId( 0 ), + mCameraAttachment( 0 ), mNextFreeRenderList( 0 ) { // reserve 6 lists, which is enough for three layers with opaque and transparent things on @@ -98,14 +97,12 @@ const RenderList* RenderInstruction::GetRenderList( RenderListContainer::SizeTyp return mRenderLists[ index ]; } -void RenderInstruction::Reset( const Matrix* viewMatrix, - const Matrix* projectionMatrix, - unsigned int offscreenTextureId, - const Viewport* viewport, - const Vector4* clearColor) +void RenderInstruction::Reset( CameraAttachment* cameraAttachment, + unsigned int offscreenTextureId, + const Viewport* viewport, + const Vector4* clearColor ) { - mViewMatrix = viewMatrix; - mProjectionMatrix = projectionMatrix; + mCameraAttachment = cameraAttachment; mViewport = viewport ? *viewport : Viewport(); mIsViewportSet = NULL != viewport; mClearColor = clearColor ? *clearColor : Color::BLACK; diff --git a/dali/internal/render/common/render-instruction.h b/dali/internal/render/common/render-instruction.h index a1ce9ee..e0c2c12 100644 --- a/dali/internal/render/common/render-instruction.h +++ b/dali/internal/render/common/render-instruction.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include #include namespace Dali @@ -32,6 +33,7 @@ namespace Internal namespace SceneGraph { class RenderTracker; +class CameraAttachment; /** * A set of rendering instructions consisting of: @@ -86,18 +88,38 @@ public: * render-lists are cleared but not released, while matrices and other settings reset in * preparation for building a set of instructions for the renderer. * - * @param[in] viewMatrix The view matrix. - * @param[in] projectionMatrix The projection matrix. + * @param[in] cameraAttachment to use to get view and projection matrices. * @param[in] offscreenId A resource Id of an off-screen render target, or 0 * @param[in] viewport A pointer to a viewport, of NULL. * @param[in] clearColor A pointer to a color to clear with, or NULL if no clear is required. */ - void Reset( const Matrix* viewMatrix, - const Matrix* projectionMatrix, + void Reset( CameraAttachment* cameraAttachment, unsigned int offscreenId, const Viewport* viewport, const Vector4* clearColor ); + /** + * Get the view matrix for rendering + * @param index of the rendering side + * @return the view matrix + */ + const Matrix* GetViewMatrix( BufferIndex index ) const + { + // inlined as this is called once per frame per render instruction + return &mCameraAttachment->GetViewMatrix( index ); + } + + /** + * Get the projection matrix for rendering + * @param index of the rendering side + * @return the projection matrix + */ + const Matrix* GetProjectionMatrix( BufferIndex index ) const + { + // inlined as this is called once per frame per render instruction + return &mCameraAttachment->GetProjectionMatrix( index ); + } + private: // Undefined @@ -107,8 +129,6 @@ private: public: // Data, TODO hide these - const Matrix* mViewMatrix; ///< Pointer to a View Matrix (owned by camera) - const Matrix* mProjectionMatrix; ///< Pointer to a Projection Matrix (owned by camera) RenderTracker* mRenderTracker; ///< Pointer to an optional tracker object (not owned) Viewport mViewport; ///< Optional viewport @@ -121,6 +141,7 @@ public: // Data, TODO hide these private: // Data + CameraAttachment* mCameraAttachment; ///< camera that is used RenderListContainer mRenderLists; ///< container of all render lists RenderListContainer::SizeType mNextFreeRenderList; ///< index for the next free render list diff --git a/dali/internal/update/render-tasks/scene-graph-render-task.cpp b/dali/internal/update/render-tasks/scene-graph-render-task.cpp index 77ca4bf..27acf09 100644 --- a/dali/internal/update/render-tasks/scene-graph-render-task.cpp +++ b/dali/internal/update/render-tasks/scene-graph-render-task.cpp @@ -123,11 +123,6 @@ void RenderTask::SetCameraNode( Node* cameraNode ) } } -Node* RenderTask::GetCameraNode() const -{ - return mCameraNode; -} - void RenderTask::SetFrameBufferId( unsigned int resourceId ) { if ( mFrameBufferResourceId != resourceId ) @@ -421,13 +416,14 @@ const Matrix& RenderTask::GetProjectionMatrix( BufferIndex bufferIndex ) const void RenderTask::PrepareRenderInstruction( RenderInstruction& instruction, BufferIndex updateBufferIndex ) { + DALI_ASSERT_DEBUG( NULL != mCameraAttachment ); + TASK_LOG(Debug::General); Viewport viewport; bool viewportSet = QueryViewport( updateBufferIndex, viewport ); - instruction.Reset( &GetViewMatrix( updateBufferIndex ), - &GetProjectionMatrix( updateBufferIndex ), + instruction.Reset( mCameraAttachment, GetFrameBufferId(), viewportSet ? &viewport : NULL, mClearEnabled ? &GetClearColor( updateBufferIndex ) : NULL ); diff --git a/dali/internal/update/render-tasks/scene-graph-render-task.h b/dali/internal/update/render-tasks/scene-graph-render-task.h index 6b9e162..3cdf32a 100644 --- a/dali/internal/update/render-tasks/scene-graph-render-task.h +++ b/dali/internal/update/render-tasks/scene-graph-render-task.h @@ -97,12 +97,6 @@ public: void SetCameraNode( Node* node ); /** - * Retrieve the camera node. - * @return The scene is viewed from the perspective of this node. - */ - Node* GetCameraNode() const; - - /** * Set the frame-buffer used as a render target. * @param[in] resourceId The resource ID of the frame-buffer, or zero if not rendering off-screen. */ -- 2.7.4