fixed bug with texture allocation

This commit is contained in:
aap
2015-09-19 19:28:23 +02:00
parent ee96da332f
commit 3c0df895f1
19 changed files with 380 additions and 273 deletions

View File

@ -15,10 +15,10 @@ main(int argc, char *argv[])
{
gta::attachPlugins();
// rw::version = 0x33002;
rw::platform = rw::PLATFORM_PS2;
rw::version = 0x34003;
// rw::platform = rw::PLATFORM_PS2;
// rw::platform = rw::PLATFORM_OGL;
// rw::platform = rw::PLATFORM_XBOX;
rw::platform = rw::PLATFORM_XBOX;
// rw::platform = rw::PLATFORM_D3D8;
// rw::platform = rw::PLATFORM_D3D9;
@ -32,7 +32,7 @@ main(int argc, char *argv[])
if(strcmp(argv[arg], "-u") == 0){
uninstance++;
arg++;
arg++;
if(argc < 3){
printf("usage: %s [-u] in.dff\n", argv[0]);
return 0;
@ -82,6 +82,9 @@ main(int argc, char *argv[])
p->instance(a);
}
if(uninstance)
rw::platform = rw::PLATFORM_D3D8;
data = new rw::uint8[1024*1024];
rw::StreamMemory out;
out.open(data, 0, 1024*1024);
@ -89,7 +92,11 @@ main(int argc, char *argv[])
currentUVAnimDictionary->streamWrite(&out);
c->streamWrite(&out);
FILE *cf = fopen("out.dff", "wb");
FILE *cf;
if(arg+1 < argc)
cf = fopen(argv[arg+1], "wb");
else
cf = fopen("out.dff", "wb");
assert(cf != NULL);
fwrite(data, out.getLength(), 1, cf);
fclose(cf);

View File

@ -81,11 +81,15 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>librw.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy /y "$(TargetPath)" "C:\Users\aap\bin\"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>

View File

@ -10,15 +10,67 @@
using namespace std;
using namespace rw;
Raster*
xboxToD3d8(Raster *raster)
{
using namespace xbox;
Raster *newras;
if(raster->platform != PLATFORM_XBOX)
return raster;
XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
int32 numLevels = raster->getNumLevels();
int32 format = raster->format;
// format &= ~Raster::MIPMAP;
if(ras->format){
newras = new Raster(raster->width, raster->height, raster->depth,
format | raster->type | 0x80, PLATFORM_D3D8);
int32 dxt = 0;
switch(ras->format){
case D3DFMT_DXT1:
dxt = 1;
break;
case D3DFMT_DXT3:
dxt = 3;
break;
case D3DFMT_DXT5:
dxt = 5;
break;
}
d3d::allocateDXT(newras, dxt, numLevels, ras->hasAlpha);
}else{
printf("swizzled!\n");
newras = new Raster(raster->width, raster->height, raster->depth,
format | raster->type, PLATFORM_D3D8);
}
if(raster->format & Raster::PAL4)
d3d::setPalette(newras, ras->palette, 32);
else if(raster->format & Raster::PAL8)
d3d::setPalette(newras, ras->palette, 256);
uint8 *data;
for(int32 i = 0; i < numLevels; i++){
if(i >= newras->getNumLevels())
break;
data = raster->lock(i);
d3d::setTexels(newras, data, i);
raster->unlock(i);
}
delete raster;
return newras;
}
int
main(int argc, char *argv[])
{
gta::attachPlugins();
rw::ps2::registerNativeRaster();
rw::xbox::registerNativeRaster();
rw::d3d::registerNativeRaster();
// rw::version = 0x33002;
rw::version = 0x32000;
// rw::platform = rw::PLATFORM_PS2;
// rw::platform = rw::PLATFORM_OGL;
// rw::platform = rw::PLATFORM_XBOX;
@ -32,7 +84,7 @@ main(int argc, char *argv[])
rw::StreamFile in;
if(in.open(argv[1], "rb") == NULL){
printf("couldn't open file\n");
printf("couldn't open file %s\n", argv[1]);
return 1;
}
rw::findChunk(&in, rw::ID_TEXDICTIONARY, NULL, NULL);
@ -42,8 +94,16 @@ main(int argc, char *argv[])
in.close();
rw::currentTexDictionary = txd;
// for(Texture *tex = txd->first; tex; tex = tex->next)
// tex->raster = xboxToD3d8(tex->raster);
for(Texture *tex = txd->first; tex; tex = tex->next)
tex->filterAddressing = (tex->filterAddressing&~0xF) | 0x2;
rw::StreamFile out;
out.open("out.txd", "wb");
if(argc > 2)
out.open(argv[2], "wb");
else
out.open("out.txd", "wb");
txd->streamWrite(&out);
out.close();