예제 #1
0
void SetupVertexProgramParameters(VERTEXSHADER* pf, int context)
{
	GLint p;
	pf->prog.link = (void*)pf;			// Setting autolink
	pf->prog.isFragment = false;			// Setting autolink
	pf->ShaderType = ShaderTypes[pf->Shader];

	pf->ParametersStart = NumActiveUniforms;

	ZZshProgram prog = madeProgram(pf->Shader, 0, "");
	glUseProgram(prog);

	GL_REPORT_ERRORD();

	// Set Z-test, log or no log;
	if (conf.settings().no_logz) {
       		g_vdepth = float4( 255.0 /256.0f,  255.0/65536.0f, 255.0f/(65535.0f*256.0f), 1.0f/(65536.0f*65536.0f));
		vlogz = float4( 1.0f, 0.0f, 0.0f, 0.0f);
	}
	else {
		g_vdepth = float4( 256.0f*65536.0f, 65536.0f, 256.0f, 65536.0f*65536.0f);	
		vlogz = float4( 0.0f, 1.0f, 0.0f, 0.0f);
	}

	INIT_UNIFORMPARAM(g_vdepth, "g_fZ");
	if (p > -1) {
		INIT_UNIFORMPARAM(vlogz, "g_fZMin");
		if (p == -1)  ZZLog::Error_Log ("Shader file version is outdated! Only log-Z is possible.");
	}
	GL_REPORT_ERRORD();

	float4 vnorm = float4(g_filog32, 0, 0,0);
	INIT_UNIFORMPARAM(vnorm, "g_fZNorm");
	INIT_UNIFORMPARAM(float4(-0.2f, -0.65f, 0.9f, 1.0f / 32767.0f ),  "g_fBilinear");
	INIT_UNIFORMPARAM(float4(1.0f/256.0f, 1.0004f, 1, 0.5f),  "g_fZBias") ;
	INIT_UNIFORMPARAM(float4(0,1, 0.001f, 0.5f), "g_fc0");

	SET_UNIFORMPARAM(sBitBltPos, "g_fBitBltPos");
	SET_UNIFORMPARAM(sBitBltTex, "g_fBitBltTex");
	SET_UNIFORMPARAM(fBitBltTrans, "g_fBitBltTrans");
	pf->ParametersFinish = NumActiveUniforms;
	if (NumActiveUniforms > MAX_ACTIVE_UNIFORMS)
		ZZLog::Error_Log("Too many shader variables. You may increase the limit in the source.");

	glUseProgram(0);
	GL_REPORT_ERRORD();
}
예제 #2
0
static void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int type)
{
	// uniform parameters
	GLint p;
	pf->prog.link = (void*)pf;			// Setting autolink
	pf->prog.isFragment = true;			// Setting autolink
	pf->ShaderType = ShaderTypes[pf->Shader];

	pf->ParametersStart = NumActiveUniforms;
	ZZshProgram prog = madeProgram(pf->Shader, 0, "");
	glUseProgram(prog);
	GL_REPORT_ERRORD();

	SET_UNIFORMPARAM(sOneColor, "g_fOneColor");
	SET_UNIFORMPARAM(sBitBltZ, "g_fBitBltZ");
	SET_UNIFORMPARAM(sInvTexDims, "g_fInvTexDims");
	SET_UNIFORMPARAM(fTexAlpha2, AddContextToName("fTexAlpha2", context));
	SET_UNIFORMPARAM(fTexOffset, AddContextToName("g_fTexOffset", context));
	SET_UNIFORMPARAM(fTexDims, AddContextToName("g_fTexDims", context));
	SET_UNIFORMPARAM(fTexBlock, AddContextToName("g_fTexBlock", context));
	SET_UNIFORMPARAM(fClampExts, AddContextToName("g_fClampExts",  context)); 		// FIXME: There is a bug, that lead FFX-1 to incorrect CLAMP if this uniform have context.
	SET_UNIFORMPARAM(fTexWrapMode, AddContextToName("TexWrapMode", context));
	SET_UNIFORMPARAM(fRealTexDims, AddContextToName("g_fRealTexDims", context));
	SET_UNIFORMPARAM(fTestBlack, AddContextToName("g_fTestBlack", context));
	SET_UNIFORMPARAM(fPageOffset, AddContextToName("g_fPageOffset", context));
	SET_UNIFORMPARAM(fTexAlpha, AddContextToName("fTexAlpha", context));
	GL_REPORT_ERRORD();

	// textures
	INIT_SAMPLERPARAM(ptexBlocks, "g_sBlocks");
	if (type == 3) 
		{INIT_SAMPLERPARAM(ptexConv16to32, "g_sConv16to32");}
	else if (type == 4) 
		{INIT_SAMPLERPARAM(ptexConv32to16, "g_sConv32to16");}
	else 
		{INIT_SAMPLERPARAM(ptexBilinearBlocks, "g_sBilinearBlocks");}
	GL_REPORT_ERRORD();

	SET_UNIFORMPARAM(sMemory, AddContextToName("g_sMemory", context));
	SET_UNIFORMPARAM(sFinal, "g_sSrcFinal");
	SET_UNIFORMPARAM(sBitwiseANDX, "g_sBitwiseANDX");
	SET_UNIFORMPARAM(sBitwiseANDY, "g_sBitwiseANDY");
	SET_UNIFORMPARAM(sCLUT, "g_sCLUT");
	SET_UNIFORMPARAM(sInterlace, "g_sInterlace");
	GL_REPORT_ERRORD();

	// set global shader constants
	INIT_UNIFORMPARAM(float4(0.5f, (conf.settings().exact_color)?0.9f/256.0f:0.5f/256.0f, 0,1/255.0f), "g_fExactColor");
	INIT_UNIFORMPARAM(float4(-0.2f, -0.65f, 0.9f, 1.0f / 32767.0f ), "g_fBilinear");
	INIT_UNIFORMPARAM(float4(1.0f/256.0f, 1.0004f, 1, 0.5f), "g_fZBias");
	INIT_UNIFORMPARAM(float4(0,1, 0.001f, 0.5f), "g_fc0");
	INIT_UNIFORMPARAM(float4(1/1024.0f, 0.2f/1024.0f, 1/128.0f, 1/512.0f), "g_fMult");
	pf->ParametersFinish = NumActiveUniforms;
	if (NumActiveUniforms > MAX_ACTIVE_UNIFORMS)
		ZZLog::Error_Log("Too many shader variables. You may increase the limit in source %d.", NumActiveUniforms);
		
	glUseProgram(0);
	GL_REPORT_ERRORD();
}
예제 #3
0
void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int type)
{
	// uniform parameters
	ZZshParameter p;

	p = cgGetNamedParameter(pf->prog, "g_fFogColor");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		cgConnectParameter(g_fparamFogColor, p);
	}

	SET_UNIFORMPARAM(sOneColor, "g_fOneColor");
	SET_UNIFORMPARAM(sBitBltZ, "g_fBitBltZ");
	SET_UNIFORMPARAM(sInvTexDims, "g_fInvTexDims");
	SET_UNIFORMPARAM(fTexAlpha2, "fTexAlpha2");
	SET_UNIFORMPARAM(fTexOffset, "g_fTexOffset");
	SET_UNIFORMPARAM(fTexDims, "g_fTexDims");
	SET_UNIFORMPARAM(fTexBlock, "g_fTexBlock");
	SET_UNIFORMPARAM(fClampExts, "g_fClampExts");
	SET_UNIFORMPARAM(fTexWrapMode, "TexWrapMode");
	SET_UNIFORMPARAM(fRealTexDims, "g_fRealTexDims");
	SET_UNIFORMPARAM(fTestBlack, "g_fTestBlack");
	SET_UNIFORMPARAM(fPageOffset, "g_fPageOffset");
	SET_UNIFORMPARAM(fTexAlpha, "fTexAlpha");

	// textures
	p = cgGetNamedParameter(pf->prog, "g_sBlocks");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		cgGLSetTextureParameter(p, ptexBlocks);
		cgGLEnableTextureParameter(p);
	}

	// cg parameter usage is wrong, so do it manually
	if( type == 3 ) {
		p = cgGetNamedParameter(pf->prog, "g_sConv16to32");
		if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
			cgGLSetTextureParameter(p, ptexConv16to32);
			cgGLEnableTextureParameter(p);
		}
	}
	else if( type == 4 ) {
		p = cgGetNamedParameter(pf->prog, "g_sConv32to16");
		if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
			cgGLSetTextureParameter(p, ptexConv32to16);
			cgGLEnableTextureParameter(p);
		}
	}
	else {
		p = cgGetNamedParameter(pf->prog, "g_sBilinearBlocks");
		if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
			cgGLSetTextureParameter(p, ptexBilinearBlocks);
			cgGLEnableTextureParameter(p);
		}
	}

	p = cgGetNamedParameter(pf->prog, "g_sMemory");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		//cgGLEnableTextureParameter(p);
		pf->sMemory = p;
	}
	p = cgGetNamedParameter(pf->prog, "g_sSrcFinal");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		//cgGLEnableTextureParameter(p);
		pf->sFinal = p;
	}
	p = cgGetNamedParameter(pf->prog, "g_sBitwiseANDX");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		//cgGLEnableTextureParameter(p);
		pf->sBitwiseANDX = p;
	}
	p = cgGetNamedParameter(pf->prog, "g_sBitwiseANDY");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		//cgGLEnableTextureParameter(p);
		pf->sBitwiseANDY = p;
	}
	p = cgGetNamedParameter(pf->prog, "g_sCLUT");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		//cgGLEnableTextureParameter(p);
		pf->sCLUT = p;
	}
	p = cgGetNamedParameter(pf->prog, "g_sInterlace");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		//cgGLEnableTextureParameter(p);
		pf->sInterlace = p;
	}

	// set global shader constants
	p = cgGetNamedParameter(pf->prog, "g_fExactColor");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE ) {
		cgGLSetParameter4fv(p, float4(0.5f, (conf.settings().exact_color)?0.9f/256.0f:0.5f/256.0f, 0,1/255.0f));
	}

	p = cgGetNamedParameter(pf->prog, "g_fBilinear");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE )
		cgGLSetParameter4fv(p, float4(-0.2f, -0.65f, 0.9f, 1.0f / 32767.0f ));

	p = cgGetNamedParameter(pf->prog, "g_fZBias");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE )
		cgGLSetParameter4fv(p, float4(1.0f/256.0f, 1.0004f, 1, 0.5f));

	p = cgGetNamedParameter(pf->prog, "g_fc0");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE )
		cgGLSetParameter4fv(p, float4(0,1, 0.001f, 0.5f));

	p = cgGetNamedParameter(pf->prog, "g_fMult");
	if( p != NULL && cgIsParameterUsed(p, pf->prog) == CG_TRUE )
		cgGLSetParameter4fv(p, float4(1/1024.0f, 0.2f/1024.0f, 1/128.0f, 1/512.0f));
}