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


C++ GLSLProgram类代码示例

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


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

示例1: attachChildShader

	//-----------------------------------------------------------------------
    void GLSLProgram::attachChildShader(const String& name)
	{
		// is the name valid and already loaded?
		// check with the high level program manager to see if it was loaded
		HighLevelGpuProgramPtr hlProgram = HighLevelGpuProgramManager::getSingleton().getByName(name);
		if (!hlProgram.isNull())
		{
			if (hlProgram->getSyntaxCode() == "glsl")
			{
				// make sure attached program source gets loaded and compiled
				// don't need a low level implementation for attached shader objects
				// loadHighLevelImpl will only load the source and compile once
				// so don't worry about calling it several times
				GLSLProgram* childShader = static_cast<GLSLProgram*>(hlProgram.getPointer());
				// load the source and attach the child shader only if supported
				if (isSupported())
				{
					childShader->loadHighLevelImpl();
					// add to the container
					mAttachedGLSLPrograms.push_back( childShader );
					mAttachedShaderNames += name + " ";
				}
			}
		}
	}
开发者ID:brock7,项目名称:TianLong,代码行数:26,代码来源:OgreGLSLProgram.cpp

示例2: glAttachObjectARB

	//-----------------------------------------------------------------------
	void GLSLProgram::attachToProgramObject( const GLhandleARB programObject )
	{
		glAttachObjectARB( programObject, mGLHandle );
		checkForGLSLError( "GLSLLinkProgram::GLSLLinkProgram",
			"Error attaching " + mName + " shader object to GLSL Program Object", programObject );
		// attach child objects
		GLSLProgramContainerIterator childprogramcurrent = mAttachedGLSLPrograms.begin();
		GLSLProgramContainerIterator childprogramend = mAttachedGLSLPrograms.end();

 		while (childprogramcurrent != childprogramend)
		{

			GLSLProgram* childShader = *childprogramcurrent;
			// bug in ATI GLSL linker : modules without main function must be recompiled each time 
			// they are linked to a different program object
			// don't check for compile errors since there won't be any
			// *** minor inconvenience until ATI fixes there driver
			childShader->compile(false);

			childShader->attachToProgramObject( programObject );

			++childprogramcurrent;
		}

	}
开发者ID:brock7,项目名称:TianLong,代码行数:26,代码来源:OgreGLSLProgram.cpp

示例3: createParameterMappingStructures

	//-----------------------------------------------------------------------
	void GLSLProgram::buildConstantDefinitions() const
	{
		// We need an accurate list of all the uniforms in the shader, but we
		// can't get at them until we link all the shaders into a program object.

		// Therefore instead, parse the source code manually and extract the uniforms
		createParameterMappingStructures(true);
        if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS))
        {
            GLSLProgramPipelineManager::getSingleton().extractConstantDefs(mSource, *mConstantDefs.get(), mName);
        }
        else
        {
            GLSLLinkProgramManager::getSingleton().extractConstantDefs(mSource, *mConstantDefs.get(), mName);
        }

		// Also parse any attached sources
		for (GLSLProgramContainer::const_iterator i = mAttachedGLSLPrograms.begin();
			i != mAttachedGLSLPrograms.end(); ++i)
		{
			GLSLProgram* childShader = *i;

            if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS))
            {
                GLSLProgramPipelineManager::getSingleton().extractConstantDefs(childShader->getSource(),
                                                                               *mConstantDefs.get(), childShader->getName());
            }
            else
            {
                GLSLLinkProgramManager::getSingleton().extractConstantDefs(childShader->getSource(),
                                                                           *mConstantDefs.get(), childShader->getName());
            }
		}
	}
开发者ID:JobsSteve,项目名称:gamekit-2,代码行数:35,代码来源:OgreGLSLProgram.cpp

示例4: GetShader

GLSLProgram* ShaderManager::UseShader(const char* vertName, const char* fragName, std::string vertString, std::string fragString)
{
	GLSLProgram* prog = GetShader(vertName, fragName,vertString, fragString);
	assert(prog != NULL);
	prog->use();
	return prog;
}
开发者ID:Gibgezr,项目名称:blit3d,代码行数:7,代码来源:ShaderManager.cpp

示例5: catch

void HelloGLSL::customInit()
{
    try
    {
        glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "HelloGLSL.vert");
        glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "HelloGLSL.frag");
    }
    catch (GLSLProgramException& e)
    {
        printf("%s\n", e.what());
        system("pause");
        exit(EXIT_FAILURE);
    }

    glslProgram.link();

    glGenBuffers(1, &positionBufferObject);

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);

    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    GLint positionLoc = glslProgram.getAttributeLocation("position");
    glEnableVertexAttribArray(positionLoc);
    glVertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, 0);

    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
开发者ID:henrya2,项目名称:OpenGL-Samples,代码行数:31,代码来源:HelloGLSL.cpp

示例6: drawModel

void Model::drawModel(GLSLProgram &shader) const {

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

        if (materials_[i].map_Kd != "") {
            glUniform1f(shader("useTextureMap"), 1.0); //use texture
            GLint whichID[1];
            glActiveTexture(GL_TEXTURE0);
            glGetIntegerv(GL_TEXTURE_BINDING_2D, whichID);
            if (whichID[0] != textures_[i]) {
                glBindTexture(GL_TEXTURE_2D, textures_[i]);
            }
        }
        else {
            glUniform1f(shader("useTextureMap"), 0.0);
            glUniform3fv(shader("materialKd"), 1 , glm::value_ptr(materials_[i].Kd));

            if (shader.isActive(shader("materialKs")))
                glUniform3fv(shader("materialKs"), 1 , glm::value_ptr(materials_[i].Ks));

            if (shader.isActive(shader("materialKa")))
                glUniform3fv(shader("materialKa"), 1 , glm::value_ptr(materials_[i].Ka));

            if (shader.isActive(shader("materialNs")))
                glUniform1f(shader("materialNs"), materials_[i].Ns);
        }

        if (materials_.size() == 1)
            glDrawElements(GL_TRIANGLES, indices_.size(), GL_UNSIGNED_SHORT, 0);
        else
            glDrawElements(GL_TRIANGLES, materials_[i].count, GL_UNSIGNED_SHORT,
                           (const GLvoid*)(&indices_[materials_[i].offset]));
    }
}
开发者ID:jaybird19,项目名称:FRTMProDesign,代码行数:34,代码来源:model.cpp

示例7: catch

void OgroInvasion::customInit()
{
	filename = g_programName + "/" + "Lenna.png";

	try
	{
		glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "shader.vert");
		glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "shader.frag");
	}
	catch (GLSLProgramException& e)
	{
		printf("%s\n", e.what());
		system("pause");
		exit(EXIT_FAILURE);
	}

	glslProgram.link();

	GLint vertexAttribLoc = glslProgram.getAttributeLocation("vVertex");

	//quad vertices and indices
	glm::vec2 vertices[4];
	GLushort indices[6];

	vertices[0] = glm::vec2(0.0f, 0.0f);
	vertices[1] = glm::vec2(1.0f, 0.0f);
	vertices[2] = glm::vec2(1.0f, 1.0f);
	vertices[3] = glm::vec2(0.0f, 1.0f);

	GLushort* id = indices;
	*id++ = 0;
	*id++ = 1;
	*id++ = 2;
	*id++ = 0;
	*id++ = 2;
	*id++ = 3;

	glGenVertexArrays(1, &vaoID);
	glBindVertexArray(vaoID);

	glGenBuffers(1, &vboVerticesID);
	glGenBuffers(1, &vboIndicesID);
	glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

	glVertexAttribPointer(vertexAttribLoc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
	glEnableVertexAttribArray(vertexAttribLoc);

	glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	mTexture = new Texture(filename);
	mTexture->load();
	mTexture->activateTexture(0); // GL_TEXTURE0

	glslProgram.setUniform("textureMap", 0); // GL_TEXTURE0
}
开发者ID:henrya2,项目名称:OpenGL-Samples,代码行数:60,代码来源:OgroInvasion.cpp

示例8: reloadShaders

void reloadShaders() {
	GLSLProgram* hold = new GLSLProgram();
	hold->compileShaders("C:/Users/josh/Desktop/Shader/Shaders/vertex.glsl", "C:/Users/josh/Desktop/Shader/Shaders/fragment.glsl");
	hold->addAttribute("vertexPosition");
	hold->linkShaders();
	_Program = *hold;
}
开发者ID:Jkoza,项目名称:Shader-Hot-Loading,代码行数:7,代码来源:main.cpp

示例9: setGeometryShaderParameters

void Shader::setGeometryShaderParameters(Ogre::RenderOperation::OperationType in,
        Ogre::RenderOperation::OperationType out, int max)
{
    GLSLProgram* t = static_cast<GLSLProgram*> (geometry.getPointer());
    t->setInputOperationType(in);
    t->setOutputOperationType(out);
    t->setMaxOutputVertices(max);
}
开发者ID:whztt07,项目名称:Mermelin,代码行数:8,代码来源:Shader.cpp

示例10: init

	void Renderer::init(GLSLProgram & shader)
	{
		setProjectionMatrix(30,1, 1, -100, projection);

		shader.use();
		shader.setUniformMatrix4fv("projectionMatrix", projection);
		shader.unuse();
	}
开发者ID:fluier,项目名称:BallProject,代码行数:8,代码来源:Renderer.cpp

示例11: glBindVertexArray

void SkyBox::Render()
{
  glBindVertexArray(_vao);
  GLSLProgram* p = _material->Program();
  p->SetUniform("draw_sky_box", true);
  glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  p->SetUniform("draw_sky_box", false);
}
开发者ID:raistlin969,项目名称:BaseGL,代码行数:8,代码来源:SkyBox.cpp

