Fix textures on VC4

This commit is contained in:
Shinovon 2026-04-29 13:17:43 +05:00
parent 3eb71f2cc5
commit d5a130fc29
5 changed files with 78 additions and 31 deletions

View file

@ -17,6 +17,7 @@ LIBRARY eikcore.lib
LIBRARY avkon.lib
LIBRARY ws32.lib
LIBRARY hal.lib
LIBRARY platformver.lib
EPOCSTACKSIZE 0x14000
EPOCHEAPSIZE 0x80000 0x4000000

View file

@ -220,12 +220,15 @@ CStreaming::Init2(void)
// PC only, figure out how much memory we got
#ifdef GTA_PC
#define MB (1024*1024)
// extern size_t _dwMemAvailPhys;
// ms_memoryAvailable = (_dwMemAvailPhys - 10*MB)/2;
// if(ms_memoryAvailable < 50*MB)
// ms_memoryAvailable = 50*MB;
// desiredNumVehiclesLoaded = (int32)((ms_memoryAvailable / MB - 50) / 3 + 12);
#ifdef __SYMBIAN32__
extern bool moreVram;
if (moreVram) {
extern size_t _dwMemAvailPhys;
ms_memoryAvailable = (_dwMemAvailPhys - 10*MB)/2;
if(ms_memoryAvailable < 10*MB)
ms_memoryAvailable = 10*MB;
} else
#endif
ms_memoryAvailable = STREAMING_MEM_SIZE;
desiredNumVehiclesLoaded = 12;
if(desiredNumVehiclesLoaded > MAXVEHICLESLOADED)
@ -2691,9 +2694,14 @@ CStreaming::MakeSpaceFor(int32 size)
#ifdef FIX_BUGS
#define MB (1024 * 1024)
if(ms_memoryAvailable == 0) {
// extern size_t _dwMemAvailPhys;
// ms_memoryAvailable = (_dwMemAvailPhys - 10 * MB) / 2;
// if(ms_memoryAvailable < 50 * MB) ms_memoryAvailable = 50 * MB;
#ifdef __SYMBIAN32__
extern bool moreVram;
if (moreVram) {
extern size_t _dwMemAvailPhys;
ms_memoryAvailable = (_dwMemAvailPhys - 10 * MB) / 2;
if(ms_memoryAvailable < 10 * MB) ms_memoryAvailable = 10 * MB;
} else
#endif
ms_memoryAvailable = STREAMING_MEM_SIZE;
}
#undef MB

View file

