예제 #1
0
        public GuiRenderer(IGL owner)
        {
            Owner = owner;

            VertexLayout = owner.CreateVertexLayout();
            VertexLayout.DefineVertexAttribute("aPosition", 0, 2, VertexAttribPointerType.Float, AttributeUsage.Position, false, 32, 0);
            VertexLayout.DefineVertexAttribute("aTexcoord", 1, 2, VertexAttribPointerType.Float, AttributeUsage.Texcoord0, false, 32, 8);
            VertexLayout.DefineVertexAttribute("aColor", 2, 4, VertexAttribPointerType.Float, AttributeUsage.Texcoord1, false, 32, 16);
            VertexLayout.Close();

            _Projection = new MatrixStack();
            _Modelview  = new MatrixStack();

            string psProgram, vsProgram;

            if (owner.API == "D3D9")
            {
                vsProgram = DefaultShader_d3d9;
                psProgram = DefaultShader_d3d9;
            }
            else
            {
                vsProgram = DefaultVertexShader_gl;
                psProgram = DefaultPixelShader_gl;
            }

            var vs = Owner.CreateVertexShader(false, vsProgram, "vsmain", true);
            var ps = Owner.CreateFragmentShader(false, psProgram, "psmain", true);

            CurrPipeline = DefaultPipeline = Owner.CreatePipeline(VertexLayout, vs, ps, true, "xgui");
        }
예제 #2
0
        // NOTE: we may need to overhaul uniform-setting infrastructure later.
        // maybe samplers will need to be set by index and not by name (I think the specs don't dictate what the sampler must be named)
        public RetroShader(IGL owner, string source, bool debug = false)
        {
            Owner = owner;

            VertexLayout = owner.CreateVertexLayout();
            VertexLayout.DefineVertexAttribute("position", 0, 4, VertexAttribPointerType.Float, AttributeUsage.Position, false, 40, 0);
            VertexLayout.DefineVertexAttribute("color", 1, 4, VertexAttribPointerType.Float, AttributeUsage.Color0, false, 40, 16);             //just dead weight, i have no idea why this is here. but some old HLSL compilers (used in bizhawk for various reasons) will want it to exist here since it exists in the vertex shader
            VertexLayout.DefineVertexAttribute("tex", 2, 2, VertexAttribPointerType.Float, AttributeUsage.Texcoord0, false, 40, 32);
            VertexLayout.Close();

            string defines  = "";
            string vsSource = $"#define VERTEX\r\n{defines}{source}";
            string psSource = $"#define FRAGMENT\r\n{defines}{source}";
            var    vs       = owner.CreateVertexShader(vsSource, "main_vertex", debug);
            var    ps       = owner.CreateFragmentShader(psSource, "main_fragment", debug);

            Pipeline = Owner.CreatePipeline(VertexLayout, vs, ps, debug, "retro");

            if (!Pipeline.Available)
            {
                Available = false;
                return;
            }

            // retroarch shaders will sometimes not have the right sampler name
            // it's unclear whether we should bind to s_p or sampler0
            // lets bind to sampler0 in case we don't have s_p
            sampler0 = Pipeline.TryGetUniform("s_p");
            if (sampler0 == null)
            {
                //sampler wasn't named correctly. this can happen on some retroarch shaders
                foreach (var u in Pipeline.GetUniforms())
                {
                    if (u.Sole.IsSampler && u.Sole.SamplerIndex == 0)
                    {
                        sampler0 = u;
                        break;
                    }
                }
            }

            //if a sampler isn't available, we can't do much, although this does interfere with debugging (shaders just returning colors will malfunction)
            if (sampler0 == null)
            {
                return;
            }

            Available = true;
        }
예제 #3
0
        //NOTE: we may need to overhaul uniform-setting infrastructure later.
        //maybe samplers will need to be set by index and not by name (I think the specs dont dictate what the sampler must be named)

        public RetroShader(IGL owner, string source, bool debug = false)
        {
            Owner = owner;

            VertexLayout = owner.CreateVertexLayout();
            VertexLayout.DefineVertexAttribute("position", 0, 4, VertexAttribPointerType.Float, AttributeUsage.Position, false, 24, 0);
            VertexLayout.DefineVertexAttribute("texCoord1", 1, 2, VertexAttribPointerType.Float, AttributeUsage.Texcoord0, false, 24, 16);
            VertexLayout.Close();

            string defines  = "#define TEXCOORD TEXCOORD0\r\n";            //maybe not safe..
            string vsSource = "#define VERTEX\r\n" + defines + source;
            string psSource = "#define FRAGMENT\r\n" + defines + source;
            var    vs       = owner.CreateVertexShader(true, vsSource, "main_vertex", debug);
            var    ps       = owner.CreateFragmentShader(true, psSource, "main_fragment", debug);

            Pipeline = Owner.CreatePipeline(VertexLayout, vs, ps, debug, "retro");
        }
예제 #4
0
        public GuiRenderer(IGL owner)
        {
            Owner = owner;

            VertexLayout = owner.CreateVertexLayout();
            VertexLayout.DefineVertexAttribute("aPosition", 0, 2, VertexAttribPointerType.Float, false, 32, 0);
            VertexLayout.DefineVertexAttribute("aTexcoord", 1, 2, VertexAttribPointerType.Float, false, 32, 8);
            VertexLayout.DefineVertexAttribute("aColor", 2, 4, VertexAttribPointerType.Float, false, 32, 16);
            VertexLayout.Close();

            _Projection = new MatrixStack();
            _Modelview  = new MatrixStack();

            var vs = Owner.CreateVertexShader(DefaultVertexShader, true);
            var ps = Owner.CreateFragmentShader(DefaultPixelShader, true);

            CurrPipeline = DefaultPipeline = Owner.CreatePipeline(VertexLayout, vs, ps, true);
        }