コード例 #1
0
        /// <summary>
        /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
        /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
        /// </summary>
        public override void BindSamplerState()
        {
            if (!base.IsBound)
            {
                D3D.SamplerDescription desc = new D3D.SamplerDescription();
                desc.AddressU = D3D10Helper.ToD3DTextureAddressMode(base.AddressU);
                desc.AddressV = D3D10Helper.ToD3DTextureAddressMode(base.AddressV);
                desc.AddressW = D3D10Helper.ToD3DTextureAddressMode(base.AddressW);
                desc.Filter   = D3D10Helper.ToD3DFilter(base.Filter);
                //Force 1-16 range.
                if (base.MaxAnisotropy < 1)
                {
                    base.MaxAnisotropy = 1;
                }
                else if (base.MaxAnisotropy > 16)
                {
                    base.MaxAnisotropy = 16;
                }
                desc.MaximumAnisotropy = base.MaxAnisotropy;
                desc.MipLodBias        = base.MipMapLevelOfDetailBias;

                //Set defaults
                desc.MinimumLod         = 0f;
                desc.MaximumLod         = float.MaxValue;
                desc.BorderColor        = new SlimDX.Color4(0, 0, 0, 0);
                desc.ComparisonFunction = D3D.Comparison.Never;

                _ss          = D3D.SamplerState.FromDescription(_graphicsDevice, desc);
                base.IsBound = true;

                //Add to tracker
                _renderer.Resources.AddTrackedObject(_ss.ComPointer, this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Flushes the collection's state to the device, only samplers that have been
        /// changed since the last draw call will get sent.
        /// </summary>
        internal void FlushState()
        {
            //Return if we haven't even touched these states, so we don't have to loop over them.
            if (!_shortCircuitUpdate)
            {
                return;
            }
            for (int i = 0; i < _maxSamplers; i++)
            {
                if (_dirtyMark[i])
                {
                    _dirtyMark[i] = false;

                    D3D.SamplerState ss    = null;
                    SamplerState     value = _samplers[i];
                    if (value != null)
                    {
                        D3D10SamplerStateImplementation impl = value.Implementation as D3D10SamplerStateImplementation;
                        ss = impl.D3D10SamplerState;
                    }

                    if (_vertexSamplers)
                    {
                        _graphicsDevice.VertexShader.SetSampler(ss, i);
                    }
                    else
                    {
                        _graphicsDevice.PixelShader.SetSampler(ss, i);
                    }
                }
            }
            _shortCircuitUpdate = false;
        }
コード例 #3
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     if (!IsDisposed)
     {
         //Dispose of managed resources
         if (disposing)
         {
             if (_ss != null)
             {
                 if (_renderer != null)
                 {
                     _renderer.Resources.RemoveTrackedObject(_ss.ComPointer);
                 }
                 _ss.Dispose();
                 _ss = null;
             }
         }
         base.Dispose(disposing);
     }
 }