コード例 #1
0
        private Accumulator CompareExpression()
        {
            var    result    = AddSubstractExpression();
            var    first     = _runEnvironment.CurrentLine.NextToken();
            IToken secondary = null;

            switch (first.Seperator)
            {
            case TokenType.Equal:
                break;

            case TokenType.LessThan:
            case TokenType.GreaterThan:
                secondary = _runEnvironment.CurrentLine.NextToken();
                break;

            default:
                _runEnvironment.CurrentLine.PushToken(first);
                return(result);
            }

            if (secondary != null)
            {
                switch (secondary.Seperator)
                {
                case TokenType.GreaterThan:
                case TokenType.Equal:
                    break;

                default:
                    _runEnvironment.CurrentLine.PushToken(secondary);
                    secondary = null;
                    break;
                }
            }

            int comparisonResult;

            if (result.Type == typeof(string))
            {
                comparisonResult = result.ValueAsString().CompareTo(AddSubstractExpression().ValueAsString());
            }
            else
            {
                comparisonResult = result.ValueAsDouble().CompareTo(AddSubstractExpression().ValueAsDouble());
            }

            return(new Accumulator(ComparisonFunction(first, secondary)(comparisonResult) ? 1.0 : 0.0));
        }
コード例 #2
0
 /// <summary>
 /// Sorts an array using specified comparison function
 /// </summary>
 /// <param name="a">Array</param>
 /// <param name="compare">Comparison function</param>
 public static void MergeSort(T[] a, ComparisonFunction <T> compare)    //2nd fastest algorithm after quicksort
 //only with one array instead
 {
     //The core idea is to split array into pairs of elements and sort them
     //during the merge
     a = Merged(a, compare);
 }
コード例 #3
0
        // Perform the compare operation.
        private void compareImagesButton_Click(object sender, EventArgs e)
        {
            ComparisonFunction function = ComparisonFunction.ClearEqual;

            switch (comparisonBox.SelectedIndex)
            {
            case 0:
                function = ComparisonFunction.ClearLess;
                break;

            case 1:
                function = ComparisonFunction.ClearLessOrEqual;
                break;

            case 2:
                function = ComparisonFunction.ClearEqual;
                break;

            case 3:
                function = ComparisonFunction.ClearGreaterOrEqual;
                break;

            case 4:
                function = ComparisonFunction.ClearGreater;
                break;
            }
            Algorithms.Compare(imageViewer1.Image, imageViewer2.Image, imageViewer3.Image, function);
        }
