Beispiel #1
0
void Shader::build()
{
	m_vertexShader = compileVertexShader(m_strVertexShader->cstr());
	m_fragmentShader = compileFragmentShader(m_strFragmentShader->cstr());
	m_shaderProgram = linkShaderProgram(m_vertexShader, m_fragmentShader);

	const SPVRTPFXUniformSemantic* semantics = PVRTPFXSemanticsGetSemanticList();

	for (int i = 0; i < m_uniforms->count(); ++i)
	{
		SPVRTPFXUniform& uniform = m_uniforms->get(i);
		const SPVRTPFXUniformSemantic& semantic = semantics[uniform.nSemantic];

		if (semantic.isAttrib)
		{
			uniform.nLocation = glGetAttribLocation(m_shaderProgram, uniform.sValueName->cstr());
			m_isAttributeRequired[semantic.n] = true;			
			++m_numAttributesRequired;
		}
		else
		{
			uniform.nLocation = glGetUniformLocation(m_shaderProgram, uniform.sValueName->cstr());

			// Check for array. Workaround for some OpenGL:ES implementations which require array element appended to uniform name
			// in order to return the correct location.
			if (uniform.nLocation == -1)
			{
				ByteArray* szTmpUniformName = ByteArray::create(uniform.sValueName->cstr());
				szTmpUniformName->append("[0]");
				uniform.nLocation = glGetUniformLocation(m_shaderProgram, szTmpUniformName->cstr());
			}
		}
	}
}
Beispiel #2
0
GLhandleARB linkVertexAndFragmentShader(const char* shaderFileName)
	{
	/* Compile the vertex and fragment shaders: */
	GLhandleARB vertexShader=compileVertexShader(shaderFileName);
	GLhandleARB fragmentShader=compileFragmentShader(shaderFileName);
	
	/* Link the shader program: */
	GLhandleARB shaderProgram=glLinkShader(vertexShader,fragmentShader);
	
	/* Release the compiled shaders (won't get deleted until shader program is released): */
	glDeleteObjectARB(vertexShader);
	glDeleteObjectARB(fragmentShader);
	
	return shaderProgram;
	}
Beispiel #3
0
void PShader::loadVertexShader(std::string src) {
    this->vertSrc = loadBytes(src);
    compileVertexShader();
    glAttachShader(glProgram, glVertex);
    glLinkProgram(glProgram);
}
Beispiel #4
0
void PShader::setVertexShader(std::string src) {
    vertSrc=src;
    compileVertexShader();
    glAttachShader(glProgram, glVertex);
    glLinkProgram(glProgram);
}