Graphics Reference
In-Depth Information
// Bind textures to the pixel shader
int texIndxOffset = mIndx * Common.Mesh.MaxTextures;
material.HasTexture = (uint)(textureViews[texIndxOffset] !=
null ? 1 : 0); // 0=false
context.PixelShader.SetShaderResources(0,
textureViews.GetRange(texIndxOffset,
Common.Mesh.MaxTextures).ToArray());
// Set texture sampler state
context.PixelShader.SetSampler(0, samplerState);
// Update material buffer
context.UpdateSubresource(ref material, PerMaterialBuffer);
10. To render each submesh, we set the vertex and index buffers in the Input Assembler
(IA) and then draw the vertices.
// Ensure the vert ex buffer and index
buffers are in range
if (subMesh.VertexBufferIndex < vertexBuffers.Count && subMesh.
IndexBufferIndex < indexBuffers.Count)
{
// Retrieve and set the vertex and index buffers
var vertexBuffer = vertexBuffers[
(int)subMesh.VertexBufferIndex];
context.InputAssembler.SetVertexBuffers(0, new
VertexBufferBinding(vertexBuffer,
Utilities.SizeOf<Vertex>(), 0));
context.InputAssembler.SetIndexBuffer(indexBuffers[
(int)subMesh.IndexBufferIndex], Format.R16_UInt, 0);
// Set topology
context.InputAssembler.PrimitiveTopology =
SharpDX.Direct3D.PrimitiveTopology.TriangleList;
}
// Draw the sub-mesh (includes the triangle count)
// The submesh has a start index into the vertex buffer
context.DrawIndexed((int)subMesh.PrimCount * 3,
(int)subMesh.StartIndex, 0);
Now we can load and render our mesh within our D3DApp class.
 
Search WWH ::




Custom Search