Skip to content

Commit

Permalink
refactor(webgl): add pixel dep, update tex gens
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 23, 2019
1 parent 1836ea7 commit 58822c8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
3 changes: 2 additions & 1 deletion packages/webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@thi.ng/equiv": "^1.0.8",
"@thi.ng/errors": "^1.1.1",
"@thi.ng/matrices": "^0.5.2",
"@thi.ng/pixel": "^0.0.1",
"@thi.ng/shader-ast": "^0.2.0",
"@thi.ng/shader-ast-glsl": "^0.1.2",
"@thi.ng/shader-ast-stdlib": "^0.1.2",
Expand All @@ -62,4 +63,4 @@
"access": "public"
},
"sideEffects": false
}
}
10 changes: 5 additions & 5 deletions packages/webgl/src/textures/checkerboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { abgr, canvas2d } from "./utils";
import { canvasPixels, swapRB } from "@thi.ng/pixel";

export interface CheckerboardOpts {
size: number;
Expand All @@ -17,16 +17,16 @@ export const checkerboard = (opts: Partial<CheckerboardOpts>) => {
...opts
};
const size = opts.size!;
const col1 = abgr(opts.col1!);
const col2 = abgr(opts.col2!);
const { canvas, ctx, img, pix } = canvas2d(size);
const col1 = swapRB(opts.col1!);
const col2 = swapRB(opts.col2!);
const { canvas, ctx, img, pix } = canvasPixels(size);
for (let y = 0, i = 0; y < size; y++) {
for (let x = 0; x < size; x++, i++) {
pix[i] = (y & 1) ^ (x & 1) ? col1 : col2;
}
}
if (opts.corners) {
const corners = opts.cornerCols!.map(abgr);
const corners = opts.cornerCols!.map(swapRB);
pix[0] = corners[0];
pix[size - 1] = corners[1];
pix[pix.length - size] = corners[2];
Expand Down
10 changes: 5 additions & 5 deletions packages/webgl/src/textures/stripes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { abgr, canvas2d } from "./utils";
import { canvasPixels, swapRB } from "@thi.ng/pixel";

export interface StripeOpts {
size: number;
Expand All @@ -15,11 +15,11 @@ export const stripes = (opts: Partial<StripeOpts>) => {
...opts
};
const size = opts.size!;
const col1 = abgr(opts.col1!);
const col2 = abgr(opts.col2!);
const col1 = swapRB(opts.col1!);
const col2 = swapRB(opts.col2!);
const { canvas, ctx, img, pix } = opts.horizontal
? canvas2d(1, size)
: canvas2d(size, 1);
? canvasPixels(1, size)
: canvasPixels(size, 1);
for (let x = size; --x >= 0; ) {
pix[x] = x & 1 ? col1 : col2;
}
Expand Down
19 changes: 0 additions & 19 deletions packages/webgl/src/textures/utils.ts

This file was deleted.

0 comments on commit 58822c8

Please sign in to comment.