Esempio n. 1
0
void OpenGL3Driver::set_uniform(const UniformBuffer& uniform, size_t unit)
{
    const OpenGL3UniformBuffer* buffer = static_cast<const OpenGL3UniformBuffer*>(uniform.impl());
    if (state_.uniforms[unit] != uniform.id())
    {
        buffer->bind(unit);
        state_.uniforms[unit] = uniform.id();
    }
    buffer->enable(current_shader_program_, unit);
    CHECK_GL_ERRORS();
}
Esempio n. 2
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;
}
Esempio n. 3
0
		inline void doRenderNonInstanced( RenderPass const & pass
			, UniformBuffer & ubo
			, Scene const & scene
			, PickingPass::NodeType type
			, MapType & nodes )
		{
			uint32_t count{ 1u };

			for ( auto itPipelines : nodes )
			{
				pass.updatePipeline( *itPipelines.first );
				itPipelines.first->apply();
				auto drawIndex = ubo.getUniform< UniformType::eUInt >( DrawIndex );
				auto nodeIndex = ubo.getUniform< UniformType::eUInt >( NodeIndex );
				drawIndex->setValue( uint8_t( type ) + ( ( count & 0x00FFFFFF ) << 8 ) );
				uint32_t index{ 0u };

				for ( auto & renderNode : itPipelines.second )
				{
					nodeIndex->setValue( index++ );
					ubo.update();

					if ( renderNode.m_data.isInitialised() )
					{
						doRenderNodeNoPass( renderNode );
					}
				}

				count++;
			}
		}
Esempio n. 4
0
		inline void doTraverseNodes( RenderPass const & pass
			, UniformBuffer & ubo
			, MapType & nodes
			, PickingPass::NodeType type
			, FuncType function )
		{
			uint32_t count{ 1u };

			for ( auto itPipelines : nodes )
			{
				pass.updatePipeline( *itPipelines.first );
				itPipelines.first->apply();
				auto drawIndex = ubo.getUniform< UniformType::eUInt >( DrawIndex );
				auto nodeIndex = ubo.getUniform< UniformType::eUInt >( NodeIndex );
				drawIndex->setValue( uint8_t( type ) + ( ( count & 0x00FFFFFF ) << 8 ) );
				uint32_t index{ 0u };

				for ( auto itPass : itPipelines.second )
				{
					for ( auto itSubmeshes : itPass.second )
					{
						nodeIndex->setValue( index++ );
						ubo.update();
						function( *itPipelines.first
							, *itPass.first
							, *itSubmeshes.first
							, itSubmeshes.first->getInstantiation()
							, itSubmeshes.second );
					}
				}

				count++;
			}
		}
