/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * 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.
#include <dali/internal/render/common/render-manager.h>
// INTERNAL INCLUDES
+#include <dali/public-api/actors/sampling.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/stage.h>
#include <dali/public-api/render-tasks/render-task.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/core.h>
#include <dali/internal/common/owner-pointer.h>
-#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/render/common/render-algorithms.h>
#include <dali/internal/render/common/render-debug.h>
#include <dali/internal/render/common/render-tracker.h>
#include <dali/internal/render/common/render-instruction-container.h>
#include <dali/internal/render/common/render-instruction.h>
+#include <dali/internal/render/data-providers/uniform-name-cache.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/gl-resources/frame-buffer-texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
-#include <dali/internal/render/renderers/render-renderer.h>
+#include <dali/internal/render/queue/render-queue.h>
+#include <dali/internal/render/renderers/render-frame-buffer.h>
#include <dali/internal/render/renderers/render-geometry.h>
+#include <dali/internal/render/renderers/render-renderer.h>
+#include <dali/internal/render/renderers/render-sampler.h>
#include <dali/internal/render/shaders/program-controller.h>
-// Uncomment the next line to enable frame snapshot logging
-//#define FRAME_SNAPSHOT_LOGGING
-
-#ifdef FRAME_SNAPSHOT_LOGGING
-
-
-namespace // unnamed namespace
-{
-unsigned int SNAPSHOT_FRAME_FREQUENCY = 1200; // dump every 20-30 seconds
-} // unnamed namespace
-
-#define SET_SNAPSHOT_FRAME_LOG_LEVEL \
- DALI_LOG_FILTER_SET_LEVEL(Context::gGlLogFilter, ((GetFrameCount() % SNAPSHOT_FRAME_FREQUENCY)==5 ? Debug::General : Debug::Concise));
-
-#else // FRAME_SNAPSHOT_LOGGING
-
-#define SET_SNAPSHOT_FRAME_LOG_LEVEL
-
-#endif // FRAME_SNAPSHOT_LOGGING
-
namespace Dali
{
typedef OwnerContainer< Render::Renderer* > RendererOwnerContainer;
typedef RendererOwnerContainer::Iterator RendererOwnerIter;
-typedef OwnerContainer< RenderGeometry* > RenderGeometryOwnerContainer;
-typedef RenderGeometryOwnerContainer::Iterator RenderGeometryOwnerIter;
+typedef OwnerContainer< Render::Geometry* > GeometryOwnerContainer;
+typedef GeometryOwnerContainer::Iterator GeometryOwnerIter;
+
+typedef OwnerContainer< Render::Sampler* > SamplerOwnerContainer;
+typedef SamplerOwnerContainer::Iterator SamplerOwnerIter;
+
+typedef OwnerContainer< Render::NewTexture* > TextureOwnerContainer;
+typedef TextureOwnerContainer::Iterator TextureOwnerIter;
+
+typedef OwnerContainer< Render::FrameBuffer* > FrameBufferOwnerContainer;
+typedef FrameBufferOwnerContainer::Iterator FrameBufferOwnerIter;
+
+typedef OwnerContainer< Render::PropertyBuffer* > PropertyBufferOwnerContainer;
+typedef PropertyBufferOwnerContainer::Iterator PropertyBufferOwnerIter;
-typedef OwnerContainer< RenderTracker* > RenderTrackerContainer;
-typedef RenderTrackerContainer::Iterator RenderTrackerIter;
-typedef RenderTrackerContainer::ConstIterator RenderTrackerConstIter;
+typedef OwnerContainer< Render::RenderTracker* > RenderTrackerContainer;
+typedef RenderTrackerContainer::Iterator RenderTrackerIter;
+typedef RenderTrackerContainer::ConstIterator RenderTrackerConstIter;
/**
* Structure to contain internal data
*/
struct RenderManager::Impl
{
- Impl( Dali::Integration::GlAbstraction& glAbstraction,
- ResourcePostProcessList& resourcePostProcessQ,
- PostProcessResourceDispatcher& postProcessDispatcher )
+ Impl( Integration::GlAbstraction& glAbstraction,
+ Integration::GlSyncAbstraction& glSyncAbstraction,
+ LockedResourceQueue& textureUploadedQ,
+ TextureUploadedDispatcher& postProcessDispatcher,
+ GeometryBatcher& geometryBatcher )
: context( glAbstraction ),
+ glSyncAbstraction( glSyncAbstraction ),
renderQueue(),
textureCache( renderQueue, postProcessDispatcher, context ),
- resourcePostProcessQueue( resourcePostProcessQ ),
+ textureUploadedQueue( textureUploadedQ ),
instructions(),
backgroundColor( Dali::Stage::DEFAULT_BACKGROUND_COLOR ),
- frameTime( 0.0f ),
- lastFrameTime( 0.0f ),
frameCount( 0 ),
renderBufferIndex( SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX ),
defaultSurfaceRect(),
rendererContainer(),
+ samplerContainer(),
+ textureContainer(),
+ frameBufferContainer(),
renderersAdded( false ),
firstRenderCompleted( false ),
defaultShader( NULL ),
- programController( glAbstraction )
+ programController( glAbstraction ),
+ geometryBatcher( geometryBatcher )
{
}
{
}
- void AddRenderTracker( RenderTracker* renderTracker )
+ void AddRenderTracker( Render::RenderTracker* renderTracker )
{
DALI_ASSERT_DEBUG( renderTracker != NULL );
mRenderTrackers.PushBack( renderTracker );
}
- void RemoveRenderTracker( RenderTracker* renderTracker )
+ void RemoveRenderTracker( Render::RenderTracker* renderTracker )
{
DALI_ASSERT_DEBUG( renderTracker != NULL );
for(RenderTrackerIter iter = mRenderTrackers.Begin(), end = mRenderTrackers.End(); iter != end; ++iter)
// the order is important for destruction,
// programs are owned by context at the moment.
Context context; ///< holds the GL state
+ Integration::GlSyncAbstraction& glSyncAbstraction; ///< GL sync abstraction
RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread.
TextureCache textureCache; ///< Cache for all GL textures
- ResourcePostProcessList& resourcePostProcessQueue; ///< A queue for requesting resource post processing in update thread
+ Render::UniformNameCache uniformNameCache; ///< Cache to provide unique indices for uniforms
+ LockedResourceQueue& textureUploadedQueue; ///< A queue for requesting resource post processing in update thread
// Render instructions describe what should be rendered during RenderManager::Render()
// Owned by RenderManager. Update manager updates instructions for the next frame while we render the current one
Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame.
- volatile float frameTime; ///< The elapsed time since the previous frame
- float lastFrameTime; ///< Last frame delta.
-
unsigned int frameCount; ///< The current frame count
BufferIndex renderBufferIndex; ///< The index of the buffer to read from; this is opposite of the "update" buffer
Rect<int> defaultSurfaceRect; ///< Rectangle for the default surface we are rendering to
RendererOwnerContainer rendererContainer; ///< List of owned renderers
- RenderGeometryOwnerContainer renderGeometryContainer; ///< List of owned RenderGeometries
+ SamplerOwnerContainer samplerContainer; ///< List of owned samplers
+ TextureOwnerContainer textureContainer; ///< List of owned textures
+ FrameBufferOwnerContainer frameBufferContainer; ///< List of owned framebuffers
+ PropertyBufferOwnerContainer propertyBufferContainer; ///< List of owned property buffers
+ GeometryOwnerContainer geometryContainer; ///< List of owned Geometries
bool renderersAdded;
bool firstRenderCompleted; ///< False until the first render is done
Shader* defaultShader; ///< Default shader to use
ProgramController programController; ///< Owner of the GL programs
+
+ SceneGraph::GeometryBatcher& geometryBatcher; ///< Instance of geometry batcher
};
-RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQ )
+RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction,
+ Integration::GlSyncAbstraction& glSyncAbstraction,
+ SceneGraph::GeometryBatcher& geometryBatcher,
+ LockedResourceQueue& textureUploadedQ )
{
RenderManager* manager = new RenderManager;
- manager->mImpl = new Impl( glAbstraction, resourcePostProcessQ, *manager );
+ manager->mImpl = new Impl( glAbstraction, glSyncAbstraction, textureUploadedQ, *manager, geometryBatcher );
return manager;
}
RenderManager::~RenderManager()
{
+ for ( TextureOwnerIter iter = mImpl->textureContainer.Begin(); iter != mImpl->textureContainer.End(); ++iter )
+ {
+ (*iter)->Destroy( mImpl->context );
+ }
+
+ for ( FrameBufferOwnerIter iter = mImpl->frameBufferContainer.Begin(); iter != mImpl->frameBufferContainer.End(); ++iter )
+ {
+ (*iter)->Destroy( mImpl->context );
+ }
+
delete mImpl;
}
void RenderManager::ContextDestroyed()
{
- // @todo Set an atomic value to prevent render manager rendering again until
- // ContextCreated has been called.
-
mImpl->context.GlContextDestroyed();
mImpl->programController.GlContextDestroyed();
}
}
-void RenderManager::DispatchPostProcessRequest(ResourcePostProcessRequest& request)
+void RenderManager::DispatchTextureUploaded(ResourceId request)
{
- mImpl->resourcePostProcessQueue[ mImpl->renderBufferIndex ].push_back( request );
+ mImpl->textureUploadedQueue.PushBack( request );
}
void RenderManager::SetShaderSaver( ShaderSaver& upstream )
mImpl->backgroundColor = color;
}
-void RenderManager::SetFrameDeltaTime( float deltaTime )
-{
- Dali::Mutex::ScopedLock lock( mMutex );
- mImpl->frameTime = deltaTime;
-}
-
void RenderManager::SetDefaultSurfaceRect(const Rect<int>& rect)
{
mImpl->defaultSurfaceRect = rect;
void RenderManager::AddRenderer( Render::Renderer* renderer )
{
// Initialize the renderer as we are now in render thread
- renderer->Initialize( mImpl->context, mImpl->textureCache );
+ renderer->Initialize( mImpl->context, mImpl->textureCache, mImpl->uniformNameCache );
mImpl->rendererContainer.PushBack( renderer );
}
}
-void RenderManager::AddGeometry( RenderGeometry* renderGeometry )
+void RenderManager::AddSampler( Render::Sampler* sampler )
{
- mImpl->renderGeometryContainer.PushBack( renderGeometry );
+ mImpl->samplerContainer.PushBack( sampler );
}
-void RenderManager::RemoveGeometry( RenderGeometry* renderGeometry )
+void RenderManager::RemoveSampler( Render::Sampler* sampler )
{
- DALI_ASSERT_DEBUG( NULL != renderGeometry );
+ DALI_ASSERT_DEBUG( NULL != sampler );
- RenderGeometryOwnerContainer& geometries = mImpl->renderGeometryContainer;
+ SamplerOwnerContainer& samplers = mImpl->samplerContainer;
- // Find the renderer
- for ( RenderGeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+ // Find the sampler
+ for ( SamplerOwnerIter iter = samplers.Begin(); iter != samplers.End(); ++iter )
{
- if ( *iter == renderGeometry )
+ if ( *iter == sampler )
+ {
+ samplers.Erase( iter ); // Sampler found; now destroy it
+ break;
+ }
+ }
+}
+
+void RenderManager::AddTexture( Render::NewTexture* texture )
+{
+ mImpl->textureContainer.PushBack( texture );
+ texture->Initialize(mImpl->context);
+}
+
+void RenderManager::RemoveTexture( Render::NewTexture* texture )
+{
+ DALI_ASSERT_DEBUG( NULL != texture );
+
+ TextureOwnerContainer& textures = mImpl->textureContainer;
+
+ // Find the texture
+ for ( TextureOwnerIter iter = textures.Begin(); iter != textures.End(); ++iter )
+ {
+ if ( *iter == texture )
+ {
+ texture->Destroy( mImpl->context );
+ textures.Erase( iter ); // Texture found; now destroy it
+ break;
+ }
+ }
+}
+
+void RenderManager::UploadTexture( Render::NewTexture* texture, PixelDataPtr pixelData, const NewTexture::UploadParams& params )
+{
+ texture->Upload( mImpl->context, pixelData, params );
+}
+
+void RenderManager::GenerateMipmaps( Render::NewTexture* texture )
+{
+ texture->GenerateMipmaps( mImpl->context );
+}
+
+void RenderManager::SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode )
+{
+ sampler->mMinificationFilter = static_cast<Dali::FilterMode::Type>(minFilterMode);
+ sampler->mMagnificationFilter = static_cast<Dali::FilterMode::Type>(magFilterMode );
+}
+
+void RenderManager::SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
+{
+ sampler->mRWrapMode = static_cast<Dali::WrapMode::Type>(rWrapMode);
+ sampler->mSWrapMode = static_cast<Dali::WrapMode::Type>(sWrapMode);
+ sampler->mTWrapMode = static_cast<Dali::WrapMode::Type>(tWrapMode);
+}
+
+void RenderManager::AddFrameBuffer( Render::FrameBuffer* frameBuffer )
+{
+ mImpl->frameBufferContainer.PushBack( frameBuffer );
+ frameBuffer->Initialize(mImpl->context);
+}
+
+void RenderManager::RemoveFrameBuffer( Render::FrameBuffer* frameBuffer )
+{
+ DALI_ASSERT_DEBUG( NULL != frameBuffer );
+
+ FrameBufferOwnerContainer& framebuffers = mImpl->frameBufferContainer;
+
+ // Find the sampler
+ for ( FrameBufferOwnerIter iter = framebuffers.Begin(); iter != framebuffers.End(); ++iter )
+ {
+ if ( *iter == frameBuffer )
+ {
+ frameBuffer->Destroy( mImpl->context );
+ framebuffers.Erase( iter ); // frameBuffer found; now destroy it
+ break;
+ }
+ }
+}
+
+void RenderManager::AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer )
+{
+ frameBuffer->AttachColorTexture( mImpl->context, texture, mipmapLevel, layer );
+}
+
+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<char>* data, size_t size )
+{
+ propertyBuffer->SetData( data, size );
+}
+
+void RenderManager::SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
+{
+ geometry->SetIndexBuffer( indices );
+}
+
+void RenderManager::AddGeometry( Render::Geometry* geometry )
+{
+ mImpl->geometryContainer.PushBack( geometry );
+}
+
+void RenderManager::RemoveGeometry( Render::Geometry* geometry )
+{
+ DALI_ASSERT_DEBUG( NULL != geometry );
+
+ GeometryOwnerContainer& geometries = mImpl->geometryContainer;
+
+ // Find the geometry
+ for ( GeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+ {
+ if ( *iter == geometry )
{
geometries.Erase( iter ); // Geometry found; now destroy it
break;
}
}
-void RenderManager::AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage )
+void RenderManager::AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer )
{
- DALI_ASSERT_DEBUG( NULL != renderGeometry );
+ DALI_ASSERT_DEBUG( NULL != geometry );
- RenderGeometryOwnerContainer& geometries = mImpl->renderGeometryContainer;
+ GeometryOwnerContainer& geometries = mImpl->geometryContainer;
// Find the renderer
- for ( RenderGeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+ for ( GeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
{
- if ( *iter == renderGeometry )
+ if ( *iter == geometry )
{
- (*iter)->AddPropertyBuffer( propertyBuffer, target, usage );
+ (*iter)->AddPropertyBuffer( propertyBuffer );
break;
}
}
}
-void RenderManager::RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer )
+void RenderManager::RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer )
{
- DALI_ASSERT_DEBUG( NULL != renderGeometry );
+ DALI_ASSERT_DEBUG( NULL != geometry );
- RenderGeometryOwnerContainer& geometries = mImpl->renderGeometryContainer;
+ GeometryOwnerContainer& geometries = mImpl->geometryContainer;
// Find the renderer
- for ( RenderGeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+ for ( GeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
{
- if ( *iter == renderGeometry )
+ if ( *iter == geometry )
{
(*iter)->RemovePropertyBuffer( propertyBuffer );
break;
}
}
+void RenderManager::SetGeometryType( Render::Geometry* geometry, unsigned int geometryType )
+{
+ geometry->SetType( Render::Geometry::Type(geometryType) );
+}
-void RenderManager::AddRenderTracker( RenderTracker* renderTracker )
+void RenderManager::AddRenderTracker( Render::RenderTracker* renderTracker )
{
mImpl->AddRenderTracker(renderTracker);
}
-void RenderManager::RemoveRenderTracker( RenderTracker* renderTracker )
+void RenderManager::RemoveRenderTracker( Render::RenderTracker* renderTracker )
{
mImpl->RemoveRenderTracker(renderTracker);
}
// Core::Render documents that GL context must be current before calling Render
DALI_ASSERT_DEBUG( mImpl->context.IsGlContextCreated() );
- status.SetHasRendered( false );
-
// Increment the frame count at the beginning of each frame
++(mImpl->frameCount);
- mImpl->context.SetFrameCount(mImpl->frameCount);
- mImpl->context.ClearRendererCount();
- mImpl->context.ClearCulledCount();
-
- PERF_MONITOR_START(PerformanceMonitor::DRAW_NODES);
-
- SET_SNAPSHOT_FRAME_LOG_LEVEL;
// Process messages queued during previous update
mImpl->renderQueue.ProcessMessages( mImpl->renderBufferIndex );
// reset the program matrices for all programs once per frame
// this ensures we will set view and projection matrix once per program per camera
- // @todo move programs out of context onto a program controller and let that handle this
mImpl->programController.ResetProgramMatrices();
// if we don't have default shader, no point doing the render calls
{
RenderInstruction& instruction = mImpl->instructions.At( mImpl->renderBufferIndex, i );
- DoRender( instruction, *mImpl->defaultShader, mImpl->lastFrameTime );
-
- const RenderListContainer::SizeType countRenderList = instruction.RenderListCount();
- if ( countRenderList > 0 )
- {
- status.SetHasRendered( true );
- }
+ DoRender( instruction, *mImpl->defaultShader );
}
GLenum attachments[] = { GL_DEPTH, GL_STENCIL };
mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
}
}
- PERF_MONITOR_END(PerformanceMonitor::DRAW_NODES);
-
- SetLastFrameTime();
-
- // check if anything has been posted to the update thread
- bool updateRequired = !mImpl->resourcePostProcessQueue[ mImpl->renderBufferIndex ].empty();
-
//Notify RenderGeometries that rendering has finished
- for ( RenderGeometryOwnerIter iter = mImpl->renderGeometryContainer.Begin(); iter != mImpl->renderGeometryContainer.End(); ++iter )
+ for ( GeometryOwnerIter iter = mImpl->geometryContainer.Begin(); iter != mImpl->geometryContainer.End(); ++iter )
{
(*iter)->OnRenderFinished();
}
DALI_PRINT_RENDER_END();
- DALI_PRINT_RENDERER_COUNT(mImpl->frameCount, mImpl->context.GetRendererCount());
- DALI_PRINT_CULL_COUNT(mImpl->frameCount, mImpl->context.GetCulledCount());
-
- return updateRequired;
-}
-
-void RenderManager::SetLastFrameTime()
-{
- Dali::Mutex::ScopedLock lock(mMutex);
- mImpl->lastFrameTime = mImpl->frameTime;
+ // check if anything has been posted to the update thread, if IsEmpty then no update required.
+ return !mImpl->textureUploadedQueue.IsEmpty();
}
-void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime )
+void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultShader )
{
Rect<int> viewportRect;
Vector4 clearColor;
return;
}
}
+ else if( instruction.mFrameBuffer != 0 )
+ {
+ instruction.mFrameBuffer->Bind( mImpl->context );
+ if ( instruction.mIsViewportSet )
+ {
+ // For glViewport the lower-left corner is (0,0)
+ const int y = ( instruction.mFrameBuffer->GetHeight() - instruction.mViewport.height ) - instruction.mViewport.y;
+ viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
+ }
+ else
+ {
+ viewportRect.Set( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
+ }
+ }
else // !(instruction.mOffscreenTexture)
{
// switch rendering to adaptor provided (default) buffer
mImpl->context,
mImpl->textureCache,
defaultShader,
- mImpl->renderBufferIndex,
- elapsedTime );
+ mImpl->geometryBatcher,
+ mImpl->renderBufferIndex );
if(instruction.mOffscreenTextureId != 0)
{
if( instruction.mRenderTracker && offscreen != NULL )
{
- instruction.mRenderTracker->CreateSyncObject();
+ // This will create a sync object every frame this render tracker
+ // is alive (though it should be now be created only for
+ // render-once render tasks)
+ instruction.mRenderTracker->CreateSyncObject( mImpl->glSyncAbstraction );
instruction.mRenderTracker = NULL; // Only create once.
}
}