forked from ultradr3mer/ultraSandbox
/
FramebufferCreator.cs
602 lines (499 loc) · 25.9 KB
/
FramebufferCreator.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
using System;
using System.Diagnostics;
using System.IO;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using System.Collections.Generic;
using System.Collections;
namespace OpenTkProject
{
public class FramebufferCreator : GameObject
{
public List<Framebuffer> Framebuffers = new List<Framebuffer> { };
public Hashtable FramebufferNames = new Hashtable();
public Framebuffer defaultFb;
public FramebufferCreator(OpenTkProjectWindow gameWindow)
{
this.gameWindow = gameWindow;
//defaultFb = createFrameBuffer( mGameWindow.Width, mGameWindow.Height);
defaultFb = new DefaultFramebuffer(new Vector2(gameWindow.Width, gameWindow.Height), this);
}
#region Randoms
Random rnd = new Random();
public const float rScale = 3f;
/// <summary>Returns a random Float in the range [-0.5*scale..+0.5*scale]</summary>
public float GetRandom()
{
return (float)(rnd.NextDouble() - 0.5) * rScale;
}
/// <summary>Returns a random Float in the range [0..1]</summary>
public float GetRandom0to1()
{
return (float)rnd.NextDouble();
}
#endregion Randoms
public Framebuffer createFrameBuffer(string name, int FboWidth, int FboHeight)
{
return createFrameBuffer(name, FboWidth, FboHeight, PixelInternalFormat.Rgba8, true);
}
public Framebuffer createFrameBuffer(int FboWidth, int FboHeight)
{
return createFrameBuffer( null, FboWidth, FboHeight, PixelInternalFormat.Rgba8, true);
}
public Framebuffer createFrameBuffer(int FboWidth, int FboHeight, PixelInternalFormat precision, bool multisampling)
{
return createFrameBuffer(null, FboWidth, FboHeight, precision, multisampling);
}
public Framebuffer createFrameBuffer(string name, int FboWidth, int FboHeight, PixelInternalFormat precision, bool multisampling)
{
int FboHandle;
int ColorTexture;
int DepthTexture;
int sampling = 0;
if (multisampling)
{
sampling = (int)TextureMinFilter.Linear;
}
else
{
sampling = (int)TextureMinFilter.Nearest;
}
// Create Color Tex
GL.GenTextures(1, out ColorTexture);
GL.BindTexture(TextureTarget.Texture2D, ColorTexture);
GL.TexImage2D(TextureTarget.Texture2D, 0, precision, FboWidth, FboHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
// GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );
// Create Depth Tex
GL.GenTextures(1, out DepthTexture);
GL.BindTexture(TextureTarget.Texture2D, DepthTexture);
GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)All.DepthComponent32, FboWidth, FboHeight, 0, PixelFormat.DepthComponent, PixelType.UnsignedInt, IntPtr.Zero);
// things go horribly wrong if DepthComponent's Bitcount does not match the main Framebuffer's Depth
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
// GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );
// Create a FBO and attach the textures
GL.Ext.GenFramebuffers(1, out FboHandle);
#region Test for Error
switch (GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt))
{
case FramebufferErrorCode.FramebufferCompleteExt:
{
gameWindow.log("FBO: The framebuffer is complete and valid for rendering.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteAttachmentExt:
{
gameWindow.log("FBO: One or more attachment points are not framebuffer attachment complete. This could mean there’s no texture attached or the format isn’t renderable. For color textures this means the base format must be RGB or RGBA and for depth textures it must be a DEPTH_COMPONENT format. Other causes of this error are that the width or height is zero or the z-offset is out of range in case of render to volume.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteMissingAttachmentExt:
{
gameWindow.log("FBO: There are no attachments.");
break;
}
/* case FramebufferErrorCode.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
{
Console.WriteLine("FBO: An object has been attached to more than one attachment point.");
break;
}*/
case FramebufferErrorCode.FramebufferIncompleteDimensionsExt:
{
gameWindow.log("FBO: Attachments are of different size. All attachments must have the same width and height.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteFormatsExt:
{
gameWindow.log("FBO: The color attachments have different format. All color attachments must have the same format.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteDrawBufferExt:
{
gameWindow.log("FBO: An attachment point referenced by GL.DrawBuffers() doesn’t have an attachment.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteReadBufferExt:
{
gameWindow.log("FBO: The attachment point referenced by GL.ReadBuffers() doesn’t have an attachment.");
break;
}
case FramebufferErrorCode.FramebufferUnsupportedExt:
{
gameWindow.log("FBO: This particular FBO configuration is not supported by the implementation.");
break;
}
default:
{
gameWindow.log("FBO: Status unknown. (yes, this is really bad.)");
break;
}
}
// using FBO might have changed states, e.g. the FBO might not support stereoscopic views or double buffering
int[] queryinfo = new int[6];
GL.GetInteger(GetPName.MaxColorAttachmentsExt, out queryinfo[0]);
GL.GetInteger(GetPName.AuxBuffers, out queryinfo[1]);
GL.GetInteger(GetPName.MaxDrawBuffers, out queryinfo[2]);
GL.GetInteger(GetPName.Stereo, out queryinfo[3]);
GL.GetInteger(GetPName.Samples, out queryinfo[4]);
GL.GetInteger(GetPName.Doublebuffer, out queryinfo[5]);
//Console.WriteLine("max. ColorBuffers: " + queryinfo[0] + " max. AuxBuffers: " + queryinfo[1] + " max. DrawBuffers: " + queryinfo[2] + "\nStereo: " + queryinfo[3] + " Samples: " + queryinfo[4] + " DoubleBuffer: " + queryinfo[5]);
Console.WriteLine("Last GL Error: " + GL.GetError());
#endregion Test for Error
gameWindow.checkGlError("createFrameBuffer");
Framebuffer myFramebuffer = new Framebuffer(FboHandle, ColorTexture, DepthTexture, new Vector2(FboWidth, FboHeight), this);
myFramebuffer.name = name;
if (name != null)
{
registerFramebuffer(myFramebuffer);
}
return myFramebuffer;
}
private void registerFramebuffer(Framebuffer newFb)
{
Framebuffers.Add(newFb);
int identifier = Framebuffers.Count;
if (FramebufferNames.ContainsKey(newFb.name))
FramebufferNames.Remove(newFb.name);
FramebufferNames.Add(newFb.name, identifier);
gameWindow.textureLoader.fromFramebuffer(newFb.name + "color", newFb.ColorTexture);
}
public void createLightBuffer(string name, int size, bool multisampling)
{
int FboHandle;
int ColorTexture;
int DepthTexture;
int sampling = 0;
if (multisampling)
{
sampling = (int)TextureMinFilter.Linear;
}
else
{
sampling = (int)TextureMinFilter.Nearest;
}
/*
// Create Color Tex
GL.GenTextures(1, out ColorTexture);
GL.BindTexture(TextureTarget.Texture2D, ColorTexture);
GL.TexImage2D(TextureTarget.Texture2D, 0, precision, size, size, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
// GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );
*/
// Create Depth Tex
GL.GenTextures(1, out DepthTexture);
GL.BindTexture(TextureTarget.Texture2D, DepthTexture);
GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)All.DepthComponent32, size, size, 0, PixelFormat.DepthComponent, PixelType.UnsignedInt, IntPtr.Zero);
// things go horribly wrong if DepthComponent's Bitcount does not match the main Framebuffer's Depth
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
// GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );
// Create a FBO and attach the textures
GL.Ext.GenFramebuffers(1, out FboHandle);
#region Test for Error
switch (GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt))
{
case FramebufferErrorCode.FramebufferCompleteExt:
{
gameWindow.log("FBO: The framebuffer is complete and valid for rendering.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteAttachmentExt:
{
gameWindow.log("FBO: One or more attachment points are not framebuffer attachment complete. This could mean there’s no texture attached or the format isn’t renderable. For color textures this means the base format must be RGB or RGBA and for depth textures it must be a DEPTH_COMPONENT format. Other causes of this error are that the width or height is zero or the z-offset is out of range in case of render to volume.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteMissingAttachmentExt:
{
gameWindow.log("FBO: There are no attachments.");
break;
}
/* case FramebufferErrorCode.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
{
Console.WriteLine("FBO: An object has been attached to more than one attachment point.");
break;
}*/
case FramebufferErrorCode.FramebufferIncompleteDimensionsExt:
{
gameWindow.log("FBO: Attachments are of different size. All attachments must have the same width and height.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteFormatsExt:
{
gameWindow.log("FBO: The color attachments have different format. All color attachments must have the same format.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteDrawBufferExt:
{
gameWindow.log("FBO: An attachment point referenced by GL.DrawBuffers() doesn’t have an attachment.");
break;
}
case FramebufferErrorCode.FramebufferIncompleteReadBufferExt:
{
gameWindow.log("FBO: The attachment point referenced by GL.ReadBuffers() doesn’t have an attachment.");
break;
}
case FramebufferErrorCode.FramebufferUnsupportedExt:
{
gameWindow.log("FBO: This particular FBO configuration is not supported by the implementation.");
break;
}
default:
{
gameWindow.log("FBO: Status unknown. (yes, this is really bad.)");
break;
}
}
// using FBO might have changed states, e.g. the FBO might not support stereoscopic views or double buffering
int[] queryinfo = new int[6];
GL.GetInteger(GetPName.MaxColorAttachmentsExt, out queryinfo[0]);
GL.GetInteger(GetPName.AuxBuffers, out queryinfo[1]);
GL.GetInteger(GetPName.MaxDrawBuffers, out queryinfo[2]);
GL.GetInteger(GetPName.Stereo, out queryinfo[3]);
GL.GetInteger(GetPName.Samples, out queryinfo[4]);
GL.GetInteger(GetPName.Doublebuffer, out queryinfo[5]);
//Console.WriteLine("max. ColorBuffers: " + queryinfo[0] + " max. AuxBuffers: " + queryinfo[1] + " max. DrawBuffers: " + queryinfo[2] + "\nStereo: " + queryinfo[3] + " Samples: " + queryinfo[4] + " DoubleBuffer: " + queryinfo[5]);
Console.WriteLine("Last GL Error: " + GL.GetError());
#endregion Test for Error
gameWindow.checkGlError("createFrameBuffer");
int identifier = Framebuffers.Count;
ColorTexture = 0;
Framebuffer myFramebuffer = new Framebuffer(FboHandle, ColorTexture, DepthTexture, new Vector2(size, size), this);
gameWindow.textureLoader.fromFramebuffer(name + "light", myFramebuffer.DepthTexture);
Framebuffers.Add(myFramebuffer);
FramebufferNames.Add(name, identifier);
//return new Framebuffer(FboHandle, ColorTexture, DepthTexture, new Vector2(FboWidth, FboHeight), mGameWindow);
}
public Framebuffer getFrameBuffer(string name)
{
int id = (int)FramebufferNames[name];
return Framebuffers[id];
}
}
public struct RenderOptions
{
public Vector2 size;
public float quality;
public bool postProcessing;
public bool ssAmbientOccluison;
public bool depthOfField;
public bool bloom;
public RenderOptions(Vector2 size)
{
this.size = size;
quality = 0.5f;
postProcessing = false;
ssAmbientOccluison = false;
depthOfField = false;
bloom = false;
}
}
public class FramebufferSet : GameObject
{
public Framebuffer
screenNormalFb,
aoFramebuffer,
aoBlurFramebuffer,
aoBlurFramebuffer2,
sceeneFramebuffer,
selectionFb,
bloomFramebuffer,
bloomFramebuffer2,
outputFb,
selectionblurFb,
selectionblurFb2,
dofFramebuffer,
dofPreFramebuffer,
dofFramebuffer2,
sceeneFramebufferTrans;
public RenderOptions renderOptions;
public FramebufferSet(FramebufferCreator mFramebufferCreator, Vector2 size, Framebuffer outputFb)
{
RenderOptions mOptions = new RenderOptions(size);
createFramebufferSet(mFramebufferCreator, outputFb, mOptions);
}
public FramebufferSet(FramebufferCreator mFramebufferCreator, Framebuffer outputFb, RenderOptions mOptions)
{
createFramebufferSet(mFramebufferCreator, outputFb, mOptions);
}
private void createFramebufferSet(FramebufferCreator mFramebufferCreator, Framebuffer outputFb, RenderOptions mOptions)
{
Vector2 size = mOptions.size;
Vector2 size2 = size * mOptions.quality;
Vector2 size3 = size2 * 0.3f;
//sceeneFramebuffer = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y);
sceeneFramebufferTrans = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba8, false);
if (mOptions.postProcessing)
{
sceeneFramebuffer = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba16f, false);
sceeneFramebuffer.clearColor = new Color4(0f, 0f, 0f, 100f);
selectionFb = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba8, false);
//screenNormalFb = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba16f, false);
//screenNormalFb.clearColor = new Color4(0f, 0f, 0f, 100f);
//lightFramebuffer = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba16f, false);
if (mOptions.depthOfField)
{
// depth of field buffers
dofPreFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
dofFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
}
dofFramebuffer2 = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, true);
aoBlurFramebuffer2 = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, true);
aoBlurFramebuffer2.clearColor = new Color4(0f, 0f, 0f, 0.5f);
if (mOptions.ssAmbientOccluison)
{
aoFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
aoBlurFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
} else {
// if ao is set of make the buffer grey
//aoBlurFramebuffer2.enable();
}
selectionblurFb = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, false);
selectionblurFb2 = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, true);
bloomFramebuffer = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, false);
bloomFramebuffer2 = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, false);
}
renderOptions = mOptions;
this.outputFb = outputFb;
}
}
public class CubemapBufferSets : GameObject
{
private Framebuffer[] outFrameBuffers = new Framebuffer[6];
public FramebufferSet[] FrameBufferSets = new FramebufferSet[6];
public ViewInfo[] cubeView = new ViewInfo[6];
public Vector3[] viewDirections = new Vector3[] {
new Vector3(-1,0,0),
new Vector3(0,0,1),
new Vector3(1,0,0),
new Vector3(0,0,-1),
new Vector3(0,1,0),
new Vector3(0,-1,0)
};
public Vector3[] upDirections = new Vector3[] {
new Vector3(0,-1,0),
new Vector3(0,-1,0),
new Vector3(0,-1,0),
new Vector3(0,-1,0),
new Vector3(0,0,-1),
new Vector3(0,0,1)
};
public int[] outTextures = new int[6];
public CubemapBufferSets(Scene parent, FramebufferCreator mFramebufferCreator, int size)
{
this.Scene = parent;
Parent = parent;
Vector2 vecSize = new Vector2(size,size);
float fovy = (float)Math.PI/2;
for (int i = 0; i < 6; i++)
{
outFrameBuffers[i] = mFramebufferCreator.createFrameBuffer(size, size, PixelInternalFormat.Rgba8, true);
outTextures[i] = outFrameBuffers[i].ColorTexture;
FrameBufferSets[i] = new FramebufferSet(mFramebufferCreator, vecSize, outFrameBuffers[i]);
cubeView[i] = new ViewInfo(this);
cubeView[i].PointingDirection = viewDirections[i];
cubeView[i].upVec = upDirections[i];
cubeView[i].aspect = 1f;
cubeView[i].fovy = fovy;
cubeView[i].updateProjectionMatrix();
}
}
public override void update()
{
Position = Scene.eyePos;
updateChilds();
}
}
public class Framebuffer : GameObject
{
public int FboHandle;
public int ColorTexture;
public int DepthTexture;
public Color4 clearColor = new Color4(0f, 0f, 0f, 0f);
public bool isDefaultFb = false;
protected new Vector2 size;
new public Vector2 Size { get { return size; } set { size = value; } }
public Framebuffer(
int FboHandle,
int ColorTexture,
int DepthTexture,
Vector2 size,
FramebufferCreator parent)
{
this.FboHandle = FboHandle;
this.ColorTexture = ColorTexture;
this.DepthTexture = DepthTexture;
this.size = size;
Parent = parent;
}
public virtual void enable(bool wipe)
{
gameWindow.checkGlError("--uncaught ERROR enabeling framebuffer--" + name);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, FboHandle);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, ColorTexture, 0);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, DepthTexture, 0);
GL.Viewport(0, 0, (int)(size.X), (int)(size.Y));
// clear the screen in red, to make it very obvious what the clear affected. only the FBO, not the real framebuffer
if (wipe)
{
GL.ClearColor(clearColor);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
}
gameWindow.currentSize = size;
gameWindow.checkGlError("--ERROR enabeling framebuffer--" + name);
}
public bool Multisampeling
{
get { return false; }
set
{
int sampling = 0;
if (value)
{
sampling = (int)TextureMinFilter.Linear;
}
else
{
sampling = (int)TextureMinFilter.Nearest;
}
GL.BindTexture(TextureTarget.Texture2D, ColorTexture);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
}
}
public Framebuffer() { }
}
public class DefaultFramebuffer : Framebuffer
{
public DefaultFramebuffer(Vector2 size, FramebufferCreator parent)
{
Parent = parent;
this.size = size;
}
public override void enable(bool wipe)
{
gameWindow.checkGlError("--uncaught ERROR enabeling framebuffer--defaultfb");
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); // disable rendering into the FBO
GL.Viewport(0, 0, (int)(size.X), (int)(size.Y));
if (wipe)
{
GL.ClearColor(clearColor);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
}
//GL.Enable(EnableCap.Texture2D); // enable Texture Mapping
//GL.BindTexture(TextureTarget.Texture2D, 0); // bind default texture
gameWindow.currentSize = size;
gameWindow.checkGlError("--ERROR enabeling framebuffer--defaultfb");
}
}
}