diff --git a/plugins/zzogl-pg/opengl/GS.h b/plugins/zzogl-pg/opengl/GS.h index 41933d1c89..c6af7f9456 100644 --- a/plugins/zzogl-pg/opengl/GS.h +++ b/plugins/zzogl-pg/opengl/GS.h @@ -515,6 +515,12 @@ typedef struct return ((primIndex + inc) % ARRAY_SIZE(gsvertex)); } + int primPrev(int dec = 1) + { + // Note: assert( dec <= ARRAY_SIZE(gsvertex) ); + return ((primIndex + (ARRAY_SIZE(gsvertex) - dec)) % ARRAY_SIZE(gsvertex)); + } + void setRGBA(u32 r, u32 g, u32 b, u32 a) { rgba = (r & 0xff) | @@ -523,23 +529,21 @@ typedef struct ((a & 0xff) << 24); } - void add_vertex(u16 x, u16 y, u32 z, u16 f) + inline void add_vertex(u16 x, u16 y, u32 z, u16 f) { vertexregs.x = x; vertexregs.y = y; vertexregs.z = z; vertexregs.f = f; gsvertex[primIndex] = vertexregs; - primIndex = primNext(); } - void add_vertex(u16 x, u16 y, u32 z) + inline void add_vertex(u16 x, u16 y, u32 z) { vertexregs.x = x; vertexregs.y = y; vertexregs.z = z; gsvertex[primIndex] = vertexregs; - primIndex = primNext(); } } GSinternal; diff --git a/plugins/zzogl-pg/opengl/Regs.cpp b/plugins/zzogl-pg/opengl/Regs.cpp index 8efea61d67..a3e1cd3c31 100644 --- a/plugins/zzogl-pg/opengl/Regs.cpp +++ b/plugins/zzogl-pg/opengl/Regs.cpp @@ -87,12 +87,8 @@ void __gifCall GIFPackedRegHandlerUV(const u32* data) void __gifCall GIFPackedRegHandlerXYZF2(const u32* data) { FUNCLOG - gs.vertexregs.x = (data[0] >> 0) & 0xffff; - gs.vertexregs.y = (data[1] >> 0) & 0xffff; - gs.vertexregs.z = (data[2] >> 4) & 0xffffff; - gs.vertexregs.f = (data[3] >> 4) & 0xff; - gs.gsvertex[gs.primIndex] = gs.vertexregs; - gs.primIndex = gs.primNext(); + GIFPackedXYZF2* r = (GIFPackedXYZF2*)(data); + gs.add_vertex(r->X, r->Y,r->Z, r->F); ZZKick->KickVertex(!!(data[3]>>31)); } @@ -100,11 +96,8 @@ void __gifCall GIFPackedRegHandlerXYZF2(const u32* data) void __gifCall GIFPackedRegHandlerXYZ2(const u32* data) { FUNCLOG - gs.vertexregs.x = (data[0] >> 0) & 0xffff; - gs.vertexregs.y = (data[1] >> 0) & 0xffff; - gs.vertexregs.z = data[2]; - gs.gsvertex[gs.primIndex] = gs.vertexregs; - gs.primIndex = gs.primNext(); + GIFPackedXYZ2* r = (GIFPackedXYZ2*)(data); + gs.add_vertex(r->X, r->Y,r->Z); ZZKick->KickVertex(!!(data[3]>>31)); } @@ -310,7 +303,6 @@ void __gifCall GIFRegHandlerPRIM(const u32 *data) //ZZLog::Warn_Log("Warning: unknown bits in prim %8.8lx_%8.8lx", data[1], data[0]); //} - gs.nTriFanVert = gs.primIndex; gs.primC = 0; prim->prim = (data[0]) & 0x7; @@ -318,6 +310,8 @@ void __gifCall GIFRegHandlerPRIM(const u32 *data) gs._prim[1].prim = (data[0]) & 0x7; gs._prim[1]._val = (data[0] >> 3) & 0xff; + gs.nTriFanVert = gs.primIndex; + Prim(); } @@ -347,12 +341,8 @@ void __gifCall GIFRegHandlerUV(const u32* data) void __gifCall GIFRegHandlerXYZF2(const u32* data) { FUNCLOG - gs.vertexregs.x = (data[0]) & 0xffff; - gs.vertexregs.y = (data[0] >> (16)) & 0xffff; - gs.vertexregs.z = data[1] & 0xffffff; - gs.vertexregs.f = data[1] >> 24; - gs.gsvertex[gs.primIndex] = gs.vertexregs; - gs.primIndex = gs.primNext(); + GIFRegXYZF* r = (GIFRegXYZF*)(data); + gs.add_vertex(r->X, r->Y,r->Z, r->F); ZZKick->KickVertex(false); } @@ -360,11 +350,8 @@ void __gifCall GIFRegHandlerXYZF2(const u32* data) void __gifCall GIFRegHandlerXYZ2(const u32* data) { FUNCLOG - gs.vertexregs.x = (data[0]) & 0xffff; - gs.vertexregs.y = (data[0] >> (16)) & 0xffff; - gs.vertexregs.z = data[1]; - gs.gsvertex[gs.primIndex] = gs.vertexregs; - gs.primIndex = gs.primNext(); + GIFRegXYZ* r = (GIFRegXYZ*)(data); + gs.add_vertex(r->X, r->Y,r->Z); ZZKick->KickVertex(false); } @@ -407,12 +394,8 @@ void __gifCall GIFRegHandlerFOG(const u32* data) void __gifCall GIFRegHandlerXYZF3(const u32* data) { FUNCLOG - gs.vertexregs.x = (data[0]) & 0xffff; - gs.vertexregs.y = (data[0] >> (16)) & 0xffff; - gs.vertexregs.z = data[1] & 0xffffff; - gs.vertexregs.f = data[1] >> 24; - gs.gsvertex[gs.primIndex] = gs.vertexregs; - gs.primIndex = gs.primNext(); + GIFRegXYZF* r = (GIFRegXYZF*)(data); + gs.add_vertex(r->X, r->Y,r->Z, r->F); ZZKick->KickVertex(true); } @@ -420,11 +403,8 @@ void __gifCall GIFRegHandlerXYZF3(const u32* data) void __gifCall GIFRegHandlerXYZ3(const u32* data) { FUNCLOG - gs.vertexregs.x = (data[0]) & 0xffff; - gs.vertexregs.y = (data[0] >> (16)) & 0xffff; - gs.vertexregs.z = data[1]; - gs.gsvertex[gs.primIndex] = gs.vertexregs; - gs.primIndex = gs.primNext(); + GIFRegXYZ* r = (GIFRegXYZ*)(data); + gs.add_vertex(r->X, r->Y,r->Z); ZZKick->KickVertex(true); } diff --git a/plugins/zzogl-pg/opengl/ZZKick.cpp b/plugins/zzogl-pg/opengl/ZZKick.cpp index 1b57773b13..2425fd9e6e 100644 --- a/plugins/zzogl-pg/opengl/ZZKick.cpp +++ b/plugins/zzogl-pg/opengl/ZZKick.cpp @@ -60,27 +60,30 @@ void __forceinline Kick::KickVertex(bool adc) gs.primC -= g_primsub[prim->prim]; + gs.primIndex = gs.primNext(); if (prim->prim == 5) { /* tri fans need special processing */ if (gs.nTriFanVert == gs.primIndex) gs.primIndex = gs.primNext(); } + } else { + gs.primIndex = gs.primNext(); } } template -void Kick::Set_Vertex(VertexGPU *p, int i) +void Kick::Set_Vertex(VertexGPU *p, Vertex & gsvertex) { VB& curvb = vb[prim->ctxt]; - p->move_x(gs.gsvertex[i], curvb.offset.x); - p->move_y(gs.gsvertex[i], curvb.offset.y); + p->move_x(gsvertex, curvb.offset.x); + p->move_y(gsvertex, curvb.offset.y); if(DO_Z_FOG) { - p->move_z(gs.gsvertex[i], curvb.zprimmask); - p->move_fog(gs.gsvertex[i]); + p->move_z(gsvertex, curvb.zprimmask); + p->move_fog(gsvertex); } - p->rgba = prim->iip ? gs.gsvertex[i].rgba : gs.rgba; + p->rgba = prim->iip ? gsvertex.rgba : gs.rgba; if (conf.settings().texa) { @@ -92,15 +95,15 @@ void Kick::Set_Vertex(VertexGPU *p, int i) { if (prim->fst) { - p->s = (float)gs.gsvertex[i].u * fiTexWidth[prim->ctxt]; - p->t = (float)gs.gsvertex[i].v * fiTexHeight[prim->ctxt]; + p->s = (float)gsvertex.u * fiTexWidth[prim->ctxt]; + p->t = (float)gsvertex.v * fiTexHeight[prim->ctxt]; p->q = 1; } else { - p->s = gs.gsvertex[i].s; - p->t = gs.gsvertex[i].t; - p->q = gs.gsvertex[i].q; + p->s = gsvertex.s; + p->t = gsvertex.t; + p->q = gsvertex.q; } } } @@ -133,13 +136,13 @@ void Kick::DrawPrim(u32 prim_type) VertexGPU* p = curvb.pBufferData + curvb.nCount; - u32 next; + u32 prev; u32 last; switch(prim_type) { case PRIM_POINT: assert(gs.primC >= 1); - Set_Vertex(&p[0], gs.primNext(2)); + Set_Vertex(&p[0], gs.gsvertex[gs.primIndex]); curvb.nCount ++; break; @@ -147,8 +150,8 @@ void Kick::DrawPrim(u32 prim_type) case PRIM_LINE_STRIP: assert(gs.primC >= 2); - Set_Vertex(&p[0], gs.primNext()); - Set_Vertex(&p[1], gs.primNext(2)); + Set_Vertex(&p[0], gs.gsvertex[gs.primPrev()]); + Set_Vertex(&p[1], gs.gsvertex[gs.primIndex]); curvb.nCount += 2; break; @@ -157,29 +160,29 @@ void Kick::DrawPrim(u32 prim_type) case PRIM_TRIANGLE_FAN: assert(gs.primC >= 3); - Set_Vertex(&p[0], 0); - Set_Vertex(&p[1], 1); - Set_Vertex(&p[2], 2); + Set_Vertex(&p[0], gs.gsvertex[0]); + Set_Vertex(&p[1], gs.gsvertex[1]); + Set_Vertex(&p[2], gs.gsvertex[2]); curvb.nCount += 3; break; case PRIM_SPRITE: assert(gs.primC >= 2); - next = gs.primNext(); - last = gs.primNext(2); + prev = gs.primPrev(); + last = gs.primIndex; // sprite is too small and AA shows lines (tek4, Mana Khemia) gs.gsvertex[last].x += (4 * AA.x); gs.gsvertex[last].y += (4 * AA.y); // might be bad sprite (KH dialog text) - //if( gs.gsvertex[next].x == gs.gsvertex[last].x || gs.gsvertex[next].y == gs.gsvertex[last].y ) + //if( gs.gsvertex[prev].x == gs.gsvertex[last].x || gs.gsvertex[prev].y == gs.gsvertex[last].y ) //return; // process sprite as 2 triangles. The common diagonal is 0,1 and 3,4 - Set_Vertex(&p[0], next); - Set_Vertex(&p[1], last); + Set_Vertex(&p[0], gs.gsvertex[prev]); + Set_Vertex(&p[1], gs.gsvertex[last]); // Only fog and Z of last vertex is valid p[0].z = p[1].z; diff --git a/plugins/zzogl-pg/opengl/ZZKick.h b/plugins/zzogl-pg/opengl/ZZKick.h index 2c70d0de4c..00ef67c5a3 100644 --- a/plugins/zzogl-pg/opengl/ZZKick.h +++ b/plugins/zzogl-pg/opengl/ZZKick.h @@ -39,7 +39,8 @@ enum PRIM_TYPE { class Kick { private: - template void Set_Vertex(VertexGPU *p, int i); + // template void Set_Vertex(VertexGPU *p, int i); + template void Set_Vertex(VertexGPU *p, Vertex &gsvertex); void Output_Vertex(VertexGPU vert, u32 id); public: Kick() { }