*
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
#ifndef I_INDEX_BUFFER11_H__
|
||||
#define I_INDEX_BUFFER11_H__
|
||||
|
||||
#include "render/IIndexBuffer.h"
|
||||
#include "Globals.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "IMemoryStream.h"
|
||||
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IIndexBuffer11 : public IIndexBuffer
|
||||
{
|
||||
public:
|
||||
ID3D11Buffer* ib;
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
D3D11_MAPPED_SUBRESOURCE* mappedData;
|
||||
LifeCore::IMemoryStream stm;
|
||||
|
||||
~IIndexBuffer11()
|
||||
{
|
||||
SAFE_RELEASE(ib);
|
||||
}
|
||||
IIndexBuffer11(ID3D11Device* _device, void* pBuffer, int _size, int _sixteenBit, int staging)
|
||||
{
|
||||
device = _device;
|
||||
length = _size;
|
||||
isShort = _sixteenBit;
|
||||
|
||||
//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_INDEX_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, &ib );
|
||||
}
|
||||
else
|
||||
device->CreateBuffer( &bd, NULL, &ib );
|
||||
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(ib,0, mapFlags,0, mappedData);
|
||||
stm.Reset(((char*)mappedData->pData) + offset, length);
|
||||
return &stm;
|
||||
}
|
||||
void Unmap()
|
||||
{
|
||||
context->Unmap(ib, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user