You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
let c2d = null; |
|
let raster_queue = []; |
|
|
|
function init_rasterizer() { |
|
c2d = document.querySelector('#offscreen').getContext('2d'); |
|
c2d.canvas.width = config.w; |
|
c2d.canvas.height = config.h; |
|
c2d.font = '16px ibm8x16'; |
|
//c2d.font = '14px monospace'; |
|
c2d.textAlign = 'center'; |
|
c2d.textBaseline = 'middle'; |
|
c2d.fillStyle = '#eeeeee'; |
|
} |
|
|
|
function rasterize(text) { |
|
c2d.clearRect(0, 0, c2d.canvas.width, c2d.canvas.height); |
|
c2d.fillText(text, config.w / 2, config.h / 2); |
|
//c2d.fillRect(0, 0, 32, 32); |
|
} |
|
|
|
function queue_rasterize(text, at) { |
|
raster_queue.push({'text': text, 'at': at}); |
|
} |
|
|
|
function copy_canvas_to_texture(at) { |
|
gl.texSubImage2D(gl.TEXTURE_2D, 0, |
|
at.x * config.w, at.y * config.h, |
|
config.w, config.h, |
|
gl.RGBA, gl.UNSIGNED_BYTE, |
|
c2d.canvas |
|
); |
|
} |
|
|
|
function rasterize_and_upload_batch(batch_size) { |
|
let head = 0; |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['raster']); |
|
|
|
for (let i = 0; i < batch_size && i < raster_queue.length; ++i) { |
|
const entry = raster_queue[i]; |
|
rasterize(entry.text); |
|
copy_canvas_to_texture(entry.at); |
|
head = i + 1; |
|
} |
|
|
|
raster_queue.splice(0, head); |
|
|
|
return raster_queue.length; |
|
}
|
|
|