-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOVRSharedRendertarget.cs
81 lines (67 loc) · 2.72 KB
/
OVRSharedRendertarget.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using OpenTK.Graphics.OpenGL4;
using OpenTK.Graphics;
using OculusWrap;
using SwapTextureSet = OculusWrap.GL.SwapTextureSet;
using System;
using System.Diagnostics;
namespace SimpleDemo
{
public class OvrSharedRendertarget
{
private OculusWrap.GL.SwapTextureSet textureSet;
private int fboId;
private int width, height;
public OvrSharedRendertarget(int w, int h, Hmd hmd)
{
width = w;
height = h;
hmd.CreateSwapTextureSetGL((uint)All.Srgb8Alpha8, width, height, out textureSet);
for (int i = 0; i < textureSet.TextureCount; i++)
{
GL.BindTexture(TextureTarget.Texture2D, textureSet.Textures[i].TexId);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
}
GL.GenFramebuffers(1, out fboId);
}
#region Properties
public int FboId
{
get { return fboId; }
}
public int Height
{
get { return height; }
}
public int Width
{
get { return width; }
}
public SwapTextureSet TextureSet
{
get { return textureSet; }
}
#endregion
public void Bind(uint depth)
{
OVR.GL.GLTextureData tex = textureSet.Textures[textureSet.CurrentIndex];
GL.BindFramebuffer(FramebufferTarget.Framebuffer, fboId);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, tex.TexId, 0);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, depth, 0);
}
public void UnBind()
{
GL.BindFramebuffer(FramebufferTarget.Framebuffer, fboId);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, 0, 0);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, 0, 0);
}
public void CleanUp()
{
textureSet.Dispose();
if (fboId != 0)
GL.DeleteFramebuffers(1, ref fboId);
}
}
}