rgb-format-support.html (3912B)
1 <!-- 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. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 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> 14 </head> 15 <body> 16 <div id="description"></div> 17 <div id="console"></div> 18 <script> 19 "use strict"; 20 var wtu = WebGLTestUtils; 21 description("Verify RGB/RGB8 textures and renderbuffers support"); 22 23 var gl = wtu.create3DContext(undefined, undefined, 2); 24 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()"); 28 29 if (!samples || samples.length == 0) { 30 testFailed("getInternalformatParameter on RGB8 fails to return valid samples"); 31 return; 32 } 33 34 for (var idx = 0; idx < samples.length + 2; ++idx) { 35 debug(""); 36 var renderbuffer = gl.createRenderbuffer(); 37 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); 38 var sampleCount = 0; 39 switch (idx) { 40 case samples.length: 41 sampleCount = 0; 42 break; 43 case samples.length + 1: 44 sampleCount = -1; // non multisampled 45 break; 46 default: 47 sampleCount = samples[idx]; 48 } 49 50 if (sampleCount < 0) { 51 debug("test non-multisampled RGB8 renderbuffer"); 52 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGB8, 2, 2); 53 } else { 54 debug("test RGB8 renderbuffer with " + sampleCount + " samples"); 55 gl.renderbufferStorageMultisample(gl.RENDERBUFFER, sampleCount, gl.RGB8, width, height); 56 } 57 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from renderbufferStorage{Multisample}"); 58 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"); 64 } else { 65 testPassed("framebuffer with renderbuffer is complete"); 66 } 67 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()"); 71 } 72 } 73 74 function testTexture(width, height) { 75 var formats = [ "RGB", "RGB8" ]; 76 for (var idx = 0; idx < formats.length; ++idx) { 77 debug(""); 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"); 84 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"); 90 } else { 91 testPassed("framebuffer with texture is complete"); 92 } 93 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()"); 97 } 98 } 99 100 if (!gl) { 101 testFailed('canvas.getContext() failed'); 102 } else { 103 testRenderbuffer(2, 2); 104 testTexture(2, 2); 105 } 106 107 var successfullyParsed = true; 108 </script> 109 <script src="../../js/js-test-post.js"></script> 110 </body> 111 </html>