org.lwjgl.opengl.WGL Java Examples

The following examples show how to use org.lwjgl.opengl.WGL. 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-awt with MIT License 5 votes vote down vote up
private void wglNvSwapGroupAndBarrier(GLData attribs, long bufferAddr, long hDC) throws AWTException {
    int success;
    long wglQueryMaxSwapGroupsNVAddr = WGL.wglGetProcAddress("wglQueryMaxSwapGroupsNV");
    success = JNI.callPPPI(hDC, bufferAddr, bufferAddr + 4, wglQueryMaxSwapGroupsNVAddr);
    int maxGroups = MemoryUtil.memGetInt(bufferAddr);
    if (maxGroups < attribs.swapGroupNV) {
        throw new AWTException("Swap group exceeds maximum group index");
    }
    int maxBarriers = MemoryUtil.memGetInt(bufferAddr + 4);
    if (maxBarriers < attribs.swapBarrierNV) {
        throw new AWTException("Swap barrier exceeds maximum barrier index");
    }
    if (attribs.swapGroupNV > 0) {
        long wglJoinSwapGroupNVAddr = WGL.wglGetProcAddress("wglJoinSwapGroupNV");
        if (wglJoinSwapGroupNVAddr == 0L) {
            throw new AWTException("WGL_NV_swap_group available but wglJoinSwapGroupNV is NULL");
        }
        success = JNI.callPI(hDC, attribs.swapGroupNV, wglJoinSwapGroupNVAddr);
        if (success == 0) {
            throw new AWTException("Failed to join swap group");
        }
        if (attribs.swapBarrierNV > 0) {
            long wglBindSwapBarrierNVAddr = WGL.wglGetProcAddress("wglBindSwapBarrierNV");
            if (wglBindSwapBarrierNVAddr == 0L) {
                throw new AWTException("WGL_NV_swap_group available but wglBindSwapBarrierNV is NULL");
            }
            success = JNI.callI(attribs.swapGroupNV, attribs.swapBarrierNV, wglBindSwapBarrierNVAddr);
            if (success == 0) {
                throw new AWTException("Failed to bind swap barrier. Probably no G-Sync card installed.");
            }
        }
    }
}
 
Example #2
Source File: PlatformWin32GLCanvas.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
public boolean makeCurrent(long context) {
    if (context == 0L)
        return WGL.wglMakeCurrent(0L, 0L);
    long hdc = User32.GetDC(hwnd);
    if (hdc == 0L)
    	return false;
    boolean ret = WGL.wglMakeCurrent(hdc, context);
    User32.ReleaseDC(hwnd, hdc);
    return ret;
}
 
Example #3
Source File: PlatformWin32GLCanvas.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
public boolean delayBeforeSwapNV(float seconds) {
    if (!wglDelayBeforeSwapNVAddr_set) {
        wglDelayBeforeSwapNVAddr = WGL.wglGetProcAddress("wglDelayBeforeSwapNV");
        wglDelayBeforeSwapNVAddr_set = true;
    }
    if (wglDelayBeforeSwapNVAddr == 0L) {
        throw new UnsupportedOperationException("wglDelayBeforeSwapNV is unavailable");
    }
    long hDC = User32.GetDC(hwnd);
    int ret = JNI.callPI(hDC, seconds, wglDelayBeforeSwapNVAddr);
    User32.ReleaseDC(hwnd, hDC);
    return ret == 1;
}
 
Example #4
Source File: PlatformWin32GLCanvas.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
private void wglNvSwapGroupAndBarrier(GLData attribs, long bufferAddr, long hDC) throws SWTException {
    int success;
    long wglQueryMaxSwapGroupsNVAddr = WGL.wglGetProcAddress("wglQueryMaxSwapGroupsNV");
    success = JNI.callPPPI(hDC, bufferAddr, bufferAddr + 4, wglQueryMaxSwapGroupsNVAddr);
    int maxGroups = MemoryUtil.memGetInt(bufferAddr);
    if (maxGroups < attribs.swapGroupNV) {
        throw new SWTException("Swap group exceeds maximum group index");
    }
    int maxBarriers = MemoryUtil.memGetInt(bufferAddr + 4);
    if (maxBarriers < attribs.swapBarrierNV) {
        throw new SWTException("Swap barrier exceeds maximum barrier index");
    }
    if (attribs.swapGroupNV > 0) {
        long wglJoinSwapGroupNVAddr = WGL.wglGetProcAddress("wglJoinSwapGroupNV");
        if (wglJoinSwapGroupNVAddr == 0L) {
            throw new SWTException("WGL_NV_swap_group available but wglJoinSwapGroupNV is NULL");
        }
        success = JNI.callPI(hDC, attribs.swapGroupNV, wglJoinSwapGroupNVAddr);
        if (success == 0) {
            throw new SWTException("Failed to join swap group");
        }
        if (attribs.swapBarrierNV > 0) {
            long wglBindSwapBarrierNVAddr = WGL.wglGetProcAddress("wglBindSwapBarrierNV");
            if (wglBindSwapBarrierNVAddr == 0L) {
                throw new SWTException("WGL_NV_swap_group available but wglBindSwapBarrierNV is NULL");
            }
            success = JNI.callI(attribs.swapGroupNV, attribs.swapBarrierNV, wglBindSwapBarrierNVAddr);
            if (success == 0) {
                throw new SWTException("Failed to bind swap barrier. Probably no G-Sync card installed.");
            }
        }
    }
}
 
