示例#1
0
void _initCgRuntime(ID3D11Device *dev)
{
	if(gCgContext == nullptr) {
		std::cout << "[CgRuntime] Initialize Cg-Runtime-Direct3D 11" << std::endl;
		//qDebug("[Cg] Initialize Cg");
		// register the error handler
		cgSetErrorHandler( &_cgErrorHandler, NULL);
		// create a new Cg Context
		gCgContext = cgCreateContext();

		
		HRESULT hr = cgD3D11SetDevice( gCgContext, dev);
	
		if( hr != S_OK )
			return;

		// Register the default state assignment for OpenGL
		//cgD3D11RegisterStates(gCgContext);
		// This will allow the Cg runtime to manage texture binding
		//cgD3D11SetManageTextureParameters(gCgContext, CG_TRUE);
		
		gCgVertexShaderProfile = cgD3D11GetLatestVertexProfile();
		if(gCgVertexShaderProfile == CG_PROFILE_UNKNOWN)
		{
			// ERROR
			std::cout << "[CgRuntime] Error: Could not get valid Vertex-Profile." << std::endl;
			return;
		}
		
		gCgGeometryShaderProfile = cgD3D11GetLatestGeometryProfile();
		if(gCgGeometryShaderProfile == CG_PROFILE_UNKNOWN)
		{
			// WARNING
			std::cout << "[CgRuntime] Warning: Could not get valid Geometry-Profile." << std::endl;
		}
		
		gCgFragmentShaderProfile = cgD3D11GetLatestPixelProfile();
		if(gCgFragmentShaderProfile == CG_PROFILE_UNKNOWN)
		{
			// ERROR
			std::cout << "[CgRuntime] Error: Could not get valid Fragment-Profile." << std::endl;
			return;
		}

		profileOpts = cgD3D11GetOptimalOptions(gCgVertexShaderProfile);
	}
}
CgShaderProgramD3D11::CgShaderProgramD3D11(
    ShaderClass* Table, const EShaderTypes Type, const EShaderVersions Version) :
    CgShaderProgram(Table, Type, Version)
{
    switch (Type)
    {
        case SHADER_VERTEX:
            cgProfile_ = cgD3D11GetLatestVertexProfile(); break;
        case SHADER_PIXEL:
            cgProfile_ = cgD3D11GetLatestPixelProfile(); break;
        case SHADER_GEOMETRY:
            cgProfile_ = cgD3D11GetLatestGeometryProfile(); break;
        case SHADER_HULL:
            cgProfile_ = cgD3D11GetLatestHullProfile(); break;
        case SHADER_DOMAIN:
            cgProfile_ = cgD3D11GetLatestDomainProfile(); break;
        default:
            io::Log::error("Invalid shader type for Cg profile");
            break;
    }
}