aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/Varying.cs
blob: b9b2afb47696a2afeb0377a4122bee6ed130edd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Ryujinx.Graphics.Shader.Translation;

namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{
    public static class Varying
    {
        public static string GetName(int offset)
        {
            offset <<= 2;

            if (offset >= AttributeConsts.UserAttributeBase &&
                offset <  AttributeConsts.UserAttributeEnd)
            {
                offset -= AttributeConsts.UserAttributeBase;

                string name = $"{ DefaultNames.OAttributePrefix}{(offset >> 4)}";

                name += "_" + "xyzw"[(offset >> 2) & 3];

                return name;
            }

            switch (offset)
            {
                case AttributeConsts.PositionX:
                case AttributeConsts.PositionY:
                case AttributeConsts.PositionZ:
                case AttributeConsts.PositionW:
                    return "gl_Position";
                case AttributeConsts.PointSize:
                    return "gl_PointSize";
                case AttributeConsts.ClipDistance0:
                    return "gl_ClipDistance[0]";
                case AttributeConsts.ClipDistance1:
                    return "gl_ClipDistance[1]";
                case AttributeConsts.ClipDistance2:
                    return "gl_ClipDistance[2]";
                case AttributeConsts.ClipDistance3:
                    return "gl_ClipDistance[3]";
                case AttributeConsts.ClipDistance4:
                    return "gl_ClipDistance[4]";
                case AttributeConsts.ClipDistance5:
                    return "gl_ClipDistance[5]";
                case AttributeConsts.ClipDistance6:
                    return "gl_ClipDistance[6]";
                case AttributeConsts.ClipDistance7:
                    return "gl_ClipDistance[7]";
                case AttributeConsts.VertexId:
                    return "gl_VertexID";
            }

            return null;
        }

        public static int GetSize(int offset)
        {
            switch (offset << 2)
            {
                case AttributeConsts.PositionX:
                case AttributeConsts.PositionY:
                case AttributeConsts.PositionZ:
                case AttributeConsts.PositionW:
                    return 4;
            }

            return 1;
        }
    }
}