Advertisement
GAMELASTER

Untitled

Jan 6th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #pragma once
  2. #include "DirectXContext.h"
  3.  
  4.  
  5. struct VERTEX { D3DXVECTOR3 Pos; D3DXCOLOR Color; };
  6.  
  7. class Mesh
  8. {
  9. public:
  10.     template<size_t N> Mesh(DirectXContext *dxc, VERTEX(&vertices)[N])
  11.     {
  12.         // create the vertex buffer
  13.         D3D11_BUFFER_DESC bd;
  14.         ZeroMemory(&bd, sizeof(bd));
  15.  
  16.         bd.Usage = D3D11_USAGE_DYNAMIC;                
  17.         bd.ByteWidth = sizeof(VERTEX) * 3;            
  18.         bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;      
  19.         bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;    
  20.  
  21.         dxc->dev->CreateBuffer(&bd, NULL, &pVBuffer);  
  22.  
  23.  
  24.                                                        
  25.         D3D11_MAPPED_SUBRESOURCE ms;
  26.         dxc->devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);  
  27.         memcpy(ms.pData, vertices, sizeof(vertices));                
  28.         dxc->devcon->Unmap(pVBuffer, NULL);                                
  29.     }
  30.     //Mesh(DirectXContext *dxc, VERTEX vertices[3]);
  31.     ID3D11Buffer *pVBuffer;              
  32.     virtual ~Mesh();
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement