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-09-18 06:30:35 +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 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-09-18 06:30:35 +02:00
|
|
|
public void BindColor(long Key, int Attachment, GalImage Image)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (Texture.TryGetImageHandler(Key, out ImageHandler CachedImage))
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
|
|
|
EnsureFrameBuffer();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
Attach(ref ColorAttachments[Attachment], CachedImage.Handle, FramebufferAttachment.ColorAttachment0 + Attachment);
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
|
|
|
|
public void BindZeta(long Key, GalImage Image)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (Texture.TryGetImageHandler(Key, out ImageHandler CachedImage))
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
|
|
|
EnsureFrameBuffer();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
if (CachedImage.HasDepth && CachedImage.HasStencil)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (DepthAttachment != CachedImage.Handle ||
|
|
|
|
StencilAttachment != CachedImage.Handle)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.DrawFramebuffer,
|
|
|
|
FramebufferAttachment.DepthStencilAttachment,
|
2018-09-18 06:30:35 +02:00
|
|
|
CachedImage.Handle,
|
2018-08-20 03:25:26 +02:00
|
|
|
0);
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
DepthAttachment = CachedImage.Handle;
|
|
|
|
StencilAttachment = CachedImage.Handle;
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
else if (CachedImage.HasDepth)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
Attach(ref DepthAttachment, CachedImage.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);
|
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
else if (CachedImage.HasStencil)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
|
|
|
Attach(ref DepthAttachment, 0, FramebufferAttachment.DepthAttachment);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
Attach(ref StencilAttachment, CachedImage.Handle, FramebufferAttachment.StencilAttachment);
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnbindZeta();
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
private void Attach(ref int OldHandle, int NewHandle, FramebufferAttachment FbAttachment)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (OldHandle != NewHandle)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.DrawFramebuffer,
|
2018-09-18 06:30:35 +02:00
|
|
|
FbAttachment,
|
|
|
|
NewHandle,
|
2018-08-20 03:25:26 +02:00
|
|
|
0);
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
OldHandle = NewHandle;
|
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-09-18 06:30:35 +02:00
|
|
|
public void UnbindZeta()
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
EnsureFrameBuffer();
|
|
|
|
|
|
|
|
if (DepthAttachment != 0 || StencilAttachment != 0)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
GL.FramebufferTexture(
|
|
|
|
FramebufferTarget.DrawFramebuffer,
|
|
|
|
FramebufferAttachment.DepthStencilAttachment,
|
|
|
|
0,
|
|
|
|
0);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
DepthAttachment = 0;
|
|
|
|
StencilAttachment = 0;
|
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-09-18 06:30:35 +02:00
|
|
|
Texture.TryGetImageHandler(Key, out ReadTex);
|
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
|
|
|
GL.Viewport(0, 0, Window.Width, Window.Height);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
if (SrcFb == 0)
|
|
|
|
{
|
|
|
|
SrcFb = GL.GenFramebuffer();
|
|
|
|
}
|
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, SrcFb);
|
2018-09-18 06:30:35 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);
|
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,
|
2018-09-18 06:30:35 +02:00
|
|
|
ClearBufferMask.ColorBufferBit,
|
|
|
|
BlitFramebufferFilter.Linear);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
|
|
|
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-09-18 06:30:35 +02:00
|
|
|
if (Texture.TryGetImageHandler(SrcKey, out ImageHandler SrcTex) &&
|
|
|
|
Texture.TryGetImageHandler(DstKey, out ImageHandler DstTex))
|
2018-07-19 07:30:21 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (SrcTex.HasColor != DstTex.HasColor ||
|
|
|
|
SrcTex.HasDepth != DstTex.HasDepth ||
|
2018-08-20 03:25:26 +02:00
|
|
|
SrcTex.HasStencil != DstTex.HasStencil)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
if (SrcFb == 0)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
SrcFb = GL.GenFramebuffer();
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
|
|
|
|
if (DstFb == 0)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
DstFb = GL.GenFramebuffer();
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
|
|
|
|
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, SrcFb);
|
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, DstFb);
|
|
|
|
|
|
|
|
FramebufferAttachment Attachment = GetAttachment(SrcTex);
|
|
|
|
|
|
|
|
GL.FramebufferTexture(FramebufferTarget.ReadFramebuffer, Attachment, SrcTex.Handle, 0);
|
|
|
|
GL.FramebufferTexture(FramebufferTarget.DrawFramebuffer, Attachment, DstTex.Handle, 0);
|
|
|
|
|
|
|
|
BlitFramebufferFilter Filter = BlitFramebufferFilter.Nearest;
|
|
|
|
|
|
|
|
if (SrcTex.HasColor)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
|
|
|
|
|
|
|
|
Filter = BlitFramebufferFilter.Linear;
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
ClearBufferMask Mask = GetClearMask(SrcTex);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GL.Clear(Mask);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GL.BlitFramebuffer(SrcX0, SrcY0, SrcX1, SrcY1, DstX0, DstY0, DstX1, DstY1, Mask, Filter);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
EnsureFrameBuffer();
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public void Reinterpret(long Key, GalImage NewImage)
|
2018-04-14 05:39:24 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (!Texture.TryGetImage(Key, out GalImage OldImage))
|
2018-07-19 07:30:21 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
return;
|
2018-07-19 07:30:21 +02:00
|
|
|
}
|
2018-04-14 05:39:24 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
if (NewImage.Format == OldImage.Format)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
return;
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
byte[] Data = GetData(Key);
|
|
|
|
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackRowLength, OldImage.Width);
|
|
|
|
|
|
|
|
Texture.Create(Key, Data, NewImage);
|
|
|
|
|
|
|
|
GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0);
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public byte[] GetData(long Key)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
if (!Texture.TryGetImageHandler(Key, out ImageHandler CachedImage))
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
return null;
|
2018-07-23 16:21:05 +02:00
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +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.ReadFramebuffer, SrcFb);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
FramebufferAttachment Attachment = GetAttachment(CachedImage);
|
|
|
|
|
|
|
|
GL.FramebufferTexture(FramebufferTarget.ReadFramebuffer, Attachment, CachedImage.Handle, 0);
|
|
|
|
|
|
|
|
int Size = ImageUtils.GetSize(CachedImage.Image);
|
|
|
|
|
|
|
|
byte[] Data = new byte[Size];
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
int Width = CachedImage.Width;
|
|
|
|
int Height = CachedImage.Height;
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
(_, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(CachedImage.Format);
|
|
|
|
|
|
|
|
GL.ReadPixels(0, 0, Width, Height, Format, Type, Data);
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static FramebufferAttachment GetAttachment(ImageHandler CachedImage)
|
|
|
|
{
|
|
|
|
if (CachedImage.HasColor)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
return FramebufferAttachment.ColorAttachment0;
|
|
|
|
}
|
|
|
|
else if (CachedImage.HasDepth && CachedImage.HasStencil)
|
|
|
|
{
|
|
|
|
return FramebufferAttachment.DepthStencilAttachment;
|
|
|
|
}
|
|
|
|
else if (CachedImage.HasDepth)
|
|
|
|
{
|
|
|
|
return FramebufferAttachment.DepthAttachment;
|
|
|
|
}
|
|
|
|
else if (CachedImage.HasStencil)
|
|
|
|
{
|
|
|
|
return FramebufferAttachment.StencilAttachment;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
private static ClearBufferMask GetClearMask(ImageHandler CachedImage)
|
|
|
|
{
|
|
|
|
return (CachedImage.HasColor ? ClearBufferMask.ColorBufferBit : 0) |
|
|
|
|
(CachedImage.HasDepth ? ClearBufferMask.DepthBufferBit : 0) |
|
|
|
|
(CachedImage.HasStencil ? ClearBufferMask.StencilBufferBit : 0);
|
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
private void EnsureFrameBuffer()
|
|
|
|
{
|
|
|
|
if (DummyFrameBuffer == 0)
|
|
|
|
{
|
|
|
|
DummyFrameBuffer = GL.GenFramebuffer();
|
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, DummyFrameBuffer);
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|