Direct3D多个顶点缓冲区,非交织元素 [英] Direct3D multiple vertex buffers, non interleaved elements

查看:110
本文介绍了Direct3D多个顶点缓冲区,非交织元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建2个顶点缓冲区,一个仅存储位置,另一个仅存储颜色.这只是Frank Luna的书中的一个练习,用来熟悉顶点描述,布局和缓冲区选项.问题是我感觉我已经进行了所有相关更改,尽管我要显示几何图形,但是颜色缓冲区无法正常工作.为了完成本练习,我使用XMFLOAT3,而不是使用示例代码(该示例代码中每个顶点存储位置和颜色)使用本书的Vertex顶点[] = {{......,{...},...} pos [] = {x,y,z ...}用于位置和XMFLOAT4颜色[] = {a,b,c,...}.我已经修改了顶点描述,以使每个元素都引用正确的输入点:

I'm trying to create 2 vertex buffers, one that only stores positions and another that only stores colors. This is just an exercise from Frank Luna's book to become familiar with vertex description, layouts and buffer options. The problem is that I feel like I have made all the relevant changes and although I am getting the geometry to show, the color buffer is not working. To complete the exercise, instead of using the book's Vertex vertices[]={{...},{...},...} from the example code where each Vertex stores the position and the color, I am using XMFLOAT3 pos[]={x,y,z...} for positions and XMFLOAT4 colors[]={a,b,c,...}. I have modified the vertex description to make each element reference the correct input spot:

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
    {
        {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}
    };

我还更改了设备上的顶点缓冲区,以期望有两个顶点缓冲区,而不仅仅是mBoxVB,后者以前是基于顶点顶点的资源[]:

I've also changed the vertex buffer on the device to expect two vertex buffers instead of just mBoxVB which previously was a resource based on Vertex vertices[]:

ID3D11Buffer* mBoxVB;
ID3D11Buffer* mBoxVBCol;
ID3D11Buffer* combined[2];
...
combined[0]=mBoxVB;
combined[1]=mBoxVBCol;
...
UINT stride[] = {sizeof(XMFLOAT3), sizeof(XMFLOAT4)};
UINT offset = 0;
md3dImmediateContext->IASetVertexBuffers(0, 2, combined, stride, &offset);

如果有帮助,这是缓冲区创建代码:

If of any help, this is the buffer creation code:

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(XMFLOAT3)*8;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    vbd.StructureByteStride = 0;

    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = Shapes::boxEx1Pos;
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));

    D3D11_BUFFER_DESC cbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(XMFLOAT4)*8;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    vbd.StructureByteStride = 0;

    D3D11_SUBRESOURCE_DATA cinitData;
    cinitData.pSysMem = Shapes::boxEx1Col;
    HR(md3dDevice->CreateBuffer(&vbd, &cinitData, &mBoxVBCol));

如果我使用combined [0] = mBoxVBCol,而不是combined [0] = mBoxVB,则会得到不同的形状,所以我知道那里有一些数据,但是我不确定为什么Color元素无法发送到顶点着色器,在我看来,第二个插槽在操作中被忽略了.

If I use combined[0]=mBoxVBCol, instead of combined[0]=mBoxVB I get a different shape so I know there is some data there but I'm not sure why the Color element is not getting sent through to the vertex shader, it seems to me that the second slot is being ignored in the operation.

推荐答案

我找到了问题的答案.简而言之,尽管我为两个缓冲区都指定了步幅数组,但是我只给出了一个偏移量,所以一旦我改变了UINT offset = 0;到UINT offset [] = {0,0};它奏效了.

I found the answer to the problem. It was simply that although I was specifying the stride array for both buffers, I was only giving one offset, so once I changed UINT offset=0; to UINT offset[]={0,0}; it worked.

这篇关于Direct3D多个顶点缓冲区,非交织元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