Graphics Reference
In-Depth Information
List<Buffer> indexBuffers = new List<Buffer>();
// Texture resources
List<ShaderResourceView> textureViews = new
List<ShaderResourceView>();
// Control sampling behavior with this state
SamplerState samplerState;
// The loaded mesh
Common.Mesh mesh;
public Common.Mesh Mesh { get { return this.mesh; } }
// The per material buffer to use so that the mesh
// parameters can be used
public Buffer PerMaterialBuffer { get; set; }
3.
Next, we will create a single constructor that accepts a Visual Studio graphics
content pipeline CMO mesh via a Common.Mesh instance.
public MeshRenderer(Common.Mesh mesh)
{
this.mesh = mesh;
}
4.
Override CreateDeviceDependentResources with the following code.
First release the existing vertex, index buffers, and texture views.
// Dispose of each vertex, index buffer and texture
vertexBuffers.ForEach(vb => RemoveAndDispose(ref vb));
vertexBuffers.Clear();
indexBuffers.ForEach(ib => RemoveAndDispose(ref ib));
indexBuffers.Clear();
textureViews.ForEach(tv => RemoveAndDispose(ref tv));
textureViews.Clear();
RemoveAndDispose(ref samplerState);
5. We read each of the vertex buffers from the CMO file into a new buffer.
// Initialize vertex buffers
for (int indx = 0; indx < mesh.VertexBuffers.Count; indx++)
{
var vb = mesh.VertexBuffers[indx];
Vertex[] vertices = new Vertex[vb.Length];
for (var i = 0; i < vb.Length; i++)
{
// Create vertex
 
Search WWH ::




Custom Search