Implemented basic TexDictionary.

This commit is contained in:
Angelo Papenhoff
2015-01-20 19:22:57 +01:00
parent fb78a7a7b9
commit 62c6fe006e
6 changed files with 209 additions and 131 deletions

View File

@@ -430,90 +430,4 @@ RegisterMaterialRightsPlugin(void)
}
//
// Texture
//
Texture::Texture(void)
{
memset(this->name, 0, 32);
memset(this->mask, 0, 32);
this->filterAddressing = (WRAP << 12) | (WRAP << 8) | NEAREST;
this->raster = NULL;
this->refCount = 1;
this->constructPlugins();
}
Texture::~Texture(void)
{
this->destructPlugins();
}
void
Texture::decRef(void)
{
this->refCount--;
if(this->refCount)
delete this;
}
Texture*
Texture::streamRead(Stream *stream)
{
uint32 length;
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
Texture *tex = new Texture;
tex->filterAddressing = stream->readU16();
// TODO: what is this? (mipmap? i think)
stream->seek(2);
assert(FindChunk(stream, ID_STRING, &length, NULL));
stream->read(tex->name, length);
assert(FindChunk(stream, ID_STRING, &length, NULL));
stream->read(tex->mask, length);
tex->raster = Raster::read(tex->name, tex->mask);
if(tex->raster == NULL)
printf("didn't find texture %s\n", tex->name);
tex->streamReadPlugins(stream);
return tex;
}
bool
Texture::streamWrite(Stream *stream)
{
int size;
WriteChunkHeader(stream, ID_TEXTURE, this->streamGetSize());
WriteChunkHeader(stream, ID_STRUCT, 4);
stream->writeU32(this->filterAddressing);
// TODO: length can't be > 32
size = strlen(this->name)+4 & ~3;
WriteChunkHeader(stream, ID_STRING, size);
stream->write(this->name, size);
size = strlen(this->mask)+4 & ~3;
WriteChunkHeader(stream, ID_STRING, size);
stream->write(this->mask, size);
this->streamWritePlugins(stream);
return true;
}
uint32
Texture::streamGetSize(void)
{
uint32 size = 0;
int strsize;
size += 12 + 4;
size += 12 + 12;
size += strlen(this->name)+4 & ~3;
size += strlen(this->mask)+4 & ~3;
size += 12 + this->streamGetPluginSize();
return size;
}
}