Example #5
Source File: PlatformWin32GLCanvas.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
public boolean delayBeforeSwapNV(GLCanvas canvas, float seconds) {
    if (!wglDelayBeforeSwapNVAddr_set) {
        wglDelayBeforeSwapNVAddr = WGL.wglGetProcAddress("wglDelayBeforeSwapNV");
        wglDelayBeforeSwapNVAddr_set = true;
    }
    if (wglDelayBeforeSwapNVAddr == 0L) {
        throw new UnsupportedOperationException("wglDelayBeforeSwapNV is unavailable");
    }
    long hDC = User32.GetDC(canvas.handle);
    int ret = JNI.callPI(hDC, seconds, wglDelayBeforeSwapNVAddr);
    User32.ReleaseDC(canvas.handle, hDC);
    return ret == 1;
}
 
Example #6
Source File: WGLContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void makeCurrent(boolean draw) {
	if(draw) {
		WGL.wglMakeCurrent(windowDrawable, context);
	} else {
		WGL.wglMakeCurrent(0, 0);
	}
}
 
Example #7
Source File: WGLContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
protected void onNewConnection() {
	PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.calloc();
	pfd.dwFlags(GDI32.PFD_DRAW_TO_WINDOW | GDI32.PFD_SUPPORT_OPENGL | GDI32.PFD_DOUBLEBUFFER);
	pfd.iPixelType(GDI32.PFD_TYPE_RGBA);
	pfd.cColorBits((byte) 32);
	pfd.cStencilBits((byte) 1);

	pfd.cDepthBits((byte) 24);

	int pixel_format = GDI32.ChoosePixelFormat(windowDrawable, pfd);
	if(pixel_format == 0) throw new Error("Could not find pixel format!");
	GDI32.SetPixelFormat(windowDrawable, pixel_format, pfd);

	pfd.free();


	context = WGL.wglCreateContext(windowDrawable);
	WGL.wglMakeCurrent(windowDrawable, context);
	WGLCapabilities caps = GL.createCapabilitiesWGL();
	if(caps.WGL_ARB_create_context && caps.WGL_ARB_create_context_profile) {
		WGL.wglDeleteContext(context);
		context = 0;

		int i = debug ? 0 : 3;
		while(context == 0 && ctx_attrs.length > i) {
			context = WGLARBCreateContext.wglCreateContextAttribsARB(windowDrawable, 0, ctx_attrs[i]);
		}
	} else {
		if(debug) {
			WGL.wglDeleteContext(context);
			throw new Error("WGL could not create a debug context!");
		}
	}

	if(context == 0) throw new Error("Could not create WGL context!");
	parent.wrapNewContext();
}
 
Example #8
Source File: PlatformWin32GLCanvas.java    From lwjgl3-awt with MIT License 4 votes vote down vote up
public boolean isCurrent(long context) {
    long ret = WGL.wglGetCurrentContext();
    return ret == context;
}
 
Example #9
Source File: PlatformWin32GLCanvas.java    From lwjgl3-awt with MIT License 4 votes vote down vote up
public boolean deleteContext(long context) {
    boolean ret = WGL.wglDeleteContext(context);
    return ret;
}
 
Example #10
Source File: PlatformWin32GLCanvas.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
public boolean isCurrent(long context) {
    long ret = WGL.wglGetCurrentContext();
    return ret == context;
}
 
Example #11
Source File: PlatformWin32GLCanvas.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
public boolean makeCurrent(GLCanvas canvas, long context) {
    long hDC = User32.GetDC(canvas.handle);
    boolean ret = WGL.wglMakeCurrent(hDC, context);
    User32.ReleaseDC(canvas.handle, hDC);
    return ret;
}
 
Example #12
Source File: PlatformWin32GLCanvas.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
public boolean deleteContext(GLCanvas canvas, long context) {
    boolean ret = WGL.wglDeleteContext(context);
    return ret;
}
 
Example #13
Source File: WGLContextCreator.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void stop() {
	WGL.wglDeleteContext(context);
}