diff --git a/build.bat b/build.bat index e69de29..4a864cb 100644 --- a/build.bat +++ b/build.bat @@ -0,0 +1,6 @@ + +if not exist bin mkdir bin + +set INCLUDES=/I src /I src/util /I src/platform /I ext +cl /Zi /Zc:preprocessor /std:c11 %INCLUDES% /c /Fo:bin/milepost.obj src/milepost.c +lib bin/milepost.obj /OUT:bin/milepost.lib diff --git a/examples/simpleWindow/build.bat b/examples/simpleWindow/build.bat index 7031793..3e918f6 100644 --- a/examples/simpleWindow/build.bat +++ b/examples/simpleWindow/build.bat @@ -1,3 +1,2 @@ set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext - -cl main.c %INCLUDES% /Zi /Zc:preprocessor /std:c11 /link user32.lib opengl32.lib gdi32.lib /out:test.exe +cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib user32.lib opengl32.lib gdi32.lib /out:test.exe diff --git a/examples/simpleWindow/main.c b/examples/simpleWindow/main.c index e29bb6e..9ab6995 100644 --- a/examples/simpleWindow/main.c +++ b/examples/simpleWindow/main.c @@ -9,20 +9,10 @@ #include #include -#include"platform.h" -#include"win32_app.c" -#include"debug_log.c" -#include"memory.c" -#include"strings.c" +#define _USE_MATH_DEFINES //NOTE: necessary for MSVC +#include - -#include"ringbuffer.c" -#include"win32_base_allocator.c" -#include"utf8.c" - -#define MG_IMPLEMENTS_BACKEND_GL -#include"graphics.c" -#include"win32_gl_surface.c" +#include"milepost.h" #define LOG_SUBSYSTEM "Main" diff --git a/src/milepost.c b/src/milepost.c index 7c4da4d..e5b5e15 100644 --- a/src/milepost.c +++ b/src/milepost.c @@ -7,23 +7,60 @@ * *****************************************************************/ +//--------------------------------------------------------------- +// utilities implementations +//--------------------------------------------------------------- #include"util/debug_log.c" -#include"memory.c" -#include"strings.c" -#include"ringbuffer.c" +#include"util/memory.c" +#include"util/strings.c" #include"util/utf8.c" #include"util/hash.c" +#include"util/ringbuffer.c" -#include"platform/unix_base_allocator.c" +//--------------------------------------------------------------- +// platform implementations +//--------------------------------------------------------------- +#include"platform.h" +#if defined(OS_WIN64) + #include"platform/win32_base_allocator.c" + //TODO +#elif defined(OS_MACOS) + #include"platform/unix_base_allocator.c" + #include"platform/osx_clock.c" + /* + #include"platform/unix_rng.c" + #include"platform/posix_thread.c" + #include"platform/posix_socket.c" + */ + +#elif defined(OS_LINUX) + #include"platform/unix_base_allocator.c" + #include"platform/linux_clock.c" + /* + #include"platform/unix_rng.c" + #include"platform/posix_thread.c" + #include"platform/posix_socket.c" + */ +#else + #error "Unsupported platform" +#endif + +//--------------------------------------------------------------- +// application layer +//--------------------------------------------------------------- + +#if defined(OS_WIN64) + #include"win32_app.c" + #include"win32_gl_surface.c" +#elif defined(OS_MACOS) + //NOTE: macos application layer is defined in milepost.m +#else + #error "Unsupported platform" +#endif + +//--------------------------------------------------------------- +// graphics/ui layer +//--------------------------------------------------------------- #include"graphics.c" -#include"ui.c" - -//TODO: guard these under platform-specific #ifdefs -#include"platform/osx_clock.c" -/* - -#include"platform/unix_rng.c" -#include"platform/posix_thread.c" -#include"platform/posix_socket.c" -*/ +//#include"ui.c" diff --git a/src/milepost.h b/src/milepost.h index e7c7e4d..711bcfd 100644 --- a/src/milepost.h +++ b/src/milepost.h @@ -9,7 +9,10 @@ #ifndef __MILEPOST_H_ #define __MILEPOST_H_ - +//---------------------------------------------------------------- +// utility layer +//---------------------------------------------------------------- +#include"platform.h" #include"typedefs.h" #include"macro_helpers.h" #include"debug_log.h" @@ -17,16 +20,32 @@ #include"memory.h" #include"strings.h" #include"utf8.h" +#include"hash.h" +//---------------------------------------------------------------- +// platform layer +//---------------------------------------------------------------- #include"platform_clock.h" /* #include"platform_rng.h" #include"platform_socket.h" #include"platform_thread.h" */ + +//---------------------------------------------------------------- +// application layer +//---------------------------------------------------------------- #include"mp_app.h" + +#if defined(OS_WIN64) || defined(OS_WIN32) + #define WIN32_GL_LOADER_API + #include"win32_gl_loader.h" +#endif + +//---------------------------------------------------------------- +// graphics/ui layer +//---------------------------------------------------------------- #include"graphics.h" #include"ui.h" -#include"hash.h" #endif //__MILEPOST_H_ diff --git a/src/platform/win32_base_allocator.c b/src/platform/win32_base_allocator.c index c35e272..92e58c7 100644 --- a/src/platform/win32_base_allocator.c +++ b/src/platform/win32_base_allocator.c @@ -6,6 +6,7 @@ * @revision: * *****************************************************************/ +#define WIN32_LEAN_AND_MEAN #include #include"platform_base_allocator.h" diff --git a/src/util/macro_helpers.h b/src/util/macro_helpers.h index e8614f3..d076d30 100644 --- a/src/util/macro_helpers.h +++ b/src/util/macro_helpers.h @@ -9,11 +9,12 @@ #ifndef __MACRO_HELPERS_H_ #define __MACRO_HELPERS_H_ +#include"typedefs.h" + //NOTE(martin): macro concatenation #define _cat2_(a, b) a##b #define _cat3_(a, b, c) a##b##c - //NOTE(martin): inline, but still generate code // (eg. use the inline version inside a library, but still exports the function for client code) //TODO(martin): this is a compiler-specific attribute, recognized by clang and gcc. See if there's a more portable approach diff --git a/src/win32_gl_loader.h b/src/win32_gl_loader.h new file mode 100644 index 0000000..24f6ad0 --- /dev/null +++ b/src/win32_gl_loader.h @@ -0,0 +1,65 @@ +/************************************************************//** +* +* @file: win32_gl_loader.h +* @author: Martin Fouilleul +* @date: 01/08/2022 +* @revision: +* +*****************************************************************/ + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include"GL/glext.h" +#include"GL/wglext.h" + +#include"macro_helpers.h" + +#define GL_PROC_LIST \ + GL_PROC(WGLCHOOSEPIXELFORMATARB, wglChoosePixelFormatARB) \ + GL_PROC(WGLCREATECONTEXTATTRIBSARB, wglCreateContextAttribsARB) \ + GL_PROC(WGLMAKECONTEXTCURRENTARB, wglMakeContextCurrentARB) \ + GL_PROC(WGLSWAPINTERVALEXT, wglSwapIntervalEXT) \ + GL_PROC(GLCREATESHADER, glCreateShader) \ + GL_PROC(GLCREATEPROGRAM, glCreateProgram) \ + GL_PROC(GLATTACHSHADER, glAttachShader) \ + GL_PROC(GLCOMPILESHADER, glCompileShader) \ + GL_PROC(GLGETSHADERIV, glGetShaderiv) \ + GL_PROC(GLGETSHADERINFOLOG, glGetShaderInfoLog) \ + GL_PROC(GLSHADERSOURCE, glShaderSource) \ + GL_PROC(GLLINKPROGRAM, glLinkProgram) \ + GL_PROC(GLGETPROGRAMIV, glGetProgramiv) \ + GL_PROC(GLGETPROGRAMINFOLOG, glGetProgramInfoLog) \ + GL_PROC(GLUSEPROGRAM, glUseProgram) \ + GL_PROC(GLGENVERTEXARRAYS, glGenVertexArrays) \ + GL_PROC(GLBINDVERTEXARRAY, glBindVertexArray) \ + GL_PROC(GLGENBUFFERS, glGenBuffers) \ + GL_PROC(GLBINDBUFFER, glBindBuffer) \ + GL_PROC(GLBUFFERDATA, glBufferData) \ + GL_PROC(GLUNIFORMMATRIX4FV, glUniformMatrix4fv) \ + GL_PROC(GLVERTEXATTRIBPOINTER, glVertexAttribPointer) \ + GL_PROC(GLENABLEVERTEXATTRIBARRAY, glEnableVertexAttribArray) + +#ifdef WIN32_GL_LOADER_API + //NOTE: pointer declarations + #define GL_PROC(type, name) extern _cat3_(PFN, type, PROC) name; + GL_PROC_LIST + #undef GL_PROC +#endif + + +#ifdef WIN32_GL_LOADER_IMPL +#define GL_PROC(type, name) _cat3_(PFN, type, PROC) name = 0; + GL_PROC_LIST +#undef GL_PROC + +void mp_gl_load_procs() +{ + #define GL_PROC(type, name) name = (_cat3_(PFN, type, PROC))wglGetProcAddress( #name ); + GL_PROC_LIST + #undef GL_PROC +} + +#endif + +#undef GL_PROC_LIST diff --git a/src/win32_gl_surface.c b/src/win32_gl_surface.c index 16f0e75..c10901b 100644 --- a/src/win32_gl_surface.c +++ b/src/win32_gl_surface.c @@ -7,13 +7,14 @@ * *****************************************************************/ -#include -#include"GL/glext.h" -#include"GL/wglext.h" +#define WIN32_GL_LOADER_IMPL +#include"win32_gl_loader.h" -#include"graphics.h" +#include"graphics_internal.h" #include"win32_app.h" +#define MG_IMPLEMENTS_BACKEND_GL + typedef struct mg_gl_surface { mg_surface_info interface;