Graphics Reference
In-Depth Information
List<UnorderedAccessView> particleUAVs =
new List<UnorderedAccessView>();
public int ParticlesPerBatch = 16;
float limiter = 0f;
// Initialize the particle buffers
public void InitializeParticles(int maxParticles,
float maxLifetime)
{
... RemoveAndDispose(...)
this.Constants.MaxParticles = maxParticles;
this.Constants.MaxLifetime = maxLifetime;
// How often and how many particles to generate
this.ParticlesPerBatch = (int)(maxParticles * 0.0128f);
this.limiter = (float)(Math.Ceiling(ParticlesPerBatch /
16.0) * 16.0 * maxLifetime) / (float)maxParticles;
#region Create Buffers and Views
... SNIP see below
#endregion
// Update the ParticleConstants buffer
device.ImmediateContext.UpdateSubresource(
ref Constants, perComputeBuffer);
}
16. We will create the particle buffers and views with the following code:
// Create 2 buffers, these are our append/consume
// buffers and will be swapped each frame
particleBuffers.Add(
ToDispose(new Buffer(device,
Utilities.SizeOf<Particle>() * maxParticles,
ResourceUsage.Default,
BindFlags.ShaderResource |
BindFlags.UnorderedAccess,
CpuAccessFlags.None,
ResourceOptionFlags.BufferStructured,
Utilities.SizeOf<Particle>())));
particleBuffers.Add (...same as above... );
// Create a UAV and SRV for each particle buffer
particleUAVs.Add(ToDispose(CreateBufferUAV(device,
particleBuffers[0],
UnorderedAccessViewBufferFlags.Append )));
 
Search WWH ::




Custom Search