some bug fixes

This commit is contained in:
aap 2018-07-04 19:21:34 +02:00
parent 2cffb3f494
commit b1c3c1dca8
6 changed files with 58 additions and 13 deletions

View File

@ -572,7 +572,7 @@ rasterFromImage(Raster *raster, Image *image)
case Raster::C1555:
out[0] = in[0];
out[1] = in[1];
in += 2;
in += inc;
out += 2;
break;
}

View File

@ -295,8 +295,8 @@ setFilterMode(uint32 stage, int32 filter)
// TODO: mip mapping
if(rwStateCache.texstage[stage].filter != (Texture::FilterMode)filter){
rwStateCache.texstage[stage].filter = (Texture::FilterMode)filter;
setSamplerState(0, D3DSAMP_MAGFILTER, filterConvMap_NoMIP[filter]);
setSamplerState(0, D3DSAMP_MINFILTER, filterConvMap_NoMIP[filter]);
setSamplerState(stage, D3DSAMP_MAGFILTER, filterConvMap_NoMIP[filter]);
setSamplerState(stage, D3DSAMP_MINFILTER, filterConvMap_NoMIP[filter]);
}
}
@ -305,7 +305,7 @@ setAddressU(uint32 stage, int32 addressing)
{
if(rwStateCache.texstage[stage].addressingU != (Texture::Addressing)addressing){
rwStateCache.texstage[stage].addressingU = (Texture::Addressing)addressing;
setSamplerState(0, D3DSAMP_ADDRESSU, addressConvMap[addressing]);
setSamplerState(stage, D3DSAMP_ADDRESSU, addressConvMap[addressing]);
}
}
@ -314,7 +314,7 @@ setAddressV(uint32 stage, int32 addressing)
{
if(rwStateCache.texstage[stage].addressingV != (Texture::Addressing)addressing){
rwStateCache.texstage[stage].addressingV = (Texture::Addressing)addressing;
setSamplerState(0, D3DSAMP_ADDRESSV, addressConvMap[addressing]);
setSamplerState(stage, D3DSAMP_ADDRESSV, addressConvMap[addressing]);
}
}

View File

@ -236,6 +236,44 @@ setAddressV(uint32 stage, int32 addressing)
}
}
static void
setRasterStageOnly(uint32 stage, Raster *raster)
{
bool32 alpha;
if(raster != rwStateCache.texstage[stage].raster){
rwStateCache.texstage[stage].raster = raster;
setActiveTexture(GL_TEXTURE0+stage);
if(raster){
assert(raster->platform == PLATFORM_GL3);
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
glBindTexture(GL_TEXTURE_2D, natras->texid);
rwStateCache.texstage[stage].filter = (rw::Texture::FilterMode)natras->filterMode;
rwStateCache.texstage[stage].addressingU = (rw::Texture::Addressing)natras->addressU;
rwStateCache.texstage[stage].addressingV = (rw::Texture::Addressing)natras->addressV;
alpha = natras->hasAlpha;
}else{
glBindTexture(GL_TEXTURE_2D, whitetex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
alpha = 0;
}
if(stage == 0){
if(alpha != rwStateCache.textureAlpha){
rwStateCache.textureAlpha = alpha;
if(!rwStateCache.vertexAlpha){
(alpha ? glEnable : glDisable)(GL_BLEND);
setAlphaTest(alpha);
}
}
}
}
}
static void
setRasterStage(uint32 stage, Raster *raster)
{
@ -288,16 +326,14 @@ setRasterStage(uint32 stage, Raster *raster)
void
setTexture(int32 stage, Texture *tex)
{
if(tex == nil){
if(tex == nil || tex->raster == nil){
setRasterStage(stage, nil);
return;
}
if(tex->raster){
setFilterMode(stage, tex->getFilter());
setAddressU(stage, tex->getAddressU());
setAddressV(stage, tex->getAddressV());
}
setRasterStage(stage, tex->raster);
setRasterStageOnly(stage, tex->raster);
setFilterMode(stage, tex->getFilter());
setAddressU(stage, tex->getAddressU());
setAddressV(stage, tex->getAddressV());
}
static void

View File

@ -49,6 +49,7 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
for(uint32 i = 0; i < header->numMeshes; i++){
findMinVertAndNumVertices(mesh->indices, mesh->numIndices,
&inst->minVert, &inst->numVertices);
assert(inst->minVert != 0xFFFFFFFF);
inst->numIndex = mesh->numIndices;
inst->material = mesh->material;
inst->vertexAlpha = 0;
@ -200,6 +201,7 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
int n = header->numMeshes;
InstanceData *inst = header->inst;
while(n--){
assert(inst->minVert != 0xFFFFFFFF);
inst->vertexAlpha = instColor(VERT_RGBA,
verts + a->offset + a->stride*inst->minVert,
geo->colors + inst->minVert,

View File

@ -378,6 +378,7 @@ Image::unindex(void)
}
this->free();
this->depth = ndepth;
this->bpp = ndepth < 8 ? 1 : ndepth/8;
this->stride = nstride;
this->setPixels(npixels);
}

View File

@ -44,10 +44,16 @@ findMinVertAndNumVertices(uint16 *indices, uint32 numIndices, uint32 *minVert, i
max = *indices;
indices++;
}
uint32 num = max - min + 1;
// if mesh is empty, this can happen
if(min > max){
min = 0;
num = 0;
}
if(minVert)
*minVert = min;
if(numVertices)
*numVertices = max - min + 1;
*numVertices = num;
}
void