2019-10-13 02:02:07 -04:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
2019-12-29 12:41:50 -05:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.Graphics.GAL;
|
2019-10-13 02:02:07 -04:00
|
|
|
using System;
|
|
|
|
|
2020-05-23 05:46:09 -04:00
|
|
|
namespace Ryujinx.Graphics.OpenGL.Image
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
|
|
|
static class TextureCopyUnscaled
|
|
|
|
{
|
2020-03-29 08:48:39 -04:00
|
|
|
public static void Copy(
|
|
|
|
TextureCreateInfo srcInfo,
|
|
|
|
TextureCreateInfo dstInfo,
|
|
|
|
int srcHandle,
|
|
|
|
int dstHandle,
|
|
|
|
int srcLayer,
|
|
|
|
int dstLayer,
|
|
|
|
int srcLevel,
|
2020-10-29 17:57:34 -04:00
|
|
|
int dstLevel)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
2020-10-29 17:57:34 -04:00
|
|
|
int srcWidth = srcInfo.Width;
|
|
|
|
int srcHeight = srcInfo.Height;
|
2020-03-29 08:48:39 -04:00
|
|
|
int srcDepth = srcInfo.GetDepthOrLayers();
|
|
|
|
int srcLevels = srcInfo.Levels;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2020-10-29 17:57:34 -04:00
|
|
|
int dstWidth = dstInfo.Width;
|
|
|
|
int dstHeight = dstInfo.Height;
|
2020-03-29 08:48:39 -04:00
|
|
|
int dstDepth = dstInfo.GetDepthOrLayers();
|
|
|
|
int dstLevels = dstInfo.Levels;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2020-02-29 15:50:44 -05:00
|
|
|
dstWidth = Math.Max(1, dstWidth >> dstLevel);
|
|
|
|
dstHeight = Math.Max(1, dstHeight >> dstLevel);
|
|
|
|
|
2020-03-29 08:48:39 -04:00
|
|
|
if (dstInfo.Target == Target.Texture3D)
|
2020-02-29 15:50:44 -05:00
|
|
|
{
|
|
|
|
dstDepth = Math.Max(1, dstDepth >> dstLevel);
|
|
|
|
}
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
// When copying from a compressed to a non-compressed format,
|
|
|
|
// the non-compressed texture will have the size of the texture
|
|
|
|
// in blocks (not in texels), so we must adjust that size to
|
|
|
|
// match the size in texels of the compressed texture.
|
2020-03-29 08:48:39 -04:00
|
|
|
if (!srcInfo.IsCompressed && dstInfo.IsCompressed)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
2020-03-29 08:48:39 -04:00
|
|
|
dstWidth = BitUtils.DivRoundUp(dstWidth, dstInfo.BlockWidth);
|
|
|
|
dstHeight = BitUtils.DivRoundUp(dstHeight, dstInfo.BlockHeight);
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
2020-03-29 08:48:39 -04:00
|
|
|
else if (srcInfo.IsCompressed && !dstInfo.IsCompressed)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
2020-11-01 13:26:24 -05:00
|
|
|
dstWidth *= srcInfo.BlockWidth;
|
|
|
|
dstHeight *= srcInfo.BlockHeight;
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int width = Math.Min(srcWidth, dstWidth);
|
|
|
|
int height = Math.Min(srcHeight, dstHeight);
|
|
|
|
int depth = Math.Min(srcDepth, dstDepth);
|
|
|
|
int levels = Math.Min(srcLevels, dstLevels);
|
|
|
|
|
|
|
|
for (int level = 0; level < levels; level++)
|
|
|
|
{
|
|
|
|
// Stop copy if we are already out of the levels range.
|
2020-03-29 08:48:39 -04:00
|
|
|
if (level >= srcInfo.Levels || dstLevel + level >= dstInfo.Levels)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.CopyImageSubData(
|
2020-03-29 08:48:39 -04:00
|
|
|
srcHandle,
|
|
|
|
srcInfo.Target.ConvertToImageTarget(),
|
|
|
|
srcLevel + level,
|
2019-10-13 02:02:07 -04:00
|
|
|
0,
|
|
|
|
0,
|
2020-03-29 08:48:39 -04:00
|
|
|
srcLayer,
|
|
|
|
dstHandle,
|
|
|
|
dstInfo.Target.ConvertToImageTarget(),
|
2019-10-13 02:02:07 -04:00
|
|
|
dstLevel + level,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
dstLayer,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
depth);
|
|
|
|
|
2020-03-29 08:48:39 -04:00
|
|
|
width = Math.Max(1, width >> 1);
|
2019-10-13 02:02:07 -04:00
|
|
|
height = Math.Max(1, height >> 1);
|
|
|
|
|
2020-03-29 08:48:39 -04:00
|
|
|
if (srcInfo.Target == Target.Texture3D)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
|
|
|
depth = Math.Max(1, depth >> 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|