/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
// CLASS HEADER
#include <dali/internal/render/renderers/render-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/render/gl-resources/gl-texture.h>
namespace Dali
{
const Vector4* blendColor,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
- DepthWriteMode::Type depthWriteMode )
+ DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
+ DepthFunction::Type depthFunction,
+ StencilParameters& stencilParameters,
+ bool writeToColorBuffer )
{
- return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode );
+ return new Renderer( dataProvider, geometry, blendingBitmask, blendColor,
+ faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode,
+ depthFunction, stencilParameters, writeToColorBuffer );
}
Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
const Vector4* blendColor,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
- DepthWriteMode::Type depthWriteMode )
+ DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
+ DepthFunction::Type depthFunction,
+ StencilParameters& stencilParameters,
+ bool writeToColorBuffer )
: mRenderDataProvider( dataProvider ),
- mContext(NULL),
+ mContext( NULL),
mTextureCache( NULL ),
- mUniformNameCache( NULL ),
mGeometry( geometry ),
mUniformIndexMap(),
mAttributesLocation(),
+ mStencilParameters( stencilParameters ),
mBlendingOptions(),
- mFaceCullingMode( faceCullingMode ),
- mDepthWriteMode( depthWriteMode ),
mIndexedDrawFirstElement( 0 ),
mIndexedDrawElementsCount( 0 ),
+ mDepthFunction( depthFunction ),
+ mFaceCullingMode( faceCullingMode ),
+ mDepthWriteMode( depthWriteMode ),
+ mDepthTestMode( depthTestMode ),
+ mWriteToColorBuffer( writeToColorBuffer ),
mUpdateAttributesLocation( true ),
mPremultipledAlphaEnabled( preMultipliedAlphaEnabled )
{
}
}
-void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache )
+void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache )
{
mContext = &context;
mTextureCache = &textureCache;
- mUniformNameCache = &uniformNameCache;
}
Renderer::~Renderer()
}
}
-bool Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& program )
+bool Renderer::BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program )
{
- int textureUnit = 0;
+ unsigned int textureUnit = 0;
bool result = true;
+ std::vector<Render::Sampler*>& samplers( mRenderDataProvider->GetSamplers() );
+
std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
+ GLint uniformLocation(-1);
for( size_t i(0); result && i<textures.size(); ++i )
{
ResourceId textureId = textures[i].GetTextureId();
{
GLint uniformLocation;
+ //TODO : This is a bug, result variable is being shadowed. Fix it!
bool result = program.GetSamplerUniformLocation( i, uniformLocation );
if( result && Program::UNIFORM_UNKNOWN != uniformLocation )
{
program.SetUniform1i( uniformLocation, textureUnit );
- unsigned int samplerBitfield(0);
- Render::Texture& textureMapping = textures[i];
- const Render::Sampler* sampler( textureMapping.GetSampler() );
+ unsigned int samplerBitfield(ImageSampler::DEFAULT_BITFIELD);
+ const Render::Sampler* sampler( samplers[i] );
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;
+ samplerBitfield = sampler->mBitfield;
}
texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
}
}
}
+
+ std::vector<Render::NewTexture*>& newTextures( mRenderDataProvider->GetNewTextures() );
+ for( size_t i(0); result && i<newTextures.size(); ++i )
+ {
+ if( newTextures[i] )
+ {
+ result = program.GetSamplerUniformLocation( i, uniformLocation ) &&
+ newTextures[i]->Bind(context, textureUnit, samplers[i] );
+
+ if( result )
+ {
+ program.SetUniform1i( uniformLocation, textureUnit );
+ ++textureUnit;
+ }
+ }
+ }
+
return result;
}
mDepthWriteMode = depthWriteMode;
}
+void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode )
+{
+ mDepthTestMode = depthTestMode;
+}
+
DepthWriteMode::Type Renderer::GetDepthWriteMode() const
{
return mDepthWriteMode;
}
+DepthTestMode::Type Renderer::GetDepthTestMode() const
+{
+ return mDepthTestMode;
+}
+
+void Renderer::SetDepthFunction( DepthFunction::Type depthFunction )
+{
+ mDepthFunction = depthFunction;
+}
+
+DepthFunction::Type Renderer::GetDepthFunction() const
+{
+ return mDepthFunction;
+}
+
+void Renderer::SetStencilMode( StencilMode::Type stencilMode )
+{
+ mStencilParameters.stencilMode = stencilMode;
+}
+
+StencilMode::Type Renderer::GetStencilMode() const
+{
+ return mStencilParameters.stencilMode;
+}
+
+void Renderer::SetStencilFunction( StencilFunction::Type stencilFunction )
+{
+ mStencilParameters.stencilFunction = stencilFunction;
+}
+
+StencilFunction::Type Renderer::GetStencilFunction() const
+{
+ return mStencilParameters.stencilFunction;
+}
+
+void Renderer::SetStencilFunctionMask( int stencilFunctionMask )
+{
+ mStencilParameters.stencilFunctionMask = stencilFunctionMask;
+}
+
+int Renderer::GetStencilFunctionMask() const
+{
+ return mStencilParameters.stencilFunctionMask;
+}
+
+void Renderer::SetStencilFunctionReference( int stencilFunctionReference )
+{
+ mStencilParameters.stencilFunctionReference = stencilFunctionReference;
+}
+
+int Renderer::GetStencilFunctionReference() const
+{
+ return mStencilParameters.stencilFunctionReference;
+}
+
+void Renderer::SetStencilMask( int stencilMask )
+{
+ mStencilParameters.stencilMask = stencilMask;
+}
+
+int Renderer::GetStencilMask() const
+{
+ return mStencilParameters.stencilMask;
+}
+
+void Renderer::SetStencilOperationOnFail( StencilOperation::Type stencilOperationOnFail )
+{
+ mStencilParameters.stencilOperationOnFail = stencilOperationOnFail;
+}
+
+StencilOperation::Type Renderer::GetStencilOperationOnFail() const
+{
+ return mStencilParameters.stencilOperationOnFail;
+}
+
+void Renderer::SetStencilOperationOnZFail( StencilOperation::Type stencilOperationOnZFail )
+{
+ mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail;
+}
+
+StencilOperation::Type Renderer::GetStencilOperationOnZFail() const
+{
+ return mStencilParameters.stencilOperationOnZFail;
+}
+
+void Renderer::SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass )
+{
+ mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass;
+}
+
+StencilOperation::Type Renderer::GetStencilOperationOnZPass() const
+{
+ return mStencilParameters.stencilOperationOnZPass;
+}
+
+void Renderer::SetWriteToColorBuffer( bool writeToColorBuffer )
+{
+ mWriteToColorBuffer = writeToColorBuffer;
+}
+
+bool Renderer::GetWriteToColorBuffer() const
+{
+ return mWriteToColorBuffer;
+}
+
void Renderer::Render( Context& context,
SceneGraph::TextureCache& textureCache,
BufferIndex bufferIndex,
const SceneGraph::NodeDataProvider& node,
SceneGraph::Shader& defaultShader,
+ const Matrix& modelMatrix,
const Matrix& modelViewMatrix,
const Matrix& viewMatrix,
const Matrix& projectionMatrix,
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*)&mRenderDataProvider->GetShader() );
+ DALI_LOG_ERROR( "Failed to get program for shader at address %p.\n", (void*)&mRenderDataProvider->GetShader() );
return;
}
}
// Take the program into use so we can send uniforms to it
program->Use();
- if( DALI_LIKELY( BindTextures( textureCache, *program ) ) )
+ if( DALI_LIKELY( BindTextures( context, textureCache, *program ) ) )
{
// Only set up and draw if we have textures and they are all valid
// set projection and view matrix if program has not yet received them yet this frame
- SetMatrices( *program, node.GetModelMatrix( bufferIndex ), viewMatrix, projectionMatrix, modelViewMatrix );
+ SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix );
// set color uniform
GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );