本文整理汇总了C++中LPDIRECT3DVERTEXBUFFER9::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DVERTEXBUFFER9::Lock方法的具体用法?C++ LPDIRECT3DVERTEXBUFFER9::Lock怎么用?C++ LPDIRECT3DVERTEXBUFFER9::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DVERTEXBUFFER9
的用法示例。
在下文中一共展示了LPDIRECT3DVERTEXBUFFER9::Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: D3DQuads_Begin
void D3DQuads_Begin (int numquads, quadvert_t **quadverts)
{
D3DQuads_OnRecover ();
D3D_SetStreamSource (0, d3d_QuadBuffer, 0, sizeof (quadvert_t));
D3D_SetStreamSource (1, NULL, 0, 0);
D3D_SetStreamSource (2, NULL, 0, 0);
D3D_SetStreamSource (3, NULL, 0, 0);
D3D_SetIndices (d3d_QuadIndexes);
D3D_SetVertexDeclaration (d3d_QuadDecl);
if (d3d_NumQuads + numquads >= D3D_MAX_QUADS)
{
d3d_QuadBuffer->Lock (0, 0, (void **) quadverts, d3d_GlobalCaps.DiscardLock);
d3d_NumQuads = 0;
}
else
{
d3d_QuadBuffer->Lock (d3d_NumQuads * 4 * sizeof (quadvert_t),
numquads * 4 * sizeof (quadvert_t),
(void **) quadverts,
d3d_GlobalCaps.NoOverwriteLock);
}
d3d_QuadsToDraw = numquads;
}
示例2: initRectangleVertexes
void initRectangleVertexes()
{
VertexData data[4] = {
/* x y z u v */
{ 0, 0, 0, 0, 0 },
{ Width, 0, 0, 1, 0 },
{ 0, Height, 0, 0, 1 },
{ Width, Height, 0, 1, 1 }
};
void *pRectBuffer = NULL;
device->CreateVertexBuffer(4 * sizeof(VertexData), D3DUSAGE_WRITEONLY,
D3DFVF_XYZ | D3DFVF_TEX0, D3DPOOL_DEFAULT, &pRectObject, NULL);
pRectObject->Lock(0, 4 * sizeof(VertexData), &pRectBuffer, 0);
memcpy(pRectBuffer, data, 4 * sizeof(VertexData));
pRectObject->Unlock();
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
device->CreateVertexDeclaration(decl, &RectDecl);
}
示例3: InitGeometry
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
// Initialize three vertices for rendering a triangle
CUSTOMVERTEX g_Vertices[] =
{
{ -1.0f,-1.0f, 0.0f, 0xffff0000, },
{ 1.0f,-1.0f, 0.0f, 0xff0000ff, },
{ 0.0f, 1.0f, 0.0f, 0xffffffff, },
};
// Create the vertex buffer.
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// Fill the vertex buffer.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
g_pVB->Unlock();
return S_OK;
}
示例4: InitVB
// Prepare quad data, we build up a quad by combine two triangles
HRESULT InitVB()
{
// Initialize three Vertices for rendering a triangle
ScreenVertex Vertices[] =
{
{ 50.0f, 100.0f, 0.0f, 1.0f, 0xffff0000}, // 0
{100.0f, 50.0f, 0.0f, 1.0f, 0xffff0000}, // 1
{150.0f, 100.0f, 0.0f, 1.0f, 0xffff0000}, // 2
{200.0f, 50.0f, 0.0f, 1.0f, 0xffff0000}, // 3
{250.0f, 100.0f, 0.0f, 1.0f, 0xffff0000}, // 4
{300.0f, 50.0f, 0.0f, 1.0f, 0xffff0000}, // 5
};
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 8* sizeof( ScreenVertex ),
0, SCREEN_SPACE_FVF,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof( Vertices ), ( void** )&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, Vertices, sizeof( Vertices ) );
g_pVB->Unlock();
return S_OK;
}
示例5: UpgradeGeometry
//-----------------------------------------------------------------------------
// Name: UpgradeGeometry()
//-----------------------------------------------------------------------------
HRESULT UpgradeGeometry( LONG lActualW, LONG lTextureW,
LONG lActualH, LONG lTextureH )
{
HRESULT hr = S_OK;
if( 0 == lTextureW || 0 == lTextureH )
{
return E_INVALIDARG;
}
FLOAT tuW = (FLOAT)lActualW / (FLOAT)lTextureW;
FLOAT tvH = (FLOAT)lActualH / (FLOAT)lTextureH;
// Fill the vertex buffer. We are setting the tu and tv texture
// coordinates, which range from 0.0 to 1.0
CUSTOMVERTEX* pVertices;
if ( FAILED( hr = g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
{
Msg(TEXT("Could not lock the vertex buffer! hr=0x%x"), hr);
return E_FAIL;
}
for( DWORD i=0; i<nGrid; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(nGrid-1) + (FLOAT)(D3DX_PI/2.f);
pVertices[2*i+0].tu = tuW * ((FLOAT)i)/((FLOAT)nGrid-1.f);
pVertices[2*i+0].tv = tvH;
pVertices[2*i+1].tu = tuW * ((FLOAT)i)/((FLOAT)nGrid-1.f);
pVertices[2*i+1].tv = 0.0f;
}
g_pVB->Unlock();
return S_OK;
}
示例6: intBuffers
void Particles::intBuffers(LPDIRECT3DDEVICE9 d3ddev){
D3DXCreateTextureFromFile(d3ddev,"white.png",&texture);
struct CUSTOMVERTEX1 t_vert[] =
{
{-.05f, .05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 1, 0,},
{-0.05f, -.05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0, 0,},
{.05f, .05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 1, 1,},
{.05f, -.05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0, 1,},
};
// create a vertex buffer interface called t_buffer
d3ddev->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX1),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&t_buffer,
NULL);
VOID* pVoid; // a void pointer
// lock t_buffer and load the vertices into it
t_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, t_vert, sizeof(t_vert));
t_buffer->Unlock();
}
示例7: InitVB
//-----------------------------------------------------------------------------
// Name: InitVB()
// Desc: Creates a vertex buffer and fills it with our vertices. The vertex
// buffer is basically just a chuck of memory that holds vertices. After
// creating it, we must Lock()/Unlock() it to fill it. For indices, D3D
// also uses index buffers. The special thing about vertex and index
// buffers is that they can be created in device memory, allowing some
// cards to process them in hardware, resulting in a dramatic
// performance gain.
//-----------------------------------------------------------------------------
HRESULT CDlg::InitVB()
{
// Initialize three vertices for rendering a triangle
CUSTOMVERTEX vertices[] =
{
{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 250.0f, 250.0f, 0.5f, 1.0f, 0xffff0000, },
{ 50.0f, 250.0f, 0.5f, 1.0f, 0xffff0000, },
};
// Create the vertex buffer. Here we are allocating enough memory
// (from the default pool) to hold all our 3 custom vertices. We also
// specify the FVF, so the vertex buffer knows what data it contains.
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// Now we fill the vertex buffer. To do this, we need to Lock() the VB to
// gain access to the vertices. This mechanism is required becuase vertex
// buffers may be in device memory.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, vertices, sizeof(vertices) );
g_pVB->Unlock();
return S_OK;
}
示例8: initializeObj
bool initializeObj() {
//手动创建数组保存顶点数据
unsigned INT colorInfo = D3DCOLOR_ARGB(1, 255, 255, 255);
D3DVertexXYZRHW vertexData[] =
{
{ 10.0f, 10.0f, 0.0f, 1.0f, colorInfo },
{ 200.0f, 10.0f, 0.0f, 1.0f, colorInfo },
{ 10.0f, 200.0f, 0.0f, 1.0f, D3DCOLOR_ARGB(1, 0, 0, 0) },
{ 200.0f, 200.0f, 0.0f, 1.0f, colorInfo },
{ 400.0f, 200.0f, 0.0f, 1.0f, colorInfo },
{ 200.0f, 400.0f, 0.0f, 1.0f, colorInfo },
};
//用D3D设备创建一个用于存放顶点数据的缓存
if (FAILED(d3dDevice->CreateVertexBuffer(sizeof(vertexData), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT, &d3dVertexBuf, NULL)))
return false;
//用ptr当媒介,向缓存填入顶点数据
VOID *ptr;
if (FAILED(d3dVertexBuf->Lock(0, sizeof(vertexData), (VOID**)&ptr, 0)))
return false;
memcpy(ptr, vertexData, sizeof(vertexData));
d3dVertexBuf->Unlock();
return true;
}
示例9:
//---------------------------------------------------------------------------------
// Name: ComputeBoundingBox
// Desc:
// pMin:[out] Pointer to a D3DXVECTOR3 structure, describing the returned lower-left
// corner of the bounding box. See Remarks.
// pMax:[out] Pointer to a D3DXVECTOR3 structure, describing the returned upper-right
// corner of the bounding box. See Remarks.
//---------------------------------------------------------------------------------
FLOAT CD3DMesh::ComputeBoundingBox(D3DXVECTOR3 *pMin, D3DXVECTOR3 *pMax )
{
HRESULT hr;
// Lock the vertex buffer, to generate a simple bounding sphere
LPDIRECT3DVERTEXBUFFER9 pMeshVB = NULL;
hr = m_pSysMemMesh->GetVertexBuffer( &pMeshVB );
if( SUCCEEDED(hr) )
{
VOID * pVertices;
hr = pMeshVB->Lock( 0, 0, &pVertices, D3DLOCK_NOSYSLOCK );
if( SUCCEEDED(hr) )
{
hr = D3DXComputeBoundingBox( (D3DXVECTOR3 *)pVertices,
m_pSysMemMesh->GetNumVertices(),
D3DXGetFVFVertexSize(m_pSysMemMesh->GetFVF()),
pMin,
pMax);
pMeshVB->Unlock();
}
pMeshVB->Release();
}
if( FAILED(hr) )
return 0;
return 1;
}
示例10: GetDevice
LPDIRECT3DVERTEXBUFFER9 OvRenderer::CreateVertexStream( void* buffer, UINT stride, UINT count )
{
OvDevice device = GetDevice();
if ( device )
{
LPDIRECT3DVERTEXBUFFER9 vertexStream = NULL;
UINT streamSize = count * stride;
HRESULT hr = device->CreateVertexBuffer
( streamSize
, 0
, 0
, D3DPOOL_MANAGED
, &vertexStream
, NULL
);
if ( SUCCEEDED(hr) && vertexStream )
{
void* copyDest = NULL;
if ( SUCCEEDED(vertexStream->Lock( 0, streamSize, ©Dest, 0)) && copyDest)
{
memcpy( copyDest, buffer, streamSize );
vertexStream->Unlock();
return vertexStream;
}
}
}
return NULL;
}
示例11: memcpy
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
HRESULT hr;
m_pFont->InitDeviceObjects( m_pd3dDevice );
ilInit();
iluInit();
ilutInit();
ilutD3D8TexFromFile(m_pd3dDevice, __argv[1], &m_pTexture);
//D3DXCreateTextureFromFile(m_pd3dDevice, __argv[1], &m_pTexture);
// Create a vertex buffer
{
if( FAILED( hr = m_pd3dDevice->CreateVertexBuffer( 4*sizeof(VERTEX),
D3DUSAGE_WRITEONLY,
D3DFVF_VERTEX,
D3DPOOL_MANAGED, &m_pVB ) ) )
return hr;
VERTEX* pVertices;
m_pVB->Lock( 0, 4*sizeof(VERTEX), (BYTE**)&pVertices, 0 );
memcpy( pVertices, g_vVertices, sizeof(VERTEX)*4 );
m_pVB->Unlock();
}
return S_OK;
}
示例12: init_vertex_buffer
//------------------------------------------------------------------------------
HRESULT init_vertex_buffer()
{
CUSTOMVERTEX vertices[] = {
{ -1, 1, 1 , 0xFFFF0000 }, /// v0
{ 1, 1, 1 , 0xFF00FF00 }, /// v1
{ 1, 1, -1 , 0xFF0000FF }, /// v2
{ -1, 1, -1 , 0xFFFFFF00 }, /// v3
{ -1, -1, 1 , 0xFF00FFFF }, /// v4
{ 1, -1, 1 , 0xFFFF00FF }, /// v5
{ 1, -1, -1 , 0xFF000000 }, /// v6
{ -1, -1, -1 , 0xFFFFFFFF }, /// v7
};
if (FAILED( g_pd3dDevice->CreateVertexBuffer( 8*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVertexBuff, NULL )))
return E_FAIL;
VOID* pVertices;
if (FAILED( g_pVertexBuff->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 )))
return E_FAIL;
memcpy( pVertices, vertices, sizeof(vertices) );
g_pVertexBuff->Unlock();
return S_OK;
}
示例13: InitGeometry
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
// Create the vertex buffer.
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// Fill the vertex buffer. We are algorithmically generating a cylinder
// here, including the normals, which are used for lighting.
CUSTOMVERTEX* pVertices;
if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
return E_FAIL;
for( DWORD i=0; i<50z; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(50-1);
pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
pVertices[2*i+0].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
pVertices[2*i+1].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
}
g_pVB->Unlock();
return S_OK;
}
示例14: InitializeVertexBuffer
HRESULT InitializeVertexBuffer()
{
//Store each point of the triangle together with its color
CUSTOMVERTEX cvVertices[] =
{
{-10.f, 0.f, 0.f, D3DCOLOR_XRGB(255, 0, 0)},
{0.f, 0.f, 10.f, D3DCOLOR_XRGB(0, 255, 0)},
{10.f, 0.f, 0.f, D3DCOLOR_XRGB(0, 0, 255)}
};
//Create the vertex buffer
if(FAILED(g_pD3DDevice->CreateVertexBuffer(sizeof(cvVertices), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer, 0)))
return E_FAIL;
//Get a pointer to the vertex buffer vertices and lock the vertex buffer
void* pVertices = 0;
if(FAILED(g_pVertexBuffer->Lock(0, sizeof(cvVertices), &pVertices, 0)))
return E_FAIL;
//Copy our stored vertices value into the vertex buffer
memcpy(pVertices, cvVertices, sizeof(cvVertices));
g_pVertexBuffer->Unlock();
return S_OK;
}
示例15: InitialBufferVershin
HRESULT InitialBufferVershin() {
/*
Вершины примитивов
*/
CUSTOMVERTEX Vershin[] =
{
{xLength, 0.0f, 0.0f, 0xffff0000 },
{0.0f, 0.0f, 0.0f, 0x00000fff},
{0.0f, yHeight, 0.0f, 0xff00ff00 },
{xLength, 0.0f, 0.0f, 0xffff0000 },
{0, yHeight, 0.0f, 0xff00ff00 },
{xLength, yHeight, 0.0f, 0x00000fff },
};
/*-----------------------------------------------------------------------------------------------*/
/*
Для хранения вершин предназначен специальный буфер вершин.
1. задает размер буфера вершин в байтах.
2. определяет параметры работы с буфером и, как правило, всегда это значение выставляется в ноль.
3. задает формат вершин буфера через набор FVF флагов.
4. определяет месторасположение буфера вершин. Значение D3DPOOL_DEFAULT говорит о том,
что библиотека сама позаботится о размещении буфера в памяти.
5. задает адрес переменной, в которую будет помещен результат вызова метода,
т.е. эта переменная будет хранить адрес буфера вершин.
6. является зарезервированным в настоящее время и всегда должен быть пустым.
*/
if (FAILED(g_pd3dDevice->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT,
&pBufferVershin, NULL)))
return E_FAIL;
/*-----------------------------------------------------------------------------------------------*/
/*
Заполнить буфер данными о вершинах. Этот шаг реализуется в три приема.
Вначале необходимо запереть буфер, т.к. заполнение его может производиться только
в закрытом состоянии. Достигается это вызовом метода Lock интерфейса
IDirect3DVertexBuffer9. Второй шаг состоит в непосредственном копировании данных
с помощью стандартной функции Win32API – memcpy(). И третий шаг заключается
в отпирании буфера вершин с помощью метода Unlock интерфейса IDirect3DVertexBuffer9.
1. смещение от начала буфера, с которого будет производиться запирание области
(значение 0 указывает на то, что запирается весь буфер с самого начала)
2. задает размер запираемой области в байтах
3. параметр возвращает адрес запираемой области
4. задает набор флагов способа запирания и, как правило, всегда равен нулю.
*/
VOID* pBV;
if (FAILED(pBufferVershin->Lock(0, sizeof(Vershin), (VOID**)&pBV, 0)))
return E_FAIL;
memcpy(pBV, Vershin, sizeof(Vershin));
pBufferVershin->Unlock();
return S_OK;
}