Пример #1
0
    //
    // Link
    //
    void CCgShadingProgram::Link()
    {
        m_UniformCache.clear();
        m_SamplerUniformCache.clear();
        m_BindableUniformCache.clear();
    
        //m_Samplers.clear();

        if (cgIsProgram( m_Program ))
            cgDestroyProgram( m_Program );
            
        if (m_Shaders.size() == 1)
            m_Program = m_Shaders[ 0 ]->m_Program;
        else
        {
            vector<CGprogram> Programs;

            for (CONST_VECTOR_ITERATION( Ptr<const CCgShader>, m_Shaders, i ))
                Programs.push_back( (*i)->m_Program );
                
            m_Program = cgCombinePrograms( static_cast<int>( Programs.size() ), &Programs[ 0 ] );
            CGerror Error = cgGetError();
            if (Error != CG_NO_ERROR)
                throw CCgException( this, Error, "::Link() : Failed to combine Cg program." );
        }

        cgGLLoadProgram( m_Program );
        CGerror Error = cgGetError();
        if (Error != CG_NO_ERROR)
            throw CCgException( this, Error, "::Link() : Failed to load Cg program. Program may fails to load for any reason." );

         sort( m_Profiles.begin(), m_Profiles.end() );
    }
Пример #2
0
int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize(1000, 1000);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("Fractal Shader");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(mouseMove);
    glutMouseFunc(mouseAction);
    glutIdleFunc(OnIdle);
    glutKeyboardFunc(keyAction);
    glutKeyboardUpFunc(keyUp);
    glClearColor(0, 0, 0, 1);
    CGcontext context = cgCreateContext();
    if(context == NULL){
        printf("Failed to create CGcontext\n");
        return 1;
    }
	f_prof = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
	v_prof = cgGLGetLatestProfile(CG_GL_VERTEX);
	printf("%d, %d\n", f_prof, v_prof);
    chdir("/Users/peter/Desktop/CG/cgtest");
    julia = cgCreateProgramFromFile(context, CG_SOURCE, "Julia.cg", f_prof, "main", NULL);
    newton = cgCreateProgramFromFile(context, CG_SOURCE, "Newton.cg", f_prof, "main", NULL);
    mandel = cgCreateProgramFromFile(context, CG_SOURCE, "Mandel.cg", f_prof, "main", NULL);
    ship = cgCreateProgramFromFile(context, CG_SOURCE, "Ship.cg", f_prof, "main", NULL);
    pass = cgCreateProgramFromFile(context, CG_SOURCE, "Pass.cg", v_prof, "main", NULL);
	gen = cgCreateProgramFromFile(context, CG_SOURCE, "GenIter.cg", f_prof, "main", NULL);
    printf("%s\n", cgGetErrorString(cgGetError()));
    cgGLLoadProgram(julia);
    cgGLLoadProgram(newton);
    cgGLLoadProgram(mandel);
    cgGLLoadProgram(ship);
	cgGLLoadProgram(gen);
    cgGLLoadProgram(pass);
    //printf("%s\n", cgGetErrorString(cgGetError()));
    cgGLEnableProfile(f_prof);
    cgGLEnableProfile(v_prof);
    printf("%s\n", cgGetErrorString(cgGetError()));
	
	Position demoList[7];
	fillPoint(&demoList[0], 0.297205, 0.063085, 0.001157, 1.012991, 15.0, 7);
	fillPoint(&demoList[1], 0.134370, 0.042840, 0.043976, 1.008928, 15.0, 7);
	fillPoint(&demoList[2], -0.129831, -0.637758, 0.507148, 1.103996, 15.0, 7);
	fillPoint(&demoList[3], -0.162030, -1.02009, 0.041826, 0.983991, 15.0, 7);
	fillPoint(&demoList[4], -0.139263, -1.846086, 0.002345, 0.516934, 15.0, 7);
	fillPoint(&demoList[5], -0.138215, -1.910406, 0.001638, 0.495934, 15.0, 7);
	fillPoint(&demoList[6], -0.138215, -3.552904, 0.302149, 0.149937, 15.0, 7);
	
	posList = demoList;
	zoom = 0.001157;
	
    glutMainLoop();
    return 0;
}
Пример #3
0
void InitCG()
{

    if( cgGLIsProfileSupported(CG_PROFILE_ARBVP1) )
        g_CGprofile_vertex = CG_PROFILE_ARBVP1;
    else if( cgGLIsProfileSupported(CG_PROFILE_VP40) )
        g_CGprofile_vertex = CG_PROFILE_VP40;
    else
    {
		ShaderWater=false;
        return;
    }

	
	if( cgGLIsProfileSupported(CG_PROFILE_ARBFP1) )
        g_CGprofile_pixel = CG_PROFILE_ARBFP1;
    else if( cgGLIsProfileSupported(CG_PROFILE_FP30) )
        g_CGprofile_pixel = CG_PROFILE_FP30;
	else if( cgGLIsProfileSupported(CG_PROFILE_FP20) )
        g_CGprofile_pixel = CG_PROFILE_FP20;
    else
    {
		ShaderWater=false;
		return;
    }
	g_CGcontext = cgCreateContext();
	
	g_Sea_vertex = cgCreateProgramFromFile( g_CGcontext,
												CG_SOURCE,
												"Sea_vertex.cg",
												g_CGprofile_vertex,
												NULL,
												NULL );
	cgGLLoadProgram(g_Sea_vertex);
	CGerror GetCGerror=cgGetError();
	if(GetCGerror!=CG_NO_ERROR)
		MessageBox (HWND_DESKTOP, "vertex shader Error!", "Error", MB_OK | MB_ICONEXCLAMATION);
	g_Sea_pixel = cgCreateProgramFromFile( g_CGcontext,
												CG_SOURCE,
												"Sea_pixel.cg",
												g_CGprofile_pixel,
												NULL,
												NULL );

	cgGLLoadProgram(g_Sea_pixel);
	GetCGerror=cgGetError();
	if(GetCGerror!=CG_NO_ERROR)
		MessageBox (HWND_DESKTOP, "pixel shader Error!", "Error", MB_OK | MB_ICONEXCLAMATION);
} 
Пример #4
0
static bool load_program(
      cg_shader_data_t *cg,
      unsigned idx,
      const char *prog,
      bool path_is_file)
{
   bool ret = true;
   char *listing_f = NULL;
   char *listing_v = NULL;

   unsigned i, argc = 0;
   const char *argv[2 + GFX_MAX_SHADERS];

   argv[argc++] = "-DPARAMETER_UNIFORM";
   for (i = 0; i < GFX_MAX_SHADERS; i++)
   {
      if (*(cg->cg_alias_define[i]))
         argv[argc++] = cg->cg_alias_define[i];
   }
   argv[argc] = NULL;

   if (path_is_file)
   {
      cg->prg[idx].fprg = cgCreateProgramFromFile(cg->cgCtx, CG_SOURCE,
            prog, cg->cgFProf, "main_fragment", argv);
      SET_LISTING(cg, f);
      cg->prg[idx].vprg = cgCreateProgramFromFile(cg->cgCtx, CG_SOURCE,
            prog, cg->cgVProf, "main_vertex", argv);
      SET_LISTING(cg, v);
   }
   else
   {
      cg->prg[idx].fprg = cgCreateProgram(cg->cgCtx, CG_SOURCE,
            prog, cg->cgFProf, "main_fragment", argv);
      SET_LISTING(cg, f);
      cg->prg[idx].vprg = cgCreateProgram(cg->cgCtx, CG_SOURCE,
            prog, cg->cgVProf, "main_vertex", argv);
      SET_LISTING(cg, v);
   }

   if (!cg->prg[idx].fprg || !cg->prg[idx].vprg)
   {
      RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError()));
      if (listing_f)
         RARCH_ERR("Fragment:\n%s\n", listing_f);
      else if (listing_v)
         RARCH_ERR("Vertex:\n%s\n", listing_v);

      ret = false;
      goto end;
   }

   cgGLLoadProgram(cg->prg[idx].fprg);
   cgGLLoadProgram(cg->prg[idx].vprg);

end:
   free(listing_f);
   free(listing_v);
   return ret;
}
Пример #5
0
void cgErrorCallback(void){
#ifdef COMPILE_CG
	CGerror LastError = cgGetError();
	if(LastError)
		printf("%s\n\n", cgGetErrorString(LastError));
#endif
}
Пример #6
0
static void handleCgError(void) 
{
    CGerror err = cgGetError();
    fprintf(stderr, "Cg error: %s\n", cgGetErrorString(err));
    fflush(stderr);
    exit(0);
}
Пример #7
0
static bool d3d9_cg_load_program(void *data,
      void *fragment_data, void *vertex_data, const char *prog, bool path_is_file)
{
   bool ret                   = true;
   const char *list           = NULL;
   char *listing_f            = NULL;
   char *listing_v            = NULL;
   CGprogram *fPrg            = (CGprogram*)fragment_data;
   CGprogram *vPrg            = (CGprogram*)vertex_data;
   CGprofile vertex_profile   = cgD3D9GetLatestVertexProfile();
   CGprofile fragment_profile = cgD3D9GetLatestPixelProfile();
   const char **fragment_opts = cgD3D9GetOptimalOptions(fragment_profile);
   const char **vertex_opts   = cgD3D9GetOptimalOptions(vertex_profile);
   cg_renderchain_t *cg_data  = (cg_renderchain_t*)data;

   RARCH_LOG("[D3D Cg]: Vertex profile: %s\n", cgGetProfileString(vertex_profile));
   RARCH_LOG("[D3D Cg]: Fragment profile: %s\n", cgGetProfileString(fragment_profile));

   if (path_is_file && !string_is_empty(prog))
      *fPrg = cgCreateProgramFromFile(cg_data->cgCtx, CG_SOURCE,
            prog, fragment_profile, "main_fragment", fragment_opts);
   else
      *fPrg = cgCreateProgram(cg_data->cgCtx, CG_SOURCE, stock_cg_d3d9_program,
            fragment_profile, "main_fragment", fragment_opts);

   list = cgGetLastListing(cg_data->cgCtx);
   if (list)
      listing_f = strdup(list);

   if (path_is_file && !string_is_empty(prog))
      *vPrg = cgCreateProgramFromFile(cg_data->cgCtx, CG_SOURCE,
            prog, vertex_profile, "main_vertex", vertex_opts);
   else
      *vPrg = cgCreateProgram(cg_data->cgCtx, CG_SOURCE, stock_cg_d3d9_program,
            vertex_profile, "main_vertex", vertex_opts);

   list = cgGetLastListing(cg_data->cgCtx);
   if (list)
      listing_v = strdup(list);

   if (!fPrg || !vPrg)
   {
      RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError()));
      if (listing_f)
         RARCH_ERR("Fragment:\n%s\n", listing_f);
      else if (listing_v)
         RARCH_ERR("Vertex:\n%s\n", listing_v);
      ret = false;
      goto end;
   }

   cgD3D9LoadProgram(*fPrg, true, 0);
   cgD3D9LoadProgram(*vPrg, true, 0);

end:
   free(listing_f);
   free(listing_v);
   return ret;
}
Пример #8
0
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
	// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
	GLenum err = GL_REPORT_ERROR();
	if (err != GL_NO_ERROR)
	{
		ERROR_LOG(VIDEO, "glError %08x before VS!", err);
	}

#if defined HAVE_CG && HAVE_CG
	char stropt[64];
	sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
	const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
	CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts);
	if (!cgIsProgram(tempprog)) {
        if (s_displayCompileAlert) {
            PanicAlert("Failed to create vertex shader");
            s_displayCompileAlert = false;
        }
        cgDestroyProgram(tempprog);
		ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
		ERROR_LOG(VIDEO, "%s", pstrprogram);
		return false;
	}

	if (cgGetError() != CG_NO_ERROR)
	{
		WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
		WARN_LOG(VIDEO, "%s", pstrprogram);
	}

	// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
	// It SHOULD not have any nasty side effects though - but you never know...
	char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
	char *plocal = strstr(pcompiledprog, "program.local");
	while (plocal != NULL) {
		const char* penv = "  program.env";
		memcpy(plocal, penv, 13);
		plocal = strstr(plocal + 13, "program.local");
	}
	glGenProgramsARB(1, &vs.glprogid);
	SetCurrentShader(vs.glprogid);

	glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);	
	err = GL_REPORT_ERROR();
	if (err != GL_NO_ERROR) {
		ERROR_LOG(VIDEO, "%s", pstrprogram);
		ERROR_LOG(VIDEO, "%s", pcompiledprog);
	}

	cgDestroyProgram(tempprog);
#endif

#if defined(_DEBUG) || defined(DEBUGFAST) 
	vs.strprog = pstrprogram;
#endif

	return true;
}
void checkCgError() {
  CGerror error = cgGetError();
  if ( error ) {
    std::cout << "CG error: ";
    std::cout << cgGetErrorString( error ) << std::endl;
    std::cout << cgGetLastListing( context ) << std::endl;
  }
}
Пример #10
0
void ErrorCheck()
{
#ifdef HAS_CG
  CGerror error = cgGetError();
  if (error)
    printf("CG Error: %s\n", cgGetErrorString(error));
#endif //HAS_CG
}
Пример #11
0
FRAGMENTSHADER* ZZshLoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed)
{
	int texwrap;

	assert( texfilter < NUM_FILTERS );
	//assert( g_nPixelShaderVer == SHADER_30 );
	if( clamp.wms == clamp.wmt ) {
		switch( clamp.wms ) {
			case 0: texwrap = TEXWRAP_REPEAT; break;
			case 1: texwrap = TEXWRAP_CLAMP; break;
			case 2: texwrap = TEXWRAP_CLAMP; break;
			default:
				texwrap = TEXWRAP_REGION_REPEAT; break;
		}
	}
	else if( clamp.wms==3||clamp.wmt==3)
		texwrap = TEXWRAP_REGION_REPEAT;
	else
		texwrap = TEXWRAP_REPEAT_CLAMP;

	int index = GET_SHADER_INDEX(type, texfilter, texwrap, fog, s_bWriteDepth, testaem, exactcolor, context, 0);

	if( pbFailed != NULL ) *pbFailed = false;

	FRAGMENTSHADER* pf = ppsTexture+index;

	if( pf->prog != NULL )
		return pf;

	pf->prog = LoadShaderFromType(EFFECT_DIR, EFFECT_NAME, type, texfilter, texwrap, fog, s_bWriteDepth, testaem, exactcolor, g_nPixelShaderVer, context);

	if( pf->prog != NULL ) {
#ifdef _DEBUG
		char str[255];
		sprintf(str, "Texture%s%d_%sPS", fog?"Fog":"", texfilter, g_pTexTypes[type]);
		pf->filename = str;
#endif
		SetupFragmentProgramParameters(pf, context, type);
		cgGLLoadProgram(pf->prog);
		if( cgGetError() != CG_NO_ERROR ) {
			// try again
//			cgGLLoadProgram(pf->prog);
//			if( cgGetError() != CG_NO_ERROR ) {
				ZZLog::Error_Log("Failed to load shader %d,%d,%d,%d", type, fog, texfilter, 4*clamp.wms+clamp.wmt);
				if( pbFailed != NULL ) *pbFailed = true;
				//assert(0);
				// NULL makes things crash
				return pf;
//			}
		}
		return pf;
	}

	ZZLog::Error_Log("Failed to create shader %d,%d,%d,%d", type, fog, texfilter, 4*clamp.wms+clamp.wmt);
	if( pbFailed != NULL ) *pbFailed = true;

	return NULL;
}
Пример #12
0
void cgErrorCallback ()
{
	CGerror cerror = cgGetError();
	if ( cerror ) {
		const char *listing = cgGetLastListing ( cgContext );		
		printf ( "CG: %s\n%s\n", cgGetErrorString( cerror ), listing );
		exit (-1);
	}
}
Пример #13
0
	//[-------------------------------------------------------]
	//[ Private static Cg callback functions                  ]
	//[-------------------------------------------------------]
	void ShaderLanguageCg::cgErrorCallback()
	{
		const CGerror lastCgError = cgGetError();
		if (CG_NO_ERROR != lastCgError)
		{
			// Output error message
			RENDERER_OUTPUT_DEBUG_PRINTF("OpenGL Cg error: %s\n", cgGetErrorString(lastCgError))
		}
	}
Пример #14
0
void cgErrorCallback()
{
    CGerror lastError = cgGetError();
    if(lastError)
    {
        printf("%s\n", cgGetErrorString(lastError));
        printf("%s\n", cgGetLastListing(context));
    }
}
Пример #15
0
void  Cg::CheckCgError(void){
	CGerror err = cgGetError();

	if (err != CG_NO_ERROR) {
		printf("CG error: %s\n", cgGetErrorString(err));
		abort();
	}

}
Пример #16
0
void cgfxTechnique::validate() const
{
    fValid = (cgValidateTechnique(fTechnique) == CG_TRUE);
    if (fValid) {
        fErrorString = "";
    }
    else {
        CGerror error = cgGetError();
        if (error != CG_NO_ERROR) {
            fErrorString = cgGetErrorString(cgGetError());
        }
        fErrorString += "\nCg compilation errors for technique \"";
        fErrorString += fName;
        fErrorString += "\":\n";
        fErrorString += cgGetLastListing(cgfxShaderNode::sCgContext);
        fErrorString += "\n";
    }
}
Пример #17
0
  void Video::print_errors() {
#if !defined(DISABLE_GL) && !defined(REQUIRE_GL_ES)
    std::cerr << "OpenGL    : " << Zeni::gluErrorString(glGetError()) << std::endl;
#endif

#ifndef DISABLE_CG
    std::cerr << "Cg        : " << cgGetErrorString(cgGetError()) << std::endl;
#endif
  }
Пример #18
0
void cgtk::cgErrorCallback()
{
	CGerror lastError=cgGetError();
	if(lastError)
	{
		cout<< cgGetErrorString(lastError) <<endl;
		if(context!=NULL)
			cout<<cgGetLastListing(context) <<endl;
		exit(0);
	}
}
Пример #19
0
CGerror CheckCgError(int line)
{
	CGerror err = cgGetError ();

	if (err != CG_NO_ERROR)
	{
		LOG ("CG error:%d at line %d %s\n", err, line, cgGetErrorString (err));
	}

	return err;
}
Пример #20
0
// this is a handy callback for the cg errors
void cfxCgErrorCallback()
{
		CGerror error = cgGetError();
			
#ifndef _LIB
		const char* report = cgGetErrorString(error);
		printf("CG Error Detected:  %s\n", report);

		assert(0 && report);
#endif
}
Пример #21
0
//START shader glow effect -- FragBait0
inline bool LoadProgram(CGprogram* pDest, CGprofile profile, const char* szFile)
{
     const char* szGameDir = gEngfuncs.pfnGetGameDirectory();
     char file[512];
     sprintf(file, "%s/%s", szGameDir, szFile);

     *pDest = cgCreateProgramFromFile(g_cgContext, CG_SOURCE, file, profile, "main", 0);
     if (!(*pDest)) {
#ifdef _WIN32
          MessageBox(NULL, cgGetErrorString(cgGetError()), NULL, NULL);
#else
          SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "CG", cgGetErrorString(cgGetError()), NULL);
#endif
          return false;
     }

     cgGLLoadProgram(*pDest);

     return true;
}
Пример #22
0
void CgErrorCallback(void)
{
	CGerror lastError = cgGetError();
	if (lastError)
	{
		printf("%s\n", cgGetErrorString(lastError));
		printf("%s\n", cgGetLastListing(Context));
		printf("Cg error, exiting...\n");
		exit(0);
	}
}
Пример #23
0
bool ZZshStartUsingShaders() {
	cgSetErrorHandler(HandleCgError, NULL);
	g_cgcontext = cgCreateContext();

	cgvProf = CG_PROFILE_ARBVP1;
	cgfProf = CG_PROFILE_ARBFP1;
	cgGLEnableProfile(cgvProf);
	cgGLEnableProfile(cgfProf);
	cgGLSetOptimalOptions(cgvProf);
	cgGLSetOptimalOptions(cgfProf);

	cgGLSetManageTextureParameters(g_cgcontext, CG_FALSE);
	//cgSetAutoCompile(g_cgcontext, CG_COMPILE_IMMEDIATE);

	g_fparamFogColor = cgCreateParameter(g_cgcontext, CG_FLOAT4);
	g_vparamPosXY[0] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
	g_vparamPosXY[1] = cgCreateParameter(g_cgcontext, CG_FLOAT4);


	ZZLog::GS_Log("Creating effects.");
	B_G(LoadEffects(), return false);

	// create a sample shader
	clampInfo temp;
	memset(&temp, 0, sizeof(temp));
	temp.wms = 3; temp.wmt = 3;

	g_nPixelShaderVer = 0;//SHADER_ACCURATE;
	// test
	bool bFailed;
	FRAGMENTSHADER* pfrag = ZZshLoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed);
	if( bFailed || pfrag == NULL ) {
		g_nPixelShaderVer = SHADER_ACCURATE|SHADER_REDUCED;

		pfrag = ZZshLoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed);
		if( pfrag != NULL )
			cgGLLoadProgram(pfrag->prog);
		if( bFailed || pfrag == NULL || cgGetError() != CG_NO_ERROR ) {
			g_nPixelShaderVer = SHADER_REDUCED;
			ZZLog::Error_Log("Basic shader test failed.");
		}
	}

	if (g_nPixelShaderVer & SHADER_REDUCED)
		conf.bilinear = 0;

	ZZLog::GS_Log("Creating extra effects.");
	B_G(ZZshLoadExtraEffects(), return false);

	ZZLog::GS_Log("using %s shaders\n", g_pShaders[g_nPixelShaderVer]);
	return true;
}
Пример #24
0
CGerror cfxCheckCgError()
{
		CGerror error = cgGetError();
			
		if (error != CG_NO_ERROR)
		{
			const char* report = cgGetErrorString(error);
			printf("CG Error Detected:  %s\n", report);
			assert(0 && report);
		}

		return error;
}
Пример #25
0
static void cgErrorCallbackSum(void) {
    CGerror LastError = cgGetError();

    if(LastError)
    {
        const char *Listing = cgGetLastListing(errContext);
        printf("\n---------------------------------------------------\n");
        printf("%s\n\n", cgGetErrorString(LastError));
        printf("%s\n", Listing);
        printf("---------------------------------------------------\n");
        printf("Cg error, exiting...\n");
        exit(0);
    }
}
Пример #26
0
Shader::Shader(std::string shader_name)
{
  // Be carefull: Cg needs a valid OpenGL context (be sure no shader is created before we have an OpenGL window)
  if (!cg_context)
    {
      cg_context = cgCreateContext();
      vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX);      // auto-detect best vertex profile
      cgGLSetOptimalOptions(vertex_profile);
      fragment_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT);  // auto-detect best fragment profile
      cgGLSetOptimalOptions(fragment_profile);
    }
  if (shader_name.length())
    {
      vertex_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, shader_name.c_str(), vertex_profile, "VertexProgram", 0);
      CGerror vertex_error = cgGetError();
      if (vertex_error != CG_NO_ERROR)
        {
          printf("Warning: No valid vertex program found in %s: %s\n", shader_name.c_str(), cgGetErrorString(vertex_error));
          vertex_program = 0;
        }
      else
        {
          cgGLLoadProgram(vertex_program);
        }
      fragment_program = cgCreateProgramFromFile(cg_context, CG_SOURCE, shader_name.c_str(), fragment_profile, "FragmentProgram", 0);
      CGerror fragment_error = cgGetError();
      if (fragment_error != CG_NO_ERROR)
        {
          printf("Warning: No valid fragment program found in %s: %s\n", shader_name.c_str(), cgGetErrorString(fragment_error));
          fragment_program = 0;
        }
      else
        {
          cgGLLoadProgram(fragment_program);
        }
    }
}
Пример #27
0
//
// Release
//
void CCgContext::Release()
{
    if (m_RefCount == 0)
        return;

    if (--m_RefCount == 0)
    {
        cgDestroyContext( m_Context );
        CGerror Error = cgGetError();
        if (Error != CG_NO_ERROR)
            throw CCgException( "GL::CCgContext", Error, "::Release() : Failed to destroy Cg context." );

        m_Context = NULL;
    }
}
Пример #28
0
    void checkForCgError(const String& ogreMethod, const String& errorTextPrefix, CGcontext context)
    {
        CGerror error = cgGetError();
        if (error != CG_NO_ERROR)
        {
            String msg = errorTextPrefix + cgGetErrorString(error); 

            if (error == CG_COMPILER_ERROR)
            {
                // Get listing with full compile errors
                msg = msg + "\n" + cgGetLastListing(context);
            }
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msg, ogreMethod);
        }
    }
