Skip to content

Commit 4d74999

Browse files
committed
chore: setup unjs package template
1 parent e0801ca commit 4d74999

27 files changed

+3233
-141
lines changed

.vscode/launch.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# useGL
2+
3+
WIP

docs/astro.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ import { defineConfig } from "astro/config";
22

33
// https://astro.build/config
44
export default defineConfig({
5-
site: "https://jsulpis.github.io",
6-
base: "/simple-webgl-library",
5+
site: "https://usegl.pages.dev",
76
});

eslint.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import unjs from "eslint-config-unjs";
2+
3+
export default unjs({
4+
rules: {
5+
"unicorn/filename-case": "off",
6+
"unicorn/no-null": "off",
7+
},
8+
});

lib/index.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/package.json

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,45 @@
22
"name": "usegl",
33
"version": "0.1.0",
44
"description": "Lightweight hooks library for WebGL",
5-
"keywords": [],
5+
"repository": "jsulpis/usegl",
66
"license": "MIT",
77
"author": "Julien SULPIS",
8-
"main": "index.ts",
8+
"sideEffects": false,
9+
"type": "module",
10+
"exports": {
11+
".": {
12+
"types": "./dist/index.d.ts",
13+
"import": "./dist/index.mjs"
14+
}
15+
},
16+
"main": "./dist/index.mjs",
17+
"module": "./dist/index.mjs",
18+
"types": "./dist/index.d.ts",
19+
"files": [
20+
"dist"
21+
],
922
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1"
23+
"build": "unbuild",
24+
"format": "prettier src --check",
25+
"format:fix": "prettier src --write",
26+
"lint": "eslint src",
27+
"lint:fix": "eslint src --fix",
28+
"prepack": "pnpm build",
29+
"release": "changelogen --release --clean",
30+
"typecheck": "tsc --noEmit"
31+
},
32+
"devDependencies": {
33+
"@types/node": "22.1.0",
34+
"changelogen": "0.5.5",
35+
"eslint": "9.8.0",
36+
"eslint-config-unjs": "0.3.2",
37+
"prettier": "3.3.3",
38+
"typescript": "5.5.4",
39+
"unbuild": "3.0.0-rc.7"
40+
},
41+
"changelog": {
42+
"excludeAuthors": [
43+
""
44+
]
1145
}
1246
}

lib/src/core/attribute.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function setAttribute(
55
gl: WebGL2RenderingContext,
66
program: WebGLProgram,
77
name: string,
8-
attribute: Attribute
8+
attribute: Attribute,
99
) {
1010
const bufferData = getBufferData(attribute.data, name === "index");
1111
const location = gl.getAttribLocation(program, name);
@@ -27,7 +27,7 @@ export function setAttribute(
2727
attribute.type || getGLType(gl, bufferData),
2828
attribute.normalize || false,
2929
attribute.stride || 0,
30-
attribute.offset || 0
30+
attribute.offset || 0,
3131
);
3232
gl.bindBuffer(gl.ARRAY_BUFFER, null);
3333

@@ -43,7 +43,7 @@ function getBufferData(data: Attribute["data"], isIndex: boolean) {
4343
return data;
4444
}
4545
if (isIndex) {
46-
return data.length < 65536 ? new Uint16Array(data) : new Uint32Array(data);
46+
return data.length < 65_536 ? new Uint16Array(data) : new Uint32Array(data);
4747
}
4848
return new Float32Array(data);
4949
}
@@ -56,4 +56,5 @@ function getGLType(gl: WebGL2RenderingContext, data: ArrayBufferView) {
5656
if (data instanceof Int16Array) return gl.SHORT;
5757
if (data instanceof Uint32Array) return gl.UNSIGNED_INT;
5858
if (data instanceof Int32Array) return gl.INT;
59+
return gl.FLOAT;
5960
}

lib/src/core/buffer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export function createAndBindBuffer(
22
gl: WebGLRenderingContext,
33
target: GLenum,
4-
data: AllowSharedBufferSource | number[]
4+
data: AllowSharedBufferSource | number[],
55
) {
66
const buffer = gl.createBuffer();
77
const bufferData = isSharedBufferSource(data) ? data : new Float32Array(data);

lib/src/core/program.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ import { createShader } from "./shader";
33
export function createProgram(
44
gl: WebGL2RenderingContext,
55
fragment: string | WebGLShader,
6-
vertex: string | WebGLShader
6+
vertex: string | WebGLShader,
77
) {
88
const vertexShader =
99
vertex instanceof WebGLShader ? vertex : createShader(gl, vertex, gl.VERTEX_SHADER);
1010
const fragmentShader =
1111
fragment instanceof WebGLShader ? fragment : createShader(gl, fragment, gl.FRAGMENT_SHADER);
1212

1313
const program = gl.createProgram();
14+
if (program === null || vertexShader == null || fragmentShader == null) {
15+
console.error("could not create program");
16+
gl.deleteProgram(program);
17+
return null;
18+
}
1419
gl.attachShader(program, vertexShader);
1520
gl.attachShader(program, fragmentShader);
1621
gl.linkProgram(program);

lib/src/core/renderTarget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createTexture } from "./texture";
33

44
export function createRenderTarget(
55
gl: WebGL2RenderingContext,
6-
size?: { width: number; height: number }
6+
size?: { width: number; height: number },
77
): RenderTarget {
88
let _width = size?.width ?? gl.canvas.width;
99
let _height = size?.height ?? gl.canvas.height;

0 commit comments

Comments
 (0)