*
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
#ifndef I_VERTEX_BUFFER11_H__
|
||||
#define I_VERTEX_BUFFER11_H__
|
||||
|
||||
#include "render/IVertexBuffer.h"
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "IMemoryStream.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IVertexBuffer11 : public IVertexBuffer
|
||||
{
|
||||
public:
|
||||
ID3D11Buffer* vb;
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
D3D11_MAPPED_SUBRESOURCE mappedData;
|
||||
LifeCore::IMemoryStream stm;
|
||||
|
||||
~IVertexBuffer11()
|
||||
{
|
||||
SAFE_RELEASE(vb);
|
||||
}
|
||||
IVertexBuffer11(ID3D11Device* _device, void* pBuffer, int _size, int _stride, int staging)
|
||||
{
|
||||
device = _device;
|
||||
length = _size;
|
||||
stride = _stride;
|
||||
|
||||
//g_desc = new BufferDescription(size, D3D11.ResourceUsage.Default,
|
||||
// BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
|
||||
D3D11_BUFFER_DESC bd;
|
||||
ZeroMemory( &bd, sizeof(bd) );
|
||||
if(pBuffer)
|
||||
bd.Usage = D3D11_USAGE_DEFAULT;
|
||||
else
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
if(staging)
|
||||
bd.Usage = D3D11_USAGE_STAGING;
|
||||
|
||||
bd.ByteWidth = _size;
|
||||
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
|
||||
if(bd.Usage == D3D11_USAGE_DEFAULT)
|
||||
bd.CPUAccessFlags = 0;
|
||||
else if(bd.Usage == D3D11_USAGE_DYNAMIC)
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
else if(bd.Usage == D3D11_USAGE_STAGING)
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
|
||||
|
||||
if(pBuffer)
|
||||
{
|
||||
D3D11_SUBRESOURCE_DATA InitData;
|
||||
ZeroMemory( &InitData, sizeof(InitData) );
|
||||
InitData.pSysMem = pBuffer;
|
||||
|
||||
device->CreateBuffer( &bd, &InitData, &vb );
|
||||
}
|
||||
else
|
||||
device->CreateBuffer( &bd, NULL, &vb );
|
||||
device->GetImmediateContext(&context);
|
||||
//if( FAILED( hr ) )
|
||||
// return hr;
|
||||
}
|
||||
LifeCore::IDataStream* Map(int offset, int flags)
|
||||
{
|
||||
D3D11_MAP mapFlags;
|
||||
|
||||
if (flags & LF_Discard)
|
||||
mapFlags = D3D11_MAP_WRITE_DISCARD;
|
||||
else if ((flags & LF_NoOverwrite))
|
||||
mapFlags = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
|
||||
else if ((flags & LF_ReadOnly))
|
||||
mapFlags = D3D11_MAP_READ;
|
||||
|
||||
else if (flags == LF_None)
|
||||
mapFlags = D3D11_MAP_READ_WRITE;
|
||||
else
|
||||
mapFlags = D3D11_MAP_WRITE;
|
||||
|
||||
context->Map(vb,0, mapFlags,0, &mappedData);
|
||||
stm.Reset(((char*)mappedData.pData) + offset, length);
|
||||
return &stm;
|
||||
}
|
||||
void Update(void* data, size_t length)
|
||||
{
|
||||
D3D11_BOX b;
|
||||
b.left = 0;
|
||||
b.right = 1;
|
||||
b.top = 0;
|
||||
b.bottom = 1;
|
||||
b.front = 0;
|
||||
b.back = 0;
|
||||
context->UpdateSubresource(vb, 0, NULL, data, length, 0);
|
||||
}
|
||||
void Unmap()
|
||||
{
|
||||
context->Unmap(vb, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user