Advertisement
ItsTotallyRSX

buffer rewrite

Sep 22nd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. static void D3DActionLoop(const Zones::ZoneFunctions * functions, std::function<HRESULT(ID3D11Device * device)> callback)
  2. {
  3.     if (!functions->T6.device)
  4.         return;
  5.  
  6.     while (true)
  7.     {
  8.         HRESULT err;
  9.         auto alwaysFails = functions->T6.alwaysfails;
  10.  
  11.         err = callback(*functions->T6.device);
  12.         if (!FAILED(err))
  13.             return;
  14.  
  15.         LogWarn("D3D11 action failed. Error: %xu", err);
  16.  
  17.         if (!alwaysFails)
  18.             break;
  19.  
  20.         if ((alwaysFails) && (*alwaysFails == 0))
  21.             break;
  22.     }
  23. }
  24.  
  25. void R_LoadIndexBuffer(const Zones::ZoneFunctions * functions, ID3D11Buffer **ib, int size, const void *data)
  26. {
  27.     D3DActionLoop(functions, [size, data, ib](ID3D11Device * device)
  28.     {
  29.         D3D11_BUFFER_DESC bufferDesc    = { 0 };
  30.         D3D11_SUBRESOURCE_DATA initData = { 0 };
  31.  
  32.         initData.pSysMem          = data;
  33.         initData.SysMemPitch      = 0;
  34.         initData.SysMemSlicePitch = 0;
  35.  
  36.  
  37.         bufferDesc.Usage          = D3D11_USAGE_DEFAULT;
  38.         bufferDesc.ByteWidth      = size * sizeof(uint16_t);
  39.         bufferDesc.BindFlags      = D3D11_BIND_INDEX_BUFFER;
  40.         bufferDesc.CPUAccessFlags = 0;
  41.         bufferDesc.MiscFlags      = 0;
  42.  
  43.         return device->CreateBuffer(&bufferDesc, &initData, ib);
  44.     });
  45. }
  46.  
  47. void R_LoadVertexBuffer(const Zones::ZoneFunctions * functions, ID3D11Buffer **ib, int sizeInBytes, const void *data)
  48. {
  49.     D3DActionLoop(functions, [sizeInBytes, data, ib](ID3D11Device * device)
  50.     {
  51.         D3D11_BUFFER_DESC bufferDesc    = { 0 };
  52.         D3D11_SUBRESOURCE_DATA initData = { 0 };
  53.  
  54.         initData.pSysMem          = data;
  55.         initData.SysMemPitch      = 0;
  56.         initData.SysMemSlicePitch = 0;
  57.  
  58.  
  59.         bufferDesc.Usage          = D3D11_USAGE_DEFAULT;
  60.         bufferDesc.ByteWidth      = sizeInBytes;
  61.         bufferDesc.BindFlags      = D3D11_BIND_VERTEX_BUFFER;
  62.         bufferDesc.CPUAccessFlags = 0;
  63.         bufferDesc.MiscFlags      = 0;
  64.  
  65.         return device->CreateBuffer(&bufferDesc, &initData, ib);
  66.     });
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement