initial implementation of WebGL-based brush renderer
This commit is contained in:
parent
b4c3260f49
commit
bb55e23979
14 changed files with 385 additions and 247 deletions
|
@ -22,15 +22,21 @@ function* chunksInRectangle(rect, chunkSize) {
|
|||
}
|
||||
}
|
||||
|
||||
export function renderToChunksInArea(layer, renderArea, renderToPixmap) {
|
||||
export function renderToChunksInArea(
|
||||
chunkAllocator,
|
||||
brushRenderer,
|
||||
layer,
|
||||
renderArea,
|
||||
renderToCanvas,
|
||||
) {
|
||||
for (let [chunkX, chunkY] of chunksInRectangle(renderArea, layer.chunkSize)) {
|
||||
let chunk = layer.getOrCreateChunk(chunkX, chunkY);
|
||||
let chunk = layer.getOrCreateChunk(chunkAllocator, chunkX, chunkY);
|
||||
if (chunk == null) continue;
|
||||
|
||||
let translationX = -chunkX * layer.chunkSize;
|
||||
let translationY = -chunkY * layer.chunkSize;
|
||||
let result = renderToPixmap(chunk.pixmap, translationX, translationY);
|
||||
chunk.markModified();
|
||||
brushRenderer.setTranslation(translationX, translationY);
|
||||
let result = renderToCanvas(brushRenderer, chunk.id, translationX, translationY);
|
||||
if (result.status != "ok") return result;
|
||||
}
|
||||
|
||||
|
@ -47,14 +53,26 @@ export function dotterRenderArea(wall, dotter) {
|
|||
};
|
||||
}
|
||||
|
||||
export function selfController(interactionQueue, wall, layer, event) {
|
||||
export function selfController(
|
||||
interactionQueue,
|
||||
chunkAllocator,
|
||||
brushRenderer,
|
||||
wall,
|
||||
layer,
|
||||
event,
|
||||
) {
|
||||
let renderArea = null;
|
||||
return {
|
||||
async runScribble(renderToPixmap) {
|
||||
async runScribble(renderToCanvas) {
|
||||
interactionQueue.push({ kind: "scribble" });
|
||||
if (renderArea != null) {
|
||||
let numChunksToRender = numChunksInRectangle(renderArea, layer.chunkSize);
|
||||
let result = renderToChunksInArea(layer, renderArea, renderToPixmap);
|
||||
let result = renderToChunksInArea(
|
||||
chunkAllocator,
|
||||
brushRenderer,
|
||||
layer,
|
||||
renderArea,
|
||||
renderToCanvas,
|
||||
);
|
||||
return result;
|
||||
} else {
|
||||
console.debug("render area is empty, nothing will be rendered");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue