RavEngine
Loading...
Searching...
No Matches
Loader.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2014-2022 NVIDIA Corporation. All rights reserved.
26
27#pragma once
28
29#define GLFW_DLL
30
31#if defined(_WIN32)
32#define GLFW_EXPOSE_NATIVE_WIN32
33#else
34#define GLFW_EXPOSE_NATIVE_X11
35#endif
36#include <GLFW/glfw3.h>
37#include <GLFW/glfw3native.h>
38
39#define NV_FLOW_SWAPCHAIN_DESC 1
40
41#include "NvFlowLoader.h"
42
43#define GLFW_PTR(X) decltype(&X) p_##X = nullptr
44
45#define GLFW_PTR_LOAD(X) ptr->p_##X = (decltype(&X))GlfwLoader_loadFunction(ptr, #X)
46
48{
49 void* module = nullptr;
50
51 GLFW_PTR(glfwInit);
52 GLFW_PTR(glfwWindowHint);
53 GLFW_PTR(glfwCreateWindow);
54 GLFW_PTR(glfwGetPrimaryMonitor);
55 GLFW_PTR(glfwGetVideoMode);
56 GLFW_PTR(glfwSetWindowUserPointer);
57 GLFW_PTR(glfwSetWindowPos);
58 GLFW_PTR(glfwSetWindowSizeCallback);
59 GLFW_PTR(glfwSetKeyCallback);
60 GLFW_PTR(glfwSetCharCallback);
61 GLFW_PTR(glfwSetMouseButtonCallback);
62 GLFW_PTR(glfwSetCursorPosCallback);
63 GLFW_PTR(glfwSetScrollCallback);
64#if defined(_WIN32)
65 GLFW_PTR(glfwGetWin32Window);
66#else
67 GLFW_PTR(glfwGetX11Display);
68 GLFW_PTR(glfwGetX11Window);
69#endif
70 GLFW_PTR(glfwDestroyWindow);
71 GLFW_PTR(glfwTerminate);
72 GLFW_PTR(glfwPollEvents);
73 GLFW_PTR(glfwWindowShouldClose);
74 GLFW_PTR(glfwGetWindowUserPointer);
75 GLFW_PTR(glfwSetWindowMonitor);
76 GLFW_PTR(glfwGetMouseButton);
77};
78
79inline void* GlfwLoader_loadFunction(GlfwLoader* ptr, const char* name)
80{
81 return NvFlowGetProcAddress(ptr->module, name);
82}
83
84inline void GlfwLoader_init(GlfwLoader* ptr)
85{
86#if defined(__aarch64__)
87 ptr->module = NvFlowLoadLibrary("glfw3.dll", "libglfw_aarch64.so.3.3");
88#else
89 ptr->module = NvFlowLoadLibrary("glfw3.dll", "libglfw.so.3");
90#endif
91
92 GLFW_PTR_LOAD(glfwInit);
93 GLFW_PTR_LOAD(glfwWindowHint);
94 GLFW_PTR_LOAD(glfwCreateWindow);
95 GLFW_PTR_LOAD(glfwGetPrimaryMonitor);
96 GLFW_PTR_LOAD(glfwGetVideoMode);
97 GLFW_PTR_LOAD(glfwSetWindowUserPointer);
98 GLFW_PTR_LOAD(glfwSetWindowPos);
99 GLFW_PTR_LOAD(glfwSetWindowSizeCallback);
100 GLFW_PTR_LOAD(glfwSetKeyCallback);
101 GLFW_PTR_LOAD(glfwSetCharCallback);
102 GLFW_PTR_LOAD(glfwSetMouseButtonCallback);
103 GLFW_PTR_LOAD(glfwSetCursorPosCallback);
104 GLFW_PTR_LOAD(glfwSetScrollCallback);
105#if defined(_WIN32)
106 GLFW_PTR_LOAD(glfwGetWin32Window);
107#else
108 GLFW_PTR_LOAD(glfwGetX11Display);
109 GLFW_PTR_LOAD(glfwGetX11Window);
110#endif
111 GLFW_PTR_LOAD(glfwDestroyWindow);
112 GLFW_PTR_LOAD(glfwTerminate);
113 GLFW_PTR_LOAD(glfwPollEvents);
114 GLFW_PTR_LOAD(glfwWindowShouldClose);
115 GLFW_PTR_LOAD(glfwGetWindowUserPointer);
116 GLFW_PTR_LOAD(glfwSetWindowMonitor);
117 GLFW_PTR_LOAD(glfwGetMouseButton);
118}
119
120inline void GlfwLoader_destroy(GlfwLoader* ptr)
121{
122 NvFlowFreeLibrary(ptr->module);
123}
Definition Loader.h:48