コード例 #4
0
 /// <summary>To initialize this structure with default value, use this constructor. The argument value is ignored.</summary>
 /// <remarks>This is only here because C# doesn’t support parameterless constructors for structures.</remarks>
 public StencilOpDesc(bool unused)
 {
     StencilFailOp      = StencilOp.Keep;
     StencilDepthFailOp = StencilOp.Keep;
     StencilPassOp      = StencilOp.Keep;
     StencilFunc        = ComparisonFunction.Always;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DepthStencilOperationDescription"/> struct.
 /// </summary>
 /// <param name="stencilFailOp">A <see cref="StencilOperation"/> value that identifies the stencil operation to perform when stencil testing fails.</param>
 /// <param name="stencilDepthFailOp">A <see cref="StencilOperation"/> value that identifies the stencil operation to perform when stencil testing passes and depth testing fails.</param>
 /// <param name="stencilPassOp">A <see cref="StencilOperation"/> value that identifies the stencil operation to perform when stencil testing and depth testing both pass.</param>
 /// <param name="stencilFunc">A <see cref="ComparisonFunction"/> value that identifies the function that compares stencil data against existing stencil data.</param>
 public DepthStencilOperationDescription(StencilOperation stencilFailOp, StencilOperation stencilDepthFailOp, StencilOperation stencilPassOp, ComparisonFunction stencilFunc)
 {
     StencilFailOp      = stencilFailOp;
     StencilDepthFailOp = stencilDepthFailOp;
     StencilPassOp      = stencilPassOp;
     StencilFunc        = stencilFunc;
 }
コード例 #6
0
ファイル: XNAHelper.cs プロジェクト: chuz/tesla-engine
        internal static XFG.CompareFunction ToXNACompareFunction(ComparisonFunction func)
        {
            switch (func)
            {
            case ComparisonFunction.Always:
                return(XFG.CompareFunction.Always);

            case ComparisonFunction.Equal:
                return(XFG.CompareFunction.Equal);

            case ComparisonFunction.Greater:
                return(XFG.CompareFunction.Greater);

            case ComparisonFunction.GreaterEqual:
                return(XFG.CompareFunction.GreaterEqual);

            case ComparisonFunction.Less:
                return(XFG.CompareFunction.Less);

            case ComparisonFunction.LessEqual:
                return(XFG.CompareFunction.LessEqual);

            case ComparisonFunction.Never:
                return(XFG.CompareFunction.Never);

            case ComparisonFunction.NotEqual:
                return(XFG.CompareFunction.NotEqual);

            default:
                throw new InvalidCastException();
            }
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DepthStencilDescription"/> struct.
 /// </summary>
 /// <param name="depthEnable">Specifies whether to enable depth testing. Set this member to <b>true</b> to enable depth testing.</param>
 /// <param name="depthWriteEnable">Specifies a value that identifies a portion of the depth-stencil buffer that can be modified by depth data.</param>
 /// <param name="depthFunc">A <see cref="ComparisonFunction"/> value that identifies a function that compares depth data against existing depth data.</param>
 /// <param name="stencilEnable">Specifies whether to enable stencil testing. Set this member to <b>true</b> to enable stencil testing.</param>
 /// <param name="stencilReadMask">Identify a portion of the depth-stencil buffer for reading stencil data.</param>
 /// <param name="stencilWriteMask">Identify a portion of the depth-stencil buffer for writing stencil data.</param>
 /// <param name="frontStencilFailOp"></param>
 /// <param name="frontStencilDepthFailOp"></param>
 /// <param name="frontStencilPassOp"></param>
 /// <param name="frontStencilFunc"></param>
 /// <param name="backStencilFailOp"></param>
 /// <param name="backStencilDepthFailOp"></param>
 /// <param name="backStencilPassOp"></param>
 /// <param name="backStencilFunc"></param>
 public DepthStencilDescription(
     bool depthEnable,
     bool depthWriteEnable,
     ComparisonFunction depthFunc,
     bool stencilEnable,
     byte stencilReadMask,
     byte stencilWriteMask,
     StencilOperation frontStencilFailOp,
     StencilOperation frontStencilDepthFailOp,
     StencilOperation frontStencilPassOp,
     ComparisonFunction frontStencilFunc,
     StencilOperation backStencilFailOp,
     StencilOperation backStencilDepthFailOp,
     StencilOperation backStencilPassOp,
     ComparisonFunction backStencilFunc)
 {
     DepthEnable                  = depthEnable;
     DepthWriteMask               = depthWriteEnable ? DepthWriteMask.All : DepthWriteMask.Zero;
     DepthFunc                    = depthFunc;
     StencilEnable                = stencilEnable;
     StencilReadMask              = stencilReadMask;
     StencilWriteMask             = stencilWriteMask;
     FrontFace.StencilFailOp      = frontStencilFailOp;
     FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
     FrontFace.StencilPassOp      = frontStencilPassOp;
     FrontFace.StencilFunc        = frontStencilFunc;
     BackFace.StencilFailOp       = backStencilFailOp;
     BackFace.StencilDepthFailOp  = backStencilDepthFailOp;
     BackFace.StencilPassOp       = backStencilPassOp;
     BackFace.StencilFunc         = backStencilFunc;
 }
コード例 #8
0
        internal static D3D.Comparison ToD3DComparison(ComparisonFunction func)
        {
            switch (func)
            {
            case ComparisonFunction.Always:
                return(D3D.Comparison.Always);

            case ComparisonFunction.Equal:
                return(D3D.Comparison.Equal);

            case ComparisonFunction.Greater:
                return(D3D.Comparison.Greater);

            case ComparisonFunction.GreaterEqual:
                return(D3D.Comparison.GreaterEqual);

            case ComparisonFunction.Less:
                return(D3D.Comparison.Less);

            case ComparisonFunction.LessEqual:
                return(D3D.Comparison.LessEqual);

            case ComparisonFunction.Never:
                return(D3D.Comparison.Never);

            case ComparisonFunction.NotEqual:
                return(D3D.Comparison.NotEqual);

            default:
                throw new ArgumentException("Invalid compare function");
            }
        }
コード例 #9
0
        public SortInfo(PropertyInfo property, string sortPropertyName)
        {
            this.property = property;
            propertyType  = property.PropertyType;
            switch (propertyType.Name.ToString())
            {
            case "Int16":
            case "Int32":
            case "Int64":
                comparisonFunction = FirstMoreOrEqInt;
                break;

            case "String":
                comparisonFunction = FirstMoreOrEqString;
                break;

            case "DateTime":
                comparisonFunction = FirstMoreOrEqDate;
                break;

            case "Double":
                comparisonFunction = FirstMoreOrEqDouble;
                break;

            default:
                comparisonFunction = null;
                break;
            }
        }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SamplerDescription"/> struct.
 /// </summary>
 /// <param name="filter">Filtering method to use when sampling a texture.</param>
 /// <param name="addressU">Method to use for resolving a u texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="addressV">Method to use for resolving a v texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="addressW">Method to use for resolving a w texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="mipLODBias">Offset from the calculated mipmap level.</param>
 /// <param name="maxAnisotropy">Clamping value used if <see cref="Filter.Anisotropic"/> or <see cref="Filter.ComparisonAnisotropic"/> is specified in Filter. Valid values are between 1 and 16.</param>
 /// <param name="comparisonFunction">A function that compares sampled data against existing sampled data. </param>
 /// <param name="borderColor">Border color to use if <see cref="TextureAddressMode.Border"/> is specified for AddressU, AddressV, or AddressW.</param>
 /// <param name="minLOD">Lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.</param>
 /// <param name="maxLOD">Upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. </param>
 public SamplerDescription(
     Filter filter,
     TextureAddressMode addressU,
     TextureAddressMode addressV,
     TextureAddressMode addressW,
     float mipLODBias,
     int maxAnisotropy,
     ComparisonFunction comparisonFunction,
     in Color4 borderColor,
コード例 #11
0
        /// <summary>
        /// Sorts array with a specified comparison function.
        /// Uses new thread.
        /// </summary>
        public static void NewThreadSort(T[] array, ComparisonFunction <T> compare)
        {
            //Creating new Thread incapsulating sorting method
            Thread thread = new Thread(() => MergeSort(array, compare));

            //Starting method in a new thread
            thread.Start();
            //It's a shame that this approach does not have anything with another CPU core.
        }
コード例 #12
0
        public void IsFinite()
        {
            // arrange
            var device = HostDevice.Instance;
            var source = NdArray <int> .Zeros(device, new[] { 2, 3, 4 });

            // action
            var result = ComparisonFunction <int> .IsFinite(source);

            // assert
            Assert.IsTrue(NdArray <int> .All(result));
        }
コード例 #13
0
        public void IsClose_DifferentDoubleVectorsWithBigTolerence_ReturnTrue()
        {
            // arrange
            var device = HostDevice.Instance;
            var source = NdArray <double> .Arange(device, 0, 10, 1);

            // action
            var close = ComparisonFunction <double> .IsClose(source, source + 1.0, 2.0);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, close.Shape);
        }
コード例 #14
0
        public void IsClose_SameDoubleVectors_ReturnTrues()
        {
            // arrange
            var device = HostDevice.Instance;
            var source = NdArray <double> .Arange(device, 0, 10, 1);

            // action
            var close = ComparisonFunction <double> .IsClose(source, source);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, close.Shape);
        }
コード例 #15
0
        public void NotEqual()
        {
            // arrange
            var device  = HostDevice.Instance;
            var sourceA = NdArray <int> .Arange(device, 0, 10, 1);

            var sourceB = NdArray <int> .Arange(device, 0, 10, 1);

            // action
            var result = ComparisonFunction <int> .NotEqual(sourceA, sourceB);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, result.Shape);
        }
コード例 #16
0
        public void AlmostEqual_DifferentIntVectors_ReturnFalse()
        {
            // arrange
            var device  = HostDevice.Instance;
            var sourceA = NdArray <int> .Zeros(device, new[] { 2, 3, 4 });

            var sourceB = NdArray <int> .Zeros(device, new[] { 2, 3, 4 }) + 1;

            // action
            var almostEqual = ComparisonFunction <int> .AlmostEqual(sourceA, sourceB);

            // assert
            Assert.IsFalse(almostEqual);
        }
コード例 #17
0
        /// <summary>
        /// Sorts array with a specified comparison function.
        /// </summary>
        public static new void MergeSort(T[] array, ComparisonFunction <T> compare)
        {
            //Subscription to event
            onSortingDone += SortingDoneSubscriber;
            //Invoking sort method from the base class
            CustomSort <T> .MergeSort(array, compare);

            //Invoking all subscribed methods
            onSortingDone?.Invoke(new object(), new SortingEventArgs <T>(array));
            //Unsubscription to event
            if (onSortingDone != null)
            {
                onSortingDone -= SortingDoneSubscriber;
            }
        }
コード例 #18
0
 /// <summary>To initialize this structure with default value, use this constructor. The argument value is ignored.</summary>
 /// <remarks>This is only here because C# doesn’t support parameterless constructors for structures.</remarks>
 public SamplerDesc(bool unused)
 {
     baseStruct     = new DeviceObjectAttribs(true);
     MinFilter      = FilterType.Linear;
     MagFilter      = FilterType.Linear;
     MipFilter      = FilterType.Linear;
     AddressU       = TextureAddressMode.Clamp;
     AddressV       = TextureAddressMode.Clamp;
     AddressW       = TextureAddressMode.Clamp;
     MipLODBias     = 0;
     MaxAnisotropy  = 0;
     ComparisonFunc = ComparisonFunction.Never;
     BorderColor    = Vector4.Zero;
     MinLOD         = 0;
     MaxLOD         = float.MaxValue;
 }
