private GLTexture SetScreenTextureBuffer(GLContext control)
        {
            var screenBuffer = ScreenBufferTexture.GetColorBuffer(control);

            if (screenBuffer == null)
            {
                return(null);
            }

            return(screenBuffer);
        }
Ejemplo n.º 2
0
        private void SetScreenTextureBuffer(ShaderProgram shader, GLContext control)
        {
            int id = 50;

            var screenBuffer = ScreenBufferTexture.GetColorBuffer(control);

            GL.ActiveTexture(TextureUnit.Texture0 + id);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            screenBuffer.Bind();
            shader.SetInt($"{ConvertSamplerID(12)}", id);
        }
        public void Draw(GLContext control, GLFrameworkEngine.Pass pass, BfresRender parentRender)
        {
            if (disposed || !IsVisible)
            {
                return;
            }

            GL.Enable(EnableCap.TextureCubeMapSeamless);

            if (pass == GLFrameworkEngine.Pass.OPAQUE && Meshes.Any(x => x.IsSelected))
            {
                GL.Enable(EnableCap.StencilTest);
                GL.Clear(ClearBufferMask.StencilBufferBit);
                GL.ClearStencil(0);
                GL.StencilFunc(StencilFunction.Always, 0x1, 0x1);
                GL.StencilOp(StencilOp.Keep, StencilOp.Replace, StencilOp.Replace);
            }

            //Go through each mesh and map materials using shader programs
            var meshes = RenderLayer.Sort(this);

            foreach (var mesh in meshes)
            {
                if (mesh.Pass != pass || !mesh.IsVisible ||
                    mesh.IsDepthShadow || mesh.IsCubeMap || mesh.UseColorBufferPass)
                {
                    continue;
                }

                //Load the material data
                var material = (FMAT)mesh.Shape.Material;
                mesh.Material = material;
                //Update the parent renderer
                ((BfresMaterialAsset)mesh.MaterialAsset).ParentRenderer = parentRender;

                if (!ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                RenderMesh(control, mesh);
            }

            GL.DepthMask(true);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            if (meshes.Any(x => x.UseColorBufferPass))
            {
                ScreenBufferTexture.FilterScreen(control);
            }

            foreach (var mesh in meshes.Where(x => x.UseColorBufferPass))
            {
                if (pass != mesh.Pass || !mesh.IsVisible)
                {
                    continue;
                }

                //Load the material data
                var material = (FMAT)mesh.Shape.Material;
                mesh.Material = material;
                ((BfresMaterialAsset)mesh.MaterialAsset).ParentRenderer = parentRender;

                if (!ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                RenderMesh(control, mesh);
            }

            if (Runtime.RenderSettings.WireframeOverlay)
            {
                DrawWireframeOutline(control);
            }

            if (pass == GLFrameworkEngine.Pass.TRANSPARENT)
            {
                DrawSelection(control, parentRender.IsSelected || this.IsSelected);
            }

            GL.DepthMask(true);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
        }