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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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