#include <dali/internal/render/gl-resources/bitmap-texture.h>
#include <dali/internal/render/renderers/render-geometry.h>
-#include <dali/internal/render/renderers/render-image-renderer.h>
-#include <dali/internal/render/renderers/render-new-renderer.h>
#include <dali/internal/render/renderers/render-property-buffer.h>
#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/renderers/render-sampler.h>
const int IMAGE_ACTOR_MEMORY_SIZE(
sizeof( Internal::ImageActor ) +
sizeof( Internal::SceneGraph::Node ) +
- sizeof( Internal::Render::ImageRenderer ));
+ sizeof( Internal::Render::Renderer ));
const int LAYER_MEMORY_SIZE(
sizeof( Internal::Layer ) +
sizeof( Internal::ActorAttachment ) +
const int RENDERER_MEMORY_SIZE(
sizeof( Internal::Renderer ) +
sizeof( Internal::SceneGraph::Renderer ) +
- sizeof( Internal::Render::NewRenderer ) );
+ sizeof( Internal::Render::Renderer ) );
const int GEOMETRY_MEMORY_SIZE(
sizeof( Internal::Geometry ) +
sizeof( Internal::SceneGraph::Geometry ) +
+++ /dev/null
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
-
-using Dali::Internal::SceneGraph::Shader;
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-RenderableAttachment::RenderableAttachment( EventThreadServices& eventThreadServices )
-: ActorAttachment( eventThreadServices )
-{
-}
-
-RenderableAttachment::~RenderableAttachment()
-{
-}
-
-void RenderableAttachment::OnStageConnection()
-{
- // For derived classes
- OnStageConnection2();
-}
-
-void RenderableAttachment::OnStageDisconnection()
-{
- // For derived classes
- OnStageDisconnection2();
-}
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_RENDERABLE_ATTACHMENT_H__
-#define __DALI_INTERNAL_RENDERABLE_ATTACHMENT_H__
-
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-class RenderableAttachment;
-}
-
-/**
- * An base class for renderable actor attachments
- */
-class RenderableAttachment : public ActorAttachment
-{
-public:
-
-
-
-protected:
-
- /**
- * Protected constructor; only base classes are instantiatable.
- * @param[in] eventThreadServices Used for messaging to and reading from scene-graph.
- */
- RenderableAttachment( EventThreadServices& eventThreadServices );
-
- /**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~RenderableAttachment();
-
-private:
-
- // Undefined
- RenderableAttachment(const RenderableAttachment&);
-
- // Undefined
- RenderableAttachment& operator=(const RenderableAttachment& rhs);
-
- /**
- * Helper for getting the scene-graph renderable attachment.
- * @return The scene object.
- */
- const SceneGraph::RenderableAttachment& GetSceneAttachment() const;
-
- /**
- * @copydoc Dali::Internal::ActorAttachment::OnStageConnection()
- */
- virtual void OnStageConnection();
-
- /**
- * @copydoc Dali::Internal::ActorAttachment::OnStageDisconnection()
- */
- virtual void OnStageDisconnection();
-
- /**
- * For derived classes, chained from OnStageConnection()
- */
- virtual void OnStageConnection2() = 0;
-
- /**
- * For derived classes, chained from OnStageDisconnection()
- */
- virtual void OnStageDisconnection2() = 0;
-
-private: // Data, cached for actor-thread getters
-
-};
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_RENDERABLE_ATTACHMENT_H__
Vector2 mTextureCoord;
};
-GeometryPtr CreateQuadGeometry( const Vector2& size, int imageWidth, int imageHeight, const Dali::ImageActor::PixelArea& pixelArea )
+GeometryPtr CreateQuadGeometry( const Vector2& size, unsigned int imageWidth, unsigned int imageHeight, const Dali::ImageActor::PixelArea& pixelArea )
{
const float halfWidth = size.width * 0.5f;
const float halfHeight = size.height * 0.5f;
return geometry;
}
-GeometryPtr CreateGridGeometry( const Vector2& size, unsigned int gridWidth, unsigned int gridHeight, int imageWidth, int imageHeight, const Dali::ImageActor::PixelArea& pixelArea )
+GeometryPtr CreateGridGeometry( const Vector2& size, unsigned int gridWidth, unsigned int gridHeight, unsigned int imageWidth, unsigned int imageHeight, const Dali::ImageActor::PixelArea& pixelArea )
{
// Create vertices
std::vector< GridVertex > vertices;
void ImageActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
{
- int imageWidth = 1;
- int imageHeight = 1;
-
- ImagePtr image = GetImage();
-
- if( image )
- {
- imageWidth = image->GetWidth();
- imageHeight = image->GetHeight();
- }
-
unsigned int gridWidth = 1;
unsigned int gridHeight = 1;
if( mShaderEffect )
gridHeight = std::min( MAXIMUM_GRID_SIZE, gridHeight );
}
+ unsigned int imageWidth = 1u;
+ unsigned int imageHeight = 1u;
+ ImagePtr image = GetImage();
+ if( image )
+ {
+ imageWidth = image->GetWidth();
+ imageHeight = image->GetHeight();
+ }
+
GeometryPtr quad = gridWidth <= 1 && gridHeight <= 1 ?
CreateQuadGeometry( size, imageWidth, imageHeight, mPixelArea ) :
CreateGridGeometry( size, gridWidth, gridHeight, imageWidth, imageHeight, mPixelArea );
mRenderer->SetGeometry( *quad );
Vector4 textureRect( 0.f, 0.f, 1.f, 1.f );
- if( mIsPixelAreaSet )
- {
- ImagePtr image = GetImage();
- if( image )
- {
- int imageWidth = image->GetWidth();
- int imageHeight = image->GetHeight();
-
- const float uScale = 1.0f / float(imageWidth);
- const float vScale = 1.0f / float(imageHeight);
- const float x = uScale * float(mPixelArea.x);
- const float y = vScale * float(mPixelArea.y);
- const float width = uScale * float(mPixelArea.width);
- const float height = vScale * float(mPixelArea.height);
-
- // bottom left
- textureRect.x = x;
- textureRect.y = y;
-
- // top right
- textureRect.z = x + width;
- textureRect.w = y + height;
- }
+ if( mIsPixelAreaSet && image )
+ {
+ const float uScale = 1.0f / float(imageWidth);
+ const float vScale = 1.0f / float(imageHeight);
+ const float x = uScale * float(mPixelArea.x);
+ const float y = vScale * float(mPixelArea.y);
+ const float width = uScale * float(mPixelArea.width);
+ const float height = vScale * float(mPixelArea.height);
+
+ // bottom left
+ textureRect.x = x;
+ textureRect.y = y;
+
+ // top right
+ textureRect.z = x + width;
+ textureRect.w = y + height;
}
Material* material = mRenderer->GetMaterial();
\
$(internal_src_dir)/event/actor-attachments/actor-attachment-impl.cpp \
$(internal_src_dir)/event/actor-attachments/camera-attachment-impl.cpp \
- $(internal_src_dir)/event/actor-attachments/renderable-attachment-impl.cpp \
$(internal_src_dir)/event/actors/actor-impl.cpp \
$(internal_src_dir)/event/actors/custom-actor-internal.cpp \
$(internal_src_dir)/event/actors/image-actor-impl.cpp \
$(internal_src_dir)/render/gl-resources/texture-cache.cpp \
$(internal_src_dir)/render/queue/render-queue.cpp \
$(internal_src_dir)/render/renderers/render-geometry.cpp \
- $(internal_src_dir)/render/renderers/render-new-renderer.cpp \
$(internal_src_dir)/render/renderers/render-property-buffer.cpp \
- $(internal_src_dir)/render/renderers/render-image-renderer.cpp \
$(internal_src_dir)/render/renderers/render-renderer.cpp \
$(internal_src_dir)/render/shaders/custom-uniform.cpp \
$(internal_src_dir)/render/shaders/program.cpp \
$(internal_src_dir)/update/gestures/scene-graph-pan-gesture.cpp \
$(internal_src_dir)/update/queue/update-message-queue.cpp \
$(internal_src_dir)/update/touch/touch-resampler.cpp \
- $(internal_src_dir)/update/manager/prepare-render-algorithms.cpp \
$(internal_src_dir)/update/manager/prepare-render-instructions.cpp \
$(internal_src_dir)/update/manager/process-render-tasks.cpp \
$(internal_src_dir)/update/manager/update-algorithms.cpp \
$(internal_src_dir)/update/manager/update-manager-debug.cpp \
$(internal_src_dir)/update/node-attachments/node-attachment.cpp \
$(internal_src_dir)/update/node-attachments/scene-graph-camera-attachment.cpp \
- $(internal_src_dir)/update/node-attachments/scene-graph-renderable-attachment.cpp \
$(internal_src_dir)/update/nodes/node.cpp \
$(internal_src_dir)/update/nodes/node-messages.cpp \
$(internal_src_dir)/update/nodes/scene-graph-layer.cpp \
+++ /dev/null
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/internal/render/renderers/render-image-renderer.h>
-
-// EXTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h>
-#include <dali/integration-api/debug.h>
-#include <dali/internal/common/internal-constants.h>
-#include <dali/internal/render/common/performance-monitor.h>
-#include <dali/internal/render/common/vertex.h>
-#include <dali/internal/render/gl-resources/gpu-buffer.h>
-#include <dali/internal/render/gl-resources/texture.h>
-#include <dali/internal/render/gl-resources/texture-cache.h>
-#include <dali/internal/render/gl-resources/texture-units.h>
-#include <dali/internal/render/shaders/program.h>
-#include <dali/internal/render/shaders/scene-graph-shader.h>
-#include <dali/internal/update/controllers/scene-controller.h>
-
-
-namespace
-{
-#if defined(DEBUG_ENABLED)
-Debug::Filter* gImageRenderFilter=Debug::Filter::New(Debug::NoLogging, false, "LOG_IMAGE_RENDERER");
-#endif
-
-/**
- * VertexToTextureCoord
- * Represents a mapping between a 1 dimensional vertex coordinate
- * and a 1 dimensional texture coordinate.
- */
-struct VertexToTextureCoord
-{
- /**
- * @param[in] xVertex Vertex coordinate
- * @param[in] uTexture Texture coordinate
- */
- VertexToTextureCoord(float xVertex, float uTexture)
- : x(xVertex),
- u(uTexture)
- {
- }
-
- float x; ///< 1D Vertex position
- float u; ///< 1D Texture position
-};
-
-/**
- * Generates a list of equally spaced intervals along a line, including
- * intervals at the points specified in insertionList.
- * The line starts from insertionList.begin() and ends at insertionList.end()-1
- * The number of intervals and spacing of these intervals is specified by
- * the caller.
- * @param[out] intervalList An empty vector to be populated with the list of intervals.
- * @param[in] intervals The number of intervals to be generated.
- * @param[in] insertionList A vector containing the points on the line to be inserted.
- */
-void GenerateIntervals(std::vector<VertexToTextureCoord>& intervalList, int intervals, const std::vector<VertexToTextureCoord>& insertionList)
-{
- DALI_ASSERT_DEBUG(insertionList.size() >= 2);
- DALI_ASSERT_DEBUG(intervals > 0);
-
- std::vector<VertexToTextureCoord>::const_iterator iter = insertionList.begin();
- if( iter != insertionList.end() )
- {
- std::vector<VertexToTextureCoord>::const_iterator end = insertionList.end()-1;
-
- const float length = end->x - iter->x;
- const float intervalSize = length / static_cast<float>(intervals);
- float x = iter->x;
-
- for(;iter!=end;++iter)
- {
- float x0 = iter[0].x;
- float u0 = iter[0].u;
- float x1 = iter[1].x;
- float u1 = iter[1].u;
-
- for(;x<x1;x+=intervalSize)
- {
- float progress = (x - x0) / (x1 - x0); // progress value between current interval and next.
- float u = u0 + (u1 - u0) * progress; // u 1D texture coordinate value for this x position.
- intervalList.push_back( VertexToTextureCoord( x, u ) );
- }
- intervalList.push_back( VertexToTextureCoord( x1, u1 ) );
- }
- }
-}
-
-}
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace Render
-{
-
-ImageRenderer* ImageRenderer::New()
-{
- return new ImageRenderer();
-}
-
-ImageRenderer::~ImageRenderer()
-{
- if ( mTextureId > 0 )
- {
- mTextureCache->RemoveObserver(mTextureId, this);
- }
-
- GlCleanup();
-}
-
-void ImageRenderer::SetTextureId( ResourceId textureId )
-{
- if ( mTextureId > 0 )
- {
- mTextureCache->RemoveObserver(mTextureId, this);
- }
-
- mTextureId = textureId;
- mTexture = NULL;
-
- if ( textureId > 0 )
- {
- mTextureCache->AddObserver(textureId, this);
- }
-}
-
-void ImageRenderer::SetPixelArea( const ImageRenderer::PixelArea& pixelArea )
-{
- mUsePixelArea = true;
- mPixelArea = pixelArea;
- mIsMeshGenerated = false;
-}
-
-void ImageRenderer::SetNinePatchBorder( const Vector4& border, bool inPixels )
-{
- mBorder = border;
- mBorderInPixels = inPixels;
- mIsMeshGenerated = false;
-}
-
-void ImageRenderer::SetUseBlend( bool useBlend )
-{
- mUseBlend = useBlend;
-}
-
-void ImageRenderer::SetBlendingOptions( unsigned int options )
-{
- mBlendingOptions.SetBitmask( options );
-}
-
-void ImageRenderer::SetBlendColor( const Vector4& color )
-{
- mBlendingOptions.SetBlendColor( color );
-}
-
-void ImageRenderer::CalculateMeshData( MeshType type, const Vector2& targetSize, bool usePixelArea )
-{
- mMeshType = type;
- mGeometrySize = targetSize;
- mUsePixelArea = usePixelArea;
- mIsMeshGenerated = false;
-}
-
-void ImageRenderer::TextureDiscarded( ResourceId textureId )
-{
- DALI_ASSERT_DEBUG( mTextureId == textureId || mTextureId == 0 );
-
- mTextureId = 0;
- mTexture = NULL;
-}
-
-void ImageRenderer::GlContextDestroyed()
-{
- if( mVertexBuffer )
- {
- mVertexBuffer->GlContextDestroyed();
- }
- if( mIndexBuffer )
- {
- mIndexBuffer->GlContextDestroyed();
- }
- // force recreation of the geometry in next render
- mIsMeshGenerated = false;
-}
-
-void ImageRenderer::GlCleanup()
-{
- DALI_LOG_INFO( gImageRenderFilter, Debug::Verbose, "GlCleanup() textureId=%d texture:%p\n", mTextureId, mTexture);
-
- mVertexBuffer.Reset();
- mIndexBuffer.Reset();
-}
-
-bool ImageRenderer::RequiresDepthTest() const
-{
- return false;
-}
-
-bool ImageRenderer::CheckResources()
-{
- if( mTexture == NULL )
- {
- if ( mTextureCache )
- {
- mTexture = mTextureCache->GetTexture( mTextureId );
- }
- }
-
- if( mTexture == NULL )
- {
- return false;
- }
-
- if( ( mTexture->GetWidth() <= 0u ) ||
- ( mTexture->GetHeight() <= 0u ) )
- {
- return false;
- }
-
- Integration::ResourceId shaderTextureId = mShader->GetTextureIdToRender();
-
- if( shaderTextureId && mTextureCache->GetTexture( shaderTextureId ) == NULL )
- {
- return false;
- }
-
- return true;
-}
-
-void ImageRenderer::DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
-{
- DALI_LOG_INFO( gImageRenderFilter, Debug::Verbose, "DoRender() textureId=%d texture:%p\n", mTextureId, mTexture);
-
- DALI_ASSERT_DEBUG( 0 != mTextureId && "ImageRenderer::DoRender. mTextureId == 0." );
- DALI_ASSERT_DEBUG( NULL != mTexture && "ImageRenderer::DoRender. mTexture == NULL." );
-
- if(! mIsMeshGenerated )
- {
- GenerateMeshData( mTexture );
- }
-
- DALI_ASSERT_DEBUG( mVertexBuffer );
-
- mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TEXTURE_UNIT_IMAGE );
-
- if( mTexture->GetTextureId() == 0 )
- {
- return; // early out if we haven't got a GL texture yet (e.g. due to context loss)
- }
-
- mTexture->ApplySampler( TEXTURE_UNIT_IMAGE, mSamplerBitfield );
-
- // Set sampler uniform
- GLint samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER );
- if( -1 != samplerLoc )
- {
- // set the uniform
- program.SetUniform1i( samplerLoc, TEXTURE_UNIT_IMAGE );
- }
-
- // make sure the vertex is bound, this has to be done before
- // we call VertexAttribPointer otherwise you get weird output on the display
- mVertexBuffer->Bind(GpuBuffer::ARRAY_BUFFER);
-
- samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER_RECT );
- if( -1 != samplerLoc )
- {
- UvRect uv;
-
- if ( mUsePixelArea )
- {
- mTexture->GetTextureCoordinates( uv, &mPixelArea );
- }
- else
- {
- mTexture->GetTextureCoordinates( uv, NULL );
- }
-
- // set the uniform
- program.SetUniform4f( samplerLoc, uv.u0, uv.v0, uv.u2, uv.v2 );
- }
-
- // Check whether the program supports the expected attributes/uniforms
- const GLint positionLoc = program.GetAttribLocation( Program::ATTRIB_POSITION );
- const GLint texCoordLoc = program.GetAttribLocation( Program::ATTRIB_TEXCOORD );
-
- if ( positionLoc != -1 )
- {
- context.EnableVertexAttributeArray( positionLoc );
-
- const int stride = 4 * sizeof(float);
- context.VertexAttribPointer( positionLoc, 2, GL_FLOAT, GL_FALSE, stride, 0 );
- }
-
- if ( texCoordLoc != -1 )
- {
- context.EnableVertexAttributeArray( texCoordLoc );
-
- const int stride = 4 * sizeof(float);
- context.VertexAttribPointer( texCoordLoc, 2, GL_FLOAT, GL_FALSE, stride, (const void*) (sizeof(float)*2) );
- }
-
- switch(mMeshType)
- {
- case QUAD:
- case NINE_PATCH:
- case NINE_PATCH_NO_CENTER:
- {
- const GLsizei vertexCount = mVertexBuffer->GetBufferSize() / sizeof(Vertex2D); // compiler will optimize this to >> if possible
- context.DrawArrays( GL_TRIANGLE_STRIP, 0, vertexCount );
- break;
- }
- case GRID_QUAD:
- case GRID_NINE_PATCH:
- case GRID_NINE_PATCH_NO_CENTER:
- {
- const GLsizei indexCount = mIndexBuffer->GetBufferSize() / sizeof(GLushort); // compiler will optimize this to >> if possible
- mIndexBuffer->Bind(GpuBuffer::ELEMENT_ARRAY_BUFFER);
- context.DrawElements( GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0 );
- break;
- }
- }
-
- if ( positionLoc != -1 )
- {
- context.DisableVertexAttributeArray( positionLoc );
- }
-
- if ( texCoordLoc != -1 )
- {
- context.DisableVertexAttributeArray( texCoordLoc );
- }
-}
-
-void ImageRenderer::DoSetBlending( Context& context )
-{
- // Set the blend color
- const Vector4* const customColor = mBlendingOptions.GetBlendColor();
- if( customColor )
- {
- context.SetCustomBlendColor( *customColor );
- }
- else
- {
- context.SetDefaultBlendColor();
- }
-
- // Set blend source & destination factors
- context.BlendFuncSeparate( mBlendingOptions.GetBlendSrcFactorRgb(),
- mBlendingOptions.GetBlendDestFactorRgb(),
- mBlendingOptions.GetBlendSrcFactorAlpha(),
- mBlendingOptions.GetBlendDestFactorAlpha() );
-
- // Set blend equations
- context.BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
- mBlendingOptions.GetBlendEquationAlpha() );
-
-}
-
-void ImageRenderer::UpdateVertexBuffer( Context& context, GLsizeiptr size, const GLvoid *data )
-{
- // create/destroy if needed/not needed.
- if ( size && !mVertexBuffer )
- {
- mVertexBuffer = new GpuBuffer( context );
- }
- else if ( !size && mVertexBuffer )
- {
- mVertexBuffer.Reset();
- }
-
- // update
- if ( mVertexBuffer )
- {
- mVertexBuffer->UpdateDataBuffer( size, data, GpuBuffer::DYNAMIC_DRAW, GpuBuffer::ARRAY_BUFFER);
- }
-}
-
-void ImageRenderer::UpdateIndexBuffer( Context& context, GLsizeiptr size, const GLvoid *data )
-{
- // create/destroy if needed/not needed.
- if ( size && !mIndexBuffer )
- {
- mIndexBuffer = new GpuBuffer( context );
- }
- else if ( !size && mIndexBuffer )
- {
- mIndexBuffer.Reset();
- }
-
- // update
- if ( mIndexBuffer )
- {
- mIndexBuffer->UpdateDataBuffer(size,data,GpuBuffer::STATIC_DRAW, GpuBuffer::ELEMENT_ARRAY_BUFFER);
- }
-}
-
-void ImageRenderer::GenerateMeshData( Texture* texture )
-{
- const PixelArea* pixelArea = NULL;
- if( mUsePixelArea )
- {
- pixelArea = &mPixelArea;
- }
-
- switch( mMeshType )
- {
- case ImageRenderer::QUAD:
- {
- SetQuadMeshData( texture, mGeometrySize, pixelArea );
- break;
- }
- case ImageRenderer::NINE_PATCH:
- {
- SetNinePatchMeshData( texture, mGeometrySize, mBorder, mBorderInPixels, pixelArea, false );
- break;
- }
- case ImageRenderer::NINE_PATCH_NO_CENTER:
- {
- SetNinePatchMeshData( texture, mGeometrySize, mBorder, mBorderInPixels, pixelArea, true );
- break;
- }
- case ImageRenderer::GRID_QUAD:
- {
- SetGridMeshData( texture, mGeometrySize, NULL, false, pixelArea );
- break;
- }
- case ImageRenderer::GRID_NINE_PATCH:
- case ImageRenderer::GRID_NINE_PATCH_NO_CENTER:
- {
- SetGridMeshData( texture, mGeometrySize, &mBorder, mBorderInPixels, pixelArea );
- break;
- }
- }
- mIsMeshGenerated = true;
-}
-
-void ImageRenderer::SetQuadMeshData( Texture* texture, const Vector2& size, const PixelArea* pixelArea )
-{
- const float x0 = -0.5f * size.x;
- const float y0 = -0.5f * size.y;
- const float x1 = 0.5f * size.x;
- const float y1 = 0.5f * size.y;
-
- /*
- * Here we render the square as a single square, as texture
- * coordinates linearly interpolate between the 4 vertices.
- *
- * Note: a square (or a quad) is rendered as 2 triangles.
- * Vertices 0,1,2 represent triangle A.
- * Vertices 1,2,3 represent triangle B.
- *
- * No indices are needed as we tell GL to render in strip mode
- * (GL_TRIANGLE_STRIP), which is faster, and consumes less
- * memory.
- *
- * 0---------2
- * | /|
- * | A / |
- * | / |
- * | / |
- * | / |
- * | / |
- * | / |
- * | / B |
- * |/ |
- * 1---------3
- */
-
- Vertex2D verts[]={
- {x0, y0, 0.0, 0.0},
- {x0, y1, 0.0, 1.0},
- {x1, y0, 1.0, 0.0},
- {x1, y1, 1.0, 1.0}
- };
-
- // We may only be displaying an area of the texture.
- // Calling MapUV converts the u,v values to correct values for the pixel area
-
- texture->MapUV( sizeof(verts)/sizeof(Vertex2D), verts, pixelArea );
-
- UpdateVertexBuffer( *mContext, sizeof(verts), verts );
- UpdateIndexBuffer( *mContext, 0, NULL );
-}
-
-void ImageRenderer::SetNinePatchMeshData( Texture* texture, const Vector2& size, const Vector4& border, bool borderInPixels, const PixelArea* pixelArea, bool noCenter )
-{
- DALI_ASSERT_ALWAYS( mTexture->GetWidth() > 0.0f && "Invalid Texture width" );
- DALI_ASSERT_ALWAYS( mTexture->GetHeight() > 0.0f && "Invalid Texture height" );
-
- float textureWidth = mTexture->GetWidth();
- float textureHeight = mTexture->GetHeight();
-
- float borderLeft, borderTop, borderRight, borderBottom; // pixels from edge
- float borderX0, borderY0, borderX1, borderY1; // In the range 0 -> 1
-
- if ( borderInPixels )
- {
- borderLeft = border.x;
- borderTop = border.y;
- borderRight = border.z;
- borderBottom = border.w;
-
- borderX0 = border.x / textureWidth;
- borderY0 = border.y / textureHeight;
- borderX1 = 1.0f - ( border.z / textureWidth );
- borderY1 = 1.0f - ( border.w / textureHeight );
- }
- else
- {
- borderLeft = textureWidth * border.x;
- borderTop = textureHeight * border.y;
- borderRight = textureWidth * (1.0f - border.z);
- borderBottom = textureHeight * (1.0f - border.w);
-
- borderX0 = border.x;
- borderY0 = border.y;
- borderX1 = border.z;
- borderY1 = border.w;
- }
-
- const float u0 = 0.0f;
- const float u3 = 1.0f;
- const float u1 = borderX0;
- const float u2 = borderX1;
-
- const float v0 = 0.0f;
- const float v3 = 1.0f;
- const float v1 = borderY0;
- const float v2 = borderY1;
-
- const float x0 = size.x * -0.5;
- const float x1 = x0 + borderLeft;
- const float x2 = x0 + size.x - borderRight;
- const float x3 = x0 + size.x;
-
- const float y0 = size.y * -0.5;
- const float y1 = y0 + borderTop;
- const float y2 = y0 + size.y - borderBottom;
- const float y3 = y0 + size.y;
-
-
- if ( !noCenter )
- {
- /*
- * We're breaking a quad in to 9 smaller quads, so that when it's
- * stretched the corners maintain their size.
- * For speed the 9-patch is drawn with a single triangle span, the draw
- * order of the span is 1->9.
- * Previously it would draw three separate spans (1->3, 4->6, 7->9), but now it
- * it does it one go by turning the corner when gets to the end of each row.
- *
- * No indices are needed as we tell GL to render in strip mode
- * (GL_TRIANGLE_STRIP), which is faster, and consumes less
- * memory.
- *
- * |---|---------------|---|
- * | 7| --> 8 | 9 |
- * |---|---------------|---|
- * | | | |
- * | 6 | <-- 5 | 4 |
- * | | | |
- * | | | |
- * |---|---------------|---|
- * | 1 | 2 --> | 3 |
- * |---|---------------|---|
- */
-
- Vertex2D vertsWithCenter[]={
- // bottom left
- { x0, y0, u0, v0 },
- { x0, y1, u0, v1 },
- { x1, y0, u1, v0 },
- { x1, y1, u1, v1 },
-
- // bottom middle
- { x2, y0, u2, v0 },
- { x2, y1, u2, v1 },
-
- // bottom right
- { x3, y0, u3, v0 },
- { x3, y1, u3, v1 },
-
- // turn the corner
- { x3, y1, u3, v1 },
- { x3, y1, u3, v1 },
-
- // 10 verts here
-
- // middle right
- { x3, y2, u3, v2 },
- { x2, y1, u2, v1 },
- { x2, y2, u2, v2 },
-
- // middle left
-
- { x1, y1, u1, v1 },
- { x1, y2, u1, v2 },
- { x0, y1, u0, v1 },
- { x0, y2, u0, v2 },
-
- // turn the corner
- { x0, y2, u0, v2 },
- { x0, y2, u0, v2 },
-
- // top left
- { x0, y3, u0, v3 },
- { x1, y2, u1, v2 },
- { x1, y3, u1, v3 },
-
- // top middle
- { x2, y2, u2, v2 },
- { x2, y3, u2, v3 },
-
- // top right
- { x3, y2, u3, v2 },
- { x3, y3, u3, v3 },
- };
-
- const size_t vertsSize = sizeof( vertsWithCenter );
- const unsigned int vertexCount = vertsSize / sizeof( vertsWithCenter[0] );
- texture->MapUV( vertexCount, vertsWithCenter, pixelArea );
- UpdateVertexBuffer( *mContext, vertsSize, vertsWithCenter );
- }
- else
- {
- /*
- * The center part is not going to be rendered. The 9-patch border is drawn with
- * a single triangle span, and the draw order of the span is 1->8.
- *
- * |---|---------------|---|
- * | 7 | <-- 6 | 5 |
- * |---|---------------|---|
- * | | | |
- * | | | |
- * | 8 | | 4 |
- * | | (not rendered)| |
- * | | | |
- * |---|---------------|---|
- * | 1 | 2 --> | 3 |
- * |---|---------------|---|
- */
-
- Vertex2D vertsWithNoCenter[]={
- // bottom left (1)
- { x0, y0, u0, v0 },
- { x0, y1, u0, v1 },
- { x1, y0, u1, v0 },
- { x1, y1, u1, v1 },
-
- // bottom middle (2)
- { x2, y0, u2, v0 },
- { x2, y1, u2, v1 },
-
- // bottom right (3)
- { x3, y0, u3, v0 },
- { x3, y1, u3, v1 },
-
- // reset the starting point to x3, y1
- { x3, y1, u3, v1 },
- { x3, y1, u3, v1 },
-
- // middle right (4)
- { x3, y2, u3, v2 },
- { x2, y1, u2, v1 },
- { x2, y2, u2, v2 },
-
- // corner turning
- { x2, y2, u2, v2 },
- { x3, y2, u3, v2 },
- { x3, y2, u3, v2 },
-
- // top right (5)
- { x3, y3, u3, v3 },
- { x2, y2, u2, v2 },
- { x2, y3, u2, v3 },
-
- // top middle (6)
- { x1, y2, u1, v2 },
- { x1, y3, u1, v3 },
-
- // reset point to x0,y3
- { x1, y3, u1, v3 },
- { x0, y3, u0, v3 },
- { x0, y3, u0, v3 },
-
- // top left box (starting from (x0,y3)) (7)
- { x0, y2, u0, v2 },
- { x1, y3, u1, v3 },
- { x1, y2, u1, v2 },
-
- // reset point
- { x1, y2, u1, v2 },
-
- // middle left (8)
- { x0, y2, u0, v2 },
- { x1, y1, u1, v2 },
- { x0, y1, u0, v2 },
- };
-
- const size_t vertsSize = sizeof( vertsWithNoCenter );
- const unsigned int vertexCount = vertsSize / sizeof( vertsWithNoCenter[0] );
- texture->MapUV( vertexCount, vertsWithNoCenter, pixelArea );
- UpdateVertexBuffer( *mContext, vertsSize, vertsWithNoCenter );
- }
- // not using an index buffer
- UpdateIndexBuffer( *mContext, 0, NULL );
-
-}
-
-void ImageRenderer::SetGridMeshData( Texture* texture, const Vector2& size, const Vector4* border, bool borderInPixels, const PixelArea* pixelArea )
-{
- /*
- * Quad Grid:
- * In Grid Mode, we tessellate the single quad into smaller quads
- * at approximately (guideGridSize x guideGridSize) in size.
- *
- * Conversion of Quad to Gridded Quad.
- *
- * |-----------| |---|---|---|
- * | | | | | |
- * | | -> |---|---|---|
- * | | | | | |
- * |-----------| |---|---|---|
- *
- * 9-Patch Grid:
- * In Grid Mode, we tessellate each quad of a 9-patch
- * (see SetNinePatchMeshData) into smaller quads at approximately
- * (guideGridSize x guideGridSize) in size.
- *
- * This satisfies the two requirements of a 9-patch with grid:
- *
- * 1. Texture coordinates within each section of the 9-patch
- * should change linearly to that 9-patch's rules.
- * 2. The image as as whole should provide Vertex points at
- * approximate guideGridSize intervals.
- *
- * The result should be the horizontal and vertical lines of
- * a 9-patch overlayed by the horizontal and vertical lines of
- * a grid.
- *
- * Non-overlayed:
- * | | | | | | | <- Grid Markers
- * -|-------|-------------------|-------|
- * | | | |
- * | 1 | 2 | 3 |
- * -| | | |
- * |-------+-------------------+-------|
- * | | | |
- * -| | | |
- * | | | |
- * | | | |
- * -| 4 | 5 | 6 | <- 9 Patch.
- * | | | |
- * | | | |
- * -| | | |
- * | | | |
- * |-------+-------------------+-------|
- * -| | | |
- * | 7 | 8 | 9 |
- * | | | |
- * -|-------|-------------------|-------|
- *
- *
- * Overlayed:
- * | | | | | | | <- Grid Markers
- * -|-------|-------------------|-------|
- * | | | | | | | | |
- * | | | | | | | | |
- * -|-----|-|---|-----|-----|---|-|-----|
- * |-------+-------------------+-------|
- * | | | | | | | | |
- * -|-----|-|---|-----|-----|---|-|-----|
- * | | | | | | | | |
- * | | | | | | | | |
- * -|-----|-|---|-----|-----|---|-|-----| <- 9 Patch.
- * | | | | | | | | |
- * | | | | | | | | |
- * -|-----|-|---|-----|-----|---|-|-----|
- * | | | | | | | | |
- * |-------+-------------------+-------|
- * -|-----|-|---|-----|-----|---|-|-----|
- * | | | | | | | | |
- * | | | | | | | | |
- * -|-------|-------------------|-------|
- */
-
- std::vector<VertexToTextureCoord> horizontalDivisions;
- std::vector<VertexToTextureCoord> verticalDivisions;
-
- const float guideGridSize = mShader->GetGridDensity();
-
- const int textureWidth = texture->GetWidth();
- const int textureHeight = texture->GetHeight();
-
- const float halfWidth = size.width * 0.5f;
- const float halfHeight = size.height * 0.5f;
-
- // Determine how many rectangles across and down to tesselate image into.
- const int guideRectX = (size.width / guideGridSize);
- const int guideRectY = (size.height / guideGridSize);
-
- // Build up list of points in X axis where vertices need to go.
- std::vector<VertexToTextureCoord> insertionList;
- insertionList.reserve(4);
- insertionList.push_back( VertexToTextureCoord( -halfWidth, 0.0f ) );
-
- // If 9-Patch Border exists, add additional border points in list.
- if(border)
- {
- float borderX0, borderX1, borderU0, borderU1;
-
- if ( borderInPixels )
- {
- borderX0 = border->x - halfWidth;
- borderX1 = halfWidth - border->z;
-
- borderU0 = border->x / textureWidth;
- borderU1 = 1.0f - (border->z / textureWidth);
- }
- else
- {
- borderX0 = border->x * textureWidth - halfWidth;
- borderX1 = halfWidth - (1.0f - border->z) * textureWidth;
- borderU0 = border->x;
- borderU1 = border->z;
- }
-
- insertionList.push_back( VertexToTextureCoord( borderX0, borderU0 ) );
- insertionList.push_back( VertexToTextureCoord( borderX1, borderU1 ) );
- }
-
- insertionList.push_back( VertexToTextureCoord( halfWidth, 1.0f ) );
- GenerateIntervals(horizontalDivisions, guideRectX + 2, insertionList);
-
- // Build up list of points in Y axis where vertices need to go.
- insertionList.clear();
- insertionList.push_back( VertexToTextureCoord( -halfHeight, 0.0f ) );
-
- // If 9-Patch Border exists, add additional border points in list.
- if(border)
- {
- float borderY0, borderY1, borderU0, borderU1;
-
- if ( borderInPixels )
- {
- borderY0 = border->y - halfHeight;
- borderY1 = halfHeight - border->w;
-
- borderU0 = border->y / textureHeight;
- borderU1 = 1.0f - (border->w / textureHeight);
- }
- else
- {
- borderY0 = border->y * textureHeight - halfHeight;
- borderY1 = halfHeight - (1.0f - border->w) * textureHeight;
-
- borderU0 = border->y;
- borderU1 = border->w;
- }
-
- insertionList.push_back( VertexToTextureCoord( borderY0, borderU0 ) );
- insertionList.push_back( VertexToTextureCoord( borderY1, borderU1 ) );
- }
-
- insertionList.push_back( VertexToTextureCoord( halfHeight, 1.0f ) );
- GenerateIntervals(verticalDivisions, guideRectY + 2, insertionList);
-
- // Now build up Vertex pattern based on the above X and Y lists.
- const int totalVertices = horizontalDivisions.size() * verticalDivisions.size();
- Vertex2D* vertices = new Vertex2D[totalVertices];
- Vertex2D* vertex = vertices;
-
- for(std::vector<VertexToTextureCoord>::const_iterator yIter = verticalDivisions.begin(); yIter != verticalDivisions.end(); ++yIter )
- {
- for(std::vector<VertexToTextureCoord>::const_iterator xIter = horizontalDivisions.begin(); xIter != horizontalDivisions.end(); ++xIter )
- {
- vertex->mX = xIter->x;
- vertex->mU = xIter->u;
- vertex->mY = yIter->x;
- vertex->mV = yIter->u;
- vertex++;
- }
- }
-
- // Build up Triangle indicies, very predictable pattern.
- const size_t rectX = horizontalDivisions.size() - 1;
- const size_t rectY = verticalDivisions.size() - 1;
- const size_t totalIndices = rectX * rectY * 6; // 2 triangles per quad (rect) and 3 points to define each triangle.
- GLushort* indices = new GLushort[totalIndices];
-
- GenerateMeshIndices(indices, rectX, rectY);
-
- texture->MapUV( totalVertices, vertices, pixelArea );
-
- UpdateVertexBuffer( *mContext, totalVertices * sizeof(Vertex2D) , vertices );
- UpdateIndexBuffer( *mContext, totalIndices * sizeof(GLushort), indices );
-
- delete[] vertices;
- delete[] indices;
-}
-
-void ImageRenderer::GenerateMeshIndices(GLushort* indices, int rectanglesX, int rectanglesY)
-{
- GLushort *i = indices;
- const int meshEndIndex = rectanglesY * (rectanglesX + 1);
-
- int index = 0;
- while(index < meshEndIndex)
- {
- const int rowEndIndex = index + rectanglesX;
- for (; index < rowEndIndex; index++ )
- {
- *i++ = index;
- *i++ = index + 1 + rectanglesX;
- *i++ = index + 1;
-
- *i++ = index + 1;
- *i++ = index + 1 + rectanglesX;
- *i++ = index + 2 + rectanglesX;
- }
- index++; // one extra vertex per row than rects.
- }
-}
-
-ImageRenderer::ImageRenderer()
-: Renderer(),
- mTexture( NULL ),
- mBorder( 0.45, 0.45, 0.1, 0.1 ),
- mPixelArea(),
- mGeometrySize(),
- mTextureId( 0 ),
- mMeshType( ImageRenderer::QUAD ),
- mIsMeshGenerated( false ),
- mBorderInPixels( false ),
- mUseBlend( false ),
- mUsePixelArea( false )
-{
-}
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_RENDER_IMAGE_RENDERER_H__
-#define __DALI_INTERNAL_RENDER_IMAGE_RENDERER_H__
-
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/public-api/actors/image-actor.h>
-#include <dali/internal/common/owner-pointer.h>
-#include <dali/internal/update/resources/resource-manager-declarations.h>
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/gl-resources/texture-observer.h>
-#include <dali/internal/render/renderers/render-renderer.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-class GpuBuffer;
-
-namespace SceneGraph
-{
-class NodeDataProvider;
-class TextureCache;
-}
-
-namespace Render
-{
-/**
- * Used to render an image.
- */
-class ImageRenderer : public Renderer, public TextureObserver
-{
-public:
-
- typedef Dali::ImageActor::PixelArea PixelArea;
-
- enum MeshType
- {
- QUAD,
- NINE_PATCH,
- NINE_PATCH_NO_CENTER,
- GRID_QUAD,
- GRID_NINE_PATCH,
- GRID_NINE_PATCH_NO_CENTER ///< Not supported yet.
- };
-
- /**
- * Create a new ImageRenderer.
- * @return The newly allocated ImageRenderer.
- */
- static ImageRenderer* New();
-
- /**
- * Virtual destructor
- */
- virtual ~ImageRenderer();
-
- /**
- * Set the texture used to render.
- * @param[in] textureId The id of the texture used to render.
- */
- void SetTextureId( ResourceId textureId );
-
- /**
- * Set the pixel area for the renderer
- * @param[in] pixelArea An area within the texture, used when building UV coordinates.
- */
- void SetPixelArea( const ImageRenderer::PixelArea& pixelArea );
-
- /**
- * Set 9 patch border for the image renderer
- * @param[in] border The border for nine-patch meshes.
- * @param[in] borderInPixels True if border is in pixels instead of percentages.
- */
- void SetNinePatchBorder( const Vector4& border, bool inPixels );
-
- /**
- * Set whether the ImageRenderer should use blending
- * @param[in] useBlend True if blending should be used.
- */
- void SetUseBlend( bool useBlend );
-
- /**
- * Set the blending options.
- * @param[in] options A bitmask of blending options.
- */
- void SetBlendingOptions( unsigned int options );
-
- /**
- * Set the blend color.
- * @param[in] color The new blend-color.
- */
- void SetBlendColor( const Vector4& color );
-
- /**
- * Calculate the mesh data used by the ImageRenderer.
- * @param[in] type The type of mesh data required; either quad, nine-patch or grid.
- * @param[in] targetSize The size which the mesh data should fit inside.
- * @param[in] usePixelArea whether to use pixel area or not
- */
- void CalculateMeshData( MeshType type, const Vector2& targetSize, bool usePixelArea );
-
- /**
- * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
- */
- virtual void GlContextDestroyed();
-
- /**
- * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
- */
- virtual void GlCleanup();
-
- /**
- * @copydoc Dali::Internal::SceneGraph::Renderer::RequiresDepthTest()
- */
- virtual bool RequiresDepthTest() const;
-
- /**
- * @copydoc Dali::Internal::SceneGraph::Renderer::CheckResources()
- */
- virtual bool CheckResources();
-
- /**
- * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
- */
- virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
-
- /**
- * @copydoc Dali::Internal::SceneGraph::Renderer::DoSetBlending()
- */
- virtual void DoSetBlending( Context& context );
-
-protected: // TextureObserver implementation
-
- /**
- * @copydoc Dali::Internal::TextureObserver::TextureDiscarded()
- */
- virtual void TextureDiscarded( ResourceId textureId );
-
-private:
- /**
- * Helper to update the vertex buffer.
- */
- void UpdateVertexBuffer( Context& context, GLsizeiptr size, const GLvoid *data );
-
- /**
- * Helper to update the index buffer.
- */
- void UpdateIndexBuffer( Context& context, GLsizeiptr size, const GLvoid *data );
-
- /**
- * Helper to generate mesh data when required
- * @param[in] texture Texture from which to get UV data
- */
- void GenerateMeshData( Texture* texture );
-
- /**
- * Helper to fill vertex/index buffers with quad data.
- * (Quads are simple meshes, and thus have a specialised mesh generation method)
- *
- * @param[in] texture Texture from which to get UV data
- * @param[in] size
- * @param[in] pixelArea An area within the texture, used when building UV coordinates. A value of NULL means use default image size.
- */
- void SetQuadMeshData( Texture* texture, const Vector2& size, const PixelArea* pixelArea );
-
- /**
- * Helper to fill vertex/index buffers with nine-patch data.
- * (9-Patches are simple meshes, and thus have a specialised mesh generation method)
- *
- * @param[in] texture Texture from which to get UV data
- * @param[in] size The target size.
- * @param[in] border 9 patch border information.
- * @param[in] borderInPixels True if border is in pixels instead of percentages.
- * @param[in] pixelArea An area within the texture, used when building UV coordinates. A value of NULL means use default image size.
- * @param[in] noCenter True if the center section of nine patch should not be rendered.
- */
- void SetNinePatchMeshData( Texture* texture, const Vector2& size, const Vector4& border, bool borderInPixels, const PixelArea* pixelArea, bool noCenter );
-
- /**
- * Helper to fill vertex/index buffers with grid data.
- * This can build grid meshes that are either of type Quad or type 9-Patch
- *
- * @param[in] size The target size.
- * @param[in] border 9 patch border information (pass NULL for no border i.e. a standard Quad)
- * @param[in] borderInPixels True if border is in pixels instead of percentages.
- * @param[in] pixelArea An area within the texture, used when building UV coordinates. A value of NULL means use default image size.
- */
- void SetGridMeshData( Texture* texture, const Vector2& size, const Vector4* border, bool borderInPixels, const PixelArea* pixelArea );
-
- /**
- * Helper to fill index buffer with uniform grid data.
- * @param[in] indices pointer to indices buffer to be filled
- * @param[in] rectanglesX number of columns for rectangles in grid
- * @param[in] rectanglesY number of rows for rectangles in grid
- */
- void GenerateMeshIndices(GLushort* indices, int rectanglesX, int rectanglesY);
-
- /**
- * Private constructor. @see New()
- */
- ImageRenderer();
-
- // Undefined
- ImageRenderer( const ImageRenderer& );
-
- // Undefined
- ImageRenderer& operator=( const ImageRenderer& rhs );
-
-private:
-
- Texture* mTexture;
-
- OwnerPointer< GpuBuffer > mVertexBuffer;
- OwnerPointer< GpuBuffer > mIndexBuffer;
-
- Vector4 mBorder;
- PixelArea mPixelArea;
- Vector2 mGeometrySize;
- ResourceId mTextureId;
-
- BlendingOptions mBlendingOptions;
-
- // flags
- MeshType mMeshType : 3; // 4 values fits in 3 bits just fine
- bool mIsMeshGenerated : 1;
- bool mBorderInPixels : 1;
- bool mUseBlend : 1; ///< True if blending should be enabled, 1 bit is enough
- bool mUsePixelArea : 1;
-
-};
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_RENDER_IMAGE_RENDERER_H__
+++ /dev/null
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "render-new-renderer.h"
-#include <dali/devel-api/common/hash.h>
-#include <dali/internal/common/image-sampler.h>
-#include <dali/internal/event/common/property-input-impl.h>
-#include <dali/internal/update/common/uniform-map.h>
-#include <dali/internal/render/data-providers/render-data-provider.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/texture.h>
-#include <dali/internal/render/gl-resources/texture-cache.h>
-#include <dali/internal/render/renderers/render-sampler.h>
-#include <dali/internal/render/shaders/program.h>
-
-
-namespace Dali
-{
-namespace Internal
-{
-namespace Render
-{
-
-NewRenderer* NewRenderer::New( SceneGraph::RenderDataProvider* dataProvider,
- SceneGraph::RenderGeometry* renderGeometry )
-{
- return new NewRenderer( dataProvider, renderGeometry);
-}
-
-
-NewRenderer::NewRenderer( SceneGraph::RenderDataProvider* dataProvider,
- SceneGraph::RenderGeometry* renderGeometry )
-: Renderer(),
- mRenderDataProvider( dataProvider ),
- mRenderGeometry( renderGeometry ),
- mUpdateAttributesLocation( true )
-{
-}
-
-NewRenderer::~NewRenderer()
-{
-}
-
-void NewRenderer::SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProvider )
-{
- mRenderDataProvider = dataProvider;
- mUpdateAttributesLocation = true;
-}
-
-void NewRenderer::SetGeometry( SceneGraph::RenderGeometry* renderGeometry )
-{
- mRenderGeometry = renderGeometry;
- mUpdateAttributesLocation = true;
-}
-
-// Note - this is currently called from UpdateThread, PrepareRenderInstructions,
-// as an optimisation.
-// @todo MESH_REWORK Should use Update thread objects only in PrepareRenderInstructions.
-bool NewRenderer::RequiresDepthTest() const
-{
- if( mRenderGeometry )
- {
- return mRenderGeometry->RequiresDepthTest();
- }
-
- return true;
-}
-
-bool NewRenderer::CheckResources()
-{
- // Query material to check it has texture pointers & image has size
- // Query geometry to check it has vertex buffers
-
- // General point though - why would we have a render item in RenderThread with no ready
- // resources in UpdateThread?
- return true;
-}
-
-void NewRenderer::DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex )
-{
- // Do nothing, we're going to set up the uniforms with our own code instead
-}
-
-void NewRenderer::DoSetCullFaceMode( Context& context )
-{
- const SceneGraph::MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
- context.CullFace( material.GetFaceCullingMode() );
-}
-
-void NewRenderer::DoSetBlending( Context& context )
-{
- const SceneGraph::MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
-
- // Blend color is optional and rarely used
- Vector4* blendColor = material.GetBlendColor();
- if( blendColor )
- {
- context.SetCustomBlendColor( *blendColor );
- }
- else
- {
- context.SetDefaultBlendColor();
- }
-
- const BlendingOptions& blending = material.GetBlendingOptions();
- // Set blend source & destination factors
- context.BlendFuncSeparate( blending.GetBlendSrcFactorRgb(),
- blending.GetBlendDestFactorRgb(),
- blending.GetBlendSrcFactorAlpha(),
- blending.GetBlendDestFactorAlpha() );
-
- // Set blend equations
- context.BlendEquationSeparate( blending.GetBlendEquationRgb(),
- blending.GetBlendEquationAlpha() );
-}
-
-void NewRenderer::DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
-{
- BindTextures( textureCache, program );
-
- SetUniforms( bufferIndex, node, program );
-
- if( mUpdateAttributesLocation || mRenderGeometry->AttributesChanged() )
- {
- mRenderGeometry->GetAttributeLocationFromProgram( mAttributesLocation, program, bufferIndex );
- mUpdateAttributesLocation = false;
- }
-
- mRenderGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation );
-}
-
-void NewRenderer::GlContextDestroyed()
-{
- mRenderGeometry->GlContextDestroyed();
-}
-
-void NewRenderer::GlCleanup()
-{
-}
-
-void NewRenderer::SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program )
-{
- // Check if the map has changed
- DALI_ASSERT_DEBUG( mRenderDataProvider && "No Uniform map data provider available" );
-
- const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
-
- if( uniformMapDataProvider.GetUniformMapChanged( bufferIndex ) ||
- node.GetUniformMapChanged(bufferIndex))
- {
- const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap( bufferIndex );
- const SceneGraph::CollectedUniformMap& uniformMapNode = node.GetUniformMap( bufferIndex );
-
- unsigned int maxMaps = uniformMap.Count() + uniformMapNode.Count();
- mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
- mUniformIndexMap.Resize( maxMaps );
-
- unsigned int mapIndex(0);
- for(; mapIndex < uniformMap.Count() ; ++mapIndex )
- {
- mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex]->propertyPtr;
- mUniformIndexMap[mapIndex].uniformIndex = program.RegisterUniform( uniformMap[mapIndex]->uniformName );
- }
-
- for( unsigned int nodeMapIndex = 0; nodeMapIndex < uniformMapNode.Count() ; ++nodeMapIndex )
- {
- unsigned int uniformIndex = program.RegisterUniform( uniformMapNode[nodeMapIndex]->uniformName );
- bool found(false);
- for( unsigned int i(0); i<uniformMap.Count(); ++i )
- {
- if( mUniformIndexMap[i].uniformIndex == uniformIndex )
- {
- mUniformIndexMap[i].propertyValue = uniformMapNode[nodeMapIndex]->propertyPtr;
- found = true;
- break;
- }
- }
-
- if( !found )
- {
- mUniformIndexMap[mapIndex].propertyValue = uniformMapNode[nodeMapIndex]->propertyPtr;
- mUniformIndexMap[mapIndex].uniformIndex = uniformIndex;
- ++mapIndex;
- }
- }
-
- mUniformIndexMap.Resize( mapIndex );
- }
-
- // Set uniforms in local map
- for( UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
- end = mUniformIndexMap.End() ;
- iter != end ;
- ++iter )
- {
- SetUniformFromProperty( bufferIndex, program, *iter );
- }
-
- GLint sizeLoc = program.GetUniformLocation( Program::UNIFORM_SIZE );
- if( -1 != sizeLoc )
- {
- Vector3 size = node.GetRenderSize( bufferIndex );
- program.SetSizeUniform3f( sizeLoc, size.x, size.y, size.z );
- }
-}
-
-void NewRenderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map )
-{
- GLint location = program.GetUniformLocation(map.uniformIndex);
- if( Program::UNIFORM_UNKNOWN != location )
- {
- // switch based on property type to use correct GL uniform setter
- switch ( map.propertyValue->GetType() )
- {
- case Property::INTEGER:
- {
- program.SetUniform1i( location, map.propertyValue->GetInteger( bufferIndex ) );
- break;
- }
- case Property::FLOAT:
- {
- program.SetUniform1f( location, map.propertyValue->GetFloat( bufferIndex ) );
- break;
- }
- case Property::VECTOR2:
- {
- Vector2 value( map.propertyValue->GetVector2( bufferIndex ) );
- program.SetUniform2f( location, value.x, value.y );
- break;
- }
-
- case Property::VECTOR3:
- {
- Vector3 value( map.propertyValue->GetVector3( bufferIndex ) );
- program.SetUniform3f( location, value.x, value.y, value.z );
- break;
- }
-
- case Property::VECTOR4:
- {
- Vector4 value( map.propertyValue->GetVector4( bufferIndex ) );
- program.SetUniform4f( location, value.x, value.y, value.z, value.w );
- break;
- }
-
- case Property::ROTATION:
- {
- Quaternion value( map.propertyValue->GetQuaternion( bufferIndex ) );
- program.SetUniform4f( location, value.mVector.x, value.mVector.y, value.mVector.z, value.mVector.w );
- break;
- }
-
- case Property::MATRIX:
- {
- const Matrix& value = map.propertyValue->GetMatrix(bufferIndex);
- program.SetUniformMatrix4fv(location, 1, value.AsFloat() );
- break;
- }
-
- case Property::MATRIX3:
- {
- const Matrix3& value = map.propertyValue->GetMatrix3(bufferIndex);
- program.SetUniformMatrix3fv(location, 1, value.AsFloat() );
- break;
- }
-
- default:
- {
- // Other property types are ignored
- break;
- }
- }
- }
-}
-
-void NewRenderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& program )
-{
- int textureUnit = 0;
-
- std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
- for( size_t i(0); i<textures.size(); ++i )
- {
- ResourceId textureId = textures[i].GetTextureId();
- Internal::Texture* texture = textureCache.GetTexture( textureId );
- if( texture )
- {
- textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
-
- Render::Texture& textureMapping = textures[i];
- // Set sampler uniform location for the texture
- int32_t uniqueIndex = textureMapping.GetUniformUniqueIndex();
- if( Render::Texture::NOT_INITIALIZED == uniqueIndex )
- {
- uniqueIndex = mUniformNameCache->GetSamplerUniformUniqueIndex( textureMapping.GetUniformName() );
- textureMapping.SetUniformUniqueIndex( uniqueIndex );
- }
- GLint uniformLocation = program.GetSamplerUniformLocation( uniqueIndex, textureMapping.GetUniformName() );
- if( Program::UNIFORM_UNKNOWN != uniformLocation )
- {
- program.SetUniform1i( uniformLocation, textureUnit );
- }
-
- unsigned int samplerBitfield(0);
- const Render::Sampler* sampler( textureMapping.GetSampler() );
- if( sampler )
- {
- samplerBitfield = ImageSampler::PackBitfield(
- static_cast< FilterMode::Type >(sampler->GetMinifyFilterMode()),
- static_cast< FilterMode::Type >(sampler->GetMagnifyFilterMode()),
- static_cast< WrapMode::Type >(sampler->GetUWrapMode()),
- static_cast< WrapMode::Type >(sampler->GetVWrapMode())
- );
- }
- else
- {
- samplerBitfield = ImageSampler::DEFAULT_BITFIELD;
- }
-
- texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
-
- ++textureUnit;
- }
- }
-}
-
-} // SceneGraph
-
-} // Internal
-
-} // Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
-#define __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
-
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/integration-api/resource-declarations.h> // For resource id
-#include <dali/internal/common/owner-pointer.h>
-#include <dali/internal/render/data-providers/render-data-provider.h>
-#include <dali/internal/render/gl-resources/texture-units.h>
-#include <dali/internal/render/renderers/render-renderer.h>
-#include <dali/internal/render/renderers/render-geometry.h>
-#include <dali/internal/update/manager/prepare-render-instructions.h>
-
-
-namespace Dali
-{
-namespace Internal
-{
-class Context;
-class PropertyInputImpl;
-
-namespace Render
-{
-
-/**
- * The new geometry renderer.
- *
- */
-class NewRenderer : public Renderer
-{
-public:
- typedef Integration::ResourceId ResourceId;
-
-public:
- /**
- * Create a new renderer instance
- * @param[in] dataProviders The data providers for the renderer
- * @param[in] renderGeometry The geometry for the renderer
- */
- static NewRenderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
-
- /**
- * Constructor.
- * @param[in] dataProviders The data providers for the renderer
- * @param[in] renderGeometry The geometry for the renderer
- */
- NewRenderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
-
- /**
- * Virtual destructor
- */
- virtual ~NewRenderer();
-
- /**
- * Change the data providers of the renderer
- * @param[in] dataProviders The data providers
- */
- void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
-
- /**
- * Change the geometry used by the renderer
- * @param[in] renderGeometry The new geometry
- */
- void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
-
- /**
- * Write the renderer's sort attributes to the passed in reference.
- * @param[in] bufferIndex The buffer index
- * @param[out] sortAttributes
- */
- void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
- {
- sortAttributes.shader = &( mRenderDataProvider->GetShader() );
- const std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
- if( !textures.empty() )
- {
- sortAttributes.textureResourceId = textures[0].GetTextureId();
- }
- else
- {
- sortAttributes.textureResourceId = Integration::InvalidResourceId;
- }
-
- sortAttributes.geometry = mRenderGeometry;
- }
-
-public: // Implementation of Renderer
-
- /**
- * @copydoc SceneGraph::Renderer::GetNewRenderer()
- */
- virtual NewRenderer* GetNewRenderer()
- {
- return this;
- }
-
- /**
- * @copydoc SceneGraph::Renderer::RequiresDepthTest()
- */
- virtual bool RequiresDepthTest() const;
-
- /**
- * @copydoc SceneGraph::Renderer::CheckResources()
- */
- virtual bool CheckResources();
-
- /**
- * @copydoc SceneGraph::Renderer::DoSetUniforms()
- */
- virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex );
-
- /**
- * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
- */
- virtual void DoSetCullFaceMode( Context& context );
-
- /**
- * @copydoc SceneGraph::Renderer::DoSetBlending
- */
- virtual void DoSetBlending( Context& context );
-
- /**
- * @copydoc SceneGraph::Renderer::DoRender()
- */
- virtual void DoRender( Context& context,
- SceneGraph::TextureCache& textureCache,
- const SceneGraph::NodeDataProvider& node,
- BufferIndex bufferIndex,
- Program& program,
- const Matrix& modelViewMatrix,
- const Matrix& viewMatrix );
-
-public: // Implementation of GlResourceOwner
-
- /**
- * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
- */
- virtual void GlContextDestroyed();
-
- /**
- * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
- */
- virtual void GlCleanup();
-
-private:
- struct UniformIndexMap;
-
- /**
- * Set the uniforms from properties according to the uniform map
- * @param[in] node The node using the renderer
- * @param[in] program The shader program on which to set the uniforms.
- */
- void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
-
- /**
- * Set the program uniform in the map from the mapped property
- */
- void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
-
- /**
- * Bind the material textures in the samplers and setup the samplers
- * @param[in] textureCache The texture cache
- * @param[in] program The shader program
- */
- void BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
-
-public:
-
- OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
-
-private:
-
- SceneGraph::RenderGeometry* mRenderGeometry;
-
- struct UniformIndexMap
- {
- unsigned int uniformIndex; // The index of the cached location in the Program
- const PropertyInputImpl* propertyValue;
- };
-
- typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
- UniformIndexMappings mUniformIndexMap;
-
- Vector<GLint> mAttributesLocation;
- bool mUpdateAttributesLocation;
-
-};
-
-
-} // SceneGraph
-} // Internal
-} // Dali
-
-#endif // __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
// INTERNAL INCLUDES
+#include <dali/internal/common/image-sampler.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/data-providers/node-data-provider.h>
+#include <dali/internal/render/data-providers/uniform-name-cache.h>
+#include <dali/internal/render/gl-resources/texture.h>
+#include <dali/internal/render/gl-resources/texture-cache.h>
#include <dali/public-api/actors/blending.h>
-#include <dali/internal/common/image-sampler.h>
-#include <dali/internal/render/renderers/render-new-renderer.h>
namespace Dali
{
namespace Render
{
+Renderer* Renderer::New( SceneGraph::RenderDataProvider* dataProvider,
+ SceneGraph::RenderGeometry* renderGeometry )
+{
+ return new Renderer( dataProvider, renderGeometry);
+}
+
+Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
+ SceneGraph::RenderGeometry* renderGeometry )
+: mRenderDataProvider( dataProvider ),
+ mContext(NULL),
+ mTextureCache( NULL ),
+ mUniformNameCache( NULL ),
+ mRenderGeometry( renderGeometry ),
+ mUniformIndexMap(),
+ mAttributesLocation(),
+ mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
+ mUpdateAttributesLocation( true ),
+ mCullFaceMode( Dali::Material::NONE )
+{
+}
+
void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache )
{
mContext = &context;
{
}
-void Renderer::SetShader( SceneGraph::Shader* shader )
+void Renderer::SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProvider )
+{
+ mRenderDataProvider = dataProvider;
+ mUpdateAttributesLocation = true;
+}
+
+void Renderer::SetGeometry( SceneGraph::RenderGeometry* renderGeometry )
+{
+ mRenderGeometry = renderGeometry;
+ mUpdateAttributesLocation = true;
+}
+
+// Note - this is currently called from UpdateThread, PrepareRenderInstructions,
+// as an optimisation.
+// @todo MESH_REWORK Should use Update thread objects only in PrepareRenderInstructions.
+bool Renderer::RequiresDepthTest() const
+{
+ return mRenderGeometry->RequiresDepthTest();
+}
+
+void Renderer::SetBlending( Context& context, bool blend )
+{
+ context.SetBlend( blend );
+ if( blend )
+ {
+ const SceneGraph::MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
+
+ // Blend color is optional and rarely used
+ Vector4* blendColor = material.GetBlendColor();
+ if( blendColor )
+ {
+ context.SetCustomBlendColor( *blendColor );
+ }
+ else
+ {
+ context.SetDefaultBlendColor();
+ }
+
+ const BlendingOptions& blending = material.GetBlendingOptions();
+ // Set blend source & destination factors
+ context.BlendFuncSeparate( blending.GetBlendSrcFactorRgb(),
+ blending.GetBlendDestFactorRgb(),
+ blending.GetBlendSrcFactorAlpha(),
+ blending.GetBlendDestFactorAlpha() );
+
+ // Set blend equations
+ context.BlendEquationSeparate( blending.GetBlendEquationRgb(),
+ blending.GetBlendEquationAlpha() );
+ }
+}
+
+void Renderer::GlContextDestroyed()
+{
+ mRenderGeometry->GlContextDestroyed();
+}
+
+void Renderer::GlCleanup()
+{
+}
+
+void Renderer::SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program )
+{
+ // Check if the map has changed
+ DALI_ASSERT_DEBUG( mRenderDataProvider && "No Uniform map data provider available" );
+
+ const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
+
+ if( uniformMapDataProvider.GetUniformMapChanged( bufferIndex ) ||
+ node.GetUniformMapChanged(bufferIndex))
+ {
+ const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap( bufferIndex );
+ const SceneGraph::CollectedUniformMap& uniformMapNode = node.GetUniformMap( bufferIndex );
+
+ unsigned int maxMaps = uniformMap.Count() + uniformMapNode.Count();
+ mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
+ mUniformIndexMap.Resize( maxMaps );
+
+ unsigned int mapIndex(0);
+ for(; mapIndex < uniformMap.Count() ; ++mapIndex )
+ {
+ mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex]->propertyPtr;
+ mUniformIndexMap[mapIndex].uniformIndex = program.RegisterUniform( uniformMap[mapIndex]->uniformName );
+ }
+
+ for( unsigned int nodeMapIndex = 0; nodeMapIndex < uniformMapNode.Count() ; ++nodeMapIndex )
+ {
+ unsigned int uniformIndex = program.RegisterUniform( uniformMapNode[nodeMapIndex]->uniformName );
+ bool found(false);
+ for( unsigned int i(0); i<uniformMap.Count(); ++i )
+ {
+ if( mUniformIndexMap[i].uniformIndex == uniformIndex )
+ {
+ mUniformIndexMap[i].propertyValue = uniformMapNode[nodeMapIndex]->propertyPtr;
+ found = true;
+ break;
+ }
+ }
+
+ if( !found )
+ {
+ mUniformIndexMap[mapIndex].propertyValue = uniformMapNode[nodeMapIndex]->propertyPtr;
+ mUniformIndexMap[mapIndex].uniformIndex = uniformIndex;
+ ++mapIndex;
+ }
+ }
+
+ mUniformIndexMap.Resize( mapIndex );
+ }
+
+ // Set uniforms in local map
+ for( UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
+ end = mUniformIndexMap.End() ;
+ iter != end ;
+ ++iter )
+ {
+ SetUniformFromProperty( bufferIndex, program, *iter );
+ }
+
+ GLint sizeLoc = program.GetUniformLocation( Program::UNIFORM_SIZE );
+ if( -1 != sizeLoc )
+ {
+ Vector3 size = node.GetRenderSize( bufferIndex );
+ program.SetSizeUniform3f( sizeLoc, size.x, size.y, size.z );
+ }
+}
+
+void Renderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map )
+{
+ GLint location = program.GetUniformLocation(map.uniformIndex);
+ if( Program::UNIFORM_UNKNOWN != location )
+ {
+ // switch based on property type to use correct GL uniform setter
+ switch ( map.propertyValue->GetType() )
+ {
+ case Property::INTEGER:
+ {
+ program.SetUniform1i( location, map.propertyValue->GetInteger( bufferIndex ) );
+ break;
+ }
+ case Property::FLOAT:
+ {
+ program.SetUniform1f( location, map.propertyValue->GetFloat( bufferIndex ) );
+ break;
+ }
+ case Property::VECTOR2:
+ {
+ Vector2 value( map.propertyValue->GetVector2( bufferIndex ) );
+ program.SetUniform2f( location, value.x, value.y );
+ break;
+ }
+
+ case Property::VECTOR3:
+ {
+ Vector3 value( map.propertyValue->GetVector3( bufferIndex ) );
+ program.SetUniform3f( location, value.x, value.y, value.z );
+ break;
+ }
+
+ case Property::VECTOR4:
+ {
+ Vector4 value( map.propertyValue->GetVector4( bufferIndex ) );
+ program.SetUniform4f( location, value.x, value.y, value.z, value.w );
+ break;
+ }
+
+ case Property::ROTATION:
+ {
+ Quaternion value( map.propertyValue->GetQuaternion( bufferIndex ) );
+ program.SetUniform4f( location, value.mVector.x, value.mVector.y, value.mVector.z, value.mVector.w );
+ break;
+ }
+
+ case Property::MATRIX:
+ {
+ const Matrix& value = map.propertyValue->GetMatrix(bufferIndex);
+ program.SetUniformMatrix4fv(location, 1, value.AsFloat() );
+ break;
+ }
+
+ case Property::MATRIX3:
+ {
+ const Matrix3& value = map.propertyValue->GetMatrix3(bufferIndex);
+ program.SetUniformMatrix3fv(location, 1, value.AsFloat() );
+ break;
+ }
+
+ default:
+ {
+ // Other property types are ignored
+ break;
+ }
+ }
+ }
+}
+
+void Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& program )
{
- mShader = shader;
+ int textureUnit = 0;
+
+ std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
+ for( size_t i(0); i<textures.size(); ++i )
+ {
+ ResourceId textureId = textures[i].GetTextureId();
+ Internal::Texture* texture = textureCache.GetTexture( textureId );
+ if( texture )
+ {
+ textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
+
+ Render::Texture& textureMapping = textures[i];
+ // Set sampler uniform location for the texture
+ int32_t uniqueIndex = textureMapping.GetUniformUniqueIndex();
+ if( Render::Texture::NOT_INITIALIZED == uniqueIndex )
+ {
+ uniqueIndex = mUniformNameCache->GetSamplerUniformUniqueIndex( textureMapping.GetUniformName() );
+ textureMapping.SetUniformUniqueIndex( uniqueIndex );
+ }
+ GLint uniformLocation = program.GetSamplerUniformLocation( uniqueIndex, textureMapping.GetUniformName() );
+ if( Program::UNIFORM_UNKNOWN != uniformLocation )
+ {
+ program.SetUniform1i( uniformLocation, textureUnit );
+ }
+
+ unsigned int samplerBitfield(0);
+ const Render::Sampler* sampler( textureMapping.GetSampler() );
+ if( sampler )
+ {
+ samplerBitfield = ImageSampler::PackBitfield(
+ static_cast< FilterMode::Type >(sampler->GetMinifyFilterMode()),
+ static_cast< FilterMode::Type >(sampler->GetMagnifyFilterMode()),
+ static_cast< WrapMode::Type >(sampler->GetUWrapMode()),
+ static_cast< WrapMode::Type >(sampler->GetVWrapMode())
+ );
+ }
+ else
+ {
+ samplerBitfield = ImageSampler::DEFAULT_BITFIELD;
+ }
+
+ texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
+
+ ++textureUnit;
+ }
+ }
}
void Renderer::SetCullFace( Dali::Material::FaceCullingMode mode )
bool cull,
bool blend )
{
- NewRenderer* renderer = GetNewRenderer(); // avoid a dynamic cast per item per frame
-
- if( renderer )
- {
- // Get the shader from the material:
- mShader = &renderer->mRenderDataProvider->GetShader();
- }
-
- // if mShader is NULL it means we're set to default
- if( !mShader )
- {
- mShader = &defaultShader;
- }
-
- if( !CheckResources() )
- {
- // CheckResources() is overriden in derived classes.
- // Prevents modify the GL state if resources are not ready and nothing is to be rendered.
- return;
- }
-
// Get the program to use:
- Program* program = mShader->GetProgram();
+ Program* program = mRenderDataProvider->GetShader().GetProgram();
if( !program )
{
// if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program
DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." );
if( !program )
{
- DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*) &*mShader );
+ DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*)&mRenderDataProvider->GetShader() );
return;
}
}
- // Take the program into use so we can send uniforms to it
- program->Use();
+ //Set cull face mode
+ context.CullFace( mRenderDataProvider->GetMaterial().GetFaceCullingMode() );
- DoSetCullFaceMode( context );
+ //Set blending mode
+ SetBlending( context, blend );
- // Enable/disable blending
- context.SetBlend( blend );
- if( blend )
- {
- DoSetBlending( context );
- }
+ // Take the program into use so we can send uniforms to it
+ program->Use();
- // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
// set projection and view matrix if program has not yet received them yet this frame
- const Matrix& modelMatrix = node.GetModelMatrix( bufferIndex );
- SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix );
+ SetMatrices( *program, node.GetModelMatrix( bufferIndex ), viewMatrix, projectionMatrix, modelViewMatrix );
// set color uniform
GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );
program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
}
- //@todo MESH_REWORK Remove after removing ImageRenderer
- DoSetUniforms(context, bufferIndex, mShader, program );
+ //Bind textures
+ BindTextures( textureCache, *program );
- // subclass rendering and actual draw call
- DoRender( context, textureCache, node, bufferIndex, *program, modelViewMatrix, viewMatrix );
-}
+ //Set uniforms
+ SetUniforms( bufferIndex, node, *program );
-void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
-{
- sortAttributes.shader = mShader;
- sortAttributes.textureResourceId = Integration::InvalidResourceId;
- sortAttributes.geometry = NULL;
-}
+ if( mUpdateAttributesLocation || mRenderGeometry->AttributesChanged() )
+ {
+ mRenderGeometry->GetAttributeLocationFromProgram( mAttributesLocation, *program, bufferIndex );
+ mUpdateAttributesLocation = false;
+ }
-// can be overridden by deriving class
-void Renderer::DoSetUniforms(Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program )
-{
- shader->SetUniforms( context, *program, bufferIndex );
+ mRenderGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation );
}
-// can be overridden by deriving class
-void Renderer::DoSetCullFaceMode( Context& context )
+void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
{
- // Set face culling mode
- context.CullFace( mCullFaceMode );
-}
+ sortAttributes.shader = &( mRenderDataProvider->GetShader() );
+ const std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
+ if( !textures.empty() )
+ {
+ sortAttributes.textureResourceId = textures[0].GetTextureId();
+ }
+ else
+ {
+ sortAttributes.textureResourceId = Integration::InvalidResourceId;
+ }
-Renderer::Renderer()
-: mContext(NULL),
- mTextureCache( NULL ),
- mUniformNameCache( NULL ),
- mShader( NULL ),
- mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
- mCullFaceMode( Dali::Material::NONE )
-{
+ sortAttributes.geometry = mRenderGeometry;
}
} // namespace SceneGraph
#include <dali/integration-api/debug.h>
#include <dali/internal/common/type-abstraction-enums.h>
#include <dali/internal/update/manager/prepare-render-instructions.h>
+#include <dali/internal/render/renderers/render-geometry.h>
namespace Dali
{
namespace Render
{
class UniformNameCache;
-class NewRenderer;
/**
* Renderers are used to render meshes
public:
/**
+ * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
+ */
+ void GlContextDestroyed();
+
+ /**
+ * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
+ */
+ void GlCleanup();
+
+ /**
+ * Create a new renderer instance
+ * @param[in] dataProviders The data providers for the renderer
+ * @param[in] renderGeometry The geometry for the renderer
+ */
+ static Renderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
+
+ /**
+ * Constructor.
+ * @param[in] dataProviders The data providers for the renderer
+ * @param[in] renderGeometry The geometry for the renderer
+ */
+ Renderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
+
+ /**
+ * Change the data providers of the renderer
+ * @param[in] dataProviders The data providers
+ */
+ void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
+
+ /**
+ * Change the geometry used by the renderer
+ * @param[in] renderGeometry The new geometry
+ */
+ void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
+ /**
* Second-phase construction.
* This is called when the renderer is inside render thread
* @param[in] context to use
void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
/**
- * Virtual destructor
+ * Destructor
*/
- virtual ~Renderer();
-
- /**
- * Set the Shader used to render.
- * @param[in] shader The shader used to render.
- */
- void SetShader( SceneGraph::Shader* shader );
+ ~Renderer();
/**
* Set the face-culling mode.
* Query whether the derived type of Renderer requires depth testing.
* @return True if the renderer requires depth testing.
*/
- virtual bool RequiresDepthTest() const = 0;
+ bool RequiresDepthTest() const;
/**
* Called to render during RenderManager::Render().
* @param[in] bufferIndex The current update buffer index.
* @param[out] sortAttributes
*/
- virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
-
-protected:
- /**
- * Protected constructor; only derived classes can be instantiated.
- * @param dataprovider for rendering
- */
- Renderer();
+ void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
private:
+ struct UniformIndexMap;
+
// Undefined
Renderer( const Renderer& );
Renderer& operator=( const Renderer& rhs );
/**
- * @return NewRenderer or NULL if this is an old renderer
+ * Sets blending options
+ * @param context to use
+ * @param blend Wheter blending should be enabled or not
*/
- virtual NewRenderer* GetNewRenderer()
- {
- return NULL;
- }
+ void SetBlending( Context& context, bool blend );
/**
- * Checks if renderer's resources are ready to be used.
- *
- * @return \e true if they are. Otherwise \e false.
+ * Set the uniforms from properties according to the uniform map
+ * @param[in] node The node using the renderer
+ * @param[in] program The shader program on which to set the uniforms.
*/
- virtual bool CheckResources() = 0;
+ void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
/**
- * Called from Render prior to DoRender().
- * @todo MESH_REWORK Remove after merge
+ * Set the program uniform in the map from the mapped property
*/
- virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
+ void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
/**
- * Called from Render prior to DoRender(). Default method to set CullFaceMode
- * @param context to use
+ * Bind the material textures in the samplers and setup the samplers
+ * @param[in] textureCache The texture cache
+ * @param[in] program The shader program
*/
- virtual void DoSetCullFaceMode( Context& context );
+ void BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
- /**
- * Called from Render prior to DoRender(). Default method to set blending options
- * @param context to use
- */
- virtual void DoSetBlending( Context& context ) = 0;
+public:
- /**
- * Called from Render; implemented in derived classes.
- * @param[in] context The context used for rendering
- * @param[in] textureCache The texture cache used to get textures
- * @param[in] bufferIndex The index of the previous update buffer.
- * @param[in] program to use.
- * @param[in] modelViewMatrix The model-view matrix.
- * @param[in] viewMatrix The view matrix.
- */
- virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
+ OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
-protected:
+private:
Context* mContext;
SceneGraph::TextureCache* mTextureCache;
Render::UniformNameCache* mUniformNameCache;
- SceneGraph::Shader* mShader;
- unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
+ SceneGraph::RenderGeometry* mRenderGeometry;
-private:
+ struct UniformIndexMap
+ {
+ unsigned int uniformIndex; // The index of the cached location in the Program
+ const PropertyInputImpl* propertyValue;
+ };
+
+ typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
+ UniformIndexMappings mUniformIndexMap;
+
+ Vector<GLint> mAttributesLocation;
- Dali::Material::FaceCullingMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
+ unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
+ bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
+ Dali::Material::FaceCullingMode mCullFaceMode:2; ///< cullface enum, 3 bits is enough
};
} // namespace SceneGraph
#include <dali/internal/common/message.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/render/queue/render-queue.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
}
}
-void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
-{
- DALI_ASSERT_DEBUG( NULL != attachment );
-
- // The GL resources will now be freed in Render frame N
- // The Update for frame N+1 may occur in parallel with the rendering of frame N
- // Queue the attachment for destruction in Update frame N+2
- if ( 0u == updateBufferIndex )
- {
- mAttachmentQueue0.PushBack( attachment );
- }
- else
- {
- mAttachmentQueue1.PushBack( attachment );
- }
-}
-
void DiscardQueue::Add( BufferIndex updateBufferIndex, Geometry* geometry )
{
DALI_ASSERT_DEBUG( NULL != geometry );
if ( 0u == updateBufferIndex )
{
mNodeQueue0.Clear();
- mAttachmentQueue0.Clear();
mShaderQueue0.Clear();
mGeometryQueue0.Clear();
mMaterialQueue0.Clear();
else
{
mNodeQueue1.Clear();
- mAttachmentQueue1.Clear();
mShaderQueue1.Clear();
mGeometryQueue1.Clear();
mMaterialQueue1.Clear();
#include <dali/devel-api/common/owner-container.h>
#include <dali/internal/common/buffer-index.h>
#include <dali/internal/update/nodes/node-declarations.h>
-#include <dali/internal/update/node-attachments/node-attachment-declarations.h>
#include <dali/internal/update/rendering/scene-graph-geometry.h>
#include <dali/internal/update/rendering/scene-graph-material.h>
#include <dali/internal/update/rendering/scene-graph-renderer.h>
void Add( BufferIndex updateBufferIndex, Node* node );
/**
- * Adds an unwanted NodeAttachment to the discard queue.
- * If necessary, a message will be sent to clean-up GL resources in the next Render.
- * @pre This method is not thread-safe, and should only be called from the update-thread.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] attachment The discarded attachment; DiscardQueue takes ownership.
- */
- void Add( BufferIndex updateBufferIndex, NodeAttachment* attachment );
-
- /**
* Adds an unwanted geometry to the discard queue.
* A message will be sent to clean up GL resources in the next Render
*/
// Messages are queued here when the update buffer index == 0
NodeOwnerContainer mNodeQueue0;
- NodeAttachmentOwnerContainer mAttachmentQueue0;
ShaderQueue mShaderQueue0;
GeometryQueue mGeometryQueue0;
MaterialQueue mMaterialQueue0;
// Messages are queued here when the update buffer index == 1
NodeOwnerContainer mNodeQueue1;
- NodeAttachmentOwnerContainer mAttachmentQueue1;
ShaderQueue mShaderQueue1;
GeometryQueue mGeometryQueue1;
MaterialQueue mMaterialQueue1;
* @param[in] renderQueue The renderQueue
* @param[in] discardQueue The discardQueue
* @param[in] completeStatusTracker The resource complete status tracker
- * @param[in] defaultShader to use for renderable attachments
*/
SceneControllerImpl( RenderMessageDispatcher& renderMessageDispatcher,
RenderQueue& renderQueue,
+++ /dev/null
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/internal/update/manager/prepare-render-algorithms.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/update/manager/sorted-layers.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
-#include <dali/internal/update/nodes/scene-graph-layer.h>
-#include <dali/internal/render/renderers/render-renderer.h>
-#include <dali/internal/render/common/render-instruction.h>
-#include <dali/internal/render/shaders/scene-graph-shader.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-/******************************************************************************
- ************************** Clear lists from previous update ******************
- ******************************************************************************/
-
-void ClearRenderables( SortedLayerPointers& sortedLayers )
-{
- // Clear the lists of renderables from the previous update
-
- const SortedLayersIter endIter = sortedLayers.end();
-
- for ( SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter )
- {
- (*iter)->stencilRenderables.clear();
- (*iter)->colorRenderables.clear();
- (*iter)->overlayRenderables.clear();
-
- (*iter)->stencilRenderers.Clear();
- (*iter)->colorRenderers.Clear();
- (*iter)->overlayRenderers.Clear();
-
- }
-}
-
-/******************************************************************************
- ***************************** Prepare renderers ******************************
- ******************************************************************************/
-
-void PrepareRenderables( BufferIndex updateBufferIndex, RenderableAttachmentContainer& renderableList )
-{
- const RenderableAttachmentIter endIter = renderableList.end();
- for ( RenderableAttachmentIter iter = renderableList.begin(); iter != endIter; ++iter )
- {
- RenderableAttachment& renderable = **iter;
- renderable.DoPrepareRender( updateBufferIndex );
- }
-}
-
-void PrepareRenderables( BufferIndex updateBufferIndex, SortedLayerPointers& sortedLayers )
-{
- const SortedLayersIter endIter = sortedLayers.end();
-
- for ( SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter )
- {
- Layer& layer = **iter;
-
- PrepareRenderables( updateBufferIndex, layer.stencilRenderables );
- PrepareRenderables( updateBufferIndex, layer.colorRenderables );
- PrepareRenderables( updateBufferIndex, layer.overlayRenderables );
- }
-}
-
-} // SceneGraph
-
-} // Internal
-
-} // Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_PREPARE_RENDER_ALGORITHMS_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_PREPARE_RENDER_ALGORITHMS_H__
-
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/internal/common/buffer-index.h>
-#include <dali/internal/update/manager/sorted-layers.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-/**
- * Clear the list of opaque/transparent renderables for each layer.
- * @param[in] sortedLayers The layers containing lists of opaque/transparent renderables.
- */
-void ClearRenderables( SortedLayerPointers& sortedLayers );
-
-/**
- * Prepares the list of opaque/transparent renderable attachments for each layer.
- * Whilst iterating through each layer, update the attachments ModelView matrices
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] sortedLayers The layers containing lists of opaque/transparent renderables.
- */
-void PrepareRenderables( BufferIndex updateBufferIndex, SortedLayerPointers& sortedLayers );
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_PREPARE_RENDER_ALGORITHMS_H__
-
#include <dali/public-api/actors/layer.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/event/actors/layer-impl.h> // for the default sorting function
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/update/manager/sorted-layers.h>
#include <dali/internal/update/render-tasks/scene-graph-render-task.h>
* Add a renderer to the list
* @param updateBufferIndex to read the model matrix from
* @param renderList to add the item to
- * @param renderable attachment
+ * @param renderable Node-Renderer pair
* @param viewMatrix used to calculate modelview matrix for the item
* @param cameraAttachment The camera used to render
* @param isLayer3d Whether we are processing a 3D layer or not
*/
inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
RenderList& renderList,
- RenderableAttachment& renderable,
- const Matrix& viewMatrix,
- SceneGraph::CameraAttachment& cameraAttachment,
- bool isLayer3d )
-{
- const Node& parentNode = renderable.GetParent();
- const Matrix& worldMatrix = parentNode.GetWorldMatrix( updateBufferIndex );
-
- // Get the next free RenderItem and initialization
- RenderItem& item = renderList.GetNextFreeItem();
- const Render::Renderer& renderer = renderable.GetRenderer();
- item.SetRenderer( const_cast< Render::Renderer* >( &renderer ) );
- item.SetNode( const_cast< Node* >( &parentNode ) );
-
- item.SetIsOpaque( renderable.IsFullyOpaque(updateBufferIndex) );
- if( isLayer3d )
- {
- item.SetDepthIndex( renderable.GetDepthIndex() );
- }
- else
- {
- item.SetDepthIndex( renderable.GetDepthIndex() + static_cast<int>( parentNode.GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER );
- }
-
- // save MV matrix onto the item
- Matrix::Multiply( item.GetModelViewMatrix(), worldMatrix, viewMatrix );
-}
-
-/**
- * Add a renderer to the list
- * @param updateBufferIndex to read the model matrix from
- * @param renderList to add the item to
- * @param NodeRenderer NodeRenderer pair
- * @param viewMatrix used to calculate modelview matrix for the item
- * @param cameraAttachment The camera used to render
- * @param isLayer3d Whether we are processing a 3D layer or not
- */
-inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
- RenderList& renderList,
- NodeRenderer& renderable,
+ Renderable& renderable,
const Matrix& viewMatrix,
SceneGraph::CameraAttachment& cameraAttachment,
bool isLayer3d )
*/
inline void AddRenderersToRenderList( BufferIndex updateBufferIndex,
RenderList& renderList,
- RenderableAttachmentContainer& attachments,
- NodeRendererContainer& renderers,
+ RenderableContainer& renderables,
const Matrix& viewMatrix,
SceneGraph::CameraAttachment& cameraAttachment,
bool isLayer3d )
{
DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n");
- // Add renderer for each attachment
- unsigned int index(0);
- const RenderableAttachmentIter endIter = attachments.end();
- for ( RenderableAttachmentIter iter = attachments.begin(); iter != endIter; ++iter )
- {
- RenderableAttachment& attachment = **iter;
- AddRendererToRenderList( updateBufferIndex, renderList, attachment, viewMatrix, cameraAttachment, isLayer3d );
-
- DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " List[%d].renderer = %p\n", index, &(attachment.GetRenderer()));
- ++index;
- }
-
- unsigned int rendererCount( renderers.Size() );
+ unsigned int rendererCount( renderables.Size() );
for( unsigned int i(0); i<rendererCount; ++i )
{
- AddRendererToRenderList( updateBufferIndex, renderList, renderers[i], viewMatrix, cameraAttachment, isLayer3d );
+ AddRendererToRenderList( updateBufferIndex, renderList, renderables[i], viewMatrix, cameraAttachment, isLayer3d );
}
}
* An example case is a toolbar layer that rarely changes or a popup on top of the rest of the stage
* @param layer that is being processed
* @param renderList that is cached from frame N-1
- * @param attachmentList that is being used
+ * @param renderables list of renderables
*/
inline bool TryReuseCachedRenderers( Layer& layer,
RenderList& renderList,
- RenderableAttachmentContainer& attachmentList )
+ RenderableContainer& renderables )
{
bool retValue = false;
- size_t renderableCount = attachmentList.size();
+ size_t renderableCount = renderables.Size();
// check that the cached list originates from this layer and that the counts match
if( ( renderList.GetSourceLayer() == &layer )&&
( renderList.GetCachedItemCount() == renderableCount ) )
size_t checkSumOld = 0;
for( size_t index = 0; index < renderableCount; ++index )
{
- RenderableAttachment* attachment = attachmentList[ index ];
- const Render::Renderer& renderer = attachment->GetRenderer();
+ const Render::Renderer& renderer = renderables[index].mRenderer->GetRenderer();
checkSumNew += size_t( &renderer );
checkSumOld += size_t( &renderList.GetRenderer( index ) );
}
return retValue;
}
-
/**
* Function which sorts render items by depth index then by instance
* ptrs of shader/geometry/material.
RendererSortingHelper& sortingHelper,
bool tryReuseRenderList )
{
- RenderList& renderList = instruction.GetNextFreeRenderList( layer.colorRenderables.size() );
+ RenderList& renderList = instruction.GetNextFreeRenderList( layer.colorRenderables.Size() );
renderList.SetClipping( layer.IsClipping(), layer.GetClippingBox() );
renderList.SetHasColorRenderItems( true );
}
}
- AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, layer.colorRenderers, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
+ AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
SortColorRenderItems( updateBufferIndex, renderList, layer, sortingHelper );
//Set render flags
RenderInstruction& instruction,
bool tryReuseRenderList )
{
- RenderList& overlayRenderList = instruction.GetNextFreeRenderList( layer.overlayRenderables.size() );
+ RenderList& overlayRenderList = instruction.GetNextFreeRenderList( layer.overlayRenderables.Size() );
overlayRenderList.SetClipping( layer.IsClipping(), layer.GetClippingBox() );
overlayRenderList.SetHasColorRenderItems( false );
return;
}
}
- AddRenderersToRenderList( updateBufferIndex, overlayRenderList, layer.overlayRenderables, layer.overlayRenderers, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
+ AddRenderersToRenderList( updateBufferIndex, overlayRenderList, layer.overlayRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
}
/**
RenderInstruction& instruction,
bool tryReuseRenderList )
{
- RenderList& stencilRenderList = instruction.GetNextFreeRenderList( layer.stencilRenderables.size() );
+ RenderList& stencilRenderList = instruction.GetNextFreeRenderList( layer.stencilRenderables.Size() );
stencilRenderList.SetClipping( layer.IsClipping(), layer.GetClippingBox() );
stencilRenderList.SetHasColorRenderItems( false );
return;
}
}
- AddRenderersToRenderList( updateBufferIndex, stencilRenderList, layer.stencilRenderables, layer.stencilRenderers, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
+ AddRenderersToRenderList( updateBufferIndex, stencilRenderList, layer.stencilRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
}
/**
{
Layer& layer = **iter;
- const bool stencilRenderablesExist( !layer.stencilRenderables.empty() || !layer.stencilRenderers.Empty() );
- const bool colorRenderablesExist( !layer.colorRenderables.empty() || !layer.colorRenderers.Empty() );
- const bool overlayRenderablesExist( !layer.overlayRenderables.empty() || !layer.overlayRenderers.Empty() );
+ const bool stencilRenderablesExist( !layer.stencilRenderables.Empty() );
+ const bool colorRenderablesExist( !layer.colorRenderables.Empty() );
+ const bool overlayRenderablesExist( !layer.overlayRenderables.Empty() );
const bool tryReuseRenderList( viewMatrixHasNotChanged && layer.CanReuseRenderers(renderTask.GetCamera()) );
// Ignore stencils if there's nothing to test
// INTERNAL INCLUDES
#include <dali/internal/update/manager/prepare-render-instructions.h>
-#include <dali/internal/update/manager/prepare-render-algorithms.h>
#include <dali/internal/update/manager/sorted-layers.h>
#include <dali/internal/update/resources/complete-status-manager.h>
#include <dali/internal/update/resources/sync-resource-tracker.h>
#include <dali/internal/update/render-tasks/scene-graph-render-task.h>
#include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/render/common/render-item.h>
#include <dali/internal/render/common/render-tracker.h>
namespace Internal
{
+
namespace SceneGraph
{
+namespace //Unnamed namespace
+{
+
// Return false if the node or it's parents are exclusive to another render-task
-static bool CheckExclusivity( const Node& node, const RenderTask& task )
+bool CheckExclusivity( const Node& node, const RenderTask& task )
{
const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
if ( exclusiveTo )
return true;
}
-static Layer* FindLayer( Node& node )
+Layer* FindLayer( Node& node )
{
if ( node.IsLayer() )
{
/**
* Rebuild the Layer::opaqueRenderables, transparentRenderables and overlayRenderables members,
- * including only renderable-attachments which are included in the current render-task.
- * Returns true if all renderable attachments have finshed acquiring resources.
+ * including only renderers which are included in the current render-task.
+ * Returns true if all renderers have finshed acquiring resources.
*/
-static bool AddRenderablesForTask( BufferIndex updateBufferIndex,
- Node& node,
- Layer& currentLayer,
- RenderTask& renderTask,
- int inheritedDrawMode )
+bool AddRenderablesForTask( BufferIndex updateBufferIndex,
+ Node& node,
+ Layer& currentLayer,
+ RenderTask& renderTask,
+ int inheritedDrawMode )
{
bool resourcesFinished = true;
// Check whether node is exclusive to a different render-task
const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
if ( exclusiveTo &&
- exclusiveTo != &renderTask )
+ exclusiveTo != &renderTask )
{
return resourcesFinished;
}
inheritedDrawMode |= node.GetDrawMode();
-
- if ( node.HasAttachment() )
- {
- RenderableAttachment* renderable = node.GetAttachment().GetRenderable(); // not all attachments render
- if ( renderable )
- {
- bool visible = renderable->HasVisibleSizeAndColor();
- // if its not potentially visible, then don't consider this renderable for render complete checking
- // note that whilst visibility is inherited (if parent is insible, skip the sub-tree),
- // size and color may not be so this needs to be done per renderable
- if( visible ) // i.e. some resources are ready
- {
- bool ready = false;
- bool complete = false;
- renderable->GetReadyAndComplete(ready, complete);
-
- DALI_LOG_INFO(gRenderTaskLogFilter, Debug::General, "Testing renderable:%p ready:%s complete:%s\n", renderable, ready?"T":"F", complete?"T":"F");
-
- resourcesFinished = !complete ? complete : resourcesFinished;
-
- if( ready ) // i.e. some resources are ready
- {
- if( DrawMode::STENCIL == inheritedDrawMode )
- {
- layer->stencilRenderables.push_back( renderable );
- }
- else if( DrawMode::OVERLAY_2D == inheritedDrawMode )
- {
- layer->overlayRenderables.push_back( renderable );
- }
- else
- {
- layer->colorRenderables.push_back( renderable );
- }
- }
- }
- }
- }
-
if( node.ResolveVisibility( updateBufferIndex ) )
{
for( unsigned int i(0); i<node.GetRendererCount(); ++i )
{
if( DrawMode::STENCIL == inheritedDrawMode )
{
- layer->stencilRenderers.PushBack( NodeRenderer(&node, renderer ) );
+ layer->stencilRenderables.PushBack( Renderable(&node, renderer ) );
}
else if( DrawMode::OVERLAY_2D == inheritedDrawMode )
{
- layer->overlayRenderers.PushBack( NodeRenderer(&node, renderer ) );
+ layer->overlayRenderables.PushBack( Renderable(&node, renderer ) );
}
else
{
- layer->colorRenderers.PushBack( NodeRenderer(&node, renderer ) );
+ layer->colorRenderables.PushBack( Renderable(&node, renderer ) );
}
}
-
-
-
}
}
return resourcesFinished;
}
+} //Unnamed namespace
void ProcessRenderTasks( BufferIndex updateBufferIndex,
CompleteStatusManager& completeStatusManager,
bool resourcesFinished = false;
if( renderTask.IsRenderRequired() )
{
- ClearRenderables( sortedLayers );
+ size_t layerCount( sortedLayers.size() );
+ for( size_t i(0); i<layerCount; ++i )
+ {
+ sortedLayers[i]->ClearRenderables();
+ }
resourcesFinished = AddRenderablesForTask( updateBufferIndex,
*sourceNode,
bool resourcesFinished = false;
if( renderTask.IsRenderRequired() )
{
- ClearRenderables( sortedLayers );
+ size_t layerCount( sortedLayers.size() );
+ for( size_t i(0); i<layerCount; ++i )
+ {
+ sortedLayers[i]->ClearRenderables();
+ }
resourcesFinished = AddRenderablesForTask( updateBufferIndex,
*sourceNode,
#include <dali/internal/update/resources/resource-manager.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/node-attachments/node-attachment.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
#include <dali/internal/update/animation/scene-graph-constraint-base.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/render/renderers/render-renderer.h>
}
}
-inline void UpdateNodeWorldMatrix( Node& node, RenderableAttachment& updatedRenderable, int nodeDirtyFlags, BufferIndex updateBufferIndex )
-{
- /**
- * If world-matrix needs to be recalculated.
- */
- if ( ( nodeDirtyFlags & TransformFlag ) ||
- updatedRenderable.IsScaleForSizeDirty() )
- {
- if( updatedRenderable.UsesGeometryScaling() )
- {
- // TODO: MESH_REWORK : remove scale for size
- Vector3 scaling;
- updatedRenderable.GetScaleForSize( node.GetSize( updateBufferIndex ), scaling );
- if( node.GetInhibitLocalTransform() )
- {
- node.SetWorldMatrix( updateBufferIndex,
- node.GetWorldScale(updateBufferIndex) * scaling,
- node.GetWorldOrientation(updateBufferIndex) / node.GetOrientation(updateBufferIndex),
- node.GetWorldPosition(updateBufferIndex) - node.GetPosition(updateBufferIndex) );
- }
- else
- {
- node.SetWorldMatrix( updateBufferIndex,
- node.GetWorldScale(updateBufferIndex) * scaling,
- node.GetWorldOrientation(updateBufferIndex),
- node.GetWorldPosition(updateBufferIndex) );
- }
- }
- else
- {
- // no scaling, i.e. Image
- if( node.GetInhibitLocalTransform() )
- {
- node.SetWorldMatrix( updateBufferIndex,
- node.GetWorldScale(updateBufferIndex),
- node.GetWorldOrientation(updateBufferIndex) / node.GetOrientation(updateBufferIndex),
- node.GetWorldPosition(updateBufferIndex) - node.GetPosition(updateBufferIndex) );
- }
- else
- {
- node.SetWorldMatrix( updateBufferIndex,
- node.GetWorldScale(updateBufferIndex),
- node.GetWorldOrientation(updateBufferIndex),
- node.GetWorldPosition(updateBufferIndex) );
- }
- }
- }
- else
- {
- node.CopyPreviousWorldMatrix( updateBufferIndex );
- }
-}
-
-/**
- * Update an attachment.
- * @return An updated renderable attachment if one was ready.
- */
-inline RenderableAttachment* UpdateAttachment( NodeAttachment& attachment,
- Node& node,
- BufferIndex updateBufferIndex,
- ResourceManager& resourceManager,
- int nodeDirtyFlags )
-{
- // Allow attachments to do specialised processing during updates
- attachment.Update( updateBufferIndex, node, nodeDirtyFlags );
-
- RenderableAttachment* renderable = attachment.GetRenderable(); // not all scene objects render
- if( renderable )
- {
- // Notify renderables when size has changed
- // Size can change while node was invisible so we need to check size again if we were previously invisible
- if( nodeDirtyFlags & (SizeFlag|VisibleFlag) )
- {
- renderable->SizeChanged( updateBufferIndex );
- }
-
- // check if node is visible
- if( renderable->ResolveVisibility( updateBufferIndex ) )
- {
- renderable->PrepareResources( updateBufferIndex, resourceManager );
- }
- }
- return renderable;
-}
-
-inline void AddRenderableToLayer( Layer& layer,
- RenderableAttachment& renderable,
- BufferIndex updateBufferIndex,
- int inheritedDrawMode )
-{
- // The renderables are stored into the opaque list temporarily for PrepareRenderables()
- // step. The list is cleared by ProcessRenderTasks().
- layer.colorRenderables.push_back( &renderable );
-}
-
/**
* This is called recursively for all children of the root Node
*/
UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex );
- // Note: nodeDirtyFlags are passed in by reference and may be modified by the following function.
- // It is important that the modified version of these flags are used by the RenderableAttachment.
+ // Note: nodeDirtyFlags are passed in by reference and may be modified by the following function
UpdateNodeTransformValues( node, nodeDirtyFlags, updateBufferIndex );
// Setting STENCIL will override OVERLAY_2D, if that would otherwise have been inherited.
if ( node.HasAttachment() )
{
- /*
- * Add renderables for the children into the current Layer
- */
- RenderableAttachment* renderable = UpdateAttachment( node.GetAttachment(),
- node,
- updateBufferIndex,
- resourceManager,
- nodeDirtyFlags );
-
-
- if( NULL != renderable )
- {
- // Update the world matrix after renderable update; the ScaleForSize property should now be calculated
- UpdateNodeWorldMatrix( node, *renderable, nodeDirtyFlags, updateBufferIndex );
-
- // The attachment is ready to render, so it is added to a set of renderables.
- AddRenderableToLayer( *layer, *renderable, updateBufferIndex, inheritedDrawMode );
- }
+ node.GetAttachment().Update( updateBufferIndex, node, nodeDirtyFlags );
}
else if( node.IsObserved() || node.GetRendererCount() )
{
#include <dali/internal/update/controllers/scene-controller-impl.h>
#include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
#include <dali/internal/update/manager/object-owner-container.h>
-#include <dali/internal/update/manager/prepare-render-algorithms.h>
#include <dali/internal/update/manager/process-render-tasks.h>
#include <dali/internal/update/manager/sorted-layers.h>
#include <dali/internal/update/manager/update-algorithms.h>
ProcessPropertyNotifications( bufferIndex );
// 10) Clear the lists of renderable-attachments from the previous update
- ClearRenderables( mImpl->sortedLayers );
- ClearRenderables( mImpl->systemLevelSortedLayers );
+ for( size_t i(0); i<mImpl->sortedLayers.size(); ++i )
+ {
+ mImpl->sortedLayers[i]->ClearRenderables();
+ }
+
+ for( size_t i(0); i<mImpl->systemLevelSortedLayers.size(); ++i )
+ {
+ mImpl->systemLevelSortedLayers[i]->ClearRenderables();
+ }
// 11) Update node hierarchy and perform sorting / culling.
// This will populate each Layer with a list of renderers which are ready.
UpdateRenderers( bufferIndex );
- // 12) Prepare for the next render
- PERF_MONITOR_START(PerformanceMonitor::PREPARE_RENDERABLES);
-
- PrepareRenderables( bufferIndex, mImpl->sortedLayers );
- PrepareRenderables( bufferIndex, mImpl->systemLevelSortedLayers );
- PERF_MONITOR_END(PerformanceMonitor::PREPARE_RENDERABLES);
-
PERF_MONITOR_START(PerformanceMonitor::PROCESS_RENDER_TASKS);
- // 14) Process the RenderTasks; this creates the instructions for rendering the next frame.
+ // 12) Process the RenderTasks; this creates the instructions for rendering the next frame.
// reset the update buffer index and make sure there is enough room in the instruction container
mImpl->renderInstructions.ResetAndReserve( bufferIndex,
mImpl->taskList.GetTasks().Count() + mImpl->systemLevelTaskList.GetTasks().Count() );
// Scene graph thread can modify this object.
Node& parent = const_cast< Node& >( constParent );
- // @todo MESH_REWORK Don't pass by owner pointer after merge with SceneGraph::RenderableAttachment ? (not needed if we split RendererAttachment to 2 objects)
typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
// Reserve some memory inside the message queue
{
class Node;
-class RenderableAttachment;
class SceneController;
/**
return *mParent;
}
- // RenderableAttachment interface
-
- /**
- * Query whether the attachment is renderable i.e. implements the SceneGraph::RenderableAttachment interface.
- * @return True if the attachment is renderable.
- */
- bool IsRenderable()
- {
- return (GetRenderable() != NULL);
- }
-
- /**
- * Convert an attachment to a renderable attachment.
- * @return A pointer to the renderable attachment, or NULL.
- */
- virtual RenderableAttachment* GetRenderable() = 0;
-
// Update methods
/**
{
}
-RenderableAttachment* CameraAttachment::GetRenderable()
-{
- return NULL;
-}
-
void CameraAttachment::SetType( Dali::Camera::Type type )
{
mType = type;
namespace SceneGraph
{
-class RenderableAttachment;
class SceneController;
/**
virtual ~CameraAttachment();
/**
- * @copydoc NodeAttachment::GetRenderable.
- * @return Always NULL.
- */
- virtual RenderableAttachment* GetRenderable();
-
- /**
* @copydoc Dali::Internal::CameraAttachment::SetType
*/
void SetType( Dali::Camera::Type type );
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_DECLARATIONS_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_DECLARATIONS_H__
-
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-class RenderableAttachment;
-
-typedef std::vector<RenderableAttachment*> RenderableAttachmentContainer;
-typedef RenderableAttachmentContainer::iterator RenderableAttachmentIter;
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
-
-// INTERNAL INCLUDES
-#include <dali/integration-api/resource-declarations.h>
-#include <dali/public-api/actors/image-actor.h>
-#include <dali/internal/update/manager/prepare-render-instructions.h>
-#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/internal/update/resources/complete-status-manager.h>
-#include <dali/internal/update/resources/resource-tracker.h>
-#include <dali/internal/render/queue/render-queue.h>
-#include <dali/internal/render/renderers/render-renderer.h>
-#include <dali/internal/render/shaders/scene-graph-shader.h>
-#include <dali/internal/common/image-sampler.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-RenderableAttachment::RenderableAttachment( bool usesGeometryScaling )
-: mSceneController(NULL), //@todo MESH_REWORK Pass in where required rather than store
- mShader( NULL ),
- mTrackedResources(),
- mSortModifier( 0.0f ),
- mBlendingMode( Dali::ImageActor::DEFAULT_BLENDING_MODE ),
- mUsesGeometryScaling( usesGeometryScaling ),
- mScaleForSizeDirty( true ),
- mHasSizeAndColorFlag( false ),
- mResourcesReady( false ),
- mFinishedResourceAcquisition( false ),
- mHasUntrackedResources( false )
-{
-}
-
-RenderableAttachment::~RenderableAttachment()
-{
-}
-
-void RenderableAttachment::Initialize( SceneController& sceneController, BufferIndex updateBufferIndex )
-{
- mSceneController = &sceneController;
-
- // Chain to derived attachments
- Initialize2( updateBufferIndex );
-}
-
-void RenderableAttachment::OnDestroy()
-{
- // Chain to derived attachments
- OnDestroy2();
-
- // SceneController is no longer valid
- mSceneController = NULL;
-}
-
-void RenderableAttachment::SetRecalculateScaleForSize()
-{
- mScaleForSizeDirty = true;
-}
-
-void RenderableAttachment::GetScaleForSize( const Vector3& nodeSize, Vector3& scaling )
-{
- DoGetScaleForSize( nodeSize, scaling );
- mScaleForSizeDirty = false;
-}
-
-bool RenderableAttachment::ResolveVisibility( BufferIndex updateBufferIndex )
-{
- mHasSizeAndColorFlag = mParent->ResolveVisibility(updateBufferIndex);
- return mHasSizeAndColorFlag;
-}
-
-void RenderableAttachment::DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling )
-{
- scaling = Vector3::ONE;
-}
-
-void RenderableAttachment::PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager )
-{
- mHasUntrackedResources = false; // Only need to know this if the resources are not yet complete
- mTrackedResources.Clear(); // Resource trackers are only needed if not yet completea
-
- if( mShader )
- {
- Integration::ResourceId id = mShader->GetEffectTextureResourceId();
-
- if( id != 0 )
- {
- CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
-
- if(CompleteStatusManager::COMPLETE != completeStatusManager.GetStatus( id ))
- {
- FollowTracker(id);
- mFinishedResourceAcquisition = false;
- mResourcesReady = false;
-
- // If shader has effect texture and it's not complete and tracked, ensure
- // we call DoPrepareResources, as the effect texture may become ready in
- // the ProcessRenderTasks step. Otherwise, may early out.
- if( mHasUntrackedResources )
- {
- return;
- }
- }
- }
- }
-
- mResourcesReady = DoPrepareResources( updateBufferIndex, resourceManager );
-}
-
-void RenderableAttachment::FollowTracker( Integration::ResourceId id )
-{
- CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
-
- if( completeStatusManager.FindResourceTracker(id) != NULL )
- {
- bool found = false;
- std::size_t numTrackedResources = mTrackedResources.Count();
- for( size_t i=0; i < numTrackedResources; ++i )
- {
- if(mTrackedResources[i] == id)
- {
- found = true;
- break;
- }
- }
- if( ! found )
- {
- mTrackedResources.PushBack( id );
- }
- }
- else
- {
- mHasUntrackedResources = true;
- }
-}
-
-
-void RenderableAttachment::GetReadyAndComplete(bool& ready, bool& complete) const
-{
- ready = mResourcesReady;
- complete = false;
-
- CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
-
- std::size_t numTrackedResources = mTrackedResources.Count();
- if( mHasUntrackedResources || numTrackedResources == 0 )
- {
- complete = mFinishedResourceAcquisition;
- }
- else
- {
- // If there are tracked resources and no untracked resources, test the trackers
- bool trackersComplete = true;
- for( size_t i=0; i < numTrackedResources; ++i )
- {
- ResourceId id = mTrackedResources[i];
- ResourceTracker* tracker = completeStatusManager.FindResourceTracker(id);
- if( tracker && ! tracker->IsComplete() )
- {
- trackersComplete = false;
- break;
- }
- }
-
- complete = mFinishedResourceAcquisition || trackersComplete;
- }
-}
-
-RenderableAttachment* RenderableAttachment::GetRenderable()
-{
- return this;
-}
-
-void RenderableAttachment::SetSortModifier(float modifier)
-{
- // Setting sort modifier makes the node dirty, i.e. we cannot reuse previous frames render items
- if( mParent )
- {
- // only do this if we are on-stage
- mParent->SetDirtyFlag( SortModifierFlag );
- }
- mSortModifier = modifier;
-}
-
-void RenderableAttachment::SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes )
-{
- sortAttributes.shader = mShader;
- sortAttributes.textureResourceId = Integration::InvalidResourceId;
- sortAttributes.geometry = NULL;
-}
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__
-
-/*
- * Copyright (c) 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/internal/common/blending-options.h>
-#include <dali/internal/common/internal-constants.h>
-#include <dali/internal/common/type-abstraction-enums.h>
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/update/controllers/scene-controller.h>
-#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
-#include <dali/internal/update/resources/resource-manager-declarations.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-class ResourceManager;
-class ResourceTracker;
-
-namespace Render
-{
-class Renderer;
-}
-namespace SceneGraph
-{
-class Shader;
-class SortAttributes;
-struct RendererWithSortAttributes;
-
-/**
- * RenderableAttachments are responsible for preparing textures, meshes, matrices etc. during the Update.
- * These resources are then passed to a renderer, for use in the next Render.
- */
-class RenderableAttachment : public NodeAttachment
-{
-protected:
- /**
- * Protected constructor; only derived classes can be instantiated.
- * @param usesGeometryScaling should be false if the derived class does not need geometry scaling
- */
- RenderableAttachment( bool usesGeometryScaling );
-
- /**
- * Virtual destructor, no deletion through this interface
- */
- virtual ~RenderableAttachment();
-
-private: // From NodeAttachment
-
- /**
- * @copydoc NodeAttachment::Initialize().
- */
- virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex );
-
- /**
- * @copydoc NodeAttachment::OnDestroy().
- */
- virtual void OnDestroy();
-
- /**
- * @copydoc NodeAttachment::GetRenderable()
- */
- virtual RenderableAttachment* GetRenderable();
-
-public: // Connection API for derived classes
- /**
- * Chained from RenderableAttachment::Initialize()
- */
- virtual void Initialize2( BufferIndex updateBufferIndex ) = 0;
-
- /**
- * Chained from RenderableAttachment::OnDestroy()
- */
- virtual void OnDestroy2() = 0;
-
-
-public: // API
-
- /**
- * @See Dali::RenderableActor::SetBlendMode().
- */
- void SetBlendingMode( BlendingMode::Type mode );
-
- /**
- * @copydoc Dali::RenderableActor::GetBlendMode().
- */
- BlendingMode::Type GetBlendingMode() const;
-
- /**
- * Flag to check if any geometry scaling is needed, inlined as called from update algorithm often
- * @return true if the derived renderable uses geometry scaling
- */
- bool UsesGeometryScaling() const
- {
- return mUsesGeometryScaling;
- }
-
- /**
- * Triggers scale for size update. GetScaleForSize will be called in this frame
- */
- void SetRecalculateScaleForSize();
-
- /**
- * Returns the scaling dirty flag, inlined as called from update algorithm often
- * @return if scale for size is dirty, i.e. scaling has changed
- */
- bool IsScaleForSizeDirty() const
- {
- return mScaleForSizeDirty;
- }
-
- /**
- * Retrieve scale-for-size for given node size
- * Clears the scale for size flag
- * @param[in] nodeSize to scale to
- * @param[out] scaling factors
- */
- void GetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
-
-
-public: // For use during in the update algorithm only
-
- /**
- * @param[in] updateBufferIndex The current update buffer index.
- * @return visible tells if this renderer can be potentially seen
- */
- bool ResolveVisibility( BufferIndex updateBufferIndex );
-
- /**
- * if this renderable actor has visible size and color
- * @return true if you can potentially see this actor
- */
- bool HasVisibleSizeAndColor() const
- {
- return mHasSizeAndColorFlag;
- }
-
- /**
- * Prepare the object resources.
- * This must be called by the UpdateManager before calling PrepareRender, for each frame.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] resourceManager The resource manager.
- */
- void PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
-
- /**
- * If the resource is being tracked, then follow it. ( Further ready tests will use this
- * list ) Otherwise, if it's not complete, set mHasUntrackedResources.
- * @param[in] The resource id
- */
- void FollowTracker( Integration::ResourceId id );
-
- /**
- * Check whether the attachment has been marked as ready to render
- * @param[out] ready TRUE if the attachment has resources to render
- * @param[out] complete TRUE if the attachment's resources are complete
- * (e.g. image has finished loading, framebuffer is ready to render, native image
- * framebuffer has been rendered)
- */
- void GetReadyAndComplete(bool& ready, bool& complete) const;
-
-public: // API for derived classes
-
- /**
- * Retrieve a Renderer used by this attachment; implemented in derived classes.
- * @note The first Renderer is the main renderer for the attachment, and
- * should always exist during the lifetime of the RenderableAttachment.
- * @return A Renderer.
- */
- virtual Render::Renderer& GetRenderer() = 0;
-
- /**
- * Retrieve a Renderer used by this attachment.
- * @note The first Renderer is the main renderer for the attachment, and
- * should always exist during the lifetime of the RenderableAttachment.
- * Other renderers are for effects such as shadows and reflections.
- * @return A Renderer.
- */
- virtual const Render::Renderer& GetRenderer() const = 0;
-
- /**
- * Prepare the object resources.
- * This must be called by the UpdateManager before calling PrepareRender, for each frame.
- * @param[in] updateBufferIndex The current buffer index.
- * @param[in] resourceManager The resource manager.
- * @return True if resources are ready, false will prevent PrepareRender being called for this attachment.
- */
- virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) = 0;
-
- /**
- * Prepare the object for rendering.
- * This is called by the UpdateManager when an object is due to be rendered in the current frame.
- * @param[in] updateBufferIndex The current update buffer index.
- */
- virtual void DoPrepareRender( BufferIndex updateBufferIndex ) = 0;
-
- /**
- * Query whether the attachment is fully opaque.
- * @param[in] updateBufferIndex The current update buffer index.
- * @return True if fully opaque.
- */
- virtual bool IsFullyOpaque( BufferIndex updateBufferIndex ) = 0;
-
- /**
- * Called to notify that the size has been changed
- * The implementation may tell the renderer to recalculate scale
- * based on the new size
- * @param[in] updateBufferIndex The current update buffer index.
- */
- virtual void SizeChanged( BufferIndex updateBufferIndex ) = 0;
-
- /**
- * Retrieve the scale-for-size for given node size. Default implementation returns Vector3::ZERO
- * @param[in] nodeSize to scale to
- * @param[out] scaling factors
- */
- virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
-
- /**
- * Set the sort-modifier for the attachment.
- * @param[in] modifier The depth-sort modifier.
- */
- void SetSortModifier(float modifier);
-
- /**
- * Get the depth index for the attachment
- * @param[in] bufferIndex The current update buffer index.
- */
- virtual int GetDepthIndex()
- {
- return static_cast<int>( mSortModifier );
- }
-
- /**
- * Write the attachment's sort attributes to the passed in reference
- * @todo MESH_REWORK Consider removing this after merge with scene-graph-renderer-attachment,
- * and allowing PrepareRenderInstruction to read directly from this object
- *
- * @param[in] bufferIndex The current update buffer index.
- * @param[out] sortAttributes
- */
- virtual void SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes );
-
-private:
-
- // Undefined
- RenderableAttachment( const RenderableAttachment& );
-
- // Undefined
- RenderableAttachment& operator=( const RenderableAttachment& rhs );
-
-protected:
- SceneController* mSceneController; ///< Used for initializing renderers whilst attached
- Shader* mShader; ///< A pointer to the shader
-
- Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
-
- float mSortModifier;
-
- BlendingMode::Type mBlendingMode:2; ///< Whether blending is used to render the renderable attachment. 2 bits is enough for 3 values
-
- bool mUsesGeometryScaling:1; ///< True if the derived renderer uses scaling.
- bool mScaleForSizeDirty:1; ///< True if mScaleForSize has changed in the current frame.
- bool mHasSizeAndColorFlag:1; ///< Set during the update algorithm to tell whether this renderer can potentially be seen
- bool mResourcesReady:1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
- bool mFinishedResourceAcquisition:1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
- bool mHasUntrackedResources:1; ///< Set during PrepareResources, true if have tried to follow untracked resources
-};
-
-// Messages for RenderableAttachment
-
-inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const RenderableAttachment& attachment, BlendingMode::Type mode )
-{
- typedef MessageValue1< RenderableAttachment, BlendingMode::Type > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- new (slot) LocalType( &attachment, &RenderableAttachment::SetBlendingMode, mode );
-}
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__
return ( mBehavior == Dali::Layer::LAYER_2D ) || mDepthTestDisabled;
}
+void Layer::ClearRenderables()
+{
+ stencilRenderables.Clear();
+ colorRenderables.Clear();
+ overlayRenderables.Clear();
+}
+
} // namespace SceneGraph
} // namespace Internal
#include <dali/public-api/actors/layer.h>
#include <dali/internal/event/common/event-thread-services.h>
#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment-declarations.h>
namespace Dali
{
namespace Internal
{
-class RenderableAttachment;
-
// value types used by messages
template <> struct ParameterType< Dali::Layer::SortFunctionType >
: public BasicType< Dali::Layer::SortFunctionType > {};
/**
* Pair of node-renderer
*/
-struct NodeRenderer
+struct Renderable
{
- NodeRenderer()
+ Renderable()
:mNode(0),
mRenderer(0)
{}
- NodeRenderer( Node* node, Renderer* renderer )
+ Renderable( Node* node, Renderer* renderer )
:mNode(node),
mRenderer(renderer)
{}
Renderer* mRenderer;
};
-typedef Dali::Vector< NodeRenderer > NodeRendererContainer;
+typedef Dali::Vector< Renderable > RenderableContainer;
/**
* Layers have a "depth" relative to all other layers in the scene-graph.
return mIsDefaultSortFunction;
}
+ /**
+ * Clears all the renderable lists
+ */
+ void ClearRenderables();
+
private:
/**
public: // For update-algorithms
- RenderableAttachmentContainer stencilRenderables;
- RenderableAttachmentContainer colorRenderables;
- RenderableAttachmentContainer overlayRenderables;
-
- NodeRendererContainer stencilRenderers;
- NodeRendererContainer colorRenderers;
- NodeRendererContainer overlayRenderers;
+ RenderableContainer stencilRenderables;
+ RenderableContainer colorRenderables;
+ RenderableContainer overlayRenderables;
private:
#include <dali/internal/update/rendering/scene-graph-geometry.h>
#include <dali/internal/update/rendering/scene-graph-material.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
-#include <dali/internal/render/renderers/render-new-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/data-providers/node-data-provider.h>
#include <dali/internal/update/resources/complete-status-manager.h>
#include <dali/internal/update/nodes/node.h>
// Tell renderer about a new provider
// @todo MESH_REWORK Should we instead create a new renderer when these change?
- typedef MessageValue1< Render::NewRenderer, OwnerPointer<RenderDataProvider> > DerivedType;
+ typedef MessageValue1< Render::Renderer, OwnerPointer<RenderDataProvider> > DerivedType;
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
- new (slot) DerivedType( mRenderer, &Render::NewRenderer::SetRenderDataProvider, dataProvider );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::SetRenderDataProvider, dataProvider );
mResendDataProviders = false;
}
// The first call to GetRenderGeometry() creates the geometry and sends it in a message
RenderGeometry* geometry = mGeometry->GetRenderGeometry( mSceneController );
- typedef MessageValue1< Render::NewRenderer, RenderGeometry* > DerivedType;
+ typedef MessageValue1< Render::Renderer, RenderGeometry* > DerivedType;
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
- new (slot) DerivedType( mRenderer, &Render::NewRenderer::SetGeometry, geometry );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::SetGeometry, geometry );
mResendGeometry = false;
}
}
RenderDataProvider* dataProvider = NewRenderDataProvider();
RenderGeometry* renderGeometry = mGeometry->GetRenderGeometry(mSceneController);
- mRenderer = Render::NewRenderer::New( dataProvider, renderGeometry );
+ mRenderer = Render::Renderer::New( dataProvider, renderGeometry );
mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer );
mResendDataProviders = false;
mResendGeometry = false;
#include <dali/internal/update/common/uniform-map.h>
#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
#include <dali/internal/render/data-providers/render-data-provider.h>
-#include <dali/internal/render/renderers/render-new-renderer.h>
#include <dali/internal/update/resources/resource-manager.h>
namespace Dali
namespace Render
{
-class NewRenderer;
+class Renderer;
}
namespace SceneGraph
{
+class SceneController;
class Renderer;
typedef Dali::Vector< Renderer* > RendererContainer;
RenderDataProvider* NewRenderDataProvider();
SceneController* mSceneController; ///< Used for initializing renderers whilst attached
- Render::NewRenderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
+ Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
Material* mMaterial; ///< The material this renderer uses. (Not owned)
Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)