/// <summary> /// numberOfBuffers is the amount of vertex buffers used by the particle system for multi buffering. /// Multi buffering can avoid stalling of the GPU but will also increases it's memory consumption. /// If you want to avoid stalling create the same amount of buffers as your maximum rendered emitters at the /// same time. /// For example allocating one buffer with 16383 particles takes up 2048KB(2MB) GPU memory. /// This call requires that there is a GL context /// </summary> /// <param name="numberOfBuffers">the amount of vertex buffers used by the particle system for multi buffering.</param> /// <param name="maxParticlesPerBuffer">Maximum number of particles that you will be able to display.</param> public static void Init(int numberOfBuffers = 2, int maxParticlesPerBuffer = MaxPossibleParticles) { _numberOfVertexBuffers = numberOfBuffers; if (maxParticlesPerBuffer > MaxPossibleParticles) { maxParticlesPerBuffer = MaxPossibleParticles; Debug.WriteLine("StardustStarlingRenderer WARNING: Tried to render than possible particles, setting value to max"); } _maxParticles = maxParticlesPerBuffer; SparrowParticleBuffers.CreateBuffers(maxParticlesPerBuffer, numberOfBuffers); if (!_initCalled) { for (int i = 0; i < 0x800; ++i) { SCosLut[i & 0x7FF] = (float)Math.Cos(i * 0.00306796157577128245943617517898); // 0.003067 = 2PI/2048 SSinLut[i & 0x7FF] = (float)Math.Sin(i * 0.00306796157577128245943617517898); } // handle a lost device context SparrowSharp.ContextCreated += SparrowSharpOnContextCreated; _initCalled = true; } }
private static void SparrowSharpOnContextCreated() { SparrowParticleBuffers.CreateBuffers(_maxParticles, _numberOfVertexBuffers); }