1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Enable texture dump.

Currently Windows only.
Press 'd' to toggle texture dump on/off
Press 'r' to reload texture cache

Fixed issue #255
This commit is contained in:
Sergey Lipskiy 2015-04-12 18:49:40 +06:00
parent f3e09bc296
commit 74f8e444a0
9 changed files with 285 additions and 11 deletions

View File

@ -24,6 +24,7 @@ set(GLideN64_SOURCES
GLSLCombiner.cpp
glState.cpp
gSP.cpp
Keys.cpp
L3D.cpp
L3DEX2.cpp
L3DEX.cpp

View File

@ -269,6 +269,7 @@
<ClCompile Include="GLideN64.cpp" />
<ClCompile Include="glState.cpp" />
<ClCompile Include="gSP.cpp" />
<ClCompile Include="Keys.cpp" />
<ClCompile Include="MupenPlusPluginAPI.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@ -358,6 +359,7 @@
<ClInclude Include="GLideN64.h" />
<ClInclude Include="GLideNHQ\Ext_TxFilter.h" />
<ClInclude Include="gSP.h" />
<ClInclude Include="Keys.h" />
<ClInclude Include="Log.h" />
<ClInclude Include="mupenplus\GLideN64_mupenplus.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>

View File

@ -195,6 +195,9 @@
<ClCompile Include="Config.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Keys.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="3DMath.h">
@ -341,6 +344,9 @@
<ClInclude Include="PostProcessor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Keys.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc">

View File

@ -888,7 +888,7 @@
<item>
<widget class="QCheckBox" name="textureDumpCheckBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Texture dumping mode:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;In this mode, you have that ability to dump textures on screen to the appropriate folder. You can also reload textures while the game is running to see how they look instantly - big time saver!&lt;/p&gt;&lt;p&gt;Hotkeys: &lt;span style=&quot; font-weight:600;&quot;&gt;R&lt;/span&gt; reloads hires textures from the texture pack - &lt;span style=&quot; font-weight:600;&quot;&gt;D&lt;/span&gt; toggles texture dumps on/off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -1386,10 +1386,10 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="bloomBlendModeButtonGroup"/>
<buttongroup name="bilinearButtonGroup"/>
<buttongroup name="screenshotButtonGroup"/>
<buttongroup name="aspectButtonGroup"/>
<buttongroup name="bloomBlendModeButtonGroup"/>
<buttongroup name="screenshotButtonGroup"/>
<buttongroup name="bilinearButtonGroup"/>
<buttongroup name="validityCheckMethodButtonGroup"/>
</buttongroups>
</ui>

125
Keys.cpp Normal file
View File

@ -0,0 +1,125 @@
/*
* Glide64 - Glide video plugin for Nintendo 64 emulators.
* Copyright (c) 2002 Dave2001
* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
*
* 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
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//****************************************************************
//
// Glide64 - Glide Plugin for Nintendo 64 emulators
// Project started on December 29th, 2001
//
// Authors:
// Dave2001, original author, founded the project in 2001, left it in 2002
// Gugaman, joined the project in 2002, left it in 2002
// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
// Hiroshi 'KoolSmoky' Morii, joined the project in 2007
//
//****************************************************************
//
// To modify Glide64:
// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
//
//****************************************************************
//
// Keys, used by Glide64.
// Since key codes are different for WinAPI and SDL, this difference is managed here
// Created by Sergey 'Gonetz' Lipski, July 2009
//
//****************************************************************
#include "OpenGL.h"
#include "Keys.h"
Glide64Keys::Glide64Keys()
{
#ifdef OS_WINDOWS
m_keys[G64_VK_CONTROL] = 0x11;
m_keys[G64_VK_ALT] = 0x12;
m_keys[G64_VK_INSERT] = 0x2D;
m_keys[G64_VK_LBUTTON] = 0x01;
m_keys[G64_VK_UP] = 0x26;
m_keys[G64_VK_DOWN] = 0x28;
m_keys[G64_VK_LEFT] = 0x25;
m_keys[G64_VK_RIGHT] = 0x27;
m_keys[G64_VK_SPACE] = 0x20;
m_keys[G64_VK_BACK] = 0x08;
m_keys[G64_VK_SCROLL] = 0x91;
m_keys[G64_VK_1] = 0x31;
m_keys[G64_VK_2] = 0x32;
m_keys[G64_VK_3] = 0x33;
m_keys[G64_VK_4] = 0x34;
m_keys[G64_VK_5] = 0x35;
m_keys[G64_VK_6] = 0x36;
m_keys[G64_VK_7] = 0x37;
m_keys[G64_VK_8] = 0x38;
m_keys[G64_VK_9] = 0x39;
m_keys[G64_VK_0] = 0x30;
m_keys[G64_VK_A] = 0x41;
m_keys[G64_VK_B] = 0x42;
m_keys[G64_VK_D] = 0x44;
m_keys[G64_VK_G] = 0x47;
m_keys[G64_VK_Q] = 0x51;
m_keys[G64_VK_R] = 0x52;
m_keys[G64_VK_S] = 0x53;
m_keys[G64_VK_V] = 0x56;
m_keys[G64_VK_W] = 0x57;
#else
m_keys[G64_VK_CONTROL] = 306;
m_keys[G64_VK_ALT] = 308;
m_keys[G64_VK_INSERT] = 277;
m_keys[G64_VK_LBUTTON] = 1;
m_keys[G64_VK_UP] = 273;
m_keys[G64_VK_DOWN] = 274;
m_keys[G64_VK_LEFT] = 276;
m_keys[G64_VK_RIGHT] = 275;
m_keys[G64_VK_SPACE] = 32;
m_keys[G64_VK_BACK] = 8;
m_keys[G64_VK_SCROLL] = 302;
m_keys[G64_VK_1] = 49;
m_keys[G64_VK_2] = 50;
m_keys[G64_VK_3] = 51;
m_keys[G64_VK_4] = 52;
m_keys[G64_VK_5] = 53;
m_keys[G64_VK_6] = 54;
m_keys[G64_VK_7] = 55;
m_keys[G64_VK_8] = 56;
m_keys[G64_VK_9] = 57;
m_keys[G64_VK_0] = 48;
m_keys[G64_VK_A] = 97;
m_keys[G64_VK_B] = 98;
m_keys[G64_VK_D] = 100;
m_keys[G64_VK_G] = 103;
m_keys[G64_VK_Q] = 113;
m_keys[G64_VK_R] = 114;
m_keys[G64_VK_S] = 115;
m_keys[G64_VK_V] = 118;
m_keys[G64_VK_W] = 119;
#endif
}
bool isKeyPressed(int _key, int _mask)
{
static Glide64Keys g64Keys;
#ifdef OS_WINDOWS
return (GetAsyncKeyState(g64Keys[_key]) & _mask);
#else
// TODO
#endif
return 0;
}

95
Keys.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Glide64 - Glide video plugin for Nintendo 64 emulators.
* Copyright (c) 2002 Dave2001
* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
*
* 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
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//****************************************************************
//
// Glide64 - Glide Plugin for Nintendo 64 emulators
// Project started on December 29th, 2001
//
// Authors:
// Dave2001, original author, founded the project in 2001, left it in 2002
// Gugaman, joined the project in 2002, left it in 2002
// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
// Hiroshi 'KoolSmoky' Morii, joined the project in 2007
//
//****************************************************************
//
// To modify Glide64:
// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
//
//****************************************************************
//
// Keys, used by Glide64.
// Since key codes are different for WinAPI and SDL, this difference is managed here
// Created by Sergey 'Gonetz' Lipski, July 2009
//
//****************************************************************
#ifndef Keys_H
#define Keys_H
#define G64_VK_CONTROL 0
#define G64_VK_ALT 1
#define G64_VK_INSERT 2
#define G64_VK_LBUTTON 3
#define G64_VK_UP 4
#define G64_VK_DOWN 5
#define G64_VK_LEFT 6
#define G64_VK_RIGHT 7
#define G64_VK_SPACE 8
#define G64_VK_BACK 9
#define G64_VK_SCROLL 10
#define G64_VK_1 11
#define G64_VK_2 12
#define G64_VK_3 13
#define G64_VK_4 14
#define G64_VK_5 15
#define G64_VK_6 16
#define G64_VK_7 17
#define G64_VK_8 18
#define G64_VK_9 19
#define G64_VK_0 20
#define G64_VK_A 21
#define G64_VK_B 22
#define G64_VK_D 23
#define G64_VK_G 24
#define G64_VK_Q 25
#define G64_VK_R 26
#define G64_VK_S 27
#define G64_VK_V 28
#define G64_VK_W 29
#define G64_NUM_KEYS 30
class Glide64Keys
{
public:
Glide64Keys();
~Glide64Keys(){}
int operator[](unsigned int index){return m_keys[index];}
private:
int m_keys[G64_NUM_KEYS];
};
bool isKeyPressed(int _key, int _mask);
#endif //Keys_H

View File

@ -227,6 +227,7 @@ void initGLFunctions();
bool checkFBO();
bool isGLError();
void displayLoadProgress(const wchar_t *format, ...);
void GHQ_init();
#endif

View File

@ -1,6 +1,8 @@
#include <assert.h>
#include <memory.h>
#include <algorithm>
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
#include "OpenGL.h"
#include "Textures.h"
#include "GBI.h"
@ -11,6 +13,7 @@
#include "convert.h"
#include "FrameBuffer.h"
#include "Config.h"
#include "Keys.h"
#include "GLideNHQ/Ext_TxFilter.h"
using namespace std;
@ -767,7 +770,7 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
free(pDest);
}
bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture)
bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc)
{
if (config.textureFilter.txHiresEnable == 0 || !TFH.isInited())
return false;
@ -808,20 +811,22 @@ bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture)
// palette = (rdp.pal_8 + (gSP.textureTile[_t]->palette << 4));
}
u64 ricecrc = txfilter_checksum(addr, tile_width, tile_height, (unsigned short)(_pTexture->format << 8 | _pTexture->size), bpl, paladdr);
_ricecrc = txfilter_checksum(addr, tile_width, tile_height, (unsigned short)(_pTexture->format << 8 | _pTexture->size), bpl, paladdr);
GHQTexInfo ghqTexInfo;
if (txfilter_hirestex(_pTexture->crc, ricecrc, palette, &ghqTexInfo)) {
if (txfilter_hirestex(_pTexture->crc, _ricecrc, palette, &ghqTexInfo)) {
glTexImage2D(GL_TEXTURE_2D, 0, ghqTexInfo.format, ghqTexInfo.width, ghqTexInfo.height, 0, ghqTexInfo.texture_format, ghqTexInfo.pixel_type, ghqTexInfo.data);
assert(!isGLError());
_updateCachedTexture(ghqTexInfo, _pTexture);
return true;
}
return false;
}
void TextureCache::_load(u32 _tile, CachedTexture *_pTexture)
{
if (_loadHiresTexture(_tile, _pTexture))
u64 ricecrc = 0;
if (_loadHiresTexture(_tile, _pTexture, ricecrc))
return;
u32 *pDest;
@ -959,7 +964,10 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture)
}
bool bLoaded = false;
if ((config.textureFilter.txEnhancementMode | config.textureFilter.txFilterMode) != 0 && maxLevel == 0 && (config.textureFilter.txFilterIgnoreBG == 0 || (RSP.cmd != G_TEXRECT && RSP.cmd != G_TEXRECTFLIP)) && TFH.isInited())
if (m_toggleDumpTex && config.textureFilter.txHiresEnable != 0 && config.textureFilter.txDump != 0) {
txfilter_dmptx((u8*)pDest, tmptex.realWidth, tmptex.realHeight, tmptex.realWidth, glInternalFormat, (unsigned short)(_pTexture->format << 8 | _pTexture->size), ricecrc);
}
else if ((config.textureFilter.txEnhancementMode | config.textureFilter.txFilterMode) != 0 && maxLevel == 0 && (config.textureFilter.txFilterIgnoreBG == 0 || (RSP.cmd != G_TEXRECT && RSP.cmd != G_TEXRECTFLIP)) && TFH.isInited())
{
GHQTexInfo ghqTexInfo;
if (txfilter_filter((u8*)pDest, tmptex.realWidth, tmptex.realHeight, glInternalFormat, (uint64)_pTexture->crc, &ghqTexInfo) != 0 && ghqTexInfo.data != NULL) {
@ -1186,6 +1194,17 @@ void TextureCache::_updateBackground()
current[0] = pCurrent;
}
void TextureCache::_clear()
{
current[0] = current[1] = NULL;
for (Textures::const_iterator cur = m_textures.cbegin(); cur != m_textures.cend(); ++cur) {
m_cachedBytes -= cur->second.textureBytes;
glDeleteTextures(1, &cur->second.glName);
}
m_textures.clear();
}
static
void _updateShiftScale(u32 _t, CachedTexture *_pTexture)
{
@ -1205,6 +1224,29 @@ void _updateShiftScale(u32 _t, CachedTexture *_pTexture)
void TextureCache::update(u32 _t)
{
if (config.textureFilter.txHiresEnable != 0 && config.textureFilter.txDump != 0) {
/* Force reload hi-res textures. Useful for texture artists */
if (isKeyPressed(G64_VK_R, 0x0001)) {
if (txfilter_reloadhirestex()) {
_clear();
}
}
/* Turn on texture dump */
else if (isKeyPressed(G64_VK_D, 0x0001)) {
m_toggleDumpTex = !m_toggleDumpTex;
if (m_toggleDumpTex) {
displayLoadProgress(L"Texture dump - ON\n");
_clear();
std::this_thread::sleep_for(std::chrono::seconds(1));
}
else {
displayLoadProgress(L"Texture dump - OFF\n");
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
}
switch(gSP.textureTile[_t]->textureMode) {
case TEXTUREMODE_BGIMAGE:
_updateBackground();

View File

@ -61,7 +61,7 @@ struct TextureCache
static TextureCache & get();
private:
TextureCache() : m_pDummy(NULL), m_hits(0), m_misses(0), m_maxBytes(0), m_cachedBytes(0), m_curUnpackAlignment(4)
TextureCache() : m_pDummy(NULL), m_hits(0), m_misses(0), m_maxBytes(0), m_cachedBytes(0), m_curUnpackAlignment(4), m_toggleDumpTex(false)
{
current[0] = NULL;
current[1] = NULL;
@ -72,10 +72,11 @@ private:
void _checkCacheSize();
CachedTexture * _addTexture(u32 _crc32);
void _load(u32 _tile, CachedTexture *_pTexture);
bool _loadHiresTexture(u32 _tile, CachedTexture *_pTexture);
bool _loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc);
void _loadBackground(CachedTexture *pTexture);
bool _loadHiresBackground(CachedTexture *_pTexture);
void _updateBackground();
void _clear();
typedef std::map<u32, CachedTexture> Textures;
Textures m_textures;
@ -85,6 +86,7 @@ private:
u32 m_maxBytes;
u32 m_cachedBytes;
GLint m_curUnpackAlignment;
bool m_toggleDumpTex;
};
inline TextureCache & textureCache()