2017-04-26 10:23:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* Project64-video - A Nintendo 64 gfx plugin. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2017 Project64. All rights reserved. *
|
|
|
|
* Copyright (C) 2003-2009 Sergey 'Gonetz' Lipski *
|
|
|
|
* Copyright (C) 2002 Dave2001 *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2017-05-17 08:01:54 +00:00
|
|
|
#include <Project64-video/Renderer/Renderer.h>
|
2016-01-28 20:00:13 +00:00
|
|
|
#include <string.h>
|
2015-12-04 21:26:58 +00:00
|
|
|
#include <Common/StdString.h>
|
2015-10-09 00:07:09 +00:00
|
|
|
#include "Gfx_1.3.h"
|
2015-02-17 09:56:34 +00:00
|
|
|
#include "Version.h"
|
2016-01-25 09:33:04 +00:00
|
|
|
#include <Common/CriticalSection.h>
|
2016-09-16 21:37:27 +00:00
|
|
|
#include <Common/DateTimeClass.h>
|
2016-01-25 11:00:45 +00:00
|
|
|
#include <Common/path.h>
|
2016-02-24 10:55:42 +00:00
|
|
|
#include <png/png.h>
|
2016-03-08 06:36:18 +00:00
|
|
|
#include <memory>
|
2016-10-09 09:44:31 +00:00
|
|
|
#include <Common/SmartPointer.h>
|
2017-04-18 11:32:43 +00:00
|
|
|
#include <Settings/Settings.h>
|
2013-04-24 05:03:21 +00:00
|
|
|
|
2016-01-25 11:00:45 +00:00
|
|
|
#include "Config.h"
|
2013-04-04 21:22:19 +00:00
|
|
|
#include "Util.h"
|
|
|
|
#include "3dmath.h"
|
|
|
|
#include "Debugger.h"
|
|
|
|
#include "Combine.h"
|
|
|
|
#include "TexCache.h"
|
|
|
|
#include "CRC.h"
|
|
|
|
#include "FBtoScreen.h"
|
|
|
|
#include "DepthBufferRender.h"
|
2016-02-01 08:56:25 +00:00
|
|
|
#include "trace.h"
|
2017-01-28 11:29:03 +00:00
|
|
|
#include "ScreenResolution.h"
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-01-28 19:27:50 +00:00
|
|
|
#ifdef _WIN32
|
2018-11-18 00:42:49 +00:00
|
|
|
#include <Windows.h>
|
2017-01-28 19:27:50 +00:00
|
|
|
#include <commctrl.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-04 21:22:19 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2017-02-08 19:08:06 +00:00
|
|
|
#ifdef ANDROID
|
2017-04-27 10:24:10 +00:00
|
|
|
uint32_t g_ScreenWidth, g_ScreenHeight;
|
2017-02-08 19:08:06 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-04 21:22:19 +00:00
|
|
|
GFX_INFO gfx;
|
|
|
|
|
|
|
|
int to_fullscreen = FALSE;
|
2016-01-20 17:12:15 +00:00
|
|
|
int GfxInitDone = FALSE;
|
2016-03-08 06:31:08 +00:00
|
|
|
bool g_romopen = false;
|
2013-04-04 21:22:19 +00:00
|
|
|
int exception = FALSE;
|
|
|
|
|
|
|
|
int ev_fullscreen = 0;
|
|
|
|
|
2017-03-13 09:34:51 +00:00
|
|
|
extern int g_viewport_offset;
|
2017-02-08 19:08:06 +00:00
|
|
|
extern int g_width, g_height;
|
|
|
|
|
2016-01-25 11:00:45 +00:00
|
|
|
#ifdef _WIN32
|
2013-04-22 01:11:55 +00:00
|
|
|
HINSTANCE hinstDLL = NULL;
|
2013-04-04 21:22:19 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 06:14:48 +00:00
|
|
|
uint32_t region = 0;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
|
|
|
unsigned int BMASK = 0x7FFFFF;
|
|
|
|
// Reality display processor structure
|
2017-05-19 06:23:43 +00:00
|
|
|
CRDP rdp;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-01-23 06:50:29 +00:00
|
|
|
CSettings * g_settings = NULL;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-08-20 22:20:19 +00:00
|
|
|
VOODOO voodoo = { 0, 0, 0,
|
2016-03-08 21:55:19 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0
|
2016-01-20 06:29:27 +00:00
|
|
|
};
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-07-25 08:29:37 +00:00
|
|
|
gfxTexInfo fontTex;
|
|
|
|
gfxTexInfo cursorTex;
|
2016-01-20 06:14:48 +00:00
|
|
|
uint32_t offset_font = 0;
|
|
|
|
uint32_t offset_cursor = 0;
|
|
|
|
uint32_t offset_textures = 0;
|
|
|
|
uint32_t offset_texbuf1 = 0;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-03-10 05:25:04 +00:00
|
|
|
bool g_ghq_use = false;
|
2017-03-13 09:28:34 +00:00
|
|
|
bool g_capture_screen = false;
|
|
|
|
std::string g_capture_path;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-01-28 11:29:03 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
static RECT g_windowedRect = { 0 };
|
|
|
|
static HMENU g_windowedMenu = 0;
|
|
|
|
static unsigned long g_windowedExStyle, g_windowedStyle;
|
|
|
|
bool g_fullscreen;
|
|
|
|
#endif // _WIN32
|
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
void ChangeSize()
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-04-27 09:06:14 +00:00
|
|
|
WriteTrace(TraceResolution, TraceDebug, "Start");
|
|
|
|
#ifdef ANDROID
|
|
|
|
g_width = g_ScreenWidth;
|
|
|
|
g_height = g_ScreenHeight;
|
|
|
|
#else
|
|
|
|
g_width = ev_fullscreen ? GetFullScreenResWidth(g_settings->FullScreenRes()) : GetScreenResWidth(g_settings->ScreenRes());
|
|
|
|
g_height = ev_fullscreen ? GetFullScreenResHeight(g_settings->FullScreenRes()) : GetScreenResHeight(g_settings->ScreenRes());
|
|
|
|
#endif
|
|
|
|
g_scr_res_x = g_res_x = g_width;
|
|
|
|
g_scr_res_y = g_res_y = g_height;
|
|
|
|
|
|
|
|
switch (g_settings->aspectmode())
|
|
|
|
{
|
|
|
|
case CSettings::Aspect_4x3:
|
|
|
|
if (g_scr_res_x >= g_scr_res_y * 4.0f / 3.0f)
|
|
|
|
{
|
|
|
|
g_res_y = g_scr_res_y;
|
|
|
|
g_res_x = (uint32_t)(g_res_y * 4.0f / 3.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_res_x = g_scr_res_x;
|
|
|
|
g_res_y = (uint32_t)(g_res_x / 4.0f * 3.0f);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CSettings::Aspect_16x9:
|
|
|
|
if (g_scr_res_x >= g_scr_res_y * 16.0f / 9.0f)
|
|
|
|
{
|
|
|
|
g_res_y = g_scr_res_y;
|
|
|
|
g_res_x = (uint32_t)(g_res_y * 16.0f / 9.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_res_x = g_scr_res_x;
|
|
|
|
g_res_y = (uint32_t)(g_res_x / 16.0f * 9.0f);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: //stretch or original
|
|
|
|
g_res_x = g_scr_res_x;
|
|
|
|
g_res_y = g_scr_res_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
float res_scl_y = (float)g_res_y / 240.0f;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
uint32_t scale_x = *gfx.VI_X_SCALE_REG & 0xFFF;
|
|
|
|
uint32_t scale_y = *gfx.VI_Y_SCALE_REG & 0xFFF;
|
2017-04-27 09:06:14 +00:00
|
|
|
if (scale_x != 0 && scale_y != 0)
|
|
|
|
{
|
|
|
|
float fscale_x = (float)scale_x / 1024.0f;
|
|
|
|
float fscale_y = (float)scale_y / 2048.0f;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
uint32_t dwHStartReg = *gfx.VI_H_START_REG;
|
|
|
|
uint32_t dwVStartReg = *gfx.VI_V_START_REG;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
uint32_t hstart = dwHStartReg >> 16;
|
|
|
|
uint32_t hend = dwHStartReg & 0xFFFF;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
// dunno... but sometimes this happens
|
|
|
|
if (hend == hstart) hend = (int)(*gfx.VI_WIDTH_REG / fscale_x);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
uint32_t vstart = dwVStartReg >> 16;
|
|
|
|
uint32_t vend = dwVStartReg & 0xFFFF;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
rdp.vi_width = (hend - hstart) * fscale_x;
|
|
|
|
rdp.vi_height = (vend - vstart) * fscale_y * 1.0126582f;
|
|
|
|
float aspect = (g_settings->adjust_aspect() && (fscale_y > fscale_x) && (rdp.vi_width > rdp.vi_height)) ? fscale_x / fscale_y : 1.0f;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
WriteTrace(TraceResolution, TraceDebug, "hstart: %d, hend: %d, vstart: %d, vend: %d", hstart, hend, vstart, vend);
|
|
|
|
WriteTrace(TraceResolution, TraceDebug, "size: %d x %d", (int)rdp.vi_width, (int)rdp.vi_height);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
rdp.scale_x = (float)g_res_x / rdp.vi_width;
|
|
|
|
if (region > 0 && g_settings->pal230())
|
|
|
|
{
|
|
|
|
// odd... but pal games seem to want 230 as height...
|
|
|
|
rdp.scale_y = res_scl_y * (230.0f / rdp.vi_height) * aspect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rdp.scale_y = (float)g_res_y / rdp.vi_height * aspect;
|
|
|
|
}
|
|
|
|
rdp.offset_y = ((float)g_res_y - rdp.vi_height * rdp.scale_y) * 0.5f;
|
|
|
|
if (((uint32_t)rdp.vi_width <= (*gfx.VI_WIDTH_REG) / 2) && (rdp.vi_width > rdp.vi_height))
|
|
|
|
rdp.scale_y *= 0.5f;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
rdp.scissor_o.ul_x = 0;
|
|
|
|
rdp.scissor_o.ul_y = 0;
|
|
|
|
rdp.scissor_o.lr_x = (uint32_t)rdp.vi_width;
|
|
|
|
rdp.scissor_o.lr_y = (uint32_t)rdp.vi_height;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
rdp.update |= UPDATE_VIEWPORT | UPDATE_SCISSOR;
|
|
|
|
}
|
|
|
|
rdp.offset_x = (g_scr_res_x - g_res_x) / 2.0f;
|
|
|
|
float offset_y = (g_scr_res_y - g_res_y) / 2.0f;
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.offset_y += offset_y;
|
2017-01-29 06:47:28 +00:00
|
|
|
if (g_settings->aspectmode() == CSettings::Aspect_Original)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
|
|
|
rdp.scale_x = rdp.scale_y = 1.0f;
|
2017-04-27 09:06:14 +00:00
|
|
|
rdp.offset_x = (g_scr_res_x - rdp.vi_width) / 2.0f;
|
|
|
|
rdp.offset_y = (g_scr_res_y - rdp.vi_height) / 2.0f;
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
2017-04-27 09:06:14 +00:00
|
|
|
WriteTrace(TraceResolution, TraceDebug, "rdp.offset_x = %f rdp.offset_y = %f rdp.scale_x = %f, rdp.scale_y = %f", rdp.offset_x, rdp.offset_y, rdp.scale_x, rdp.scale_y);
|
|
|
|
WriteTrace(TraceResolution, TraceDebug, "Done");
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 18:29:41 +00:00
|
|
|
extern int g_width, g_height;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2013-04-22 01:11:55 +00:00
|
|
|
int GetTexAddrUMA(int /*tmu*/, int texsize)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
int addr = voodoo.tex_min_addr[0] + voodoo.tmem_ptr[0];
|
|
|
|
voodoo.tmem_ptr[0] += texsize;
|
|
|
|
voodoo.tmem_ptr[1] = voodoo.tmem_ptr[0];
|
|
|
|
return addr;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
int GetTexAddrNonUMA(int tmu, int texsize)
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
int addr = voodoo.tex_min_addr[tmu] + voodoo.tmem_ptr[tmu];
|
|
|
|
voodoo.tmem_ptr[tmu] += texsize;
|
|
|
|
return addr;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// guLoadTextures - used to load the cursor and font textures
|
2016-01-20 06:29:27 +00:00
|
|
|
void guLoadTextures()
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
|
|
|
int tbuf_size = 0;
|
2017-08-17 22:27:54 +00:00
|
|
|
if (g_scr_res_x <= 1024)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-07-23 00:04:04 +00:00
|
|
|
gfxTextureBufferExt(GFX_TMU0, voodoo.tex_min_addr[GFX_TMU0], GFX_LOD_LOG2_1024, GFX_LOD_LOG2_1024,
|
2017-08-10 07:25:40 +00:00
|
|
|
GFX_ASPECT_LOG2_1x1, GFX_TEXFMT_RGB_565, GFX_MIPMAPLEVELMASK_BOTH);
|
2017-07-20 07:30:08 +00:00
|
|
|
tbuf_size = gfxTexCalcMemRequired(GFX_LOD_LOG2_1024, GFX_LOD_LOG2_1024,
|
2017-07-25 08:29:37 +00:00
|
|
|
GFX_ASPECT_LOG2_1x1, GFX_TEXFMT_RGB_565);
|
2017-07-22 06:03:12 +00:00
|
|
|
gfxRenderBuffer(GFX_BUFFER_TEXTUREBUFFER_EXT);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2017-07-22 06:03:12 +00:00
|
|
|
gfxRenderBuffer(GFX_BUFFER_BACKBUFFER);
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-23 00:04:04 +00:00
|
|
|
gfxTextureBufferExt(GFX_TMU0, voodoo.tex_min_addr[GFX_TMU0], GFX_LOD_LOG2_2048, GFX_LOD_LOG2_2048,
|
2017-08-10 07:25:40 +00:00
|
|
|
GFX_ASPECT_LOG2_1x1, GFX_TEXFMT_RGB_565, GFX_MIPMAPLEVELMASK_BOTH);
|
2017-07-20 07:30:08 +00:00
|
|
|
tbuf_size = gfxTexCalcMemRequired(GFX_LOD_LOG2_2048, GFX_LOD_LOG2_2048,
|
2017-07-25 08:29:37 +00:00
|
|
|
GFX_ASPECT_LOG2_1x1, GFX_TEXFMT_RGB_565);
|
2017-07-22 06:03:12 +00:00
|
|
|
gfxRenderBuffer(GFX_BUFFER_TEXTUREBUFFER_EXT);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2017-07-22 06:03:12 +00:00
|
|
|
gfxRenderBuffer(GFX_BUFFER_BACKBUFFER);
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 00:04:04 +00:00
|
|
|
rdp.texbufs[0].tmu = GFX_TMU0;
|
|
|
|
rdp.texbufs[0].begin = voodoo.tex_min_addr[GFX_TMU0];
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.texbufs[0].end = rdp.texbufs[0].begin + tbuf_size;
|
2013-04-04 21:22:19 +00:00
|
|
|
rdp.texbufs[0].count = 0;
|
|
|
|
rdp.texbufs[0].clear_allowed = TRUE;
|
|
|
|
offset_font = tbuf_size;
|
2017-05-17 08:01:54 +00:00
|
|
|
if ((nbTextureUnits > 2 ? 2 : 1) > 1)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-07-23 00:04:04 +00:00
|
|
|
rdp.texbufs[1].tmu = GFX_TMU1;
|
2017-05-21 10:44:34 +00:00
|
|
|
rdp.texbufs[1].begin = rdp.texbufs[0].end;
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.texbufs[1].end = rdp.texbufs[1].begin + tbuf_size;
|
|
|
|
rdp.texbufs[1].count = 0;
|
|
|
|
rdp.texbufs[1].clear_allowed = TRUE;
|
2017-05-21 10:44:34 +00:00
|
|
|
offset_font += tbuf_size;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "font.h"
|
2016-01-20 06:29:27 +00:00
|
|
|
uint32_t *data = (uint32_t*)font;
|
|
|
|
uint32_t cur;
|
|
|
|
|
|
|
|
// ** Font texture **
|
|
|
|
uint8_t *tex8 = (uint8_t*)malloc(256 * 64);
|
|
|
|
|
2017-05-21 21:06:12 +00:00
|
|
|
fontTex.smallLodLog2 = fontTex.largeLodLog2 = GFX_LOD_LOG2_256;
|
2017-07-25 08:29:37 +00:00
|
|
|
fontTex.aspectRatioLog2 = GFX_ASPECT_LOG2_4x1;
|
2017-05-17 10:34:55 +00:00
|
|
|
fontTex.format = GFX_TEXFMT_ALPHA_8;
|
2016-01-20 06:29:27 +00:00
|
|
|
fontTex.data = tex8;
|
|
|
|
|
|
|
|
// Decompression: [1-bit inverse alpha --> 8-bit alpha]
|
|
|
|
uint32_t i, b;
|
|
|
|
for (i = 0; i < 0x200; i++)
|
|
|
|
{
|
|
|
|
// cur = ~*(data++), byteswapped
|
2013-04-04 21:22:19 +00:00
|
|
|
#ifdef __VISUALC__
|
2016-01-20 06:29:27 +00:00
|
|
|
cur = _byteswap_ulong(~*(data++));
|
2013-04-04 21:22:19 +00:00
|
|
|
#else
|
2016-01-20 06:29:27 +00:00
|
|
|
cur = ~*(data++);
|
|
|
|
cur = ((cur & 0xFF) << 24) | (((cur >> 8) & 0xFF) << 16) | (((cur >> 16) & 0xFF) << 8) | ((cur >> 24) & 0xFF);
|
2013-04-04 21:22:19 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
for (b = 0x80000000; b != 0; b >>= 1)
|
|
|
|
{
|
|
|
|
if (cur&b) *tex8 = 0xFF;
|
|
|
|
else *tex8 = 0x00;
|
|
|
|
tex8++;
|
2016-02-24 07:07:50 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 00:04:04 +00:00
|
|
|
gfxTexDownloadMipMap(GFX_TMU0,
|
|
|
|
voodoo.tex_min_addr[GFX_TMU0] + offset_font,
|
2017-08-10 07:25:40 +00:00
|
|
|
GFX_MIPMAPLEVELMASK_BOTH,
|
2016-01-20 06:29:27 +00:00
|
|
|
&fontTex);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-08-10 07:25:40 +00:00
|
|
|
offset_cursor = offset_font + gfxTexTextureMemRequired(GFX_MIPMAPLEVELMASK_BOTH, &fontTex);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
free(fontTex.data);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// ** Cursor texture **
|
2013-04-04 21:22:19 +00:00
|
|
|
#include "cursor.h"
|
2016-01-20 06:29:27 +00:00
|
|
|
data = (uint32_t*)cursor;
|
|
|
|
|
|
|
|
uint16_t *tex16 = (uint16_t*)malloc(32 * 32 * 2);
|
|
|
|
|
2017-05-21 21:06:12 +00:00
|
|
|
cursorTex.smallLodLog2 = cursorTex.largeLodLog2 = GFX_LOD_LOG2_32;
|
2017-07-25 08:29:37 +00:00
|
|
|
cursorTex.aspectRatioLog2 = GFX_ASPECT_LOG2_1x1;
|
2017-05-17 10:34:55 +00:00
|
|
|
cursorTex.format = GFX_TEXFMT_ARGB_1555;
|
2016-01-20 06:29:27 +00:00
|
|
|
cursorTex.data = tex16;
|
|
|
|
|
|
|
|
// Conversion: [16-bit 1555 (swapped) --> 16-bit 1555]
|
|
|
|
for (i = 0; i < 0x200; i++)
|
|
|
|
{
|
|
|
|
cur = *(data++);
|
|
|
|
*(tex16++) = (uint16_t)(((cur & 0x000000FF) << 8) | ((cur & 0x0000FF00) >> 8));
|
|
|
|
*(tex16++) = (uint16_t)(((cur & 0x00FF0000) >> 8) | ((cur & 0xFF000000) >> 24));
|
|
|
|
}
|
|
|
|
|
2017-07-23 00:04:04 +00:00
|
|
|
gfxTexDownloadMipMap(GFX_TMU0,
|
|
|
|
voodoo.tex_min_addr[GFX_TMU0] + offset_cursor,
|
2017-08-10 07:25:40 +00:00
|
|
|
GFX_MIPMAPLEVELMASK_BOTH,
|
2016-01-20 06:29:27 +00:00
|
|
|
&cursorTex);
|
|
|
|
|
|
|
|
// Round to higher 16
|
2017-08-10 07:25:40 +00:00
|
|
|
offset_textures = ((offset_cursor + gfxTexTextureMemRequired(GFX_MIPMAPLEVELMASK_BOTH, &cursorTex))
|
2016-01-20 06:29:27 +00:00
|
|
|
& 0xFFFFFFF0) + 16;
|
|
|
|
free(cursorTex.data);
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayLoadProgress(const wchar_t *format, ...)
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
va_list args;
|
|
|
|
wchar_t wbuf[INFO_BUF];
|
|
|
|
char buf[INFO_BUF];
|
|
|
|
|
|
|
|
// process input
|
|
|
|
va_start(args, format);
|
|
|
|
vswprintf(wbuf, INFO_BUF, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
// XXX: convert to multibyte
|
|
|
|
wcstombs(buf, wbuf, INFO_BUF);
|
|
|
|
|
2016-01-20 17:12:15 +00:00
|
|
|
float x;
|
|
|
|
set_message_combiner();
|
|
|
|
output(382, 380, 1, "LOADING TEXTURES. PLEASE WAIT...");
|
2016-01-25 09:58:29 +00:00
|
|
|
int len = minval((int)strlen(buf) * 8, 1024);
|
2016-01-20 17:12:15 +00:00
|
|
|
x = (1024 - len) / 2.0f;
|
|
|
|
output(x, 360, 1, buf);
|
2017-05-25 22:19:03 +00:00
|
|
|
gfxBufferSwap(0);
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxColorMask(true, true);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 11:29:03 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
void SetWindowDisplaySize(HWND hWnd)
|
|
|
|
{
|
2017-01-31 06:56:52 +00:00
|
|
|
if (ev_fullscreen)
|
2017-01-28 11:29:03 +00:00
|
|
|
{
|
|
|
|
ZeroMemory(&g_windowedRect, sizeof(RECT));
|
|
|
|
GetWindowRect(hWnd, &g_windowedRect);
|
|
|
|
|
|
|
|
g_windowedExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
|
|
|
|
g_windowedStyle = GetWindowLong(hWnd, GWL_STYLE);
|
|
|
|
|
|
|
|
// primary monitor only
|
2017-03-13 06:33:08 +00:00
|
|
|
if (!EnterFullScreen(g_settings->FullScreenRes()))
|
2017-01-28 11:29:03 +00:00
|
|
|
{
|
|
|
|
WriteTrace(TraceGlitch, TraceWarning, "can't change to fullscreen mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_windowedMenu = GetMenu(hWnd);
|
|
|
|
if (g_windowedMenu) SetMenu(hWnd, NULL);
|
|
|
|
|
2020-06-09 13:04:38 +00:00
|
|
|
HWND hStatusBar = FindWindowEx(hWnd, NULL, L"msctls_statusbar32", NULL); // 1964
|
2017-01-28 11:29:03 +00:00
|
|
|
if (hStatusBar) ShowWindow(hStatusBar, SW_HIDE);
|
|
|
|
|
|
|
|
SetWindowLong(hWnd, GWL_STYLE, 0);
|
|
|
|
SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
|
|
|
|
SetWindowPos(hWnd, NULL, 0, 0, g_width, g_height, SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
|
|
|
2017-03-13 09:34:51 +00:00
|
|
|
g_viewport_offset = 0;
|
2017-01-28 11:29:03 +00:00
|
|
|
g_fullscreen = true;
|
|
|
|
}
|
2017-01-31 06:56:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT clientRect = { 0 }, toolbarRect = { 0 }, statusbarRect = { 0 }, windowedRect = { 0 };
|
|
|
|
HWND hToolBar = FindWindowEx(hWnd, NULL, REBARCLASSNAME, NULL);
|
|
|
|
HWND hStatusBar = FindWindowEx(hWnd, NULL, STATUSCLASSNAME, NULL);
|
|
|
|
if (hStatusBar == NULL)
|
|
|
|
{
|
2020-06-09 13:04:38 +00:00
|
|
|
hStatusBar = FindWindowEx(hWnd, NULL, L"msctls_statusbar32", NULL);
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
|
|
|
if (hToolBar != NULL)
|
|
|
|
{
|
|
|
|
GetWindowRect(hToolBar, &toolbarRect);
|
|
|
|
}
|
|
|
|
if (hStatusBar != NULL)
|
|
|
|
{
|
|
|
|
GetWindowRect(hStatusBar, &statusbarRect);
|
|
|
|
}
|
2017-03-13 09:34:51 +00:00
|
|
|
g_viewport_offset = statusbarRect.bottom - statusbarRect.top;
|
2017-01-31 06:56:52 +00:00
|
|
|
GetWindowRect(hWnd, &g_windowedRect);
|
|
|
|
GetClientRect(hWnd, &clientRect);
|
|
|
|
g_windowedRect.right += (g_width - (clientRect.right - clientRect.left));
|
|
|
|
g_windowedRect.bottom += (g_height + (toolbarRect.bottom - toolbarRect.top) + (statusbarRect.bottom - statusbarRect.top) - (clientRect.bottom - clientRect.top));
|
|
|
|
SetWindowPos(hWnd, NULL, 0, 0, g_windowedRect.right - g_windowedRect.left, g_windowedRect.bottom - g_windowedRect.top, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
|
|
|
|
|
|
|
|
g_fullscreen = false;
|
|
|
|
}
|
2017-01-28 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExitFullScreen(void)
|
|
|
|
{
|
|
|
|
if (g_fullscreen)
|
|
|
|
{
|
|
|
|
ChangeDisplaySettings(NULL, 0);
|
2017-08-17 22:08:43 +00:00
|
|
|
SetWindowPos((HWND)gfx.hWnd, NULL, g_windowedRect.left, g_windowedRect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
|
|
|
|
SetWindowLong((HWND)gfx.hWnd, GWL_STYLE, g_windowedStyle);
|
|
|
|
SetWindowLong((HWND)gfx.hWnd, GWL_EXSTYLE, g_windowedExStyle);
|
|
|
|
if (g_windowedMenu) SetMenu((HWND)gfx.hWnd, g_windowedMenu);
|
2017-01-28 11:29:03 +00:00
|
|
|
g_fullscreen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-03-12 20:48:22 +00:00
|
|
|
|
|
|
|
void setPattern();
|
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
int InitGfx()
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 17:12:15 +00:00
|
|
|
if (GfxInitDone)
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
ReleaseGfx();
|
2016-01-20 17:12:15 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2017-04-27 09:06:14 +00:00
|
|
|
ChangeSize();
|
2017-02-08 19:08:06 +00:00
|
|
|
#ifndef ANDROID
|
2017-04-18 12:03:49 +00:00
|
|
|
SetWindowDisplaySize((HWND)gfx.hWnd);
|
2017-02-08 19:08:06 +00:00
|
|
|
#endif
|
2017-08-08 10:45:53 +00:00
|
|
|
if (!gfxSstWinOpen(GFX_COLORFORMAT_RGBA, GFX_ORIGIN_UPPER_LEFT, 2, 1))
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
2017-04-18 11:32:43 +00:00
|
|
|
g_Notify->DisplayError("Error setting display mode");
|
2016-01-20 06:29:27 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-05-19 06:23:43 +00:00
|
|
|
rdp.init();
|
|
|
|
util_init();
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 17:12:15 +00:00
|
|
|
GfxInitDone = TRUE;
|
2016-01-20 06:29:27 +00:00
|
|
|
to_fullscreen = FALSE;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// get maximal texture size
|
2017-07-23 00:04:04 +00:00
|
|
|
voodoo.tex_min_addr[0] = voodoo.tex_min_addr[1] = gfxTexMinAddress(GFX_TMU0);
|
|
|
|
voodoo.tex_max_addr[0] = voodoo.tex_max_addr[1] = gfxTexMaxAddress(GFX_TMU0);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
voodoo.gamma_correction = 0;
|
2017-08-10 22:36:26 +00:00
|
|
|
voodoo.gamma_table_size = 256;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-03-12 20:48:22 +00:00
|
|
|
srand(g_settings->stipple_pattern());
|
|
|
|
setPattern();
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
InitCombine();
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-08-02 21:48:55 +00:00
|
|
|
gfxCullMode(GFX_CULL_NEGATIVE);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-03-09 20:54:56 +00:00
|
|
|
if (g_settings->fog()) //"FOGCOORD" extension
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-05-24 07:30:02 +00:00
|
|
|
gfxFogGenerateLinear(0.0f, 255.0f);
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 22:02:52 +00:00
|
|
|
gfxDepthBufferMode(GFX_DEPTHBUFFER_ZBUFFER);
|
2017-07-31 11:05:29 +00:00
|
|
|
gfxDepthBufferFunction(GFX_CMP_LESS);
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxDepthMask(true);
|
2016-01-20 06:29:27 +00:00
|
|
|
|
|
|
|
ChangeSize();
|
|
|
|
|
|
|
|
guLoadTextures();
|
|
|
|
ClearCache();
|
|
|
|
|
2017-08-02 21:48:55 +00:00
|
|
|
gfxCullMode(GFX_CULL_DISABLE);
|
2017-08-02 22:02:52 +00:00
|
|
|
gfxDepthBufferMode(GFX_DEPTHBUFFER_ZBUFFER);
|
2017-07-31 11:05:29 +00:00
|
|
|
gfxDepthBufferFunction(GFX_CMP_ALWAYS);
|
2017-07-22 06:03:12 +00:00
|
|
|
gfxRenderBuffer(GFX_BUFFER_BACKBUFFER);
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxColorMask(true, true);
|
|
|
|
gfxDepthMask(true);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2017-05-25 22:19:03 +00:00
|
|
|
gfxBufferSwap(0);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxDepthMask(false);
|
2017-08-08 20:23:11 +00:00
|
|
|
gfxTexFilterMode(GFX_TMU0, GFX_TEXTUREFILTER_BILINEAR, GFX_TEXTUREFILTER_BILINEAR);
|
|
|
|
gfxTexFilterMode(GFX_TMU1, GFX_TEXTUREFILTER_BILINEAR, GFX_TEXTUREFILTER_BILINEAR);
|
2017-08-08 19:55:25 +00:00
|
|
|
gfxTexClampMode(GFX_TMU0, GFX_TEXTURECLAMP_CLAMP, GFX_TEXTURECLAMP_CLAMP);
|
|
|
|
gfxTexClampMode(GFX_TMU1, GFX_TEXTURECLAMP_CLAMP, GFX_TEXTURECLAMP_CLAMP);
|
2017-05-22 10:18:43 +00:00
|
|
|
gfxClipWindow(0, 0, g_scr_res_x, g_scr_res_y);
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.update |= UPDATE_SCISSOR | UPDATE_COMBINE | UPDATE_ZBUF_ENABLED | UPDATE_CULL_MODE;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-03-10 05:25:04 +00:00
|
|
|
if (!g_ghq_use)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-03-10 05:25:04 +00:00
|
|
|
g_ghq_use = g_settings->ghq_fltr() != CSettings::TextureFilter_None || g_settings->ghq_enht() != CSettings::TextureEnht_None || g_settings->ghq_hirs() != CSettings::HiResPackFormat_None;
|
|
|
|
if (g_ghq_use)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
|
|
|
/* Plugin path */
|
2017-03-09 21:37:26 +00:00
|
|
|
int options = g_settings->ghq_fltr() | g_settings->ghq_enht() | g_settings->ghq_cmpr() | g_settings->ghq_hirs();
|
2017-03-10 05:31:59 +00:00
|
|
|
if (g_settings->ghq_enht_cmpr())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= COMPRESS_TEX;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 06:01:41 +00:00
|
|
|
if (g_settings->ghq_hirs_cmpr())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= COMPRESS_HIRESTEX;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 06:10:09 +00:00
|
|
|
if (g_settings->ghq_hirs_tile())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= TILE_HIRESTEX;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 05:36:38 +00:00
|
|
|
if (g_settings->ghq_enht_f16bpp())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= FORCE16BPP_TEX;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 12:03:10 +00:00
|
|
|
if (g_settings->ghq_hirs_f16bpp())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= FORCE16BPP_HIRESTEX;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 05:42:29 +00:00
|
|
|
if (g_settings->ghq_enht_gz())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= GZ_TEXCACHE;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 12:17:57 +00:00
|
|
|
if (g_settings->ghq_hirs_gz())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= GZ_HIRESTEXCACHE;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-10 20:47:57 +00:00
|
|
|
if (g_settings->ghq_cache_save())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= (DUMP_TEXCACHE | DUMP_HIRESTEXCACHE);
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-12 17:54:23 +00:00
|
|
|
if (g_settings->ghq_hirs_let_texartists_fly())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= LET_TEXARTISTS_FLY;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2017-03-12 17:57:37 +00:00
|
|
|
if (g_settings->ghq_hirs_dump())
|
2017-01-31 06:56:52 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
options |= DUMP_TEX;
|
2017-01-31 06:56:52 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2017-08-17 22:27:54 +00:00
|
|
|
g_ghq_use = (int)ext_ghq_init(2048, // max texture width supported by hardware
|
|
|
|
2048, // max texture height supported by hardware
|
2017-08-18 08:02:38 +00:00
|
|
|
32, // max texture bpp supported by hardware
|
2016-01-20 06:29:27 +00:00
|
|
|
options,
|
2017-03-12 17:49:23 +00:00
|
|
|
g_settings->ghq_cache_size() * 1024 * 1024, // cache texture to system memory
|
2017-03-09 21:12:37 +00:00
|
|
|
g_settings->texture_dir(),
|
2016-01-25 10:34:16 +00:00
|
|
|
rdp.RomName, // name of ROM. must be no longer than 256 characters
|
2016-01-20 06:29:27 +00:00
|
|
|
DisplayLoadProgress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2017-04-18 12:03:49 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
void ReleaseGfx()
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-05-19 06:23:43 +00:00
|
|
|
rdp.free();
|
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// Restore gamma settings
|
|
|
|
if (voodoo.gamma_correction)
|
|
|
|
{
|
|
|
|
if (voodoo.gamma_table_r)
|
2017-07-20 07:41:50 +00:00
|
|
|
gfxLoadGammaTable(voodoo.gamma_table_size, voodoo.gamma_table_r, voodoo.gamma_table_g, voodoo.gamma_table_b);
|
2016-01-20 06:29:27 +00:00
|
|
|
else
|
2017-07-20 07:47:25 +00:00
|
|
|
gfxGammaCorrectionRGB(1.3f, 1.3f, 1.3f); //1.3f is default 3dfx gamma for everything but desktop
|
2016-01-20 06:29:27 +00:00
|
|
|
voodoo.gamma_correction = 0;
|
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// Release graphics
|
2017-07-23 02:53:37 +00:00
|
|
|
gfxSstWinClose();
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 17:12:15 +00:00
|
|
|
GfxInitDone = FALSE;
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.window_changed = TRUE;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 09:33:04 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
CriticalSection * g_ProcessDListCS = NULL;
|
2013-04-09 12:02:27 +00:00
|
|
|
|
2016-01-25 11:00:45 +00:00
|
|
|
extern "C" int WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID /*lpReserved*/)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
|
|
|
{
|
|
|
|
hinstDLL = hinst;
|
2016-01-25 09:33:04 +00:00
|
|
|
if (g_ProcessDListCS == NULL)
|
|
|
|
{
|
|
|
|
g_ProcessDListCS = new CriticalSection();
|
|
|
|
}
|
2016-03-08 22:22:28 +00:00
|
|
|
ConfigInit(hinst);
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
|
|
|
else if (fdwReason == DLL_PROCESS_DETACH)
|
|
|
|
{
|
2016-01-25 09:33:04 +00:00
|
|
|
if (g_ProcessDListCS)
|
|
|
|
{
|
|
|
|
delete g_ProcessDListCS;
|
|
|
|
}
|
2016-03-08 22:22:28 +00:00
|
|
|
ConfigCleanup();
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: CaptureScreen
|
|
|
|
Purpose: This function dumps the current frame to a file
|
|
|
|
input: pointer to the directory to save the file to
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
EXPORT void CALL CaptureScreen(char * Directory)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-03-13 09:28:34 +00:00
|
|
|
g_capture_screen = true;
|
|
|
|
g_capture_path = Directory;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: ChangeWindow
|
|
|
|
Purpose: to change the window between fullscreen and window
|
|
|
|
mode. If the window was in fullscreen this should
|
|
|
|
change the screen to window mode and vice vesa.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
EXPORT void CALL ChangeWindow(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-08-17 07:24:11 +00:00
|
|
|
if (!ev_fullscreen)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-08-17 07:24:11 +00:00
|
|
|
to_fullscreen = TRUE;
|
|
|
|
ev_fullscreen = TRUE;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
else
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-08-17 07:24:11 +00:00
|
|
|
ev_fullscreen = FALSE;
|
|
|
|
InitGfx();
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: CloseDLL
|
|
|
|
Purpose: This function is called when the emulator is closing
|
|
|
|
down allowing the dll to de-initialise.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL CloseDLL(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-03-10 05:25:04 +00:00
|
|
|
if (g_ghq_use)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
|
|
|
ext_ghq_shutdown();
|
2017-03-10 05:25:04 +00:00
|
|
|
g_ghq_use = false;
|
2016-01-25 07:15:46 +00:00
|
|
|
}
|
2016-02-01 08:56:25 +00:00
|
|
|
|
|
|
|
if (g_settings)
|
|
|
|
{
|
|
|
|
delete g_settings;
|
|
|
|
g_settings = NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-20 17:12:15 +00:00
|
|
|
ReleaseGfx();
|
2016-01-20 06:29:27 +00:00
|
|
|
ZLUT_release();
|
|
|
|
ClearCache();
|
|
|
|
delete[] voodoo.gamma_table_r;
|
|
|
|
voodoo.gamma_table_r = 0;
|
|
|
|
delete[] voodoo.gamma_table_g;
|
|
|
|
voodoo.gamma_table_g = 0;
|
|
|
|
delete[] voodoo.gamma_table_b;
|
|
|
|
voodoo.gamma_table_b = 0;
|
2018-11-24 02:47:37 +00:00
|
|
|
StopTrace();
|
2016-02-24 07:07:50 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: DllTest
|
|
|
|
Purpose: This function is optional function that is provided
|
|
|
|
to allow the user to test the dll
|
|
|
|
input: a handle to the window that calls this function
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2017-08-12 09:01:30 +00:00
|
|
|
void CALL DllTest(void * /*hParent*/)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: DrawScreen
|
|
|
|
Purpose: This function is called when the emulator receives a
|
|
|
|
WM_PAINT message. This allows the gfx to fit in when
|
|
|
|
it is being used in the desktop.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL DrawScreen(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: GetDllInfo
|
|
|
|
Purpose: This function allows the emulator to gather information
|
|
|
|
about the dll by filling in the PluginInfo structure.
|
|
|
|
input: a pointer to a PLUGIN_INFO stucture that needs to be
|
|
|
|
filled by the function. (see def above)
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL GetDllInfo(PLUGIN_INFO * PluginInfo)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
PluginInfo->Version = 0x0104; // Set to 0x0104
|
|
|
|
PluginInfo->Type = PLUGIN_TYPE_GFX; // Set to PLUGIN_TYPE_GFX
|
2013-04-22 01:11:55 +00:00
|
|
|
#ifdef _DEBUG
|
2017-04-27 09:06:14 +00:00
|
|
|
sprintf(PluginInfo->Name, "Project64 Video Plugin (Debug): %s", VER_FILE_VERSION_STR);
|
2013-04-22 01:11:55 +00:00
|
|
|
#else
|
2017-04-27 09:06:14 +00:00
|
|
|
sprintf(PluginInfo->Name, "Project64 Video Plugin: %s", VER_FILE_VERSION_STR);
|
2013-04-22 01:11:55 +00:00
|
|
|
#endif
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// If DLL supports memory these memory options then set them to TRUE or FALSE
|
|
|
|
// if it does not support it
|
|
|
|
PluginInfo->NormalMemory = FALSE; // a normal uint8_t array
|
|
|
|
PluginInfo->MemoryBswaped = TRUE; // a normal uint8_t array where the memory has been pre
|
|
|
|
// bswap on a dword (32 bits) boundry
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: InitiateGFX
|
|
|
|
Purpose: This function is called when the DLL is started to give
|
|
|
|
information from the emulator that the n64 graphics
|
|
|
|
uses. This is not called from the emulation thread.
|
|
|
|
Input: Gfx_Info is passed to this function which is defined
|
|
|
|
above.
|
|
|
|
Output: TRUE on success
|
|
|
|
FALSE on failure to initialise
|
|
|
|
|
|
|
|
** note on interrupts **:
|
|
|
|
To generate an interrupt set the appropriate bit in MI_INTR_REG
|
|
|
|
and then call the function CheckInterrupts to tell the emulator
|
|
|
|
that there is a waiting interrupt.
|
|
|
|
*******************************************************************/
|
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
int CALL InitiateGFX(GFX_INFO Gfx_Info)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-01 08:56:25 +00:00
|
|
|
WriteTrace(TraceInterface, TraceDebug, "Start");
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// Assume scale of 1 for debug purposes
|
|
|
|
rdp.scale_x = 1.0f;
|
|
|
|
rdp.scale_y = 1.0f;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
char name[21] = "DEFAULT";
|
2017-01-24 19:08:33 +00:00
|
|
|
g_settings->ReadGameSettings(name);
|
2017-01-23 18:28:13 +00:00
|
|
|
ZLUT_init();
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
gfx = Gfx_Info;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-05-19 06:23:43 +00:00
|
|
|
if (!rdp.init())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
math_init();
|
|
|
|
TexCacheInit();
|
|
|
|
CRC_BuildTable();
|
|
|
|
CountCombine();
|
2016-05-01 02:43:24 +00:00
|
|
|
ZLUT_init();
|
2016-01-20 06:29:27 +00:00
|
|
|
return TRUE;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: MoveScreen
|
|
|
|
Purpose: This function is called in response to the emulator
|
|
|
|
receiving a WM_MOVE passing the xpos and ypos passed
|
|
|
|
from that message.
|
|
|
|
input: xpos - the x-coordinate of the upper-left corner of the
|
|
|
|
client area of the window.
|
|
|
|
ypos - y-coordinate of the upper-left corner of the
|
|
|
|
client area of the window.
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL MoveScreen(int xpos, int ypos)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
xpos = xpos;
|
|
|
|
ypos = ypos;
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "xpos: %d ypos: %d", xpos, ypos);
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.window_changed = TRUE;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL PluginLoaded(void)
|
2013-04-24 05:03:21 +00:00
|
|
|
{
|
2017-04-18 12:03:49 +00:00
|
|
|
SetupTrace();
|
2017-01-23 06:50:29 +00:00
|
|
|
if (g_settings == NULL)
|
|
|
|
{
|
|
|
|
g_settings = new CSettings;
|
|
|
|
}
|
2017-04-18 12:03:49 +00:00
|
|
|
StartTrace();
|
2016-02-01 08:56:25 +00:00
|
|
|
|
|
|
|
WriteTrace(TraceInterface, TraceDebug, "Start");
|
|
|
|
WriteTrace(TraceInterface, TraceDebug, "Done");
|
2013-04-24 05:03:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 06:50:02 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
void vbo_disable(void);
|
|
|
|
#endif
|
|
|
|
|
2013-04-04 21:22:19 +00:00
|
|
|
/******************************************************************
|
|
|
|
Function: RomClosed
|
|
|
|
Purpose: This function is called when a rom is closed.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL RomClosed(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2016-06-04 06:50:02 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
vbo_disable();
|
|
|
|
#endif
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.window_changed = TRUE;
|
2016-03-08 06:31:08 +00:00
|
|
|
g_romopen = FALSE;
|
2017-05-19 06:23:43 +00:00
|
|
|
ReleaseGfx();
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: RomOpen
|
|
|
|
Purpose: This function is called when a rom is open. (from the
|
|
|
|
emulation thread)
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL RomOpen(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2016-01-20 06:29:27 +00:00
|
|
|
no_dlist = true;
|
2016-03-08 06:31:08 +00:00
|
|
|
g_romopen = TRUE;
|
2017-01-30 17:34:36 +00:00
|
|
|
g_ucode_error_report = TRUE; // allowed to report ucode errors
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
// Get the country code & translate to NTSC(0) or PAL(1)
|
|
|
|
uint16_t code = ((uint16_t*)gfx.HEADER)[0x1F ^ 1];
|
|
|
|
|
|
|
|
if (code == 0x4400) region = 1; // Germany (PAL)
|
|
|
|
if (code == 0x4500) region = 0; // USA (NTSC)
|
|
|
|
if (code == 0x4A00) region = 0; // Japan (NTSC)
|
|
|
|
if (code == 0x5000) region = 1; // Europe (PAL)
|
|
|
|
if (code == 0x5500) region = 0; // Australia (NTSC)
|
|
|
|
|
|
|
|
// get the name of the ROM
|
2016-03-08 21:55:19 +00:00
|
|
|
char name[21];
|
2016-01-20 06:29:27 +00:00
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
const char invalid_ch = '?'; /* Some Japanese games use wide chars. */
|
|
|
|
|
|
|
|
ch = (char)gfx.HEADER[(32 + i) ^ 3];
|
|
|
|
if (ch == '\0')
|
|
|
|
ch = ' ';
|
|
|
|
if (ch < ' ')
|
|
|
|
ch = invalid_ch;
|
|
|
|
if (ch > '~')
|
|
|
|
ch = invalid_ch;
|
|
|
|
name[i] = ch;
|
|
|
|
}
|
|
|
|
name[20] = '\0';
|
|
|
|
|
|
|
|
// remove all trailing spaces
|
|
|
|
while (name[strlen(name) - 1] == ' ')
|
2016-01-25 10:34:16 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
name[strlen(name) - 1] = 0;
|
2016-01-25 10:34:16 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2017-03-10 05:25:04 +00:00
|
|
|
if (g_ghq_use && strcmp(rdp.RomName, name) != 0)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
|
|
|
ext_ghq_shutdown();
|
2017-03-10 05:25:04 +00:00
|
|
|
g_ghq_use = false;
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
2016-01-25 10:34:16 +00:00
|
|
|
strcpy(rdp.RomName, name);
|
2017-01-24 19:08:33 +00:00
|
|
|
g_settings->ReadGameSettings(name);
|
2016-01-20 06:29:27 +00:00
|
|
|
ClearCache();
|
|
|
|
|
2017-08-16 08:03:13 +00:00
|
|
|
BMASK = g_settings->RdramSize() - 1;
|
2017-05-19 06:23:43 +00:00
|
|
|
InitGfx();
|
2017-08-04 23:01:05 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: ShowCFB
|
|
|
|
Purpose: Useally once Dlists are started being displayed, cfb is
|
|
|
|
ignored. This function tells the dll to start displaying
|
|
|
|
them again.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
|
|
|
bool no_dlist = true;
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL ShowCFB(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "-");
|
2016-01-20 06:29:27 +00:00
|
|
|
no_dlist = true;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawViRegBG()
|
|
|
|
{
|
2016-03-08 21:55:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "start");
|
2016-01-20 06:29:27 +00:00
|
|
|
FB_TO_SCREEN_INFO fb_info;
|
2017-03-13 09:28:34 +00:00
|
|
|
fb_info.width = *gfx.VI_WIDTH_REG;
|
2016-01-20 06:29:27 +00:00
|
|
|
fb_info.height = (uint32_t)rdp.vi_height;
|
|
|
|
if (fb_info.height == 0)
|
|
|
|
{
|
2016-02-11 09:58:42 +00:00
|
|
|
WriteTrace(TraceRDP, TraceDebug, "Image height = 0 - skipping");
|
2016-01-20 06:29:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fb_info.ul_x = 0;
|
|
|
|
|
2017-03-13 09:28:34 +00:00
|
|
|
fb_info.lr_x = fb_info.width - 1;
|
2016-01-20 06:29:27 +00:00
|
|
|
// fb_info.lr_x = (uint32_t)rdp.vi_width - 1;
|
|
|
|
fb_info.ul_y = 0;
|
|
|
|
fb_info.lr_y = fb_info.height - 1;
|
|
|
|
fb_info.opaque = 1;
|
|
|
|
fb_info.addr = *gfx.VI_ORIGIN_REG;
|
|
|
|
fb_info.size = *gfx.VI_STATUS_REG & 3;
|
|
|
|
rdp.last_bg = fb_info.addr;
|
|
|
|
|
|
|
|
bool drawn = DrawFrameBufferToScreen(fb_info);
|
2017-01-29 06:26:41 +00:00
|
|
|
if (g_settings->hacks(CSettings::hack_Lego) && drawn)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
|
|
|
rdp.updatescreen = 1;
|
|
|
|
newSwapBuffers();
|
|
|
|
DrawFrameBufferToScreen(fb_info);
|
|
|
|
}
|
2016-03-08 21:55:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "done");
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
static void DrawFrameBuffer()
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
if (to_fullscreen)
|
|
|
|
GoToFullScreen();
|
|
|
|
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxDepthMask(true);
|
|
|
|
gfxColorMask(true, true);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2016-01-20 17:12:15 +00:00
|
|
|
drawViRegBG();
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: UpdateScreen
|
|
|
|
Purpose: This function is called in response to a vsync of the
|
|
|
|
screen were the VI bit in MI_INTR_REG has already been
|
|
|
|
set
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:14:48 +00:00
|
|
|
uint32_t update_screen_count = 0;
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL UpdateScreen(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-02-11 09:58:42 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "Origin: %08x, Old origin: %08x, width: %d", *gfx.VI_ORIGIN_REG, rdp.vi_org_reg, *gfx.VI_WIDTH_REG);
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
uint32_t width = (*gfx.VI_WIDTH_REG) << 1;
|
2016-01-20 17:12:15 +00:00
|
|
|
if (*gfx.VI_ORIGIN_REG > width)
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
update_screen_count++;
|
2016-01-20 17:12:15 +00:00
|
|
|
}
|
2017-01-29 06:26:41 +00:00
|
|
|
uint32_t limit = g_settings->hacks(CSettings::hack_Lego) ? 15 : 30;
|
2017-01-24 19:08:33 +00:00
|
|
|
if (g_settings->fb_cpu_write_hack_enabled() && (update_screen_count > limit) && (rdp.last_bg == 0))
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
2016-02-11 09:58:42 +00:00
|
|
|
WriteTrace(TraceRDP, TraceDebug, "DirectCPUWrite hack!");
|
2016-01-20 06:29:27 +00:00
|
|
|
update_screen_count = 0;
|
|
|
|
no_dlist = true;
|
|
|
|
ClearCache();
|
|
|
|
UpdateScreen();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (no_dlist)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
if (*gfx.VI_ORIGIN_REG > width)
|
|
|
|
{
|
|
|
|
ChangeSize();
|
2016-02-11 09:58:42 +00:00
|
|
|
WriteTrace(TraceRDP, TraceDebug, "ChangeSize done");
|
2016-01-20 06:29:27 +00:00
|
|
|
DrawFrameBuffer();
|
2016-02-11 09:58:42 +00:00
|
|
|
WriteTrace(TraceRDP, TraceDebug, "DrawFrameBuffer done");
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.updatescreen = 1;
|
|
|
|
newSwapBuffers();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-01-29 18:05:06 +00:00
|
|
|
if (g_settings->swapmode() == CSettings::SwapMode_Old)
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
newSwapBuffers();
|
2017-01-29 18:05:06 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawWholeFrameBufferToScreen()
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
static uint32_t toScreenCI = 0;
|
|
|
|
if (rdp.ci_width < 200)
|
2017-01-29 18:05:06 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
return;
|
2017-01-29 18:05:06 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
if (rdp.cimg == toScreenCI)
|
2017-01-29 18:05:06 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
return;
|
2017-01-29 18:05:06 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
toScreenCI = rdp.cimg;
|
|
|
|
FB_TO_SCREEN_INFO fb_info;
|
|
|
|
fb_info.addr = rdp.cimg;
|
|
|
|
fb_info.size = rdp.ci_size;
|
|
|
|
fb_info.width = rdp.ci_width;
|
|
|
|
fb_info.height = rdp.ci_height;
|
|
|
|
if (fb_info.height == 0)
|
2017-01-29 18:05:06 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
return;
|
2017-01-29 18:05:06 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
fb_info.ul_x = 0;
|
|
|
|
fb_info.lr_x = rdp.ci_width - 1;
|
|
|
|
fb_info.ul_y = 0;
|
|
|
|
fb_info.lr_y = rdp.ci_height - 1;
|
|
|
|
fb_info.opaque = 0;
|
|
|
|
DrawFrameBufferToScreen(fb_info);
|
2017-01-24 19:08:33 +00:00
|
|
|
if (!g_settings->fb_ref_enabled())
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
memset(gfx.RDRAM + rdp.cimg, 0, (rdp.ci_width*rdp.ci_height) << rdp.ci_size >> 1);
|
2017-01-24 19:08:33 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void GetGammaTable()
|
|
|
|
{
|
2017-07-22 22:42:02 +00:00
|
|
|
voodoo.gamma_table_r = new uint32_t[voodoo.gamma_table_size];
|
|
|
|
voodoo.gamma_table_g = new uint32_t[voodoo.gamma_table_size];
|
|
|
|
voodoo.gamma_table_b = new uint32_t[voodoo.gamma_table_size];
|
2017-07-20 07:44:45 +00:00
|
|
|
gfxGetGammaTableExt(voodoo.gamma_table_size, voodoo.gamma_table_r, voodoo.gamma_table_g, voodoo.gamma_table_b);
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:55:42 +00:00
|
|
|
void write_png_file(const char* file_name, int width, int height, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
/* create file */
|
|
|
|
FILE *fp = fopen(file_name, "wb");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "File %s could not be opened for writing", file_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize stuff */
|
|
|
|
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
|
|
if (png_ptr == NULL)
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "png_create_write_struct failed");
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
|
|
|
if (info_ptr == NULL)
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "png_create_info_struct failed");
|
|
|
|
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr)))
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "Error during init_io");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_init_io(png_ptr, fp);
|
|
|
|
|
|
|
|
/* write header */
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr)))
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "Error during writing header");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_byte bit_depth = 8;
|
|
|
|
png_byte color_type = PNG_COLOR_TYPE_RGB;
|
|
|
|
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
|
|
|
|
|
|
|
png_write_info(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
/* write bytes */
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr)))
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "Error during writing bytes");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pixel_size = 3;
|
|
|
|
int p = 0;
|
2016-03-08 21:55:19 +00:00
|
|
|
png_bytep * row_pointers = (png_bytep*)malloc(sizeof(png_bytep)* height);
|
2016-02-24 10:55:42 +00:00
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
row_pointers[y] = (png_byte*)malloc(width*pixel_size);
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
row_pointers[y][x*pixel_size + 0] = buffer[p++];
|
|
|
|
row_pointers[y][x*pixel_size + 1] = buffer[p++];
|
|
|
|
row_pointers[y][x*pixel_size + 2] = buffer[p++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
png_write_image(png_ptr, row_pointers);
|
|
|
|
|
|
|
|
// cleanup heap allocation
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
free(row_pointers[y]);
|
|
|
|
}
|
|
|
|
free(row_pointers);
|
|
|
|
|
|
|
|
/* end write */
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr)))
|
|
|
|
{
|
|
|
|
WriteTrace(TracePNG, TraceError, "Error during end of write");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
png_write_end(png_ptr, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2016-01-20 06:14:48 +00:00
|
|
|
uint32_t curframe = 0;
|
2013-04-04 21:22:19 +00:00
|
|
|
void newSwapBuffers()
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
if (!rdp.updatescreen)
|
|
|
|
return;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 06:29:27 +00:00
|
|
|
rdp.updatescreen = 0;
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-02-11 09:58:42 +00:00
|
|
|
WriteTrace(TraceRDP, TraceDebug, "swapped");
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2016-01-20 17:12:15 +00:00
|
|
|
rdp.update |= UPDATE_SCISSOR | UPDATE_COMBINE | UPDATE_ZBUF_ENABLED | UPDATE_CULL_MODE;
|
2017-05-22 10:18:43 +00:00
|
|
|
gfxClipWindow(0, 0, g_scr_res_x, g_scr_res_y);
|
2017-07-31 11:05:29 +00:00
|
|
|
gfxDepthBufferFunction(GFX_CMP_ALWAYS);
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxDepthMask(false);
|
2017-08-02 21:48:55 +00:00
|
|
|
gfxCullMode(GFX_CULL_DISABLE);
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2017-03-13 09:28:34 +00:00
|
|
|
if (g_capture_screen)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-03-13 09:28:34 +00:00
|
|
|
CPath path(g_capture_path);
|
2016-01-25 11:00:45 +00:00
|
|
|
if (!path.DirectoryExists())
|
|
|
|
{
|
|
|
|
path.DirectoryCreate();
|
|
|
|
}
|
|
|
|
stdstr romName = rdp.RomName;
|
|
|
|
romName.Replace(" ", "_");
|
|
|
|
romName.Replace(":", ";");
|
2016-01-20 06:29:27 +00:00
|
|
|
|
|
|
|
for (int i = 1;; i++)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-01-28 19:11:28 +00:00
|
|
|
stdstr_f filename("Glide64_%s_%s%d.png", romName.c_str(), i < 10 ? "0" : "", i);
|
2016-01-25 11:00:45 +00:00
|
|
|
path.SetNameExtension(filename.c_str());
|
|
|
|
if (!path.Exists())
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
break;
|
2016-01-25 11:00:45 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
|
|
|
|
const uint32_t offset_x = (uint32_t)rdp.offset_x;
|
|
|
|
const uint32_t offset_y = (uint32_t)rdp.offset_y;
|
2017-04-27 09:06:14 +00:00
|
|
|
const uint32_t image_width = g_scr_res_x - offset_x * 2;
|
|
|
|
const uint32_t image_height = g_scr_res_y - offset_y * 2;
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2017-08-08 12:21:56 +00:00
|
|
|
gfxLfbInfo_t info;
|
|
|
|
info.size = sizeof(gfxLfbInfo_t);
|
2017-08-09 22:30:58 +00:00
|
|
|
if (gfxLfbLock(GFX_LFB_READ_ONLY, GFX_BUFFER_BACKBUFFER, GFX_LFBWRITEMODE_565, GFX_ORIGIN_UPPER_LEFT, false, &info))
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-10-09 09:44:31 +00:00
|
|
|
AUTO_PTR<uint8_t> ssimg_buffer(new uint8_t[image_width * image_height * 3]);
|
2016-02-24 10:55:42 +00:00
|
|
|
uint8_t * ssimg = ssimg_buffer.get();
|
2016-01-20 06:29:27 +00:00
|
|
|
int sspos = 0;
|
|
|
|
uint32_t offset_src = info.strideInBytes * offset_y;
|
|
|
|
|
|
|
|
// Copy the screen
|
2017-08-08 12:16:31 +00:00
|
|
|
if (info.writeMode == GFX_LFBWRITEMODE_8888)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
|
|
|
uint32_t col;
|
|
|
|
for (uint32_t y = 0; y < image_height; y++)
|
|
|
|
{
|
|
|
|
uint32_t *ptr = (uint32_t*)((uint8_t*)info.lfbPtr + offset_src);
|
|
|
|
ptr += offset_x;
|
|
|
|
for (uint32_t x = 0; x < image_width; x++)
|
|
|
|
{
|
|
|
|
col = *(ptr++);
|
|
|
|
ssimg[sspos++] = (uint8_t)((col >> 16) & 0xFF);
|
|
|
|
ssimg[sspos++] = (uint8_t)((col >> 8) & 0xFF);
|
|
|
|
ssimg[sspos++] = (uint8_t)(col & 0xFF);
|
|
|
|
}
|
|
|
|
offset_src += info.strideInBytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint16_t col;
|
|
|
|
for (uint32_t y = 0; y < image_height; y++)
|
|
|
|
{
|
|
|
|
uint16_t *ptr = (uint16_t*)((uint8_t*)info.lfbPtr + offset_src);
|
|
|
|
ptr += offset_x;
|
|
|
|
for (uint32_t x = 0; x < image_width; x++)
|
|
|
|
{
|
|
|
|
col = *(ptr++);
|
|
|
|
ssimg[sspos++] = (uint8_t)((float)(col >> 11) / 31.0f * 255.0f);
|
|
|
|
ssimg[sspos++] = (uint8_t)((float)((col >> 5) & 0x3F) / 63.0f * 255.0f);
|
|
|
|
ssimg[sspos++] = (uint8_t)((float)(col & 0x1F) / 31.0f * 255.0f);
|
|
|
|
}
|
|
|
|
offset_src += info.strideInBytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Unlock the backbuffer
|
2017-08-04 23:01:05 +00:00
|
|
|
gfxLfbUnlock(GFX_LFB_READ_ONLY, GFX_BUFFER_BACKBUFFER);
|
2017-01-28 19:11:28 +00:00
|
|
|
write_png_file(path, image_width, image_height, ssimg);
|
2017-03-13 09:28:34 +00:00
|
|
|
g_capture_screen = false;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-01-24 19:08:33 +00:00
|
|
|
if (g_settings->fb_read_back_to_screen_enabled())
|
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
DrawWholeFrameBufferToScreen();
|
2017-01-24 19:08:33 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlide64, TraceDebug, "BUFFER SWAPPED");
|
2017-05-25 22:19:03 +00:00
|
|
|
gfxBufferSwap(g_settings->vsync());
|
2016-01-20 17:12:15 +00:00
|
|
|
if (*gfx.VI_STATUS_REG & 0x08) //gamma correction is used
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2016-01-20 17:12:15 +00:00
|
|
|
if (!voodoo.gamma_correction)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
2016-01-20 17:12:15 +00:00
|
|
|
if (voodoo.gamma_table_size && !voodoo.gamma_table_r)
|
|
|
|
GetGammaTable(); //save initial gamma tables
|
2017-07-20 07:47:25 +00:00
|
|
|
gfxGammaCorrectionRGB(2.0f, 2.0f, 2.0f); //with gamma=2.0 gamma table is the same, as in N64
|
2016-01-20 17:12:15 +00:00
|
|
|
voodoo.gamma_correction = 1;
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
2016-01-20 17:12:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (voodoo.gamma_correction)
|
2016-01-20 06:29:27 +00:00
|
|
|
{
|
2016-01-20 17:12:15 +00:00
|
|
|
if (voodoo.gamma_table_r)
|
2017-07-20 07:41:50 +00:00
|
|
|
gfxLoadGammaTable(voodoo.gamma_table_size, voodoo.gamma_table_r, voodoo.gamma_table_g, voodoo.gamma_table_b);
|
2016-01-20 17:12:15 +00:00
|
|
|
else
|
2017-07-20 07:47:25 +00:00
|
|
|
gfxGammaCorrectionRGB(1.3f, 1.3f, 1.3f); //1.3f is default 3dfx gamma for everything but desktop
|
2016-01-20 17:12:15 +00:00
|
|
|
voodoo.gamma_correction = 0;
|
2016-01-20 06:29:27 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 18:18:58 +00:00
|
|
|
if (g_settings->wireframe() || g_settings->buff_clear() || (g_settings->hacks(CSettings::hack_PPL) && g_settings->ucode() == CSettings::ucode_S2DEX))
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
2017-08-09 22:30:58 +00:00
|
|
|
gfxDepthMask((g_settings->hacks(CSettings::hack_RE2) && g_settings->fb_depth_render_enabled()) ? false : true);
|
2017-05-25 22:03:56 +00:00
|
|
|
gfxBufferClear(0, 0, 0xFFFF);
|
2016-01-20 17:12:15 +00:00
|
|
|
}
|
2013-04-04 21:22:19 +00:00
|
|
|
|
2017-01-24 19:08:33 +00:00
|
|
|
if (g_settings->fb_read_back_to_screen2_enabled())
|
2016-01-20 17:12:15 +00:00
|
|
|
{
|
2016-01-20 06:29:27 +00:00
|
|
|
DrawWholeFrameBufferToScreen();
|
2016-01-20 17:12:15 +00:00
|
|
|
}
|
2016-01-20 06:29:27 +00:00
|
|
|
frame_count++;
|
2013-04-04 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: ViStatusChanged
|
|
|
|
Purpose: This function is called to notify the dll that the
|
|
|
|
ViStatus registers value has been changed.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL ViStatusChanged(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: ViWidthChanged
|
|
|
|
Purpose: This function is called to notify the dll that the
|
|
|
|
ViWidth registers value has been changed.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
2016-01-20 06:29:27 +00:00
|
|
|
void CALL ViWidthChanged(void)
|
2013-04-04 21:22:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-10 18:29:41 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
/******************************************************************
|
|
|
|
Function: SurfaceCreated
|
|
|
|
Purpose: this function is called when the surface is created.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
|
|
|
void CALL SurfaceCreated(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Function: SurfaceChanged
|
|
|
|
Purpose: this function is called when the surface is has changed.
|
|
|
|
input: none
|
|
|
|
output: none
|
|
|
|
*******************************************************************/
|
|
|
|
void CALL SurfaceChanged(int width, int height)
|
|
|
|
{
|
2017-04-27 10:24:10 +00:00
|
|
|
g_ScreenWidth = width;
|
|
|
|
g_ScreenHeight = height;
|
2016-03-10 18:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Android_JNI_SwapWindow()
|
|
|
|
{
|
|
|
|
gfx.SwapBuffers();
|
|
|
|
}
|
2017-04-18 11:32:43 +00:00
|
|
|
#endif
|