2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL Texture Attachment Format Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
13 <script src=
"../../../js/js-test-pre.js"></script>
14 <script src=
"../../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"2" height=
"2" style=
"width: 100px; height:100px; border: 1px solid black;"> </canvas>
24 var wtu
= WebGLTestUtils
;
25 var gl
= wtu
.create3DContext("canvas");
27 testFailed("context does not exist");
29 testPassed("context exists");
32 debug("Checking texture formats.");
34 var numValidFormats
= 0;
35 var clearColor
= [0.25, 0.5, 0.75, 0.25];
37 var floatToBits = function(value
, bits
) {
38 var range
= (1 << bits
) - 1;
41 result
= Math
.floor(Math
.floor(value
* range
) * 255 / range
);
44 //debug("v = " + value + ", bits = " + bits + ", range = " + range + ", result = " + result);
48 var testFormat = function(info
) {
50 debug("testing: " + info
.format
+ ", " + info
.type
);
52 var format
= gl
[info
.format
];
53 var type
= gl
[info
.type
];
55 gl
.texImage2D(gl
.TEXTURE_2D
,
57 format
, // internalFormat
64 var fbStatus
= gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
);
65 debug(wtu
.glEnumToString(gl
, fbStatus
));
66 if (fbStatus
!= gl
.FRAMEBUFFER_COMPLETE
) {
67 debug("format unsupported");
68 if (info
.mustBeFramebufferComplete
) {
69 testFailed(info
.format
+ " must be FRAMEBUFFER_COMPLETE");
76 var startExpected
= [0, 0, 0, info
.channels
[3] < 0 ? 255 : 0];
80 for (var ii
= 0; ii
< 4; ++ii
) {
82 var channel
= info
.channels
[ii
];
84 color
= ii
< 3 ? 0 : 255
86 color
= floatToBits(clearColor
[channel
], info
.bits
[ii
]);
89 tolerance
.push(channel
< 0 ? 0 : (1 + (1 << (8 - info
.bits
[ii
]))));
92 wtu
.checkCanvas(gl
, startExpected
, "should be " + startExpected
);
93 gl
.clear(gl
.COLOR_BUFFER_BIT
);
94 wtu
.checkCanvas(gl
, expected
, "should be " + expected
+ " with tolerance " + tolerance
, tolerance
);
99 type
: 'UNSIGNED_BYTE',
100 channels
: [0, 1, 2, 3],
102 mustBeFramebufferComplete
: true
105 type
: 'UNSIGNED_BYTE',
106 channels
: [-1, -1, -1, 3],
108 mustBeFramebufferComplete
: false
111 type
: 'UNSIGNED_BYTE',
112 channels
: [0, 1, 2, -1],
114 mustBeFramebufferComplete
: false
117 type
: 'UNSIGNED_SHORT_5_6_5',
118 channels
: [0, 1, 2, -1],
120 mustBeFramebufferComplete
: false
123 type
: 'UNSIGNED_SHORT_5_5_5_1',
124 channels
: [0, 1, 2, 3],
126 mustBeFramebufferComplete
: false
129 type
: 'UNSIGNED_SHORT_4_4_4_4',
130 channels
: [0, 1, 2, 3],
132 mustBeFramebufferComplete
: false
134 { format
: 'LUMINANCE',
135 type
: 'UNSIGNED_BYTE',
136 channels
: [0, 0, 0, -1],
138 mustBeFramebufferComplete
: false
140 { format
: 'LUMINANCE_ALPHA',
141 type
: 'UNSIGNED_BYTE',
142 channels
: [0, 0, 0, 3],
144 mustBeFramebufferComplete
: false
148 gl
.clearColor(clearColor
[0], clearColor
[1], clearColor
[2], clearColor
[3]);
149 var fbo
= gl
.createFramebuffer();
150 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
151 var tex
= gl
.createTexture();
152 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
153 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
154 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
155 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
156 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.LINEAR
);
157 gl
.framebufferTexture2D(
158 gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex
, 0);
160 for (var ii
= 0; ii
< validFormats
.length
; ++ii
) {
161 var info
= validFormats
[ii
];
166 shouldBeTrue("numValidFormats > 0");
167 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "there should be no errors");
171 var successfullyParsed
= true;
173 <script src=
"../../../js/js-test-post.js"></script>