texture changes

This commit is contained in:
aap 2016-07-21 08:59:06 +02:00
parent 069c66b699
commit 0b5498c060
9 changed files with 57 additions and 46 deletions

View File

@ -513,7 +513,6 @@ readNativeTexture(Stream *stream)
pallength = format & Raster::PAL4 ? 32 : 256; pallength = format & Raster::PAL4 ? 32 : 256;
if(!d3d::isP8supported){ if(!d3d::isP8supported){
tex->raster = readAsImage(stream, width, height, depth, format|type, numLevels); tex->raster = readAsImage(stream, width, height, depth, format|type, numLevels);
Texture::s_plglist.streamRead(stream, tex);
return tex; return tex;
} }
} }
@ -547,7 +546,6 @@ readNativeTexture(Stream *stream)
}else }else
stream->seek(size); stream->seek(size);
} }
Texture::s_plglist.streamRead(stream, tex);
return tex; return tex;
} }
@ -555,9 +553,7 @@ void
writeNativeTexture(Texture *tex, Stream *stream) writeNativeTexture(Texture *tex, Stream *stream)
{ {
int32 chunksize = getSizeNativeTexture(tex); int32 chunksize = getSizeNativeTexture(tex);
int32 plgsize = Texture::s_plglist.streamGetSize(tex); writeChunkHeader(stream, ID_STRUCT, chunksize-12);
writeChunkHeader(stream, ID_TEXTURENATIVE, chunksize);
writeChunkHeader(stream, ID_STRUCT, chunksize-24-plgsize);
stream->writeU32(PLATFORM_D3D8); stream->writeU32(PLATFORM_D3D8);
// Texture // Texture
@ -611,7 +607,6 @@ writeNativeTexture(Texture *tex, Stream *stream)
stream->write(data, size); stream->write(data, size);
raster->unlock(i); raster->unlock(i);
} }
Texture::s_plglist.streamWrite(stream, tex);
} }
uint32 uint32
@ -625,7 +620,6 @@ getSizeNativeTexture(Texture *tex)
size += 4*256; size += 4*256;
for(int32 i = 0; i < levels; i++) for(int32 i = 0; i < levels; i++)
size += 4 + getLevelSize(tex->raster, i); size += 4 + getLevelSize(tex->raster, i);
size += 12 + Texture::s_plglist.streamGetSize(tex);
return size; return size;
} }

View File

@ -656,7 +656,6 @@ readNativeTexture(Stream *stream)
}else }else
stream->seek(size); stream->seek(size);
} }
Texture::s_plglist.streamRead(stream, tex);
return tex; return tex;
} }
@ -664,9 +663,7 @@ void
writeNativeTexture(Texture *tex, Stream *stream) writeNativeTexture(Texture *tex, Stream *stream)
{ {
int32 chunksize = getSizeNativeTexture(tex); int32 chunksize = getSizeNativeTexture(tex);
int32 plgsize = Texture::s_plglist.streamGetSize(tex); writeChunkHeader(stream, ID_STRUCT, chunksize-12);
writeChunkHeader(stream, ID_TEXTURENATIVE, chunksize);
writeChunkHeader(stream, ID_STRUCT, chunksize-24-plgsize);
stream->writeU32(PLATFORM_D3D9); stream->writeU32(PLATFORM_D3D9);
// Texture // Texture
@ -708,7 +705,6 @@ writeNativeTexture(Texture *tex, Stream *stream)
stream->write(data, size); stream->write(data, size);
raster->unlock(i); raster->unlock(i);
} }
Texture::s_plglist.streamWrite(stream, tex);
} }
uint32 uint32
@ -722,7 +718,6 @@ getSizeNativeTexture(Texture *tex)
size += 4*256; size += 4*256;
for(int32 i = 0; i < levels; i++) for(int32 i = 0; i < levels; i++)
size += 4 + getLevelSize(tex->raster, i); size += 4 + getLevelSize(tex->raster, i);
size += 12 + Texture::s_plglist.streamGetSize(tex);
return size; return size;
} }

View File

@ -682,7 +682,6 @@ readNativeTexture(Stream *stream)
stream->read(data, totalSize); stream->read(data, totalSize);
raster->unlock(0); raster->unlock(0);
Texture::s_plglist.streamRead(stream, tex);
return tex; return tex;
} }
@ -690,9 +689,7 @@ void
writeNativeTexture(Texture *tex, Stream *stream) writeNativeTexture(Texture *tex, Stream *stream)
{ {
int32 chunksize = getSizeNativeTexture(tex); int32 chunksize = getSizeNativeTexture(tex);
int32 plgsize = Texture::s_plglist.streamGetSize(tex); writeChunkHeader(stream, ID_STRUCT, chunksize-12);
writeChunkHeader(stream, ID_TEXTURENATIVE, chunksize);
writeChunkHeader(stream, ID_STRUCT, chunksize-24-plgsize);
stream->writeU32(PLATFORM_XBOX); stream->writeU32(PLATFORM_XBOX);
// Texture // Texture
@ -729,8 +726,6 @@ writeNativeTexture(Texture *tex, Stream *stream)
uint8 *data = raster->lock(0); uint8 *data = raster->lock(0);
stream->write(data, totalSize); stream->write(data, totalSize);
raster->unlock(0); raster->unlock(0);
Texture::s_plglist.streamWrite(stream, tex);
} }
uint32 uint32
@ -745,7 +740,6 @@ getSizeNativeTexture(Texture *tex)
size += 4*32; size += 4*32;
else if(tex->raster->format & Raster::PAL8) else if(tex->raster->format & Raster::PAL8)
size += 4*256; size += 4*256;
size += 12 + Texture::s_plglist.streamGetSize(tex);
return size; return size;
} }

