1
0
Fork 0

Add import for shaders

This commit is contained in:
Pabloader 2025-05-08 23:06:55 +00:00
parent 9cb6516209
commit db4a0f5f6f
7 changed files with 69 additions and 4 deletions

View File

@ -1,4 +1,9 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
extern unsigned char __heap_base;
@ -22,3 +27,7 @@ IMPORT(log) void print_int(int64_t);
EXPORT(__srand) void srand(uint64_t seed);
uint64_t rand(void);
#ifdef __cplusplus
}
#endif

22
build/filePlugin.ts Normal file
View File

@ -0,0 +1,22 @@
import { plugin, type BunPlugin } from "bun";
const filePlugin: BunPlugin = {
name: "File loader",
async setup(build) {
build.onLoad({ filter: /\.glsl$/ }, async (args) => {
console.log(args);
const text = await Bun.file(args.path).text();
return {
contents: `
const text = (${JSON.stringify(text)});
export default text;
`,
loader: 'js',
};
});
}
};
plugin(filePlugin);
export default filePlugin;

View File

@ -5,9 +5,10 @@ import UglifyJS from 'uglify-js';
import wasmPlugin from './wasmPlugin';
import imagePlugin from './imagePlugin';
import fontPlugin from './fontPlugin';
import audioPlugin from './audioPlugin';
import filePlugin from './filePlugin';
import { getGames } from './isGame';
import audioPlugin from './audioPlugin';
interface Args {
production?: boolean;
@ -30,6 +31,7 @@ export async function buildHTML(game: string, { production = false, portable = f
audioPlugin,
fontPlugin,
wasmPlugin({ production, portable }),
filePlugin,
]
});

View File

@ -0,0 +1,9 @@
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
void main() {
gl_Position = a_position;
v_color = a_color;
}

View File

@ -0,0 +1,16 @@
#include <stdlib.h>
struct awoo {
int a;
awoo operator+(const awoo& other) const { return awoo{a + other.a}; }
operator int() const { return a * 2; }
};
EXPORT(cpptest) uint32_t cpptest() {
awoo a{42};
awoo b{69};
return a + b;
}

View File

@ -1,10 +1,11 @@
import { render } from "preact";
import attack from './assets/attack.wav';
import awoo from "./awoo.cpp";
import shader from './assets/shader.glsl';
export default function main() {
console.log(shader);
render(
<button onClick={() => attack.play()}>
<button onClick={() => console.log(awoo.cpptest())}>
Attack
</button>,
document.body

6
src/types.d.ts vendored
View File

@ -46,6 +46,7 @@ declare module "*.c" {
data: DataView;
malloc: (size: number) => number;
free: (ptr: number) => void;
realloc: (ptr: number, size: number) => number;
[x: string]: (...args: any) => any;
};
@ -57,8 +58,13 @@ declare module "*.cpp" {
data: DataView;
malloc: (size: number) => void;
free: (ptr: number) => void;
realloc: (ptr: number, size: number) => number;
[x: string]: (...args: any) => any;
};
export default instance;
}
declare module "*.glsl" {
const content: string;
export default content;
}