Пример #1
0
        public static ShaderStorageBuffer Create()
        {
            var screen   = Engine.GetValidCurrentContext();
            var instance = new ShaderStorageBuffer(Ssbo.Create());

            ContextAssociatedMemorySafety.Register(instance, screen);
            return(instance);
        }
Пример #2
0
 public void Load(ReadOnlySpan <Bone> bones)
 {
     if (IsBoneLoaded)
     {
         throw new InvalidOperationException("Already loaded");
     }
     InitializeSkeletonData(this, bones);
     _boneTranslationData.Load(_matrices !.AsSpan().MarshalCast <Matrix4, Color4>());
     ContextAssociatedMemorySafety.Register(this, Engine.GetValidCurrentContext());
 }
Пример #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _impl.Dispose();
     }
     else
     {
         ContextAssociatedMemorySafety.OnFinalized(this);
     }
 }
Пример #4
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         Ssbo.Delete(ref _ssbo);
     }
     else
     {
         ContextAssociatedMemorySafety.OnFinalized(this);
     }
 }
Пример #5
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         ContextMismatchException.ThrowIfContextNotEqual(Engine.GetValidCurrentContext(), _screen);
         ProgramObject.Delete(ref _program);
     }
     else
     {
         ContextAssociatedMemorySafety.OnFinalized(this);
     }
 }
Пример #6
0
        public static ComputeShaderDispatcher Create(IComputeShader shader)
        {
            ArgumentNullException.ThrowIfNull(shader);

            var screen   = Engine.GetValidCurrentContext();
            var source   = IComputeShader.GetShaderSourceInternal(shader);
            var program  = ShaderCompiler.CompileComputeShader(source);
            var instance = new ComputeShaderDispatcher(program, screen, shader);

            ContextAssociatedMemorySafety.Register(instance, screen);
            return(instance);
        }
Пример #7
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }
            _disposed = true;

            _currentTiming = CurrentFrameTiming.OutOfFrameLoop;

            Layers.AbortAllLayers();

            TimingPoints.AbortAllEvents();
            Lights.Release();
            ContextAssociatedMemorySafety.EnsureCollect(OwnerScreen);   // Must be called before the opengl context is deleted.
            Disposed?.Invoke();
        }
Пример #8
0
        public async UniTask LoadAsync <TBoneSpan>(TBoneSpan bones, FrameTimingPointList timingPoints, FrameTiming timing,
                                                   CancellationToken cancellationToken = default) where TBoneSpan : IReadOnlySpan <Bone>
        {
            if (IsBoneLoaded)
            {
                throw new InvalidOperationException("Already loaded");
            }
            if (timingPoints is null)
            {
                throw new ArgumentNullException(nameof(timingPoints));
            }
            timing.ThrowArgExceptionIfNotSpecified(nameof(timing));

            cancellationToken.ThrowIfCancellationRequested();
            await UniTask.SwitchToThreadPool();

            cancellationToken.ThrowIfCancellationRequested();
            try {
                InitializeSkeletonData(this, bones.AsReadOnlySpan());
                await timingPoints.TimingOf(timing).Next(cancellationToken);

                if (IsBoneLoaded)
                {
                    throw new InvalidOperationException("Already loaded");
                }
                _boneTranslationData.Load(_matrices !.AsSpan().MarshalCast <Matrix4, Color4>());
            }
            catch {
                _posMatrices.Dispose();
                _posInvMatrices.Dispose();
                _tree.Dispose();
                _matrices.Dispose();
                _translations.Dispose();
                throw;
            }

            ContextAssociatedMemorySafety.Register(this, Engine.GetValidCurrentContext());
            return;
        }
Пример #9
0
 public void LoadAsPowerOfTwo(ReadOnlySpan <Color4> pixels)
 {
     _impl.LoadAsPOT(pixels);
     ContextAssociatedMemorySafety.Register(this, Engine.GetValidCurrentContext());
 }
