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 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
12 <script src=
"../../js/js-test-pre.js"></script>
13 <script src=
"../../js/webgl-test-utils.js"></script>
16 <div id=
"description"></div>
17 <div id=
"console"></div>
20 var wtu
= WebGLTestUtils
;
21 description("Verify RGB/RGB8 textures and renderbuffers support");
23 var gl
= wtu
.create3DContext(undefined, undefined, 2);
25 function testRenderbuffer(width
, height
) {
26 var samples
= gl
.getInternalformatParameter(gl
.RENDERBUFFER
, gl
.RGB8
, gl
.SAMPLES
);
27 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from getInternalformatParameter()");
29 if (!samples
|| samples
.length
== 0) {
30 testFailed("getInternalformatParameter on RGB8 fails to return valid samples");
34 for (var idx
= 0; idx
< samples
.length
+ 2; ++idx
) {
36 var renderbuffer
= gl
.createRenderbuffer();
37 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, renderbuffer
);
43 case samples
.length
+ 1:
44 sampleCount
= -1; // non multisampled
47 sampleCount
= samples
[idx
];
50 if (sampleCount
< 0) {
51 debug("test non-multisampled RGB8 renderbuffer");
52 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGB8
, 2, 2);
54 debug("test RGB8 renderbuffer with " + sampleCount
+ " samples");
55 gl
.renderbufferStorageMultisample(gl
.RENDERBUFFER
, sampleCount
, gl
.RGB8
, width
, height
);
57 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from renderbufferStorage{Multisample}");
59 var fbo
= gl
.createFramebuffer();
60 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
61 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, renderbuffer
);
62 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
63 testFailed("framebuffer with renderbuffer is incomplete");
65 testPassed("framebuffer with renderbuffer is complete");
68 gl
.clearColor(1, 0, 1, 1);
69 gl
.clear(gl
.COLOR_BIT
);
70 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from clear()");
74 function testTexture(width
, height
) {
75 var formats
= [ "RGB", "RGB8" ];
76 for (var idx
= 0; idx
< formats
.length
; ++idx
) {
78 debug("test texture format " + formats
[idx
]);
79 var internalformat
= gl
[formats
[idx
]];
80 var tex
= gl
.createTexture();
81 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
82 gl
.texImage2D(gl
.TEXTURE_2D
, 0, internalformat
, width
, height
, 0, gl
.RGB
, gl
.UNSIGNED_BYTE
, null);
83 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from texture setup");
85 var fbo
= gl
.createFramebuffer();
86 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
87 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex
, 0);
88 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
89 testFailed("framebuffer with texture is incomplete");
91 testPassed("framebuffer with texture is complete");
94 gl
.clearColor(1, 0, 1, 1);
95 gl
.clear(gl
.COLOR_BIT
);
96 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from clear()");
101 testFailed('canvas.getContext() failed');
103 testRenderbuffer(2, 2);
107 var successfullyParsed
= true;
109 <script src=
"../../js/js-test-post.js"></script>