当前位置: 首页>>代码示例>>C++>>正文


C++ IDirect3DIndexBuffer9类代码示例

本文整理汇总了C++中IDirect3DIndexBuffer9的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DIndexBuffer9类的具体用法?C++ IDirect3DIndexBuffer9怎么用?C++ IDirect3DIndexBuffer9使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IDirect3DIndexBuffer9类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Cache

bool CIndexBuffer::Cache(CDisplayDevice *poDisplayDevice) {
#if RENDER == DX9
	IDirect3DIndexBuffer9* IB;

	int len = sizeof(unsigned short) * m_iNumIndices; 
	HRESULT result = poDisplayDevice->m_pDevice->CreateIndexBuffer(
		len, 
		D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16, 
		D3DPOOL_SYSTEMMEM,
		&IB, 
		0);

	if (result != D3D_OK)
		return false;

	char *buffer;
	IB->Lock(0, 0, (void **)&buffer, 0);
	memcpy(buffer, GetIndexBuffer(), len);
	IB->Unlock();

	m_pCachedData = IB;
#endif

	return true;
}
开发者ID:goldenpython,项目名称:ObjLoader,代码行数:26,代码来源:IndexBuffer.cpp

示例2: rp

void Impl::Unlock(BytesPtr srcBytes, BytesPtr dstBytes)
{
    bytes::read_proc rp(srcBytes);
    ProxyId id;
    rp(id);
    
    IDirect3DIndexBuffer9 *self = procMap_->getPtr<IDirect3DIndexBuffer9>(id);
    
    UINT offset, size;
    DWORD flags;

    rp(offset);
    rp(size);
    rp(flags);
    char *ptr = nullptr;

    HRESULT res;
    
    res = self->Lock(offset, size, reinterpret_cast<void**>(&ptr), flags);
    if (SUCCEEDED(res))
    {
        rp.array(ptr, size);
        res = self->Unlock();
        Assert(SUCCEEDED(res));
    }
    else
    {
        vector<char> dump(size);
        rp.array(dump.data(), size);
        Assert(false);
    }

    bytes::write_proc wp(dstBytes);
    wp(res);
}
开发者ID:vasily-knk,项目名称:D3Digger,代码行数:35,代码来源:ProcImpl_IB.cpp

示例3: MFVertex_LockIndexBuffer

MF_API void MFVertex_LockIndexBuffer(MFIndexBuffer *pIndexBuffer, uint16 **ppIndices)
{
	MFDebug_Assert(!pIndexBuffer->bLocked, "Index buffer already locked!");

	IDirect3DIndexBuffer9 *pIB = (IDirect3DIndexBuffer9*)pIndexBuffer->pPlatformData;
	HRESULT hr = pIB->Lock(0, sizeof(uint16)*pIndexBuffer->numIndices, &pIndexBuffer->pLocked, 0);
	MFDebug_Assert(SUCCEEDED(hr), "Failed to lock index buffer");

	if(ppIndices)
		*ppIndices = (uint16*)pIndexBuffer->pLocked;

	pIndexBuffer->bLocked = true;
}
开发者ID:TurkeyMan,项目名称:fuji,代码行数:13,代码来源:MFVertex_D3D9.cpp

示例4: Gfx_IndexBuffer_Lock

    IndexBufferLock Gfx_IndexBuffer_Lock(RenderDevice* dev, IndexBufferHandle h, uint32 offset, uint32 size) 
    { 
        IndexBufferLock lock;

        if( h.valid() )
        {
            lock.size = size;
            lock.handle = h;

            uint32 flags = buffer_mode_to_d3d_lock_flags(dev->resources->index_buffers[h].desc.mode);

            IDirect3DIndexBuffer9* ib = dev->resources->index_buffers[h].native;
            HRESULT hr = ib->Lock(offset, size, &lock.data, flags);
            validate_d3d_result(hr);
        }

        return lock;
    };
