예제 #1
0
파일: Cg.cpp 프로젝트: EwgB/frontier-net
void CgUpdate ()
{

  float     elapsed;


  elapsed = SdlElapsed ();
  wind += elapsed * 0.001f;
  if (!CVarUtils::GetCVar<bool> ("render.textured"))
    cgGLSetManageTextureParameters (cgContext,  CG_TRUE);
  else
    cgGLSetManageTextureParameters (cgContext,  CG_FALSE);

}
예제 #2
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;
}
예제 #3
0
    void Effect::initialize()
    {
        context = cgCreateContext();

        if (context == 0)
        {
            throw std::runtime_error("Could not create context");
        }

        cgSetErrorHandler(CgErrorHandler, 0);

        cgGLRegisterStates(context);
        cgGLSetManageTextureParameters(context, true);
    }
예제 #4
0
int createShader ( int n, std::string vname, std::string vfunc, std::string fname, std::string ffunc)
{
#if 0
	char vnbuf[200];
	char vfbuf[200];
	char fnbuf[200];
	char ffbuf[200];
	strcpy ( vnbuf, vname.c_str() );
	strcpy ( vfbuf, vfunc.c_str() );
	strcpy ( fnbuf, fname.c_str() );
	strcpy ( ffbuf, ffunc.c_str() );

	if ( cgContext == 0 ) {
		cgSetErrorCallback( cgErrorCallback );
		cgContext = cgCreateContext();
	}

	// Select profiles
	vert_profile = cgGLGetLatestProfile ( CG_GL_VERTEX );
	cgGLSetOptimalOptions( vert_profile );
	
	frag_profile = cgGLGetLatestProfile ( CG_GL_FRAGMENT );
	cgGLSetOptimalOptions( frag_profile );

	printf ( "Vertex profile:   %s\n", cgGetProfileString(vert_profile) );
	printf ( "Fragment profile: %s\n", cgGetProfileString(frag_profile) );
	printf ( " (See http.developer.nvidia.com/Cg/index_profiles.html)\n");

	//debug.PrintF ( "rend", "Geometry profile: %s\n", cgGetProfileString(vert_profile) );	

	printf ( "Loading VP:       %s\n", vnbuf );
	cgVP = cgCreateProgramFromFile( cgContext, CG_SOURCE, vnbuf, vert_profile, vfbuf, NULL );
	cgGLLoadProgram( cgVP );
	
	printf ( "Loading FP:       %s\n", fnbuf );
	cgFP = cgCreateProgramFromFile( cgContext, CG_SOURCE, fnbuf, frag_profile, ffbuf, NULL );	
	cgGLLoadProgram( cgFP );
	
	cgGLSetManageTextureParameters ( cgContext, CG_FALSE ); 
	cgGLBindProgram ( cgVP );
	cgGLBindProgram ( cgFP );	
#endif
	return 0;
}
예제 #5
0
    void GLRenderer::Initialise()
    {
        RenderState rs;
        rs.state = RenderState::None;
        rs.matrixMode = -1;
        rs.target = 0;
        this->_PushState(rs);

        GLenum error = glewInit();
        if (error != GLEW_OK)
            throw std::runtime_error(ToString("glewInit() failed: ") + ToString(glewGetErrorString(error)));
        if (!(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader))
            throw std::runtime_error("ARB_vertex_shader and ARB_fragment_shader are required");

        Tools::log << "Glew version: " << (char const*)glewGetString(GLEW_VERSION) << "\n";
        Tools::log << "OpenGL version: " << (char const*)glGetString(GL_VERSION) << "\n";

        GLCHECK(glEnable(GL_BLEND));
        //GLCHECK(glEnable(GL_ALPHA_TEST));
        GLCHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
        //GLCHECK(glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA));

        if (_cgGlobalContext == 0)
            _cgGlobalContext = cgCreateContext();
        this->_cgContext = _cgGlobalContext;
        ++_cgGlobalNbReferences;
        cgSetErrorCallback(&ErrCallback);
        cgGLSetDebugMode(CG_FALSE);
        cgSetParameterSettingMode(this->_cgContext, CG_DEFERRED_PARAMETER_SETTING);
        cgGLRegisterStates(this->_cgContext);
        cgGLSetManageTextureParameters(this->_cgContext, CG_TRUE);

        InitDevIL();

        GLCHECK(glCullFace(GL_FRONT));
    }
예제 #6
0
cCgShaderHelper::cCgShaderHelper(const zsString& shaderPath) {

	cFileUtil::ReplaceIncludeDirectives(shaderPath, cgFileLines, includedFilesPaths);

	// Setup context, for creation (Yeah silly, but use OpenGL cg state and params) because equal with dx...
	CGcontext con = cgCreateContext();
	cgGLRegisterStates(con);
	cgGLSetManageTextureParameters(con, CG_TRUE);
	
	// Create cg effect from file (load)
	assert(shaderPath.size() <= 256);
	char ansiShaderPath[256];
	cStrUtil::ToAnsi(shaderPath, ansiShaderPath, 256);
	CGeffect effect = cgCreateEffectFromFile(con, ansiShaderPath, nullptr);
	if (effect == nullptr) {
		lastErrorMsg = cgGetLastListing(con);

		// Free up
		cgDestroyEffect(effect);
		cgDestroyContext(con);
		return;
	}

	// Tech creation
	CGtechnique tech = cgGetFirstTechnique(effect);
	if (tech == nullptr) {
		lastErrorMsg = L"There is no Technique in shader: " + shaderPath;

		// Free up
		cgDestroyEffect(effect);
		cgDestroyContext(con);
		return;
	}

	// Pass creation
	CGpass pass = cgGetFirstPass(tech);
	if (pass == nullptr) {
		lastErrorMsg = L"There is no pass in shader: " + shaderPath;
		// Free up
		cgDestroyEffect(effect);
		cgDestroyContext(con);
		return;
	}

	CGprogram shaderPrograms[NDOMAINS];
		shaderPrograms[VS] = cgGetPassProgram(pass, CGdomain::CG_VERTEX_DOMAIN);
		shaderPrograms[HS] = cgGetPassProgram(pass, CGdomain::CG_TESSELLATION_CONTROL_DOMAIN);
		shaderPrograms[DS] = cgGetPassProgram(pass, CGdomain::CG_TESSELLATION_EVALUATION_DOMAIN);
		shaderPrograms[GS] = cgGetPassProgram(pass, CGdomain::CG_GEOMETRY_DOMAIN);
		shaderPrograms[PS] = cgGetPassProgram(pass, CGdomain::CG_FRAGMENT_DOMAIN);


	// Domain infos
	for (uint8_t i = 0; i < NDOMAINS; i++) {
		// Domain existence
		info.domainsExist[i] = shaderPrograms[i] != nullptr;

		// if exist save entry name
		if (info.domainsExist[i]) 
			info.domainsEntry[i] = cgGetProgramString(shaderPrograms[i], CGenum::CG_PROGRAM_ENTRY);
	}

	// Free up
	cgDestroyEffect(effect);
	cgDestroyContext(con);
}