public UniformBinding <T> GetUniformBinding <T> (Material material, string uniformName) where T : struct { var effect = material.Effect; if (effect == null) { return(null); } var key = new UniformBindingKey(effect, uniformName, typeof(T)); lock (UniformBindings) { IUniformBinding existing; if (UniformBindings.TryGetValue(key, out existing)) { return(existing.Cast <T>()); } if (material.OwningThread != Thread.CurrentThread) { throw new InvalidOperationException("Uniform bindings must be allocated on the thread that owns the material."); } #if SDL2 UniformBinding <T> result; throw new NotImplementedException("Create uniform binding for effect"); #else var result = UniformBinding <T> .TryCreate(effect, uniformName); #endif UniformBindings.Add(key, result); return(result); } }
// We must acquire both locks before resetting the device to avoid letting the reset happen during a paint or content load operation. protected void OnDeviceResetting(object sender, EventArgs args) { Monitor.Enter(DrawLock); Monitor.Enter(CreateResourceLock); Monitor.Enter(UseResourceLock); UniformBinding.HandleDeviceReset(); }
public virtual void Flush() { if (Effect != null) { UniformBinding.FlushEffect(Effect); var currentTechnique = Effect.CurrentTechnique; currentTechnique.Passes[0].Apply(); } }
/// <summary> /// Bind a single named uniform of the effect as type T. /// </summary> private UniformBinding(Effect effect, string uniformName) { Type = typeof(T); Effect = effect; Name = uniformName; ScratchBuffer = new Storage(); UploadBuffer = new Storage(); IsDirty = true; UniformBinding.Register(effect, this); }
private void Flush_Epilogue(DeviceManager deviceManager) { if (Effect != null) { UniformBinding.FlushEffect(Effect); var currentTechnique = Effect.CurrentTechnique; currentTechnique.Passes[0].Apply(); } if (deviceManager.ActiveViewTransform != null) { deviceManager.ActiveViewTransform.ActiveMaterial = this; } }
// We must acquire both locks before resetting the device to avoid letting the reset happen during a paint or content load operation. protected void OnDeviceResetting(object sender, EventArgs args) { TimeOfLastResetOrDeviceChange = Time.Ticks; FirstFrameSinceReset = true; if (!IsResetting) { IsResetting = true; Monitor.Enter(DrawLock); Monitor.Enter(CreateResourceLock); Monitor.Enter(UseResourceLock); } UniformBinding.HandleDeviceReset(); }
private UniformBinding <T> GetUniformBindingSlow <T> (Material material, TypedUniform <T> uniform) where T : unmanaged { var effect = material.Effect; if (effect == null) { return(null); } IUniformBinding existing; var key = uniform.KeyTemplate; key.Effect = effect; lock (UniformBindings) { if (UniformBindings.TryGetValue(key, out existing)) { return(existing.Cast <T>()); } #if FNA // This is fine :-) #else if (material.OwningThread != Thread.CurrentThread) { throw new UniformBindingException( "Uniform bindings must be allocated on the thread that owns the material. An attempt was made to allocate a binding for '" + uniform.Name + "' on '" + material.Effect.CurrentTechnique.Name + "'" ); } #endif var result = UniformBinding <T> .TryCreate(effect, uniform.Name); UniformBindings.Add(key, result); material.UniformBindings.Add(uniform.ID, result); return(result); } }
public bool BeginDraw() { var ffsr = FirstFrameSinceReset; if (IsResetting || _DeviceIsDisposed) { EndReset(); if (_DeviceIsDisposed) { _DeviceIsDisposed = Device.IsDisposed; if (!_DeviceIsDisposed) { _DeviceLost = false; } } return(false); } if (IsDisposed) { return(false); } if (_InsideDrawOperation > 0) { return(false); } if (IsWaitingForDeviceToSettle) { return(false); } try { WaitForActiveSynchronousDraw(); WaitForActiveDraw(); } catch (Exception exc) { if (ShouldSuppressResetRelatedDrawErrors) { if ( (exc is ObjectDisposedException) || (exc is InvalidOperationException) || (exc is NullReferenceException) ) { return(false); } } throw; } Interlocked.Increment(ref _InsideDrawOperation); try { _ActualEnableThreading = EnableThreading; PresentBegunSignal.Reset(); bool result; if (_Running) { if (DoThreadedIssue) { result = true; } else { result = _SyncBeginDraw(); } } else { result = false; } if (ffsr && FirstFrameSinceReset && result) { FirstFrameSinceReset = false; UniformBinding.CollectGarbage(); } return(result); } finally { Interlocked.Decrement(ref _InsideDrawOperation); } }