当前位置: 首页>>代码示例>>C++>>正文


C++ ShaderProgram::Bind方法代码示例

本文整理汇总了C++中ShaderProgram::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::Bind方法的具体用法?C++ ShaderProgram::Bind怎么用?C++ ShaderProgram::Bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShaderProgram的用法示例。


在下文中一共展示了ShaderProgram::Bind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Render

void SimpleRender::Render(ICamera* camera, const Vector4f& lightPosition) {

    ShaderProgram* shader = isAo ? m_aoShader : m_simpleShader;

    // bind shader of the batch.
    shader->Bind();

    m_vertexBuffer->EnableVertexAttribInterleavedWithBind();

    shader->SetUniform("textureArray", 0);
    Texture::SetActiveTextureUnit(0);
    m_arrayTexture->Bind();

    shader->SetUniform("aoOnly", 1.0f);

    Matrix4f modelMatrix = Matrix4f::CreateIdentity(); //geoObj->GetModelMatrix();

    shader->SetPhongUniforms(
	modelMatrix
	, camera, lightPosition);

    for(size_t i = 0; i < m_chunks.size(); ++i) {

	Chunk* chunk = m_chunks[i];

	chunk->m_indexBuffer->Bind();
	chunk->m_indexBuffer->DrawIndices(GL_TRIANGLES, (chunk->m_numTriangles)*3);
	chunk->m_indexBuffer->Unbind();
    }

    m_vertexBuffer->DisableVertexAttribInterleavedWithBind();

    m_arrayTexture->Unbind();

}
开发者ID:Erkaman,项目名称:graphics-experiments,代码行数:35,代码来源:simple_render.cpp

示例2: Init

void MaterialManager::Init(unsigned int reserveObjectsCount)
{
	LOG_INFO("Init material manager");
	mCurrentMaterial = nullptr;

	mMaterials.reserve(reserveObjectsCount);

	ShaderProgram * program = new ShaderProgram();
	Shader * vertexShader = new Shader(File::GetRelative("Shaders/default.vert"), ShaderType::VertexShader);
	Shader * fragmentShader = new Shader(File::GetRelative("Shaders/default.frag"), ShaderType::FragmentShader);
	program->AddShader(*vertexShader);
	program->AddShader(*fragmentShader);
	program->Compile();
	program->Bind(); // To make sure nothing goes wrong before the first update loop
	
	mDefaultMaterial = new Material(program);
	//mDefaultMaterial->SetShaderProgram(*program);
	//mDefaultMaterial->BindShadersAndTextures();
}
开发者ID:jorisshh,项目名称:GameEngine,代码行数:19,代码来源:MaterialManager.cpp

示例3: Draw

	void GLText::Draw(ShaderProgram &program, GLCamera &camera) const {
		program.Bind();
		glUniformMatrix4fv(program.getUniformLocation("camera"), 1, GL_FALSE, glm::value_ptr(camera.PVMatrix()));
		glm::mat4 model;
		model = glm::translate(model, position);
		model = glm::rotate(model, glm::radians(rotation.x), { 1,0,0 });
		model = glm::rotate(model, glm::radians(rotation.y+180), { 0,1,0 });
		model = glm::rotate(model, glm::radians(rotation.z), { 0,0,1 });
		model = glm::scale(model, scale);
		glUniformMatrix4fv(program.getUniformLocation("model"), 1, GL_FALSE, glm::value_ptr(model));

		glDisable(GL_CULL_FACE);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, textureid);

		glBindVertexArray(vao);
		glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr); // Draw plane with 36 vertices
		glBindVertexArray(0);

		glBindTexture(GL_TEXTURE_2D, 0);
		glActiveTexture(0);
		glEnable(GL_CULL_FACE);

	}
开发者ID:SerraPlo,项目名称:JocsEnXarxa,代码行数:24,代码来源:GLText.cpp

