aboutsummaryrefslogtreecommitdiffstatsci
path: root/vkEngine
diff options
context:
space:
mode:
Diffstat (limited to 'vkEngine')
-rw-r--r--vkEngine/VkEngine.cs156
-rw-r--r--vkEngine/enums.cs203
2 files changed, 359 insertions, 0 deletions
diff --git a/vkEngine/VkEngine.cs b/vkEngine/VkEngine.cs
new file mode 100644
index 00000000..d4a43c5b
--- /dev/null
+++ b/vkEngine/VkEngine.cs
@@ -0,0 +1,156 @@
+//
+// VkEngine.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2018 jp
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Runtime.InteropServices;
+using vkh;
+
+namespace vkglfw
+{
+ public delegate void VKEmousebuttonfun(IntPtr win, MouseButton but, KeyAction action, KeyModifiers mods);
+ public delegate void VKEcursorposfun(IntPtr win, double x, double y);
+ public delegate void VKEscrollfun(IntPtr win, double xdelta, double ydelta);
+ public delegate void VKEkeyfun(IntPtr win, Key key, int scancode, KeyAction action, KeyModifiers mods);
+ public delegate void VKEcharfun(IntPtr win, uint codepoint);
+
+ public class VkEngine : IDisposable
+ {
+ const string libvkglfw = "vkglfw";
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern IntPtr vkengine_create (VkPhysicalDeviceType devType, uint width, uint height);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_close (IntPtr e);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_destroy (IntPtr vkengine_handle);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_blitter_run (IntPtr vkengine_handle, IntPtr vkImage);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern IntPtr vkengine_get_device (IntPtr vkengine_handle);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern IntPtr vkengine_get_physical_device (IntPtr vkengine_handle);
+
+ //[DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ //internal static extern void vkengine_get_queues_properties (IntPtr e, ref IntPtr ptrProps, out uint count);
+
+ //[DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ //internal static extern void vkengine_free_ptr (IntPtr ptr);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern IntPtr vkengine_get_queue (IntPtr vkengine_handle);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern uint vkengine_get_queue_fam_idx (IntPtr vkengine_handle);
+
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_set_mouse_but_callback (IntPtr e, VKEmousebuttonfun onMouseBut);
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_set_cursor_pos_callback (IntPtr e, VKEcursorposfun onMouseMove);
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_set_scroll_callback (IntPtr e, VKEscrollfun onScroll);
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_set_key_callback (IntPtr e, VKEkeyfun onKey);
+ [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)]
+ internal static extern void vkengine_set_char_callback (IntPtr e, VKEcharfun onChar);
+
+
+ void onMouseButton(IntPtr win, MouseButton but, KeyAction action, KeyModifiers mods){}
+ void onMouseMove(IntPtr win, double x, double y){
+ Console.WriteLine("mouse ({0},{1})", x, y);
+ }
+ void onScroll(IntPtr win, double xdelta, double ydelta){}
+ void onKey(IntPtr win, Key key, int scancode, KeyAction action, KeyModifiers mods){
+ if (key == Key.Escape && action == KeyAction.Press)
+ vkengine_close (handle);
+ }
+ void onChar(IntPtr win, uint codepoint){}
+
+ IntPtr handle = IntPtr.Zero;
+
+ public VkEngine (int width, int height)
+ {
+ handle = vkengine_create (VkPhysicalDeviceType.DiscreteGPU, (uint)width, (uint)height);
+
+ vkengine_set_mouse_but_callback (handle, onMouseButton);
+ vkengine_set_cursor_pos_callback (handle, onMouseMove);
+ vkengine_set_scroll_callback (handle, onScroll);
+ vkengine_set_key_callback (handle, onKey);
+ vkengine_set_char_callback (handle, onChar);
+ }
+ ~VkEngine ()
+ {
+ Dispose (false);
+ }
+
+// public QueueFamilyProperties[] AvailableQueues {
+// get {
+// IntPtr ptr = IntPtr.Zero, p;
+// uint count;
+// vkengine_get_queues_properties (handle, ref ptr, out count);
+// QueueFamilyProperties[] qfps = new QueueFamilyProperties[count];
+// p = ptr;
+// for (int i = 0; i < count; i++) {
+// qfps[i] = (QueueFamilyProperties)Marshal.PtrToStructure(p, typeof(QueueFamilyProperties));
+// p += Marshal.SizeOf(typeof(QueueFamilyProperties));
+// }
+// vkengine_free_ptr (ptr);
+// return qfps;
+// }
+// }
+
+ public IntPtr Handle { get { return handle; }}
+ public IntPtr Device { get { return vkengine_get_device (handle); }}
+ public IntPtr Phy { get { return vkengine_get_physical_device (handle); }}
+ public IntPtr Queue { get { return vkengine_get_queue (handle); }}
+ public uint QueueFamIdx { get { return vkengine_get_queue_fam_idx (handle); }}
+
+ public void Run (vkvg.Surface surf) {
+ vkengine_blitter_run (handle, surf.VkImage);
+ }
+
+ #region IDisposable implementation
+ public void Dispose ()
+ {
+ Dispose (true);
+ GC.SuppressFinalize (this);
+ }
+
+ protected virtual void Dispose (bool disposing)
+ {
+ if (!disposing || handle == IntPtr.Zero)
+ return;
+
+ vkengine_destroy (handle);
+ handle = IntPtr.Zero;
+ }
+ #endregion
+ }
+}
+
diff --git a/vkEngine/enums.cs b/vkEngine/enums.cs
new file mode 100644
index 00000000..549d4401
--- /dev/null
+++ b/vkEngine/enums.cs
@@ -0,0 +1,203 @@
+//
+// enums.cs
+//
+// Author:
+// Copyright (c) 2013 Antonie Blom
+//
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace vkglfw
+{
+ public enum VkPhysicalDeviceType {
+ Other = 0,
+ IntegratedGPU = 1,
+ DiscreteGPU = 2,
+ VirtualGPU = 3,
+ CPU = 4,
+ }
+ //taken from pencil.gaming (Copyright (c) 2013 Antonie Blom)
+ public enum KeyModifiers
+ {
+ Shift = 1 << 0, //1
+ Control = 1 << 1, //2
+ Alt = 1 << 2, //4
+ Super = 1 << 3 //8
+ }
+ public enum KeyAction {
+ Release = 0,
+ Press,
+ Repeat,
+ }
+ public enum MouseButton {
+ Button1 = 0,
+ Button2,
+ Button3,
+ Button4,
+ Button5,
+ Button6,
+ Button7,
+ Button8,
+ LeftButton = 0,
+ RightButton,
+ MiddleButton,
+ }
+ public enum Joystick {
+ Joystick1 = 0,
+ Joystick2,
+ Joystick3,
+ Joystick4,
+ Joystick5,
+ Joystick6,
+ Joystick7,
+ Joystick8,
+ Joystick9,
+ Joystick10,
+ Joystick11,
+ Joystick12,
+ Joystick13,
+ Joystick14,
+ Joystick15,
+ Joystick16,
+ }
+ public enum Key {
+ Space = 32,
+ Apostrophe = 39,
+ Comma = 44,
+ Minus,
+ Period,
+ Slash,
+ Zero,
+ One,
+ Two,
+ Three,
+ Four,
+ Five,
+ Six,
+ Seven,
+ Eight,
+ Nine,
+ Semicolon = 59,
+ Equal = 61,
+ A = 65,
+ B,
+ C,
+ D,
+ E,
+ F,
+ G,
+ H,
+ I,
+ J,
+ K,
+ L,
+ M,
+ N,
+ O,
+ P,
+ Q,
+ R,
+ S,
+ T,
+ U,
+ V,
+ W,
+ X,
+ Y,
+ Z,
+ LeftBracket,
+ Backslash,
+ RightBracket,
+ GraveAccent = 96,
+ World1 = 161,
+ World2,
+ Escape = 256,
+ Enter,
+ Tab,
+ Backspace,
+ Insert,
+ Delete,
+ Right,
+ Left,
+ Down,
+ Up,
+ PageUp,
+ PageDown,
+ Home,
+ End,
+ CapsLock = 280,
+ ScrollLock,
+ NumLock,
+ PrintScreen,
+ Pause,
+ F1 = 290,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
+ F13,
+ F14,
+ F15,
+ F16,
+ F17,
+ F18,
+ F19,
+ F20,
+ F21,
+ F22,
+ F23,
+ F24,
+ F25,
+ KP0 = 320,
+ KP1,
+ KP2,
+ KP3,
+ KP4,
+ KP5,
+ KP6,
+ KP7,
+ KP8,
+ KP9,
+ KPDecimal,
+ KPDivide,
+ KPMultiply,
+ KPSubtract,
+ KPAdd,
+ KPEnter,
+ KPEqual,
+ LeftShift = 340,
+ LeftControl,
+ LeftAlt,
+ LeftSuper,
+ RightShift,
+ RightControl,
+ RightAlt,
+ RightSuper,
+ Menu,
+ }
+}
+