Best JavaScript code snippet using wpt
webgl-test-utils.js
Source: webgl-test-utils.js
...179 * @return {!WebGLProgram}180 */181 var setupTexturedQuad = function(182 gl, opt_positionLocation, opt_texcoordLocation) {183 var program = setupSimpleTextureProgram(184 gl, opt_positionLocation, opt_texcoordLocation);185 setupUnitQuad(gl, opt_positionLocation, opt_texcoordLocation);186 return program;187 };188 /**189 * Draws a previously setup quad.190 * @param {!WebGLContext} gl The WebGLContext to use.191 * @param {!Array.<number>} opt_color The color to fill clear with before192 * drawing. A 4 element array where each element is in the range 0 to193 * 255. Default [255, 255, 255, 255]194 */195 var drawQuad = function(gl, opt_color) {196 opt_color = opt_color || [255, 255, 255, 255];197 gl.clearColor(...
Using AI Code Generation
1var gl = wpt.create3DContext();2var program = wpt.setupSimpleTextureProgram(gl);3var texture = gl.createTexture();4gl.bindTexture(gl.TEXTURE_2D, texture);5gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255]));6gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);7gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);8gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);9gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);10gl.viewport(0, 0, 1, 1);11gl.clearColor(0, 0, 0, 1);12gl.clear(gl.COLOR_BUFFER_BIT);13gl.useProgram(program);14gl.bindTexture(gl.TEXTURE_2D, texture);15gl.drawArrays(gl.TRIANGLES, 0, 6);16var pixels = new Uint8Array(4);17gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);18if (pixels[0] != 255 || pixels[1] != 0 || pixels[2] != 0 || pixels[3] != 255) {19 testFailed("drawArrays with texture failed");20} else {21 testPassed("drawArrays with texture passed");22}23> + if (m_isIntel && m_isOSX) 24if (m_isIntel && m_isOSX && !m_isIOS)
Using AI Code Generation
1var program = setupSimpleTextureProgram(gl);2var program = setupSimpleTextureProgram(gl);3var program = setupSimpleTextureProgram(gl);4var program = setupSimpleTextureProgram(gl);5var program = setupSimpleTextureProgram(gl);6var program = setupSimpleTextureProgram(gl);7var program = setupSimpleTextureProgram(gl);8var program = setupSimpleTextureProgram(gl);9var program = setupSimpleTextureProgram(gl);10var program = setupSimpleTextureProgram(gl);11var program = setupSimpleTextureProgram(gl);12var program = setupSimpleTextureProgram(gl);13var program = setupSimpleTextureProgram(gl);14var program = setupSimpleTextureProgram(gl
Using AI Code Generation
1let canvas = document.getElementById('canvas');2let gl = canvas.getContext('webgl');3let program = wpt.setupSimpleTextureProgram(gl);4let texture = wpt.setupSimpleTexture(gl);5gl.bindTexture(gl.TEXTURE_2D, texture);6gl.useProgram(program);7gl.drawArrays(gl.TRIANGLES, 0, 6);8setupSimpleTextureProgram: function(gl) {9 attribute vec4 aVertexPosition;10 attribute vec2 aTextureCoord;11 uniform mat4 uModelViewMatrix;12 uniform mat4 uProjectionMatrix;13 varying highp vec2 vTextureCoord;14 void main(void) {15 gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;16 vTextureCoord = aTextureCoord;17 }18 `;19 varying highp vec2 vTextureCoord;20 uniform sampler2D uSampler;21 void main(void) {22 gl_FragColor = texture2D(uSampler, vTextureCoord);23 }24 `;25 const shaderProgram = wpt.initShaderProgram(gl, vsSource, fsSource);26 const programInfo = {27 attribLocations: {28 vertexPosition: gl.getAttribLocation(shaderProgram, 'aVertexPosition'),29 textureCoord: gl.getAttribLocation(shaderProgram, 'aTextureCoord'),30 },31 uniformLocations: {32 projectionMatrix: gl.getUniformLocation(shaderProgram, 'uProjectionMatrix'),33 modelViewMatrix: gl.getUniformLocation(shaderProgram, 'uModelViewMatrix'),34 uSampler: gl.getUniformLocation(shaderProgram, 'uSampler'),35 },36 };37 const buffers = wpt.initBuffers(gl);38 const texture = wpt.setupSimpleTexture(gl);39 wpt.drawScene(gl, programInfo, buffers, texture);40 return programInfo;41},42setupSimpleTexture: function(gl) {43 const texture = gl.createTexture();44 gl.bindTexture(gl.TEXTURE_2D, texture);
Using AI Code Generation
1var program = setupSimpleTextureProgram(gl, vertexShaderSource, fragmentShaderSource);2gl.useProgram(program);3function setupSimpleTextureProgram(gl, vertexShaderSource, fragmentShaderSource) {4 var program = createProgram(gl, vertexShaderSource, fragmentShaderSource);5 gl.useProgram(program);6 program.positionLocation = gl.getAttribLocation(program, "a_position");7 program.texcoordLocation = gl.getAttribLocation(program, "a_texCoord");8 program.matrixLocation = gl.getUniformLocation(program, "u_matrix");9 program.textureLocation = gl.getUniformLocation(program, "u_texture");10 program.colorLocation = gl.getUniformLocation(program, "u_color");11 return program;12}13function createProgram(gl, vertexShaderSource, fragmentShaderSource) {14 var program = gl.createProgram();15 var vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);16 var fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);17 gl.attachShader(program, vertexShader);18 gl.attachShader(program, fragmentShader);19 gl.linkProgram(program);20 var success = gl.getProgramParameter(program, gl.LINK_STATUS);21 if (success) {22 return program;23 }24 console.log(gl.getProgramInfoLog(program));25 gl.deleteProgram(program);26}27function createShader(gl, type, source) {28 var shader = gl.createShader(type);29 gl.shaderSource(shader, source);30 gl.compileShader(shader);31 var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);32 if (success) {33 return shader;34 }35 console.log(gl.getShaderInfoLog(shader));36 gl.deleteShader(shader);37}
Using AI Code Generation
1function main() {2 var canvas = document.getElementById("canvas");3 var gl = canvas.getContext("webgl");4 var program = wptSetupSimpleTextureProgram(gl);5}6function wptSetupSimpleTextureProgram(gl) {7 var program = gl.createProgram();8 var vs = wptCreateShaderFromScriptElement(gl, "vertex-shader");9 var fs = wptCreateShaderFromScriptElement(gl, "fragment-shader");10 gl.attachShader(program, vs);11 gl.attachShader(program, fs);12 gl.linkProgram(program);13 gl.useProgram(program);14 return program;15}16function wptCreateShaderFromScriptElement(gl, scriptId) {17 var shaderScript = document.getElementById(scriptId);18 if (!shaderScript) {19 return null;20 }21 var shaderSource = shaderScript.text;22 var shader;23 if (shaderScript.type == "x-shader/x-fragment") {24 shader = gl.createShader(gl.FRAGMENT_SHADER);25 } else if (shaderScript.type == "x-shader/x-vertex") {26 shader = gl.createShader(gl.VERTEX_SHADER);27 } else {28 return null;29 }30 gl.shaderSource(shader, shaderSource);31 gl.compileShader(shader);32 if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {33 return null;34 }35 return shader;36}37precision mediump float;38varying vec2 v_texCoord;39uniform sampler2D u_texture;40void main() {41 gl_FragColor = texture2D(u_texture, v_texCoord);42}43attribute vec2 a_position;44attribute vec2 a_texCoord;45varying vec2 v_texCoord;46void main() {47 gl_Position = vec4(a_position, 0, 1);48 v_texCoord = a_texCoord;49}
Using AI Code Generation
1var canvas = document.getElementById("canvas");2var gl = canvas.getContext("webgl");3var program = setupSimpleTextureProgram(gl);4gl.useProgram(program);5gl.drawArrays(gl.TRIANGLES, 0, 6);6var canvas = document.getElementById("canvas");7var gl = canvas.getContext("webgl");8var program = setupTextureProgram(gl);9gl.useProgram(program);10gl.drawArrays(gl.TRIANGLES, 0, 6);11var canvas = document.getElementById("canvas");12var gl = canvas.getContext("webgl");13var program = setupTextureProgram(gl);14gl.useProgram(program);15gl.drawArrays(gl.TRIANGLES, 0, 6);16var canvas = document.getElementById("canvas");17var gl = canvas.getContext("webgl");18var program = setupTextureProgram(gl);19gl.useProgram(program);20gl.drawArrays(gl.TRIANGLES, 0, 6);
Using AI Code Generation
1"use strict";2var canvas;3var gl;4var numVertices = 6;5var texSize = 64;6var program;7var pointsArray = [];8var texCoordsArray = [];9var texture;10var c;11window.onload = function init()12{13 canvas = document.getElementById( "gl-canvas" );14 gl = WebGLUtils.setupWebGL( canvas );15 if ( !gl ) { alert( "WebGL isn't available" ); }16 gl.viewport( 0, 0, canvas.width, canvas.height );17 gl.clearColor( 0.0, 0.0, 0.0, 1.0 );18 program = initShaders( gl, "vertex-shader", "fragment-shader" );19 gl.useProgram( program);20 setupSimpleTextureProgram(gl, program);21 initTexture();22 configureTexture( texture );23 render();24}25function initTexture() {26 texture = gl.createTexture();27 gl.bindTexture( gl.TEXTURE_2D, texture );28 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);29 gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, texSize, texSize, 0,30 gl.RGBA, gl.UNSIGNED_BYTE, null );31 gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,32 gl.NEAREST );33 gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER,34 gl.NEAREST );35 gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S,36 gl.CLAMP_TO_EDGE );37 gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T,38 gl.CLAMP_TO_EDGE );39}40function configureTexture( image ) {41 gl.bindTexture( gl.TEXTURE_2D, texture );42 gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA,43 gl.UNSIGNED_BYTE, image );44 gl.generateMipmap( gl.TEXTURE_2D );45 gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
Using AI Code Generation
1var textureProgram = setupSimpleTextureProgram(gl);2var texture = gl.createTexture();3gl.bindTexture(gl.TEXTURE_2D, texture);4gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,5new Uint8Array([255, 0, 0, 255]));6gl.bindTexture(gl.TEXTURE_2D, null);7var vertexBuffer = gl.createBuffer();8gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);9var vertices = new Float32Array([10]);11gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);12gl.bindBuffer(gl.ARRAY_BUFFER, null);13var indexBuffer = gl.createBuffer();14gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);15var indices = new Uint16Array([0, 1, 2, 0, 2, 3]);16gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);17gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);18gl.useProgram(textureProgram);19gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);20gl.enableVertexAttribArray(textureProgram.vertexPositionAttribute);21gl.vertexAttribPointer(textureProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 16, 0);22gl.enableVertexAttribArray(textureProgram.textureCoordAttribute);23gl.vertexAttribPointer(textureProgram.textureCoordAttribute, 2, gl.FLOAT, false, 16, 8);24gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);25gl.activeTexture(gl.TEXTURE0);26gl.bindTexture(gl.TEXTURE_2D, texture);27gl.uniform1i(textureProgram.samplerUniform, 0);28gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);29gl.bindTexture(gl.TEXTURE_2D, null);
Check out the latest blogs from LambdaTest on this topic:
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
We launched LT Browser in 2020, and we were overwhelmed by the response as it was awarded as the #5 product of the day on the ProductHunt platform. Today, after 74,585 downloads and 7,000 total test runs with an average of 100 test runs each day, the LT Browser has continued to help developers build responsive web designs in a jiffy.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!