我正在尝试将指向顶点数据数组(基类成员)的指针传递到用于初始化 Direct3D 顶点缓冲区(ID3D11Buffer)的方法中。
我想使用变量“v4”,指向数组的指针,但我认为我没有正确取消引用指针。有人能指出我正确的方向吗?
我已经尝试了很多方法来完成这个任务,但我只能得到一个基本的数组工作,(有时我最终会转换为“const void *”错误)。
我将如何使用指针?
我遇到的问题是... vertexSubResourceData.pSysMem = v1;
(ps 使用 VS C++ Nov 2012 CTP 编译器.. 尚未发布..)
*已回答:已确认这是 Visual Studio 2012 C++ Nov. CTP Compiler Bug。即使在类之外,使用 C++ 11 初始化语法声明的 Vector 结构数组也被错误地解释(当然,除非我使用了不正确的数组初始化语法)。另请注意:这仅适用于与指针关联的初始化列表。*
谢谢!
// 简化代码
void Triangle::InitializeVertexBuffer()
{
struct V
{
float X, Y, Z; // vertex position
};
// Compiles But doesn't work as desired.
// changed from V* v4 = new V[] // Compiled without range.
// Pointer to this data would ideally come from base static pointer, or file.
V* v4 = new V[3]
{
{ 0.50f, 0.5f, 0.0f },
{ 0.50f, -0.5f, 0.0f },
{ -0.50f, -0.5f, 0.0f },
};
// Compiles and Works to prove compiler issue with initialization lists.
V* vectorList = new V[3];
vectorList[0].X = 0.5f;
vectorList[0].Y = 0.5f;
vectorList[0].Z = 0.00f;
vectorList[1].X = 0.5f;
vectorList[1].Y = -0.5f;
vectorList[1].Z = 0.00f;
vectorList[2].X = -0.5f;
vectorList[2].Y = -0.5f;
vectorList[2].Z = 0.00f;
unsigned int size = sizeof(V) * 3; //sizeof(* Model::Vertices);
// The Description of the Vertex Buffer
D3D11_BUFFER_DESC vertexBufferDescription = {0};
vertexBufferDescription.ByteWidth = size;
vertexBufferDescription.BindFlags = D3D11_BIND_VERTEX_BUFFER;
// Model Data to be transferred to GPU Buffer.
D3D11_SUBRESOURCE_DATA vertexSubResourceData = {0};
vertexSubResourceData.SysMemPitch = 0;
vertexSubResourceData.SysMemSlicePitch = 0;
// Can't figure out how to dereference v4
vertexSubResourceData.pSysMem = vectorList; // works, but using "v4" doesn't.
// vertexSubResourceData.pSysMem = Model::Vertices;
// This is what I /really/ want .. Pointer to vertice array data from base class
NS::DeviceManager::Device->CreateBuffer(
&vertexBufferDescription,
&vertexSubResourceData,
&NS::ModelRenderer::VertexBuffer);
}