Skip to content

Commit c22e8ee

Browse files
authored
Merge pull request #126 from Kylogias/plat-defines
Add platform specific defines
2 parents dcadc5d + 543d9b1 commit c22e8ee

9 files changed

Lines changed: 112 additions & 104 deletions

File tree

CNFG.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ int CNFGLastScancode = 0;
88

99
#if defined( CNFGHTTP )
1010
#include "CNFGHTTP.c"
11-
#elif defined( __wasm__ )
11+
#elif defined( CNFG_WASM )
1212
#include "CNFGWASMDriver.c"
13-
#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
13+
#elif defined( CNFG_WINDOWS )
1414
#include "CNFGWinDriver.c"
1515
#elif defined( EGL_LEAN_AND_MEAN )
1616
#include "CNFGEGLLeanAndMean.c"
17-
#elif defined( __android__ ) || defined( ANDROID )
17+
#elif defined( CNFG_ANDROID )
1818
#include "CNFGEGLDriver.c"
1919
#else
2020
#include "CNFGXDriver.c"

CNFG.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,22 @@ Usually tested combinations:
5151
#include <stdint.h>
5252

5353
//Some per-platform logic.
54-
#if defined( ANDROID ) || defined( __android__ )
54+
#if defined( WINDOWS ) || defined( WIN32 ) || defined( WIN64 ) || defined( _WIN32 ) || defined( _WIN64 ) || defined( __CYGWIN__ )
55+
#define CNFG_WINDOWS
56+
#elif defined( __wasm__ )
57+
#define CNFG_WASM
58+
#elif defined( ANDROID ) || defined( __android__ )
59+
#define CNFG_ANDROID
5560
#define CNFGOGL
61+
#else
62+
#define CNFG_X11
5663
#endif
5764

58-
#if ( defined( CNFGOGL ) || defined( __wasm__ ) ) && !defined(CNFG_HAS_XSHAPE)
65+
#if ( defined( CNFGOGL ) || defined( CNFG_WASM ) ) && !defined(CNFG_HAS_XSHAPE)
5966

6067
#define CNFG_BATCH 8192 //131,072 bytes.
6168

62-
#if defined( ANDROID ) || defined( __android__ ) || defined( __wasm__ ) || defined( EGL_LEAN_AND_MEAN )
69+
#if defined( CNFG_ANDROID ) || defined( CNFG_WASM ) || defined( EGL_LEAN_AND_MEAN )
6370
#define CNFGEWGL //EGL or WebGL
6471
#else
6572
#define CNFGDESKTOPGL
@@ -208,7 +215,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH];
208215

209216
#define CNFG_KEY_FOCUS 0xf000
210217

211-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
218+
#ifdef CNFG_WINDOWS
212219

213220
#define CNFG_KEY_BACKSPACE 0x08
214221
#define CNFG_KEY_TAB 0x09
@@ -288,8 +295,8 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH];
288295
#define CNFG_KEY_RIGHT_ALT 0xA5
289296

290297
#elif defined( EGL_LEAN_AND_MEAN ) // doesn't have any keys
291-
#elif defined( __android__ ) || defined( ANDROID ) // ^
292-
#elif defined( __wasm__ )
298+
#elif defined( CNFG_ANDROID ) // ^
299+
#elif defined( CNFG_WASM )
293300

294301
#define CNFG_KEY_BACKSPACE 8
295302
#define CNFG_KEY_TAB 9
@@ -453,7 +460,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH];
453460

454461
#ifdef CNFG3D
455462

456-
#ifndef __wasm__
463+
#ifndef CNFG_WASM
457464
#include <math.h>
458465
#endif
459466

@@ -469,7 +476,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH];
469476
#define tdSQRT sqrtf
470477
#endif
471478

472-
#ifdef __wasm__
479+
#ifdef CNFG_WASM
473480
void tdMATCOPY( float * x, const float * y ); //Copy y into x
474481
#else
475482
#define tdMATCOPY(x,y) memcpy( x, y, 16*sizeof(float))
@@ -535,7 +542,7 @@ extern const unsigned short RawdrawFontCharMap[256];
535542
#endif
536543

537544

538-
#if defined( ANDROID ) || defined( __android__ )
545+
#ifdef CNFG_ANDROID
539546
#include "CNFGAndroid.h"
540547
#endif
541548

CNFG3D.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "CNFG.h"
99

10-
#ifdef __wasm__
10+
#ifdef CNFG_WASM
1111
double sin( double v );
1212
double cos( double v );
1313
double tan( double v );
@@ -262,7 +262,7 @@ void tdMultiply( float * fin1, float * fin2, float * fout )
262262
tdMATCOPY( fout, fotmp );
263263
}
264264

265-
#ifndef __wasm__
265+
#ifndef CNFG_WASM
266266
void tdPrint( const float * f )
267267
{
268268
int i;

CNFGAndroid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void HandleSuspend();
5353

5454
// For debugging:
5555

56-
#if defined( ANDROID ) && !defined( __cplusplus )
56+
#if defined( CNFG_ANDROID ) && !defined( __cplusplus )
5757

5858
#include <jni.h>
5959

CNFGEGLDriver.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
* DEALINGS IN THE SOFTWARE.
2323
*/
2424

25-
26-
#if defined( __android__ ) && !defined( ANDROID )
27-
#define ANDROID
28-
#endif
29-
3025
//Note: This interface provides the following two things privately.
3126
//you may "extern" them in your code.
3227

3328

34-
#ifdef ANDROID
29+
#ifdef CNFG_ANDROID
3530

3631

3732
#include "CNFGAndroid.h"
@@ -60,7 +55,7 @@ int android_sdk_version;
6055
#include <stdint.h>
6156
#include <EGL/egl.h>
6257

63-
#ifdef ANDROID
58+
#ifdef CNFG_ANDROID
6459
#include <GLES3/gl3.h>
6560
#else
6661
#include <GLES2/gl2.h>
@@ -105,7 +100,7 @@ int android_sdk_version;
105100
unsigned int format; /* extra format information in case rgbal is not enough, especially for YUV formats */
106101
} fbdev_pixmap;
107102

