diff --git a/src/d3d/d3d.cpp b/src/d3d/d3d.cpp index c5c5153..f6465a9 100644 --- a/src/d3d/d3d.cpp +++ b/src/d3d/d3d.cpp @@ -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; } diff --git a/src/d3d/d3ddevice.cpp b/src/d3d/d3ddevice.cpp index 2177161..91d2fa3 100755 --- a/src/d3d/d3ddevice.cpp +++ b/src/d3d/d3ddevice.cpp @@ -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]); } } diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index b05d3b7..2bde1b9 100755 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -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 diff --git a/src/gl/gl3pipe.cpp b/src/gl/gl3pipe.cpp index a88616f..f50bfa5 100644 --- a/src/gl/gl3pipe.cpp +++ b/src/gl/gl3pipe.cpp @@ -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, diff --git a/src/image.cpp b/src/image.cpp index 7316b4a..847a0fb 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -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); } diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 842ce9a..477b150 100755 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -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