您只需要一个顶点缓冲区来执行此操作,然后对它们进行批处理,
所以这是你可以做的,你可以制作一个数组/向量来保存三角形信息,比如说(伪代码)
struct TriangleInfo{
..... texture;
vect2 pos;
vect2 dimension;
float rot;
}
然后在你的绘制方法中
for(int i=0; i < vector.size(); i++){
TriangleInfo tInfo = vector[i];
matrix worldMatrix = Transpose(matrix(tInfo.dimension) * matrix(tInfo.rot) * matrix(tInfo.pos));
shaderParameters.worldMatrix = worldMatrix; //info to the constabuffer
..
..
dctx->PSSetShaderResources(0, 1, &tInfo.texture);
dctx->Draw(0,4);
}
然后在你的顶点着色器中:
cbuffer cbParameters : register( b0 ) {
float4x4 worldMatrix;
};
VOut main(float4 position : POSITION, float4 texCoord : TEXCOORD)
{
....
output.position = mul(position,worldMatrix);
...
}
记住所有都是伪代码,但这应该给你的想法,但如果你打算制作很多三角形,比如1000个三角形,可能会出现问题,也许这不是最好的选择,你应该使用DrawIndexed 和修改每个三角形的顶点位置,或者您可以使用 DrawInstanced ,更简单,能够在一次 Draw 调用中发送所有信息,因为调用 Draw * triangleCount ,对于大量而言非常繁重