Skip to content

Commit

Permalink
Simple sharedDrawable implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Mar 2, 2024
1 parent 9ced28b commit 0914eca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/lwjglx/opengl/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ public class Display {
* <p>
* The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
*
* @param pixel_format Describes the minimum specifications the context must fulfill.
* @param shared_drawable The Drawable to share context with. (optional, may be null)
* @param pixelFormat Describes the minimum specifications the context must fulfill.
* @param sharedDrawable The Drawable to share context with. (optional, may be null)
*
* @throws org.lwjglx.LWJGLException
*/
public static void create(PixelFormat pixel_format, Drawable shared_drawable) {
create(pixel_format, (ContextAttribs) null);
public static void create(PixelFormat pixelFormat, Drawable sharedDrawable) {
create(pixelFormat, (ContextAttribs) null, sharedDrawable.getGlfwWindowId());
}

public static void create() {
Expand All @@ -128,6 +128,10 @@ public static void create(PixelFormat pixelFormat) {
}

public static void create(PixelFormat pixelFormat, ContextAttribs attribs) {
create(pixelFormat, attribs, NULL);
}

public static void create(PixelFormat pixelFormat, ContextAttribs attribs, long sharedWindow) {
if (displayCreated) {
return;
}
Expand Down Expand Up @@ -184,7 +188,7 @@ public static void create(PixelFormat pixelFormat, ContextAttribs attribs) {
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); // request a non-hidpi framebuffer on Retina displays
// on MacOS

Window.handle = glfwCreateWindow(mode.getWidth(), mode.getHeight(), windowTitle, NULL, NULL);
Window.handle = glfwCreateWindow(mode.getWidth(), mode.getHeight(), windowTitle, NULL, sharedWindow);
if (Window.handle == 0L) {
throw new IllegalStateException("Failed to create Display window");
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/lwjglx/opengl/Drawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public interface Drawable {
* @param properties The target properties buffer. It must have at least 4 positions remaining.
*/
void setCLSharingProperties(PointerBuffer properties) throws LWJGLException;

default long getGlfwWindowId() {
return 0;
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/lwjglx/opengl/DrawableGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,11 @@ public void setCLSharingProperties(final PointerBuffer properties) throws LWJGLE
protected final void checkDestroyed() {
if (context == null) throw new IllegalStateException("The Drawable has no context available.");
}

@Override
public long getGlfwWindowId() {
synchronized (GlobalLock.lock) {
return context.glfwWindow;
}
}
}

0 comments on commit 0914eca

Please sign in to comment.