2018-04-08 21:17:35 +02:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
2018-09-08 19:51:50 +02:00
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-04-08 21:17:35 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
class OGLRenderTarget : IGalRenderTarget
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-04-14 05:39:24 +02:00
|
|
|
private struct Rect
|
|
|
|
{
|
|
|
|
public int X { get; private set; }
|
|
|
|
public int Y { get; private set; }
|
|
|
|
public int Width { get; private set; }
|
|
|
|
public int Height { get; private set; }
|
|
|
|
|
|
|
|
public Rect(int X, int Y, int Width, int Height)
|
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
this.X = X;
|
|
|
|
this.Y = Y;
|
|
|
|
this.Width = Width;
|
2018-04-14 05:39:24 +02:00
|
|
|
this.Height = Height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 16:21:05 +02:00
|
|
|
private const int NativeWidth = 1280;
|
|
|
|
private const int NativeHeight = 720;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
private const GalImageFormat RawFormat = GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private OGLTexture Texture;
|
2018-04-14 05:39:24 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private ImageHandler RawTex;
|
|
|
|
private ImageHandler ReadTex;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private Rect Viewport;
|
|
|
|
private Rect Window;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-07-23 16:21:05 +02:00
|
|
|
private bool FlipX;
|
|
|
|
private bool FlipY;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-07-23 16:21:05 +02:00
|
|
|
private int CropTop;
|
|
|
|
private int CropLeft;
|
|
|
|
private int CropRight;
|
|
|
|
private int CropBottom;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
//This framebuffer is used to attach guest rendertargets,
|
|
|
|
//think of it as a dummy OpenGL VAO
|
|
|
|
private int DummyFrameBuffer;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
//These framebuffers are used to blit images
|
|
|
|
private int SrcFb;
|
|
|
|
private int DstFb;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
//Holds current attachments, used to avoid unnecesary calls to OpenGL
|
|
|
|
private int[] ColorAttachments;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private int DepthAttachment;
|
|
|
|
private int StencilAttachment;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
public OGLRenderTarget(OGLTexture Texture)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
|
|
|
ColorAttachments = new int[8];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
this.Texture = Texture;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
public void BindColor(long Key, int Attachment)
|
|
|
|
{
|
|
|
|
if (Texture.TryGetImage(Key, out ImageHandler Tex))
|
|
|
|
{
|
|
|
|
EnsureFrameBuffer();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
Attach(ref ColorAttachments[Attachment], Tex.Handle, FramebufferAttachment.ColorAttachment0 + Attachment);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnbindColor(Attachment);
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
public void UnbindColor(int Attachment)
|
|
|
|
{
|
|
|
|
EnsureFrameBuffer();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
Attach(ref ColorAttachments[Attachment], 0, FramebufferAttachment.ColorAttachment0 + Attachment);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BindZeta(long Key)
|
|
|
|
{
|
|
|
|
if (Texture.TryGetImage(Key, out ImageHandler Tex))
|
|
|
|
{
|
|
|
|
EnsureFrameBuffer();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
if (Tex.HasDepth && Tex.HasStencil)
|
|
|
|
{
|
|
|
|
if (DepthAttachment != Tex.Handle ||
|
|
|
|
StencilAttachment != Tex.Handle)
|
|
|
|
{
|
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.DrawFramebuffer,
|
|
|
|
FramebufferAttachment.DepthStencilAttachment,
|
|
|
|
Tex.Handle,
|
|
|
|
0);
|
|
|
|
|
|
|
|
DepthAttachment = Tex.Handle;
|
|
|
|
|
|
|
|
StencilAttachment = Tex.Handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Tex.HasDepth)
|
|
|
|
{
|
|
|
|
Attach(ref DepthAttachment, Tex.Handle, FramebufferAttachment.DepthAttachment);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
Attach(ref StencilAttachment, 0, FramebufferAttachment.StencilAttachment);
|
|
|
|
}
|
|
|
|
else if (Tex.HasStencil)
|
|
|
|
{
|
|
|
|
Attach(ref DepthAttachment, 0, FramebufferAttachment.DepthAttachment);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
Attach(ref StencilAttachment, Tex.Handle, FramebufferAttachment.StencilAttachment);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnbindZeta();
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
public void UnbindZeta()
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
EnsureFrameBuffer();
|
|
|
|
|
|
|
|
if (DepthAttachment != 0 ||
|
|
|
|
StencilAttachment != 0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.DrawFramebuffer,
|
|
|
|
FramebufferAttachment.DepthStencilAttachment,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
|
|
|
|
DepthAttachment = 0;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
StencilAttachment = 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
public void BindTexture(long Key, int Index)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (Texture.TryGetImage(Key, out ImageHandler Tex))
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
|
|
|
GL.ActiveTexture(TextureUnit.Texture0 + Index);
|
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindTexture(TextureTarget.Texture2D, Tex.Handle);
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
public void Set(long Key)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (Texture.TryGetImage(Key, out ImageHandler Tex))
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
ReadTex = Tex;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-04-13 20:12:58 +02:00
|
|
|
public void Set(byte[] Data, int Width, int Height)
|
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (RawTex == null)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
RawTex = new ImageHandler();
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
RawTex.EnsureSetup(new GalImage(Width, Height, RawFormat));
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindTexture(TextureTarget.Texture2D, RawTex.Handle);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, Width, Height, RawTex.PixelFormat, RawTex.PixelType, Data);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
ReadTex = RawTex;
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 07:07:23 +02:00
|
|
|
public void SetMap(int[] Map)
|
|
|
|
{
|
|
|
|
if (Map != null && Map.Length > 0)
|
|
|
|
{
|
|
|
|
DrawBuffersEnum[] Mode = new DrawBuffersEnum[Map.Length];
|
|
|
|
|
|
|
|
for (int i = 0; i < Map.Length; i++)
|
|
|
|
{
|
|
|
|
Mode[i] = DrawBuffersEnum.ColorAttachment0 + Map[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.DrawBuffers(Mode.Length, Mode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 16:21:05 +02:00
|
|
|
public void SetTransform(bool FlipX, bool FlipY, int Top, int Left, int Right, int Bottom)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-07-23 16:21:05 +02:00
|
|
|
this.FlipX = FlipX;
|
|
|
|
this.FlipY = FlipY;
|
2018-06-24 02:39:25 +02:00
|
|
|
|
2018-07-23 16:21:05 +02:00
|
|
|
CropTop = Top;
|
|
|
|
CropLeft = Left;
|
|
|
|
CropRight = Right;
|
|
|
|
CropBottom = Bottom;
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 06:14:42 +02:00
|
|
|
public void SetWindowSize(int Width, int Height)
|
|
|
|
{
|
2018-04-14 06:31:27 +02:00
|
|
|
Window = new Rect(0, 0, Width, Height);
|
2018-04-14 06:14:42 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 05:39:24 +02:00
|
|
|
public void SetViewport(int X, int Y, int Width, int Height)
|
|
|
|
{
|
|
|
|
Viewport = new Rect(X, Y, Width, Height);
|
|
|
|
|
2018-07-19 07:30:21 +02:00
|
|
|
SetViewport(Viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetViewport(Rect Viewport)
|
|
|
|
{
|
|
|
|
GL.Viewport(
|
|
|
|
Viewport.X,
|
|
|
|
Viewport.Y,
|
|
|
|
Viewport.Width,
|
|
|
|
Viewport.Height);
|
2018-04-14 05:39:24 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 20:12:58 +02:00
|
|
|
public void Render()
|
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (ReadTex == null)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-07 04:40:12 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
int SrcX0, SrcX1, SrcY0, SrcY1;
|
2018-07-07 04:40:12 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
if (CropLeft == 0 && CropRight == 0)
|
|
|
|
{
|
|
|
|
SrcX0 = 0;
|
|
|
|
SrcX1 = ReadTex.Width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SrcX0 = CropLeft;
|
|
|
|
SrcX1 = CropRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CropTop == 0 && CropBottom == 0)
|
|
|
|
{
|
|
|
|
SrcY0 = 0;
|
|
|
|
SrcY1 = ReadTex.Height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SrcY0 = CropTop;
|
|
|
|
SrcY1 = CropBottom;
|
|
|
|
}
|
2018-07-07 04:40:12 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
float RatioX = MathF.Min(1f, (Window.Height * (float)NativeWidth) / ((float)NativeHeight * Window.Width));
|
|
|
|
float RatioY = MathF.Min(1f, (Window.Width * (float)NativeHeight) / ((float)NativeWidth * Window.Height));
|
2018-04-14 03:42:55 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
int DstWidth = (int)(Window.Width * RatioX);
|
|
|
|
int DstHeight = (int)(Window.Height * RatioY);
|
2018-04-14 03:42:55 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
int DstPaddingX = (Window.Width - DstWidth) / 2;
|
|
|
|
int DstPaddingY = (Window.Height - DstHeight) / 2;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
int DstX0 = FlipX ? Window.Width - DstPaddingX : DstPaddingX;
|
|
|
|
int DstX1 = FlipX ? DstPaddingX : Window.Width - DstPaddingX;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
int DstY0 = FlipY ? DstPaddingY : Window.Height - DstPaddingY;
|
|
|
|
int DstY1 = FlipY ? Window.Height - DstPaddingY : DstPaddingY;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
if (SrcFb == 0) SrcFb = GL.GenFramebuffer();
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.Viewport(0, 0, Window.Width, Window.Height);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, SrcFb);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.FramebufferTexture(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, ReadTex.Handle, 0);
|
|
|
|
|
|
|
|
GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
|
|
|
|
GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
|
|
|
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
|
|
|
|
GL.BlitFramebuffer(
|
|
|
|
SrcX0, SrcY0, SrcX1, SrcY1,
|
|
|
|
DstX0, DstY0, DstX1, DstY1,
|
|
|
|
ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear);
|
|
|
|
|
|
|
|
EnsureFrameBuffer();
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-07-19 07:30:21 +02:00
|
|
|
public void Copy(
|
|
|
|
long SrcKey,
|
|
|
|
long DstKey,
|
|
|
|
int SrcX0,
|
|
|
|
int SrcY0,
|
|
|
|
int SrcX1,
|
|
|
|
int SrcY1,
|
|
|
|
int DstX0,
|
|
|
|
int DstY0,
|
|
|
|
int DstX1,
|
|
|
|
int DstY1)
|
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (Texture.TryGetImage(SrcKey, out ImageHandler SrcTex) &&
|
|
|
|
Texture.TryGetImage(DstKey, out ImageHandler DstTex))
|
2018-07-19 07:30:21 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (SrcTex.HasColor != DstTex.HasColor ||
|
|
|
|
SrcTex.HasDepth != DstTex.HasDepth ||
|
|
|
|
SrcTex.HasStencil != DstTex.HasStencil)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
if (SrcTex.HasColor)
|
|
|
|
{
|
|
|
|
CopyTextures(
|
|
|
|
SrcX0, SrcY0, SrcX1, SrcY1,
|
|
|
|
DstX0, DstY0, DstX1, DstY1,
|
|
|
|
SrcTex.Handle,
|
|
|
|
DstTex.Handle,
|
|
|
|
FramebufferAttachment.ColorAttachment0,
|
|
|
|
ClearBufferMask.ColorBufferBit,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
else if (SrcTex.HasDepth && SrcTex.HasStencil)
|
|
|
|
{
|
|
|
|
CopyTextures(
|
|
|
|
SrcX0, SrcY0, SrcX1, SrcY1,
|
|
|
|
DstX0, DstY0, DstX1, DstY1,
|
|
|
|
SrcTex.Handle,
|
|
|
|
DstTex.Handle,
|
|
|
|
FramebufferAttachment.DepthStencilAttachment,
|
|
|
|
ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
else if (SrcTex.HasDepth)
|
|
|
|
{
|
|
|
|
CopyTextures(
|
|
|
|
SrcX0, SrcY0, SrcX1, SrcY1,
|
|
|
|
DstX0, DstY0, DstX1, DstY1,
|
|
|
|
SrcTex.Handle,
|
|
|
|
DstTex.Handle,
|
|
|
|
FramebufferAttachment.DepthAttachment,
|
|
|
|
ClearBufferMask.DepthBufferBit,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
else if (SrcTex.HasStencil)
|
|
|
|
{
|
|
|
|
CopyTextures(
|
|
|
|
SrcX0, SrcY0, SrcX1, SrcY1,
|
|
|
|
DstX0, DstY0, DstX1, DstY1,
|
|
|
|
SrcTex.Handle,
|
|
|
|
DstTex.Handle,
|
|
|
|
FramebufferAttachment.StencilAttachment,
|
|
|
|
ClearBufferMask.StencilBufferBit,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
}
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
public void GetBufferData(long Key, Action<byte[]> Callback)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (Texture.TryGetImage(Key, out ImageHandler Tex))
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
byte[] Data = new byte[ImageUtils.GetSize(Tex.Image)];
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindTexture(TextureTarget.Texture2D, Tex.Handle);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.GetTexImage(
|
|
|
|
TextureTarget.Texture2D,
|
2018-04-26 04:11:26 +02:00
|
|
|
0,
|
2018-08-20 03:25:26 +02:00
|
|
|
Tex.PixelFormat,
|
|
|
|
Tex.PixelType,
|
2018-04-26 04:11:26 +02:00
|
|
|
Data);
|
|
|
|
|
|
|
|
Callback(Data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 07:30:21 +02:00
|
|
|
public void SetBufferData(
|
|
|
|
long Key,
|
|
|
|
int Width,
|
|
|
|
int Height,
|
|
|
|
byte[] Buffer)
|
2018-04-14 05:39:24 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (Texture.TryGetImage(Key, out ImageHandler Tex))
|
2018-07-19 07:30:21 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindTexture(TextureTarget.Texture2D, Tex.Handle);
|
2018-07-19 07:30:21 +02:00
|
|
|
|
|
|
|
const int Level = 0;
|
|
|
|
const int Border = 0;
|
|
|
|
|
|
|
|
GL.TexImage2D(
|
|
|
|
TextureTarget.Texture2D,
|
|
|
|
Level,
|
2018-08-20 03:25:26 +02:00
|
|
|
Tex.InternalFormat,
|
2018-07-19 07:30:21 +02:00
|
|
|
Width,
|
|
|
|
Height,
|
|
|
|
Border,
|
2018-08-20 03:25:26 +02:00
|
|
|
Tex.PixelFormat,
|
|
|
|
Tex.PixelType,
|
2018-07-19 07:30:21 +02:00
|
|
|
Buffer);
|
|
|
|
}
|
2018-04-14 05:39:24 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private void EnsureFrameBuffer()
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (DummyFrameBuffer == 0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
DummyFrameBuffer = GL.GenFramebuffer();
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, DummyFrameBuffer);
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private void Attach(ref int OldHandle, int NewHandle, FramebufferAttachment FbAttachment)
|
|
|
|
{
|
|
|
|
if (OldHandle != NewHandle)
|
|
|
|
{
|
2018-07-23 16:21:05 +02:00
|
|
|
GL.FramebufferTexture(
|
2018-08-20 03:25:26 +02:00
|
|
|
FramebufferTarget.DrawFramebuffer,
|
|
|
|
FbAttachment,
|
|
|
|
NewHandle,
|
2018-07-23 16:21:05 +02:00
|
|
|
0);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
OldHandle = NewHandle;
|
2018-07-23 16:21:05 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
private void CopyTextures(
|
|
|
|
int SrcX0,
|
|
|
|
int SrcY0,
|
|
|
|
int SrcX1,
|
|
|
|
int SrcY1,
|
|
|
|
int DstX0,
|
|
|
|
int DstY0,
|
|
|
|
int DstX1,
|
|
|
|
int DstY1,
|
|
|
|
int SrcTexture,
|
|
|
|
int DstTexture,
|
|
|
|
FramebufferAttachment Attachment,
|
|
|
|
ClearBufferMask Mask,
|
|
|
|
bool Color)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
if (SrcFb == 0) SrcFb = GL.GenFramebuffer();
|
|
|
|
if (DstFb == 0) DstFb = GL.GenFramebuffer();
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, SrcFb);
|
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, DstFb);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.ReadFramebuffer,
|
|
|
|
Attachment,
|
|
|
|
SrcTexture,
|
|
|
|
0);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.DrawFramebuffer,
|
|
|
|
Attachment,
|
|
|
|
DstTexture,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (Color)
|
|
|
|
{
|
|
|
|
GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
|
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.Clear(Mask);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BlitFramebuffer(
|
|
|
|
SrcX0, SrcY0, SrcX1, SrcY1,
|
|
|
|
DstX0, DstY0, DstX1, DstY1,
|
|
|
|
Mask,
|
|
|
|
Color ? BlitFramebufferFilter.Linear : BlitFramebufferFilter.Nearest);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
EnsureFrameBuffer();
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|