/*
- * 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/gl-resources/frame-buffer-texture.h>
#include <dali/internal/render/gl-resources/texture-cache.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 ),
frameCount( 0 ),
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
Render::UniformNameCache uniformNameCache; ///< Cache to provide unique indices for uniforms
- ResourcePostProcessList& resourcePostProcessQueue; ///< A queue for requesting resource post processing in update thread
+ 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
RendererOwnerContainer rendererContainer; ///< List of owned renderers
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
- RenderGeometryOwnerContainer renderGeometryContainer; ///< List of owned RenderGeometries
+ 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 )
}
}
+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->SetFilterMode( (Dali::FilterMode::Type)minFilterMode, (Dali::FilterMode::Type)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 uWrapMode, unsigned int vWrapMode )
+void RenderManager::SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
{
- sampler->SetWrapMode( (Dali::WrapMode::Type)uWrapMode, (Dali::WrapMode::Type)vWrapMode );
+ 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 )
propertyBuffer->SetFormat( format );
}
-void RenderManager::SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data)
+void RenderManager::SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size )
{
- propertyBuffer->SetData( data );
+ propertyBuffer->SetData( data, size );
}
-void RenderManager::SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size )
+void RenderManager::SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
{
- propertyBuffer->SetSize( size );
+ geometry->SetIndexBuffer( indices );
}
-void RenderManager::AddGeometry( RenderGeometry* renderGeometry )
+void RenderManager::AddGeometry( Render::Geometry* geometry )
{
- mImpl->renderGeometryContainer.PushBack( renderGeometry );
+ mImpl->geometryContainer.PushBack( geometry );
}
-void RenderManager::RemoveGeometry( RenderGeometry* renderGeometry )
+void RenderManager::RemoveGeometry( Render::Geometry* geometry )
{
- DALI_ASSERT_DEBUG( NULL != renderGeometry );
+ DALI_ASSERT_DEBUG( NULL != geometry );
- RenderGeometryOwnerContainer& geometries = mImpl->renderGeometryContainer;
+ GeometryOwnerContainer& geometries = mImpl->geometryContainer;
// Find the geometry
- for ( RenderGeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+ for ( GeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
{
- if ( *iter == renderGeometry )
+ if ( *iter == geometry )
{
geometries.Erase( iter ); // Geometry found; now destroy it
break;
}
}
-void RenderManager::AddPropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer )
+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, isIndexBuffer );
+ (*iter)->AddPropertyBuffer( propertyBuffer );
break;
}
}
}
-void RenderManager::RemovePropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* 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( RenderGeometry* geometry, int type )
+void RenderManager::SetGeometryType( Render::Geometry* geometry, unsigned int geometryType )
{
- geometry->SetGeometryType( static_cast<Geometry::GeometryType>(type) );
+ geometry->SetType( Render::Geometry::Type(geometryType) );
}
-void RenderManager::SetGeometryRequiresDepthTest( RenderGeometry* geometry, bool requiresDepthTest )
-{
- geometry->SetRequiresDepthTest( requiresDepthTest );
-}
-
-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 );
RenderInstruction& instruction = mImpl->instructions.At( mImpl->renderBufferIndex, i );
DoRender( instruction, *mImpl->defaultShader );
-
- const RenderListContainer::SizeType countRenderList = instruction.RenderListCount();
- if ( countRenderList > 0 )
- {
- status.SetHasRendered( true );
- }
}
GLenum attachments[] = { GL_DEPTH, GL_STENCIL };
mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
}
}
- PERF_MONITOR_END(PerformanceMonitor::DRAW_NODES);
-
- // 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;
+ // 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 )
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->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.
}
}