Exemplo n.º 1
0
        /// <summary>
        /// Samples at specified address of texture using sampler.
        /// </summary>
        /// <param name="sampler"></param>
        /// <param name="texture"></param>
        /// <param name="position"></param>
        /// <param name="sample"></param>
        public void Sample([NotNull] Operand sampler, [NotNull] Operand texture, [NotNull] Operand position, Operand offset, [NotNull] Operand sample)
        {
            // We first validate.
            switch (texture.Format)
            {
            case PinFormat.Texture1D:
                if (position.Format != PinFormat.Float)
                {
                    throw new ArgumentException("Position must be one-dimensional.");
                }
                break;

            case PinFormat.Texture1DArray:
                if (position.Format != PinFormat.Floatx2)
                {
                    throw new ArgumentException("Position must be two-dimensional.");
                }
                break;

            case PinFormat.Texture2D:
                if (position.Format != PinFormat.Floatx2)
                {
                    throw new ArgumentException("Position must be two-dimensional.");
                }
                break;

            case PinFormat.Texture2DArray:
                if (position.Format != PinFormat.Floatx3)
                {
                    throw new ArgumentException("Position must be three-dimensional.");
                }
                break;

            case PinFormat.TextureCube:
                if (position.Format != PinFormat.Floatx3)
                {
                    throw new ArgumentException("Position must be three-dimensional.");
                }
                break;

            case PinFormat.Texture3D:
                if (position.Format != PinFormat.Floatx3)
                {
                    throw new ArgumentException("Position must be three-dimensional.");
                }
                break;

            case PinFormat.BufferTexture:
                if (position.Format != PinFormat.Integer)
                {
                    throw new ArgumentException("Position must be one dimensional.");
                }
                break;

            default:
                break;
            }

            compiler.Sample(sampler.Name, texture.Name, position.Name,
                            offset != null ? offset.Name : -1, sample.Name);
        }