mirror of
https://github.com/aap/librw.git
synced 2024-11-25 05:05:42 +00:00
fixes to matfx
This commit is contained in:
parent
a3d8e3ba01
commit
f043126233
@ -874,6 +874,7 @@ StreamMemory::getLength(void)
|
|||||||
StreamFile*
|
StreamFile*
|
||||||
StreamFile::open(const char *path, const char *mode)
|
StreamFile::open(const char *path, const char *mode)
|
||||||
{
|
{
|
||||||
|
assert(this->file == nil);
|
||||||
this->file = fopen(path, mode);
|
this->file = fopen(path, mode);
|
||||||
if(this->file == nil){
|
if(this->file == nil){
|
||||||
RWERROR((ERR_FILE, path));
|
RWERROR((ERR_FILE, path));
|
||||||
@ -885,7 +886,9 @@ StreamFile::open(const char *path, const char *mode)
|
|||||||
void
|
void
|
||||||
StreamFile::close(void)
|
StreamFile::close(void)
|
||||||
{
|
{
|
||||||
|
assert(this->file);
|
||||||
fclose(this->file);
|
fclose(this->file);
|
||||||
|
this->file = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32
|
uint32
|
||||||
|
@ -95,28 +95,37 @@ clearMatFX(MatFX *matfx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MatFX::setEffects(uint32 type)
|
MatFX::setEffects(Material *mat, uint32 type)
|
||||||
{
|
{
|
||||||
if(this->type != 0 && this->type != type)
|
MatFX *matfx;
|
||||||
clearMatFX(this);
|
|
||||||
this->type = type;
|
matfx = MatFX::get(mat);
|
||||||
|
if(matfx == nil){
|
||||||
|
matfx = new MatFX;
|
||||||
|
memset(matfx, 0, sizeof(MatFX));
|
||||||
|
*PLUGINOFFSET(MatFX*, mat, matFXGlobals.materialOffset) = matfx;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matfx->type != 0 && matfx->type != type)
|
||||||
|
clearMatFX(matfx);
|
||||||
|
matfx->type = type;
|
||||||
switch(type){
|
switch(type){
|
||||||
case BUMPMAP:
|
case BUMPMAP:
|
||||||
case ENVMAP:
|
case ENVMAP:
|
||||||
case DUAL:
|
case DUAL:
|
||||||
case UVTRANSFORM:
|
case UVTRANSFORM:
|
||||||
this->fx[0].type = type;
|
matfx->fx[0].type = type;
|
||||||
this->fx[1].type = NOTHING;
|
matfx->fx[1].type = NOTHING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUMPENVMAP:
|
case BUMPENVMAP:
|
||||||
this->fx[0].type = BUMPMAP;
|
matfx->fx[0].type = BUMPMAP;
|
||||||
this->fx[1].type = ENVMAP;
|
matfx->fx[1].type = ENVMAP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DUALUVTRANSFORM:
|
case DUALUVTRANSFORM:
|
||||||
this->fx[0].type = UVTRANSFORM;
|
matfx->fx[0].type = UVTRANSFORM;
|
||||||
this->fx[1].type = DUAL;
|
matfx->fx[1].type = DUAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,16 +270,17 @@ copyMaterialMatFX(void *dst, void *src, int32 offset, int32)
|
|||||||
static Stream*
|
static Stream*
|
||||||
readMaterialMatFX(Stream *stream, int32, void *object, int32 offset, int32)
|
readMaterialMatFX(Stream *stream, int32, void *object, int32 offset, int32)
|
||||||
{
|
{
|
||||||
|
Material *mat;
|
||||||
|
MatFX *matfx;
|
||||||
Texture *tex, *bumpedTex;
|
Texture *tex, *bumpedTex;
|
||||||
float coefficient;
|
float coefficient;
|
||||||
int32 fbAlpha;
|
int32 fbAlpha;
|
||||||
int32 srcBlend, dstBlend;
|
int32 srcBlend, dstBlend;
|
||||||
int32 idx;
|
int32 idx;
|
||||||
|
|
||||||
MatFX *matfx = new MatFX;
|
mat = (Material*)object;
|
||||||
memset(matfx, 0, sizeof(MatFX));
|
MatFX::setEffects(mat, stream->readU32());
|
||||||
*PLUGINOFFSET(MatFX*, object, offset) = matfx;
|
matfx = MatFX::get(mat);
|
||||||
matfx->setEffects(stream->readU32());
|
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++){
|
for(int i = 0; i < 2; i++){
|
||||||
uint32 type = stream->readU32();
|
uint32 type = stream->readU32();
|
||||||
@ -390,7 +400,7 @@ getSizeMaterialMatFX(void *object, int32 offset, int32)
|
|||||||
return -1;
|
return -1;
|
||||||
int32 size = 4 + 4 + 4;
|
int32 size = 4 + 4 + 4;
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++)
|
for(int i = 0; i < 2; i++){
|
||||||
switch(matfx->fx[i].type){
|
switch(matfx->fx[i].type){
|
||||||
case MatFX::BUMPMAP:
|
case MatFX::BUMPMAP:
|
||||||
size += 4 + 4 + 4;
|
size += 4 + 4 + 4;
|
||||||
@ -416,6 +426,7 @@ getSizeMaterialMatFX(void *object, int32 offset, int32)
|
|||||||
matfx->fx[i].dual.tex->streamGetSize();
|
matfx->fx[i].dual.tex->streamGetSize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +300,7 @@ class StreamFile : public Stream
|
|||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
public:
|
public:
|
||||||
|
StreamFile(void) { file = nil; }
|
||||||
void close(void);
|
void close(void);
|
||||||
uint32 write(const void *data, uint32 length);
|
uint32 write(const void *data, uint32 length);
|
||||||
uint32 read(void *data, uint32 length);
|
uint32 read(void *data, uint32 length);
|
||||||
|
@ -116,6 +116,7 @@ struct MatFX
|
|||||||
float *dualTransform;
|
float *dualTransform;
|
||||||
};
|
};
|
||||||
struct {
|
struct {
|
||||||
|
// uint32 foo[32];
|
||||||
uint32 type;
|
uint32 type;
|
||||||
union {
|
union {
|
||||||
Bump bump;
|
Bump bump;
|
||||||
@ -126,7 +127,7 @@ struct MatFX
|
|||||||
} fx[2];
|
} fx[2];
|
||||||
uint32 type;
|
uint32 type;
|
||||||
|
|
||||||
void setEffects(uint32 flags);
|
static void setEffects(Material *m, uint32 flags);
|
||||||
static uint32 getEffects(Material *m);
|
static uint32 getEffects(Material *m);
|
||||||
static MatFX *get(Material *m);
|
static MatFX *get(Material *m);
|
||||||
uint32 getEffectIndex(uint32 type);
|
uint32 getEffectIndex(uint32 type);
|
||||||
|
Loading…
Reference in New Issue
Block a user