View File

@ -30,6 +30,10 @@ Engine::init(void)
Frame::dirtyList.init(); Frame::dirtyList.init();
engine->currentCamera = nil;
engine->currentWorld = nil;
engine->currentTexDictionary = nil;
engine->beginUpdate = null::beginUpdate; engine->beginUpdate = null::beginUpdate;
engine->endUpdate = null::endUpdate; engine->endUpdate = null::endUpdate;
engine->clearCamera = null::clearCamera; engine->clearCamera = null::clearCamera;

View File

@ -138,7 +138,6 @@ Shader::fromStrings(const char *vsrc, const char *fsrc)
{ {
GLuint vs, fs, program; GLuint vs, fs, program;
int i; int i;
char *src;
int fail; int fail;
fail = compileshader(GL_VERTEX_SHADER, vsrc, &vs); fail = compileshader(GL_VERTEX_SHADER, vsrc, &vs);

View File

@ -28,8 +28,6 @@ namespace rw {
// TexDictionary // TexDictionary
// //
TexDictionary *currentTexDictionary;
TexDictionary* TexDictionary*
TexDictionary::create(void) TexDictionary::create(void)
{ {
@ -53,6 +51,16 @@ TexDictionary::destroy(void)
free(this); free(this);
} }
void
TexDictionary::add(Texture *t)
{
if(engine->currentTexDictionary == this)
engine->currentTexDictionary = nil;
if(t->dict)
t->inDict.remove();
t->dict = this;
this->textures.append(&t->inDict);
}
Texture* Texture*
TexDictionary::find(const char *name) TexDictionary::find(const char *name)
{ {
@ -86,6 +94,7 @@ TexDictionary::streamRead(Stream *stream)
tex = Texture::streamReadNative(stream); tex = Texture::streamReadNative(stream);
if(tex == nil) if(tex == nil)
goto fail; goto fail;
Texture::s_plglist.streamRead(stream, tex);
txd->add(tex); txd->add(tex);
} }
if(s_plglist.streamRead(stream, txd)) if(s_plglist.streamRead(stream, txd))
@ -103,8 +112,14 @@ TexDictionary::streamWrite(Stream *stream)
int32 numTex = this->count(); int32 numTex = this->count();
stream->writeI16(numTex); stream->writeI16(numTex);
stream->writeI16(0); stream->writeI16(0);
FORLIST(lnk, this->textures) FORLIST(lnk, this->textures){
Texture::fromDict(lnk)->streamWriteNative(stream); Texture *tex = Texture::fromDict(lnk);
uint32 sz = tex->streamGetSizeNative();
sz += 12 + Texture::s_plglist.streamGetSize(tex);
writeChunkHeader(stream, ID_TEXTURENATIVE, sz);
tex->streamWriteNative(stream);
Texture::s_plglist.streamWrite(stream, tex);
}
s_plglist.streamWrite(stream, this); s_plglist.streamWrite(stream, this);
} }
@ -112,12 +127,27 @@ uint32
TexDictionary::streamGetSize(void) TexDictionary::streamGetSize(void)
{ {
uint32 size = 12 + 4; uint32 size = 12 + 4;
FORLIST(lnk, this->textures) FORLIST(lnk, this->textures){
size += 12 + Texture::fromDict(lnk)->streamGetSizeNative(); Texture *tex = Texture::fromDict(lnk);
size += 12 + tex->streamGetSizeNative();
size += 12 + Texture::s_plglist.streamGetSize(tex);
}
size += 12 + s_plglist.streamGetSize(this); size += 12 + s_plglist.streamGetSize(this);
return size; return size;
} }
void
TexDictionary::setCurrent(TexDictionary *txd)
{
engine->currentTexDictionary = txd;
}
TexDictionary*
TexDictionary::getCurrent(void)
{
return engine->currentTexDictionary;
}
// //
// Texture // Texture
// //
@ -166,8 +196,8 @@ Texture::destroy(void)
static Texture* static Texture*
defaultFindCB(const char *name) defaultFindCB(const char *name)
{ {
if(currentTexDictionary) if(engine->currentTexDictionary)
return currentTexDictionary->find(name); return engine->currentTexDictionary->find(name);
// TODO: RW searches *all* TXDs otherwise // TODO: RW searches *all* TXDs otherwise
return nil; return nil;
} }
@ -219,10 +249,10 @@ Texture::read(const char *name, const char *mask)
raster = Raster::create(0, 0, 0, Raster::DONTALLOCATE); raster = Raster::create(0, 0, 0, Raster::DONTALLOCATE);
tex->raster = raster; tex->raster = raster;
} }
if(currentTexDictionary){ if(engine->currentTexDictionary){
if(tex->dict) if(tex->dict)
tex->inDict.remove(); tex->inDict.remove();
currentTexDictionary->add(tex); engine->currentTexDictionary->add(tex);
} }
return tex; return tex;
} }
@ -258,10 +288,10 @@ Texture::streamRead(Stream *stream)
return nil; return nil;
if(tex->refCount == 1) if(tex->refCount == 1)
tex->filterAddressing = filterAddressing; tex->filterAddressing = filterAddressing;
tex->refCount++; // TODO: RW doesn't do this, why?
if(s_plglist.streamRead(stream, tex)) if(s_plglist.streamRead(stream, tex))
return tex; return tex;
tex->destroy(); tex->destroy();
return nil; return nil;
} }

