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.
i created array of point sizes:
var pointsizes = new uint8array(2000);
i added attribute shader point sizes:
attribute float pointsize;
the main function has: gl_pointsize = pointsize;
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);
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
Post a Comment