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
|
2012-04-19 21:22:08 +00:00
|
|
|
#include "Util.h"
|
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-11-23 03:35:01 +00:00
|
|
|
#include "ZZoglDrawing.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-10-23 08:15:39 +00:00
|
|
|
#include "ZZoglVB.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;
|
2012-04-19 21:22:08 +00:00
|
|
|
|
|
|
|
// I'm making this variable global for the moment in the course of fiddling with the interlace code
|
|
|
|
// to try and make it more straightforward.
|
|
|
|
int interlace_mode = 0; // 0 - not interlacing, 1 - interlacing.
|
|
|
|
bool bUsingStencil = false;
|
|
|
|
|
|
|
|
bool INTERLACE_COUNT()
|
|
|
|
{
|
|
|
|
return (interlace_mode && (gs.interlace == conf.interlace));
|
|
|
|
}
|
|
|
|
|
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-11-14 01:38:10 +00:00
|
|
|
if (conf.width * GLWin.backbuffer.h > conf.height * GLWin.backbuffer.w) // limited by width
|
2010-04-24 23:22:49 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// change in ratio
|
2010-11-14 01:38:10 +00:00
|
|
|
f = ((float)GLWin.backbuffer.w / (float)conf.width) / ((float)GLWin.backbuffer.h / (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-11-14 01:38:10 +00:00
|
|
|
v.y += (1 - (float)modf(v.y * (float)GLWin.backbuffer.h * 0.5f + 0.05f, &temp)) * 2.0f / (float)GLWin.backbuffer.h;
|
|
|
|
v.w += (1 - (float)modf(v.w * (float)GLWin.backbuffer.h * 0.5f + 0.05f, &temp)) * 2.0f / (float)GLWin.backbuffer.h;
|
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
|
|
|
{
|
2010-11-14 01:38:10 +00:00
|
|
|
f = ((float)GLWin.backbuffer.h / (float)conf.height) / ((float)GLWin.backbuffer.w / (float)conf.width);
|
|
|
|
f -= (float)modf(f * GLWin.backbuffer.w, &temp) / (float)GLWin.backbuffer.w;
|
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
|
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
DeleteFile(L"frame2.tga");
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function populated tex0Info[2] array
|
2012-04-19 21:22:08 +00:00
|
|
|
inline void FrameObtainDispinfo(tex0Info* dispinfo)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
if (!Circuit_Enabled(i))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
dispinfo[i].tw = 0;
|
|
|
|
dispinfo[i].th = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
GSRegDISPFB* pfb = Dispfb_Reg(i);
|
|
|
|
GSRegDISPLAY* pd = Display_Reg(i);
|
|
|
|
|
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
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
// Note: This is what causes the double image if interlace is off on the Final Fantasy X-2 opening.
|
|
|
|
if (interlace_mode && 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.
|
2012-04-19 21:22:08 +00:00
|
|
|
inline void RenderStartHelper()
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
if (conf.mrtdepth && ZZshExistProgram(pvs[8]))
|
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;
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
FB::Unbind(); // switch to the backbuffer
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-11-14 01:38:10 +00:00
|
|
|
glViewport(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// if interlace, only clear every other vsync
|
2012-04-19 21:22:08 +00:00
|
|
|
if (!interlace_mode)
|
2010-03-19 06:38:44 +00:00
|
|
|
{
|
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();
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
if (interlace_mode) 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.
|
2013-07-03 18:42:05 +00:00
|
|
|
inline void RenderGetForClip(int psm, CRTC_TYPE render_type)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderGetForClip");
|
2012-04-19 21:22:08 +00:00
|
|
|
FRAGMENTSHADER* prog = curr_pps(render_type);
|
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
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
if (psm == PSMCT24)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
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
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
if (interlace_mode)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
if (gs.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-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put interlaced texture in use for shader prog.
|
2012-04-19 21:22:08 +00:00
|
|
|
// Note: if the frame is interlaced, its th is halved, so we should multiply it by 2.
|
|
|
|
inline void RenderCreateInterlaceTex(int th, CRTC_TYPE render_type)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
FRAGMENTSHADER* prog;
|
|
|
|
int interlacetex;
|
|
|
|
|
|
|
|
if (!interlace_mode) return;
|
|
|
|
|
|
|
|
prog = curr_pps(render_type);
|
|
|
|
interlacetex = CreateInterlaceTex(2 * th);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
ZZshGLSetTextureParameter(prog->prog, prog->sInterlace, interlacetex, "Interlace");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
// Use the ALP register for alpha blending.
|
2010-05-01 20:33:53 +00:00
|
|
|
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
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
// Use the alpha value of circuit 1 for alpha blending.
|
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)
|
|
|
|
{
|
|
|
|
s_stencilmask = 1 << i;
|
2012-04-19 21:22:08 +00:00
|
|
|
glStencilMask(s_stencilmask);
|
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
|
2012-04-19 21:22:08 +00:00
|
|
|
inline void RenderUpdateStencil(int i)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
if (!bUsingStencil)
|
|
|
|
{
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT);
|
|
|
|
bUsingStencil = true;
|
|
|
|
}
|
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
|
2012-04-19 21:22:08 +00:00
|
|
|
/*inline void RenderCRTC24helper(int psm)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
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?)
|
2012-04-19 21:22:08 +00:00
|
|
|
RenderGetForClip(psm, CRTC_RENDER_24);
|
|
|
|
ZZshSetPixelShader(curr_ppsCRTC24()->prog);
|
2010-06-19 05:41:06 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
DrawTriangleArray();
|
2012-04-19 21:22:08 +00:00
|
|
|
}*/
|
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.
|
2012-04-19 21:22:08 +00:00
|
|
|
inline float4 RenderSetTargetBitPos(int dh, int th, int movy)
|
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);
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
if (INTERLACE_COUNT())
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
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.
|
2012-04-19 21:22:08 +00:00
|
|
|
inline float4 RenderSetTargetBitTex(float th, float tw, float dh, float dw)
|
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
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
if (INTERLACE_COUNT())
|
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
|
2012-04-19 21:22:08 +00:00
|
|
|
inline float4 RenderSetTargetInvTex(int tw, int th, CRTC_TYPE render_type)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SetShaderCaller("RenderSetTargetInvTex");
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
FRAGMENTSHADER* prog = curr_pps(render_type);
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listTargs, int circuit);
|
2010-06-27 00:53:06 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// First try to draw frame from targets.
|
2012-04-19 21:22:08 +00:00
|
|
|
inline void RenderCheckForTargets(tex0Info& texframe, list<CRenderTarget*>& listTargs, int circuit)
|
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);
|
2012-04-19 21:22:08 +00:00
|
|
|
GSRegDISPFB* pfb = Dispfb_Reg(circuit);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
int start, end;
|
2012-04-19 21:22:08 +00:00
|
|
|
int tex_th = (interlace_mode) ? texframe.th * 2 : texframe.th;
|
|
|
|
|
|
|
|
//ZZLog::WriteLn("Render checking for targets, circuit %d", circuit);
|
|
|
|
GetRectMemAddressZero(start, end, texframe.psm, texframe.tw, tex_th, texframe.tbp0, texframe.tbw);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
FRAGMENTSHADER* pps;
|
2010-06-27 00:53:06 +00:00
|
|
|
int dby = pfb->DBY;
|
|
|
|
int movy = 0;
|
|
|
|
|
2012-04-19 21:22:08 +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)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
if (ptarg->fbh - dby < tex_th - movy && !bUsingStencil)
|
|
|
|
{
|
|
|
|
RenderUpdateStencil(circuit);
|
|
|
|
}
|
|
|
|
else if (ptarg->fbh - dby > 2 * ( tex_th - movy )) // I'm not sure this is needed any more.
|
2010-06-28 10:54:26 +00:00
|
|
|
{
|
|
|
|
// 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.
|
2012-04-19 21:22:08 +00:00
|
|
|
dby -= ((ptarg->fbh - dby) >> 2) - ((tex_th + movy) >> 1);
|
2010-06-28 10:54:26 +00:00
|
|
|
}
|
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
|
2012-04-19 21:22:08 +00:00
|
|
|
float4 v = RenderSetTargetBitTex((float)RW(texframe.tw), (float)RH(dh), (float)RW(pfb->DBX), (float)RH(dby));
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// dest rect
|
2012-04-19 21:22:08 +00:00
|
|
|
v = RenderSetTargetBitPos(dh, texframe.th, movy);
|
2010-03-19 00:31:15 +00:00
|
|
|
v = RenderSetTargetBitTrans(ptarg->fbh);
|
2012-04-19 21:22:08 +00:00
|
|
|
v = RenderSetTargetInvTex(texframe.tbw, ptarg->fbh, CRTC_RENDER_TARG); // FIXME. This is no use
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2013-07-03 18:42:05 +00:00
|
|
|
RenderGetForClip(texframe.psm, CRTC_RENDER_TARG);
|
2012-04-19 21:22:08 +00:00
|
|
|
pps = curr_ppsCRTCTarg();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// inside vb[0]'s target area, so render that region only
|
2012-04-19 21:22:08 +00:00
|
|
|
ZZshGLSetTextureParameter(pps->prog, pps->sFinal, ptarg->ptex, "CRTC target");
|
|
|
|
RenderCreateInterlaceTex(texframe.th, CRTC_RENDER_TARG);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
ZZshSetPixelShader(pps->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
|
|
|
|
2012-04-19 21:22:08 +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;
|
|
|
|
}
|
2012-04-19 21:22:08 +00:00
|
|
|
RenderCheckForMemory(texframe, listTargs, circuit);
|
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.
|
2012-04-19 21:22:08 +00:00
|
|
|
inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listTargs, int circuit)
|
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
|
2012-04-19 21:22:08 +00:00
|
|
|
if (interlace_mode >= 2) ZZLog::Error_Log("CRCR Check for memory shader fault.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
//if (!bUsingStencil) RenderUpdateStencil(i);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
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;
|
2012-04-19 21:22:08 +00:00
|
|
|
SetTexVariablesInt(0, 2, texframe, false, curr_ppsCRTC(), 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;
|
2012-04-19 21:22:08 +00:00
|
|
|
SetTexVariablesInt(0, 0, texframe, false, curr_ppsCRTC(), 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.
|
2012-04-19 21:22:08 +00:00
|
|
|
v = RenderSetTargetBitTex(w1, h1, w2, h2);
|
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)
|
2012-04-19 21:22:08 +00:00
|
|
|
v = RenderSetTargetBitPos(1, 1, 0);
|
2010-03-19 00:31:15 +00:00
|
|
|
v = RenderSetTargetBitTrans(texframe.th);
|
2012-04-19 21:22:08 +00:00
|
|
|
v = RenderSetTargetInvTex(texframe.tw, texframe.th, CRTC_RENDER);
|
2013-07-03 18:42:05 +00:00
|
|
|
RenderGetForClip(texframe.psm, CRTC_RENDER);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
ZZshGLSetTextureParameter(curr_ppsCRTC()->prog, curr_ppsCRTC()->sMemory, vb[0].pmemtarg->ptex->tex, "CRTC memory");
|
2012-06-18 21:38:41 +00:00
|
|
|
RenderCreateInterlaceTex(texframe.th, CRTC_RENDER);
|
2012-04-19 21:22:08 +00:00
|
|
|
ZZshSetPixelShader(curr_ppsCRTC()->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);
|
|
|
|
|
2010-11-14 01:38:10 +00:00
|
|
|
font_p->printString(pstr, left * 2.0f / (float)GLWin.backbuffer.w - 1, 1 - top * 2.0f / (float)GLWin.backbuffer.h, 0);
|
2010-10-17 08:47:31 +00:00
|
|
|
ZZshGLEnableProfile();
|
|
|
|
}
|
|
|
|
|
2010-06-15 11:20:52 +00:00
|
|
|
// Put FPS counter on screen (not in window title)
|
2010-11-09 12:04:07 +00:00
|
|
|
inline void DisplayFPS()
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
// Snapshot helper
|
2010-11-09 12:04:07 +00:00
|
|
|
inline void MakeSnapshot()
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
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-11-14 01:38:10 +00:00
|
|
|
if (SaveRenderTarget(strSnapshot != "" ? strSnapshot.c_str() : "temp.jpg", GLWin.backbuffer.w, -GLWin.backbuffer.h, 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
|
|
|
|
2010-11-09 12:04:07 +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;
|
2012-04-19 21:22:08 +00:00
|
|
|
g_vsprog = g_psprog = sZero;
|
2010-10-18 11:24:40 +00:00
|
|
|
|
|
|
|
ZZGSStateReset();
|
|
|
|
ZZDestroy();
|
2010-10-23 08:15:39 +00:00
|
|
|
//clear_drawfn();
|
|
|
|
if (ZZKick != NULL) delete ZZKick;
|
2010-10-18 11:24:40 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// Put new values on statistic variable
|
2010-11-09 12:04:07 +00:00
|
|
|
inline void CountStatistics()
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
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-11-09 12:04:07 +00:00
|
|
|
if (g_bDisplayFPS) DisplayFPS();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-11-09 12:04:07 +00:00
|
|
|
// Swapping buffers, so we could use another window
|
|
|
|
GLWin.SwapGLBuffers();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-11-09 12:04:07 +00:00
|
|
|
// clear all targets
|
|
|
|
if (conf.wireframe()) s_nWireframeCount = 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-11-09 12:04:07 +00:00
|
|
|
if (g_bMakeSnapshot) MakeSnapshot();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-03 07:57:56 +00:00
|
|
|
CaptureFrame();
|
2010-11-09 12:04:07 +00:00
|
|
|
CountStatistics();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-11-09 12:04:07 +00:00
|
|
|
if (s_nNewWidth >= 0 && s_nNewHeight >= 0)
|
|
|
|
{
|
|
|
|
// If needed reset
|
|
|
|
ZZReset();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-11-09 12:04:07 +00:00
|
|
|
ChangeDeviceSize(s_nNewWidth, s_nNewHeight);
|
|
|
|
s_nNewWidth = s_nNewHeight = -1;
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
maxmin = 608;
|
|
|
|
}
|
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
// Swich Framebuffers
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void AfterRendererSwitchBackToTextures()
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
FB::Bind();
|
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-11-07 05:51:54 +00:00
|
|
|
s_nCurResolveIndex = (s_nCurResolveIndex + 1) % ArraySize(s_nResolveCounts);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
2013-06-28 10:43:50 +00:00
|
|
|
for (u32 i = 0; i < ArraySize(s_nResolveCounts); ++i) total += s_nResolveCounts[i];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-11-07 05:51:54 +00:00
|
|
|
if (total / ArraySize(s_nResolveCounts) > 3)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
|
|
|
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-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;
|
2012-04-19 21:22:08 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// The main renderer function
|
2012-04-19 21:22:08 +00:00
|
|
|
void RenderCRTC()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
tex0Info dispinfo[2];
|
2012-04-19 21:22:08 +00:00
|
|
|
|
|
|
|
if (FrameSkippingHelper()) return;
|
|
|
|
|
|
|
|
// If we are in frame mode and interlacing, and we haven't forced interlacing off, interlace_mode is 1.
|
|
|
|
interlace_mode = SMODE2->INT && SMODE2->FFMD && (conf.interlace < 2);
|
|
|
|
bUsingStencil = false;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
RenderStartHelper();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
FrameObtainDispinfo(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)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
if (!Circuit_Enabled(i)) continue;
|
2010-03-19 00:31:15 +00:00
|
|
|
tex0Info& texframe = dispinfo[i];
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
// I don't think this is neccessary, now that we make sure the ciruit we are working with is enabled.
|
2012-05-25 06:44:22 +00:00
|
|
|
//
|
|
|
|
// Actually it seems there are still empty frame in some games (persona 4 and tales of abyss). I'm not sure it
|
|
|
|
// is normal, for the moment keep the check to avoid some undefined behavior. -- Gregory
|
|
|
|
if (texframe.th <= 1) continue;
|
2012-04-19 21:22:08 +00:00
|
|
|
|
2010-08-22 09:42:28 +00:00
|
|
|
if (SMODE2->INT && SMODE2->FFMD)
|
|
|
|
{
|
|
|
|
texframe.th >>= 1;
|
2012-04-19 21:22:08 +00:00
|
|
|
|
2010-08-22 09:42:28 +00:00
|
|
|
// Final Fantasy X-2 issue here.
|
2012-04-19 21:22:08 +00:00
|
|
|
/*if (conf.interlace == 2 && texframe.th >= 512)
|
|
|
|
{
|
2010-08-22 09:42:28 +00:00
|
|
|
texframe.th >>= 1;
|
2012-04-19 21:22:08 +00:00
|
|
|
}*/
|
2010-08-22 09:42:28 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (i == 0) RenderSetupBlending();
|
|
|
|
if (bUsingStencil) RenderSetupStencil(i);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
/*if (texframe.psm == 0x12) // Probably broken - 0x12 isn't a valid psm. 24 bit is 1.
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
RenderCRTC24helper(texframe.psm);
|
2010-03-19 00:31:15 +00:00
|
|
|
continue;
|
2012-04-19 21:22:08 +00:00
|
|
|
}*/
|
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
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
// if we could not draw image from target's, do it from memory
|
|
|
|
RenderCheckForTargets(texframe, listTargs, i);
|
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();
|
|
|
|
}
|