[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Public WebGL] Unused but enabled VertexAttribs
- To: public webgl <email@example.com>
- Subject: [Public WebGL] Unused but enabled VertexAttribs
- From: Gregg Tavares <firstname.lastname@example.org>
- Date: Mon, 10 May 2010 10:53:32 -0700
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1273514027; bh=6M3LQr/j9asPC/XySJ7mquTsw7E=; h=MIME-Version:Date:Message-ID:Subject:From:To:Content-Type; b=ULYSNQLeq7mgMb2Si7G7jaPEX9N+C3yjh1YD22fMIIpP1PyXDgFy/7pvOjdz/bbSt nYvIXzqIhac8mxZD17rLg==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:date:message-id:subject:from:to:content-type:x-system-of-record; b=LezakgoLBOGN1Mpz165rNNVLoSIeNXvqBN5PJZ4Og5+J6mOgw/PELMqZ2fl6pRAcs DcEoa44kY6pF63eF3yjJA==
- Sender: email@example.com
So it turns out that if you just enable a vertex attrib, even though your shader doesn't use it, you can crash some OpenGL drivers.
Example: this is just the modified triangle sample from here.
Just before draw, add the following line
gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
gl.viewport(0, 0, 50, 50);
var vertexObject = gl.createBuffer();
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(3); // added line
gl.drawArrays(gl.TRIANGLES, 0, 3); // CRASH! (depending on GL driver)
Catching this issue in WebGL 2 paths come to mind.
#1) Generate INVALID_OPERATION on drawArrays because the enabled vertex attrib is not used by the current shader program
#2) Generate INVALID_OPERATION on drawArrays because the enabled vertex attrib does not have a buffer bound that has enough elements to satisfy the drawArray call (as though it was used by the current shader program)
#2 seems like the better option as many programs probably enable 4 to 8 attribs and never disable them and after that just manipulate what they point to through vertexAttribPointer()