-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCommandList.OpenGL.cs
More file actions
1830 lines (1543 loc) · 81.3 KB
/
CommandList.OpenGL.cs
File metadata and controls
1830 lines (1543 loc) · 81.3 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
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#if STRIDE_GRAPHICS_API_OPENGL
using System;
using System.Threading;
using Stride.Core;
using Stride.Core.Mathematics;
using Stride;
using Stride.Shaders;
using Color4 = Stride.Core.Mathematics.Color4;
namespace Stride.Graphics
{
public partial class CommandList
{
// How many frames to wait before allowing non-blocking texture readbacks
private const int ReadbackFrameDelay = 2;
private const int MaxBoundRenderTargets = 16;
internal uint enabledVertexAttribArrays;
private uint boundProgram = 0;
internal int BoundStencilReference;
internal int NewStencilReference;
internal Color4 BoundBlendFactor;
internal Color4 NewBlendFactor;
private bool vboDirty = true;
private GraphicsDevice.FBOTexture boundDepthStencilBuffer;
private int boundRenderTargetCount = 0;
private GraphicsDevice.FBOTexture[] boundRenderTargets = new GraphicsDevice.FBOTexture[MaxBoundRenderTargets];
internal GraphicsResource[] boundShaderResourceViews = new GraphicsResource[64];
private GraphicsResource[] shaderResourceViews = new GraphicsResource[64];
private SamplerState[] samplerStates = new SamplerState[64];
internal DepthStencilBoundState DepthStencilBoundState;
internal RasterizerBoundState RasterizerBoundState;
private Buffer[] constantBuffers = new Buffer[64];
private uint boundFBO;
private bool needUpdateFBO = true;
private PipelineState newPipelineState;
private PipelineState currentPipelineState;
private DescriptorSet[] currentDescriptorSets = new DescriptorSet[32];
internal int activeTexture = 0;
private IndexBufferView indexBuffer;
private VertexBufferView[] vertexBuffers = new VertexBufferView[8];
#if !STRIDE_GRAPHICS_API_OPENGLES
private readonly float[] nativeViewports = new float[4 * MaxViewportAndScissorRectangleCount];
private readonly int[] nativeScissorRectangles = new int[4 * MaxViewportAndScissorRectangleCount];
#endif
public static CommandList New(GraphicsDevice device)
{
if (device.InternalMainCommandList != null)
{
throw new InvalidOperationException("Can't create multiple command lists with OpenGL");
}
return new CommandList(device);
}
private CommandList(GraphicsDevice device) : base(device)
{
device.InternalMainCommandList = this;
// Default state
DepthStencilBoundState.DepthBufferWriteEnable = true;
DepthStencilBoundState.StencilWriteMask = 0xFF;
RasterizerBoundState.FrontFaceDirection = FrontFaceDirection.Ccw;
#if !STRIDE_GRAPHICS_API_OPENGLES
RasterizerBoundState.PolygonMode = PolygonMode.Fill;
#endif
ClearState();
}
// No OpenGL-specific implementation
public unsafe partial void Reset() { }
// No OpenGL-specific implementation
public partial void Flush() { }
// No OpenGL-specific implementation
public partial CompiledCommandList Close()
{
return default;
}
public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
var clearFBO = GraphicsDevice.FindOrCreateFBO(depthStencilBuffer);
if (clearFBO != boundFBO)
GL.BindFramebuffer(FramebufferTarget.Framebuffer, clearFBO);
ClearBufferMask clearBufferMask =
((options & DepthStencilClearOptions.DepthBuffer) == DepthStencilClearOptions.DepthBuffer ? ClearBufferMask.DepthBufferBit : 0)
| ((options & DepthStencilClearOptions.Stencil) == DepthStencilClearOptions.Stencil ? ClearBufferMask.StencilBufferBit : 0);
GL.ClearDepth(depth);
GL.ClearStencil(stencil);
// Check if we need to change depth mask
var currentDepthMask = DepthStencilBoundState.DepthBufferWriteEnable;
if (!currentDepthMask)
GL.DepthMask(true);
GL.Clear(clearBufferMask);
if (!currentDepthMask)
GL.DepthMask(false);
if (clearFBO != boundFBO)
GL.BindFramebuffer(FramebufferTarget.Framebuffer, boundFBO);
}
public void Clear(Texture renderTarget, Color4 color)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
var clearFBO = GraphicsDevice.FindOrCreateFBO(renderTarget);
if (clearFBO != boundFBO)
GL.BindFramebuffer(FramebufferTarget.Framebuffer, clearFBO);
// Check if we need to change color mask
var blendState = currentPipelineState.BlendState;
var needColorMaskOverride = blendState.ColorWriteChannels != ColorWriteChannels.All;
if (needColorMaskOverride)
GL.ColorMask(true, true, true, true);
GL.ClearColor(color.R, color.G, color.B, color.A);
GL.Clear(ClearBufferMask.ColorBufferBit);
// revert the color mask value as it was before
if (needColorMaskOverride)
blendState.RestoreColorMask(GL);
if (clearFBO != boundFBO)
GL.BindFramebuffer(FramebufferTarget.Framebuffer, boundFBO);
}
public unsafe void ClearReadWrite(Buffer buffer, Vector4 value)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
if ((buffer.ViewFlags & BufferFlags.UnorderedAccess) != BufferFlags.UnorderedAccess)
throw new ArgumentException("Buffer does not support unordered access");
GL.BindBuffer(buffer.BufferTarget, buffer.BufferId);
GL.ClearBufferData((BufferStorageTarget)buffer.BufferTarget, (SizedInternalFormat)buffer.TextureInternalFormat, buffer.TextureFormat, PixelType.UnsignedInt8888, value);
GL.BindBuffer(buffer.BufferTarget, 0);
#endif
}
public unsafe void ClearReadWrite(Buffer buffer, Int4 value)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
if ((buffer.ViewFlags & BufferFlags.UnorderedAccess) != BufferFlags.UnorderedAccess)
throw new ArgumentException("Buffer does not support unordered access");
GL.BindBuffer(buffer.BufferTarget, buffer.BufferId);
GL.ClearBufferData((BufferStorageTarget)buffer.BufferTarget, (SizedInternalFormat)buffer.TextureInternalFormat, buffer.TextureFormat, PixelType.UnsignedInt8888, value);
GL.BindBuffer(buffer.BufferTarget, 0);
#endif
}
public unsafe void ClearReadWrite(Buffer buffer, UInt4 value)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
if ((buffer.ViewFlags & BufferFlags.UnorderedAccess) != BufferFlags.UnorderedAccess)
throw new ArgumentException("Buffer does not support unordered access");
GL.BindBuffer(buffer.BufferTarget, buffer.BufferId);
GL.ClearBufferData((BufferStorageTarget)buffer.BufferTarget, (SizedInternalFormat)buffer.TextureInternalFormat, buffer.TextureFormat, PixelType.UnsignedInt8888, value);
GL.BindBuffer(buffer.BufferTarget, 0);
#endif
}
public unsafe void ClearReadWrite(Texture texture, Vector4 value)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
if (activeTexture != 0)
{
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
}
GL.BindTexture(texture.TextureTarget, texture.TextureId);
GL.ClearTexImage(texture.TextureId, 0, texture.TextureFormat, texture.TextureType, value);
GL.BindTexture(texture.TextureTarget, 0);
boundShaderResourceViews[0] = null;
#endif
}
public unsafe void ClearReadWrite(Texture texture, Int4 value)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
if (activeTexture != 0)
{
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
}
GL.BindTexture(texture.TextureTarget, texture.TextureId);
GL.ClearTexImage(texture.TextureId, 0, texture.TextureFormat, texture.TextureType, value);
GL.BindTexture(texture.TextureTarget, 0);
boundShaderResourceViews[0] = null;
#endif
}
public unsafe void ClearReadWrite(Texture texture, UInt4 value)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
if (activeTexture != 0)
{
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
}
GL.BindTexture(texture.TextureTarget, texture.TextureId);
GL.ClearTexImage(texture.TextureId, 0, texture.TextureFormat, texture.TextureType, value);
GL.BindTexture(texture.TextureTarget, 0);
boundShaderResourceViews[0] = null;
#endif
}
/// <summary>
/// OpenGL-specific implementation that clears and restores the state of the Graphics Device.
/// </summary>
private partial void ClearStateImpl()
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
// Clear sampler states
for (int i = 0; i < samplerStates.Length; ++i)
samplerStates[i] = null;
for (int i = 0; i < boundShaderResourceViews.Length; ++i)
{
shaderResourceViews[i] = null;
}
// Clear active texture state
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
// set default states
currentPipelineState = GraphicsDevice.DefaultPipelineState;
newPipelineState = GraphicsDevice.DefaultPipelineState;
// Actually reset states
//currentPipelineState.BlendState.Apply();
GL.Disable(EnableCap.Blend);
GL.ColorMask(true, true, true, true);
currentPipelineState.DepthStencilState.Apply(this);
currentPipelineState.RasterizerState.Apply(this);
#if STRIDE_GRAPHICS_API_OPENGLCORE
GL.Enable(EnableCap.FramebufferSrgb);
#endif
}
/// <summary>
/// Copy a region of a <see cref="GraphicsResource"/> into another.
/// </summary>
/// <param name="source">The source from which to copy the data</param>
/// <param name="regionSource">The region of the source <see cref="GraphicsResource"/> to copy.</param>
/// <param name="destination">The destination into which to copy the data</param>
/// <remarks>This might alter some states such as currently bound texture.</remarks>
public unsafe void CopyRegion(GraphicsResource source, int sourceSubResource, ResourceRegion? regionSource, GraphicsResource destination, int destinationSubResource, int dstX = 0, int dstY = 0, int dstZ = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
var sourceTexture = source as Texture;
var destTexture = destination as Texture;
if (sourceTexture == null || destTexture == null)
{
throw new NotSupportedException("Copy is only implemented for Texture objects.");
}
// Get parent texture
if (sourceTexture.ParentTexture != null)
sourceTexture = sourceTexture.ParentTexture;
if (destTexture.ParentTexture != null)
destTexture = sourceTexture.ParentTexture;
var sourceWidth = Texture.CalculateMipSize(sourceTexture.Description.Width, sourceSubResource % sourceTexture.MipLevelCount);
var sourceHeight = Texture.CalculateMipSize(sourceTexture.Description.Height, sourceSubResource % sourceTexture.MipLevelCount);
var sourceDepth = Texture.CalculateMipSize(sourceTexture.Description.Depth, sourceSubResource % sourceTexture.MipLevelCount);
var sourceRegion = regionSource.HasValue ? regionSource.Value : new ResourceRegion(0, 0, 0, sourceWidth, sourceHeight, sourceDepth);
var sourceRectangle = new Rectangle(sourceRegion.Left, sourceRegion.Top, sourceRegion.Right - sourceRegion.Left, sourceRegion.Bottom - sourceRegion.Top);
if (sourceRectangle.Width == 0 || sourceRectangle.Height == 0)
return;
if (destTexture.Description.Usage == GraphicsResourceUsage.Staging)
{
if (sourceTexture.Description.Usage == GraphicsResourceUsage.Staging)
{
// Staging => Staging
if (sourceRegion.Left != 0 || sourceRegion.Top != 0 || sourceRegion.Front != 0
|| sourceRegion.Right != sourceWidth || sourceRegion.Bottom != sourceHeight || sourceRegion.Back != sourceDepth)
{
throw new NotSupportedException("ReadPixels from staging texture to staging texture only support full copy of subresource");
}
GL.BindBuffer(BufferTargetARB.CopyReadBuffer, sourceTexture.PixelBufferObjectId);
GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, destTexture.PixelBufferObjectId);
GL.CopyBufferSubData(CopyBufferSubDataTarget.CopyReadBuffer, CopyBufferSubDataTarget.CopyWriteBuffer,
(IntPtr)sourceTexture.ComputeBufferOffset(sourceSubResource, 0),
(IntPtr)destTexture.ComputeBufferOffset(destinationSubResource, 0),
(UIntPtr)destTexture.ComputeSubResourceSize(destinationSubResource));
}
else
{
// GPU => Staging
if (dstX != 0 || dstY != 0 || dstZ != 0)
throw new NotSupportedException("ReadPixels from staging texture using non-zero destination is not supported");
GL.Viewport(0, 0, (uint)sourceWidth, (uint)sourceHeight);
var isDepthBuffer = Texture.InternalIsDepthStencilFormat(sourceTexture.Format);
GL.BindFramebuffer(FramebufferTarget.Framebuffer, isDepthBuffer ? GraphicsDevice.CopyDepthSourceFBO : GraphicsDevice.CopyColorSourceFBO);
var attachmentType = FramebufferAttachment.ColorAttachment0;
for (int depthSlice = sourceRegion.Front; depthSlice < sourceRegion.Back; ++depthSlice)
{
attachmentType = GraphicsDevice.UpdateFBO(FramebufferTarget.Framebuffer, new GraphicsDevice.FBOTexture(sourceTexture, sourceSubResource / sourceTexture.MipLevelCount + depthSlice, sourceSubResource % sourceTexture.MipLevelCount));
GL.BindBuffer(BufferTargetARB.PixelPackBuffer, destTexture.PixelBufferObjectId);
GL.ReadPixels(sourceRectangle.Left, sourceRectangle.Top, (uint)sourceRectangle.Width, (uint)sourceRectangle.Height, destTexture.TextureFormat, destTexture.TextureType, (void*)destTexture.ComputeBufferOffset(destinationSubResource, depthSlice));
GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0);
destTexture.PixelBufferFrame = GraphicsDevice.FrameCounter;
}
// Unbind attachment
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachmentType, TextureTarget.Texture2D, 0, 0);
// Restore FBO and viewport
GL.BindFramebuffer(FramebufferTarget.Framebuffer, boundFBO);
GL.Viewport((int)viewports[0].X, (int)viewports[0].Y, (uint)viewports[0].Width, (uint)viewports[0].Height);
}
return;
}
// GPU => GPU
{
var isDepthBuffer = Texture.InternalIsDepthStencilFormat(sourceTexture.Format);
// Use our temporary mutable FBO
GL.BindFramebuffer(FramebufferTarget.Framebuffer, isDepthBuffer ? GraphicsDevice.CopyDepthSourceFBO : GraphicsDevice.CopyColorSourceFBO);
var attachmentType = FramebufferAttachment.ColorAttachment0;
if (activeTexture != 0)
{
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
}
GL.Viewport(0, 0, (uint)sourceWidth, (uint)sourceHeight);
GL.BindTexture(destTexture.TextureTarget, destTexture.TextureId);
for (int depthSlice = sourceRegion.Front; depthSlice < sourceRegion.Back; ++depthSlice)
{
// Note: In practice, either it's a 2D texture array and its arrayslice can be non zero, or it's a 3D texture and it's depthslice can be non-zero, but not both at the same time
attachmentType = GraphicsDevice.UpdateFBO(FramebufferTarget.Framebuffer, new GraphicsDevice.FBOTexture(sourceTexture, sourceSubResource / sourceTexture.MipLevelCount + depthSlice, sourceSubResource % sourceTexture.MipLevelCount));
var arraySlice = destinationSubResource / destTexture.MipLevelCount;
var mipLevel = destinationSubResource % destTexture.MipLevelCount;
switch (destTexture.TextureTarget)
{
#if !STRIDE_GRAPHICS_API_OPENGLES
case TextureTarget.Texture1D:
GL.CopyTexSubImage1D(TextureTarget.Texture1D, mipLevel, dstX, sourceRectangle.Left, sourceRectangle.Top, (uint)sourceRectangle.Width);
break;
#endif
case TextureTarget.Texture2D:
GL.CopyTexSubImage2D(TextureTarget.Texture2D, mipLevel, dstX, dstY, sourceRectangle.Left, sourceRectangle.Top, (uint)sourceRectangle.Width, (uint)sourceRectangle.Height);
break;
case TextureTarget.Texture2DArray:
GL.CopyTexSubImage3D(TextureTarget.Texture2DArray, mipLevel, dstX, dstY, arraySlice, sourceRectangle.Left, sourceRectangle.Top, (uint)sourceRectangle.Width, (uint)sourceRectangle.Height);
break;
case TextureTarget.Texture3D:
GL.CopyTexSubImage3D(TextureTarget.Texture3D, mipLevel, dstX, dstY, depthSlice, sourceRectangle.Left, sourceRectangle.Top, (uint)sourceRectangle.Width, (uint)sourceRectangle.Height);
break;
case TextureTarget.TextureCubeMap:
GL.CopyTexSubImage2D(Texture.GetTextureTargetForDataSet2D(destTexture.TextureTarget, arraySlice), mipLevel, dstX, dstY, sourceRectangle.Left, sourceRectangle.Top, (uint)sourceRectangle.Width, (uint)sourceRectangle.Height);
break;
default:
throw new NotSupportedException("Invalid texture target: " + destTexture.TextureTarget);
}
}
// Unbind texture and force it to be set again next draw call
GL.BindTexture(destTexture.TextureTarget, 0);
boundShaderResourceViews[0] = null;
// Unbind attachment
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachmentType, TextureTarget.Texture2D, 0, 0);
// Restore FBO and viewport
GL.BindFramebuffer(FramebufferTarget.Framebuffer, boundFBO);
GL.Viewport((int)viewports[0].X, (int)viewports[0].Y, (uint)viewports[0].Width, (uint)viewports[0].Height);
}
}
internal unsafe void CopyScaler2D(Texture sourceTexture, Texture destTexture, Rectangle sourceRectangle, Rectangle destRectangle, bool flipY = false)
{
// Use rendering
GL.Viewport(0, 0, (uint)destTexture.Description.Width, (uint)destTexture.Description.Height);
GL.BindFramebuffer(FramebufferTarget.Framebuffer, GraphicsDevice.FindOrCreateFBO(destTexture));
var sourceRegionSize = new Vector2(sourceRectangle.Width, sourceRectangle.Height);
var destRegionSize = new Vector2(destRectangle.Width, destRectangle.Height);
// Source
var sourceSize = new Vector2(sourceTexture.Width, sourceTexture.Height);
var sourceRegionLeftTop = new Vector2(sourceRectangle.Left, sourceRectangle.Top);
var sourceScale = new Vector2(sourceRegionSize.X / sourceSize.X, sourceRegionSize.Y / sourceSize.Y);
var sourceOffset = new Vector2(sourceRegionLeftTop.X / sourceSize.X, sourceRegionLeftTop.Y / sourceSize.Y);
// Dest
var destSize = new Vector2(destTexture.Width, destTexture.Height);
var destRegionLeftTop = new Vector2(destRectangle.X, flipY ? destRectangle.Bottom : destRectangle.Y);
var destScale = new Vector2(destRegionSize.X / destSize.X, destRegionSize.Y / destSize.Y);
var destOffset = new Vector2(destRegionLeftTop.X / destSize.X, destRegionLeftTop.Y / destSize.Y);
if (flipY)
destScale.Y = -destScale.Y;
var enabledColors = new bool[4];
GL.GetBoolean(GetPName.ColorWritemask, enabledColors);
var isDepthTestEnabled = GL.IsEnabled(EnableCap.DepthTest);
var isCullFaceEnabled = GL.IsEnabled(EnableCap.CullFace);
var isBlendEnabled = GL.IsEnabled(EnableCap.Blend);
var isStencilEnabled = GL.IsEnabled(EnableCap.StencilTest);
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.CullFace);
GL.Disable(EnableCap.Blend);
GL.Disable(EnableCap.StencilTest);
GL.ColorMask(true, true, true, true);
// TODO find a better way to detect if sRGB conversion is needed (need to detect if main frame buffer is sRGB or not at init time)
#if STRIDE_GRAPHICS_API_OPENGLES
// If we are copying from an SRgb texture to a non SRgb texture, we use a special SRGb copy shader
bool needSRgbConversion = sourceTexture.Description.Format.IsSRgb() && destTexture == GraphicsDevice.WindowProvidedRenderTexture;
#else
bool needSRgbConversion = false;
#endif
int offsetLocation, scaleLocation;
var program = GraphicsDevice.GetCopyProgram(needSRgbConversion, out offsetLocation, out scaleLocation);
GL.UseProgram(program);
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
GL.BindTexture(TextureTarget.Texture2D, sourceTexture.TextureId);
boundShaderResourceViews[0] = null;
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
sourceTexture.BoundSamplerState = GraphicsDevice.SamplerStates.PointClamp;
vboDirty = true;
enabledVertexAttribArrays |= 1 << 0;
GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTargetARB.ArrayBuffer, GraphicsDevice.GetSquareBuffer().BufferId);
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, null);
GL.Uniform4(offsetLocation, sourceOffset.X, sourceOffset.Y, destOffset.X, destOffset.Y);
GL.Uniform4(scaleLocation, sourceScale.X, sourceScale.Y, destScale.X, destScale.Y);
GL.Viewport(0, 0, (uint)destTexture.Width, (uint)destTexture.Height);
GL.DrawArrays(PrimitiveTypeGl.TriangleStrip, 0, 4);
GL.UseProgram(boundProgram);
// Restore context
if (isDepthTestEnabled)
GL.Enable(EnableCap.DepthTest);
if (isCullFaceEnabled)
GL.Enable(EnableCap.CullFace);
if (isBlendEnabled)
GL.Enable(EnableCap.Blend);
if (isStencilEnabled)
GL.Enable(EnableCap.StencilTest);
GL.ColorMask(enabledColors[0], enabledColors[1], enabledColors[2], enabledColors[3]);
// Restore FBO and viewport
GL.BindFramebuffer(FramebufferTarget.Framebuffer, boundFBO);
GL.Viewport((int)viewports[0].X, (int)viewports[0].Y, (uint)viewports[0].Width, (uint)viewports[0].Height);
}
internal unsafe void CopyScaler2D(Texture sourceTexture, Rectangle sourceRectangle, Rectangle destRectangle, bool needSRgbConversion = false, bool flipY = false)
{
// Use rendering
GL.Viewport(0, 0, (uint)sourceTexture.Description.Width, (uint)sourceTexture.Description.Height);
var sourceRegionSize = new Vector2(sourceRectangle.Width, sourceRectangle.Height);
var destRegionSize = new Vector2(destRectangle.Width, destRectangle.Height);
// Source
var sourceSize = new Vector2(sourceTexture.Width, sourceTexture.Height);
var sourceRegionLeftTop = new Vector2(sourceRectangle.Left, sourceRectangle.Top);
var sourceScale = new Vector2(sourceRegionSize.X / sourceSize.X, sourceRegionSize.Y / sourceSize.Y);
var sourceOffset = new Vector2(sourceRegionLeftTop.X / sourceSize.X, sourceRegionLeftTop.Y / sourceSize.Y);
// Dest
var destSize = new Vector2(sourceTexture.Width, sourceTexture.Height);
var destRegionLeftTop = new Vector2(destRectangle.X, flipY ? destRectangle.Bottom : destRectangle.Y);
var destScale = new Vector2(destRegionSize.X / destSize.X, destRegionSize.Y / destSize.Y);
var destOffset = new Vector2(destRegionLeftTop.X / destSize.X, destRegionLeftTop.Y / destSize.Y);
if (flipY)
destScale.Y = -destScale.Y;
var enabledColors = new bool[4];
GL.GetBoolean(GetPName.ColorWritemask, enabledColors);
var isDepthTestEnabled = GL.IsEnabled(EnableCap.DepthTest);
var isCullFaceEnabled = GL.IsEnabled(EnableCap.CullFace);
var isBlendEnabled = GL.IsEnabled(EnableCap.Blend);
var isStencilEnabled = GL.IsEnabled(EnableCap.StencilTest);
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.CullFace);
GL.Disable(EnableCap.Blend);
GL.Disable(EnableCap.StencilTest);
GL.ColorMask(true, true, true, true);
int offsetLocation, scaleLocation;
var program = GraphicsDevice.GetCopyProgram(needSRgbConversion, out offsetLocation, out scaleLocation);
GL.UseProgram(program);
activeTexture = 0;
GL.ActiveTexture(TextureUnit.Texture0);
GL.BindTexture(TextureTarget.Texture2D, sourceTexture.TextureId);
boundShaderResourceViews[0] = null;
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
sourceTexture.BoundSamplerState = GraphicsDevice.SamplerStates.PointClamp;
vboDirty = true;
enabledVertexAttribArrays |= 1 << 0;
GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTargetARB.ArrayBuffer, GraphicsDevice.GetSquareBuffer().BufferId);
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, null);
GL.Uniform4(offsetLocation, sourceOffset.X, sourceOffset.Y, destOffset.X, destOffset.Y);
GL.Uniform4(scaleLocation, sourceScale.X, sourceScale.Y, destScale.X, destScale.Y);
GL.Viewport(0, 0, (uint)sourceTexture.Width, (uint)sourceTexture.Height);
GL.DrawArrays(PrimitiveTypeGl.TriangleStrip, 0, 4);
GL.UseProgram(boundProgram);
// Restore context
if (isDepthTestEnabled)
GL.Enable(EnableCap.DepthTest);
if (isCullFaceEnabled)
GL.Enable(EnableCap.CullFace);
if (isBlendEnabled)
GL.Enable(EnableCap.Blend);
if (isStencilEnabled)
GL.Enable(EnableCap.StencilTest);
GL.ColorMask(enabledColors[0], enabledColors[1], enabledColors[2], enabledColors[3]);
// Restore viewport
GL.Viewport((int)viewports[0].X, (int)viewports[0].Y, (uint)viewports[0].Width, (uint)viewports[0].Height);
}
/// <summary>
/// Copy a <see cref="GraphicsResource"/> into another.
/// </summary>
/// <param name="source">The source from which to copy the data</param>
/// <param name="destination">The destination into which to copy the data</param>
/// <remarks>This might alter some states such as currently bound texture.</remarks>
public void Copy(GraphicsResource source, GraphicsResource destination)
{
// Count subresources
var subresourceCount = 1;
var sourceTexture = source as Texture;
if (sourceTexture != null)
{
subresourceCount = sourceTexture.ArraySize * sourceTexture.MipLevelCount;
}
// Copy each subresource
for (int i = 0; i < subresourceCount; ++i)
{
CopyRegion(source, i, null, destination, i);
}
}
public void CopyMultisample(Texture sourceMultisampleTexture, int sourceSubResource, Texture destTexture, int destSubResource, PixelFormat format = PixelFormat.None)
{
// Check if the source and destination are compatible:
if (sourceMultisampleTexture.Width != destTexture.Width &&
sourceMultisampleTexture.Height != destTexture.Height &&
sourceMultisampleTexture.Format != destTexture.Format) // TODO: Blitting seems to be okay even if the sizes don't match, but only in case of non-MSAA buffers.
{
throw new InvalidOperationException("sourceMultisampleTexture and destTexture don't match in size and format!");
}
// Set up the read (source) buffer to use for the blitting operation:
var readFBOID = GraphicsDevice.FindOrCreateFBO(sourceMultisampleTexture); // Find the FBO that the sourceMultisampleTexture is bound to.
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFBOID);
// Set up the draw (destination) buffer to use for the blitting operation:
var drawFBOID = GraphicsDevice.FindOrCreateFBO(destTexture); // Find the FBO that the destTexture is bound to.
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFBOID);
ClearBufferMask clearBufferMask;
BlitFramebufferFilter blitFramebufferFilter;
// TODO: PERFORMANCE: We could copy the depth buffer AND color buffer at the same time by doing "ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit".
if (sourceMultisampleTexture.IsDepthBuffer && destTexture.IsDepthBuffer)
{
clearBufferMask = ClearBufferMask.DepthBufferBit;
blitFramebufferFilter = BlitFramebufferFilter.Nearest; // Must be set to nearest for depth buffers according to the spec: "GL_INVALID_OPERATION is generated if mask contains any of the GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT and filter is not GL_NEAREST."
}
else
{
clearBufferMask = ClearBufferMask.ColorBufferBit;
blitFramebufferFilter = BlitFramebufferFilter.Linear; // TODO: STABILITY: For integer formats this has to be set to Nearest.
}
#if !STRIDE_PLATFORM_IOS
// MSAA is not supported on iOS currently because OpenTK doesn't expose "GL.BlitFramebuffer()" on iOS for some reason.
// Do the actual blitting operation:
GL.BlitFramebuffer(0, 0, sourceMultisampleTexture.Width, sourceMultisampleTexture.Height, 0, 0, destTexture.Width, destTexture.Height, clearBufferMask, blitFramebufferFilter);
#endif
}
public void CopyCount(Buffer sourceBuffer, Buffer destBuffer, int offsetToDest)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
throw new NotSupportedException();
}
public void Dispatch(int threadCountX, int threadCountY, int threadCountZ)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if !STRIDE_GRAPHICS_API_OPENGLES
GL.DispatchCompute((uint)threadCountX, (uint)threadCountY, (uint)threadCountZ);
#else
throw new NotSupportedException();
#endif
}
public void Dispatch(Buffer indirectBuffer, int offsetInBytes)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
#if !STRIDE_GRAPHICS_API_OPENGLES
GL.BindBuffer(BufferTargetARB.DispatchIndirectBuffer, indirectBuffer.BufferId);
GL.DispatchComputeIndirect((IntPtr)offsetInBytes);
GL.BindBuffer(BufferTargetARB.DispatchIndirectBuffer, 0);
#else
throw new NotSupportedException();
#endif
}
public void Draw(int vertexCount, int startVertex = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
PreDraw();
GL.DrawArrays(newPipelineState.PrimitiveType, startVertex, (uint)vertexCount);
GraphicsDevice.FrameTriangleCount += (uint)vertexCount;
GraphicsDevice.FrameDrawCalls++;
}
public void DrawAuto(PrimitiveType primitiveType)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
PreDraw();
//GL.DrawArraysIndirect(newPipelineState.PrimitiveType, (IntPtr)0);
//GraphicsDevice.FrameDrawCalls++;
throw new NotSupportedException();
}
/// <summary>
/// Draw indexed, non-instanced primitives.
/// </summary>
/// <param name="indexCount">Number of indices to draw.</param>
/// <param name="startIndexLocation">The location of the first index read by the GPU from the index buffer.</param>
/// <param name="baseVertexLocation">A value added to each index before reading a vertex from the vertex buffer.</param>
public unsafe void DrawIndexed(int indexCount, int startIndexLocation = 0, int baseVertexLocation = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
PreDraw();
#if STRIDE_GRAPHICS_API_OPENGLES
if (baseVertexLocation != 0)
throw new NotSupportedException("DrawIndexed with no null baseVertexLocation is not supported on OpenGL ES.");
GL.DrawElements(newPipelineState.PrimitiveType, (uint)indexCount, indexBuffer.Type, (void*)(indexBuffer.Offset + (startIndexLocation * indexBuffer.ElementSize)));
#else
GL.DrawElementsBaseVertex(newPipelineState.PrimitiveType, (uint)indexCount, indexBuffer.Type, (void*)(indexBuffer.Offset + (startIndexLocation * indexBuffer.ElementSize)), baseVertexLocation);
#endif
GraphicsDevice.FrameDrawCalls++;
GraphicsDevice.FrameTriangleCount += (uint)indexCount;
}
/// <summary>
/// Draw indexed, instanced primitives.
/// </summary>
/// <param name="indexCountPerInstance">Number of indices read from the index buffer for each instance.</param>
/// <param name="instanceCount">Number of instances to draw.</param>
/// <param name="startIndexLocation">The location of the first index read by the GPU from the index buffer.</param>
/// <param name="baseVertexLocation">A value added to each index before reading a vertex from the vertex buffer.</param>
/// <param name="startInstanceLocation">A value added to each index before reading per-instance data from a vertex buffer.</param>
public unsafe void DrawIndexedInstanced(int indexCountPerInstance, int instanceCount, int startIndexLocation = 0, int baseVertexLocation = 0, int startInstanceLocation = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
PreDraw();
#if STRIDE_GRAPHICS_API_OPENGLES
throw new NotSupportedException();
#else
GL.DrawElementsInstancedBaseVertex(newPipelineState.PrimitiveType, (uint)indexCountPerInstance, indexBuffer.Type, (void*)(indexBuffer.Offset + (startIndexLocation * indexBuffer.ElementSize)), (uint)instanceCount, baseVertexLocation);
#endif
GraphicsDevice.FrameDrawCalls++;
GraphicsDevice.FrameTriangleCount += (uint)(indexCountPerInstance * instanceCount);
}
/// <summary>
/// Draw indexed, instanced, GPU-generated primitives.
/// </summary>
/// <param name="argumentsBuffer">A buffer containing the GPU generated primitives.</param>
/// <param name="alignedByteOffsetForArgs">Offset in <em>pBufferForArgs</em> to the start of the GPU generated primitives.</param>
public void DrawIndexedInstanced(Buffer argumentsBuffer, int alignedByteOffsetForArgs = 0)
{
if (argumentsBuffer == null) throw new ArgumentNullException(nameof(argumentsBuffer));
#if DEBUG
//GraphicsDevice.EnsureContextActive();
#endif
//PreDraw();
//GraphicsDevice.FrameDrawCalls++;
throw new NotSupportedException();
}
/// <summary>
/// Draw non-indexed, instanced primitives.
/// </summary>
/// <param name="vertexCountPerInstance">Number of vertices to draw.</param>
/// <param name="instanceCount">Number of instances to draw.</param>
/// <param name="startVertexLocation">Index of the first vertex.</param>
/// <param name="startInstanceLocation">A value added to each index before reading per-instance data from a vertex buffer.</param>
public void DrawInstanced(int vertexCountPerInstance, int instanceCount, int startVertexLocation = 0, int startInstanceLocation = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
PreDraw();
GL.DrawArraysInstanced(newPipelineState.PrimitiveType, startVertexLocation, (uint)vertexCountPerInstance, (uint)instanceCount);
GraphicsDevice.FrameDrawCalls++;
GraphicsDevice.FrameTriangleCount += (uint)(vertexCountPerInstance * instanceCount);
}
/// <summary>
/// Draw instanced, GPU-generated primitives.
/// </summary>
/// <param name="argumentsBuffer">An arguments buffer</param>
/// <param name="alignedByteOffsetForArgs">Offset in <em>pBufferForArgs</em> to the start of the GPU generated primitives.</param>
public void DrawInstanced(Buffer argumentsBuffer, int alignedByteOffsetForArgs = 0)
{
if (argumentsBuffer == null)
throw new ArgumentNullException(nameof(argumentsBuffer));
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
PreDraw();
#if STRIDE_GRAPHICS_API_OPENGLES
GraphicsDevice.FrameDrawCalls++;
throw new NotSupportedException();
#else
GL.BindBuffer(BufferTargetARB.DrawIndirectBuffer, argumentsBuffer.BufferId);
GL.DrawArraysIndirect(newPipelineState.PrimitiveType, (IntPtr)alignedByteOffsetForArgs);
GL.BindBuffer(BufferTargetARB.DrawIndirectBuffer, 0);
GraphicsDevice.FrameDrawCalls++;
#endif
}
public void BeginProfile(Color4 profileColor, string name)
{
if (GraphicsDevice.ProfileEnabled)
{
GL.PushDebugGroup(DebugSource.DebugSourceApplication, 1, uint.MaxValue, name);
}
}
public void EndProfile()
{
if (GraphicsDevice.ProfileEnabled)
{
GL.PopDebugGroup();
}
}
/// <summary>
/// Submit a timestamp query.
/// </summary>
/// <param name="queryPool">The QueryPool owning the query.</param>
/// <param name="index">The query index.</param>
public void WriteTimestamp(QueryPool queryPool, int index)
{
#if STRIDE_GRAPHICS_API_OPENGLES
GraphicsDevice.GLExtDisjointTimerQuery.QueryCounter(queryPool.NativeQueries[index], QueryCounterTarget.Timestamp);
#else
GL.QueryCounter(queryPool.NativeQueries[index], QueryCounterTarget.Timestamp);
#endif
}
public void ResetQueryPool(QueryPool queryPool)
{
}
public unsafe partial MappedResource MapSubResource(GraphicsResource resource, int subResourceIndex, MapMode mapMode, bool doNotWait = false, int offsetInBytes = 0, int lengthInBytes = 0)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
// This resource has just been recycled by the GraphicsResourceAllocator, we force a rename to avoid GPU=>GPU sync point
if (resource.DiscardNextMap && mapMode == MapMode.WriteNoOverwrite)
mapMode = MapMode.WriteDiscard;
if (resource is Buffer buffer)
{
if (lengthInBytes == 0)
lengthInBytes = buffer.Description.SizeInBytes;
IntPtr mapResult = IntPtr.Zero;
GL.BindBuffer(buffer.BufferTarget, buffer.BufferId);
// Orphan the buffer (let driver knows we don't need it anymore)
if (mapMode == MapMode.WriteDiscard)
{
doNotWait = true;
GL.BufferData(buffer.BufferTarget, (uint)buffer.Description.SizeInBytes, null, buffer.BufferUsageHint);
}
var unsynchronized = doNotWait && mapMode != MapMode.Read && mapMode != MapMode.ReadWrite;
mapResult = (IntPtr)GL.MapBufferRange(buffer.BufferTarget, offsetInBytes, (UIntPtr)lengthInBytes, mapMode.ToOpenGLMask() | (unsynchronized ? MapBufferAccessMask.UnsynchronizedBit : 0));
return new MappedResource(resource, subResourceIndex, new DataBox { DataPointer = mapResult, SlicePitch = 0, RowPitch = 0 });
}
if (resource is Texture texture)
{
if (lengthInBytes == 0)
lengthInBytes = texture.ComputeSubResourceSize(subResourceIndex);
if (mapMode == MapMode.Read)
{
if (texture.Description.Usage != GraphicsResourceUsage.Staging)
throw new NotSupportedException("Only staging textures can be mapped.");
var mipLevel = subResourceIndex % texture.MipLevelCount;
if (doNotWait)
{
// Wait at least 2 frames after last operation
if (GraphicsDevice.FrameCounter < texture.PixelBufferFrame + ReadbackFrameDelay)
{
return new MappedResource(resource, subResourceIndex, new DataBox(), offsetInBytes, lengthInBytes);
}
}
return MapTexture(texture, true, BufferTargetARB.PixelPackBuffer, texture.PixelBufferObjectId, subResourceIndex, mapMode, offsetInBytes, lengthInBytes);
}
else if (mapMode == MapMode.WriteDiscard)
{
if (texture.Description.Usage != GraphicsResourceUsage.Dynamic)
throw new NotSupportedException("Only dynamic texture can be mapped.");
// Create a temporary unpack pixel buffer
// TODO: Pool/allocator? (it's an upload buffer basically)
var pixelBufferObjectId = texture.GeneratePixelBufferObject(BufferTargetARB.PixelUnpackBuffer, PixelStoreParameter.UnpackAlignment, BufferUsageARB.DynamicCopy, texture.ComputeSubResourceSize(subResourceIndex));
return MapTexture(texture, false, BufferTargetARB.PixelUnpackBuffer, pixelBufferObjectId, subResourceIndex, mapMode, offsetInBytes, lengthInBytes);
}
}
throw new NotSupportedException("MapSubResource not implemented for type " + resource.GetType());
}
public unsafe partial void UnmapSubResource(MappedResource unmapped)
{
#if DEBUG
GraphicsDevice.EnsureContextActive();
#endif
var texture = unmapped.Resource as Texture;
if (texture != null)
{
if (texture.Description.Usage == GraphicsResourceUsage.Staging)
{
GL.BindBuffer(BufferTargetARB.PixelPackBuffer, texture.PixelBufferObjectId);
GL.UnmapBuffer(BufferTargetARB.PixelPackBuffer);
GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0);
}