View File

@ -765,8 +765,7 @@ streamExt.mipmapVal);
stream->read(raster->palette-0x50, natras->paletteSize); stream->read(raster->palette-0x50, natras->paletteSize);
} }
//printf("\n"); //printf("\n");
if(Texture::s_plglist.streamRead(stream, tex)) return tex;
return tex;
fail: fail:
tex->destroy(); tex->destroy();
@ -778,8 +777,6 @@ writeNativeTexture(Texture *tex, Stream *stream)
{ {
Raster *raster = tex->raster; Raster *raster = tex->raster;
Ps2Raster *ras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset); Ps2Raster *ras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset);
int32 chunksize = getSizeNativeTexture(tex);
writeChunkHeader(stream, ID_TEXTURENATIVE, chunksize);
writeChunkHeader(stream, ID_STRUCT, 8); writeChunkHeader(stream, ID_STRUCT, 8);
stream->writeU32(FOURCC_PS2); stream->writeU32(FOURCC_PS2);
stream->writeU32(tex->filterAddressing); stream->writeU32(tex->filterAddressing);
@ -824,7 +821,6 @@ writeNativeTexture(Texture *tex, Stream *stream)
stream->write(raster->texels-0x50, ras->texelSize); stream->write(raster->texels-0x50, ras->texelSize);
stream->write(raster->palette-0x50, ras->paletteSize); stream->write(raster->palette-0x50, ras->paletteSize);
} }
Texture::s_plglist.streamWrite(stream, tex);
} }
uint32 uint32
@ -833,10 +829,10 @@ getSizeNativeTexture(Texture *tex)
uint32 size = 12 + 8; uint32 size = 12 + 8;
size += 12 + strlen(tex->name)+4 & ~3; size += 12 + strlen(tex->name)+4 & ~3;
size += 12 + strlen(tex->mask)+4 & ~3; size += 12 + strlen(tex->mask)+4 & ~3;
size += 12 + 12 + 64 + 12; size += 12;
size += 12 + 64;
Ps2Raster *ras = PLUGINOFFSET(Ps2Raster, tex->raster, nativeRasterOffset); Ps2Raster *ras = PLUGINOFFSET(Ps2Raster, tex->raster, nativeRasterOffset);
size += ras->texelSize + ras->paletteSize; size += 12 + ras->texelSize + ras->paletteSize;
size += 12 + Texture::s_plglist.streamGetSize(tex);
return size; return size;
} }

View File

@ -50,6 +50,7 @@ struct Engine
{ {
void *currentCamera; void *currentCamera;
void *currentWorld; void *currentWorld;
TexDictionary *currentTexDictionary;
// Device // Device
float32 zNear, zFar; float32 zNear, zFar;

View File

@ -637,16 +637,14 @@ struct TexDictionary : PluginBase<TexDictionary>
static TexDictionary *create(void); static TexDictionary *create(void);
void destroy(void); void destroy(void);
int32 count(void) { return this->textures.count(); } int32 count(void) { return this->textures.count(); }
void add(Texture *t){ void add(Texture *t);
t->dict = this;
this->textures.append(&t->inDict);
}
Texture *find(const char *name); Texture *find(const char *name);
static TexDictionary *streamRead(Stream *stream); static TexDictionary *streamRead(Stream *stream);
void streamWrite(Stream *stream); void streamWrite(Stream *stream);
uint32 streamGetSize(void); uint32 streamGetSize(void);
static void setCurrent(TexDictionary *txd);
static TexDictionary *getCurrent(void);
}; };
extern TexDictionary *currentTexDictionary;
} }