Esempio n. 5
0
void OpenGL3Driver::bind_uniform(const UniformBuffer& uniform, size_t unit)
{
    const OpenGL3UniformBuffer* buffer = static_cast<const OpenGL3UniformBuffer*>(uniform.impl());
    // TODO: need to add state checks
    buffer->bind(current_shader_program_, unit);
    CHECK_GL_ERRORS();
}
Esempio n. 6
0
	bool UniformBuffer::TextWriter::operator()( UniformBuffer const & object, TextFile & file )
	{
		bool result = file.writeText( m_tabs + cuT( "constants_buffer \"" ) + object.getName() + cuT( "\"\n" ) ) > 0
						&& file.writeText( m_tabs + cuT( "{\n" ) ) > 0;
		checkError( result, "Frame variable buffer" );
		auto tabs = m_tabs + cuT( "\t" );

		if ( result )
		{
			for ( auto & variable : object )
			{
				if ( result )
				{
					result = file.writeText( tabs + cuT( "variable \"" ) + variable->getName() + cuT( "\"\n" ) ) > 0
						&& file.writeText( tabs + cuT( "{\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable name" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "\tcount " ) + string::toString( variable->getOccCount() ) + cuT( "\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable occurences" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "\ttype " ) + variable->getFullTypeName() + cuT( "\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable type name" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "\tvalue " ) + variable->getStrValue() + cuT( "\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable value" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "}\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable end" );
				}
			}
		}

		if ( result )
		{
			result = file.writeText( m_tabs + cuT( "}\n" ) ) > 0;
			checkError( result, "Frame variable buffer end" );
		}

		return result;
	}
Esempio n. 7
0
void GraphicScreen::set_active_uniform_buffers(GraphicContext_State *state)
{
    int old_max_uniform_buffers = active_state.uniform_buffers.size();
    active_state.uniform_buffers = state->uniform_buffers;
    unsigned int max_uniform_buffers = active_state.uniform_buffers.size();
    for (unsigned int cnt = 0; cnt < max_uniform_buffers; cnt++)
    {
        UniformBuffer buffer = active_state.uniform_buffers[cnt];
        if (buffer.is_null())
        {
            provider->reset_uniform_buffer(cnt);
        }
        else
        {
            provider->set_uniform_buffer(cnt, buffer);
        }
    }
    for (unsigned int cnt = max_uniform_buffers; cnt < old_max_uniform_buffers; cnt++)
    {
        provider->reset_uniform_buffer(cnt);
    }
}
Esempio n. 8
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);
	}
}
Esempio n. 9
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 );
    }
}
Esempio n. 10
0
void Application::InitSSAO()
{
    m_Renderer->SetUsePostProcessing(true);

    m_SSAO = new PostProcessingEffect(m_Renderer);
    m_SSAO->LoadEffect(Load("Common/SSAO.ppe"));
    m_Renderer->AddPostProcessingEffect(m_SSAO);

    m_SSAORandomTex = m_Renderer->GetRasterizer()->CreateTexture();
    m_SSAORandomTex->CreateTexture(4,4,Texture::PT_FLOAT);

    for(i32 x = 0; x < 4; x++)
    {
        for(i32 y = 0; y < 4; y++)
        {
            m_SSAORandomTex->SetPixel(Vec2(x,y),Vec4(Random(-1.0f,1.0f),Random(-1.0f,1.0f),0.0f,1.0f));
        }
    }
    m_SSAORandomTex->UpdateTexture();
    m_SSAO->GetStage(0)->GetMaterial()->SetMap(Material::MT_CUSTOM0,m_SSAORandomTex);

    UniformBuffer* SSAOInputs = m_SSAO->GetStage(0)->GetMaterial()->GetUserUniforms();

    vector<Vec3> SSAOKernel;
    for(i32 i = 0; i < SSAOInputs->GetUniformInfo(0)->ArraySize; i++)
    {
        Vec3 Sample = RandomVec(1.0f);
        Sample.z = abs(Sample.z);
        Sample.Normalize();

        Scalar Scale = Scalar(i) / Scalar(SSAOInputs->GetUniformInfo(0)->ArraySize);
        Scale = 0.1f + ((1.0f - 0.1f) * pow(Scale,2.0f));
        Sample *= Scale;
        SSAOKernel.push_back(Sample);
    }

    SSAOInputs->SetUniform(0,SSAOKernel);
    SSAOInputs->SetUniform(1,SSAOInputs->GetUniformInfo(0)->ArraySize);
    SSAOInputs->SetUniform(2,0.2f);
    SSAOInputs->SetUniform(3,1.0f);
    SetSSAONoiseScale(4);
}
Esempio n. 11
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    UniformBuffer<Variable<int>,Variable<double>,Variable<float>> ub;    
    ub.f(); // provoke error to show the deduced types First and Args...
}
	void GL3GraphicContextProvider::set_uniform_buffer(int index, const UniformBuffer &buffer)
	{
		OpenGL::set_active(this);
		glBindBufferBase(GL_UNIFORM_BUFFER, index, static_cast<GL3UniformBufferProvider*>(buffer.get_provider())->get_handle());
	}