1 /*
2  * Copyright (c) 2002-2011 LWJGL Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of 'LWJGL' nor the names of
17  *   its contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 package org.lwjgl.opengl;
34 
35 import org.lwjgl.BufferChecks;
36 import org.lwjgl.LWJGLUtil;
37 
38 import java.nio.ByteBuffer;
39 import java.nio.IntBuffer;
40 import java.nio.LongBuffer;
41 
42 /**
43  * This class exposes the platform specific functionality present in the
44  * NV_present_video extension.
45  *
46  * @author Spasi
47  * @since 20/5/2011
48  */
49 public final class NVPresentVideoUtil {
50 
NVPresentVideoUtil()51 	private NVPresentVideoUtil() {}
52 
checkExtension()53 	private static void checkExtension() {
54 		if ( LWJGLUtil.CHECKS && !GLContext.getCapabilities().GL_NV_present_video )
55 			throw new IllegalStateException("NV_present_video is not supported");
56 	}
57 
getPeerInfo()58 	private static ByteBuffer getPeerInfo() {
59 		return ContextGL.getCurrentContext().getPeerInfo().getHandle();
60 	}
61 
62 	/**
63 	 * Enumerate the available video output devices. This method is the cross-platform
64 	 * equivalent of glXEnumerateVideoDevicesNV and wglEnumerateVideoDevicesNV. Since they are
65 	 * not really compatible, this method works like the WGL version. That is, you first
66 	 * call it with a null devices buffer, get the number of devices, then call it again
67 	 * with an appropriately sized buffer.
68 	 *
69 	 * @param devices the buffer to store devices in
70 	 *
71 	 * @return the number of available video output devices
72 	 */
glEnumerateVideoDevicesNV(LongBuffer devices)73 	public static int glEnumerateVideoDevicesNV(LongBuffer devices) {
74 		checkExtension();
75 
76 		if ( devices != null )
77 			BufferChecks.checkBuffer(devices, 1);
78 		return nglEnumerateVideoDevicesNV(getPeerInfo(), devices, devices == null ? 0 : devices.position());
79 	}
80 
nglEnumerateVideoDevicesNV(ByteBuffer peer_info, LongBuffer devices, int devices_position)81 	private static native int nglEnumerateVideoDevicesNV(ByteBuffer peer_info, LongBuffer devices, int devices_position);
82 
83 	/**
84 	 * Binds the video output device specified to one of the context's available video output slots.
85 	 * This method is the cross-platform equivalent of glXBindVideoDeviceNV and wglBindVideoDeviceNV.
86 	 * To release a video device without binding another device to the same slot, call it with
87 	 * video_device set to 0 (will use INVALID_HANDLE_VALUE on WGL).
88 	 *
89 	 * @param video_slot   the video slot
90 	 * @param video_device the video device
91 	 * @param attrib_list  the attributes to use
92 	 *
93 	 * @return true if the binding was successful
94 	 */
glBindVideoDeviceNV(int video_slot, long video_device, IntBuffer attrib_list)95 	public static boolean glBindVideoDeviceNV(int video_slot, long video_device, IntBuffer attrib_list) {
96 		checkExtension();
97 
98 		if ( attrib_list != null )
99 			BufferChecks.checkNullTerminated(attrib_list);
100 		return nglBindVideoDeviceNV(getPeerInfo(), video_slot, video_device, attrib_list, attrib_list == null ? 0 : attrib_list.position());
101 	}
102 
nglBindVideoDeviceNV(ByteBuffer peer_info, int video_slot, long video_device, IntBuffer attrib_list, int attrib_list_position)103 	private static native boolean nglBindVideoDeviceNV(ByteBuffer peer_info, int video_slot, long video_device, IntBuffer attrib_list, int attrib_list_position);
104 
105 	/**
106 	 * Queries an attribute associated with the current context. This method is the cross-platform
107 	 * equivalent of glXQueryContext and wglQueryCurrentContextNV.
108 	 *
109 	 * @param attrib the attribute to query
110 	 * @param value  the buffer to store the value in
111 	 */
glQueryContextNV(int attrib, IntBuffer value)112 	public static boolean glQueryContextNV(int attrib, IntBuffer value) {
113 		checkExtension();
114 
115 		BufferChecks.checkBuffer(value, 1);
116 		ContextGL ctx = ContextGL.getCurrentContext();
117 		return nglQueryContextNV(ctx.getPeerInfo().getHandle(), ctx.getHandle(), attrib, value, value.position());
118 	}
119 
nglQueryContextNV(ByteBuffer peer_info, ByteBuffer context_handle, int attrib, IntBuffer value, int value_position)120 	private static native boolean nglQueryContextNV(ByteBuffer peer_info, ByteBuffer context_handle, int attrib, IntBuffer value, int value_position);
121 
122 }
123