/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/ZZoglFlush.cpp
ViewVC logotype

Diff of /trunk/plugins/zzogl-pg/opengl/ZZoglFlush.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 1  Line 1 
1  /*  ZZ Open GL graphics plugin  /*  ZZ Open GL graphics plugin
2   *  Copyright (c)2009 zeydlitz@gmail.com   *  Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3   *  Based on Zerofrog's ZeroGS KOSMOS (c)2005-2006   *  Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
4   *   *
5   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
6   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 14  Line 14 
14   *   *
15   *  You should have received a copy of the GNU General Public License   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */   */
19    
20  // Realisation of Flush -- drawing function of GS  // Realization of Flush -- drawing function of GS
21    
22  #include <stdlib.h>  #include <stdlib.h>
23    
# Line 29  Line 29 
29  using namespace ZeroGS;  using namespace ZeroGS;
30    
31  //------------------ Defines  //------------------ Defines
32  #ifndef DEVBUILD  #ifndef ZEROGS_DEVBUILD
33    
34  #define INC_GENVARS()  #define INC_GENVARS()
35  #define INC_TEXVARS()  #define INC_TEXVARS()
# Line 61  bool g_bSaveResolved = 0; Line 61  bool g_bSaveResolved = 0;
61  //#define STENCIL_PBE              16  //#define STENCIL_PBE              16
62  #define STENCIL_CLEAR      (2|4|8|16)  #define STENCIL_CLEAR      (2|4|8|16)
63    
64  #define DRAW() glDrawArrays(primtype[curvb.curprim.prim], 0, curvb.nCount)  void Draw(const VB& curvb)
65    {
66            glDrawArrays(primtype[curvb.curprim.prim], 0, curvb.nCount);
67    }
68    
69  #define GL_BLEND_RGB(src, dst) { \  #define GL_BLEND_RGB(src, dst) { \
70          s_srcrgb = src; \          s_srcrgb = src; \
# Line 114  bool g_bSaveResolved = 0; Line 117  bool g_bSaveResolved = 0;
117    
118  //------------------ variables  //------------------ variables
119    
120  extern bool g_bIsLost;  extern int g_nDepthBias;
121    extern float g_fBlockMult;
122  bool g_bUpdateStencil = 1;  bool g_bUpdateStencil = 1;
123  u32 g_SaveFrameNum = 0;                                                                 // ZZ  //u32 g_SaveFrameNum = 0;                                                                       // ZZ
124    
125  int GPU_TEXWIDTH = 512;  int GPU_TEXWIDTH = 512;
126  float g_fiGPU_TEXWIDTH = 1 / 512.0f;  float g_fiGPU_TEXWIDTH = 1 / 512.0f;
# Line 138  static const u32 g_dwZCmp[] = { GL_NEVER Line 142  static const u32 g_dwZCmp[] = { GL_NEVER
142  /////////////////////  /////////////////////
143  // graphics resources  // graphics resources
144  #define s_bForceTexFlush 1                                      // ZZ  #define s_bForceTexFlush 1                                      // ZZ
145  u32 s_ptexCurSet[2] = {0};  static u32 s_ptexCurSet[2] = {0};
146  static u32 s_ptexNextSet[2] = {0};                              // ZZ  static u32 s_ptexNextSet[2] = {0};                              // ZZ
147    
 vector<u32> s_vecTempTextures;             // temporary textures, released at the end of every frame  
