Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. void Render(ID3D11DeviceContext* devcontext, ID3D11Buffer* iBuffer)
  2. {
  3. if (m_quads.size() == 0)
  4. return;
  5. UINT stride = sizeof(TL_VERTEX);
  6. UINT offset = 0;
  7. int size = (m_quads.size()) * 6;
  8. int numVertices = 0;
  9. D3D11_MAPPED_SUBRESOURCE ms;
  10. if (m_quads.size() == 0)
  11. return;
  12. devcontext->Map(m_vb, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
  13. for (int i = 0; i < m_quads.size(); i++)
  14. {
  15. memcpy(&ms.pData + (i - 1 * sizeof(m_quads[i].m_vertices)), &m_quads[i].m_vertices, sizeof(m_quads[i].m_vertices));
  16. numVertices = numVertices + (sizeof(TL_VERTEX) * 6);
  17. }
  18. //std::cout << sizeof(ms.pData) << std::endl;
  19. devcontext->Unmap(m_vb, NULL);
  20. devcontext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset);
  21. devcontext->PSSetShaderResources(0, 1, &m_texture);
  22. if (indexCount < size)
  23. {
  24. indexCount = size;
  25. std::cout << "IndexCount is smaller! " << indexCount << " | " << size << std::endl;
  26. tempIndices = new DWORD[indexCount];
  27. for (int i = 0; i < indexCount; i = i + 6)
  28. {
  29. //std::cout << i << std::endl;
  30. tempIndices[i] = i;
  31. tempIndices[i + 1] = i + 1;
  32. tempIndices[i + 2] = i + 2;
  33. tempIndices[i + 3] = i + 3;
  34. tempIndices[i + 4] = i + 4;
  35. tempIndices[i + 5] = i + 5;
  36. }
  37. }
  38.  
  39. D3D11_MAPPED_SUBRESOURCE is;
  40. devcontext->Map(iBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &is);
  41. memcpy(is.pData, &tempIndices, sizeof(tempIndices));
  42. devcontext->Unmap(iBuffer, NULL);
  43. devcontext->IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0);
  44. //std::cout << sizeof(m_quads) << std::endl;
  45. //devcontext->DrawIndexed(6, 0, 0);
  46. devcontext->DrawIndexed(numVertices, 0, 0);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement