Guest User

Untitled

a guest
Apr 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1.     void CDX9Renderer::ResizeRenderTargetTexture(TextureHandle th, uint new_width, uint new_height)
  2.     {
  3.         // Can't call during lost device
  4.         //if (device_is_lost)
  5.         //  return NULL;
  6.        
  7.         EndBatch();
  8.  
  9.         d3d9texture* tex = th;
  10.         tex->texture_ptr->Release();
  11.         texture_format format=th->format;
  12.         uint width=new_width;
  13.         uint height=new_height;
  14.  
  15.         D3DSURFACE_DESC surface_desc;
  16.  
  17.  {
  18.             // Create render-target texture
  19.             hr = D3DXCreateTexture(d3d9_device, width, height, 1, D3DUSAGE_RENDERTARGET,
  20.                                 get_d3d9_equiv(format), D3DPOOL_DEFAULT, &(tex->texture_ptr));
  21.  
  22.             if (tex->texture_ptr == NULL || FAILED(hr))
  23.                 throw error(_T("Failed to create render target texture"), hr);
  24.  
  25.             // Initialise the texture
  26.             tex->texture_ptr->GetLevelDesc(0, &surface_desc);
  27.         }
  28.  
  29.         tex->rendertarget = true;       // Render target
  30.         tex->format = format;
  31.  
  32.         // Get the surface & image sizes
  33.         tex->surface_width = surface_desc.Width;
  34.         tex->surface_height = surface_desc.Height;
  35.  
  36.         tex->image_width = width;
  37.         tex->image_height = height;
  38.  
  39.         tex->image_widthf = tex->image_width;
  40.         tex->image_heightf = tex->image_height;
  41.  
  42.         // Precompute the x and y image-to-surface ratios
  43.         tex->xf = (cr_float)width / (cr_float)surface_desc.Width;
  44.         tex->yf = (cr_float)height / (cr_float)surface_desc.Height;
  45.  
  46.         // Calculate size, in bytes
  47.         tex->size_bytes = tex->surface_width * tex->surface_height * get_format_bytes_per_pixel(format);
  48.  
  49.         // Add to the texture list
  50.         //textures.insert(tex);
  51.  
  52.         // Return the pointer as the handle
  53.         //return tex;
  54.     }
  55.  
  56.     void CDX9Renderer::ResizeRenderTargetTexture(TextureHandle th, uint new_width, uint new_height)
  57.     {
  58.         if (!th->rendertarget)
  59.             throw error(_T("Can't resize a non-rendertarget texture"), E_FAIL);
  60.  
  61.         if (th->surface_ptr != NULL)
  62.             throw error(_T("Resizing multisample render targets is not supported"), E_FAIL);
  63.  
  64.         // Not a batched command
  65.         EndBatch();
  66.  
  67.         // Save state
  68.         TextureHandle old_rendertarget = GetRenderTarget();
  69.         TextureHandle old_texture = GetTexture();
  70.  
  71.         // Create new rendertarget of new size
  72.         TextureHandle new_tex = CreateRenderTargetTexture(new_width, new_height, th->format);
  73.  
  74.         // Copy the image content
  75.         SetRenderTarget(new_tex);
  76.         ClearRenderTarget();
  77.         SetTexture(th);
  78.         Quad(0.0, 0.0);
  79.  
  80.         // Replace the old texture with the new one
  81.         th->texture_ptr->Release();             // Free texture
  82.         th->texture_ptr = new_tex->texture_ptr; // Adopt new texture
  83.  
  84.         th->image_height = new_tex->image_height;
  85.         th->image_heightf = new_tex->image_heightf;
  86.         th->image_width = new_tex->image_width;
  87.         th->image_widthf = new_tex->image_widthf;
  88.  
  89.         th->size_bytes = new_tex->size_bytes;
  90.         th->surface_height = new_tex->surface_height;
  91.         th->surface_width = new_tex->surface_width;
  92.         th->xf = new_tex->xf;
  93.         th->yf = new_tex->yf;
  94.  
  95.         // Get rid of the new texture's handle, its texture is used by th now
  96.         textures.erase(textures.find(new_tex));
  97.  
  98.         // Restore state
  99.         SetRenderTarget(old_rendertarget);
  100.         SetTexture(old_texture);
  101.     }
Add Comment
Please, Sign In to add comment