| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 Use of this source code is governed by a BSD-style license that can be | |
| 4 found in the LICENSE file. | |
| 5 --> | |
| 6 <!DOCTYPE html> | |
| 7 <html> | |
| 8 <head> | |
| 9 <meta charset="utf-8"> | |
| 10 <title>WebGL GLSL 2 types of textures on same unit conformance test.</title> | |
| 11 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
| 12 <script src="../resources/js-test-pre.js"></script> | |
| 13 <script src="resources/webgl-test.js"> </script> | |
| 14 <script src="../../debug/webgl-debug.js"> </script> | |
| 15 </head> | |
| 16 <body> | |
| 17 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></c
anvas> | |
| 18 <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></
canvas> | |
| 19 <div id="description"></div> | |
| 20 <div id="console"></div> | |
| 21 <script id="vshader" type="x-shader/x-vertex"> | |
| 22 attribute vec4 vPosition; | |
| 23 attribute vec2 texCoord0; | |
| 24 varying vec2 texCoord; | |
| 25 void main() | |
| 26 { | |
| 27 gl_Position = vPosition; | |
| 28 texCoord = texCoord0; | |
| 29 } | |
| 30 </script> | |
| 31 | |
| 32 <script id="fshader" type="x-shader/x-fragment"> | |
| 33 precision mediump float; | |
| 34 | |
| 35 uniform sampler2D tex2d; | |
| 36 uniform samplerCube texCube; | |
| 37 varying vec2 texCoord; | |
| 38 void main() | |
| 39 { | |
| 40 gl_FragColor = texture2D(tex2d, texCoord) + | |
| 41 textureCube(texCube, vec3(0,1,0)); | |
| 42 } | |
| 43 </script> | |
| 44 | |
| 45 <script> | |
| 46 function init() | |
| 47 { | |
| 48 if (window.initNonKhronosFramework) { | |
| 49 window.initNonKhronosFramework(false); | |
| 50 } | |
| 51 | |
| 52 debug("Tests that using 2 types of textures on the same texture unit"); | |
| 53 debug("and referencing them both in the same program fails as per"); | |
| 54 debug("OpenGL ES 2.0.24 spec section 2.10.4, Samplers subsection."); | |
| 55 debug(""); | |
| 56 | |
| 57 var canvas2d = document.getElementById("canvas2d"); | |
| 58 var ctx2d = canvas2d.getContext("2d"); | |
| 59 | |
| 60 gl = initWebGL("example", "vshader", "fshader", [ "vPosition", "texCoord0"], | |
| 61 [ 0, 0, 0, 1 ], 1); | |
| 62 | |
| 63 gl.disable(gl.DEPTH_TEST); | |
| 64 gl.disable(gl.BLEND); | |
| 65 | |
| 66 var vertexObject = gl.createBuffer(); | |
| 67 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
| 68 gl.bufferData( | |
| 69 gl.ARRAY_BUFFER, | |
| 70 new Float32Array([ | |
| 71 -1, 1,0, 1,1,0, -1,-1,0, | |
| 72 -1,-1,0, 1,1,0, 1,-1,0]), | |
| 73 gl.STATIC_DRAW); | |
| 74 gl.enableVertexAttribArray(0); | |
| 75 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
| 76 | |
| 77 var vertexObject = gl.createBuffer(); | |
| 78 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
| 79 gl.bufferData( | |
| 80 gl.ARRAY_BUFFER, | |
| 81 new Float32Array([ | |
| 82 0,0, 1,0, 0,1, | |
| 83 0,1, 1,0, 1,1]), | |
| 84 gl.STATIC_DRAW); | |
| 85 gl.enableVertexAttribArray(1); | |
| 86 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); | |
| 87 | |
| 88 // Make texture unit 1 active. | |
| 89 gl.activeTexture(gl.TEXTURE1); | |
| 90 | |
| 91 // Make a 2d texture | |
| 92 var tex2d = gl.createTexture(); | |
| 93 gl.bindTexture(gl.TEXTURE_2D, tex2d); | |
| 94 ctx2d.fillStyle = "rgba(0, 0, 255, 255)"; | |
| 95 ctx2d.fillRect(0, 0, 1, 1); | |
| 96 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); | |
| 97 | |
| 98 // make a cube texture | |
| 99 var texCube = gl.createTexture(); | |
| 100 ctx2d.fillStyle = "rgba(0, 255, 0, 64)"; | |
| 101 ctx2d.fillRect(0, 0, 1, 1); | |
| 102 var targets = [ | |
| 103 gl.TEXTURE_CUBE_MAP_POSITIVE_X, | |
| 104 gl.TEXTURE_CUBE_MAP_NEGATIVE_X, | |
| 105 gl.TEXTURE_CUBE_MAP_POSITIVE_Y, | |
| 106 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, | |
| 107 gl.TEXTURE_CUBE_MAP_POSITIVE_Z, | |
| 108 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; | |
| 109 for (var ii = 0; ii < targets.length; ++ii) { | |
| 110 gl.texImage2D(targets[ii], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); | |
| 111 } | |
| 112 | |
| 113 var tex2dLoc = gl.getUniformLocation(gl.program, "tex2d"); | |
| 114 var texCubeLoc = gl.getUniformLocation(gl.program, "texCube"); | |
| 115 gl.uniform1i(tex2dLoc, 1); | |
| 116 gl.uniform1i(texCubeLoc, 1); | |
| 117 | |
| 118 gl.clearColor(1,0,0,1); | |
| 119 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
| 120 | |
| 121 for (var ii = 0; ii < 4; ++ii) { | |
| 122 var x = ii % 2; | |
| 123 var y = Math.floor(ii / 2); | |
| 124 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
| 125 glErrorShouldBe(gl, gl.INVALID_OPERATION, | |
| 126 "drawing with 2 different targets on the same texture unit should
generate INVALID_VALUE"); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 init(); | |
| 131 successfullyParsed = true; | |
| 132 </script> | |
| 133 <script src="../resources/js-test-post.js"></script> | |
| 134 | |
| 135 </body> | |
| 136 </html> | |
| 137 | |
| OLD | NEW |