--- a/mojoshader_common.c Wed Apr 01 17:11:09 2020 -0400
+++ b/mojoshader_common.c Wed Apr 01 17:12:48 2020 -0400
@@ -1,6 +1,8 @@
#define __MOJOSHADER_INTERNAL__ 1
#include "mojoshader_internal.h"
+#ifndef MOJOSHADER_USE_SDL_STDLIB
#include <math.h>
+#endif /* MOJOSHADER_USE_SDL_STDLIB */
// Convenience functions for allocators...
#if !MOJOSHADER_FORCE_ALLOCATOR
--- a/mojoshader_effects.c Wed Apr 01 17:11:09 2020 -0400
+++ b/mojoshader_effects.c Wed Apr 01 17:12:48 2020 -0400
@@ -12,7 +12,9 @@
#ifdef MOJOSHADER_EFFECT_SUPPORT
+#ifndef MOJOSHADER_USE_SDL_STDLIB
#include <math.h>
+#endif /* MOJOSHADER_USE_SDL_STDLIB */
void MOJOSHADER_runPreshader(const MOJOSHADER_preshader *preshader,
float *outregs)
--- a/mojoshader_internal.h Wed Apr 01 17:11:09 2020 -0400
+++ b/mojoshader_internal.h Wed Apr 01 17:12:48 2020 -0400
@@ -8,11 +8,71 @@
// Shader bytecode format is described at MSDN:
// http://msdn.microsoft.com/en-us/library/ff569705.aspx
+#ifdef MOJOSHADER_USE_SDL_STDLIB
+#include <SDL_assert.h>
+#include <SDL_stdinc.h>
+
+/* stdint.h */
+typedef Uint8 uint8;
+typedef Uint16 uint16;
+typedef Uint32 uint32;
+typedef Sint32 int32;
+typedef Sint64 int64;
+typedef Uint64 uint64;
+
+/* assert.h */
+#define assert SDL_assert
+
+/* stdlib.h */
+#define malloc SDL_malloc
+#define free SDL_free
+
+/* stdio.h */
+#define sscanf SDL_sscanf
+#define snprintf SDL_snprintf
+#define vsnprintf SDL_vsnprintf
+
+/* math.h */
+#define acos SDL_acos
+#define asin SDL_asin
+#define atan SDL_atan
+#define atan2 SDL_atan2
+#define cos SDL_acos
+#define exp SDL_exp
+#define floor SDL_floor
+#define log SDL_log
+#define sin SDL_sin
+#define sqrt SDL_sqrt
+
+/* string.h */
+#define strchr SDL_strchr
+#define strcmp SDL_strcmp
+/* TODO: Move MojoShader away from strcpy! This len is awful! */
+#define strcpy(dst, src) SDL_strlcpy(dst, src, SDL_strlen(src) + 1)
+#define strlen SDL_strlen
+#define strncmp SDL_strncmp
+#define strstr SDL_strstr
+
+/* string.h but with undefs for Apple systems */
+#ifdef memcmp
+#undef memcmp
+#endif
+#define memcmp SDL_memcmp
+#ifdef memcpy
+#undef memcpy
+#endif
+#define memcpy SDL_memcpy
+#ifdef memset
+#define memset
+#endif
+#define memset SDL_memset
+#else /* MOJOSHADER_USE_SDL_STDLIB */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
+#endif /* MOJOSHADER_USE_SDL_STDLIB */
#include "mojoshader.h"
@@ -114,6 +174,7 @@
// Locale-independent float printing replacement for snprintf
size_t MOJOSHADER_printFloat(char *text, size_t maxlen, float arg);
+#ifndef MOJOSHADER_USE_SDL_STDLIB
#ifdef _MSC_VER
#include <float.h>
#include <malloc.h>
@@ -155,6 +216,7 @@
#ifdef sun
#include <alloca.h>
#endif
+#endif /* MOJOSHADER_USE_SDL_STDLIB */
#ifdef __GNUC__
#define ISPRINTF(x,y) __attribute__((format (printf, x, y)))
--- a/mojoshader_opengl.c Wed Apr 01 17:11:09 2020 -0400
+++ b/mojoshader_opengl.c Wed Apr 01 17:12:48 2020 -0400
@@ -7,12 +7,6 @@
* This file written by Ryan C. Gordon.
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <assert.h>
-
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h> // GL headers need this for WINGDIAPI definition.