Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
fix makeCanvas() flush problem
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Dec 28, 2023
1 parent c4d0215 commit 96b9aa4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,21 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
}

function makeCanvas(w: number, h: number) {
return new FrameBuffer(ggl, w, h)
const fb = new FrameBuffer(ggl, w, h)
return {
clear: () => fb.clear(),
free: () => fb.free(),
toDataURL: () => fb.toDataURL(),
toImageData: () => fb.toImageData(),
width: fb.width,
height: fb.height,
draw: (action) => {
fb.bind()
action()
flush()
fb.unbind()
},
}
}

function makeShader(
Expand Down
12 changes: 11 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ export interface KaboomCtx {
*
* @since v3000.2
*/
makeCanvas(w: number, h: number): FrameBuffer
makeCanvas(w: number, h: number): Canvas
/**
* @section Debug
*
Expand Down Expand Up @@ -3226,6 +3226,16 @@ export declare class FrameBuffer {
free(): void
}

export type Canvas = {
width: number
height: number
toImageData(): ImageData
toDataURL(): string
clear(): void
draw(action: () => void): void
free(): void
}

export interface GfxFont {
tex: Texture,
map: Record<string, Quad>,
Expand Down

0 comments on commit 96b9aa4

Please sign in to comment.