public void Render(DxCamera camera) { // // Set constants. // _viewProjVar.SetMatrix(camera.View * camera.Projection); _gameTimeVar.Set(_gameTime); _timeStepVar.Set(_timeStep); _eyePosVar.Set(camera.Eye); _emitPosVar.Set(_emitPosW); _emitDirVar.Set(_emitDirW); _texArrayVar.SetResource(_texArrayRV); _randomTexVar.SetResource(_randomTexRV); // // Set IA stage. // _dxDevice.InputAssembler.SetInputLayout(_vertexLayout); _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.PointList); int stride = Marshal.SizeOf(typeof(ParticleVertex)); const int offset = 0; // On the first pass, use the initialization VB. Otherwise, use // the VB that contains the current particle list. _dxDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_firstRun ? _initVB : _drawVB, stride, offset)); // // Draw the current particle list using stream output only to update // them. The updated vertices are streamed out to the target VB. // _dxDevice.StreamOutput.SetTargets( new StreamOutputBufferBinding(_streamOutVB, offset)); for (int p = 0; p < _streamOutTech.Description.PassCount; ++p) { _streamOutTech.GetPassByIndex(p).Apply(); if (_firstRun) { _dxDevice.Draw(1, 0); _firstRun = false; } else { _dxDevice.DrawAuto(); } } // done streaming out--unbind the vertex buffer _dxDevice.StreamOutput.SetTargets(null); // ping-pong the vertex buffers var tmpVB = _drawVB; _drawVB = _streamOutVB; _streamOutVB = tmpVB; // // Draw the updated particle system we just streamed out. // _dxDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_drawVB, stride, offset)); for (int p = 0; p < _drawTech.Description.PassCount; ++p) { _drawTech.GetPassByIndex(p).Apply(); _dxDevice.DrawAuto(); } }