minor reorg of prev change

This commit is contained in:
cxgeorge 2002-01-01 00:04:05 +00:00
parent ffe43ef615
commit 9fac91aa0e
4 changed files with 42 additions and 46 deletions

View File

@ -588,6 +588,13 @@ dx_init( LPDIRECTDRAW7 context,
exit(1);
}
// s3 virge drivers sometimes give crap values for these
if(_D3DDevDesc.dwMaxTextureWidth==0)
_D3DDevDesc.dwMaxTextureWidth=256;
if(_D3DDevDesc.dwMaxTextureHeight==0)
_D3DDevDesc.dwMaxTextureHeight=256;
_bIsTNLDevice = (IsEqualGUID(_D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0);
if ((dx_decal_type==GDT_offset) && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) {
@ -3932,7 +3939,7 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) {
TextureContext *DXGraphicsStateGuardian::
prepare_texture(Texture *tex) {
DXTextureContext *gtc = new DXTextureContext(tex);
DXTextureContext *dtc = new DXTextureContext(tex);
#ifdef WBD_GL_MODE
glGenTextures(1, &gtc->_index);
@ -3941,20 +3948,20 @@ prepare_texture(Texture *tex) {
specify_texture(tex);
apply_texture_immediate(tex);
#else
if (gtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) {
delete gtc;
if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts,&_D3DDevDesc) == NULL) {
delete dtc;
return NULL;
}
#endif // WBD_GL_MODE
bool inserted = mark_prepared_texture(gtc);
bool inserted = mark_prepared_texture(dtc);
// If this assertion fails, the same texture was prepared twice,
// which shouldn't be possible, since the texture itself should
// detect this.
nassertr(inserted, NULL);
return gtc;
return dtc;
}
////////////////////////////////////////////////////////////////////
@ -3997,10 +4004,9 @@ apply_texture(TextureContext *tc) {
}
dtc->DeleteTexture();
if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) {
if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts,&_D3DDevDesc)==NULL) {
// Oops, we can't re-create the texture for some reason.
dxgsg_cat.error()
<< "Unable to re-create texture " << *dtc->_texture << endl;
dxgsg_cat.error() << "Unable to re-create texture " << *dtc->_texture << endl;
release_texture(dtc);
enable_texturing(false);
@ -6320,8 +6326,8 @@ bool recreate_tex_callback(TextureContext *tc,void *void_dxgsg_ptr) {
// Re-fill the contents of textures and vertex buffers
// which just got restored now.
LPDIRECTDRAWSURFACE7 ddtex = dtc->CreateTexture(dxgsg->_d3dDevice,
dxgsg->_cNumTexPixFmts,dxgsg->_pTexPixFmts);
LPDIRECTDRAWSURFACE7 ddtex = dtc->CreateTexture(dxgsg->_d3dDevice,dxgsg->_cNumTexPixFmts,
dxgsg->_pTexPixFmts,&dxgsg->_D3DDevDesc);
return ddtex!=NULL;
}

View File

@ -230,6 +230,7 @@ public:
LPDIRECT3DDEVICE7 _d3dDevice;
LPDDPIXELFORMAT _pTexPixFmts;
int _cNumTexPixFmts;
D3DDEVICEDESC7 _D3DDevDesc;
protected:
void free_pointers(); // free local internal buffers
@ -265,8 +266,6 @@ protected:
RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation
D3DDEVICEDESC7 _D3DDevDesc;
void GenerateSphere(void *pVertexSpace,DWORD dwVertSpaceByteSize,
void *pIndexSpace,DWORD dwIndexSpaceByteSize,
D3DVECTOR *pCenter, float fRadius,

View File

@ -972,7 +972,7 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf)
// texture, and then copies the bitmap into the texture.
//-----------------------------------------------------------------------------
LPDIRECTDRAWSURFACE7 DXTextureContext::
CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts) {
CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts, LPD3DDEVICEDESC7 pD3DDevDesc) {
HRESULT hr;
int i;
PixelBuffer *pbuf = _texture->_pbuffer;
@ -1006,19 +1006,10 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
DWORD dwOrigWidth = (DWORD)pbuf->get_xsize();
DWORD dwOrigHeight = (DWORD)pbuf->get_ysize();
// Get the device caps so we can check if the device has any constraints
// when using textures. Could we use the
D3DDEVICEDESC7 devDesc;
if(FAILED( pd3dDevice->GetCaps( &devDesc ) )) {
goto error_exit;
}
// Use the device caps so we can check if the device has any constraints
// when using textures.
// s3 virge drivers sometimes give crap values for these
if(devDesc.dwMaxTextureWidth==0)
devDesc.dwMaxTextureWidth=256;
if(devDesc.dwMaxTextureHeight==0)
devDesc.dwMaxTextureHeight=256;
assert((pD3DDevDesc->dwMaxTextureWidth>0) && (pD3DDevDesc->dwMaxTextureHeight>0));
// Setup the new surface desc for the texture. Note how we are using the
// texture manage attribute, so Direct3D does alot of dirty work for us
@ -1073,21 +1064,21 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
bool bShrinkOriginal;
bShrinkOriginal=false;
if((dwOrigWidth>devDesc.dwMaxTextureWidth)||(dwOrigHeight>devDesc.dwMaxTextureHeight)) {
if((dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth)||(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight)) {
#ifdef _DEBUG
dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !!\n"
<< "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<< devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !\n";
dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !!\n"
<< "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<< pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !\n";
#endif
if(dwOrigWidth>devDesc.dwMaxTextureWidth)
ddsd.dwWidth=devDesc.dwMaxTextureWidth;
if(dwOrigHeight>devDesc.dwMaxTextureHeight)
ddsd.dwHeight=devDesc.dwMaxTextureHeight;
if(dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth)
ddsd.dwWidth=pD3DDevDesc->dwMaxTextureWidth;
if(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight)
ddsd.dwHeight=pD3DDevDesc->dwMaxTextureHeight;
bShrinkOriginal=true;
}
// checks for SQUARE reqmt (nvidia riva128 needs this)
if((ddsd.dwWidth != ddsd.dwHeight) && (devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) {
if((ddsd.dwWidth != ddsd.dwHeight) && (pD3DDevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) {
// assume pow2 textures. sum exponents, divide by 2 rounding down to get sq size
int i,width_exp,height_exp;
@ -1489,7 +1480,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
else ft=Texture::FT_linear;
}
if((ft==Texture::FT_linear) && !(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
if((ft==Texture::FT_linear) && !(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
ft=Texture::FT_nearest;
_tex->set_magfilter(ft);
@ -1522,26 +1513,26 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
ft=Texture::FT_linear;
}
assert((devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0);
assert((pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0);
switch(ft) {
case Texture::FT_nearest_mipmap_linear:
if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST))
if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST))
ft=Texture::FT_nearest_mipmap_nearest;
break;
case Texture::FT_linear_mipmap_nearest:
if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR))
if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR))
ft=Texture::FT_nearest_mipmap_nearest;
break;
case Texture::FT_linear_mipmap_linear:
if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) {
if(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)
if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) {
if(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)
ft=Texture::FT_linear_mipmap_nearest;
else ft=Texture::FT_nearest_mipmap_nearest; // if you cant do linear in a level, you probably cant do linear b/w levels, so just do nearest-all
}
break;
case Texture::FT_linear:
if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
ft=Texture::FT_nearest;
break;
}
@ -1551,14 +1542,14 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
uint aniso_degree;
aniso_degree=1;
if(devDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) {
if(pD3DDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) {
aniso_degree=_tex->get_anisotropic_degree();
if((aniso_degree>devDesc.dwMaxAnisotropy)
if((aniso_degree>pD3DDevDesc->dwMaxAnisotropy)
#ifdef _DEBUG
|| dx_force_anisotropic_filtering
#endif
)
aniso_degree=devDesc.dwMaxAnisotropy;
aniso_degree=pD3DDevDesc->dwMaxAnisotropy;
}
_tex->set_anisotropic_degree(aniso_degree);
#ifdef _DEBUG
@ -1572,7 +1563,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
dxgsg_cat.debug() << "CreateTexture: generating mipmaps for "<< _tex->get_name() << endl;
}
if(devDesc.dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) {
if(pD3DDevDesc->dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) {
// must assign a texture to a specific stage
// for now I'm just going to use stage 0 for all
ddsd.dwTextureStage=0;

View File

@ -55,8 +55,8 @@ public:
LPDIRECTDRAWSURFACE7 _surface;
Texture *_tex; // ptr to parent, primarily for access to namestr
LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts);
LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
LPDDPIXELFORMAT pTexPixFmts,LPD3DDEVICEDESC7 pD3DDevDesc);
bool _bHasMipMaps;
DWORD _PixBufConversionType; // enum ConversionType