コード例 #19
0
        public void FillNotEqual()
        {
            // arrange
            var device  = HostDevice.Instance;
            var sourceA = NdArray <int> .Arange(device, 0, 10, 1);

            var sourceB = NdArray <int> .Arange(device, 0, 10, 1);

            var result = NdArray <bool> .Zeros(device, new[] { 10 });

            // action
            ComparisonFunction <bool> .FillNotEqual(result, sourceA, sourceB);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, result.Shape);
        }
コード例 #20
0
        public StaticSamplerDescription(ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace)
        {
            Filter             = Filter.MinMagMipLinear;
            AddressU           = TextureAddressMode.Clamp;
            AddressV           = TextureAddressMode.Clamp;
            AddressW           = TextureAddressMode.Clamp;
            MipLodBias         = 0.0f;
            MaxAnisotropy      = 1;
            ComparisonFunction = ComparisonFunction.Never;
            BorderColor        = StaticBorderColor.TransparentBlack;
            MinLod             = float.MinValue;
            MaxLod             = float.MaxValue;

            ShaderRegister   = shaderRegister;
            RegisterSpace    = registerSpace;
            ShaderVisibility = shaderVisibility;
        }
コード例 #21
0
        private void AddComparisonFunction(string name, ComparisonFunction compFunc)
        {
            // Register the built-in function as a symbol in the root environment
            rootEnv.Symbols[name] = new BuiltInFunction((env, args) =>
            {
                int argCount = args.Count();

                // Comparison functions require at least two arguments
                if (argCount < 2)
                {
                    throw new UnexpectedNumberOfArgumentsException(name, ">= 2", argCount);
                }

                // Convert all arguments to number expression
                IEnumerable <NumberExpression> numArgs = args.Select(x => x as NumberExpression);

                // If any of the arguments cannot be converted to a number
                if (numArgs.Any(x => x == null))
                {
                    throw new UnexpectedArgumentTypeException(name);
                }

                // Convert the number expressions to integers
                IEnumerable <int> intArgs = numArgs.Select(x => x.Value);

                // Get the first expression
                int previous = intArgs.First();

                // Check if the comparison function applies to all of the values
                // Every value is compared to the value before it
                foreach (int val in intArgs.Skip(1))
                {
                    if (compFunc(previous, val))
                    {
                        previous = val;
                    }
                    else
                    {
                        return(new NumberExpression(false));
                    }
                }

                // All of the values have passed the comparison test
                return(new NumberExpression(true));
            });
        }
コード例 #22
0
        public D3D11Sampler(ID3D11Device device, ref SamplerDescription description)
        {
            ComparisonFunction comparision = description.ComparisonKind == null ? ComparisonFunction.Never : D3D11Formats.VdToD3D11ComparisonFunc(description.ComparisonKind.Value);

            Vortice.Direct3D11.SamplerDescription samplerStateDesc = new Vortice.Direct3D11.SamplerDescription
            {
                AddressU           = D3D11Formats.VdToD3D11AddressMode(description.AddressModeU),
                AddressV           = D3D11Formats.VdToD3D11AddressMode(description.AddressModeV),
                AddressW           = D3D11Formats.VdToD3D11AddressMode(description.AddressModeW),
                Filter             = D3D11Formats.ToD3D11Filter(description.Filter, description.ComparisonKind.HasValue),
                MinLOD             = description.MinimumLod,
                MaxLOD             = description.MaximumLod,
                MaxAnisotropy      = (int)description.MaximumAnisotropy,
                ComparisonFunction = comparision,
                MipLODBias         = description.LodBias,
                BorderColor        = ToRawColor4(description.BorderColor)
            };

            DeviceSampler = device.CreateSamplerState(samplerStateDesc);
        }
コード例 #23
0
        internal SharpDX.Direct3D11.SamplerState GetState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // Build the description.
                var desc = new SharpDX.Direct3D11.SamplerStateDescription
                {
                    AddressU = GetAddressMode(AddressU),
                    AddressV = GetAddressMode(AddressV),
                    AddressW = GetAddressMode(AddressW),

#if WINDOWS_UAP
                    desc.BorderColor = new SharpDX.Mathematics.Interop.RawColor4(
                        BorderColor.R / 255.0f,
                        BorderColor.G / 255.0f,
                        BorderColor.B / 255.0f,
                        BorderColor.A / 255.0f);
#else
                    BorderColor = BorderColor.ToColor4(),
#endif
                    Filter             = GetFilter(Filter, FilterMode),
                    MaximumAnisotropy  = Math.Min(MaxAnisotropy, device.Capabilities.MaxTextureAnisotropy),
                    MipLodBias         = MipMapLevelOfDetailBias,
                    ComparisonFunction = ComparisonFunction.ToComparison(),

                    // TODO: How do i do this?
                    MinimumLod = 0.0f,

                    // To support feature level 9.1 these must
                    // be set to these exact values.
                    MaximumLod = float.MaxValue
                };

                // Create the state.
                _state = new SharpDX.Direct3D11.SamplerState(GraphicsDevice._d3dDevice, desc);
            }

            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            return(_state);
        }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SamplerDescription"/> struct.
 /// </summary>
 /// <param name="filter">Filtering method to use when sampling a texture.</param>
 /// <param name="addressU">Method to use for resolving a u texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="addressV">Method to use for resolving a v texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="addressW">Method to use for resolving a w texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="mipLODBias">Offset from the calculated mipmap level.</param>
 /// <param name="maxAnisotropy">Clamping value used if <see cref="Filter.Anisotropic"/> or <see cref="Filter.ComparisonAnisotropic"/> is specified in Filter. Valid values are between 1 and 16.</param>
 /// <param name="comparisonFunction">A function that compares sampled data against existing sampled data. </param>
 /// <param name="minLOD">Lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.</param>
 /// <param name="maxLOD">Upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. </param>
 public SamplerDescription(
     Filter filter,
     TextureAddressMode addressU,
     TextureAddressMode addressV,
     TextureAddressMode addressW,
     float mipLODBias  = 0.0f,
     int maxAnisotropy = 1,
     ComparisonFunction comparisonFunction = ComparisonFunction.Never,
     float minLOD = float.MinValue,
     float maxLOD = float.MaxValue)
 {
     Filter             = filter;
     AddressU           = addressU;
     AddressV           = addressV;
     AddressW           = addressW;
     MipLODBias         = mipLODBias;
     MaxAnisotropy      = maxAnisotropy;
     ComparisonFunction = comparisonFunction;
     BorderColor        = new RawColor4(1.0f, 1.0f, 1.0f, 1.0f);
     MinLOD             = minLOD;
     MaxLOD             = maxLOD;
 }
コード例 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SamplerDescription"/> struct.
 /// </summary>
 /// <param name="filter">Filtering method to use when sampling a texture.</param>
 /// <param name="addressU">Method to use for resolving a u texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="addressV">Method to use for resolving a v texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="addressW">Method to use for resolving a w texture coordinate that is outside the 0 to 1 range.</param>
 /// <param name="mipLODBias">Offset from the calculated mipmap level.</param>
 /// <param name="maxAnisotropy">Clamping value used if <see cref="Filter.Anisotropic"/> or <see cref="Filter.ComparisonAnisotropic"/> is specified in Filter. Valid values are between 1 and 16.</param>
 /// <param name="comparisonFunction">A function that compares sampled data against existing sampled data. </param>
 /// <param name="borderColor">Border color to use if <see cref="TextureAddressMode.Border"/> is specified for AddressU, AddressV, or AddressW.</param>
 /// <param name="minLOD">Lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.</param>
 /// <param name="maxLOD">Upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. </param>
 public SamplerDescription(
     Filter filter,
     TextureAddressMode addressU,
     TextureAddressMode addressV,
     TextureAddressMode addressW,
     float mipLODBias,
     int maxAnisotropy,
     ComparisonFunction comparisonFunction,
     RawColor4 borderColor,
     float minLOD,
     float maxLOD)
 {
     Filter             = filter;
     AddressU           = addressU;
     AddressV           = addressV;
     AddressW           = addressW;
     MipLODBias         = mipLODBias;
     MaxAnisotropy      = maxAnisotropy;
     ComparisonFunction = comparisonFunction;
     BorderColor        = borderColor;
     MinLOD             = minLOD;
     MaxLOD             = maxLOD;
 }
コード例 #26
0
        private void Update(EvaluationContext context)
        {
            var samplerDesc = new SamplerStateDescription()
            {
                Filter             = Filter.GetValue(context),
                AddressU           = AddressU.GetValue(context),
                AddressV           = AddressV.GetValue(context),
                AddressW           = AddressW.GetValue(context),
                MipLodBias         = MipLoadBias.GetValue(context),
                MaximumAnisotropy  = MaximumAnisotropy.GetValue(context),
                ComparisonFunction = ComparisonFunction.GetValue(context),
                // BorderColor = BorderColor.GetValue(context),
                MinimumLod = MinimumLod.GetValue(context),
                MaximumLod = MaximumLod.GetValue(context)
            };

            try
            {
                var samplerState = new SamplerState(ResourceManager.Instance().Device, samplerDesc); // todo: put into resource manager
                SamplerState.Value?.Dispose();
                SamplerState.Value = samplerState;
            }
            catch (SharpDXException e)
            {
                Log.Error($"{Parent.Symbol.Name}.SamplerStateOp: Invalid sampler state " + e.Message);
                if (SamplerState.Value == null)
                {
                    // there was no previous valid sampler state, so set default sampler state
                    SamplerState.Value = ResourceManager.Instance().DefaultSamplerState;
                    Log.Error("Using the default sampler state instead.");
                }
                else
                {
                    Log.Error("Using the last valid sampler state instead.");
                }
            }
        }