Пример #10
0
 public void Load(ReadOnlySpan <Vector4> pixels)
 {
     _impl.Load(pixels.MarshalCast <Vector4, Color4>());
     ContextAssociatedMemorySafety.Register(this, Engine.GetValidCurrentContext());
 }
Пример #11
0
        public void RenderFrame()
        {
            // ------------------------------------------------------------
            // Out of frame loop
            Debug.Assert(_currentTiming == CurrentFrameTiming.OutOfFrameLoop);
            var isCloseRequested = _isCloseRequested;
            var layers           = Layers;

            var frameTimingPoints = TimingPoints;

            Mouse.InitFrame();
            Keyboard.InitFrame();

            // ------------------------------------------------------------
            // First Frame initializing
            if (_state == RenderingAreaLifeState.Activating)
            {
                _currentTiming = CurrentFrameTiming.FirstFrameInitializing;
                try {
                    Initialized?.Invoke(OwnerScreen);
                }
                catch {
                    if (EngineSetting.UserCodeExceptionCatchMode == UserCodeExceptionCatchMode.Throw)
                    {
                        throw;
                    }
                    // Don't throw. (Ignore exceptions in user code)
                }
                finally {
                    _state = RenderingAreaLifeState.Alive;
                }
            }

            // ------------------------------------------------------------
            // Frame initializing
            _currentTiming = CurrentFrameTiming.FrameInitializing;
            if (isCloseRequested && _state == RenderingAreaLifeState.Alive)
            {
                _state = RenderingAreaLifeState.Terminating;
                _runningTokenSource.Cancel();
                layers.TerminateAllLayers(this,
                                          onDead: static self =>
                {
                    self._state = RenderingAreaLifeState.Dead;
                });
            }
            layers.ApplyAdd();
            frameTimingPoints.FrameInitializing.DoQueuedEvents();

            // ------------------------------------------------------------
            // Early update
            _currentTiming = CurrentFrameTiming.EarlyUpdate;
            frameTimingPoints.EarlyUpdate.DoQueuedEvents();
            layers.EarlyUpdate();

            // ------------------------------------------------------------
            // Update
            _currentTiming = CurrentFrameTiming.Update;
            frameTimingPoints.Update.DoQueuedEvents();
            layers.Update();

            // ------------------------------------------------------------
            // Late update
            _currentTiming = CurrentFrameTiming.LateUpdate;
            frameTimingPoints.LateUpdate.DoQueuedEvents();
            layers.LateUpdate();

            // ------------------------------------------------------------
            // Before rendering
            _currentTiming = CurrentFrameTiming.BeforeRendering;
            FBO.Bind(FBO.Empty, FBO.Target.FrameBuffer);
            ElffyGL.Clear(ClearMask.ColorBufferBit | ClearMask.DepthBufferBit);
            frameTimingPoints.BeforeRendering.DoQueuedEvents();

            // ------------------------------------------------------------
            // Rendering
            _currentTiming = CurrentFrameTiming.Rendering;
            layers.Render();

            // ------------------------------------------------------------
            // After rendering
            _currentTiming = CurrentFrameTiming.AfterRendering;
            frameTimingPoints.AfterRendering.DoQueuedEvents();

            // ------------------------------------------------------------
            // Frame finalizing
            _currentTiming = CurrentFrameTiming.FrameFinalizing;
            layers.ApplyRemove();

            // ------------------------------------------------------------
            // End of frame (only internal accessible)
            _currentTiming = CurrentFrameTiming.Internal_EndOfFrame;
            frameTimingPoints.InternalEndOfFrame.DoQueuedEvents();

            // ------------------------------------------------------------
            // Out of frame loop
            _currentTiming = CurrentFrameTiming.OutOfFrameLoop;
            ContextAssociatedMemorySafety.CollectIfExist(OwnerScreen);

            if (_state == RenderingAreaLifeState.Dead)
            {
                Dispose();
            }
        }