2019-10-13 08:02:07 +02:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
2020-11-20 17:30:59 +01:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.Graphics.GAL;
|
2019-12-31 23:09:49 +01:00
|
|
|
using System;
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2020-05-23 11:46:09 +02:00
|
|
|
namespace Ryujinx.Graphics.OpenGL.Image
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2019-12-31 23:09:49 +01:00
|
|
|
class TextureCopy : IDisposable
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2020-03-29 05:02:58 +02:00
|
|
|
private readonly Renderer _renderer;
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
private int _srcFramebuffer;
|
|
|
|
private int _dstFramebuffer;
|
|
|
|
|
2020-07-26 05:03:40 +02:00
|
|
|
private int _copyPboHandle;
|
|
|
|
private int _copyPboSize;
|
|
|
|
|
2020-03-29 05:02:58 +02:00
|
|
|
public TextureCopy(Renderer renderer)
|
|
|
|
{
|
|
|
|
_renderer = renderer;
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
public void Copy(
|
|
|
|
TextureView src,
|
|
|
|
TextureView dst,
|
|
|
|
Extents2D srcRegion,
|
|
|
|
Extents2D dstRegion,
|
|
|
|
bool linearFilter)
|
|
|
|
{
|
2021-08-20 23:26:25 +02:00
|
|
|
TextureView srcConverted = src.Format.IsBgr() != dst.Format.IsBgr() ? BgraSwap(src) : src;
|
2020-07-26 05:03:40 +02:00
|
|
|
|
2020-05-24 15:44:12 +02:00
|
|
|
(int oldDrawFramebufferHandle, int oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers();
|
2019-10-13 08:02:07 +02:00
|
|
|
|
|
|
|
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetSrcFramebufferLazy());
|
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, GetDstFramebufferLazy());
|
|
|
|
|
2020-11-20 21:14:45 +01:00
|
|
|
int levels = Math.Min(src.Info.Levels, dst.Info.Levels);
|
|
|
|
int layers = Math.Min(src.Info.GetLayers(), dst.Info.GetLayers());
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2020-11-20 21:14:45 +01:00
|
|
|
for (int level = 0; level < levels; level++)
|
2020-07-07 04:41:07 +02:00
|
|
|
{
|
2020-11-20 21:14:45 +01:00
|
|
|
for (int layer = 0; layer < layers; layer++)
|
|
|
|
{
|
|
|
|
if (layers > 1)
|
|
|
|
{
|
|
|
|
Attach(FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, level, layer);
|
|
|
|
Attach(FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, level, layer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Attach(FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, level);
|
|
|
|
Attach(FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearBufferMask mask = GetMask(src.Format);
|
|
|
|
|
|
|
|
if ((mask & (ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit)) != 0 || src.Format.IsInteger())
|
|
|
|
{
|
|
|
|
linearFilter = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlitFramebufferFilter filter = linearFilter
|
|
|
|
? BlitFramebufferFilter.Linear
|
|
|
|
: BlitFramebufferFilter.Nearest;
|
|
|
|
|
|
|
|
GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
|
|
|
|
GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
|
|
|
|
|
|
|
|
GL.Disable(EnableCap.RasterizerDiscard);
|
|
|
|
GL.Disable(IndexedEnableCap.ScissorTest, 0);
|
|
|
|
|
|
|
|
GL.BlitFramebuffer(
|
|
|
|
srcRegion.X1,
|
|
|
|
srcRegion.Y1,
|
|
|
|
srcRegion.X2,
|
|
|
|
srcRegion.Y2,
|
|
|
|
dstRegion.X1,
|
|
|
|
dstRegion.Y1,
|
|
|
|
dstRegion.X2,
|
|
|
|
dstRegion.Y2,
|
|
|
|
mask,
|
|
|
|
filter);
|
|
|
|
}
|
2020-03-29 05:02:58 +02:00
|
|
|
|
2020-11-20 21:14:45 +01:00
|
|
|
if (level < levels - 1)
|
|
|
|
{
|
|
|
|
srcRegion = srcRegion.Reduce(1);
|
|
|
|
dstRegion = dstRegion.Reduce(1);
|
|
|
|
}
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2020-07-07 04:41:07 +02:00
|
|
|
Attach(FramebufferTarget.ReadFramebuffer, src.Format, 0);
|
|
|
|
Attach(FramebufferTarget.DrawFramebuffer, dst.Format, 0);
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle);
|
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle);
|
2020-03-29 05:02:58 +02:00
|
|
|
|
2020-04-07 11:19:45 +02:00
|
|
|
((Pipeline)_renderer.Pipeline).RestoreScissor0Enable();
|
|
|
|
((Pipeline)_renderer.Pipeline).RestoreRasterizerDiscard();
|
2020-07-26 05:03:40 +02:00
|
|
|
|
|
|
|
if (srcConverted != src)
|
|
|
|
{
|
|
|
|
srcConverted.Dispose();
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
|
2020-11-20 17:30:59 +01:00
|
|
|
public void CopyUnscaled(
|
|
|
|
ITextureInfo src,
|
|
|
|
ITextureInfo dst,
|
|
|
|
int srcLayer,
|
|
|
|
int dstLayer,
|
|
|
|
int srcLevel,
|
|
|
|
int dstLevel)
|
|
|
|
{
|
|
|
|
TextureCreateInfo srcInfo = src.Info;
|
|
|
|
TextureCreateInfo dstInfo = dst.Info;
|
|
|
|
|
2021-03-02 23:30:54 +01:00
|
|
|
int srcDepth = srcInfo.GetDepthOrLayers();
|
|
|
|
int srcLevels = srcInfo.Levels;
|
|
|
|
|
|
|
|
int dstDepth = dstInfo.GetDepthOrLayers();
|
|
|
|
int dstLevels = dstInfo.Levels;
|
|
|
|
|
|
|
|
if (dstInfo.Target == Target.Texture3D)
|
|
|
|
{
|
|
|
|
dstDepth = Math.Max(1, dstDepth >> dstLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
int depth = Math.Min(srcDepth, dstDepth);
|
|
|
|
int levels = Math.Min(srcLevels, dstLevels);
|
|
|
|
|
|
|
|
CopyUnscaled(src, dst, srcLayer, dstLayer, srcLevel, dstLevel, depth, levels);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CopyUnscaled(
|
|
|
|
ITextureInfo src,
|
|
|
|
ITextureInfo dst,
|
|
|
|
int srcLayer,
|
|
|
|
int dstLayer,
|
|
|
|
int srcLevel,
|
|
|
|
int dstLevel,
|
|
|
|
int depth,
|
|
|
|
int levels)
|
|
|
|
{
|
|
|
|
TextureCreateInfo srcInfo = src.Info;
|
|
|
|
TextureCreateInfo dstInfo = dst.Info;
|
|
|
|
|
2020-11-20 17:30:59 +01:00
|
|
|
int srcHandle = src.Handle;
|
|
|
|
int dstHandle = dst.Handle;
|
|
|
|
|
|
|
|
int srcWidth = srcInfo.Width;
|
|
|
|
int srcHeight = srcInfo.Height;
|
|
|
|
|
|
|
|
int dstWidth = dstInfo.Width;
|
|
|
|
int dstHeight = dstInfo.Height;
|
|
|
|
|
|
|
|
srcWidth = Math.Max(1, srcWidth >> srcLevel);
|
|
|
|
srcHeight = Math.Max(1, srcHeight >> srcLevel);
|
|
|
|
|
|
|
|
dstWidth = Math.Max(1, dstWidth >> dstLevel);
|
|
|
|
dstHeight = Math.Max(1, dstHeight >> dstLevel);
|
|
|
|
|
|
|
|
int blockWidth = 1;
|
|
|
|
int blockHeight = 1;
|
|
|
|
bool sizeInBlocks = false;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
srcWidth *= dstInfo.BlockWidth;
|
|
|
|
srcHeight *= dstInfo.BlockHeight;
|
|
|
|
blockWidth = dstInfo.BlockWidth;
|
|
|
|
blockHeight = dstInfo.BlockHeight;
|
|
|
|
|
|
|
|
sizeInBlocks = true;
|
|
|
|
}
|
|
|
|
else if (srcInfo.IsCompressed && !dstInfo.IsCompressed)
|
|
|
|
{
|
|
|
|
dstWidth *= srcInfo.BlockWidth;
|
|
|
|
dstHeight *= srcInfo.BlockHeight;
|
|
|
|
blockWidth = srcInfo.BlockWidth;
|
|
|
|
blockHeight = srcInfo.BlockHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = Math.Min(srcWidth, dstWidth);
|
|
|
|
int height = Math.Min(srcHeight, dstHeight);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((width % blockWidth != 0 || height % blockHeight != 0) && src is TextureView srcView && dst is TextureView dstView)
|
|
|
|
{
|
|
|
|
PboCopy(srcView, dstView, srcLayer, dstLayer, srcLevel + level, dstLevel + level, width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int copyWidth = sizeInBlocks ? BitUtils.DivRoundUp(width, blockWidth) : width;
|
|
|
|
int copyHeight = sizeInBlocks ? BitUtils.DivRoundUp(height, blockHeight) : height;
|
|
|
|
|
2021-04-18 02:27:19 +02:00
|
|
|
if (HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows)
|
2021-04-13 03:09:42 +02:00
|
|
|
{
|
|
|
|
GL.CopyImageSubData(
|
2021-04-17 22:16:28 +02:00
|
|
|
src.Storage.Handle,
|
|
|
|
src.Storage.Info.Target.ConvertToImageTarget(),
|
2021-04-13 03:09:42 +02:00
|
|
|
src.FirstLevel + srcLevel + level,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
src.FirstLayer + srcLayer,
|
2021-04-17 22:16:28 +02:00
|
|
|
dst.Storage.Handle,
|
|
|
|
dst.Storage.Info.Target.ConvertToImageTarget(),
|
2021-04-13 03:09:42 +02:00
|
|
|
dst.FirstLevel + dstLevel + level,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
dst.FirstLayer + dstLayer,
|
|
|
|
copyWidth,
|
|
|
|
copyHeight,
|
|
|
|
depth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL.CopyImageSubData(
|
|
|
|
srcHandle,
|
|
|
|
srcInfo.Target.ConvertToImageTarget(),
|
|
|
|
srcLevel + level,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
srcLayer,
|
|
|
|
dstHandle,
|
|
|
|
dstInfo.Target.ConvertToImageTarget(),
|
|
|
|
dstLevel + level,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
dstLayer,
|
|
|
|
copyWidth,
|
|
|
|
copyHeight,
|
|
|
|
depth);
|
|
|
|
}
|
2020-11-20 17:30:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
width = Math.Max(1, width >> 1);
|
|
|
|
height = Math.Max(1, height >> 1);
|
|
|
|
|
|
|
|
if (srcInfo.Target == Target.Texture3D)
|
|
|
|
{
|
|
|
|
depth = Math.Max(1, depth >> 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:14:45 +01:00
|
|
|
private static FramebufferAttachment AttachmentForFormat(Format format)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
if (format == Format.D24UnormS8Uint || format == Format.D32FloatS8Uint)
|
|
|
|
{
|
2020-11-20 21:14:45 +01:00
|
|
|
return FramebufferAttachment.DepthStencilAttachment;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
else if (IsDepthOnly(format))
|
|
|
|
{
|
2020-11-20 21:14:45 +01:00
|
|
|
return FramebufferAttachment.DepthAttachment;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
else if (format == Format.S8Uint)
|
|
|
|
{
|
2020-11-20 21:14:45 +01:00
|
|
|
return FramebufferAttachment.StencilAttachment;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-20 21:14:45 +01:00
|
|
|
return FramebufferAttachment.ColorAttachment0;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:14:45 +01:00
|
|
|
private static void Attach(FramebufferTarget target, Format format, int handle, int level = 0)
|
|
|
|
{
|
|
|
|
FramebufferAttachment attachment = AttachmentForFormat(format);
|
|
|
|
|
|
|
|
GL.FramebufferTexture(target, attachment, handle, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void Attach(FramebufferTarget target, Format format, int handle, int level, int layer)
|
|
|
|
{
|
|
|
|
FramebufferAttachment attachment = AttachmentForFormat(format);
|
|
|
|
|
|
|
|
GL.FramebufferTextureLayer(target, attachment, handle, level, layer);
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
private static ClearBufferMask GetMask(Format format)
|
|
|
|
{
|
2022-03-15 03:42:08 +01:00
|
|
|
if (format == Format.D24UnormS8Uint || format == Format.D32FloatS8Uint || format == Format.S8UintD24Unorm)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit;
|
|
|
|
}
|
|
|
|
else if (IsDepthOnly(format))
|
|
|
|
{
|
|
|
|
return ClearBufferMask.DepthBufferBit;
|
|
|
|
}
|
|
|
|
else if (format == Format.S8Uint)
|
|
|
|
{
|
|
|
|
return ClearBufferMask.StencilBufferBit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ClearBufferMask.ColorBufferBit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsDepthOnly(Format format)
|
|
|
|
{
|
2022-03-15 03:42:08 +01:00
|
|
|
return format == Format.D16Unorm || format == Format.D32Float;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
|
2020-07-26 05:03:40 +02:00
|
|
|
public TextureView BgraSwap(TextureView from)
|
|
|
|
{
|
2020-10-29 22:57:34 +01:00
|
|
|
TextureView to = (TextureView)_renderer.CreateTexture(from.Info, from.ScaleFactor);
|
2020-07-26 05:03:40 +02:00
|
|
|
|
|
|
|
EnsurePbo(from);
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle);
|
|
|
|
|
|
|
|
from.WriteToPbo(0, forceBgra: true);
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelPackBuffer, 0);
|
|
|
|
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, _copyPboHandle);
|
|
|
|
|
|
|
|
to.ReadFromPbo(0, _copyPboSize);
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
|
|
|
|
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
2020-11-20 17:30:59 +01:00
|
|
|
private TextureView PboCopy(TextureView from, TextureView to, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int width, int height)
|
|
|
|
{
|
|
|
|
int dstWidth = width;
|
|
|
|
int dstHeight = height;
|
|
|
|
|
|
|
|
// The size of the source texture.
|
|
|
|
int unpackWidth = from.Width;
|
|
|
|
int unpackHeight = from.Height;
|
|
|
|
|
|
|
|
if (from.Info.IsCompressed != to.Info.IsCompressed)
|
|
|
|
{
|
|
|
|
if (from.Info.IsCompressed)
|
|
|
|
{
|
|
|
|
// Dest size is in pixels, but should be in blocks
|
|
|
|
dstWidth = BitUtils.DivRoundUp(width, from.Info.BlockWidth);
|
|
|
|
dstHeight = BitUtils.DivRoundUp(height, from.Info.BlockHeight);
|
|
|
|
|
|
|
|
// When copying from a compressed texture, the source size must be taken in blocks for unpacking to the uncompressed block texture.
|
|
|
|
unpackWidth = BitUtils.DivRoundUp(from.Info.Width, from.Info.BlockWidth);
|
|
|
|
unpackHeight = BitUtils.DivRoundUp(from.Info.Height, from.Info.BlockHeight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// When copying to a compressed texture, the source size must be scaled by the block width for unpacking on the compressed target.
|
|
|
|
unpackWidth = from.Info.Width * to.Info.BlockWidth;
|
|
|
|
unpackHeight = from.Info.Height * to.Info.BlockHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsurePbo(from);
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle);
|
|
|
|
|
|
|
|
// The source texture is written out in full, then the destination is taken as a slice from the data using unpack params.
|
|
|
|
// The offset points to the base at which the requested layer is at.
|
|
|
|
|
|
|
|
int offset = from.WriteToPbo2D(0, srcLayer, srcLevel);
|
|
|
|
|
|
|
|
// If the destination size is not an exact match for the source unpack parameters, we need to set them to slice the data correctly.
|
|
|
|
|
|
|
|
bool slice = (unpackWidth != dstWidth || unpackHeight != dstHeight);
|
|
|
|
|
|
|
|
if (slice)
|
|
|
|
{
|
|
|
|
// Set unpack parameters to take a slice of width/height:
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackRowLength, unpackWidth);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackImageHeight, unpackHeight);
|
|
|
|
|
|
|
|
if (to.Info.IsCompressed)
|
|
|
|
{
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockWidth, to.Info.BlockWidth);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockHeight, to.Info.BlockHeight);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockDepth, 1);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockSize, to.Info.BytesPerPixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelPackBuffer, 0);
|
|
|
|
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, _copyPboHandle);
|
|
|
|
|
|
|
|
to.ReadFromPbo2D(offset, dstLayer, dstLevel, dstWidth, dstHeight);
|
|
|
|
|
|
|
|
if (slice)
|
|
|
|
{
|
|
|
|
// Reset unpack parameters
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackImageHeight, 0);
|
|
|
|
|
|
|
|
if (to.Info.IsCompressed)
|
|
|
|
{
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockWidth, 0);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockHeight, 0);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockDepth, 0);
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockSize, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
|
|
|
|
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
2020-07-26 05:03:40 +02:00
|
|
|
private void EnsurePbo(TextureView view)
|
|
|
|
{
|
|
|
|
int requiredSize = 0;
|
|
|
|
|
|
|
|
for (int level = 0; level < view.Info.Levels; level++)
|
|
|
|
{
|
|
|
|
requiredSize += view.Info.GetMipSize(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_copyPboSize < requiredSize && _copyPboHandle != 0)
|
|
|
|
{
|
|
|
|
GL.DeleteBuffer(_copyPboHandle);
|
|
|
|
|
|
|
|
_copyPboHandle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_copyPboHandle == 0)
|
|
|
|
{
|
|
|
|
_copyPboHandle = GL.GenBuffer();
|
|
|
|
_copyPboSize = requiredSize;
|
|
|
|
|
|
|
|
GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle);
|
|
|
|
GL.BufferData(BufferTarget.PixelPackBuffer, requiredSize, IntPtr.Zero, BufferUsageHint.DynamicCopy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
private int GetSrcFramebufferLazy()
|
|
|
|
{
|
|
|
|
if (_srcFramebuffer == 0)
|
|
|
|
{
|
|
|
|
_srcFramebuffer = GL.GenFramebuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _srcFramebuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int GetDstFramebufferLazy()
|
|
|
|
{
|
|
|
|
if (_dstFramebuffer == 0)
|
|
|
|
{
|
|
|
|
_dstFramebuffer = GL.GenFramebuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _dstFramebuffer;
|
|
|
|
}
|
2019-12-31 23:09:49 +01:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (_srcFramebuffer != 0)
|
|
|
|
{
|
|
|
|
GL.DeleteFramebuffer(_srcFramebuffer);
|
|
|
|
|
|
|
|
_srcFramebuffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_dstFramebuffer != 0)
|
|
|
|
{
|
|
|
|
GL.DeleteFramebuffer(_dstFramebuffer);
|
|
|
|
|
|
|
|
_dstFramebuffer = 0;
|
|
|
|
}
|
2020-07-26 05:03:40 +02:00
|
|
|
|
|
|
|
if (_copyPboHandle != 0)
|
|
|
|
{
|
|
|
|
GL.DeleteBuffer(_copyPboHandle);
|
|
|
|
|
|
|
|
_copyPboHandle = 0;
|
|
|
|
}
|
2019-12-31 23:09:49 +01:00
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
}
|