Example #1
0
bool RenderDevice::setupRenderStateMatrix( const RenderState& state )
{
    const Matrix4x3& matModel = state.modelMatrix;
    const Matrix4x3& matView = activeView->viewMatrix;
    const Matrix4x4& matProjection = activeView->projectionMatrix;

    UniformBuffer* ub = state.renderable->getUniformBuffer().get();
    ub->setUniform( "vp_ModelMatrix", matModel );
    ub->setUniform( "vp_ViewMatrix", matView );
    ub->setUniform( "vp_ProjectionMatrix", matProjection );

    return true;
}
Example #2
0
void Model::setupShaderSkinning()
{
	// Setup matrices.
	std::vector<Matrix4x4> matrices;
	matrices.reserve( bones.size() );

	for( size_t i = 0; i < bones.size(); ++i )
	{
		const Matrix4x3& bone = bones[i];
		matrices.push_back( Matrix4x4(bone) );
	}

	// Send them to the uniform buffer.
	const std::vector<RenderBatchPtr>& rends = getRenderables();

	for( size_t i = 0; i < rends.size(); ++i )
	{
		const RenderBatch* rend = rends[i].get();
		
		UniformBuffer* ub = rend->getUniformBuffer().get();
		ub->setUniform("vp_BonesMatrix", matrices);
	}
}
Example #3
0
void RenderDevice::bindTextureUnits(const RenderState& state, bool bindUniforms)
{
    TextureUnitMap& units = state.material->textureUnits;
    UniformBuffer* ub = state.renderable->getUniformBuffer().get();

    TextureUnitMap::ConstIterator it;
    for( it = units.Begin(); it != units.End(); it++ )
    {
        const TextureUnit& unit = it->second;
        const ImageHandle& handle = unit.image;

        Texture* texture = activeContext->textureManager->getTexture(handle).get();
        if( !texture ) continue;

        if( !texture->isUploaded() )
        {
            renderBackend->uploadTexture(texture);
            renderBackend->configureTexture(texture);
        }

        renderBackend->bindTexture(texture);
        renderBackend->setupTextureUnit(texture, unit);
        
        if( !bindUniforms ) continue;

        char s_TextureUniform[] = "vp_Texture0";
        size_t s_TextureUniformSize = FLD_ARRAY_SIZE(s_TextureUniform) - 2;

        // Build the uniform string without allocating memory.
        uint8 index = unit.unit;
        char indexChar = (index + '0');
        
        s_TextureUniform[s_TextureUniformSize] = indexChar;
        ub->setUniform( s_TextureUniform, (int32) index );
    }
}