Пример #29
0
bool Glow::LoadProgram(CGprogram* pDest, CGprofile profile, const char* szFile)
{
	char file[512];
	sprintf_s(file, "%s", szFile);

	*pDest = cgCreateProgramFromFile(this->g_cgContext, CG_SOURCE, file, profile, "main", 0);
	if (!(*pDest)) {
		MessageBox(NULL, cgGetErrorString(cgGetError()), NULL, NULL);
		return false;
	}

	cgGLLoadProgram(*pDest);

	return true;
}
Пример #30
0
static __forceinline void LOAD_VS(int Index, ZZshProgram prog)
{
	assert(mapShaderResources.find(Index) != mapShaderResources.end());
	header = mapShaderResources[Index];
	assert((header) != NULL && (header)->index == (Index));
	prog = cgCreateProgram(g_cgcontext, CG_OBJECT, (char*)(s_lpShaderResources + (header)->offset), cgvProf, NULL, NULL);
	if (!cgIsProgram(prog)) 
	{
		ZZLog::Error_Log("Failed to load vs %d: \n%s", Index, cgGetLastListing(g_cgcontext));
		return false;
	}
	cgGLLoadProgram(prog);
	
	if (cgGetError() != CG_NO_ERROR) ZZLog::Error_Log("Failed to load program %d.", Index);
	SetupVertexProgramParameters(prog, !!(Index&SH_CONTEXT1));	
}