你需要做到这一点的,然后分批他们只有一个顶点缓冲,
所以这里你可以做什么,你可以让一个数组/矢量拿着三角形的信息,让我们说(伪代码)
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);
...
}
Remenber都是伪代码,但是这应该给你的想法,但如果你是刨去让很多三角形的问题,假设有1000个三角形,也许这不是最好的选择,您应该使用DrawIndexed并修改每个三角形的顶点位置,或者可以使用更简单的DrawInstanced来发送所有信息。Draw call ,因为调用Draw * triangleCount,对于大数量来说非常沉重