Skip to content

Commit 1f564f7

Browse files
committed
feat: load Vulkan with LWJGL 3
1 parent 5e81eef commit 1f564f7

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

generators/vulkan/src/main/kotlin/overrungl/vulkan/VulkanGenerator2.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ fun genModuleInfo() {
11141114
requires transitive overrungl.core;
11151115
requires static org.graalvm.nativeimage;
11161116
requires static org.jspecify;
1117+
requires org.lwjgl.vulkan;
11171118
}
11181119
""".trimIndent()
11191120
)

modules/overrungl.vulkan/src/main/generated/module-info.java

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/overrungl.vulkan/src/main/java/overrungl/vulkan/VK.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212
*
1313
* The above copyright notice and this permission notice shall be included in all
1414
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
1523
*/
1624

1725
package overrungl.vulkan;
1826

27+
import org.lwjgl.system.Configuration;
1928
import overrungl.util.MemoryStack;
2029
import overrungl.util.MemoryUtil;
2130

@@ -36,15 +45,24 @@ public final class VK {
3645
private VK() {
3746
}
3847

39-
/// Loads necessary functions for Vulkan to create [VkInstance] with the given loading function.
48+
/// Loads Vulkan with LWJGL 3.
4049
///
41-
/// @param func a function that returns an address of a Vulkan function specified with the given name. this can be `GLFW::glfwGetInstanceProcAddress`
50+
/// @param func unused
4251
public static void create(VKLoadFunc func) {
43-
if (loadFunc != null) {
44-
throw new IllegalStateException("Vulkan has already been created.");
52+
create();
53+
}
54+
55+
/// Loads Vulkan with LWJGL 3.
56+
///
57+
/// @since 0.3.0
58+
public static void create() {
59+
if (Configuration.VULKAN_EXPLICIT_INIT.get(false)) {
60+
org.lwjgl.vulkan.VK.create();
4561
}
46-
loadFunc = func;
47-
globalCommands = new GlobalCommands(func);
62+
loadFunc = (_, name) ->
63+
MemorySegment.ofAddress(org.lwjgl.vulkan.VK.getFunctionProvider()
64+
.getFunctionAddress(Objects.requireNonNull(MemoryUtil.nativeString(name))));
65+
globalCommands = new GlobalCommands(loadFunc);
4866
}
4967

5068
/// Removes loaded functions.

0 commit comments

Comments
 (0)