diff --git a/bindings/src/generation.ts b/bindings/src/generation.ts index 57e9bd5..0af1547 100644 --- a/bindings/src/generation.ts +++ b/bindings/src/generation.ts @@ -218,6 +218,41 @@ export abstract class GenericCodeGenerator { if(isStatic) this.inline("static ") this.statement(`${structName} ${varName} = { ${values.join(', ')} }`) } + + public switch(switchVar: string){ + this.line(`switch(${switchVar}) {`) + this.indent() + const body = this.child() + this.unindent() + this.line("}") + return body + } + + public case(value: string){ + this.line(`case ${value}:`) + } + + public defaultBreak(){ + this.line("default:") + this.line("{") + this.indent() + const body = this.child() + this.statement("break") + this.unindent() + this.line("}") + return body + } + + public caseBreak(value: string){ + this.case(value) + this.line("{") + this.indent() + const body = this.child() + this.statement("break") + this.unindent() + this.line("}") + return body + } } export class CodeGenerator extends GenericCodeGenerator{ diff --git a/bindings/src/index.ts b/bindings/src/index.ts index a5ec784..f5761f8 100644 --- a/bindings/src/index.ts +++ b/bindings/src/index.ts @@ -106,8 +106,8 @@ function main(){ }) core.addApiStructByName("Camera3D",{ properties: { - position: { get: false, set: true }, - target: { get: false, set: true }, + position: { get: true, set: true }, + target: { get: true, set: true }, up: { get: false, set: true }, fovy: { get: true, set: true }, projection: { get: true, set: true }, @@ -266,7 +266,32 @@ function main(){ core.addApiFunctionByName("IsShaderReady") core.addApiFunctionByName("GetShaderLocation") core.addApiFunctionByName("GetShaderLocationAttrib") - // core.addApiFunctionByName("SetShaderValue") + core.addApiFunctionByName("SetShaderValue", null, { body: (gen) => { + gen.jsToC("Shader","shader","argv[0]", core.structLookup) + gen.jsToC("int","locIndex","argv[1]", core.structLookup) + gen.declare("value","void *", false, "NULL") + gen.jsToC("int","uniformType","argv[3]", core.structLookup) + const sw = gen.switch("uniformType") + let b = sw.caseBreak("SHADER_UNIFORM_FLOAT") + b.jsToC("float", "valueFloat", "argv[2]", core.structLookup) + b.statement("value = (void *)&valueFloat") + b = sw.caseBreak("SHADER_UNIFORM_VEC2") + b.jsToC("Vector2 *", "valueV2", "argv[2]", core.structLookup) + b.statement("value = (void*)valueV2") + b = sw.caseBreak("SHADER_UNIFORM_VEC3") + b.jsToC("Vector3 *", "valueV3", "argv[2]", core.structLookup) + b.statement("value = (void*)valueV3") + b = sw.caseBreak("SHADER_UNIFORM_VEC4") + b.jsToC("Vector4 *", "valueV4", "argv[2]", core.structLookup) + b.statement("value = (void*)valueV4") + b = sw.caseBreak("SHADER_UNIFORM_INT") + b.jsToC("int", "valueInt", "argv[2]", core.structLookup) + b.statement("value = (void*)&valueInt") + b = sw.defaultBreak() + b.returnExp("JS_EXCEPTION") + gen.call("SetShaderValue", ["shader","locIndex","value","uniformType"]) + gen.returnExp("JS_UNDEFINED") + }}) // core.addApiFunctionByName("SetShaderValueV") core.addApiFunctionByName("SetShaderValueMatrix") core.addApiFunctionByName("SetShaderValueTexture") @@ -912,6 +937,8 @@ function main(){ api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) api.enums.find(x => x.name === "CameraMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "ShaderLocationIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "ShaderUniformDataType")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) core.writeTo("src/bindings/js_raylib_core.h") core.typings.writeTo("examples/lib.raylib.d.ts") } diff --git a/bindings/src/quickjs.ts b/bindings/src/quickjs.ts index 329d509..4ea1e53 100644 --- a/bindings/src/quickjs.ts +++ b/bindings/src/quickjs.ts @@ -81,7 +81,6 @@ export abstract class GenericQuickJsGenerator extend case "const char *": case "char *": this.statement(`${type} ${name} = (${type})JS_ToCString(ctx, ${src})`) - this.statement(`if(${name} == NULL) return JS_EXCEPTION`) break; case "double": this.statement(`${type} ${name}`) diff --git a/bindings/src/raylib-header.ts b/bindings/src/raylib-header.ts index d44d874..307ea63 100644 --- a/bindings/src/raylib-header.ts +++ b/bindings/src/raylib-header.ts @@ -13,6 +13,7 @@ export interface StructBindingOptions { export interface FuncBindingOptions { before?: (gen: QuickJsGenerator) => void after?: (gen: QuickJsGenerator) => void + body?: (gen: QuickJsGenerator) => void } @@ -31,25 +32,29 @@ export class RayLibHeader extends QuickJsHeader { const jName = jsName || api.name.charAt(0).toLowerCase() + api.name.slice(1) const fun = this.functions.jsBindingFunction(jName) - if(options.before) options.before(fun) - // read parameters - for (let i = 0; i < api.params.length; i++) { - const para = api.params[i] - fun.jsToC(para.type,para.name,"argv["+i+"]", this.structLookup) - } - // call c function - fun.call(api.name, api.params.map(x => x.name), api.returnType === "void" ? null : {type: api.returnType, name: "returnVal"}) - // clean up parameters - for (const param of api.params) { - fun.jsCleanUpParameter(param.type, param.name) - } - if(options.after) options.after(fun) - // return result - if(api.returnType === "void"){ - fun.statement("return JS_UNDEFINED") + if(options.body) { + options.body(fun) } else { - fun.jsToJs(api.returnType, "ret", "returnVal", this.structLookup) - fun.returnExp("ret") + if(options.before) options.before(fun) + // read parameters + for (let i = 0; i < api.params.length; i++) { + const para = api.params[i] + fun.jsToC(para.type,para.name,"argv["+i+"]", this.structLookup) + } + // call c function + fun.call(api.name, api.params.map(x => x.name), api.returnType === "void" ? null : {type: api.returnType, name: "returnVal"}) + // clean up parameters + for (const param of api.params) { + fun.jsCleanUpParameter(param.type, param.name) + } + if(options.after) options.after(fun) + // return result + if(api.returnType === "void"){ + fun.statement("return JS_UNDEFINED") + } else { + fun.jsToJs(api.returnType, "ret", "returnVal", this.structLookup) + fun.returnExp("ret") + } } // add binding to function declaration @@ -77,7 +82,7 @@ export class RayLibHeader extends QuickJsHeader { const el = options.properties[field] let _get: CodeGenerator | undefined = undefined let _set: CodeGenerator | undefined = undefined - if(el.get) _get = this.structs.jsStructGetter(struct.name, classId, field, type, /*Be carefull when allocating memory in a getter*/{}) + if(el.get) _get = this.structs.jsStructGetter(struct.name, classId, field, type, /*Be carefull when allocating memory in a getter*/this.structLookup) if(el.set) _set = this.structs.jsStructSetter(struct.name, classId, field, type, this.structLookup) propDeclarations.jsGetSetDef(field, _get?.getTag("_name"), _set?.getTag("_name")) } diff --git a/bindings/src/typescript.ts b/bindings/src/typescript.ts index 6ce3ae9..09d5cee 100644 --- a/bindings/src/typescript.ts +++ b/bindings/src/typescript.ts @@ -43,8 +43,18 @@ export class TypeScriptDeclaration { case "const char *": case "char *": return "string" + case "void *": + case "const void *": + return "any" + case "Camera": + return "Camera3D" + case "Texture2D": + case "TextureCubemap": + return "Texture" + case "Quaternion": + return "Vector4" default: - return type + return type.replace(" *", "") } } diff --git a/examples/lib.raylib.d.ts b/examples/lib.raylib.d.ts index d26d96c..936cdd7 100644 --- a/examples/lib.raylib.d.ts +++ b/examples/lib.raylib.d.ts @@ -327,22 +327,24 @@ declare function isShaderReady(shader: Shader): boolean; declare function getShaderLocation(shader: Shader, uniformName: string): number; /** Get shader attribute location */ declare function getShaderLocationAttrib(shader: Shader, attribName: string): number; +/** Set shader uniform value */ +declare function setShaderValue(shader: Shader, locIndex: number, value: any, uniformType: number): void; /** Set shader uniform value (matrix 4x4) */ declare function setShaderValueMatrix(shader: Shader, locIndex: number, mat: Matrix): void; /** Set shader uniform value for texture (sampler2d) */ -declare function setShaderValueTexture(shader: Shader, locIndex: number, texture: Texture2D): void; +declare function setShaderValueTexture(shader: Shader, locIndex: number, texture: Texture): void; /** Get a ray trace from mouse position */ -declare function getMouseRay(mousePosition: Vector2, camera: Camera): Ray; +declare function getMouseRay(mousePosition: Vector2, camera: Camera3D): Ray; /** Get camera transform matrix (view matrix) */ -declare function getCameraMatrix(camera: Camera): Matrix; +declare function getCameraMatrix(camera: Camera3D): Matrix; /** Get camera 2d transform matrix */ declare function getCameraMatrix2D(camera: Camera2D): Matrix; /** Get the screen space position for a 3d world space position */ -declare function getWorldToScreen(position: Vector3, camera: Camera): Vector2; +declare function getWorldToScreen(position: Vector3, camera: Camera3D): Vector2; /** Get the world space position for a 2d camera screen space position */ declare function getScreenToWorld2D(position: Vector2, camera: Camera2D): Vector2; /** Get size position for a 3d world space position */ -declare function getWorldToScreenEx(position: Vector3, camera: Camera, width: number, height: number): Vector2; +declare function getWorldToScreenEx(position: Vector3, camera: Camera3D, width: number, height: number): Vector2; /** Get the screen space position for a 2d camera world space position */ declare function getWorldToScreen2D(position: Vector2, camera: Camera2D): Vector2; /** Set target FPS (maximum) */ @@ -490,9 +492,9 @@ declare function getGesturePinchVector(): Vector2; /** Get gesture pinch angle */ declare function getGesturePinchAngle(): number; /** Update camera position for selected mode */ -declare function updateCamera(camera: Camera *, mode: number): void; +declare function updateCamera(camera: Camera, mode: number): void; /** Update camera movement/rotation */ -declare function updateCameraPro(camera: Camera *, movement: Vector3, rotation: Vector3, zoom: number): void; +declare function updateCameraPro(camera: Camera, movement: Vector3, rotation: Vector3, zoom: number): void; /** Draw a pixel */ declare function drawPixel(posX: number, posY: number, color: Color): void; /** Draw a pixel (Vector version) */ @@ -582,7 +584,7 @@ declare function loadImage(fileName: string): Image; /** Load image from RAW file data */ declare function loadImageRaw(fileName: string, width: number, height: number, format: number, headerSize: number): Image; /** Load image from GPU texture data */ -declare function loadImageFromTexture(texture: Texture2D): Image; +declare function loadImageFromTexture(texture: Texture): Image; /** Load image from screen buffer and (screenshot) */ declare function loadImageFromScreen(): Image; /** Check if an image is ready */ @@ -616,111 +618,111 @@ declare function imageText(text: string, fontSize: number, color: Color): Image; /** Create an image from text (custom sprite font) */ declare function imageTextEx(font: Font, text: string, fontSize: number, spacing: number, tint: Color): Image; /** Convert image data to desired format */ -declare function imageFormat(image: Image *, newFormat: number): void; +declare function imageFormat(image: Image, newFormat: number): void; /** Convert image to POT (power-of-two) */ -declare function imageToPOT(image: Image *, fill: Color): void; +declare function imageToPOT(image: Image, fill: Color): void; /** Crop an image to a defined rectangle */ -declare function imageCrop(image: Image *, crop: Rectangle): void; +declare function imageCrop(image: Image, crop: Rectangle): void; /** Crop image depending on alpha value */ -declare function imageAlphaCrop(image: Image *, threshold: number): void; +declare function imageAlphaCrop(image: Image, threshold: number): void; /** Clear alpha channel to desired color */ -declare function imageAlphaClear(image: Image *, color: Color, threshold: number): void; +declare function imageAlphaClear(image: Image, color: Color, threshold: number): void; /** Apply alpha mask to image */ -declare function imageAlphaMask(image: Image *, alphaMask: Image): void; +declare function imageAlphaMask(image: Image, alphaMask: Image): void; /** Premultiply alpha channel */ -declare function imageAlphaPremultiply(image: Image *): void; +declare function imageAlphaPremultiply(image: Image): void; /** Apply Gaussian blur using a box blur approximation */ -declare function imageBlurGaussian(image: Image *, blurSize: number): void; +declare function imageBlurGaussian(image: Image, blurSize: number): void; /** Resize image (Bicubic scaling algorithm) */ -declare function imageResize(image: Image *, newWidth: number, newHeight: number): void; +declare function imageResize(image: Image, newWidth: number, newHeight: number): void; /** Resize image (Nearest-Neighbor scaling algorithm) */ -declare function imageResizeNN(image: Image *, newWidth: number, newHeight: number): void; +declare function imageResizeNN(image: Image, newWidth: number, newHeight: number): void; /** Resize canvas and fill with color */ -declare function imageResizeCanvas(image: Image *, newWidth: number, newHeight: number, offsetX: number, offsetY: number, fill: Color): void; +declare function imageResizeCanvas(image: Image, newWidth: number, newHeight: number, offsetX: number, offsetY: number, fill: Color): void; /** Compute all mipmap levels for a provided image */ -declare function imageMipmaps(image: Image *): void; +declare function imageMipmaps(image: Image): void; /** Dither image data to 16bpp or lower (Floyd-Steinberg dithering) */ -declare function imageDither(image: Image *, rBpp: number, gBpp: number, bBpp: number, aBpp: number): void; +declare function imageDither(image: Image, rBpp: number, gBpp: number, bBpp: number, aBpp: number): void; /** Flip image vertically */ -declare function imageFlipVertical(image: Image *): void; +declare function imageFlipVertical(image: Image): void; /** Flip image horizontally */ -declare function imageFlipHorizontal(image: Image *): void; +declare function imageFlipHorizontal(image: Image): void; /** Rotate image clockwise 90deg */ -declare function imageRotateCW(image: Image *): void; +declare function imageRotateCW(image: Image): void; /** Rotate image counter-clockwise 90deg */ -declare function imageRotateCCW(image: Image *): void; +declare function imageRotateCCW(image: Image): void; /** Modify image color: tint */ -declare function imageColorTint(image: Image *, color: Color): void; +declare function imageColorTint(image: Image, color: Color): void; /** Modify image color: invert */ -declare function imageColorInvert(image: Image *): void; +declare function imageColorInvert(image: Image): void; /** Modify image color: grayscale */ -declare function imageColorGrayscale(image: Image *): void; +declare function imageColorGrayscale(image: Image): void; /** Modify image color: contrast (-100 to 100) */ -declare function imageColorContrast(image: Image *, contrast: number): void; +declare function imageColorContrast(image: Image, contrast: number): void; /** Modify image color: brightness (-255 to 255) */ -declare function imageColorBrightness(image: Image *, brightness: number): void; +declare function imageColorBrightness(image: Image, brightness: number): void; /** Modify image color: replace color */ -declare function imageColorReplace(image: Image *, color: Color, replace: Color): void; +declare function imageColorReplace(image: Image, color: Color, replace: Color): void; /** Get image alpha border rectangle */ declare function getImageAlphaBorder(image: Image, threshold: number): Rectangle; /** Get image pixel color at (x, y) position */ declare function getImageColor(image: Image, x: number, y: number): Color; /** Clear image background with given color */ -declare function imageClearBackground(dst: Image *, color: Color): void; +declare function imageClearBackground(dst: Image, color: Color): void; /** Draw pixel within an image */ -declare function imageDrawPixel(dst: Image *, posX: number, posY: number, color: Color): void; +declare function imageDrawPixel(dst: Image, posX: number, posY: number, color: Color): void; /** Draw pixel within an image (Vector version) */ -declare function imageDrawPixelV(dst: Image *, position: Vector2, color: Color): void; +declare function imageDrawPixelV(dst: Image, position: Vector2, color: Color): void; /** Draw line within an image */ -declare function imageDrawLine(dst: Image *, startPosX: number, startPosY: number, endPosX: number, endPosY: number, color: Color): void; +declare function imageDrawLine(dst: Image, startPosX: number, startPosY: number, endPosX: number, endPosY: number, color: Color): void; /** Draw line within an image (Vector version) */ -declare function imageDrawLineV(dst: Image *, start: Vector2, end: Vector2, color: Color): void; +declare function imageDrawLineV(dst: Image, start: Vector2, end: Vector2, color: Color): void; /** Draw a filled circle within an image */ -declare function imageDrawCircle(dst: Image *, centerX: number, centerY: number, radius: number, color: Color): void; +declare function imageDrawCircle(dst: Image, centerX: number, centerY: number, radius: number, color: Color): void; /** Draw a filled circle within an image (Vector version) */ -declare function imageDrawCircleV(dst: Image *, center: Vector2, radius: number, color: Color): void; +declare function imageDrawCircleV(dst: Image, center: Vector2, radius: number, color: Color): void; /** Draw circle outline within an image */ -declare function imageDrawCircleLines(dst: Image *, centerX: number, centerY: number, radius: number, color: Color): void; +declare function imageDrawCircleLines(dst: Image, centerX: number, centerY: number, radius: number, color: Color): void; /** Draw circle outline within an image (Vector version) */ -declare function imageDrawCircleLinesV(dst: Image *, center: Vector2, radius: number, color: Color): void; +declare function imageDrawCircleLinesV(dst: Image, center: Vector2, radius: number, color: Color): void; /** Draw rectangle within an image */ -declare function imageDrawRectangle(dst: Image *, posX: number, posY: number, width: number, height: number, color: Color): void; +declare function imageDrawRectangle(dst: Image, posX: number, posY: number, width: number, height: number, color: Color): void; /** Draw rectangle within an image (Vector version) */ -declare function imageDrawRectangleV(dst: Image *, position: Vector2, size: Vector2, color: Color): void; +declare function imageDrawRectangleV(dst: Image, position: Vector2, size: Vector2, color: Color): void; /** Draw rectangle within an image */ -declare function imageDrawRectangleRec(dst: Image *, rec: Rectangle, color: Color): void; +declare function imageDrawRectangleRec(dst: Image, rec: Rectangle, color: Color): void; /** Draw rectangle lines within an image */ -declare function imageDrawRectangleLines(dst: Image *, rec: Rectangle, thick: number, color: Color): void; +declare function imageDrawRectangleLines(dst: Image, rec: Rectangle, thick: number, color: Color): void; /** Draw a source image within a destination image (tint applied to source) */ -declare function imageDraw(dst: Image *, src: Image, srcRec: Rectangle, dstRec: Rectangle, tint: Color): void; +declare function imageDraw(dst: Image, src: Image, srcRec: Rectangle, dstRec: Rectangle, tint: Color): void; /** Draw text (using default font) within an image (destination) */ -declare function imageDrawText(dst: Image *, text: string, posX: number, posY: number, fontSize: number, color: Color): void; +declare function imageDrawText(dst: Image, text: string, posX: number, posY: number, fontSize: number, color: Color): void; /** Draw text (custom sprite font) within an image (destination) */ -declare function imageDrawTextEx(dst: Image *, font: Font, text: string, position: Vector2, fontSize: number, spacing: number, tint: Color): void; +declare function imageDrawTextEx(dst: Image, font: Font, text: string, position: Vector2, fontSize: number, spacing: number, tint: Color): void; /** Load texture from file into GPU memory (VRAM) */ -declare function loadTexture(fileName: string): Texture2D; +declare function loadTexture(fileName: string): Texture; /** Load texture from image data */ -declare function loadTextureFromImage(image: Image): Texture2D; +declare function loadTextureFromImage(image: Image): Texture; /** Load cubemap from image, multiple image cubemap layouts supported */ -declare function loadTextureCubemap(image: Image, layout: number): TextureCubemap; +declare function loadTextureCubemap(image: Image, layout: number): Texture; /** Check if a texture is ready */ -declare function isTextureReady(texture: Texture2D): boolean; +declare function isTextureReady(texture: Texture): boolean; /** Generate GPU mipmaps for a texture */ -declare function genTextureMipmaps(texture: Texture2D *): void; +declare function genTextureMipmaps(texture: Texture2D): void; /** Set texture scaling filter mode */ -declare function setTextureFilter(texture: Texture2D, filter: number): void; +declare function setTextureFilter(texture: Texture, filter: number): void; /** Set texture wrapping mode */ -declare function setTextureWrap(texture: Texture2D, wrap: number): void; +declare function setTextureWrap(texture: Texture, wrap: number): void; /** Draw a Texture2D */ -declare function drawTexture(texture: Texture2D, posX: number, posY: number, tint: Color): void; +declare function drawTexture(texture: Texture, posX: number, posY: number, tint: Color): void; /** Draw a Texture2D with position defined as Vector2 */ -declare function drawTextureV(texture: Texture2D, position: Vector2, tint: Color): void; +declare function drawTextureV(texture: Texture, position: Vector2, tint: Color): void; /** Draw a Texture2D with extended parameters */ -declare function drawTextureEx(texture: Texture2D, position: Vector2, rotation: number, scale: number, tint: Color): void; +declare function drawTextureEx(texture: Texture, position: Vector2, rotation: number, scale: number, tint: Color): void; /** Draw a part of a texture defined by a rectangle */ -declare function drawTextureRec(texture: Texture2D, source: Rectangle, position: Vector2, tint: Color): void; +declare function drawTextureRec(texture: Texture, source: Rectangle, position: Vector2, tint: Color): void; /** Draw a part of a texture defined by a rectangle with 'pro' parameters */ -declare function drawTexturePro(texture: Texture2D, source: Rectangle, dest: Rectangle, origin: Vector2, rotation: number, tint: Color): void; +declare function drawTexturePro(texture: Texture, source: Rectangle, dest: Rectangle, origin: Vector2, rotation: number, tint: Color): void; /** Get color with alpha applied, alpha goes from 0.0f to 1.0f */ declare function fade(color: Color, alpha: number): Color; /** Get hexadecimal value for a Color */ @@ -832,19 +834,19 @@ declare function drawModelWiresEx(model: Model, position: Vector3, rotationAxis: /** Draw bounding box (wires) */ declare function drawBoundingBox(box: BoundingBox, color: Color): void; /** Draw a billboard texture */ -declare function drawBillboard(camera: Camera, texture: Texture2D, position: Vector3, size: number, tint: Color): void; +declare function drawBillboard(camera: Camera3D, texture: Texture, position: Vector3, size: number, tint: Color): void; /** Draw a billboard texture defined by source */ -declare function drawBillboardRec(camera: Camera, texture: Texture2D, source: Rectangle, position: Vector3, size: Vector2, tint: Color): void; +declare function drawBillboardRec(camera: Camera3D, texture: Texture, source: Rectangle, position: Vector3, size: Vector2, tint: Color): void; /** Draw a billboard texture defined by source and rotation */ -declare function drawBillboardPro(camera: Camera, texture: Texture2D, source: Rectangle, position: Vector3, up: Vector3, size: Vector2, origin: Vector2, rotation: number, tint: Color): void; +declare function drawBillboardPro(camera: Camera3D, texture: Texture, source: Rectangle, position: Vector3, up: Vector3, size: Vector2, origin: Vector2, rotation: number, tint: Color): void; /** Upload mesh vertex data in GPU and provide VAO/VBO ids */ -declare function uploadMesh(mesh: Mesh *, dynamic: boolean): void; +declare function uploadMesh(mesh: Mesh, dynamic: boolean): void; /** Export mesh data to file, returns true on success */ declare function exportMesh(mesh: Mesh, fileName: string): boolean; /** Compute mesh bounding box limits */ declare function getMeshBoundingBox(mesh: Mesh): BoundingBox; /** Compute mesh tangents */ -declare function genMeshTangents(mesh: Mesh *): void; +declare function genMeshTangents(mesh: Mesh): void; /** Generate polygonal mesh */ declare function genMeshPoly(sides: number, radius: number): Mesh; /** Generate plane mesh (with subdivisions) */ @@ -922,9 +924,9 @@ declare function setSoundPan(sound: Sound, pan: number): void; /** Copy a wave to a new wave */ declare function waveCopy(wave: Wave): Wave; /** Crop a wave to defined samples range */ -declare function waveCrop(wave: Wave *, initSample: number, finalSample: number): void; +declare function waveCrop(wave: Wave, initSample: number, finalSample: number): void; /** Convert wave data to desired format */ -declare function waveFormat(wave: Wave *, sampleRate: number, sampleSize: number, channels: number): void; +declare function waveFormat(wave: Wave, sampleRate: number, sampleSize: number, channels: number): void; /** Load music stream from file */ declare function loadMusicStream(fileName: string): Music; /** Checks if a music stream is ready */ @@ -1060,7 +1062,7 @@ declare function vector3Normalize(v: Vector3): Vector3; /** */ declare function vector3Transform(v: Vector3, mat: Matrix): Vector3; /** */ -declare function vector3RotateByQuaternion(v: Vector3, q: Quaternion): Vector3; +declare function vector3RotateByQuaternion(v: Vector3, q: Vector4): Vector3; /** */ declare function vector3RotateByAxisAngle(v: Vector3, axis: Vector3, angle: number): Vector3; /** */ @@ -1126,49 +1128,49 @@ declare function matrixOrtho(left: number, right: number, bottom: number, top: n /** */ declare function matrixLookAt(eye: Vector3, target: Vector3, up: Vector3): Matrix; /** */ -declare function quaternionAdd(q1: Quaternion, q2: Quaternion): Quaternion; +declare function quaternionAdd(q1: Vector4, q2: Vector4): Vector4; /** */ -declare function quaternionAddValue(q: Quaternion, add: number): Quaternion; +declare function quaternionAddValue(q: Vector4, add: number): Vector4; /** */ -declare function quaternionSubtract(q1: Quaternion, q2: Quaternion): Quaternion; +declare function quaternionSubtract(q1: Vector4, q2: Vector4): Vector4; /** */ -declare function quaternionSubtractValue(q: Quaternion, sub: number): Quaternion; +declare function quaternionSubtractValue(q: Vector4, sub: number): Vector4; /** */ -declare function quaternionIdentity(): Quaternion; +declare function quaternionIdentity(): Vector4; /** */ -declare function quaternionLength(q: Quaternion): number; +declare function quaternionLength(q: Vector4): number; /** */ -declare function quaternionNormalize(q: Quaternion): Quaternion; +declare function quaternionNormalize(q: Vector4): Vector4; /** */ -declare function quaternionInvert(q: Quaternion): Quaternion; +declare function quaternionInvert(q: Vector4): Vector4; /** */ -declare function quaternionMultiply(q1: Quaternion, q2: Quaternion): Quaternion; +declare function quaternionMultiply(q1: Vector4, q2: Vector4): Vector4; /** */ -declare function quaternionScale(q: Quaternion, mul: number): Quaternion; +declare function quaternionScale(q: Vector4, mul: number): Vector4; /** */ -declare function quaternionDivide(q1: Quaternion, q2: Quaternion): Quaternion; +declare function quaternionDivide(q1: Vector4, q2: Vector4): Vector4; /** */ -declare function quaternionLerp(q1: Quaternion, q2: Quaternion, amount: number): Quaternion; +declare function quaternionLerp(q1: Vector4, q2: Vector4, amount: number): Vector4; /** */ -declare function quaternionNlerp(q1: Quaternion, q2: Quaternion, amount: number): Quaternion; +declare function quaternionNlerp(q1: Vector4, q2: Vector4, amount: number): Vector4; /** */ -declare function quaternionSlerp(q1: Quaternion, q2: Quaternion, amount: number): Quaternion; +declare function quaternionSlerp(q1: Vector4, q2: Vector4, amount: number): Vector4; /** */ -declare function quaternionFromVector3ToVector3(from: Vector3, to: Vector3): Quaternion; +declare function quaternionFromVector3ToVector3(from: Vector3, to: Vector3): Vector4; /** */ -declare function quaternionFromMatrix(mat: Matrix): Quaternion; +declare function quaternionFromMatrix(mat: Matrix): Vector4; /** */ -declare function quaternionToMatrix(q: Quaternion): Matrix; +declare function quaternionToMatrix(q: Vector4): Matrix; /** */ -declare function quaternionFromAxisAngle(axis: Vector3, angle: number): Quaternion; +declare function quaternionFromAxisAngle(axis: Vector3, angle: number): Vector4; /** */ -declare function quaternionFromEuler(pitch: number, yaw: number, roll: number): Quaternion; +declare function quaternionFromEuler(pitch: number, yaw: number, roll: number): Vector4; /** */ -declare function quaternionToEuler(q: Quaternion): Vector3; +declare function quaternionToEuler(q: Vector4): Vector3; /** */ -declare function quaternionTransform(q: Quaternion, mat: Matrix): Quaternion; +declare function quaternionTransform(q: Vector4, mat: Matrix): Vector4; /** */ -declare function quaternionEquals(p: Quaternion, q: Quaternion): number; +declare function quaternionEquals(p: Vector4, q: Vector4): number; /** Light Gray */ declare var LIGHTGRAY: Color; /** Gray */ @@ -1595,3 +1597,73 @@ declare var CAMERA_ORBITAL: number; declare var CAMERA_FIRST_PERSON: number; /** Third person camera */ declare var CAMERA_THIRD_PERSON: number; +/** Shader location: vertex attribute: position */ +declare var SHADER_LOC_VERTEX_POSITION: number; +/** Shader location: vertex attribute: texcoord01 */ +declare var SHADER_LOC_VERTEX_TEXCOORD01: number; +/** Shader location: vertex attribute: texcoord02 */ +declare var SHADER_LOC_VERTEX_TEXCOORD02: number; +/** Shader location: vertex attribute: normal */ +declare var SHADER_LOC_VERTEX_NORMAL: number; +/** Shader location: vertex attribute: tangent */ +declare var SHADER_LOC_VERTEX_TANGENT: number; +/** Shader location: vertex attribute: color */ +declare var SHADER_LOC_VERTEX_COLOR: number; +/** Shader location: matrix uniform: model-view-projection */ +declare var SHADER_LOC_MATRIX_MVP: number; +/** Shader location: matrix uniform: view (camera transform) */ +declare var SHADER_LOC_MATRIX_VIEW: number; +/** Shader location: matrix uniform: projection */ +declare var SHADER_LOC_MATRIX_PROJECTION: number; +/** Shader location: matrix uniform: model (transform) */ +declare var SHADER_LOC_MATRIX_MODEL: number; +/** Shader location: matrix uniform: normal */ +declare var SHADER_LOC_MATRIX_NORMAL: number; +/** Shader location: vector uniform: view */ +declare var SHADER_LOC_VECTOR_VIEW: number; +/** Shader location: vector uniform: diffuse color */ +declare var SHADER_LOC_COLOR_DIFFUSE: number; +/** Shader location: vector uniform: specular color */ +declare var SHADER_LOC_COLOR_SPECULAR: number; +/** Shader location: vector uniform: ambient color */ +declare var SHADER_LOC_COLOR_AMBIENT: number; +/** Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE) */ +declare var SHADER_LOC_MAP_ALBEDO: number; +/** Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR) */ +declare var SHADER_LOC_MAP_METALNESS: number; +/** Shader location: sampler2d texture: normal */ +declare var SHADER_LOC_MAP_NORMAL: number; +/** Shader location: sampler2d texture: roughness */ +declare var SHADER_LOC_MAP_ROUGHNESS: number; +/** Shader location: sampler2d texture: occlusion */ +declare var SHADER_LOC_MAP_OCCLUSION: number; +/** Shader location: sampler2d texture: emission */ +declare var SHADER_LOC_MAP_EMISSION: number; +/** Shader location: sampler2d texture: height */ +declare var SHADER_LOC_MAP_HEIGHT: number; +/** Shader location: samplerCube texture: cubemap */ +declare var SHADER_LOC_MAP_CUBEMAP: number; +/** Shader location: samplerCube texture: irradiance */ +declare var SHADER_LOC_MAP_IRRADIANCE: number; +/** Shader location: samplerCube texture: prefilter */ +declare var SHADER_LOC_MAP_PREFILTER: number; +/** Shader location: sampler2d texture: brdf */ +declare var SHADER_LOC_MAP_BRDF: number; +/** Shader uniform type: float */ +declare var SHADER_UNIFORM_FLOAT: number; +/** Shader uniform type: vec2 (2 float) */ +declare var SHADER_UNIFORM_VEC2: number; +/** Shader uniform type: vec3 (3 float) */ +declare var SHADER_UNIFORM_VEC3: number; +/** Shader uniform type: vec4 (4 float) */ +declare var SHADER_UNIFORM_VEC4: number; +/** Shader uniform type: int */ +declare var SHADER_UNIFORM_INT: number; +/** Shader uniform type: ivec2 (2 int) */ +declare var SHADER_UNIFORM_IVEC2: number; +/** Shader uniform type: ivec3 (3 int) */ +declare var SHADER_UNIFORM_IVEC3: number; +/** Shader uniform type: ivec4 (4 int) */ +declare var SHADER_UNIFORM_IVEC4: number; +/** Shader uniform type: sampler2d */ +declare var SHADER_UNIFORM_SAMPLER2D: number; diff --git a/examples/raymarching.js b/examples/raymarching.js index a9fbd9d..bc72f3d 100644 --- a/examples/raymarching.js +++ b/examples/raymarching.js @@ -15,7 +15,7 @@ const camera = new Camera3D(position,target, up, fovy, projection) // Load raymarching shader // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader -const shader = loadShader(0, "assets/shaders/glsl330/raymarching.fs"); +const shader = loadShader(null, "assets/shaders/glsl330/raymarching.fs"); // Get shader locations for required uniforms const viewEyeLoc = getShaderLocation(shader, "viewEye"); @@ -43,8 +43,8 @@ while (!windowShouldClose()) // Detect window close button or ESC key runTime += deltaTime; // Set shader required uniform values - setShaderValue(shader, viewEyeLoc, position, SHADER_UNIFORM_VEC3); - setShaderValue(shader, viewCenterLoc, target, SHADER_UNIFORM_VEC3); + setShaderValue(shader, viewEyeLoc, camera.position, SHADER_UNIFORM_VEC3); + setShaderValue(shader, viewCenterLoc, camera.target, SHADER_UNIFORM_VEC3); setShaderValue(shader, runTimeLoc, runTime, SHADER_UNIFORM_FLOAT); // Check if screen is resized diff --git a/generate-bindings.js b/generate-bindings.js index 6420ac7..02986cb 100644 --- a/generate-bindings.js +++ b/generate-bindings.js @@ -267,6 +267,37 @@ class GenericCodeGenerator { this.inline("static "); this.statement(`${structName} ${varName} = { ${values.join(', ')} }`); } + switch(switchVar) { + this.line(`switch(${switchVar}) {`); + this.indent(); + const body = this.child(); + this.unindent(); + this.line("}"); + return body; + } + case(value) { + this.line(`case ${value}:`); + } + defaultBreak() { + this.line("default:"); + this.line("{"); + this.indent(); + const body = this.child(); + this.statement("break"); + this.unindent(); + this.line("}"); + return body; + } + caseBreak(value) { + this.case(value); + this.line("{"); + this.indent(); + const body = this.child(); + this.statement("break"); + this.unindent(); + this.line("}"); + return body; + } } exports.GenericCodeGenerator = GenericCodeGenerator; class CodeGenerator extends GenericCodeGenerator { @@ -350,7 +381,6 @@ class GenericQuickJsGenerator extends generation_1.GenericCodeGenerator { case "const char *": case "char *": this.statement(`${type} ${name} = (${type})JS_ToCString(ctx, ${src})`); - this.statement(`if(${name} == NULL) return JS_EXCEPTION`); break; case "double": this.statement(`${type} ${name}`); @@ -558,28 +588,33 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { addApiFunction(api, jsName = null, options = {}) { const jName = jsName || api.name.charAt(0).toLowerCase() + api.name.slice(1); const fun = this.functions.jsBindingFunction(jName); - if (options.before) - options.before(fun); - // read parameters - for (let i = 0; i < api.params.length; i++) { - const para = api.params[i]; - fun.jsToC(para.type, para.name, "argv[" + i + "]", this.structLookup); - } - // call c function - fun.call(api.name, api.params.map(x => x.name), api.returnType === "void" ? null : { type: api.returnType, name: "returnVal" }); - // clean up parameters - for (const param of api.params) { - fun.jsCleanUpParameter(param.type, param.name); - } - if (options.after) - options.after(fun); - // return result - if (api.returnType === "void") { - fun.statement("return JS_UNDEFINED"); + if (options.body) { + options.body(fun); } else { - fun.jsToJs(api.returnType, "ret", "returnVal", this.structLookup); - fun.returnExp("ret"); + if (options.before) + options.before(fun); + // read parameters + for (let i = 0; i < api.params.length; i++) { + const para = api.params[i]; + fun.jsToC(para.type, para.name, "argv[" + i + "]", this.structLookup); + } + // call c function + fun.call(api.name, api.params.map(x => x.name), api.returnType === "void" ? null : { type: api.returnType, name: "returnVal" }); + // clean up parameters + for (const param of api.params) { + fun.jsCleanUpParameter(param.type, param.name); + } + if (options.after) + options.after(fun); + // return result + if (api.returnType === "void") { + fun.statement("return JS_UNDEFINED"); + } + else { + fun.jsToJs(api.returnType, "ret", "returnVal", this.structLookup); + fun.returnExp("ret"); + } } // add binding to function declaration this.moduleFunctionList.jsFuncDef(jName, api.argc, fun.getTag("_name")); @@ -606,7 +641,7 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { let _get = undefined; let _set = undefined; if (el.get) - _get = this.structs.jsStructGetter(struct.name, classId, field, type, /*Be carefull when allocating memory in a getter*/ {}); + _get = this.structs.jsStructGetter(struct.name, classId, field, type, /*Be carefull when allocating memory in a getter*/ this.structLookup); if (el.set) _set = this.structs.jsStructSetter(struct.name, classId, field, type, this.structLookup); propDeclarations.jsGetSetDef(field, _get?.getTag("_name"), _set?.getTag("_name")); @@ -700,8 +735,18 @@ class TypeScriptDeclaration { case "const char *": case "char *": return "string"; + case "void *": + case "const void *": + return "any"; + case "Camera": + return "Camera3D"; + case "Texture2D": + case "TextureCubemap": + return "Texture"; + case "Quaternion": + return "Vector4"; default: - return type; + return type.replace(" *", ""); } } writeTo(filename) { @@ -903,8 +948,8 @@ function main() { }); core.addApiStructByName("Camera3D", { properties: { - position: { get: false, set: true }, - target: { get: false, set: true }, + position: { get: true, set: true }, + target: { get: true, set: true }, up: { get: false, set: true }, fovy: { get: true, set: true }, projection: { get: true, set: true }, @@ -1057,7 +1102,32 @@ function main() { core.addApiFunctionByName("IsShaderReady"); core.addApiFunctionByName("GetShaderLocation"); core.addApiFunctionByName("GetShaderLocationAttrib"); - // core.addApiFunctionByName("SetShaderValue") + core.addApiFunctionByName("SetShaderValue", null, { body: (gen) => { + gen.jsToC("Shader", "shader", "argv[0]", core.structLookup); + gen.jsToC("int", "locIndex", "argv[1]", core.structLookup); + gen.declare("value", "void *", false, "NULL"); + gen.jsToC("int", "uniformType", "argv[3]", core.structLookup); + const sw = gen.switch("uniformType"); + let b = sw.caseBreak("SHADER_UNIFORM_FLOAT"); + b.jsToC("float", "valueFloat", "argv[2]", core.structLookup); + b.statement("value = (void *)&valueFloat"); + b = sw.caseBreak("SHADER_UNIFORM_VEC2"); + b.jsToC("Vector2 *", "valueV2", "argv[2]", core.structLookup); + b.statement("value = (void*)valueV2"); + b = sw.caseBreak("SHADER_UNIFORM_VEC3"); + b.jsToC("Vector3 *", "valueV3", "argv[2]", core.structLookup); + b.statement("value = (void*)valueV3"); + b = sw.caseBreak("SHADER_UNIFORM_VEC4"); + b.jsToC("Vector4 *", "valueV4", "argv[2]", core.structLookup); + b.statement("value = (void*)valueV4"); + b = sw.caseBreak("SHADER_UNIFORM_INT"); + b.jsToC("int", "valueInt", "argv[2]", core.structLookup); + b.statement("value = (void*)&valueInt"); + b = sw.defaultBreak(); + b.returnExp("JS_EXCEPTION"); + gen.call("SetShaderValue", ["shader", "locIndex", "value", "uniformType"]); + gen.returnExp("JS_UNDEFINED"); + } }); // core.addApiFunctionByName("SetShaderValueV") core.addApiFunctionByName("SetShaderValueMatrix"); core.addApiFunctionByName("SetShaderValueTexture"); @@ -1653,6 +1723,8 @@ function main() { api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); api.enums.find(x => x.name === "CameraMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "ShaderLocationIndex")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "ShaderUniformDataType")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); core.writeTo("src/bindings/js_raylib_core.h"); core.typings.writeTo("examples/lib.raylib.d.ts"); } diff --git a/src/bindings/js_raylib_core.h b/src/bindings/js_raylib_core.h index a336095..8f458e7 100644 --- a/src/bindings/js_raylib_core.h +++ b/src/bindings/js_raylib_core.h @@ -720,6 +720,19 @@ static void js_Camera3D_finalizer(JSRuntime * rt, JSValue val) { } } +static JSValue js_Camera3D_get_position(JSContext* ctx, JSValueConst this_val) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + Vector3 position = ptr->position; + Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3)); + *ret_ptr = position; + JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + static JSValue js_Camera3D_set_position(JSContext* ctx, JSValueConst this_val, JSValueConst v) { Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); if(!ptr) { @@ -732,6 +745,19 @@ static JSValue js_Camera3D_set_position(JSContext* ctx, JSValueConst this_val, J return JS_UNDEFINED; } +static JSValue js_Camera3D_get_target(JSContext* ctx, JSValueConst this_val) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + Vector3 target = ptr->target; + Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3)); + *ret_ptr = target; + JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + static JSValue js_Camera3D_set_target(JSContext* ctx, JSValueConst this_val, JSValueConst v) { Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); if(!ptr) { @@ -800,8 +826,8 @@ static JSValue js_Camera3D_set_projection(JSContext* ctx, JSValueConst this_val, } static const JSCFunctionListEntry js_Camera3D_proto_funcs[] = { - JS_CGETSET_DEF("position",NULL,js_Camera3D_set_position), - JS_CGETSET_DEF("target",NULL,js_Camera3D_set_target), + JS_CGETSET_DEF("position",js_Camera3D_get_position,js_Camera3D_set_position), + JS_CGETSET_DEF("target",js_Camera3D_get_target,js_Camera3D_set_target), JS_CGETSET_DEF("up",NULL,js_Camera3D_set_up), JS_CGETSET_DEF("fovy",js_Camera3D_get_fovy,js_Camera3D_set_fovy), JS_CGETSET_DEF("projection",js_Camera3D_get_projection,js_Camera3D_set_projection), @@ -1398,7 +1424,6 @@ static JSValue js_initWindow(JSContext * ctx, JSValueConst this_val, int argc, J int height; JS_ToInt32(ctx, &height, argv[1]); const char * title = (const char *)JS_ToCString(ctx, argv[2]); - if(title == NULL) return JS_EXCEPTION; InitWindow(width, height, title); JS_FreeCString(ctx, title); return JS_UNDEFINED; @@ -1509,7 +1534,6 @@ static JSValue js_setWindowIcon(JSContext * ctx, JSValueConst this_val, int argc static JSValue js_setWindowTitle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * title = (const char *)JS_ToCString(ctx, argv[0]); - if(title == NULL) return JS_EXCEPTION; SetWindowTitle(title); JS_FreeCString(ctx, title); return JS_UNDEFINED; @@ -1672,7 +1696,6 @@ static JSValue js_getMonitorName(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_setClipboardText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * text = (const char *)JS_ToCString(ctx, argv[0]); - if(text == NULL) return JS_EXCEPTION; SetClipboardText(text); JS_FreeCString(ctx, text); return JS_UNDEFINED; @@ -1816,9 +1839,7 @@ static JSValue js_endScissorMode(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_loadShader(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * vsFileName = (const char *)JS_ToCString(ctx, argv[0]); - if(vsFileName == NULL) return JS_EXCEPTION; const char * fsFileName = (const char *)JS_ToCString(ctx, argv[1]); - if(fsFileName == NULL) return JS_EXCEPTION; Shader returnVal = LoadShader(vsFileName, fsFileName); JS_FreeCString(ctx, vsFileName); JS_FreeCString(ctx, fsFileName); @@ -1843,7 +1864,6 @@ static JSValue js_getShaderLocation(JSContext * ctx, JSValueConst this_val, int if(shader_ptr == NULL) return JS_EXCEPTION; Shader shader = *shader_ptr; const char * uniformName = (const char *)JS_ToCString(ctx, argv[1]); - if(uniformName == NULL) return JS_EXCEPTION; int returnVal = GetShaderLocation(shader, uniformName); JS_FreeCString(ctx, uniformName); JSValue ret = JS_NewInt32(ctx, returnVal); @@ -1855,13 +1875,68 @@ static JSValue js_getShaderLocationAttrib(JSContext * ctx, JSValueConst this_val if(shader_ptr == NULL) return JS_EXCEPTION; Shader shader = *shader_ptr; const char * attribName = (const char *)JS_ToCString(ctx, argv[1]); - if(attribName == NULL) return JS_EXCEPTION; int returnVal = GetShaderLocationAttrib(shader, attribName); JS_FreeCString(ctx, attribName); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; } +static JSValue js_setShaderValue(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Shader* shader_ptr = (Shader*)JS_GetOpaque2(ctx, argv[0], js_Shader_class_id); + if(shader_ptr == NULL) return JS_EXCEPTION; + Shader shader = *shader_ptr; + int locIndex; + JS_ToInt32(ctx, &locIndex, argv[1]); + void * value = NULL; + int uniformType; + JS_ToInt32(ctx, &uniformType, argv[3]); + switch(uniformType) { + case SHADER_UNIFORM_FLOAT: + { + double _double_valueFloat; + JS_ToFloat64(ctx, &_double_valueFloat, argv[2]); + float valueFloat = (float)_double_valueFloat; + value = (void *)&valueFloat; + break; + } + case SHADER_UNIFORM_VEC2: + { + Vector2* valueV2 = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(valueV2 == NULL) return JS_EXCEPTION; + value = (void*)valueV2; + break; + } + case SHADER_UNIFORM_VEC3: + { + Vector3* valueV3 = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(valueV3 == NULL) return JS_EXCEPTION; + value = (void*)valueV3; + break; + } + case SHADER_UNIFORM_VEC4: + { + Vector4* valueV4 = (Vector4*)JS_GetOpaque2(ctx, argv[2], js_Vector4_class_id); + if(valueV4 == NULL) return JS_EXCEPTION; + value = (void*)valueV4; + break; + } + case SHADER_UNIFORM_INT: + { + int valueInt; + JS_ToInt32(ctx, &valueInt, argv[2]); + value = (void*)&valueInt; + break; + } + default: + { + return JS_EXCEPTION; + break; + } + } + SetShaderValue(shader, locIndex, value, uniformType); + return JS_UNDEFINED; +} + static JSValue js_setShaderValueMatrix(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { Shader* shader_ptr = (Shader*)JS_GetOpaque2(ctx, argv[0], js_Shader_class_id); if(shader_ptr == NULL) return JS_EXCEPTION; @@ -2035,7 +2110,6 @@ static JSValue js_setRandomSeed(JSContext * ctx, JSValueConst this_val, int argc static JSValue js_takeScreenshot(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; TakeScreenshot(fileName); JS_FreeCString(ctx, fileName); return JS_UNDEFINED; @@ -2052,7 +2126,6 @@ static JSValue js_traceLog(JSContext * ctx, JSValueConst this_val, int argc, JSV int logLevel; JS_ToInt32(ctx, &logLevel, argv[0]); const char * text = (const char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; TraceLog(logLevel, text); JS_FreeCString(ctx, text); return JS_UNDEFINED; @@ -2067,7 +2140,6 @@ static JSValue js_setTraceLogLevel(JSContext * ctx, JSValueConst this_val, int a static JSValue js_openURL(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * url = (const char *)JS_ToCString(ctx, argv[0]); - if(url == NULL) return JS_EXCEPTION; OpenURL(url); JS_FreeCString(ctx, url); return JS_UNDEFINED; @@ -2075,7 +2147,6 @@ static JSValue js_openURL(JSContext * ctx, JSValueConst this_val, int argc, JSVa static JSValue js_loadFileText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; char * returnVal = LoadFileText(fileName); JS_FreeCString(ctx, fileName); UnloadFileText(returnVal); @@ -2085,9 +2156,7 @@ static JSValue js_loadFileText(JSContext * ctx, JSValueConst this_val, int argc, static JSValue js_saveFileText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; char * text = (char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; bool returnVal = SaveFileText(fileName, text); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewBool(ctx, returnVal); @@ -2096,7 +2165,6 @@ static JSValue js_saveFileText(JSContext * ctx, JSValueConst this_val, int argc, static JSValue js_fileExists(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; bool returnVal = FileExists(fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewBool(ctx, returnVal); @@ -2105,7 +2173,6 @@ static JSValue js_fileExists(JSContext * ctx, JSValueConst this_val, int argc, J static JSValue js_directoryExists(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * dirPath = (const char *)JS_ToCString(ctx, argv[0]); - if(dirPath == NULL) return JS_EXCEPTION; bool returnVal = DirectoryExists(dirPath); JS_FreeCString(ctx, dirPath); JSValue ret = JS_NewBool(ctx, returnVal); @@ -2114,9 +2181,7 @@ static JSValue js_directoryExists(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_isFileExtension(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; const char * ext = (const char *)JS_ToCString(ctx, argv[1]); - if(ext == NULL) return JS_EXCEPTION; bool returnVal = IsFileExtension(fileName, ext); JS_FreeCString(ctx, fileName); JS_FreeCString(ctx, ext); @@ -2126,7 +2191,6 @@ static JSValue js_isFileExtension(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_getFileLength(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; int returnVal = GetFileLength(fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewInt32(ctx, returnVal); @@ -2135,7 +2199,6 @@ static JSValue js_getFileLength(JSContext * ctx, JSValueConst this_val, int argc static JSValue js_getFileExtension(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; const char * returnVal = GetFileExtension(fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewString(ctx, returnVal); @@ -2144,7 +2207,6 @@ static JSValue js_getFileExtension(JSContext * ctx, JSValueConst this_val, int a static JSValue js_getFileName(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * filePath = (const char *)JS_ToCString(ctx, argv[0]); - if(filePath == NULL) return JS_EXCEPTION; const char * returnVal = GetFileName(filePath); JS_FreeCString(ctx, filePath); JSValue ret = JS_NewString(ctx, returnVal); @@ -2153,7 +2215,6 @@ static JSValue js_getFileName(JSContext * ctx, JSValueConst this_val, int argc, static JSValue js_getFileNameWithoutExt(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * filePath = (const char *)JS_ToCString(ctx, argv[0]); - if(filePath == NULL) return JS_EXCEPTION; const char * returnVal = GetFileNameWithoutExt(filePath); JS_FreeCString(ctx, filePath); JSValue ret = JS_NewString(ctx, returnVal); @@ -2162,7 +2223,6 @@ static JSValue js_getFileNameWithoutExt(JSContext * ctx, JSValueConst this_val, static JSValue js_getDirectoryPath(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * filePath = (const char *)JS_ToCString(ctx, argv[0]); - if(filePath == NULL) return JS_EXCEPTION; const char * returnVal = GetDirectoryPath(filePath); JS_FreeCString(ctx, filePath); JSValue ret = JS_NewString(ctx, returnVal); @@ -2171,7 +2231,6 @@ static JSValue js_getDirectoryPath(JSContext * ctx, JSValueConst this_val, int a static JSValue js_getPrevDirectoryPath(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * dirPath = (const char *)JS_ToCString(ctx, argv[0]); - if(dirPath == NULL) return JS_EXCEPTION; const char * returnVal = GetPrevDirectoryPath(dirPath); JS_FreeCString(ctx, dirPath); JSValue ret = JS_NewString(ctx, returnVal); @@ -2192,7 +2251,6 @@ static JSValue js_getApplicationDirectory(JSContext * ctx, JSValueConst this_val static JSValue js_changeDirectory(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * dir = (const char *)JS_ToCString(ctx, argv[0]); - if(dir == NULL) return JS_EXCEPTION; bool returnVal = ChangeDirectory(dir); JS_FreeCString(ctx, dir); JSValue ret = JS_NewBool(ctx, returnVal); @@ -2201,7 +2259,6 @@ static JSValue js_changeDirectory(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_isPathFile(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * path = (const char *)JS_ToCString(ctx, argv[0]); - if(path == NULL) return JS_EXCEPTION; bool returnVal = IsPathFile(path); JS_FreeCString(ctx, path); JSValue ret = JS_NewBool(ctx, returnVal); @@ -2216,7 +2273,6 @@ static JSValue js_isFileDropped(JSContext * ctx, JSValueConst this_val, int argc static JSValue js_getFileModTime(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; long returnVal = GetFileModTime(fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewInt32(ctx, returnVal); @@ -2356,7 +2412,6 @@ static JSValue js_getGamepadAxisMovement(JSContext * ctx, JSValueConst this_val, static JSValue js_setGamepadMappings(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * mappings = (const char *)JS_ToCString(ctx, argv[0]); - if(mappings == NULL) return JS_EXCEPTION; int returnVal = SetGamepadMappings(mappings); JS_FreeCString(ctx, mappings); JSValue ret = JS_NewInt32(ctx, returnVal); @@ -3316,7 +3371,6 @@ static JSValue js_getCollisionRec(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_loadImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Image returnVal = LoadImage(fileName); JS_FreeCString(ctx, fileName); Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); @@ -3328,7 +3382,6 @@ static JSValue js_loadImage(JSContext * ctx, JSValueConst this_val, int argc, JS static JSValue js_loadImageRaw(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; int width; JS_ToInt32(ctx, &width, argv[1]); int height; @@ -3381,7 +3434,6 @@ static JSValue js_exportImage(JSContext * ctx, JSValueConst this_val, int argc, if(image_ptr == NULL) return JS_EXCEPTION; Image image = *image_ptr; const char * fileName = (const char *)JS_ToCString(ctx, argv[1]); - if(fileName == NULL) return JS_EXCEPTION; bool returnVal = ExportImage(image, fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewBool(ctx, returnVal); @@ -3544,7 +3596,6 @@ static JSValue js_genImageText(JSContext * ctx, JSValueConst this_val, int argc, int height; JS_ToInt32(ctx, &height, argv[1]); const char * text = (const char *)JS_ToCString(ctx, argv[2]); - if(text == NULL) return JS_EXCEPTION; Image returnVal = GenImageText(width, height, text); JS_FreeCString(ctx, text); Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); @@ -3583,7 +3634,6 @@ static JSValue js_imageFromImage(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_imageText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * text = (const char *)JS_ToCString(ctx, argv[0]); - if(text == NULL) return JS_EXCEPTION; int fontSize; JS_ToInt32(ctx, &fontSize, argv[1]); Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); @@ -3603,7 +3653,6 @@ static JSValue js_imageTextEx(JSContext * ctx, JSValueConst this_val, int argc, if(font_ptr == NULL) return JS_EXCEPTION; Font font = *font_ptr; const char * text = (const char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; double _double_fontSize; JS_ToFloat64(ctx, &_double_fontSize, argv[2]); float fontSize = (float)_double_fontSize; @@ -4095,7 +4144,6 @@ static JSValue js_imageDrawText(JSContext * ctx, JSValueConst this_val, int argc Image* dst = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); if(dst == NULL) return JS_EXCEPTION; const char * text = (const char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; int posX; JS_ToInt32(ctx, &posX, argv[2]); int posY; @@ -4117,7 +4165,6 @@ static JSValue js_imageDrawTextEx(JSContext * ctx, JSValueConst this_val, int ar if(font_ptr == NULL) return JS_EXCEPTION; Font font = *font_ptr; const char * text = (const char *)JS_ToCString(ctx, argv[2]); - if(text == NULL) return JS_EXCEPTION; Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[3], js_Vector2_class_id); if(position_ptr == NULL) return JS_EXCEPTION; Vector2 position = *position_ptr; @@ -4137,7 +4184,6 @@ static JSValue js_imageDrawTextEx(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_loadTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Texture2D returnVal = LoadTexture(fileName); JS_FreeCString(ctx, fileName); Texture2D* ret_ptr = (Texture2D*)js_malloc(ctx, sizeof(Texture2D)); @@ -4488,7 +4534,6 @@ static JSValue js_getFontDefault(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_loadFont(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Font returnVal = LoadFont(fileName); JS_FreeCString(ctx, fileName); Font* ret_ptr = (Font*)js_malloc(ctx, sizeof(Font)); @@ -4535,7 +4580,6 @@ static JSValue js_drawFPS(JSContext * ctx, JSValueConst this_val, int argc, JSVa static JSValue js_drawText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * text = (const char *)JS_ToCString(ctx, argv[0]); - if(text == NULL) return JS_EXCEPTION; int posX; JS_ToInt32(ctx, &posX, argv[1]); int posY; @@ -4555,7 +4599,6 @@ static JSValue js_drawTextEx(JSContext * ctx, JSValueConst this_val, int argc, J if(font_ptr == NULL) return JS_EXCEPTION; Font font = *font_ptr; const char * text = (const char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); if(position_ptr == NULL) return JS_EXCEPTION; Vector2 position = *position_ptr; @@ -4578,7 +4621,6 @@ static JSValue js_drawTextPro(JSContext * ctx, JSValueConst this_val, int argc, if(font_ptr == NULL) return JS_EXCEPTION; Font font = *font_ptr; const char * text = (const char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); if(position_ptr == NULL) return JS_EXCEPTION; Vector2 position = *position_ptr; @@ -4623,7 +4665,6 @@ static JSValue js_drawTextCodepoint(JSContext * ctx, JSValueConst this_val, int static JSValue js_measureText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * text = (const char *)JS_ToCString(ctx, argv[0]); - if(text == NULL) return JS_EXCEPTION; int fontSize; JS_ToInt32(ctx, &fontSize, argv[1]); int returnVal = MeasureText(text, fontSize); @@ -4637,7 +4678,6 @@ static JSValue js_measureTextEx(JSContext * ctx, JSValueConst this_val, int argc if(font_ptr == NULL) return JS_EXCEPTION; Font font = *font_ptr; const char * text = (const char *)JS_ToCString(ctx, argv[1]); - if(text == NULL) return JS_EXCEPTION; double _double_fontSize; JS_ToFloat64(ctx, &_double_fontSize, argv[2]); float fontSize = (float)_double_fontSize; @@ -5025,7 +5065,6 @@ static JSValue js_drawGrid(JSContext * ctx, JSValueConst this_val, int argc, JSV static JSValue js_loadModel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Model returnVal = LoadModel(fileName); JS_FreeCString(ctx, fileName); Model* ret_ptr = (Model*)js_malloc(ctx, sizeof(Model)); @@ -5247,7 +5286,6 @@ static JSValue js_exportMesh(JSContext * ctx, JSValueConst this_val, int argc, J if(mesh_ptr == NULL) return JS_EXCEPTION; Mesh mesh = *mesh_ptr; const char * fileName = (const char *)JS_ToCString(ctx, argv[1]); - if(fileName == NULL) return JS_EXCEPTION; bool returnVal = ExportMesh(mesh, fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewBool(ctx, returnVal); @@ -5625,7 +5663,6 @@ static JSValue js_setMasterVolume(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_loadWave(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Wave returnVal = LoadWave(fileName); JS_FreeCString(ctx, fileName); Wave* ret_ptr = (Wave*)js_malloc(ctx, sizeof(Wave)); @@ -5646,7 +5683,6 @@ static JSValue js_isWaveReady(JSContext * ctx, JSValueConst this_val, int argc, static JSValue js_loadSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Sound returnVal = LoadSound(fileName); JS_FreeCString(ctx, fileName); Sound* ret_ptr = (Sound*)js_malloc(ctx, sizeof(Sound)); @@ -5682,7 +5718,6 @@ static JSValue js_exportWave(JSContext * ctx, JSValueConst this_val, int argc, J if(wave_ptr == NULL) return JS_EXCEPTION; Wave wave = *wave_ptr; const char * fileName = (const char *)JS_ToCString(ctx, argv[1]); - if(fileName == NULL) return JS_EXCEPTION; bool returnVal = ExportWave(wave, fileName); JS_FreeCString(ctx, fileName); JSValue ret = JS_NewBool(ctx, returnVal); @@ -5801,7 +5836,6 @@ static JSValue js_waveFormat(JSContext * ctx, JSValueConst this_val, int argc, J static JSValue js_loadMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; Music returnVal = LoadMusicStream(fileName); JS_FreeCString(ctx, fileName); Music* ret_ptr = (Music*)js_malloc(ctx, sizeof(Music)); @@ -7521,6 +7555,7 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = { JS_CFUNC_DEF("isShaderReady",1,js_isShaderReady), JS_CFUNC_DEF("getShaderLocation",2,js_getShaderLocation), JS_CFUNC_DEF("getShaderLocationAttrib",2,js_getShaderLocationAttrib), + JS_CFUNC_DEF("setShaderValue",4,js_setShaderValue), JS_CFUNC_DEF("setShaderValueMatrix",3,js_setShaderValueMatrix), JS_CFUNC_DEF("setShaderValueTexture",3,js_setShaderValueTexture), JS_CFUNC_DEF("getMouseRay",2,js_getMouseRay), @@ -8327,6 +8362,41 @@ static int js_raylib_core_init(JSContext * ctx, JSModuleDef * m) { JS_SetModuleExport(ctx, m, "CAMERA_ORBITAL", JS_NewInt32(ctx, CAMERA_ORBITAL)); JS_SetModuleExport(ctx, m, "CAMERA_FIRST_PERSON", JS_NewInt32(ctx, CAMERA_FIRST_PERSON)); JS_SetModuleExport(ctx, m, "CAMERA_THIRD_PERSON", JS_NewInt32(ctx, CAMERA_THIRD_PERSON)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VERTEX_POSITION", JS_NewInt32(ctx, SHADER_LOC_VERTEX_POSITION)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VERTEX_TEXCOORD01", JS_NewInt32(ctx, SHADER_LOC_VERTEX_TEXCOORD01)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VERTEX_TEXCOORD02", JS_NewInt32(ctx, SHADER_LOC_VERTEX_TEXCOORD02)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VERTEX_NORMAL", JS_NewInt32(ctx, SHADER_LOC_VERTEX_NORMAL)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VERTEX_TANGENT", JS_NewInt32(ctx, SHADER_LOC_VERTEX_TANGENT)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VERTEX_COLOR", JS_NewInt32(ctx, SHADER_LOC_VERTEX_COLOR)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MATRIX_MVP", JS_NewInt32(ctx, SHADER_LOC_MATRIX_MVP)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MATRIX_VIEW", JS_NewInt32(ctx, SHADER_LOC_MATRIX_VIEW)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MATRIX_PROJECTION", JS_NewInt32(ctx, SHADER_LOC_MATRIX_PROJECTION)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MATRIX_MODEL", JS_NewInt32(ctx, SHADER_LOC_MATRIX_MODEL)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MATRIX_NORMAL", JS_NewInt32(ctx, SHADER_LOC_MATRIX_NORMAL)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_VECTOR_VIEW", JS_NewInt32(ctx, SHADER_LOC_VECTOR_VIEW)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_COLOR_DIFFUSE", JS_NewInt32(ctx, SHADER_LOC_COLOR_DIFFUSE)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_COLOR_SPECULAR", JS_NewInt32(ctx, SHADER_LOC_COLOR_SPECULAR)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_COLOR_AMBIENT", JS_NewInt32(ctx, SHADER_LOC_COLOR_AMBIENT)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_ALBEDO", JS_NewInt32(ctx, SHADER_LOC_MAP_ALBEDO)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_METALNESS", JS_NewInt32(ctx, SHADER_LOC_MAP_METALNESS)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_NORMAL", JS_NewInt32(ctx, SHADER_LOC_MAP_NORMAL)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_ROUGHNESS", JS_NewInt32(ctx, SHADER_LOC_MAP_ROUGHNESS)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_OCCLUSION", JS_NewInt32(ctx, SHADER_LOC_MAP_OCCLUSION)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_EMISSION", JS_NewInt32(ctx, SHADER_LOC_MAP_EMISSION)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_HEIGHT", JS_NewInt32(ctx, SHADER_LOC_MAP_HEIGHT)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_CUBEMAP", JS_NewInt32(ctx, SHADER_LOC_MAP_CUBEMAP)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_IRRADIANCE", JS_NewInt32(ctx, SHADER_LOC_MAP_IRRADIANCE)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_PREFILTER", JS_NewInt32(ctx, SHADER_LOC_MAP_PREFILTER)); + JS_SetModuleExport(ctx, m, "SHADER_LOC_MAP_BRDF", JS_NewInt32(ctx, SHADER_LOC_MAP_BRDF)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_FLOAT", JS_NewInt32(ctx, SHADER_UNIFORM_FLOAT)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_VEC2", JS_NewInt32(ctx, SHADER_UNIFORM_VEC2)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_VEC3", JS_NewInt32(ctx, SHADER_UNIFORM_VEC3)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_VEC4", JS_NewInt32(ctx, SHADER_UNIFORM_VEC4)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_INT", JS_NewInt32(ctx, SHADER_UNIFORM_INT)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_IVEC2", JS_NewInt32(ctx, SHADER_UNIFORM_IVEC2)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_IVEC3", JS_NewInt32(ctx, SHADER_UNIFORM_IVEC3)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_IVEC4", JS_NewInt32(ctx, SHADER_UNIFORM_IVEC4)); + JS_SetModuleExport(ctx, m, "SHADER_UNIFORM_SAMPLER2D", JS_NewInt32(ctx, SHADER_UNIFORM_SAMPLER2D)); return 0; } @@ -8557,6 +8627,41 @@ JSModuleDef * js_init_module_raylib_core(JSContext * ctx, const char * module_na JS_AddModuleExport(ctx, m, "CAMERA_ORBITAL"); JS_AddModuleExport(ctx, m, "CAMERA_FIRST_PERSON"); JS_AddModuleExport(ctx, m, "CAMERA_THIRD_PERSON"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VERTEX_POSITION"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VERTEX_TEXCOORD01"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VERTEX_TEXCOORD02"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VERTEX_NORMAL"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VERTEX_TANGENT"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VERTEX_COLOR"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MATRIX_MVP"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MATRIX_VIEW"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MATRIX_PROJECTION"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MATRIX_MODEL"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MATRIX_NORMAL"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_VECTOR_VIEW"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_COLOR_DIFFUSE"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_COLOR_SPECULAR"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_COLOR_AMBIENT"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_ALBEDO"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_METALNESS"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_NORMAL"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_ROUGHNESS"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_OCCLUSION"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_EMISSION"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_HEIGHT"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_CUBEMAP"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_IRRADIANCE"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_PREFILTER"); + JS_AddModuleExport(ctx, m, "SHADER_LOC_MAP_BRDF"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_FLOAT"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_VEC2"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_VEC3"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_VEC4"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_INT"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_IVEC2"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_IVEC3"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_IVEC4"); + JS_AddModuleExport(ctx, m, "SHADER_UNIFORM_SAMPLER2D"); return m; }