diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx index 5009984ac6..294c7cbdc5 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx @@ -3982,6 +3982,32 @@ apply_texture(TextureContext *tc) { return; // tex already set (and possible problem in state-sorting?) } + // If the texture image has changed, or if its use of mipmaps has + // changed, we need to re-create the image. + int dirty = dtc->get_dirty_flags(); + if ((dirty & (Texture::DF_image | Texture::DF_mipmap)) != 0) { + // If this is *only* because of a mipmap change, issue a + // warning--it is likely that this change is the result of an + // error or oversight. + if ((dirty & Texture::DF_image) == 0) { + dxgsg_cat.warning() + << "Texture " << *dtx->_texture << " has changed mipmap state.\n"; + } + + dtc->DeleteTexture(); + if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) { + // Oops, we can't re-create the texture for some reason. + dxgsg_cat.error() + << "Unable to re-create texture " << *dtx->_texture << endl; + + release_texture(dtc); + enable_texturing(false); + return; + } + } + + dtc->clear_dirty_flags(); + Texture *tex = tc->_texture; Texture::WrapMode wrapU,wrapV; wrapU=tex->get_wrapu(); @@ -4076,7 +4102,6 @@ apply_texture(TextureContext *tc) { // bugbug: does this handle the case of untextured geometry? // we dont see this bug cause we never mix textured/untextured - _d3dDevice->SetTexture(0,dtc->_surface); #if 0