Platform web.

This commit is contained in:
jussi
2023-11-29 19:52:47 +02:00
parent 4ff1b1dcb9
commit 8882d2ff2c
9 changed files with 79 additions and 33 deletions

View File

@@ -14,8 +14,8 @@ static int getBufferElementSize( Buffer *buffer ) {
case BUFFER_INT: return sizeof( int );
case BUFFER_FLOAT: return sizeof( float );
case BUFFER_DOUBLE: return sizeof( double );
default: 1;
}
return 1;
}
void unloadBuffer( Buffer *buffer ) {

View File

@@ -15,6 +15,7 @@ Copy a block of pixels from one framebuffer object to another.
Use -1 RenderTexture for window framebuffer
*/
int lglBlitFramebuffer( lua_State *L ) {
#if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL )
if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) {
TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" );
lua_pushnil( L );
@@ -52,4 +53,5 @@ int lglBlitFramebuffer( lua_State *L ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
return 1;
#endif
}

View File

@@ -18,6 +18,8 @@
#include "platforms/core_desktop.c"
#elif PLATFORM_DESKTOP_SDL
#include "platforms/core_desktop_sdl.c"
#elif PLATFORM_WEB
#include "platforms/core_web.c"
#endif
/* Define types. */
@@ -28,6 +30,7 @@ static int gcBuffer( lua_State *L ) {
Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
unloadBuffer( buffer );
}
return 0;
}
static void defineBuffer() {
@@ -46,6 +49,7 @@ static int gcImage( lua_State *L ) {
Image *image = luaL_checkudata( L, 1, "Image" );
UnloadImage( *image );
}
return 0;
}
static void defineImage() {
@@ -64,6 +68,7 @@ static int gcTexture( lua_State *L ) {
Texture *texture = luaL_checkudata( L, 1, "Texture" );
UnloadTexture( *texture );
}
return 0;
}
static void defineTexture() {
@@ -83,6 +88,7 @@ static int gcRenderTexture( lua_State *L ) {
RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" );
UnloadRenderTexture( *renderTexture );
}
return 0;
}
static void defineRenderTexture() {
@@ -119,6 +125,7 @@ static int gcShader( lua_State *L ) {
Shader *shader = luaL_checkudata( L, 1, "Shader" );
UnloadShader( *shader );
}
return 0;
}
static void defineShader() {
@@ -137,6 +144,7 @@ static int gcFont( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
UnloadFont( *font );
}
return 0;
}
static void defineFont() {
@@ -155,6 +163,7 @@ static int gcWave( lua_State *L ) {
Wave *wave = luaL_checkudata( L, 1, "Wave" );
UnloadWave( *wave );
}
return 0;
}
static void defineWave() {
@@ -173,6 +182,7 @@ static int gcSound( lua_State *L ) {
Sound *sound = luaL_checkudata( L, 1, "Sound" );
UnloadSound( *sound );
}
return 0;
}
static void defineSound() {
@@ -191,6 +201,7 @@ static int gcMusic( lua_State *L ) {
Music *music = luaL_checkudata( L, 1, "Music" );
UnloadMusicStream( *music );
}
return 0;
}
static void defineMusic() {
@@ -219,6 +230,7 @@ static int gcMaterial( lua_State *L ) {
/* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
unloadMaterial( material );
}
return 0;
}
static void defineMaterial() {
@@ -237,6 +249,7 @@ static int gcMesh( lua_State *L ) {
Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
UnloadMesh( *mesh );
}
return 0;
}
static void defineMesh() {
@@ -256,6 +269,7 @@ static int gcModel( lua_State *L ) {
UnloadModel( *model );
// UnloadModelKeepMeshes( *model );
}
return 0;
}
static void defineModel() {
@@ -274,6 +288,7 @@ static int gcModelAnimation( lua_State *L ) {
ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
UnloadModelAnimation( *modelAnimation );
}
return 0;
}
static void defineModelAnimation() {
@@ -1030,11 +1045,11 @@ bool luaCallMain() {
char path[ STRING_LEN ] = { '\0' };
/* If web, set path to resources folder. */
#ifdef EMSCRIPTEN
snprintf( path, STRING_LEN, "resources/main.lua" );
#ifdef PLATFORM_WEB
snprintf( path, STRING_LEN, "main.lua" );
/* Alternatively look for main. Could be precompiled binary file. */
if ( !FileExists( path ) ) {
snprintf( path, STRING_LEN, "resources/main" );
snprintf( path, STRING_LEN, "main" );
}
#else
snprintf( path, STRING_LEN, "%smain.lua", state->exePath );
@@ -1055,8 +1070,6 @@ bool luaCallMain() {
/* Apply custom callback here. */
SetTraceLogCallback( logCustom );
platformRegisterEvents();
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "init" );
@@ -1077,6 +1090,7 @@ bool luaCallMain() {
}
void luaCallProcess() {
#ifdef PLATFORM_DESKTOP_SDL
platformSendEvents();
#endif

View File

@@ -3,7 +3,7 @@
#include "core.h"
#include "platforms/core_desktop.h"
static void platformDefineGlobals() {
void platformDefineGlobals() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
@@ -87,17 +87,6 @@ int lcoreGetKeyScancode( lua_State *L ) {
return 1;
}
static void luaPlatformRegister() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
/* Input-related functions: keyboard. */
assingGlobalFunction( "GetKeyName", lcoreGetKeyName );
assingGlobalFunction( "GetKeyScancode", lcoreGetKeyScancode );
lua_pop( L, -1 );
}
/* Events. */
/*
@@ -649,3 +638,16 @@ static void platformRegisterEvents() {
// state->glfwtabletCursorCallback = glfwSetPenTabletCursorCallback( penTabletCursorEvent );
// state->glfwtabletProximityCallback = glfwSetPenTabletProximityCallback( penTabletProximityEvent );
}
void luaPlatformRegister() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
/* Input-related functions: keyboard. */
assingGlobalFunction( "GetKeyName", lcoreGetKeyName );
assingGlobalFunction( "GetKeyScancode", lcoreGetKeyScancode );
lua_pop( L, -1 );
platformRegisterEvents();
}

View File

@@ -3,7 +3,7 @@
#include "core.h"
#include "platforms/core_desktop_sdl.h"
static void platformDefineGlobals() {
void platformDefineGlobals() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
@@ -111,17 +111,6 @@ int lcoreGetScancodeFromKey( lua_State *L ) {
return 1;
}
static void luaPlatformRegister() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
/* Input-related functions: keyboard. */
assingGlobalFunction( "GetKeyName", lcoreGetKeyName );
assingGlobalFunction( "GetScancodeFromKey", lcoreGetScancodeFromKey );
lua_pop( L, -1 );
}
/* Events. */
/*
@@ -555,3 +544,16 @@ Event occurs an event of type SDL_DOLLARGESTURE or SDL_DOLLARRECORD is reported.
}
state->SDL_eventQueueLen = 0;
}
void luaPlatformRegister() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
/* Input-related functions: keyboard. */
assingGlobalFunction( "GetKeyName", lcoreGetKeyName );
assingGlobalFunction( "GetScancodeFromKey", lcoreGetScancodeFromKey );
lua_pop( L, -1 );
platformRegisterEvents()
}

20
src/platforms/core_web.c Normal file
View File

@@ -0,0 +1,20 @@
#include "main.h"
#include "lua_core.h"
#include "core.h"
void platformDefineGlobals() {
lua_State *L = state->luaState;
lua_getglobal( L, "RL" );
/*DOC_DEFINES_START*/
/*DOC_DEFINES_END*/
lua_pop( L, -1 );
}
/* Functions. */
/* Events. */
void luaPlatformRegister() {
return;
}