示例12: GLSLProgram

GLSLProgram* GLSLProgram::createFromStrings(const char *vertSrc, const char *fragSrc) {
    GLSLProgram *prog = new GLSLProgram();
    if (prog->setSourceFromStrings(vertSrc, fragSrc)) {
        return prog;
    } else {
        delete prog;
        return NULL;
    }
}
开发者ID:BobLChen,项目名称:opengl-es-2d-3d,代码行数:9,代码来源:GLSLProgram.cpp

示例13: useMaterial

void PlaneModelData::useMaterial(GLSLProgram const& prog) const
{
	prog.setUniform("material.ambient", *reinterpret_cast<glm::vec3 const*>(material.ambient));
	prog.setUniform("material.diffuse", *reinterpret_cast<glm::vec3 const*>(material.diffuse));
	prog.setUniform("material.specular", *reinterpret_cast<glm::vec3 const*>(material.specular));
	prog.setUniform("material.shininess", material.shininess);

	glActiveTexture(GL_TEXTURE0 + 5);
	glBindTexture(GL_TEXTURE_2D, (GLuint) material.texture1_map.user_ptr);
}
开发者ID:Zakallamo,项目名称:March-of-the-Bombs,代码行数:10,代码来源:PlaneModelData.cpp

示例14: sendToShader

void CascadedShadowMap::sendToShader(string sShader)
{
	GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader(sShader);
	glActiveTexture(GL_TEXTURE4);
	glBindTexture(GL_TEXTURE_2D,m_shadowMaps[0]->getTexture());
	glslProgram->sendUniform("shadowMap[0]",4);
	glActiveTexture(GL_TEXTURE5);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,m_shadowMaps[1]->getTexture());
	glslProgram->sendUniform("shadowMap[1]",5);
	glActiveTexture(GL_TEXTURE6);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,m_shadowMaps[2]->getTexture());
	glslProgram->sendUniform("shadowMap[2]",6);
	glActiveTexture(GL_TEXTURE7);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,m_shadowMaps[3]->getTexture());
	glslProgram->sendUniform("shadowMap[3]",7);

	glslProgram->sendUniform("slices[0]",m_nSlices[0]);
	glslProgram->sendUniform("slices[1]",m_nSlices[1]);
	glslProgram->sendUniform("slices[2]",m_nSlices[2]);

	m_m4LightMatrix[0] = glm::translate(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * glm::scale(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * m_m4LightMatrix[0];
	m_m4LightMatrix[1] = glm::translate(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * glm::scale(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * m_m4LightMatrix[1];
	m_m4LightMatrix[2] = glm::translate(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * glm::scale(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * m_m4LightMatrix[2];
	m_m4LightMatrix[3] = glm::translate(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * glm::scale(glm::mat4(1.0f),glm::vec3(0.5f,0.5f,0.5f)) * m_m4LightMatrix[3];

	glslProgram->sendUniform("lightMatrix[0]", &m_m4LightMatrix[0][0][0]);
	glslProgram->sendUniform("lightMatrix[1]", &m_m4LightMatrix[1][0][0]);
	glslProgram->sendUniform("lightMatrix[2]", &m_m4LightMatrix[2][0][0]);
	glslProgram->sendUniform("lightMatrix[3]", &m_m4LightMatrix[3][0][0]);
}
开发者ID:Argo15,项目名称:ArgoVox,代码行数:33,代码来源:CascadedShadowMap.cpp

示例15: GLSLProgram

GLSLProgram* ShaderManager::Load(const char* vertName, const char*fragName)
{
	GLSLProgram* prog = new GLSLProgram();
	
	if (!prog->compileShaderFromFile(vertName, GLSLShader::VERTEX))
	{
		printf("Vertex shader failed to compile!\n%s", prog->log().c_str());
		sLog(Level::Severe) << "Vertex shader <" << vertName << "> failed to compile." << prog->log();
		assert(false && "Vertex shader failed to compile");
		return NULL;
	}

	if (!prog->compileShaderFromFile(fragName, GLSLShader::FRAGMENT))
	{
		printf("Fragment shader failed to compile!\n%s", prog->log().c_str());
		sLog(Level::Severe) << "Fragment shader <" << fragName << "> failed to compile." << prog->log();
		assert(false && "Fragment shader failed to compile");
		return NULL;
	}

	if (!prog->link())
	{
		printf("Shader program failed to link!\n%s", prog->log().c_str());
		sLog(Level::Severe) << "Shader program failed to link." << prog->log();
		assert(false && "Shader program failed to link.");
		return NULL;
	}

	assert(prog != NULL);
	return prog;
}
开发者ID:Gibgezr,项目名称:blit3d,代码行数:31,代码来源:ShaderManager.cpp


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