108-
#if defined( ANDROID )
103+
#if defined( CNFG_ANDROID )
109104
EGLNativeWindowType native_window;
110105
#else
111106
struct fbdev_window native_window;
@@ -123,7 +118,7 @@ static EGLint const config_attribute_list[] = {
123118
EGL_STENCIL_SIZE, 0,
124119
EGL_DEPTH_SIZE, EGL_ZBITS,
125120
//EGL_SAMPLES, 1,
126-
#ifdef ANDROID
121+
#ifdef CNFG_ANDROID
127122
#if ANDROIDVERSION >= 28
128123
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
129124
#else
@@ -164,7 +159,7 @@ void CNFGSwapBuffers()
164159
if ( egl_display == EGL_NO_DISPLAY ) return;
165160
CNFGFlushRender();
166161
eglSwapBuffers(egl_display, egl_surface);
167-
#ifdef ANDROID
162+
#ifdef CNFG_ANDROID
168163
if( !override_android_screen_dimensons )
169164
{
170165
android_width = ANativeWindow_getWidth( native_window );
@@ -178,7 +173,7 @@ void CNFGSwapBuffers()
178173

179174
void CNFGGetDimensions( short * x, short * y )
180175
{
181-
#ifdef ANDROID
176+
#ifdef CNFG_ANDROID
182177
*x = android_width;
183178
*y = android_height;
184179
#else
@@ -232,7 +227,7 @@ int CNFGSetup( const char * WindowName, int w, int h )
232227
egl_display = eglGetDisplay((EGLNativeDisplayType) XDisplay);
233228
#else
234229

235-
#ifndef ANDROID
230+
#ifndef CNFG_ANDROID
236231
if( w >= 1 && h >= 1 )
237232
{
238233
native_window.width = w;
@@ -306,7 +301,7 @@ int CNFGSetup( const char * WindowName, int w, int h )
306301
}
307302
printf( "Width/Height: %dx%d\n", android_width, android_height );
308303
egl_surface = eglCreateWindowSurface(egl_display, egl_config,
309-
#ifdef ANDROID
304+
#ifdef CNFG_ANDROID
310305
gapp->window,
311306
#else
312307
(EGLNativeWindowType)&native_window,
@@ -321,7 +316,7 @@ int CNFGSetup( const char * WindowName, int w, int h )
321316
return -1;
322317
}
323318

324-
#ifndef ANDROID
319+
#ifndef CNFG_ANDROID
325320
int width, height;
326321
if (!eglQuerySurface(egl_display, egl_surface, EGL_WIDTH, &width) ||
327322
!eglQuerySurface(egl_display, egl_surface, EGL_HEIGHT, &height)) {
@@ -373,7 +368,7 @@ bool touch_is_down[MAX_NUM_TOUCHES];
373368

374369
int32_t handle_input(struct android_app* app, AInputEvent* event)
375370
{
376-
#ifdef ANDROID
371+
#ifdef CNFG_ANDROID
377372
//Potentially do other things here.
378373

379374
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
@@ -440,7 +435,7 @@ int32_t handle_input(struct android_app* app, AInputEvent* event)
440435
int CNFGHandleInput()
441436
{
442437

443-
#ifdef ANDROID
438+
#ifdef CNFG_ANDROID
444439
int events;
445440
struct android_poll_source* source;
446441
while( ALooper_pollOnce( 0, 0, &events, (void**)&source) >= 0 )
@@ -473,7 +468,7 @@ int CNFGHandleInput()
473468

474469

475470

476-
#ifdef ANDROID
471+
#ifdef CNFG_ANDROID
477472

478473
void (*HandleWindowTermination)();
479474

CNFGFunctions.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize )
333333
void CNFGEmitBackendTriangles( const float * fv, const uint32_t * col, int nr_verts );
334334

335335
//If on WASM, sqrtf is implied. On other platforms, need sqrtf from math.h
336-
#ifdef __wasm__
336+
#ifdef CNFG_WASM
337337
float sqrtf( float f );
338338
#define cnfg_sqrtf sqrtf
339339
#elif defined( __TINYC__ ) && defined( WIN32 )
@@ -453,7 +453,7 @@ void CNFGSetLineWidth( short width )
453453
#endif
454454

455455

456-
#if !defined( __wasm__ ) && !defined( CNFGHTTP )
456+
#if !defined( CNFG_WASM ) && !defined( CNFGHTTP )
457457
//In WASM, Javascript takes over this functionality.
458458

459459
//Shader compilation errors go to stderr.
@@ -472,14 +472,14 @@ void CNFGSetLineWidth( short width )
472472
#define LGLchar GLchar
473473
#endif
474474

475-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64)
475+
#ifdef CNFG_WINDOWS
476476
#define CNFGOGL_NEED_EXTENSION
477477
#include <GL/gl.h>
478478
#endif
479479

480480
#ifdef CNFGOGL_NEED_EXTENSION
481481
// If we are going to be defining our own function pointer call
482-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64)
482+
#ifdef CNFG_WINDOWS
483483
// Make sure to use __stdcall on Windows
484484
#define CHEWTYPEDEF( ret, name, rv, paramcall, ... ) \
485485
typedef ret (__stdcall *CNFGTYPE##name)( __VA_ARGS__ ); \
@@ -552,7 +552,7 @@ CHEWTYPEDEF( void, glActiveTexture, , (texture), GLenum texture )
552552
#endif
553553

554554
#ifdef CNFGOGL_NEED_EXTENSION
555-
#if defined( WIN32 ) || defined( WINDOWS ) || defined( WIN64 )
555+
#ifdef CNFG_WINDOWS
556556

557557
//From https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions
558558
void * CNFGGetProcAddress(const char *name)
@@ -952,7 +952,7 @@ void CNFGClearFrame()
952952

953953
#endif
954954

955-
#endif //__wasm__
955+
#endif // CNFG_WASM
956956

957957
#else
958958

CNFGHTTP.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ uint8_t WSPOPMASK()
871871

872872

873873

874-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
874+
#ifdef CNFG_WINDOWS
875875
#define _WINSOCK_DEPRECATED_NO_WARNINGS
876876
#include <winsock2.h>
877877
#define socklen_t uint32_t
@@ -1032,7 +1032,7 @@ int TickHTTP()
10321032
{
10331033
static double last;
10341034
double now;
1035-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
1035+
#ifdef CNFG_WINDOWS
10361036
static LARGE_INTEGER lpf;
10371037
LARGE_INTEGER li;
10381038

@@ -1092,7 +1092,7 @@ int TickHTTP()
10921092
memset( &tin, 0, addrlen );
10931093
int tsocket = accept( serverSocket, (struct sockaddr *)&tin, &addrlen );
10941094

1095-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
1095+
#ifdef CNFG_WINDOWS
10961096
struct linger lx;
10971097
lx.l_onoff = 1;
10981098
lx.l_linger = 0;
@@ -1181,7 +1181,7 @@ int TickHTTP()
11811181

11821182
int RunHTTP( int port )
11831183
{
1184-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
1184+
#ifdef CNFG_WINDOWS
11851185
{
11861186
WORD wVersionRequested;
11871187
WSADATA wsaData;
@@ -1211,7 +1211,7 @@ int RunHTTP( int port )
12111211
}
12121212

12131213
//Disable SO_LINGER (Well, enable it but turn it way down)
1214-
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
1214+
#ifdef CNFG_WINDOWS
12151215
struct linger lx;
12161216
lx.l_onoff = 1;
12171217
lx.l_linger = 0;

CNFGRasterizer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void CNFGInternalResize( short x, short y )
2727
#endif
2828
}
2929

30-
#ifdef __wasm__
30+
#ifdef CNFG_WASM
3131
static uint32_t SWAPS( uint32_t r )
3232
{
3333
uint32_t ret = (r&0xFF)<<24;
@@ -299,17 +299,17 @@ void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h )
299299
//Alpha blend.
300300
int alfa = newm&0xff;
301301
int onemalfa = 255-alfa;
302-
#ifdef __wasm__
302+
#if defined( CNFG_WASM )
303303
uint32_t newv = 255<<0; //Alpha, then RGB
304304
newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24;
305305
newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16;
306306
newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8;
307-
#elif defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
307+
#elif defined( CNFG_WINDOWS )
308308
uint32_t newv = 255UL<<24; //Alpha, then RGB
309309
newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>16)&0xff) * onemalfa + 128)>>8)<<16;
310310
newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>8)&0xff) * onemalfa + 128)>>8)<<8;
311311
newv |= ((((newm>>8)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0;
312-
#elif defined( ANDROID ) || defined( __android__ )
312+
#elif defined( CNFG_ANDROID )
313313
uint32_t newv = 255<<16; //Alpha, then RGB
314314
newv |= ((((newm>>24)&0xff) * alfa + ((oldm>>24)&0xff) * onemalfa + 128)>>8)<<24;
315315
newv |= ((((newm>>16)&0xff) * alfa + ((oldm>>0)&0xff) * onemalfa + 128)>>8)<<0;

0 commit comments

Comments
 (0)