Ejemplo n.º 1
0
void
Scene::loadShader() 
{
	std::string sourcePtr = read("vshader.cg");

	auto optimal = cgD3D11GetOptimalOptions(mCgVertexShaderProfile);

	mVertexShaderId = cgCreateProgram(mCgContext, CG_SOURCE, sourcePtr.c_str(), mCgVertexShaderProfile, "main", optimal);

	if(mVertexShaderId != nullptr)
	{
		optimal = cgD3D11GetOptimalOptions(mCgFragmentShaderProfile);

		HRESULT res = cgD3D11LoadProgram(mVertexShaderId, NULL);

		CGerror error;
		const char *errorString = cgGetLastErrorString(&error);
		sourcePtr = read("fshader.cg");
		mFragmentShaderId = cgCreateProgram(mCgContext, CG_SOURCE, sourcePtr.c_str(), mCgFragmentShaderProfile, "main", optimal);
		errorString = cgGetLastErrorString(&error);
		res = cgD3D11LoadProgram(mFragmentShaderId, NULL);
	}

	// here the uniform can be set 
	CGparameter location = cgGetNamedParameter(mVertexShaderId, "ambient");
	checkForCgError("could not get uniform color location", mCgContext, false);
	cgSetParameter4fv(location, glm::value_ptr(glm::vec4(1.0,1.0,1.0,1.0)));
	checkForCgError("could not set uniform color", mCgContext, false);

	bindShader(mVertexShaderId, mFragmentShaderId);

}
Ejemplo n.º 2
0
static void checkForCgError( const char * situation, CGcontext myCgContext, bool _exit = true )
{
	CGerror error;
	const char *string = cgGetLastErrorString(&error);

	if( error != CG_NO_ERROR ) 
	{
		if( error == CG_COMPILER_ERROR ) 
		{
			fprintf(stderr,
				"Situation: %s\n"
				"Error: %s\n\n"
				"Cg compiler output...\n%s",
				situation, string,
				cgGetLastListing(myCgContext));
		} 
		else 
		{
			fprintf(stderr,
				"Situation: %s\n"
				"Error: %s", situation, string);
		}

		if( _exit )
			exit(1);
	}
}
Ejemplo n.º 3
0
bool GLCgShader::CheckForError(const std::string& situation, const std::string& additionalInfo)
{
	CGerror error;
	const char *string = cgGetLastErrorString(&error);

	if (error != CG_NO_ERROR)
	{
		std::string text = "Situation: ";
		text.append(situation);
		text.append("\nCg error string: ");
		text.append(string);
		text.append("\nAdditional info: ");
		text.append(additionalInfo);
		if (error == CG_COMPILER_ERROR)
		{
			text += "\nCg compiler error: ";
			text += cgGetLastListing(m_cgContext);
		}
		if (error == CG_UNKNOWN_PROFILE_ERROR)
		{
			text += "\nThe current profile is not supported!";
		}
		ShowMessage(text, error == CG_COMPILER_ERROR ? GSMT_ERROR : GSMT_WARNING);
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 4
0
	void checkForCgError(const char *situation){
		CGerror error;
		const char *string = cgGetLastErrorString(&error);

		if(error == CG_NO_ERROR) return;
		printf("%s: %s\n", situation, string);
		if(error == CG_COMPILER_ERROR)
			printf("%s\n", cgGetLastListing(mCgContext));
	}
Ejemplo n.º 5
0
	void checkForCgError(const char *situation, const char* ShaderName = NULL)
	{
		CGerror error;
		const char *string = cgGetLastErrorString(&error);

		if (error != CG_NO_ERROR) 
		{
			io::Logger::Error("%s: %s: %s\n",
				ShaderName, situation, string);
		}
	}
Ejemplo n.º 6
0
	bool CGFXShader::LoadFromFile(const char* szFile)
	{
		HRESULT hr = S_OK;

		char buffer[128];
		m_pEffect = cgCreateEffectFromFile( m_pCG, szFile, NULL );
		
		CGerror error;
		const char *string = cgGetLastErrorString(&error);

		static char szError[1024];
		if( error != CG_NO_ERROR ) 
		{
			if( error == CG_COMPILER_ERROR ) 
			{
				sprintf(szError,
					"Program: %s\n"
					"Error: %s\n\n"
					"Cg compiler output...\n%s",
					szFile, string,
					cgGetLastListing(m_pCG));
			} 
			else 
			{
				sprintf(szError,
	                "Program: %s\n"
					"Error: %s",
					szFile, string);
			}

			OutputDebugStringA(szError);
			OutputDebugStringA("\n");

		}
   
		if(m_pEffect == NULL)
		{
			return false;
		}

		CGtechnique pTechnique = cgGetFirstTechnique( m_pEffect );
		while( pTechnique && cgValidateTechnique( pTechnique ) == CG_FALSE ) 
		{
			pTechnique = cgGetNextTechnique( pTechnique );
		}
			
		if( pTechnique == NULL) 
		{
			return false;
		}
		m_pTechnique = pTechnique;
		
		return true;
	}
Ejemplo n.º 7
0
// error checking routine for Cg
static void checkForCgError(const char *situation) {
  CGerror error;
  const char *string = cgGetLastErrorString(&error);

  if (error != CG_NO_ERROR) {
    printf("%s: %s\n", situation, string);
    if (error == CG_COMPILER_ERROR) {
      printf("%s\n", cgGetLastListing(cg_context));
    }
    exit(1);
  }
}
Ejemplo n.º 8
0
void ShaderSystem::checkError(const char *situation)
{
	CGerror error;
	const char *string = cgGetLastErrorString(&error);
	if (error != CG_NO_ERROR) {
		printf("%s: %s\n",situation, string);
		if (error == CG_COMPILER_ERROR) {
			printf("%s\n", cgGetLastListing(cgContext));
		}
		systemError("cg error");
	}
}
Ejemplo n.º 9
0
bool GLCgShaderContext::CheckForError(const std::string& situation)
{
	CGerror error;
	const char *string = cgGetLastErrorString(&error);

	if (error != CG_NO_ERROR)
	{
		std::stringstream ss;
		ss << "Situation: " << situation << "\nError: " << string;
		ShowMessage(ss, GSMT_ERROR);
		return true;
	}
	return false;
}
Ejemplo n.º 10
0
static void checkForCgError(const char *situation)
{
	CGerror error;
	const char *string = cgGetLastErrorString(&error);

	if (error != CG_NO_ERROR) {
		printf("CGERR: %s: %s\n",
				situation, string);
		if (error == CG_COMPILER_ERROR) {
//			printf("%s\n", cgGetLastListing(prof));
			printf("compile error\n");
		}
	}
}
Ejemplo n.º 11
0
CgEffect::CgEffect(CGcontext context, const char* filename, bool fromFile)
    : effect(NULL),
    context(context),
    activeTechnique(NULL),
    currentPass(NULL),
    nextPass(NULL)
{
    effect = cgCreateEffectFromFile(context, filename, NULL);

    CGerror error;
    const char* errorStr = cgGetLastErrorString(&error);

    if(error)
        throw new GeexShaderException("CG Effect creation failed", errorStr);
}
Ejemplo n.º 12
0
 bool _check_error(CGcontext context) {
     CGerror error;
     const char* str = cgGetLastErrorString(&error);
     if(error != CG_NO_ERROR) {
         if(error == CG_COMPILER_ERROR) {
             const char* listing =  cgGetLastListing(context);
             if(listing)
                 log_error(std::string(str) + listing);
             else
                 log_error(str);
         } else 
             log_error(str);
         return false;
     }
     return true;
 }
Ejemplo n.º 13
0
 bool _check_error(CGcontext context, const wchar_t* file = 0) {
     CGerror error;
     const char* str = cgGetLastErrorString(&error);
     if(error != CG_NO_ERROR) {
         if(error == CG_COMPILER_ERROR) {
             const char* listing =  cgGetLastListing(context);
             if(listing) {
                 LOG_CG_ERROR(std::string(str) + listing, file);
             }
             else {
                 LOG_CG_ERROR(str, file);
             }
         } else {
             LOG_CG_ERROR(str, file);
         }
         return false;
     }
     return true;
 }
	i32 CCGShaderSystem::CheckForErrors(lpcastr situation, lpcastr lpszShaderName)
	{
		CGerror error;
		const char *string = cgGetLastErrorString(&error);

		if( error != CG_NO_ERROR ) 
		{
			if( error == CG_COMPILER_ERROR ) 
			{
				/*fprintf(stderr,
					"Program: %s\n"
					"Situation: %s\n"
					"Error: %s\n\n"
					"Cg compiler output...\n%s",
					lpszShaderName, situation, string,
					cgGetLastListing( m_CGContext ));
				XST_LOG_ERR( stderr );*/
				XST_LOG_ERR(	"Program: " << lpszShaderName << 
								"\nSituation: " << situation << 
								"\nError: " << string <<
								"\nCg compiler output: " << cgGetLastListing( m_CGContext ) );
			} 
			else 
			{
				/*fprintf(stderr,
					"Program: %s\n"
					"Situation: %s\n"
					"Error: %s",
					lpszShaderName, situation, string);
				XST_LOG_ERR( stderr );*/
				XST_LOG_ERR(	"Program: " << lpszShaderName << 
								"\nSituation: " << situation << 
								"\nError: " << string );
			}

			return XST_FAIL;
		}

		return XST_OK;
	}
Ejemplo n.º 15
0
static void checkForCgError(const char *situation)
{
	char buffer[4096];
	CGerror error;
	const char *string = cgGetLastErrorString(&error);

	if (error != CG_NO_ERROR) {
		if (error == CG_COMPILER_ERROR) {
			sprintf(buffer,
					"Program: %s\n"
					"Situation: %s\n"
					"Error: %s\n\n"
					"Cg compiler output...\n",
					g_strWindowTitle, situation, string);
			OutputDebugStringA(buffer);
			OutputDebugStringA(cgGetLastListing(g_cgContext));
			sprintf(buffer,
					"Program: %s\n"
					"Situation: %s\n"
					"Error: %s\n\n"
					"Check debug output for Cg compiler output...",
					g_strWindowTitle, situation, string);
			MessageBoxA(0, buffer,
						"Cg compilation error", MB_OK | MB_ICONSTOP | MB_TASKMODAL);
		}
		else {
			sprintf(buffer,
					"Program: %s\n"
					"Situation: %s\n"
					"Error: %s",
					g_strWindowTitle, situation, string);
			MessageBoxA(0, buffer,
						"Cg runtime error", MB_OK | MB_ICONSTOP | MB_TASKMODAL);
		}
		exit(1);
	}
}
Ejemplo n.º 16
0
static sBool GetCgError(const sStringDesc &errors)
{
#if sCOMP_CG_ENABLE
  CGerror error;
  const sChar8 *string = cgGetLastErrorString(&error);

  if(error==CG_NO_ERROR) return sFALSE;

  sErrorString temp0;
  sErrorString temp1;
  sCopyString(temp0,string,0x4000);

  if(error==CG_COMPILER_ERROR)
  {
    const sChar8 *msg = cgGetLastListing(CGC);
    if(msg)
      sCopyString(temp1,msg,0x4000);
  }
  sSPrintF(errors,L"%s\n%s",temp0,temp1);
  return sTRUE;
#else
  return sTRUE;
#endif
}
Ejemplo n.º 17
0
//---------------------------------------------------------------------------------
// init
// this function load and compile a vertex/fragment program on the specified context
// if the source file is not found, it assigns a default GREEN color shader
// if the compile failed, it assigns a default RED color shader
//---------------------------------------------------------------------------------
bool FFxProgram::init(CGcontext aContext)
{
	CGenum	fileType;

	// remove existing program (in case a program is already loaded)

	if (mProgram)
	{
		cgDestroyProgram(mProgram);
		mProgram = 0;
	}
	fileType = CG_SOURCE;

#ifdef WIN32
	HRESULT hr;

	if (GDD->GetClassID() == ClassIDZDisplayDeviceDX9)
	{
		const char** profileOpts;
		profileOpts = cgD3D9GetOptimalOptions(mProfile);
		const char *nOpts[16];
		nOpts[0] = COMPILE_ARGS[0];
		int idx =1;
		while ( (idx<15) && profileOpts[idx-1])
		{
			nOpts[idx] = profileOpts[idx-1];
			idx++;
		}
		nOpts[idx] = 0;

		const char *szDXprofile = NULL;

		if (mProfile == CG_PROFILE_VS_2_0)
		{
			szDXprofile = D3DXGetVertexShaderProfile(GDD->GetD3D9Device());
		}
		else
		{
			szDXprofile = D3DXGetPixelShaderProfile(GDD->GetD3D9Device());
		}
/*

		//LPD3DXBUFFER mDXShader;
		D3DXCompileShader(
			mSourceBuffer,
			strlen(mSourceBuffer),
			NULL,
			NULL,
			mEntry.c_str(),
			szDXprofile,
			0,
			&mDXShader,
			NULL,
			NULL
			);
		*/



		mProgram = cgCreateProgram(aContext, fileType, mSourceBuffer, mProfile, mEntry.c_str(), nOpts);
		hr = cgD3D9LoadProgram(mProgram, true, 0);
	}
	else
#endif
	{
		// opengl
		//mProgram = cgCreateProgram(aContext, fileType, mSourceBuffer, mProfile, mEntry.c_str(), COMPILE_ARGS);
		mProfile = (mProfileDomain == CG_VERTEX_DOMAIN) ?cgGLGetLatestProfile(CG_GL_VERTEX):cgGLGetLatestProfile(CG_GL_FRAGMENT );
		assert(cgGLIsProfileSupported(mProfile));
		mProgram = cgCreateProgramFromFile(aContext, fileType, mFileName, mProfile, mEntry.c_str(), COMPILE_ARGS);
		if (mProgram == NULL) {
			CGerror error;
			const char* errTxt = cgGetLastErrorString(&error);
			LOG ("ERROR %x: can't compile %s : %s\n", error, mFileName.c_str(), errTxt);
			useDefaultProgram(aContext);
			assert(false);
			return false;
		}
		cgGLLoadProgram(mProgram);
		checkForCgError("loadprog");
	}
	if (mProgram == 0)
	{
		CGerror error = cgGetError();
		LOG ("ERROR %x: can't load or compile %s : %s\n", error, mFileName.c_str(), cgGetLastErrorString(&error));
		useDefaultProgram(aContext);
		assert(false);
		return false;
	}
	return true;
}