本文整理汇总了C++中IDirect3DDevice9::CreateIndexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DDevice9::CreateIndexBuffer方法的具体用法?C++ IDirect3DDevice9::CreateIndexBuffer怎么用?C++ IDirect3DDevice9::CreateIndexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DDevice9
的用法示例。
在下文中一共展示了IDirect3DDevice9::CreateIndexBuffer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HDAPIException
void DX9IB::create(int sizeInBytes, HDResourceMgr *pMgr)
{
ASSERT(sizeInBytes > 0);
ASSERT(pMgr);
destroy();
//
DX9ResourceMgr* pDX9Mgr = (DX9ResourceMgr*)pMgr;
IDirect3DDevice9* pDev = pDX9Mgr->getDX9Device();
HRESULT hr;
hr = pDev->CreateIndexBuffer(sizeInBytes,
D3DUSAGE_WRITEONLY, // usage
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&m_pIB, NULL);
if(FAILED(hr))
{
LOG("index buffer create failed, size = %d\r\n", sizeInBytes);
throw HDAPIException("index buffer create failed.");
}
m_sizeInBytes = sizeInBytes;
}
示例2: Create
bool IndexBuffer::Create()
{
Release();
if (!indexCount_)
return true;
if (graphics_)
{
if (graphics_->IsDeviceLost())
{
LOGWARNING("Index buffer creation while device is lost");
return true;
}
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
if (!device || FAILED(device->CreateIndexBuffer(
indexCount_ * indexSize_,
usage_,
indexSize_ == sizeof(unsigned) ? D3DFMT_INDEX32 : D3DFMT_INDEX16,
(D3DPOOL)pool_,
(IDirect3DIndexBuffer9**)&object_,
0)))
{
LOGERROR("Could not create index buffer");
return false;
}
}
return true;
}
示例3: Lock
//----------------------------------------------------------------------------
PdrIndexBuffer::PdrIndexBuffer (Renderer* renderer,
const IndexBuffer* ibuffer)
{
IDirect3DDevice9* device = renderer->mData->mDevice;
UINT numBytes = (UINT)ibuffer->GetNumBytes();
DWORD usage = gDX9BufferUsage[ibuffer->GetUsage()];
D3DFORMAT format =
(ibuffer->GetElementSize() == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32);
D3DPOOL pool;
if (ibuffer->GetUsage() == Buffer::BU_STATIC)
{
pool = D3DPOOL_MANAGED;
}
else
{
pool = D3DPOOL_DEFAULT;
}
HRESULT hr = device->CreateIndexBuffer(numBytes, usage, format,
pool, &mBuffer, 0);
PX2_UNUSED(hr);
assertion(hr == D3D_OK, "Failed to create index buffer: %s\n",
DXGetErrorString(hr));
void* data = Lock(Buffer::BL_WRITE_ONLY);
memcpy(data, ibuffer->GetData(), ibuffer->GetNumBytes());
Unlock();
}
示例4:
/// @copydoc D3D9DeviceResetListener::OnPostReset()
void D3D9DynamicIndexBuffer::OnPostReset( D3D9Renderer* pRenderer )
{
HELIUM_ASSERT( pRenderer );
IDirect3DDevice9* pDevice = pRenderer->GetD3DDevice();
HELIUM_ASSERT( pDevice );
HELIUM_ASSERT( !m_pBuffer );
L_D3D9_VERIFY( pDevice->CreateIndexBuffer(
m_size,
D3DUSAGE_DYNAMIC,
( m_bUse32BitIndices ? D3DFMT_INDEX32 : D3DFMT_INDEX16 ),
D3DPOOL_DEFAULT,
&m_pBuffer,
NULL ) );
}
示例5: f2dGraphicsImpl
f2dGraphics2DImpl::f2dGraphics2DImpl(f2dRenderDeviceImpl* pParent, fuInt VertexBufferCount, fuInt IndexBufferCount)
: f2dGraphicsImpl(pParent),
m_pVB(NULL), m_pIB(NULL),
m_VBMaxCount(VertexBufferCount), m_IBMaxCount(IndexBufferCount),
m_VBUsedCount(0), m_IBUsedCount(0), m_VBAlloced(0), m_IBAlloced(0),
m_pVBData(NULL), m_pIBData(NULL),
m_ColorBlendType(F2DGRAPH2DBLENDTYPE_ADD)
{
// 设置默认的投影矩阵
SetProjTransform(fcyMatrix4::GetOrthoOffCenterLH(
0.f,
(float)pParent->GetBufferWidth(),
(float)pParent->GetBufferHeight(),
0.f, 0.f, 100.f
));
// 创建缓存
HRESULT tHR;
IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle();
if(FAILED(tHR = pDev->CreateVertexBuffer(
m_VBMaxCount * sizeof(f2dGraphics2DVertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
FVF,
D3DPOOL_DEFAULT,
&m_pVB,
NULL)))
{
throw fcyWin32COMException("f2dGraphics2DImpl::f2dGraphics2DImpl", "IDirect3DDevice9::CreateVertexBuffer Failed.", tHR);
}
if(FAILED(tHR = pDev->CreateIndexBuffer(
m_IBMaxCount * sizeof(fuShort),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&m_pIB,
NULL)))
{
FCYSAFEKILL(m_pVB);
throw fcyWin32COMException("f2dGraphics2DImpl::f2dGraphics2DImpl", "IDirect3DDevice9::CreateIndexBuffer Failed.", tHR);
}
// 注册监听器
m_pParent->AttachListener(this);
}
示例6: sizeof
void f2dGraphics2DImpl::OnRenderDeviceReset()
{
IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle();
pDev->CreateVertexBuffer(
m_VBMaxCount * sizeof(f2dGraphics2DVertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
FVF,
D3DPOOL_DEFAULT,
&m_pVB,
NULL);
pDev->CreateIndexBuffer(
m_IBMaxCount * sizeof(fuShort),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&m_pIB,
NULL);
}
示例7: Create
bool IndexBuffer::Create()
{
Release();
if (!indexCount_)
return true;
if (graphics_)
{
if (graphics_->IsDeviceLost())
{
ATOMIC_LOGWARNING("Index buffer creation while device is lost");
return true;
}
unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
HRESULT hr = device->CreateIndexBuffer(
indexCount_ * indexSize_,
d3dUsage,
indexSize_ == sizeof(unsigned) ? D3DFMT_INDEX32 : D3DFMT_INDEX16,
(D3DPOOL)pool,
(IDirect3DIndexBuffer9**)&object_,
0);
if (FAILED(hr))
{
ATOMIC_SAFE_RELEASE(object_.ptr_)
ATOMIC_LOGD3DERROR("Could not create index buffer", hr);
return false;
}
}
return true;
}
示例8: sizeof
void NX::Sphere::CreateTriangles() {
int nV = (m_iStacks - 1) * (m_iSlices + 1) + 2, r, c;
int nI = (m_iStacks - 2) * (m_iSlices + 1) * 2 + (m_iSlices + 2) * 2;
float rr = kfPiOver2, rc, dr = kfPi / m_iStacks, dc = kf2Pi / m_iSlices;
float sr, cr, sc, cc;
IDirect3DDevice9 *pDevice = glb_GetD3DDevice();
m_pVertexs = new Vertex[nV];
{//calculate vertex data
Vertex *pVertex = m_pVertexs;
*pVertex++ = { 0.f, m_fRadius, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f };
for (r = 1; r < m_iStacks; ++r) {
rr -= dr;
rc = 0.f;
cr = std::cosf(rr), sr = std::sinf(rr);
for (c = 0; c <= m_iSlices; ++c) {
sc = std::sinf(rc);
cc = std::cosf(rc);
*pVertex++ = { m_fRadius * cr * cc, m_fRadius * sr, m_fRadius * cr * sc, c * 1.f / m_iSlices, r * 1.f / m_iStacks, cr * cc, sr, cr * sc };
rc += dc;
}
}
*pVertex = { 0.f, -m_fRadius, 0.f, 0.f, 1.f, 0.f, -1.f, 0.f };
pDevice->CreateVertexBuffer(sizeof(Vertex) * nV, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_pVertexBuffer, nullptr);
void *pBase = nullptr;
m_pVertexBuffer->Lock(0, 0, &pBase, D3DLOCK_DISCARD);
memcpy(pBase, m_pVertexs, sizeof(Vertex) * nV);
m_pVertexBuffer->Unlock();
}
{//vertex desc
D3DVERTEXELEMENT9 VertexDesc[] = {
{ 0, CLS_MEM_OFFSET(Vertex, x), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, CLS_MEM_OFFSET(Vertex, u), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, CLS_MEM_OFFSET(Vertex,nx), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END(),
};
pDevice->CreateVertexDeclaration(VertexDesc, &m_pVertexDesc);
}
{//calculate index data
pDevice->CreateIndexBuffer(nI * sizeof(int), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &m_pIndexBuffer, nullptr);
int *pBase = nullptr;
m_pIndexBuffer->Lock(0, 0, (void**)&pBase, D3DLOCK_DISCARD);
for (int i = 0; i <= m_iSlices + 1; ++i) {//first stack, triangle_fan
*pBase++ = i;
}
int a = 1;
for (int i = 1; i < m_iStacks - 1; ++i) {//inner stacks, triangle_list
for (int j = 0; j <= m_iSlices; ++j) {
*pBase++ = a;
*pBase++ = a + m_iSlices + 1;
++a;
}
}
*pBase++ = (m_iStacks - 1) * (m_iSlices + 1) + 1;
for (int i = 0; i <= m_iSlices; ++i) {
*pBase++ = (m_iStacks - 2) * (m_iSlices + 1) + 1 + i;
}
m_pIndexBuffer->Unlock();
}
}