2010-03-19 00:31:15 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
2010-07-10 08:20:50 +00:00
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 00:31:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 00:31:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Realisation of RenderCRTC function ONLY.
|
2010-04-25 00:31:27 +00:00
|
|
|
// It draw picture direct on screen, so here we have interlacing and frame skipping.
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//------------------ Includes
|
2010-06-27 00:53:06 +00:00
|
|
|
#include "ZZoglCRTC.h"
|
2010-09-01 10:28:37 +00:00
|
|
|
#include "GLWin.h"
|
2010-09-15 16:54:19 +00:00
|
|
|
#include "ZZoglShaders.h"
|
2010-10-17 09:07:16 +00:00
|
|
|
#include "ZZoglShoots.h"
|
2010-10-18 11:24:40 +00:00
|
|
|
#include "ZZKick.h"
|
2010-10-17 08:47:31 +00:00
|
|
|
#include "rasterfont.h" // simple font
|
2010-10-18 11:24:40 +00:00
|
|
|
#include <math.h>
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//------------------ Defines
|
2010-04-25 09:02:36 +00:00
|
|
|
#if !defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
#define g_bSaveFrame 0
|
|
|
|
#define g_bSaveFinalFrame 0
|
2010-05-01 20:33:53 +00:00
|
|
|
#else
|
2010-05-01 23:34:44 +00:00
|
|
|
bool g_bSaveFrame = 0; // saves the current psurfTarget
|
|
|
|
bool g_bSaveFinalFrame = 0; // saves the input to the CRTC
|
2010-04-25 09:02:36 +00:00
|
|
|
#endif // !defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-03 07:57:56 +00:00
|
|
|
extern int maxmin;
|
|
|
|
extern bool g_bCRTCBilinear;
|
|
|
|
bool g_bDisplayFPS = false;
|
2010-06-27 00:53:06 +00:00
|
|
|
int g_nFrameRender = 10, g_nFramesSkipped = 0, s_nResolved = 0; // s_nResolved == number of targets resolved this frame
|
|
|
|
// Helper for skip frames.
|
|
|
|
int TimeLastSkip = 0;
|
2010-07-03 07:57:56 +00:00
|
|
|
|
|
|
|
vector<u32> s_vecTempTextures; // temporary textures, released at the end of every frame
|
|
|
|
|
|
|
|
// Snapshot variables.
|
2010-07-02 12:10:40 +00:00
|
|
|
extern bool g_bMakeSnapshot;
|
2010-07-03 07:57:56 +00:00
|
|
|
extern string strSnapshot;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-18 11:24:40 +00:00
|
|
|
extern void ExtWrite();
|
|
|
|
extern void ZZDestroy();
|
|
|
|
extern void ChangeDeviceSize(int nNewWidth, int nNewHeight);
|
|
|
|
|
|
|
|
extern GLuint vboRect;
|
2010-03-19 00:31:15 +00:00
|
|
|
// Adjusts vertex shader BitBltPos vector v to preserve aspect ratio. It used to emulate 4:3 or 16:9.
|
2010-10-16 11:54:46 +00:00
|
|
|
void AdjustTransToAspect(float4& v)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
double temp;
|
|
|
|
float f;
|
2010-09-20 13:03:40 +00:00
|
|
|
const float mult = 1 / 32767.0f;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
if (conf.width * nBackbufferHeight > conf.height * nBackbufferWidth) // limited by width
|
2010-04-24 23:22:49 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// change in ratio
|
2010-04-24 23:22:49 +00:00
|
|
|
f = ((float)nBackbufferWidth / (float)conf.width) / ((float)nBackbufferHeight / (float)conf.height);
|
2010-03-19 00:31:15 +00:00
|
|
|
v.y *= f;
|
|
|
|
v.w *= f;
|
|
|
|
|
|
|
|
// scanlines mess up when not aligned right
|
2010-05-01 20:33:53 +00:00
|
|
|
v.y += (1 - (float)modf(v.y * (float)nBackbufferHeight * 0.5f + 0.05f, &temp)) * 2.0f / (float)nBackbufferHeight;
|
|
|
|
v.w += (1 - (float)modf(v.w * (float)nBackbufferHeight * 0.5f + 0.05f, &temp)) * 2.0f / (float)nBackbufferHeight;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-06-27 00:53:06 +00:00
|
|
|
else // limited by height
|
2010-04-24 23:22:49 +00:00
|
|
|
{
|
|
|
|
f = ((float)nBackbufferHeight / (float)conf.height) / ((float)nBackbufferWidth / (float)conf.width);
|
2010-05-01 20:33:53 +00:00
|
|
|
f -= (float)modf(f * nBackbufferWidth, &temp) / (float)nBackbufferWidth;
|
2010-03-19 00:31:15 +00:00
|
|
|
v.x *= f;
|
|
|
|
v.z *= f;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-09-20 13:03:40 +00:00
|
|
|
v *= mult;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
inline bool FrameSkippingHelper()
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
bool ShouldSkip = false;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (g_nFrameRender > 0)
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_nFrameRender < 8)
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFrameRender++;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (g_nFrameRender <= 3)
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFramesSkipped++;
|
|
|
|
ShouldSkip = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_nFrameRender < -1)
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFramesSkipped++;
|
|
|
|
ShouldSkip = true;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFrameRender--;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#if defined _DEBUG
|
2010-05-01 20:33:53 +00:00
|
|
|
if (timeGetTime() - TimeLastSkip > 15000 && ShouldSkip)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Debug_Log("ZZogl Skipped frames.");
|
2010-03-19 00:31:15 +00:00
|
|
|
TimeLastSkip = timeGetTime();
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
#endif
|
2010-06-27 00:53:06 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return ShouldSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function for save frame in picture.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void FrameSavingHelper()
|
|
|
|
{
|
|
|
|
if (g_bSaveFrame)
|
|
|
|
{
|
|
|
|
if (vb[0].prndr != NULL)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SaveTexture("frame1.tga", GL_TEXTURE_RECTANGLE_NV, vb[0].prndr->ptex, RW(vb[0].prndr->fbw), RH(vb[0].prndr->fbh));
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (vb[1].prndr != NULL && vb[0].prndr != vb[1].prndr)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SaveTexture("frame2.tga", GL_TEXTURE_RECTANGLE_NV, vb[1].prndr->ptex, RW(vb[1].prndr->fbw), RH(vb[1].prndr->fbh));
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#ifdef _WIN32
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DeleteFile("frame2.tga");
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function populated tex0Info[2] array
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void FrameObtainDispinfo(u32 bInterlace, tex0Info* dispinfo)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!(*(u32*)(PMODE) & (1 << i)))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
dispinfo[i].tw = 0;
|
|
|
|
dispinfo[i].th = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GSRegDISPFB* pfb = i ? DISPFB2 : DISPFB1;
|
|
|
|
GSRegDISPLAY* pd = i ? DISPLAY2 : DISPLAY1;
|
2010-05-01 20:33:53 +00:00
|
|
|
int magh = pd->MAGH + 1;
|
|
|
|
int magv = pd->MAGV + 1;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
dispinfo[i].tbp0 = pfb->FBP << 5;
|
|
|
|
dispinfo[i].tbw = pfb->FBW << 6;
|
|
|
|
dispinfo[i].tw = (pd->DW + 1) / magh;
|
|
|
|
dispinfo[i].th = (pd->DH + 1) / magv;
|
|
|
|
dispinfo[i].psm = pfb->PSM;
|
|
|
|
|
|
|
|
// hack!!
|
|
|
|
// 2 * dispinfo[i].tw / dispinfo[i].th <= 1, metal slug 4
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
if (bInterlace && 2 * dispinfo[i].tw / dispinfo[i].th <= 1 && !(conf.settings().interlace_2x))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
dispinfo[i].th >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 11:24:40 +00:00
|
|
|
extern bool s_bWriteDepth;
|
|
|
|
|
2010-07-26 10:51:06 +00:00
|
|
|
// Something should be done before Renderering the picture.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void RenderStartHelper(u32 bInterlace)
|
|
|
|
{
|
|
|
|
if (conf.mrtdepth && pvs[8] == NULL)
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.mrtdepth = 0;
|
2010-05-01 23:34:44 +00:00
|
|
|
s_bWriteDepth = false;
|
2010-04-25 08:33:05 +00:00
|
|
|
|
|
|
|
ZZLog::Debug_Log("Disabling MRT depth writing\n");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 05:41:06 +00:00
|
|
|
FlushBoth();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
FrameSavingHelper();
|
|
|
|
|
2010-06-19 05:41:06 +00:00
|
|
|
if (s_RangeMngr.ranges.size() > 0) FlushTransferRanges(NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
SetShaderCaller("RenderStartHelper");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// reset fba after every frame
|
|
|
|
vb[0].fba.fba = 0;
|
|
|
|
vb[1].fba.fba = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the backbuffer
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glViewport(0, 0, nBackbufferWidth, nBackbufferHeight);
|
|
|
|
|
|
|
|
// if interlace, only clear every other vsync
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!bInterlace)
|
2010-03-19 06:38:44 +00:00
|
|
|
{
|
|
|
|
//u32 color = COLOR_ARGB(0, BGCOLOR->R, BGCOLOR->G, BGCOLOR->B);
|
2010-05-01 20:33:53 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
ZZshSetVertexShader(pvsBitBlt.prog);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vboRect);
|
|
|
|
SET_STREAM();
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-19 05:41:06 +00:00
|
|
|
DisableAllgl();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (bInterlace) g_PrevBitwiseTexX = -1; // reset since will be using
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-07-26 10:51:06 +00:00
|
|
|
// Settings for interlace texture multiplied vector;
|
|
|
|
// The idea is: (x, y) -- position on screen, then interlaced texture get F = 1 or 0 depending
|
|
|
|
// on image y coords. So if we write valpha.z * F + valpha.w + 0.5, it would be switching odd
|
|
|
|
// and even strings at each frame.
|
|
|
|
// valpha.x and y are used for image blending.
|
2010-09-19 08:01:48 +00:00
|
|
|
inline float4 RenderGetForClip(u32 bInterlace, int interlace, int psm, FRAGMENTSHADER* prog)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderGetForClip");
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 valpha;
|
2010-03-19 00:31:15 +00:00
|
|
|
// first render the current render targets, then from ptexMem
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (psm == 1)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
valpha.x = 1;
|
|
|
|
valpha.y = 0;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
valpha.x = 0;
|
|
|
|
valpha.y = 1;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (bInterlace)
|
|
|
|
{
|
2010-07-26 10:51:06 +00:00
|
|
|
if (interlace == (conf.interlace & 1))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// pass if odd
|
|
|
|
valpha.z = 1.0f;
|
|
|
|
valpha.w = -0.4999f;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// pass if even
|
|
|
|
valpha.z = -1.0f;
|
|
|
|
valpha.w = 0.5001f;
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// always pass interlace test
|
|
|
|
valpha.z = 0;
|
|
|
|
valpha.w = 1;
|
|
|
|
}
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshSetParameter4fv(prog->prog, prog->sOneColor, valpha, "g_fOneColor");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return valpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put interlaced texture in use for shader prog.
|
|
|
|
// Note: if frame interlaced it's th is halved, so we should x2 it.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void RenderCreateInterlaceTex(u32 bInterlace, int th, FRAGMENTSHADER* prog)
|
|
|
|
{
|
2010-06-27 00:53:06 +00:00
|
|
|
if (!bInterlace) return;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
int interlacetex = CreateInterlaceTex(2 * th);
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshGLSetTextureParameter(prog->prog, prog->sInterlace, interlacetex, "Interlace");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Well, do blending setup prior to second pass of half-frame drawing
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void RenderSetupBlending()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// setup right blending
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
zgsBlendEquationSeparateEXT(GL_FUNC_ADD, GL_FUNC_ADD);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (PMODE->MMOD)
|
|
|
|
{
|
|
|
|
glBlendColorEXT(PMODE->ALP*(1 / 255.0f), PMODE->ALP*(1 / 255.0f), PMODE->ALP*(1 / 255.0f), 0.5f);
|
2010-03-19 00:31:15 +00:00
|
|
|
s_srcrgb = GL_CONSTANT_COLOR_EXT;
|
|
|
|
s_dstrgb = GL_ONE_MINUS_CONSTANT_COLOR_EXT;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
s_srcrgb = GL_SRC_ALPHA;
|
|
|
|
s_dstrgb = GL_ONE_MINUS_SRC_ALPHA;
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
if (PMODE->AMOD)
|
|
|
|
{
|
|
|
|
s_srcalpha = GL_ZERO;
|
|
|
|
s_dstalpha = GL_ONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_srcalpha = GL_ONE;
|
|
|
|
s_dstalpha = GL_ZERO;
|
|
|
|
}
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
zgsBlendFuncSeparateEXT(s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha);
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
// each frame could be drawn in two stages, so blending should be different for them
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void RenderSetupStencil(int i)
|
|
|
|
{
|
|
|
|
glStencilMask(1 << i);
|
|
|
|
s_stencilmask = 1 << i;
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_STENCILFUNC_SET();
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
// do stencil check for each found target i -- texturing stage
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void RenderUpdateStencil(int i, bool* bUsingStencil)
|
|
|
|
{
|
2010-06-27 00:53:06 +00:00
|
|
|
if (!(*bUsingStencil)) glClear(GL_STENCIL_BUFFER_BIT);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
*bUsingStencil = 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glEnable(GL_STENCIL_TEST);
|
2010-05-01 20:33:53 +00:00
|
|
|
GL_STENCILFUNC(GL_NOTEQUAL, 3, 1 << i);
|
2010-03-19 00:31:15 +00:00
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
2010-05-01 20:33:53 +00:00
|
|
|
glStencilMask(1 << i);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// CRTC24 could not be rendered
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void RenderCRTC24helper(u32 bInterlace, int interlace, int psm)
|
|
|
|
{
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::Debug_Log("ZZogl: CRTC24!!! I'm trying to show something.");
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderCRTC24helper");
|
|
|
|
// assume that data is already in ptexMem (do Resolve?)
|
|
|
|
RenderGetForClip(bInterlace, interlace, psm, &ppsCRTC24[bInterlace]);
|
2010-09-15 16:54:19 +00:00
|
|
|
ZZshSetPixelShader(ppsCRTC24[bInterlace].prog);
|
2010-06-19 05:41:06 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
DrawTriangleArray();
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe I do this function global-defined. Calculate bits per pixel for
|
2010-06-19 05:41:06 +00:00
|
|
|
// each psm. It's the only place with PSMCT16 which have a different bpp.
|
2010-03-19 00:31:15 +00:00
|
|
|
// FIXME: check PSMCT16S
|
2010-05-01 20:33:53 +00:00
|
|
|
inline int RenderGetBpp(int psm)
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (psm == PSMCT16S)
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
2010-06-27 00:53:06 +00:00
|
|
|
//ZZLog::Debug_Log("ZZogl: 16S target.");
|
2010-03-19 00:31:15 +00:00
|
|
|
return 3;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
if (PSMT_ISHALF(psm)) return 2;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to draw ptarg on screen, that could be disaligned to viewport.
|
|
|
|
// So we do aligning it by height.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline int RenderGetOffsets(int* dby, int* movy, tex0Info& texframe, CRenderTarget* ptarg, int bpp)
|
|
|
|
{
|
|
|
|
*dby += (256 / bpp) * (texframe.tbp0 - ptarg->fbp) / texframe.tbw;
|
|
|
|
|
|
|
|
if (*dby < 0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
*movy = -*dby;
|
|
|
|
*dby = 0;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return min(ptarg->fbh - *dby, texframe.th - *movy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BltBit shader calculate vertex (4 coord's pixel) position at the viewport.
|
2010-09-19 08:01:48 +00:00
|
|
|
inline float4 RenderSetTargetBitPos(int dh, int th, int movy, bool isInterlace)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderSetTargetBitPos");
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v;
|
2010-03-19 00:31:15 +00:00
|
|
|
// dest rect
|
|
|
|
v.x = 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
v.y = dh / (float)th;
|
2010-03-19 00:31:15 +00:00
|
|
|
v.z = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
v.w = 1 - v.y;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (movy > 0) v.w -= movy / (float)th;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
AdjustTransToAspect(v);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (isInterlace)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// move down by 1 pixel
|
|
|
|
v.w += 1.0f / (float)dh ;
|
|
|
|
}
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltPos, v, "g_fBitBltPos");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
// Important stuff. We could use these coordinates to change viewport position on the frame.
|
|
|
|
// For example, use tw / X and tw / X magnify the viewport.
|
|
|
|
// Interlaced output is little out of VB, it could be seen as an evil blinking line on top
|
|
|
|
// and bottom, so we try to remove it.
|
2010-09-19 08:01:48 +00:00
|
|
|
inline float4 RenderSetTargetBitTex(float th, float tw, float dh, float dw, bool isInterlace)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderSetTargetBitTex");
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v;
|
|
|
|
v = float4(th, tw, dh, dw);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
// Incorrect Aspect ratio on interlaced frames
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (isInterlace)
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
v.y -= 1.0f / conf.height;
|
|
|
|
v.w += 1.0f / conf.height;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2010-07-26 10:51:06 +00:00
|
|
|
// Translator for POSITION coordinates (-1.0:+1.0f at x axis, +1.0f:-1.0y at y) into target frame ones.
|
|
|
|
// We don't need x coordinate, because interlacing is y-axis only.
|
2010-09-19 08:01:48 +00:00
|
|
|
inline float4 RenderSetTargetBitTrans(int th)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderSetTargetBitTrans");
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v = float4(float(th), -float(th), float(th), float(th));
|
|
|
|
ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.fBitBltTrans, v, "g_fBitBltTrans");
|
2010-03-19 00:31:15 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use g_fInvTexDims to store inverse texture dims
|
|
|
|
// Seems, that Targ shader does not use it
|
2010-09-19 08:01:48 +00:00
|
|
|
inline float4 RenderSetTargetInvTex(int bInterlace, int tw, int th, FRAGMENTSHADER* prog)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderSetTargetInvTex");
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v = float4(0, 0, 0, 0);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (prog->sInvTexDims)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
v.x = 1.0f / (float)tw;
|
|
|
|
v.y = 1.0f / (float)th;
|
|
|
|
v.z = (float)0.0;
|
|
|
|
v.w = -0.5f / (float)th;
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshSetParameter4fv(prog->prog, prog->sInvTexDims, v, "g_fInvTexDims");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
// Metal Slug 5 hack (as was written). If target tbp not equal to framed fbp, than we look for a better possibility,
|
|
|
|
// Note, than after true result iterator it could not be used.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline bool RenderLookForABetterTarget(int fbp, int tbp, list<CRenderTarget*>& listTargs, list<CRenderTarget*>::iterator& it)
|
|
|
|
{
|
2010-06-27 00:53:06 +00:00
|
|
|
if (fbp == tbp) return false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// look for a better target (metal slug 5)
|
|
|
|
list<CRenderTarget*>::iterator itbetter;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (itbetter = listTargs.begin(); itbetter != listTargs.end(); ++itbetter)
|
|
|
|
{
|
|
|
|
if ((*itbetter)->fbp == tbp) break;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (itbetter != listTargs.end())
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
it = listTargs.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listTargs, int i, bool* bUsingStencil, int interlace, int bInterlace);
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// First try to draw frame from targets.
|
2010-06-27 00:53:06 +00:00
|
|
|
inline void RenderCheckForTargets(tex0Info& texframe, list<CRenderTarget*>& listTargs, int i, bool* bUsingStencil, int interlace, int bInterlace)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// get the start and end addresses of the buffer
|
|
|
|
int bpp = RenderGetBpp(texframe.psm);
|
|
|
|
GSRegDISPFB* pfb = i ? DISPFB2 : DISPFB1;
|
|
|
|
|
|
|
|
int start, end;
|
|
|
|
GetRectMemAddress(start, end, texframe.psm, 0, 0, texframe.tw, texframe.th, texframe.tbp0, texframe.tbw);
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
// We need share list of targets between functions
|
2010-03-19 00:31:15 +00:00
|
|
|
s_RTs.GetTargs(start, end, listTargs);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (list<CRenderTarget*>::iterator it = listTargs.begin(); it != listTargs.end();)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
CRenderTarget* ptarg = *it;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (ptarg->fbw == texframe.tbw && !(ptarg->status&CRenderTarget::TS_NeedUpdate) && ((256 / bpp)*(texframe.tbp0 - ptarg->fbp)) % texframe.tbw == 0)
|
|
|
|
{
|
2010-06-27 00:53:06 +00:00
|
|
|
int dby = pfb->DBY;
|
|
|
|
int movy = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (RenderLookForABetterTarget(ptarg->fbp, texframe.tbp0, listTargs, it)) continue;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_bSaveFinalFrame) SaveTexture("frame1.tga", GL_TEXTURE_RECTANGLE_NV, ptarg->ptex, RW(ptarg->fbw), RH(ptarg->fbh));
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// determine the rectangle to render
|
|
|
|
int dh = RenderGetOffsets(&dby, &movy, texframe, ptarg, bpp);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (dh >= 64)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (ptarg->fbh - dby < texframe.th - movy && !(*bUsingStencil))
|
2010-03-19 00:31:15 +00:00
|
|
|
RenderUpdateStencil(i, bUsingStencil);
|
2010-06-28 10:54:26 +00:00
|
|
|
else if (ptarg->fbh - dby > 2 * ( texframe.th - movy ))
|
|
|
|
{
|
|
|
|
// Sometimes calculated position onscreen is misaligned, ie in FFX-2 intro. In such case some part of image are out of
|
|
|
|
// border's and we should move it manually.
|
|
|
|
dby -= ((ptarg->fbh - dby) >> 2) - ((texframe.th + movy) >> 1) ;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderCheckForTargets");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// Texture
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v = RenderSetTargetBitTex((float)RW(texframe.tw), (float)RH(dh), (float)RW(pfb->DBX), (float)RH(dby), INTERLACE_COUNT);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// dest rect
|
|
|
|
v = RenderSetTargetBitPos(dh, texframe.th, movy, INTERLACE_COUNT);
|
|
|
|
v = RenderSetTargetBitTrans(ptarg->fbh);
|
2010-04-25 00:31:27 +00:00
|
|
|
v = RenderSetTargetInvTex(bInterlace, texframe.tbw, ptarg->fbh, &ppsCRTCTarg[bInterlace]) ; // FIXME. This is no use
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 valpha = RenderGetForClip(bInterlace, interlace, texframe.psm, &ppsCRTCTarg[bInterlace]);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// inside vb[0]'s target area, so render that region only
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshGLSetTextureParameter(ppsCRTCTarg[bInterlace].prog, ppsCRTCTarg[bInterlace].sFinal, ptarg->ptex, "CRTC target");
|
2010-03-19 00:31:15 +00:00
|
|
|
RenderCreateInterlaceTex(bInterlace, texframe.th, &ppsCRTCTarg[bInterlace]);
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
ZZshSetPixelShader(ppsCRTCTarg[bInterlace].prog);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
DrawTriangleArray();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
if (abs(dh - (int)texframe.th) <= 1) return;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (abs(dh - (int)ptarg->fbh) <= 1)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
it = listTargs.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
++it;
|
|
|
|
}
|
2010-06-27 00:53:06 +00:00
|
|
|
RenderCheckForMemory(texframe, listTargs, i, bUsingStencil, interlace, bInterlace);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// The same as the previous, but from memory.
|
|
|
|
// If you ever wondered why a picture from a minute ago suddenly flashes on the screen (say, in Mana Khemia),
|
|
|
|
// this is the function that does it.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listTargs, int i, bool* bUsingStencil, int interlace, int bInterlace)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 v;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (list<CRenderTarget*>::iterator it = listTargs.begin(); it != listTargs.end(); ++it)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
(*it)->Resolve();
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// context has to be 0
|
2010-09-15 16:54:19 +00:00
|
|
|
if (bInterlace >= 2) ZZLog::Error_Log("CRCR Check for memory shader fault.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
//if (!(*bUsingStencil)) RenderUpdateStencil(i, bUsingStencil);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderCheckForMemory");
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
float w1, h1, w2, h2;
|
|
|
|
if (g_bCRTCBilinear)
|
|
|
|
{
|
|
|
|
w1 = texframe.tw;
|
|
|
|
h1 = texframe.th;
|
|
|
|
w2 = -0.5f;
|
|
|
|
h2 = -0.5f;
|
2010-09-15 16:54:19 +00:00
|
|
|
SetTexVariablesInt(0, 2, texframe, false, &ppsCRTC[bInterlace], 1);
|
2010-06-27 00:53:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w1 = 1;
|
|
|
|
h1 = 1;
|
|
|
|
w2 = -0.5f / (float)texframe.tw;
|
|
|
|
h2 = -0.5f / (float)texframe.th;
|
2010-09-15 16:54:19 +00:00
|
|
|
SetTexVariablesInt(0, 0, texframe, false, &ppsCRTC[bInterlace], 1);
|
2010-06-27 00:53:06 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_bSaveFinalFrame) SaveTex(&texframe, g_bSaveFinalFrame - 1 > 0);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
// Fixme: Why is this here?
|
|
|
|
// We should probably call RenderSetTargetBitTex instead.
|
2010-06-27 00:53:06 +00:00
|
|
|
v = RenderSetTargetBitTex(w1, h1, w2, h2, INTERLACE_COUNT);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// finally render from the memory (note that the stencil buffer will keep previous regions)
|
|
|
|
v = RenderSetTargetBitPos(1, 1, 0, INTERLACE_COUNT);
|
2010-03-19 00:31:15 +00:00
|
|
|
v = RenderSetTargetBitTrans(texframe.th);
|
|
|
|
v = RenderSetTargetInvTex(bInterlace, texframe.tw, texframe.th, &ppsCRTC[bInterlace]);
|
2010-09-19 08:01:48 +00:00
|
|
|
float4 valpha = RenderGetForClip(bInterlace, interlace, texframe.psm, &ppsCRTC[bInterlace]);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshGLSetTextureParameter(ppsCRTC[bInterlace].prog, ppsCRTC[bInterlace].sMemory, vb[0].pmemtarg->ptex->tex, "CRTC memory");
|
2010-03-19 00:31:15 +00:00
|
|
|
RenderCreateInterlaceTex(bInterlace, texframe.th, &ppsCRTC[bInterlace]);
|
2010-09-15 16:54:19 +00:00
|
|
|
ZZshSetPixelShader(ppsCRTC[bInterlace].prog);
|
2010-06-19 05:41:06 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
DrawTriangleArray();
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-17 08:47:31 +00:00
|
|
|
extern RasterFont* font_p;
|
|
|
|
|
|
|
|
void DrawText(const char* pstr, int left, int top, u32 color)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
ZZshGLDisableProfile();
|
|
|
|
|
|
|
|
float4 v;
|
|
|
|
v.SetColor(color);
|
|
|
|
glColor3f(v.z, v.y, v.x);
|
|
|
|
|
|
|
|
font_p->printString(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, 0);
|
|
|
|
ZZshGLEnableProfile();
|
|
|
|
}
|
|
|
|
|
2010-06-15 11:20:52 +00:00
|
|
|
// Put FPS counter on screen (not in window title)
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRenderDisplayFPS()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
char str[64];
|
|
|
|
int left = 10, top = 15;
|
|
|
|
sprintf(str, "%.1f fps", fFPS);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
DrawText(str, left + 1, top + 1, 0xff000000);
|
2010-03-19 00:31:15 +00:00
|
|
|
DrawText(str, left, top, 0xffc0ffff);
|
|
|
|
}
|
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
// Swapping buffers, so we could use another window
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRenderSwapBuffers()
|
|
|
|
{
|
|
|
|
if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
GLWin.SwapGLBuffers();
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SnapeShoot helper
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRenderMadeSnapshoot()
|
|
|
|
{
|
2010-07-03 07:57:56 +00:00
|
|
|
|
|
|
|
if (!g_bMakeSnapshot) return;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
char str[64];
|
|
|
|
int left = 200, top = 15;
|
2010-05-01 20:33:53 +00:00
|
|
|
sprintf(str, "ZeroGS %d.%d.%d - %.1f fps %s", zgsrevision, zgsbuild, zgsminor, fFPS, s_frameskipping ? " - frameskipping" : "");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
DrawText(str, left + 1, top + 1, 0xff000000);
|
2010-03-19 00:31:15 +00:00
|
|
|
DrawText(str, left, top, 0xffc0ffff);
|
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
if (SaveRenderTarget(strSnapshot != "" ? strSnapshot.c_str() : "temp.jpg", nBackbufferWidth, -nBackbufferHeight, 0)) //(conf.options.tga_snap)?0:1) ) {
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
char str[255];
|
|
|
|
sprintf(str, "saved %s\n", strSnapshot.c_str());
|
2010-10-16 11:54:46 +00:00
|
|
|
ZZAddMessage(str, 500);
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|
2010-07-03 07:57:56 +00:00
|
|
|
|
|
|
|
g_bMakeSnapshot = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 11:24:40 +00:00
|
|
|
// call to destroy video resources
|
|
|
|
void ZZReset()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
s_RTs.ResolveAll();
|
|
|
|
s_DepthRTs.ResolveAll();
|
|
|
|
|
|
|
|
vb[0].nCount = 0;
|
|
|
|
vb[1].nCount = 0;
|
|
|
|
|
|
|
|
memset(s_nResolveCounts, 0, sizeof(s_nResolveCounts));
|
|
|
|
s_nLastResolveReset = 0;
|
|
|
|
|
|
|
|
icurctx = -1;
|
|
|
|
g_vsprog = g_psprog = 0;
|
|
|
|
|
|
|
|
ZZGSStateReset();
|
|
|
|
ZZDestroy();
|
|
|
|
clear_drawfn();
|
|
|
|
}
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// If needed reset
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRendererResizeWindow()
|
|
|
|
{
|
2010-10-16 11:54:46 +00:00
|
|
|
ZZReset();
|
2010-03-19 00:31:15 +00:00
|
|
|
ChangeDeviceSize(s_nNewWidth, s_nNewHeight);
|
|
|
|
s_nNewWidth = s_nNewHeight = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put new values on statistic variable
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRenderCountStatistics()
|
|
|
|
{
|
|
|
|
if (s_nWriteDepthCount > 0)
|
|
|
|
{
|
|
|
|
assert(conf.mrtdepth);
|
|
|
|
|
|
|
|
if (--s_nWriteDepthCount <= 0)
|
|
|
|
{
|
2010-05-01 23:34:44 +00:00
|
|
|
s_bWriteDepth = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (s_nWriteDestAlphaTest > 0)
|
|
|
|
{
|
|
|
|
if (--s_nWriteDestAlphaTest <= 0)
|
|
|
|
{
|
2010-05-01 23:34:44 +00:00
|
|
|
s_bDestAlphaTest = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_nDepthUsed > 0) --g_nDepthUsed;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
s_ClutResolve = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nDepthUpdateCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This all could be easily forefeit
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRendererUnimportantJob()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
ProcessMessages();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_bDisplayFPS) AfterRenderDisplayFPS();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
AfterRenderSwapBuffers();
|
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.wireframe())
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// clear all targets
|
|
|
|
s_nWireframeCount = 1;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_bMakeSnapshot)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
AfterRenderMadeSnapshoot();
|
2010-07-02 12:10:40 +00:00
|
|
|
g_bMakeSnapshot = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 07:57:56 +00:00
|
|
|
CaptureFrame();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
AfterRenderCountStatistics();
|
|
|
|
|
2010-08-22 09:42:28 +00:00
|
|
|
if (s_nNewWidth >= 0 && s_nNewHeight >= 0)
|
2010-03-19 00:31:15 +00:00
|
|
|
AfterRendererResizeWindow();
|
|
|
|
|
|
|
|
maxmin = 608;
|
|
|
|
}
|
|
|
|
|
2010-10-17 08:47:31 +00:00
|
|
|
extern u32 s_uFramebuffer;
|
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
// Swich Framebuffers
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRendererSwitchBackToTextures()
|
|
|
|
{
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, s_uFramebuffer);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_MemTargs.DestroyCleared();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (s_vecTempTextures.size() > 0)
|
2010-03-19 00:31:15 +00:00
|
|
|
glDeleteTextures((GLsizei)s_vecTempTextures.size(), &s_vecTempTextures[0]);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
s_vecTempTextures.clear();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (EXTWRITE->WRITE & 1)
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
|
|
|
ZZLog::Warn_Log("EXTWRITE!");
|
2010-03-19 00:31:15 +00:00
|
|
|
ExtWrite();
|
|
|
|
EXTWRITE->WRITE = 0;
|
|
|
|
}
|
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (icurctx >= 0)
|
|
|
|
{
|
2010-05-01 23:34:44 +00:00
|
|
|
vb[icurctx].bVarsSetTarg = false;
|
|
|
|
vb[icurctx].bVarsTexSync = false;
|
|
|
|
vb[0].bVarsTexSync = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset Targets Helper, for hack.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRendererAutoresetTargets()
|
|
|
|
{
|
2010-06-19 08:46:40 +00:00
|
|
|
if (conf.settings().auto_reset)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
s_nResolveCounts[s_nCurResolveIndex] = s_nResolved;
|
2010-05-01 20:33:53 +00:00
|
|
|
s_nCurResolveIndex = (s_nCurResolveIndex + 1) % ARRAY_SIZE(s_nResolveCounts);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(s_nResolveCounts); ++i) total += s_nResolveCounts[i];
|
|
|
|
|
|
|
|
if (total / ARRAY_SIZE(s_nResolveCounts) > 3)
|
|
|
|
{
|
|
|
|
if (s_nLastResolveReset > (int)(fFPS * 8))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// reset
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Video memory reset.");
|
2010-03-19 00:31:15 +00:00
|
|
|
s_nLastResolveReset = 0;
|
|
|
|
memset(s_nResolveCounts, 0, sizeof(s_nResolveCounts));
|
|
|
|
|
|
|
|
s_RTs.ResolveAll();
|
2010-05-01 20:33:53 +00:00
|
|
|
return;
|
2010-06-27 00:53:06 +00:00
|
|
|
// s_RTs.Destroy();
|
|
|
|
// s_DepthRTs.ResolveAll();
|
|
|
|
// s_DepthRTs.Destroy();
|
|
|
|
//
|
|
|
|
// vb[0].prndr = NULL;
|
|
|
|
// vb[0].pdepth = NULL;
|
|
|
|
// vb[0].bNeedFrameCheck = 1;
|
|
|
|
// vb[0].bNeedZCheck = 1;
|
|
|
|
// vb[1].prndr = NULL;
|
|
|
|
// vb[1].pdepth = NULL;
|
|
|
|
// vb[1].bNeedFrameCheck = 1;
|
|
|
|
// vb[1].bNeedZCheck = 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_nLastResolveReset++;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (s_nResolved > 8)
|
|
|
|
s_nResolved = 2;
|
|
|
|
else if (s_nResolved > 0)
|
|
|
|
--s_nResolved;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
// The main renderer function
|
2010-10-16 11:54:46 +00:00
|
|
|
void RenderCRTC(int interlace)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-08-22 09:42:28 +00:00
|
|
|
if (FrameSkippingHelper()) return;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
u32 bInterlace = SMODE2->INT && SMODE2->FFMD && (conf.interlace < 2);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
RenderStartHelper(bInterlace);
|
|
|
|
|
2010-06-27 00:53:06 +00:00
|
|
|
bool bUsingStencil = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
tex0Info dispinfo[2];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
FrameObtainDispinfo(bInterlace, dispinfo);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// start from the last circuit
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = !PMODE->SLBG; i >= 0; --i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
tex0Info& texframe = dispinfo[i];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (texframe.th <= 1) continue;
|
2010-08-22 09:42:28 +00:00
|
|
|
if (SMODE2->INT && SMODE2->FFMD)
|
|
|
|
{
|
|
|
|
texframe.th >>= 1;
|
|
|
|
|
|
|
|
// Final Fantasy X-2 issue here.
|
|
|
|
if (conf.interlace == 2 && texframe.th >= 512)
|
|
|
|
texframe.th >>= 1;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (i == 0) RenderSetupBlending();
|
|
|
|
if (bUsingStencil) RenderSetupStencil(i);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (texframe.psm == 0x12)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
RenderCRTC24helper(bInterlace, interlace, texframe.psm);
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// We shader targets between two functions, so declare it here;
|
2010-04-25 00:31:27 +00:00
|
|
|
list<CRenderTarget*> listTargs;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// if we could not draw image from target's do it from memory
|
2010-06-27 00:53:06 +00:00
|
|
|
RenderCheckForTargets(texframe, listTargs, i, &bUsingStencil, interlace, bInterlace);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glDisable(GL_BLEND);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
AfterRendererUnimportantJob();
|
|
|
|
AfterRendererSwitchBackToTextures();
|
|
|
|
AfterRendererAutoresetTargets();
|
|
|
|
}
|