-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDepthBuffer.cs
More file actions
70 lines (54 loc) · 1.94 KB
/
Copy pathDepthBuffer.cs
File metadata and controls
70 lines (54 loc) · 1.94 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Graphics.OpenGL4;
namespace SimpleDemo
{
public class DepthBuffer
{
private uint texId;
int width, height;
public DepthBuffer(int w, int h)
{
width = w;
height = h;
GL.GenTextures(1, out texId);
GL.BindTexture(TextureTarget.Texture2D, texId);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
var extensions = GL.GetString(StringName.Extensions).Split(' ');
PixelInternalFormat internalFormat = PixelInternalFormat.DepthComponent;
PixelType type = PixelType.Float;
if (extensions.Contains("GL_ARB_depth_buffer_float"))
{
internalFormat = PixelInternalFormat.DepthComponent32f;
type = PixelType.Float;
}
GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, width, height, 0, PixelFormat.DepthComponent, type, IntPtr.Zero);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
public uint TexId
{
get { return texId; }
}
public int Height
{
get { return height; }
set { height = value; }
}
public int Width
{
get { return width; }
set { width = value; }
}
public void CleanUp()
{
if ( texId != 0)
GL.DeleteTextures(1, ref texId);
}
}
}