本文整理汇总了C++中Shader::GetUniformLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::GetUniformLocation方法的具体用法?C++ Shader::GetUniformLocation怎么用?C++ Shader::GetUniformLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shader
的用法示例。
在下文中一共展示了Shader::GetUniformLocation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Render
void World::Render()
{
ResourceManager* resourceManager = ResourceManager::GetInstance();
glm::mat4 depthProj = glm::ortho<float>(-5, 5, -5, 5, -100, 100);
glm::mat4 depthView = glm::lookAt(mCamera->GetPosition() - glm::normalize(glm::vec3(1.0f, -3.0f, 2.0f)) * 10.0f, mCamera->GetPosition(), glm::vec3(0, 1, 0));
Shader* depthShader = resourceManager->GetShader("depth");
Shader* defaultShader = resourceManager->GetShader("default");
// Depth map rendering
mFbo->Bind();
depthShader->Bind();
RenderObjects(depthShader, depthProj, depthView, false);
mFbo->Unbind();
// World rendering
defaultShader->Bind();
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, mFbo->textureID);
glUniform1i(defaultShader->GetUniformLocation("shadowMap"), 1);
GLuint depthMVPLocation = defaultShader->GetUniformLocation("depthMVP");
glUniformMatrix4fv(depthMVPLocation, 1, GL_FALSE, &(depthProj * depthView)[0][0]);
RenderObjects(defaultShader, mProjection, mCamera->GetView(), true);
}
示例2: Initialize
bool DeferredRenderTechnique::Initialize()
{
const char vertexSource_Basic[] =
"#version 140\n"
"in vec3 VertexPosition;\n"
"uniform mat4 WorldViewProjMatrix;\n"
"void main()\n"
"{\n"
"gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);\n"
"}\n";
const char vertexSource_PostProcess[] =
"#version 140\n"
"in vec3 VertexPosition;\n"
"void main()\n"
"{\n"
"gl_Position = vec4(VertexPosition, 1.0);"
"}\n";
ShaderStage basicVertexStage(ShaderStageType_Vertex);
if (!basicVertexStage.IsValid())
{
NazaraError("Failed to create basic vertex shader");
return false;
}
basicVertexStage.SetSource(vertexSource_Basic, sizeof(vertexSource_Basic));
if (!basicVertexStage.Compile())
{
NazaraError("Failed to compile basic vertex shader");
return false;
}
ShaderStage ppVertexStage(ShaderStageType_Vertex);
if (!ppVertexStage.IsValid())
{
NazaraError("Failed to create vertex shader");
return false;
}
ppVertexStage.SetSource(vertexSource_PostProcess, sizeof(vertexSource_PostProcess));
if (!ppVertexStage.Compile())
{
NazaraError("Failed to compile vertex shader");
return false;
}
String error;
Shader* shader;
// Shaders critiques (Nécessaires pour le Deferred Shading minimal)
shader = RegisterDeferredShader("DeferredGBufferClear", r_fragmentSource_GBufferClear, sizeof(r_fragmentSource_GBufferClear), ppVertexStage, &error);
if (!shader)
{
NazaraError("Failed to register critical shader: " + error);
return false;
}
shader = RegisterDeferredShader("DeferredDirectionnalLight", r_fragmentSource_DirectionalLight, sizeof(r_fragmentSource_DirectionalLight), ppVertexStage, &error);
if (!shader)
{
NazaraError("Failed to register critical shader: " + error);
return false;
}
shader->SendInteger(shader->GetUniformLocation("GBuffer0"), 0);
shader->SendInteger(shader->GetUniformLocation("GBuffer1"), 1);
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 2);
shader->SendInteger(shader->GetUniformLocation("DepthBuffer"), 3);
shader = RegisterDeferredShader("DeferredPointSpotLight", r_fragmentSource_PointSpotLight, sizeof(r_fragmentSource_PointSpotLight), basicVertexStage, &error);
if (!shader)
{
NazaraError("Failed to register critical shader: " + error);
return false;
}
shader->SendInteger(shader->GetUniformLocation("GBuffer0"), 0);
shader->SendInteger(shader->GetUniformLocation("GBuffer1"), 1);
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 2);
shader->SendInteger(shader->GetUniformLocation("DepthBuffer"), 3);
// Shaders optionnels (S'ils ne sont pas présents, le rendu minimal sera quand même assuré)
shader = RegisterDeferredShader("DeferredBloomBright", r_fragmentSource_BloomBright, sizeof(r_fragmentSource_BloomBright), ppVertexStage, &error);
if (shader)
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
else
{
NazaraWarning("Failed to register bloom (bright pass) shader, certain features will not work: " + error);
//.........这里部分代码省略.........
示例3: _RenderMesh
void PickingRenderer::_RenderMesh( BasicObject* tempObject )
{
Transform* cameraTransform = _renderingCamera->transform;
Camera* cameraComponent = _renderingCamera->camera;
Material* material = tempObject->meshDrawing->GetMaterial();
Mesh* mesh = tempObject->meshDrawing->GetMesh();
if ( material == NULL || mesh == NULL ) return;
Shader* shader = material->GetShader();
uint programID = shader->GetProgramID( E_ShadingType::Picking );
_gl->glUseProgram( programID );
_gl->glBindBuffer( GL_ARRAY_BUFFER, mesh->GetVertexBufferID() );
_gl->glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mesh->GetIndexBufferID() );
_gl->glEnableVertexAttribArray(0);
_gl->glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) (offsetof(Vertex, position)) );
int worldLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_world" );
int viewLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_view" );
int projectionLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_projection" );
int scaleMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_scaleMat" );
int rotationMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_rotationMat" );
int positionMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_positionMat" );
int camRotationMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_camRotationMat" );
int objectIndexLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_uniqueIndex" );
Matrix4 worldMatrix = tempObject->transform->GetWorldMatrix();
Matrix4 viewMatrix = cameraTransform->GetViewMatrix();
Matrix4 projectionMatrix = cameraComponent->GetProjectionMatrix();
Matrix4 scaleMatrix = tempObject->transform->GetScaleMatrix();
Matrix4 rotationMatrix = tempObject->transform->GetRotationMatrix();
Matrix4 positionMatrix = tempObject->transform->GetPositionMatrix();
Matrix4 camRotationMatrix = cameraTransform->GetRotationMatrix();
_gl->glUniformMatrix4fv ( worldLoc, 1, GL_FALSE, worldMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( viewLoc, 1, GL_FALSE, viewMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( projectionLoc, 1, GL_FALSE, projectionMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( scaleMatLoc, 1, GL_FALSE, scaleMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( rotationMatLoc, 1, GL_FALSE, rotationMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( positionMatLoc, 1, GL_FALSE, positionMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( camRotationMatLoc, 1, GL_FALSE, camRotationMatrix.GetValuePtr() );
_gl->glUniform1i ( objectIndexLoc, tempObject->uniqueIndex );
if ( material->IsWireframe() )
{
_gl->glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
_gl->glLineWidth( material->GetLineWidth() );
_gl->glDisable( GL_CULL_FACE );
}
else
{
_gl->glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
if ( material->GetFaceCulling() == E_FaceCulling::CULL_NONE )
{
_gl->glDisable( GL_CULL_FACE );
}
else
{
_gl->glEnable(GL_CULL_FACE);
if ( material->GetFaceCulling() == E_FaceCulling::CULL_BACK )
_gl->glCullFace( GL_BACK );
if ( material->GetFaceCulling() == E_FaceCulling::CULL_FRONT )
_gl->glCullFace( GL_FRONT );
}
}
if ( mesh->GetMeshType() == E_MeshType::POLYGON )
_gl->glDrawElements( GL_TRIANGLES, mesh->GetNumIndices(), GL_UNSIGNED_INT, 0 );
else
_gl->glDrawElements( GL_LINES, mesh->GetNumIndices(), GL_UNSIGNED_INT, 0 );
// unbind
_gl->glBindBuffer( GL_ARRAY_BUFFER, 0 );
_gl->glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
_gl->glUseProgram( 0 );
}