Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CNFG.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 16 additions & 9 deletions CNFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ Usually tested combinations:
#include <stdint.h>

//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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -453,7 +460,7 @@ extern uint32_t CNFGVertDataC[CNFG_BATCH];

#ifdef CNFG3D

#ifndef __wasm__
#ifndef CNFG_WASM
#include <math.h>
#endif

Expand All @@ -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))
Expand Down Expand Up @@ -535,7 +542,7 @@ extern const unsigned short RawdrawFontCharMap[256];
#endif


#if defined( ANDROID ) || defined( __android__ )
#ifdef CNFG_ANDROID
#include "CNFGAndroid.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions CNFG3D.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "CNFG.h"

#ifdef __wasm__
#ifdef CNFG_WASM
double sin( double v );
double cos( double v );
double tan( double v );
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion CNFGAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void HandleSuspend();

// For debugging:

#if defined( ANDROID ) && !defined( __cplusplus )
#if defined( CNFG_ANDROID ) && !defined( __cplusplus )

#include <jni.h>

Expand Down
29 changes: 12 additions & 17 deletions CNFGEGLDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -60,7 +55,7 @@ int android_sdk_version;
#include <stdint.h>
#include <EGL/egl.h>

#ifdef ANDROID
#ifdef CNFG_ANDROID
#include <GLES3/gl3.h>
#else
#include <GLES2/gl2.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 );
Expand All @@ -178,7 +173,7 @@ void CNFGSwapBuffers()

void CNFGGetDimensions( short * x, short * y )
{
#ifdef ANDROID
#ifdef CNFG_ANDROID
*x = android_width;
*y = android_height;
#else
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -473,7 +468,7 @@ int CNFGHandleInput()



#ifdef ANDROID
#ifdef CNFG_ANDROID

void (*HandleWindowTermination)();

Expand Down
12 changes: 6 additions & 6 deletions CNFGFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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.
Expand All @@ -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 <GL/gl.h>
#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__ ); \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -952,7 +952,7 @@ void CNFGClearFrame()

#endif

#endif //__wasm__
#endif // CNFG_WASM

#else

Expand Down
10 changes: 5 additions & 5 deletions CNFGHTTP.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <winsock2.h>
#define socklen_t uint32_t
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions CNFGRasterizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading