Add automipmap generation code to eliminate dynamic textures.

The automipmap generation filter is not as good as the D3DX box filter so dont' use it for now.
This commit is contained in:
aignacio_sf 2006-03-20 23:08:38 +00:00
parent a29aaeb14f
commit bd97d329c4
2 changed files with 62 additions and 45 deletions

View File

@ -657,25 +657,30 @@ create_texture(DXScreenData &scrn) {
} }
else { else {
_managed = scrn._managed_textures; _managed = scrn._managed_textures;
if (_managed) if (_managed) {
{
pool = D3DPOOL_MANAGED; pool = D3DPOOL_MANAGED;
usage = 0;
} }
else else {
{ if (scrn._supports_automatic_mipmap_generation) {
if (scrn._supports_dynamic_textures) pool = D3DPOOL_DEFAULT;
{ usage = D3DUSAGE_AUTOGENMIPMAP;
}
else {
if (dx_use_dynamic_textures) {
if (scrn._supports_dynamic_textures) {
pool = D3DPOOL_DEFAULT; pool = D3DPOOL_DEFAULT;
usage = D3DUSAGE_DYNAMIC; usage = D3DUSAGE_DYNAMIC;
} }
else else {
{
// can't lock textures so go back to managed for now // can't lock textures so go back to managed for now
// need to use UpdateTexture or UpdateSurface // need to use UpdateTexture or UpdateSurface
_managed = true; _managed = true;
pool = D3DPOOL_MANAGED; pool = D3DPOOL_MANAGED;
usage = 0; }
}
else {
pool = D3DPOOL_DEFAULT;
}
} }
} }
} }
@ -805,7 +810,7 @@ create_texture(DXScreenData &scrn) {
<< " => " << D3DFormatStr(target_pixel_format) << endl; << " => " << D3DFormatStr(target_pixel_format) << endl;
} }
hr = fill_d3d_texture_pixels(); hr = fill_d3d_texture_pixels(scrn._supports_automatic_mipmap_generation);
if (FAILED(hr)) { if (FAILED(hr)) {
goto error_exit; goto error_exit;
} }
@ -814,18 +819,15 @@ create_texture(DXScreenData &scrn) {
// must not put render to texture into LRU // must not put render to texture into LRU
if (_lru_page == 0 && _managed == false && get_texture()->get_render_to_texture ( ) == false) if (_lru_page == 0 && _managed == false && get_texture()->get_render_to_texture ( ) == false) {
{
Lru *lru; Lru *lru;
lru = scrn._dxgsg9 -> _lru; lru = scrn._dxgsg9 -> _lru;
if (lru) if (lru) {
{
LruPage *lru_page; LruPage *lru_page;
lru_page = lru -> allocate_page (data_size); lru_page = lru -> allocate_page (data_size);
if (lru_page) if (lru_page) {
{
lru_page -> _m.type = GPT_Texture; lru_page -> _m.type = GPT_Texture;
lru_page -> _m.lru_page_type.pointer = this; lru_page -> _m.lru_page_type.pointer = this;
@ -1129,7 +1131,7 @@ d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface9 *d3d_surface,
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
HRESULT DXTextureContext9:: HRESULT DXTextureContext9::
fill_d3d_texture_pixels() { fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation) {
if (get_texture()->get_texture_type() == Texture::TT_3d_texture) { if (get_texture()->get_texture_type() == Texture::TT_3d_texture) {
return fill_d3d_volume_texture_pixels(); return fill_d3d_volume_texture_pixels();
} }
@ -1265,14 +1267,28 @@ fill_d3d_texture_pixels() {
} }
if (_has_mipmaps) { if (_has_mipmaps) {
if (_managed == false && supports_automatic_mipmap_generation) {
if (false)
{
// hr = _d3d_texture -> SetAutoGenFilterType (D3DTEXF_PYRAMIDALQUAD);
// hr = _d3d_texture -> SetAutoGenFilterType (D3DTEXF_GAUSSIANQUAD);
// hr = _d3d_texture -> SetAutoGenFilterType (D3DTEXF_ANISOTROPIC);
hr = _d3d_texture -> SetAutoGenFilterType (D3DTEXF_LINEAR);
if (FAILED(hr)) {
dxgsg9_cat.error() << "SetAutoGenFilterType failed " << D3DERRORSTRING(hr);
}
_d3d_texture -> GenerateMipSubLevels ( );
}
}
else {
if (!dx_use_triangle_mipgen_filter) { if (!dx_use_triangle_mipgen_filter) {
mip_filter_flags = D3DX_FILTER_BOX; mip_filter_flags = D3DX_FILTER_BOX;
} else { } else {
mip_filter_flags = D3DX_FILTER_TRIANGLE; mip_filter_flags = D3DX_FILTER_TRIANGLE;
} }
// mip_filter_flags| = D3DX_FILTER_DITHER; // mip_filter_flags |= D3DX_FILTER_DITHER;
hr = D3DXFilterTexture(_d3d_texture, (PALETTEENTRY*)NULL, 0, hr = D3DXFilterTexture(_d3d_texture, (PALETTEENTRY*)NULL, 0,
mip_filter_flags); mip_filter_flags);
if (FAILED(hr)) { if (FAILED(hr)) {
@ -1282,6 +1298,7 @@ fill_d3d_texture_pixels() {
goto exit_FillDDSurf; goto exit_FillDDSurf;
} }
} }
}
if (using_temp_buffer) { if (using_temp_buffer) {
SAFE_DELETE_ARRAY(pixels); SAFE_DELETE_ARRAY(pixels);
} }

View File

@ -49,7 +49,7 @@ public:
int z); int z);
private: private:
HRESULT fill_d3d_texture_pixels(); HRESULT fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation);
HRESULT fill_d3d_volume_texture_pixels(); HRESULT fill_d3d_volume_texture_pixels();
static int down_to_power_2(int value); static int down_to_power_2(int value);
unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits); unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);