Skip to content

Commit

Permalink
Add texture remastering
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jan 13, 2017
1 parent b8e97f8 commit df71de3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 1
#define TBF_BUILD 1
#define TBF_BUILD 2
#define TBF_REV 0


Expand Down
4 changes: 2 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ TBF_LoadConfig (std::wstring name)

render.rescale_shadows->load (config.render.shadow_rescale);

//textures.remaster->load (config.textures.remaster);
textures.remaster->load (config.textures.remaster);
textures.cache->load (config.textures.cache);
textures.dump->load (config.textures.dump);
textures.cache_size->load (config.textures.max_cache_in_mib);
Expand Down Expand Up @@ -331,7 +331,7 @@ TBF_SaveConfig (std::wstring name, bool close_config)

render.rescale_shadows->store (config.render.shadow_rescale);

//textures.remaster->store (config.textures.remaster);
textures.remaster->store (config.textures.remaster);
textures.cache->store (config.textures.cache);
textures.dump->store (config.textures.dump);
textures.cache_size->store (config.textures.max_cache_in_mib);
Expand Down
62 changes: 31 additions & 31 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ int draw_count = 0;
int next_draw = 0;
int scene_count = 0;

std::string mod_text;

COM_DECLSPEC_NOTHROW
HRESULT
STDMETHODCALLTYPE
Expand Down Expand Up @@ -531,6 +533,33 @@ D3D9EndScene_Detour (IDirect3DDevice9* This)
}
#endif

typedef BOOL (__stdcall *SKX_DrawExternalOSD_pfn)(const char* szAppName, const char* szText);

static HMODULE hMod =
GetModuleHandle (config.system.injector.c_str ());
static SKX_DrawExternalOSD_pfn SKX_DrawExternalOSD
=
(SKX_DrawExternalOSD_pfn)GetProcAddress (hMod, "SKX_DrawExternalOSD");

extern bool __show_cache;

if (__show_cache) {
static std::string output;

output = "Texture Cache\n";
output += "-------------\n";
output += tbf::RenderFix::tex_mgr.osdStats ();

output += mod_text;

SKX_DrawExternalOSD ("ToBFix", output.c_str ());

output = "";
} else
SKX_DrawExternalOSD ("ToBFix", mod_text.c_str ());

mod_text = "";

HRESULT hr = D3D9EndScene_Original (This);

extern bool pending_loads (void);
Expand Down Expand Up @@ -570,8 +599,6 @@ D3D9EndFrame_Pre (void)
return SK_BeginBufferSwap ();
}

std::string mod_text;

COM_DECLSPEC_NOTHROW
HRESULT
STDMETHODCALLTYPE
Expand All @@ -581,12 +608,12 @@ D3D9EndFrame_Post (HRESULT hr, IUnknown* device)
if (device != tbf::RenderFix::pDevice)
return SK_EndBufferSwap (hr, device);

tbf::RenderFix::draw_state.cegui_active = false;

scene_count = 0;

tbf::RenderFix::dwRenderThreadID = GetCurrentThreadId ();

tbf::RenderFix::draw_state.cegui_active = false;

hr = SK_EndBufferSwap (hr, device);

extern bool pending_loads (void);
Expand All @@ -598,33 +625,6 @@ D3D9EndFrame_Post (HRESULT hr, IUnknown* device)
//if (config.framerate.minimize_latency)
//tbf::FrameRateFix::RenderTick ();

typedef BOOL (__stdcall *SKX_DrawExternalOSD_pfn)(const char* szAppName, const char* szText);

static HMODULE hMod =
GetModuleHandle (config.system.injector.c_str ());
static SKX_DrawExternalOSD_pfn SKX_DrawExternalOSD
=
(SKX_DrawExternalOSD_pfn)GetProcAddress (hMod, "SKX_DrawExternalOSD");

extern bool __show_cache;

if (__show_cache) {
static std::string output;

output = "Texture Cache\n";
output += "-------------\n";
output += tbf::RenderFix::tex_mgr.osdStats ();

output += mod_text;

SKX_DrawExternalOSD ("ToBFix", output.c_str ());

output = "";
} else
SKX_DrawExternalOSD ("ToBFix", mod_text.c_str ());

mod_text = "";

return hr;
}

Expand Down
14 changes: 10 additions & 4 deletions src/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,14 +1755,20 @@ D3DXCreateTextureFromFileInMemoryEx_Detour (
// Generate complete mipmap chains for best image quality
// (will increase load-time on uncached textures)
if ((Pool == D3DPOOL_DEFAULT) && config.textures.remaster) {
if (Format == D3DFMT_DXT1 ||
Format == D3DFMT_DXT3 ||
Format == D3DFMT_DXT5)
if (Width >= 128 && Height >= 128) {
D3DXIMAGE_INFO info = { 0 };
D3DXGetImageInfoFromFileInMemory (pSrcData, SrcDataSize, &info);

D3DFORMAT fmt_real = info.Format;

if (true) {//fmt_real == D3DFMT_DXT1 ||
//fmt_real == D3DFMT_DXT3 ||
//fmt_real == D3DFMT_DXT5) {
if (/*info.Width >= 128 && info.Height >= 128 && */info.MipLevels == 3) {
// Don't resample faces
if ( resample_blacklist.count (checksum) == 0 )
resample = true;
}
}
}

HRESULT hr = E_FAIL;
Expand Down
Binary file modified tbf.VC.db
Binary file not shown.
Binary file modified version.ini
Binary file not shown.

0 comments on commit df71de3

Please sign in to comment.