From d0e4edfb43a1f5bebf705c4efc2c6883360ca66e Mon Sep 17 00:00:00 2001 From: hikari Date: Mon, 5 Dec 2022 23:58:31 +0200 Subject: [PATCH 1/5] sys/windows: added helper gl proc --- core/sys/windows/wgl.odin | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/sys/windows/wgl.odin b/core/sys/windows/wgl.odin index 150358d01..e91463a3c 100644 --- a/core/sys/windows/wgl.odin +++ b/core/sys/windows/wgl.odin @@ -85,3 +85,8 @@ foreign Opengl32 { wglUseFontBitmaps :: proc(hdc: HDC, first, count, list_base: DWORD) -> BOOL --- wglUseFontOutlines :: proc(hdc: HDC, first, count, list_base: DWORD, deviation, extrusion: f32, format: c.int, gmf: LPGLYPHMETRICSFLOAT) -> BOOL --- } + +// Used by vendor:OpenGL +gl_set_proc_address :: proc(p: rawptr, name: cstring) { + (^rawptr)(p)^ = wglGetProcAddress(name) +} From ce1ee962f5a7e00a6ff9ebf4adccc09f2dff68c3 Mon Sep 17 00:00:00 2001 From: hikari Date: Tue, 6 Dec 2022 00:00:05 +0200 Subject: [PATCH 2/5] OpenGL: updated README --- vendor/OpenGL/README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/vendor/OpenGL/README.md b/vendor/OpenGL/README.md index 928d5eb5d..3f5f05c81 100644 --- a/vendor/OpenGL/README.md +++ b/vendor/OpenGL/README.md @@ -7,17 +7,11 @@ Includes procedures to load OpenGL function pointers. Currently only supports th ```go gl.load_up_to(4, 5, proc(p: rawptr, name: cstring) do (cast(^rawptr)p)^ = glfw.GetProcAddress(name); ); ``` -[odin-glfw](https://github.com/vassvik/odin-glfw) also provides a useful helper you can pass straight to `gl.load_up_to`: +`vendor:glfw` also provides a useful helper you can pass straight to `gl.load_up_to`: ```go gl.load_up_to(4, 5, glfw.gl_set_proc_address); ``` -#### NOTE: It is recommended to put this into the shared collection: -``` -cd /path/to/Odin/shared -git clone https://github.com/vassvik/odin-gl.git -``` - ## Extra utility procedures (Outdated. See the end of `gl.odin`) Some useful helper procedures can be found in `helpers.odin`, for tasks such as: @@ -56,4 +50,4 @@ glGetError() returned NO_ERROR glGetError() returned NO_ERROR call: glClearColor(0.800, 0.800, 0.800, 1.000) in: C://main.odin(272:6) -``` \ No newline at end of file +``` From f9f4551e8d2d1e86dcf902c5c4f630cbb638ea83 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 5 Dec 2022 22:31:35 +0000 Subject: [PATCH 3/5] Add `user_data: rawptr` to `filepath.Walk_Proc` callback --- core/path/filepath/walk.odin | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/path/filepath/walk.odin b/core/path/filepath/walk.odin index dad63cc09..9ba3165dc 100644 --- a/core/path/filepath/walk.odin +++ b/core/path/filepath/walk.odin @@ -14,7 +14,7 @@ import "core:slice" // The sole exception is if 'skip_dir' is returned as true: // when 'skip_dir' is invoked on a directory. 'walk' skips directory contents // when 'skip_dir' is invoked on a non-directory. 'walk' skips the remaining files in the containing directory -Walk_Proc :: #type proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip_dir: bool) +Walk_Proc :: #type proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Errno, skip_dir: bool) // walk walks the file tree rooted at 'root', calling 'walk_proc' for each file or directory in the tree, including 'root' // All errors that happen visiting files and directories are filtered by walk_proc @@ -22,28 +22,28 @@ Walk_Proc :: #type proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, // NOTE: Walking large directories can be inefficient due to the lexical sort // NOTE: walk does not follow symbolic links // NOTE: os.File_Info uses the 'context.temp_allocator' to allocate, and will delete when it is done -walk :: proc(root: string, walk_proc: Walk_Proc) -> os.Errno { +walk :: proc(root: string, walk_proc: Walk_Proc, user_data: rawptr) -> os.Errno { info, err := os.lstat(root, context.temp_allocator) defer os.file_info_delete(info, context.temp_allocator) skip_dir: bool if err != 0 { - err, skip_dir = walk_proc(info, err) + err, skip_dir = walk_proc(info, err, user_data) } else { - err, skip_dir = _walk(info, walk_proc) + err, skip_dir = _walk(info, walk_proc, user_data) } return 0 if skip_dir else err } @(private) -_walk :: proc(info: os.File_Info, walk_proc: Walk_Proc) -> (err: os.Errno, skip_dir: bool) { +_walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (err: os.Errno, skip_dir: bool) { if !info.is_dir { if info.fullpath == "" && info.name == "" { // ignore empty things return } - return walk_proc(info, 0) + return walk_proc(info, 0, user_data) } fis: []os.File_Info @@ -51,14 +51,14 @@ _walk :: proc(info: os.File_Info, walk_proc: Walk_Proc) -> (err: os.Errno, skip_ fis, err = read_dir(info.fullpath, context.temp_allocator) defer os.file_info_slice_delete(fis, context.temp_allocator) - err1, skip_dir = walk_proc(info, err) + err1, skip_dir = walk_proc(info, err, user_data) if err != 0 || err1 != 0 || skip_dir { err = err1 return } for fi in fis { - err, skip_dir = _walk(fi, walk_proc) + err, skip_dir = _walk(fi, walk_proc, user_data) if err != 0 || skip_dir { if !fi.is_dir || !skip_dir { return From abaacfe78d4bf78eef9960add82dd4893398f3ff Mon Sep 17 00:00:00 2001 From: hikari Date: Tue, 6 Dec 2022 01:53:19 +0200 Subject: [PATCH 4/5] sys/windows: fix wgl function loading in accordance with OpenGL wiki --- core/sys/windows/wgl.odin | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/sys/windows/wgl.odin b/core/sys/windows/wgl.odin index e91463a3c..56f61ed32 100644 --- a/core/sys/windows/wgl.odin +++ b/core/sys/windows/wgl.odin @@ -87,6 +87,12 @@ foreign Opengl32 { } // Used by vendor:OpenGL +// https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions#Windows gl_set_proc_address :: proc(p: rawptr, name: cstring) { - (^rawptr)(p)^ = wglGetProcAddress(name) + func := wglGetProcAddress(name) + if uintptr(func) == 0 || uintptr(func) == 1 || uintptr(func) == 2 || uintptr(func) == 3 || uintptr(func) == ~uintptr(0) { + module := LoadLibraryW(L("opengl32.dll")) + func = GetProcAddress(module, name) + } + (^rawptr)(p)^ = func } From 89eb351d2b86a6c3473c06e5e4987e224699511f Mon Sep 17 00:00:00 2001 From: hikari Date: Tue, 6 Dec 2022 02:01:35 +0200 Subject: [PATCH 5/5] sys/windows: wgl style fix --- core/sys/windows/wgl.odin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/sys/windows/wgl.odin b/core/sys/windows/wgl.odin index 56f61ed32..77cff2fa9 100644 --- a/core/sys/windows/wgl.odin +++ b/core/sys/windows/wgl.odin @@ -90,7 +90,8 @@ foreign Opengl32 { // https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions#Windows gl_set_proc_address :: proc(p: rawptr, name: cstring) { func := wglGetProcAddress(name) - if uintptr(func) == 0 || uintptr(func) == 1 || uintptr(func) == 2 || uintptr(func) == 3 || uintptr(func) == ~uintptr(0) { + switch uintptr(func) { + case 0, 1, 2, 3, ~uintptr(0): module := LoadLibraryW(L("opengl32.dll")) func = GetProcAddress(module, name) }