From b481bcac003d9a5453b11eaedc65819420f6c408 Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Fri, 1 Feb 2008 01:33:42 +0000 Subject: [PATCH] Clear render to texture textures to black when they are first created. --- panda/src/dxgsg9/dxTextureContext9.cxx | 37 +++++++++++++++++++++++--- panda/src/dxgsg9/dxTextureContext9.h | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/panda/src/dxgsg9/dxTextureContext9.cxx b/panda/src/dxgsg9/dxTextureContext9.cxx index 6ad3811457..0ae3c498c1 100755 --- a/panda/src/dxgsg9/dxTextureContext9.cxx +++ b/panda/src/dxgsg9/dxTextureContext9.cxx @@ -925,7 +925,7 @@ create_texture(DXScreenData &scrn) { << " => " << D3DFormatStr(target_pixel_format) << endl; } - hr = fill_d3d_texture_pixels(scrn._supports_automatic_mipmap_generation); + hr = fill_d3d_texture_pixels(scrn._supports_automatic_mipmap_generation, scrn._d3d_device); if (FAILED(hr)) { dxgsg9_cat.debug () @@ -1410,7 +1410,7 @@ exit_FillMipmapSurf: // Description: //////////////////////////////////////////////////////////////////// HRESULT DXTextureContext9:: -fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation) { +fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation, IDirect3DDevice9 *device) { if (get_texture()->get_texture_type() == Texture::TT_3d_texture) { return fill_d3d_volume_texture_pixels(); } @@ -1424,7 +1424,38 @@ fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation) { // The texture doesn't have an image to load. That's ok; it // might be a texture we've rendered to by frame buffer // operations or something. - if (get_texture()->get_render_to_texture()) { + if (get_texture()->get_render_to_texture()) { + HRESULT result; + + // clear render to texture + IDirect3DSurface9 *surface; + + result = _d3d_2d_texture -> GetSurfaceLevel (0, &surface); + if (result == D3D_OK) { + D3DSURFACE_DESC surface_description; + + if (surface -> GetDesc (&surface_description) == D3D_OK) { + IDirect3DSurface9 *current_render_target; + + if (device -> GetRenderTarget (0, ¤t_render_target) == D3D_OK) { + if (device -> SetRenderTarget (0, surface) == D3D_OK) { + DWORD flags; + D3DCOLOR color; + + color = 0xFF000000; + flags = D3DCLEAR_TARGET; + if (device -> Clear (NULL, NULL, flags, color, 0.0f, 0) == D3D_OK) { + } + } + + device -> SetRenderTarget (0, current_render_target); + current_render_target -> Release(); + } + } + + surface -> Release(); + } + return S_OK; } return E_FAIL; diff --git a/panda/src/dxgsg9/dxTextureContext9.h b/panda/src/dxgsg9/dxTextureContext9.h index d6b07c4a10..e8684dfec3 100755 --- a/panda/src/dxgsg9/dxTextureContext9.h +++ b/panda/src/dxgsg9/dxTextureContext9.h @@ -50,7 +50,7 @@ public: private: HRESULT fill_d3d_texture_mipmap_pixels(int mip_level, int depth_index, D3DFORMAT source_format); - HRESULT fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation); + HRESULT fill_d3d_texture_pixels(bool supports_automatic_mipmap_generation, IDirect3DDevice9 *device); HRESULT fill_d3d_volume_texture_pixels(); static int down_to_power_2(int value); unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);