aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs
blob: 1c5acedf3afe51b1a3a6b9f8078c39081796afac (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
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
using System;

namespace Ryujinx.Graphics.OpenGL.Image
{
    class ImageArray : IImageArray
    {
        private record struct TextureRef
        {
            public int Handle;
            public Format Format;
        }

        private readonly TextureRef[] _images;

        public ImageArray(int size)
        {
            _images = new TextureRef[size];
        }

        public void SetFormats(int index, GAL.Format[] imageFormats)
        {
            for (int i = 0; i < imageFormats.Length; i++)
            {
                _images[index + i].Format = imageFormats[i];
            }
        }

        public void SetImages(int index, ITexture[] images)
        {
            for (int i = 0; i < images.Length; i++)
            {
                ITexture image = images[i];

                if (image is TextureBase imageBase)
                {
                    _images[index + i].Handle = imageBase.Handle;
                }
                else
                {
                    _images[index + i].Handle = 0;
                }
            }
        }

        public void Bind(int baseBinding)
        {
            for (int i = 0; i < _images.Length; i++)
            {
                if (_images[i].Handle == 0)
                {
                    GL.BindImageTexture(baseBinding + i, 0, 0, true, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8);
                }
                else
                {
                    SizedInternalFormat format = FormatTable.GetImageFormat(_images[i].Format);

                    if (format != 0)
                    {
                        GL.BindImageTexture(baseBinding + i, _images[i].Handle, 0, true, 0, TextureAccess.ReadWrite, format);
                    }
                }
            }
        }
    }
}