Esempio n. 1
0
        public void SetRenderTargets(ITexture[] colors, ITexture depthStencil)
        {
            EnsureFramebuffer();

            _rtColor0Texture = (TextureBase)colors[0];
            _rtDepthTexture  = (TextureBase)depthStencil;

            for (int index = 0; index < colors.Length; index++)
            {
                TextureView color = (TextureView)colors[index];

                _framebuffer.AttachColor(index, color);

                _fpIsBgra[index] = color != null && color.Format.IsBgra8() ? 1 : 0;
            }

            UpdateFpIsBgra();

            TextureView depthStencilView = (TextureView)depthStencil;

            _framebuffer.AttachDepthStencil(depthStencilView);
            _framebuffer.SetDrawBuffers(colors.Length);

            _hasDepthBuffer = depthStencil != null && depthStencilView.Format != Format.S8Uint;

            UpdateDepthTest();
        }
Esempio n. 2
0
        public void SetTexture(int index, ShaderStage stage, ITexture texture)
        {
            int unit = _program.GetTextureUnit(stage, index);

            if (unit != -1 && texture != null)
            {
                if (unit == 0)
                {
                    _unit0Texture = (TextureBase)texture;
                }
                else
                {
                    ((TextureBase)texture).Bind(unit);
                }

                // Update scale factor for bound textures.

                switch (stage)
                {
                case ShaderStage.Fragment:
                    if (_program.FragmentRenderScaleUniform != -1)
                    {
                        // Only update and send sampled texture scales if the shader uses them.
                        bool  interpolate = false;
                        float scale       = texture.ScaleFactor;

                        if (scale != 1)
                        {
                            TextureBase activeTarget = _rtColor0Texture ?? _rtDepthTexture;

                            if (activeTarget != null && activeTarget.Width / (float)texture.Width == activeTarget.Height / (float)texture.Height)
                            {
                                // If the texture's size is a multiple of the sampler size,
                                // enable interpolation using gl_FragCoord.
                                // (helps "invent" new integer values between scaled pixels)
                                interpolate = true;
                            }
                        }

                        _fpRenderScale[index + 1] = interpolate ? -scale : scale;
                    }
                    break;

                case ShaderStage.Compute:
                    _cpRenderScale[index] = texture.ScaleFactor;
                    break;
                }
            }
        }
Esempio n. 3
0
        public void SetImage(int index, ShaderStage stage, ITexture texture)
        {
            int unit = _program.GetImageUnit(stage, index);

            if (unit != -1 && texture != null)
            {
                TextureBase texBase = (TextureBase)texture;

                FormatInfo formatInfo = FormatTable.GetFormatInfo(texBase.Format);

                SizedInternalFormat format = (SizedInternalFormat)formatInfo.PixelInternalFormat;

                GL.BindImageTexture(unit, texBase.Handle, 0, true, 0, TextureAccess.ReadWrite, format);
            }
        }
Esempio n. 4
0
        public void SetTexture(int index, ShaderStage stage, ITexture texture)
        {
            int unit = _program.GetTextureUnit(stage, index);

            if (unit != -1 && texture != null)
            {
                if (unit == 0)
                {
                    _unit0Texture = (TextureBase)texture;
                }
                else
                {
                    ((TextureBase)texture).Bind(unit);
                }
            }
        }