gpt4 book ai didi

c++ - 使用 D3DPT_LINELIST 渲染 3D 线条

转载 作者:行者123 更新时间:2023-11-30 04:28:43 33 4
gpt4 key购买 nike

当尝试使用 D3DPT_LINELIST 在 3D 空间中绘制一条线时,Direct3D 给我一个关于无效顶点声明的错误,说它不能转换为 FVF .我使用的顶点声明和着色器/流设置与我的 D3DPT_TRIANGLELIST 渲染完全正确。

如何使用 D3DPT_LINELIST 在 3D 空间中渲染一些线条?

这是我的原始 Draw 调用。

D3DCALL(device->SetVertexDeclaration(VertexDecl));
D3DCALL(device->SetStreamSource(1, PerBoneBuffer.get(), 0, sizeof(PerInstanceData)));
D3DCALL(device->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1));
D3DCALL(device->SetStreamSource(0, LineVerts, 0, sizeof(D3DXVECTOR3)));
D3DCALL(device->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | lines.size()));
D3DCALL(device->SetIndices(LineIndices));
PerInstanceData* data;
std::vector<Wide::Render::Line*> lines_vec(lines.begin(), lines.end());
D3DCALL(PerBoneBuffer->Lock(0, lines.size() * sizeof(PerInstanceData), reinterpret_cast<void**>(&data), D3DLOCK_DISCARD));
std::for_each(lines.begin(), lines.end(), [&](Wide::Render::Line* ptr) {
data->Color = D3DXColor(ptr->Colour);
D3DXMATRIXA16 Translate, Scale, Rotate;
D3DXMatrixTranslation(&Translate, ptr->Start.x, ptr->Start.y, ptr->Start.z);
D3DXMatrixScaling(&Scale, ptr->Scale, 1, 1);
D3DXMatrixRotationQuaternion(&Rotate, &D3DQuaternion(ptr->Rotation));
data->World = Scale * Rotate * Translate;
});
D3DCALL(PerBoneBuffer->Unlock());
D3DCALL(device->DrawIndexedPrimitive(D3DPRIMITIVETYPE::D3DPT_LINELIST, 0, 0, 2, 0, 1));

这是我的顶点声明:

D3DVERTEXELEMENT9 BasicMeshVertices[] = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{1, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
{1, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2},
{1, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3},
{1, 64, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};
D3DCALL(Device->CreateVertexDeclaration(
BasicMeshVertices,
PointerToPointer(BasicMeshVertexDecl)
));

LineIndices 只是0, 1LineVerts 只是{0,0,0}{1,0,0},表示沿 X 轴的单位 3D 线。

最佳答案

我不确定您是否真的在使用顶点着色器(没有看到它的代码 - 它是固定管道吗?)。我不知道是什么导致了三角形和线列表之间的差异,但你得到的错误意味着你的顶点声明无法转换为旧的 FVF。

来自 here (第 177 页 - 5.8.1:固定函数声明):

When using the fixed-function pipeline with a vertex declaration, the appropriate vertex components must each be mapped to a particular usage. You can use multiple streams, but the vertices must conform to the order and type constraints of the FVF codes described in section 5.7.

从 5.7 节开始:

The vertex components are laid out in memory in the same order as the vertex components listed in the table, starting with the position component.

该表只是头文件中 D3DFVF_* 常量的列表。

因此在您的情况下 - 尝试将颜色组件移动到 PerInstanceData(流 1)结构中的 tex 坐标组件之前。

关于c++ - 使用 D3DPT_LINELIST 渲染 3D 线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9932216/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com