XaskeL

MTA dxCreateRenderTarget memory calc

Mar 4th, 2021 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. --[[ function dxRenderTargetCalc( fWidth, fHeight, bAlpha )
  2.     local iPixels = ( fWidth * fHeight );
  3.     return ( bAlpha and ( iPixels * ( 4 + 4 + 4 + 4 ) ) or ( iPixels * ( 2 + 2 + 2 ) ) ) / 1e+6;
  4. end;
  5.  
  6. print( dxRenderTargetCalc( 1920, 1080, true ) ) -- 33.1776 MiB
  7. --]]
  8.  
  9. CRenderTarget =
  10. {
  11.     GetWeightFromSize   = function ( this, fWidth, fHeight, bAlpha )
  12.         local iPixels = ( fWidth * fHeight );
  13.         return ( bAlpha and ( iPixels * ( 4 + 4 + 4 + 4 ) ) or ( iPixels * ( 2 + 2 + 2 ) ) ) / 1e+6;
  14.     end;
  15.    
  16.     GetPixelsFromWeight = function ( this, iMiB, bAlpha )
  17.         local iBytes = iMiB * 1e+6;
  18.        
  19.         return ( bAlpha and ( iBytes / ( 4 + 4 + 4 + 4 ) ) or ( iBytes / ( 2 + 2 + 2 ) ) );
  20.     end;
  21. };
  22.  
  23. local iMiB = CRenderTarget:GetWeightFromSize( 1920, 1080, false );
  24.  
  25. print( 'iMiB: ', iMiB ); -- iMiB: 12.4416
  26.  
  27. local iPixels = CRenderTarget:GetPixelsFromWeight( iMiB, false );
  28.  
  29. print( 'iPixels:', iPixels ); -- iPixels: 2073600.0
Add Comment
Please, Sign In to add comment