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


C++ Shader::Link方法代码示例

本文整理汇总了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));
	}
开发者ID:edunad,项目名称:TomatoLib,代码行数:26,代码来源:Render.cpp

示例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;
	}
开发者ID:RedRingRico,项目名称:7DFPS_2014,代码行数:66,代码来源:MaterialManager.cpp

示例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);
//.........这里部分代码省略.........
开发者ID:beltegeuse,项目名称:Amaterasu3D,代码行数:101,代码来源:ShadersLoader.cpp

示例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;
    }
开发者ID:Epidilius,项目名称:PhysicsHackAndSlash,代码行数:101,代码来源:ShaderManager.cpp


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