* fix properly context, directly save the state in the shader
* replace the last deprecated variable in the shader. Remain the issue that host enable 1 output and the shader write 2 outputs
* It seems that VBO does't depends on the VAO but vertex format depends on both VBO/VAO so I set the format multiple time. Not sure the behavior is fully correct


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5211 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-05-15 06:40:45 +00:00
parent e7de58c3e2
commit d062ca1727
9 changed files with 144 additions and 109 deletions

View File

@ -196,6 +196,8 @@ public:
switch (layout[i].type) {
case GL_UNSIGNED_SHORT:
case GL_UNSIGNED_INT:
case GL_SHORT:
case GL_INT:
// Rule: when shader use integral (not normalized) you must use glVertexAttribIPointer (note the extra I)
glVertexAttribIPointer(layout[i].index, layout[i].size, layout[i].type, layout[i].stride, layout[i].offset);
break;

View File

@ -203,11 +203,7 @@ void CDepthTarget::Update(int context, CRenderTarget* prndr)
// write color and zero out stencil buf, always 0 context!
SetTexVariablesInt(0, 0, texframe, false, &ppsBitBltDepth, 1);
#ifdef GLSL4_API
ZZshGLSetTextureParameter(ppsBitBltDepth.prog, ppsBitBltDepth.sMemory[context], vb[0].pmemtarg->ptex->tex, "BitBltDepth");
#else
ZZshGLSetTextureParameter(ppsBitBltDepth.prog, ppsBitBltDepth.sMemory, vb[0].pmemtarg->ptex->tex, "BitBltDepth");
#endif
float4 v = DefaultBitBltPos();

View File

@ -432,11 +432,7 @@ void CRenderTarget::Update(int context, CRenderTarget* pdepth)
// Fix in r133 -- FFX movies and Gust backgrounds!
//SetTexVariablesInt(0, 0*(AA.x || AA.y) ? 2 : 0, texframe, false, &ppsBitBlt[!!s_AAx], 1);
SetTexVariablesInt(0, 0, texframe, false, &ppsBitBlt[bit_idx], 1);
#ifdef GLSL4_API
ZZshGLSetTextureParameter(ppsBitBlt[bit_idx].prog, ppsBitBlt[bit_idx].sMemory[context], vb[0].pmemtarg->ptex->tex, "BitBlt.memory");
#else
ZZshGLSetTextureParameter(ppsBitBlt[bit_idx].prog, ppsBitBlt[bit_idx].sMemory, vb[0].pmemtarg->ptex->tex, "BitBlt.memory");
#endif
v = float4(1, 1, 0.0f, 0.0f);
ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");

View File

@ -656,13 +656,7 @@ inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listT
v = RenderSetTargetInvTex(texframe.tw, texframe.th, CRTC_RENDER);
float4 valpha = RenderGetForClip(texframe.psm, CRTC_RENDER);
#ifdef GLSL4_API
// FIXME context
int context = 0;
ZZshGLSetTextureParameter(curr_ppsCRTC()->prog, curr_ppsCRTC()->sMemory[context], vb[0].pmemtarg->ptex->tex, "CRTC memory");
#else
ZZshGLSetTextureParameter(curr_ppsCRTC()->prog, curr_ppsCRTC()->sMemory, vb[0].pmemtarg->ptex->tex, "CRTC memory");
#endif
RenderCreateInterlaceTex(texframe.th, CRTC_RENDER_TARG);
ZZshSetPixelShader(curr_ppsCRTC()->prog);

View File

@ -574,6 +574,19 @@ bool ZZCreate(int _width, int _height)
GL_REPORT_ERROR();
#ifdef GLSL4_API
// FIXME maybe GL_UNSIGNED_SHORT could be better than GL_SHORT
GSInputLayoutOGL vert_format[] =
{
{0 , 4 , GL_SHORT , GL_FALSE , sizeof(VertexGPU) , (const GLvoid*)(0) } , // vertex
{1 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(VertexGPU) , (const GLvoid*)(8) } , // color
{2 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(VertexGPU) , (const GLvoid*)(12) } , // z value. FIXME WTF 4 unsigned byte, why not a full integer
{3 , 3 , GL_FLOAT , GL_FALSE , sizeof(VertexGPU) , (const GLvoid*)(16) } , // tex coord
};
vertex_array = new GSVertexBufferStateOGL(sizeof(VertexGPU), vert_format, 4);
#endif
g_nCurVBOIndex = 0;
if (!vb_buffer_allocated) {
@ -582,6 +595,9 @@ bool ZZCreate(int _width, int _height)
{
glBindBuffer(GL_ARRAY_BUFFER, g_vboBuffers[i]);
glBufferData(GL_ARRAY_BUFFER, 0x100*sizeof(VertexGPU), NULL, GL_STREAM_DRAW);
#ifdef GLSL4_API
vertex_array->set_internal_format(vert_format, 4);
#endif
}
vb_buffer_allocated = true; // mark the buffer allocated
}
@ -663,6 +679,9 @@ bool ZZCreate(int _width, int _height)
// fill a simple rect
glGenBuffers(1, &vboRect);
glBindBuffer(GL_ARRAY_BUFFER, vboRect);
#ifdef GLSL4_API
vertex_array->set_internal_format(vert_format, 4);
#endif
vector<VertexGPU> verts(4);
@ -682,8 +701,6 @@ bool ZZCreate(int _width, int _height)
glBufferDataARB(GL_ARRAY_BUFFER, 4*sizeof(VertexGPU), &verts[0], GL_STATIC_DRAW);
// FIXME Done inside ZZoglShadersGLSL4 for the moment
// Move it later
#ifndef GLSL4_API
// setup the default vertex declaration
glEnableClientState(GL_VERTEX_ARRAY);
@ -819,6 +836,8 @@ void ZZDestroy()
vb_buffer_allocated = false; // mark the buffer unallocated
}
delete vertex_array;
g_nCurVBOIndex = 0;
if (pvs != NULL)

View File

@ -852,11 +852,7 @@ inline void FlushSetTexture(VB& curvb, FRAGMENTSHADER* pfragment, CRenderTarget*
ZZshGLSetTextureParameter(pfragment->prog, pfragment->sBitwiseANDY, curvb.ptexClamp[1], "Clamp 1");
if( pfragment->sMemory != NULL && s_ptexCurSet[context] != 0)
#ifdef GLSL4_API
ZZshGLSetTextureParameter(pfragment->prog, pfragment->sMemory[context], s_ptexCurSet[context], "Clamp memory");
#else
ZZshGLSetTextureParameter(pfragment->prog, pfragment->sMemory, s_ptexCurSet[context], "Clamp memory");
#endif
}
// Reset program and texture variables;

View File

@ -136,7 +136,7 @@ struct GlobalUniform {
};
float linear[2*4];
};
void SettleFloat(int indice, const float* v) {
void SettleFloat(uint indice, const float* v) {
assert(indice >= 0);
assert(indice + 3 < sizeof(linear));
linear[indice+0] = v[0];
@ -162,7 +162,7 @@ struct ConstantUniform {
};
float linear[8*4];
};
void SettleFloat(int indice, const float* v) {
void SettleFloat(uint indice, const float* v) {
assert(indice >= 0);
assert(indice + 3 < sizeof(linear));
linear[indice+0] = v[0];
@ -190,7 +190,7 @@ struct FragmentUniform {
};
float linear[13*4];
};
void SettleFloat(int indice, const float* v) {
void SettleFloat(uint indice, const float* v) {
assert(indice >= 0);
assert(indice + 3 < sizeof(linear));
linear[indice+0] = v[0];
@ -208,7 +208,7 @@ struct VertexUniform {
};
float linear[3*4];
};
void SettleFloat(int indice, const float* v) {
void SettleFloat(uint indice, const float* v) {
assert(indice >= 0);
assert(indice + 3 < sizeof(linear) / 4);
linear[indice+0] = v[0];
@ -356,8 +356,8 @@ struct SamplerParam {
}
}
void set_texture(GLuint texid) {
texid = texid;
void set_texture(GLuint new_texid) {
texid = new_texid;
}
};
@ -365,6 +365,8 @@ struct FRAGMENTSHADER
{
FRAGMENTSHADER() : prog(sZero)
, program(0)
, context(0)
, sMemory(0) // dual context need 2 slots
, sFinal(2)
, sBitwiseANDX(3)
, sBitwiseANDY(4)
@ -386,15 +388,13 @@ struct FRAGMENTSHADER
fTestBlack = (ZZshParameter)offsetof(struct FragmentUniform, g_fTestBlack) /4;
fPageOffset = (ZZshParameter)offsetof(struct FragmentUniform, g_fPageOffset) /4;
sMemory[ZZSH_CTX_0] = 0;
sMemory[ZZSH_CTX_1] = 1;
//sFinal = 2;
//sBitwiseANDX = 3;
//sBitwiseANDY = 4;
//sInterlace = 5;
//sCLUT = 6;
samplers[sMemory[ZZSH_CTX_0]].set_unit(0);
samplers[sMemory[ZZSH_CTX_1]].set_unit(0); // Dual context. Use same unit
samplers[sMemory+0].set_unit(0);
samplers[sMemory+1].set_unit(0); // Dual context. Use same unit
samplers[sFinal].set_unit(1);
samplers[sBitwiseANDX].set_unit(6);
samplers[sBitwiseANDY].set_unit(7);
@ -405,11 +405,12 @@ struct FRAGMENTSHADER
ZZshShaderLink prog; // it link to FRAGMENTSHADER structure, for compability between GLSL and CG
ZZshProgram program;
ZZshShaderType ShaderType; // Not every PS and VS are used together, only compatible ones.
uint context;
FragmentUniform uniform_buffer[ZZSH_CTX_ALL];
// sampler
ZZshParameter sMemory[ZZSH_CTX_ALL];
const ZZshParameter sMemory;
const ZZshParameter sFinal, sBitwiseANDX, sBitwiseANDY, sInterlace, sCLUT;
SamplerParam samplers[7];
@ -421,22 +422,32 @@ struct FRAGMENTSHADER
string filename;
#endif
void ZZshSetParameter4fv(ZZshParameter param, const float* v, int context = ZZSH_CTX_ALL) {
if (context < ZZSH_CTX_ALL)
void ZZshSetParameter4fv(ZZshParameter param, const float* v) {
if (IsDualContext(param))
uniform_buffer[context].SettleFloat((int) param, v);
else
for ( int i = 0; i < ZZSH_CTX_ALL ; i++)
uniform_buffer[i].SettleFloat((int) param, v);
}
void enable_texture(int context) {
samplers[0+context].enable_texture();
bool IsDualContext(ZZshParameter param) {
if (param == sInvTexDims || param == sBitBltZ || param == sOneColor)
return false;
else
return true;
}
void enable_texture() {
samplers[0+context].enable_texture(); // sMemory is dual context
for (int i = 2; i < 7; i++)
samplers[i].enable_texture();
}
void set_texture(ZZshParameter param, GLuint texid) {
samplers[param].set_texture(texid);
if (param == 0) // sMemory is dual context
samplers[0+context].set_texture(texid);
else
samplers[param].set_texture(texid);
}
};
#endif
@ -444,7 +455,8 @@ struct FRAGMENTSHADER
#ifdef GLSL4_API
struct COMMONSHADER
{
COMMONSHADER() : sBlocks(0)
COMMONSHADER() : context(0)
, sBlocks(0)
, sBilinearBlocks(1)
, sConv16to32(2)
, sConv32to16(3)
@ -499,6 +511,7 @@ struct COMMONSHADER
ZZshParameter g_fparamFogColor, g_vparamPosXY;
ZZshParameter g_fBilinear, g_fZBias, g_fc0, g_fMult, g_fZ, g_fZMin, g_fZNorm, g_fExactColor;
uint context;
GlobalUniform uniform_buffer[ZZSH_CTX_ALL];
ConstantUniform uniform_buffer_constant;
@ -507,14 +520,19 @@ struct COMMONSHADER
const ZZshParameter sBlocks, sBilinearBlocks, sConv16to32, sConv32to16;
SamplerParam samplers[4];
void ZZshSetParameter4fv(ZZshParameter param, const float* v, int context = ZZSH_CTX_ALL) {
if (context < ZZSH_CTX_ALL)
void ZZshSetParameter4fv(ZZshParameter param, const float* v) {
if (IsDualContext(param))
uniform_buffer[context].SettleFloat((int) param, v);
else
for ( int i = 0; i < ZZSH_CTX_ALL ; i++)
uniform_buffer[i].SettleFloat((int) param, v);
}
bool IsDualContext(ZZshParameter param) {
if (param == g_vparamPosXY) return true;
else return false;
}
void set_texture(ZZshParameter param, GLuint texid) {
samplers[param].set_texture(texid);
}
@ -543,8 +561,7 @@ struct VERTEXSHADER
struct VERTEXSHADER
{
VERTEXSHADER() : prog(sZero), program(0)
//: prog(sZero), Shader(0), sBitBltPos(pZero), sBitBltTex(pZero) {}
VERTEXSHADER() : prog(sZero), program(0), context(0)
{
sBitBltPos = (ZZshParameter)offsetof(struct VertexUniform, g_fBitBltPos) /4;
sBitBltTex = (ZZshParameter)offsetof(struct VertexUniform, g_fBitBltTex) /4;
@ -560,17 +577,20 @@ struct VERTEXSHADER
ZZshShaderLink prog;
ZZshProgram program;
ZZshShaderType ShaderType;
uint context;
ZZshParameter sBitBltPos, sBitBltTex, fBitBltTrans; // vertex shader constants
void ZZshSetParameter4fv(ZZshParameter param, const float* v, int context = ZZSH_CTX_ALL) {
if (context < ZZSH_CTX_ALL)
void ZZshSetParameter4fv(ZZshParameter param, const float* v) {
if (IsDualContext(param))
uniform_buffer[context].SettleFloat((int) param, v);
else
for ( int i = 0; i < ZZSH_CTX_ALL ; i++)
uniform_buffer[i].SettleFloat((int) param, v);
}
bool IsDualContext(ZZshParameter param) { return false;}
};
#endif
@ -706,8 +726,9 @@ extern GSUniformBufferOGL *vertex_buffer;
extern GSUniformBufferOGL *fragment_buffer;
extern GSVertexBufferStateOGL *vertex_array;
static void init_shader();
static void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps, int context);
extern void init_shader();
extern void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps);
extern void init_shader();
#endif

View File

@ -123,6 +123,9 @@ GSVertexBufferStateOGL *vertex_array;
COMMONSHADER g_cs;
static GLuint s_pipeline = 0;
FRAGMENTSHADER ppsDebug;
FRAGMENTSHADER ppsDebug2;
//------------------ Code
inline int GET_SHADER_INDEX(int type, int texfilter, int texwrap, int fog, int writedepth, int testaem, int exactcolor, int context, int ps) {
@ -221,8 +224,6 @@ void ZZshExitCleaning() {
delete vertex_buffer;
delete fragment_buffer;
delete vertex_array;
glDeleteProgramPipelines(1, &s_pipeline);
}
@ -280,7 +281,6 @@ void ZZshDefaultOneColor( FRAGMENTSHADER& ptr ) {
ShaderHandleName = "Set Default One colot";
float4 v = float4 ( 1, 1, 1, 1 );
//ZZshSetParameter4fv(ptr.prog, ptr.sOneColor, v, "DegaultOne");
// FIXME context
ptr.ZZshSetParameter4fv(ptr.sOneColor, v);
}
//-------------------------------------------------------------------------------------
@ -391,9 +391,7 @@ inline bool LoadShaderFromFile(ZZshProgram& program, const char* DefineString, c
static void PutParametersAndRun(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
UNIFORM_ERROR_LOG("Run program %s(%d) \t+\t%s(%d)", ShaderNames[vs->program], vs->program, ShaderNames[ps->program], ps->program);
// FIXME context argument
int context = 0;
PutParametersInProgram(vs, ps, context);
PutParametersInProgram(vs, ps);
#if defined(DEVBUILD) || defined(_DEBUG)
glValidateProgramPipeline(s_pipeline);
@ -429,10 +427,21 @@ static void ZZshSetShader(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
int pss = (ps!=NULL)?ps->program:0;
if (vss !=0 && pss != 0) {
FRAGMENTSHADER* debug = ps;
glUseProgramStages(s_pipeline, GL_VERTEX_SHADER_BIT, vs->program);
glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ps->program);
PutParametersAndRun(vs, ps);
// // FIXME DEBUG PS SHADER
// if (ps->ShaderType == ZZ_SH_TEXTURE) {
// glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ppsDebug2.program);
// PutParametersAndRun(vs, &ppsDebug2);
// } else {
// glUseProgramStages(s_pipeline, GL_FRAGMENT_SHADER_BIT, ps->program);
// PutParametersAndRun(vs, ps);
// }
GL_REPORT_ERRORD();
}
}
@ -449,7 +458,7 @@ void ZZshSetPixelShader(ZZshShaderLink prog) {
//------------------------------------------------------------------------------------------------------------------
static void init_shader() {
void init_shader() {
// TODO:
// Note it would be more clever to allocate buffer inside SHADER class
// Add a dirty flags to avoid to upload twice same data...
@ -465,36 +474,29 @@ static void init_shader() {
constant_buffer->bind();
constant_buffer->upload((void*)&g_cs.uniform_buffer_constant);
g_cs.set_texture(g_cs.sBlocks, ptexBlocks);
g_cs.set_texture(g_cs.sConv16to32, ptexConv16to32);
g_cs.set_texture(g_cs.sConv32to16, ptexConv32to16);
g_cs.set_texture(g_cs.sBilinearBlocks, ptexBilinearBlocks);
glGenProgramPipelines(1, &s_pipeline);
glBindProgramPipeline(s_pipeline);
// FIXME maybe GL_UNSIGNED_SHORT could be better than GL_SHORT
GSInputLayoutOGL vert_format[] =
{
{0 , 4 , GL_SHORT , GL_FALSE , sizeof(VertexGPU) , (const GLvoid*)(0) } , // vertex
{1 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(VertexGPU) , (const GLvoid*)(8) } , // color
{2 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(VertexGPU) , (const GLvoid*)(12) } , // z value. FIXME WTF 4 unsigned byte, why not a full integer
{3 , 3 , GL_FLOAT , GL_FALSE , sizeof(VertexGPU) , (const GLvoid*)(16) } , // tex coord
};
vertex_array = new GSVertexBufferStateOGL(sizeof(VertexGPU), vert_format, 4);
}
static void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps, int context) {
void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
common_buffer->bind();
common_buffer->upload((void*)&g_cs.uniform_buffer[context]);
common_buffer->upload((void*)&g_cs.uniform_buffer[g_cs.context]);
vertex_buffer->bind();
vertex_buffer->upload((void*)&vs->uniform_buffer[context]);
vertex_buffer->upload((void*)&vs->uniform_buffer[vs->context]);
fragment_buffer->bind();
fragment_buffer->upload((void*)&ps->uniform_buffer[context]);
fragment_buffer->upload((void*)&ps->uniform_buffer[ps->context]);
g_cs.enable_texture();
ps->enable_texture(context);
ps->enable_texture();
}
static void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int type)
@ -503,13 +505,9 @@ static void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int
pf->prog.link = (void*)pf; // Setting autolink
pf->prog.isFragment = true; // Setting autolink
pf->ShaderType = ShaderTypes[pf->program];
pf->context = context;
g_cs.set_texture(g_cs.sBlocks, ptexBlocks);
g_cs.set_texture(g_cs.sConv16to32, ptexConv16to32);
g_cs.set_texture(g_cs.sConv32to16, ptexConv32to16);
g_cs.set_texture(g_cs.sBilinearBlocks, ptexBilinearBlocks);
GL_REPORT_ERRORD();
}
void SetupVertexProgramParameters(VERTEXSHADER* pf, int context)
@ -517,8 +515,7 @@ void SetupVertexProgramParameters(VERTEXSHADER* pf, int context)
pf->prog.link = (void*)pf; // Setting autolink
pf->prog.isFragment = false; // Setting autolink
pf->ShaderType = ShaderTypes[pf->program];
GL_REPORT_ERRORD();
pf->context = context;
}
//const int GLSL_VERSION = 130; // Sampler2DRect appear in 1.3
@ -535,10 +532,10 @@ static __forceinline bool LOAD_VS(char* DefineString, const char* name, VERTEXSH
bool flag;
char temp[200];
GlslHeaderString(temp, name, depth);
sprintf(DefineString, "%s#define VERTEX_SHADER 1\n#define CTX %d\n", temp, context * NOCONTEXT);
sprintf(DefineString, "%s#define VERTEX_SHADER 1\n", temp);
//ZZLog::WriteLn("Define for VS == '%s'", DefineString);
flag = LoadShaderFromFile(vertex.program, DefineString, name, GL_VERTEX_SHADER);
SetupVertexProgramParameters(&vertex, context);
SetupVertexProgramParameters(&vertex, context * NOCONTEXT);
return flag;
}
@ -547,11 +544,11 @@ static __forceinline bool LOAD_PS(char* DefineString, const char* name, FRAGMENT
bool flag;
char temp[200];
GlslHeaderString(temp, name, depth);
sprintf(DefineString, "%s#define FRAGMENT_SHADER 1\n#define CTX %d\n", temp, context * NOCONTEXT);
sprintf(DefineString, "%s#define FRAGMENT_SHADER 1\n", temp);
//ZZLog::WriteLn("Define for PS == '%s'", DefineString);
flag = LoadShaderFromFile(fragment.program, DefineString, name, GL_FRAGMENT_SHADER);
SetupFragmentProgramParameters(&fragment, context, 0);
SetupFragmentProgramParameters(&fragment, context * NOCONTEXT, 0);
return flag;
}
@ -633,6 +630,10 @@ bool ZZshLoadExtraEffects() {
if (!LOAD_PS(DefineString, "Convert16to32PS", ppsConvert16to32, cgfProf, 0, "")) bLoadSuccess = false;
if (!LOAD_PS(DefineString, "Convert32to16PS", ppsConvert32to16, cgfProf, 0, "")) bLoadSuccess = false;
// DEBUG
if (!LOAD_PS(DefineString, "ZeroDebugPS", ppsDebug, cgfProf, 0, "")) bLoadSuccess = false;
if (!LOAD_PS(DefineString, "ZeroDebug2PS", ppsDebug2, cgfProf, 0, "")) bLoadSuccess = false;
GL_REPORT_ERRORD();
return true;
}

View File

@ -109,7 +109,7 @@ out gl_PerVertex {
float gl_ClipDistance[];
};
layout(location = 0) in uvec2 Vert;
layout(location = 0) in ivec2 Vert;
layout(location = 1) in vec4 Color;
layout(location = 2) in vec4 SecondaryColor;
layout(location = 3) in vec3 TexCoord;
@ -610,8 +610,8 @@ half4 ps2FinalColor(half4 col)
void RegularPS() {
// whenever outputting depth, make sure to mult by 255/256 and 1
gl_FragData[0] = ps2FinalColor(PSin.color);
DOZWRITE(gl_FragData[1] = PSin.z;)
FragData0 = ps2FinalColor(PSin.color);
DOZWRITE(FragData1 = PSin.z;)
}
#ifdef WRITE_DEPTH
@ -619,8 +619,8 @@ void RegularPS() {
#define DECL_TEXPS(num, bit) \
void Texture##num##bit##PS() \
{ \
gl_FragData[0] = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
gl_FragData[1] = PSin.z; \
FragData0 = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
FragData1 = PSin.z; \
}
#else
@ -628,7 +628,7 @@ void Texture##num##bit##PS() \
#define DECL_TEXPS(num, bit) \
void Texture##num##bit##PS() \
{ \
gl_FragData[0] = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
FragData0 = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
}
#endif
@ -652,8 +652,8 @@ void RegularFogPS() {
half4 c;
c.xyz = mix(g_fFogColor.xyz, PSin.color.xyz, vec3(PSin.fog));
c.w = PSin.color.w;
gl_FragData[0] = ps2FinalColor(c);
DOZWRITE(gl_FragData[1] = PSin.z;)
FragData0 = ps2FinalColor(c);
DOZWRITE(FragData1 = PSin.z;)
}
#ifdef WRITE_DEPTH
@ -663,8 +663,8 @@ void TextureFog##num##bit##PS() \
{ \
half4 c = ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color); \
c.xyz = mix(g_fFogColor.xyz, c.xyz, vec3(PSin.fog)); \
gl_FragData[0] = ps2FinalColor(c); \
gl_FragData[1] = PSin.z; \
FragData0 = ps2FinalColor(c); \
FragData1 = PSin.z; \
}
#else
@ -674,7 +674,7 @@ void TextureFog##num##bit##PS() \
{ \
half4 c = ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color); \
c.xyz = mix(g_fFogColor.xyz, c.xyz, vec3(PSin.fog)); \
gl_FragData[0] = ps2FinalColor(c); \
FragData0 = ps2FinalColor(c); \
}
#endif
@ -715,26 +715,26 @@ half4 BilinearBitBlt(float2 tex0)
}
void BitBltPS() {
gl_FragData[0] = texture(g_sMemory, ps2memcoord(PSin.tex.xy).xy)*g_fOneColor.xxxy;
FragData0 = texture(g_sMemory, ps2memcoord(PSin.tex.xy).xy)*g_fOneColor.xxxy;
}
// used when AA
void BitBltAAPS() {
gl_FragData[0] = BilinearBitBlt(PSin.tex.xy) * g_fOneColor.xxxy;
FragData0 = BilinearBitBlt(PSin.tex.xy) * g_fOneColor.xxxy;
}
void BitBltDepthPS() {
vec4 data;
data = texture(g_sMemory, ps2memcoord(PSin.tex.xy));
gl_FragData[0] = data + g_fZBias.y;
FragData0 = data + g_fZBias.y;
gl_FragDepth = (log(g_fc0.y + dot(data, g_fBitBltZ)) * g_fOneColor.w) * g_fZMin.y + dot(data, g_fBitBltZ) * g_fZMin.x ;
}
void BitBltDepthMRTPS() {
vec4 data;
data = texture(g_sMemory, ps2memcoord(PSin.tex.xy));
gl_FragData[0] = data + g_fZBias.y;
gl_FragData[1].x = g_fc0.x;
FragData0 = data + g_fZBias.y;
FragData1.x = g_fc0.x;
gl_FragDepth = (log(g_fc0.y + dot(data, g_fBitBltZ)) * g_fOneColor.w) * g_fZMin.y + dot(data, g_fBitBltZ) * g_fZMin.x ;
}
@ -759,13 +759,15 @@ void CRTCTargInterPS() {
float finter = texture(g_sInterlace, PSin.z.yy).x * g_fOneColor.z + g_fOneColor.w + g_fc0.w;
float4 c = BilinearFloat16(PSin.tex.xy);
c.w = ( g_fc0.w*c.w * g_fOneColor.x + g_fOneColor.y ) * finter;
gl_FragData[0] = c;
FragData0 = c;
}
void CRTCTargPS() {
float4 c = BilinearFloat16(PSin.tex.xy);
// FIXME DEBUG: to validate tex coord on blit
//vec4 c = vec4(PSin.tex.x/512.0f, PSin.tex.y/512.0f, 0.0, 1.0);
c.w = g_fc0.w * c.w * g_fOneColor.x + g_fOneColor.y;
gl_FragData[0] = c;
FragData0 = c;
}
void CRTCInterPS() {
@ -773,7 +775,7 @@ void CRTCInterPS() {
float2 filtcoord = trunc(PSin.tex.xy) * g_fInvTexDims.xy + g_fInvTexDims.zw;
half4 c = BilinearBitBlt(filtcoord);
c.w = (c.w * g_fOneColor.x + g_fOneColor.y)*finter;
gl_FragData[0] = c;
FragData0 = c;
}
// simpler
@ -781,21 +783,21 @@ void CRTCInterPS_Nearest() {
float finter = texture(g_sInterlace, PSin.z.yy).x * g_fOneColor.z + g_fOneColor.w + g_fc0.w;
half4 c = texture(g_sMemory, ps2memcoord(PSin.tex.xy).xy);
c.w = (c.w * g_fOneColor.x + g_fOneColor.y)*finter;
gl_FragData[0] = c;
FragData0 = c;
}
void CRTCPS() {
float2 filtcoord = PSin.tex.xy * g_fInvTexDims.xy+g_fInvTexDims.zw;
half4 c = BilinearBitBlt(filtcoord);
c.w = c.w * g_fOneColor.x + g_fOneColor.y;
gl_FragData[0] = c;
FragData0 = c;
}
// simpler
void CRTCPS_Nearest() {
half4 c = texture(g_sMemory, ps2memcoord(PSin.tex.xy).xy);
c.w = c.w * g_fOneColor.x + g_fOneColor.y;
gl_FragData[0] = c;
FragData0 = c;
}
void CRTC24InterPS() {
@ -804,22 +806,30 @@ void CRTC24InterPS() {
half4 c = texture(g_sMemory, ps2memcoord(filtcoord).xy);
c.w = (c.w * g_fOneColor.x + g_fOneColor.y)*finter;
gl_FragData[0] = c;
FragData0 = c;
}
void CRTC24PS() {
float2 filtcoord = trunc(PSin.tex.xy) * g_fInvTexDims.xy + g_fInvTexDims.zw;
half4 c = texture(g_sMemory, ps2memcoord(filtcoord).xy);
c.w = c.w * g_fOneColor.x + g_fOneColor.y;
gl_FragData[0] = c;
FragData0 = c;
}
void ZeroPS() {
gl_FragData[0] = g_fOneColor;
FragData0 = g_fOneColor;
}
void ZeroDebugPS() {
FragData0 = vec4(0.0, 1.0, 0.0, 1.0);
}
void ZeroDebug2PS() {
FragData0 = vec4(1.0, 0.0, 0.0, 1.0);
}
void BaseTexturePS() {
gl_FragData[0] = texture(g_sSrcFinal, PSin.tex.xy) * g_fOneColor;
FragData0 = texture(g_sSrcFinal, PSin.tex.xy) * g_fOneColor;
}
void Convert16to32PS() {
@ -838,7 +848,7 @@ void Convert16to32PS() {
final.zy = texture(g_sConv32to16, lower.zyx).xy + lower.ww*g_fPageOffset.zw;
final.xw = texture(g_sConv32to16, upper.zyx).xy + upper.ww*g_fPageOffset.zw;
gl_FragData[0]= final;
FragData0= final;
}
// use when texture is not tiled and converting from 32bit to 16bit
@ -859,7 +869,7 @@ void Convert32to16PS() {
half4 color = texture(g_sSrcFinal, tex0*g_fTexDims.xy)*g_fc0.yyyw;
float2 uv = upper ? color.xw : color.zy;
gl_FragData[0] = texture(g_sConv16to32, uv*g_fPageOffset.xy+g_fPageOffset.zw)*g_fTexDims.xxxy;
FragData0 = texture(g_sConv16to32, uv*g_fPageOffset.xy+g_fPageOffset.zw)*g_fTexDims.xxxy;
}
#endif //FRAGMENT_SHADER