From 543d9b1d527ea532a3bef1a3eee21cb9b4ae4718 Mon Sep 17 00:00:00 2001 From: Kylogias <45217130+Kylogias@users.noreply.github.com> Date: Tue, 29 Jul 2025 09:51:25 -0400 Subject: [PATCH] Add platform specific defines --- CNFG.c | 6 +-- CNFG.h | 25 ++++++---- CNFG3D.c | 4 +- CNFGAndroid.h | 2 +- CNFGEGLDriver.c | 29 +++++------- CNFGFunctions.c | 12 ++--- CNFGHTTP.c | 10 ++-- CNFGRasterizer.c | 8 ++-- rawdraw_sf.h | 120 +++++++++++++++++++++++++---------------------- 9 files changed, 112 insertions(+), 104 deletions(-) diff --git a/CNFG.c b/CNFG.c index af8ffec..49affc2 100644 --- a/CNFG.c +++ b/CNFG.c @@ -8,13 +8,13 @@ int CNFGLastScancode = 0; #if defined( CNFGHTTP ) #include "CNFGHTTP.c" -#elif defined( __wasm__ ) +#elif defined( CNFG_WASM ) #include "CNFGWASMDriver.c" -#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#elif defined( CNFG_WINDOWS ) #include "CNFGWinDriver.c" #elif defined( EGL_LEAN_AND_MEAN ) #include "CNFGEGLLeanAndMean.c" -#elif defined( __android__ ) || defined( ANDROID ) +#elif defined( CNFG_ANDROID ) #include "CNFGEGLDriver.c" #else #include "CNFGXDriver.c" diff --git a/CNFG.h b/CNFG.h index c8a332c..7bc69a6 100644 --- a/CNFG.h +++ b/CNFG.h @@ -51,15 +51,22 @@ Usually tested combinations: #include //Some per-platform logic. -#if defined( ANDROID ) || defined( __android__ ) +#if defined( WINDOWS ) || defined( WIN32 ) || defined( WIN64 ) || defined( _WIN32 ) || defined( _WIN64 ) || defined( __CYGWIN__ ) + #define CNFG_WINDOWS +#elif defined( __wasm__ ) + #define CNFG_WASM +#elif defined( ANDROID ) || defined( __android__ ) + #define CNFG_ANDROID #define CNFGOGL +#else + #define CNFG_X11 #endif -#if ( defined( CNFGOGL ) || defined( __wasm__ ) ) && !defined(CNFG_HAS_XSHAPE) +#if ( defined( CNFGOGL ) || defined( CNFG_WASM ) ) && !defined(CNFG_HAS_XSHAPE) #define CNFG_BATCH 8192 //131,072 bytes. - #if defined( ANDROID ) || defined( __android__ ) || defined( __wasm__ ) || defined( EGL_LEAN_AND_MEAN ) + #if defined( CNFG_ANDROID ) || defined( CNFG_WASM ) || defined( EGL_LEAN_AND_MEAN ) #define CNFGEWGL //EGL or WebGL #else #define CNFGDESKTOPGL @@ -208,7 +215,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #define CNFG_KEY_FOCUS 0xf000 -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS #define CNFG_KEY_BACKSPACE 0x08 #define CNFG_KEY_TAB 0x09 @@ -288,8 +295,8 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #define CNFG_KEY_RIGHT_ALT 0xA5 #elif defined( EGL_LEAN_AND_MEAN ) // doesn't have any keys -#elif defined( __android__ ) || defined( ANDROID ) // ^ -#elif defined( __wasm__ ) +#elif defined( CNFG_ANDROID ) // ^ +#elif defined( CNFG_WASM ) #define CNFG_KEY_BACKSPACE 8 #define CNFG_KEY_TAB 9 @@ -453,7 +460,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #ifdef CNFG3D -#ifndef __wasm__ +#ifndef CNFG_WASM #include #endif @@ -469,7 +476,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #define tdSQRT sqrtf #endif -#ifdef __wasm__ +#ifdef CNFG_WASM void tdMATCOPY( float * x, const float * y ); //Copy y into x #else #define tdMATCOPY(x,y) memcpy( x, y, 16*sizeof(float)) @@ -535,7 +542,7 @@ extern const unsigned short RawdrawFontCharMap[256]; #endif -#if defined( ANDROID ) || defined( __android__ ) +#ifdef CNFG_ANDROID #include "CNFGAndroid.h" #endif diff --git a/CNFG3D.c b/CNFG3D.c index 8c5876c..2d205eb 100644 --- a/CNFG3D.c +++ b/CNFG3D.c @@ -7,7 +7,7 @@ #include "CNFG.h" -#ifdef __wasm__ +#ifdef CNFG_WASM double sin( double v ); double cos( double v ); double tan( double v ); @@ -262,7 +262,7 @@ void tdMultiply( float * fin1, float * fin2, float * fout ) tdMATCOPY( fout, fotmp ); } -#ifndef __wasm__ +#ifndef CNFG_WASM void tdPrint( const float * f ) { int i; diff --git a/CNFGAndroid.h b/CNFGAndroid.h index b889bb6..58f5933 100644 --- a/CNFGAndroid.h +++ b/CNFGAndroid.h @@ -53,7 +53,7 @@ void HandleSuspend(); // For debugging: -#if defined( ANDROID ) && !defined( __cplusplus ) +#if defined( CNFG_ANDROID ) && !defined( __cplusplus ) #include diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index b4b760e..44ffd28 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -22,16 +22,11 @@ * DEALINGS IN THE SOFTWARE. */ - -#if defined( __android__ ) && !defined( ANDROID ) -#define ANDROID -#endif - //Note: This interface provides the following two things privately. //you may "extern" them in your code. -#ifdef ANDROID +#ifdef CNFG_ANDROID #include "CNFGAndroid.h" @@ -60,7 +55,7 @@ int android_sdk_version; #include #include -#ifdef ANDROID +#ifdef CNFG_ANDROID #include #else #include @@ -105,7 +100,7 @@ int android_sdk_version; unsigned int format; /* extra format information in case rgbal is not enough, especially for YUV formats */ } fbdev_pixmap; -#if defined( ANDROID ) +#if defined( CNFG_ANDROID ) EGLNativeWindowType native_window; #else struct fbdev_window native_window; @@ -123,7 +118,7 @@ static EGLint const config_attribute_list[] = { EGL_STENCIL_SIZE, 0, EGL_DEPTH_SIZE, EGL_ZBITS, //EGL_SAMPLES, 1, -#ifdef ANDROID +#ifdef CNFG_ANDROID #if ANDROIDVERSION >= 28 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, #else @@ -164,7 +159,7 @@ void CNFGSwapBuffers() if ( egl_display == EGL_NO_DISPLAY ) return; CNFGFlushRender(); eglSwapBuffers(egl_display, egl_surface); -#ifdef ANDROID +#ifdef CNFG_ANDROID if( !override_android_screen_dimensons ) { android_width = ANativeWindow_getWidth( native_window ); @@ -178,7 +173,7 @@ void CNFGSwapBuffers() void CNFGGetDimensions( short * x, short * y ) { -#ifdef ANDROID +#ifdef CNFG_ANDROID *x = android_width; *y = android_height; #else @@ -232,7 +227,7 @@ int CNFGSetup( const char * WindowName, int w, int h ) egl_display = eglGetDisplay((EGLNativeDisplayType) XDisplay); #else -#ifndef ANDROID +#ifndef CNFG_ANDROID if( w >= 1 && h >= 1 ) { native_window.width = w; @@ -306,7 +301,7 @@ int CNFGSetup( const char * WindowName, int w, int h ) } printf( "Width/Height: %dx%d\n", android_width, android_height ); egl_surface = eglCreateWindowSurface(egl_display, egl_config, -#ifdef ANDROID +#ifdef CNFG_ANDROID gapp->window, #else (EGLNativeWindowType)&native_window, @@ -321,7 +316,7 @@ int CNFGSetup( const char * WindowName, int w, int h ) return -1; } -#ifndef ANDROID +#ifndef CNFG_ANDROID int width, height; if (!eglQuerySurface(egl_display, egl_surface, EGL_WIDTH, &width) || !eglQuerySurface(egl_display, egl_surface, EGL_HEIGHT, &height)) { @@ -373,7 +368,7 @@ bool touch_is_down[MAX_NUM_TOUCHES]; int32_t handle_input(struct android_app* app, AInputEvent* event) { -#ifdef ANDROID +#ifdef CNFG_ANDROID //Potentially do other things here. if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) @@ -440,7 +435,7 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) int CNFGHandleInput() { -#ifdef ANDROID +#ifdef CNFG_ANDROID int events; struct android_poll_source* source; while( ALooper_pollOnce( 0, 0, &events, (void**)&source) >= 0 ) @@ -473,7 +468,7 @@ int CNFGHandleInput() -#ifdef ANDROID +#ifdef CNFG_ANDROID void (*HandleWindowTermination)(); diff --git a/CNFGFunctions.c b/CNFGFunctions.c index e9d013a..6b2b7d2 100644 --- a/CNFGFunctions.c +++ b/CNFGFunctions.c @@ -333,7 +333,7 @@ void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize ) void CNFGEmitBackendTriangles( const float * fv, const uint32_t * col, int nr_verts ); //If on WASM, sqrtf is implied. On other platforms, need sqrtf from math.h -#ifdef __wasm__ +#ifdef CNFG_WASM float sqrtf( float f ); #define cnfg_sqrtf sqrtf #elif defined( __TINYC__ ) && defined( WIN32 ) @@ -453,7 +453,7 @@ void CNFGSetLineWidth( short width ) #endif -#if !defined( __wasm__ ) && !defined( CNFGHTTP ) +#if !defined( CNFG_WASM ) && !defined( CNFGHTTP ) //In WASM, Javascript takes over this functionality. //Shader compilation errors go to stderr. @@ -472,14 +472,14 @@ void CNFGSetLineWidth( short width ) #define LGLchar GLchar #endif -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) +#ifdef CNFG_WINDOWS #define CNFGOGL_NEED_EXTENSION #include #endif #ifdef CNFGOGL_NEED_EXTENSION // If we are going to be defining our own function pointer call - #if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) + #ifdef CNFG_WINDOWS // Make sure to use __stdcall on Windows #define CHEWTYPEDEF( ret, name, rv, paramcall, ... ) \ typedef ret (__stdcall *CNFGTYPE##name)( __VA_ARGS__ ); \ @@ -552,7 +552,7 @@ CHEWTYPEDEF( void, glActiveTexture, , (texture), GLenum texture ) #endif #ifdef CNFGOGL_NEED_EXTENSION -#if defined( WIN32 ) || defined( WINDOWS ) || defined( WIN64 ) +#ifdef CNFG_WINDOWS //From https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions void * CNFGGetProcAddress(const char *name) @@ -952,7 +952,7 @@ void CNFGClearFrame() #endif -#endif //__wasm__ +#endif // CNFG_WASM #else diff --git a/CNFGHTTP.c b/CNFGHTTP.c index 1795c3a..ea1f31e 100644 --- a/CNFGHTTP.c +++ b/CNFGHTTP.c @@ -871,7 +871,7 @@ uint8_t WSPOPMASK() -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS #define _WINSOCK_DEPRECATED_NO_WARNINGS #include #define socklen_t uint32_t @@ -1032,7 +1032,7 @@ int TickHTTP() { static double last; double now; -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS static LARGE_INTEGER lpf; LARGE_INTEGER li; @@ -1092,7 +1092,7 @@ int TickHTTP() memset( &tin, 0, addrlen ); int tsocket = accept( serverSocket, (struct sockaddr *)&tin, &addrlen ); -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS struct linger lx; lx.l_onoff = 1; lx.l_linger = 0; @@ -1181,7 +1181,7 @@ int TickHTTP() int RunHTTP( int port ) { -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS { WORD wVersionRequested; WSADATA wsaData; @@ -1211,7 +1211,7 @@ int RunHTTP( int port ) } //Disable SO_LINGER (Well, enable it but turn it way down) -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS struct linger lx; lx.l_onoff = 1; lx.l_linger = 0; diff --git a/CNFGRasterizer.c b/CNFGRasterizer.c index ae1a55b..35c34ea 100644 --- a/CNFGRasterizer.c +++ b/CNFGRasterizer.c @@ -27,7 +27,7 @@ void CNFGInternalResize( short x, short y ) #endif } -#ifdef __wasm__ +#ifdef CNFG_WASM static uint32_t SWAPS( uint32_t r ) { uint32_t ret = (r&0xFF)<<24; @@ -299,17 +299,17 @@ void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h ) //Alpha blend. int alfa = newm&0xff; int onemalfa = 255-alfa; -#ifdef __wasm__ +#if defined( CNFG_WASM ) uint32_t newv = 255<<0; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; -#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#elif defined( CNFG_WINDOWS ) uint32_t newv = 255UL<<24; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; -#elif defined( ANDROID ) || defined( __android__ ) +#elif defined( CNFG_ANDROID ) uint32_t newv = 255<<16; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; diff --git a/rawdraw_sf.h b/rawdraw_sf.h index 1bfa0ad..68f0ab5 100644 --- a/rawdraw_sf.h +++ b/rawdraw_sf.h @@ -1,5 +1,5 @@ //This file was automatically generated by Makefile at https://github.com/cntools/rawdraw -//Generated from files git hash b1b945260514c1a3b2366b017b1de502b4d78e1c on Mon Jul 21 08:38:02 PM EDT 2025 (This is not the git hash of this file) +//Generated from files git hash 4775c42d1e2766f25a1407e7e3c69c153d99f302 on Tue Jul 29 10:35:19 AM EDT 2025 (This is not the git hash of this file) // Copyright 2010-2021 <>< CNLohr, et. al. (Several other authors, many but not all mentioned) // Licensed under the MIT/x11 or NewBSD License you choose. // @@ -53,15 +53,22 @@ Usually tested combinations: #include //Some per-platform logic. -#if defined( ANDROID ) || defined( __android__ ) +#if defined( WINDOWS ) || defined( WIN32 ) || defined( WIN64 ) || defined( _WIN32 ) || defined( _WIN64 ) || defined( __CYGWIN__ ) + #define CNFG_WINDOWS +#elif defined( __wasm__ ) + #define CNFG_WASM +#elif defined( ANDROID ) || defined( __android__ ) + #define CNFG_ANDROID #define CNFGOGL +#else + #define CNFG_X11 #endif -#if ( defined( CNFGOGL ) || defined( __wasm__ ) ) && !defined(CNFG_HAS_XSHAPE) +#if ( defined( CNFGOGL ) || defined( CNFG_WASM ) ) && !defined(CNFG_HAS_XSHAPE) #define CNFG_BATCH 8192 //131,072 bytes. - #if defined( ANDROID ) || defined( __android__ ) || defined( __wasm__ ) || defined( EGL_LEAN_AND_MEAN ) + #if defined( CNFG_ANDROID ) || defined( CNFG_WASM ) || defined( EGL_LEAN_AND_MEAN ) #define CNFGEWGL //EGL or WebGL #else #define CNFGDESKTOPGL @@ -210,7 +217,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #define CNFG_KEY_FOCUS 0xf000 -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS #define CNFG_KEY_BACKSPACE 0x08 #define CNFG_KEY_TAB 0x09 @@ -290,8 +297,8 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #define CNFG_KEY_RIGHT_ALT 0xA5 #elif defined( EGL_LEAN_AND_MEAN ) // doesn't have any keys -#elif defined( __android__ ) || defined( ANDROID ) // ^ -#elif defined( __wasm__ ) +#elif defined( CNFG_ANDROID ) // ^ +#elif defined( CNFG_WASM ) #define CNFG_KEY_BACKSPACE 8 #define CNFG_KEY_TAB 9 @@ -455,7 +462,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #ifdef CNFG3D -#ifndef __wasm__ +#ifndef CNFG_WASM #include #endif @@ -471,7 +478,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH]; #define tdSQRT sqrtf #endif -#ifdef __wasm__ +#ifdef CNFG_WASM void tdMATCOPY( float * x, const float * y ); //Copy y into x #else #define tdMATCOPY(x,y) memcpy( x, y, 16*sizeof(float)) @@ -537,7 +544,7 @@ extern const unsigned short RawdrawFontCharMap[256]; #endif -#if defined( ANDROID ) || defined( __android__ ) +#ifdef CNFG_ANDROID #ifndef _CNFG_ANDROID_H #define _CNFG_ANDROID_H @@ -593,7 +600,7 @@ void HandleSuspend(); // For debugging: -#if defined( ANDROID ) && !defined( __cplusplus ) +#if defined( CNFG_ANDROID ) && !defined( __cplusplus ) #include @@ -1641,7 +1648,7 @@ uint8_t WSPOPMASK() -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS #define _WINSOCK_DEPRECATED_NO_WARNINGS #include #define socklen_t uint32_t @@ -1802,7 +1809,7 @@ int TickHTTP() { static double last; double now; -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS static LARGE_INTEGER lpf; LARGE_INTEGER li; @@ -1862,7 +1869,7 @@ int TickHTTP() memset( &tin, 0, addrlen ); int tsocket = accept( serverSocket, (struct sockaddr *)&tin, &addrlen ); -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS struct linger lx; lx.l_onoff = 1; lx.l_linger = 0; @@ -1951,7 +1958,7 @@ int TickHTTP() int RunHTTP( int port ) { -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS { WORD wVersionRequested; WSADATA wsaData; @@ -1981,7 +1988,7 @@ int RunHTTP( int port ) } //Disable SO_LINGER (Well, enable it but turn it way down) -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#ifdef CNFG_WINDOWS struct linger lx; lx.l_onoff = 1; lx.l_linger = 0; @@ -2948,7 +2955,7 @@ void CNFGGetDimensions( short * x, short * y ) #endif -#elif defined( __wasm__ ) +#elif defined( CNFG_WASM ) //Right now, designed for use with https://github.com/cnlohr/rawdrawwasm/ #include #include @@ -3009,6 +3016,10 @@ void CNFGGetScissors( int * xywh ) CNFGGetScissorsInternal( xywh ); } +void CNFGBlitImage(uint32_t *data, int x, int y, int w, int h) { + CNFGBlitImageInternal(data, x, y, w, h); +} + #else //Rasterizer - if you want to do this, you will need to enable blitting in the javascript. @@ -3050,7 +3061,7 @@ void CNFGInternalResize( short x, short y ) #endif } -#ifdef __wasm__ +#ifdef CNFG_WASM static uint32_t SWAPS( uint32_t r ) { uint32_t ret = (r&0xFF)<<24; @@ -3322,17 +3333,17 @@ void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h ) //Alpha blend. int alfa = newm&0xff; int onemalfa = 255-alfa; -#ifdef __wasm__ +#if defined( CNFG_WASM ) uint32_t newv = 255<<0; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; -#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#elif defined( CNFG_WINDOWS ) uint32_t newv = 255UL<<24; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; -#elif defined( ANDROID ) || defined( __android__ ) +#elif defined( CNFG_ANDROID ) uint32_t newv = 255<<16; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; @@ -3386,7 +3397,7 @@ int CNFGHandleInput() #endif -#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#elif defined( CNFG_WINDOWS ) //Copyright (c) 2011-2019 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose. //Portion from: http://en.wikibooks.org/wiki/Windows_Programming/Window_Creation @@ -3448,7 +3459,7 @@ void CNFGInternalResize( short x, short y ) #endif } -#ifdef __wasm__ +#ifdef CNFG_WASM static uint32_t SWAPS( uint32_t r ) { uint32_t ret = (r&0xFF)<<24; @@ -3720,17 +3731,17 @@ void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h ) //Alpha blend. int alfa = newm&0xff; int onemalfa = 255-alfa; -#ifdef __wasm__ +#if defined( CNFG_WASM ) uint32_t newv = 255<<0; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; -#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#elif defined( CNFG_WINDOWS ) uint32_t newv = 255UL<<24; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; -#elif defined( ANDROID ) || defined( __android__ ) +#elif defined( CNFG_ANDROID ) uint32_t newv = 255<<16; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; @@ -4546,7 +4557,7 @@ void CNFGSwapBuffers() } -#elif defined( __android__ ) || defined( ANDROID ) +#elif defined( CNFG_ANDROID ) /* * Copyright (c) 2011-2013 Luc Verhaegen * Copyright (c) 2018-2020 <>< Charles Lohr @@ -4571,16 +4582,11 @@ void CNFGSwapBuffers() * DEALINGS IN THE SOFTWARE. */ - -#if defined( __android__ ) && !defined( ANDROID ) -#define ANDROID -#endif - //Note: This interface provides the following two things privately. //you may "extern" them in your code. -#ifdef ANDROID +#ifdef CNFG_ANDROID #ifndef _CNFG_ANDROID_H @@ -4638,7 +4644,7 @@ void HandleSuspend(); // For debugging: -#if defined( ANDROID ) && !defined( __cplusplus ) +#if defined( CNFG_ANDROID ) && !defined( __cplusplus ) #include @@ -4825,7 +4831,7 @@ int android_sdk_version; #include #include -#ifdef ANDROID +#ifdef CNFG_ANDROID #include #else #include @@ -4870,7 +4876,7 @@ int android_sdk_version; unsigned int format; /* extra format information in case rgbal is not enough, especially for YUV formats */ } fbdev_pixmap; -#if defined( ANDROID ) +#if defined( CNFG_ANDROID ) EGLNativeWindowType native_window; #else struct fbdev_window native_window; @@ -4888,7 +4894,7 @@ static EGLint const config_attribute_list[] = { EGL_STENCIL_SIZE, 0, EGL_DEPTH_SIZE, EGL_ZBITS, //EGL_SAMPLES, 1, -#ifdef ANDROID +#ifdef CNFG_ANDROID #if ANDROIDVERSION >= 28 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, #else @@ -4929,7 +4935,7 @@ void CNFGSwapBuffers() if ( egl_display == EGL_NO_DISPLAY ) return; CNFGFlushRender(); eglSwapBuffers(egl_display, egl_surface); -#ifdef ANDROID +#ifdef CNFG_ANDROID if( !override_android_screen_dimensons ) { android_width = ANativeWindow_getWidth( native_window ); @@ -4943,7 +4949,7 @@ void CNFGSwapBuffers() void CNFGGetDimensions( short * x, short * y ) { -#ifdef ANDROID +#ifdef CNFG_ANDROID *x = android_width; *y = android_height; #else @@ -4997,7 +5003,7 @@ int CNFGSetup( const char * WindowName, int w, int h ) egl_display = eglGetDisplay((EGLNativeDisplayType) XDisplay); #else -#ifndef ANDROID +#ifndef CNFG_ANDROID if( w >= 1 && h >= 1 ) { native_window.width = w; @@ -5071,7 +5077,7 @@ int CNFGSetup( const char * WindowName, int w, int h ) } printf( "Width/Height: %dx%d\n", android_width, android_height ); egl_surface = eglCreateWindowSurface(egl_display, egl_config, -#ifdef ANDROID +#ifdef CNFG_ANDROID gapp->window, #else (EGLNativeWindowType)&native_window, @@ -5086,7 +5092,7 @@ int CNFGSetup( const char * WindowName, int w, int h ) return -1; } -#ifndef ANDROID +#ifndef CNFG_ANDROID int width, height; if (!eglQuerySurface(egl_display, egl_surface, EGL_WIDTH, &width) || !eglQuerySurface(egl_display, egl_surface, EGL_HEIGHT, &height)) { @@ -5138,7 +5144,7 @@ bool touch_is_down[MAX_NUM_TOUCHES]; int32_t handle_input(struct android_app* app, AInputEvent* event) { -#ifdef ANDROID +#ifdef CNFG_ANDROID //Potentially do other things here. if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) @@ -5205,7 +5211,7 @@ int32_t handle_input(struct android_app* app, AInputEvent* event) int CNFGHandleInput() { -#ifdef ANDROID +#ifdef CNFG_ANDROID int events; struct android_poll_source* source; while( ALooper_pollOnce( 0, 0, &events, (void**)&source) >= 0 ) @@ -5238,7 +5244,7 @@ int CNFGHandleInput() -#ifdef ANDROID +#ifdef CNFG_ANDROID void (*HandleWindowTermination)(); @@ -6272,7 +6278,7 @@ void CNFGInternalResize( short x, short y ) #endif } -#ifdef __wasm__ +#ifdef CNFG_WASM static uint32_t SWAPS( uint32_t r ) { uint32_t ret = (r&0xFF)<<24; @@ -6544,17 +6550,17 @@ void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h ) //Alpha blend. int alfa = newm&0xff; int onemalfa = 255-alfa; -#ifdef __wasm__ +#if defined( CNFG_WASM ) uint32_t newv = 255<<0; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; -#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#elif defined( CNFG_WINDOWS ) uint32_t newv = 255UL<<24; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8; newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; -#elif defined( ANDROID ) || defined( __android__ ) +#elif defined( CNFG_ANDROID ) uint32_t newv = 255<<16; //Alpha, then RGB newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24; newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0; @@ -7001,7 +7007,7 @@ void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize ) void CNFGEmitBackendTriangles( const float * fv, const uint32_t * col, int nr_verts ); //If on WASM, sqrtf is implied. On other platforms, need sqrtf from math.h -#ifdef __wasm__ +#ifdef CNFG_WASM float sqrtf( float f ); #define cnfg_sqrtf sqrtf #elif defined( __TINYC__ ) && defined( WIN32 ) @@ -7121,7 +7127,7 @@ void CNFGSetLineWidth( short width ) #endif -#if !defined( __wasm__ ) && !defined( CNFGHTTP ) +#if !defined( CNFG_WASM ) && !defined( CNFGHTTP ) //In WASM, Javascript takes over this functionality. //Shader compilation errors go to stderr. @@ -7140,14 +7146,14 @@ void CNFGSetLineWidth( short width ) #define LGLchar GLchar #endif -#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) +#ifdef CNFG_WINDOWS #define CNFGOGL_NEED_EXTENSION #include #endif #ifdef CNFGOGL_NEED_EXTENSION // If we are going to be defining our own function pointer call - #if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) + #ifdef CNFG_WINDOWS // Make sure to use __stdcall on Windows #define CHEWTYPEDEF( ret, name, rv, paramcall, ... ) \ typedef ret (__stdcall *CNFGTYPE##name)( __VA_ARGS__ ); \ @@ -7220,7 +7226,7 @@ CHEWTYPEDEF( void, glActiveTexture, , (texture), GLenum texture ) #endif #ifdef CNFGOGL_NEED_EXTENSION -#if defined( WIN32 ) || defined( WINDOWS ) || defined( WIN64 ) +#ifdef CNFG_WINDOWS //From https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions void * CNFGGetProcAddress(const char *name) @@ -7620,7 +7626,7 @@ void CNFGClearFrame() #endif -#endif //__wasm__ +#endif // CNFG_WASM #else @@ -7643,7 +7649,7 @@ void CNFGFlushRender() { } #ifdef CNFG3D -#ifdef __wasm__ +#ifdef CNFG_WASM double sin( double v ); double cos( double v ); double tan( double v ); @@ -7898,7 +7904,7 @@ void tdMultiply( float * fin1, float * fin2, float * fout ) tdMATCOPY( fout, fotmp ); } -#ifndef __wasm__ +#ifndef CNFG_WASM void tdPrint( const float * f ) { int i;