/// <summary>
        /// Generates a OpenGL sampler based on sampler/texture combination.
        /// </summary>
        /// <param name="sampler">The D3D sampler (can be null).</param>
        /// <param name="texture">The D3D texture.</param>
        private void GenerateGLSampler(Variable sampler, Variable texture, bool needsComparison = false)
        {
            Variable glslSampler;

            if (texture == null)
                throw new InvalidOperationException();

            var samplerKey = new SamplerTextureKey(sampler, texture);
            if (!samplerMapping.TryGetValue(samplerKey, out glslSampler))
            {
                var samplerTypeName = texture.Type.ResolveType().Name.Text.Replace("Texture", "sampler");

                // Handle comparison samplers
                if (needsComparison)
                    samplerTypeName += "Shadow";

                glslSampler = new Variable(new TypeName(samplerTypeName), texture.Name + (sampler != null ? "_" + sampler.Name : "_NoSampler")) { Span = sampler == null ? texture.Span : sampler.Span };
                samplerMapping.Add(samplerKey, glslSampler);
            }
        }
        /// <summary>
        /// Generates a OpenGL sampler based on sampler/texture combination.
        /// </summary>
        /// <param name="sampler">The D3D sampler (can be null).</param>
        /// <param name="texture">The D3D texture.</param>
        private void GenerateGLSampler(Variable sampler, Variable texture, bool needsComparison = false)
        {
            Variable glslSampler;

            if (texture == null)
                throw new InvalidOperationException();

            var samplerKey = new SamplerTextureKey(sampler, texture);
            if (!samplerMapping.TryGetValue(samplerKey, out glslSampler))
            {
                var samplerType = texture.Type.ResolveType();
                var samplerTypeName = samplerType.Name.Text;

                if (samplerTypeName.StartsWith("Texture"))
                    samplerTypeName = "sampler" + samplerTypeName.Substring("Texture".Length);
                else if (samplerTypeName.StartsWith("Buffer"))
                    samplerTypeName = "samplerBuffer";

                // TODO: How do we support this on OpenGL ES 2.0? Cast to int/uint on Load()/Sample()?
                var genericSamplerType = samplerType as IGenerics;
                if (genericSamplerType != null && genericSamplerType.GenericArguments.Count == 1)
                {
                    var genericArgument = genericSamplerType.GenericArguments[0].ResolveType();
                    if (TypeBase.GetBaseType(genericArgument) == ScalarType.UInt)
                        samplerTypeName = "u" + samplerTypeName;
                    else if (TypeBase.GetBaseType(genericArgument) == ScalarType.Int)
                        samplerTypeName = "i" + samplerTypeName;
                }

                // Handle comparison samplers
                if (needsComparison)
                    samplerTypeName += "Shadow";

                glslSampler = new Variable(new TypeName(samplerTypeName), texture.Name + (sampler != null ? "_" + sampler.Name : "_NoSampler")) { Span = sampler == null ? texture.Span : sampler.Span };
                samplerMapping.Add(samplerKey, glslSampler);
            }
        }