Java Code Examples for org.lwjgl.system.MemoryStack#setPointer()

The following examples show how to use org.lwjgl.system.MemoryStack#setPointer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformWin32GLCanvas.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
public long create(GLCanvas canvas, GLData attribs, GLData effective) {
    Canvas dummycanvas = new Canvas(canvas.getParent(), checkStyle(canvas.getParent(), canvas.getStyle()));
    long context = 0L;
    MemoryStack stack = MemoryStack.stackGet(); int ptr = stack.getPointer();
    try {
        context = create(canvas.handle, dummycanvas.handle, attribs, effective);
    } catch (SWTException e) {
        stack.setPointer(ptr);
        SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH, e);
    }
    final long finalContext = context;
    dummycanvas.dispose();
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
                deleteContext(canvas, finalContext);
                break;
            }
        }
    };
    canvas.addListener(SWT.Dispose, listener);
    return context;
}
 
Example 2
Source File: PlatformX11VKCanvas.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
@Override
public long create(Canvas canvas, VKData data) throws AWTException {
    MemoryStack stack = MemoryStack.stackGet();
    int ptr = stack.getPointer();
    JAWTDrawingSurface ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface());
    try {
        int lock = JAWT_DrawingSurface_Lock(ds, ds.Lock());
        if ((lock & JAWT_LOCK_ERROR) != 0)
            throw new AWTException("JAWT_DrawingSurface_Lock() failed");
        try {
            JAWTDrawingSurfaceInfo dsi = JAWT_DrawingSurface_GetDrawingSurfaceInfo(ds, ds.GetDrawingSurfaceInfo());
            try {
                JAWTX11DrawingSurfaceInfo dsiX11 = JAWTX11DrawingSurfaceInfo.create(dsi.platformInfo());
                long display = dsiX11.display();
                long window = dsiX11.drawable();

                VkXlibSurfaceCreateInfoKHR sci = VkXlibSurfaceCreateInfoKHR.callocStack(stack)
                        .sType(VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR)
                        .dpy(display)
                        .window(window);

                long surfaceAddr = stack.nmalloc(8, 8);
                int err = nvkCreateXlibSurfaceKHR(data.instance, sci.address(), 0L, surfaceAddr);
                long surface = MemoryUtil.memGetLong(surfaceAddr);
                stack.setPointer(ptr);
                if (err != VK_SUCCESS) {
                    throw new AWTException("Calling vkCreateXlibSurfaceKHR failed with error: " + err);
                }

                return surface;
            } finally {
                JAWT_DrawingSurface_FreeDrawingSurfaceInfo(dsi, ds.FreeDrawingSurfaceInfo());
            }
        } finally {
            JAWT_DrawingSurface_Unlock(ds, ds.Unlock());
        }
    } finally {
        JAWT_FreeDrawingSurface(ds, awt.FreeDrawingSurface());
    }
}
 
Example 3
Source File: PlatformWin32VKCanvas.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
public long create(Canvas canvas, VKData data) throws AWTException {
    MemoryStack stack = MemoryStack.stackGet();
    int ptr = stack.getPointer();
    JAWTDrawingSurface ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface());
    try {
        int lock = JAWT_DrawingSurface_Lock(ds, ds.Lock());
        if ((lock & JAWT_LOCK_ERROR) != 0)
            throw new AWTException("JAWT_DrawingSurface_Lock() failed");
        try {
            JAWTDrawingSurfaceInfo dsi = JAWT_DrawingSurface_GetDrawingSurfaceInfo(ds, ds.GetDrawingSurfaceInfo());
            try {
                JAWTWin32DrawingSurfaceInfo dsiWin = JAWTWin32DrawingSurfaceInfo.create(dsi.platformInfo());
                long hwnd = dsiWin.hwnd();
                VkWin32SurfaceCreateInfoKHR sci = VkWin32SurfaceCreateInfoKHR.callocStack(stack)
                        .sType(VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR)
                        .hinstance(WinBase.GetModuleHandle((ByteBuffer) null))
                        .hwnd(hwnd);
                long surfaceAddr = stack.nmalloc(8, 8);
                int err = nvkCreateWin32SurfaceKHR(data.instance, sci.address(), 0L, surfaceAddr);
                long surface = MemoryUtil.memGetLong(surfaceAddr);
                stack.setPointer(ptr);
                if (err != VK_SUCCESS) {
                    throw new AWTException("Calling vkCreateWin32SurfaceKHR failed with error: " + err);
                }
                return surface;
            } finally {
                JAWT_DrawingSurface_FreeDrawingSurfaceInfo(dsi, ds.FreeDrawingSurfaceInfo());
            }
        } finally {
            JAWT_DrawingSurface_Unlock(ds, ds.Unlock());
        }
    } finally {
        JAWT_FreeDrawingSurface(ds, awt.FreeDrawingSurface());
    }
}
 
Example 4
Source File: PlatformLinuxGLCanvas.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
private static int getInteger(int pname, long function) {
	MemoryStack stack = MemoryStack.stackGet();
	int stackPointer = stack.getPointer();
	try {
		IntBuffer params = stack.callocInt(1);
		JNI.callPV(pname, memAddress(params), function);
		return params.get(0);
	} finally {
		stack.setPointer(stackPointer);
	}
}