示例4: RenderInitialPose

	void ModelRenderer::RenderInitialPose( Model & p_Model )
	{
		// Get const free graphic device
		GraphicDevice & graphicDevice = const_cast<GraphicDevice &>( m_GraphicDevice );

		// Get the default shader program.
		ShaderProgram * pShaderProgram = m_GraphicDevice.GetDefaultShaderProgram( GraphicDevice::InitialPoseShader );

		// Error check the shader program.
		if( pShaderProgram == NULL )
		{
			return;
		}

		// Error check the vertex data.
		if( p_Model.GetVertexGroup( ).GetVertexDataCount( ) == 0 )
		{
			return;
		}

		// Bind the shader program.
		pShaderProgram->Bind( );

		// Set uniform data.
		pShaderProgram->SetUniformMatrix4x4f( "uProjectionMatrix", MatrixManager::GetProjectionMatrix( ) );
		pShaderProgram->SetUniformMatrix4x4f( "uModelViewMatrix", MatrixManager::GetModelViewMatrix( ) );

		// Set light uniforms
		GraphicDevice::DefaultModelSettings & modelSettings =  graphicDevice.GetDefaultModelSettings( );

		// Set light count
		pShaderProgram->SetUniform1i( "uLightCount", modelSettings.GetActiveLightCount( ) );

		// Set ambient color
		const Vector3f32 & ambColor = modelSettings.GetAmbientLight( );
		pShaderProgram->SetUniform3f("uAmbientColor", ambColor.x, ambColor.y, ambColor.z);

		// Go throguh all the lights
		for( SizeType i = 0; i < modelSettings.GetActiveLightCount( ); i++ )
		{
			std::stringstream positionStream;
			positionStream << "uLightPositions[" << i << "]";
			std::stringstream colorStream;
			colorStream << "uLightColors[" << i << "]";

			const Vector4f32 & pos = modelSettings.GetLight( i ).GetPosition( );
			const Vector3f32 & color = modelSettings.GetLight( i ).GetColor( );
			pShaderProgram->SetUniform4f( positionStream.str( ).c_str( ), pos.x, pos.y, pos.z, pos.w );
			pShaderProgram->SetUniform3f( colorStream.str( ).c_str( ), color.x, color.y, color.z );
		}

		// Get the vertex group
		ModelVertexGroup & vertexGroup = p_Model.GetVertexGroup( );

		// Go throguh all the vertex data elements.
		for( SizeType i = 0; i < vertexGroup.GetVertexDataCount( ); i++ )
		{
			// Get the current vertex data.
			ModelVertexData * vertexData = vertexGroup.GetVertexData( i );

			// Error check the vertex data pointer.
			if( vertexData == NULL || vertexData->GetVertexArray( ) == NULL )
			{
				continue;
			}

			// Get the model material
			const ModelMaterial & material = vertexData->GetMaterial();

			// Bind the color texture if any
			Texture * pTexture = material.GetColorTexture();

			//pShaderProgram->SetUniform4f( "uColor", 1.0f, 1.0f, 1.0f, 1.0f );
			if (vertexData->GetBitmask() & 0x02 && pTexture)
			{
				pShaderProgram->SetUniform1i( "uUseTexture", 1 );
			}
			else
			{
				pShaderProgram->SetUniform1i( "uUseTexture", 0 );
			}

			// Set use normals flag.
			if( vertexData->GetBitmask( ) & 0x04 )
			{
				pShaderProgram->SetUniform1i( "uUseNormals", 1 );
			}
			else
			{
				pShaderProgram->SetUniform1i( "uUseNormals", 0 );
			}

			// Set diffuse color
			Vector4f32 diffuseColor = material.GetDiffuseColor();
			pShaderProgram->SetUniform4f("uDiffuseColor", diffuseColor.x, diffuseColor.y, diffuseColor.z, diffuseColor.w);

			// Bind the texture.
			if( pTexture )
			{
				pTexture->Bind( 0 );
//.........这里部分代码省略.........
开发者ID:jimmiebergmann,项目名称:Bit-Engine,代码行数:101,代码来源:ModelRenderer.cpp


注:本文中的ShaderProgram::Bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。