本文整理汇总了C++中Shader::Link方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::Link方法的具体用法?C++ Shader::Link怎么用?C++ Shader::Link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shader
的用法示例。
在下文中一共展示了Shader::Link方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __shaderStuff
void __shaderStuff(Shader& s) {
s.Link();
s.Use();
glBindFragDataLocation(s.ProgramHandle, 0, "outColor");
glUniform1i(glGetUniformLocation(s.ProgramHandle, "tex"), 0);
GLint posAttrib = glGetAttribLocation(s.ProgramHandle, "position");
glEnableVertexAttribArray(posAttrib);
checkGL;
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 9, 0);
checkGL;
GLint tposAttrib = glGetAttribLocation(s.ProgramHandle, "texpos");
checkGL;
glEnableVertexAttribArray(tposAttrib);
checkGL;
glVertexAttribPointer(tposAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 9, (void*)(sizeof(float) * 3));
checkGL;
GLint colAttrib = glGetAttribLocation(s.ProgramHandle, "color");
checkGL;
glEnableVertexAttribArray(colAttrib);
checkGL;
glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 9, (void*)(sizeof(float) * 5));
}
示例2: CreateShader
FPS_UINT32 MaterialManager::CreateShader(
const MATERIAL_SHADER &p_ShaderInfo,
std::list< std::string > &p_ShaderParameters,
MD5_DIGEST &p_ShaderDigest )
{
Shader *pMaterialShader = new Shader( );
if( p_ShaderInfo.Types & SHADER_TYPE_VERTEX )
{
if( pMaterialShader->CreateShaderFromSource(
p_ShaderInfo.VertexSource, SHADER_TYPE_VERTEX,
p_ShaderInfo.VertexFile ) != FPS_OK )
{
std::cout << "[FPS::MaterialManager::CreateShader] <ERROR> "
"Failed to compile the vertex shader" << std::endl;
return FPS_FAIL;
}
}
if( p_ShaderInfo.Types & SHADER_TYPE_FRAGMENT )
{
if( pMaterialShader->CreateShaderFromSource(
p_ShaderInfo.FragmentSource, SHADER_TYPE_FRAGMENT,
p_ShaderInfo.FragmentFile ) != FPS_OK )
{
std::cout << "[FPS::MaterialManager::CreateShader] <ERROR> "
"Failed to compile the vertex shader" << std::endl;
return FPS_FAIL;
}
}
if( p_ShaderInfo.Types & SHADER_TYPE_GEOMETRY )
{
if( pMaterialShader->CreateShaderFromSource(
p_ShaderInfo.GeometrySource, SHADER_TYPE_GEOMETRY,
p_ShaderInfo.GeometryFile ) != FPS_OK )
{
std::cout << "[FPS::MaterialManager::CreateShader] <ERROR> "
"Failed to compile the vertex shader" << std::endl;
return FPS_FAIL;
}
}
pMaterialShader->GetShaderParameters( p_ShaderParameters );
pMaterialShader->Link( );
pMaterialShader->GetDigest( p_ShaderDigest );
std::pair< std::map< MD5_DIGEST, Shader * >::iterator, bool >
ShaderMapResult;
ShaderMapResult = m_Shaders.insert( std::pair< MD5_DIGEST, Shader * >(
p_ShaderDigest, pMaterialShader ) );
if( ShaderMapResult.second == false )
{
// The shader wasn't added, so delete it
std::cout << "[FPS::MaterialManager::CreateShader] <INFO> "
"Duplicate shader detected, not adding" << std::endl;
SafeDelete< Shader >( pMaterialShader );
}
return FPS_OK;
}
示例3: LoadFromFile
Shader* ShadersLoader::LoadFromFile(const std::string& Filename)
{
TiXmlDocument doc(Filename.c_str());
if (!doc.LoadFile())
{
Logger::Log() << "[ERROR] TinyXML error : " << doc.ErrorDesc() << "\n";
throw CLoadingFailed(Filename, "unable to load xml with TinyXML");
}
// Get the root
TiXmlHandle hdl(&doc);
TiXmlElement *root = hdl.FirstChild("Shader").Element();
// Problem to find the root
if (!root)
{
throw CLoadingFailed(Filename, "unable to find root (Shader)");
}
// Get the shader name and display it
std::string name;
std::string shaderTypeName;
TinyXMLGetAttributeValue<std::string>(root, "name", &name);
TinyXMLGetAttributeValue<std::string>(root, "type", &shaderTypeName);
Logger::Log() << "[INFO] Load shader : " << name << " ( " << shaderTypeName
<< " ) ... \n";
ShaderType shaderType;
if (shaderTypeName == "Basic")
shaderType = BASIC_SHADER;
else if (shaderTypeName == "GBuffer")
shaderType = GBUFFER_SHADER;
else
throw CException("unknow shader type");
// Load the shader compiler config
ShaderCompilerConfig config = LoadShaderCompilerConfig(root);
// Get the 2 files name
// * Vertex shader
TiXmlElement *shadername = root->FirstChildElement("VertexShader");
if (!shadername)
{
throw CLoadingFailed(Filename, "unable to find VertexShader (Shader)");
}
std::string vertexShadername = std::string(
shadername->Attribute("filename"));
Logger::Log() << " * Vertex shader : " << vertexShadername << "\n";
// * Fragment shader
shadername = root->FirstChildElement("FragmentShader");
if (!shadername)
{
throw CLoadingFailed(Filename, "unable to find VertexShader (Shader)");
}
std::string fragmentShadername = std::string(
shadername->Attribute("filename"));
Logger::Log() << " * Fragment shader : " << fragmentShadername << "\n";
/*
* Find full path
*/
vertexShadername =
CMediaManager::Instance().FindMedia(vertexShadername).Fullname();
fragmentShadername =
CMediaManager::Instance().FindMedia(fragmentShadername).Fullname();
Shader* shader = 0;
shadername = root->FirstChildElement("GeometryShader");
if (shadername != 0)
{
std::string geometryShadername = std::string(
shadername->Attribute("filename"));
Logger::Log() << " * Geometry shader : " << geometryShadername
<< "\n";
geometryShadername = CMediaManager::Instance().FindMedia(
geometryShadername).Fullname();
std::string in, out;
TinyXMLGetAttributeValue(shadername, "in", &in);
TinyXMLGetAttributeValue(shadername, "out", &out);
shader = CShaderManager::Instance().loadfromFile(
vertexShadername.c_str(), fragmentShadername.c_str(),
geometryShadername.c_str(), shaderType, config);
shader->SetGeometryShaderParameters(OpenGLEnumFromString(in),
OpenGLEnumFromString(out));
}
else
{
Logger::Log() << " * No Geometry shader\n";
// Shader creation ....
shader = CShaderManager::Instance().loadfromFile(
vertexShadername.c_str(), fragmentShadername.c_str(),
shaderType, config);
}
shader->Link();
// Attrib blinding ...
LoadShaderAttributs(shader, root);
// Textures uniform
LoadShaderTextures(shader, root);
// Matrix uniform
LoadShaderMatrix(shader, root);
// FBO
LoadShaderFBO(shader, root);
//.........这里部分代码省略.........
示例4: LoadShader
//.........这里部分代码省略.........
{
Error(false, "Failed to load the vertex shader");
return nullptr;
}
//Allocate memory for the source string including the version preprocessor information
GLchar* vertexSource = nullptr;
//Do we append a version to the vertex source?
if(appendVersion == true)
{
vertexSource = (GLchar*)malloc(vertexShaderFile.GetBufferSize() + versionStringSize);
//Prepend our vertex shader source string with the supported GLSL version so
//the shader will work on ES, Legacy, and OpenGL 3.2 Core Profile contexts
if(ServiceLocator::GetPlatformLayer()->GetPlatformType() == PlatformType_iOS)
{
sprintf(vertexSource, "#version %d es\n%s", version, vertexShaderFile.GetBuffer());
}
else
{
sprintf(vertexSource, "#version %d\n%s", version, vertexShaderFile.GetBuffer());
}
}
else
{
vertexSource = (GLchar*)malloc(vertexShaderFile.GetBufferSize());
sprintf(vertexSource, "%s", vertexShaderFile.GetBuffer());
}
//Was .fsh appended to the filename? If it was, remove it
string fragmentShader = string(aFragmentShader);
found = fragmentShader.find(".fsh");
if(found != std::string::npos)
{
fragmentShader.erase(found, 4);
}
//Get the path for the fragment shader file
string fragmentPath = ServiceLocator::GetPlatformLayer()->GetPathForResourceInDirectory(fragmentShader.c_str(), "fsh", directory.c_str());
//Load the fragment shader
File fragmentShaderFile(fragmentPath);
//Safety check the fragment shader
if(fragmentShaderFile.GetBufferSize() == 0)
{
Error(false, "Failed to load the fragment shader");
return nullptr;
}
//Allocate memory for the source string including the version preprocessor information
GLchar* fragmentSource = nullptr;
//Do we append a version to the fragment source?
if(appendVersion == true)
{
fragmentSource = (GLchar*)malloc(fragmentShaderFile.GetBufferSize() + versionStringSize);
//Prepend our fragment shader source string with the supported GLSL version so
//the shader will work on ES, Legacy, and OpenGL 3.2 Core Profile contexts
if(ServiceLocator::GetPlatformLayer()->GetPlatformType() == PlatformType_iOS)
{
sprintf(fragmentSource, "#version %d es\n%s", version, fragmentShaderFile.GetBuffer());
}
else
{
sprintf(fragmentSource, "#version %d\n%s", version, fragmentShaderFile.GetBuffer());
}
}
else
{
fragmentSource = (GLchar*)malloc(fragmentShaderFile.GetBufferSize());
sprintf(fragmentSource, "%s", fragmentShaderFile.GetBuffer());
}
//Create a new shader with the vertex and fragment shaders
Shader* shader = new Shader(vertexSource, fragmentSource);
shader->SetKey(key);
//Cycle through the attributes and add them to the shader
for(unsigned int i = 0; i < aAttributes.size(); i++)
{
shader->AddAttribute(aAttributes.at(i).c_str());
}
//Link the shader
shader->Link();
//Set the shader map pair for the filename key
m_ShaderMap[key] = shader;
//Free the memory for the vertex and fragment sources
free(vertexSource);
free(fragmentSource);
}
//Return the shader object
return shader;
}