From 54725c011cf99c34774e080e20d63f27072fa229 Mon Sep 17 00:00:00 2001
From: Berthold Krevert <berthold.krevert@basyskom.com>
Date: Thu, 23 Oct 2014 11:05:36 +0200
Subject: [PATCH] Plasmaeffect example: Disable vertex attributes if not used
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes a crash that may occur on some hardware

Change-Id: I603352ce625ea01f977ff0ca19b1c64ae003d3c1
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
---
 .../qml/plasmaeffects/plasmaeffects.js              | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js b/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js
index a0c7889..86e7836 100644
--- a/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js
+++ b/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js
@@ -158,6 +158,9 @@ function renderGL(canvas) {
 
     gl.drawArrays(gl.TRIANGLES, 0, 6);
 
+    gl.disableVertexAttribArray(bkgAttribute_vertexPosition);
+    gl.disableVertexAttribArray(bkgAttribute_textureCoord);
+
     gl.enable(gl.DEPTH_TEST);
     gl.depthMask(true);
     gl.enable(gl.DEPTH_WRITE);
@@ -240,6 +243,11 @@ function renderGL(canvas) {
 
     gl.uniformMatrix4fva(cubeUniform_mvMatrix, false, mvMatrix);
     gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0);
+
+    gl.disableVertexAttribArray(cubeAttribute_vertexPosition);
+    gl.disableVertexAttribArray(cubeAttribute_vertexColor);
+    gl.disableVertexAttribArray(cubeAttribute_textureCoord);
+
 }
 
 function initBuffers()
@@ -447,11 +455,8 @@ function initShaders()
     gl.useProgram(cubeShaderProgram);
 
     cubeAttribute_vertexPosition = gl.getAttribLocation(cubeShaderProgram, "aVertexPosition");
-    gl.enableVertexAttribArray(cubeAttribute_vertexPosition);
     cubeAttribute_vertexColor = gl.getAttribLocation(cubeShaderProgram, "aVertexColor");
-    gl.enableVertexAttribArray(cubeAttribute_vertexColor);
     cubeAttribute_textureCoord = gl.getAttribLocation(cubeShaderProgram, "aTextureCoord");
-    gl.enableVertexAttribArray(cubeAttribute_textureCoord);
 
     cubeUniform_time = gl.getUniformLocation(cubeShaderProgram, "uTime");
     cubeUniform_pMatrix = gl.getUniformLocation(cubeShaderProgram, "uPMatrix");
@@ -524,9 +529,7 @@ function initShaders()
     gl.useProgram(bkgShaderProgram);
 
     bkgAttribute_vertexPosition = gl.getAttribLocation(bkgShaderProgram, "aVertexPosition");
-    gl.enableVertexAttribArray(bkgAttribute_vertexPosition);
     bkgAttribute_textureCoord = gl.getAttribLocation(bkgShaderProgram, "aTextureCoord");
-    gl.enableVertexAttribArray(bkgAttribute_textureCoord);
 
     bkgUniform_time = gl.getUniformLocation(bkgShaderProgram, "uTime");
     gl.bindTexture(gl.TEXTURE_2D, 0);
-- 
GitLab