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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLFramebuffer.h"
// You know it's going to be fun when these two show up:
#include <algorithm>
#include <iterator>
#include "GLContext.h"
#include "GLScreenBuffer.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
#include "nsPrintfCString.h"
#include "WebGLContext.h"
#include "WebGLContextUtils.h"
#include "WebGLExtensions.h"
#include "WebGLRenderbuffer.h"
#include "WebGLShader.h"
#include "WebGLTexture.h"
#include "WebGLObjectModel.h"
namespace mozilla {
WebGLFBAttachPoint::WebGLFBAttachPoint()
: mFB(nullptr)
, mAttachmentPoint(0)
, mTexImageTarget(LOCAL_GL_NONE)
, mTexImageLayer(0)
, mTexImageLevel(0)
{ }
WebGLFBAttachPoint::WebGLFBAttachPoint(WebGLFramebuffer* fb, GLenum attachmentPoint)
: mFB(fb)
, mAttachmentPoint(attachmentPoint)
, mTexImageTarget(LOCAL_GL_NONE)
, mTexImageLayer(0)
, mTexImageLevel(0)
{ }
WebGLFBAttachPoint::~WebGLFBAttachPoint()
{
MOZ_ASSERT(mFB, "Should have been Init'd.");
MOZ_ASSERT(!mRenderbufferPtr);
MOZ_ASSERT(!mTexturePtr);
}
void
WebGLFBAttachPoint::Unlink()
{
Clear();
}
bool
WebGLFBAttachPoint::IsDeleteRequested() const
{
return Texture() ? Texture()->IsDeleteRequested()
: Renderbuffer() ? Renderbuffer()->IsDeleteRequested()
: false;
}
bool
WebGLFBAttachPoint::IsDefined() const
{
/*
return (Renderbuffer() && Renderbuffer()->IsDefined()) ||
(Texture() && Texture()->ImageInfoAt(mTexImageTarget,
mTexImageLevel).IsDefined());
*/
return (Renderbuffer() || Texture());
}
const webgl::FormatUsageInfo*
WebGLFBAttachPoint::Format() const
{
MOZ_ASSERT(IsDefined());
if (Texture())
return Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).mFormat;
if (Renderbuffer())
return Renderbuffer()->Format();
return nullptr;
}
uint32_t
WebGLFBAttachPoint::Samples() const
{
MOZ_ASSERT(IsDefined());
if (mRenderbufferPtr)
return mRenderbufferPtr->Samples();
return 0;
}
bool
WebGLFBAttachPoint::HasAlpha() const
{
return Format()->format->a;
}
bool
WebGLFBAttachPoint::IsReadableFloat() const
{
auto formatUsage = Format();
MOZ_ASSERT(formatUsage);
auto format = formatUsage->format;
if (!format->IsColorFormat())
return false;
return format->componentType == webgl::ComponentType::Float;
}
void
WebGLFBAttachPoint::Clear()
{
if (mRenderbufferPtr) {
MOZ_ASSERT(!mTexturePtr);
mRenderbufferPtr->UnmarkAttachment(*this);
} else if (mTexturePtr) {
mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel).RemoveAttachPoint(this);
}
mTexturePtr = nullptr;
mRenderbufferPtr = nullptr;
OnBackingStoreRespecified();
}
void
WebGLFBAttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level,
GLint layer)
{
Clear();
mTexturePtr = tex;
mTexImageTarget = target;
mTexImageLevel = level;
mTexImageLayer = layer;
if (mTexturePtr) {
mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel).AddAttachPoint(this);
}
}
void
WebGLFBAttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb)
{
Clear();
mRenderbufferPtr = rb;
if (mRenderbufferPtr) {
mRenderbufferPtr->MarkAttachment(*this);
}
}
bool
WebGLFBAttachPoint::HasUninitializedImageData() const
{
if (!HasImage())
return false;
if (mRenderbufferPtr)
return mRenderbufferPtr->HasUninitializedImageData();
MOZ_ASSERT(mTexturePtr);
auto& imageInfo = mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel);
MOZ_ASSERT(imageInfo.IsDefined());
return !imageInfo.IsDataInitialized();
}
void
WebGLFBAttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus) const
{
if (!HasImage())
return;
if (mRenderbufferPtr) {
mRenderbufferPtr->mImageDataStatus = newStatus;
return;
}
MOZ_ASSERT(mTexturePtr);
auto& imageInfo = mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel);
MOZ_ASSERT(imageInfo.IsDefined());
const bool isDataInitialized = (newStatus == WebGLImageDataStatus::InitializedImageData);
imageInfo.SetIsDataInitialized(isDataInitialized, mTexturePtr);
}
bool
WebGLFBAttachPoint::HasImage() const
{
if (Texture() && Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).IsDefined())
return true;
if (Renderbuffer() && Renderbuffer()->IsDefined())
return true;
return false;
}
void
WebGLFBAttachPoint::Size(uint32_t* const out_width, uint32_t* const out_height) const
{
MOZ_ASSERT(HasImage());
if (Renderbuffer()) {
*out_width = Renderbuffer()->Width();
*out_height = Renderbuffer()->Height();
return;
}
MOZ_ASSERT(Texture());
MOZ_ASSERT(Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).IsDefined());
const auto& imageInfo = Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel);
*out_width = imageInfo.mWidth;
*out_height = imageInfo.mHeight;
}
void
WebGLFBAttachPoint::OnBackingStoreRespecified() const
{
mFB->InvalidateFramebufferStatus();
}
void
WebGLFBAttachPoint::AttachmentName(nsCString* out) const
{
switch (mAttachmentPoint) {
case LOCAL_GL_DEPTH_ATTACHMENT:
out->AssignLiteral("DEPTH_ATTACHMENT");
return;
case LOCAL_GL_STENCIL_ATTACHMENT:
out->AssignLiteral("STENCIL_ATTACHMENT");
return;
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
out->AssignLiteral("DEPTH_STENCIL_ATTACHMENT");
return;
default:
MOZ_ASSERT(mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0);
out->AssignLiteral("COLOR_ATTACHMENT");
const uint32_t n = mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
out->AppendInt(n);
return;
}
}
bool
WebGLFBAttachPoint::IsComplete(WebGLContext* webgl, nsCString* const out_info) const
{
MOZ_ASSERT(IsDefined());
if (!HasImage()) {
AttachmentName(out_info);
out_info->AppendLiteral("'s image is not defined");
return false;
}
uint32_t width;
uint32_t height;
Size(&width, &height);
if (!width || !height) {
AttachmentName(out_info);
out_info->AppendLiteral(" has no width or height");
return false;
}
const auto formatUsage = Format();
if (!formatUsage->IsRenderable()) {
nsAutoCString attachName;
AttachmentName(&attachName);
*out_info = nsPrintfCString("%s has an effective format of %s, which is not"
" renderable",
attachName.BeginReading(), formatUsage->format->name);
return false;
}
if (webgl->IsWebGL2() && Texture() &&
Texture()->IsCubeMap() && !Texture()->IsCubeComplete())
{
AttachmentName(out_info);
out_info->AppendLiteral(" is not cube complete");
return false;
}
const auto format = formatUsage->format;
bool hasRequiredBits;
switch (mAttachmentPoint) {
case LOCAL_GL_DEPTH_ATTACHMENT:
hasRequiredBits = format->d;
break;
case LOCAL_GL_STENCIL_ATTACHMENT:
hasRequiredBits = format->s;
break;
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
MOZ_ASSERT(!webgl->IsWebGL2());
hasRequiredBits = (format->d && format->s);
break;
default:
MOZ_ASSERT(mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0);
hasRequiredBits = format->IsColorFormat();
break;
}
if (!hasRequiredBits) {
AttachmentName(out_info);
out_info->AppendLiteral("'s format is missing required color/depth/stencil bits");
return false;
}
if (!webgl->IsWebGL2()) {
bool hasSurplusPlanes = false;
switch (mAttachmentPoint) {
case LOCAL_GL_DEPTH_ATTACHMENT:
hasSurplusPlanes = format->s;
break;
case LOCAL_GL_STENCIL_ATTACHMENT:
hasSurplusPlanes = format->d;
break;
}
if (hasSurplusPlanes) {
AttachmentName(out_info);
out_info->AppendLiteral("'s format has depth or stencil bits when it"
" shouldn't");
return false;
}
}
return true;
}
void
WebGLFBAttachPoint::Resolve(gl::GLContext* gl) const
{
if (!HasImage())
return;
if (Renderbuffer()) {
Renderbuffer()->DoFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint);
return;
}
MOZ_ASSERT(Texture());
MOZ_ASSERT(gl == Texture()->mContext->GL());
const auto& texName = Texture()->mGLName;
////
const auto fnAttach2D = [&](GLenum attachmentPoint) {
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, attachmentPoint,
mTexImageTarget.get(), texName, mTexImageLevel);
};
////
switch (mTexImageTarget.get()) {
case LOCAL_GL_TEXTURE_2D:
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if (mAttachmentPoint == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
fnAttach2D(LOCAL_GL_DEPTH_ATTACHMENT);
fnAttach2D(LOCAL_GL_STENCIL_ATTACHMENT);
} else {
fnAttach2D(mAttachmentPoint);
}
break;
case LOCAL_GL_TEXTURE_2D_ARRAY:
case LOCAL_GL_TEXTURE_3D:
// If we have fFramebufferTextureLayer, we can rely on having
// DEPTH_STENCIL_ATTACHMENT.
gl->fFramebufferTextureLayer(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint, texName,
mTexImageLevel, mTexImageLayer);
break;
}
}
JS::Value
WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSContext* cx,
GLenum target, GLenum attachment, GLenum pname,
ErrorResult* const out_error) const
{
const bool hasAttachment = (mTexturePtr || mRenderbufferPtr);
if (!hasAttachment) {
// Divergent between GLES 3 and 2.
// GLES 2.0.25 p127:
// "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then querying any
// other pname will generate INVALID_ENUM."
// GLES 3.0.4 p240:
// "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no framebuffer is
// bound to target. In this case querying pname
// FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other queries
// will generate an INVALID_OPERATION error."
switch (pname) {
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
return JS::Int32Value(LOCAL_GL_NONE);
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
if (webgl->IsWebGL2())
return JS::NullValue();
break;
default:
break;
}
nsCString attachmentName;
WebGLContext::EnumName(attachment, &attachmentName);
if (webgl->IsWebGL2()) {
webgl->ErrorInvalidOperation("%s: No attachment at %s.", funcName,
attachmentName.BeginReading());
} else {
webgl->ErrorInvalidEnum("%s: No attachment at %s.", funcName,
attachmentName.BeginReading());
}
return JS::NullValue();
}
bool isPNameValid = false;
switch (pname) {
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
return JS::Int32Value(mTexturePtr ? LOCAL_GL_TEXTURE
: LOCAL_GL_RENDERBUFFER);
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
return (mTexturePtr ? webgl->WebGLObjectAsJSValue(cx, mTexturePtr.get(),
*out_error)
: webgl->WebGLObjectAsJSValue(cx, mRenderbufferPtr.get(),
*out_error));
//////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
if (mTexturePtr)
return JS::Int32Value(MipLevel());
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
if (mTexturePtr) {
GLenum face = 0;
if (mTexturePtr->Target() == LOCAL_GL_TEXTURE_CUBE_MAP) {
face = ImageTarget().get();
}
return JS::Int32Value(face);
}
break;
//////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
if (webgl->IsWebGL2() && mTexturePtr) {
int32_t layer = 0;
if (ImageTarget() == LOCAL_GL_TEXTURE_2D_ARRAY ||
ImageTarget() == LOCAL_GL_TEXTURE_3D)
{
layer = Layer();
}
return JS::Int32Value(layer);
}
break;
//////
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
isPNameValid = webgl->IsWebGL2();
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
isPNameValid = (webgl->IsWebGL2() ||
webgl->IsExtensionEnabled(WebGLExtensionID::EXT_sRGB));
break;
}
if (!isPNameValid) {
webgl->ErrorInvalidEnum("%s: Invalid pname: 0x%04x", funcName, pname);
return JS::NullValue();
}
const auto usage = Format();
if (!usage) {
if (pname == LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING)
return JS::NumberValue(LOCAL_GL_LINEAR);
return JS::NullValue();
}
auto format = usage->format;
GLint ret = 0;
switch (pname) {
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
ret = format->r;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
ret = format->g;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
ret = format->b;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
ret = format->a;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
ret = format->d;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
ret = format->s;
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
ret = (format->isSRGB ? LOCAL_GL_SRGB
: LOCAL_GL_LINEAR);
break;
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
MOZ_ASSERT(attachment != LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
if (format->componentType == webgl::ComponentType::Special) {
// Special format is used for DS mixed format(e.g. D24S8 and D32FS8).
MOZ_ASSERT(format->unsizedFormat == webgl::UnsizedFormat::DEPTH_STENCIL);
MOZ_ASSERT(attachment == LOCAL_GL_DEPTH_ATTACHMENT ||
attachment == LOCAL_GL_STENCIL_ATTACHMENT);
if (attachment == LOCAL_GL_DEPTH_ATTACHMENT) {
switch (format->effectiveFormat) {
case webgl::EffectiveFormat::DEPTH24_STENCIL8:
format = webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT24);
break;
case webgl::EffectiveFormat::DEPTH32F_STENCIL8:
format = webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT32F);
break;
default:
MOZ_ASSERT(false, "no matched DS format");
break;
}
} else if (attachment == LOCAL_GL_STENCIL_ATTACHMENT) {
switch (format->effectiveFormat) {
case webgl::EffectiveFormat::DEPTH24_STENCIL8:
case webgl::EffectiveFormat::DEPTH32F_STENCIL8:
format = webgl::GetFormat(webgl::EffectiveFormat::STENCIL_INDEX8);
break;
default:
MOZ_ASSERT(false, "no matched DS format");
break;
}
}
}
switch (format->componentType) {
case webgl::ComponentType::None:
ret = LOCAL_GL_NONE;
break;
case webgl::ComponentType::Int:
ret = LOCAL_GL_INT;
break;
case webgl::ComponentType::UInt:
ret = LOCAL_GL_UNSIGNED_INT;
break;
case webgl::ComponentType::NormInt:
ret = LOCAL_GL_SIGNED_NORMALIZED;
break;
case webgl::ComponentType::NormUInt:
ret = LOCAL_GL_UNSIGNED_NORMALIZED;
break;
case webgl::ComponentType::Float:
ret = LOCAL_GL_FLOAT;
break;
default:
MOZ_ASSERT(false, "No matched component type");
break;
}
break;
default:
MOZ_ASSERT(false, "Missing case.");
break;
}
return JS::Int32Value(ret);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// WebGLFramebuffer
WebGLFramebuffer::WebGLFramebuffer(WebGLContext* webgl, GLuint fbo)
: WebGLRefCountedObject(webgl)
, mGLName(fbo)
, mDepthAttachment(this, LOCAL_GL_DEPTH_ATTACHMENT)
, mStencilAttachment(this, LOCAL_GL_STENCIL_ATTACHMENT)
, mDepthStencilAttachment(this, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
{
mContext->mFramebuffers.insertBack(this);
size_t i = 0;
for (auto& cur : mColorAttachments) {
new (&cur) WebGLFBAttachPoint(this, LOCAL_GL_COLOR_ATTACHMENT0 + i);
i++;
}
mColorDrawBuffers.push_back(&mColorAttachments[0]);
mColorReadBuffer = &mColorAttachments[0];
}
void
WebGLFramebuffer::Delete()
{
InvalidateFramebufferStatus();
mDepthAttachment.Clear();
mStencilAttachment.Clear();
mDepthStencilAttachment.Clear();
for (auto& cur : mColorAttachments) {
cur.Clear();
}
mContext->MakeContextCurrent();
mContext->gl->fDeleteFramebuffers(1, &mGLName);
LinkedListElement<WebGLFramebuffer>::removeFrom(mContext->mFramebuffers);
}
////
Maybe<WebGLFBAttachPoint*>
WebGLFramebuffer::GetColorAttachPoint(GLenum attachPoint)
{
if (attachPoint == LOCAL_GL_NONE)
return Some<WebGLFBAttachPoint*>(nullptr);
if (attachPoint < LOCAL_GL_COLOR_ATTACHMENT0)
return Nothing();
const size_t colorId = attachPoint - LOCAL_GL_COLOR_ATTACHMENT0;
MOZ_ASSERT(mContext->mImplMaxColorAttachments <= kMaxColorAttachments);
if (colorId >= mContext->mImplMaxColorAttachments)
return Nothing();
return Some(&mColorAttachments[colorId]);
}
Maybe<WebGLFBAttachPoint*>
WebGLFramebuffer::GetAttachPoint(GLenum attachPoint)
{
switch (attachPoint) {
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
return Some(&mDepthStencilAttachment);
case LOCAL_GL_DEPTH_ATTACHMENT:
return Some(&mDepthAttachment);
case LOCAL_GL_STENCIL_ATTACHMENT:
return Some(&mStencilAttachment);
default:
return GetColorAttachPoint(attachPoint);
}
}
#define FOR_EACH_ATTACHMENT(X) \
X(mDepthAttachment); \
X(mStencilAttachment); \
X(mDepthStencilAttachment); \
\
for (auto& cur : mColorAttachments) { \
X(cur); \
}
void
WebGLFramebuffer::DetachTexture(const WebGLTexture* tex)
{
const auto fnDetach = [&](WebGLFBAttachPoint& attach) {
if (attach.Texture() == tex) {
attach.Clear();
}
};
FOR_EACH_ATTACHMENT(fnDetach)
}
void
WebGLFramebuffer::DetachRenderbuffer(const WebGLRenderbuffer* rb)
{
const auto fnDetach = [&](WebGLFBAttachPoint& attach) {
if (attach.Renderbuffer() == rb) {
attach.Clear();
}
};
FOR_EACH_ATTACHMENT(fnDetach)
}
////////////////////////////////////////////////////////////////////////////////
// Completeness
bool
WebGLFramebuffer::HasDefinedAttachments() const
{
bool hasAttachments = false;
const auto func = [&](const WebGLFBAttachPoint& attach) {
hasAttachments |= attach.IsDefined();
};
FOR_EACH_ATTACHMENT(func)
return hasAttachments;
}
bool
WebGLFramebuffer::HasIncompleteAttachments(nsCString* const out_info) const
{
bool hasIncomplete = false;
const auto func = [&](const WebGLFBAttachPoint& cur) {
if (!cur.IsDefined())
return; // Not defined, so can't count as incomplete.
hasIncomplete |= !cur.IsComplete(mContext, out_info);
};
FOR_EACH_ATTACHMENT(func)
return hasIncomplete;
}
bool
WebGLFramebuffer::AllImageRectsMatch() const
{
MOZ_ASSERT(HasDefinedAttachments());
DebugOnly<nsCString> fbStatusInfo;
MOZ_ASSERT(!HasIncompleteAttachments(&fbStatusInfo));
bool needsInit = true;
uint32_t width = 0;
uint32_t height = 0;
bool hasMismatch = false;
const auto func = [&](const WebGLFBAttachPoint& attach) {
if (!attach.HasImage())
return;
uint32_t curWidth;
uint32_t curHeight;
attach.Size(&curWidth, &curHeight);
if (needsInit) {
needsInit = false;
width = curWidth;
height = curHeight;
return;
}
hasMismatch |= (curWidth != width ||
curHeight != height);
};
FOR_EACH_ATTACHMENT(func)
return !hasMismatch;
}
bool
WebGLFramebuffer::AllImageSamplesMatch() const
{
MOZ_ASSERT(HasDefinedAttachments());
DebugOnly<nsCString> fbStatusInfo;
MOZ_ASSERT(!HasIncompleteAttachments(&fbStatusInfo));
bool needsInit = true;
uint32_t samples = 0;
bool hasMismatch = false;
const auto func = [&](const WebGLFBAttachPoint& attach) {
if (!attach.HasImage())
return;
const uint32_t curSamples = attach.Samples();
if (needsInit) {
needsInit = false;
samples = curSamples;
return;
}
hasMismatch |= (curSamples != samples);
};
FOR_EACH_ATTACHMENT(func)
return !hasMismatch;
}
#undef FOR_EACH_ATTACHMENT
FBStatus
WebGLFramebuffer::PrecheckFramebufferStatus(nsCString* const out_info) const
{
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
if (!HasDefinedAttachments())
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; // No attachments
if (HasIncompleteAttachments(out_info))
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
if (!AllImageRectsMatch())
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; // Inconsistent sizes
if (!AllImageSamplesMatch())
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; // Inconsistent samples
if (mContext->IsWebGL2()) {
MOZ_ASSERT(!mDepthStencilAttachment.IsDefined());
} else {
const auto depthOrStencilCount = int(mDepthAttachment.IsDefined()) +
int(mStencilAttachment.IsDefined()) +
int(mDepthStencilAttachment.IsDefined());
if (depthOrStencilCount > 1)
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
}
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
}
////////////////////////////////////////
// Validation
bool
WebGLFramebuffer::ValidateAndInitAttachments(const char* funcName)
{
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
const auto fbStatus = CheckFramebufferStatus(funcName);
if (fbStatus == LOCAL_GL_FRAMEBUFFER_COMPLETE)
return true;
mContext->ErrorInvalidFramebufferOperation("%s: Framebuffer must be"
" complete.",
funcName);
return false;
}
bool
WebGLFramebuffer::ValidateClearBufferType(const char* funcName, GLenum buffer,
uint32_t drawBuffer, GLenum funcType) const
{
if (buffer != LOCAL_GL_COLOR)
return true;
const auto& attach = mColorAttachments[drawBuffer];
if (!attach.IsDefined())
return true;
if (!count(mColorDrawBuffers.begin(), mColorDrawBuffers.end(), &attach))
return true; // DRAW_BUFFERi set to NONE.
GLenum attachType;
switch (attach.Format()->format->componentType) {
case webgl::ComponentType::Int:
attachType = LOCAL_GL_INT;
break;
case webgl::ComponentType::UInt:
attachType = LOCAL_GL_UNSIGNED_INT;
break;
default:
attachType = LOCAL_GL_FLOAT;
break;
}
if (attachType != funcType) {
mContext->ErrorInvalidOperation("%s: This attachment is of type 0x%04x, but"
" this function is of type 0x%04x.",
funcName, attachType, funcType);
return false;
}
return true;
}
bool
WebGLFramebuffer::ValidateForRead(const char* funcName,
const webgl::FormatUsageInfo** const out_format,
uint32_t* const out_width, uint32_t* const out_height)
{
if (!ValidateAndInitAttachments(funcName))
return false;
if (!mColorReadBuffer) {
mContext->ErrorInvalidOperation("%s: READ_BUFFER must not be NONE.", funcName);
return false;
}
if (!mColorReadBuffer->IsDefined()) {
mContext->ErrorInvalidOperation("%s: The READ_BUFFER attachment is not defined.",
funcName);
return false;
}
if (mColorReadBuffer->Samples()) {
mContext->ErrorInvalidOperation("%s: The READ_BUFFER attachment is multisampled.",
funcName);
return false;
}
*out_format = mColorReadBuffer->Format();
mColorReadBuffer->Size(out_width, out_height);
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Resolution and caching
void
WebGLFramebuffer::ResolveAttachments() const
{
const auto& gl = mContext->gl;
////
// Nuke attachment points.
for (uint32_t i = 0; i < mContext->mImplMaxColorAttachments; i++) {
const GLenum attachEnum = LOCAL_GL_COLOR_ATTACHMENT0 + i;
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, attachEnum,
LOCAL_GL_RENDERBUFFER, 0);
}
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT,
LOCAL_GL_RENDERBUFFER, 0);
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_STENCIL_ATTACHMENT,
LOCAL_GL_RENDERBUFFER, 0);
////
for (const auto& attach : mColorAttachments) {
attach.Resolve(gl);
}
mDepthAttachment.Resolve(gl);
mStencilAttachment.Resolve(gl);
mDepthStencilAttachment.Resolve(gl);
}
bool
WebGLFramebuffer::ResolveAttachmentData(const char* funcName) const
{
//////
// Check if we need to initialize anything
const auto fnIs3D = [&](const WebGLFBAttachPoint& attach) {
const auto& tex = attach.Texture();
if (!tex)
return false;
const auto& info = tex->ImageInfoAt(attach.ImageTarget(), attach.MipLevel());
if (info.mDepth == 1)
return false;
return true;
};
uint32_t clearBits = 0;
std::vector<const WebGLFBAttachPoint*> attachmentsToClear;
std::vector<const WebGLFBAttachPoint*> colorAttachmentsToClear;
std::vector<const WebGLFBAttachPoint*> tex3DAttachmentsToInit;
const auto fnGather = [&](const WebGLFBAttachPoint& attach, GLenum attachClearBits) {
if (!attach.HasUninitializedImageData())
return false;
if (fnIs3D(attach)) {
tex3DAttachmentsToInit.push_back(&attach);
return false;
}
clearBits |= attachClearBits;
attachmentsToClear.push_back(&attach);
return true;
};
//////
for (auto& cur : mColorDrawBuffers) {
if (fnGather(*cur, LOCAL_GL_COLOR_BUFFER_BIT)) {
colorAttachmentsToClear.push_back(cur);
}
}
fnGather(mDepthAttachment, LOCAL_GL_DEPTH_BUFFER_BIT);
fnGather(mStencilAttachment, LOCAL_GL_STENCIL_BUFFER_BIT);
fnGather(mDepthStencilAttachment, LOCAL_GL_DEPTH_BUFFER_BIT |
LOCAL_GL_STENCIL_BUFFER_BIT);
//////
for (const auto& attach : tex3DAttachmentsToInit) {
const auto& tex = attach->Texture();
if (!tex->InitializeImageData(funcName, attach->ImageTarget(),
attach->MipLevel()))
{
return false;
}
}
if (clearBits) {
const auto fnDrawBuffers = [&](const std::vector<const WebGLFBAttachPoint*>& src)
{
std::vector<GLenum> enumList;
for (const auto& cur : src) {
const auto& attachEnum = cur->mAttachmentPoint;
const GLenum attachId = attachEnum - LOCAL_GL_COLOR_ATTACHMENT0;
while (enumList.size() < attachId) {
enumList.push_back(LOCAL_GL_NONE);
}
enumList.push_back(attachEnum);
}
mContext->gl->fDrawBuffers(enumList.size(), enumList.data());
};
////
// Clear
mContext->MakeContextCurrent();
const bool hasDrawBuffers = mContext->HasDrawBuffers();
if (hasDrawBuffers) {
fnDrawBuffers(colorAttachmentsToClear);
}
{
gl::ScopedBindFramebuffer autoBind(mContext->gl, mGLName);
mContext->ForceClearFramebufferWithDefaultValues(clearBits, false);
}
if (hasDrawBuffers) {
RefreshDrawBuffers();
}
// Mark initialized.
for (const auto& cur : attachmentsToClear) {
cur->SetImageDataStatus(WebGLImageDataStatus::InitializedImageData);
}
}
return true;
}
WebGLFramebuffer::ResolvedData::ResolvedData(const WebGLFramebuffer& parent)
{
texDrawBuffers.reserve(parent.mColorDrawBuffers.size() + 2); // +2 for depth+stencil.
const auto fnCommon = [&](const WebGLFBAttachPoint& attach) {
if (!attach.IsDefined())
return false;
if (attach.Texture()) {
texDrawBuffers.push_back(&attach);
}
return true;
};
////
const auto fnDepthStencil = [&](const WebGLFBAttachPoint& attach) {
if (!fnCommon(attach))
return;
drawSet.insert(WebGLFBAttachPoint::Ordered(attach));
readSet.insert(WebGLFBAttachPoint::Ordered(attach));
};
fnDepthStencil(parent.mDepthAttachment);
fnDepthStencil(parent.mStencilAttachment);
fnDepthStencil(parent.mDepthStencilAttachment);
////
for (const auto& pAttach : parent.mColorDrawBuffers) {
const auto& attach = *pAttach;
if (!fnCommon(attach))
return;
drawSet.insert(WebGLFBAttachPoint::Ordered(attach));
}
if (parent.mColorReadBuffer) {
const auto& attach = *parent.mColorReadBuffer;
if (!fnCommon(attach))
return;
readSet.insert(WebGLFBAttachPoint::Ordered(attach));
}
}
void
WebGLFramebuffer::RefreshResolvedData()
{
if (mResolvedCompleteData) {
mResolvedCompleteData.reset(new ResolvedData(*this));
}
}
////////////////////////////////////////////////////////////////////////////////
// Entrypoints
FBStatus
WebGLFramebuffer::CheckFramebufferStatus(const char* funcName)
{
if (IsResolvedComplete())
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
// Ok, let's try to resolve it!
nsCString statusInfo;
FBStatus ret = PrecheckFramebufferStatus(&statusInfo);
do {
if (ret != LOCAL_GL_FRAMEBUFFER_COMPLETE)
break;
// Looks good on our end. Let's ask the driver.
gl::GLContext* const gl = mContext->gl;
gl->MakeCurrent();
const ScopedFBRebinder autoFB(mContext);
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGLName);
////
ResolveAttachments(); // OK, attach everything properly!
RefreshDrawBuffers();
RefreshReadBuffer();
ret = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
////
if (ret != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
const nsPrintfCString text("Bad status according to the driver: 0x%04x",
ret.get());
statusInfo = text;
break;
}
if (!ResolveAttachmentData(funcName)) {
ret = LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
statusInfo.AssignLiteral("Failed to lazily-initialize attachment data.");
break;
}
mResolvedCompleteData.reset(new ResolvedData(*this));
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
} while (false);
MOZ_ASSERT(ret != LOCAL_GL_FRAMEBUFFER_COMPLETE);
mContext->GenerateWarning("%s: Framebuffer not complete. (status: 0x%04x) %s",
funcName, ret.get(), statusInfo.BeginReading());
return ret;
}
////
void
WebGLFramebuffer::RefreshDrawBuffers() const
{
const auto& gl = mContext->gl;
if (!gl->IsSupported(gl::GLFeature::draw_buffers))
return;
// Prior to GL4.1, having a no-image FB attachment that's selected by DrawBuffers
// yields a framebuffer status of FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER.
// We could workaround this only on affected versions, but it's easier be
// unconditional.
std::vector<GLenum> driverBuffers(mContext->mImplMaxDrawBuffers, LOCAL_GL_NONE);
for (const auto& attach : mColorDrawBuffers) {
if (attach->HasImage()) {
const uint32_t index = attach->mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
driverBuffers[index] = attach->mAttachmentPoint;
}
}
gl->fDrawBuffers(driverBuffers.size(), driverBuffers.data());
}
void
WebGLFramebuffer::RefreshReadBuffer() const
{
const auto& gl = mContext->gl;
if (!gl->IsSupported(gl::GLFeature::read_buffer))
return;
// Prior to GL4.1, having a no-image FB attachment that's selected by ReadBuffer
// yields a framebuffer status of FRAMEBUFFER_INCOMPLETE_READ_BUFFER.
// We could workaround this only on affected versions, but it's easier be
// unconditional.
GLenum driverBuffer = LOCAL_GL_NONE;
if (mColorReadBuffer && mColorReadBuffer->HasImage()) {
driverBuffer = mColorReadBuffer->mAttachmentPoint;
}
gl->fReadBuffer(driverBuffer);
}
////
void
WebGLFramebuffer::DrawBuffers(const char* funcName, const dom::Sequence<GLenum>& buffers)
{
if (buffers.Length() > mContext->mImplMaxDrawBuffers) {
// "An INVALID_VALUE error is generated if `n` is greater than MAX_DRAW_BUFFERS."
mContext->ErrorInvalidValue("%s: `buffers` must have a length <="
" MAX_DRAW_BUFFERS.", funcName);
return;
}
std::vector<const WebGLFBAttachPoint*> newColorDrawBuffers;
newColorDrawBuffers.reserve(buffers.Length());
for (size_t i = 0; i < buffers.Length(); i++) {
// "If the GL is bound to a draw framebuffer object, the `i`th buffer listed in
// bufs must be COLOR_ATTACHMENTi or NONE. Specifying a buffer out of order,
// BACK, or COLOR_ATTACHMENTm where `m` is greater than or equal to the value of
// MAX_COLOR_ATTACHMENTS, will generate the error INVALID_OPERATION.
// WEBGL_draw_buffers:
// "The value of the MAX_COLOR_ATTACHMENTS_WEBGL parameter must be greater than or
// equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter."
// This means that if buffers.Length() isn't larger than MaxDrawBuffers, it won't
// be larger than MaxColorAttachments.
const auto& cur = buffers[i];
if (cur == LOCAL_GL_COLOR_ATTACHMENT0 + i) {
const auto& attach = mColorAttachments[i];
newColorDrawBuffers.push_back(&attach);
} else if (cur != LOCAL_GL_NONE) {
const bool isColorEnum = (cur >= LOCAL_GL_COLOR_ATTACHMENT0 &&
cur < mContext->LastColorAttachmentEnum());
if (cur != LOCAL_GL_BACK &&
!isColorEnum)
{
mContext->ErrorInvalidEnum("%s: Unexpected enum in buffers.", funcName);
return;
}
mContext->ErrorInvalidOperation("%s: `buffers[i]` must be NONE or"
" COLOR_ATTACHMENTi.",
funcName);
return;
}
}
////
mContext->MakeContextCurrent();
mColorDrawBuffers.swap(newColorDrawBuffers);
RefreshDrawBuffers(); // Calls glDrawBuffers.
RefreshResolvedData();
}
void
WebGLFramebuffer::ReadBuffer(const char* funcName, GLenum attachPoint)
{
const auto& maybeAttach = GetColorAttachPoint(attachPoint);
if (!maybeAttach) {
const char text[] = "%s: `mode` must be a COLOR_ATTACHMENTi, for 0 <= i <"
" MAX_DRAW_BUFFERS.";
if (attachPoint == LOCAL_GL_BACK) {
mContext->ErrorInvalidOperation(text, funcName);
} else {
mContext->ErrorInvalidEnum(text, funcName);
}
return;
}
const auto& attach = maybeAttach.value(); // Might be nullptr.
////
mContext->MakeContextCurrent();
mColorReadBuffer = attach;
RefreshReadBuffer(); // Calls glReadBuffer.
RefreshResolvedData();
}
////
void
WebGLFramebuffer::FramebufferRenderbuffer(const char* funcName, GLenum attachEnum,
GLenum rbtarget, WebGLRenderbuffer* rb)
{
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
// `attachment`
const auto maybeAttach = GetAttachPoint(attachEnum);
if (!maybeAttach || !maybeAttach.value()) {
mContext->ErrorInvalidEnum("%s: Bad `attachment`: 0x%x.", funcName, attachEnum);
return;
}
const auto& attach = maybeAttach.value();
// `rbTarget`
if (rbtarget != LOCAL_GL_RENDERBUFFER) {
mContext->ErrorInvalidEnumInfo("framebufferRenderbuffer: rbtarget:", rbtarget);
return;
}
// `rb`
if (rb && !mContext->ValidateObject("framebufferRenderbuffer: rb", *rb))
return;
// End of validation.
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
mDepthAttachment.SetRenderbuffer(rb);
mStencilAttachment.SetRenderbuffer(rb);
} else {
attach->SetRenderbuffer(rb);
}
InvalidateFramebufferStatus();
}
void
WebGLFramebuffer::FramebufferTexture2D(const char* funcName, GLenum attachEnum,
GLenum texImageTarget, WebGLTexture* tex,
GLint level)
{
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
// `attachment`
const auto maybeAttach = GetAttachPoint(attachEnum);
if (!maybeAttach || !maybeAttach.value()) {
mContext->ErrorInvalidEnum("%s: Bad `attachment`: 0x%x.", funcName, attachEnum);
return;
}
const auto& attach = maybeAttach.value();
// `texImageTarget`
if (texImageTarget != LOCAL_GL_TEXTURE_2D &&
(texImageTarget < LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
texImageTarget > LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))
{
mContext->ErrorInvalidEnumInfo("framebufferTexture2D: texImageTarget:",
texImageTarget);
return;
}
// `texture`
if (tex) {
if (!mContext->ValidateObject("framebufferTexture2D: texture", *tex))
return;
if (!tex->HasEverBeenBound()) {
mContext->ErrorInvalidOperation("%s: `texture` has never been bound.",
funcName);
return;
}
const TexTarget destTexTarget = TexImageTargetToTexTarget(texImageTarget);
if (tex->Target() != destTexTarget) {
mContext->ErrorInvalidOperation("%s: Mismatched texture and texture target.",
funcName);
return;
}
}
// `level`
if (level < 0)
return mContext->ErrorInvalidValue("%s: `level` must not be negative.", funcName);
if (mContext->IsWebGL2()) {
/* GLES 3.0.4 p208:
* If textarget is one of TEXTURE_CUBE_MAP_POSITIVE_X,
* TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z,
* TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_Y,
* or TEXTURE_CUBE_MAP_NEGATIVE_Z, then level must be greater
* than or equal to zero and less than or equal to log2 of the
* value of MAX_CUBE_MAP_TEXTURE_SIZE. If textarget is TEXTURE_2D,
* level must be greater than or equal to zero and no larger than
* log2 of the value of MAX_TEXTURE_SIZE. Otherwise, an
* INVALID_VALUE error is generated.
*/
if (texImageTarget == LOCAL_GL_TEXTURE_2D) {
if (uint32_t(level) > FloorLog2(mContext->mImplMaxTextureSize))
return mContext->ErrorInvalidValue("%s: `level` is too large.", funcName);
} else {
MOZ_ASSERT(texImageTarget >= LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
texImageTarget <= LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
if (uint32_t(level) > FloorLog2(mContext->mImplMaxCubeMapTextureSize))
return mContext->ErrorInvalidValue("%s: `level` is too large.", funcName);
}
} else if (level != 0) {
return mContext->ErrorInvalidValue("%s: `level` must be 0.", funcName);
}
// End of validation.
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
mDepthAttachment.SetTexImage(tex, texImageTarget, level);
mStencilAttachment.SetTexImage(tex, texImageTarget, level);
} else {
attach->SetTexImage(tex, texImageTarget, level);
}
InvalidateFramebufferStatus();
}
void
WebGLFramebuffer::FramebufferTextureLayer(const char* funcName, GLenum attachEnum,
WebGLTexture* tex, GLint level, GLint layer)
{
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
// `attachment`
const auto maybeAttach = GetAttachPoint(attachEnum);
if (!maybeAttach || !maybeAttach.value()) {
mContext->ErrorInvalidEnum("%s: Bad `attachment`: 0x%x.", funcName, attachEnum);
return;
}
const auto& attach = maybeAttach.value();
// `level`, `layer`
if (layer < 0)
return mContext->ErrorInvalidValue("%s: `layer` must be >= 0.", funcName);
if (level < 0)
return mContext->ErrorInvalidValue("%s: `level` must be >= 0.", funcName);
// `texture`
TexImageTarget texImageTarget = LOCAL_GL_TEXTURE_3D;
if (tex) {
if (!mContext->ValidateObject("framebufferTextureLayer: texture", *tex))
return;
if (!tex->HasEverBeenBound()) {
mContext->ErrorInvalidOperation("%s: `texture` has never been bound.",
funcName);
return;
}
texImageTarget = tex->Target().get();
switch (texImageTarget.get()) {
case LOCAL_GL_TEXTURE_3D:
if (uint32_t(layer) >= mContext->mImplMax3DTextureSize) {
mContext->ErrorInvalidValue("%s: `layer` must be < %s.", funcName,
"MAX_3D_TEXTURE_SIZE");
return;
}
if (uint32_t(level) > FloorLog2(mContext->mImplMax3DTextureSize)) {
mContext->ErrorInvalidValue("%s: `level` must be <= log2(%s).", funcName,
"MAX_3D_TEXTURE_SIZE");
return;
}
break;
case LOCAL_GL_TEXTURE_2D_ARRAY:
if (uint32_t(layer) >= mContext->mImplMaxArrayTextureLayers) {
mContext->ErrorInvalidValue("%s: `layer` must be < %s.", funcName,
"MAX_ARRAY_TEXTURE_LAYERS");
return;
}
if (uint32_t(level) > FloorLog2(mContext->mImplMaxTextureSize)) {
mContext->ErrorInvalidValue("%s: `level` must be <= log2(%s).", funcName,
"MAX_TEXTURE_SIZE");
return;
}
break;
default:
mContext->ErrorInvalidOperation("%s: `texture` must be a TEXTURE_3D or"
" TEXTURE_2D_ARRAY.",
funcName);
return;
}
}
// End of validation.
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
mDepthAttachment.SetTexImage(tex, texImageTarget, level, layer);
mStencilAttachment.SetTexImage(tex, texImageTarget, level, layer);
} else {
attach->SetTexImage(tex, texImageTarget, level, layer);
}
InvalidateFramebufferStatus();
}
JS::Value
WebGLFramebuffer::GetAttachmentParameter(const char* funcName, JSContext* cx,
GLenum target, GLenum attachEnum, GLenum pname,
ErrorResult* const out_error)
{
const auto maybeAttach = GetAttachPoint(attachEnum);
if (!maybeAttach || attachEnum == LOCAL_GL_NONE) {
mContext->ErrorInvalidEnum("%s: Can only query COLOR_ATTACHMENTi,"
" DEPTH_ATTACHMENT, DEPTH_STENCIL_ATTACHMENT, or"
" STENCIL_ATTACHMENT for a framebuffer.",
funcName);
return JS::NullValue();
}
auto attach = maybeAttach.value();
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
// There are a couple special rules for this one.
if (pname == LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) {
mContext->ErrorInvalidOperation("%s: Querying"
" FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
" against DEPTH_STENCIL_ATTACHMENT is an"
" error.",
funcName);
return JS::NullValue();
}
if (mDepthAttachment.Renderbuffer() != mStencilAttachment.Renderbuffer() ||
mDepthAttachment.Texture() != mStencilAttachment.Texture())
{
mContext->ErrorInvalidOperation("%s: DEPTH_ATTACHMENT and STENCIL_ATTACHMENT"
" have different objects bound.",
funcName);
return JS::NullValue();
}
attach = &mDepthAttachment;
}
return attach->GetParameter(funcName, mContext, cx, target, attachEnum, pname,
out_error);
}
////////////////////
static void
GetBackbufferFormats(const WebGLContext* webgl,
const webgl::FormatInfo** const out_color,
const webgl::FormatInfo** const out_depth,
const webgl::FormatInfo** const out_stencil)
{
const auto& options = webgl->Options();
const auto effFormat = (options.alpha ? webgl::EffectiveFormat::RGBA8
: webgl::EffectiveFormat::RGB8);
*out_color = webgl::GetFormat(effFormat);
*out_depth = nullptr;
*out_stencil = nullptr;
if (options.depth && options.stencil) {
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH24_STENCIL8);
*out_stencil = *out_depth;
} else {
if (options.depth) {
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT16);
}
if (options.stencil) {
*out_stencil = webgl::GetFormat(webgl::EffectiveFormat::STENCIL_INDEX8);
}
}
}
/*static*/ void
WebGLFramebuffer::BlitFramebuffer(WebGLContext* webgl,
const WebGLFramebuffer* srcFB, GLint srcX0, GLint srcY0,
GLint srcX1, GLint srcY1,
const WebGLFramebuffer* dstFB, GLint dstX0, GLint dstY0,
GLint dstX1, GLint dstY1,
GLbitfield mask, GLenum filter)
{
const char funcName[] = "blitFramebuffer";
const auto& gl = webgl->gl;
////
// Collect data
const auto fnGetDepthAndStencilAttach = [](const WebGLFramebuffer* fb,
const WebGLFBAttachPoint** const out_depth,
const WebGLFBAttachPoint** const out_stencil)
{
*out_depth = nullptr;
*out_stencil = nullptr;
if (!fb)
return;
if (fb->mDepthStencilAttachment.IsDefined()) {
*out_depth = *out_stencil = &fb->mDepthStencilAttachment;
return;
}
if (fb->mDepthAttachment.IsDefined()) {
*out_depth = &fb->mDepthAttachment;
}
if (fb->mStencilAttachment.IsDefined()) {
*out_stencil = &fb->mStencilAttachment;
}
};
const WebGLFBAttachPoint* srcDepthAttach;
const WebGLFBAttachPoint* srcStencilAttach;
fnGetDepthAndStencilAttach(srcFB, &srcDepthAttach, &srcStencilAttach);
const WebGLFBAttachPoint* dstDepthAttach;
const WebGLFBAttachPoint* dstStencilAttach;
fnGetDepthAndStencilAttach(dstFB, &dstDepthAttach, &dstStencilAttach);
////
const auto fnGetFormat = [](const WebGLFBAttachPoint* cur,
bool* const out_hasSamples) -> const webgl::FormatInfo*
{
if (!cur || !cur->IsDefined())
return nullptr;
*out_hasSamples |= bool(cur->Samples());
return cur->Format()->format;
};
const auto fnNarrowComponentType = [&](const webgl::FormatInfo* format) {
switch (format->componentType) {
case webgl::ComponentType::NormInt:
case webgl::ComponentType::NormUInt:
return webgl::ComponentType::Float;
default:
return format->componentType;
}
};
bool srcHasSamples;
const webgl::FormatInfo* srcColorFormat;
webgl::ComponentType srcColorType = webgl::ComponentType::None;
const webgl::FormatInfo* srcDepthFormat;
const webgl::FormatInfo* srcStencilFormat;
if (srcFB) {
srcHasSamples = false;
srcColorFormat = fnGetFormat(srcFB->mColorReadBuffer, &srcHasSamples);
srcDepthFormat = fnGetFormat(srcDepthAttach, &srcHasSamples);
srcStencilFormat = fnGetFormat(srcStencilAttach, &srcHasSamples);
} else {
srcHasSamples = false; // Always false.
GetBackbufferFormats(webgl, &srcColorFormat, &srcDepthFormat, &srcStencilFormat);
}
if (srcColorFormat) {
srcColorType = fnNarrowComponentType(srcColorFormat);
}
////
bool dstHasSamples;
const webgl::FormatInfo* dstDepthFormat;
const webgl::FormatInfo* dstStencilFormat;
bool dstHasColor = false;
bool colorFormatsMatch = true;
bool colorTypesMatch = true;
const auto fnCheckColorFormat = [&](const webgl::FormatInfo* dstFormat) {
MOZ_ASSERT(dstFormat->r || dstFormat->g || dstFormat->b || dstFormat->a);
dstHasColor = true;
colorFormatsMatch &= (dstFormat == srcColorFormat);
colorTypesMatch &= ( fnNarrowComponentType(dstFormat) == srcColorType );
};
if (dstFB) {
dstHasSamples = false;
for (const auto& cur : dstFB->mColorDrawBuffers) {
const auto& format = fnGetFormat(cur, &dstHasSamples);
if (!format)
continue;
fnCheckColorFormat(format);
}
dstDepthFormat = fnGetFormat(dstDepthAttach, &dstHasSamples);
dstStencilFormat = fnGetFormat(dstStencilAttach, &dstHasSamples);
} else {
dstHasSamples = bool(gl->Screen()->Samples());
const webgl::FormatInfo* dstColorFormat;
GetBackbufferFormats(webgl, &dstColorFormat, &dstDepthFormat, &dstStencilFormat);
fnCheckColorFormat(dstColorFormat);
}
////
// Clear unused buffer bits
if (mask & LOCAL_GL_COLOR_BUFFER_BIT &&
!srcColorFormat && !dstHasColor)
{
mask ^= LOCAL_GL_COLOR_BUFFER_BIT;
}
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
!srcDepthFormat && !dstDepthFormat)
{
mask ^= LOCAL_GL_DEPTH_BUFFER_BIT;
}
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
!srcStencilFormat && !dstStencilFormat)
{
mask ^= LOCAL_GL_STENCIL_BUFFER_BIT;
}
////
// Validation
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
if (srcColorFormat && filter == LOCAL_GL_LINEAR) {
const auto& type = srcColorFormat->componentType;
if (type == webgl::ComponentType::Int ||
type == webgl::ComponentType::UInt)
{
webgl->ErrorInvalidOperation("%s: `filter` is LINEAR and READ_BUFFER"
" contains integer data.",
funcName);
return;
}
}
if (!colorTypesMatch) {
webgl->ErrorInvalidOperation("%s: Color component types (fixed/float/uint/"
"int) must match.",
funcName);
return;
}
}
const GLbitfield depthAndStencilBits = LOCAL_GL_DEPTH_BUFFER_BIT |
LOCAL_GL_STENCIL_BUFFER_BIT;
if (bool(mask & depthAndStencilBits) &&
filter != LOCAL_GL_NEAREST)
{
webgl->ErrorInvalidOperation("%s: DEPTH_BUFFER_BIT and STENCIL_BUFFER_BIT can"
" only be used with NEAREST filtering.",
funcName);
return;
}
/* GLES 3.0.4, p199:
* Calling BlitFramebuffer will result in an INVALID_OPERATION error if
* mask includes DEPTH_BUFFER_BIT or STENCIL_BUFFER_BIT, and the source
* and destination depth and stencil buffer formats do not match.
*
* jgilbert: The wording is such that if only DEPTH_BUFFER_BIT is specified,
* the stencil formats must match. This seems wrong. It could be a spec bug,
* or I could be missing an interaction in one of the earlier paragraphs.
*/
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
dstDepthFormat && dstDepthFormat != srcDepthFormat)
{
webgl->ErrorInvalidOperation("%s: Depth buffer formats must match if selected.",
funcName);
return;
}
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
dstStencilFormat && dstStencilFormat != srcStencilFormat)
{
webgl->ErrorInvalidOperation("%s: Stencil buffer formats must match if selected.",
funcName);
return;
}
////
if (dstHasSamples) {
webgl->ErrorInvalidOperation("%s: DRAW_FRAMEBUFFER may not have multiple"
" samples.",
funcName);
return;
}
if (srcHasSamples) {
if (mask & LOCAL_GL_COLOR_BUFFER_BIT &&
dstHasColor && !colorFormatsMatch)
{
webgl->ErrorInvalidOperation("%s: Color buffer formats must match if"
" selected, when reading from a multisampled"
" source.",
funcName);
return;
}
if (dstX0 != srcX0 ||
dstX1 != srcX1 ||
dstY0 != srcY0 ||
dstY1 != srcY1)
{
webgl->ErrorInvalidOperation("%s: If the source is multisampled, then the"
" source and dest regions must match exactly.",
funcName);
return;
}
}
////
// Check for feedback
if (srcFB && dstFB) {
const WebGLFBAttachPoint* feedback = nullptr;
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
MOZ_ASSERT(srcFB->mColorReadBuffer->IsDefined());
for (const auto& cur : dstFB->mColorDrawBuffers) {
if (srcFB->mColorReadBuffer->IsEquivalentForFeedback(*cur)) {
feedback = cur;
break;
}
}
}
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
srcDepthAttach->IsEquivalentForFeedback(*dstDepthAttach))
{
feedback = dstDepthAttach;
}
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
srcStencilAttach->IsEquivalentForFeedback(*dstStencilAttach))
{
feedback = dstStencilAttach;
}
if (feedback) {
webgl->ErrorInvalidOperation("%s: Feedback detected into DRAW_FRAMEBUFFER's"
" 0x%04x attachment.",
funcName, feedback->mAttachmentPoint);
return;
}
} else if (!srcFB && !dstFB) {
webgl->ErrorInvalidOperation("%s: Feedback with default framebuffer.", funcName);
return;
}
////
gl->MakeCurrent();
webgl->OnBeforeReadCall();
WebGLContext::ScopedDrawCallWrapper wrapper(*webgl);
gl->fBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1,
mask, filter);
}
////////////////////////////////////////////////////////////////////////////////
// Goop.
JSObject*
WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
{
return dom::WebGLFramebufferBinding::Wrap(cx, this, givenProto);
}
inline void
ImplCycleCollectionUnlink(mozilla::WebGLFBAttachPoint& field)
{
field.Unlink();
}
inline void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
mozilla::WebGLFBAttachPoint& field,
const char* name,
uint32_t flags = 0)
{
CycleCollectionNoteChild(callback, field.Texture(), name, flags);
CycleCollectionNoteChild(callback, field.Renderbuffer(), name, flags);
}
template<typename C>
inline void
ImplCycleCollectionUnlink(C& field)
{
for (auto& cur : field) {
cur.Unlink();
}
}
template<typename C>
inline void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
C& field,
const char* name,
uint32_t flags = 0)
{
for (auto& cur : field) {
ImplCycleCollectionTraverse(callback, cur, name, flags);
}
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLFramebuffer,
mDepthAttachment,
mStencilAttachment,
mDepthStencilAttachment,
mColorAttachments)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLFramebuffer, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLFramebuffer, Release)
} // namespace mozilla
|