Skip to content

Commit

Permalink
refactor(vector-pools): update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 7, 2019
1 parent 12898f0 commit 6537610
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 56 deletions.
47 changes: 1 addition & 46 deletions packages/vector-pools/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
GLType,
ILogger,
IObjectOf,
IRelease,
Expand Down Expand Up @@ -55,52 +56,6 @@ export type VecFactory = (
stride: number
) => StridedVec;

/**
* WebGL numeric type constants. These can be used by classes in this
* package as aliases for thi.ng/malloc's `Type` enum (see `GL2TYPE` LUT
* below), but also then used directly when initializing WebGL buffers
* from given attribute buffer specs.
*
* See `AttribPool` & readme examples for more details.
*/
export const enum GLType {
I8 = 0x1400,
U8 = 0x1401,
I16 = 0x1402,
U16 = 0x1403,
I32 = 0x1404,
U32 = 0x1405,
F32 = 0x1406
}

/**
* Conversion from `GLType` to `Type`.
*/
export const GL2TYPE: { [id: number]: Type } = {
[GLType.I8]: Type.I8,
[GLType.U8]: Type.U8,
[GLType.I16]: Type.I16,
[GLType.U16]: Type.U16,
[GLType.I32]: Type.I32,
[GLType.I32]: Type.I32,
[GLType.U32]: Type.U32,
[GLType.F32]: Type.F32
};

/**
* Conversion from `Type` to `GLType`.
*/
export const TYPE2GL: { [id: number]: GLType } = {
[Type.I8]: GLType.I8,
[Type.U8]: GLType.U8,
[Type.I16]: GLType.I16,
[Type.U16]: GLType.U16,
[Type.I32]: GLType.I32,
[Type.I32]: GLType.I32,
[Type.U32]: GLType.U32,
[Type.F32]: GLType.F32
};

export let LOGGER = NULL_LOGGER;

export const setLogger = (logger: ILogger) => (LOGGER = logger);
11 changes: 5 additions & 6 deletions packages/vector-pools/src/attrib-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {
IObjectOf,
IRelease,
SIZEOF,
TypedArray
TypedArray,
TYPEDARRAY_CTORS
} from "@thi.ng/api";
import { align, Pow2 } from "@thi.ng/binary";
import { isNumber } from "@thi.ng/checks";
import { MemPool, TYPEDARRAY_CTORS, wrap } from "@thi.ng/malloc";
import { MemPool, wrap } from "@thi.ng/malloc";
import { range } from "@thi.ng/transducers";
import { ReadonlyVec, Vec, zeroes } from "@thi.ng/vectors";
import { AttribPoolOpts, AttribSpec, LOGGER } from "./api";
Expand Down Expand Up @@ -123,7 +124,7 @@ export class AttribPool implements IRelease {
const size = spec.size;
const stride = spec.stride!;
const src = this.attribs[id];
const dest = new TYPEDARRAY_CTORS[(asNativeType(spec.type))](n * size);
const dest = new TYPEDARRAY_CTORS[asNativeType(spec.type)](n * size);
if (size > 1) {
for (let i = 0, j = 0; i < n; i++, j += stride) {
dest.set(src.subarray(j, j + size), i * size);
Expand Down Expand Up @@ -247,9 +248,7 @@ export class AttribPool implements IRelease {
() =>
(!isNum && a.size === (<Vec>a.default).length) ||
(isNum && a.size === 1),
`attrib ${id}: incompatible default value, expected size ${
a.size
}`
`attrib ${id}: incompatible default value, expected size ${a.size}`
);
assert(
a.byteOffset % size === 0,
Expand Down
8 changes: 6 additions & 2 deletions packages/vector-pools/src/convert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Type } from "@thi.ng/api";
import { GL2TYPE, GLType, TYPE2GL } from "./api";
import {
GL2TYPE,
GLType,
Type,
TYPE2GL
} from "@thi.ng/api";

/**
* Returns canonical `Type` value of `type` by first attempting to
Expand Down
4 changes: 2 additions & 2 deletions packages/vector-pools/src/vec-pool.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type, TypedArray } from "@thi.ng/api";
import { GLType, Type, TypedArray } from "@thi.ng/api";
import { isTypedArray } from "@thi.ng/checks";
import { MemPool, MemPoolOpts, MemPoolStats } from "@thi.ng/malloc";
import { StridedVec } from "@thi.ng/vectors";
import { GLType, IVecPool } from "./api";
import { IVecPool } from "./api";
import { asNativeType } from "./convert";
import { wrap } from "./wrap";

Expand Down

0 comments on commit 6537610

Please sign in to comment.