コード例 #27
0
        internal void Activate(GraphicsDevice device, TextureTarget target, bool useMipmaps = false)
        {
            if (GraphicsDevice == null)
            {
                // We're now bound to a device... no one should
                // be changing the state of this object now!
                GraphicsDevice = device;
            }
            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            switch (Filter)
            {
            case TextureFilter.Point:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest : TextureMinFilter.Nearest));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.Linear:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.Anisotropic:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, MathHelper.Clamp(this.MaxAnisotropy, 1.0f, GraphicsDevice.GraphicsCapabilities.MaxTextureAnisotropy));
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.PointMipLinear:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear : TextureMinFilter.Nearest));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.LinearMipPoint:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest : TextureMinFilter.Linear));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.MinLinearMagPointMipLinear:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.MinLinearMagPointMipPoint:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest: TextureMinFilter.Linear));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.MinPointMagLinearMipLinear:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear: TextureMinFilter.Nearest));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilter.MinPointMagLinearMipPoint:
                if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic)
                {
                    GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f);
                    GraphicsExtensions.CheckGLError();
                }
                GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest: TextureMinFilter.Nearest));
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GraphicsExtensions.CheckGLError();
                break;

            default:
                throw new NotSupportedException();
            }

            // Set up texture addressing.
            GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)GetWrapMode(AddressU));
            GraphicsExtensions.CheckGLError();
            GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)GetWrapMode(AddressV));
            GraphicsExtensions.CheckGLError();
#if !GLES
            // Border color is not supported by glTexParameter in OpenGL ES 2.0
            _openGLBorderColor[0] = BorderColor.R / 255.0f;
            _openGLBorderColor[1] = BorderColor.G / 255.0f;
            _openGLBorderColor[2] = BorderColor.B / 255.0f;
            _openGLBorderColor[3] = BorderColor.A / 255.0f;
            GL.TexParameter(target, TextureParameterName.TextureBorderColor, _openGLBorderColor);
            GraphicsExtensions.CheckGLError();
            // LOD bias is not supported by glTexParameter in OpenGL ES 2.0
            GL.TexParameter(target, TextureParameterName.TextureLodBias, MipMapLevelOfDetailBias);
            GraphicsExtensions.CheckGLError();
            // Comparison samplers are not supported in OpenGL ES 2.0 (without an extension, anyway)
            switch (FilterMode)
            {
            case TextureFilterMode.Comparison:
                GL.TexParameter(target, TextureParameterName.TextureCompareMode, (int)TextureCompareMode.CompareRefToTexture);
                GraphicsExtensions.CheckGLError();
                GL.TexParameter(target, TextureParameterName.TextureCompareFunc, (int)ComparisonFunction.GetDepthFunction());
                GraphicsExtensions.CheckGLError();
                break;

            case TextureFilterMode.Default:
                GL.TexParameter(target, TextureParameterName.TextureCompareMode, (int)TextureCompareMode.None);
                GraphicsExtensions.CheckGLError();
                break;

            default:
                throw new InvalidOperationException("Invalid filter mode!");
            }
#endif
            if (GraphicsDevice.GraphicsCapabilities.SupportsTextureMaxLevel)
            {
                if (this.MaxMipLevel > 0)
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterNameTextureMaxLevel, this.MaxMipLevel);
                }
                else
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterNameTextureMaxLevel, 1000);
                }
                GraphicsExtensions.CheckGLError();
            }
        }
コード例 #28
0
ファイル: Device.cs プロジェクト: Burton-Radons/Alexandria
 public AlphaTest(ComparisonFunction function, double reference)
 {
     Function = function;
     Reference = reference;
 }
コード例 #29
0
ファイル: Interop.cs プロジェクト: chopshop-166/WPILib
 public static extern int imaqCompare(IntPtr dest, IntPtr source, IntPtr compareImage, ComparisonFunction compare);
コード例 #30
0
 public ISampler CreateSampler(TextureAddressMode addressModeU, TextureAddressMode addressModeV, Filter filter, ComparisonFunction comparisonFunction)
 {
     throw new System.NotImplementedException();
 }
コード例 #31
0
 public ISampler CreateSampler(TextureAddressMode addressModeU, TextureAddressMode addressModeV, Filter filter, ComparisonFunction comparisonFunction)
 {
     return(new D3D11Sampler(_graphicsDevice, addressModeU, addressModeV, filter, comparisonFunction));
 }
コード例 #32
0
ファイル: GL46GraphicsFactory.cs プロジェクト: deccer/Xacor
 public ISampler CreateSampler(TextureAddressMode addressModeU, TextureAddressMode addressModeV, Filter filter, ComparisonFunction comparisonFunction)
 {
     return(null);
 }