win32 opengl loader nonsense

This commit is contained in:
martinfouilleul 2022-12-22 18:24:43 +01:00
parent a696c2ba2b
commit 30bd704af2
9 changed files with 155 additions and 36 deletions

View File

@ -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

View File

@ -1,3 +1,2 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib user32.lib opengl32.lib gdi32.lib /out:test.exe
cl main.c %INCLUDES% /Zi /Zc:preprocessor /std:c11 /link user32.lib opengl32.lib gdi32.lib /out:test.exe

View File

@ -9,20 +9,10 @@
#include<stdlib.h> #include<stdlib.h>
#include<string.h> #include<string.h>
#include"platform.h" #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include"win32_app.c" #include<math.h>
#include"debug_log.c"
#include"memory.c"
#include"strings.c"
#include"milepost.h"
#include"ringbuffer.c"
#include"win32_base_allocator.c"
#include"utf8.c"
#define MG_IMPLEMENTS_BACKEND_GL
#include"graphics.c"
#include"win32_gl_surface.c"
#define LOG_SUBSYSTEM "Main" #define LOG_SUBSYSTEM "Main"

View File

@ -7,23 +7,60 @@
* *
*****************************************************************/ *****************************************************************/
//---------------------------------------------------------------
// utilities implementations
//---------------------------------------------------------------
#include"util/debug_log.c" #include"util/debug_log.c"
#include"memory.c" #include"util/memory.c"
#include"strings.c" #include"util/strings.c"
#include"ringbuffer.c"
#include"util/utf8.c" #include"util/utf8.c"
#include"util/hash.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"graphics.c"
#include"ui.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"
*/

View File

@ -9,7 +9,10 @@
#ifndef __MILEPOST_H_ #ifndef __MILEPOST_H_
#define __MILEPOST_H_ #define __MILEPOST_H_
//----------------------------------------------------------------
// utility layer
//----------------------------------------------------------------
#include"platform.h"
#include"typedefs.h" #include"typedefs.h"
#include"macro_helpers.h" #include"macro_helpers.h"
#include"debug_log.h" #include"debug_log.h"
@ -17,16 +20,32 @@
#include"memory.h" #include"memory.h"
#include"strings.h" #include"strings.h"
#include"utf8.h" #include"utf8.h"
#include"hash.h"
//----------------------------------------------------------------
// platform layer
//----------------------------------------------------------------
#include"platform_clock.h" #include"platform_clock.h"
/* /*
#include"platform_rng.h" #include"platform_rng.h"
#include"platform_socket.h" #include"platform_socket.h"
#include"platform_thread.h" #include"platform_thread.h"
*/ */
//----------------------------------------------------------------
// application layer
//----------------------------------------------------------------
#include"mp_app.h" #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"graphics.h"
#include"ui.h" #include"ui.h"
#include"hash.h"
#endif //__MILEPOST_H_ #endif //__MILEPOST_H_

View File

@ -6,6 +6,7 @@
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/
#define WIN32_LEAN_AND_MEAN
#include<windows.h> #include<windows.h>
#include"platform_base_allocator.h" #include"platform_base_allocator.h"

View File

@ -9,11 +9,12 @@
#ifndef __MACRO_HELPERS_H_ #ifndef __MACRO_HELPERS_H_
#define __MACRO_HELPERS_H_ #define __MACRO_HELPERS_H_
#include"typedefs.h"
//NOTE(martin): macro concatenation //NOTE(martin): macro concatenation
#define _cat2_(a, b) a##b #define _cat2_(a, b) a##b
#define _cat3_(a, b, c) a##b##c #define _cat3_(a, b, c) a##b##c
//NOTE(martin): inline, but still generate code //NOTE(martin): inline, but still generate code
// (eg. use the inline version inside a library, but still exports the function for client 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 //TODO(martin): this is a compiler-specific attribute, recognized by clang and gcc. See if there's a more portable approach

65
src/win32_gl_loader.h Normal file
View File

@ -0,0 +1,65 @@
/************************************************************//**
*
* @file: win32_gl_loader.h
* @author: Martin Fouilleul
* @date: 01/08/2022
* @revision:
*
*****************************************************************/
#define WIN32_LEAN_AND_MEAN
#include<windows.h>
#include<GL/gl.h>
#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

View File

@ -7,13 +7,14 @@
* *
*****************************************************************/ *****************************************************************/
#include<GL/gl.h> #define WIN32_GL_LOADER_IMPL
#include"GL/glext.h" #include"win32_gl_loader.h"
#include"GL/wglext.h"
#include"graphics.h" #include"graphics_internal.h"
#include"win32_app.h" #include"win32_app.h"
#define MG_IMPLEMENTS_BACKEND_GL
typedef struct mg_gl_surface typedef struct mg_gl_surface
{ {
mg_surface_info interface; mg_surface_info interface;