Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Renderer"/> class.
        /// </summary>
        public Renderer()
        {
            _commandBuckets    = new List <CommandBucket>();
            _nextFrameCommands = new Command[MaxCommands];

            _commandCount = 0;
            _views        = new Dictionary <byte, View>();

            _shaderPrograms = new Dictionary <int, ShaderProgram>();

#if RENDERER_GL
            _glProgramCache = new ResourceCache <GLShaderProgram>(MaxShaderPrograms);
            _glShaderCache  = new ResourceCache <GLShader>(MaxShaderPrograms);
            _glVBCache      = new ResourceCache <GLBuffer>(MaxVertexBuffers);
            _glIBCache      = new ResourceCache <GLBuffer>(MaxIndexBuffers);
            _glTextureCache = new ResourceCache <GLTexture>(MaxTextures);
            _glSamplerCache = new ResourceCache <GLSampler>(MaxTextures);
#endif
            _currentState = new FrameState();

            _defaultBlendState      = new BlendState();
            _defaultDepthState      = new DepthState();
            _defaultRasteriserState = new RasteriserState();

            _defaultTextureSampler = new TextureSampler();
        }
Example #2
0
        public void SetTexture(uint stage, Texture texture, Uniform textureUniform, TextureSampler textureSampler)
        {
            TextureStages[stage].Texture        = texture;
            TextureStages[stage].TextureUniform = textureUniform;
            TextureStages[stage].TextureSampler = textureSampler;

            Instructions |= (CommandInstructions)Enum.Parse(typeof(CommandInstructions), $"SetTexture{stage}");
        }
Example #3
0
        public void Build(TextureSampler sampler)
        {
            GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureWrapS, (int)glTextureWrapMapping[sampler.AddressU]);
            GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureWrapT, (int)glTextureWrapMapping[sampler.AddressV]);
            GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureWrapR, (int)glTextureWrapMapping[sampler.AddressW]);

            // When we're working with mips we do special handling
            if (sampler.MipFilter != TextureFilter.None)
            {
                if (sampler.MipFilter == TextureFilter.Nearest && sampler.MinFilter == TextureFilter.Nearest)
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapNearest);
                }
                else if (sampler.MipFilter == TextureFilter.Nearest && sampler.MinFilter == TextureFilter.Linear)
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapNearest);
                }
                else if (sampler.MipFilter == TextureFilter.Linear && sampler.MinFilter == TextureFilter.Nearest)
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapNearest);
                }
                else
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
                }
            }
            else
            {
                if (sampler.MinFilter == TextureFilter.Nearest)
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                }
                else
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                }

                if (sampler.MagFilter == TextureFilter.Nearest)
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                }
                else
                {
                    GL.SamplerParameter(SamplerRef, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                }
            }

            // TODO: Support for antrioscopic filtering.
        }
Example #4
0
        /// <summary>
        /// Creates the specified sampler.
        /// </summary>
        /// <param name="sampler">The sampler.</param>
        public void Create(TextureSampler sampler)
        {
            SamplerRef = GL.GenSampler();

            this.Build(sampler);
        }