Beispiel #1
0
//##ModelId=4C32C8AB0148
void fluid::glExtension::btGLShaderModel_4_0::createGeometryShader(const char* path, const char* entry,btGLBufferBundle *bundle)
{
	if(hasGeometry)
		cgDestroyProgram(geometryShader);

	if(path == NULL)
		hasGeometry=false;

	geometryShader=cgCreateProgramFromFile(context,CG_SOURCE,path,getProfile(CG_GL_GEOMETRY),entry,NULL);

	if(bundle != NULL)
	{
		//search for bindable uniform
		GLint max;
		glGetIntegerv(GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT,&max);
		char uniformBufferName[256];
		for(int i=0;i < max;i++)
		{
			sprintf_s(uniformBufferName,256,"geometry_bindable_uniform_%d",i);
			if(bundle->existsName(uniformBufferName))
			{
				CGbuffer buf=bundle->getBindableUniformBufferIdForName(uniformBufferName);
				cgSetProgramBuffer(geometryShader,i,buf);
			}
		}
	}

	cgGLLoadProgram(geometryShader);
	hasGeometry=true;
}
//[-------------------------------------------------------]
//[ Public virtual PLRenderer::ProgramUniformBlock functions ]
//[-------------------------------------------------------]
bool ProgramUniformBlockCg::SetUniformBuffer(PLRenderer::UniformBuffer *pUniformBuffer, uint32 nBindingPoint)
{
	// Cg hides the binding point internally, so the given binding point is ignored in here...

	// Is there an uniform buffer given?
	if (pUniformBuffer) {
		// The given uniform buffer must have at least the same number of bytes as this uniform block and the shader language must match!
		if (cgGetParameterResourceSize(m_pCgParameter) <= static_cast<long>(pUniformBuffer->GetSize()) && m_sShaderLanguage == pUniformBuffer->GetShaderLanguage()) {
			// The Cg-documentation states: (http://http.developer.nvidia.com/Cg/cgSetProgramBuffer.html)
			// "When the next program bind operation occurs, each buffer index which is set to a valid buffer handle is bound (along with the program) for use by the 3D API"
			cgSetProgramBuffer(cgGetParameterProgram(m_pCgParameter), cgGetParameterBufferIndex(m_pCgParameter), static_cast<UniformBufferCg*>(pUniformBuffer)->GetCgBuffer());
		} else {
			// Error!
			return false;
		}
	} else {
		cgSetProgramBuffer(cgGetParameterProgram(m_pCgParameter), cgGetParameterBufferIndex(m_pCgParameter), nullptr);
	}

	// Done
	return true;
}