Ejemplo n.º 1
0
	IOGLBaseShader::IOGLBaseShader(CRefPtr<COGLDevice> pDevice, const Graphic::ShaderType uType, const Graphic::ShaderVersion uVersion, CGenum uSourceType, CGprofile uProfile, const CString& strSource, const CString& strEntryPoint) :
		m_uVersion(uVersion),
		m_uType(uType),
		m_uProgram(0),
		m_bBinded(false),
		Manage::IManagedObject<COGLDevice, IOGLBaseShader>(pDevice)
	{
		if(!cgIsProfileSupported(uProfile)){
			throw Exception::CInvalidArgumentException(L"uProfile", String::FromANSI(reinterpret_cast<const int8*>(cgGetProfileString(uProfile))),
				L"Unsupported shader profile.", CR_INFO());
		}

		auto szSource = String::ToANSI(strSource);
		auto szEntryPoint = String::ToANSI(strEntryPoint);

		this->m_uProgram = cgCreateProgram(this->GetParent()->GetCGC().Get(), uSourceType, reinterpret_cast<const char*>(szSource.GetPointer()), uProfile, reinterpret_cast<const char*>(szEntryPoint.GetPointer()), 0);
		if(!cgIsProgram(this->m_uProgram)){
			CR_THROW(L"Failed to create shader program.");
		}

		cgCompileProgram(this->m_uProgram);
		if(!cgIsProgramCompiled(this->m_uProgram)){
			CR_THROW(L"Failed to compile program.");
		}

		cgGLLoadProgram(this->m_uProgram);
	}
Ejemplo n.º 2
0
void CGShader::init(const char *filename, const char *funcname, const char **options)
{
	char* gpopt[3]={0,"-profileopts Vertices=16",0};
	assert(cgIsContext(*m_pCgContext));
	//if (*m_pCGProfile == cgGLGetLatestProfile(CG_GL_GEOMETRY)){
	//	options = &gpopt[0];
	//}
    m_program = cgCreateProgramFromFile(*m_pCgContext, CG_SOURCE, filename, *m_pCGProfile, funcname, (const char**)gpopt);
    if (!cgIsProgramCompiled(m_program))
        cgCompileProgram(m_program);
    cgGLLoadProgram(m_program);
}
Ejemplo n.º 3
0
void cgtk::load_fragment_program(CGprogram &f_program,char *shader_path, char *program_name)
{
	assert(cgIsContext(context));
	f_program = cgCreateProgramFromFile(context, CG_SOURCE, shader_path,
		fragmentProfile,program_name, NULL);	
	if (!cgIsProgramCompiled(f_program))
		cgCompileProgram(f_program);

	cgGLEnableProfile(fragmentProfile);
	cgGLLoadProgram(f_program);
	cgGLDisableProfile(fragmentProfile);
}
Ejemplo n.º 4
0
void cgtk::load_vertex_program(CGprogram &v_program,char *shader_path, char *program_name)
{
	assert(cgIsContext(context));
	v_program = cgCreateProgramFromFile(context, CG_SOURCE,shader_path,
		vertexProfile,program_name, NULL);	
	if (!cgIsProgramCompiled(v_program))
		cgCompileProgram(v_program);

	cgGLEnableProfile(vertexProfile);
	cgGLLoadProgram(v_program);
	cgGLDisableProfile(vertexProfile);

}