Testing textures and shaders in scripting.
This commit is contained in:
@ -8,12 +8,6 @@
|
|||||||
#include "sandboxscene.h"
|
#include "sandboxscene.h"
|
||||||
|
|
||||||
bool sandboxSceneInit(sandboxscene_t *game) {
|
bool sandboxSceneInit(sandboxscene_t *game) {
|
||||||
assetFontLoad(&game->font, "fonts/opensans/OpenSans-Regular.ttf");
|
|
||||||
assetTextureLoad(&game->texture, "test_texture.png");
|
|
||||||
assetShaderLoad(&game->shader,
|
|
||||||
"shaders/textured.vert", "shaders/textured.frag"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Init Scripter
|
// Init Scripter
|
||||||
scripterInit(&game->scripter, &game->engine);
|
scripterInit(&game->scripter, &game->engine);
|
||||||
game->scripter.user = game;
|
game->scripter.user = game;
|
||||||
@ -21,30 +15,16 @@ bool sandboxSceneInit(sandboxscene_t *game) {
|
|||||||
scriptsApiIo(&game->scripter);
|
scriptsApiIo(&game->scripter);
|
||||||
scriptsApiDisplay(&game->scripter);
|
scriptsApiDisplay(&game->scripter);
|
||||||
scriptsApiAsset(&game->scripter);
|
scriptsApiAsset(&game->scripter);
|
||||||
|
|
||||||
assetScripterAppend(&game->scripter, "scripts/main.js");
|
assetScripterAppend(&game->scripter, "scripts/main.js");
|
||||||
|
|
||||||
|
|
||||||
scripterInvokeMethodSimple(&game->scripter, "init");
|
scripterInvokeMethodSimple(&game->scripter, "init");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sandboxSceneUpdate(sandboxscene_t *game) {
|
void sandboxSceneUpdate(sandboxscene_t *game) {
|
||||||
// cameraLookAt(&game->camera, 3,3,3, 0,0,0);
|
|
||||||
|
|
||||||
// cameraPerspective(&game->camera, 45,
|
|
||||||
// game->engine.render.width/game->engine.render.height,
|
|
||||||
// 0.01f, 1000.0f
|
|
||||||
// );
|
|
||||||
|
|
||||||
// cameraLookAt(&game->camera,
|
|
||||||
// 3, 3, 3,
|
|
||||||
// 0, 0, 0
|
|
||||||
// );
|
|
||||||
|
|
||||||
// shaderUse(&game->shader);
|
|
||||||
// shaderUseCamera(&game->shader, &game->camera);
|
|
||||||
// shaderUsePosition(&game->shader, 0,0,0, 0,0,0);
|
|
||||||
// shaderUseTexture(&game->shader, &game->texture);
|
|
||||||
|
|
||||||
scripterInvokeMethodSimple(&game->scripter, "update");
|
scripterInvokeMethodSimple(&game->scripter, "update");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,13 +32,6 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
engine_t engine;
|
engine_t engine;
|
||||||
camera_t camera;
|
|
||||||
|
|
||||||
primitive_t primitive;
|
|
||||||
texture_t texture;
|
|
||||||
shader_t shader;
|
|
||||||
font_t font;
|
|
||||||
|
|
||||||
scripter_t scripter;
|
scripter_t scripter;
|
||||||
} sandboxscene_t;
|
} sandboxscene_t;
|
||||||
|
|
||||||
|
@ -7,19 +7,21 @@
|
|||||||
|
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
|
||||||
void _scriptApiShaderLoad(scriptercontext_t *ctx) {
|
scripterreturn_t _scriptApiShaderLoad(scriptercontext_t *ctx) {
|
||||||
assetShaderLoad(
|
assetShaderLoad(
|
||||||
duk_to_pointer(ctx, 0),
|
duk_to_pointer(ctx, 0),
|
||||||
duk_to_string(ctx, 1),
|
duk_to_string(ctx, 1),
|
||||||
duk_to_string(ctx, 2)
|
duk_to_string(ctx, 2)
|
||||||
);
|
);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _scriptApiTextureLoad(scriptercontext_t *ctx) {
|
scripterreturn_t _scriptApiTextureLoad(scriptercontext_t *ctx) {
|
||||||
assetShaderLoad(
|
assetTextureLoad(
|
||||||
duk_to_pointer(ctx, 0),
|
duk_to_pointer(ctx, 0),
|
||||||
duk_to_string(ctx, 1)
|
duk_to_string(ctx, 1)
|
||||||
);
|
);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scriptsApiAsset(scripter_t *s) {
|
void scriptsApiAsset(scripter_t *s) {
|
||||||
|
6
src/script/api/asset.d.ts
vendored
6
src/script/api/asset.d.ts
vendored
@ -3,8 +3,6 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
declare function assetShaderLoad(
|
declare function assetShaderLoad(shader:Shader, vert:string, frag:string):void;
|
||||||
shader:Shader, fileVertex:string, fileFrag:string
|
|
||||||
):void;
|
|
||||||
|
|
||||||
declare function assetTextureLoad(shader:Shader, texture:Texture):void;
|
declare function assetTextureLoad(texture:Texture, file:string):void;
|
@ -141,6 +141,11 @@ scripterreturn_t _scriptShaderUseCamera(scriptercontext_t *ctx) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scripterreturn_t _scriptShaderUseTexture(scriptercontext_t *ctx) {
|
||||||
|
shaderUseTexture(duk_to_pointer(ctx, 0), duk_to_pointer(ctx, 1));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
scripterreturn_t _scriptShaderUsePosition(scriptercontext_t *ctx) {
|
scripterreturn_t _scriptShaderUsePosition(scriptercontext_t *ctx) {
|
||||||
shaderUsePosition(
|
shaderUsePosition(
|
||||||
duk_to_pointer(ctx, 0),
|
duk_to_pointer(ctx, 0),
|
||||||
@ -172,6 +177,21 @@ scripterreturn_t _scriptShaderUsePositionAndScale(scriptercontext_t *ctx) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
scripterreturn_t _scriptTextureCreate(scriptercontext_t *ctx) {
|
||||||
|
texture_t *texture = malloc(sizeof(texture_t));
|
||||||
|
duk_push_pointer(ctx, texture);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
scripterreturn_t _scriptTextureDispose(scriptercontext_t *ctx) {
|
||||||
|
texture_t *texture = duk_to_pointer(ctx, 0);
|
||||||
|
textureDispose(texture);
|
||||||
|
free(texture);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void scriptsApiDisplay(scripter_t *s) {
|
void scriptsApiDisplay(scripter_t *s) {
|
||||||
scripterDefineMethod(s, "primitiveCreate", 0, &_scriptPrimitiveCreate);
|
scripterDefineMethod(s, "primitiveCreate", 0, &_scriptPrimitiveCreate);
|
||||||
scripterDefineMethod(s, "primitiveInit", 3, &_scriptPrimitiveInit);
|
scripterDefineMethod(s, "primitiveInit", 3, &_scriptPrimitiveInit);
|
||||||
@ -191,9 +211,13 @@ void scriptsApiDisplay(scripter_t *s) {
|
|||||||
scripterDefineMethod(s, "shaderInit", 3, &_scriptShaderInit);
|
scripterDefineMethod(s, "shaderInit", 3, &_scriptShaderInit);
|
||||||
scripterDefineMethod(s, "shaderDispose", 1, &_scriptShaderDispose);
|
scripterDefineMethod(s, "shaderDispose", 1, &_scriptShaderDispose);
|
||||||
scripterDefineMethod(s, "shaderUse", 1, &_scriptShaderUse);
|
scripterDefineMethod(s, "shaderUse", 1, &_scriptShaderUse);
|
||||||
|
scripterDefineMethod(s, "shaderUseTexture", 2, &_scriptShaderUseTexture);
|
||||||
scripterDefineMethod(s, "shaderUseCamera", 2, &_scriptShaderUseCamera);
|
scripterDefineMethod(s, "shaderUseCamera", 2, &_scriptShaderUseCamera);
|
||||||
scripterDefineMethod(s, "shaderUsePosition", 7, &_scriptShaderUsePosition);
|
scripterDefineMethod(s, "shaderUsePosition", 7, &_scriptShaderUsePosition);
|
||||||
scripterDefineMethod(
|
scripterDefineMethod(
|
||||||
s, "shaderUsePositionAndScale", 10, &_scriptShaderUsePositionAndScale
|
s, "shaderUsePositionAndScale", 10, &_scriptShaderUsePositionAndScale
|
||||||
);
|
);
|
||||||
|
|
||||||
|
scripterDefineMethod(s, "textureCreate", 0, &_scriptTextureCreate);
|
||||||
|
scripterDefineMethod(s, "textureDispose", 1, &_scriptTextureDispose);
|
||||||
}
|
}
|
10
src/script/api/display.d.ts
vendored
10
src/script/api/display.d.ts
vendored
@ -56,6 +56,8 @@ declare function shaderDispose(shader:Shader):void;
|
|||||||
|
|
||||||
declare function shaderUse(shader:Shader):void;
|
declare function shaderUse(shader:Shader):void;
|
||||||
|
|
||||||
|
declare function shaderUseTexture(shader:Shader, texture:Texture):void;
|
||||||
|
|
||||||
declare function shaderUseCamera(shader:Shader, camera:Camera):void;
|
declare function shaderUseCamera(shader:Shader, camera:Camera):void;
|
||||||
|
|
||||||
declare function shaderUsePosition(shader:Shader,
|
declare function shaderUsePosition(shader:Shader,
|
||||||
@ -67,4 +69,10 @@ declare function shaderUsePositionAndScale(shader:Shader,
|
|||||||
x:number, y:number, z:number,
|
x:number, y:number, z:number,
|
||||||
pitch:number, yaw:number, roll:number,
|
pitch:number, yaw:number, roll:number,
|
||||||
sx:number, sy:number, sz:number
|
sx:number, sy:number, sz:number
|
||||||
):void;
|
):void;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
declare function textureCreate():Texture;
|
||||||
|
|
||||||
|
declare function textureDispose(texture:Texture):void;
|
13
ts/main.ts
13
ts/main.ts
@ -1,25 +1,30 @@
|
|||||||
let cube:Primitive;
|
let cube:Primitive;
|
||||||
let shader:Shader;
|
let shader:Shader;
|
||||||
let camera:Camera;
|
let camera:Camera;
|
||||||
|
let texture:Texture;
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
print('Main invoked');
|
print('Main invoked');
|
||||||
|
|
||||||
|
// Create Quad
|
||||||
cube = primitiveCreate();
|
cube = primitiveCreate();
|
||||||
quadInit(cube, 0, -1, -1, 0, 0, 1, 1, 1, 1);
|
quadInit(cube, 0, -1, -1, 0, 0, 1, 1, 1, 1);
|
||||||
|
|
||||||
|
// Create Camera
|
||||||
camera = cameraCreate();
|
camera = cameraCreate();
|
||||||
|
|
||||||
|
// Load Shader
|
||||||
shader = shaderCreate();
|
shader = shaderCreate();
|
||||||
assetShaderLoad(shader, "shaders/textured.vert", "shaders/textured.frag");
|
assetShaderLoad(shader, "shaders/textured.vert", "shaders/textured.frag");
|
||||||
|
|
||||||
shaderUse(shader);
|
// Texture load
|
||||||
cameraLookAt(camera, 3,3,3, 0,0,0);
|
texture = textureCreate();
|
||||||
cameraPerspective(camera, 45, 16/9, 0.01, 100);
|
assetTextureLoad(texture, "test_texture.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
shaderUse(shader);
|
shaderUse(shader);
|
||||||
|
shaderUseTexture(shader, texture);
|
||||||
|
|
||||||
cameraLookAt(camera, 3,3,3, 0,0,0);
|
cameraLookAt(camera, 3,3,3, 0,0,0);
|
||||||
cameraPerspective(camera, 45, 16/9, 0.01, 100);
|
cameraPerspective(camera, 45, 16/9, 0.01, 100);
|
||||||
|
Reference in New Issue
Block a user