図0007a
//頂点の変更
void SquareSprite::UpdateVertex(float ElapsedTime) {
m_TotalTime += ElapsedTime;
if (m_TotalTime > 1.0f) {
m_TotalTime = 0;
}
auto Dev = App::GetApp()->GetDeviceResources();
auto pD3D11DeviceContext = Dev->GetD3DDeviceContext();
//頂点の変更準備
//D3D11_MAP_WRITE_DISCARDは重要。この処理により、GPUに邪魔されない
D3D11_MAP mapType = D3D11_MAP_WRITE_DISCARD;
D3D11_MAPPED_SUBRESOURCE mappedBuffer;
//頂点のマップ
if (FAILED(pD3D11DeviceContext->Map(m_SquareMesh->GetVertexBuffer().Get(),
0, mapType, 0, &mappedBuffer))) {
// Map失敗
throw BaseException(
L"頂点のMapに失敗しました。",
L"if(FAILED(pID3D11DeviceContext->Map()))",
L"SquareObject::OnUpdate()"
);
}
//頂点の変更
VertexPositionTexture* vertices
= (VertexPositionTexture*)mappedBuffer.pData;
for (size_t i = 0; i < m_SquareMesh->GetNumVertices(); i++) {
Vec2 UV = m_BackupVertices[i].textureCoordinate;
if (UV.x == 0.0f) {
UV.x = m_TotalTime;
}
else if (UV.x == 4.0f) {
UV.x += m_TotalTime;
}
vertices[i] = VertexPositionTexture(
m_BackupVertices[i].position,
UV
);
}
//アンマップ
pD3D11DeviceContext->Unmap(m_SquareMesh->GetVertexBuffer().Get(), 0);
}