1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-20 04:26:39 +00:00
Ryujinx/Ryujinx.Graphics.OpenGL/Image/TextureCopyUnscaled.cs

95 lines
3.2 KiB
C#
Raw Normal View History

2019-10-13 07:02:07 +01:00
using OpenTK.Graphics.OpenGL;
2019-12-29 17:41:50 +00:00
using Ryujinx.Common;
using Ryujinx.Graphics.GAL;
2019-10-13 07:02:07 +01:00
using System;
namespace Ryujinx.Graphics.OpenGL.Image
2019-10-13 07:02:07 +01:00
{
static class TextureCopyUnscaled
{
public static void Copy(
TextureCreateInfo srcInfo,
TextureCreateInfo dstInfo,
int srcHandle,
int dstHandle,
int srcLayer,
int dstLayer,
int srcLevel,
int dstLevel,
float scaleFactor = 1f)
2019-10-13 07:02:07 +01:00
{
int srcWidth = (int)Math.Ceiling(srcInfo.Width * scaleFactor);
int srcHeight = (int)Math.Ceiling(srcInfo.Height * scaleFactor);
int srcDepth = srcInfo.GetDepthOrLayers();
int srcLevels = srcInfo.Levels;
2019-10-13 07:02:07 +01:00
int dstWidth = (int)Math.Ceiling(dstInfo.Width * scaleFactor);
int dstHeight = (int)Math.Ceiling(dstInfo.Height * scaleFactor);
int dstDepth = dstInfo.GetDepthOrLayers();
int dstLevels = dstInfo.Levels;
2019-10-13 07:02:07 +01:00
dstWidth = Math.Max(1, dstWidth >> dstLevel);
dstHeight = Math.Max(1, dstHeight >> dstLevel);
if (dstInfo.Target == Target.Texture3D)
{
dstDepth = Math.Max(1, dstDepth >> dstLevel);
}
2019-10-13 07:02:07 +01: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.
if (!srcInfo.IsCompressed && dstInfo.IsCompressed)
2019-10-13 07:02:07 +01:00
{
dstWidth = BitUtils.DivRoundUp(dstWidth, dstInfo.BlockWidth);
dstHeight = BitUtils.DivRoundUp(dstHeight, dstInfo.BlockHeight);
2019-10-13 07:02:07 +01:00
}
else if (srcInfo.IsCompressed && !dstInfo.IsCompressed)
2019-10-13 07:02:07 +01:00
{
dstWidth *= dstInfo.BlockWidth;
dstHeight *= dstInfo.BlockHeight;
2019-10-13 07:02:07 +01: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.
if (level >= srcInfo.Levels || dstLevel + level >= dstInfo.Levels)
2019-10-13 07:02:07 +01:00
{
break;
}
GL.CopyImageSubData(
srcHandle,
srcInfo.Target.ConvertToImageTarget(),
srcLevel + level,
2019-10-13 07:02:07 +01:00
0,
0,
srcLayer,
dstHandle,
dstInfo.Target.ConvertToImageTarget(),
2019-10-13 07:02:07 +01:00
dstLevel + level,
0,
0,
dstLayer,
width,
height,
depth);
width = Math.Max(1, width >> 1);
2019-10-13 07:02:07 +01:00
height = Math.Max(1, height >> 1);
if (srcInfo.Target == Target.Texture3D)
2019-10-13 07:02:07 +01:00
{
depth = Math.Max(1, depth >> 1);
}
}
}
}
}