WebGL bufferSubData is not working when trying to set a point size during a mousemove event -


i want draw different point sizes during mousemove events using webgl. example, press mouse , draw points size of 1 pixel. select different size , when press mouse , move, can draw points new size.

i discovered strange , appreciate feedback.

  1. i created array of point sizes:

    var pointsizes = new uint8array(2000); 
  2. i added attribute shader point sizes:

    attribute float pointsize; 

    the main function has: gl_pointsize = pointsize;

  3. if populate array size, works fine long not bind in mousemove event:

    for(var = 0; i<=1999; i++)     {pointsizes[i] = 5.0;}  //draw points of size 5   apointsizebuffer = gl.createbuffer(); gl.bindbuffer(gl.array_buffer, apointsizebuffer); gl.bufferdata(gl.array_buffer, pointsizes, gl.static_draw); apointsize = gl.getattriblocation(program, "pointsize"); gl.vertexattribpointer(apointsize, 1, gl.unsigned_byte, false, 0, 0); gl.enablevertexattribarray(apointsize); 
  4. as bind buffer , set buffersubdata in mousemove event, no points shown when move mouse. note: index variable increases mouse move identify position in vertex related pixel. here code in mousemove event:

    gl.bindbuffer(gl.array_buffer, apointsizebuffer); pointsizes[index] = fpointsize;  //this selected size gl.buffersubdata(gl.array_buffer, index, pointsizes[index]); 

    it not matter if of these things:

          gl.buffersubdata(gl.array_buffer, index, fpointsize); 

    or even:

          gl.buffersubdata(gl.array_buffer, index,1); 

thanks again help

gl.buffersubdata expects 3rd argument typearray. pointsizes[index] appears uint8. try use pointsizes.subarray(index, index+1) , see if fixes it.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -