michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that vertex and fragment shader sources can be changed. michael@0: */ michael@0: michael@0: function ifWebGLSupported() { michael@0: let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL); michael@0: front.setup({ reload: true }); michael@0: michael@0: let programActor = yield once(front, "program-linked"); michael@0: let vertexShader = yield programActor.getVertexShader(); michael@0: let fragmentShader = yield programActor.getFragmentShader(); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 191, g: 64, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: michael@0: let vertSource = yield vertexShader.getText(); michael@0: let fragSource = yield fragmentShader.getText(); michael@0: ok(!vertSource.contains("2.0"), michael@0: "The vertex shader source is correct before changing it."); michael@0: ok(!fragSource.contains("0.5"), michael@0: "The fragment shader source is correct before changing it."); michael@0: michael@0: let newVertSource = vertSource.replace("1.0", "2.0"); michael@0: let status = yield vertexShader.compile(newVertSource); michael@0: ok(!status, michael@0: "The new vertex shader source was compiled without errors."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: michael@0: let vertSource = yield vertexShader.getText(); michael@0: let fragSource = yield fragmentShader.getText(); michael@0: ok(vertSource.contains("2.0"), michael@0: "The vertex shader source is correct after changing it."); michael@0: ok(!fragSource.contains("0.5"), michael@0: "The fragment shader source is correct after changing the vertex shader."); michael@0: michael@0: let newFragSource = fragSource.replace("1.0", "0.5"); michael@0: let status = yield fragmentShader.compile(newFragSource); michael@0: ok(!status, michael@0: "The new fragment shader source was compiled without errors."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 127 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: michael@0: let vertSource = yield vertexShader.getText(); michael@0: let fragSource = yield fragmentShader.getText(); michael@0: ok(vertSource.contains("2.0"), michael@0: "The vertex shader source is correct after changing the fragment shader."); michael@0: ok(fragSource.contains("0.5"), michael@0: "The fragment shader source is correct after changing it."); michael@0: michael@0: yield removeTab(target.tab); michael@0: finish(); michael@0: }