148    
149    extern vector<u32> s_vecTempTextures;              // temporary textures, released at the end of every frame
150  extern bool s_bTexFlush;  extern bool s_bTexFlush;
151  bool s_bWriteDepth = false;  bool s_bWriteDepth = false;
152  bool s_bDestAlphaTest = false;  bool s_bDestAlphaTest = false;
# Line 155  int s_nWriteDestAlphaTest = 0;                                 // ZZ Line 159  int s_nWriteDestAlphaTest = 0;                                 // ZZ
159  // State parameters  // State parameters
160  static Vector vAlphaBlendColor;  // used for GPU_COLOR  static Vector vAlphaBlendColor;  // used for GPU_COLOR
161    
162  static u8 bNeedBlendFactorInAlpha;        // set if the output source alpha is different from the real source alpha (only when blend factor > 0x80)  static bool bNeedBlendFactorInAlpha;      // set if the output source alpha is different from the real source alpha (only when blend factor > 0x80)
163  static u32 s_dwColorWrite = 0xf;                        // the color write mask of the current target  static u32 s_dwColorWrite = 0xf;                        // the color write mask of the current target
164    
165  union  typedef union
166  {  {
   
167          struct          struct
168          {          {
169                  u8 _bNeedAlphaColor;            // set if vAlphaBlendColor needs to be set                  u8 _bNeedAlphaColor;            // set if vAlphaBlendColor needs to be set
# Line 171  union Line 174  union
174          };          };
175    
176          u32 _bAlphaState;          u32 _bAlphaState;
177  } g_vars;  } g_flag_vars;
178    
179    g_flag_vars g_vars;
180    
181  //#define bNeedAlphaColor g_vars._bNeedAlphaColor  //#define bNeedAlphaColor g_vars._bNeedAlphaColor
182  #define b2XAlphaTest g_vars._b2XAlphaTest  #define b2XAlphaTest g_vars._b2XAlphaTest
# Line 180  union Line 185  union
185    
186  int g_PrevBitwiseTexX = -1, g_PrevBitwiseTexY = -1; // textures stored in SAMP_BITWISEANDX and SAMP_BITWISEANDY         // ZZ  int g_PrevBitwiseTexX = -1, g_PrevBitwiseTexY = -1; // textures stored in SAMP_BITWISEANDX and SAMP_BITWISEANDY         // ZZ
187    
188  static alphaInfo s_alphaInfo;                                                                                           // ZZ  //static alphaInfo s_alphaInfo;                                                                                         // ZZ
189    
190  extern u8* g_pbyGSClut;  extern u8* g_pbyGSClut;
191    extern int ppf;
192    
193    int s_nWireframeCount = 0;
194    
195  //------------------ Namespace  //------------------ Namespace
196    
# Line 244  inline void SetAlphaTest(const pixTest& Line 252  inline void SetAlphaTest(const pixTest&
252  // Switch wireframe rendering off for first flush, so it's draw few solid primitives  // Switch wireframe rendering off for first flush, so it's draw few solid primitives
253  inline void SwitchWireframeOff()  inline void SwitchWireframeOff()
254  {  {
255          if (conf.options & GSOPTION_WIREFRAME)          if (conf.wireframe())
256          {          {
257                  if (s_nWireframeCount > 0)                  if (s_nWireframeCount > 0)
258                  {                  {
# Line 256  inline void SwitchWireframeOff() Line 264  inline void SwitchWireframeOff()
264  // Switch wireframe rendering on, look at previous function  // Switch wireframe rendering on, look at previous function
265  inline void SwitchWireframeOn()  inline void SwitchWireframeOn()
266  {  {
267          if (conf.options & GSOPTION_WIREFRAME)          if (conf.wireframe())
268          {          {
269                  if (s_nWireframeCount > 0)                  if (s_nWireframeCount > 0)
270                  {                  {
# Line 312  inline void VisualBufferMessage(int cont Line 320  inline void VisualBufferMessage(int cont
320          static const char* patst[8] = { "NEVER", "ALWAYS", "LESS", "LEQUAL", "EQUAL", "GEQUAL", "GREATER", "NOTEQUAL"};          static const char* patst[8] = { "NEVER", "ALWAYS", "LESS", "LEQUAL", "EQUAL", "GEQUAL", "GREATER", "NOTEQUAL"};
321          static const char* pztst[4] = { "NEVER", "ALWAYS", "GEQUAL", "GREATER" };          static const char* pztst[4] = { "NEVER", "ALWAYS", "GEQUAL", "GREATER" };
322          static const char* pafail[4] = { "KEEP", "FB_ONLY", "ZB_ONLY", "RGB_ONLY" };          static const char* pafail[4] = { "KEEP", "FB_ONLY", "ZB_ONLY", "RGB_ONLY" };
323          ZZLog::Error_Log("**Drawing ctx %d, num %d, fbp: 0x%x, zbp: 0x%x, fpsm: %d, zpsm: %d, fbw: %d", context, vb[context].nCount, curvb.prndr->fbp, curvb.zbuf.zbp, curvb.prndr->psm, curvb.zbuf.psm, curvb.prndr->fbw);          ZZLog::Debug_Log("**Drawing ctx %d, num %d, fbp: 0x%x, zbp: 0x%x, fpsm: %d, zpsm: %d, fbw: %d", context, vb[context].nCount, curvb.prndr->fbp, curvb.zbuf.zbp, curvb.prndr->psm, curvb.zbuf.psm, curvb.prndr->fbw);
324          ZZLog::Error_Log("prim: prim=%x iip=%x tme=%x fge=%x abe=%x aa1=%x fst=%x ctxt=%x fix=%x",          ZZLog::Debug_Log("prim: prim=%x iip=%x tme=%x fge=%x abe=%x aa1=%x fst=%x ctxt=%x fix=%x",
325                                           curvb.curprim.prim, curvb.curprim.iip, curvb.curprim.tme, curvb.curprim.fge, curvb.curprim.abe, curvb.curprim.aa1, curvb.curprim.fst, curvb.curprim.ctxt, curvb.curprim.fix);                                           curvb.curprim.prim, curvb.curprim.iip, curvb.curprim.tme, curvb.curprim.fge, curvb.curprim.abe, curvb.curprim.aa1, curvb.curprim.fst, curvb.curprim.ctxt, curvb.curprim.fix);
326          ZZLog::Error_Log("test: ate:%d, atst: %s, aref: %d, afail: %s, date: %d, datm: %d, zte: %d, ztst: %s, fba: %d",          ZZLog::Debug_Log("test: ate:%d, atst: %s, aref: %d, afail: %s, date: %d, datm: %d, zte: %d, ztst: %s, fba: %d",
327                                           curvb.test.ate, patst[curvb.test.atst], curvb.test.aref, pafail[curvb.test.afail], curvb.test.date, curvb.test.datm, curvb.test.zte, pztst[curvb.test.ztst], curvb.fba.fba);                                           curvb.test.ate, patst[curvb.test.atst], curvb.test.aref, pafail[curvb.test.afail], curvb.test.date, curvb.test.datm, curvb.test.zte, pztst[curvb.test.ztst], curvb.fba.fba);
328          ZZLog::Error_Log("alpha: A%d B%d C%d D%d FIX:%d pabe: %d; aem: %d, ta0: %d, ta1: %d\n", curvb.alpha.a, curvb.alpha.b, curvb.alpha.c, curvb.alpha.d, curvb.alpha.fix, gs.pabe, gs.texa.aem, gs.texa.ta[0], gs.texa.ta[1]);          ZZLog::Debug_Log("alpha: A%d B%d C%d D%d FIX:%d pabe: %d; aem: %d, ta0: %d, ta1: %d\n", curvb.alpha.a, curvb.alpha.b, curvb.alpha.c, curvb.alpha.d, curvb.alpha.fix, gs.pabe, gs.texa.aem, gs.texa.ta[0], gs.texa.ta[1]);
329          ZZLog::Error_Log("tex0: tbp0=0x%x, tbw=%d, psm=0x%x, tw=%d, th=%d, tcc=%d, tfx=%d, cbp=0x%x, cpsm=0x%x, csm=%d, csa=%d, cld=%d",          ZZLog::Debug_Log("tex0: tbp0=0x%x, tbw=%d, psm=0x%x, tw=%d, th=%d, tcc=%d, tfx=%d, cbp=0x%x, cpsm=0x%x, csm=%d, csa=%d, cld=%d",
330                                           curvb.tex0.tbp0, curvb.tex0.tbw, curvb.tex0.psm, curvb.tex0.tw,                                           curvb.tex0.tbp0, curvb.tex0.tbw, curvb.tex0.psm, curvb.tex0.tw,
331                                           curvb.tex0.th, curvb.tex0.tcc, curvb.tex0.tfx, curvb.tex0.cbp,                                           curvb.tex0.th, curvb.tex0.tcc, curvb.tex0.tfx, curvb.tex0.cbp,
332                                           curvb.tex0.cpsm, curvb.tex0.csm, curvb.tex0.csa, curvb.tex0.cld);                                           curvb.tex0.cpsm, curvb.tex0.csm, curvb.tex0.csa, curvb.tex0.cld);
# Line 331  inline void VisualBufferMessage(int cont Line 339  inline void VisualBufferMessage(int cont
339          ZZLog::Error_Log("TGA name '%s'.", Name);          ZZLog::Error_Log("TGA name '%s'.", Name);
340          free(Name);          free(Name);
341  //      }  //      }
342          ZZLog::Error_Log("frame: %d, buffer %ld.\n", g_SaveFrameNum, BufferNumber);  //      ZZLog::Debug_Log("frame: %d, buffer %ld.\n", g_SaveFrameNum, BufferNumber);
343            ZZLog::Debug_Log("buffer %ld.\n", BufferNumber);
344  #endif  #endif
345  }  }
346    
# Line 339  inline void SaveRendererTarget(VB& curvb Line 348  inline void SaveRendererTarget(VB& curvb
348  {  {
349  #ifdef _DEBUG  #ifdef _DEBUG
350    
351          if (g_bSaveFlushedFrame & 0x80000000)  //      if (g_bSaveFlushedFrame & 0x80000000)
352          {  //      {
353                  char str[255];  //              char str[255];
354                  sprintf(str, "rndr.tga", g_SaveFrameNum);  //              sprintf(str, "rndr%d.tga", g_SaveFrameNum);
355                  SaveRenderTarget(str, curvb.prndr->fbw, curvb.prndr->fbh, 0);  //              SaveRenderTarget(str, curvb.prndr->fbw, curvb.prndr->fbh, 0);
356          }  //      }
357    
358  #endif  #endif
359  }  }
# Line 366  inline void FlushUpdateEffect() Line 375  inline void FlushUpdateEffect()
375  // Check, maybe we cold skip flush  // Check, maybe we cold skip flush
376  inline bool IsFlushNoNeed(VB& curvb, const pixTest& curtest)  inline bool IsFlushNoNeed(VB& curvb, const pixTest& curtest)
377  {  {
378          if (curvb.nCount == 0 || (curtest.zte && curtest.ztst == 0) || g_bIsLost)          if (curvb.nCount == 0 || (curtest.zte && curtest.ztst == 0))
379          {          {
380                  curvb.nCount = 0;                  curvb.nCount = 0;
381                  return true;                  return true;
# Line 390  inline void FlushTransferRangesHelper(VB Line 399  inline void FlushTransferRangesHelper(VB
399          }          }
400  }  }
401    
402  // If set bit for texture cheking, do it. Maybe it's all.  // If set bit for texture checking, do it. Maybe it's all.
403  inline bool FushTexDataHelper(VB& curvb)  inline bool FushTexDataHelper(VB& curvb)
404  {  {
405          if (curvb.bNeedFrameCheck || curvb.bNeedZCheck)          if (curvb.bNeedFrameCheck || curvb.bNeedZCheck)
# Line 449  inline CRenderTarget* FlushReGetTarget(i Line 458  inline CRenderTarget* FlushReGetTarget(i
458          // This was incorrect code          // This was incorrect code
459          CRenderTarget* ptextarg = NULL;          CRenderTarget* ptextarg = NULL;
460    
461          if (ptextarg == NULL && tpsm == PSMT8 && (g_GameSettings & GAME_REGETHACK))          if ((ptextarg == NULL) && (tpsm == PSMT8) && (conf.settings().reget))
462          {          {
463                  // check for targets with half the width. Break Valkyrie Chronicles                  // check for targets with half the width. Break Valkyrie Chronicles
464                  ptextarg = s_RTs.GetTarg(tbp0, tbw / 2, curvb);                  ptextarg = s_RTs.GetTarg(tbp0, tbw / 2, curvb);
# Line 481  inline CRenderTarget* FlushReGetTarget(i Line 490  inline CRenderTarget* FlushReGetTarget(i
490                  ptextarg = s_DepthRTs.GetTarg(tbp0, tbw, curvb);                  ptextarg = s_DepthRTs.GetTarg(tbp0, tbw, curvb);
491          }          }
492    
493          if ((ptextarg == NULL) && (g_GameSettings & GAME_TEXTURETARGS))          if ((ptextarg == NULL) && (conf.settings().texture_targs))
494          {          {
495                  // check if any part of the texture intersects the current target                  // check if any part of the texture intersects the current target
496                  if (!PSMT_ISCLUT(tpsm) && (curvb.tex0.tbp0 >= curvb.frame.fbp) && ((curvb.tex0.tbp0) < curvb.prndr->end))                  if (!PSMT_ISCLUT(tpsm) && (curvb.tex0.tbp0 >= curvb.frame.fbp) && ((curvb.tex0.tbp0) < curvb.prndr->end))
# Line 490  inline CRenderTarget* FlushReGetTarget(i Line 499  inline CRenderTarget* FlushReGetTarget(i
499                  }                  }
500          }          }
501    
502  #ifdef DEBUG  #ifdef _DEBUG
503          if (tbp0 == 0x3600 && tbw == 0x100)          if (tbp0 == 0x3600 && tbw == 0x100)
504          {          {
505                  if (ptextarg == NULL)                  if (ptextarg == NULL)
# Line 624  inline void FlushSetContextTarget(VB& cu Line 633  inline void FlushSetContextTarget(VB& cu
633    
634          if (curvb.pdepth != NULL)          if (curvb.pdepth != NULL)
635          {          {
636                  assert(!(curvb.pdepth->status&CRenderTarget::TS_NeedUpdate));  #ifdef _DEBUG
637                    // Reduce an assert to a warning.
638                    if (curvb.pdepth->status & CRenderTarget::TS_NeedUpdate)
639                    {
640                            ZZLog::Debug_Log("In FlushSetContextTarget, pdepth has TS_NeedUpdate set.");
641                    }
642    #endif
643                  if (!curvb.zbuf.zmsk)                  if (!curvb.zbuf.zmsk)
644                  {                  {
645                          assert(!(curvb.pdepth->status & CRenderTarget::TS_Virtual));                          assert(!(curvb.pdepth->status & CRenderTarget::TS_Virtual));
# Line 643  inline void FlushSetStream(VB& curvb) Line 657  inline void FlushSetStream(VB& curvb)
657  //      memcpy_amd(pdata, curvb.pBufferData, curvb.nCount * sizeof(VertexGPU));  //      memcpy_amd(pdata, curvb.pBufferData, curvb.nCount * sizeof(VertexGPU));
658  //      glUnmapBuffer(GL_ARRAY_BUFFER);  //      glUnmapBuffer(GL_ARRAY_BUFFER);
659          SET_STREAM();          SET_STREAM();
660  #ifdef _DEBUG          
661          GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);          GL_REPORT_ERRORD();
         assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT);  
 #endif  
   
662  }  }
663    
664  int SetMaskR = 0x0;  int SetMaskR = 0x0;
# Line 764  inline void FlushDecodeClut(VB& curvb, G Line 775  inline void FlushDecodeClut(VB& curvb, G
775                          }                          }
776                  }                  }
777    
778                  glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 1, 0, GL_RGBA, PSMT_ISHALF_STORAGE(curvb.tex0) ? GL_UNSIGNED_SHORT_5_5_5_1 : GL_UNSIGNED_BYTE, &data[0]);                  GLenum tempType = PSMT_ISHALF_STORAGE(curvb.tex0) ? GL_UNSIGNED_SHORT_5_5_5_1 : GL_UNSIGNED_BYTE;
779                    Texture2D(4, 256, 1, GL_RGBA, tempType, &data[0]);
780                    
781                  s_vecTempTextures.push_back(ptexclut);                  s_vecTempTextures.push_back(ptexclut);
782    
783                  if (g_bSaveTex) SaveTexture("clut.tga", GL_TEXTURE_2D, ptexclut, 256, 1);                  if (g_bSaveTex) SaveTexture("clut.tga", GL_TEXTURE_2D, ptexclut, 256, 1);
784    
785                  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);                  setTex2DWrap(GL_REPEAT);
786                  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);                  setTex2DFilters(GL_LINEAR);
                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  
                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  
787          }          }
788  }  }
789    
790  inline int FlushGetShaderType(VB& curvb, CRenderTarget* ptextarg, GLuint& ptexclut)  inline int FlushGetShaderType(VB& curvb, CRenderTarget* ptextarg, GLuint& ptexclut)
791  {  {
792          if (PSMT_ISCLUT(curvb.tex0.psm) && !(g_GameSettings&GAME_NOTARGETCLUT))          if (PSMT_ISCLUT(curvb.tex0.psm) && !(conf.settings().no_target_clut))
793          {          {
794                  FlushDecodeClut(curvb, ptexclut);                  FlushDecodeClut(curvb, ptexclut);
795    
# Line 814  inline int FlushGetShaderType(VB& curvb, Line 824  inline int FlushGetShaderType(VB& curvb,
824  }  }
825    
826    
827  //Set page offsets depends omn shader type.  //Set page offsets depends on shader type.
828  inline Vector FlushSetPageOffset(FRAGMENTSHADER* pfragment, int shadertype, CRenderTarget* ptextarg)  inline Vector FlushSetPageOffset(FRAGMENTSHADER* pfragment, int shadertype, CRenderTarget* ptextarg)
829  {  {
830          SetShaderCaller("FlushSetPageOffset");          SetShaderCaller("FlushSetPageOffset");
# Line 932  inline void FlushApplyResizeFilter(VB& c Line 942  inline void FlushApplyResizeFilter(VB& c
942  }  }
943    
944    
945  // Usage existing targets depends on several tricks, 32-16 conversion and CLUTing, so we need handle it.  // Usage existing targets depends on several tricks, 32-16 conversion and CLUTing, so we need to handle it.
946  inline FRAGMENTSHADER* FlushUseExistRenderTaget(VB& curvb, CRenderTarget* ptextarg, u32& dwFilterOpts, int exactcolor, int context)  inline FRAGMENTSHADER* FlushUseExistRenderTarget(VB& curvb, CRenderTarget* ptextarg, u32& dwFilterOpts, int exactcolor, int context)
947  {  {
948          if (ptextarg->IsDepth())          if (ptextarg->IsDepth())
949                  SetWriteDepth();                  SetWriteDepth();
# Line 986  inline FRAGMENTSHADER* FlushMadeNewTarge Line 996  inline FRAGMENTSHADER* FlushMadeNewTarge
996          }          }
997    
998          FRAGMENTSHADER* pfragment = LoadShadeEffect(0, GetTexFilter(curvb.tex1), curvb.curprim.fge,          FRAGMENTSHADER* pfragment = LoadShadeEffect(0, GetTexFilter(curvb.tex1), curvb.curprim.fge,
   
999                                                                  IsAlphaTestExpansion(curvb), exactcolor, curvb.clamp, context, NULL);                                                                  IsAlphaTestExpansion(curvb), exactcolor, curvb.clamp, context, NULL);
1000    
1001          if (pfragment == NULL)          if (pfragment == NULL)
# Line 1042  inline FRAGMENTSHADER* FlushRendererStag Line 1051  inline FRAGMENTSHADER* FlushRendererStag
1051          if (curvb.curprim.tme)          if (curvb.curprim.tme)
1052          {          {
1053                  if (ptextarg != NULL)                  if (ptextarg != NULL)
1054                          pfragment = FlushUseExistRenderTaget(curvb, ptextarg, dwFilterOpts, exactcolor, context);                          pfragment = FlushUseExistRenderTarget(curvb, ptextarg, dwFilterOpts, exactcolor, context);
1055                  else                  else
1056                          pfragment = FlushMadeNewTarget(curvb, exactcolor, context);                          pfragment = FlushMadeNewTarget(curvb, exactcolor, context);
1057    
# Line 1073  inline FRAGMENTSHADER* FlushRendererStag Line 1082  inline FRAGMENTSHADER* FlushRendererStag
1082  inline bool AlphaCanRenderStencil(VB& curvb)  inline bool AlphaCanRenderStencil(VB& curvb)
1083  {  {
1084          return g_bUpdateStencil && (PSMT_BITMODE(curvb.prndr->psm) != 1) &&          return g_bUpdateStencil && (PSMT_BITMODE(curvb.prndr->psm) != 1) &&
1085                     !ZZOglGet_fbmHighByte(curvb.frame.fbm) && !(g_GameSettings & GAME_NOSTENCIL);                     !ZZOglGet_fbmHighByte(curvb.frame.fbm) && !(conf.settings().no_stencil);
1086  }  }
1087    
1088  inline void AlphaSetStencil(bool DoIt)  inline void AlphaSetStencil(bool DoIt)
# Line 1244  inline void AlphaTest(VB& curvb) Line 1253  inline void AlphaTest(VB& curvb)
1253    
1254          if (!curvb.test.ate || curvb.test.atst > 0)          if (!curvb.test.ate || curvb.test.atst > 0)
1255          {          {
1256                  DRAW();                  Draw(curvb);
1257          }          }
1258    
1259          GL_REPORT_ERRORD();          GL_REPORT_ERRORD();
# Line 1269  inline void AlphaPabe(VB& curvb, FRAGMEN Line 1278  inline void AlphaPabe(VB& curvb, FRAGMEN
1278    
1279                  ZZcgSetParameter4fv(pfragment->sOneColor, v, "g_fOneColor");                  ZZcgSetParameter4fv(pfragment->sOneColor, v, "g_fOneColor");
1280    
1281                  DRAW();                  Draw(curvb);
1282    
1283                  // reset                  // reset
1284                  if (!s_stencilmask) s_stencilfunc = GL_ALWAYS;                  if (!s_stencilmask) s_stencilfunc = GL_ALWAYS;
# Line 1284  inline void AlphaPabe(VB& curvb, FRAGMEN Line 1293  inline void AlphaPabe(VB& curvb, FRAGMEN
1293  // First three cases are trivial manual.  // First three cases are trivial manual.
1294  inline bool AlphaFailureIgnore(const pixTest curtest)  inline bool AlphaFailureIgnore(const pixTest curtest)
1295  {  {
1296          if (!curtest.ate) return true;          if ((!curtest.ate) || (curtest.atst == 1) || (curtest.afail == 0)) return true;
         if (curtest.atst == 1) return true;  
         if (curtest.afail == 0) return true;  
1297    
1298          if (g_GameSettings & GAME_NOALPHAFAIL && ((s_dwColorWrite < 8) || (s_dwColorWrite == 15 && curtest.atst == 5 && (curtest.aref == 64))))          if (conf.settings().no_alpha_fail && ((s_dwColorWrite < 8) || (s_dwColorWrite == 15 && curtest.atst == 5 && (curtest.aref == 64))))
1299                  return true;                  return true;
1300    
1301  //      old and seemingly incorrect code.  //      old and seemingly incorrect code.
1302  //      if ((s_dwColorWrite < 8 && s_dwColorWrite !=8) && curtest.afail == 1)  //      if ((s_dwColorWrite < 8 && s_dwColorWrite !=8) && curtest.afail == 1)
1303  //              return true;  //              return true;
1304  //      if ((s_dwColorWrite == 0xf) && curtest.atst == 5 && curtest.afail == 1 && !(g_GameSettings & GAME_REGETHACK))  //      if ((s_dwColorWrite == 0xf) && curtest.atst == 5 && curtest.afail == 1 && !(conf.settings() & GAME_REGETHACK))
1305  //              return true;  //              return true;
1306          return false;          return false;
1307  }  }
# Line 1344  inline void AlphaFailureTestJob(VB& curv Line 1351  inline void AlphaFailureTestJob(VB& curv
1351                  GL_STENCILFUNC(GL_EQUAL, s_stencilref | STENCIL_FBA, s_stencilmask | STENCIL_FBA);                  GL_STENCILFUNC(GL_EQUAL, s_stencilref | STENCIL_FBA, s_stencilmask | STENCIL_FBA);
1352          }          }
1353    
1354          DRAW();          Draw(curvb);
1355    
1356          GL_REPORT_ERRORD();          GL_REPORT_ERRORD();
1357    
# Line 1364  inline void AlphaFailureTestJob(VB& curv Line 1371  inline void AlphaFailureTestJob(VB& curv
1371    
1372                  ZZcgSetParameter4fv(pfragment->sOneColor, v, "g_fOneColor");                  ZZcgSetParameter4fv(pfragment->sOneColor, v, "g_fOneColor");
1373    
1374                  DRAW();                  Draw(curvb);
1375    
1376                  // reset                  // reset
1377                  if (oldabe) glEnable(GL_BLEND);                  if (oldabe) glEnable(GL_BLEND);
# Line 1415  inline void AlphaSpecialTesting(VB& curv Line 1422  inline void AlphaSpecialTesting(VB& curv
1422    
1423                  Vector v = Vector(0, exactcolor ? 510.0f : 2.0f, 0, 0);                  Vector v = Vector(0, exactcolor ? 510.0f : 2.0f, 0, 0);
1424                  ZZcgSetParameter4fv(pfragment->sOneColor, v, "g_fOneColor");                  ZZcgSetParameter4fv(pfragment->sOneColor, v, "g_fOneColor");
1425                  DRAW();                  Draw(curvb);
1426    
1427                  // don't need to restore                  // don't need to restore
1428          }          }
# Line 1474  inline void AlphaSaveTarget(VB& curvb) Line 1481  inline void AlphaSaveTarget(VB& curvb)
1481  inline void AlphaColorClamping(VB& curvb, const pixTest curtest)  inline void AlphaColorClamping(VB& curvb, const pixTest curtest)
1482  {  {
1483          // clamp the final colors, when enabled ffx2 credits mess up          // clamp the final colors, when enabled ffx2 credits mess up
1484          if (curvb.curprim.abe && bAlphaClamping && GetRenderFormat() != RFT_byte8 && !(g_GameSettings&GAME_NOCOLORCLAMP))   // if !colclamp, skip          //if (gs.colclamp) ZZLog::Error_Log("ColClamp!");
1485            if ((curvb.curprim.abe && bAlphaClamping) && (GetRenderFormat() != RFT_byte8) && !(conf.settings().no_color_clamp))   // if !colclamp, skip
1486          {          {
1487                    //ZZLog::Error_Log("Clamped.");
1488                  ResetAlphaVariables();                  ResetAlphaVariables();
1489    
1490                  // if processing the clamping case, make sure can write to the front buffer                  // if processing the clamping case, make sure can write to the front buffer
# Line 1500  inline void AlphaColorClamping(VB& curvb Line 1509  inline void AlphaColorClamping(VB& curvb
1509                          f = 0;                          f = 0;
1510                          ZZcgSetParameter4fv(ppsOne.sOneColor, &f, "g_fOneColor");                          ZZcgSetParameter4fv(ppsOne.sOneColor, &f, "g_fOneColor");
1511                          GL_BLENDEQ_RGB(GL_MAX_EXT);                          GL_BLENDEQ_RGB(GL_MAX_EXT);
1512                          DRAW();                          Draw(curvb);
1513                  }                  }
1514    
1515                  // bios shows white screen                  // bios shows white screen
# Line 1509  inline void AlphaColorClamping(VB& curvb Line 1518  inline void AlphaColorClamping(VB& curvb
1518                          f = 1;                          f = 1;
1519                          ZZcgSetParameter4fv(ppsOne.sOneColor, &f, "g_fOneColor");                          ZZcgSetParameter4fv(ppsOne.sOneColor, &f, "g_fOneColor");
1520                          GL_BLENDEQ_RGB(GL_MIN_EXT);                          GL_BLENDEQ_RGB(GL_MIN_EXT);
1521                          DRAW();                          Draw(curvb);
1522                  }                  }
1523    
1524                  if (!curvb.zbuf.zmsk)                  if (!curvb.zbuf.zmsk)
# Line 1557  void ZeroGS::Flush(int context) Line 1566  void ZeroGS::Flush(int context)
1566          SwitchWireframeOff();          SwitchWireframeOff();
1567          FlushDoContextJob(curvb, context);          FlushDoContextJob(curvb, context);
1568    
1569          u32 dwUsingSpecialTesting = 0;          u32 dwUsingSpecialTesting = 0, dwFilterOpts = 0;
         u32 dwFilterOpts = 0;  
1570          int exactcolor = FlushGetExactcolor(curtest);          int exactcolor = FlushGetExactcolor(curtest);
1571    
1572          FRAGMENTSHADER* pfragment = FlushRendererStage(curvb, dwFilterOpts, ptextarg, exactcolor, context);          FRAGMENTSHADER* pfragment = FlushRendererStage(curvb, dwFilterOpts, ptextarg, exactcolor, context);
# Line 1600  void ZeroGS::Flush(int context) Line 1608  void ZeroGS::Flush(int context)
1608          GL_REPORT_ERRORD();          GL_REPORT_ERRORD();
1609  }  }
1610    
1611    void ZeroGS::FlushBoth()
1612    {
1613            Flush(0);
1614            Flush(1);
1615    }
1616    
1617  inline void ZeroGS::RenderFBA(const VB& curvb, CGparameter sOneColor)  inline void ZeroGS::RenderFBA(const VB& curvb, CGparameter sOneColor)
1618  {  {
1619          // add fba to all pixels          // add fba to all pixels
# Line 1623  inline void ZeroGS::RenderFBA(const VB& Line 1637  inline void ZeroGS::RenderFBA(const VB&
1637    
1638          ZZcgSetParameter4fv(sOneColor, v, "g_fOneColor");          ZZcgSetParameter4fv(sOneColor, v, "g_fOneColor");
1639    
1640          DRAW();          Draw(curvb);
1641    
1642          SetAlphaTest(curvb.test);          SetAlphaTest(curvb.test);
1643    
# Line 1676  __forceinline void ZeroGS::RenderAlphaTe Line 1690  __forceinline void ZeroGS::RenderAlphaTe
1690                  glStencilMask(STENCIL_CLEAR);                  glStencilMask(STENCIL_CLEAR);
1691                  glDisable(GL_ALPHA_TEST);                  glDisable(GL_ALPHA_TEST);
1692                  GL_STENCILFUNC_SET();                  GL_STENCILFUNC_SET();
1693                  DRAW();                  Draw(curvb);
1694    
1695                  if (curvb.test.ate && curvb.test.afail != 1 && USEALPHATESTING) glEnable(GL_ALPHA_TEST);                  if (curvb.test.ate && curvb.test.afail != 1 && USEALPHATESTING) glEnable(GL_ALPHA_TEST);
1696          }          }
# Line 1694  __forceinline void ZeroGS::RenderAlphaTe Line 1708  __forceinline void ZeroGS::RenderAlphaTe
1708          GL_STENCILFUNC_SET();          GL_STENCILFUNC_SET();
1709          glDisable(GL_DEPTH_TEST);          glDisable(GL_DEPTH_TEST);
1710    
1711          DRAW();          Draw(curvb);
1712    
1713          if (curvb.test.zte) glEnable(GL_DEPTH_TEST);          if (curvb.test.zte) glEnable(GL_DEPTH_TEST);
1714    
# Line 1749  inline void ZeroGS::ProcessStencil(const Line 1763  inline void ZeroGS::ProcessStencil(const
1763          SetShaderCaller("ProcessStencil");          SetShaderCaller("ProcessStencil");
1764    
1765          SETPIXELSHADER(ppsOne.prog);          SETPIXELSHADER(ppsOne.prog);
1766          DRAW();          Draw(curvb);
1767    
1768          // process when alpha >= 0xff          // process when alpha >= 0xff
1769          GL_STENCILFUNC(GL_EQUAL, STENCIL_PIXELWRITE | STENCIL_FBA | STENCIL_ALPHABIT, STENCIL_PIXELWRITE | STENCIL_FBA);          GL_STENCILFUNC(GL_EQUAL, STENCIL_PIXELWRITE | STENCIL_FBA | STENCIL_ALPHABIT, STENCIL_PIXELWRITE | STENCIL_FBA);
1770          DRAW();          Draw(curvb);
1771    
1772          // clear STENCIL_PIXELWRITE bit          // clear STENCIL_PIXELWRITE bit
1773          glStencilMask(STENCIL_CLEAR);          glStencilMask(STENCIL_CLEAR);
1774    
1775          GL_STENCILFUNC(GL_ALWAYS, 0, STENCIL_PIXELWRITE | STENCIL_FBA);          GL_STENCILFUNC(GL_ALWAYS, 0, STENCIL_PIXELWRITE | STENCIL_FBA);
1776          DRAW();          Draw(curvb);
1777    
1778          // restore state          // restore state
1779          GL_COLORMASK(s_dwColorWrite);          GL_COLORMASK(s_dwColorWrite);
# Line 1810  __forceinline void ZeroGS::ProcessFBA(co Line 1824  __forceinline void ZeroGS::ProcessFBA(co
1824          float f = 1;          float f = 1;
1825          ZZcgSetParameter4fv(sOneColor, &f, "g_fOneColor");          ZZcgSetParameter4fv(sOneColor, &f, "g_fOneColor");
1826          SETPIXELSHADER(ppsOne.prog);          SETPIXELSHADER(ppsOne.prog);
1827          DRAW();          Draw(curvb);
1828          glDisable(GL_ALPHA_TEST);          glDisable(GL_ALPHA_TEST);
1829    
1830          // reset bits          // reset bits
1831          glStencilMask(STENCIL_CLEAR);          glStencilMask(STENCIL_CLEAR);
1832          GL_STENCILFUNC(GL_GREATER, 0, STENCIL_PIXELWRITE | STENCIL_FBA);          GL_STENCILFUNC(GL_GREATER, 0, STENCIL_PIXELWRITE | STENCIL_FBA);
1833          glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);          glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
1834          DRAW();          Draw(curvb);
1835    
1836          if (curvb.test.atst && USEALPHATESTING)          if (curvb.test.atst && USEALPHATESTING)
1837          {          {
# Line 1867  void ZeroGS::SetContextTarget(int contex Line 1881  void ZeroGS::SetContextTarget(int contex
1881    
1882          assert(curvb.prndr != NULL && curvb.pdepth != NULL);          assert(curvb.prndr != NULL && curvb.pdepth != NULL);
1883    
1884          assert(curvb.pdepth->fbh == curvb.prndr->fbh);          if (curvb.pdepth->fbh != curvb.prndr->fbh) ZZLog::Debug_Log("(curvb.pdepth->fbh(0x%x) != curvb.prndr->fbh(0x%x))", curvb.pdepth->fbh, curvb.prndr->fbh);
1885            //assert(curvb.pdepth->fbh == curvb.prndr->fbh);
1886    
1887          if (curvb.pdepth->status & CRenderTarget::TS_Virtual)          if (curvb.pdepth->status & CRenderTarget::TS_Virtual)
1888          {          {
# Line 1933  void ZeroGS::SetContextTarget(int contex Line 1948  void ZeroGS::SetContextTarget(int contex
1948    
1949          if (vb[!context].prndr != curvb.prndr) vb[!context].bVarsSetTarg = false;          if (vb[!context].prndr != curvb.prndr) vb[!context].bVarsSetTarg = false;
1950    
1951          assert(!(curvb.prndr->status&CRenderTarget::TS_NeedUpdate));  #ifdef _DEBUG
1952          assert(curvb.pdepth == NULL || !(curvb.pdepth->status&CRenderTarget::TS_NeedUpdate));          // These conditions happen often enough that we'll just warn about it rather then abort in Debug mode.
1953            if (curvb.prndr->status & CRenderTarget::TS_NeedUpdate)
1954            {
1955                    ZZLog::Debug_Log("In SetContextTarget, prndr is ending with TS_NeedUpdate set.");
1956            }
1957            
1958            if (curvb.pdepth != NULL && (curvb.pdepth->status & CRenderTarget::TS_NeedUpdate))
1959            {
1960                    ZZLog::Debug_Log("In SetContextTarget, pdepth is ending with TS_NeedUpdate set.");
1961            }
1962    #endif
1963    
1964          GL_REPORT_ERRORD();          GL_REPORT_ERRORD();
1965  }  }
# Line 2006  void ZeroGS::SetTexClamping(int context, Line 2031  void ZeroGS::SetTexClamping(int context,
2031    
2032                  case 3: // region rep x                  case 3: // region rep x
2033                          v.x = 0.9999f;                          v.x = 0.9999f;
2034                          v.z = fw;                          v.z = (float)fw;
2035                          v2.x = (float)GPU_TEXMASKWIDTH / fw;                          v2.x = (float)GPU_TEXMASKWIDTH / fw;
2036                          v2.z = pclamp->maxu / fw;                          v2.z = pclamp->maxu / fw;
2037                          int correctMinu = pclamp->minu & (~pclamp->maxu);               // (A && B) || C == (A && (B && !C)) + C                          int correctMinu = pclamp->minu & (~pclamp->maxu);               // (A && B) || C == (A && (B && !C)) + C
# Line 2041  void ZeroGS::SetTexClamping(int context, Line 2066  void ZeroGS::SetTexClamping(int context,
2066    
2067                  case 3: // region rep y                  case 3: // region rep y
2068                          v.y = 0.9999f;                          v.y = 0.9999f;
2069                          v.w = fh;                          v.w = (float)fh;
2070                          v2.y = (float)GPU_TEXMASKWIDTH / fh;                          v2.y = (float)GPU_TEXMASKWIDTH / fh;
2071                          v2.w = pclamp->maxv / fh;                          v2.w = pclamp->maxv / fh;
2072                          int correctMinv = pclamp->minv & (~pclamp->maxv);               // (A && B) || C == (A && (B && !C)) + C                          int correctMinv = pclamp->minv & (~pclamp->maxv);               // (A && B) || C == (A && (B && !C)) + C
# Line 2396  void ZeroGS::SetTexVariablesInt(int cont Line 2421  void ZeroGS::SetTexVariablesInt(int cont
2421                  break; \                  break; \
2422                  \                  \
2423                  case 2: \                  case 2: \
2424                          bNeedBlendFactorInAlpha = 1; /* should disable alpha channel writing */ \                          bNeedBlendFactorInAlpha = true; /* should disable alpha channel writing */ \
2425                          vAlphaBlendColor.y = 0; \                          vAlphaBlendColor.y = 0; \
2426                          vAlphaBlendColor.w = (sign) ? (float)a.fix * (2.0f/255.0f) : (float)a.fix * (-2.0f/255.0f); \                          vAlphaBlendColor.w = (sign) ? (float)a.fix * (2.0f/255.0f) : (float)a.fix * (-2.0f/255.0f); \
2427                          usec = 0; /* change so that alpha comes from source*/ \                          usec = 0; /* change so that alpha comes from source*/ \
# Line 2420  inline void ZeroGS::NeedFactor(int w) Line 2445  inline void ZeroGS::NeedFactor(int w)
2445  {  {
2446          if (bDestAlphaColor == 2)          if (bDestAlphaColor == 2)
2447          {          {
2448                  bNeedBlendFactorInAlpha = (w + 1) ? 1 : 0;                  bNeedBlendFactorInAlpha = (w + 1) ? true : false;
2449                  vAlphaBlendColor.y = 0;                  vAlphaBlendColor.y = 0;
2450                  vAlphaBlendColor.w = (float)w;                  vAlphaBlendColor.w = (float)w;
2451          }          }
# Line 2435  void ZeroGS::SetAlphaVariables(const alp Line 2460  void ZeroGS::SetAlphaVariables(const alp
2460    
2461          // TODO: negative color when not clamping turns to positive???          // TODO: negative color when not clamping turns to positive???
2462          g_vars._bAlphaState = 0; // set all to zero          g_vars._bAlphaState = 0; // set all to zero
2463          bNeedBlendFactorInAlpha = 0;          bNeedBlendFactorInAlpha = false;
2464          b2XAlphaTest = 1;          b2XAlphaTest = 1;
2465          //u32 dwTemp = 0xffffffff;          //u32 dwTemp = 0xffffffff;
2466          bDestAlphaColor = 0;          bDestAlphaColor = 0;
# Line 2446  void ZeroGS::SetAlphaVariables(const alp Line 2471  void ZeroGS::SetAlphaVariables(const alp
2471          s_alphaeq = GL_FUNC_ADD;          s_alphaeq = GL_FUNC_ADD;
2472          s_rgbeq = 1;          s_rgbeq = 1;
2473    
2474          s_alphaInfo = a;  //      s_alphaInfo = a;
2475          vAlphaBlendColor = Vector(1, 2 * 255.0f / 256.0f, 0, 0);          vAlphaBlendColor = Vector(1, 2 * 255.0f / 256.0f, 0, 0);
2476          u32 usec = a.c;          u32 usec = a.c;
2477    

Legend:
Removed from v.31  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22