2017-08-11 9 views
1

Edit: Ce n'est pas un bug Firefox uniquement, je reçois les mêmes erreurs en chrome aswellWebGL: aucune VBO liée au vertex activé. Ai-je besoin de "vertexAttribPointer" pour les indices de vertex?

Je reçois l'erreur suivante:

WebGL warning: drawElements: no VBO bound to enabled vertex attrib index 1u!

Je regardais autour du filet et il semble que les indices buffer a besoin d'un "vertexAttribPointer", mais je ne trouve aucun endroit qui explique cela, donc je ne suis toujours pas sûr.

Et voici ma vbo rendre la fonction:

g.activeTexture(g.TEXTURE0); 
g.bindTexture(g.TEXTURE_2D, obj.texture); 
g.uniform1i(g.getUniformLocation(shaderProgram, 'uSampler'), 0); 
g.vertexAttribPointer(
    textureCoordAttribute, 2, g.FLOAT, g.FALSE, 0, 0); 

//vertices 
g.bindBuffer(g.ARRAY_BUFFER, obj.vertBuffer); 
g.vertexAttribPointer(
    positionAttribLocation, obj.vertSize, g.FLOAT, g.FALSE, 0, 0); 

//white color 
g.bindBuffer(g.ARRAY_BUFFER, whiteColorBuffer); 
g.vertexAttribPointer(
    colorAttribLocation, 4, g.FLOAT, g.FALSE, 0, 0); 

//Texture coords 
g.bindBuffer(g.ARRAY_BUFFER, obj.textureBuffer); 
g.vertexAttribPointer(
    textureCoordAttribute, 2, g.FLOAT, g.FALSE, 0, 0); 

//indices buffer 
g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, obj.indexBuffer); 
setMatrixUniforms(); 

g.drawElements(g.TRIANGLES, obj.indexNumItems, g.UNSIGNED_SHORT, 0); 
g.bindTexture(g.TEXTURE_2D, null); 
g.bindBuffer(g.ARRAY_BUFFER, null); 
g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, null); 

Le tableau des indices est un tableau correct et le sommet, car il a travaillé sans textures avant (même si elle a rendu seulement la moitié des sommets). Dois-je ajouter des variables d'index aux shaders?

Edit2: Voici comment mes getAttribLocations regardent actuellement comme:

positionAttribLocation = g.getAttribLocation(shaderProgram, "vertPosition"); 
colorAttribLocation = g.getAttribLocation(shaderProgram, "vertColor"); 
textureCoordAttribute = g.getAttribLocation(shaderProgram, "aTextureCoord"); 


g.vertexAttribPointer(
    positionAttribLocation, // attribute location 
    2, //number of elements per attribute 
    gl.FLOAT, // type of element 
    gl.FALSE, 
    5 * Float32Array.BYTES_PER_ELEMENT,//size of induvidual vertex 
    0//offset from the beginning of a single vertex to this attribute 
    ); 
g.vertexAttribPointer(
    colorAttribLocation, 
    3, 
    g.FLOAT, 
    g.FALSE, 
    5 * Float32Array.BYTES_PER_ELEMENT, 
    2 * Float32Array.BYTES_PER_ELEMENT 
    ); 
g.vertexAttribPointer(
    textureCoordAttribute, 
    2, 
    g.FLOAT, 
    g.FALSE, 
    0, 
    0 
); 
g.enableVertexAttribArray(positionAttribLocation); 
g.enableVertexAttribArray(colorAttribLocation); 
g.enableVertexAttribArray(textureCoordAttribute); 
+0

Copie possible de [erreur WebGL VBO dans Firefox] (https://stackoverflow.com/questions/28490041/webgl-v bo-error-in-firefox) –

+0

Aussi, ai-je mentionné qu'il n'y a pas de 'gl.FALSE'? Je pense que je l'ai fait. –

+0

Où faites-vous [getAttribLocation] (https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getAttribLocation) et où allez-vous [enableVertexAttribArray] (https://developer.mozilla.org/ de/docs/Web/API/WebGLRenderingContext/enableVertexAttribArray) – Rabbid76

Répondre

0

Remarque, la méthode vertexAttribPointer spécifie le type de données et l'emplacement d'un attribut de sommet, dans la limite actuellement ARRAY_BUFFER.

Vous devez utiliser bindBuffer pour lier le tampon approprié avant de spécifier la disposition de mémoire du tampon contenant les attributs de sommet.
Étant donné que certains de vos attributs de sommet sont dans des tampons différents, vous devez vous assurer que le tampon correspondant est lié avant d'appeler vertexAttribPointer.

Votre code devrait ressembler en quelque sorte comme ceci:

Bind tampon obj.vertBuffer et définir des données d'attributs sommet générique pour positionAttribLocation et colorAttribLocation, parce qu'ils sont tous deux situés dans le même tampon.

g.bindBuffer(g.ARRAY_BUFFER, obj.vertBuffer); 
g.vertexAttribPointer(positionAttribLocation, 
    2, gl.FLOAT, false, 5 * Float32Array.BYTES_PER_ELEMENT, 0); 
g.vertexAttribPointer(colorAttribLocation, 
    3, gl.FLOAT, false, 5 * Float32Array.BYTES_PER_ELEMENT, 2 * Float32Array.BYTES_PER_ELEMENT); 

Bind tampon obj.texture Buffer et définir des données d'attributs sommet générique pour textureCoord Attribute, parce que les coordonnées de texture sont situés dans un tampon séparé:

g.bindBuffer(g.ARRAY_BUFFER, obj.textureBuffer); 
g.vertexAttribPointer(textureCoordAttribute, 2, g.FLOAT, false, 0, 0); 


Cela signifie que votre code devrait llok comme ceci:

positionAttribLocation = g.getAttribLocation(shaderProgram, "vertPosition"); 
colorAttribLocation = g.getAttribLocation(shaderProgram, "vertColor"); 
textureCoordAttribute = g.getAttribLocation(shaderProgram, "aTextureCoord"); 

g.bindBuffer(g.ARRAY_BUFFER, obj.vertBuffer); // <---------------- 
g.vertexAttribPointer(
    positionAttribLocation, // attribute location 
    2, //number of elements per attribute 
    gl.FLOAT, // type of element 
    gl.FALSE, 
    5 * Float32Array.BYTES_PER_ELEMENT,//size of induvidual vertex 
    0//offset from the beginning of a single vertex to this attribute 
    ); 
g.vertexAttribPointer(
    colorAttribLocation, 
    3, 
    g.FLOAT, 
    g.FALSE, 
    5 * Float32Array.BYTES_PER_ELEMENT, 
    2 * Float32Array.BYTES_PER_ELEMENT 
    ); 

g.bindBuffer(g.ARRAY_BUFFER, obj.textureBuffer); // <---------------- 
g.vertexAttribPointer(
    textureCoordAttribute, 
    2, 
    g.FLOAT, 
    g.FALSE, 
    0, 
    0 
    ); 

g.enableVertexAttribArray(positionAttribLocation); 
g.enableVertexAttribArray(colorAttribLocation); 
g.enableVertexAttribArray(textureCoordAttribute);