summaryrefslogtreecommitdiff
path: root/src/rw/TexRead.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rw/TexRead.cpp')
-rw-r--r--src/rw/TexRead.cpp108
1 files changed, 104 insertions, 4 deletions
diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp
index 5dde20dd..d0addcca 100644
--- a/src/rw/TexRead.cpp
+++ b/src/rw/TexRead.cpp
@@ -18,6 +18,7 @@
#include "Sprite2d.h"
#include "Text.h"
#include "RwHelper.h"
+#include "Frontend.h"
#endif //GTA_PC
float texLoadTime;
@@ -150,11 +151,80 @@ RwTexDictionaryGtaStreamRead2(RwStream *stream, RwTexDictionary *texDict)
}
#ifdef GTA_PC
-#ifdef RWLIBS
-extern "C" RwInt32 _rwD3D8FindCorrectRasterFormat(RwRasterType type, RwInt32 flags);
-#else
-RwInt32 _rwD3D8FindCorrectRasterFormat(RwRasterType type, RwInt32 flags);
+
+#ifdef LIBRW
+
+#define CAPSVERSION 0
+
+struct GPUcaps
+{
+ uint32 version; // so we can force regeneration easily
+ uint32 platform;
+ uint32 subplatform;
+ uint32 dxtSupport;
+};
+
+static void
+GetGPUcaps(GPUcaps *caps)
+{
+ caps->version = CAPSVERSION;
+ caps->platform = rw::platform;
+ caps->subplatform = 0;
+ caps->dxtSupport = 0;
+ // TODO: more later
+#ifdef RW_GL3
+ caps->subplatform = rw::gl3::gl3Caps.gles;
+ caps->dxtSupport = rw::gl3::gl3Caps.dxtSupported;
+#endif
+#ifdef RW_D3D9
+ caps->dxtSupport = 1; // TODO, probably
#endif
+}
+
+void
+ReadVideoCardCapsFile(GPUcaps *caps)
+{
+ memset(caps, 0, sizeof(GPUcaps));
+
+ int32 file = CFileMgr::OpenFile("DATA\\CAPS.DAT", "rb");
+ if (file != 0) {
+ CFileMgr::Read(file, (char*)&caps->version, 4);
+ CFileMgr::Read(file, (char*)&caps->platform, 4);
+ CFileMgr::Read(file, (char*)&caps->subplatform, 4);
+ CFileMgr::Read(file, (char*)&caps->dxtSupport, 4);
+ CFileMgr::CloseFile(file);
+ }
+}
+
+bool
+CheckVideoCardCaps(void)
+{
+ GPUcaps caps, fcaps;
+ GetGPUcaps(&caps);
+ ReadVideoCardCapsFile(&fcaps);
+ return caps.version != fcaps.version ||
+ caps.platform != fcaps.platform ||
+ caps.subplatform != fcaps.subplatform ||
+ caps.dxtSupport != fcaps.dxtSupport;
+}
+
+void
+WriteVideoCardCapsFile(void)
+{
+ GPUcaps caps;
+ GetGPUcaps(&caps);
+ int32 file = CFileMgr::OpenFile("DATA\\CAPS.DAT", "wb");
+ if (file != 0) {
+ CFileMgr::Write(file, (char*)&caps.version, 4);
+ CFileMgr::Write(file, (char*)&caps.platform, 4);
+ CFileMgr::Write(file, (char*)&caps.subplatform, 4);
+ CFileMgr::Write(file, (char*)&caps.dxtSupport, 4);
+ CFileMgr::CloseFile(file);
+ }
+}
+
+#else
+extern "C" RwInt32 _rwD3D8FindCorrectRasterFormat(RwRasterType type, RwInt32 flags);
void
ReadVideoCardCapsFile(uint32 &cap32, uint32 &cap24, uint32 &cap16, uint32 &cap8)
{
@@ -201,6 +271,7 @@ WriteVideoCardCapsFile(void)
CFileMgr::CloseFile(file);
}
}
+#endif
void
ConvertingTexturesScreen(uint32 num, uint32 count, const char *text)
@@ -282,6 +353,22 @@ CreateTxdImageForVideoCard()
return false;
}
+#ifdef RW_GL3
+ // so we can read back DXT with GLES
+ // only works for textures that are not yet loaded
+ // so let's hope that is the case for all
+ rw::gl3::needToReadBackTextures = true;
+#endif
+
+#ifdef DISABLE_VSYNC_ON_TEXTURE_CONVERSION
+ // let's disable vsync and frame limiter to speed up texture conversion
+ // (actually we probably don't need to disable frame limiter in here, but let's do it just in case =P)
+ int8 vsyncState = CMenuManager::m_PrefsVsync;
+ int8 frameLimiterState = CMenuManager::m_PrefsFrameLimiter;
+ CMenuManager::m_PrefsVsync = 0;
+ CMenuManager::m_PrefsFrameLimiter = 0;
+#endif
+
int32 i;
for (i = 0; i < TXDSTORESIZE; i++) {
ConvertingTexturesScreen(i, TXDSTORESIZE, "CVT_MSG");
@@ -309,6 +396,9 @@ CreateTxdImageForVideoCard()
delete []buf;
delete pDir;
CStreaming::RemoveTxd(i);
+#ifdef RW_GL3
+ rw::gl3::needToReadBackTextures = false;
+#endif
return false;
}
@@ -332,9 +422,19 @@ CreateTxdImageForVideoCard()
}
}
+#ifdef DISABLE_VSYNC_ON_TEXTURE_CONVERSION
+ // restore vsync and frame limiter states
+ CMenuManager::m_PrefsVsync = vsyncState;
+ CMenuManager::m_PrefsFrameLimiter = frameLimiterState;
+#endif
+
RwStreamClose(img, nil);
delete []buf;
+#ifdef RW_GL3
+ rw::gl3::needToReadBackTextures = false;
+#endif
+
if (!pDir->WriteDirFile("models\\txd.dir")) {
DealWithTxdWriteError(i, TXDSTORESIZE, "CVT_ERR");
delete pDir;