开发者ID:kayru,项目名称:reversez,代码行数:18,代码来源:GfxDeviceDX9.cpp

示例5: PX2_UNUSED

//----------------------------------------------------------------------------
void PdrIndexBuffer::Disable (Renderer* renderer)
{
	IDirect3DDevice9* device = renderer->mData->mDevice;
	HRESULT hr;
	PX2_UNUSED(hr);

#ifdef PX2_PDR_DEBUG
	// 检测需要被取消激活的数据,是否匹配。
	IDirect3DIndexBuffer9 *activeBuffer = 0;
	hr = device->GetIndices(&activeBuffer);
	assertion(hr == D3D_OK, "Failed to get indices: %s\n",
		DXGetErrorString(hr));
	assertion(activeBuffer == mBuffer, "Mismatched index buffers\n");
	activeBuffer->Release();
#endif

	hr = device->SetIndices(0);
	assertion(hr == D3D_OK, "Failed to set indices: %s\n",
		DXGetErrorString(hr));
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:21,代码来源:PX2Dx9IndexBuffer.cpp

示例6: MFVertex_UnlockIndexBuffer

MF_API void MFVertex_UnlockIndexBuffer(MFIndexBuffer *pIndexBuffer)
{
	MFDebug_Assert(pIndexBuffer->bLocked, "Index buffer not locked!");

	IDirect3DIndexBuffer9 *pIB = (IDirect3DIndexBuffer9*)pIndexBuffer->pPlatformData;
	pIB->Unlock();

	pIndexBuffer->pLocked = NULL;
	pIndexBuffer->bLocked = false;
/*
	// why on earth did I defer the index locking to a post process???
	IDirect3DIndexBuffer9 *pIB = (IDirect3DIndexBuffer9*)pIndexBuffer->pPlatformData;

	void *pData;
	pIB->Lock(0, 0, &pData, 0);
	MFCopyMemory(pData, pIndexBuffer->pIndices, sizeof(uint16)*pIndexBuffer->numIndices);
	pIB->Unlock();

	pIndexBuffer->bLocked = false;
*/
}
开发者ID:TurkeyMan,项目名称:fuji,代码行数:21,代码来源:MFVertex_D3D9.cpp

示例7: sizeof

void Terrain::AlllocateBuffers()
{
	IDirect3DVertexBuffer9* vb;
	d3dContext->CreateVertexBuffer(
		m_uNumVertices*sizeof(TexVertex),
		D3DUSAGE_WRITEONLY,
		TexVertex::FVF_TEX,
		D3DPOOL_MANAGED,
		&vb,
		0);
	m_spVetexBuffer.reset(vb, [](IDirect3DVertexBuffer9* vb) {vb->Release(); });

	IDirect3DIndexBuffer9* ib;
	d3dContext->CreateIndexBuffer(
		m_uNumTriangles * 3 * sizeof(DWORD),
		D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX32,
		D3DPOOL_MANAGED,
		&ib,
		0);
	m_spIndexBuffer.reset(ib, [](IDirect3DIndexBuffer9* ib) {ib->Release(); });
}
开发者ID:ECNU-ZR,项目名称:physwf-c-lab,代码行数:22,代码来源:Terrain.cpp

示例8: MFVertex_CreateIndexBufferPlatformSpecific

bool MFVertex_CreateIndexBufferPlatformSpecific(MFIndexBuffer *pIndexBuffer, uint16 *pIndexBufferMemory)
{
	IDirect3DIndexBuffer9 *pIB;
	HRESULT hr = pd3dDevice->CreateIndexBuffer(sizeof(uint16)*pIndexBuffer->numIndices, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &pIB, NULL);
	MFDebug_Assert(SUCCEEDED(hr), "Failed to create index buffer");
	if(FAILED(hr))
		return false;

	if(pIndexBuffer->pName)
		MFRenderer_D3D9_SetDebugName(pIB, pIndexBuffer->pName);
	pIndexBuffer->pPlatformData = pIB;

	if(pIndexBufferMemory)
	{
		void *pData;
		pIB->Lock(0, 0, &pData, 0);
		MFCopyMemory(pData, pIndexBufferMemory, sizeof(uint16)*pIndexBuffer->numIndices);
		pIB->Unlock();
	}

	return true;
}
开发者ID:TurkeyMan,项目名称:fuji,代码行数:22,代码来源:MFVertex_D3D9.cpp

示例9: StripifyMeshSubset

bool StripifyMeshSubset(ID3DXMesh* mesh,
                        DWORD attribId,
                        ostream& meshfile)
{
    // TODO: Fall back to tri lists if the strip size is too small
    // TODO: Detect when a tri fan should be used instead of a tri list

    // Convert to tri strips
    IDirect3DIndexBuffer9* indices = NULL;
    DWORD numIndices = 0;
    ID3DXBuffer* strips = NULL;
    DWORD numStrips = 0;
    HRESULT hr;
    hr = D3DXConvertMeshSubsetToStrips(mesh,
                                       attribId,
                                       0,
                                       &indices,
                                       &numIndices,
                                       &strips,
                                       &numStrips);
    if (FAILED(hr))
    {
        cout << "Stripify failed\n";
        return false;
    }

    cout << "Converted to " << numStrips << " strips\n";
    cout << "Strip buffer size: " << strips->GetBufferSize() << '\n';
    if (numStrips != strips->GetBufferSize() / 4) 
    {
        cout << "Strip count is incorrect!\n";
        return false;
    }

    bool index32 = false;
    {
        D3DINDEXBUFFER_DESC desc;
        indices->GetDesc(&desc);
        if (desc.Format == D3DFMT_INDEX32)
        {
            index32 = true;
        }
        else if (desc.Format == D3DFMT_INDEX16)
        {
            index32 = false;
        }
        else
        {
            cout << "Bad index format.  Strange.\n";
            return false;
        }
    }

    void* indexData = NULL;
    hr = indices->Lock(0, 0, &indexData, D3DLOCK_READONLY);
    if (FAILED(hr))
    {
        cout << "Failed to lock index buffer: " << D3DErrorString(hr) << '\n';
        return false;
    }

    {
        DWORD* stripLengths = reinterpret_cast<DWORD*>(strips->GetBufferPointer());
        int k = 0;
        for (int i = 0; i < numStrips; i++)
        {
            if (stripLengths[i] == 0)
            {
                cout << "Bad triangle strip (length == 0) in mesh!\n";
                return false;
            }

            if (index32)
            {
                DWORD* indices = reinterpret_cast<DWORD*>(indexData) + k;
                int fanStart = checkForFan(stripLengths[i], indices);
                if (fanStart != 1)
                {
                    DumpTriStrip(stripLengths[i], indices, (int) attribId,
                                 meshfile);
                }
                else
                {
                    DumpTriStripAsFan(stripLengths[i], indices, (int) attribId,
                                      fanStart, meshfile);
                }
            }
            else
            {
                WORD* indices = reinterpret_cast<WORD*>(indexData) + k;
                int fanStart = checkForFan(stripLengths[i], indices);
                if (fanStart != 1)
                {
                    DumpTriStrip(stripLengths[i], indices, (int) attribId,
                                 meshfile);
                }
                else
                {
                    DumpTriStripAsFan(stripLengths[i], indices, (int) attribId,
                                      fanStart, meshfile);
//.........这里部分代码省略.........
开发者ID:Habatchii,项目名称:celestia,代码行数:101,代码来源:xtocmod.cpp

示例10: D3DXCreateMeshFVF

Map::Map(std::string RAW_File_Name,
		 int Vertex_Length,
		 int Vertex_Width,
		 int Cell_Spacing,
		 float Height_Scale)
{
	vertex_length = Vertex_Length;
	vertex_width = Vertex_Width;

	total_vertices = vertex_length * vertex_width;				//Total = L * W

	cell_length = vertex_length - 1;
	cell_width = vertex_width - 1;

	cell_spacing = Cell_Spacing;
	height_scale = Height_Scale;

	length = cell_length * cell_spacing;
	width = cell_width * cell_spacing;

	total_triangles = cell_length * cell_width * 2;

	D3DXCreateMeshFVF(cell_length * cell_width * 2,
		vertex_length * vertex_width,
		D3DXMESH_MANAGED,
		Terrain_Vertex::FVF,
		d3ddev,
		&mesh);

	if (!Raw_To_Int_Vector(RAW_File_Name))
	{
		MessageBox(0, "Raw_To_Int_Vector - FAILED", 0, 0);
		PostQuitMessage(0);
	}

	for (int i = 0; i < height_int_vector.size(); i++)
	{
		height_float_vector.push_back((float)height_int_vector[i]);

		height_float_vector[i] = height_float_vector[i] * height_scale;
	}

	if (!Create_Normals(&LightDirectionThree))
	{
		MessageBox(0, "Create_Normals - FAILED", 0, 0);
		PostQuitMessage(0);
	}

	Generate_Vertex_Normals();

	if (!Generate_Vertices())
	{
		MessageBox(0, "Generate_Vertices - FAILED", 0, 0);
		PostQuitMessage(0);
	}

	if (!Generate_Indices())									//Also Generates Mesh
	{
		MessageBox(0, "Generate_Indices - FAILED", 0, 0);
		PostQuitMessage(0);
	}

	adjacency_buffer = new DWORD[cell_width * cell_length * 2 * 3];

	mesh->GenerateAdjacency(0.001f, adjacency_buffer);
	mesh->OptimizeInplace(D3DXMESH_MANAGED |
		D3DXMESHOPT_COMPACT |
		D3DXMESHOPT_ATTRSORT | 
		D3DXMESHOPT_VERTEXCACHE,
		adjacency_buffer,
		adjacency_buffer,
		0,
		0);

	IDirect3DVertexBuffer9* bufvert;
	Terrain_Vertex* tempvert;

	mesh->GetVertexBuffer(&bufvert);
	bufvert->Lock(0, 0, (void**)&tempvert, 0);
	vertexdata = tempvert;
	bufvert->Unlock();

	IDirect3DIndexBuffer9* bufind;
	WORD* tempind;

	mesh->GetIndexBuffer(&bufind);
	bufind->Lock(0, 0, (void**)&tempind, 0);
	indexdata = tempind;
	bufind->Unlock();

	SafeRelease(bufvert);
	SafeRelease(bufind);
}
开发者ID:guorenxu,项目名称:3DGamePrototype,代码行数:93,代码来源:Maps.cpp

示例11: build_submodel

    void build_submodel( SubModel& m )
    {
        const std::vector< model_vertex_type >& vsrc = m.vertex_source;
        const std::vector< WORD >&              isrc = m.index_source;

        if( vsrc.empty() || isrc.empty() ) {
            return;
        }

        // triangle vb
        {
            IDirect3DVertexBuffer9* vb = NULL;
            if( FAILED( device_->CreateVertexBuffer(
                            UINT( vsrc.size() ) *
                            sizeof( model_vertex_type ),
                            0,
                            0,
                            D3DPOOL_MANAGED,
                            &vb,
                            NULL ) ) ) {
                onError( "create vertex buffer failed\n" );
                return;
            }
                        
            model_vertex_type* p;
            if( FAILED( vb->Lock( 0, 0, (void**)&p, 0 ) ) ) {
                onError( "Lock vertexbuffer failed\n" );
                vb->Release();
                return;
            }

            int mm = int(vsrc.size());
            for( int j = 0 ; j < mm ; j++ ){
                *p++ = vsrc[j];
            }

            vb->Unlock();
            m.vb = vb;
        }

        // triangle ib
        {
            IDirect3DIndexBuffer9* ib = NULL;
            if( FAILED( device_->CreateIndexBuffer(
                            UINT( isrc.size() ) *
                            sizeof( WORD ),
                            0,
                            D3DFMT_INDEX16,
                            D3DPOOL_MANAGED,
                            &ib,
                            NULL ) ) ) {
                onError( "create index buffer failed\n" );
                m.vb->Release();
                return;
            }
                                
            WORD* p;
            if( FAILED( ib->Lock( 0, 0, (void**)&p, 0 ) ) ) {
                onError( "Lock vertexbuffer failed\n" );
                m.vb->Release();
                ib->Release();
                return;
            }

            int mm = int(isrc.size());
            for( int j = 0 ; j < mm ; j++ ){
                *p++ = isrc[j];
            }

            ib->Unlock();
            m.ib = ib;
        }                        
    }
开发者ID:jonigata,项目名称:yamadumi,代码行数:73,代码来源:shape.cpp

示例12: buildGeoBuffers

void TriGridDemo::buildGeoBuffers()
{
	std::vector<D3DXVECTOR3> verts;
	std::vector<DWORD> indices;

	GenTriGrid(100, 100, 1.0f, 1.0f, D3DXVECTOR3(0.0f, 0.0f, 0.0f), verts, indices);

	mNumVertices  = 100*100;
	mNumTriangles = 99*99*2;

	HR(gd3dDevice->CreateVertexBuffer(mNumVertices * sizeof(VertexPos),
		D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &mVB, 0));

	VertexPos *v = 0;
	HR(mVB->Lock(0, 0, (void**)&v, 0));
	for (DWORD i = 0; i < mNumVertices; ++i) v[i] = verts[i];
	HR(mVB->Unlock());

	HR(gd3dDevice->CreateIndexBuffer(mNumTriangles*3*sizeof(WORD), D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16, D3DPOOL_MANAGED, &mIB, 0));

	WORD *k = 0;
	HR(mIB->Lock(0, 0, (void**)&k, 0));
	for (DWORD i = 0; i < mNumTriangles*3; ++i) k[i] = (WORD)indices[i];
	HR(mIB->Unlock());
}
开发者ID:kasicass,项目名称:introdx9,代码行数:26,代码来源:TriGridDemo.cpp

示例13: buildIndexBuffer

void CubeDemo::buildIndexBuffer()
{
	HR(gd3dDevice->CreateIndexBuffer(36*sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &mIB, 0));

	WORD *k = 0;
	HR(mIB->Lock(0, 0, (void**)&k, 0));

	// front
	k[0] = 0; k[1] = 1; k[2] = 2;
	k[3] = 0; k[4] = 2; k[5] = 3;

	// back
	k[6] = 4; k[7] = 6; k[8] = 5;
	k[9] = 4; k[10] = 7; k[11] = 6;

	// left
	k[12] = 4; k[13] = 5; k[14] = 1;
	k[15] = 4; k[16] = 1; k[17] = 0;

	// right
	k[18] = 3; k[19] = 2; k[20] = 6;
	k[21] = 3; k[22] = 6; k[23] = 7;

	// top
	k[24] = 1; k[25] = 5; k[26] = 6;
	k[27] = 1; k[28] = 6; k[29] = 2;

	k[30] = 4; k[31] = 0; k[32] = 3;
	k[33] = 4; k[34] = 3; k[35] = 7;

	HR(mIB->Unlock());
}
开发者ID:kasicass,项目名称:introdx9,代码行数:32,代码来源:CubeDemo.cpp

示例14: buildGridGeometry

void MultiTexDemo::buildGridGeometry()
{
	std::vector<D3DXVECTOR3> verts;
	std::vector<DWORD> indices;

	GenTriGrid(100, 100, 1.0f, 1.0f, 
		D3DXVECTOR3(0.0f, 0.0f, 0.0f), verts, indices);

	// Save vertex count and triangle count for DrawIndexedPrimitive arguments.
	mNumGridVertices  = 100*100;
	mNumGridTriangles = 99*99*2;

	// Obtain a pointer to a new vertex buffer.
	HR(gd3dDevice->CreateVertexBuffer(mNumGridVertices * sizeof(VertexPNT), 
		D3DUSAGE_WRITEONLY,	0, D3DPOOL_MANAGED, &mGridVB, 0));

	// Now lock it to obtain a pointer to its internal data, and write the
	// grid's vertex data.
	VertexPNT* v = 0;
	HR(mGridVB->Lock(0, 0, (void**)&v, 0));

	float w = 99.0f; 
	float d = 99.0f;
	for(int i = 0; i < 100; ++i)
	{
		for(int j = 0; j < 100; ++j)
		{
			DWORD index = i * 100 + j;
			v[index].pos    = verts[index];
			v[index].normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
			v[index].tex0.x = (v[index].pos.x + (0.5f*w)) / w;
			v[index].tex0.y = (v[index].pos.z - (0.5f*d)) / -d;
		}
	}

	HR(mGridVB->Unlock());


	// Obtain a pointer to a new index buffer.
	HR(gd3dDevice->CreateIndexBuffer(mNumGridTriangles*3*sizeof(WORD), D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16, D3DPOOL_MANAGED, &mGridIB, 0));

	// Now lock it to obtain a pointer to its internal data, and write the
	// grid's index data.

	WORD* k = 0;
	HR(mGridIB->Lock(0, 0, (void**)&k, 0));

	for(DWORD i = 0; i < mNumGridTriangles*3; ++i)
		k[i] = (WORD)indices[i];

	HR(mGridIB->Unlock());
}
开发者ID:derekqian,项目名称:d3dcoder,代码行数:53,代码来源:MultiTexDemo.cpp

示例15: buildGeoBuffers

void SpotlightDemo::buildGeoBuffers()
{
	std::vector<D3DXVECTOR3> verts;
	std::vector<DWORD> indices;

	GenTriGrid(100, 100, 1.0f, 1.0f, 
		D3DXVECTOR3(0.0f, 0.0f, 0.0f), verts, indices);

	// Save vertex count and triangle count for DrawIndexedPrimitive arguments.
	mNumGridVertices  = 100*100;
	mNumGridTriangles = 99*99*2;

	// Obtain a pointer to a new vertex buffer.
	HR(gd3dDevice->CreateVertexBuffer(mNumGridVertices * sizeof(VertexPN), 
		D3DUSAGE_WRITEONLY,	0, D3DPOOL_MANAGED, &mVB, 0));

	// Now lock it to obtain a pointer to its internal data, and write the
	// grid's vertex data.
	VertexPN* v = 0;
	HR(mVB->Lock(0, 0, (void**)&v, 0));

	for(DWORD i = 0; i < mNumGridVertices; ++i)
	{
		v[i].pos = verts[i];
		v[i].normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	}

	HR(mVB->Unlock());


	// Obtain a pointer to a new index buffer.
	HR(gd3dDevice->CreateIndexBuffer(mNumGridTriangles*3*sizeof(WORD), D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16, D3DPOOL_MANAGED, &mIB, 0));

	// Now lock it to obtain a pointer to its internal data, and write the
	// grid's index data.

	WORD* k = 0;
	HR(mIB->Lock(0, 0, (void**)&k, 0));

	for(DWORD i = 0; i < mNumGridTriangles*3; ++i)
		k[i] = (WORD)indices[i];

	HR(mIB->Unlock());
}
开发者ID:nguyenkim495,项目名称:KidBuu,代码行数:45,代码来源:SpotlightDemo.cpp


注:本文中的IDirect3DIndexBuffer9类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。