Ejemplo n.º 1
0
 private void glControl_ContextDestroying(object sender, GlControlEventArgs e)
 {
     clear();
     if (mlBufferCache != null)
     {
         mlBufferCache.Dispose();
         mlBufferCache = null;
     }
     if (mlBufferOutput != null)
     {
         mlBufferOutput.Dispose();
         mlBufferOutput = null;
     }
     if (glbufTexCache > 0)
     {
         Gl.DeleteTextures(glbufTexCache);
         glbufTexCache = 0;
     }
     if (glbufOutput > 0)
     {
         Gl.DeleteFramebuffers(glbufOutput);
         glbufOutput = 0;
     }
 }
Ejemplo n.º 2
0
        public static void MemoryLock_TestAddress()
        {
            float[] array = new float[16];

            // Allow null argument
            Assert.DoesNotThrow(() => { using (new MemoryLock(null)) {} });
            // Nominal case does not throw exceptions
            Assert.DoesNotThrow(() => { using (new MemoryLock(array)) {} });
            // Null argument lead to IntPtr.Zero
            using (MemoryLock nullLock = new MemoryLock(null)) {
                Assert.AreEqual(IntPtr.Zero, nullLock.Address);
            }

            MemoryLock arrayLock = new MemoryLock(array);

            try {
                // Existing reference have non-null pointer
                Assert.AreNotEqual(IntPtr.Zero, arrayLock.Address);
            } finally { arrayLock.Dispose(); }
            // Address reset to IntPtr.Zero after disposition
            Assert.AreEqual(IntPtr.Zero, arrayLock.Address);
            // Allow multiple Dispose()
            Assert.DoesNotThrow(() => arrayLock.Dispose());
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     _positionLock.Dispose();
     _colorLock.Dispose();
     _textureLock.Dispose();
 }
Ejemplo n.º 4
0
        public void updateAttr(int _maxRenderTime = -1)
        {
            particleCount = md.particleCount;
            if (particleCount > MainModel.ins.configModel.maxParticleCount)
            {
                particleCount = MainModel.ins.configModel.maxParticleCount;
            }

            if (md.particleCount <= 0)
            {
                return;
            }
            if (_maxRenderTime > 0)
            {
                maxRenderTime = _maxRenderTime;
            }

            var rootMd = MainModel.ins.particleEditModel;
            //md.
            Random rand = null;

            if (!rootMd.isSeedAuto)
            {
                nowSeed = rootMd.seed;
            }
            else if (nowSeed < 0)
            {
                nowSeed = new Random().Next();
            }
            rand = new Random(nowSeed);

            //int count = _ArrayIndex.Length;
            //int idxCount = count / 2;

            const int attrCount = 14;

            float[] _arrParticleAttr = new float[particleCount * attrCount];

            for (int i = 0; i < particleCount; ++i)
            {
                int   x   = i * 2;
                int   y   = x + 1;
                float ir0 = (float)rand.NextDouble();
                float ir1 = (float)rand.NextDouble();
                float ir2 = (float)rand.NextDouble();
                float ir3 = (float)rand.NextDouble();
                float ir4 = (float)rand.NextDouble();
                float ir5 = (float)rand.NextDouble();
                float ir6 = (float)rand.NextDouble();
                float ir7 = (float)rand.NextDouble();
                float ir8 = (float)rand.NextDouble();

                //pos
                float px = md.xFloat * (ir0 - 0.5f) * 2;
                float py = md.yFloat * (ir1 - 0.5f) * 2;
                px = md.x + px;
                py = md.y + py;

                //speed
                float speed  = md.startSpeed + md.startSpeedFloat * (ir2 - 0.5f) * 2;
                float sAngle = md.startSpeedAngle - 90 + md.startSpeedAngleFloat * (ir3 - 0.5f) * 2;
                float speedx = (float)(speed * Math.Cos(sAngle / 180 * Math.PI));
                float speedy = (float)(speed * Math.Sin(sAngle / 180 * Math.PI));

                //aspeed
                float aSpeed  = md.gravityValue;
                float aSAngle = md.gravityAngle - 90;
                float aSpeedx = (float)(aSpeed * Math.Cos(aSAngle / 180 * Math.PI));
                float aSpeedy = (float)(aSpeed * Math.Sin(aSAngle / 180 * Math.PI));

                //size
                float startSize = md.particleStartSize + md.particleStartSizeFloat * (ir4 - 0.5f) * 2;
                startSize = Math.Max(0, startSize);
                float endSize = md.particleEndSize + md.particleEndSizeFloat * (ir5 - 0.5f) * 2;
                endSize = Math.Max(0, endSize);
                endSize = (endSize - startSize) / md.particleLife;

                //particle angle
                float startAngle          = md.particleStartAngle + md.particleStartAngleFloat * (ir6 - 0.5f) * 2;
                float ParticleRotateSpeed = md.particleRotateSpeed + md.particleRotateSpeedFloat * (ir7 - 0.5f) * 2;
                startAngle          = startAngle / 180 * (float)Math.PI;
                ParticleRotateSpeed = ParticleRotateSpeed / 180 * (float)Math.PI;

                //alpha
                float startAlpha = Math.Min(1, Math.Max(0, md.startAlpha));
                float endAlpha   = Math.Min(1, Math.Max(0, md.endAlpha));
                endAlpha = (endAlpha - startAlpha) / md.particleLife;

                //lifeTime
                float lifeTime = md.particleLife - md.particleLifeFloat * ir8;
                lifeTime *= 1000;

                //startTime
                float startTime = (float)(particleCount - i) / particleCount * maxRenderTime;

                _arrParticleAttr[i * attrCount + 0]  = px;
                _arrParticleAttr[i * attrCount + 1]  = py;
                _arrParticleAttr[i * attrCount + 2]  = speedx;
                _arrParticleAttr[i * attrCount + 3]  = speedy;
                _arrParticleAttr[i * attrCount + 4]  = aSpeedx;
                _arrParticleAttr[i * attrCount + 5]  = aSpeedy;
                _arrParticleAttr[i * attrCount + 6]  = startSize;
                _arrParticleAttr[i * attrCount + 7]  = endSize;
                _arrParticleAttr[i * attrCount + 8]  = startAngle;
                _arrParticleAttr[i * attrCount + 9]  = ParticleRotateSpeed;
                _arrParticleAttr[i * attrCount + 10] = startAlpha;
                _arrParticleAttr[i * attrCount + 11] = endAlpha;
                _arrParticleAttr[i * attrCount + 12] = lifeTime;
                _arrParticleAttr[i * attrCount + 13] = startTime;
            }

            arrParticleAttr = _arrParticleAttr;

            if (lockBufferData != null)
            {
                lockBufferData.Dispose();
            }
            lockBufferData = new MemoryLock(arrParticleAttr);

            Gl.BindBuffer(BufferTarget.ShaderStorageBuffer, attrBufferId);
            //Gl.BufferData(BufferTarget.ShaderStorageBuffer, (uint)arrPointAttr.Length * sizeof(float), lockBufferData.Address, BufferUsage.DynamicDraw);
            Gl.BufferData(BufferTarget.ShaderStorageBuffer, (uint)arrParticleAttr.Length * sizeof(float), lockBufferData.Address, BufferUsage.StaticDraw);
        }