|
|
@ -31,41 +31,43 @@ function draw(state, context) { |
|
|
|
gl.enableVertexAttribArray(locations['a_pos']); |
|
|
|
gl.enableVertexAttribArray(locations['a_pos']); |
|
|
|
gl.enableVertexAttribArray(locations['a_color']); |
|
|
|
gl.enableVertexAttribArray(locations['a_color']); |
|
|
|
|
|
|
|
|
|
|
|
gl.vertexAttribPointer(locations['a_pos'], 2, gl.FLOAT, false, 4 * 3, 0); |
|
|
|
gl.vertexAttribPointer(locations['a_pos'], 3, gl.FLOAT, false, 4 * 4, 0); |
|
|
|
gl.vertexAttribPointer(locations['a_color'], 3, gl.UNSIGNED_BYTE, true, 4 * 3, 4 * 2); |
|
|
|
gl.vertexAttribPointer(locations['a_color'], 3, gl.UNSIGNED_BYTE, true, 4 * 4, 4 * 3); |
|
|
|
|
|
|
|
|
|
|
|
gl.activeTexture(gl.TEXTURE0 + 0); |
|
|
|
gl.activeTexture(gl.TEXTURE0 + 0); |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['points']); |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['points']); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
|
|
|
|
|
|
|
|
|
|
|
const npoints = context.point_serializer.offset / (4 * 2); |
|
|
|
const npoints = context.point_serializer.offset / (4 * 2); |
|
|
|
const nstrokes = context.quad_serializer.offset / (6 * 3 * 4); |
|
|
|
const nstrokes = context.quad_serializer.offset / (6 * 4 * 4); |
|
|
|
|
|
|
|
|
|
|
|
// TOOD: if points changed
|
|
|
|
if (npoints > 0) { |
|
|
|
if (true) { |
|
|
|
// TOOD: if points changed
|
|
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, npoints, 1, 0, gl.RG, gl.FLOAT, new Float32Array(context.point_serializer.buffer, 0, context.point_serializer.offset / 4)); |
|
|
|
if (true) { |
|
|
|
} |
|
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, npoints, 1, 0, gl.RG, gl.FLOAT, new Float32Array(context.point_serializer.buffer, 0, context.point_serializer.offset / 4)); |
|
|
|
|
|
|
|
} |
|
|
|
gl.activeTexture(gl.TEXTURE0 + 1); |
|
|
|
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['indices']); |
|
|
|
gl.activeTexture(gl.TEXTURE0 + 1); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['indices']); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
|
|
|
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
|
|
|
// TOOD: if points changed
|
|
|
|
|
|
|
|
if (true) { |
|
|
|
// TOOD: if points changed
|
|
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32UI, nstrokes, 1, 0, gl.RG_INTEGER, gl.UNSIGNED_INT, new Uint32Array(context.index_serializer.buffer, 0, context.index_serializer.offset / 4)); |
|
|
|
if (true) { |
|
|
|
|
|
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32UI, nstrokes, 1, 0, gl.RG_INTEGER, gl.UNSIGNED_INT, new Uint32Array(context.index_serializer.buffer, 0, context.index_serializer.offset / 4)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
|
|
|
gl.uniform1i(locations['u_texture_points'], 0); |
|
|
|
|
|
|
|
gl.uniform1i(locations['u_texture_indices'], 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(context.quad_serializer.buffer, 0, context.quad_serializer.offset), gl.STATIC_DRAW); |
|
|
|
|
|
|
|
gl.drawArrays(gl.TRIANGLES, 0, nstrokes * 6); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
|
|
|
gl.uniform1i(locations['u_texture_points'], 0); |
|
|
|
|
|
|
|
gl.uniform1i(locations['u_texture_indices'], 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(context.quad_serializer.buffer, 0, context.quad_serializer.offset), gl.STATIC_DRAW); |
|
|
|
|
|
|
|
gl.drawArrays(gl.TRIANGLES, 0, nstrokes * 6); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Images
|
|
|
|
// Images
|
|
|
|
// locations = context.locations['image'];
|
|
|
|
// locations = context.locations['image'];
|
|
|
|
// buffers = context.buffers['image'];
|
|
|
|
// buffers = context.buffers['image'];
|
|
|
|