diff --git a/src/java/org/lwjgl/d3d/Context.java b/src/java/org/lwjgl/d3d/Context.java new file mode 100644 index 00000000..0ab0387a --- /dev/null +++ b/src/java/org/lwjgl/d3d/Context.java @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.Sys; + +/** + *

+ * Context encapsulates an OpenGL context. + *

+ * + * This class is thread-safe. + * + * @author elias_naur + * @version $Revision: 2730 $ + * $Id: Context.java 2730 2007-01-17 12:58:38Z elias_naur $ + */ +final class Context { + /** + * The platform specific implementation of context methods + */ + private final static ContextImplementation implementation; + + /** The current Context */ + private final static ThreadLocal current_context_local = new ThreadLocal(); + + /** + * Handle to the native GL rendering context + */ + private final ByteBuffer handle; + private final PeerInfo peer_info; + + /** Whether the context has been destroyed */ + private boolean destroyed; + + private boolean destroy_requested; + + /** The thread that has this context current, or null. */ + private Thread thread; + + static { + Sys.initialize(); + implementation = createImplementation(); + } + + private static ContextImplementation createImplementation() { + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + return new WindowsContextImplementation(); + default: + throw new IllegalStateException("Unsupported platform"); + } + } + + PeerInfo getPeerInfo() { + return peer_info; + } + + static Context getCurrentContext() { + return (Context)current_context_local.get(); + } + + /** + * Create a context with the specified peer info and shared context + */ + public Context(PeerInfo peer_info, Context shared_context) throws LWJGLException { + Context context_lock = shared_context != null ? shared_context : this; + // If shared_context is not null, synchronize on it to make sure it is not deleted + // while this context is created. Otherwise, simply synchronize on ourself to avoid NPE + synchronized (context_lock) { + if (shared_context != null && shared_context.destroyed) + throw new IllegalArgumentException("Shared context is destroyed"); +// GLContext.loadOpenGLLibrary(); + try { + this.peer_info = peer_info; + this.handle = implementation.create(peer_info, shared_context != null ? shared_context.handle : null); + } catch (LWJGLException e) { +// GLContext.unloadOpenGLLibrary(); + throw e; + } + } + } + + /** + * Release the current context (if any). After this call, no context is current. + */ + public static void releaseCurrentContext() throws LWJGLException { + Context current_context = getCurrentContext(); + if (current_context != null) { + implementation.releaseCurrentContext(); +// GLContext.useContext(null); + current_context_local.set(null); + synchronized (current_context) { + current_context.thread = null; + current_context.checkDestroy(); + } + } + } + + /** + * Release the context from its drawable. This is necessary on some platforms, + * like Mac OS X, where binding the context to a drawable and binding the context + * for rendering are two distinct actions and where calling releaseDrawable + * on every releaseCurrentContext results in artifacts. + */ + public synchronized void releaseDrawable() throws LWJGLException { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + implementation.releaseDrawable(getHandle()); + } + + /** + * Update the context. Should be called whenever it's drawable is moved or resized + */ + public synchronized void update() { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + implementation.update(getHandle()); + } + + /** + * Swap the buffers on the current context. Only valid for double-buffered contexts + */ + public static void swapBuffers(PeerInfo peerInfo) throws LWJGLException { + implementation.swapBuffers(peerInfo); + } + + private boolean canAccess() { + return thread == null || Thread.currentThread() == thread; + } + + private void checkAccess() { + if (!canAccess()) + throw new IllegalStateException("From thread " + Thread.currentThread() + ": " + thread + " already has the context current"); + } + + /** + * Make the context current + */ + public synchronized void makeCurrent() throws LWJGLException { + checkAccess(); + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + thread = Thread.currentThread(); + current_context_local.set(this); + implementation.makeCurrent(peer_info, handle); +// GLContext.useContext(this); + } + + ByteBuffer getHandle() { + return handle; + } + + /** + * Query whether the context is current + */ + public synchronized boolean isCurrent() throws LWJGLException { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + return implementation.isCurrent(handle); + } + + private void checkDestroy() { + if (!destroyed && destroy_requested) { + try { + releaseDrawable(); + implementation.destroy(peer_info, handle); + destroyed = true; + thread = null; +// GLContext.unloadOpenGLLibrary(); + } catch (LWJGLException e) { + LWJGLUtil.log("Exception occurred while destroying context: " + e); + } + } + } + + /** + * Set the buffer swap interval. This call is a best-attempt at changing + * the monitor swap interval, which is the minimum periodicity of color buffer swaps, + * measured in video frame periods, and is not guaranteed to be successful. + * + * A video frame period is the time required to display a full frame of video data. + * + * @param sync true to synchronize; false to ignore synchronization + */ + public static void setSwapInterval(int value) { + implementation.setSwapInterval(value); + } + + + /** + * Destroy the context. This method behaves the same as destroy() with the extra + * requirement that the context must be either current to the current thread or not + * current at all. + */ + public synchronized void forceDestroy() throws LWJGLException { + checkAccess(); + destroy(); + } + + /** + * Request destruction of the Context. If the context is current, no context will be current after this call. + * The context is destroyed when no thread has it current. + */ + public synchronized void destroy() throws LWJGLException { + if (destroyed) + return; + destroy_requested = true; + boolean was_current = isCurrent(); +// int error = GL11.GL_NO_ERROR; + if (was_current) { +// if (GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11) +// error = GL11.glGetError(); + releaseCurrentContext(); + } + checkDestroy(); +// if (was_current && error != GL11.GL_NO_ERROR) +// throw new OpenGLException(error); + } +} diff --git a/src/java/org/lwjgl/d3d/ContextImplementation.java b/src/java/org/lwjgl/d3d/ContextImplementation.java new file mode 100644 index 00000000..858f1a13 --- /dev/null +++ b/src/java/org/lwjgl/d3d/ContextImplementation.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; + +/** + *

+ * Context implementation interface. + *

+ * + * @author elias_naur + * @version $Revision: 2356 $ + * $Id: ContextImplementation.java 2356 2006-06-07 06:35:52Z elias_naur $ + */ +interface ContextImplementation { + /** + * Create a context. + */ + public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException; + + /** + * Swap the buffers of the current context. Only valid for double-buffered contexts. + */ + public void swapBuffers(PeerInfo peerInfo) throws LWJGLException; + + /** + * Release the context from its drawable, if any. + */ + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException; + + /** + * Release the current context (if any). After this call, no context is current. + */ + public void releaseCurrentContext() throws LWJGLException; + + /** + * Update the context. Should be called whenever it's drawable is moved or resized + */ + public void update(ByteBuffer context_handle); + + /** + * Query whether the context is current + */ + public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException; + + /** + * Query whether the context is current + */ + public boolean isCurrent(ByteBuffer handle) throws LWJGLException; + + public void setSwapInterval(int value); + + /** + * Destroys the Context. + */ + public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException; +} diff --git a/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java b/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java new file mode 100644 index 00000000..48f7f76d --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java @@ -0,0 +1,81 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DAdapterIdentifier9 { + public byte Driver[] = new byte[Direct3DConstants.MAX_DEVICE_IDENTIFIER_STRING];//512 char [MAX_DEVICE_IDENTIFIER_STRING] + public byte Description[] = new byte[Direct3DConstants.MAX_DEVICE_IDENTIFIER_STRING];//512 char [MAX_DEVICE_IDENTIFIER_STRING] + public byte DeviceName[] = new byte[32]; //32 char [32] + public long DriverVersion; //8 LARGE_INTEGER + public long VendorId; //4 DWORD + public long DeviceId; //4 DWORD + public long SubSysId; //4 DWORD + public long Revision; //4 DWORD + public GUID DeviceIdentifier = new GUID(); //16 GUID + public long WHQLLevel; //4 DWORD + private static final int D3D_ADAPTER_IDENTIFIER_BYTE_SIZE = 1100; + private ByteBuffer buffer; + + public D3DAdapterIdentifier9() { + buffer = ByteBuffer.allocateDirect(D3D_ADAPTER_IDENTIFIER_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put(Driver); + buffer.put(Description); + buffer.put(DeviceName); + buffer.putLong(DriverVersion); + buffer.putInt((int)VendorId); + buffer.putInt((int)DeviceId); + buffer.putInt((int)SubSysId); + buffer.putInt((int)Revision); + buffer.putInt((int)DeviceIdentifier.Data1); + buffer.putShort(DeviceIdentifier.Data2); + buffer.putShort(DeviceIdentifier.Data3); + buffer.put(DeviceIdentifier.Data4); + buffer.putInt((int)WHQLLevel); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + buffer.get(Driver); + buffer.get(Description); + buffer.get(DeviceName); + DriverVersion = buffer.getLong(); + VendorId = buffer.getInt(); + DeviceId = buffer.getInt(); + SubSysId = buffer.getInt(); + Revision = buffer.getInt(); + DeviceIdentifier.Data1 = buffer.getInt(); + DeviceIdentifier.Data2 = buffer.getShort(); + DeviceIdentifier.Data3 = buffer.getShort(); + buffer.get(DeviceIdentifier.Data4); + WHQLLevel = buffer.getInt(); + } + + public String toString() { + return + "\n Driver = " + new String(Driver) + + "\n Description = " + new String(Description) + + "\n DeviceName = " + new String(DeviceName) + + "\nDriverVersion = " + DriverVersion + + "\n VendorId = " + VendorId + + "\n DeviceId = " + DeviceId + + "\n SubSysId = " + SubSysId + + "\n Revision = " + Revision + + "\n WHQLLevel = " + WHQLLevel + + DeviceIdentifier; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/D3DBox.java b/src/java/org/lwjgl/d3d/D3DBox.java new file mode 100644 index 00000000..c4fb223e --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DBox.java @@ -0,0 +1,10 @@ +package org.lwjgl.d3d; + +public class D3DBox { + public int Left; //UINT + public int Top; //UINT + public int Right; //UINT + public int Bottom; //UINT + public int Front; //UINT + public int Back; //UINT +} diff --git a/src/java/org/lwjgl/d3d/D3DCaps9.java b/src/java/org/lwjgl/d3d/D3DCaps9.java new file mode 100644 index 00000000..7ab39228 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DCaps9.java @@ -0,0 +1,327 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DCaps9 { + public int DeviceType; //4 D3DDEVTYPE + public int AdapterOrdinal; //4 UINT + public long Caps; //4 DWORD + public long Caps2; //4 DWORD + public long Caps3; //4 DWORD + public long PresentationIntervals; //4 DWORD + public long CursorCaps; //4 DWORD + public long DevCaps; //4 DWORD + public long PrimitiveMiscCaps; //4 DWORD + public long RasterCaps; //4 DWORD + public long ZCmpCaps; //4 DWORD + public long SrcBlendCaps; //4 DWORD + public long DestBlendCaps; //4 DWORD + public long AlphaCmpCaps; //4 DWORD + public long ShadeCaps; //4 DWORD + public long TextureCaps; //4 DWORD + public long TextureFilterCaps; //4 DWORD + public long CubeTextureFilterCaps; //4 DWORD + public long VolumeTextureFilterCaps; //4 DWORD + public long TextureAddressCaps; //4 DWORD + public long VolumeTextureAddressCaps; //4 DWORD + public long LineCaps; //4 DWORD + public long MaxTextureWidth; //4 DWORD + public long MaxTextureHeight; //4 DWORD + public long MaxVolumeExtent; //4 DWORD + public long MaxTextureRepeat; //4 DWORD + public long MaxTextureAspectRatio; //4 DWORD + public long MaxAnisotropy; //4 DWORD + public float MaxVertexW; //4 + public float GuardBandLeft; //4 + public float GuardBandTop; //4 + public float GuardBandRight; //4 + public float GuardBandBottom; //4 + public float ExtentsAdjust; //4 + public long StencilCaps; //4 DWORD + public long FVFCaps; //4 DWORD + public long TextureOpCaps; //4 DWORD + public long MaxTextureBlendStages; //4 DWORD + public long MaxSimultaneousTextures; //4 DWORD + public long VertexProcessingCaps; //4 DWORD + public long MaxActiveLights; //4 DWORD + public long MaxUserClipPlanes; //4 DWORD + public long MaxVertexBlendMatrices; //4 DWORD + public long MaxVertexBlendMatrixIndex; //4 DWORD + public float MaxPointSize; //4 + public long MaxPrimitiveCount; //4 DWORD + public long MaxVertexIndex; //4 DWORD + public long MaxStreams; //4 DWORD + public long MaxStreamStride; //4 DWORD + public long VertexShaderVersion; //4 DWORD + public long MaxVertexShaderConst; //4 DWORD + public long PixelShaderVersion; //4 DWORD + public float PixelShader1xMaxValue; //4 + public long DevCaps2; //4 DWORD + public float MaxNpatchTessellationLevel; //4 + public long Reserved5; //4 DWORD + public int MasterAdapterOrdinal; //4 UINT + public int AdapterOrdinalInGroup; //4 UINT + public int NumberOfAdaptersInGroup; //4 UINT + public long DeclTypes; //4 DWORD + public long NumSimultaneousRTs; //4 DWORD + public long StretchRectFilterCaps; //4 DWORD + public D3DVShaderCaps2_0 VS20Caps = new D3DVShaderCaps2_0(); //16 D3DVSHADERCAPS2_0 + public D3DPShaderCaps2_0 D3DPSHADERCAPS2_0 = new D3DPShaderCaps2_0(); //20 D3DPSHADERCAPS2_0 + public long VertexTextureFilterCaps; //4 DWORD + public long MaxVShaderInstructionsExecuted; //4 DWORD + public long MaxPShaderInstructionsExecuted; //4 DWORD + public long MaxVertexShader30InstructionSlots; //4 DWORD + public long MaxPixelShader30InstructionSlots; //4 DWORD + private static final int D3D_CAPS_BYTE_SIZE = 304; + + private ByteBuffer buffer; + + public D3DCaps9() { + buffer = ByteBuffer.allocateDirect(D3D_CAPS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(DeviceType); + buffer.putInt(AdapterOrdinal); + buffer.putInt((int)Caps); + buffer.putInt((int)Caps2); + buffer.putInt((int)Caps3); + buffer.putInt((int)PresentationIntervals); + buffer.putInt((int)CursorCaps); + buffer.putInt((int)DevCaps); + buffer.putInt((int)PrimitiveMiscCaps); + buffer.putInt((int)RasterCaps); + buffer.putInt((int)ZCmpCaps); + buffer.putInt((int)SrcBlendCaps); + buffer.putInt((int)DestBlendCaps); + buffer.putInt((int)AlphaCmpCaps); + buffer.putInt((int)ShadeCaps); + buffer.putInt((int)TextureCaps); + buffer.putInt((int)TextureFilterCaps); + buffer.putInt((int)CubeTextureFilterCaps); + buffer.putInt((int)VolumeTextureFilterCaps); + buffer.putInt((int)TextureAddressCaps); + buffer.putInt((int)VolumeTextureAddressCaps); + buffer.putInt((int)LineCaps); + buffer.putInt((int)MaxTextureWidth); + buffer.putInt((int)MaxTextureHeight); + buffer.putInt((int)MaxVolumeExtent); + buffer.putInt((int)MaxTextureRepeat); + buffer.putInt((int)MaxTextureAspectRatio); + buffer.putInt((int)MaxAnisotropy); + buffer.putFloat(MaxVertexW); + buffer.putFloat(GuardBandLeft); + buffer.putFloat(GuardBandTop); + buffer.putFloat(GuardBandRight); + buffer.putFloat(GuardBandBottom); + buffer.putFloat(ExtentsAdjust); + buffer.putInt((int)StencilCaps); + buffer.putInt((int)FVFCaps); + buffer.putInt((int)TextureOpCaps); + buffer.putInt((int)MaxTextureBlendStages); + buffer.putInt((int)MaxSimultaneousTextures); + buffer.putInt((int)VertexProcessingCaps); + buffer.putInt((int)MaxActiveLights); + buffer.putInt((int)MaxUserClipPlanes); + buffer.putInt((int)MaxVertexBlendMatrices); + buffer.putInt((int)MaxVertexBlendMatrixIndex); + buffer.putFloat(MaxPointSize); + buffer.putInt((int)MaxPrimitiveCount); + buffer.putInt((int)MaxVertexIndex); + buffer.putInt((int)MaxStreams); + buffer.putInt((int)MaxStreamStride); + buffer.putInt((int)VertexShaderVersion); + buffer.putInt((int)MaxVertexShaderConst); + buffer.putInt((int)PixelShaderVersion); + buffer.putFloat(PixelShader1xMaxValue); + buffer.putInt((int)DevCaps2); + buffer.putFloat(MaxNpatchTessellationLevel); + buffer.putInt((int)Reserved5); + buffer.putInt(MasterAdapterOrdinal); + buffer.putInt(AdapterOrdinalInGroup); + buffer.putInt(NumberOfAdaptersInGroup); + buffer.putInt((int)DeclTypes); + buffer.putInt((int)NumSimultaneousRTs); + buffer.putInt((int)StretchRectFilterCaps); + buffer.putInt((int)VS20Caps.Caps); + buffer.putInt(VS20Caps.DynamicFlowControlDepth); + buffer.putInt(VS20Caps.NumTemps); + buffer.putInt(VS20Caps.StaticFlowControlDepth); + buffer.putInt((int)D3DPSHADERCAPS2_0.Caps); + buffer.putInt(D3DPSHADERCAPS2_0.DynamicFlowControlDepth); + buffer.putInt(D3DPSHADERCAPS2_0.NumTemps); + buffer.putInt(D3DPSHADERCAPS2_0.StaticFlowControlDepth); + buffer.putInt(D3DPSHADERCAPS2_0.NumInstructionSlots); + buffer.putInt((int)VertexTextureFilterCaps); + buffer.putInt((int)MaxVShaderInstructionsExecuted); + buffer.putInt((int)MaxPShaderInstructionsExecuted); + buffer.putInt((int)MaxVertexShader30InstructionSlots); + buffer.putInt((int)MaxPixelShader30InstructionSlots); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + DeviceType = buffer.getInt(); + AdapterOrdinal = buffer.getInt(); + Caps = buffer.getInt(); + Caps2 = buffer.getInt(); + Caps3 = buffer.getInt(); + PresentationIntervals = buffer.getInt(); + CursorCaps = buffer.getInt(); + DevCaps = buffer.getInt(); + PrimitiveMiscCaps = buffer.getInt(); + RasterCaps = buffer.getInt(); + ZCmpCaps = buffer.getInt(); + SrcBlendCaps = buffer.getInt(); + DestBlendCaps = buffer.getInt(); + AlphaCmpCaps = buffer.getInt(); + ShadeCaps = buffer.getInt(); + TextureCaps = buffer.getInt(); + TextureFilterCaps = buffer.getInt(); + CubeTextureFilterCaps = buffer.getInt(); + VolumeTextureFilterCaps = buffer.getInt(); + TextureAddressCaps = buffer.getInt(); + VolumeTextureAddressCaps = buffer.getInt(); + LineCaps = buffer.getInt(); + MaxTextureWidth = buffer.getInt(); + MaxTextureHeight = buffer.getInt(); + MaxVolumeExtent = buffer.getInt(); + MaxTextureRepeat = buffer.getInt(); + MaxTextureAspectRatio = buffer.getInt(); + MaxAnisotropy = buffer.getInt(); + MaxVertexW = buffer.getFloat(); + GuardBandLeft = buffer.getFloat(); + GuardBandTop = buffer.getFloat(); + GuardBandRight = buffer.getFloat(); + GuardBandBottom = buffer.getFloat(); + ExtentsAdjust = buffer.getFloat(); + StencilCaps = buffer.getInt(); + FVFCaps = buffer.getInt(); + TextureOpCaps = buffer.getInt(); + MaxTextureBlendStages = buffer.getInt(); + MaxSimultaneousTextures = buffer.getInt(); + VertexProcessingCaps = buffer.getInt(); + MaxActiveLights = buffer.getInt(); + MaxUserClipPlanes = buffer.getInt(); + MaxVertexBlendMatrices = buffer.getInt(); + MaxVertexBlendMatrixIndex = buffer.getInt(); + MaxPointSize = buffer.getFloat(); + MaxPrimitiveCount = buffer.getInt(); + MaxVertexIndex = buffer.getInt(); + MaxStreams = buffer.getInt(); + MaxStreamStride = buffer.getInt(); + VertexShaderVersion = buffer.getInt(); + MaxVertexShaderConst = buffer.getInt(); + PixelShaderVersion = buffer.getInt(); + PixelShader1xMaxValue = buffer.getFloat(); + DevCaps2 = buffer.getInt(); + MaxNpatchTessellationLevel = buffer.getFloat(); + Reserved5 = buffer.getInt(); + MasterAdapterOrdinal = buffer.getInt(); + AdapterOrdinalInGroup = buffer.getInt(); + NumberOfAdaptersInGroup = buffer.getInt(); + DeclTypes = buffer.getInt(); + NumSimultaneousRTs = buffer.getInt(); + StretchRectFilterCaps = buffer.getInt(); + VS20Caps.Caps = buffer.getInt(); + VS20Caps.DynamicFlowControlDepth = buffer.getInt(); + VS20Caps.NumTemps = buffer.getInt(); + VS20Caps.StaticFlowControlDepth = buffer.getInt(); + D3DPSHADERCAPS2_0.Caps = buffer.getInt(); + D3DPSHADERCAPS2_0.DynamicFlowControlDepth = buffer.getInt(); + D3DPSHADERCAPS2_0.NumTemps = buffer.getInt(); + D3DPSHADERCAPS2_0.StaticFlowControlDepth = buffer.getInt(); + D3DPSHADERCAPS2_0.NumInstructionSlots = buffer.getInt(); + VertexTextureFilterCaps = buffer.getInt(); + MaxVShaderInstructionsExecuted = buffer.getInt(); + MaxPShaderInstructionsExecuted = buffer.getInt(); + MaxVertexShader30InstructionSlots = buffer.getInt() & 0x00000000ffffffffL; + MaxPixelShader30InstructionSlots = buffer.getInt(); + } + + public String toString() { + return + "\n DeviceType = " + DeviceType + + "\n AdapterOrdinal = " + AdapterOrdinal + + "\n Caps = " + Caps + + "\n Caps2 = " + Caps2 + + "\n Caps3 = " + Caps3 + + "\n PresentationIntervals = " + PresentationIntervals + + "\n CursorCaps = " + CursorCaps + + "\n DevCaps = " + DevCaps + + "\n PrimitiveMiscCaps = " + PrimitiveMiscCaps + + "\n RasterCaps = " + RasterCaps + + "\n ZCmpCaps = " + ZCmpCaps + + "\n SrcBlendCaps = " + SrcBlendCaps + + "\n DestBlendCaps = " + DestBlendCaps + + "\n AlphaCmpCaps = " + AlphaCmpCaps + + "\n ShadeCaps = " + ShadeCaps + + "\n TextureCaps = " + TextureCaps + + "\n TextureFilterCaps = " + TextureFilterCaps + + "\n CubeTextureFilterCaps = " + CubeTextureFilterCaps + + "\n VolumeTextureFilterCaps = " + VolumeTextureFilterCaps + + "\n TextureAddressCaps = " + TextureAddressCaps + + "\n VolumeTextureAddressCaps = " + VolumeTextureAddressCaps + + "\n LineCaps = " + LineCaps + + "\n MaxTextureWidth = " + MaxTextureWidth + + "\n MaxTextureHeight = " + MaxTextureHeight + + "\n MaxVolumeExtent = " + MaxVolumeExtent + + "\n MaxTextureRepeat = " + MaxTextureRepeat + + "\n MaxTextureAspectRatio = " + MaxTextureAspectRatio + + "\n MaxAnisotropy = " + MaxAnisotropy + + "\n MaxVertexW = " + MaxVertexW + + "\n GuardBandLeft = " + GuardBandLeft + + "\n GuardBandTop = " + GuardBandTop + + "\n GuardBandRight = " + GuardBandRight + + "\n GuardBandBottom = " + GuardBandBottom + + "\n ExtentsAdjust = " + ExtentsAdjust + + "\n StencilCaps = " + StencilCaps + + "\n FVFCaps = " + FVFCaps + + "\n TextureOpCaps = " + TextureOpCaps + + "\n MaxTextureBlendStages = " + MaxTextureBlendStages + + "\n MaxSimultaneousTextures = " + MaxSimultaneousTextures + + "\n VertexProcessingCaps = " + VertexProcessingCaps + + "\n MaxActiveLights = " + MaxActiveLights + + "\n MaxUserClipPlanes = " + MaxUserClipPlanes + + "\n MaxVertexBlendMatrices = " + MaxVertexBlendMatrices + + "\n MaxVertexBlendMatrixIndex = " + MaxVertexBlendMatrixIndex + + "\n MaxPointSize = " + MaxPointSize + + "\n MaxPrimitiveCount = " + MaxPrimitiveCount + + "\n MaxVertexIndex = " + MaxVertexIndex + + "\n MaxStreams = " + MaxStreams + + "\n MaxStreamStride = " + MaxStreamStride + + "\n VertexShaderVersion = " + VertexShaderVersion + + "\n MaxVertexShaderConst = " + MaxVertexShaderConst + + "\n PixelShaderVersion = " + PixelShaderVersion + + "\n PixelShader1xMaxValue = " + PixelShader1xMaxValue + + "\n DevCaps2 = " + DevCaps2 + + "\n MaxNpatchTessellationLevel = " + MaxNpatchTessellationLevel + + "\n Reserved5 = " + Reserved5 + + "\n MasterAdapterOrdinal = " + MasterAdapterOrdinal + + "\n AdapterOrdinalInGroup = " + AdapterOrdinalInGroup + + "\n NumberOfAdaptersInGroup = " + NumberOfAdaptersInGroup + + "\n DeclTypes = " + DeclTypes + + "\n NumSimultaneousRTs = " + NumSimultaneousRTs + + "\n StretchRectFilterCaps = " + StretchRectFilterCaps + + VS20Caps.toString() + + D3DPSHADERCAPS2_0.toString() + + "\n VertexTextureFilterCaps = " + VertexTextureFilterCaps + + "\n MaxVShaderInstructionsExecuted = " + MaxVShaderInstructionsExecuted + + "\n MaxPShaderInstructionsExecuted = " + MaxPShaderInstructionsExecuted + + "\nMaxVertexShader30InstructionSlots = " + MaxVertexShader30InstructionSlots + + "\n MaxPixelShader30InstructionSlots = " + MaxPixelShader30InstructionSlots; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/D3DClipStatus9.java b/src/java/org/lwjgl/d3d/D3DClipStatus9.java new file mode 100644 index 00000000..db08f422 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DClipStatus9.java @@ -0,0 +1,42 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DClipStatus9 { + public long ClipUnion; //4 DWORD + public long ClipIntersection; //4 DWORD + private static final int D3D_CLIP_STATUS_BYTE_SIZE = 8; + + private ByteBuffer buffer; + + public D3DClipStatus9() { + buffer = ByteBuffer.allocateDirect(D3D_CLIP_STATUS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)ClipUnion); + buffer.putInt((int)ClipIntersection); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + ClipUnion = buffer.getInt(); + ClipIntersection = buffer.getInt(); + } + public String toString() { + return + "\n ClipUnion = " + ClipUnion + + "\nClipIntersection = " + ClipIntersection; + } +} diff --git a/src/java/org/lwjgl/d3d/D3DColorValue.java b/src/java/org/lwjgl/d3d/D3DColorValue.java new file mode 100644 index 00000000..53449f29 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DColorValue.java @@ -0,0 +1,44 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DColorValue { + public float r; + public float g; + public float b; + public float a; + + private static final int D3D_COLOR_VALUE_BYTE_SIZE = 16; + private ByteBuffer buffer; + + public D3DColorValue() { + buffer = ByteBuffer.allocateDirect(D3D_COLOR_VALUE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putFloat(r); + buffer.putFloat(g); + buffer.putFloat(b); + buffer.putFloat(a); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + r = buffer.getFloat(); + g = buffer.getFloat(); + b = buffer.getFloat(); + a = buffer.getFloat(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java b/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java new file mode 100644 index 00000000..4a3edb00 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java @@ -0,0 +1,50 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DDeviceCreationParameters { + public int AdapterOrdinal; //4 UINT + public int DeviceType; //4 D3DDEVTYPE + public long hFocusWindow; //4 HWND + public long BehaviorFlags; //4 DWORD + private static final int D3D_CREATION_PARAMETERS_STATUS_BYTE_SIZE = 16; + + private ByteBuffer buffer; + + public D3DDeviceCreationParameters() { + buffer = ByteBuffer.allocateDirect(D3D_CREATION_PARAMETERS_STATUS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(AdapterOrdinal); + buffer.putInt(DeviceType); + buffer.putInt((int)hFocusWindow); + buffer.putInt((int)BehaviorFlags); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + AdapterOrdinal = buffer.getInt(); + DeviceType = buffer.getInt(); + hFocusWindow = buffer.getInt(); + BehaviorFlags = buffer.getInt(); + } + public String toString() { + return + "\nAdapterOrdinal = " + AdapterOrdinal + + "\n DeviceType = " + DeviceType + + "\n hFocusWindow = " + hFocusWindow + + "\n BehaviorFlags = " + BehaviorFlags; + } +} diff --git a/src/java/org/lwjgl/d3d/D3DDisplaymode.java b/src/java/org/lwjgl/d3d/D3DDisplaymode.java new file mode 100644 index 00000000..ba26ad8d --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DDisplaymode.java @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DDisplaymode { + public int Width; //4 UINT + public int Height; //4 UINT + public int RefreshRate; //4 UINT + public int Format; //4 D3DFORMAT + private static final int D3D_DISPLAYMODE_BYTE_SIZE = 16; + private ByteBuffer buffer; + + public D3DDisplaymode() { + buffer = ByteBuffer.allocateDirect(D3D_DISPLAYMODE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(Width); + buffer.putInt(Height); + buffer.putInt(RefreshRate); + buffer.putInt(Format); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + Width = buffer.getInt(); + Height = buffer.getInt(); + RefreshRate = buffer.getInt(); + Format = buffer.getInt(); + } + + public String toString() { + return + "\n width = " + Width + + "\n height = " + Height + + "\nrefreshRate = " + RefreshRate + + "\n format = " + Format; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java b/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java new file mode 100644 index 00000000..8ca5a01c --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java @@ -0,0 +1,11 @@ +package org.lwjgl.d3d; + +public class D3DDisplaymodeEx { + public int Size; //UINT + public int Width; //UINT + public int Height; //UINT + public int RefreshRate; //UINT + public int Format; //D3DFORMAT + public int ScanLineOrdering; //D3DSCANLINEORDERING + +} diff --git a/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java b/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java new file mode 100644 index 00000000..b896af1a --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java @@ -0,0 +1,8 @@ +package org.lwjgl.d3d; + +public class D3DDisplaymodeFilter { + public int Size; //UINT + public int Format; //D3DFORMAT + public int ScanLineOrdering; //D3DSCANLINEORDERING + +} diff --git a/src/java/org/lwjgl/d3d/D3DGammaRamp.java b/src/java/org/lwjgl/d3d/D3DGammaRamp.java new file mode 100644 index 00000000..d3e295fd --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DGammaRamp.java @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.ShortBuffer; + +public class D3DGammaRamp { + private ByteBuffer redForNative = ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); //2 WORD + private ByteBuffer greenForNative = ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); //2 WORD + private ByteBuffer blueForNative = ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); //2 WORD + public ShortBuffer red = redForNative.asShortBuffer(); + public ShortBuffer green = greenForNative.asShortBuffer(); + public ShortBuffer blue = blueForNative.asShortBuffer(); + + private static final int D3D_GAMMA_RAMP_BYTE_SIZE = 1536; + private ByteBuffer buffer; + + public D3DGammaRamp() { + buffer = ByteBuffer.allocateDirect(D3D_GAMMA_RAMP_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + redForNative.rewind(); + buffer.put(redForNative); + greenForNative.rewind(); + buffer.put(greenForNative); + blueForNative.rewind(); + buffer.put(blueForNative); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + byte temp[] = new byte[512]; + buffer.get(temp); + redForNative.put(temp); + buffer.get(temp); + greenForNative.put(temp); + buffer.get(temp); + blueForNative.put(temp); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java b/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java new file mode 100644 index 00000000..20be7583 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +public class D3DIndexBufferDesc { + public int Format; //D3DFORMAT + public int Type; //D3DRESOURCETYPE + public long Usage; //DWORD + public int Pool; //D3DPOOL + public int Size; //UINT +} diff --git a/src/java/org/lwjgl/d3d/D3DLight9.java b/src/java/org/lwjgl/d3d/D3DLight9.java new file mode 100644 index 00000000..710eb790 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DLight9.java @@ -0,0 +1,78 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DLight9 { + public int Type; //2 D3DLIGHTTYPE + public D3DColorValue Diffuse; //16 D3DCOLORVALUE + public D3DColorValue Specular; //16 D3DCOLORVALUE + public D3DColorValue Ambient; //16 D3DCOLORVALUE + public D3DVector Position; //12 D3DVECTOR + public D3DVector Direction; //12 D3DVECTOR + public float Range; //4 + public float Falloff; //4 + public float Attenuation0; //4 + public float Attenuation1; //4 + public float Attenuation2; //4 + public float Theta; //4 + public float Phi; //4 + + private static final int D3D_LIGHT_BYTE_SIZE = 102; + private ByteBuffer buffer; + + public D3DLight9() { + buffer = ByteBuffer.allocateDirect(D3D_LIGHT_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putShort((short)Type); + buffer.put(Diffuse.getBuffer()); + buffer.put(Specular.getBuffer()); + buffer.put(Ambient.getBuffer()); + buffer.put(Position.getBuffer()); + buffer.put(Direction.getBuffer()); + buffer.putFloat(Range); + buffer.putFloat(Falloff); + buffer.putFloat(Attenuation1); + buffer.putFloat(Attenuation1); + buffer.putFloat(Attenuation2); + buffer.putFloat(Theta); + buffer.putFloat(Phi); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + Type = buffer.getShort(); + byte temp[] = new byte[16]; + buffer.get(temp); + Diffuse.setBuffer(Diffuse.getEmptyBuffer().put(temp)); + buffer.get(temp); + Specular.setBuffer(Specular.getEmptyBuffer().put(temp)); + buffer.get(temp); + Ambient.setBuffer(Ambient.getEmptyBuffer().put(temp)); + temp = new byte[12]; + buffer.get(temp); + Position.setBuffer(Position.getEmptyBuffer().put(temp)); + buffer.get(temp); + Direction.setBuffer(Direction.getEmptyBuffer().put(temp)); + Range = buffer.getFloat(); + Falloff = buffer.getFloat(); + Attenuation1 = buffer.getFloat(); + Attenuation1 = buffer.getFloat(); + Attenuation2 = buffer.getFloat(); + Theta = buffer.getFloat(); + Phi = buffer.getFloat(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DLockedBox.java b/src/java/org/lwjgl/d3d/D3DLockedBox.java new file mode 100644 index 00000000..b5d21862 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DLockedBox.java @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class D3DLockedBox { + public int RowPitch; + public int SlicePitch; + public ByteBuffer pBits; +} diff --git a/src/java/org/lwjgl/d3d/D3DLockedRect.java b/src/java/org/lwjgl/d3d/D3DLockedRect.java new file mode 100644 index 00000000..31d61024 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DLockedRect.java @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class D3DLockedRect { + int Pitch; + public ByteBuffer pBits; //void * + +} diff --git a/src/java/org/lwjgl/d3d/D3DMaterial9.java b/src/java/org/lwjgl/d3d/D3DMaterial9.java new file mode 100644 index 00000000..a942869f --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DMaterial9.java @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DMaterial9 { + public D3DColorValue Diffuse; //16 + public D3DColorValue Ambient; //16 + public D3DColorValue Specular; //16 + public D3DColorValue Emissive; //16 + public float Power; //4 + + private static final int D3D_MATERIAL_BYTE_SIZE = 68; + private ByteBuffer buffer; + + public D3DMaterial9() { + buffer = ByteBuffer.allocateDirect(D3D_MATERIAL_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put(Diffuse.getBuffer()); + buffer.put(Ambient.getBuffer()); + buffer.put(Specular.getBuffer()); + buffer.put(Emissive.getBuffer()); + buffer.putFloat(Power); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + byte temp[] = new byte[16]; + buffer.get(temp); + Diffuse.setBuffer(Diffuse.getEmptyBuffer().put(temp)); + buffer.get(temp); + Ambient.setBuffer(Ambient.getEmptyBuffer().put(temp)); + buffer.get(temp); + Specular.setBuffer(Specular.getEmptyBuffer().put(temp)); + buffer.get(temp); + Emissive.setBuffer(Emissive.getEmptyBuffer().put(temp)); + Power = buffer.getFloat(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DMatrix.java b/src/java/org/lwjgl/d3d/D3DMatrix.java new file mode 100644 index 00000000..a518b020 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DMatrix.java @@ -0,0 +1,42 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class D3DMatrix { + public float m[][] = new float[4][4]; + + private static final int D3D_MATRIX_BYTE_SIZE = 64; + private ByteBuffer buffer; + + public D3DMatrix() { + buffer = ByteBuffer.allocateDirect(D3D_MATRIX_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + FloatBuffer temp = buffer.asFloatBuffer(); + for(int i=0;i<4;i++) { + temp.put(m[i]); + } + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + FloatBuffer temp = buffer.asFloatBuffer(); + for(int i=0;i<4;i++) { + temp.get(m[i]); + } + } +} diff --git a/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java b/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java new file mode 100644 index 00000000..c8debd62 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java @@ -0,0 +1,18 @@ +package org.lwjgl.d3d; + +public class D3DPShaderCaps2_0 { + public long Caps; //4 DWORD + public int DynamicFlowControlDepth; //4 INT + public int NumTemps; //4 INT + public int StaticFlowControlDepth; //4 INT + public int NumInstructionSlots; //4 INT + + public String toString() { + return + "\n Caps = " + Caps + + "\nDynamicFlowControlDepth = " + DynamicFlowControlDepth + + "\n NumTemps = " + NumTemps + + "\n StaticFlowControlDepth = " + StaticFlowControlDepth + + "\n NumInstructionSlots = " + NumInstructionSlots; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/D3DPresentParameters.java b/src/java/org/lwjgl/d3d/D3DPresentParameters.java new file mode 100644 index 00000000..51891304 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DPresentParameters.java @@ -0,0 +1,88 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DPresentParameters { + public int BackBufferWidth; //4 UINT + public int BackBufferHeight; //4 UINT + public int BackBufferFormat; //4 D3DFORMAT + public int BackBufferCount; //4 UINT + public int MultiSampleType; //4 D3DMULTISAMPLE_TYPE + public int MultiSampleQuality; //4 DWORD + public int SwapEffect; //4 D3DSWAPEFFECT + public long hDeviceWindow; //4 HWND + public boolean Windowed; //4 + public boolean EnableAutoDepthStencil; //4 + public int AutoDepthStencilFormat; //4 D3DFORMAT + public long Flags; //4 DWORD + public int FullScreen_RefreshRateInHz; //4 UINT + public int PresentationInterval; //4 UINT + private ByteBuffer buffer; + private static final int D3D_PRESENT_PARAMETERS_BYTE_SIZE = 56; + + public D3DPresentParameters() { + buffer = ByteBuffer.allocateDirect(D3D_PRESENT_PARAMETERS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(BackBufferWidth); + buffer.putInt(BackBufferHeight); + buffer.putInt(BackBufferFormat); + buffer.putInt(BackBufferCount); + buffer.putInt(MultiSampleType); + buffer.putInt(MultiSampleQuality); + buffer.putInt(SwapEffect); + buffer.putInt((int)hDeviceWindow); + buffer.putInt(Windowed ? 1 : 0); + buffer.putInt(EnableAutoDepthStencil ? 1 : 0); + buffer.putInt(AutoDepthStencilFormat); + buffer.putInt((int)Flags); + buffer.putInt(FullScreen_RefreshRateInHz); + buffer.putInt(PresentationInterval); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + BackBufferWidth = buffer.getInt(); + BackBufferHeight = buffer.getInt(); + BackBufferFormat = buffer.getInt(); + BackBufferCount = buffer.getInt(); + MultiSampleType = buffer.getInt(); + MultiSampleQuality = buffer.getInt(); + SwapEffect = buffer.getInt(); + hDeviceWindow = buffer.getInt(); + Windowed = buffer.getInt() == 1; + EnableAutoDepthStencil = buffer.getInt() == 1; + AutoDepthStencilFormat = buffer.getInt(); + Flags = buffer.getInt(); + FullScreen_RefreshRateInHz = buffer.getInt(); + PresentationInterval = buffer.getInt(); + } + public String toString() { + return + "\n BackBufferWidth = " + BackBufferWidth + + "\n BackBufferHeight = " + BackBufferHeight + + "\n BackBufferFormat = " + BackBufferFormat + + "\n BackBufferCount = " + BackBufferCount + + "\n MultiSampleType = " + MultiSampleType + + "\n MultiSampleQuality = " + MultiSampleQuality + + "\n SwapEffect = " + SwapEffect + + "\n hDeviceWindow = " + hDeviceWindow + + "\n Windowed = " + Windowed + + "\n EnableAutoDepthStencil = " + EnableAutoDepthStencil + + "\n AutoDepthStencilFormat = " + AutoDepthStencilFormat + + "\n Flags = " + Flags + + "\nFullScreen_RefreshRateInHz = " + FullScreen_RefreshRateInHz + + "\n PresentationInterval = " + PresentationInterval; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/D3DPresentStats.java b/src/java/org/lwjgl/d3d/D3DPresentStats.java new file mode 100644 index 00000000..446a74bf --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DPresentStats.java @@ -0,0 +1,11 @@ +package org.lwjgl.d3d; + +import java.math.BigInteger; + +public class D3DPresentStats { + public int PresentCount; //UINT + public int PresentRefreshCount; //UINT + public int SyncRefreshCount; //UINT + public BigInteger SyncQPCTime; //LARGE_INTEGER + public BigInteger SyncGPUTime; //LARGE_INTEGER +} diff --git a/src/java/org/lwjgl/d3d/D3DRasterStatus.java b/src/java/org/lwjgl/d3d/D3DRasterStatus.java new file mode 100644 index 00000000..f5b83f04 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DRasterStatus.java @@ -0,0 +1,38 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DRasterStatus { + public boolean InVBlank; + public int ScanLine; + + private static final int D3D_RASTER_STATUS_BYTE_SIZE = 3; + private ByteBuffer buffer; + + public D3DRasterStatus() { + buffer = ByteBuffer.allocateDirect(D3D_RASTER_STATUS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put((byte)(InVBlank ? 1 : 0)); + buffer.putShort((short)ScanLine); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + InVBlank = buffer.get() == 1; + ScanLine = buffer.getShort(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DRectPatchInfo.java b/src/java/org/lwjgl/d3d/D3DRectPatchInfo.java new file mode 100644 index 00000000..69f16b08 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DRectPatchInfo.java @@ -0,0 +1,63 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DRectPatchInfo { + public int StartVertexOffsetWidth; //4 UINT + public int StartVertexOffsetHeight; //4 UINT + public int Width; //4 UINT + public int Height; //4 UINT + public int Stride; //4 UINT + public int Basis; //4 D3DBASISTYPE + public int Degree; //4 D3DDEGREETYPE + + private static final int D3D_RECT_PATCH_INFO_BYTE_SIZE = 28; + + private ByteBuffer buffer; + + public D3DRectPatchInfo() { + buffer = ByteBuffer.allocateDirect(D3D_RECT_PATCH_INFO_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(StartVertexOffsetWidth); + buffer.putInt(StartVertexOffsetHeight); + buffer.putInt(Width); + buffer.putInt(Height); + buffer.putInt(Stride); + buffer.putInt(Basis); + buffer.putInt(Degree); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + StartVertexOffsetWidth = buffer.getInt(); + StartVertexOffsetHeight = buffer.getInt(); + Width = buffer.getInt(); + Height = buffer.getInt(); + Stride = buffer.getInt(); + Basis = buffer.getInt(); + Degree = buffer.getInt(); + } + public String toString() { + return + "\n StartVertexOffsetWidth = " + StartVertexOffsetWidth + + "\nStartVertexOffsetHeight = " + StartVertexOffsetHeight + + "\n Width = " + Width + + "\n Height = " + Height + + "\n Stride = " + Stride + + "\n Basis = " + Basis + + "\n Degree = " + Degree; + } +} diff --git a/src/java/org/lwjgl/d3d/D3DRegionData.java b/src/java/org/lwjgl/d3d/D3DRegionData.java new file mode 100644 index 00000000..8cc5d5b7 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DRegionData.java @@ -0,0 +1,37 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +//From RGNDATA +public class D3DRegionData { + D3DRegionDataHeader regionHeaderData; + byte Buffer[] = new byte[1]; + private static final int RECTANGLE_BYTE_SIZE = 33; + + private ByteBuffer buffer; + + public D3DRegionData() { + buffer = ByteBuffer.allocateDirect(RECTANGLE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + buffer.clear(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put(Buffer); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + regionHeaderData.setBuffer(buffer); + buffer.get(Buffer); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DRegionDataHeader.java b/src/java/org/lwjgl/d3d/D3DRegionDataHeader.java new file mode 100644 index 00000000..3dc61955 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DRegionDataHeader.java @@ -0,0 +1,47 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +//From RGNDATAHEADER +public class D3DRegionDataHeader { + public long dwSize; //4 DWORD + public long iType; //4 DWORD + public long nCount; //4 DWORD + public long nRgnSize; //4 DWORD + Rectangle rcBound; //16 RECT + private static final int RECTANGLE_BYTE_SIZE = 32; + + private ByteBuffer buffer; + + public D3DRegionDataHeader() { + buffer = ByteBuffer.allocateDirect(RECTANGLE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + buffer.clear(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)dwSize); + buffer.putInt((int)iType); + buffer.putInt((int)nCount); + buffer.putInt((int)nRgnSize); + buffer.put(rcBound.getBuffer()); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + dwSize = buffer.getInt(); + iType = buffer.getInt(); + nCount = buffer.getInt(); + nRgnSize = buffer.getInt(); + rcBound.setBuffer(buffer.slice()); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DSsurfaceDesc.java b/src/java/org/lwjgl/d3d/D3DSsurfaceDesc.java new file mode 100644 index 00000000..47a20670 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DSsurfaceDesc.java @@ -0,0 +1,12 @@ +package org.lwjgl.d3d; + +public class D3DSsurfaceDesc { + public int Format; //D3DFORMAT + public int Type; //D3DRESOURCETYPE + public long Usage; //DWORD + public int Pool; //D3DPOOL + public int MultiSampleType; //D3DMULTISAMPLE_TYPE + public long MultiSampleQuality; //DWORD + public int Width; //UINT + public int Height; //UINT +} diff --git a/src/java/org/lwjgl/d3d/D3DSurfaceDesc.java b/src/java/org/lwjgl/d3d/D3DSurfaceDesc.java new file mode 100644 index 00000000..87354e87 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DSurfaceDesc.java @@ -0,0 +1,12 @@ +package org.lwjgl.d3d; + +public class D3DSurfaceDesc { + public int Format; //D3DFORMAT + public int Type; //D3DRESOURCETYPE + public long Usage; //DWORD + public int Pool; //D3DPOOL + public int MultiSampleType; //D3DMULTISAMPLE_TYPE + public long MultiSampleQuality; //DWORD + public int Width; //UINT + public int Height; //UINT +} diff --git a/src/java/org/lwjgl/d3d/D3DTriPatchInfo.java b/src/java/org/lwjgl/d3d/D3DTriPatchInfo.java new file mode 100644 index 00000000..d524ae77 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DTriPatchInfo.java @@ -0,0 +1,50 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DTriPatchInfo { + public int StartVertexOffset; //4 UINT + public int NumVertices; //4 UINT + public int Basis; //4 D3DBASISTYPE + public int Degree; //4 D3DDEGREETYPE + private static final int D3D_TRI_PATCH_INFO_BYTE_SIZE = 16; + + private ByteBuffer buffer; + + public D3DTriPatchInfo() { + buffer = ByteBuffer.allocateDirect(D3D_TRI_PATCH_INFO_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(StartVertexOffset); + buffer.putInt(NumVertices); + buffer.putInt(Basis); + buffer.putInt(Degree); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + StartVertexOffset = buffer.getInt(); + NumVertices = buffer.getInt(); + Basis = buffer.getInt(); + Degree = buffer.getInt(); + } + public String toString() { + return + "\nStartVertexOffset = " + StartVertexOffset + + "\n NumVertices = " + NumVertices + + "\n Basis = " + Basis + + "\n Degree = " + Degree; + } +} diff --git a/src/java/org/lwjgl/d3d/D3DUtil.java b/src/java/org/lwjgl/d3d/D3DUtil.java new file mode 100644 index 00000000..cb497701 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DUtil.java @@ -0,0 +1,71 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DUtil { + public final static void D3DXMatrixLookAtLH(D3DMatrix out, D3DVector eye, D3DVector at, D3DVector up) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixLookAtLH(buffer, eye.getBuffer(), at.getBuffer(), up.getBuffer()); + out.setBuffer(buffer); + } + + public final static void D3DXMatrixPerspectiveFovLH(D3DMatrix out, float fovy, float aspect, float zn, float zf) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixPerspectiveFovLH(buffer, fovy, aspect, zn, zf); + out.setBuffer(buffer); + } + + public final static void D3DXMatrixIdentity(D3DMatrix out) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixIdentity(buffer); + out.setBuffer(buffer); + } + + public final static void D3DXMatrixScaling(D3DMatrix out, float sx, float sy, float sz) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixScaling(buffer, sx, sy, sz); + out.setBuffer(buffer); + } + + public final static void D3DXMatrixTranslation(D3DMatrix out, float x, float y ,float z) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixTranslation(buffer, x, y, z); + out.setBuffer(buffer); + } + public final static void D3DXMatrixRotationX(D3DMatrix out, float angle) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixRotationX(buffer, angle); + out.setBuffer(buffer); + } + public final static void D3DXMatrixRotationY(D3DMatrix out, float angle) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixRotationY(buffer, angle); + out.setBuffer(buffer); + } + public final static void D3DXMatrixRotationZ(D3DMatrix out, float angle) { + ByteBuffer buffer = out.getBuffer(); + nD3DXMatrixRotationZ(buffer, angle); + out.setBuffer(buffer); + } + public final static D3DMatrix D3DXMatrixMultiply(D3DMatrix out, D3DMatrix m1, D3DMatrix m2) { + D3DMatrix result = new D3DMatrix(); + ByteBuffer buffer = out.getBuffer(); + ByteBuffer resultBuffer = nD3DXMatrixMultiply(buffer, m1.getBuffer(), m2.getBuffer()); + resultBuffer.order(ByteOrder.nativeOrder()); + out.setBuffer(buffer); + result.setBuffer(resultBuffer); + + return result; + } + //natives + private final static native void nD3DXMatrixLookAtLH(ByteBuffer out, ByteBuffer eye, ByteBuffer at, ByteBuffer up); + private final static native void nD3DXMatrixPerspectiveFovLH(ByteBuffer out, float fovy, float aspect, float zn, float zf); + private final static native void nD3DXMatrixIdentity(ByteBuffer out); + private final static native void nD3DXMatrixScaling(ByteBuffer out, float sx, float sy, float sz); + private final static native void nD3DXMatrixTranslation(ByteBuffer out, float x, float y ,float z); + private final static native void nD3DXMatrixRotationX(ByteBuffer out, float angle); + private final static native void nD3DXMatrixRotationY(ByteBuffer out, float angle); + private final static native void nD3DXMatrixRotationZ(ByteBuffer out, float angle); + private final static native ByteBuffer nD3DXMatrixMultiply(ByteBuffer out, ByteBuffer m1, ByteBuffer m2); +} diff --git a/src/java/org/lwjgl/d3d/D3DVShaderCaps2_0.java b/src/java/org/lwjgl/d3d/D3DVShaderCaps2_0.java new file mode 100644 index 00000000..7a366d98 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DVShaderCaps2_0.java @@ -0,0 +1,16 @@ +package org.lwjgl.d3d; + +public class D3DVShaderCaps2_0 { + public long Caps; //4 DWORD + public int DynamicFlowControlDepth; //4 INT + public int NumTemps; //4 INT + public int StaticFlowControlDepth; //4 INT + + public String toString() { + return + "\n Caps = " + Caps + + "\nDynamicFlowControlDepth = " + DynamicFlowControlDepth + + "\n NumTemps = " + NumTemps + + "\n StaticFlowControlDepth = " + StaticFlowControlDepth; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/D3DVector.java b/src/java/org/lwjgl/d3d/D3DVector.java new file mode 100644 index 00000000..4b66decf --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DVector.java @@ -0,0 +1,40 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DVector { + public float x; + public float y; + public float z; + private static final int D3D_VECTOR_BYTE_SIZE = 12; + private ByteBuffer buffer; + + public D3DVector() { + buffer = ByteBuffer.allocateDirect(D3D_VECTOR_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putFloat(x); + buffer.putFloat(y); + buffer.putFloat(z); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + x = buffer.getFloat(); + y = buffer.getFloat(); + z = buffer.getFloat(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DVertexBufferDesc.java b/src/java/org/lwjgl/d3d/D3DVertexBufferDesc.java new file mode 100644 index 00000000..c9d4308e --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DVertexBufferDesc.java @@ -0,0 +1,49 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DVertexBufferDesc { + public int Format; //4 D3DFORMAT + public int Type; //4 D3DRESOURCETYPE + public long Usage; //4 DWORD + public int Pool; //4 D3DPOOL + public int Size; //4 UINT + public long FVF; //4 DWORD + + private static final int D3D_VERTEX_BUFFER_DESC_BYTE_SIZE = 24; + private ByteBuffer buffer; + + public D3DVertexBufferDesc() { + buffer = ByteBuffer.allocateDirect(D3D_VERTEX_BUFFER_DESC_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(Format); + buffer.putInt(Type); + buffer.putInt((int)Usage); + buffer.putInt(Pool); + buffer.putInt(Size); + buffer.putInt((int)FVF); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + Format = buffer.getInt(); + Type = buffer.getInt(); + Usage = buffer.getInt(); + Pool = buffer.getInt(); + Size = buffer.getInt(); + FVF = buffer.getInt(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DVertexElement9.java b/src/java/org/lwjgl/d3d/D3DVertexElement9.java new file mode 100644 index 00000000..64006be1 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DVertexElement9.java @@ -0,0 +1,60 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DVertexElement9 { + public long Stream; //WORD + public long Offset; //WORD + public byte Type; //BYTE + public byte Method; //BYTE + public byte Usage; //BYTE + public byte UsageIndex; //BYTE + private static final int D3D_VERTEX_ELEMENT_BYTE_SIZE = 12; + + private ByteBuffer buffer; + + public D3DVertexElement9() { + buffer = ByteBuffer.allocateDirect(D3D_VERTEX_ELEMENT_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)Stream); + buffer.putInt((int)Offset); + buffer.put(Type); + buffer.put(Method); + buffer.put(Usage); + buffer.put(UsageIndex); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + Stream = buffer.getInt(); + Offset = buffer.getInt(); + Type = buffer.get(); + Method = buffer.get(); + Usage = buffer.get(); + UsageIndex = buffer.get(); + } + + public String toString() { + return + "\n Stream = " + Stream + + "\n Offset = " + Offset + + "\n Type = " + Type + + "\n Method = " + Method + + "\n Usage = " + Usage + + "\nUsageIndex = " + UsageIndex; + } +} diff --git a/src/java/org/lwjgl/d3d/D3DViewport9.java b/src/java/org/lwjgl/d3d/D3DViewport9.java new file mode 100644 index 00000000..f6b16601 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DViewport9.java @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class D3DViewport9 { + public long X; //4 DWORD + public long Y; //4 DWORD + public long Width; //4 DWORD + public long Height; //4 DWORD + public float MinZ; //4 + public float MaxZ; //4 + + private static final int D3D_VIEWPORT_BYTE_SIZE = 24; + private ByteBuffer buffer; + + public D3DViewport9() { + buffer = ByteBuffer.allocateDirect(D3D_VIEWPORT_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)X); + buffer.putInt((int)Y); + buffer.putInt((int)Width); + buffer.putInt((int)Height); + buffer.putFloat(MinZ); + buffer.putFloat(MaxZ); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + X = buffer.getInt(); + Y = buffer.getInt(); + Width = buffer.getInt(); + Height = buffer.getInt(); + MinZ = buffer.getFloat(); + MaxZ = buffer.getFloat(); + } +} diff --git a/src/java/org/lwjgl/d3d/D3DVolumeDesc.java b/src/java/org/lwjgl/d3d/D3DVolumeDesc.java new file mode 100644 index 00000000..ece52ef6 --- /dev/null +++ b/src/java/org/lwjgl/d3d/D3DVolumeDesc.java @@ -0,0 +1,11 @@ +package org.lwjgl.d3d; + +public class D3DVolumeDesc { + public int Format; //D3DFORMAT + public int Type; //D3DRESOURCETYPE + public long Usage; //DWORD + public int Pool; //D3DPOOL + public int Width; //UINT + public int Height; //UINT + public int Depth; //UINT +} diff --git a/src/java/org/lwjgl/d3d/Direct3DConstants.java b/src/java/org/lwjgl/d3d/Direct3DConstants.java new file mode 100644 index 00000000..f06f89b5 --- /dev/null +++ b/src/java/org/lwjgl/d3d/Direct3DConstants.java @@ -0,0 +1,446 @@ +package org.lwjgl.d3d; + +public class Direct3DConstants { + public static final int D3DADAPTER_DEFAULT = 0; + public static final int D3DPRESENT_BACK_BUFFERS_MAX = 3; + public static final int D3DENUM_WHQL_LEVEL = 0x00000002; + public static final int MAX_DEVICE_IDENTIFIER_STRING = 512; + //D3DDEVTYPE + public static final int D3DDEVTYPE_HAL = 1; + public static final int D3DDEVTYPE_NULLREF = 4; + public static final int D3DDEVTYPE_REF = 2; + public static final int D3DDEVTYPE_SW = 3; + public static final int D3DDEVTYPE_FORCE_DWORD = 0xffffffff; + //D3DFORMAT + public static final int D3DFMT_UNKNOWN = 0; + public static final int D3DFMT_R8G8B8 = 20; + public static final int D3DFMT_A8R8G8B8 = 21; + public static final int D3DFMT_X8R8G8B8 = 22; + public static final int D3DFMT_R5G6B5 = 23; + public static final int D3DFMT_X1R5G5B5 = 24; + public static final int D3DFMT_A1R5G5B5 = 25; + public static final int D3DFMT_A4R4G4B4 = 26; + public static final int D3DFMT_R3G3B2 = 27; + public static final int D3DFMT_A8 = 28; + public static final int D3DFMT_A8R3G3B2 = 29; + public static final int D3DFMT_X4R4G4B4 = 30; + public static final int D3DFMT_A2B10G10R10 = 31; + public static final int D3DFMT_G16R16 = 34; + public static final int D3DFMT_A8P8 = 40; + public static final int D3DFMT_P8 = 41; + public static final int D3DFMT_L8 = 50; + public static final int D3DFMT_A8L8 = 51; + public static final int D3DFMT_A4L4 = 52; + public static final int D3DFMT_V8U8 = 60; + public static final int D3DFMT_L6V5U5 = 61; + public static final int D3DFMT_X8L8V8U8 = 62; + public static final int D3DFMT_Q8W8V8U8 = 63; + public static final int D3DFMT_V16U16 = 64; + public static final int D3DFMT_W11V11U10 = 65; + public static final int D3DFMT_A2W10V10U10 = 67; + public static final int D3DFMT_UYVY = MAKEFOURCC('U', 'Y', 'V', 'Y'); + public static final int D3DFMT_YUY2 = MAKEFOURCC('Y', 'U', 'Y', '2'); + public static final int D3DFMT_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'); + public static final int D3DFMT_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'); + public static final int D3DFMT_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'); + public static final int D3DFMT_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'); + public static final int D3DFMT_DXT5 = MAKEFOURCC('D', 'X', 'T', '5'); + public static final int D3DFMT_D16_LOCKABLE = 70; + public static final int D3DFMT_D32 = 71; + public static final int D3DFMT_D15S1 = 73; + public static final int D3DFMT_D24S8 = 75; + public static final int D3DFMT_D16 = 80; + public static final int D3DFMT_D24X8 = 77; + public static final int D3DFMT_D24X4S4 = 79; + public static final int D3DFMT_VERTEXDATA =100; + public static final int D3DFMT_INDEX16 =101; + public static final int D3DFMT_INDEX32 =102; + public static final int D3DFMT_FORCE_DWORD =0x7fffffff; + //D3DRESOURCETYPE + public static final int D3DRTYPE_SURFACE = 1; + public static final int D3DRTYPE_VOLUME = 2; + public static final int D3DRTYPE_TEXTURE = 3; + public static final int D3DRTYPE_VOLUMETEXTURE = 4; + public static final int D3DRTYPE_CubeTexture = 5; + public static final int D3DRTYPE_VERTEXBUFFER = 6; + public static final int D3DRTYPE_INDEXBUFFER = 7; + public static final int D3DRTYPE_FORCE_DWORD = 0x7fffffff; + //D3DUSAGE + public static final int D3DUSAGE_RENDERTARGET = 0x00000001; + public static final int D3DUSAGE_DEPTHSTENCIL = 0x00000002; + public static final int D3DUSAGE_AUTOGENMIPMAP = 0x00000400; + public static final int D3DUSAGE_DMAP = 0x00004000; + //The following usages are valid only for querying CheckDeviceFormat + public static final int D3DUSAGE_QUERY_LEGACYBUMPMAP = 0x00008000; + public static final int D3DUSAGE_QUERY_SRGBREAD = 0x00010000; + public static final int D3DUSAGE_QUERY_FILTER = 0x00020000; + public static final int D3DUSAGE_QUERY_SRGBWRITE = 0x00040000; + public static final int D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING = 0x00080000; + public static final int D3DUSAGE_QUERY_VERTEXTEXTURE = 0x00100000; + public static final int D3DUSAGE_QUERY_WRAPANDMIP = 0x00200000; + /* Usages for Vertex/Index buffers */ + public static final int D3DUSAGE_WRITEONLY = 0x00000008; + public static final int D3DUSAGE_SOFTWAREPROCESSING = 0x00000010; + public static final int D3DUSAGE_DONOTCLIP = 0x00000020; + public static final int D3DUSAGE_POINTS = 0x00000040; + public static final int D3DUSAGE_RTPATCHES = 0x00000080; + public static final int D3DUSAGE_NPATCHES = 0x00000100; + //D3DMULTISAMPLE_TYPE + public static final int D3DMULTISAMPLE_NONE = 0; + public static final int D3DMULTISAMPLE_NONMASKABLE = 1; + public static final int D3DMULTISAMPLE_2_SAMPLES = 2; + public static final int D3DMULTISAMPLE_3_SAMPLES = 3; + public static final int D3DMULTISAMPLE_4_SAMPLES = 4; + public static final int D3DMULTISAMPLE_5_SAMPLES = 5; + public static final int D3DMULTISAMPLE_6_SAMPLES = 6; + public static final int D3DMULTISAMPLE_7_SAMPLES = 7; + public static final int D3DMULTISAMPLE_8_SAMPLES = 8; + public static final int D3DMULTISAMPLE_9__SAMPLES = 9; + public static final int D3DMULTISAMPLE_10_SAMPLES = 10; + public static final int D3DMULTISAMPLE_11_SAMPLES = 11; + public static final int D3DMULTISAMPLE_12_SAMPLES = 12; + public static final int D3DMULTISAMPLE_13_SAMPLES = 13; + public static final int D3DMULTISAMPLE_14_SAMPLES = 14; + public static final int D3DMULTISAMPLE_15_SAMPLES = 15; + public static final int D3DMULTISAMPLE_16_SAMPLES = 16; + public static final int D3DMULTISAMPLE_FORCE_DWORD = 0xffffffff; + //D3DSWAPEFFECT + public static final int D3DSWAPEFFECT_DISCARD = 1; + public static final int D3DSWAPEFFECT_FLIP = 2; + public static final int D3DSWAPEFFECT_COPY = 3; + public static final int D3DSWAPEFFECT_FORCE_DWORD = 0xFFFFFFFF; + //D3DPOOL + public static final int D3DPOOL_DEFAULT = 0; + public static final int D3DPOOL_MANAGED = 1; + public static final int D3DPOOL_SYSTEMMEM = 2; + public static final int D3DPOOL_SCRATCH = 3; + public static final int D3DPOOL_FORCE_DWORD = 0x7fffffff; + //D3DQUERYTYPE + public static final int D3DQUERYTYPE_VCACHE = 4; + public static final int D3DQUERYTYPE_ResourceManager = 5; + public static final int D3DQUERYTYPE_VERTEXSTATS = 6; + public static final int D3DQUERYTYPE_EVENT = 8; + public static final int D3DQUERYTYPE_OCCLUSION = 9; + public static final int D3DQUERYTYPE_TIMESTAMP = 10; + public static final int D3DQUERYTYPE_TIMESTAMPDISJOINT = 11; + public static final int D3DQUERYTYPE_TIMESTAMPFREQ = 12; + public static final int D3DQUERYTYPE_PIPELINETIMINGS = 13; + public static final int D3DQUERYTYPE_INTERFACETIMINGS = 14; + public static final int D3DQUERYTYPE_VERTEXTIMINGS = 15; + public static final int D3DQUERYTYPE_PIXELTIMINGS = 16; + public static final int D3DQUERYTYPE_BANDWIDTHTIMINGS = 17; + public static final int D3DQUERYTYPE_CACHEUTILIZATION = 18; + //D3DSTATEBLOCKTYPE + public static final int D3DSBT_ALL = 1; + public static final int D3DSBT_PIXELSTATE = 2; + public static final int D3DSBT_VERTEXSTATE = 2; + public static final int D3DSBT_FORCE_DWORD = 0xffffffff; + //D3DPRIMITIVETYPE + public static final int D3DPT_POINTLIST = 1; + public static final int D3DPT_LINELIST = 2; + public static final int D3DPT_LINESTRIP = 3; + public static final int D3DPT_TRIANGLELIST = 4; + public static final int D3DPT_TRIANGLESTRIP = 5; + public static final int D3DPT_TRIANGLEFAN = 6; + public static final int D3DPT_FORCE_DWORD = 0x7fffffff; + //D3DBASISTYPE + public static final int D3DBASIS_BEZIER = 0; + public static final int D3DBASIS_BSPLINE = 1; + public static final int D3DBASIS_CATMULL_ROM = 2; + public static final int D3DBASIS_FORCE_DWORD = 0x7fffffff; + //D3DDEGREETYPE + public static final int D3DDEGREE_LINEAR = 1; + public static final int D3DDEGREE_QUADRATIC = 2; + public static final int D3DDEGREE_CUBIC = 3; + public static final int D3DDEGREE_QUINTIC = 5; + public static final int D3DDEGREE_FORCE_DWORD = 0x7fffffff; + //D3DBACKBUFFER_TYPE + public static final int D3DBACKBUFFER_TYPE_MONO = 0; + public static final int D3DBACKBUFFER_TYPE_FORCE_DWORD = 0x7fffffff; + //D3DLIGHTTYPE + public static final int D3DLIGHT_POINT = 1; + public static final int D3DLIGHT_SPOT = 2; + public static final int D3DLIGHT_DIRECTIONAL = 3; + public static final int D3DLIGHT_FORCE_DWORD = 0x7fffffff; + //D3DRENDERSTATETYPE + public static final int D3DRS_ZENABLE = 7; + public static final int D3DRS_FILLMODE = 8; + public static final int D3DRS_SHADEMODE = 9; + public static final int D3DRS_ZWRITEENABLE = 14; + public static final int D3DRS_ALPHATESTENABLE = 15; + public static final int D3DRS_LASTPIXEL = 16; + public static final int D3DRS_SRCBLEND = 19; + public static final int D3DRS_DESTBLEND = 20; + public static final int D3DRS_CULLMODE = 22; + public static final int D3DRS_ZFUNC = 23; + public static final int D3DRS_ALPHAREF = 24; + public static final int D3DRS_ALPHAFUNC = 25; + public static final int D3DRS_DITHERENABLE = 26; + public static final int D3DRS_ALPHABLENDENABLE = 27; + public static final int D3DRS_FOGENABLE = 28; + public static final int D3DRS_SPECULARENABLE = 29; + public static final int D3DRS_FOGCOLOR = 34; + public static final int D3DRS_FOGTABLEMODE = 35; + public static final int D3DRS_FOGSTART = 36; + public static final int D3DRS_FOGEND = 37; + public static final int D3DRS_FOGDENSITY = 38; + public static final int D3DRS_RANGEFOGENABLE = 48; + public static final int D3DRS_STENCILENABLE = 52; + public static final int D3DRS_STENCILFAIL = 53; + public static final int D3DRS_STENCILZFAIL = 54; + public static final int D3DRS_STENCILPASS = 55; + public static final int D3DRS_STENCILFUNC = 56; + public static final int D3DRS_STENCILREF = 57; + public static final int D3DRS_STENCILMASK = 58; + public static final int D3DRS_STENCILWRITEMASK = 59; + public static final int D3DRS_TEXTUREFACTOR = 60; + public static final int D3DRS_WRAP0 = 128; + public static final int D3DRS_WRAP1 = 129; + public static final int D3DRS_WRAP2 = 130; + public static final int D3DRS_WRAP3 = 131; + public static final int D3DRS_WRAP4 = 132; + public static final int D3DRS_WRAP5 = 133; + public static final int D3DRS_WRAP6 = 134; + public static final int D3DRS_WRAP7 = 135; + public static final int D3DRS_CLIPPING = 136; + public static final int D3DRS_LIGHTING = 137; + public static final int D3DRS_AMBIENT = 139; + public static final int D3DRS_FOGVERTEXMODE = 140; + public static final int D3DRS_COLORVERTEX = 141; + public static final int D3DRS_LOCALVIEWER = 142; + public static final int D3DRS_NORMALIZENORMALS = 143; + public static final int D3DRS_DIFFUSEMATERIALSOURCE = 145; + public static final int D3DRS_SPECULARMATERIALSOURCE = 146; + public static final int D3DRS_AMBIENTMATERIALSOURCE = 147; + public static final int D3DRS_EMISSIVEMATERIALSOURCE = 148; + public static final int D3DRS_VERTEXBLEND = 151; + public static final int D3DRS_CLIPPLANEENABLE = 152; + public static final int D3DRS_POINTSIZE = 154; + public static final int D3DRS_POINTSIZE_MIN = 155; + public static final int D3DRS_POINTSPRITEENABLE = 156; + public static final int D3DRS_POINTSCALEENABLE = 157; + public static final int D3DRS_POINTSCALE_A = 158; + public static final int D3DRS_POINTSCALE_B = 159; + public static final int D3DRS_POINTSCALE_C = 160; + public static final int D3DRS_MULTISAMPLEANTIALIAS = 161; + public static final int D3DRS_MULTISAMPLEMASK = 162; + public static final int D3DRS_PATCHEDGESTYLE = 163; + public static final int D3DRS_DEBUGMONITORTOKEN = 165; + public static final int D3DRS_POINTSIZE_MAX = 166; + public static final int D3DRS_INDEXEDVERTEXBLENDENABLE = 167; + public static final int D3DRS_COLORWRITEENABLE = 168; + public static final int D3DRS_TWEENFACTOR = 170; + public static final int D3DRS_BLENDOP = 171; + public static final int D3DRS_POSITIONDEGREE = 172; + public static final int D3DRS_NORMALDEGREE = 173; + public static final int D3DRS_SCISSORTESTENABLE = 174; + public static final int D3DRS_SLOPESCALEDEPTHBIAS = 175; + public static final int D3DRS_ANTIALIASEDLINEENABLE = 176; + public static final int D3DRS_MINTESSELLATIONLEVEL = 178; + public static final int D3DRS_MAXTESSELLATIONLEVEL = 179; + public static final int D3DRS_ADAPTIVETESS_X = 180; + public static final int D3DRS_ADAPTIVETESS_Y = 181; + public static final int D3DRS_ADAPTIVETESS_Z = 182; + public static final int D3DRS_ADAPTIVETESS_W = 183; + public static final int D3DRS_ENABLEADAPTIVETESSELLATION = 184; + public static final int D3DRS_TWOSIDEDSTENCILMODE = 185; + public static final int D3DRS_CCW_STENCILFAIL = 186; + public static final int D3DRS_CCW_STENCILZFAIL = 187; + public static final int D3DRS_CCW_STENCILPASS = 188; + public static final int D3DRS_CCW_STENCILFUNC = 189; + public static final int D3DRS_COLORWRITEENABLE1 = 190; + public static final int D3DRS_COLORWRITEENABLE2 = 191; + public static final int D3DRS_COLORWRITEENABLE3 = 192; + public static final int D3DRS_BLENDFACTOR = 193; + public static final int D3DRS_SRGBWRITEENABLE = 194; + public static final int D3DRS_DEPTHBIAS = 195; + public static final int D3DRS_WRAP8 = 198; + public static final int D3DRS_WRAP9 = 199; + public static final int D3DRS_WRAP10 = 200; + public static final int D3DRS_WRAP11 = 201; + public static final int D3DRS_WRAP12 = 202; + public static final int D3DRS_WRAP13 = 203; + public static final int D3DRS_WRAP14 = 204; + public static final int D3DRS_WRAP15 = 205; + public static final int D3DRS_SEPARATEALPHABLENDENABLE = 206; + public static final int D3DRS_SRCBLENDALPHA = 207; + public static final int D3DRS_DESTBLENDALPHA = 208; + public static final int D3DRS_BLENDOPALPHA = 209; + public static final int D3DRS_FORCE_DWORD = 0x7fffffff; + //D3DSAMPLERSTATETYPE + public static final int D3DSAMP_ADDRESSU = 1; + public static final int D3DSAMP_ADDRESSV = 2; + public static final int D3DSAMP_ADDRESSW = 3; + public static final int D3DSAMP_BORDERCOLOR = 4; + public static final int D3DSAMP_MAGFILTER = 5; + public static final int D3DSAMP_MINFILTER = 6; + public static final int D3DSAMP_MIPFILTER = 7; + public static final int D3DSAMP_MIPMAPLODBIAS = 8; + public static final int D3DSAMP_MAXMIPLEVEL = 9; + public static final int D3DSAMP_MAXANISOTROPY = 10; + public static final int D3DSAMP_SRGBTEXTURE = 11; + public static final int D3DSAMP_ELEMENTINDEX = 12; + public static final int D3DSAMP_DMAPOFFSET = 13; + public static final int D3DSAMP_FORCE_DWORD = 0x7fffffff; + //D3DTEXTURESTAGESTATETYPE + public static final int D3DTSS_COLOROP = 1; + public static final int D3DTSS_COLORARG1 = 2; + public static final int D3DTSS_COLORARG2 = 3; + public static final int D3DTSS_ALPHAOP = 4; + public static final int D3DTSS_ALPHAARG1 = 5; + public static final int D3DTSS_ALPHAARG2 = 6; + public static final int D3DTSS_BUMPENVMAT00 = 7; + public static final int D3DTSS_BUMPENVMAT01 = 8; + public static final int D3DTSS_BUMPENVMAT10 = 9; + public static final int D3DTSS_BUMPENVMAT11 = 10; + public static final int D3DTSS_TEXCOORDINDEX = 11; + public static final int D3DTSS_BUMPENVLSCALE = 22; + public static final int D3DTSS_BUMPENVLOFFSET = 23; + public static final int D3DTSS_TEXTURETRANSFORMFLAGS = 24; + public static final int D3DTSS_COLORARG0 = 26; + public static final int D3DTSS_ALPHAARG0 = 27; + public static final int D3DTSS_RESULTARG = 28; + public static final int D3DTSS_CONSTANT = 32; + public static final int D3DTSS_FORCE_DWORD = 0x7fffffff; + public static final int D3DTS_WORLD = 256; + //D3DTRANSFORMSTATETYPE + public static final int D3DTS_VIEW = 2; + public static final int D3DTS_PROJECTION = 3; + public static final int D3DTS_TEXTURE0 = 16; + public static final int D3DTS_TEXTURE1 = 17; + public static final int D3DTS_TEXTURE2 = 18; + public static final int D3DTS_TEXTURE3 = 19; + public static final int D3DTS_TEXTURE4 = 20; + public static final int D3DTS_TEXTURE5 = 21; + public static final int D3DTS_TEXTURE6 = 22; + public static final int D3DTS_TEXTURE7 = 23; + public static final int D3DTS_FORCE_DWORD = 0x7fffffff; + //D3DTEXTUREFILTERTYPE + public static final int D3DTEXF_NONE = 0; + public static final int D3DTEXF_POINT = 1; + public static final int D3DTEXF_LINEAR = 2; + public static final int D3DTEXF_ANISOTROPIC = 3; + public static final int D3DTEXF_PYRAMIDALQUAD = 6; + public static final int D3DTEXF_GAUSSIANQUAD = 7; + public static final int D3DTEXF_CONVOLUTIONMONO = 8; + public static final int D3DTEXF_FORCE_DWORD = 0x7fffffff; + //D3DSCANLINEORDERING + public static final int D3DSCANLINEORDERING_PROGRESSIVE = 1; + public static final int D3DSCANLINEORDERING_INTERLACED = 2; + //D3DDISPLAYROTATION + public static final int D3DDISPLAYROTATION_IDENTITY = 1; + public static final int D3DDISPLAYROTATION_90 = 2; + public static final int D3DDISPLAYROTATION_180 = 2; + public static final int D3DDISPLAYROTATION_270 = 2; + //D3DCUBEMAP_FACES + public static final int D3DCUBEMAP_FACE_POSITIVE_X = 0; + public static final int D3DCUBEMAP_FACE_NEGATIVE_X = 1; + public static final int D3DCUBEMAP_FACE_POSITIVE_Y = 2; + public static final int D3DCUBEMAP_FACE_NEGATIVE_Y = 3; + public static final int D3DCUBEMAP_FACE_POSITIVE_Z = 4; + public static final int D3DCUBEMAP_FACE_NEGATIVE_Z = 5; + public static final int D3DCUBEMAP_FACE_FORCE_DWORD = 0xffffffff; + //D3DCOMPOSERECTSOP + public static final int D3DCOMPOSERECTS_COPY = 1; + public static final int D3DCOMPOSERECTS_OR = 2; + public static final int D3DCOMPOSERECTS_AND = 3; + public static final int D3DCOMPOSERECTS_NEG = 4; + public static final int D3DCOMPOSERECTS_FORCE_DWORD = 0x7fffffff; + //D3DCREATE + public static final int D3DCREATE_FPU_PRESERVE = 0x00000002; + public static final int D3DCREATE_MULTITHREADED = 0x00000004; + public static final int D3DCREATE_PUREDEVICE = 0x00000010; + public static final int D3DCREATE_SOFTWARE_VERTEXPROCESSING = 0x00000020; + public static final int D3DCREATE_HARDWARE_VERTEXPROCESSING = 0x00000040; + public static final int D3DCREATE_MIXED_VERTEXPROCESSING = 0x00000080; + public static final int D3DCREATE_DISABLE_DRIVER_MANAGEMENT = 0x00000100; + public static final int D3DCREATE_ADAPTERGROUP_DEVICE = 0x00000200; + public static final int D3DCREATE_DISABLE_DRIVER_MANAGEMENT_EX = 0x00000400; + public static final int D3DCREATE_NOWINDOWCHANGES = 0x00000800; + public static final int D3DCREATE_DISABLE_PSGP_THREADING = 0x00002000; + public static final int D3DCREATE_ENABLE_PRESENTSTATS = 0x00004000; + public static final int D3DCREATE_DISABLE_PRINTSCREEN = 0x00008000; + public static final int D3DCREATE_SCREENSAVER = 0x10000000; + //D3DERR + public static final int D3D_OK = 0; + public static final int D3DERR_WRONGTEXTUREFORMAT = MAKE_D3DHRESULT(2072); + public static final int D3DERR_UNSUPPORTEDCOLOROPERATION = MAKE_D3DHRESULT(2073); + public static final int D3DERR_UNSUPPORTEDCOLORARG = MAKE_D3DHRESULT(2074); + public static final int D3DERR_UNSUPPORTEDALPHAOPERATION = MAKE_D3DHRESULT(2075); + public static final int D3DERR_UNSUPPORTEDALPHAARG = MAKE_D3DHRESULT(2076); + public static final int D3DERR_TOOMANYOPERATIONS = MAKE_D3DHRESULT(2077); + public static final int D3DERR_CONFLICTINGTEXTUREFILTER = MAKE_D3DHRESULT(2078); + public static final int D3DERR_UNSUPPORTEDFACTORVALUE = MAKE_D3DHRESULT(2079); + public static final int D3DERR_CONFLICTINGRENDERSTATE = MAKE_D3DHRESULT(2081); + public static final int D3DERR_UNSUPPORTEDTEXTUREFILTER = MAKE_D3DHRESULT(2082); + public static final int D3DERR_CONFLICTINGTEXTUREPALETTE = MAKE_D3DHRESULT(2086); + public static final int D3DERR_DRIVERINTERNALERROR = MAKE_D3DHRESULT(2087); + public static final int D3DERR_NOTFOUND = MAKE_D3DHRESULT(2150); + public static final int D3DERR_MOREDATA = MAKE_D3DHRESULT(2151); + public static final int D3DERR_DEVICELOST = MAKE_D3DHRESULT(2152); + public static final int D3DERR_DEVICENOTRESET = MAKE_D3DHRESULT(2153); + public static final int D3DERR_NOTAVAILABLE = MAKE_D3DHRESULT(2154); + public static final int D3DERR_OUTOFVIDEOMEMORY = MAKE_D3DHRESULT(380); + public static final int D3DERR_INVALIDDEVICE = MAKE_D3DHRESULT(2155); + public static final int D3DERR_INVALIDCALL = MAKE_D3DHRESULT(2156); + public static final int D3DERR_DRIVERINVALIDCALL = MAKE_D3DHRESULT(2157); + public static final int D3DERR_WASSTILLDRAWING = MAKE_D3DHRESULT(540); + public static final int D3DOK_NOAUTOGEN = MAKE_D3DSTATUS(2159); + //D3DFVF + public static final int D3DFVF_RESERVED0 = 0x001; + public static final int D3DFVF_POSITION_MASK = 0x400E; + public static final int D3DFVF_XYZ = 0x002; + public static final int D3DFVF_XYZRHW = 0x004; + public static final int D3DFVF_XYZB1 = 0x006; + public static final int D3DFVF_XYZB2 = 0x008; + public static final int D3DFVF_XYZB3 = 0x00a; + public static final int D3DFVF_XYZB4 = 0x00c; + public static final int D3DFVF_XYZB5 = 0x00e; + public static final int D3DFVF_XYZW = 0x4002; + public static final int D3DFVF_NORMAL = 0x010; + public static final int D3DFVF_PSIZE = 0x020; + public static final int D3DFVF_DIFFUSE = 0x040; + public static final int D3DFVF_SPECULAR = 0x080; + public static final int D3DFVF_TEXCOUNT_MASK = 0xf00; + public static final int D3DFVF_TEXCOUNT_SHIFT = 8; + public static final int D3DFVF_TEX0 = 0x000; + public static final int D3DFVF_TEX1 = 0x100; + public static final int D3DFVF_TEX2 = 0x200; + public static final int D3DFVF_TEX3 = 0x300; + public static final int D3DFVF_TEX4 = 0x400; + public static final int D3DFVF_TEX5 = 0x500; + public static final int D3DFVF_TEX6 = 0x600; + public static final int D3DFVF_TEX7 = 0x700; + public static final int D3DFVF_TEX8 = 0x800; + public static final int D3DFVF_LASTBETA_UBYTE4 = 0x1000; + public static final int D3DFVF_LASTBETA_D3DCOLOR = 0x8000; + public static final int D3DFVF_RESERVED2 = 0x6000; + //D3DCLEAR + public static final int D3DCLEAR_TARGET = 0x00000001; + public static final int D3DCLEAR_ZBUFFER = 0x00000002; + public static final int D3DCLEAR_STENCIL = 0x00000004; + //D3DCULL + public static final int D3DCULL_NONE = 1; + public static final int D3DCULL_CW = 2; + public static final int D3DCULL_CCW = 3; + public static final int D3DCULL_FORCE_DWORD = 0x7fffffff; /* force 32-bit size enum */ + + //D3DX + public static final double D3DX_PI = 3.141592654; + public static final double D3DX_1BYPI = 0.318309886; + + private static int MAKEFOURCC(char ch0, char ch1, char ch2, char ch3) { + return ((((int)ch0)) | (((int)ch1) << 8) | (((int)ch2) << 16) | (((int)ch3) << 24 )); + } + + private static int MAKE_D3DHRESULT(int code) { + return MAKE_HRESULT( 1, 0x876, code ); + } + private static int MAKE_D3DSTATUS(int code) { + return MAKE_HRESULT( 0, 0x876, code ); + } + + private static int MAKE_HRESULT(int sev, int fac, int code) { + return (int)(((long)(sev)<<31) | ((long)(fac)<<16) | ((long)(code))); + } +} diff --git a/src/java/org/lwjgl/d3d/Display.java b/src/java/org/lwjgl/d3d/Display.java new file mode 100644 index 00000000..39d5d1e8 --- /dev/null +++ b/src/java/org/lwjgl/d3d/Display.java @@ -0,0 +1,992 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; +/** + * This is the abstract class for a Display in LWJGL. LWJGL displays have some + * peculiar characteristics: + * + * - the display may be closeable by the user or operating system, and may be minimized + * by the user or operating system + * - only one display may ever be open at once + * - the operating system may or may not be able to do fullscreen or windowed displays. + * + * @author foo + */ + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Arrays; +import java.util.HashSet; + +import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.Sys; +import org.lwjgl.input.Controllers; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public final class Display { + private static final Thread shutdown_hook = new Thread() { + public void run() { + reset(); + } + }; + + /** The display implementor */ + private static final WindowsDisplay display_impl; + + /** The initial display mode */ + private static final DisplayMode initial_mode; + + /** The current display mode, if created */ + private static DisplayMode current_mode; + + /** Timer for sync() */ + private static long timeNow, timeThen; + + /** X coordinate of the window */ + private static int x = -1; + + /** Cached window icons, for when Display is recreated */ + private static ByteBuffer[] cached_icons; + + /** + * Y coordinate of the window. Y in window coordinates is from the top of the display down, + * unlike GL, where it is typically at the bottom of the display. + */ + private static int y = -1; + + /** Title of the window (never null) */ + private static String title = "Game"; + + /** Fullscreen */ + private static boolean fullscreen; + + /** Swap interval */ + private static int swap_interval; + + /** A unique context object, so we can track different contexts between creates() and destroys() */ + private static PeerInfo peer_info; + private static Context context; + + /** The Drawable instance that tracks the current Display context */ + private final static Drawable drawable; + + private static boolean window_created = false; + + static { + Sys.initialize(); + if(LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_WINDOWS) { + throw new IllegalStateException("Unsupported platform"); + } + display_impl = new WindowsDisplay(); + try { + current_mode = initial_mode = display_impl.init(); + LWJGLUtil.log("Initial mode: " + initial_mode); + } catch (LWJGLException e) { + throw new RuntimeException(e); + } + drawable = new Drawable() { + public Context getContext() { + synchronized (GlobalLock.lock) { + return isCreated() ? context : null; + } + } + }; + } + + /** + * Fetch the Drawable from the Display. + * + * @return the Drawable corresponding to the Display context + */ + public static Drawable getDrawable() { + return drawable; + } + + /** + * Only constructed by ourselves + */ + private Display() { + } + + /** + * Returns the entire list of possible fullscreen display modes as an array, in no + * particular order. Although best attempts to filter out invalid modes are done, any + * given mode is not guaranteed to be available nor is it guaranteed to be within the + * current monitor specs (this is especially a problem with the frequency parameter). + * Furthermore, it is not guaranteed that create() will detect an illegal display mode. + * + * The only certain way to check + * is to call create() and make sure it works. + * Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32). + * Only DisplayModes from this call can be used when the Display is in fullscreen + * mode. + * + * @return an array of all display modes the system reckons it can handle. + */ + public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException { + synchronized (GlobalLock.lock) { + DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes(); + + if (unfilteredModes == null) { + return new DisplayMode[0]; + } + + // We'll use a HashSet to filter out the duplicated modes + HashSet modes = new HashSet(unfilteredModes.length); + + modes.addAll(Arrays.asList(unfilteredModes)); + DisplayMode[] filteredModes = new DisplayMode[modes.size()]; + modes.toArray(filteredModes); + + LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); + + return filteredModes; + } + } + + /** + * Return the current display mode, as set by setDisplayMode(). + * @return The current display mode + */ + public static DisplayMode getDisplayMode() { + synchronized (GlobalLock.lock) { + return current_mode; + } + } + + /** + * Set the current display mode. If no OpenGL context has been created, the given mode will apply to + * the context when create() is called, and no immediate mode switching will happen. If there is a + * context already, it will be resized according to the given mode. If the context is also a + * fullscreen context, the mode will also be switched immediately. The native cursor position + * is also reset. + * + * @param mode The new display mode to set + * @throws LWJGLException if the display mode could not be set + */ + public static void setDisplayMode(DisplayMode mode) throws LWJGLException { + synchronized (GlobalLock.lock) { + if (mode == null) + throw new NullPointerException("mode must be non-null"); + current_mode = mode; + if (isCreated()) { + destroyWindow(); + // If mode is not fullscreen capable, make sure we are in windowed mode + if (!mode.isFullscreen()) + resetFullscreen(); + try { + if (fullscreen) + switchDisplayMode(); + createWindow(); +// makeCurrentAndSetSwapInterval(); + } catch (LWJGLException e) { + destroyContext(); + destroyPeerInfo(); + display_impl.resetDisplayMode(); + throw e; + } + } + } + } + + /** + * Create the native window peer from the given mode and fullscreen flag. + * A native context must exist, and it will be attached to the window. + */ + private static void createWindow() throws LWJGLException { + if (window_created) { + return; + } + int window_x; + int window_y; + if (!fullscreen) { + // if no display location set, center window + if (x == -1 && y == -1) { + window_x = Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2); + window_y = Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2); + } else { + window_x = x; + window_y = y; + } + } else { + window_x = 0; + window_y = 0; + } + display_impl.createWindow(current_mode, fullscreen, window_x, window_y); + window_created = true; + + setTitle(title); + initControls(); + + // set cached window icon if exists + if(cached_icons != null) { + setIcon(cached_icons); + } else { + setIcon(new ByteBuffer[] { LWJGLUtil.LWJGLIcon32x32, LWJGLUtil.LWJGLIcon16x16 }); + } + } + + private static void destroyWindow() { + if (!window_created) { + return; + } +// try { +// if (context != null && context.isCurrent()) { +// context.releaseDrawable(); +// Context.releaseCurrentContext(); +// } +// } catch (LWJGLException e) { +// LWJGLUtil.log("Exception occurred while trying to release context: " + e); +// } + + // Automatically destroy keyboard & mouse + if (Mouse.isCreated()) { + Mouse.destroy(); + } + if (Keyboard.isCreated()) { + Keyboard.destroy(); + } + display_impl.destroyWindow(); + window_created = false; + } + + private static void switchDisplayMode() throws LWJGLException { + if (!current_mode.isFullscreen()) { + LWJGLUtil.log("Switching to "+initial_mode); + setDisplayMode(initial_mode); + } + display_impl.switchDisplayMode(current_mode); + } + + /** + * Set the display configuration to the specified gamma, brightness and contrast. + * The configuration changes will be reset when destroy() is called. + * + * @param gamma The gamma value + * @param brightness The brightness value between -1.0 and 1.0, inclusive + * @param contrast The contrast, larger than 0.0. + */ + public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException { + synchronized (GlobalLock.lock) { + if (!isCreated()) { + throw new LWJGLException("Display not yet created."); + } + if (brightness < -1.0f || brightness > 1.0f) + throw new IllegalArgumentException("Invalid brightness value"); + if (contrast < 0.0f) + throw new IllegalArgumentException("Invalid contrast value"); + int rampSize = display_impl.getGammaRampLength(); + if (rampSize == 0) { + throw new LWJGLException("Display configuration not supported"); + } + FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize); + for (int i = 0; i < rampSize; i++) { + float intensity = (float)i/(rampSize - 1); + // apply gamma + float rampEntry = (float)java.lang.Math.pow(intensity, gamma); + // apply brightness + rampEntry += brightness; + // apply contrast + rampEntry = (rampEntry - 0.5f)*contrast + 0.5f; + // Clamp entry to [0, 1] + if (rampEntry > 1.0f) + rampEntry = 1.0f; + else if (rampEntry < 0.0f) + rampEntry = 0.0f; + gammaRamp.put(i, rampEntry); + } + display_impl.setGammaRamp(gammaRamp); + LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast); + } + } + + /** + * Synchronize the display to a capped frame rate. Note that we are being "smart" about the + * desired results in our implementation; we automatically subtract 1 from the desired framerate + * to prevent just missing the frame time if vsync is set. + * @param fps The desired frame rate, in frames per second + */ + public static void sync3(int fps) { + synchronized (GlobalLock.lock) { + float frameTime = 1.0f / (fps > 1 ? fps - 1 : 1); + timeNow = Sys.getTime(); + while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameTime) { + // This is a system-friendly way of allowing other stuff to use CPU if it wants to + Thread.yield(); + timeNow = Sys.getTime(); + } + timeThen = timeNow; + } + } + + private static long timeLate; + + /** + * Alternative sync method which works better on triple-buffered GL displays. + * + * @param fps The desired frame rate, in frames per second + */ + public static void sync2(int fps) { + synchronized (GlobalLock.lock) { + long gapTo = Sys.getTimerResolution() / fps + timeThen; + timeNow = Sys.getTime(); + + while (gapTo > timeNow + timeLate) { + Thread.yield(); + timeNow = Sys.getTime(); + } + + if (gapTo < timeNow) + timeLate = timeNow - gapTo; + else + timeLate = 0; + + timeThen = timeNow; + } + } + + /** + * Best sync method that works reliably. + * + * @param fps The desired frame rate, in frames per second + */ + public static void sync(int fps) { + synchronized (GlobalLock.lock) { + long gapTo = Sys.getTimerResolution() / fps + timeThen; + timeNow = Sys.getTime(); + + while (gapTo > timeNow + timeLate) { + try { + Thread.sleep(1); + } catch (InterruptedException e) { + } + timeNow = Sys.getTime(); + } + + if (gapTo < timeNow) + timeLate = timeNow - gapTo; + else + timeLate = 0; + + timeThen = timeNow; + } + } + + /** + * @return the X coordinate of the window (always 0 for fullscreen) + */ + /*public static int getX() { + return (fullscreen) ? 0 : x; + }*/ + + /** + * @return the Y coordinate of the window (always 0 for fullscreen) + */ + /*public static int getY() { + return (fullscreen) ? 0 : y; + }*/ + + + /** + * @return the title of the window + */ + public static String getTitle() { + synchronized (GlobalLock.lock) { + return title; + } + } + + private static void resetFullscreen() { + synchronized (GlobalLock.lock) { + if (Display.fullscreen) { + Display.fullscreen = false; + display_impl.resetDisplayMode(); + } + } + } + + /** + * Set the fullscreen mode of the context. If no context has been created through create(), + * the mode will apply when create() is called. If fullscreen is true, the context will become + * a fullscreen context and the display mode is switched to the mode given by getDisplayMode(). If + * fullscreen is false, the context will become a windowed context with the dimensions given in the + * mode returned by getDisplayMode(). The native cursor position is also reset. + * + * @param fullscreen Specify the fullscreen mode of the context. + * @throws LWJGLException If fullscreen is true, and the current DisplayMode instance is not + * from getAvailableDisplayModes() or if the mode switch fails. + */ + public static void setFullscreen(boolean fullscreen) throws LWJGLException { + synchronized (GlobalLock.lock) { + if (Display.fullscreen != fullscreen) { + Display.fullscreen = fullscreen; + if (!isCreated()) + return; + destroyWindow(); + try { + if (fullscreen) { + switchDisplayMode(); + } else { + display_impl.resetDisplayMode(); + } + createWindow(); + makeCurrentAndSetSwapInterval(); + } catch (LWJGLException e) { + destroyContext(); + destroyPeerInfo(); + display_impl.resetDisplayMode(); + throw e; + } + } + } + } + + /** + * @return whether the Display is in fullscreen mode + */ + public static boolean isFullscreen() { + synchronized (GlobalLock.lock) { + return fullscreen; + } + } + + /** + * Set the title of the window. This may be ignored by the underlying OS. + * @param newTitle The new window title + */ + public static void setTitle(String newTitle) { + synchronized (GlobalLock.lock) { + if (newTitle == null) { + newTitle = ""; + } + title = newTitle; + if (isCreated()) + display_impl.setTitle(title); + } + } + + /** + * @return true if the user or operating system has asked the window to close + */ + public static boolean isCloseRequested() { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine close requested state of uncreated window"); + display_impl.update(); + return display_impl.isCloseRequested(); + } + } + + /** + * @return true if the window is visible, false if not + */ + public static boolean isVisible() { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine minimized state of uncreated window"); + display_impl.update(); + return display_impl.isVisible(); + } + } + + /** + * @return true if window is active, that is, the foreground display of the operating system. + */ + public static boolean isActive() { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine focused state of uncreated window"); + display_impl.update(); + return display_impl.isActive(); + } + } + + /** + * Determine if the window's contents have been damaged by external events. + * If you are writing a straightforward game rendering loop and simply paint + * every frame regardless, you can ignore this flag altogether. If you are + * trying to be kind to other processes you can check this flag and only + * redraw when it returns true. The flag is cleared when update() or isDirty() is called. + * + * @return true if the window has been damaged by external changes + * and needs to repaint itself + */ + public static boolean isDirty() { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine dirty state of uncreated window"); + display_impl.update(); + return display_impl.isDirty(); + } + } + + /** + * Process operating system events. Call this to update the Display's state and make sure the + * input devices receive events. This method is called from update(), and should normally not be called by + * the application. + */ + public static void processMessages() { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display not created"); + + display_impl.update(); + } + } + + /** + * Swap the display buffers. This method is called from update(), and should normally not be called by + * the application. + * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError() + */ + public static void swapBuffers() throws LWJGLException { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display not created"); +// +// Util.checkGLError(); +// Context.swapBuffers(); + } + } + + /** + * Update the window. This calls processMessages(), and if the window is visible + * clears the dirty flag and calls swapBuffers() and finally polls the input devices. + * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError() + */ + public static void update() { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display not created"); + + // We paint only when the window is visible or dirty + if (isVisible() || isDirty()) { + try { + swapBuffers(); + } catch (LWJGLException e) { + throw new RuntimeException(e); + } + } + + processMessages(); + pollDevices(); + } + } + + static void pollDevices() { + // Poll the input devices while we're here + if (Mouse.isCreated()) { + Mouse.poll(); + Mouse.updateCursor(); + } + + if (Keyboard.isCreated()) { + Keyboard.poll(); + } + + if(Controllers.isCreated()) { + Controllers.poll(); + } + } + + /** + * Release the Display context. + * + * @throws LWJGLException If the context could not be released + */ + public static void releaseContext() throws LWJGLException { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display is not created"); + if (context.isCurrent()) + Context.releaseCurrentContext(); + } + } + + /** + * Make the Display the current rendering context for GL calls. + * + * @throws LWJGLException If the context could not be made current + */ + public static void makeCurrent() throws LWJGLException { + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display is not created"); + context.makeCurrent(); + } + } + + /** + * Create the OpenGL context. If isFullscreen() is true or if windowed + * context are not supported on the platform, the display mode will be switched to the mode returned by + * getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context + * will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be + * created with the given parameters, a LWJGLException will be thrown. + * + *

The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates. + * + * @throws LWJGLException + */ + public static void create() throws LWJGLException { + synchronized (GlobalLock.lock) { + create(new PixelFormat()); + } + } + + /** + * Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed + * context are not supported on the platform, the display mode will be switched to the mode returned by + * getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context + * will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be + * created with the given parameters, a LWJGLException will be thrown. + * + *

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. + * @throws LWJGLException + */ + public static void create(PixelFormat pixel_format) throws LWJGLException { + synchronized (GlobalLock.lock) { + create(pixel_format, null); + } + } + + private static void removeShutdownHook() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().removeShutdownHook(shutdown_hook); + return null; + } + }); + } + + private static void registerShutdownHook() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(shutdown_hook); + return null; + } + }); + } + + /** + * Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed + * context are not supported on the platform, the display mode will be switched to the mode returned by + * getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context + * will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be + * created with the given parameters, a LWJGLException will be thrown. + * + *

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 or null. + * @throws LWJGLException + */ + public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException { + synchronized (GlobalLock.lock) { + if (isCreated()) + throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time."); + if (pixel_format == null) + throw new NullPointerException("pixel_format cannot be null"); + removeShutdownHook(); + registerShutdownHook(); + if (fullscreen) + switchDisplayMode(); +// try { +// peer_info = display_impl.createPeerInfo(); + try { + createWindow(); +// try { +// context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null); +// try { +// makeCurrentAndSetSwapInterval(); +// initContext(); +// } catch (LWJGLException e) { +// destroyContext(); +// throw e; +// } +// } catch (LWJGLException e) { +// destroyWindow(); +// throw e; +// } + } catch (LWJGLException e) { + destroyPeerInfo(); + throw e; + } +// } catch (LWJGLException e) { +// display_impl.resetDisplayMode(); +// throw e; +// } + } + } + + private static void makeCurrentAndSetSwapInterval() throws LWJGLException { +// makeCurrent(); +// Util.checkGLError(); +// setSwapInterval(swap_interval); + } + +// private static void initContext() { +// // Put the window into orthographic projection mode with 1:1 pixel ratio. +// // We haven't used GLU here to do this to avoid an unnecessary dependency. +// GL11.glMatrixMode(GL11.GL_PROJECTION); +// GL11.glLoadIdentity(); +// GL11.glOrtho(0.0, current_mode.getWidth(), 0.0, current_mode.getHeight(), -1.0, 1.0); +// GL11.glMatrixMode(GL11.GL_MODELVIEW); +// GL11.glLoadIdentity(); +// GL11.glViewport(0, 0, current_mode.getWidth(), current_mode.getHeight()); +// // Clear window to avoid the desktop "showing through" +// GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); +// update(); +// } +// + static DisplayImplementation getImplementation() { + return display_impl; + } + + /** + * Gets a boolean property as a privileged action. + */ + static boolean getPrivilegedBoolean(final String property_name) { + Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return new Boolean(Boolean.getBoolean(property_name)); + } + }); + return value.booleanValue(); + } + + private static void initControls() { + // Automatically create mouse, keyboard and controller + if (!getPrivilegedBoolean("org.lwjgl.opengl.Display.noinput")) { + if (!Mouse.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nomouse")) { + try { + Mouse.create(); + } catch (LWJGLException e) { + if (LWJGLUtil.DEBUG) { + e.printStackTrace(System.err); + } else { + LWJGLUtil.log("Failed to create Mouse: "+e); + } + } + } + if (!Keyboard.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nokeyboard")) { + try { + Keyboard.create(); + } catch (LWJGLException e) { + if (LWJGLUtil.DEBUG) { + e.printStackTrace(System.err); + } else { + LWJGLUtil.log("Failed to create Keyboard: "+e); + } + } + } + } + } + + /** + * Destroy the Display. After this call, there will be no current GL rendering context, + * regardless of whether the Display was the current rendering context. + */ + public static void destroy() { + synchronized (GlobalLock.lock) { + if (!isCreated()) { + return; + } + + destroyWindow(); +// destroyContext(); +// destroyPeerInfo(); + x = y = -1; + cached_icons = null; + reset(); + removeShutdownHook(); + } + } + + private static void destroyPeerInfo() { +// peer_info.destroy(); +// peer_info = null; + } + + private static void destroyContext() { +// try { +// context.forceDestroy(); +// } catch (LWJGLException e) { +// throw new RuntimeException(e); +// } finally { +// context = null; +// } + } + + /* + * Reset display mode if fullscreen. This method is also called from the shutdown hook added + * in the static constructor + */ + private static void reset() { + display_impl.resetDisplayMode(); + current_mode = initial_mode; + } + + /** + * @return true if the window's native peer has been created + */ + public static boolean isCreated() { + synchronized (GlobalLock.lock) { + return window_created; + } + } + + /** + * Set the buffer swap interval. This call is a best-attempt at changing + * the monitor swap interval, which is the minimum periodicity of color buffer swaps, + * measured in video frame periods, and is not guaranteed to be successful. + * + * A video frame period is the time required to display a full frame of video data. + * + * @param sync true to synchronize; false to ignore synchronization + */ + public static void setSwapInterval(int value) { + synchronized (GlobalLock.lock) { + swap_interval = value; + if (isCreated()) + Context.setSwapInterval(swap_interval); + } + } + + + /** + * Enable or disable vertical monitor synchronization. This call is a best-attempt at changing + * the vertical refresh synchronization of the monitor, and is not guaranteed to be successful. + * @param sync true to synchronize; false to ignore synchronization + */ + public static void setVSyncEnabled(boolean sync) { + synchronized (GlobalLock.lock) { + setSwapInterval(sync ? 1 : 0); + } + } + + /** + * Set the window's location. This is a no-op on fullscreen windows. + * The window is clamped to remain entirely on the screen. If you attempt + * to position the window such that it would extend off the screen, the window + * is simply placed as close to the edge as possible. + *
noteIf no location has been specified (or x == y == -1) the window will be centered + * @param x The new window location on the x axis + * @param y The new window location on the y axis + */ + public static void setLocation(int new_x, int new_y) { + synchronized (GlobalLock.lock) { + if (fullscreen) { + return; + } + + // cache position + x = new_x; + y = new_y; + + // offset if already created + if(isCreated()) { + display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight()); + } + } + } + + /** + * Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2", + * "Radeon9700". If the adapter cannot be determined, this function returns null. + * @return a String + */ + public static String getAdapter() { + synchronized (GlobalLock.lock) { + return display_impl.getAdapter(); + } + } + + /** + * Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined, + * this function returns null. + * @return a String + */ + public static String getVersion() { + synchronized (GlobalLock.lock) { + return display_impl.getVersion(); + } + } + + + /** + * Sets one or more icons for the Display. + *

+ * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + *

+ * NOTE: The display will make a deep copy of the supplied byte buffer array, for the purpose + * of recreating the icons when you go back and forth fullscreen mode. You therefore only need to + * set the icon once per instance. + * + * @param icons Array of icons in RGBA mode. Pass the icons in order of preference. + * @return number of icons used, or 0 if display hasn't been created + */ + public static int setIcon(ByteBuffer[] icons) { + synchronized (GlobalLock.lock) { + // make deep copy so we dont rely on the supplied buffers later on + // don't recache! + if(cached_icons != icons) { + cached_icons = new ByteBuffer[icons.length]; + for(int i=0;i + *

  • On Windows you should supply at least one 16x16 icon and one 32x32.
  • + *
  • Linux (and similar platforms) expect one 32x32 icon.
  • + *
  • Mac OS X should be supplied one 128x128 icon
  • + * + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public int setIcon(ByteBuffer[] icons); +} diff --git a/src/java/org/lwjgl/d3d/DisplayMode.java b/src/java/org/lwjgl/d3d/DisplayMode.java new file mode 100644 index 00000000..f429685c --- /dev/null +++ b/src/java/org/lwjgl/d3d/DisplayMode.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** +* +* This class encapsulates the properties for a given display mode. +* This class is not instantiable, and is aquired from the Display. +* getAvailableDisplayModes() method. +* +* @author cix_foo +* @version $Revision: 2286 $ +* $Id: DisplayMode.java 2286 2006-03-23 19:32:21Z matzon $ +*/ + +public class DisplayMode { + + /** properties of the display mode */ + private final int width, height, bpp, freq; + /** If true, this instance can be used for fullscreen modes */ + private final boolean fullscreen; + + /** + * Construct a display mode. DisplayModes constructed through the + * public constructor can only be used to specify the dimensions of + * the Display in windowed mode. To get the available DisplayModes for + * fullscreen modes, use Display.getAvailableDisplayModes(). + * + * @param width The Display width. + * @param height The Display height. + * @see Display + */ + public DisplayMode(int width, int height) { + this(width, height, 0, 0, false); + } + + DisplayMode(int width, int height, int bpp, int freq) { + this(width, height, bpp, freq, true); + } + + private DisplayMode(int width, int height, int bpp, int freq, boolean fullscreen) { + this.width = width; + this.height = height; + this.bpp = bpp; + this.freq = freq; + this.fullscreen = fullscreen; + } + + /** True iff this instance can be used for fullscreen modes */ + boolean isFullscreen() { + return fullscreen; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public int getBitsPerPixel() { + return bpp; + } + + public int getFrequency() { + return freq; + } + + /** + * Tests for DisplayMode equality + * + * @see java.lang.Object#equals(Object) + */ + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof DisplayMode)) { + return false; + } + + DisplayMode dm = (DisplayMode) obj; + return dm.width == width + && dm.height == height + && dm.bpp == bpp + && dm.freq == freq; + } + + /** + * Retrieves the hashcode for this object + * + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return width ^ height ^ freq ^ bpp; + } + + /** + * Retrieves a String representation of this DisplayMode + * + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer sb = new StringBuffer(32); + sb.append(width); + sb.append(" x "); + sb.append(height); + sb.append(" x "); + sb.append(bpp); + sb.append(" @"); + sb.append(freq); + sb.append("Hz"); + return sb.toString(); + } +} diff --git a/src/java/org/lwjgl/d3d/Drawable.java b/src/java/org/lwjgl/d3d/Drawable.java new file mode 100644 index 00000000..0d6e0f02 --- /dev/null +++ b/src/java/org/lwjgl/d3d/Drawable.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * The Drawable interface describes an OpenGL drawable with an associated + * Context. + * + * @author elias_naur + */ + +public interface Drawable { + Context getContext(); +} diff --git a/src/java/org/lwjgl/d3d/EventQueue.java b/src/java/org/lwjgl/d3d/EventQueue.java new file mode 100644 index 00000000..5defcd43 --- /dev/null +++ b/src/java/org/lwjgl/d3d/EventQueue.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * A java implementation of a LWJGL compatible event queue. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +class EventQueue { + private static final int QUEUE_SIZE = 200; + + private final int event_size; + + private final ByteBuffer queue; + + protected EventQueue(int event_size) { + this.event_size = event_size; + this.queue = ByteBuffer.allocate(QUEUE_SIZE*event_size); + } + + protected synchronized void clearEvents() { + queue.clear(); + } + + /** + * Copy available events into the specified buffer. + */ + public synchronized void copyEvents(ByteBuffer dest) { + queue.flip(); + int old_limit = queue.limit(); + if (dest.remaining() < queue.remaining()) + queue.limit(dest.remaining() + queue.position()); + dest.put(queue); + queue.limit(old_limit); + queue.compact(); + } + + /** + * Put an event into the queue. + * @return true if the event fitted into the queue, false otherwise + */ + public synchronized boolean putEvent(ByteBuffer event) { + if (event.remaining() != event_size) + throw new IllegalArgumentException("Internal error: event size " + event_size + " does not equal the given event size " + event.remaining()); + if (queue.remaining() >= event.remaining()) { + queue.put(event); + return true; + } else + return false; + } +} diff --git a/src/java/org/lwjgl/d3d/GUID.java b/src/java/org/lwjgl/d3d/GUID.java new file mode 100644 index 00000000..167ebc4a --- /dev/null +++ b/src/java/org/lwjgl/d3d/GUID.java @@ -0,0 +1,26 @@ +package org.lwjgl.d3d; + +public class GUID { + public long Data1; //4 DWORD + public short Data2; //2 WORD + public short Data3; //2 WORD + public byte Data4[] = new byte[8]; //8 BYTE + + public String toString() { + return + "\nGUID = " + padDigits(Integer.toHexString((int)Data1).toUpperCase(), 8) + "-" + + padDigits(Integer.toHexString(Data2).toUpperCase(), 4) + "-" + + padDigits(Integer.toHexString(Data3).toUpperCase(), 4) + "-" + + padDigits(Integer.toHexString(((((int)Data4[0]) << 8) + ((int)Data4[1])) & 0xFFFF).toUpperCase(), 4) + "-" + + padDigits(Integer.toHexString((((int)Data4[2]) << 24) + (((int)Data4[3]) << 16) + (((int)Data4[4]) << 8) + ((int)Data4[5])).toUpperCase(), 8) + + padDigits(Integer.toHexString(((((int)Data4[6]) << 8) + ((int)Data4[7])) & 0xFFFF).toUpperCase(), 4); + } + + private String padDigits(String source, int size) { + while(source.length() < size) { + source = "0" + source; + } + + return source; + } +} diff --git a/src/java/org/lwjgl/d3d/GlobalLock.java b/src/java/org/lwjgl/d3d/GlobalLock.java new file mode 100644 index 00000000..1910ec36 --- /dev/null +++ b/src/java/org/lwjgl/d3d/GlobalLock.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This class contains the global lock that LWJGL will use to + * synchronize access to Display. + */ +final class GlobalLock { + final static Object lock = new Object(); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3D9.java b/src/java/org/lwjgl/d3d/IDirect3D9.java new file mode 100644 index 00000000..9abbb5e5 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3D9.java @@ -0,0 +1,259 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.LongBuffer; + +import org.lwjgl.BufferChecks; + +/** + * + * @author Mark + * + */ +public final class IDirect3D9 { + private long iDirect3D9; + + /** + * Constructor for creating a Direct3D9 interface. + * + * @param iDirect3D9 A pointer to the native interface. + */ + private IDirect3D9(long iDirect3D9) { + this.iDirect3D9 = iDirect3D9; + } + /** + * HRESULT CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, + * D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat); + * + * @param adapter + * @param deviceType + * @param adapterFormat + * @param renderTargetFormat + * @param depthStencilFormat + * @return + */ + public final long checkDepthStencilMatch(int adapter, int deviceType, int adapterFormat, + int renderTargetFormat, int depthStencilFormat){ + return nCheckDepthStencilMatch(iDirect3D9, adapter, deviceType, adapterFormat, renderTargetFormat, depthStencilFormat); + } + /** + *HRESULT CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, + * DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat); + * + * @param adapter + * @param deviceType + * @param adapterFormat + * @param usage + * @param resoruceType + * @param checkFormat + * @return + */ + public final long checkDeviceFormat(int adapter, int deviceType, int adapterFormat, + int usage, int resoruceType, int checkFormat){ + return nCheckDeviceFormat(iDirect3D9, adapter, deviceType, adapterFormat, usage, resoruceType, checkFormat); + } + /** + *HRESULT CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, + * D3DFORMAT TargetFormat); + * + * @param adapter + * @param deviceType + * @param sourceFormat + * @param targetFormat + * @return + */ + public final long checkDeviceFormatConversion(int adapter, int deviceType, int sourceFormat, int targetFormat){ + return nCheckDeviceFormatConversion(iDirect3D9, adapter, deviceType, sourceFormat, targetFormat); + } + /** + * HRESULT CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, + * BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels); + * + * @param adapter + * @param deviceType + * @param surfaceFormat + * @param windowed + * @param multiSampleType + * @param qualityLevels + * @return + */ + public final long checkDeviceMultiSampleType(int adapter, int deviceType, int surfaceFormat, + boolean windowed, int multiSampleType, IntBuffer qualityLevels){ + if(qualityLevels != null) { + BufferChecks.checkBuffer(qualityLevels, 1); + } + + return nCheckDeviceMultiSampleType(iDirect3D9, adapter, deviceType, surfaceFormat, windowed, multiSampleType, qualityLevels); + } + /** + * HRESULT CheckDeviceType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT DisplayFormat, + * D3DFORMAT BackBufferFormat, BOOL Windowed); + * + * @param adapter + * @param deviceType + * @param displayFormat + * @param backBufferFormat + * @param windowed + * @return + */ + public final long checkDeviceType(int adapter, int deviceType, int displayFormat, + int backBufferFormat, boolean windowed){ + return nCheckDeviceType(iDirect3D9, adapter, deviceType, displayFormat, backBufferFormat, windowed); + } + /** + * HRESULT CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, + * D3DPRESENT_PARAMETERS * pPresentationParameters, + * IDirect3DDevice9 ** ppReturnedDeviceInterface); + * + * @param adapter + * @param deviceType + * @param focusWindow + * @param behaviorFlags + * @param presentationParameters + * @param returnedDeviceInterface + * @return + */ + public final long createDevice(int adapter, int deviceType, long focusWindow, int behaviorFlags, + D3DPresentParameters presentationParameters, IDirect3DDevice9 returnedDeviceInterface){ + return nCreateDevice(iDirect3D9, adapter, deviceType, focusWindow, behaviorFlags, presentationParameters.getBuffer(), returnedDeviceInterface); + } + /** + * HRESULT EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode); + * + * @param adapter + * @param format + * @param modeIndex + * @param mode + * @return + */ + public final long enumAdapterModes(int adapter, int format, int modeIndex, D3DDisplaymode mode){ + return nEnumAdapterModes(iDirect3D9, adapter, format, modeIndex, mode.getEmptyBuffer()); + } + /** + * UINT GetAdapterCount(); + * + * @return + */ + public final int getAdapterCount(){ + return nGetAdapterCount(iDirect3D9); + } + /** + * HRESULT GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE * pMode); + * + * @param adapter + * @param mode + * @return + */ + public final long getAdapterDisplayMode(int adapter, D3DDisplaymode mode){ + ByteBuffer buffer = mode.getEmptyBuffer(); + long result = nGetAdapterDisplayMode(iDirect3D9, adapter, buffer); + mode.setBuffer(buffer); + + return result; + } + /** + * HRESULT GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9 * pIdentifier); + * + * @param adapter + * @param flags + * @param identifier + * @return + */ + public final long getAdapterIdentifier(int adapter, int flags, D3DAdapterIdentifier9 identifier){ + ByteBuffer buffer = identifier.getEmptyBuffer(); + long result = nGetAdapterIdentifier(iDirect3D9, adapter, flags, buffer); + identifier.setBuffer(buffer); + + return result; + } + /** + * UINT GetAdapterModeCount(UINT Adapter, D3DFORMAT Format); + * + * @param adapter + * @param format + * @return + */ + public final int getAdapterModeCount(int adapter, int format){ + return nGetAdapterModeCount(iDirect3D9, adapter, format); + } + /** + * HMONITOR GetAdapterMonitor(UINT Adapter); + * + * @param adapter + * @return + */ + public final long getAdapterMonitor(int adapter){ + return nGetAdapterMonitor(iDirect3D9, adapter); + } + /** + * HRESULT GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9 * pCaps); + * + * @param adapter + * @param deviceType + * @param caps + * @return + */ + public final long getDeviceCaps(int adapter, int deviceType, D3DCaps9 caps){ + ByteBuffer buffer = caps.getEmptyBuffer(); + long result = nGetDeviceCaps(iDirect3D9, adapter, deviceType, buffer); + caps.setBuffer(buffer); + + return result; + } + /** + * HRESULT RegisterSoftwareDevice(void * pInitializeFunction); + * + * @return + */ + public final long registerSoftwareDevice(){ + throw new UnsupportedOperationException("Not implemented yet."); + } + + /** + * Release the native resources associated with this interface. + * To get another interface, a new call to create needs to be made. + * + */ + public final void release() { + nRelease(iDirect3D9); + } + /** + * Create the Direct3D interface and store the pointer to the native interface in this class. + * + * @return A IDirect3D9 class representing the native interface. + */ + public final static IDirect3D9 create() { + long tempiDirect3D9 = nCreate(); + + return new IDirect3D9(tempiDirect3D9); + } + + /** + * Get the pointer to the native interface. + * + * @return The pointer to the native interface. + */ + public final long getIDirect3D9() { + return iDirect3D9; + } + + //native methods + private final native long nCheckDepthStencilMatch(long iDirect3D9, int adapter, int deviceType, int adapterFormat, int renderTargetFormat, int depthStencilFormat); + private final native long nCheckDeviceFormat(long iDirect3D9, int adapter, int deviceType, int adapterFormat, int usage, int resoruceType, int checkFormat); + private final native long nCheckDeviceFormatConversion(long iDirect3D9, int adapter, int deviceType, int sourceFormat, int targetFormat); + private final native long nCheckDeviceMultiSampleType(long iDirect3D9, int adapter, int deviceType, int surfaceFormat, boolean windowed, int multiSampleType, IntBuffer qualityLevels); + private final native long nCheckDeviceType(long iDirect3D9, int adapter, int deviceType, int displayFormat, int backBufferFormat, boolean windowed); + private final native long nCreateDevice(long iDirect3D9, int adapter, int deviceType, long focusWindow, int behaviorFlags, ByteBuffer presentationParameters, IDirect3DDevice9 returnedDeviceInterface); + private final native long nEnumAdapterModes(long iDirect3D9, int adapter, int format, int modeIndex, ByteBuffer mode); + private final native int nGetAdapterCount(long iDirect3D9); + private final native long nGetAdapterDisplayMode(long iDirect3D9, int adapter, ByteBuffer mode); + private final native long nGetAdapterIdentifier(long iDirect3D9, int adapter, int flags, ByteBuffer identifier); + private final native int nGetAdapterModeCount(long iDirect3D9, int adapter, int format); + private final native long nGetAdapterMonitor(long iDirect3D9, int adapter); + private final native long nGetDeviceCaps(long iDirect3D9, int adapter, int deviceType, ByteBuffer caps); + private final native long nRegisterSoftwareDevice(long iDirect3D9); + private final native void nRelease(long iDirect3D9); + private static native long nCreate(); + +} diff --git a/src/java/org/lwjgl/d3d/IDirect3D9Ex.java b/src/java/org/lwjgl/d3d/IDirect3D9Ex.java new file mode 100644 index 00000000..3f848d79 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3D9Ex.java @@ -0,0 +1,37 @@ +package org.lwjgl.d3d; + +public class IDirect3D9Ex { + private long iDirect3D9Ex; + //HRESULT CreateDeviceEx(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, + // D3DPRESENT_PARAMETERS* pPresentationParameters, + // D3DDISPLAYMODEEX *pFullscreenDisplayMode, IDirect3DDevice9Ex **ppReturnedDeviceInterface); + public long CreateDeviceEx(int adapter, int deviceType, long focusWindow, long behaviorFlags, + D3DPresentParameters presentationParameters, D3DDisplaymodeEx fullscreenDisplayMode, + IDirect3DDevice9Ex returnedDeviceInterface){ + return nCreateDeviceEx(iDirect3D9Ex, adapter, deviceType, focusWindow, behaviorFlags, + presentationParameters, fullscreenDisplayMode, returnedDeviceInterface); + } + //HRESULT EnumAdapterModesEx(UINT Adapter, CONST D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode); + public long EnumAdapterModesEx(int adapter, D3DDisplaymodeFilter filter, int mode, D3DDisplaymodeEx displayMode){ + return nEnumAdapterModesEx(iDirect3D9Ex, adapter, filter, mode, displayMode); + } + //HRESULT GetAdapterDisplayModeEx(UINT Adapter, D3DDISPLAYMODEEX * pMode, D3DDISPLAYROTATION * pRotation); + public long GetAdapterDisplayModeEx(int adapter, D3DDisplaymodeEx mode, int rotation){ + return nGetAdapterDisplayModeEx(iDirect3D9Ex, adapter, mode, rotation); + } + //HRESULT GetAdapterLUID(UINT Adapter, LUID *pLUID); + public long GetAdapterLUID(int adapter, LUID LUID){ + return nGetAdapterLUID(iDirect3D9Ex, adapter, LUID); + } + //UINT GetAdapterModeCountEx(UINT Adapter, CONST D3DDISPLAYMODEFILTER* pFilter); + public int GetAdapterModeCountEx(int adapter, D3DDisplaymodeFilter filter){ + return nGetAdapterModeCountEx(iDirect3D9Ex, adapter, filter); + } + + //natives + private native long nCreateDeviceEx(long iDirect3D9Ex, int adapter, int deviceType, long focusWindow, long behaviorFlags, D3DPresentParameters presentationParameters, D3DDisplaymodeEx fullscreenDisplayMode, IDirect3DDevice9Ex returnedDeviceInterface); + private native long nEnumAdapterModesEx(long iDirect3D9Ex, int adapter, D3DDisplaymodeFilter filter, int mode, D3DDisplaymodeEx displayMode); + private native long nGetAdapterDisplayModeEx(long iDirect3D9Ex, int adapter, D3DDisplaymodeEx mode, int rotation); + private native long nGetAdapterLUID(long iDirect3D9Ex, int adapter, LUID LUID); + private native int nGetAdapterModeCountEx(long iDirect3D9Ex, int adapter, D3DDisplaymodeFilter filter); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DBaseTexture9.java b/src/java/org/lwjgl/d3d/IDirect3DBaseTexture9.java new file mode 100644 index 00000000..10d448cf --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DBaseTexture9.java @@ -0,0 +1,44 @@ +package org.lwjgl.d3d; + +public class IDirect3DBaseTexture9 { + private long iDirect3DBaseTexture9; + //VOID GenerateMipSubLevels(); + public void GenerateMipSubLevels(){ + nGenerateMipSubLevels(iDirect3DBaseTexture9); + } + //D3DTEXTUREFILTERTYPE GetAutoGenFilterType(); + public int GetAutoGenFilterType(){ + return nGetAutoGenFilterType(iDirect3DBaseTexture9); + } + //DWORD GetLevelCount(); + public long GetLevelCount(){ + return nGetLevelCount(iDirect3DBaseTexture9); + } + //DWORD GetLOD(); + public long GetLOD(){ + return nGetLOD(iDirect3DBaseTexture9); + } + //HRESULT SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType); + public long SetAutoGenFilterType(int filterType){ + return nSetAutoGenFilterType(iDirect3DBaseTexture9, filterType); + } + //DWORD SetLOD(DWORD LODNew); + public long SetLOD(long LODNew){ + return nSetLOD(iDirect3DBaseTexture9, LODNew); + } + + public long getIDirect3DBaseTexture9() { + return iDirect3DBaseTexture9; + } + public void setIDirect3DBaseTexture9(long direct3DBaseTexture9) { + iDirect3DBaseTexture9 = direct3DBaseTexture9; + } + + //natives + private native void nGenerateMipSubLevels(long iDirect3DBaseTexture9); + private native int nGetAutoGenFilterType(long iDirect3DBaseTexture9); + private native long nGetLevelCount(long iDirect3DBaseTexture9); + private native long nGetLOD(long iDirect3DBaseTexture9); + private native long nSetAutoGenFilterType(long iDirect3DBaseTexture9, int filterType); + private native long nSetLOD(long iDirect3DBaseTexture9, long LODNew); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DCubeTexture9.java b/src/java/org/lwjgl/d3d/IDirect3DCubeTexture9.java new file mode 100644 index 00000000..8ff925ee --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DCubeTexture9.java @@ -0,0 +1,38 @@ +package org.lwjgl.d3d; + +public class IDirect3DCubeTexture9 { + private long iDirect3DCubeTexture9; + //HRESULT AddDirtyRect(D3DCUBEMAP_FACES FaceType, CONST RECT * pDirtyRect); + public long AddDirtyRect(int faceType, Rectangle dirtyRect){ + return nAddDirtyRect(iDirect3DCubeTexture9, faceType, dirtyRect); + } + //HRESULT GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9 ** ppCubeMapSurface); + public long GetCubeMapSurface(int faceType, int level, IDirect3DSurface9 cubeMapSurface){ + return nGetCubeMapSurface(iDirect3DCubeTexture9, faceType, level, cubeMapSurface); + } + //HRESULT GetLevelDesc(UINT Level, D3DSURFACE_DESC * pDesc); + public long GetLevelDesc(int level, D3DSsurfaceDesc desc){ + return nGetLevelDesc(iDirect3DCubeTexture9, level, desc); + } + //HRESULT LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT * pLockedRect, CONST RECT * pRect, DWORD Flags); + public long LockRect(int faceType, int level, D3DLockedRect lockedRect, Rectangle rect, long flags){ + return nLockRect(iDirect3DCubeTexture9, faceType, level, lockedRect, rect, flags); + } + //HRESULT UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level); + public long UnlockRect(int faceType, int level){ + return nUnlockRect(iDirect3DCubeTexture9, faceType, level); + } + + public long getIDirect3DCubeTexture9() { + return iDirect3DCubeTexture9; + } + public void setIDirect3DCubeTexture9(long direct3DCubeTexture9) { + iDirect3DCubeTexture9 = direct3DCubeTexture9; + } + //natives + private native long nAddDirtyRect(long iDirect3DCubeTexture9, int faceType, Rectangle dirtyRect); + private native long nGetCubeMapSurface(long iDirect3DCubeTexture9, int faceType, int level, IDirect3DSurface9 cubeMapSurface); + private native long nGetLevelDesc(long iDirect3DCubeTexture9, int level, D3DSsurfaceDesc desc); + private native long nLockRect(long iDirect3DCubeTexture9, int faceType, int level, D3DLockedRect lockedRect, Rectangle rect, long flags); + private native long nUnlockRect(long iDirect3DCubeTexture9, int faceType, int level); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DDevice9.java b/src/java/org/lwjgl/d3d/IDirect3DDevice9.java new file mode 100644 index 00000000..330a003a --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DDevice9.java @@ -0,0 +1,1552 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.LongBuffer; +import java.nio.ShortBuffer; + +public class IDirect3DDevice9 { + private long iDirect3DDevice9; + /** + * TODO: done + * HRESULT BeginScene(); + * + * @return + */ + public final long beginScene(){ + return nBeginScene(iDirect3DDevice9); + } + /** + * TODO: test native + * HRESULT BeginStateBlock(); + * + * @return + */ + public final long beginStateBlock(){ + return nBeginStateBlock(iDirect3DDevice9); + } + /** + * TODO: done + * HRESULT Clear(DWORD Count, CONST D3DRECT * pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil); + * + * @param count + * @param rects + * @param flags + * @param color + * @param z + * @param stencil + * @return + */ + public final long clear(long count, LongBuffer rects, long flags, int color, float z, long stencil){ + return nClear(iDirect3DDevice9, count, rects, flags, color, z, stencil); + } + /** + * TODO: not tested + * HRESULT ColorFill(IDirect3DSurface9 * pSurface, CONST RECT * pRect, D3DCOLOR color); + * + * @param surface + * @param rect + * @param color + * @return + */ + public final long colorFill(IDirect3DSurface9 surface, Rectangle rect, int color){ + return nColorFill(iDirect3DDevice9, surface.getIDirect3DSurface9(), rect.getBuffer(), color); + } + /** + * TODO: not tested + * HRESULT CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, + * IDirect3DSwapChain9** ppSwapChain); + * + * @param presentationParameters + * @param swapChain + * @return + */ + public final long createAdditionalSwapChain(D3DPresentParameters presentationParameters, + IDirect3DSwapChain9 swapChain){ + return nCreateAdditionalSwapChain(iDirect3DDevice9, presentationParameters.getBuffer(), swapChain); + } + /** + * TODO: not tested + * HRESULT CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, + * IDirect3DCubeTexture9 ** ppCubeTexture, HANDLE* pSharedHandle); + * + * @param edgeLength + * @param levels + * @param usage + * @param format + * @param pool + * @param cubeTexture + * @param sharedHandle + * @return + */ + public final long createCubeTexture(int edgeLength, int levels, long usage, int format, int pool, + IDirect3DCubeTexture9 cubeTexture, long sharedHandle){ + return nCreateCubeTexture(iDirect3DDevice9, edgeLength, levels, usage, format, pool, cubeTexture, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, + * D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, + * IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle); + * + * @param width + * @param height + * @param format + * @param multiSample + * @param multiSampleQuality + * @param discard + * @param surface + * @param sharedHandle + * @return + */ + public final long createDepthStencilSurface(int width, int height, int format, + int multiSample, long multiSampleQuality, boolean discard, IDirect3DSurface9 surface, long sharedHandle){ + return nCreateDepthStencilSurface(iDirect3DDevice9, width, height, format, + multiSample, multiSampleQuality, discard, surface, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, + * IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle); + * + * @param length + * @param usage + * @param format + * @param pool + * @param indexBuffer + * @param sharedHandle + * @return + */ + public final long createIndexBuffer(int length, long usage, int format, int pool, + IDirect3DIndexBuffer9 indexBuffer, long sharedHandle){ + return nCreateIndexBuffer(iDirect3DDevice9, length, usage, format, pool, indexBuffer, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreateOffscreenPlainSurface(UINT Width, UINT Height, D3DFORMAT Format, DWORD Pool, + * IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle); + * + * @param width + * @param height + * @param format + * @param pool + * @param surface + * @param sharedHandle + * @return + */ + public final long createOffscreenPlainSurface(int width, int height, int format, long pool, + IDirect3DSurface9 surface, long sharedHandle){ + return nCreateOffscreenPlainSurface(iDirect3DDevice9, width, height, format, pool, surface, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreatePixelShader(CONST DWORD * pFunction, IDirect3DPixelShader9** ppShader); + * + * @param function + * @param shader + * @return + */ + public final long createPixelShader(long function, IDirect3DPixelShader9 shader){ + return nCreatePixelShader(iDirect3DDevice9, function, shader); + } + /** + * TODO: not tested + * HRESULT CreateQuery(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery); + * + * @param type + * @param query + * @return + */ + public final long createQuery(int type, IDirect3DQuery9 query){ + return nCreateQuery(iDirect3DDevice9, type, query); + } + /** + * TODO: not tested + * HRESULT CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, + * DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, + * HANDLE* pSharedHandle); + * + * @param width + * @param height + * @param format + * @param multiSample + * @param multiSampleQuality + * @param lockable + * @param surface + * @param sharedHandle + * @return + */ + public final long createRenderTarget(int width, int height, int format, + int multiSample, long multiSampleQuality, boolean lockable, + IDirect3DSurface9 surface, long sharedHandle){ + return nCreateRenderTarget(iDirect3DDevice9, width, height, format, multiSample, multiSampleQuality, lockable, surface, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreateStateBlock(D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB); + * + * @param type + * @param stateBlock + * @return + */ + public final long createStateBlock(int type, IDirect3DStateBlock9 stateBlock){ + return nCreateStateBlock(iDirect3DDevice9, type, stateBlock); + } + /** + * TODO: not tested + * HRESULT CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, + * IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle); + * + * @param width + * @param height + * @param levels + * @param usage + * @param format + * @param pool + * @param texture + * @param sharedHandle + * @return + */ + public final long createTexture(int width, int height, int levels, long usage, int format, + int pool, IDirect3DTexture9 texture, long sharedHandle){ + return nCreateTexture(iDirect3DDevice9, width, height, levels, usage, format, pool, texture, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, + * IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle); + * + * @param length + * @param usage + * @param FVF + * @param pool + * @param vertexBuffer + * @param sharedHandle + * @return + */ + public final long createVertexBuffer(int length, int usage, int FVF, int pool, + IDirect3DVertexBuffer9 vertexBuffer, long sharedHandle){ + return nCreateVertexBuffer(iDirect3DDevice9, length, usage, FVF, pool, vertexBuffer, sharedHandle); + } + /** + * TODO: not tested + * HRESULT CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl); + * + * @param vertexElements + * @param decl + * @return + */ + public final long createVertexDeclaration(D3DVertexElement9 vertexElements, IDirect3DVertexDeclaration9 decl){ + return nCreateVertexDeclaration(iDirect3DDevice9, vertexElements.getBuffer(), decl); + } + /** + * TODO: not tested + * HRESULT CreateVertexShader(CONST DWORD * pFunction, IDirect3DVertexShader9** ppShader); + * + * @param function + * @param shader + * @return + */ + public final long createVertexShader(long function, IDirect3DVertexShader9 shader){ + return nCreateVertexShader(iDirect3DDevice9, function, shader); + } + /** + * TODO: not tested + * HRESULT CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, + * D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle); + * + * @param width + * @param height + * @param depth + * @param levels + * @param usage + * @param format + * @param pool + * @param volumeTexture + * @param sharedHandle + * @return + */ + public final long createVolumeTexture(int width, int height, int depth, int levels, long usage, int format, + int pool, IDirect3DVolumeTexture9 volumeTexture, long sharedHandle){ + return nCreateVolumeTexture(iDirect3DDevice9, width, height, depth, levels, usage, format, pool, volumeTexture, sharedHandle); + } + /** + * TODO: not tested + * HRESULT DeletePatch(UINT Handle); + * + * @param handle + * @return + */ + public final long deletePatch(int handle){ + return nDeletePatch(iDirect3DDevice9, handle); + } + /** + * TODO: not tested + * HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, + * UINT NumVertices, UINT StartIndex, UINT PrimitiveCount); + * + * @param type + * @param baseVertexIndex + * @param minIndex + * @param numVertices + * @param startIndex + * @param primitiveCount + * @return + */ + public final long drawIndexedPrimitive(int type, int baseVertexIndex, int minIndex, + int numVertices, int startIndex, int primitiveCount){ + return nDrawIndexedPrimitive(iDirect3DDevice9, type, baseVertexIndex, minIndex, numVertices, startIndex, primitiveCount); + } + /** + * TODO: not tested + * HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, + * UINT PrimitiveCount, CONST void * pIndexData, D3DFORMAT IndexDataFormat, + * CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride); + * + * @param primitiveType + * @param minVertexIndex + * @param numVertices + * @param primitiveCount + * @param indexData + * @param indexDataFormat + * @param vertexStreamZeroData + * @param vertexStreamZeroStride + * @return + */ + public final long drawIndexedPrimitiveUP(int primitiveType, int minVertexIndex, int numVertices, + int primitiveCount, ByteBuffer indexData, int indexDataFormat, ByteBuffer vertexStreamZeroData, + int vertexStreamZeroStride){ + return nDrawIndexedPrimitiveUP(iDirect3DDevice9, primitiveType, minVertexIndex, numVertices, primitiveCount, indexData, + indexDataFormat, vertexStreamZeroData, vertexStreamZeroStride); + } + /** + * TODO: not tested + * HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount); + * + * @param primitiveType + * @param startVertex + * @param primitiveCount + * @return + */ + public final long drawPrimitive(int primitiveType, int startVertex, int primitiveCount){ + return nDrawPrimitive(iDirect3DDevice9, primitiveType, startVertex, primitiveCount); + } + /** + * TODO: done + * Ensure the the ByteBuffer vertexStreamZeroData is set to ByteOrder.nativeOrder() before putting + * any data into it. + * + * HRESULT DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, + * CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride); + * + * @param primitiveType + * @param primitiveCount + * @param vertexStreamZeroData + * @param vertexStreamZeroStride + * @return + */ + public final long drawPrimitiveUP(int primitiveType, int primitiveCount, ByteBuffer vertexStreamZeroData, + int vertexStreamZeroStride){ + return nDrawPrimitiveUP(iDirect3DDevice9, primitiveType, primitiveCount, vertexStreamZeroData, vertexStreamZeroStride); + } + /** + * TODO: not tested + * HRESULT DrawRectPatch(UINT Handle, const float* pNumSegs, const D3DRECTPATCH_INFO* pRectPatchInfo); + * + * @param handle + * @param numSegs + * @param rectPatchInfo + * @return + */ + public final long drawRectPatch(int handle, FloatBuffer numSegs, D3DRectPatchInfo rectPatchInfo){ + return nDrawRectPatch(iDirect3DDevice9, handle, numSegs, rectPatchInfo.getBuffer()); + } + /** + * TODO: not tested + * HRESULT DrawTriPatch(UINT Handle, const float* pNumSegs, const D3DTRIPATCH_INFO* pTriPatchInfo); + * + * @param handle + * @param numSegs + * @param triPatchInfo + * @return + */ + public final long drawTriPatch(int handle, FloatBuffer numSegs, D3DTriPatchInfo triPatchInfo){ + return nDrawTriPatch(iDirect3DDevice9, handle, numSegs, triPatchInfo.getBuffer()); + } + /** + * TODO: done + * HRESULT EndScene(); + * + * @return + */ + public final long endScene(){ + return nEndScene(iDirect3DDevice9); + } + /** + * TODO: not tested + * HRESULT EndStateBlock(IDirect3DStateBlock9 ** ppSB); + * + * @param stateBlock + * @return + */ + public final long endStateBlock(IDirect3DStateBlock9 stateBlock){ + return nEndStateBlock(iDirect3DDevice9, stateBlock); + } + /** + * TODO: not tested + * HRESULT EvictManagedResources(); + * + * @return + */ + public final long evictManagedResources(){ + return nEvictManagedResources(iDirect3DDevice9); + } + /** + * TODO: not tested + * UINT GetAvailableTextureMem(); + * + * @return + */ + public final int getAvailableTextureMem(){ + return nGetAvailableTextureMem(iDirect3DDevice9); + } + /** + * TODO: not tested + * HRESULT GetBackBuffer(UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, + * IDirect3DSurface9 ** ppBackBuffer); + * + * @param swapChain + * @param backBuffer + * @param type + * @param backBufferSurface + * @return + */ + public final long getBackBuffer(int swapChain, int backBuffer, int type, IDirect3DSurface9 backBufferSurface){ + return nGetBackBuffer(iDirect3DDevice9, swapChain, backBuffer, type, backBufferSurface); + } + /** + * TODO: not tested + * HRESULT GetClipPlane(DWORD Index, float * pPlane); + * + * @param index + * @param plane + * @return + */ + public final long getClipPlane(long index, FloatBuffer plane){ + return nGetClipPlane(iDirect3DDevice9, index, plane); + } + /** + * TODO: not tested + * HRESULT GetClipStatus(D3DCLIPSTATUS9 * pClipStatus); + * + * @param clipStatus + * @return + */ + public final long getClipStatus(D3DClipStatus9 clipStatus){ + return nGetClipStatus(iDirect3DDevice9, clipStatus.getBuffer()); + } + /** + * TODO: not tested + * HRESULT GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS * pParameters); + * + * @param parameters + * @return + */ + public final long getCreationParameters(D3DDeviceCreationParameters parameters){ + ByteBuffer buffer = parameters.getEmptyBuffer(); + long hResult = nGetCreationParameters(iDirect3DDevice9, buffer); + parameters.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT GetCurrentTexturePalette(UINT * pPaletteNumber); + * + * @param paletteNumber + * @return + */ + public final long getCurrentTexturePalette(IntBuffer paletteNumber){ + return nGetCurrentTexturePalette(iDirect3DDevice9, paletteNumber); + } + /** + * TODO: not tested + * HRESULT GetDepthStencilSurface(IDirect3DSurface9 ** ppZStencilSurface); + * + * @param zStencilSurface + * @return + */ + public final long getDepthStencilSurface(IDirect3DSurface9 zStencilSurface){ + return nGetDepthStencilSurface(iDirect3DDevice9, zStencilSurface); + } + /** + * TODO: not tested + * HRESULT GetDeviceCaps(D3DCAPS9 * pCaps); + * + * @param caps + * @return + */ + public final long getDeviceCaps(D3DCaps9 caps){ + ByteBuffer buffer = caps.getEmptyBuffer(); + long hResult = nGetDeviceCaps(iDirect3DDevice9, buffer); + caps.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT GetDirect3D(IDirect3D9 ** ppD3D9); + * + * @param D3D9 + * @return + */ + public final long getDirect3D(IDirect3D9 D3D9){ + return nGetDirect3D(iDirect3DDevice9, D3D9); + } + /** + * TODO: not tested + * HRESULT GetDisplayMode(UINT iSwapChain,D3DDISPLAYMODE * pMode); + * + * @param swapChain + * @param mode + * @return + */ + public final long getDisplayMode(int swapChain, D3DDisplaymode mode){ + ByteBuffer buffer = mode.getEmptyBuffer(); + long hResult = nGetDisplayMode(iDirect3DDevice9, swapChain, buffer); + mode.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT GetFrontBufferData(UINT iSwapChain, IDirect3DSurface9 * pDestSurface); + * + * @param swapChain + * @param destSurface + * @return + */ + public final long getFrontBufferData(int swapChain, IDirect3DSurface9 destSurface){ + return nGetFrontBufferData(iDirect3DDevice9, swapChain, destSurface.getIDirect3DSurface9()); + } + /** + * TODO: not tested + * HRESULT GetFVF(DWORD * pFVF); + * + * @param FVF + * @return + */ + public final long getFVF(IntBuffer FVF){ + return nGetFVF(iDirect3DDevice9, FVF); + } + /** + * TODO: not tested + * void GetGammaRamp(UINT iSwapChain, D3DGAMMARAMP * pRamp); + * + * @param swapChain + * @param ramp + * @return + */ + public void getGammaRamp(int swapChain, D3DGammaRamp ramp){ + ByteBuffer buffer = ramp.getBuffer(); + nGetGammaRamp(iDirect3DDevice9, swapChain, buffer); + ramp.setBuffer(buffer); + } + /** + * TODO: not tested + * HRESULT GetIndices(IDirect3DIndexBuffer9 ** ppIndexData); + * + * @param indexData + * @param baseVertexIndex + * @return + */ + public final long getIndices(IDirect3DIndexBuffer9 indexData){ + return nGetIndices(iDirect3DDevice9, indexData); + } + /** + * TODO: not tested + * HRESULT GetLight(DWORD Index, D3DLIGHT9 * pLight); + * + * @param index + * @param light + * @return + */ + public final long getLight(long index, D3DLight9 light){ + return nGetLight(iDirect3DDevice9, index, light); + } + /** + * TODO: not tested + * + * TODO revisit to see if there is a better way to pass back a boolean value through pointers + * HRESULT GetLightEnable(DWORD Index, BOOL * pEnable); + * + * @param index + * @param enable + * @return + */ + public final long getLightEnable(long index, ByteBuffer enable){ + return nGetLightEnable(iDirect3DDevice9, index, enable); + } + /** + * TODO: not tested + * HRESULT GetMaterial(D3DMATERIAL9 * pMaterial); + * + * @param material + * @return + */ + public final long getMaterial(D3DMaterial9 material){ + ByteBuffer buffer = material.getBuffer(); + long hResult = nGetMaterial(iDirect3DDevice9, buffer); + material.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * FLOAT GetNPatchMode(); + * + * @return + */ + public float GetNPatchMode(){ + return nGetNPatchMode(iDirect3DDevice9); + } + /** + * TODO: not tested + * UINT GetNumberOfSwapChains(); + * + * @return + */ + public final int getNumberOfSwapChains(){ + return nGetNumberOfSwapChains(iDirect3DDevice9); + } + /** + * TODO: not tested + * HRESULT GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY * pEntries); + * + * @param paletteNumber + * @param entries + * @return + */ + public final long getPaletteEntries(int paletteNumber, PaletteEntry entries){ + ByteBuffer buffer = entries.getBuffer(); + long hResult = nGetPaletteEntries(iDirect3DDevice9, paletteNumber, buffer); + entries.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT GetPixelShader(IDirect3DPixelShader9** ppShader); + * + * @param shader + * @return + */ + public final long getPixelShader(IDirect3DPixelShader9 shader){ + return nGetPixelShader(iDirect3DDevice9, shader); + } + /** + * TODO: not tested + * + * TODO revisit to see if there is a better way to pass back a boolean value through pointers + * HRESULT GetPixelShaderConstantB(UINT StartRegister, BOOL * pConstantData, UINT BoolCount); + * + * @param startRegister + * @param constantData + * @param boolCount + * @return + */ + public final long getPixelShaderConstantB(int startRegister, ByteBuffer constantData, int boolCount){ + return nGetPixelShaderConstantB(iDirect3DDevice9, startRegister, constantData, boolCount); + } + /** + * TODO: not tested + * HRESULT GetPixelShaderConstantF(UINT StartRegister, float * pConstantData, UINT Vector4fCount); + * + * @param startRegister + * @param constantData + * @param vector4fCount + * @return + */ + public final long getPixelShaderConstantF(int startRegister, FloatBuffer constantData, int vector4fCount){ + return nGetPixelShaderConstantF(iDirect3DDevice9, startRegister, constantData, vector4fCount); + } + /** + * TODO: not tested + * HRESULT GetPixelShaderConstantI(UINT StartRegister, int * pConstantData, UINT Vector4iCount); + * + * @param startRegister + * @param constantData + * @param vector4iCount + * @return + */ + public final long getPixelShaderConstantI(int startRegister, ShortBuffer constantData, int vector4iCount){ + return nGetPixelShaderConstantI(iDirect3DDevice9, startRegister, constantData, vector4iCount); + } + /** + * TODO: not tested + * HRESULT GetRasterStatus(UINT iSwapChain, D3DRASTER_STATUS * pRasterStatus); + * + * @param swapChain + * @param rasterStatus + * @return + */ + public final long getRasterStatus(int swapChain, D3DRasterStatus rasterStatus){ + ByteBuffer buffer = rasterStatus.getBuffer(); + long hResult = nGetRasterStatus(iDirect3DDevice9, swapChain, buffer); + rasterStatus.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT GetRenderState(D3DRENDERSTATETYPE State, DWORD * pValue); + * + * @param state + * @param value + * @return + */ + public final long getRenderState(int state, IntBuffer value){ + return nGetRenderState(iDirect3DDevice9, state, value); + } + /** + * TODO: not tested + * HRESULT GetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9 ** ppRenderTarget); + * + * @param renderTargetIndex + * @param renderTarget + * @return + */ + public final long getRenderTarget(long renderTargetIndex, IDirect3DSurface9 renderTarget){ + return nGetRenderTarget(iDirect3DDevice9, renderTargetIndex, renderTarget); + } + /** + * TODO: not tested + * HRESULT GetRenderTargetData(IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface); + * + * @param renderTarget + * @param destSurface + * @return + */ + public final long getRenderTargetData(IDirect3DSurface9 renderTarget, IDirect3DSurface9 destSurface){ + return nGetRenderTargetData(iDirect3DDevice9, renderTarget.getIDirect3DSurface9(), + destSurface.getIDirect3DSurface9()); + } + /** + * TODO: not tested + * HRESULT GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue); + * + * @param sampler + * @param type + * @param value + * @return + */ + public final long getSamplerState(long sampler, int type, LongBuffer value){ + return nGetSamplerState(iDirect3DDevice9, sampler, type, value); + } + /** + * TODO: not tested + * HRESULT GetScissorRect(RECT * pRect); + * + * @param rect + * @return + */ + public final long getScissorRect(Rectangle rect){ + ByteBuffer buffer = rect.getBuffer(); + long hResult = nGetScissorRect(iDirect3DDevice9, buffer); + rect.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * BOOL GetSoftwareVertexProcessing(); + * + * @return + */ + public boolean GetSoftwareVertexProcessing(){ + return nGetSoftwareVertexProcessing(iDirect3DDevice9); + } + /** + * TODO: not tested + * HRESULT GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9 ** ppStreamData, UINT * pOffsetInBytes, + * UINT * pStride); + * + * @param streamNumber + * @param streamData + * @param offsetInBytes + * @param stride + * @return + */ + public final long getStreamSource(int streamNumber, IDirect3DVertexBuffer9 streamData, ShortBuffer offsetInBytes, + ShortBuffer stride){ + return nGetStreamSource(iDirect3DDevice9, streamNumber, streamData, offsetInBytes, stride); + } + /** + * TODO: not tested + * HRESULT GetStreamSourceFreq(UINT StreamNumber, UINT* pDivider); + * + * @param streamNumber + * @param divider + * @return + */ + public final long getStreamSourceFreq(int streamNumber, ShortBuffer divider){ + return nGetStreamSourceFreq(iDirect3DDevice9, streamNumber, divider); + } + /** + * TODO: not tested + * HRESULT GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9 ** ppSwapChain); + * + * @param swapChainOrdinal + * @param swapChain + * @return + */ + public final long getSwapChain(int swapChainOrdinal, IDirect3DSwapChain9 swapChain){ + return nGetSwapChain(iDirect3DDevice9, swapChainOrdinal, swapChain); + } + /** + * TODO: not tested + * HRESULT GetTexture(DWORD Stage, IDirect3DBaseTexture9 ** ppTexture); + * + * @param stage + * @param texture + * @return + */ + public final long getTexture(long stage, IDirect3DBaseTexture9 texture){ + return nGetTexture(iDirect3DDevice9, stage, texture); + } + /** + * TODO: not tested + * HRESULT GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD * pValue); + * + * @param stage + * @param type + * @param value + * @return + */ + public final long getTextureStageState(long stage, int type, IntBuffer value){ + return nGetTextureStageState(iDirect3DDevice9, stage, type, value); + } + /** + * TODO: not tested + * //HRESULT GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX * pMatrix); + * + * @param state + * @param matrix + * @return + */ + public final long getTransform(int state, D3DMatrix matrix){ + ByteBuffer buffer = matrix.getBuffer(); + long hResult = nGetTransform(iDirect3DDevice9, state, buffer); + matrix.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl); + * + * @param vertexDecleration + * @return + */ + public final long getVertexDeclaration(IDirect3DVertexDeclaration9 vertexDecleration){ + return nGetVertexDeclaration(iDirect3DDevice9, vertexDecleration); + } + /** + * TODO: not tested + * HRESULT GetVertexShader(IDirect3DVertexShader9** ppShader); + * + * @param shader + * @return + */ + public final long getVertexShader(IDirect3DVertexShader9 shader){ + return nGetVertexShader(iDirect3DDevice9, shader); + } + /** + * TODO: not tested + * HRESULT GetVertexShaderConstantB(UINT StartRegister, BOOL * pConstantData, UINT BoolCount); + * + * @param startRegister + * @param constantData + * @param boolCount + * @return + */ + public final long getVertexShaderConstantB(int startRegister, ByteBuffer constantData, int boolCount){ + return nGetVertexShaderConstantB(iDirect3DDevice9, startRegister, constantData, boolCount); + } + /** + * TODO: not tested + * HRESULT GetVertexShaderConstantF(UINT StartRegister, float * pConstantData, UINT Vector4fCount); + * + * @param startRegister + * @param constantData + * @param vector4fCount + * @return + */ + public final long getVertexShaderConstantF(int startRegister, FloatBuffer constantData, int vector4fCount){ + return nGetVertexShaderConstantF(iDirect3DDevice9, startRegister, constantData, vector4fCount); + } + /** + * TODO: not tested + * HRESULT GetVertexShaderConstantI(UINT StartRegister, int * pConstantData, UINT Vector4iCount); + * + * @param startRegister + * @param constantData + * @param vector4iCount + * @return + */ + public final long getVertexShaderConstantI(int startRegister, IntBuffer constantData, int vector4iCount){ + return nGetVertexShaderConstantI(iDirect3DDevice9, startRegister, constantData, vector4iCount); + } + /** + * TODO: not tested + * HRESULT GetViewport(D3DVIEWPORT9 * pViewport); + * + * @param viewport + * @return + */ + public final long getViewport(D3DViewport9 viewport){ + ByteBuffer buffer = viewport.getBuffer(); + long hResult = nGetViewport(iDirect3DDevice9, buffer); + viewport.setBuffer(buffer); + + return hResult; + } + /** + * TODO: not tested + * HRESULT LightEnable(DWORD LightIndex, BOOL bEnable); + * + * @param lightIndex + * @param enable + * @return + */ + public final long lightEnable(long lightIndex, boolean enable){ + return nLightEnable(iDirect3DDevice9, lightIndex, enable); + } + /** + * TODO: not tested + * HRESULT MultiplyTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX * pMatrix); + * + * @param state + * @param matrix + * @return + */ + public final long multiplyTransform(int state, D3DMatrix matrix){ + ByteBuffer buffer = matrix.getBuffer(); + long hResult = nMultiplyTransform(iDirect3DDevice9, state, buffer); + matrix.setBuffer(buffer); + + return hResult; + } + /** + * TODO: fix native side + * HRESULT Present(CONST RECT * pSourceRect, CONST RECT * pDestRect, HWND hDestWindowOverride, + * CONST RGNDATA * pDirtyRegion); + * + * @param sourceRect + * @param destRect + * @param destWindowOverride + * @param dirtyRegion + * @return + */ + public final long present(Rectangle sourceRect, Rectangle destRect, long destWindowOverride, + D3DRegionData dirtyRegion){ + ByteBuffer sourceRectBuffer = null; + if(sourceRect != null) { + sourceRectBuffer = sourceRect.getBuffer(); + } + ByteBuffer destRectBuffer = null; + if(destRect != null) { + destRectBuffer = destRect.getBuffer(); + } + ByteBuffer dirtyRegionBuffer = null; + if(dirtyRegion != null) { + dirtyRegionBuffer = dirtyRegion.getBuffer(); + } + return nPresent(iDirect3DDevice9, sourceRectBuffer, destRectBuffer, destWindowOverride, + dirtyRegionBuffer); + } + /** + * HRESULT ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9 * pDestBuffer, + * IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags); + * + * @param srcStartIndex + * @param destIndex + * @param vertexCount + * @param destBuffer + * @param vertexDecl + * @param flags + * @return + */ + public final long processVertices(int srcStartIndex, int destIndex, int vertexCount, + IDirect3DVertexBuffer9 destBuffer, IDirect3DVertexDeclaration9 vertexDecl, long flags){ + return nProcessVertices(iDirect3DDevice9, srcStartIndex, destIndex, vertexCount, + destBuffer.getIDirect3DVertexBuffer9(), vertexDecl.getIDirect3DVertexDeclaration9(), flags); + } + /** + * HRESULT Reset(D3DPRESENT_PARAMETERS* pPresentationParameters); + * + * @param presentationParameters + * @return + */ + public final long reset(D3DPresentParameters presentationParameters){ + ByteBuffer buffer = presentationParameters.getBuffer(); + long hResult = nReset(iDirect3DDevice9, presentationParameters); + presentationParameters.setBuffer(buffer); + + return hResult; + } + /** + * HRESULT SetClipPlane(DWORD Index, CONST float * pPlane); + * + * @param index + * @param plane + * @return + */ + public final long setClipPlane(long index, FloatBuffer plane){ + return nSetClipPlane(iDirect3DDevice9, index, plane); + } + /** + * HRESULT SetClipStatus(CONST D3DCLIPSTATUS9 * pClipStatus); + * + * @param clipStatus + * @return + */ + public final long setClipStatus(D3DClipStatus9 clipStatus){ + return nSetClipStatus(iDirect3DDevice9, clipStatus.getBuffer()); + } + /** + * HRESULT SetCurrentTexturePalette(UINT PaletteNumber); + * + * @param paletteNumber + * @return + */ + public final long setCurrentTexturePalette(int paletteNumber){ + return nSetCurrentTexturePalette(iDirect3DDevice9, paletteNumber); + } + /** + * void SetCursorPosition(INT X, INT Y, DWORD Flags); + * + * @param x + * @param y + * @param flags + */ + public final void SetCursorPosition(int x, int y, long flags){ + nSetCursorPosition(iDirect3DDevice9, x, y, flags); + } + /** + * HRESULT SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9 * pCursorBitmap); + * + * @param xHotSpot + * @param yHotSpot + * @param cursorBitmap + * @return + */ + public final long setCursorProperties(int xHotSpot, int yHotSpot, IDirect3DSurface9 cursorBitmap){ + return nSetCursorProperties(iDirect3DDevice9, xHotSpot, yHotSpot, cursorBitmap.getIDirect3DSurface9()); + } + /** + * HRESULT SetDepthStencilSurface(IDirect3DSurface9 * pNewZStencil); + * + * @param newZStencil + * @return + */ + public final long setDepthStencilSurface(IDirect3DSurface9 newZStencil){ + return nSetDepthStencilSurface(iDirect3DDevice9, newZStencil.getIDirect3DSurface9()); + } + /** + * HRESULT SetDialogBoxMode(BOOL bEnableDialogs); + * + * @param enableDialogs + * @return + */ + public final long setDialogBoxMode(boolean enableDialogs){ + return nSetDialogBoxMode(iDirect3DDevice9, enableDialogs); + } + /** + * TODO: done + * HRESULT SetFVF(DWORD FVF); + * + * @param FVF + * @return + */ + public final long setFVF(long FVF){ + return nSetFVF(iDirect3DDevice9, FVF); + } + /** + * void SetGammaRamp(UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP * pRamp); + * + * @param swapChain + * @param flags + * @param ramp + */ + public final void SetGammaRamp(int swapChain, long flags, D3DGammaRamp ramp){ + nSetGammaRamp(iDirect3DDevice9, swapChain, flags, ramp.getBuffer()); + } + /** + * HRESULT SetIndices(IDirect3DIndexBuffer9 * pIndexData); + * + * @param indexData + * @return + */ + public final long setIndices(IDirect3DIndexBuffer9 indexData){ + return nSetIndices(iDirect3DDevice9, indexData.getIDirect3DIndexBuffer9()); + } + /** + * HRESULT SetLight(DWORD Index, CONST D3DLIGHT9 * pLight); + * + * @param index + * @param light + * @return + */ + public final long setLight(long index, D3DLight9 light){ + return nSetLight(iDirect3DDevice9, index, light.getBuffer()); + } + /** + * HRESULT SetMaterial(CONST D3DMATERIAL9 * pMaterial); + * + * @param material + * @return + */ + public final long setMaterial(D3DMaterial9 material){ + return nSetMaterial(iDirect3DDevice9, material.getBuffer()); + } + /** + * HRESULT SetNPatchMode(float nSegments); + * + * @param segments + * @return + */ + public final long setNPatchMode(float segments){ + return nSetNPatchMode(iDirect3DDevice9, segments); + } + /** + * //HRESULT SetPaletteEntries(UINT PaletteNumber, CONST PALETTEENTRY * pEntries); + * + * @param paletteNumber + * @param entries + * @return + */ + public final long setPaletteEntries(int paletteNumber, PaletteEntry entries){ + return nSetPaletteEntries(iDirect3DDevice9, paletteNumber, entries.getBuffer()); + } + /** + * HRESULT SetPixelShader(IDirect3DPixelShader9* pShader); + * + * @param shader + * @return + */ + public final long setPixelShader(IDirect3DPixelShader9 shader){ + return nSetPixelShader(iDirect3DDevice9, shader.getIDirect3DPixelShader9()); + } + /** + * HRESULT SetPixelShaderConstantB(UINT StartRegister, CONST BOOL * pConstantData, UINT BoolCount); + * + * @param startRegister + * @param constantData + * @param boolCount + * @return + */ + public final long setPixelShaderConstantB(int startRegister, ByteBuffer constantData, int boolCount){ + return nSetPixelShaderConstantB(iDirect3DDevice9, startRegister, constantData, boolCount); + } + /** + * HRESULT SetPixelShaderConstantF(UINT StartRegister, CONST float * pConstantData, UINT Vector4fCount); + * + * @param startRegister + * @param constantData + * @param vector4fCount + * @return + */ + public final long setPixelShaderConstantF(int startRegister, FloatBuffer constantData, int vector4fCount){ + return nSetPixelShaderConstantF(iDirect3DDevice9, startRegister, constantData, vector4fCount); + } + /** + * HRESULT SetPixelShaderConstantI(UINT StartRegister, CONST int * pConstantData, UINT Vector4iCount); + * + * @param startRegister + * @param constantData + * @param vector4iCount + * @return + */ + public final long setPixelShaderConstantI(int startRegister, IntBuffer constantData, int vector4iCount){ + return nSetPixelShaderConstantI(iDirect3DDevice9, startRegister, constantData, vector4iCount); + } + /** + * HRESULT SetRenderState(D3DRENDERSTATETYPE State, DWORD Value); + * + * @param state + * @param value + * @return + */ + public final long setRenderState(int state, long value){ + return nSetRenderState(iDirect3DDevice9, state, value); + } + /** + * HRESULT SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9 * pRenderTarget); + * + * @param renderTargetIndex + * @param renderTarget + * @return + */ + public final long setRenderTarget(long renderTargetIndex, IDirect3DSurface9 renderTarget){ + return nSetRenderTarget(iDirect3DDevice9, renderTargetIndex, renderTarget.getIDirect3DSurface9()); + } + /** + * HRESULT SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value); + * + * @param sampler + * @param type + * @param value + * @return + */ + public final long setSamplerState(long sampler, int type, long value){ + return nSetSamplerState(iDirect3DDevice9, sampler, type, value); + } + /** + * HRESULT SetScissorRect(CONST RECT * pRect); + * + * @param rect + * @return + */ + public final long setScissorRect(Rectangle rect){ + return nSetScissorRect(iDirect3DDevice9, rect.getBuffer()); + } + /** + * HRESULT SetSoftwareVertexProcessing(BOOL bSoftware); + * + * @param software + * @return + */ + public final long setSoftwareVertexProcessing(boolean software){ + return nSetSoftwareVertexProcessing(iDirect3DDevice9, software); + } + /** + * HRESULT SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9 * pStreamData, UINT OffsetInBytes, + * UINT Stride); + * + * @param streamNumber + * @param streamData + * @param offsetInBytes + * @param stride + * @return + */ + public final long setStreamSource(int streamNumber, IDirect3DVertexBuffer9 streamData, int offsetInBytes, + int stride){ + return nSetStreamSource(iDirect3DDevice9, streamNumber, streamData.getIDirect3DVertexBuffer9(), offsetInBytes, stride); + } + /** + * HRESULT SetStreamSourceFreq(UINT StreamNumber, UINT FrequencyParameter); + * + * @param streamNumber + * @param frequencyParameter + * @return + */ + public final long setStreamSourceFreq(int streamNumber, int frequencyParameter){ + return nSetStreamSourceFreq(iDirect3DDevice9, streamNumber, frequencyParameter); + } + /** + * HRESULT SetTexture(DWORD Sampler, IDirect3DBaseTexture9 * pTexture); + * + * @param sampler + * @param texture + * @return + */ + public final long setTexture(long sampler, IDirect3DBaseTexture9 texture){ + return nSetTexture(iDirect3DDevice9, sampler, texture.getIDirect3DBaseTexture9()); + } + /** + * HRESULT SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value); + * + * @param stage + * @param type + * @param value + * @return + */ + public final long setTextureStageState(long stage, int type, long value){ + return nSetTextureStageState(iDirect3DDevice9, stage, type, value); + } + /** + * HRESULT SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX * pMatrix); + * + * @param state + * @param matrix + * @return + */ + public final long setTransform(int state, D3DMatrix matrix){ + return nSetTransform(iDirect3DDevice9, state, matrix.getBuffer()); + } + /** + * HRESULT SetVertexDeclaration(IDirect3DVertexDeclaration9 * pDecl); + * + * @param vertexDeclaration + * @return + */ + public final long setVertexDeclaration(IDirect3DVertexDeclaration9 vertexDeclaration){ + return nSetVertexDeclaration(iDirect3DDevice9, vertexDeclaration.getIDirect3DVertexDeclaration9()); + } + /** + * HRESULT SetVertexShader(IDirect3DVertexShader9* pShader); + * + * @param shader + * @return + */ + public final long setVertexShader(IDirect3DVertexShader9 shader){ + return nSetVertexShader(iDirect3DDevice9, shader.getIDirect3DVertexShader9()); + } + /** + * HRESULT SetVertexShaderConstantB(UINT StartRegister, CONST BOOL * pConstantData, UINT BoolCount); + * + * @param startRegister + * @param constantData + * @param boolCount + * @return + */ + public final long setVertexShaderConstantB(int startRegister, ByteBuffer constantData, int boolCount){ + return nSetVertexShaderConstantB(iDirect3DDevice9, startRegister, constantData, boolCount); + } + /** + * HRESULT SetVertexShaderConstantF(UINT StartRegister, CONST float * pConstantData, UINT Vector4fCount); + * + * @param startRegister + * @param constantData + * @param vector4fCount + * @return + */ + public final long setVertexShaderConstantF(int startRegister, FloatBuffer constantData, int vector4fCount){ + return nSetVertexShaderConstantF(iDirect3DDevice9, startRegister, constantData, vector4fCount); + } + /** + * HRESULT SetVertexShaderConstantI(UINT StartRegister, CONST int * pConstantData, UINT Vector4iCount); + * + * @param startRegister + * @param constantData + * @param vector4iCount + * @return + */ + public final long setVertexShaderConstantI(int startRegister, IntBuffer constantData, int vector4iCount){ + return nSetVertexShaderConstantI(iDirect3DDevice9, startRegister, constantData, vector4iCount); + } + /** + * HRESULT SetViewport(CONST D3DVIEWPORT9 * pViewport); + * + * @param viewport + * @return + */ + public final long setViewport(D3DViewport9 viewport){ + return nSetViewport(iDirect3DDevice9, viewport.getBuffer()); + } + /** + * BOOL ShowCursor(BOOL bShow); + * + * @param show + * @return + */ + public boolean ShowCursor(boolean show){ + return nShowCursor(iDirect3DDevice9, show); + } + /** + * HRESULT StretchRect(IDirect3DSurface9 * pSourceSurface, CONST RECT * pSourceRect, + * IDirect3DSurface9 * pDestSurface, CONST RECT * pDestRect, D3DTEXTUREFILTERTYPE Filter); + * + * @param sourceSurface + * @param sourceRect + * @param destSurface + * @param destRect + * @param filter + * @return + */ + public final long stretchRect(IDirect3DSurface9 sourceSurface, Rectangle sourceRect, + IDirect3DSurface9 destSurface, Rectangle destRect, int filter){ + return nStretchRect(iDirect3DDevice9, sourceSurface.getIDirect3DSurface9(), sourceRect.getBuffer(), + destSurface.getIDirect3DSurface9(), destRect.getBuffer(), filter); + } + /** + * HRESULT TestCooperativeLevel(); + * + * @return + */ + public final long tstCooperativeLevel(){ + return nTestCooperativeLevel(iDirect3DDevice9); + } + /** + * HRESULT UpdateSurface(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, + * IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestinationPoint); + * + * @param sourceSurface + * @param sourceRect + * @param destinationSurface + * @param destinationPoint + * @return + */ + public final long updateSurface(IDirect3DSurface9 sourceSurface, Rectangle sourceRect, IDirect3DSurface9 destinationSurface, Point destinationPoint){ + return nUpdateSurface(iDirect3DDevice9, sourceSurface.getIDirect3DSurface9(), sourceRect.getBuffer(), + destinationSurface.getIDirect3DSurface9(), destinationPoint.getBuffer()); + } + /** + * HRESULT UpdateTexture(IDirect3DBaseTexture9 * pSourceTexture, IDirect3DBaseTexture9 * pDestinationTexture); + * + * @param sourceTexture + * @param destinationTexture + * @return + */ + public final long updateTexture(IDirect3DBaseTexture9 sourceTexture, IDirect3DBaseTexture9 destinationTexture){ + return nUpdateTexture(iDirect3DDevice9, sourceTexture.getIDirect3DBaseTexture9(), destinationTexture.getIDirect3DBaseTexture9()); + } + /** + * HRESULT ValidateDevice(DWORD * pNumPasses); + * + * @param numPasses + * @return + */ + public final long validateDevice(IntBuffer numPasses){ + return nValidateDevice(iDirect3DDevice9, numPasses); + } + + /** + * TODO: done + * Release the native resources associated with this interface. + * A new call to org.lwjgl.d3d.IDirect3D9.createDevice() will have to be made to get a new interface. + * + */ + public final void release() { + nRelease(iDirect3DDevice9); + } + + //setters/getters + /** + * Get the pointer to the native interface. + * + * @return The pointer to the native interface. + */ + public final long getIDirect3DDevice9() { + return iDirect3DDevice9; + } + /** + * Set the pointer to the native interface. + * + * @param direct3DDevice9 The pointer to the native interface. + */ + public final void setIDirect3DDevice9(long direct3DDevice9) { + iDirect3DDevice9 = direct3DDevice9; + } + + //natives + private final native long nBeginScene(long iDirect3DDevice9); + private final native long nBeginStateBlock(long iDirect3DDevice9); + private final native long nClear(long iDirect3DDevice9, long count, LongBuffer rects, long flags, int color, float z, long stencil); + private final native long nColorFill(long iDirect3DDevice9, long surface, ByteBuffer rect, int color); + private final native long nCreateAdditionalSwapChain(long iDirect3DDevice9, ByteBuffer presentationParameters, IDirect3DSwapChain9 swapChain); + private final native long nCreateCubeTexture(long iDirect3DDevice9, int edgeLength, int levels, long usage, int format, int pool, IDirect3DCubeTexture9 cubeTexture, long sharedHandle); + private final native long nCreateDepthStencilSurface(long iDirect3DDevice9, int width, int height, int format, int multiSample, long multiSampleQuality, boolean discard, IDirect3DSurface9 surface, long sharedHandle); + private final native long nCreateIndexBuffer(long iDirect3DDevice9, int length, long usage, int format, int pool, IDirect3DIndexBuffer9 indexBuffer, long sharedHandle); + private final native long nCreateOffscreenPlainSurface(long iDirect3DDevice9, int width, int height, int format, long pool, IDirect3DSurface9 surface, long sharedHandle); + private final native long nCreatePixelShader(long iDirect3DDevice9, long function, IDirect3DPixelShader9 shader); + private final native long nCreateQuery(long iDirect3DDevice9, int type, IDirect3DQuery9 query); + private final native long nCreateRenderTarget(long iDirect3DDevice9, int width, int height, int format, int multiSample, long multiSampleQuality, boolean lockable, IDirect3DSurface9 surface, long sharedHandle); + private final native long nCreateStateBlock(long iDirect3DDevice9, int type, IDirect3DStateBlock9 stateBlock); + private final native long nCreateTexture(long iDirect3DDevice9, int width, int height, int levels, long usage, int format, int pool, IDirect3DTexture9 texture, long sharedHandle); + private final native long nCreateVertexBuffer(long iDirect3DDevice9, int length, int usage, int FVF, int pool, IDirect3DVertexBuffer9 vertexBuffer, long sharedHandle); + private final native long nCreateVertexDeclaration(long iDirect3DDevice9, ByteBuffer vertexElements, IDirect3DVertexDeclaration9 decl); + private final native long nCreateVertexShader(long iDirect3DDevice9, long function, IDirect3DVertexShader9 shader); + private final native long nCreateVolumeTexture(long iDirect3DDevice9, int width, int height, int depth, int levels, long usage, int format, int pool, IDirect3DVolumeTexture9 volumeTexture, long sharedHandle); + private final native long nDeletePatch(long iDirect3DDevice9, int handle); + private final native long nDrawIndexedPrimitive(long iDirect3DDevice9, int type, int baseVertexIndex, int minIndex, int numVertices, int startIndex, int primitiveCount); + private final native long nDrawIndexedPrimitiveUP(long iDirect3DDevice9, int primitiveType, int minVertexIndex, int numVertices, int primitiveCount, ByteBuffer indexData, int indexDataFormat, ByteBuffer vertexStreamZeroData, int vertexStreamZeroStride); + private final native long nDrawPrimitive(long iDirect3DDevice9, int primitiveType, int startVertex, int primitiveCount); + private final native long nDrawPrimitiveUP(long iDirect3DDevice9, int primitiveType, int primitiveCount, ByteBuffer vertexStreamZeroData, int vertexStreamZeroStride); + private final native long nDrawRectPatch(long iDirect3DDevice9, int handle, FloatBuffer numSegs, ByteBuffer rectPatchInfo); + private final native long nDrawTriPatch(long iDirect3DDevice9, int handle, FloatBuffer numSegs, ByteBuffer triPatchInfo); + private final native long nEndScene(long iDirect3DDevice9); + private final native long nEndStateBlock(long iDirect3DDevice9, IDirect3DStateBlock9 stateBlock); + private final native long nEvictManagedResources(long iDirect3DDevice9); + private final native int nGetAvailableTextureMem(long iDirect3DDevice9); + private final native long nGetBackBuffer(long iDirect3DDevice9, int swapChain, int backBuffer, int type, IDirect3DSurface9 backBufferSurface); + private final native long nGetClipPlane(long iDirect3DDevice9, long index, FloatBuffer plane); + private final native long nGetClipStatus(long iDirect3DDevice9, ByteBuffer clipStatus); + private final native long nGetCreationParameters(long iDirect3DDevice9, ByteBuffer parameters); + private final native long nGetCurrentTexturePalette(long iDirect3DDevice9, IntBuffer paletteNumber); + private final native long nGetDepthStencilSurface(long iDirect3DDevice9, IDirect3DSurface9 zStencilSurface); + private final native long nGetDeviceCaps(long iDirect3DDevice9, ByteBuffer caps); + private final native long nGetDirect3D(long iDirect3DDevice9, IDirect3D9 D3D9); + private final native long nGetDisplayMode(long iDirect3DDevice9, int swapChain, ByteBuffer mode); + private final native long nGetFrontBufferData(long iDirect3DDevice9, int swapChain, long destSurface); + private final native long nGetFVF(long iDirect3DDevice9, IntBuffer FVF); + private final native void nGetGammaRamp(long iDirect3DDevice9, int swapChain, ByteBuffer ramp); + private final native long nGetIndices(long iDirect3DDevice9, IDirect3DIndexBuffer9 indexData); + private final native long nGetLight(long iDirect3DDevice9, long index, D3DLight9 light); + private final native long nGetLightEnable(long iDirect3DDevice9, long index, ByteBuffer enable); + private final native long nGetMaterial(long iDirect3DDevice9, ByteBuffer material); + private final native float nGetNPatchMode(long iDirect3DDevice9); + private final native int nGetNumberOfSwapChains(long iDirect3DDevice9); + private final native long nGetPaletteEntries(long iDirect3DDevice9, int paletteNumber, ByteBuffer entries); + private final native long nGetPixelShader(long iDirect3DDevice9, IDirect3DPixelShader9 shader); + private final native long nGetPixelShaderConstantB(long iDirect3DDevice9, int startRegister, ByteBuffer constantData, int boolCount); + private final native long nGetPixelShaderConstantF(long iDirect3DDevice9, int startRegister, FloatBuffer constantData, int vector4fCount); + private final native long nGetPixelShaderConstantI(long iDirect3DDevice9, int startRegister, ShortBuffer constantData, int vector4iCount); + private final native long nGetRasterStatus(long iDirect3DDevice9, int swapChain, ByteBuffer rasterStatus); + private final native long nGetRenderState(long iDirect3DDevice9, int state, IntBuffer value); + private final native long nGetRenderTarget(long iDirect3DDevice9, long renderTargetIndex, IDirect3DSurface9 renderTarget); + private final native long nGetRenderTargetData(long iDirect3DDevice9, long renderTarget, long destSurface); + private final native long nGetSamplerState(long iDirect3DDevice9, long sampler, int type, LongBuffer value); + private final native long nGetScissorRect(long iDirect3DDevice9, ByteBuffer rect); + private final native boolean nGetSoftwareVertexProcessing(long iDirect3DDevice9); + private final native long nGetStreamSource(long iDirect3DDevice9, int streamNumber, IDirect3DVertexBuffer9 streamData, ShortBuffer offsetInBytes, ShortBuffer stride); + private final native long nGetStreamSourceFreq(long iDirect3DDevice9, int streamNumber, ShortBuffer divider); + private final native long nGetSwapChain(long iDirect3DDevice9, int swapChainOrdinal, IDirect3DSwapChain9 swapChain); + private final native long nGetTexture(long iDirect3DDevice9, long stage, IDirect3DBaseTexture9 texture); + private final native long nGetTextureStageState(long iDirect3DDevice9, long stage, int type, IntBuffer value); + private final native long nGetTransform(long iDirect3DDevice9, int state, ByteBuffer matrix); + private final native long nGetVertexDeclaration(long iDirect3DDevice9, IDirect3DVertexDeclaration9 vertexDecleration); + private final native long nGetVertexShader(long iDirect3DDevice9, IDirect3DVertexShader9 shader); + private final native long nGetVertexShaderConstantB(long iDirect3DDevice9, int startRegister, ByteBuffer constantData, int boolCount); + private final native long nGetVertexShaderConstantF(long iDirect3DDevice9, int startRegister, FloatBuffer constantData, int vector4fCount); + private final native long nGetVertexShaderConstantI(long iDirect3DDevice9, int startRegister, IntBuffer constantData, int vector4iCount); + private final native long nGetViewport(long iDirect3DDevice9, ByteBuffer viewport); + private final native long nLightEnable(long iDirect3DDevice9, long lightIndex, boolean enable); + private final native long nMultiplyTransform(long iDirect3DDevice9, int state, ByteBuffer matrix); + private final native long nPresent(long iDirect3DDevice9, ByteBuffer sourceRect, ByteBuffer destRect, long destWindowOverride, ByteBuffer dirtyRegion); + private final native long nProcessVertices(long iDirect3DDevice9, int srcStartIndex, int destIndex, int vertexCount, long destBuffer, long vertexDecl, long flags); + private final native long nReset(long iDirect3DDevice9, D3DPresentParameters presentationParameters); + private final native long nSetClipPlane(long iDirect3DDevice9, long index, FloatBuffer plane); + private final native long nSetClipStatus(long iDirect3DDevice9, ByteBuffer clipStatus); + private final native long nSetCurrentTexturePalette(long iDirect3DDevice9, int paletteNumber); + private final native void nSetCursorPosition(long iDirect3DDevice9, int x, int y, long flags); + private final native long nSetCursorProperties(long iDirect3DDevice9, int xHotSpot, int yHotSpot, long cursorBitmap); + private final native long nSetDepthStencilSurface(long iDirect3DDevice9, long newZStencil); + private final native long nSetDialogBoxMode(long iDirect3DDevice9, boolean enableDialogs); + private final native long nSetFVF(long iDirect3DDevice9, long FVF); + private final native void nSetGammaRamp(long iDirect3DDevice9, int swapChain, long flags, ByteBuffer ramp); + private final native long nSetIndices(long iDirect3DDevice9, long indexData); + private final native long nSetLight(long iDirect3DDevice9, long index, ByteBuffer light); + private final native long nSetMaterial(long iDirect3DDevice9, ByteBuffer material); + private final native long nSetNPatchMode(long iDirect3DDevice9, float segments); + private final native long nSetPaletteEntries(long iDirect3DDevice9, int paletteNumber, ByteBuffer entries); + private final native long nSetPixelShader(long iDirect3DDevice9, long shader); + private final native long nSetPixelShaderConstantB(long iDirect3DDevice9, int startRegister, ByteBuffer constantData, int boolCount); + private final native long nSetPixelShaderConstantF(long iDirect3DDevice9, int startRegister, FloatBuffer constantData, int vector4fCount); + private final native long nSetPixelShaderConstantI(long iDirect3DDevice9, int startRegister, IntBuffer constantData, int vector4iCount); + private final native long nSetRenderState(long iDirect3DDevice9, int state, long value); + private final native long nSetRenderTarget(long iDirect3DDevice9, long renderTargetIndex, long renderTarget); + private final native long nSetSamplerState(long iDirect3DDevice9, long sampler, int type, long value); + private final native long nSetScissorRect(long iDirect3DDevice9, ByteBuffer rect); + private final native long nSetSoftwareVertexProcessing(long iDirect3DDevice9, boolean software); + private final native long nSetStreamSource(long iDirect3DDevice9, int streamNumber, long streamData, int offsetInBytes, int stride); + private final native long nSetStreamSourceFreq(long iDirect3DDevice9, int streamNumber, int frequencyParameter); + private final native long nSetTexture(long iDirect3DDevice9, long sampler, long texture); + private final native long nSetTextureStageState(long iDirect3DDevice9, long stage, int type, long value); + private final native long nSetTransform(long iDirect3DDevice9, int state, ByteBuffer matrix); + private final native long nSetVertexDeclaration(long iDirect3DDevice9, long vertexDeclaration); + private final native long nSetVertexShader(long iDirect3DDevice9, long shader); + private final native long nSetVertexShaderConstantB(long iDirect3DDevice9, int startRegister, ByteBuffer constantData, int boolCount); + private final native long nSetVertexShaderConstantF(long iDirect3DDevice9, int startRegister, FloatBuffer constantData, int vector4fCount); + private final native long nSetVertexShaderConstantI(long iDirect3DDevice9, int startRegister, IntBuffer constantData, int vector4iCount); + private final native long nSetViewport(long iDirect3DDevice9, ByteBuffer viewport); + private final native boolean nShowCursor(long iDirect3DDevice9, boolean show); + private final native long nStretchRect(long iDirect3DDevice9, long sourceSurface, ByteBuffer sourceRect, long destSurface, ByteBuffer destRect, int filter); + private final native long nTestCooperativeLevel(long iDirect3DDevice9); + private final native long nUpdateSurface(long iDirect3DDevice9, long sourceSurface, ByteBuffer sourceRect, long destinationSurface, ByteBuffer destinationPoint); + private final native long nUpdateTexture(long iDirect3DDevice9, long sourceTexture, long destinationTexture); + private final native long nValidateDevice(long iDirect3DDevice9, IntBuffer numPasses); + private final native void nRelease(long iDirect3DDevice9); +} \ No newline at end of file diff --git a/src/java/org/lwjgl/d3d/IDirect3DDevice9Ex.java b/src/java/org/lwjgl/d3d/IDirect3DDevice9Ex.java new file mode 100644 index 00000000..50ccfb52 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DDevice9Ex.java @@ -0,0 +1,98 @@ +package org.lwjgl.d3d; + +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +public class IDirect3DDevice9Ex { + private long iDirect3DDevice9Ex; + //HRESULT CheckDeviceState(HWND hWindow); + public long CheckDeviceState(long window){ + return nCheckDeviceState(iDirect3DDevice9Ex, window); + } + //HRESULT CheckResourceResidency(IDirect3DResource9 * pResourceArray, UINT32 NumResources); + public long CheckResourceResidency(IDirect3DResource9 resourceArray, long numResources){ + return nCheckResourceResidency(iDirect3DDevice9Ex, resourceArray, numResources); + } + //HRESULT CreateDepthStencilSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, + // D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, + // IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage); + public long CreateDepthStencilSurfaceEx(int width, int height, int format, int multiSample, + long multisampleQuality, boolean discard, IDirect3DSurface9 surface, long sharedHandle, long usage){ + return nCreateDepthStencilSurfaceEx(iDirect3DDevice9Ex, width, height, format, multiSample, + multisampleQuality, discard, surface, sharedHandle, usage); + } + //HRESULT CreateOffscreenPlainSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, DWORD Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage); + public long CreateOffscreenPlainSurfaceEx(int width, int height, int format, long pool, + IDirect3DSurface9 surface, long sharedHandle, long usage){ + return nCreateOffscreenPlainSurfaceEx(iDirect3DDevice9Ex, width, height, format, pool, surface, + sharedHandle, usage); + } + //HRESULT CreateRenderTargetEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage); + public long CreateRenderTargetEx(int width, int height, int format, int multiSample, long multisampleQuality, boolean lockable, IDirect3DSurface9 surface, long sharedHandle, long usage){ + return nCreateRenderTargetEx(iDirect3DDevice9Ex, width, height, format, multiSample, multisampleQuality, + lockable, surface, sharedHandle, usage); + } + //HRESULT ComposeRect(IDirect3DSurface9 *pSource, IDirect3DSurface9 *pDestination, IDirect3DVertexBuffer9 *pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescriptors, D3DCOMPOSEOP Operation, INT XOffset, INT YOffset); + public long ComposeRect(IDirect3DSurface9 source, IDirect3DSurface9 destination, IDirect3DVertexBuffer9 srcRectDescriptors, int numRects, IDirect3DVertexBuffer9 dstRectDescriptors, int operation, int xOffset, int yOffset){ + return nComposeRect(iDirect3DDevice9Ex, source, destination, srcRectDescriptors, numRects, + dstRectDescriptors, operation, xOffset, yOffset); + } + //HRESULT GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation); + public long GetDisplayModeEx(int swapChain, D3DDisplaymodeEx mode, int rotation){ + return nGetDisplayModeEx(iDirect3DDevice9Ex, swapChain, mode, rotation); + } + //HRESULT GetGPUThreadPriority(INT *pPriority); + public long GetGPUThreadPriority(IntBuffer priority){ + return nGetGPUThreadPriority(iDirect3DDevice9Ex, priority); + } + //GetMaximumFrameLatency(UINT *pMaxLatency); + public long GetMaximumFrameLatency(IntBuffer maxLatency){ + return nGetMaximumFrameLatency(iDirect3DDevice9Ex, maxLatency); + } + //HRESULT PresentEx(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags); + public long PresentEx(Rectangle sourceRect, Rectangle destRect, long destWindowOverride, D3DRegionData dirtyRegion, long flags){ + return nPresentEx(iDirect3DDevice9Ex, sourceRect, destRect, destWindowOverride, dirtyRegion, flags); + } + //HRESULT ResetEx(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode); + public long ResetEx(D3DPresentParameters presentationParameters, D3DDisplaymodeEx fullscreenDisplayMode){ + return nResetEx(iDirect3DDevice9Ex, presentationParameters, fullscreenDisplayMode); + } + //HRESULT SetConvolutionMonoKernel(UINT Width, UINT Height, float *RowWeights, float *ColumnWeights); + public long SetConvolutionMonoKernel(int width, int height, FloatBuffer rowWeights, FloatBuffer columnWeights){ + return nSetConvolutionMonoKernel(iDirect3DDevice9Ex, width, height, rowWeights, columnWeights); + } + //HRESULT SetGPUThreadPriority(INT pPriority); + public long SetGPUThreadPriority(int priority){ + return nSetGPUThreadPriority(iDirect3DDevice9Ex, priority); + } + //HRESULT SetMaximumFrameLatency(UINT pMaxLatency); + public long SetMaximumFrameLatency(int maxLatency){ + return nSetMaximumFrameLatency(iDirect3DDevice9Ex, maxLatency); + } + //HRESULT TestCooperativeLevel(); + public long TestCooperativeLevel(){ + return nTestCooperativeLevel(iDirect3DDevice9Ex); + } + //HRESULT WaitForVBlank(UINT SwapChainIndex); + public long WaitForVBlank(int swapChainIndex){ + return nWaitForVBlank(iDirect3DDevice9Ex, swapChainIndex); + } + + //natives + private native long nCheckDeviceState(long iDirect3DDevice9Ex, long window); + private native long nCheckResourceResidency(long iDirect3DDevice9Ex, IDirect3DResource9 resourceArray, long numResources); + private native long nCreateDepthStencilSurfaceEx(long iDirect3DDevice9Ex, int width, int height, int format, int multiSample, long multisampleQuality, boolean discard, IDirect3DSurface9 surface, long sharedHandle, long usage); + private native long nCreateOffscreenPlainSurfaceEx(long iDirect3DDevice9Ex, int width, int height, int format, long pool, IDirect3DSurface9 surface, long sharedHandle, long usage); + private native long nCreateRenderTargetEx(long iDirect3DDevice9Ex, int width, int height, int format, int multiSample, long multisampleQuality, boolean lockable, IDirect3DSurface9 surface, long sharedHandle, long usage); + private native long nComposeRect(long iDirect3DDevice9Ex, IDirect3DSurface9 source, IDirect3DSurface9 destination, IDirect3DVertexBuffer9 srcRectDescriptors, int numRects, IDirect3DVertexBuffer9 dstRectDescriptors, int operation, int xOffset, int yOffset); + private native long nGetDisplayModeEx(long iDirect3DDevice9Ex, int swapChain, D3DDisplaymodeEx mode, int rotation); + private native long nGetGPUThreadPriority(long iDirect3DDevice9Ex, IntBuffer priority); + private native long nGetMaximumFrameLatency(long iDirect3DDevice9Ex, IntBuffer maxLatency); + private native long nPresentEx(long iDirect3DDevice9Ex, Rectangle sourceRect, Rectangle destRect, long destWindowOverride, D3DRegionData dirtyRegion, long flags); + private native long nResetEx(long iDirect3DDevice9Ex, D3DPresentParameters presentationParameters, D3DDisplaymodeEx fullscreenDisplayMode); + private native long nSetConvolutionMonoKernel(long iDirect3DDevice9Ex, int width, int height, FloatBuffer rowWeights, FloatBuffer columnWeights); + private native long nSetGPUThreadPriority(long iDirect3DDevice9Ex, int priority); + private native long nSetMaximumFrameLatency(long iDirect3DDevice9Ex, int maxLatency); + private native long nTestCooperativeLevel(long iDirect3DDevice9Ex); + private native long nWaitForVBlank(long iDirect3DDevice9Ex, int swapChainIndex); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DIndexBuffer9.java b/src/java/org/lwjgl/d3d/IDirect3DIndexBuffer9.java new file mode 100644 index 00000000..86046612 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DIndexBuffer9.java @@ -0,0 +1,31 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class IDirect3DIndexBuffer9 { + private long iDirect3DIndexBuffer9; + //HRESULT GetDesc(D3DINDEXBUFFER_DESC * pDesc); + public long GetDesc(D3DIndexBufferDesc desc){ + return nGetDesc(iDirect3DIndexBuffer9, desc); + } + //HRESULT Lock(UINT OffsetToLock, UINT SizeToLock, VOID ** ppbData, DWORD Flags); + public long Lock(int offsetToLock, int sizeToLock, ByteBuffer data, long flags){ + return nLock(iDirect3DIndexBuffer9, offsetToLock, sizeToLock, data, flags); + } + //HRESULT Unlock(); + public long Unlock(){ + return nUnlock(iDirect3DIndexBuffer9); + } + + public long getIDirect3DIndexBuffer9() { + return iDirect3DIndexBuffer9; + } + public void setIDirect3DIndexBuffer9(long direct3DIndexBuffer9) { + iDirect3DIndexBuffer9 = direct3DIndexBuffer9; + } + + //natives + private native long nGetDesc(long iDirect3DIndexBuffer9, D3DIndexBufferDesc desc); + private native long nLock(long iDirect3DIndexBuffer9, int offsetToLock, int sizeToLock, ByteBuffer data, long flags); + private native long nUnlock(long iDirect3DIndexBuffer9); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DPixelShader9.java b/src/java/org/lwjgl/d3d/IDirect3DPixelShader9.java new file mode 100644 index 00000000..e94d7fa1 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DPixelShader9.java @@ -0,0 +1,27 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +public class IDirect3DPixelShader9 { + private long iDirect3DPixelShader9; + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DPixelShader9, device); + } + //HRESULT GetFunction(void* pData, UINT* pSizeOfData); + public long GetFunction(ByteBuffer data, IntBuffer sizeOfData){ + return nGetFunction(iDirect3DPixelShader9, data, sizeOfData); + } + + public long getIDirect3DPixelShader9() { + return iDirect3DPixelShader9; + } + public void setIDirect3DPixelShader9(long direct3DPixelShader9) { + iDirect3DPixelShader9 = direct3DPixelShader9; + } + + //natives + private native long nGetDevice(long iDirect3DPixelShader9, IDirect3DDevice9 device); + private native long nGetFunction(long iDirect3DPixelShader9, ByteBuffer data, IntBuffer sizeOfData); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DQuery9.java b/src/java/org/lwjgl/d3d/IDirect3DQuery9.java new file mode 100644 index 00000000..2ebd10e3 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DQuery9.java @@ -0,0 +1,40 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class IDirect3DQuery9 { + private long iDirect3DQuery9; + //HRESULT GetData(void* pData, DWORD dwSize, DWORD dwGetDataFlags); + public long GetData(ByteBuffer data, long size, long getDataFlags){ + return nGetData(iDirect3DQuery9, data, size, getDataFlags); + } + //DWORD GetDataSize(); + public long GetDataSize(){ + return nGetDataSize(iDirect3DQuery9); + } + //HRESULT GetDevice(IDirect3DDevice9 ** pDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DQuery9, device); + } + //D3DQUERYTYPE GetType(); + public int GetType(){ + return nGetType(iDirect3DQuery9); + } + //HRESULT Issue(DWORD dwIssueFlags); + public long Issue(long issueFlags){ + return nIssue(iDirect3DQuery9, issueFlags); + } + + public long getIDirect3DQuery9() { + return iDirect3DQuery9; + } + public void setIDirect3DQuery9(long direct3DQuery9) { + iDirect3DQuery9 = direct3DQuery9; + } + //natives + private native long nGetData(long iDirect3DQuery9, ByteBuffer data, long size, long getDataFlags); + private native long nGetDataSize(long iDirect3DQuery9); + private native long nGetDevice(long iDirect3DQuery9, IDirect3DDevice9 device); + private native int nGetType(long iDirect3DQuery9); + private native long nIssue(long iDirect3DQuery9, long issueFlags); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DResource9.java b/src/java/org/lwjgl/d3d/IDirect3DResource9.java new file mode 100644 index 00000000..faa8f07e --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DResource9.java @@ -0,0 +1,50 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.LongBuffer; + +public class IDirect3DResource9 { + private long iDirect3DResource9; + //HRESULT FreePrivateData(REFGUID refguid); + public long FreePrivateData(GUID refguid){ + return nFreePrivateData(iDirect3DResource9, refguid); + } + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DResource9, device); + } + //DWORD GetPriority(); + public long GetPriority(){ + return nGetPriority(iDirect3DResource9); + } + //HRESULT GetPrivateData(REFGUID refguid, void * pData, DWORD * pSizeOfData); + public long GetPrivateData(GUID refguid, ByteBuffer data, LongBuffer sizeOfData){ + return nGetPrivateData(iDirect3DResource9, refguid, data, sizeOfData); + } + //D3DRESOURCETYPE GetType(); + public int GetType(){ + return nGetType(iDirect3DResource9); + } + // + public void PreLoad(){ + nPreLoad(iDirect3DResource9); + } + //DWORD SetPriority(DWORD PriorityNew); + public long SetPriority(long priorityNew){ + return nSetPriority(iDirect3DResource9, priorityNew); + } + //HRESULT SetPrivateData(REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags); + public long SetPrivateData(GUID refguid, ByteBuffer data, long sizeOfData, long flags){ + return nSetPrivateData(iDirect3DResource9, refguid, data, sizeOfData, flags); + } + + //natives + private native long nFreePrivateData(long iDirect3DResource9, GUID refguid); + private native long nGetDevice(long iDirect3DResource9, IDirect3DDevice9 device); + private native long nGetPriority(long iDirect3DResource9); + private native long nGetPrivateData(long iDirect3DResource9, GUID refguid, ByteBuffer data, LongBuffer sizeOfData); + private native int nGetType(long iDirect3DResource9); + private native void nPreLoad(long iDirect3DResource9); + private native long nSetPriority(long iDirect3DResource9, long priorityNew); + private native long nSetPrivateData(long iDirect3DResource9, GUID refguid, ByteBuffer data, long sizeOfData, long flags); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DStateBlock9.java b/src/java/org/lwjgl/d3d/IDirect3DStateBlock9.java new file mode 100644 index 00000000..3210dd7d --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DStateBlock9.java @@ -0,0 +1,28 @@ +package org.lwjgl.d3d; + +public class IDirect3DStateBlock9 { + private long iDirect3DStateBlock9; + //HRESULT Apply(); + public long Apply(){ + return nApply(iDirect3DStateBlock9); + } + //HRESULT Capture(); + public long Capture(){ + return nCapture(iDirect3DStateBlock9); + } + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DStateBlock9, device); + } + + public long getIDirect3DStateBlock9() { + return iDirect3DStateBlock9; + } + public void setIDirect3DStateBlock9(long direct3DStateBlock9) { + iDirect3DStateBlock9 = direct3DStateBlock9; + } + //natives + private native long nApply(long iDirect3DStateBlock9); + private native long nCapture(long iDirect3DStateBlock9); + private native long nGetDevice(long iDirect3DStateBlock9, IDirect3DDevice9 device); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DSurface9.java b/src/java/org/lwjgl/d3d/IDirect3DSurface9.java new file mode 100644 index 00000000..7394bd26 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DSurface9.java @@ -0,0 +1,47 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class IDirect3DSurface9 { + private long iDirect3DSurface9; + + //HRESULT GetContainer(REFIID riid, void ** ppContainer); + //TODO: find definition of REFIID + public long GetContainer(long riid, ByteBuffer container){ + return nGetContainer(iDirect3DSurface9, riid, container); + } + //HRESULT GetDC(HDC* phdc); + public long GetDC(long hdc){ + return nGetDC(iDirect3DSurface9, hdc); + } + //HRESULT GetDesc(D3DSURFACE_DESC * pDesc); + public long GetDesc(D3DSurfaceDesc desc){ + return nGetDesc(iDirect3DSurface9, desc); + } + //HRESULT LockRect(D3DLOCKED_RECT * pLockedRect, CONST RECT * pRect, DWORD Flags); + public long LockRect(D3DLockedRect lockedRect, Rectangle rect, long flags){ + return nLockRect(iDirect3DSurface9, lockedRect, rect, flags); + } + //HRESULT ReleaseDC(HDC hdc); + public long ReleaseDC(long hdc){ + return nReleaseDC(iDirect3DSurface9, hdc); + } + //HRESULT UnlockRect(); + public long UnlockRect(){ + return nUnlockRect(iDirect3DSurface9); + } + + public long getIDirect3DSurface9() { + return iDirect3DSurface9; + } + public void setIDirect3DSurface9(long direct3DSurface9) { + iDirect3DSurface9 = direct3DSurface9; + } + //natives + private native long nGetContainer(long iDirect3DSurface9, long riid, ByteBuffer container); + private native long nGetDC(long iDirect3DSurface9, long hdc); + private native long nGetDesc(long iDirect3DSurface9, D3DSurfaceDesc desc); + private native long nLockRect(long iDirect3DSurface9, D3DLockedRect lockedRect, Rectangle rect, long flags); + private native long nReleaseDC(long iDirect3DSurface9, long hdc); + private native long nUnlockRect(long iDirect3DSurface9); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DSwapChain9.java b/src/java/org/lwjgl/d3d/IDirect3DSwapChain9.java new file mode 100644 index 00000000..b805fed0 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DSwapChain9.java @@ -0,0 +1,48 @@ +package org.lwjgl.d3d; + +public class IDirect3DSwapChain9 { + private long iDirect3DSwapChain9; + //HRESULT GetBackBuffer(UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer); + public long GetBackBuffer(int backBuffer, int type, IDirect3DSurface9 backBufferSurface){ + return nGetBackBuffer(iDirect3DSwapChain9, backBuffer, type, backBufferSurface); + } + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DSwapChain9, device); + } + //HRESULT GetDisplayMode(D3DDISPLAYMODE * pMode); + public long GetDisplayMode(D3DDisplaymode mode){ + return nGetDisplayMode(iDirect3DSwapChain9, mode); + } + //HRESULT GetFrontBufferData(IDirect3DSurface9 * pDestSurface); + public long GetFrontBufferData(IDirect3DSurface9 destSurface){ + return nGetFrontBufferData(iDirect3DSwapChain9, destSurface); + } + //HRESULT GetPresentParameters(D3DPRESENT_PARAMETERS* pPresentationParameters); + public long GetPresentParameters(D3DPresentParameters presentationParameters){ + return nGetPresentParameters(iDirect3DSwapChain9, presentationParameters); + } + //HRESULT GetRasterStatus(D3DRASTER_STATUS * pRasterStatus); + public long GetRasterStatus(D3DRasterStatus rasterStatus){ + return nGetRasterStatus(iDirect3DSwapChain9, rasterStatus); + } + //HRESULT Present(CONST RECT * pSourceRect, CONST RECT * pDestRect, HWND hDestWindowOverride, CONST RGNDATA * pDirtyRegion, DWORD dwFlags); + public long Present(Rectangle sourceRect, Rectangle destRect, long destWindowOverride, RegionData dirtyRegion, long flags){ + return nPresent(iDirect3DSwapChain9, sourceRect, destRect, destWindowOverride, dirtyRegion, flags); + } + + public long getIDirect3DSwapChain9() { + return iDirect3DSwapChain9; + } + public void setIDirect3DSwapChain9(long direct3DSwapChain9) { + iDirect3DSwapChain9 = direct3DSwapChain9; + } + //natives + private native long nGetBackBuffer(long iDirect3DSwapChain9, int backBuffer, int type, IDirect3DSurface9 backBufferSurface); + private native long nGetDevice(long iDirect3DSwapChain9, IDirect3DDevice9 device); + private native long nGetDisplayMode(long iDirect3DSwapChain9, D3DDisplaymode mode); + private native long nGetFrontBufferData(long iDirect3DSwapChain9, IDirect3DSurface9 destSurface); + private native long nGetPresentParameters(long iDirect3DSwapChain9, D3DPresentParameters presentationParameters); + private native long nGetRasterStatus(long iDirect3DSwapChain9, D3DRasterStatus rasterStatus); + private native long nPresent(long iDirect3DSwapChain9, Rectangle sourceRect, Rectangle destRect, long destWindowOverride, RegionData dirtyRegion, long flags); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DSwapChain9Ex.java b/src/java/org/lwjgl/d3d/IDirect3DSwapChain9Ex.java new file mode 100644 index 00000000..94aaee5d --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DSwapChain9Ex.java @@ -0,0 +1,24 @@ +package org.lwjgl.d3d; + +import java.nio.IntBuffer; + +public class IDirect3DSwapChain9Ex { + private long iDirect3DSwapChain9Ex; + //HRESULT GetDisplayModeEx(D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation); + public long GetDisplayModeEx(D3DDisplaymodeEx mode, int rotation){ + return nGetDisplayModeEx(iDirect3DSwapChain9Ex, mode, rotation); + } + //HRESULT GetLastPresentCount(UINT * pLastPresentCount); + public long GetLastPresentCount(IntBuffer lastPresentCount){ + return nGetLastPresentCount(iDirect3DSwapChain9Ex, lastPresentCount); + } + //HRESULT GetPresentStatistics(D3DPRESENTSTATS * pPresentationStatistics); + public long GetPresentStatistics(D3DPresentStats presentationStatistics){ + return nGetPresentStatistics(iDirect3DSwapChain9Ex, presentationStatistics); + } + + //natives + private native long nGetDisplayModeEx(long iDirect3DSwapChain9Ex, D3DDisplaymodeEx mode, int rotation); + private native long nGetLastPresentCount(long iDirect3DSwapChain9Ex, IntBuffer lastPresentCount); + private native long nGetPresentStatistics(long iDirect3DSwapChain9Ex, D3DPresentStats presentationStatistics); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DTexture9.java b/src/java/org/lwjgl/d3d/IDirect3DTexture9.java new file mode 100644 index 00000000..aaecbf67 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DTexture9.java @@ -0,0 +1,32 @@ +package org.lwjgl.d3d; + +public class IDirect3DTexture9 { + private long iDirect3DTexture9; + //HRESULT AddDirtyRect(CONST RECT * pDirtyRect); + public long AddDirtyRect(Rectangle dirtyRect){ + return nAddDirtyRect(iDirect3DTexture9, dirtyRect); + } + //HRESULT GetLevelDesc(UINT Level, D3DSURFACE_DESC * pDesc); + public long GetLevelDesc(int level, D3DSurfaceDesc desc){ + return nGetLevelDesc(iDirect3DTexture9, level, desc); + } + //HRESULT GetSurfaceLevel(UINT Level, IDirect3DSurface9 ** ppSurfaceLevel); + public long GetSurfaceLevel(int level, IDirect3DSurface9 surfaceLevel){ + return nGetSurfaceLevel(iDirect3DTexture9, level, surfaceLevel); + } + //HRESULT LockRect(UINT Level, D3DLOCKED_RECT * pLockedRect, CONST RECT * pRect, DWORD Flags); + public long LockRect(int level, D3DLockedRect lockedRect, Rectangle rect, long flags){ + return nLockRect(iDirect3DTexture9, level, lockedRect, rect, flags); + } + //HRESULT UnlockRect(UINT Level); + public long UnlockRect(int level){ + return nUnlockRect(iDirect3DTexture9, level); + } + + //natives + private native long nAddDirtyRect(long iDirect3DTexture9, Rectangle dirtyRect); + private native long nGetLevelDesc(long iDirect3DTexture9, int level, D3DSurfaceDesc desc); + private native long nGetSurfaceLevel(long iDirect3DTexture9, int level, IDirect3DSurface9 surfaceLevel); + private native long nLockRect(long iDirect3DTexture9, int level, D3DLockedRect lockedRect, Rectangle rect, long flags); + private native long nUnlockRect(long iDirect3DTexture9, int level); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DVertexBuffer9.java b/src/java/org/lwjgl/d3d/IDirect3DVertexBuffer9.java new file mode 100644 index 00000000..4fa73286 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DVertexBuffer9.java @@ -0,0 +1,58 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class IDirect3DVertexBuffer9 { + private long iDirect3DVertexBuffer9; + + public IDirect3DVertexBuffer9() { + create(this); + } + + /** + * HRESULT GetDesc(D3DVERTEXBUFFER_DESC * pDesc); + * + * @param desc + * @return + */ + public final long GetDesc(D3DVertexBufferDesc desc) { + ByteBuffer buffer = desc.getBuffer(); + long hResult = nGetDesc(iDirect3DVertexBuffer9, buffer); + desc.setBuffer(buffer); + + return hResult; + } + /** + * HRESULT Lock(UINT OffsetToLock, UINT SizeToLock, VOID ** ppbData, DWORD Flags); + * + * @param offsetToLock + * @param sizeToLock + * @param ata + * @param flags + * @return + */ + public final long Lock(int offsetToLock, int sizeToLock, ByteBuffer ata, long flags){ + return nLock(iDirect3DVertexBuffer9, offsetToLock, sizeToLock, ata, flags, ata.capacity()); + } + /** + * HRESULT Unlock(); + * + * @return + */ + public final long Unlock(){ + return nUnlock(iDirect3DVertexBuffer9); + } + + public final long getIDirect3DVertexBuffer9() { + return iDirect3DVertexBuffer9; + } + public final void setIDirect3DVertexBuffer9(long direct3DVertexBuffer9) { + iDirect3DVertexBuffer9 = direct3DVertexBuffer9; + } + + //natives + private final native long nGetDesc(long iDirect3DVertexBuffer9, ByteBuffer desc); + private final native long nLock(long iDirect3DVertexBuffer9, int offsetToLock, int sizeToLock, ByteBuffer ata, long flags, int bufferSize); + private final native long nUnlock(long iDirect3DVertexBuffer9); + private final native void create(IDirect3DVertexBuffer9 iDirect3DVertexBuffer9); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DVertexDeclaration9.java b/src/java/org/lwjgl/d3d/IDirect3DVertexDeclaration9.java new file mode 100644 index 00000000..9c74fff4 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DVertexDeclaration9.java @@ -0,0 +1,26 @@ +package org.lwjgl.d3d; + +import java.nio.IntBuffer; + +public class IDirect3DVertexDeclaration9 { + private long iDirect3DVertexDeclaration9; + //HRESULT GetDeclaration(D3DVERTEXELEMENT9* pDecl, UINT* pNumElements); + public long GetDeclaration(D3DVertexElement9 decl, IntBuffer numElements){ + return nGetDeclaration(iDirect3DVertexDeclaration9, decl, numElements); + } + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DVertexDeclaration9, device); + } + + public long getIDirect3DVertexDeclaration9() { + return iDirect3DVertexDeclaration9; + } + public void setIDirect3DVertexDeclaration9(long direct3DVertexDeclaration9) { + iDirect3DVertexDeclaration9 = direct3DVertexDeclaration9; + } + + //natives + private native long nGetDeclaration(long iDirect3DVertexDeclaration9, D3DVertexElement9 decl, IntBuffer numElements); + private native long nGetDevice(long iDirect3DVertexDeclaration9, IDirect3DDevice9 device); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DVertexShader9.java b/src/java/org/lwjgl/d3d/IDirect3DVertexShader9.java new file mode 100644 index 00000000..c7217c8f --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DVertexShader9.java @@ -0,0 +1,27 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +public class IDirect3DVertexShader9 { + private long iDirect3DVertexShader9; + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DVertexShader9, device); + } + //HRESULT GetFunction(void* pData, UINT* pSizeOfData); + public long GetFunction(ByteBuffer data, IntBuffer sizeOfData){ + return nGetFunction(iDirect3DVertexShader9, data, sizeOfData); + } + + public long getIDirect3DVertexShader9() { + return iDirect3DVertexShader9; + } + public void setIDirect3DVertexShader9(long direct3DVertexShader9) { + iDirect3DVertexShader9 = direct3DVertexShader9; + } + + //natives + private native long nGetDevice(long iDirect3DVertexShader9, IDirect3DDevice9 device); + private native long nGetFunction(long iDirect3DVertexShader9, ByteBuffer data, IntBuffer sizeOfData); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DVolume9.java b/src/java/org/lwjgl/d3d/IDirect3DVolume9.java new file mode 100644 index 00000000..903bd963 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DVolume9.java @@ -0,0 +1,50 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class IDirect3DVolume9 { + private long iDirect3DVolume9; + //HRESULT FreePrivateData(REFGUID refguid); + public long FreePrivateData(GUID refguid){ + return nFreePrivateData(iDirect3DVolume9, refguid); + } + //HRESULT GetContainer(REFIID riid, void ** ppContainer); + //TODO: find REFIID definition + public long GetContainer(long riid, ByteBuffer container){ + return nGetContainer(iDirect3DVolume9, riid, container); + } + //HRESULT GetDesc(D3DVOLUME_DESC * pDesc); + public long GetDesc(D3DVolumeDesc desc){ + return nGetDesc(iDirect3DVolume9, desc); + } + //HRESULT GetDevice(IDirect3DDevice9 ** ppDevice); + public long GetDevice(IDirect3DDevice9 device){ + return nGetDevice(iDirect3DVolume9, device); + } + //HRESULT GetPrivateData(REFGUID refguid, void * pData, DWORD * pSizeOfData); + public long GetPrivateData(GUID refguid, ByteBuffer data, long sizeOfData){ + return nGetPrivateData(iDirect3DVolume9, refguid, data, sizeOfData); + } + //HRESULT LockBox(D3DLOCKED_BOX * pLockedVolume, CONST D3DBOX * pBox, DWORD Flags); + public long LockBox(D3DLockedBox lockedVolume, D3DBox box, long flags){ + return nLockBox(iDirect3DVolume9, lockedVolume, box, flags); + } + //HRESULT SetPrivateData(REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags); + public long SetPrivateData(GUID refguid, ByteBuffer data, long sizeOfData, long flags){ + return nSetPrivateData(iDirect3DVolume9, refguid, data, sizeOfData, flags); + } + //HRESULT UnlockBox(); + public long UnlockBox(){ + return nUnlockBox(iDirect3DVolume9); + } + + //natives + private native long nFreePrivateData(long iDirect3DVolume9, GUID refguid); + private native long nGetContainer(long iDirect3DVolume9, long riid, ByteBuffer container); + private native long nGetDesc(long iDirect3DVolume9, D3DVolumeDesc desc); + private native long nGetDevice(long iDirect3DVolume9, IDirect3DDevice9 device); + private native long nGetPrivateData(long iDirect3DVolume9, GUID refguid, ByteBuffer data, long sizeOfData); + private native long nLockBox(long iDirect3DVolume9, D3DLockedBox lockedVolume, D3DBox box, long flags); + private native long nSetPrivateData(long iDirect3DVolume9, GUID refguid, ByteBuffer data, long sizeOfData, long flags); + private native long nUnlockBox(long iDirect3DVolume9); +} diff --git a/src/java/org/lwjgl/d3d/IDirect3DVolumeTexture9.java b/src/java/org/lwjgl/d3d/IDirect3DVolumeTexture9.java new file mode 100644 index 00000000..fc7e8f87 --- /dev/null +++ b/src/java/org/lwjgl/d3d/IDirect3DVolumeTexture9.java @@ -0,0 +1,38 @@ +package org.lwjgl.d3d; + +public class IDirect3DVolumeTexture9 { + private long iDirect3DVolumeTexture9; + //HRESULT AddDirtyBox(CONST D3DBOX * pDirtyBox); + public long AddDirtyBox(D3DBox dirtyBox){ + return nAddDirtyBox(iDirect3DVolumeTexture9, dirtyBox); + } + //HRESULT GetLevelDesc(UINT Level, D3DVOLUME_DESC * pDesc); + public long GetLevelDesc(int level, D3DVolumeDesc desc){ + return nGetLevelDesc(iDirect3DVolumeTexture9, level, desc); + } + //HRESULT GetVolumeLevel(UINT Level, IDirect3DVolume9 ** ppVolumeLevel); + public long GetVolumeLevel(int level, IDirect3DVolume9 volumeLevel){ + return nGetVolumeLevel(iDirect3DVolumeTexture9, level, volumeLevel); + } + //HRESULT LockBox(UINT Level, D3DLOCKED_BOX * pLockedVolume, CONST D3DBOX * pBox, DWORD Flags); + public long LockBox(int level, D3DLockedBox lockedVolume, D3DBox box, long flags){ + return nLockBox(iDirect3DVolumeTexture9, level, lockedVolume, box, flags); + } + //HRESULT UnlockBox(UINT Level); + public long UnlockBox(int level){ + return nUnlockBox(iDirect3DVolumeTexture9, level); + } + + public long getIDirect3DVolumeTexture9() { + return iDirect3DVolumeTexture9; + } + public void setIDirect3DVolumeTexture9(long direct3DVolumeTexture9) { + iDirect3DVolumeTexture9 = direct3DVolumeTexture9; + } + //natives + private native long nAddDirtyBox(long iDirect3DVolumeTexture9, D3DBox dirtyBox); + private native long nGetLevelDesc(long iDirect3DVolumeTexture9, int level, D3DVolumeDesc desc); + private native long nGetVolumeLevel(long iDirect3DVolumeTexture9, int level, IDirect3DVolume9 volumeLevel); + private native long nLockBox(long iDirect3DVolumeTexture9, int level, D3DLockedBox lockedVolume, D3DBox box, long flags); + private native long nUnlockBox(long iDirect3DVolumeTexture9, int level); +} diff --git a/src/java/org/lwjgl/d3d/InputImplementation.java b/src/java/org/lwjgl/d3d/InputImplementation.java new file mode 100644 index 00000000..0ebd9679 --- /dev/null +++ b/src/java/org/lwjgl/d3d/InputImplementation.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import org.lwjgl.LWJGLException; + +public interface InputImplementation { + /* + * Mouse methods + */ + /** Query of wheel support */ + boolean hasWheel(); + + /** Query of button count */ + int getButtonCount(); + + /** + * Method to create the mouse. + */ + void createMouse() throws LWJGLException; + + /** + * Method the destroy the mouse + */ + void destroyMouse(); + + /** + * Method to poll the mouse + */ + void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons); + + /** + * Method to read the keyboard buffer + */ + void readMouse(ByteBuffer buffer); + + void grabMouse(boolean grab); + + /** + * Function to determine native cursor support + */ + int getNativeCursorCapabilities(); + + /** Method to set the native cursor position */ + void setCursorPosition(int x, int y); + + /** Method to set the native cursor */ + void setNativeCursor(Object handle) throws LWJGLException; + + /** Method returning the minimum cursor size */ + int getMinCursorSize(); + + /** Method returning the maximum cursor size */ + int getMaxCursorSize(); + + /* + * Keyboard methods + */ + + /** + * Method to create the keyboard + */ + void createKeyboard() throws LWJGLException; + + /** + * Method to destroy the keyboard + */ + void destroyKeyboard(); + + /** + * Method to poll the keyboard. + * + * @param keyDownBuffer the address of a 256-byte buffer to place + * key states in. + */ + void pollKeyboard(ByteBuffer keyDownBuffer); + + /** + * Method to read the keyboard buffer + */ + void readKeyboard(ByteBuffer buffer); + +// int isStateKeySet(int key); + + /** Native cursor handles */ + Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException; + + void destroyCursor(Object cursor_handle); + + int getWidth(); + + int getHeight(); +} diff --git a/src/java/org/lwjgl/d3d/LUID.java b/src/java/org/lwjgl/d3d/LUID.java new file mode 100644 index 00000000..386101f0 --- /dev/null +++ b/src/java/org/lwjgl/d3d/LUID.java @@ -0,0 +1,7 @@ +package org.lwjgl.d3d; + +public class LUID { + public long LowPart; //DWORD + public long HighPart; + +} diff --git a/src/java/org/lwjgl/d3d/NewDisplay.java b/src/java/org/lwjgl/d3d/NewDisplay.java new file mode 100644 index 00000000..75ce0e8e --- /dev/null +++ b/src/java/org/lwjgl/d3d/NewDisplay.java @@ -0,0 +1,135 @@ +package org.lwjgl.d3d; + +import java.util.Arrays; +import java.util.HashSet; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public class NewDisplay { + private static final DisplayMode initialMode; + private static DisplayMode currentMode; + private static long hwnd; + private static boolean created; + private static boolean fullscreen; + private static boolean modeSet; + + static { + try { + currentMode = initialMode = nGetCurrentDisplayMode(); + LWJGLUtil.log("Initial mode: " + initialMode); + } catch (LWJGLException e) { + throw new RuntimeException(e); + } + } + + private NewDisplay(){} + public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException { + synchronized (GlobalLock.lock) { + Object[] unfilteredModes = nGetAvailableDisplayModes(); + + if (unfilteredModes == null) { + return new DisplayMode[0]; + } + + // We'll use a HashSet to filter out the duplicated modes + HashSet modes = new HashSet(unfilteredModes.length); + + modes.addAll(Arrays.asList(unfilteredModes)); + DisplayMode[] filteredModes = new DisplayMode[modes.size()]; + modes.toArray(filteredModes); + + LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); + + return filteredModes; + } + } + + public static void setDisplayMode(DisplayMode mode) throws LWJGLException { + synchronized (GlobalLock.lock) { + if (mode == null) + throw new NullPointerException("mode must be non-null"); + currentMode = mode; + if (isCreated()) { + destroyWindow(); + // If mode is not fullscreen capable, make sure we are in windowed mode + if (!mode.isFullscreen()) + resetFullscreen(); + try { + if (fullscreen) { + switchDisplayMode(); + } + createWindow(); +// makeCurrentAndSetSwapInterval(); + } catch (LWJGLException e) { +// destroyContext(); +// destroyPeerInfo(); + resetDisplayMode(); + throw e; + } + } + } + } + + public static void create() throws LWJGLException { + //TODO + } + public static void destroy() { + //TODO + } + + public static boolean isCreated() { + return created; + } + private static void destroyWindow() { + if (created) { +// if (Mouse.isCreated()) { +// Mouse.destroy(); +// } +// if (Keyboard.isCreated()) { +// Keyboard.destroy(); +// } + nDestroyWindow(); +// resetCursorClipping(); + created = false; + } + } + private static void resetFullscreen() { + synchronized (GlobalLock.lock) { + if (NewDisplay.fullscreen) { + NewDisplay.fullscreen = false; + resetDisplayMode(); + } + } + } + private static void switchDisplayMode() throws LWJGLException { + if (!currentMode.isFullscreen()) { + LWJGLUtil.log("Switching to " + initialMode); + setDisplayMode(initialMode); + } + switchDisplayMode(initialMode); + } + public static void switchDisplayMode(DisplayMode mode) throws LWJGLException { + nSwitchDisplayMode(mode); + currentMode = mode; + modeSet = true; + } + private static void createWindow() { + //TODO + } + private static void resetDisplayMode() { + if (modeSet) { + modeSet = false; + nResetDisplayMode(); + } +// resetCursorClipping(); + } + private static native void nDestroyWindow(); + private static native DisplayMode[] nGetAvailableDisplayModes(); + private static native void nSetDisplayMode(DisplayMode mode); + private static native void nSwitchDisplayMode(DisplayMode mode) throws LWJGLException; + private static native void nResetDisplayMode(); + private static native DisplayMode nGetCurrentDisplayMode() throws LWJGLException; +} diff --git a/src/java/org/lwjgl/d3d/PaletteEntry.java b/src/java/org/lwjgl/d3d/PaletteEntry.java new file mode 100644 index 00000000..0631b8ed --- /dev/null +++ b/src/java/org/lwjgl/d3d/PaletteEntry.java @@ -0,0 +1,42 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class PaletteEntry { + public byte peRed; + public byte peGreen; + public byte peBlue; + public byte peFlags; + private static final int D3D_VECTOR_BYTE_SIZE = 4; + private ByteBuffer buffer; + + public PaletteEntry() { + buffer = ByteBuffer.allocateDirect(D3D_VECTOR_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put(peRed); + buffer.put(peGreen); + buffer.put(peBlue); + buffer.put(peFlags); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + peRed = buffer.get(); + peGreen = buffer.get(); + peBlue = buffer.get(); + peFlags = buffer.get(); + } +} diff --git a/src/java/org/lwjgl/d3d/PeerInfo.java b/src/java/org/lwjgl/d3d/PeerInfo.java new file mode 100644 index 00000000..c65728fa --- /dev/null +++ b/src/java/org/lwjgl/d3d/PeerInfo.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; + +/** +* +* @author elias_naur +* @version $Revision: 2286 $ +* $Id: PeerInfo.java 2286 2006-03-23 19:32:21Z matzon $ +*/ +abstract class PeerInfo { + private final ByteBuffer handle; + private Thread locking_thread; // Thread that has locked this PeerInfo + private int lock_count; + + protected PeerInfo(ByteBuffer handle) { + this.handle = handle; + } + + private final void lockAndInitHandle() throws LWJGLException { + doLockAndInitHandle(); + } + + public synchronized final void unlock() throws LWJGLException { + if (lock_count <= 0) + throw new IllegalStateException("PeerInfo not locked!"); + if (Thread.currentThread() != locking_thread) + throw new IllegalStateException("PeerInfo already locked by " + locking_thread); + lock_count--; + if (lock_count == 0) { + doUnlock(); + locking_thread = null; + notify(); + } + } + + protected abstract void doLockAndInitHandle() throws LWJGLException; + protected abstract void doUnlock() throws LWJGLException; + + public synchronized final ByteBuffer lockAndGetHandle() throws LWJGLException { + Thread this_thread = Thread.currentThread(); + while (locking_thread != null && locking_thread != this_thread) { + try { + wait(); + } catch (InterruptedException e) { + LWJGLUtil.log("Interrupted while waiting for PeerInfo lock: " + e); + } + } + if (lock_count == 0) { + locking_thread = this_thread; + doLockAndInitHandle(); + } + lock_count++; + return getHandle(); + } + + protected final ByteBuffer getHandle() { + return handle; + } + + public void destroy() { + } +} diff --git a/src/java/org/lwjgl/d3d/PixelFormat.java b/src/java/org/lwjgl/d3d/PixelFormat.java new file mode 100644 index 00000000..565ce1c5 --- /dev/null +++ b/src/java/org/lwjgl/d3d/PixelFormat.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This class describes pixel format properties for an OpenGL context. Instances + * of this class is used as arguments to Display.create(), Pbuffer.create() and + * AWTGLCanvas, to indicate minimum required properties. + * + * WARNING: Some pixel formats are known to cause troubles on certain buggy drivers. + * Example: Under Windows, specifying samples != 0 will enable the ARB + * pixel format selection path, which could trigger a crash. + * + * @author elias_naur@sourceforge.net + * @version $Revision: 2361 $ + */ + +public final class PixelFormat { + /** + * The number of bits per pixel, exluding alpha. + * This parameter is ignored in Display.create(). + */ + private final int bpp; + /** The number of alpha bits. */ + private final int alpha; + /** The number of depth buffer bits*/ + private final int depth; + /** The number of stencil bits */ + private final int stencil; + /** + * The number of samples to use in anti-aliasing. + * 0 means that anti-aliasing is disabled. + */ + private final int samples; + /** The number of auxilliary buffers */ + private final int num_aux_buffers; + /** The number of bits per pixel in the accumulation buffer */ + private final int accum_bpp; + /** The number of alpha bits in the accumulation buffer */ + private final int accum_alpha; + /** Whether this format requires a stereo buffer */ + private final boolean stereo; + /** Whether this format specifies a floating point format */ + private final boolean floating_point; + + /** + * Default pixel format is minimum 8 bits depth, and no alpha + * nor stencil requirements. + */ + public PixelFormat() { + this(0, 8, 0); + } + + public PixelFormat(int alpha, int depth, int stencil) { + this(alpha, depth, stencil, 0); + } + + public PixelFormat(int alpha, int depth, int stencil, int samples) { + this(0, alpha, depth, stencil, samples); + } + + public PixelFormat(int bpp, int alpha, int depth, int stencil, int samples) { + this(bpp, alpha, depth, stencil, samples, 0, 0, 0, false); + } + + public PixelFormat(int bpp, int alpha, int depth, int stencil, int samples, int num_aux_buffers, int accum_bpp, int accum_alpha, boolean stereo) { + this(bpp, alpha, depth, stencil, samples, num_aux_buffers, accum_bpp, accum_alpha, stereo, false); + } + + public PixelFormat(int bpp, int alpha, int depth, int stencil, int samples, int num_aux_buffers, int accum_bpp, int accum_alpha, boolean stereo, boolean floating_point) { + this.bpp = bpp; + this.alpha = alpha; + this.depth = depth; + this.stencil = stencil; + this.samples = samples; + this.num_aux_buffers = num_aux_buffers; + this.accum_bpp = accum_bpp; + this.accum_alpha = accum_alpha; + this.stereo = stereo; + this.floating_point = floating_point; + } + + public int getBitsPerPixel() { + return bpp; + } + + public int getAlphaBits() { + return alpha; + } + + public int getDepthBits() { + return depth; + } + + public int getStencilBits() { + return stencil; + } + + public int getSamples() { + return samples; + } + + public int getAuxBuffers() { + return num_aux_buffers; + } + + public int getAccumulationBitsPerPixel() { + return accum_bpp; + } + + public int getAccumulationAlpha() { + return accum_alpha; + } + + public boolean isStereo() { + return stereo; + } + + public boolean isFloatingPoint() { + return floating_point; + } +} diff --git a/src/java/org/lwjgl/d3d/Point.java b/src/java/org/lwjgl/d3d/Point.java new file mode 100644 index 00000000..a41973de --- /dev/null +++ b/src/java/org/lwjgl/d3d/Point.java @@ -0,0 +1,37 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class Point { + public long x; + public long y; + + private static final int RECTANGLE_BYTE_SIZE = 8; + private ByteBuffer buffer; + + public Point() { + buffer = ByteBuffer.allocateDirect(RECTANGLE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + buffer.clear(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)x); + buffer.putInt((int)y); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + x = buffer.getInt(); + y = buffer.getInt(); + } +} diff --git a/src/java/org/lwjgl/d3d/Rectangle.java b/src/java/org/lwjgl/d3d/Rectangle.java new file mode 100644 index 00000000..2f94f632 --- /dev/null +++ b/src/java/org/lwjgl/d3d/Rectangle.java @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +//From RECT +public class Rectangle { + public long left; + public long top; + public long right; + public long bottom; + private static final int RECTANGLE_BYTE_SIZE = 16; + + private ByteBuffer buffer; + + public Rectangle() { + buffer = ByteBuffer.allocateDirect(RECTANGLE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + buffer.clear(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)left); + buffer.putInt((int)top); + buffer.putInt((int)right); + buffer.putInt((int)bottom); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + left = buffer.getInt(); + top = buffer.getInt(); + right = buffer.getInt(); + bottom = buffer.getInt(); + } + public String toString() { + return + " left = " + left + + " top = " + top + + " right = " + right + + "bottom = " + bottom; + } +} diff --git a/src/java/org/lwjgl/d3d/RegionData.java b/src/java/org/lwjgl/d3d/RegionData.java new file mode 100644 index 00000000..f86ee9f0 --- /dev/null +++ b/src/java/org/lwjgl/d3d/RegionData.java @@ -0,0 +1,6 @@ +package org.lwjgl.d3d; + +public class RegionData { + public RegionDataHeader rdh; //RGNDATAHEADER + public char Buffer[] = new char[1]; +} diff --git a/src/java/org/lwjgl/d3d/RegionDataHeader.java b/src/java/org/lwjgl/d3d/RegionDataHeader.java new file mode 100644 index 00000000..0b0b7bef --- /dev/null +++ b/src/java/org/lwjgl/d3d/RegionDataHeader.java @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +public class RegionDataHeader { + public long dwSize; //DWORD + public long iType; //DWORD + public long nCount; //DWORD + public long nRgnSize; //DWORD + public Rectangle rcBound; //RECT +} diff --git a/src/java/org/lwjgl/d3d/WindowsContextImplementation.java b/src/java/org/lwjgl/d3d/WindowsContextImplementation.java new file mode 100644 index 00000000..433983bb --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsContextImplementation.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; + +/** + * + * @author elias_naur + * @version $Revision: 2832 $ + * $Id: WindowsContextImplementation.java 2832 2007-05-27 15:32:25Z elias_naur $ + */ +final class WindowsContextImplementation implements ContextImplementation { + public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException { + ByteBuffer peer_handle = peer_info.lockAndGetHandle(); + try { + return nCreate(peer_handle, shared_context_handle); + } finally { + peer_info.unlock(); + } + } + private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException; + + public void swapBuffers(PeerInfo peerInfo) throws LWJGLException { +// Context current_context = Context.getCurrentContext(); +// if (current_context == null) +// throw new IllegalStateException("No context is current"); +// synchronized (current_context) { +// PeerInfo current_peer_info = current_context.getPeerInfo(); + ByteBuffer peer_handle = peerInfo.lockAndGetHandle(); + try { + nSwapBuffers(peer_handle); + } finally { + peerInfo.unlock(); + } +// } + } + private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException; + + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException { + } + + public void update(ByteBuffer context_handle) { + } + + public void releaseCurrentContext() throws LWJGLException { + nReleaseCurrentContext(); + } + private static native void nReleaseCurrentContext() throws LWJGLException; + + public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { + ByteBuffer peer_handle = peer_info.lockAndGetHandle(); + try { + nMakeCurrent(peer_handle, handle); + } finally { + peer_info.unlock(); + } + } + private static native void nMakeCurrent(ByteBuffer peer_handle, ByteBuffer context_handle) throws LWJGLException; + + public boolean isCurrent(ByteBuffer handle) throws LWJGLException { + boolean result = nIsCurrent(handle); + return result; + } + private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException; + + public void setSwapInterval(int value) { + boolean success = nSetSwapInterval(value); + if (!success) + LWJGLUtil.log("Failed to set swap interval"); + } + private static native boolean nSetSwapInterval(int value); + + public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { + nDestroy(handle); + } + private static native void nDestroy(ByteBuffer context_handle) throws LWJGLException; +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInput.java b/src/java/org/lwjgl/d3d/WindowsDirectInput.java new file mode 100644 index 00000000..ad2ad1af --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInput.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInput base class + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +abstract class WindowsDirectInput { + public final static int KEYBOARD_TYPE = 1; + public final static int MOUSE_TYPE = 2; + + /* DirectInput constants */ + public final static int DI_OK = 0x00000000; + public final static int DI_NOEFFECT = 0x00000001; + public final static int DI_PROPNOEFFECT = 0x00000001; + public final static int DI_POLLEDDEVICE = 0x00000002; + + public final static int DI_DOWNLOADSKIPPED = 0x00000003; + public final static int DI_EFFECTRESTARTED = 0x00000004; + public final static int DI_TRUNCATED = 0x00000008; + public final static int DI_SETTINGSNOTSAVED = 0x0000000B; + public final static int DI_TRUNCATEDANDRESTARTED = 0x0000000C; + + public final static int DI_BUFFEROVERFLOW = 0x00000001; + public final static int DIERR_INPUTLOST = 0x8007001E; + public final static int DIERR_NOTACQUIRED = 0x8007001C; + public final static int DIERR_OTHERAPPHASPRIO = 0x80070005; + + private final long di_interface; + + public WindowsDirectInput(long hinst) throws LWJGLException { + di_interface = createDirectInput(hinst); + } + protected abstract long createDirectInput(long hinst) throws LWJGLException; + + public WindowsDirectInputDevice createDevice(int type) throws LWJGLException { + return createDevice(di_interface, type); + } + protected abstract WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException; + + public void release() { + release(di_interface); + } + protected abstract void release(long di_interface); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInput3.java b/src/java/org/lwjgl/d3d/WindowsDirectInput3.java new file mode 100644 index 00000000..7d0936af --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInput3.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInput3 interface + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +final class WindowsDirectInput3 extends WindowsDirectInput { + /* Re-define device types to get them included in the native headers */ + public final static int KEYBOARD_TYPE = WindowsDirectInput.KEYBOARD_TYPE; + public final static int MOUSE_TYPE = WindowsDirectInput.MOUSE_TYPE; + + public WindowsDirectInput3(long hinst) throws LWJGLException { + super(hinst); + } + + protected native long createDirectInput(long hinst) throws LWJGLException; + + protected WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException { + long device = nCreateDevice(di_interface, type); + return new WindowsDirectInputDevice3(device); + } + private static native long nCreateDevice(long di_interface, int type) throws LWJGLException; + + protected native void release(long di_interface); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInput8.java b/src/java/org/lwjgl/d3d/WindowsDirectInput8.java new file mode 100644 index 00000000..97cae646 --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInput8.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInput8 interface + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +final class WindowsDirectInput8 extends WindowsDirectInput { + /* Re-define device types to get them included in the native headers */ + public final static int KEYBOARD_TYPE = WindowsDirectInput.KEYBOARD_TYPE; + public final static int MOUSE_TYPE = WindowsDirectInput.MOUSE_TYPE; + + public WindowsDirectInput8(long hinst) throws LWJGLException { + super(hinst); + } + + protected native long createDirectInput(long hinst) throws LWJGLException; + + protected WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException { + long device = nCreateDevice(di_interface, type); + return new WindowsDirectInputDevice8(device); + } + private static native long nCreateDevice(long di_interface, int type) throws LWJGLException; + + protected native void release(long di_interface); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInputDevice.java b/src/java/org/lwjgl/d3d/WindowsDirectInputDevice.java new file mode 100644 index 00000000..f2790db5 --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInputDevice.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInputDevice interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; +import org.lwjgl.BufferUtils; + +abstract class WindowsDirectInputDevice { + public final static int DISCL_EXCLUSIVE = 0x00000001; + public final static int DISCL_NONEXCLUSIVE = 0x00000002; + public final static int DISCL_FOREGROUND = 0x00000004; + public final static int DISCL_BACKGROUND = 0x00000008; + public final static int DISCL_NOWINKEY = 0x00000010; + + public final static int GUID_XAxis = 1; + public final static int GUID_YAxis = 2; + public final static int GUID_ZAxis = 3; + public final static int GUID_Button = 4; + public final static int GUID_Unknown = 5; + + public final static int DATA_SIZE = 3; + + private final long di_device; + private ByteBuffer event_buffer; + + public WindowsDirectInputDevice(long di_device) { + this.di_device = di_device; + } + + public void release() { + release(di_device); + } + protected abstract void release(long di_device); + + public int poll() { + return poll(di_device); + } + protected abstract int poll(long di_device); + + public void setDataFormat(int type) throws LWJGLException { + int ret = setDataFormat(di_device, type); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set data format (" + Integer.toHexString(ret) + ")"); + } + protected abstract int setDataFormat(long di_device, int type); + + public void setCooperateLevel(long hwnd, int flags) throws LWJGLException { + int ret = setCooperativeLevel(di_device, hwnd, flags); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set cooperative level (" + Integer.toHexString(ret) + ")"); + } + protected abstract int setCooperativeLevel(long di_device, long hwnd, int flags); + + public int acquire() { + return acquire(di_device); + } + protected abstract int acquire(long di_device); + + public void setBufferSize(int buffer_size) throws LWJGLException { + int ret = setBufferSize(di_device, buffer_size); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_PROPNOEFFECT && ret != WindowsDirectInput.DI_POLLEDDEVICE) + throw new LWJGLException("Failed to set buffer size (" + Integer.toHexString(ret) + ")"); + int event_buffer_size = getEventSize()*buffer_size; + event_buffer = BufferUtils.createByteBuffer(event_buffer_size); + } + protected abstract int setBufferSize(long di_device, int buffer_size); + + public int getDeviceData(IntBuffer buffer) { + int events_remaining = buffer.remaining()/DATA_SIZE; + if (event_buffer == null || events_remaining > event_buffer.remaining()/getEventSize()) + event_buffer = BufferUtils.createByteBuffer(events_remaining*getEventSize()); + return getDeviceData(di_device, event_buffer, event_buffer.capacity(), buffer, buffer.position(), buffer.remaining()); + } + protected abstract int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + /** + * Device data is returned in tuples of the form . + * buffer position() is moved accordingly to number of events. + */ + public int getDeviceState(ByteBuffer buffer) { + return getDeviceState(di_device, buffer, buffer.position(), buffer.remaining()); + } + protected abstract int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + public void unacquire() { + unacquire(di_device); + } + protected abstract int unacquire(long di_device); + + public int enumObjects(WindowsDirectInputDeviceObjectCallback enumerator) { + return enumObjects(di_device, enumerator); + } + protected abstract int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); + + protected abstract int getEventSize(); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInputDevice3.java b/src/java/org/lwjgl/d3d/WindowsDirectInputDevice3.java new file mode 100644 index 00000000..b3d77711 --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInputDevice3.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInputDevice3 interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; + +final class WindowsDirectInputDevice3 extends WindowsDirectInputDevice { + /** Re-declare to get the constants into the native headers */ + public final static int GUID_XAxis = WindowsDirectInputDevice.GUID_XAxis; + public final static int GUID_YAxis = WindowsDirectInputDevice.GUID_YAxis; + public final static int GUID_ZAxis = WindowsDirectInputDevice.GUID_ZAxis; + public final static int GUID_Button = WindowsDirectInputDevice.GUID_Button; + public final static int GUID_Unknown = WindowsDirectInputDevice.GUID_Unknown; + + public final static int DATA_SIZE = WindowsDirectInputDevice.DATA_SIZE; + + public WindowsDirectInputDevice3(long di_device) { + super(di_device); + } + + protected native int setDataFormat(long di_device, int type); + + protected native int setCooperativeLevel(long di_device, long hwnd, int flags); + + protected native int acquire(long di_device); + + protected native int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + protected native int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + protected native int unacquire(long di_device); + + protected int poll(long di_device) { + return WindowsDirectInput.DI_OK; + } + + protected native int setBufferSize(long di_device, int buffer_size); + protected native int getEventSize(); + + protected native void release(long di_device); + + protected native int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInputDevice8.java b/src/java/org/lwjgl/d3d/WindowsDirectInputDevice8.java new file mode 100644 index 00000000..de8f16ad --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInputDevice8.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInputDevice3 interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; + +final class WindowsDirectInputDevice8 extends WindowsDirectInputDevice { + /** Re-declare to get the constants into the native headers */ + public final static int GUID_XAxis = WindowsDirectInputDevice.GUID_XAxis; + public final static int GUID_YAxis = WindowsDirectInputDevice.GUID_YAxis; + public final static int GUID_ZAxis = WindowsDirectInputDevice.GUID_ZAxis; + public final static int GUID_Button = WindowsDirectInputDevice.GUID_Button; + public final static int GUID_Unknown = WindowsDirectInputDevice.GUID_Unknown; + + public final static int DATA_SIZE = WindowsDirectInputDevice.DATA_SIZE; + + public WindowsDirectInputDevice8(long di_device) { + super(di_device); + } + + protected native int setDataFormat(long di_device, int type); + + protected native int setCooperativeLevel(long di_device, long hwnd, int flags); + + protected native int acquire(long di_device); + + protected native int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + protected native int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + protected native int unacquire(long di_device); + + protected native int poll(long di_device); + + protected native int setBufferSize(long di_device, int buffer_size); + protected native int getEventSize(); + + protected native void release(long di_device); + + protected native int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDirectInputDeviceObjectCallback.java b/src/java/org/lwjgl/d3d/WindowsDirectInputDeviceObjectCallback.java new file mode 100644 index 00000000..a823489a --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDirectInputDeviceObjectCallback.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the DirectInputDevice callback interface + * @author elias_naur + */ + +interface WindowsDirectInputDeviceObjectCallback { + public boolean nextObject(int type, String name); +} diff --git a/src/java/org/lwjgl/d3d/WindowsDisplay.java b/src/java/org/lwjgl/d3d/WindowsDisplay.java new file mode 100644 index 00000000..6bd89e11 --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDisplay.java @@ -0,0 +1,751 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the Display implementation interface. Display delegates + * to implementors of this interface. There is one DisplayImplementation + * for each supported platform. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Cursor; + +final class WindowsDisplay implements DisplayImplementation { + private final static int GAMMA_LENGTH = 256; + private final static int WM_MOUSEMOVE = 0x0200; + private final static int WM_LBUTTONDOWN = 0x0201; + private final static int WM_LBUTTONUP = 0x0202; + private final static int WM_LBUTTONDBLCLK = 0x0203; + private final static int WM_RBUTTONDOWN = 0x0204; + private final static int WM_RBUTTONUP = 0x0205; + private final static int WM_RBUTTONDBLCLK = 0x0206; + private final static int WM_MBUTTONDOWN = 0x0207; + private final static int WM_MBUTTONUP = 0x0208; + private final static int WM_MBUTTONDBLCLK = 0x0209; + private final static int WM_MOUSEWHEEL = 0x020A; + private final static int WM_KEYDOWN = 256; + private final static int WM_KEYUP = 257; + private final static int WM_SYSKEYUP = 261; + private final static int WM_SYSKEYDOWN = 260; + private final static int WM_CHAR = 258; + + private final static int WM_QUIT = 0x0012; + private final static int WM_CLOSE = 0x0010; + private final static int WM_DESTROY = 0x0002; + private final static int WM_SYSCOMMAND = 0x0112; + private final static int WM_PAINT = 0x000F; + + private final static int SC_SIZE = 0xF000; + private final static int SC_MOVE = 0xF010; + private final static int SC_MINIMIZE = 0xF020; + private final static int SC_MAXIMIZE = 0xF030; + private final static int SC_NEXTWINDOW = 0xF040; + private final static int SC_PREVWINDOW = 0xF050; + private final static int SC_CLOSE = 0xF060; + private final static int SC_VSCROLL = 0xF070; + private final static int SC_HSCROLL = 0xF080; + private final static int SC_MOUSEMENU = 0xF090; + private final static int SC_KEYMENU = 0xF100; + private final static int SC_ARRANGE = 0xF110; + private final static int SC_RESTORE = 0xF120; + private final static int SC_TASKLIST = 0xF130; + private final static int SC_SCREENSAVE = 0xF140; + private final static int SC_HOTKEY = 0xF150; + private final static int SC_DEFAULT = 0xF160; + private final static int SC_MONITORPOWER = 0xF170; + private final static int SC_CONTEXTHELP = 0xF180; + private final static int SC_SEPARATOR = 0xF00F; + + final static int SM_CXCURSOR = 13; + final static int SM_CYCURSOR = 14; + final static int SM_CMOUSEBUTTONS = 43; + final static int SM_MOUSEWHEELPRESENT = 75; + + private final static int SIZE_RESTORED = 0; + private final static int SIZE_MINIMIZED = 1; + private final static int SIZE_MAXIMIZED = 2; + private final static int WM_SIZE = 0x0005; + private final static int WM_ACTIVATE = 0x0006; + private final static int WA_INACTIVE = 0; + private final static int WA_ACTIVE = 1; + private final static int WA_CLICKACTIVE = 2; + private final static int SW_SHOWMINNOACTIVE = 7; + private final static int SW_SHOWDEFAULT = 10; + private final static int SW_RESTORE = 9; + + private final static IntBuffer rect_buffer = BufferUtils.createIntBuffer(4); + private final static Rect rect = new Rect(); + private final static Rect rect2 = new Rect(); + private static WindowsDisplay current_display; + + private static boolean cursor_clipped; + private WindowsDisplayPeerInfo peer_info; + private Object current_cursor; + + private WindowsKeyboard keyboard; + private WindowsMouse mouse; + + private boolean close_requested; + private boolean is_dirty; + + private ByteBuffer current_gamma; + private ByteBuffer saved_gamma; + private DisplayMode current_mode; + + private boolean mode_set; + private boolean isFullscreen; + private boolean isMinimized; + private boolean isFocused; + private boolean did_maximize; + private boolean inAppActivate; + + public WindowsDisplay() { + current_display = this; + } + + public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException { + close_requested = false; + is_dirty = false; + isFullscreen = fullscreen; + isMinimized = false; + isFocused = false; + did_maximize = false; + nCreateWindow(mode, fullscreen, x, y); +// peer_info.initDC(); + showWindow(getHwnd(), SW_SHOWDEFAULT); + setForegroundWindow(getHwnd()); + setFocus(getHwnd()); + } + private native void nCreateWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException; + + public void destroyWindow() { + nDestroyWindow(); + resetCursorClipping(); + } + private static native void nDestroyWindow(); + static void resetCursorClipping() { + if (cursor_clipped) { + try { + clipCursor(0, null); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to reset cursor clipping: " + e); + } + cursor_clipped = false; + } + } + + private static void getGlobalClientRect(long hwnd, Rect rect) { + rect_buffer.put(0, 0).put(1, 0); + clientToScreen(hwnd, rect_buffer); + int offset_x = rect_buffer.get(0); + int offset_y = rect_buffer.get(1); + getClientRect(hwnd, rect_buffer); + rect.copyFromBuffer(rect_buffer); + rect.offset(offset_x, offset_y); + } + + static WindowsDirectInput createDirectInput() throws LWJGLException { + try { + return new WindowsDirectInput8(getDllInstance()); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to create DirectInput 8 interface, falling back to DirectInput 3"); + return new WindowsDirectInput3(getDllInstance()); + } + } + + static void setupCursorClipping(long hwnd) throws LWJGLException { + cursor_clipped = true; + getGlobalClientRect(hwnd, rect); + rect.copyToBuffer(rect_buffer); + clipCursor(hwnd, rect_buffer); + } + private static native void clipCursor(long hwnd, IntBuffer rect) throws LWJGLException; + + public void switchDisplayMode(DisplayMode mode) throws LWJGLException { + nSwitchDisplayMode(mode); + current_mode = mode; + mode_set = true; + } + private static native void nSwitchDisplayMode(DisplayMode mode) throws LWJGLException; + + /* + * Called when the application is alt-tabbed to or from + */ + private void appActivate(boolean active) { + if (inAppActivate) { + return; + } + inAppActivate = true; + isFocused = active; + if (active) { + if (isFullscreen) { + restoreDisplayMode(); + } + showWindow(getHwnd(), SW_RESTORE); + setForegroundWindow(getHwnd()); + setFocus(getHwnd()); + did_maximize = true; + } else if (isFullscreen) { + showWindow(getHwnd(), SW_SHOWMINNOACTIVE); + resetDisplayMode(); + } + inAppActivate = false; + } + private static native void showWindow(long hwnd, int mode); + private static native void setForegroundWindow(long hwnd); + private static native void setFocus(long hwnd); + + private void restoreDisplayMode() { + try { + doSetGammaRamp(current_gamma); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to restore gamma: " + e.getMessage()); + } + + if (!mode_set) { + mode_set = true; + try { + nSwitchDisplayMode(current_mode); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to restore display mode: " + e.getMessage()); + } + } + } + + public void resetDisplayMode() { + try { + doSetGammaRamp(saved_gamma); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to reset gamma ramp: " + e.getMessage()); + } + current_gamma = saved_gamma; + if (mode_set) { + mode_set = false; + nResetDisplayMode(); + } + resetCursorClipping(); + } + private static native void nResetDisplayMode(); + + public int getGammaRampLength() { + return GAMMA_LENGTH; + } + + public void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException { + doSetGammaRamp(convertToNativeRamp(gammaRamp)); + } + private static native ByteBuffer convertToNativeRamp(FloatBuffer gamma_ramp) throws LWJGLException; + private static native ByteBuffer getCurrentGammaRamp() throws LWJGLException; + + private void doSetGammaRamp(ByteBuffer native_gamma) throws LWJGLException { + nSetGammaRamp(native_gamma); + current_gamma = native_gamma; + } + private static native void nSetGammaRamp(ByteBuffer native_ramp) throws LWJGLException; + + public String getAdapter() { + try { + String adapter_string = WindowsRegistry.queryRegistrationKey( + WindowsRegistry.HKEY_LOCAL_MACHINE, + "HARDWARE\\DeviceMap\\Video", + "\\Device\\Video0"); + String root_key = "\\registry\\machine\\"; + if (adapter_string.toLowerCase().startsWith(root_key)) { + String driver_value = WindowsRegistry.queryRegistrationKey( + WindowsRegistry.HKEY_LOCAL_MACHINE, + adapter_string.substring(root_key.length()), + "InstalledDisplayDrivers"); + return driver_value; + } + } catch (LWJGLException e) { + LWJGLUtil.log("Exception occurred while querying registry: " + e); + } + return null; + } + + public String getVersion() { + String driver = getAdapter(); + if (driver != null) { + WindowsFileVersion version = nGetVersion(driver + ".dll"); + if (version != null) + return version.toString(); + } + return null; + } + private native WindowsFileVersion nGetVersion(String driver); + + public DisplayMode init() throws LWJGLException { + current_gamma = saved_gamma = getCurrentGammaRamp(); + return current_mode = getCurrentDisplayMode(); + } + private static native DisplayMode getCurrentDisplayMode() throws LWJGLException; + + public native void setTitle(String title); + + public boolean isCloseRequested() { + boolean saved = close_requested; + close_requested = false; + return saved; + } + + public boolean isVisible() { + return !isMinimized; + } + + public boolean isActive() { + return isFocused; + } + + public boolean isDirty() { + boolean saved = is_dirty; + is_dirty = false; + return saved; + } + + public PeerInfo createPeerInfo() throws LWJGLException { + peer_info = new WindowsDisplayPeerInfo(); + return peer_info; + } + + public void update() { + nUpdate(); + if (did_maximize) { + did_maximize = false; + /** + * WORKAROUND: + * Making the context current (redundantly) when the window + * is maximized helps some gfx recover from fullscreen + */ + try { + if (Display.getDrawable().getContext() != null && Display.getDrawable().getContext().isCurrent()) + Display.getDrawable().getContext().makeCurrent(); + } catch (LWJGLException e) { + LWJGLUtil.log("Exception occurred while trying to make context current: " + e); + } + } + } + private static native void nUpdate(); + + public void reshape(int x, int y, int width, int height) { + if (!isFullscreen) + nReshape(getHwnd(), x, y, width, height); + } + private static native void nReshape(long hwnd, int x, int y, int width, int height); + public native DisplayMode[] getAvailableDisplayModes() throws LWJGLException; + + /* Mouse */ + public boolean hasWheel() { + return mouse.hasWheel(); + } + + public int getButtonCount() { + return mouse.getButtonCount(); + } + + public void createMouse() throws LWJGLException { + mouse = new WindowsMouse(getHwnd()); + } + + public void destroyMouse() { + if (mouse != null) + mouse.destroy(); + mouse = null; + } + + public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) { + update(); + mouse.poll(coord_buffer, buttons); + } + + public void readMouse(ByteBuffer buffer) { + update(); + mouse.read(buffer); + } + + public void grabMouse(boolean grab) { + mouse.grab(grab, shouldGrab()); + try { + updateCursor(); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to update cursor: " + e); + } + } + + public int getNativeCursorCapabilities() { + return Cursor.CURSOR_ONE_BIT_TRANSPARENCY; + } + + public void setCursorPosition(int x, int y) { + getGlobalClientRect(getHwnd(), rect); + int transformed_x = rect.left + x; + int transformed_y = rect.bottom - 1 - y; + nSetCursorPosition(transformed_x, transformed_y); + setMousePosition(x, y); + } + private static native void nSetCursorPosition(int x, int y); + + public void setNativeCursor(Object handle) throws LWJGLException { + current_cursor = handle; + updateCursor(); + } + + private void updateCursor() throws LWJGLException { + if (mouse != null && mouse.isGrabbed()) + nSetNativeCursor(getHwnd(), mouse.getBlankCursor()); + else + nSetNativeCursor(getHwnd(), current_cursor); + } + static native void nSetNativeCursor(long hwnd, Object handle) throws LWJGLException; + + public int getMinCursorSize() { + return getSystemMetrics(SM_CXCURSOR); + } + + public int getMaxCursorSize() { + return getSystemMetrics(SM_CXCURSOR); + } + + static native int getSystemMetrics(int index); + + private static native long getDllInstance(); + public static native long getHwnd(); + private static native long getDesktopWindow(); + static void centerCursor(long hwnd) { + getGlobalClientRect(getHwnd(), rect); + int local_offset_x = rect.left; + int local_offset_y = rect.top; + getGlobalClientRect(getDesktopWindow(), rect2); + Rect.intersect(rect, rect2, rect); + int center_x = (rect.left + rect.right)/2; + int center_y = (rect.top + rect.bottom)/2; + nSetCursorPosition(center_x, center_y); + int local_x = center_x - local_offset_x; + int local_y = center_y - local_offset_y; + if (current_display != null) + current_display.setMousePosition(local_x, transformY(getHwnd(), local_y)); + } + + private void setMousePosition(int x, int y) { + if (mouse != null) + mouse.setPosition(x, y); + } + + /* Keyboard */ + public void createKeyboard() throws LWJGLException { + keyboard = new WindowsKeyboard(getHwnd()); + } + + public void destroyKeyboard() { + keyboard.destroy(); + keyboard = null; + } + + public void pollKeyboard(ByteBuffer keyDownBuffer) { + update(); + keyboard.poll(keyDownBuffer); + } + + public void readKeyboard(ByteBuffer buffer) { + update(); + keyboard.read(buffer); + } + +// public native int isStateKeySet(int key); + + public static native ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; + + public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { + return doCreateCursor(width, height, xHotspot, yHotspot, numImages, images, delays); + } + + static Object doCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { + return nCreateCursor(width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1); + } + + public void destroyCursor(Object cursorHandle) { + doDestroyCursor(cursorHandle); + } + static native void doDestroyCursor(Object cursorHandle); + +// public int getPbufferCapabilities() { +// try { +// // Return the capabilities of a minimum pixel format +// return nGetPbufferCapabilities(new PixelFormat(0, 0, 0, 0, 0, 0, 0, 0, false)); +// } catch (LWJGLException e) { +// LWJGLUtil.log("Exception occurred while determining pbuffer capabilities: " + e); +// return 0; +// } +// } +// private native int nGetPbufferCapabilities(PixelFormat format) throws LWJGLException; + + /** + * Sets one or more icons for the Display. + *
      + *
    • On Windows you should supply at least one 16x16 icon and one 32x32.
    • + *
    • Linux (and similar platforms) expect one 32x32 icon.
    • + *
    • Mac OS X should be supplied one 128x128 icon
    • + *
    + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public int setIcon(ByteBuffer[] icons) { + boolean done16 = false; + boolean done32 = false; + int used = 0; + + for (int i=0;i>> 30) & 0x1); + byte state = (byte)(1 - ((lParam >>> 31) & 0x1)); + boolean repeat = state == previous_state; + if (keyboard != null) + keyboard.handleChar((int)(wParam & 0xFF), millis, repeat); + } + + private void handleKeyButton(long wParam, long lParam, long millis) { + byte previous_state = (byte)((lParam >>> 30) & 0x1); + byte state = (byte)(1 - ((lParam >>> 31) & 0x1)); + boolean repeat = state == previous_state; // Repeat message + byte extended = (byte)((lParam >>> 24) & 0x1); + int scan_code = (int)((lParam >>> 16) & 0xFF); + if (keyboard != null) + keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis, repeat); + } + + private static int transformY(long hwnd, int y) { + getClientRect(hwnd, rect_buffer); + rect.copyFromBuffer(rect_buffer); + return (rect.bottom - rect.top) - 1 - y; + } + + private static native void clientToScreen(long hwnd, IntBuffer point); + + private static boolean handleMessage(long hwnd, int msg, long wParam, long lParam, long millis) { + if (current_display != null) + return current_display.doHandleMessage(hwnd, msg, wParam, lParam, millis); + else + return false; + } + + private boolean doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) { + if ((isFullscreen || (mouse != null && mouse.isGrabbed())) && !isMinimized && isFocused) { + try { + setupCursorClipping(getHwnd()); + } catch (LWJGLException e) { + LWJGLUtil.log("setupCursorClipping failed: " + e.getMessage()); + } + } else { + resetCursorClipping(); + } + switch (msg) { + // disable screen saver and monitor power down messages which wreak havoc + case WM_ACTIVATE: + switch ((int)wParam) { + case WA_ACTIVE: + case WA_CLICKACTIVE: + appActivate(true); + break; + case WA_INACTIVE: + appActivate(false); + break; + } + return true; + case WM_SIZE: + switch ((int)wParam) { + case SIZE_RESTORED: + case SIZE_MAXIMIZED: + isMinimized = false; + break; + case SIZE_MINIMIZED: + isMinimized = true; + break; + } + return false; + case WM_MOUSEMOVE: + int xPos = (int)(short)(lParam & 0xFFFF); + int yPos = transformY(getHwnd(), (int)(short)((lParam >> 16) & 0xFFFF)); + handleMouseMoved(xPos, yPos, millis); + return true; + case WM_MOUSEWHEEL: + int dwheel = (int)(short)((wParam >> 16) & 0xFFFF); + handleMouseScrolled(dwheel, millis); + return true; + case WM_LBUTTONDOWN: + handleMouseButton(0, 1, millis); + return true; + case WM_LBUTTONUP: + handleMouseButton(0, 0, millis); + return true; + case WM_RBUTTONDOWN: + handleMouseButton(1, 1, millis); + return true; + case WM_RBUTTONUP: + handleMouseButton(1, 0, millis); + return true; + case WM_MBUTTONDOWN: + handleMouseButton(2, 1, millis); + return true; + case WM_MBUTTONUP: + handleMouseButton(2, 0, millis); + return true; + case WM_CHAR: + handleChar(wParam, lParam, millis); + return true; + case WM_SYSKEYDOWN: /* Fall through */ + case WM_SYSKEYUP: /* Fall through */ + case WM_KEYUP: /* Fall through */ + case WM_KEYDOWN: + handleKeyButton(wParam, lParam, millis); + return false; + case WM_DESTROY: + case WM_CLOSE: + case WM_QUIT: + close_requested = true; + return true; + case WM_SYSCOMMAND: + switch ((int)(wParam & 0xfff0)) { + case SC_KEYMENU: + case SC_MOUSEMENU: + case SC_SCREENSAVE: + case SC_MONITORPOWER: + return true; + case SC_CLOSE: + close_requested = true; + return true; + default: + break; + } + return false; + case WM_PAINT: + is_dirty = true; + return false; + default: + return false; + } + } + + public int getWidth() { + return Display.getDisplayMode().getWidth(); + } + + public int getHeight() { + return Display.getDisplayMode().getHeight(); + } + + private static final class Rect { + public int top; + public int bottom; + public int left; + public int right; + + public void copyToBuffer(IntBuffer buffer) { + buffer.put(0, top).put(1, bottom).put(2, left).put(3, right); + } + + public void copyFromBuffer(IntBuffer buffer) { + top = buffer.get(0); + bottom = buffer.get(1); + left = buffer.get(2); + right = buffer.get(3); + } + + public void offset(int offset_x, int offset_y) { + left += offset_x; + right += offset_x; + top += offset_y; + bottom += offset_y; + } + + public static void intersect(Rect r1, Rect r2, Rect dst) { + dst.top = Math.max(r1.top, r2.top); + dst.bottom = Math.min(r1.bottom, r2.bottom); + dst.left = Math.max(r1.left, r2.left); + dst.right = Math.min(r1.right, r2.right); + } + + public String toString() { + return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right; + } + } +} diff --git a/src/java/org/lwjgl/d3d/WindowsDisplayPeerInfo.java b/src/java/org/lwjgl/d3d/WindowsDisplayPeerInfo.java new file mode 100644 index 00000000..2ed21d4b --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsDisplayPeerInfo.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; + +/** +* +* @author elias_naur +* @version $Revision: 2575 $ +* $Id: WindowsDisplayPeerInfo.java 2575 2006-09-19 14:17:13Z elias_naur $ +*/ +final class WindowsDisplayPeerInfo extends WindowsPeerInfo { +// private final PixelFormat pixel_format; + + public WindowsDisplayPeerInfo() { +// this.pixel_format = pixel_format; +// GLContext.loadOpenGLLibrary(); + } + + void initDC() throws LWJGLException { + nInitDC(getHandle()); +// choosePixelFormat(0, 0, pixel_format, null, true, true, false, true); + } + private static native void nInitDC(ByteBuffer peer_info_handle); + + protected void doLockAndInitHandle() throws LWJGLException { + // NO-OP + } + + protected void doUnlock() throws LWJGLException { + // NO-OP + } + + public void destroy() { + super.destroy(); +// GLContext.unloadOpenGLLibrary(); + } +} diff --git a/src/java/org/lwjgl/d3d/WindowsFileVersion.java b/src/java/org/lwjgl/d3d/WindowsFileVersion.java new file mode 100644 index 00000000..f2413480 --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsFileVersion.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * @author elias_naur + */ + +final class WindowsFileVersion { + private final int product_version_ms; + private final int product_version_ls; + + public WindowsFileVersion(int product_version_ms, int product_version_ls) { + this.product_version_ms = product_version_ms; + this.product_version_ls = product_version_ls; + } + + public String toString() { + int f1 = (product_version_ms >> 16) & 0xFFFF; + int f2 = product_version_ms & 0xFFFF; + int f3 = (product_version_ls >> 16) & 0xFFFF; + int f4 = product_version_ls & 0xFFFF; + return f1 + "." + f2 + "." + f3 + "." + f4; + } +} diff --git a/src/java/org/lwjgl/d3d/WindowsKeyboard.java b/src/java/org/lwjgl/d3d/WindowsKeyboard.java new file mode 100644 index 00000000..278c479e --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsKeyboard.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the Windows implementation of the Keyboard. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Keyboard; + +final class WindowsKeyboard { + private final static int MAPVK_VK_TO_VSC = 0; + + private final static int BUFFER_SIZE = 50; + + private final long hwnd; + private final ByteBuffer keyboard_state; + private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE]; + private final EventQueue event_queue = new EventQueue(Keyboard.EVENT_SIZE); + private final ByteBuffer tmp_event = ByteBuffer.allocate(Keyboard.EVENT_SIZE); + + private boolean grabbed; + + private boolean has_retained_event; // Indicates if we're waiting for a WM_CHAR + private int retained_key_code; + private byte retained_state; + private int retained_char; + private long retained_millis; + private boolean retained_repeat; + + public WindowsKeyboard(long hwnd) throws LWJGLException { + this.hwnd = hwnd; + keyboard_state = BufferUtils.createByteBuffer(256); + } + private static native boolean isWindowsNT(); + + public void destroy() { + } + + public void grab(boolean grab) { + if(grab) { + if (!grabbed) { + grabbed = true; + } + } else { + if (grabbed) { + grabbed = false; + } + } + } + + public void poll(ByteBuffer keyDownBuffer) { + int old_position = keyDownBuffer.position(); + keyDownBuffer.put(key_down_buffer); + keyDownBuffer.position(old_position); + } + + private static native int MapVirtualKey(int uCode, int uMapType); + private static native int ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags); + private static native int ToAscii(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, ByteBuffer lpChar, int flags); + private static native int GetKeyboardState(ByteBuffer lpKeyState); + private static native int GetKeyState(int virt_key); + + private void putEvent(int keycode, byte state, int ch, long millis, boolean repeat) { + tmp_event.clear(); + tmp_event.putInt(keycode).put(state).putInt(ch).putLong(millis*1000000).put(repeat ? (byte)1 : (byte)0); + tmp_event.flip(); + event_queue.putEvent(tmp_event); + } + + private boolean checkShiftKey(int virt_key, byte state) { + int key_state = (GetKeyState(virt_key) >>> 15) & 0x1; + int lwjgl_code = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key); + return (key_down_buffer[lwjgl_code] == 1 - state) && (key_state == state); + } + + private int translateShift(int scan_code, byte state) { + if (checkShiftKey(WindowsKeycodes.VK_LSHIFT, state)) { + return WindowsKeycodes.VK_LSHIFT; + } else if (checkShiftKey(WindowsKeycodes.VK_RSHIFT, state)) { + return WindowsKeycodes.VK_RSHIFT; + } else { + if (scan_code== 0x2A) + return WindowsKeycodes.VK_LSHIFT; + else { + if (scan_code == 0x36) + return WindowsKeycodes.VK_RSHIFT; + else + return WindowsKeycodes.VK_LSHIFT; + } + } + } + + private int translateExtended(int virt_key, int scan_code, byte state, boolean extended) { + switch (virt_key) { + case WindowsKeycodes.VK_SHIFT: + return translateShift(scan_code, state); + case WindowsKeycodes.VK_CONTROL: + return extended ? WindowsKeycodes.VK_RCONTROL : WindowsKeycodes.VK_LCONTROL; + case WindowsKeycodes.VK_MENU: + return extended ? WindowsKeycodes.VK_RMENU : WindowsKeycodes.VK_LMENU; + default: + return virt_key; + } + } + + private void flushRetained() { + if (has_retained_event) { + has_retained_event = false; + putEvent(retained_key_code, retained_state, retained_char, retained_millis, retained_repeat); + } + } + + public void handleKey(int virt_key, int scan_code, boolean extended, byte event_state, long millis, boolean repeat) { + virt_key = translateExtended(virt_key, scan_code, event_state, extended); + flushRetained(); + has_retained_event = true; + int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key); + if (keycode < key_down_buffer.length) + key_down_buffer[keycode] = event_state; + retained_key_code = keycode; + retained_state = event_state; + retained_millis = millis; + retained_char = 0; + retained_repeat = repeat; + } + + public void handleChar(int event_char, long millis, boolean repeat) { + if (has_retained_event && retained_char != 0) + flushRetained(); + if (!has_retained_event) { + putEvent(0, (byte)0, event_char, millis, repeat); + } else + retained_char = event_char; + } + + public void read(ByteBuffer buffer) { + flushRetained(); + event_queue.copyEvents(buffer); + } +} diff --git a/src/java/org/lwjgl/d3d/WindowsKeycodes.java b/src/java/org/lwjgl/d3d/WindowsKeycodes.java new file mode 100644 index 00000000..e044134c --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsKeycodes.java @@ -0,0 +1,577 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * @author elias_naur + */ + +import org.lwjgl.input.Keyboard; + +final class WindowsKeycodes { + public final static int VK_LBUTTON = 0x01; + public final static int VK_RBUTTON = 0x02; + public final static int VK_CANCEL = 0x03; + public final static int VK_MBUTTON = 0x04; /* NOT contiguous with L & RBUTTON */ + + public final static int VK_XBUTTON1 = 0x05; /* NOT contiguous with L & RBUTTON */ + public final static int VK_XBUTTON2 = 0x06; /* NOT contiguous with L & RBUTTON */ + +/* + * 0x07 : unassigned + */ + + public final static int VK_BACK = 0x08; + public final static int VK_TAB = 0x09; + +/* + * 0x0A - 0x0B : reserved + */ + + public final static int VK_CLEAR = 0x0C; + public final static int VK_RETURN = 0x0D; + + public final static int VK_SHIFT = 0x10; + public final static int VK_CONTROL = 0x11; + public final static int VK_MENU = 0x12; + public final static int VK_PAUSE = 0x13; + public final static int VK_CAPITAL = 0x14; + + public final static int VK_KANA = 0x15; + public final static int VK_HANGEUL = 0x15; /* old name - should be here for compatibility */ + public final static int VK_HANGUL = 0x15; + public final static int VK_JUNJA = 0x17; + public final static int VK_FINAL = 0x18; + public final static int VK_HANJA = 0x19; + public final static int VK_KANJI = 0x19; + + public final static int VK_ESCAPE = 0x1B; + + public final static int VK_CONVERT = 0x1C; + public final static int VK_NONCONVERT = 0x1D; + public final static int VK_ACCEPT = 0x1E; + public final static int VK_MODECHANGE = 0x1F; + + public final static int VK_SPACE = 0x20; + public final static int VK_PRIOR = 0x21; + public final static int VK_NEXT = 0x22; + public final static int VK_END = 0x23; + public final static int VK_HOME = 0x24; + public final static int VK_LEFT = 0x25; + public final static int VK_UP = 0x26; + public final static int VK_RIGHT = 0x27; + public final static int VK_DOWN = 0x28; + public final static int VK_SELECT = 0x29; + public final static int VK_PRINT = 0x2A; + public final static int VK_EXECUTE = 0x2B; + public final static int VK_SNAPSHOT = 0x2C; + public final static int VK_INSERT = 0x2D; + public final static int VK_DELETE = 0x2E; + public final static int VK_HELP = 0x2F; +/* + * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39) + * 0x40 : unassigned + * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) + */ + public final static int VK_0 = 0x30; + public final static int VK_1 = 0x31; + public final static int VK_2 = 0x32; + public final static int VK_3 = 0x33; + public final static int VK_4 = 0x34; + public final static int VK_5 = 0x35; + public final static int VK_6 = 0x36; + public final static int VK_7 = 0x37; + public final static int VK_8 = 0x38; + public final static int VK_9 = 0x39; + + public final static int VK_A = 0x41; + public final static int VK_B = 0x42; + public final static int VK_C = 0x43; + public final static int VK_D = 0x44; + public final static int VK_E = 0x45; + public final static int VK_F = 0x46; + public final static int VK_G = 0x47; + public final static int VK_H = 0x48; + public final static int VK_I = 0x49; + public final static int VK_J = 0x4A; + public final static int VK_K = 0x4B; + public final static int VK_L = 0x4C; + public final static int VK_M = 0x4D; + public final static int VK_N = 0x4E; + public final static int VK_O = 0x4F; + public final static int VK_P = 0x50; + public final static int VK_Q = 0x51; + public final static int VK_R = 0x52; + public final static int VK_S = 0x53; + public final static int VK_T = 0x54; + public final static int VK_U = 0x55; + public final static int VK_V = 0x56; + public final static int VK_W = 0x57; + public final static int VK_X = 0x58; + public final static int VK_Y = 0x59; + public final static int VK_Z = 0x5A; + + public final static int VK_LWIN = 0x5B; + public final static int VK_RWIN = 0x5C; + public final static int VK_APPS = 0x5D; +/* + * 0x5E : reserved; + */ + + public final static int VK_SLEEP = 0x5F; + + public final static int VK_NUMPAD0 = 0x60; + public final static int VK_NUMPAD1 = 0x61; + public final static int VK_NUMPAD2 = 0x62; + public final static int VK_NUMPAD3 = 0x63; + public final static int VK_NUMPAD4 = 0x64; + public final static int VK_NUMPAD5 = 0x65; + public final static int VK_NUMPAD6 = 0x66; + public final static int VK_NUMPAD7 = 0x67; + public final static int VK_NUMPAD8 = 0x68; + public final static int VK_NUMPAD9 = 0x69; + public final static int VK_MULTIPLY = 0x6A; + public final static int VK_ADD = 0x6B; + public final static int VK_SEPARATOR = 0x6C; + public final static int VK_SUBTRACT = 0x6D; + public final static int VK_DECIMAL = 0x6E; + public final static int VK_DIVIDE = 0x6F; + public final static int VK_F1 = 0x70; + public final static int VK_F2 = 0x71; + public final static int VK_F3 = 0x72; + public final static int VK_F4 = 0x73; + public final static int VK_F5 = 0x74; + public final static int VK_F6 = 0x75; + public final static int VK_F7 = 0x76; + public final static int VK_F8 = 0x77; + public final static int VK_F9 = 0x78; + public final static int VK_F10 = 0x79; + public final static int VK_F11 = 0x7A; + public final static int VK_F12 = 0x7B; + public final static int VK_F13 = 0x7C; + public final static int VK_F14 = 0x7D; + public final static int VK_F15 = 0x7E; + public final static int VK_F16 = 0x7F; + public final static int VK_F17 = 0x80; + public final static int VK_F18 = 0x81; + public final static int VK_F19 = 0x82; + public final static int VK_F20 = 0x83; + public final static int VK_F21 = 0x84; + public final static int VK_F22 = 0x85; + public final static int VK_F23 = 0x86; + public final static int VK_F24 = 0x87; + +/* + * 0x88 - 0x8F : unassigned; + */ + + public final static int VK_NUMLOCK = 0x90; + public final static int VK_SCROLL = 0x91; + +/* + * NEC PC-9800 kbd definitions + */ + public final static int VK_OEM_NEC_EQUAL = 0x92; // '=' key on numpad +/* + * Fujitsu/OASYS kbd definitions + */ + public final static int VK_OEM_FJ_JISHO = 0x92; // 'Dictionary' key + public final static int VK_OEM_FJ_MASSHOU = 0x93; // 'Unregister word' key + public final static int VK_OEM_FJ_TOUROKU = 0x94; // 'Register word' key + public final static int VK_OEM_FJ_LOYA = 0x95; // 'Left OYAYUBI' key + public final static int VK_OEM_FJ_ROYA = 0x96; // 'Right OYAYUBI' key + +/* + * 0x97 - 0x9F : unassigned + */ + +/* + * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. + * Used only as parameters to GetAsyncKeyState() and GetKeyState(). + * No other API or message will distinguish left and right keys in this way. + */ + public final static int VK_LSHIFT = 0xA0; + public final static int VK_RSHIFT = 0xA1; + public final static int VK_LCONTROL = 0xA2; + public final static int VK_RCONTROL = 0xA3; + public final static int VK_LMENU = 0xA4; + public final static int VK_RMENU = 0xA5; + + public final static int VK_BROWSER_BACK = 0xA6; + public final static int VK_BROWSER_FORWARD = 0xA7; + public final static int VK_BROWSER_REFRESH = 0xA8; + public final static int VK_BROWSER_STOP = 0xA9; + public final static int VK_BROWSER_SEARCH = 0xAA; + public final static int VK_BROWSER_FAVORITES = 0xAB; + public final static int VK_BROWSER_HOME = 0xAC; + + public final static int VK_VOLUME_MUTE = 0xAD; + public final static int VK_VOLUME_DOWN = 0xAE; + public final static int VK_VOLUME_UP = 0xAF; + public final static int VK_MEDIA_NEXT_TRACK = 0xB0; + public final static int VK_MEDIA_PREV_TRACK = 0xB1; + public final static int VK_MEDIA_STOP = 0xB2; + public final static int VK_MEDIA_PLAY_PAUSE = 0xB3; + public final static int VK_LAUNCH_MAIL = 0xB4; + public final static int VK_LAUNCH_MEDIA_SELECT = 0xB5; + public final static int VK_LAUNCH_APP1 = 0xB6; + public final static int VK_LAUNCH_APP2 = 0xB7; + +/* + * 0xB8 - 0xB9 : reserved + */ + + public final static int VK_OEM_1 = 0xBA; // ';:' for US + public final static int VK_OEM_PLUS = 0xBB; // '+' any country + public final static int VK_OEM_COMMA = 0xBC; // ',' any country + public final static int VK_OEM_MINUS = 0xBD; // '-' any country + public final static int VK_OEM_PERIOD = 0xBE; // '.' any country + public final static int VK_OEM_2 = 0xBF; // '/?' for US + public final static int VK_OEM_3 = 0xC0; // '`~' for US + +/* + * 0xC1 - 0xD7 : reserved + */ + +/* + * 0xD8 - 0xDA : unassigned + */ + + public final static int VK_OEM_4 = 0xDB; // '[{' for US + public final static int VK_OEM_5 = 0xDC; // '\|' for US + public final static int VK_OEM_6 = 0xDD; // ']}' for US + public final static int VK_OEM_7 = 0xDE; // ''"' for US + public final static int VK_OEM_8 = 0xDF; + +/* + * 0xE0 : reserved + */ + +/* + * Various extended or enhanced keyboards + */ + public final static int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd + public final static int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd. + public final static int VK_ICO_HELP = 0xE3; // Help key on ICO + public final static int VK_ICO_00 = 0xE4; // 00 key on ICO + + public final static int VK_PROCESSKEY = 0xE5; + + public final static int VK_ICO_CLEAR = 0xE6; + + + public final static int VK_PACKET = 0xE7; + +/* + * 0xE8 : unassigned + */ + +/* + * Nokia/Ericsson definitions + */ + public final static int VK_OEM_RESET = 0xE9; + public final static int VK_OEM_JUMP = 0xEA; + public final static int VK_OEM_PA1 = 0xEB; + public final static int VK_OEM_PA2 = 0xEC; + public final static int VK_OEM_PA3 = 0xED; + public final static int VK_OEM_WSCTRL = 0xEE; + public final static int VK_OEM_CUSEL = 0xEF; + public final static int VK_OEM_ATTN = 0xF0; + public final static int VK_OEM_FINISH = 0xF1; + public final static int VK_OEM_COPY = 0xF2; + public final static int VK_OEM_AUTO = 0xF3; + public final static int VK_OEM_ENLW = 0xF4; + public final static int VK_OEM_BACKTAB = 0xF5; + + public final static int VK_ATTN = 0xF6; + public final static int VK_CRSEL = 0xF7; + public final static int VK_EXSEL = 0xF8; + public final static int VK_EREOF = 0xF9; + public final static int VK_PLAY = 0xFA; + public final static int VK_ZOOM = 0xFB; + public final static int VK_NONAME = 0xFC; + public final static int VK_PA1 = 0xFD; + public final static int VK_OEM_CLEAR = 0xFE; + + public static int mapVirtualKeyToLWJGLCode(int virt_key) { + switch (virt_key) { + case VK_ESCAPE: + return Keyboard.KEY_ESCAPE; + case VK_1: + return Keyboard.KEY_1; + case VK_2: + return Keyboard.KEY_2; + case VK_3: + return Keyboard.KEY_3; + case VK_4: + return Keyboard.KEY_4; + case VK_5: + return Keyboard.KEY_5; + case VK_6: + return Keyboard.KEY_6; + case VK_7: + return Keyboard.KEY_7; + case VK_8: + return Keyboard.KEY_8; + case VK_9: + return Keyboard.KEY_9; + case VK_0: + return Keyboard.KEY_0; + case VK_OEM_MINUS: + return Keyboard.KEY_MINUS; +/* case VK_EQUALS: + return Keyboard.KEY_EQUALS;*/ + case VK_BACK: + return Keyboard.KEY_BACK; + case VK_TAB: + return Keyboard.KEY_TAB; + case VK_Q: + return Keyboard.KEY_Q; + case VK_W: + return Keyboard.KEY_W; + case VK_E: + return Keyboard.KEY_E; + case VK_R: + return Keyboard.KEY_R; + case VK_T: + return Keyboard.KEY_T; + case VK_Y: + return Keyboard.KEY_Y; + case VK_U: + return Keyboard.KEY_U; + case VK_I: + return Keyboard.KEY_I; + case VK_O: + return Keyboard.KEY_O; + case VK_P: + return Keyboard.KEY_P; + case VK_OEM_4: + return Keyboard.KEY_LBRACKET; + case VK_OEM_6: + return Keyboard.KEY_RBRACKET; + case VK_RETURN: + return Keyboard.KEY_RETURN; + case VK_LCONTROL: + return Keyboard.KEY_LCONTROL; + case VK_A: + return Keyboard.KEY_A; + case VK_S: + return Keyboard.KEY_S; + case VK_D: + return Keyboard.KEY_D; + case VK_F: + return Keyboard.KEY_F; + case VK_G: + return Keyboard.KEY_G; + case VK_H: + return Keyboard.KEY_H; + case VK_J: + return Keyboard.KEY_J; + case VK_K: + return Keyboard.KEY_K; + case VK_L: + return Keyboard.KEY_L; + case VK_OEM_1: + return Keyboard.KEY_SEMICOLON; + case VK_OEM_7: + return Keyboard.KEY_APOSTROPHE; + case VK_OEM_3: + return Keyboard.KEY_GRAVE; + case VK_LSHIFT: + return Keyboard.KEY_LSHIFT; + case VK_OEM_5: + return Keyboard.KEY_BACKSLASH; + case VK_Z: + return Keyboard.KEY_Z; + case VK_X: + return Keyboard.KEY_X; + case VK_C: + return Keyboard.KEY_C; + case VK_V: + return Keyboard.KEY_V; + case VK_B: + return Keyboard.KEY_B; + case VK_N: + return Keyboard.KEY_N; + case VK_M: + return Keyboard.KEY_M; + case VK_OEM_COMMA: + return Keyboard.KEY_COMMA; + case VK_OEM_PERIOD: + return Keyboard.KEY_PERIOD; + case VK_OEM_2: + return Keyboard.KEY_SLASH; + case VK_RSHIFT: + return Keyboard.KEY_RSHIFT; + case VK_MULTIPLY: + return Keyboard.KEY_MULTIPLY; + case VK_LMENU: + return Keyboard.KEY_LMENU; + case VK_SPACE: + return Keyboard.KEY_SPACE; + case VK_CAPITAL: + return Keyboard.KEY_CAPITAL; + case VK_F1: + return Keyboard.KEY_F1; + case VK_F2: + return Keyboard.KEY_F2; + case VK_F3: + return Keyboard.KEY_F3; + case VK_F4: + return Keyboard.KEY_F4; + case VK_F5: + return Keyboard.KEY_F5; + case VK_F6: + return Keyboard.KEY_F6; + case VK_F7: + return Keyboard.KEY_F7; + case VK_F8: + return Keyboard.KEY_F8; + case VK_F9: + return Keyboard.KEY_F9; + case VK_F10: + return Keyboard.KEY_F10; + case VK_NUMLOCK: + return Keyboard.KEY_NUMLOCK; + case VK_SCROLL: + return Keyboard.KEY_SCROLL; + case VK_NUMPAD7: + return Keyboard.KEY_NUMPAD7; + case VK_NUMPAD8: + return Keyboard.KEY_NUMPAD8; + case VK_NUMPAD9: + return Keyboard.KEY_NUMPAD9; + case VK_SUBTRACT: + return Keyboard.KEY_SUBTRACT; + case VK_NUMPAD4: + return Keyboard.KEY_NUMPAD4; + case VK_NUMPAD5: + return Keyboard.KEY_NUMPAD5; + case VK_NUMPAD6: + return Keyboard.KEY_NUMPAD6; + case VK_ADD: + return Keyboard.KEY_ADD; + case VK_NUMPAD1: + return Keyboard.KEY_NUMPAD1; + case VK_NUMPAD2: + return Keyboard.KEY_NUMPAD2; + case VK_NUMPAD3: + return Keyboard.KEY_NUMPAD3; + case VK_NUMPAD0: + return Keyboard.KEY_NUMPAD0; + case VK_DECIMAL: + return Keyboard.KEY_DECIMAL; + case VK_F11: + return Keyboard.KEY_F11; + case VK_F12: + return Keyboard.KEY_F12; + case VK_F13: + return Keyboard.KEY_F13; + case VK_F14: + return Keyboard.KEY_F14; + case VK_F15: + return Keyboard.KEY_F15; + case VK_KANA: + return Keyboard.KEY_KANA; + case VK_CONVERT: + return Keyboard.KEY_CONVERT; + case VK_NONCONVERT: + return Keyboard.KEY_NOCONVERT; +/* case VK_YEN: + return Keyboard.KEY_YEN; + case VK_NUMPADEQUALS: + return Keyboard.KEY_NUMPADEQUALS; + case VK_CIRCUMFLEX: + return Keyboard.KEY_CIRCUMFLEX; + case VK_AT: + return Keyboard.KEY_AT; + case VK_COLON: + return Keyboard.KEY_COLON; + case VK_UNDERLINE: + return Keyboard.KEY_UNDERLINE;*/ + case VK_KANJI: + return Keyboard.KEY_KANJI; +/* case VK_STOP: + return Keyboard.KEY_STOP; + case VK_AX: + return Keyboard.KEY_AX; + case VK_UNLABELED: + return Keyboard.KEY_UNLABELED; + case VK_NUMPADENTER: + return Keyboard.KEY_NUMPADENTER;*/ + case VK_RCONTROL: + return Keyboard.KEY_RCONTROL; + case VK_SEPARATOR: + return Keyboard.KEY_NUMPADCOMMA; + case VK_DIVIDE: + return Keyboard.KEY_DIVIDE; + case VK_PRINT: + return Keyboard.KEY_SYSRQ; + case VK_RMENU: + return Keyboard.KEY_RMENU; + case VK_PAUSE: + return Keyboard.KEY_PAUSE; + case VK_HOME: + return Keyboard.KEY_HOME; + case VK_UP: + return Keyboard.KEY_UP; + case VK_PRIOR: + return Keyboard.KEY_PRIOR; + case VK_LEFT: + return Keyboard.KEY_LEFT; + case VK_RIGHT: + return Keyboard.KEY_RIGHT; + case VK_END: + return Keyboard.KEY_END; + case VK_DOWN: + return Keyboard.KEY_DOWN; + case VK_NEXT: + return Keyboard.KEY_NEXT; + case VK_INSERT: + return Keyboard.KEY_INSERT; + case VK_DELETE: + return Keyboard.KEY_DELETE; + case VK_LWIN: + return Keyboard.KEY_LWIN; + case VK_RWIN: + return Keyboard.KEY_RWIN; + case VK_APPS: + return Keyboard.KEY_APPS; +/* case VK_POWER: + return Keyboard.KEY_POWER;*/ + case VK_SLEEP: + return Keyboard.KEY_SLEEP; + default: + return Keyboard.KEY_NONE; + } + } +} diff --git a/src/java/org/lwjgl/d3d/WindowsMouse.java b/src/java/org/lwjgl/d3d/WindowsMouse.java new file mode 100644 index 00000000..51ca421d --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsMouse.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is the Windows implementation of the Mouse. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Mouse; +import org.lwjgl.input.Cursor; + +final class WindowsMouse { + private final long hwnd; + + private final int mouse_button_count; + private final boolean has_wheel; + + private final EventQueue event_queue = new EventQueue(Mouse.EVENT_SIZE); + + private final ByteBuffer mouse_event = ByteBuffer.allocate(Mouse.EVENT_SIZE); + private final Object blank_cursor; + + private boolean mouse_grabbed; + private byte[] button_states; + private int accum_dx; + private int accum_dy; + private int accum_dwheel; + private int last_x; + private int last_y; + + public WindowsMouse(long hwnd) throws LWJGLException { + this.hwnd = hwnd; + this.mouse_button_count = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CMOUSEBUTTONS); + this.has_wheel = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_MOUSEWHEELPRESENT) != 0; + this.blank_cursor = createBlankCursor(); + this.button_states = new byte[mouse_button_count]; + } + + private Object createBlankCursor() throws LWJGLException { + int width = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CXCURSOR); + int height = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CYCURSOR); + IntBuffer pixels = BufferUtils.createIntBuffer(width*height); + return WindowsDisplay.doCreateCursor(width, height, 0, 0, 1, pixels, null); + } + + public boolean isGrabbed() { + return mouse_grabbed; + } + + public boolean hasWheel() { + return has_wheel; + } + + public int getButtonCount() { + return mouse_button_count; + } + + public void poll(IntBuffer coord_buffer, ByteBuffer buttons) { + for (int i = 0; i < coord_buffer.remaining(); i++) + coord_buffer.put(coord_buffer.position() + i, 0); + int num_buttons = mouse_button_count; + coord_buffer.put(coord_buffer.position() + 2, accum_dwheel); + if (num_buttons > button_states.length) + num_buttons = button_states.length; + for (int j = 0; j < num_buttons; j++) { + buttons.put(buttons.position() + j, button_states[j]); + } + if (isGrabbed()) { + coord_buffer.put(coord_buffer.position() + 0, accum_dx); + coord_buffer.put(coord_buffer.position() + 1, accum_dy); + } else { + coord_buffer.put(coord_buffer.position() + 0, last_x); + coord_buffer.put(coord_buffer.position() + 1, last_y); + } + accum_dx = accum_dy = accum_dwheel = 0; + } + + private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) { + mouse_event.clear(); + mouse_event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz).putLong(nanos); + mouse_event.flip(); + event_queue.putEvent(mouse_event); + } + + private void putMouseEvent(byte button, byte state, int dz, long nanos) { + if (mouse_grabbed) + putMouseEventWithCoords(button, state, 0, 0, dz, nanos); + else + putMouseEventWithCoords(button, state, last_x, last_y, dz, nanos); + } + + public void read(ByteBuffer buffer) { + event_queue.copyEvents(buffer); + } + + public Object getBlankCursor() { + return blank_cursor; + } + + public void grab(boolean grab, boolean should_center) { + if (grab) { + if (!mouse_grabbed) { + mouse_grabbed = true; + try { + WindowsDisplay.setupCursorClipping(hwnd); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to setup cursor clipping: " + e); + } + if (should_center) + centerCursor(); + } + } else { + if (mouse_grabbed) { + mouse_grabbed = false; + WindowsDisplay.resetCursorClipping(); + } + } + event_queue.clearEvents(); + } + + public void handleMouseScrolled(int event_dwheel, long millis) { + accum_dwheel += event_dwheel; + putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000); + } + + private void centerCursor() { + WindowsDisplay.centerCursor(hwnd); + } + + public void setPosition(int x, int y) { + this.last_x = x; + this.last_y = y; + } + + public void destroy() { + WindowsDisplay.doDestroyCursor(blank_cursor); + } + + public void handleMouseMoved(int x, int y, long millis, boolean should_center) { + int dx = x - last_x; + int dy = y - last_y; + if (dx != 0 || dy != 0) { + accum_dx += dx; + accum_dy += dy; + last_x = x; + last_y = y; + long nanos = millis*1000000; + if (mouse_grabbed) { + putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos); + if (should_center) + centerCursor(); + } else { + putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0, nanos); + } + } + } + + public void handleMouseButton(byte button, byte state, long millis) { + putMouseEvent(button, state, 0, millis*1000000); + if (button < button_states.length) + button_states[button] = state != 0 ? (byte)1 : (byte)0; + } +} diff --git a/src/java/org/lwjgl/d3d/WindowsPeerInfo.java b/src/java/org/lwjgl/d3d/WindowsPeerInfo.java new file mode 100644 index 00000000..1c0b910a --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsPeerInfo.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import org.lwjgl.LWJGLException; + +/** +* +* @author elias_naur +* @version $Revision: 2618 $ +* $Id: WindowsPeerInfo.java 2618 2006-10-30 15:46:42Z elias_naur $ +*/ +abstract class WindowsPeerInfo extends PeerInfo { + public WindowsPeerInfo() { + super(createHandle()); + } + private static native ByteBuffer createHandle(); + + protected void choosePixelFormat(int origin_x, int origin_y, PixelFormat pixel_format, IntBuffer pixel_format_caps, boolean use_hdc_bpp, boolean support_window, boolean support_pbuffer, boolean double_buffered) throws LWJGLException { + nChoosePixelFormat(getHandle(), origin_x, origin_y, pixel_format, pixel_format_caps, use_hdc_bpp, support_window, support_pbuffer, double_buffered); + } + private static native void nChoosePixelFormat(ByteBuffer peer_info_handle, int origin_x, int origin_y, PixelFormat pixel_format, IntBuffer pixel_format_caps, boolean use_hdc_bpp, boolean support_window, boolean support_pbuffer, boolean double_buffered) throws LWJGLException; + + public final long getHwnd() { + return nGetHwnd(getHandle()); + } + private static native long nGetHwnd(ByteBuffer handle); +} diff --git a/src/java/org/lwjgl/d3d/WindowsRegistry.java b/src/java/org/lwjgl/d3d/WindowsRegistry.java new file mode 100644 index 00000000..b906927d --- /dev/null +++ b/src/java/org/lwjgl/d3d/WindowsRegistry.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +/** + * This is an interface to the windows registry + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; +import org.lwjgl.Sys; + +final class WindowsRegistry { + final static int HKEY_CLASSES_ROOT = 1; + final static int HKEY_CURRENT_USER = 2; + final static int HKEY_LOCAL_MACHINE = 3; + final static int HKEY_USERS = 4; + + static { + Sys.initialize(); + } + + /** + * Query the registry value specified by the root key, subkey, value tuple + */ + static String queryRegistrationKey(int root_key, String subkey, String value) throws LWJGLException { + switch (root_key) { + case HKEY_CLASSES_ROOT: + case HKEY_CURRENT_USER: + case HKEY_LOCAL_MACHINE: + case HKEY_USERS: + break; + default: + throw new IllegalArgumentException("Invalid enum: " + root_key); + } + return nQueryRegistrationKey(root_key, subkey, value); + } + + private static native String nQueryRegistrationKey(int root_key, String subkey, String value) throws LWJGLException; +}