@ -28,6 +28,7 @@
float texLoadTime;
int32 texNumLoaded;
#ifdef __SYMBIAN32__
static RwImage* resizeImage(RwImage *image, int newWidth, int newHeight)
{
image->convertTo32();
@ -84,9 +85,9 @@ static RwImage* resizeImage(RwImage *image, int newWidth, int newHeight)
}
static int clamp(int32 size)
static int clamp(int size, int targetSize)
{
while (size > 32 && size > 1) {
while (size > targetSize && size > 1) {
size = (size + 1) / 2;
}
return size;
@ -98,12 +99,15 @@ static void downscaleTexture(RwTexture *texture)
if (oldRaster == nil)
return;
extern bool moreVram;
int targetSize = moreVram ? 64 : 32;
int oldWidth = RwRasterGetWidth(oldRaster);
int oldHeight = RwRasterGetHeight(oldRaster);
if (oldWidth <= 32 && oldHeight <= 32) return;
if (oldWidth <= targetSize && oldHeight <= targetSize) return;
int newWidth = clamp(oldWidth);
int newHeight = clamp(oldHeight);
int newWidth = clamp(oldWidth, targetSize);
int newHeight = clamp(oldHeight, targetSize);
if (newWidth == oldWidth && newHeight == oldHeight) return;
RwImage *image = oldRaster->toImage();
@ -120,6 +124,7 @@ static void downscaleTexture(RwTexture *texture)
RwTextureSetRaster(texture, newRaster);
RwRasterDestroy(oldRaster);
}
#endif
#ifdef LIBRW
#define READNATIVE(stream, tex, size) rwNativeTextureHackRead(stream, tex, size)
@ -490,11 +495,13 @@ CreateTxdImageForVideoCard()
sprintf(filename, "%s.txd", CTxdStore::GetTxdName(i));
if (CTxdStore::GetSlot(i)->texDict) {
#ifdef __SYMBIAN32__
RwTexDictionary *texDict = CTxdStore::GetSlot(i)->texDict;
FORLIST(lnk, texDict->textures){
rw::Texture *texture = rw::Texture::fromDict(lnk);
downscaleTexture(texture);
}
#endif
int32 pos = STREAMTELL(img);
if (RwTexDictionaryStreamWrite(CTxdStore::GetSlot(i)->texDict, img) == nil) {

View file

@ -12,6 +12,7 @@
#include <gles2/gl2.h>
#include <EGL/egl.h>
#include <locale.h>
#include <versioninfo.h>
#include "common.h"
#include "rwcore.h"
@ -74,6 +75,10 @@ static psGlobalType PsGlobal;
static TBool foreground;
bool moreVram;
static bool spinning;
void _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) {
}
@ -82,6 +87,18 @@ const char* _psGetUserFilesFolder() {
}
void HandleExit() {
if (IsForegroundApp()) {
User::ResetInactivityTime();
}
RThread thread;
TInt error = KErrNone;
spinning = true;
while (thread.RequestCount()) {
if (!CActiveScheduler::RunIfReady(error, CActive::EPriorityIdle))
continue;
User::WaitForAnyRequest();
}
spinning = false;
}
RwInt32 _psGetNumVideModes() {
@ -178,17 +195,14 @@ void psTerminate(void) {
RwBool psInitialize(void) {
CFileMgr::Initialise();
TInt memFree = 0;
if (HAL::Get(HALData::EMemoryRAMFree, memFree) == KErrNone) {
if (memFree > 40 * 1024 * 1024) {
_dwMemAvailPhys = 40 * 1024 * 1024;
} else if (memFree <= 0) {
HAL::Get(HALData::EMemoryRAMFree, memFree);
if (memFree <= 0) {
_dwMemAvailPhys = 10 * 1024 * 1024;
} else if (memFree > 60 * 1024 * 1024) {
_dwMemAvailPhys = 60 * 1024 * 1024;
} else {
_dwMemAvailPhys = memFree;
}
} else {
_dwMemAvailPhys = 40 * 1024 * 1024;
}
C_PcSave::SetSaveDirectory(_psGetUserFilesFolder());
@ -240,6 +254,8 @@ public:
return EFalse;
}
if (spinning) return ETrue;
switch (container->gGameState) {
case GS_START_UP:
foreground = true;
@ -311,18 +327,24 @@ public:
void RestartTimerL(TInt aInterval) {
if (iPeriodic) iPeriodic->Cancel();
else iPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
else iPeriodic = CPeriodic::NewL(CActive::EPriorityLow);
iPeriodic->Start(aInterval, aInterval, TCallBack(CCContainer::LoopCallBack, this));
}
void ConstructL(const TRect& aRect, CAknAppUi* aAppUi) {
iAppUi = aAppUi;
CreateWindowL();
iAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
SetExtentToWholeScreen();
Window().EnableAdvancedPointers();
EnableDragEvents();
ActivateL();
// VC4 check
VersionInfo::TPlatformVersion platformVersion;
VersionInfo::GetVersion(platformVersion);
moreVram = platformVersion.iMajorVersion == 5 && platformVersion.iMinorVersion >= 4;
TSize size = Size();
RsGlobal.width = size.iWidth;
RsGlobal.height = size.iHeight;
@ -524,6 +546,7 @@ public:
void HandleCommandL(TInt aCommand) {
if (aCommand == EAknSoftkeyBack || aCommand == EEikCmdExit) {
RsGlobal.quit = 1;
// Exit();
}
}
};

View file

@ -16,6 +16,10 @@
#define PLUGIN_ID ID_DRIVER
#ifdef __SYMBIAN32__
extern bool moreVram;
#endif
namespace rw {
namespace gl3 {
@ -202,7 +206,6 @@ rasterCreateCameraTexture(Raster *raster)
break;
}
// i don't remember why this was once here...
if(gl3Caps.gles){
natras->internalFormat = natras->format;
}
@ -609,8 +612,11 @@ rasterUnlock(Raster *raster, int32 level)
natras->backingStore->levels[level].size);
}
}else{
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE) {
if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE
#ifdef __SYMBIAN32__
&& !moreVram
#endif
) {
// convert to 16-bit
uint16_t* pixels16 = (uint16_t*)malloc(raster->width * raster->height * sizeof(uint16_t));
uint8_t* pixels8 = (uint8_t*)raster->pixels;
@ -625,14 +631,16 @@ rasterUnlock(Raster *raster, int32 level)
}
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, raster->width, raster->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels16);
free(pixels16);
} else {
} else
{
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat,
raster->width, raster->height,
0, natras->format, natras->type, raster->pixels);
}
}
if(level == 0 && natras->autogenMipmap)
glGenerateMipmap(GL_TEXTURE_2D);
// if(level == 0 && natras->autogenMipmap)
// glGenerateMipmap(GL_TEXTURE_2D);
bindTexture(prev);
}
break;