From c24fe5015ace7633b1a955d6e5ed67d867a94af6 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sat, 13 Mar 2021 16:17:23 +0100 Subject: [PATCH 01/17] remove unused lines in triangle example --- examples/triangle-gl/app.d | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/examples/triangle-gl/app.d b/examples/triangle-gl/app.d index 3b23296..96fd786 100644 --- a/examples/triangle-gl/app.d +++ b/examples/triangle-gl/app.d @@ -36,22 +36,15 @@ int main() { const GLuint program = getProgram(); const GLuint vaoTriangle = getTriangleVao(); - const GLint mvp_location = glGetUniformLocation(program, "MVP"); - double oldTime = glfwGetTime(); while (!glfwWindowShouldClose(window)) { - const newTime = glfwGetTime(); - const elapsedTime = newTime - oldTime; - oldTime = newTime; - int width, height; glfwGetFramebufferSize(window, &width, &height); - const float ratio = width / cast(float) height; glViewport(0, 0, width, height); glUseProgram(program); glBindVertexArray(vaoTriangle); - glDrawArrays(GL_TRIANGLES, 0, 3); + glDrawArrays(GL_TRIANGLES, /*first*/ 0, /*count*/ 3); glfwSwapBuffers(window); glfwPollEvents(); @@ -66,12 +59,11 @@ extern(C) @nogc nothrow void errorCallback(int error, const(char)* description) // SHADER PROGRAM ///////////////////////// immutable string vertexShaderSource = "#version 330 -uniform mat4 MVP; layout(location = 0) in vec2 position; layout(location = 1) in vec3 color; out vec3 fragColor; void main() { - gl_Position = vec4(position, 0.0, 1.0); // MVP * + gl_Position = vec4(position, 0.0, 1.0); fragColor = color; }"; From e74ae440360cbfe1672606960a5e6c99ea3ea78c Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sun, 17 Jan 2021 20:34:14 +0100 Subject: [PATCH 02/17] add rumble support --- examples/empty-window/app.d | 1 + source/glfw3/api.d | 32 ++++++++++ source/glfw3/input.d | 28 +++++++++ source/glfw3/internal.d | 1 + source/glfw3/linux_joystick.d | 59 ++++++++++++++++- source/glfw3/linuxinput.d | 115 ++++++++++++++++++++++++++++++++++ source/glfw3/win32_init.d | 2 + source/glfw3/win32_joystick.d | 17 ++++- source/glfw3/win32_platform.d | 2 + 9 files changed, 254 insertions(+), 3 deletions(-) diff --git a/examples/empty-window/app.d b/examples/empty-window/app.d index bba15f9..9b588c2 100644 --- a/examples/empty-window/app.d +++ b/examples/empty-window/app.d @@ -125,6 +125,7 @@ void printMonitorState() { void printJoystickState() { for (int js = GLFW_JOYSTICK_1; js <= GLFW_JOYSTICK_LAST; js++) { if (glfwJoystickPresent(js)) { + // glfwSetJoystickRumble(js, 1.0, 1.0); printf("Joystick %d has name `%s` and GUID `%s`\n", js, glfwGetJoystickName(js), glfwGetJoystickGUID(js)); int buttonsLength, axesLength, hatsLength; const(ubyte)* buttonsPtr = glfwGetJoystickButtons(js, &buttonsLength); diff --git a/source/glfw3/api.d b/source/glfw3/api.d index 29e68c4..dd9aefb 100644 --- a/source/glfw3/api.d +++ b/source/glfw3/api.d @@ -5199,6 +5199,38 @@ const(char)* glfwGetGamepadName(int jid); */ int glfwGetGamepadState(int jid, GLFWgamepadstate* state); +/** Sets the intensity of a joystick's rumble effect. + * + * This function sends vibration data to joysticks that implement haptic feedback + * effects using two vibration motors: a low-frequency motor, and a + * high-frequency motor. + * + * Vibration intensity is a value between 0.0 and 1.0 inclusive, where 0.0 is no + * vibration, and 1.0 is maximum vibration. It is set separately for the + * joystick's low frequency and high frequency rumble motors. + * + * If the specified joystick is not present or does not support the rumble effect, + * this function will return `GLFW_FALSE` but will not generate an error. + * + * Params: + * jid = The [joystick](@ref joysticks) to vibrate. + * slowMotorIntensity = The low frequency vibration intensity. + * fastMotorIntensity = The high frequency vibration intensity. + * Returns: `GLFW_TRUE` if successful, or `GLFW_FALSE` if no joystick is connected, + * or the joystick does not support the rumble effect. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * Thread_Safety: This function must only be called from the main thread. + * + * Note: @win32 This function is only implemented for XInput devices. + * Note: @macos This function is not implemented. + * + * Ingroup: input + */ +int glfwSetJoystickRumble(int jid, float slowMotorIntensity, float fastMotorIntensity); + /** Sets the clipboard to the specified string. * * This function sets the system clipboard to the specified, UTF-8 encoded diff --git a/source/glfw3/input.d b/source/glfw3/input.d index 98425b4..36a9d92 100644 --- a/source/glfw3/input.d +++ b/source/glfw3/input.d @@ -1252,6 +1252,34 @@ int glfwGetGamepadState(int jid, GLFWgamepadstate* state) { return GLFW_TRUE; } +int glfwSetJoystickRumble(int jid, float slowMotorIntensity, float fastMotorIntensity) +{ + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + + mixin(_GLFW_REQUIRE_INIT_OR_RETURN!"GLFW_FALSE"); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return GLFW_FALSE; + } + + js = _glfw.joysticks.ptr + jid; + if (!js.present) + return GLFW_FALSE; + + slowMotorIntensity = slowMotorIntensity < 0.0f ? 0.0f : slowMotorIntensity; + slowMotorIntensity = slowMotorIntensity > 1.0f ? 1.0f : slowMotorIntensity; + + fastMotorIntensity = fastMotorIntensity < 0.0f ? 0.0f : fastMotorIntensity; + fastMotorIntensity = fastMotorIntensity > 1.0f ? 1.0f : fastMotorIntensity; + + return _glfwPlatformSetJoystickRumble(js, slowMotorIntensity, fastMotorIntensity); +} + void glfwSetClipboardString(GLFWwindow* handle, const(char)* string) { assert(string != null); diff --git a/source/glfw3/internal.d b/source/glfw3/internal.d index 264c553..b44e4b2 100644 --- a/source/glfw3/internal.d +++ b/source/glfw3/internal.d @@ -587,6 +587,7 @@ const(char)* _glfwPlatformGetClipboardString(); int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode); void _glfwPlatformUpdateGamepadGUID(char* guid); +int _glfwPlatformSetJoystickRumble(_GLFWjoystick* js, float slowMotorIntensity, float fastMotorIntensity); ulong _glfwPlatformGetTimerValue(); ulong _glfwPlatformGetTimerFrequency(); diff --git a/source/glfw3/linux_joystick.d b/source/glfw3/linux_joystick.d index 78b3d07..b21b78a 100644 --- a/source/glfw3/linux_joystick.d +++ b/source/glfw3/linux_joystick.d @@ -64,6 +64,8 @@ struct _GLFWjoystickLinux { int[ABS_CNT] absMap; input_absinfo[ABS_CNT] absInfo; int[2][4] hats; + bool hasRumble = false; + ff_effect rumble; } // Linux-specific joystick API data @@ -156,6 +158,30 @@ private void pollAbsState(_GLFWjoystick* js) { // #define isBitSet(bit, arr) (arr[(bit) / 8] & (1 << ((bit) % 8))) enum string isBitSet(string bit, string arr) = ` (`~arr~`[(`~bit~`) / 8] & (1 << ((`~bit~`) % 8)))`; +private void initJoystickForceFeedback(_GLFWjoystickLinux *linjs) +{ + linjs.hasRumble = false; + + char[(FF_CNT + 7) / 8] ffBits = 0; + if (ioctl(linjs.fd, EVIOCGBIT!(typeof(ffBits))(EV_FF), ffBits.ptr) < 0) + { + return; + } + + if (mixin(isBitSet!("FF_RUMBLE", "ffBits"))) + { + linjs.rumble.type = + linjs.rumble.type = FF_RUMBLE; + linjs.rumble.id = -1; + linjs.rumble.direction = 0; + linjs.rumble.trigger = ff_trigger(/*.button*/ 0, /*.interval*/ 0); + linjs.rumble.replay = ff_replay(/*length*/ 2000, /*delay*/ 0); + linjs.rumble.u.rumble = ff_rumble_effect(/*strong_magnitude*/ 0, /*weak_magnitude*/ 0); // xinput rumble lasts ~2 seconds + + linjs.hasRumble = (ioctl(linjs.fd, EVIOCSFF, &linjs.rumble) >= 0); + } +} + // Attempt to open the specified joystick device // private GLFWbool openJoystickDevice(const(char)* path) { @@ -168,7 +194,7 @@ private GLFWbool openJoystickDevice(const(char)* path) { } _GLFWjoystickLinux linjs = _GLFWjoystickLinux(0); - linjs.fd = open(path, O_RDONLY | O_NONBLOCK); + linjs.fd = open(path, O_RDWR | O_NONBLOCK); if (linjs.fd == -1) return GLFW_FALSE; @@ -255,6 +281,8 @@ private GLFWbool openJoystickDevice(const(char)* path) { } } + initJoystickForceFeedback(&linjs); + _GLFWjoystick* js = _glfwAllocJoystick(name.ptr, guid.ptr, axisCount, buttonCount, hatCount); if (!js) { @@ -508,4 +536,31 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) { } void _glfwPlatformUpdateGamepadGUID(char* guid) { -} \ No newline at end of file +} + +int _glfwPlatformSetJoystickRumble(_GLFWjoystick* js, float slowMotorIntensity, float fastMotorIntensity) +{ + _GLFWjoystickLinux *linjs = &js.linjs; + + if (!js.linjs.hasRumble) + return GLFW_FALSE; + + js.linjs.rumble.u.rumble = ff_rumble_effect( + /*strong_magnitude*/ cast(ushort) (65_535 * slowMotorIntensity), + /*weak_magnitude*/ cast(ushort) (65_535 * fastMotorIntensity) + ); + + input_event play; + play.type = EV_FF; + play.code = linjs.rumble.id; + play.value = 1; + + if (ioctl(linjs.fd, EVIOCSFF, &linjs.rumble) < 0) { + return GLFW_FALSE; + } + if (write(linjs.fd, &play, play.sizeof) < 0) { + return GLFW_FALSE; + } + + return GLFW_TRUE; +} diff --git a/source/glfw3/linuxinput.d b/source/glfw3/linuxinput.d index 70e9902..f8f30a0 100644 --- a/source/glfw3/linuxinput.d +++ b/source/glfw3/linuxinput.d @@ -37,6 +37,121 @@ auto EVIOCSABS(T)(T abs) {return _IOW!input_absinfo('E', 0xc0 + (abs));} enum EVIOCGID = _IOR!input_id('E', 0x02); auto EVIOCGNAME(T)() {return _IOC!T(_IOC_READ, 'E', 0x06);} +enum EVIOCSFF = _IOW!ff_effect('E', 0x80); +enum EVIOCRMFF = _IOW!int('E', 0x81); +enum EVIOCGEFFECTS =_IOR!int('E', 0x84); +enum EVIOCGRAB = _IOW!int('E', 0x90); +enum EVIOCREVOKE = _IOW!int('E', 0x91); + +// force feedback +enum FF_STATUS_STOPPED = 0x00; +enum FF_STATUS_PLAYING = 0x01; +enum FF_STATUS_MAX = 0x01; + +struct ff_replay { + ushort length; + ushort delay; +} + +struct ff_trigger { + ushort button; + ushort interval; +} + +struct ff_envelope { + ushort attack_length; + ushort attack_level; + ushort fade_length; + ushort fade_level; +} + +struct ff_constant_effect { + short level; + ff_envelope envelope; +} + +struct ff_ramp_effect { + short start_level; + short end_level; + ff_envelope envelope; +} + +struct ff_condition_effect { + ushort right_saturation; + ushort left_saturation; + + short right_coeff; + short left_coeff; + + ushort deadband; + short center; +} + +struct ff_periodic_effect { + ushort waveform; + ushort period; + short magnitude; + short offset; + ushort phase; + + ff_envelope envelope; + + uint custom_len; + short* custom_data; +} + +struct ff_rumble_effect { + ushort strong_magnitude; + ushort weak_magnitude; +} + +struct ff_effect { + ushort type; + short id; + ushort direction; + ff_trigger trigger; + ff_replay replay; + + union _U { + ff_constant_effect constant; + ff_ramp_effect ramp; + ff_periodic_effect periodic; + ff_condition_effect[2] condition; + ff_rumble_effect rumble; + } + _U u; +} + +enum FF_RUMBLE = 0x50; +enum FF_PERIODIC = 0x51; +enum FF_CONSTANT = 0x52; +enum FF_SPRING = 0x53; +enum FF_FRICTION = 0x54; +enum FF_DAMPER = 0x55; +enum FF_INERTIA = 0x56; +enum FF_RAMP = 0x57; + +enum FF_EFFECT_MIN = FF_RUMBLE; +enum FF_EFFECT_MAX = FF_RAMP; + +enum FF_SQUARE = 0x58; +enum FF_TRIANGLE = 0x59; +enum FF_SINE = 0x5a; +enum FF_SAW_UP = 0x5b; +enum FF_SAW_DOWN = 0x5c; +enum FF_CUSTOM = 0x5d; + +enum FF_WAVEFORM_MIN = FF_SQUARE; +enum FF_WAVEFORM_MAX = FF_CUSTOM; + +enum FF_GAIN = 0x60; +enum FF_AUTOCENTER = 0x61; + +enum FF_MAX_EFFECTS = FF_GAIN; + +enum FF_MAX = 0x7f; +enum FF_CNT = (FF_MAX+1); + // // input-event-codes.h // diff --git a/source/glfw3/win32_init.d b/source/glfw3/win32_init.d index 7e96e8b..b3ecb8d 100644 --- a/source/glfw3/win32_init.d +++ b/source/glfw3/win32_init.d @@ -132,6 +132,8 @@ static GLFWbool loadLibraries() { GetProcAddress(_glfw.win32.xinput.instance, "XInputGetCapabilities"); _glfw.win32.xinput.GetState = cast(PFN_XInputGetState) GetProcAddress(_glfw.win32.xinput.instance, "XInputGetState"); + _glfw.win32.xinput.SetState = cast(PFN_XInputSetState) + GetProcAddress(_glfw.win32.xinput.instance, "XInputSetState"); break; } diff --git a/source/glfw3/win32_joystick.d b/source/glfw3/win32_joystick.d index 50b5d14..1741259 100644 --- a/source/glfw3/win32_joystick.d +++ b/source/glfw3/win32_joystick.d @@ -744,4 +744,19 @@ void _glfwPlatformUpdateGamepadGUID(char* guid) { sprintf(guid, "03000000%.4s0000%.4s000000000000", original.ptr, original.ptr + 4); } -} \ No newline at end of file +} + +int _glfwPlatformSetJoystickRumble(_GLFWjoystick* js, float slowMotorIntensity, float fastMotorIntensity) +{ + XINPUT_VIBRATION effect; + + if (js.win32.device) + return GLFW_FALSE; + + ZeroMemory(&effect, XINPUT_VIBRATION.sizeof); + + effect.wLeftMotorSpeed = cast(WORD)(65535.0f * slowMotorIntensity); + effect.wRightMotorSpeed = cast(WORD)(65535.0f * fastMotorIntensity); + + return cast(int) (mixin(XInputSetState)(js.win32.index, &effect) == ERROR_SUCCESS); +} diff --git a/source/glfw3/win32_platform.d b/source/glfw3/win32_platform.d index d4a2af1..aa2a599 100644 --- a/source/glfw3/win32_platform.d +++ b/source/glfw3/win32_platform.d @@ -171,6 +171,7 @@ extern(Windows) { alias PFN_XInputGetState = DWORD function(DWORD,XINPUT_STATE*); enum XInputGetCapabilities = "_glfw.win32.xinput.GetCapabilities"; enum XInputGetState = "_glfw.win32.xinput.GetState"; + enum XInputSetState = "_glfw.win32.xinput.SetState"; // dinput8.dll function pointer typedefs alias PFN_DirectInput8Create = HRESULT function(HINSTANCE,DWORD,REFIID,LPVOID*,LPUNKNOWN); @@ -299,6 +300,7 @@ struct _GLFWlibraryWin32 { HINSTANCE instance; PFN_XInputGetCapabilities GetCapabilities; PFN_XInputGetState GetState; + PFN_XInputSetState SetState; }_Xinput xinput; struct _User32 { From a1babfc708eade5f4a7951f2cb102d205189a556 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 18 Jan 2021 19:53:16 +0100 Subject: [PATCH 03/17] windows fixes --- examples/empty-window/app.d | 2 +- source/glfw3/win32_joystick.d | 8 ++-- source/glfw3/win32_platform.d | 1 + source/glfw3/xinput.d | 90 +---------------------------------- 4 files changed, 7 insertions(+), 94 deletions(-) diff --git a/examples/empty-window/app.d b/examples/empty-window/app.d index 9b588c2..5bd18ef 100644 --- a/examples/empty-window/app.d +++ b/examples/empty-window/app.d @@ -125,7 +125,7 @@ void printMonitorState() { void printJoystickState() { for (int js = GLFW_JOYSTICK_1; js <= GLFW_JOYSTICK_LAST; js++) { if (glfwJoystickPresent(js)) { - // glfwSetJoystickRumble(js, 1.0, 1.0); + //glfwSetJoystickRumble(js, /*slow*/ 0.25, /*fast*/ 0.25); printf("Joystick %d has name `%s` and GUID `%s`\n", js, glfwGetJoystickName(js), glfwGetJoystickGUID(js)); int buttonsLength, axesLength, hatsLength; const(ubyte)* buttonsPtr = glfwGetJoystickButtons(js, &buttonsLength); diff --git a/source/glfw3/win32_joystick.d b/source/glfw3/win32_joystick.d index 1741259..24fe43b 100644 --- a/source/glfw3/win32_joystick.d +++ b/source/glfw3/win32_joystick.d @@ -748,15 +748,13 @@ void _glfwPlatformUpdateGamepadGUID(char* guid) { int _glfwPlatformSetJoystickRumble(_GLFWjoystick* js, float slowMotorIntensity, float fastMotorIntensity) { - XINPUT_VIBRATION effect; + XINPUT_VIBRATION effect = _XINPUT_VIBRATION.init; if (js.win32.device) return GLFW_FALSE; - ZeroMemory(&effect, XINPUT_VIBRATION.sizeof); - - effect.wLeftMotorSpeed = cast(WORD)(65535.0f * slowMotorIntensity); - effect.wRightMotorSpeed = cast(WORD)(65535.0f * fastMotorIntensity); + effect.wLeftMotorSpeed = cast(WORD)(65_535.0f * slowMotorIntensity); + effect.wRightMotorSpeed = cast(WORD)(65_535.0f * fastMotorIntensity); return cast(int) (mixin(XInputSetState)(js.win32.index, &effect) == ERROR_SUCCESS); } diff --git a/source/glfw3/win32_platform.d b/source/glfw3/win32_platform.d index aa2a599..b75f8c4 100644 --- a/source/glfw3/win32_platform.d +++ b/source/glfw3/win32_platform.d @@ -169,6 +169,7 @@ extern(Windows) { // xinput.dll function pointer typedefs alias PFN_XInputGetCapabilities = DWORD function(DWORD,DWORD,XINPUT_CAPABILITIES*); alias PFN_XInputGetState = DWORD function(DWORD,XINPUT_STATE*); + alias PFN_XInputSetState = DWORD function(DWORD,XINPUT_VIBRATION*); enum XInputGetCapabilities = "_glfw.win32.xinput.GetCapabilities"; enum XInputGetState = "_glfw.win32.xinput.GetState"; enum XInputSetState = "_glfw.win32.xinput.SetState"; diff --git a/source/glfw3/xinput.d b/source/glfw3/xinput.d index 5ae29cf..cfddfa9 100644 --- a/source/glfw3/xinput.d +++ b/source/glfw3/xinput.d @@ -2,33 +2,9 @@ module glfw3.xinput; extern(Windows): @nogc: nothrow: __gshared: -/* - * The Wine project - Xinput Joystick Library - * Copyright 2008 Andrew Fenn - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ import core.sys.windows.windef; -/* - * Bitmasks for the joysticks buttons, determines what has - * been pressed on the joystick, these need to be mapped - * to whatever device you're using instead of an xbox 360 - * joystick - */ enum XINPUT_GAMEPAD_DPAD_UP = 0x0001; enum XINPUT_GAMEPAD_DPAD_DOWN = 0x0002; @@ -45,18 +21,11 @@ enum XINPUT_GAMEPAD_B = 0x2000; enum XINPUT_GAMEPAD_X = 0x4000; enum XINPUT_GAMEPAD_Y = 0x8000; -/* - * Defines the flags used to determine if the user is pushing - * down on a button, not holding a button, etc - */ enum XINPUT_KEYSTROKE_KEYDOWN = 0x0001; enum XINPUT_KEYSTROKE_KEYUP = 0x0002; enum XINPUT_KEYSTROKE_REPEAT = 0x0004; -/* - * Defines the codes which are returned by XInputGetKeystroke - */ enum VK_PAD_A = 0x5800; enum VK_PAD_B = 0x5801; @@ -91,26 +60,11 @@ enum VK_PAD_RTHUMB_UPRIGHT = 0x5835; enum VK_PAD_RTHUMB_DOWNRIGHT = 0x5836; enum VK_PAD_RTHUMB_DOWNLEFT = 0x5837; -/* - * Deadzones are for analogue joystick controls on the joypad - * which determine when input should be assumed to be in the - * middle of the pad. This is a threshold to stop a joypad - * controlling the game when the player isn't touching the - * controls. - */ enum XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE = 7849; enum XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE = 8689; enum XINPUT_GAMEPAD_TRIGGER_THRESHOLD = 30; - -/* - * Defines what type of abilities the type of joystick has - * DEVTYPE_GAMEPAD is available for all joysticks, however - * there may be more specific identifiers for other joysticks - * which are being used. - */ - enum XINPUT_DEVTYPE_GAMEPAD = 0x01; enum XINPUT_DEVSUBTYPE_GAMEPAD = 0x01; enum XINPUT_DEVSUBTYPE_WHEEL = 0x02; @@ -120,23 +74,10 @@ enum XINPUT_DEVSUBTYPE_DANCE_PAD = 0x05; enum XINPUT_DEVSUBTYPE_GUITAR = 0x06; enum XINPUT_DEVSUBTYPE_DRUM_KIT = 0x08; -/* - * These are used with the XInputGetCapabilities function to - * determine the abilities to the joystick which has been - * plugged in. - */ enum XINPUT_CAPS_VOICE_SUPPORTED = 0x0004; enum XINPUT_FLAG_GAMEPAD = 0x00000001; -/* - * Defines the status of the battery if one is used in the - * attached joystick. The first two define if the joystick - * supports a battery. Disconnected means that the joystick - * isn't connected. Wired shows that the joystick is a wired - * joystick. - */ - enum BATTERY_DEVTYPE_GAMEPAD = 0x00; enum BATTERY_DEVTYPE_HEADSET = 0x01; enum BATTERY_TYPE_DISCONNECTED = 0x00; @@ -149,18 +90,9 @@ enum BATTERY_LEVEL_LOW = 0x01; enum BATTERY_LEVEL_MEDIUM = 0x02; enum BATTERY_LEVEL_FULL = 0x03; -/* - * How many joysticks can be used with this library. Games that - * use the xinput library will not go over this number. - */ - enum XUSER_MAX_COUNT = 4; enum XUSER_INDEX_ANY = 0x000000FF; -/* - * Defines the structure of an xbox 360 joystick. - */ - struct _XINPUT_GAMEPAD { WORD wButtons; BYTE bLeftTrigger; @@ -180,27 +112,13 @@ struct _XINPUT_STATE { alias _XINPUT_STATE XINPUT_STATE; alias _XINPUT_STATE* PXINPUT_STATE; -/* - * Defines the structure of how much vibration is set on both the - * right and left motors in a joystick. If you're not using a 360 - * joystick you will have to map these to your device. - */ - struct _XINPUT_VIBRATION { - WORD wLeftMotorSpeed; - WORD wRightMotorSpeed; + WORD wLeftMotorSpeed = 0; + WORD wRightMotorSpeed = 0; } alias _XINPUT_VIBRATION XINPUT_VIBRATION; alias _XINPUT_VIBRATION* PXINPUT_VIBRATION; -/* - * Defines the structure for what kind of abilities the joystick has - * such abilities are things such as if the joystick has the ability - * to send and receive audio, if the joystick is in fact a driving - * wheel or perhaps if the joystick is some kind of dance pad or - * guitar. - */ - struct _XINPUT_CAPABILITIES { BYTE Type; BYTE SubType; @@ -211,10 +129,6 @@ struct _XINPUT_CAPABILITIES { alias _XINPUT_CAPABILITIES XINPUT_CAPABILITIES; alias _XINPUT_CAPABILITIES* PXINPUT_CAPABILITIES; -/* - * Defines the structure for a joystick input event which is - * retrieved using the function XInputGetKeystroke - */ struct _XINPUT_KEYSTROKE { WORD VirtualKey; WCHAR Unicode; From 2ffaada3cecd93efd36d4bc2283c8d66f34df5b3 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Wed, 20 Jan 2021 20:26:44 +0100 Subject: [PATCH 04/17] make isBitSet a function --- source/glfw3/linux_joystick.d | 22 +++++++++++----------- source/glfw3/linuxinput.d | 10 +++++----- source/glfw3/xinput.d | 5 ----- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/source/glfw3/linux_joystick.d b/source/glfw3/linux_joystick.d index b21b78a..9caaa0d 100644 --- a/source/glfw3/linux_joystick.d +++ b/source/glfw3/linux_joystick.d @@ -155,22 +155,22 @@ private void pollAbsState(_GLFWjoystick* js) { } } -// #define isBitSet(bit, arr) (arr[(bit) / 8] & (1 << ((bit) % 8))) -enum string isBitSet(string bit, string arr) = ` (`~arr~`[(`~bit~`) / 8] & (1 << ((`~bit~`) % 8)))`; +// #define isBitSet(bit, arr) (arr[(bit) / 8] & (1 << ((bit) % 8))) +// enum string isBitSet(string bit, string arr) = ` (`~arr~`[(`~bit~`) / 8] & (1 << ((`~bit~`) % 8)))`; +private bool isBitSet(int bit, scope const ubyte[] arr) {return cast(bool) (arr[bit / 8] & (1 << (bit % 8)));} private void initJoystickForceFeedback(_GLFWjoystickLinux *linjs) { linjs.hasRumble = false; - char[(FF_CNT + 7) / 8] ffBits = 0; + ubyte[(FF_CNT + 7) / 8] ffBits = 0; if (ioctl(linjs.fd, EVIOCGBIT!(typeof(ffBits))(EV_FF), ffBits.ptr) < 0) { return; } - if (mixin(isBitSet!("FF_RUMBLE", "ffBits"))) + if (isBitSet(FF_RUMBLE, ffBits)) { - linjs.rumble.type = linjs.rumble.type = FF_RUMBLE; linjs.rumble.id = -1; linjs.rumble.direction = 0; @@ -198,9 +198,9 @@ private GLFWbool openJoystickDevice(const(char)* path) { if (linjs.fd == -1) return GLFW_FALSE; - char[(EV_CNT + 7) / 8] evBits = '\0'; - char[(KEY_CNT + 7) / 8] keyBits = '\0'; - char[(ABS_CNT + 7) / 8] absBits = '\0'; + ubyte[(EV_CNT + 7) / 8] evBits = 0; + ubyte[(KEY_CNT + 7) / 8] keyBits = 0; + ubyte[(ABS_CNT + 7) / 8] absBits = 0; input_id id; if (ioctl(linjs.fd, EVIOCGBIT!(typeof(evBits) )( 0), evBits.ptr) < 0 || @@ -216,7 +216,7 @@ private GLFWbool openJoystickDevice(const(char)* path) { } // Ensure this device supports the events expected of a joystick - if (!mixin(isBitSet!("EV_KEY", "evBits")) || !mixin(isBitSet!("EV_ABS", "evBits"))) + if (!isBitSet(EV_KEY, evBits) || !isBitSet(EV_ABS, evBits)) { close(linjs.fd); return GLFW_FALSE; @@ -251,7 +251,7 @@ private GLFWbool openJoystickDevice(const(char)* path) { for (int code = BTN_MISC; code < KEY_CNT; code++) { - if (!mixin(isBitSet!("code", "keyBits"))) + if (!isBitSet(code, keyBits)) continue; linjs.keyMap[code - BTN_MISC] = buttonCount; @@ -261,7 +261,7 @@ private GLFWbool openJoystickDevice(const(char)* path) { for (int code = 0; code < ABS_CNT; code++) { linjs.absMap[code] = -1; - if (!mixin(isBitSet!("code", "absBits"))) + if (!isBitSet(code, absBits)) continue; if (code >= ABS_HAT0X && code <= ABS_HAT3Y) diff --git a/source/glfw3/linuxinput.d b/source/glfw3/linuxinput.d index f8f30a0..5b17920 100644 --- a/source/glfw3/linuxinput.d +++ b/source/glfw3/linuxinput.d @@ -37,11 +37,11 @@ auto EVIOCSABS(T)(T abs) {return _IOW!input_absinfo('E', 0xc0 + (abs));} enum EVIOCGID = _IOR!input_id('E', 0x02); auto EVIOCGNAME(T)() {return _IOC!T(_IOC_READ, 'E', 0x06);} -enum EVIOCSFF = _IOW!ff_effect('E', 0x80); -enum EVIOCRMFF = _IOW!int('E', 0x81); -enum EVIOCGEFFECTS =_IOR!int('E', 0x84); -enum EVIOCGRAB = _IOW!int('E', 0x90); -enum EVIOCREVOKE = _IOW!int('E', 0x91); +enum EVIOCSFF = _IOW!ff_effect('E', 0x80); +enum EVIOCRMFF = _IOW!int('E', 0x81); +enum EVIOCGEFFECTS = _IOR!int('E', 0x84); +enum EVIOCGRAB = _IOW!int('E', 0x90); +enum EVIOCREVOKE = _IOW!int('E', 0x91); // force feedback enum FF_STATUS_STOPPED = 0x00; diff --git a/source/glfw3/xinput.d b/source/glfw3/xinput.d index cfddfa9..3b89062 100644 --- a/source/glfw3/xinput.d +++ b/source/glfw3/xinput.d @@ -5,7 +5,6 @@ extern(Windows): @nogc: nothrow: __gshared: import core.sys.windows.windef; - enum XINPUT_GAMEPAD_DPAD_UP = 0x0001; enum XINPUT_GAMEPAD_DPAD_DOWN = 0x0002; enum XINPUT_GAMEPAD_DPAD_LEFT = 0x0004; @@ -21,12 +20,10 @@ enum XINPUT_GAMEPAD_B = 0x2000; enum XINPUT_GAMEPAD_X = 0x4000; enum XINPUT_GAMEPAD_Y = 0x8000; - enum XINPUT_KEYSTROKE_KEYDOWN = 0x0001; enum XINPUT_KEYSTROKE_KEYUP = 0x0002; enum XINPUT_KEYSTROKE_REPEAT = 0x0004; - enum VK_PAD_A = 0x5800; enum VK_PAD_B = 0x5801; enum VK_PAD_X = 0x5802; @@ -60,7 +57,6 @@ enum VK_PAD_RTHUMB_UPRIGHT = 0x5835; enum VK_PAD_RTHUMB_DOWNRIGHT = 0x5836; enum VK_PAD_RTHUMB_DOWNLEFT = 0x5837; - enum XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE = 7849; enum XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE = 8689; enum XINPUT_GAMEPAD_TRIGGER_THRESHOLD = 30; @@ -74,7 +70,6 @@ enum XINPUT_DEVSUBTYPE_DANCE_PAD = 0x05; enum XINPUT_DEVSUBTYPE_GUITAR = 0x06; enum XINPUT_DEVSUBTYPE_DRUM_KIT = 0x08; - enum XINPUT_CAPS_VOICE_SUPPORTED = 0x0004; enum XINPUT_FLAG_GAMEPAD = 0x00000001; From 1ee85ed4221e9c48730cbe2d98f0e50a74435627 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sat, 13 Mar 2021 16:31:15 +0100 Subject: [PATCH 05/17] put new function behind preview version identifier --- source/glfw3/api.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/glfw3/api.d b/source/glfw3/api.d index dd9aefb..0fd4e6a 100644 --- a/source/glfw3/api.d +++ b/source/glfw3/api.d @@ -5199,6 +5199,10 @@ const(char)* glfwGetGamepadName(int jid); */ int glfwGetGamepadState(int jid, GLFWgamepadstate* state); +// This version identifier needs to be defined because there might be breaking API changes, +// as of writing the pull request is not merged in the GLFW repository: +// https://github.com/glfw/glfw/pull/1678 +version(GLFW_PREVIEW_JOYSTICK_RUMBLE) /** Sets the intensity of a joystick's rumble effect. * * This function sends vibration data to joysticks that implement haptic feedback From 9f5486ee1d10aed25cc68d1a5d3baae4c39b7722 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sat, 13 Mar 2021 16:37:49 +0100 Subject: [PATCH 06/17] fix module declarations lacking the `glfw3` --- source/glfw3/context.d | 2 +- source/glfw3/x11_init.d | 2 +- source/glfw3/x11_monitor.d | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/glfw3/context.d b/source/glfw3/context.d index 550bbed..cab7b1c 100644 --- a/source/glfw3/context.d +++ b/source/glfw3/context.d @@ -1,5 +1,5 @@ /// Translated from C to D -module context; +module glfw3.context; extern(C): @nogc: nothrow: __gshared: //======================================================================== diff --git a/source/glfw3/x11_init.d b/source/glfw3/x11_init.d index 2ec6dc6..6af799a 100644 --- a/source/glfw3/x11_init.d +++ b/source/glfw3/x11_init.d @@ -1,5 +1,5 @@ /// Translated from C to D -module x11_init; +module glfw3.x11_init; extern(C): @nogc: nothrow: __gshared: diff --git a/source/glfw3/x11_monitor.d b/source/glfw3/x11_monitor.d index e143658..a30bd51 100644 --- a/source/glfw3/x11_monitor.d +++ b/source/glfw3/x11_monitor.d @@ -1,5 +1,5 @@ /// Translated from C to D -module x11_monitor; +module glfw3.x11_monitor; extern(C): @nogc: nothrow: __gshared: //======================================================================== From 9813d8f48e933b895a96233286e1b1346e0ac0a4 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sun, 14 Mar 2021 00:34:41 +0100 Subject: [PATCH 07/17] remove useless version identifier --- source/glfw3/vulkan.d | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/glfw3/vulkan.d b/source/glfw3/vulkan.d index de8397f..7c4b097 100644 --- a/source/glfw3/vulkan.d +++ b/source/glfw3/vulkan.d @@ -54,9 +54,7 @@ GLFWbool _glfwInitVulkan(int mode) { return GLFW_TRUE; version (_GLFW_VULKAN_STATIC) {} else { -version (_GLFW_VULKAN_LIBRARY) { - _glfw.vk.handle = _glfw_dlopen(_GLFW_VULKAN_LIBRARY); -} else version (_GLFW_WIN32) { +version (_GLFW_WIN32) { _glfw.vk.handle = _glfw_dlopen("vulkan-1.dll"); } else version (_GLFW_COCOA) { _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib"); From c1ea9fe2e486b1f1f41d83e4af60c9fbfc77800a Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sun, 14 Mar 2021 00:34:58 +0100 Subject: [PATCH 08/17] replace static with private --- source/glfw3/egl_context.d | 18 +-- source/glfw3/glx_context.d | 18 +-- source/glfw3/init.d | 6 +- source/glfw3/linux_joystick.d | 2 +- source/glfw3/null_window.d | 2 +- source/glfw3/osmesa_context.d | 6 +- source/glfw3/wayland.d | 288 +++++++++++++++++----------------- source/glfw3/wgl_context.d | 16 +- source/glfw3/win32_init.d | 6 +- source/glfw3/win32_joystick.d | 30 ++-- source/glfw3/win32_monitor.d | 4 +- source/glfw3/win32_platform.d | 8 +- source/glfw3/win32_window.d | 16 +- source/glfw3/wl_init.d | 76 ++++----- source/glfw3/wl_monitor.d | 10 +- source/glfw3/wl_window.d | 98 ++++++------ source/glfw3/x11_init.d | 14 +- source/glfw3/x11_monitor.d | 8 +- source/glfw3/x11_window.d | 30 ++-- 19 files changed, 328 insertions(+), 328 deletions(-) diff --git a/source/glfw3/egl_context.d b/source/glfw3/egl_context.d index 2da3577..40e1c90 100644 --- a/source/glfw3/egl_context.d +++ b/source/glfw3/egl_context.d @@ -220,7 +220,7 @@ import core.stdc.stdint; // Return a description of the specified EGL error // -static const(char)* getEGLErrorString(EGLint error) { +private const(char)* getEGLErrorString(EGLint error) { switch (error) { case EGL_SUCCESS: @@ -260,7 +260,7 @@ static const(char)* getEGLErrorString(EGLint error) { // Returns the specified attribute of the specified EGLConfig // -static int getEGLConfigAttrib(EGLConfig config, int attrib) { +private int getEGLConfigAttrib(EGLConfig config, int attrib) { int value; _glfw.egl.GetConfigAttrib(_glfw.egl.display, config, attrib, &value); return value; @@ -268,7 +268,7 @@ static int getEGLConfigAttrib(EGLConfig config, int attrib) { // Return the EGLConfig most closely matching the specified hints // -static GLFWbool chooseEGLConfig(const(_GLFWctxconfig)* ctxconfig, const(_GLFWfbconfig)* desired, EGLConfig* result) { +private GLFWbool chooseEGLConfig(const(_GLFWctxconfig)* ctxconfig, const(_GLFWfbconfig)* desired, EGLConfig* result) { EGLConfig* nativeConfigs; _GLFWfbconfig* usableConfigs; const(_GLFWfbconfig)* closest; @@ -365,7 +365,7 @@ static GLFWbool chooseEGLConfig(const(_GLFWctxconfig)* ctxconfig, const(_GLFWfbc return closest != null; } -static void makeContextCurrentEGL(_GLFWwindow* window) { +private void makeContextCurrentEGL(_GLFWwindow* window) { if (window) { if (!_glfw.egl.MakeCurrent(_glfw.egl.display, @@ -396,7 +396,7 @@ static void makeContextCurrentEGL(_GLFWwindow* window) { _glfwPlatformSetTls(&_glfw.contextSlot, window); } -static void swapBuffersEGL(_GLFWwindow* window) { +private void swapBuffersEGL(_GLFWwindow* window) { if (window != _glfwPlatformGetTls(&_glfw.contextSlot)) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -407,11 +407,11 @@ static void swapBuffersEGL(_GLFWwindow* window) { _glfw.egl.SwapBuffers(_glfw.egl.display, window.context.egl.surface); } -static void swapIntervalEGL(int interval) { +private void swapIntervalEGL(int interval) { _glfw.egl.SwapInterval(_glfw.egl.display, interval); } -static int extensionSupportedEGL(const(char)* extension) { +private int extensionSupportedEGL(const(char)* extension) { const(char)* extensions = _glfw.egl.QueryString(_glfw.egl.display, EGL_EXTENSIONS); if (extensions) { @@ -422,7 +422,7 @@ static int extensionSupportedEGL(const(char)* extension) { return GLFW_FALSE; } -static GLFWglproc getProcAddressEGL(const(char)* procname) { +private GLFWglproc getProcAddressEGL(const(char)* procname) { auto window = cast(_GLFWwindow*) _glfwPlatformGetTls(&_glfw.contextSlot); if (window.context.egl.client) @@ -436,7 +436,7 @@ static GLFWglproc getProcAddressEGL(const(char)* procname) { return _glfw.egl.GetProcAddress(procname); } -static void destroyContextEGL(_GLFWwindow* window) { +private void destroyContextEGL(_GLFWwindow* window) { // NOTE: Do not unload libGL.so.1 while the X11 display is still open, // as it will make XCloseDisplay segfault version (_GLFW_X11) { diff --git a/source/glfw3/glx_context.d b/source/glfw3/glx_context.d index 729a415..39eb158 100644 --- a/source/glfw3/glx_context.d +++ b/source/glfw3/glx_context.d @@ -192,7 +192,7 @@ enum GLXBadProfileARB = 13; // Returns the specified attribute of the specified GLXFBConfig // -static int getGLXFBConfigAttrib(GLXFBConfig fbconfig, int attrib) { +private int getGLXFBConfigAttrib(GLXFBConfig fbconfig, int attrib) { int value; _glfw.glx.GetFBConfigAttrib(_glfw.x11.display, fbconfig, attrib, &value); return value; @@ -200,7 +200,7 @@ static int getGLXFBConfigAttrib(GLXFBConfig fbconfig, int attrib) { // Return the GLXFBConfig most closely matching the specified hints // -static GLFWbool chooseGLXFBConfig(const(_GLFWfbconfig)* desired, GLXFBConfig* result) { +private GLFWbool chooseGLXFBConfig(const(_GLFWfbconfig)* desired, GLXFBConfig* result) { GLXFBConfig* nativeConfigs; _GLFWfbconfig* usableConfigs; const(_GLFWfbconfig)* closest; @@ -293,7 +293,7 @@ static GLFWbool chooseGLXFBConfig(const(_GLFWfbconfig)* desired, GLXFBConfig* re // Create the OpenGL context using legacy API // -static GLXContext createLegacyContextGLX(_GLFWwindow* window, GLXFBConfig fbconfig, GLXContext share) { +private GLXContext createLegacyContextGLX(_GLFWwindow* window, GLXFBConfig fbconfig, GLXContext share) { return _glfw.glx.CreateNewContext(_glfw.x11.display, fbconfig, GLX_RGBA_TYPE, @@ -301,7 +301,7 @@ static GLXContext createLegacyContextGLX(_GLFWwindow* window, GLXFBConfig fbconf True); } -static void makeContextCurrentGLX(_GLFWwindow* window) { +private void makeContextCurrentGLX(_GLFWwindow* window) { if (window) { if (!_glfw.glx.MakeCurrent(_glfw.x11.display, @@ -326,11 +326,11 @@ static void makeContextCurrentGLX(_GLFWwindow* window) { _glfwPlatformSetTls(&_glfw.contextSlot, window); } -static void swapBuffersGLX(_GLFWwindow* window) { +private void swapBuffersGLX(_GLFWwindow* window) { _glfw.glx.SwapBuffers(_glfw.x11.display, window.context.glx.window); } -static void swapIntervalGLX(int interval) { +private void swapIntervalGLX(int interval) { auto window = cast(_GLFWwindow*) _glfwPlatformGetTls(&_glfw.contextSlot); if (_glfw.glx.EXT_swap_control) @@ -348,7 +348,7 @@ static void swapIntervalGLX(int interval) { } } -static int extensionSupportedGLX(const(char)* extension) { +private int extensionSupportedGLX(const(char)* extension) { const(char)* extensions = _glfw.glx.QueryExtensionsString(_glfw.x11.display, _glfw.x11.screen); if (extensions) { @@ -359,7 +359,7 @@ static int extensionSupportedGLX(const(char)* extension) { return GLFW_FALSE; } -static GLFWglproc getProcAddressGLX(const(char)* procname) { +private GLFWglproc getProcAddressGLX(const(char)* procname) { if (_glfw.glx.GetProcAddress) return cast(typeof(return)) _glfw.glx.GetProcAddress(cast(const(GLubyte)*) procname); else if (_glfw.glx.GetProcAddressARB) @@ -368,7 +368,7 @@ static GLFWglproc getProcAddressGLX(const(char)* procname) { return cast(typeof(return)) _glfw_dlsym(_glfw.glx.handle, procname); } -static void destroyContextGLX(_GLFWwindow* window) { +private void destroyContextGLX(_GLFWwindow* window) { if (window.context.glx.window) { _glfw.glx.DestroyWindow(_glfw.x11.display, window.context.glx.window); diff --git a/source/glfw3/init.d b/source/glfw3/init.d index eb4e876..6e132cf 100644 --- a/source/glfw3/init.d +++ b/source/glfw3/init.d @@ -53,9 +53,9 @@ _GLFWlibrary _glfw = _GLFWlibrary(GLFW_FALSE); // These are outside of _glfw so they can be used before initialization and // after termination // -static _GLFWerror _glfwMainThreadError; -static GLFWerrorfun _glfwErrorCallback; -static _GLFWinitconfig _glfwInitHints = _GLFWinitconfig( +private _GLFWerror _glfwMainThreadError; +private GLFWerrorfun _glfwErrorCallback; +private _GLFWinitconfig _glfwInitHints = _GLFWinitconfig( GLFW_TRUE, // hat buttons _GLFWinitconfig._Ns( GLFW_TRUE, // macOS menu bar diff --git a/source/glfw3/linux_joystick.d b/source/glfw3/linux_joystick.d index 9caaa0d..a20b95a 100644 --- a/source/glfw3/linux_joystick.d +++ b/source/glfw3/linux_joystick.d @@ -94,7 +94,7 @@ private void handleKeyEvent(_GLFWjoystick* js, int code, int value) { // Apply an EV_ABS event to the specified joystick // -static void handleAbsEvent(_GLFWjoystick* js, int code, int value) { +private void handleAbsEvent(_GLFWjoystick* js, int code, int value) { const(int) index = js.linjs.absMap[code]; if (code >= ABS_HAT0X && code <= ABS_HAT3Y) diff --git a/source/glfw3/null_window.d b/source/glfw3/null_window.d index 60069f0..59d0328 100644 --- a/source/glfw3/null_window.d +++ b/source/glfw3/null_window.d @@ -34,7 +34,7 @@ extern(C): @nogc: nothrow: __gshared: import glfw3.internal; -static int createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig) { +private int createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig) { window.null_.width = wndconfig.width; window.null_.height = wndconfig.height; diff --git a/source/glfw3/osmesa_context.d b/source/glfw3/osmesa_context.d index 02bbd28..f80ebd2 100644 --- a/source/glfw3/osmesa_context.d +++ b/source/glfw3/osmesa_context.d @@ -150,15 +150,15 @@ private void destroyContextOSMesa(_GLFWwindow* window) { } } -static void swapBuffersOSMesa(_GLFWwindow* window) { +private void swapBuffersOSMesa(_GLFWwindow* window) { // No double buffering on OSMesa } -static void swapIntervalOSMesa(int interval) { +private void swapIntervalOSMesa(int interval) { // No swap interval on OSMesa } -static int extensionSupportedOSMesa(const(char)* extension) { +private int extensionSupportedOSMesa(const(char)* extension) { // OSMesa does not have extensions return GLFW_FALSE; } diff --git a/source/glfw3/wayland.d b/source/glfw3/wayland.d index d06415b..79536c8 100644 --- a/source/glfw3/wayland.d +++ b/source/glfw3/wayland.d @@ -242,7 +242,7 @@ struct wl_shell_surface_listener { void function(void* data, wl_shell_surface* wl_shell_surface) popup_done; } -pragma(inline, true) static void* wl_registry_bind(wl_registry* wl_registry, uint name, const(wl_interface)* interface_, uint version_) { +pragma(inline, true) private void* wl_registry_bind(wl_registry* wl_registry, uint name, const(wl_interface)* interface_, uint version_) { wl_proxy* id; id = wl_proxy_marshal_constructor_versioned(cast(wl_proxy*) wl_registry, WL_REGISTRY_BIND, interface_, version_, name, interface_.name, version_, null); @@ -250,12 +250,12 @@ pragma(inline, true) static void* wl_registry_bind(wl_registry* wl_registry, uin return cast(void*) id; } -pragma(inline, true) static int wl_output_add_listener(wl_output* wl_output, const(wl_output_listener)* listener, void* data) { +pragma(inline, true) private int wl_output_add_listener(wl_output* wl_output, const(wl_output_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_output, cast(void function()) listener, data); } -pragma(inline, true) static void wl_output_destroy(wl_output* wl_output) { +pragma(inline, true) private void wl_output_destroy(wl_output* wl_output) { wl_proxy_destroy(cast(wl_proxy*) wl_output); } @@ -304,7 +304,7 @@ struct wl_display_listener { void function(void* data, wl_display* wl_display, void* object_id, uint code, const(char)* message) error; void function(void* data, wl_display* wl_display, uint id) delete_id; } -pragma(inline, true) static int wl_display_add_listener(wl_display* wl_display, const(wl_display_listener)* listener, void* data) { +pragma(inline, true) private int wl_display_add_listener(wl_display* wl_display, const(wl_display_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_display, cast(void function()) listener, data); } @@ -315,13 +315,13 @@ enum WL_DISPLAY_DELETE_ID_SINCE_VERSION = 1; enum WL_DISPLAY_SYNC_SINCE_VERSION = 1; enum WL_DISPLAY_GET_REGISTRY_SINCE_VERSION = 1; -pragma(inline, true) static void wl_display_set_user_data(wl_display* wl_display, void* user_data) { +pragma(inline, true) private void wl_display_set_user_data(wl_display* wl_display, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_display, user_data); } -pragma(inline, true) static void* wl_display_get_user_data(wl_display* wl_display) { +pragma(inline, true) private void* wl_display_get_user_data(wl_display* wl_display) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_display); } -pragma(inline, true) static uint wl_display_get_version(wl_display* wl_display) { +pragma(inline, true) private uint wl_display_get_version(wl_display* wl_display) { return wl_proxy_get_version(cast(wl_proxy*) wl_display); } pragma(inline, true) static wl_callback* wl_display_sync(wl_display* wl_display) { @@ -336,7 +336,7 @@ pragma(inline, true) static wl_registry* wl_display_get_registry(wl_display* wl_ WL_DISPLAY_GET_REGISTRY, &wl_registry_interface, null); return cast(wl_registry*) registry; } -pragma(inline, true) static int wl_registry_add_listener(wl_registry* wl_registry, const(wl_registry_listener)* listener, void* data) { +pragma(inline, true) private int wl_registry_add_listener(wl_registry* wl_registry, const(wl_registry_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_registry, cast(void function()) listener, data); } @@ -345,38 +345,38 @@ enum WL_REGISTRY_GLOBAL_SINCE_VERSION = 1; enum WL_REGISTRY_GLOBAL_REMOVE_SINCE_VERSION = 1; enum WL_REGISTRY_BIND_SINCE_VERSION = 1; -pragma(inline, true) static void wl_registry_set_user_data(wl_registry* wl_registry, void* user_data) { +pragma(inline, true) private void wl_registry_set_user_data(wl_registry* wl_registry, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_registry, user_data); } -pragma(inline, true) static void* wl_registry_get_user_data(wl_registry* wl_registry) { +pragma(inline, true) private void* wl_registry_get_user_data(wl_registry* wl_registry) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_registry); } -pragma(inline, true) static uint wl_registry_get_version(wl_registry* wl_registry) { +pragma(inline, true) private uint wl_registry_get_version(wl_registry* wl_registry) { return wl_proxy_get_version(cast(wl_proxy*) wl_registry); } -pragma(inline, true) static void wl_registry_destroy(wl_registry* wl_registry) { +pragma(inline, true) private void wl_registry_destroy(wl_registry* wl_registry) { wl_proxy_destroy(cast(wl_proxy*) wl_registry); } struct wl_callback_listener { void function(void* data, wl_callback* wl_callback, uint callback_data) done; } -pragma(inline, true) static int wl_callback_add_listener(wl_callback* wl_callback, const(wl_callback_listener)* listener, void* data) { +pragma(inline, true) private int wl_callback_add_listener(wl_callback* wl_callback, const(wl_callback_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_callback, cast(void function()) listener, data); } enum WL_CALLBACK_DONE_SINCE_VERSION = 1; -pragma(inline, true) static void wl_callback_set_user_data(wl_callback* wl_callback, void* user_data) { +pragma(inline, true) private void wl_callback_set_user_data(wl_callback* wl_callback, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_callback, user_data); } -pragma(inline, true) static void* wl_callback_get_user_data(wl_callback* wl_callback) { +pragma(inline, true) private void* wl_callback_get_user_data(wl_callback* wl_callback) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_callback); } -pragma(inline, true) static uint wl_callback_get_version(wl_callback* wl_callback) { +pragma(inline, true) private uint wl_callback_get_version(wl_callback* wl_callback) { return wl_proxy_get_version(cast(wl_proxy*) wl_callback); } -pragma(inline, true) static void wl_callback_destroy(wl_callback* wl_callback) { +pragma(inline, true) private void wl_callback_destroy(wl_callback* wl_callback) { wl_proxy_destroy(cast(wl_proxy*) wl_callback); } enum WL_COMPOSITOR_CREATE_SURFACE = 0; @@ -384,16 +384,16 @@ enum WL_COMPOSITOR_CREATE_REGION = 1; enum WL_COMPOSITOR_CREATE_SURFACE_SINCE_VERSION = 1; enum WL_COMPOSITOR_CREATE_REGION_SINCE_VERSION = 1; -pragma(inline, true) static void wl_compositor_set_user_data(wl_compositor* wl_compositor, void* user_data) { +pragma(inline, true) private void wl_compositor_set_user_data(wl_compositor* wl_compositor, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_compositor, user_data); } -pragma(inline, true) static void* wl_compositor_get_user_data(wl_compositor* wl_compositor) { +pragma(inline, true) private void* wl_compositor_get_user_data(wl_compositor* wl_compositor) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_compositor); } -pragma(inline, true) static uint wl_compositor_get_version(wl_compositor* wl_compositor) { +pragma(inline, true) private uint wl_compositor_get_version(wl_compositor* wl_compositor) { return wl_proxy_get_version(cast(wl_proxy*) wl_compositor); } -pragma(inline, true) static void wl_compositor_destroy(wl_compositor* wl_compositor) { +pragma(inline, true) private void wl_compositor_destroy(wl_compositor* wl_compositor) { wl_proxy_destroy(cast(wl_proxy*) wl_compositor); } pragma(inline, true) static wl_surface* wl_compositor_create_surface(wl_compositor* wl_compositor) { @@ -415,13 +415,13 @@ enum WL_SHM_POOL_CREATE_BUFFER_SINCE_VERSION = 1; enum WL_SHM_POOL_DESTROY_SINCE_VERSION = 1; enum WL_SHM_POOL_RESIZE_SINCE_VERSION = 1; -pragma(inline, true) static void wl_shm_pool_set_user_data(wl_shm_pool* wl_shm_pool, void* user_data) { +pragma(inline, true) private void wl_shm_pool_set_user_data(wl_shm_pool* wl_shm_pool, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_shm_pool, user_data); } -pragma(inline, true) static void* wl_shm_pool_get_user_data(wl_shm_pool* wl_shm_pool) { +pragma(inline, true) private void* wl_shm_pool_get_user_data(wl_shm_pool* wl_shm_pool) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_shm_pool); } -pragma(inline, true) static uint wl_shm_pool_get_version(wl_shm_pool* wl_shm_pool) { +pragma(inline, true) private uint wl_shm_pool_get_version(wl_shm_pool* wl_shm_pool) { return wl_proxy_get_version(cast(wl_proxy*) wl_shm_pool); } pragma(inline, true) static wl_buffer* wl_shm_pool_create_buffer(wl_shm_pool* wl_shm_pool, int offset, int width, int height, int stride, uint format) { @@ -430,12 +430,12 @@ pragma(inline, true) static wl_buffer* wl_shm_pool_create_buffer(wl_shm_pool* wl WL_SHM_POOL_CREATE_BUFFER, &wl_buffer_interface, null, offset, width, height, stride, format); return cast(wl_buffer*) id; } -pragma(inline, true) static void wl_shm_pool_destroy(wl_shm_pool* wl_shm_pool) { +pragma(inline, true) private void wl_shm_pool_destroy(wl_shm_pool* wl_shm_pool) { wl_proxy_marshal(cast(wl_proxy*) wl_shm_pool, WL_SHM_POOL_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_shm_pool); } -pragma(inline, true) static void wl_shm_pool_resize(wl_shm_pool* wl_shm_pool, int size) { +pragma(inline, true) private void wl_shm_pool_resize(wl_shm_pool* wl_shm_pool, int size) { wl_proxy_marshal(cast(wl_proxy*) wl_shm_pool, WL_SHM_POOL_RESIZE, size); } enum wl_shm_error { @@ -506,23 +506,23 @@ enum wl_shm_format { struct wl_shm_listener { void function(void* data, wl_shm* wl_shm, uint format) format; }; -pragma(inline, true) static int wl_shm_add_listener(wl_shm* wl_shm, const(wl_shm_listener)* listener, void* data) { +pragma(inline, true) private int wl_shm_add_listener(wl_shm* wl_shm, const(wl_shm_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_shm, cast(void function()) listener, data); } enum WL_SHM_CREATE_POOL = 0; enum WL_SHM_FORMAT_SINCE_VERSION = 1; enum WL_SHM_CREATE_POOL_SINCE_VERSION = 1; -pragma(inline, true) static void wl_shm_set_user_data(wl_shm* wl_shm, void* user_data) { +pragma(inline, true) private void wl_shm_set_user_data(wl_shm* wl_shm, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_shm, user_data); } -pragma(inline, true) static void* wl_shm_get_user_data(wl_shm* wl_shm) { +pragma(inline, true) private void* wl_shm_get_user_data(wl_shm* wl_shm) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_shm); } -pragma(inline, true) static uint wl_shm_get_version(wl_shm* wl_shm) { +pragma(inline, true) private uint wl_shm_get_version(wl_shm* wl_shm) { return wl_proxy_get_version(cast(wl_proxy*) wl_shm); } -pragma(inline, true) static void wl_shm_destroy(wl_shm* wl_shm) { +pragma(inline, true) private void wl_shm_destroy(wl_shm* wl_shm) { wl_proxy_destroy(cast(wl_proxy*) wl_shm); } pragma(inline, true) static wl_shm_pool* wl_shm_create_pool(wl_shm* wl_shm, int fd, int size) { @@ -534,23 +534,23 @@ pragma(inline, true) static wl_shm_pool* wl_shm_create_pool(wl_shm* wl_shm, int struct wl_buffer_listener { void function(void* data, wl_buffer* wl_buffer) release; }; -pragma(inline, true) static int wl_buffer_add_listener(wl_buffer* wl_buffer, const(wl_buffer_listener)* listener, void* data) { +pragma(inline, true) private int wl_buffer_add_listener(wl_buffer* wl_buffer, const(wl_buffer_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_buffer, cast(void function()) listener, data); } enum WL_BUFFER_DESTROY = 0; enum WL_BUFFER_RELEASE_SINCE_VERSION = 1; enum WL_BUFFER_DESTROY_SINCE_VERSION = 1; -pragma(inline, true) static void wl_buffer_set_user_data(wl_buffer* wl_buffer, void* user_data) { +pragma(inline, true) private void wl_buffer_set_user_data(wl_buffer* wl_buffer, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_buffer, user_data); } -pragma(inline, true) static void* wl_buffer_get_user_data(wl_buffer* wl_buffer) { +pragma(inline, true) private void* wl_buffer_get_user_data(wl_buffer* wl_buffer) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_buffer); } -pragma(inline, true) static uint wl_buffer_get_version(wl_buffer* wl_buffer) { +pragma(inline, true) private uint wl_buffer_get_version(wl_buffer* wl_buffer) { return wl_proxy_get_version(cast(wl_proxy*) wl_buffer); } -pragma(inline, true) static void wl_buffer_destroy(wl_buffer* wl_buffer) { +pragma(inline, true) private void wl_buffer_destroy(wl_buffer* wl_buffer) { wl_proxy_marshal(cast(wl_proxy*) wl_buffer, WL_BUFFER_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_buffer); @@ -561,7 +561,7 @@ enum wl_data_offer_error { WL_DATA_OFFER_ERROR_INVALID_ACTION = 2, WL_DATA_OFFER_ERROR_INVALID_OFFER = 3, } -pragma(inline, true) static int wl_data_offer_add_listener(wl_data_offer* wl_data_offer, const(wl_data_offer_listener)* listener, void* data) { +pragma(inline, true) private int wl_data_offer_add_listener(wl_data_offer* wl_data_offer, const(wl_data_offer_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_data_offer, cast(void function()) listener, data); } @@ -578,33 +578,33 @@ enum WL_DATA_OFFER_RECEIVE_SINCE_VERSION = 1; enum WL_DATA_OFFER_DESTROY_SINCE_VERSION = 1; enum WL_DATA_OFFER_FINISH_SINCE_VERSION = 3; enum WL_DATA_OFFER_SET_ACTIONS_SINCE_VERSION = 3; -pragma(inline, true) static void wl_data_offer_set_user_data(wl_data_offer* wl_data_offer, void* user_data) { +pragma(inline, true) private void wl_data_offer_set_user_data(wl_data_offer* wl_data_offer, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_data_offer, user_data); } -pragma(inline, true) static void* wl_data_offer_get_user_data(wl_data_offer* wl_data_offer) { +pragma(inline, true) private void* wl_data_offer_get_user_data(wl_data_offer* wl_data_offer) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_data_offer); } -pragma(inline, true) static uint wl_data_offer_get_version(wl_data_offer* wl_data_offer) { +pragma(inline, true) private uint wl_data_offer_get_version(wl_data_offer* wl_data_offer) { return wl_proxy_get_version(cast(wl_proxy*) wl_data_offer); } -pragma(inline, true) static void wl_data_offer_accept(wl_data_offer* wl_data_offer, uint serial, const(char)* mime_type) { +pragma(inline, true) private void wl_data_offer_accept(wl_data_offer* wl_data_offer, uint serial, const(char)* mime_type) { wl_proxy_marshal(cast(wl_proxy*) wl_data_offer, WL_DATA_OFFER_ACCEPT, serial, mime_type); } -pragma(inline, true) static void wl_data_offer_receive(wl_data_offer* wl_data_offer, const(char)* mime_type, int fd) { +pragma(inline, true) private void wl_data_offer_receive(wl_data_offer* wl_data_offer, const(char)* mime_type, int fd) { wl_proxy_marshal(cast(wl_proxy*) wl_data_offer, WL_DATA_OFFER_RECEIVE, mime_type, fd); } -pragma(inline, true) static void wl_data_offer_destroy(wl_data_offer* wl_data_offer) { +pragma(inline, true) private void wl_data_offer_destroy(wl_data_offer* wl_data_offer) { wl_proxy_marshal(cast(wl_proxy*) wl_data_offer, WL_DATA_OFFER_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_data_offer); } -pragma(inline, true) static void wl_data_offer_finish(wl_data_offer* wl_data_offer) { +pragma(inline, true) private void wl_data_offer_finish(wl_data_offer* wl_data_offer) { wl_proxy_marshal(cast(wl_proxy*) wl_data_offer, WL_DATA_OFFER_FINISH); } -pragma(inline, true) static void wl_data_offer_set_actions(wl_data_offer* wl_data_offer, uint dnd_actions, uint preferred_action) { +pragma(inline, true) private void wl_data_offer_set_actions(wl_data_offer* wl_data_offer, uint dnd_actions, uint preferred_action) { wl_proxy_marshal(cast(wl_proxy*) wl_data_offer, WL_DATA_OFFER_SET_ACTIONS, dnd_actions, preferred_action); } @@ -612,7 +612,7 @@ enum wl_data_source_error { WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK = 0, WL_DATA_SOURCE_ERROR_INVALID_SOURCE = 1, } -pragma(inline, true) static int wl_data_source_add_listener(wl_data_source* wl_data_source, const(wl_data_source_listener)* listener, void* data) { +pragma(inline, true) private int wl_data_source_add_listener(wl_data_source* wl_data_source, const(wl_data_source_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_data_source, cast(void function()) listener, data); } @@ -628,32 +628,32 @@ enum WL_DATA_SOURCE_ACTION_SINCE_VERSION = 3; enum WL_DATA_SOURCE_OFFER_SINCE_VERSION = 1; enum WL_DATA_SOURCE_DESTROY_SINCE_VERSION = 1; enum WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION = 3; -pragma(inline, true) static void wl_data_source_set_user_data(wl_data_source* wl_data_source, void* user_data) { +pragma(inline, true) private void wl_data_source_set_user_data(wl_data_source* wl_data_source, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_data_source, user_data); } -pragma(inline, true) static void* wl_data_source_get_user_data(wl_data_source* wl_data_source) { +pragma(inline, true) private void* wl_data_source_get_user_data(wl_data_source* wl_data_source) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_data_source); } -pragma(inline, true) static uint wl_data_source_get_version(wl_data_source* wl_data_source) { +pragma(inline, true) private uint wl_data_source_get_version(wl_data_source* wl_data_source) { return wl_proxy_get_version(cast(wl_proxy*) wl_data_source); } -pragma(inline, true) static void wl_data_source_offer(wl_data_source* wl_data_source, const(char)* mime_type) { +pragma(inline, true) private void wl_data_source_offer(wl_data_source* wl_data_source, const(char)* mime_type) { wl_proxy_marshal(cast(wl_proxy*) wl_data_source, WL_DATA_SOURCE_OFFER, mime_type); } -pragma(inline, true) static void wl_data_source_destroy(wl_data_source* wl_data_source) { +pragma(inline, true) private void wl_data_source_destroy(wl_data_source* wl_data_source) { wl_proxy_marshal(cast(wl_proxy*) wl_data_source, WL_DATA_SOURCE_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_data_source); } -pragma(inline, true) static void wl_data_source_set_actions(wl_data_source* wl_data_source, uint dnd_actions) { +pragma(inline, true) private void wl_data_source_set_actions(wl_data_source* wl_data_source, uint dnd_actions) { wl_proxy_marshal(cast(wl_proxy*) wl_data_source, WL_DATA_SOURCE_SET_ACTIONS, dnd_actions); } enum wl_data_device_error { WL_DATA_DEVICE_ERROR_ROLE = 0, } -pragma(inline, true) static int wl_data_device_add_listener(wl_data_device* wl_data_device, const(wl_data_device_listener)* listener, void* data) { +pragma(inline, true) private int wl_data_device_add_listener(wl_data_device* wl_data_device, const(wl_data_device_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_data_device, cast(void function()) listener, data); } @@ -669,27 +669,27 @@ enum WL_DATA_DEVICE_SELECTION_SINCE_VERSION = 1; enum WL_DATA_DEVICE_START_DRAG_SINCE_VERSION = 1; enum WL_DATA_DEVICE_SET_SELECTION_SINCE_VERSION = 1; enum WL_DATA_DEVICE_RELEASE_SINCE_VERSION = 2; -pragma(inline, true) static void wl_data_device_set_user_data(wl_data_device* wl_data_device, void* user_data) { +pragma(inline, true) private void wl_data_device_set_user_data(wl_data_device* wl_data_device, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_data_device, user_data); } -pragma(inline, true) static void* wl_data_device_get_user_data(wl_data_device* wl_data_device) { +pragma(inline, true) private void* wl_data_device_get_user_data(wl_data_device* wl_data_device) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_data_device); } -pragma(inline, true) static uint wl_data_device_get_version(wl_data_device* wl_data_device) { +pragma(inline, true) private uint wl_data_device_get_version(wl_data_device* wl_data_device) { return wl_proxy_get_version(cast(wl_proxy*) wl_data_device); } -pragma(inline, true) static void wl_data_device_destroy(wl_data_device* wl_data_device) { +pragma(inline, true) private void wl_data_device_destroy(wl_data_device* wl_data_device) { wl_proxy_destroy(cast(wl_proxy*) wl_data_device); } -pragma(inline, true) static void wl_data_device_start_drag(wl_data_device* wl_data_device, wl_data_source* source, wl_surface* origin, wl_surface* icon, uint serial) { +pragma(inline, true) private void wl_data_device_start_drag(wl_data_device* wl_data_device, wl_data_source* source, wl_surface* origin, wl_surface* icon, uint serial) { wl_proxy_marshal(cast(wl_proxy*) wl_data_device, WL_DATA_DEVICE_START_DRAG, source, origin, icon, serial); } -pragma(inline, true) static void wl_data_device_set_selection(wl_data_device* wl_data_device, wl_data_source* source, uint serial) { +pragma(inline, true) private void wl_data_device_set_selection(wl_data_device* wl_data_device, wl_data_source* source, uint serial) { wl_proxy_marshal(cast(wl_proxy*) wl_data_device, WL_DATA_DEVICE_SET_SELECTION, source, serial); } -pragma(inline, true) static void wl_data_device_release(wl_data_device* wl_data_device) { +pragma(inline, true) private void wl_data_device_release(wl_data_device* wl_data_device) { wl_proxy_marshal(cast(wl_proxy*) wl_data_device, WL_DATA_DEVICE_RELEASE); wl_proxy_destroy(cast(wl_proxy*) wl_data_device); @@ -704,16 +704,16 @@ enum WL_DATA_DEVICE_MANAGER_CREATE_DATA_SOURCE = 0; enum WL_DATA_DEVICE_MANAGER_GET_DATA_DEVICE = 1; enum WL_DATA_DEVICE_MANAGER_CREATE_DATA_SOURCE_SINCE_VERSION = 1; enum WL_DATA_DEVICE_MANAGER_GET_DATA_DEVICE_SINCE_VERSION = 1; -pragma(inline, true) static void wl_data_device_manager_set_user_data(wl_data_device_manager* wl_data_device_manager, void* user_data) { +pragma(inline, true) private void wl_data_device_manager_set_user_data(wl_data_device_manager* wl_data_device_manager, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_data_device_manager, user_data); } -pragma(inline, true) static void* wl_data_device_manager_get_user_data(wl_data_device_manager* wl_data_device_manager) { +pragma(inline, true) private void* wl_data_device_manager_get_user_data(wl_data_device_manager* wl_data_device_manager) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_data_device_manager); } -pragma(inline, true) static uint wl_data_device_manager_get_version(wl_data_device_manager* wl_data_device_manager) { +pragma(inline, true) private uint wl_data_device_manager_get_version(wl_data_device_manager* wl_data_device_manager) { return wl_proxy_get_version(cast(wl_proxy*) wl_data_device_manager); } -pragma(inline, true) static void wl_data_device_manager_destroy(wl_data_device_manager* wl_data_device_manager) { +pragma(inline, true) private void wl_data_device_manager_destroy(wl_data_device_manager* wl_data_device_manager) { wl_proxy_destroy(cast(wl_proxy*) wl_data_device_manager); } pragma(inline, true) static wl_data_source* wl_data_device_manager_create_data_source(wl_data_device_manager* wl_data_device_manager) { @@ -733,16 +733,16 @@ enum wl_shell_error { } enum WL_SHELL_GET_SHELL_SURFACE = 0; enum WL_SHELL_GET_SHELL_SURFACE_SINCE_VERSION = 1; -pragma(inline, true) static void wl_shell_set_user_data(wl_shell* wl_shell, void* user_data) { +pragma(inline, true) private void wl_shell_set_user_data(wl_shell* wl_shell, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_shell, user_data); } -pragma(inline, true) static void* wl_shell_get_user_data(wl_shell* wl_shell) { +pragma(inline, true) private void* wl_shell_get_user_data(wl_shell* wl_shell) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_shell); } -pragma(inline, true) static uint wl_shell_get_version(wl_shell* wl_shell) { +pragma(inline, true) private uint wl_shell_get_version(wl_shell* wl_shell) { return wl_proxy_get_version(cast(wl_proxy*) wl_shell); } -pragma(inline, true) static void wl_shell_destroy(wl_shell* wl_shell) { +pragma(inline, true) private void wl_shell_destroy(wl_shell* wl_shell) { wl_proxy_destroy(cast(wl_proxy*) wl_shell); } pragma(inline, true) static wl_shell_surface* wl_shell_get_shell_surface(wl_shell* wl_shell, wl_surface* surface) { @@ -760,7 +760,7 @@ enum wl_shell_surface_fullscreen_method { WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER = 2, WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL = 3, } -pragma(inline, true) static int wl_shell_surface_add_listener(wl_shell_surface* wl_shell_surface, const(wl_shell_surface_listener)* listener, void* data) { +pragma(inline, true) private int wl_shell_surface_add_listener(wl_shell_surface* wl_shell_surface, const(wl_shell_surface_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_shell_surface, cast(void function()) listener, data); } enum WL_SHELL_SURFACE_PONG = 0; @@ -787,52 +787,52 @@ enum WL_SHELL_SURFACE_SET_MAXIMIZED_SINCE_VERSION = 1; enum WL_SHELL_SURFACE_SET_TITLE_SINCE_VERSION = 1; enum WL_SHELL_SURFACE_SET_CLASS_SINCE_VERSION = 1; -pragma(inline, true) static void wl_shell_surface_set_user_data(wl_shell_surface* wl_shell_surface, void* user_data) { +pragma(inline, true) private void wl_shell_surface_set_user_data(wl_shell_surface* wl_shell_surface, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_shell_surface, user_data); } -pragma(inline, true) static void* wl_shell_surface_get_user_data(wl_shell_surface* wl_shell_surface) { +pragma(inline, true) private void* wl_shell_surface_get_user_data(wl_shell_surface* wl_shell_surface) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_shell_surface); } -pragma(inline, true) static uint wl_shell_surface_get_version(wl_shell_surface* wl_shell_surface) { +pragma(inline, true) private uint wl_shell_surface_get_version(wl_shell_surface* wl_shell_surface) { return wl_proxy_get_version(cast(wl_proxy*) wl_shell_surface); } -pragma(inline, true) static void wl_shell_surface_destroy(wl_shell_surface* wl_shell_surface) { +pragma(inline, true) private void wl_shell_surface_destroy(wl_shell_surface* wl_shell_surface) { wl_proxy_destroy(cast(wl_proxy*) wl_shell_surface); } -pragma(inline, true) static void wl_shell_surface_pong(wl_shell_surface* wl_shell_surface, uint serial) { +pragma(inline, true) private void wl_shell_surface_pong(wl_shell_surface* wl_shell_surface, uint serial) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_PONG, serial); } -pragma(inline, true) static void wl_shell_surface_move(wl_shell_surface* wl_shell_surface, wl_seat* seat, uint serial) { +pragma(inline, true) private void wl_shell_surface_move(wl_shell_surface* wl_shell_surface, wl_seat* seat, uint serial) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_MOVE, seat, serial); } -pragma(inline, true) static void wl_shell_surface_resize(wl_shell_surface* wl_shell_surface, wl_seat* seat, uint serial, uint edges) { +pragma(inline, true) private void wl_shell_surface_resize(wl_shell_surface* wl_shell_surface, wl_seat* seat, uint serial, uint edges) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_RESIZE, seat, serial, edges); } -pragma(inline, true) static void wl_shell_surface_set_toplevel(wl_shell_surface* wl_shell_surface) { +pragma(inline, true) private void wl_shell_surface_set_toplevel(wl_shell_surface* wl_shell_surface) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_TOPLEVEL); } -pragma(inline, true) static void wl_shell_surface_set_transient(wl_shell_surface* wl_shell_surface, wl_surface* parent, int x, int y, uint flags) { +pragma(inline, true) private void wl_shell_surface_set_transient(wl_shell_surface* wl_shell_surface, wl_surface* parent, int x, int y, uint flags) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_TRANSIENT, parent, x, y, flags); } -pragma(inline, true) static void wl_shell_surface_set_fullscreen(wl_shell_surface* wl_shell_surface, uint method, uint framerate, wl_output* output) { +pragma(inline, true) private void wl_shell_surface_set_fullscreen(wl_shell_surface* wl_shell_surface, uint method, uint framerate, wl_output* output) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_FULLSCREEN, method, framerate, output); } -pragma(inline, true) static void wl_shell_surface_set_popup(wl_shell_surface* wl_shell_surface, wl_seat* seat, uint serial, wl_surface* parent, int x, int y, uint flags) { +pragma(inline, true) private void wl_shell_surface_set_popup(wl_shell_surface* wl_shell_surface, wl_seat* seat, uint serial, wl_surface* parent, int x, int y, uint flags) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_POPUP, seat, serial, parent, x, y, flags); } -pragma(inline, true) static void wl_shell_surface_set_maximized(wl_shell_surface* wl_shell_surface, wl_output* output) { +pragma(inline, true) private void wl_shell_surface_set_maximized(wl_shell_surface* wl_shell_surface, wl_output* output) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_MAXIMIZED, output); } -pragma(inline, true) static void wl_shell_surface_set_title(wl_shell_surface* wl_shell_surface, const(char)* title) { +pragma(inline, true) private void wl_shell_surface_set_title(wl_shell_surface* wl_shell_surface, const(char)* title) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_TITLE, title); } -pragma(inline, true) static void wl_shell_surface_set_class(wl_shell_surface* wl_shell_surface, const(char)* class_) { +pragma(inline, true) private void wl_shell_surface_set_class(wl_shell_surface* wl_shell_surface, const(char)* class_) { wl_proxy_marshal(cast(wl_proxy*) wl_shell_surface, WL_SHELL_SURFACE_SET_CLASS, class_); } @@ -840,7 +840,7 @@ enum wl_surface_error { WL_SURFACE_ERROR_INVALID_SCALE = 0, WL_SURFACE_ERROR_INVALID_TRANSFORM = 1, } -pragma(inline, true) static int wl_surface_add_listener(wl_surface* wl_surface, const(wl_surface_listener)* listener, void* data) { +pragma(inline, true) private int wl_surface_add_listener(wl_surface* wl_surface, const(wl_surface_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_surface, cast(void function()) listener, data); } enum WL_SURFACE_DESTROY = 0; @@ -866,25 +866,25 @@ enum WL_SURFACE_SET_BUFFER_TRANSFORM_SINCE_VERSION = 2; enum WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION = 3; enum WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION = 4; -pragma(inline, true) static void wl_surface_set_user_data(wl_surface* wl_surface, void* user_data) { +pragma(inline, true) private void wl_surface_set_user_data(wl_surface* wl_surface, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_surface, user_data); } -pragma(inline, true) static void* wl_surface_get_user_data(wl_surface* wl_surface) { +pragma(inline, true) private void* wl_surface_get_user_data(wl_surface* wl_surface) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_surface); } -pragma(inline, true) static uint wl_surface_get_version(wl_surface* wl_surface) { +pragma(inline, true) private uint wl_surface_get_version(wl_surface* wl_surface) { return wl_proxy_get_version(cast(wl_proxy*) wl_surface); } -pragma(inline, true) static void wl_surface_destroy(wl_surface* wl_surface) { +pragma(inline, true) private void wl_surface_destroy(wl_surface* wl_surface) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_surface); } -pragma(inline, true) static void wl_surface_attach(wl_surface* wl_surface, wl_buffer* buffer, int x, int y) { +pragma(inline, true) private void wl_surface_attach(wl_surface* wl_surface, wl_buffer* buffer, int x, int y) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_ATTACH, buffer, x, y); } -pragma(inline, true) static void wl_surface_damage(wl_surface* wl_surface, int x, int y, int width, int height) { +pragma(inline, true) private void wl_surface_damage(wl_surface* wl_surface, int x, int y, int width, int height) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_DAMAGE, x, y, width, height); } @@ -894,31 +894,31 @@ pragma(inline, true) static wl_callback* wl_surface_frame(wl_surface* wl_surface WL_SURFACE_FRAME, &wl_callback_interface, null); return cast(wl_callback*) callback; } -pragma(inline, true) static void wl_surface_set_opaque_region(wl_surface* wl_surface, wl_region* region) { +pragma(inline, true) private void wl_surface_set_opaque_region(wl_surface* wl_surface, wl_region* region) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_SET_OPAQUE_REGION, region); } -pragma(inline, true) static void wl_surface_set_input_region(wl_surface* wl_surface, wl_region* region) { +pragma(inline, true) private void wl_surface_set_input_region(wl_surface* wl_surface, wl_region* region) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_SET_INPUT_REGION, region); } -pragma(inline, true) static void wl_surface_commit(wl_surface* wl_surface) { +pragma(inline, true) private void wl_surface_commit(wl_surface* wl_surface) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_COMMIT); } -pragma(inline, true) static void wl_surface_set_buffer_transform(wl_surface* wl_surface, int transform) { +pragma(inline, true) private void wl_surface_set_buffer_transform(wl_surface* wl_surface, int transform) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_SET_BUFFER_TRANSFORM, transform); } -pragma(inline, true) static void wl_surface_set_buffer_scale(wl_surface* wl_surface, int scale) { +pragma(inline, true) private void wl_surface_set_buffer_scale(wl_surface* wl_surface, int scale) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_SET_BUFFER_SCALE, scale); } -pragma(inline, true) static void wl_surface_damage_buffer(wl_surface* wl_surface, int x, int y, int width, int height) { +pragma(inline, true) private void wl_surface_damage_buffer(wl_surface* wl_surface, int x, int y, int width, int height) { wl_proxy_marshal(cast(wl_proxy*) wl_surface, WL_SURFACE_DAMAGE_BUFFER, x, y, width, height); } -pragma(inline, true) static int wl_seat_add_listener(wl_seat* wl_seat, const(wl_seat_listener)* listener, void* data) { +pragma(inline, true) private int wl_seat_add_listener(wl_seat* wl_seat, const(wl_seat_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_seat, cast(void function()) listener, data); } @@ -933,17 +933,17 @@ enum WL_SEAT_GET_KEYBOARD_SINCE_VERSION = 1; enum WL_SEAT_GET_TOUCH_SINCE_VERSION = 1; enum WL_SEAT_RELEASE_SINCE_VERSION = 5; -pragma(inline, true) static void wl_seat_set_user_data(wl_seat* wl_seat, void* user_data) { +pragma(inline, true) private void wl_seat_set_user_data(wl_seat* wl_seat, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_seat, user_data); } -pragma(inline, true) static void* wl_seat_get_user_data(wl_seat* wl_seat) { +pragma(inline, true) private void* wl_seat_get_user_data(wl_seat* wl_seat) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_seat); } -pragma(inline, true) static uint wl_seat_get_version(wl_seat* wl_seat) { +pragma(inline, true) private uint wl_seat_get_version(wl_seat* wl_seat) { return wl_proxy_get_version(cast(wl_proxy*) wl_seat); } -pragma(inline, true) static void wl_seat_destroy(wl_seat* wl_seat) { +pragma(inline, true) private void wl_seat_destroy(wl_seat* wl_seat) { wl_proxy_destroy(cast(wl_proxy*) wl_seat); } pragma(inline, true) static wl_pointer* wl_seat_get_pointer(wl_seat* wl_seat) { @@ -963,7 +963,7 @@ pragma(inline, true) static wl_touch* wl_seat_get_touch(wl_seat* wl_seat) { id = wl_proxy_marshal_constructor(cast(wl_proxy*) wl_seat, WL_SEAT_GET_TOUCH, &wl_touch_interface, null); return cast(wl_touch*) id; } -pragma(inline, true) static void wl_seat_release(wl_seat* wl_seat) { +pragma(inline, true) private void wl_seat_release(wl_seat* wl_seat) { wl_proxy_marshal(cast(wl_proxy*) wl_seat, WL_SEAT_RELEASE); wl_proxy_destroy(cast(wl_proxy*) wl_seat); } @@ -975,7 +975,7 @@ enum wl_pointer_axis_source { WL_POINTER_AXIS_SOURCE_FINGER = 1, WL_POINTER_AXIS_SOURCE_CONTINUOUS = 2, } -pragma(inline, true) static int wl_pointer_add_listener(wl_pointer* wl_pointer, const(wl_pointer_listener)* listener, void* data) { +pragma(inline, true) private int wl_pointer_add_listener(wl_pointer* wl_pointer, const(wl_pointer_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_pointer, cast(void function()) listener, data); } enum WL_POINTER_SET_CURSOR = 0; @@ -992,28 +992,28 @@ enum WL_POINTER_AXIS_DISCRETE_SINCE_VERSION = 5; enum WL_POINTER_SET_CURSOR_SINCE_VERSION = 1; enum WL_POINTER_RELEASE_SINCE_VERSION = 3; -pragma(inline, true) static void wl_pointer_set_user_data(wl_pointer* wl_pointer, void* user_data) { +pragma(inline, true) private void wl_pointer_set_user_data(wl_pointer* wl_pointer, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_pointer, user_data); } -pragma(inline, true) static void* wl_pointer_get_user_data(wl_pointer* wl_pointer) { +pragma(inline, true) private void* wl_pointer_get_user_data(wl_pointer* wl_pointer) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_pointer); } -pragma(inline, true) static uint wl_pointer_get_version(wl_pointer* wl_pointer) { +pragma(inline, true) private uint wl_pointer_get_version(wl_pointer* wl_pointer) { return wl_proxy_get_version(cast(wl_proxy*) wl_pointer); } -pragma(inline, true) static void wl_pointer_destroy(wl_pointer* wl_pointer) { +pragma(inline, true) private void wl_pointer_destroy(wl_pointer* wl_pointer) { wl_proxy_destroy(cast(wl_proxy*) wl_pointer); } -pragma(inline, true) static void wl_pointer_set_cursor(wl_pointer* wl_pointer, uint serial, wl_surface* surface, int hotspot_x, int hotspot_y) { +pragma(inline, true) private void wl_pointer_set_cursor(wl_pointer* wl_pointer, uint serial, wl_surface* surface, int hotspot_x, int hotspot_y) { wl_proxy_marshal(cast(wl_proxy*) wl_pointer, WL_POINTER_SET_CURSOR, serial, surface, hotspot_x, hotspot_y); } -pragma(inline, true) static void wl_pointer_release(wl_pointer* wl_pointer) { +pragma(inline, true) private void wl_pointer_release(wl_pointer* wl_pointer) { wl_proxy_marshal(cast(wl_proxy*) wl_pointer, WL_POINTER_RELEASE); wl_proxy_destroy(cast(wl_proxy*) wl_pointer); } -pragma(inline, true) static int wl_keyboard_add_listener(wl_keyboard* wl_keyboard, const(wl_keyboard_listener)* listener, void* data) { +pragma(inline, true) private int wl_keyboard_add_listener(wl_keyboard* wl_keyboard, const(wl_keyboard_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_keyboard, cast(void function()) listener, data); } @@ -1026,21 +1026,21 @@ enum WL_KEYBOARD_MODIFIERS_SINCE_VERSION = 1; enum WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION = 4; enum WL_KEYBOARD_RELEASE_SINCE_VERSION = 3; -pragma(inline, true) static void wl_keyboard_set_user_data(wl_keyboard* wl_keyboard, void* user_data) { +pragma(inline, true) private void wl_keyboard_set_user_data(wl_keyboard* wl_keyboard, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_keyboard, user_data); } -pragma(inline, true) static void* wl_keyboard_get_user_data(wl_keyboard* wl_keyboard) { +pragma(inline, true) private void* wl_keyboard_get_user_data(wl_keyboard* wl_keyboard) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_keyboard); } -pragma(inline, true) static uint wl_keyboard_get_version(wl_keyboard* wl_keyboard) { +pragma(inline, true) private uint wl_keyboard_get_version(wl_keyboard* wl_keyboard) { return wl_proxy_get_version(cast(wl_proxy*) wl_keyboard); } -pragma(inline, true) static void wl_keyboard_destroy(wl_keyboard* wl_keyboard) { +pragma(inline, true) private void wl_keyboard_destroy(wl_keyboard* wl_keyboard) { wl_proxy_destroy(cast(wl_proxy*) wl_keyboard); } -pragma(inline, true) static void wl_keyboard_release(wl_keyboard* wl_keyboard) { +pragma(inline, true) private void wl_keyboard_release(wl_keyboard* wl_keyboard) { wl_proxy_marshal(cast(wl_proxy*) wl_keyboard, WL_KEYBOARD_RELEASE); wl_proxy_destroy(cast(wl_proxy*) wl_keyboard); @@ -1052,7 +1052,7 @@ struct wl_touch_listener { void function(void* data, wl_touch* wl_touch) frame; void function(void* data, wl_touch* wl_touch) cancel; }; -pragma(inline, true) static int wl_touch_add_listener(wl_touch* wl_touch, const(wl_touch_listener)* listener, void* data) { +pragma(inline, true) private int wl_touch_add_listener(wl_touch* wl_touch, const(wl_touch_listener)* listener, void* data) { return wl_proxy_add_listener(cast(wl_proxy*) wl_touch, cast(void function()) listener, data); } enum WL_TOUCH_RELEASE = 0; @@ -1063,21 +1063,21 @@ enum WL_TOUCH_FRAME_SINCE_VERSION = 1; enum WL_TOUCH_CANCEL_SINCE_VERSION = 1; enum WL_TOUCH_RELEASE_SINCE_VERSION = 3; -pragma(inline, true) static void wl_touch_set_user_data(wl_touch* wl_touch, void* user_data) { +pragma(inline, true) private void wl_touch_set_user_data(wl_touch* wl_touch, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_touch, user_data); } -pragma(inline, true) static void* wl_touch_get_user_data(wl_touch* wl_touch) { +pragma(inline, true) private void* wl_touch_get_user_data(wl_touch* wl_touch) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_touch); } -pragma(inline, true) static uint wl_touch_get_version(wl_touch* wl_touch) { +pragma(inline, true) private uint wl_touch_get_version(wl_touch* wl_touch) { return wl_proxy_get_version(cast(wl_proxy*) wl_touch); } -pragma(inline, true) static void wl_touch_destroy(wl_touch* wl_touch) { +pragma(inline, true) private void wl_touch_destroy(wl_touch* wl_touch) { wl_proxy_destroy(cast(wl_proxy*) wl_touch); } -pragma(inline, true) static void wl_touch_release(wl_touch* wl_touch) { +pragma(inline, true) private void wl_touch_release(wl_touch* wl_touch) { wl_proxy_marshal(cast(wl_proxy*) wl_touch, WL_TOUCH_RELEASE); wl_proxy_destroy(cast(wl_proxy*) wl_touch); } @@ -1106,16 +1106,16 @@ enum WL_OUTPUT_DONE_SINCE_VERSION = 2; enum WL_OUTPUT_SCALE_SINCE_VERSION = 2; enum WL_OUTPUT_RELEASE_SINCE_VERSION = 3; -pragma(inline, true) static void wl_output_set_user_data(wl_output* wl_output, void* user_data) { +pragma(inline, true) private void wl_output_set_user_data(wl_output* wl_output, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_output, user_data); } -pragma(inline, true) static void* wl_output_get_user_data(wl_output* wl_output) { +pragma(inline, true) private void* wl_output_get_user_data(wl_output* wl_output) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_output); } -pragma(inline, true) static uint wl_output_get_version(wl_output* wl_output) { +pragma(inline, true) private uint wl_output_get_version(wl_output* wl_output) { return wl_proxy_get_version(cast(wl_proxy*) wl_output); } -pragma(inline, true) static void wl_output_release(wl_output* wl_output) { +pragma(inline, true) private void wl_output_release(wl_output* wl_output) { wl_proxy_marshal(cast(wl_proxy*) wl_output, WL_OUTPUT_RELEASE); wl_proxy_destroy(cast(wl_proxy*) wl_output); } @@ -1126,26 +1126,26 @@ enum WL_REGION_DESTROY_SINCE_VERSION = 1; enum WL_REGION_ADD_SINCE_VERSION = 1; enum WL_REGION_SUBTRACT_SINCE_VERSION = 1; -pragma(inline, true) static void wl_region_set_user_data(wl_region* wl_region, void* user_data) { +pragma(inline, true) private void wl_region_set_user_data(wl_region* wl_region, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_region, user_data); } -pragma(inline, true) static void* wl_region_get_user_data(wl_region* wl_region) { +pragma(inline, true) private void* wl_region_get_user_data(wl_region* wl_region) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_region); } -pragma(inline, true) static uint wl_region_get_version(wl_region* wl_region) { +pragma(inline, true) private uint wl_region_get_version(wl_region* wl_region) { return wl_proxy_get_version(cast(wl_proxy*) wl_region); } -pragma(inline, true) static void wl_region_destroy(wl_region* wl_region) { +pragma(inline, true) private void wl_region_destroy(wl_region* wl_region) { wl_proxy_marshal(cast(wl_proxy*) wl_region, WL_REGION_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_region); } -pragma(inline, true) static void wl_region_add(wl_region* wl_region, int x, int y, int width, int height) { +pragma(inline, true) private void wl_region_add(wl_region* wl_region, int x, int y, int width, int height) { wl_proxy_marshal(cast(wl_proxy*) wl_region, WL_REGION_ADD, x, y, width, height); } -pragma(inline, true) static void wl_region_subtract(wl_region* wl_region, int x, int y, int width, int height) { +pragma(inline, true) private void wl_region_subtract(wl_region* wl_region, int x, int y, int width, int height) { wl_proxy_marshal(cast(wl_proxy*) wl_region, WL_REGION_SUBTRACT, x, y, width, height); } @@ -1158,18 +1158,18 @@ enum WL_SUBCOMPOSITOR_DESTROY_SINCE_VERSION = 1; enum WL_SUBCOMPOSITOR_GET_SUBSURFACE_SINCE_VERSION = 1; -pragma(inline, true) static void wl_subcompositor_set_user_data(wl_subcompositor* wl_subcompositor, void* user_data) { +pragma(inline, true) private void wl_subcompositor_set_user_data(wl_subcompositor* wl_subcompositor, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_subcompositor, user_data); } -pragma(inline, true) static void* wl_subcompositor_get_user_data(wl_subcompositor* wl_subcompositor) { +pragma(inline, true) private void* wl_subcompositor_get_user_data(wl_subcompositor* wl_subcompositor) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_subcompositor); } -pragma(inline, true) static uint wl_subcompositor_get_version(wl_subcompositor* wl_subcompositor) { +pragma(inline, true) private uint wl_subcompositor_get_version(wl_subcompositor* wl_subcompositor) { return wl_proxy_get_version(cast(wl_proxy*) wl_subcompositor); } -pragma(inline, true) static void wl_subcompositor_destroy(wl_subcompositor* wl_subcompositor) { +pragma(inline, true) private void wl_subcompositor_destroy(wl_subcompositor* wl_subcompositor) { wl_proxy_marshal(cast(wl_proxy*) wl_subcompositor, WL_SUBCOMPOSITOR_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_subcompositor); @@ -1196,36 +1196,36 @@ enum WL_SUBSURFACE_PLACE_BELOW_SINCE_VERSION = 1; enum WL_SUBSURFACE_SET_SYNC_SINCE_VERSION = 1; enum WL_SUBSURFACE_SET_DESYNC_SINCE_VERSION = 1; -pragma(inline, true) static void wl_subsurface_set_user_data(wl_subsurface* wl_subsurface, void* user_data) { +pragma(inline, true) private void wl_subsurface_set_user_data(wl_subsurface* wl_subsurface, void* user_data) { wl_proxy_set_user_data(cast(wl_proxy*) wl_subsurface, user_data); } -pragma(inline, true) static void* wl_subsurface_get_user_data(wl_subsurface* wl_subsurface) { +pragma(inline, true) private void* wl_subsurface_get_user_data(wl_subsurface* wl_subsurface) { return wl_proxy_get_user_data(cast(wl_proxy*) wl_subsurface); } -pragma(inline, true) static uint wl_subsurface_get_version(wl_subsurface* wl_subsurface) { +pragma(inline, true) private uint wl_subsurface_get_version(wl_subsurface* wl_subsurface) { return wl_proxy_get_version(cast(wl_proxy*) wl_subsurface); } -pragma(inline, true) static void wl_subsurface_destroy(wl_subsurface* wl_subsurface) { +pragma(inline, true) private void wl_subsurface_destroy(wl_subsurface* wl_subsurface) { wl_proxy_marshal(cast(wl_proxy*) wl_subsurface, WL_SUBSURFACE_DESTROY); wl_proxy_destroy(cast(wl_proxy*) wl_subsurface); } -pragma(inline, true) static void wl_subsurface_set_position(wl_subsurface* wl_subsurface, int x, int y) { +pragma(inline, true) private void wl_subsurface_set_position(wl_subsurface* wl_subsurface, int x, int y) { wl_proxy_marshal(cast(wl_proxy*) wl_subsurface, WL_SUBSURFACE_SET_POSITION, x, y); } -pragma(inline, true) static void wl_subsurface_place_above(wl_subsurface* wl_subsurface, wl_surface* sibling) { +pragma(inline, true) private void wl_subsurface_place_above(wl_subsurface* wl_subsurface, wl_surface* sibling) { wl_proxy_marshal(cast(wl_proxy*) wl_subsurface, WL_SUBSURFACE_PLACE_ABOVE, sibling); } -pragma(inline, true) static void wl_subsurface_place_below(wl_subsurface* wl_subsurface, wl_surface* sibling) { +pragma(inline, true) private void wl_subsurface_place_below(wl_subsurface* wl_subsurface, wl_surface* sibling) { wl_proxy_marshal(cast(wl_proxy*) wl_subsurface, WL_SUBSURFACE_PLACE_BELOW, sibling); } -pragma(inline, true) static void wl_subsurface_set_sync(wl_subsurface* wl_subsurface) { +pragma(inline, true) private void wl_subsurface_set_sync(wl_subsurface* wl_subsurface) { wl_proxy_marshal(cast(wl_proxy*) wl_subsurface, WL_SUBSURFACE_SET_SYNC); } -pragma(inline, true) static void wl_subsurface_set_desync(wl_subsurface* wl_subsurface) { +pragma(inline, true) private void wl_subsurface_set_desync(wl_subsurface* wl_subsurface) { wl_proxy_marshal(cast(wl_proxy*) wl_subsurface, WL_SUBSURFACE_SET_DESYNC); } diff --git a/source/glfw3/wgl_context.d b/source/glfw3/wgl_context.d index 666f96c..e4c21b9 100644 --- a/source/glfw3/wgl_context.d +++ b/source/glfw3/wgl_context.d @@ -174,7 +174,7 @@ import core.stdc.assert_; // Return the value corresponding to the specified attribute // -static int findPixelFormatAttribValue(const(int)* attribs, int attribCount, const(int)* values, int attrib) { +private int findPixelFormatAttribValue(const(int)* attribs, int attribCount, const(int)* values, int attrib) { int i; for (i = 0; i < attribCount; i++) @@ -191,7 +191,7 @@ static int findPixelFormatAttribValue(const(int)* attribs, int attribCount, cons // Return a list of available and usable framebuffer configs // -static int choosePixelFormat(_GLFWwindow* window, const(_GLFWctxconfig)* ctxconfig, const(_GLFWfbconfig)* fbconfig) { +private int choosePixelFormat(_GLFWwindow* window, const(_GLFWctxconfig)* ctxconfig, const(_GLFWfbconfig)* fbconfig) { _GLFWfbconfig* usableConfigs; const(_GLFWfbconfig)* closest; int i;int pixelFormat;int nativeCount;int usableCount = 0;int attribCount = 0; @@ -423,7 +423,7 @@ static int choosePixelFormat(_GLFWwindow* window, const(_GLFWctxconfig)* ctxconf return pixelFormat; } -static void makeContextCurrentWGL(_GLFWwindow* window) { +private void makeContextCurrentWGL(_GLFWwindow* window) { if (window) { if (_glfw.wgl.MakeCurrent(window.context.wgl.dc, window.context.wgl.handle)) @@ -447,7 +447,7 @@ static void makeContextCurrentWGL(_GLFWwindow* window) { } } -static void swapBuffersWGL(_GLFWwindow* window) { +private void swapBuffersWGL(_GLFWwindow* window) { if (!window.monitor) { if (IsWindowsVistaOrGreater()) @@ -469,7 +469,7 @@ static void swapBuffersWGL(_GLFWwindow* window) { SwapBuffers(window.context.wgl.dc); } -static void swapIntervalWGL(int interval) { +private void swapIntervalWGL(int interval) { auto window = cast(_GLFWwindow*) _glfwPlatformGetTls(&_glfw.contextSlot); window.context.wgl.interval = interval; @@ -493,7 +493,7 @@ static void swapIntervalWGL(int interval) { _glfw.wgl.SwapIntervalEXT(interval); } -static int extensionSupportedWGL(const(char)* extension) { +private int extensionSupportedWGL(const(char)* extension) { const(char)* extensions = null; if (_glfw.wgl.GetExtensionsStringARB) @@ -507,7 +507,7 @@ static int extensionSupportedWGL(const(char)* extension) { return _glfwStringInExtensionString(extension, extensions); } -static GLFWglproc getProcAddressWGL(const(char)* procname) { +private GLFWglproc getProcAddressWGL(const(char)* procname) { const(GLFWglproc) proc = cast(GLFWglproc) _glfw.wgl.GetProcAddress(procname); if (proc) return proc; @@ -515,7 +515,7 @@ static GLFWglproc getProcAddressWGL(const(char)* procname) { return cast(GLFWglproc) GetProcAddress(_glfw.wgl.instance, procname); } -static void destroyContextWGL(_GLFWwindow* window) { +private void destroyContextWGL(_GLFWwindow* window) { if (window.context.wgl.handle) { _glfw.wgl.DeleteContext(window.context.wgl.handle); diff --git a/source/glfw3/win32_init.d b/source/glfw3/win32_init.d index b3ecb8d..3f57d7b 100644 --- a/source/glfw3/win32_init.d +++ b/source/glfw3/win32_init.d @@ -40,7 +40,7 @@ public import glfw3.internal; import core.stdc.stdlib; import core.stdc.string; -static const(GUID) _glfw_GUID_DEVINTERFACE_HID = GUID(0x4d1e55b2,0xf16f,0x11cf,[0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30]); +private const(GUID) _glfw_GUID_DEVINTERFACE_HID = GUID(0x4d1e55b2,0xf16f,0x11cf,[0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30]); enum GUID_DEVINTERFACE_HID = _glfw_GUID_DEVINTERFACE_HID; @@ -72,7 +72,7 @@ extern(Windows) BOOL DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) // Load necessary libraries (DLLs) // -static GLFWbool loadLibraries() { +private GLFWbool loadLibraries() { _glfw.win32.winmm.instance = LoadLibraryA("winmm.dll"); if (!_glfw.win32.winmm.instance) { @@ -335,7 +335,7 @@ private extern(D) void createKeyTables() { // Creates a dummy window for behind-the-scenes work // -static GLFWbool createHelperWindow() { +private GLFWbool createHelperWindow() { MSG msg; _glfw.win32.helperWindowHandle = diff --git a/source/glfw3/win32_joystick.d b/source/glfw3/win32_joystick.d index 24fe43b..bbabb88 100644 --- a/source/glfw3/win32_joystick.d +++ b/source/glfw3/win32_joystick.d @@ -80,15 +80,15 @@ struct _GLFWobjenumWin32 { // Define local copies of the necessary GUIDs // -static immutable GUID _glfw_IID_IDirectInput8W = GUID(0xbf798031,0x483a,0x4da2,[0xaa,0x99,0x5d,0x64,0xed,0x36,0x97,0x00]); -static immutable GUID _glfw_GUID_XAxis = GUID(0xa36d02e0,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_YAxis = GUID(0xa36d02e1,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_ZAxis = GUID(0xa36d02e2,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_RxAxis = GUID(0xa36d02f4,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_RyAxis = GUID(0xa36d02f5,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_RzAxis = GUID(0xa36d02e3,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_Slider = GUID(0xa36d02e4,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); -static immutable GUID _glfw_GUID_POV = GUID(0xa36d02f2,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_IID_IDirectInput8W = GUID(0xbf798031,0x483a,0x4da2,[0xaa,0x99,0x5d,0x64,0xed,0x36,0x97,0x00]); +private immutable GUID _glfw_GUID_XAxis = GUID(0xa36d02e0,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_YAxis = GUID(0xa36d02e1,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_ZAxis = GUID(0xa36d02e2,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_RxAxis = GUID(0xa36d02f4,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_RyAxis = GUID(0xa36d02f5,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_RzAxis = GUID(0xa36d02e3,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_Slider = GUID(0xa36d02e4,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); +private immutable GUID _glfw_GUID_POV = GUID(0xa36d02f2,0xc9f3,0x11cf,[0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00]); alias IID_IDirectInput8W = _glfw_IID_IDirectInput8W; alias GUID_XAxis = _glfw_GUID_XAxis; @@ -103,7 +103,7 @@ alias GUID_POV = _glfw_GUID_POV; // Object data array for our clone of c_dfDIJoystick // Generated with https://github.com/elmindreda/c_dfDIJoystick2 // -static DIOBJECTDATAFORMAT[44] _glfwObjectDataFormats = [ +private DIOBJECTDATAFORMAT[44] _glfwObjectDataFormats = [ DIOBJECTDATAFORMAT(&GUID_XAxis,DIJOFS_X,DIDFT_AXIS|DIDFT_OPTIONAL|DIDFT_ANYINSTANCE,DIDOI_ASPECTPOSITION), DIOBJECTDATAFORMAT(&GUID_YAxis,DIJOFS_Y,DIDFT_AXIS|DIDFT_OPTIONAL|DIDFT_ANYINSTANCE,DIDOI_ASPECTPOSITION), DIOBJECTDATAFORMAT(&GUID_ZAxis,DIJOFS_Z,DIDFT_AXIS|DIDFT_OPTIONAL|DIDFT_ANYINSTANCE,DIDOI_ASPECTPOSITION), @@ -152,7 +152,7 @@ static DIOBJECTDATAFORMAT[44] _glfwObjectDataFormats = [ // Our clone of c_dfDIJoystick // -static const DIDATAFORMAT _glfwDataFormat = DIDATAFORMAT( +private const DIDATAFORMAT _glfwDataFormat = DIDATAFORMAT( DIDATAFORMAT.sizeof, DIOBJECTDATAFORMAT.sizeof, DIDFT_ABSAXIS, @@ -163,7 +163,7 @@ static const DIDATAFORMAT _glfwDataFormat = DIDATAFORMAT( // Returns a description fitting the specified XInput capabilities // -static const(char)* getDeviceDescription(const(XINPUT_CAPABILITIES)* xic) { +private const(char)* getDeviceDescription(const(XINPUT_CAPABILITIES)* xic) { switch (xic.SubType) { case XINPUT_DEVSUBTYPE_WHEEL: @@ -193,7 +193,7 @@ static const(char)* getDeviceDescription(const(XINPUT_CAPABILITIES)* xic) { // Lexically compare device objects // -static int compareJoystickObjects(const(void)* first, const(void)* second) { +private int compareJoystickObjects(const(void)* first, const(void)* second) { auto fo = cast(const(_GLFWjoyobjectWin32)*) first; auto so = cast(const(_GLFWjoyobjectWin32)*) second; @@ -206,7 +206,7 @@ static int compareJoystickObjects(const(void)* first, const(void)* second) { // Checks whether the specified device supports XInput // Technique from FDInputJoystickManager::IsXInputDeviceFast in ZDoom // -static GLFWbool supportsXInput(const(GUID)* guid) { +private GLFWbool supportsXInput(const(GUID)* guid) { UINT i;UINT count = 0; RAWINPUTDEVICELIST* ridl; GLFWbool result = GLFW_FALSE; @@ -269,7 +269,7 @@ static GLFWbool supportsXInput(const(GUID)* guid) { // Frees all resources associated with the specified joystick // -static void closeJoystick(_GLFWjoystick* js) { +private void closeJoystick(_GLFWjoystick* js) { if (js.win32.device) { js.win32.device.Unacquire(); diff --git a/source/glfw3/win32_monitor.d b/source/glfw3/win32_monitor.d index 863c758..63f86a6 100644 --- a/source/glfw3/win32_monitor.d +++ b/source/glfw3/win32_monitor.d @@ -40,7 +40,7 @@ import core.stdc.wchar_; // Callback for EnumDisplayMonitors in createMonitor // -extern(Windows) static BOOL monitorCallback(HMONITOR handle, HDC dc, RECT* rect, LPARAM data) { +extern(Windows) private BOOL monitorCallback(HMONITOR handle, HDC dc, RECT* rect, LPARAM data) { MONITORINFOEXW mi; memset(&mi, 0, typeof(mi).sizeof); mi.cbSize = typeof(mi).sizeof; @@ -57,7 +57,7 @@ extern(Windows) static BOOL monitorCallback(HMONITOR handle, HDC dc, RECT* rect, // Create monitor from an adapter and (optionally) a display // -static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, DISPLAY_DEVICEW* display) { +private extern(D) _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, DISPLAY_DEVICEW* display) { _GLFWmonitor* monitor; int widthMM;int heightMM; char* name; diff --git a/source/glfw3/win32_platform.d b/source/glfw3/win32_platform.d index b75f8c4..c5b5eeb 100644 --- a/source/glfw3/win32_platform.d +++ b/source/glfw3/win32_platform.d @@ -103,10 +103,10 @@ version (all) { enum DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = cast(HANDLE) -4; // HACK: Define versionhelpers.h functions manually as MinGW lacks the header -static { - private enum _WIN32_WINNT_WINXP = 0x0501; - private enum _WIN32_WINNT_VISTA = 0x0600; - private enum _WIN32_WINNT_WIN7 = 0x0601; +private { + enum _WIN32_WINNT_WINXP = 0x0501; + enum _WIN32_WINNT_VISTA = 0x0600; + enum _WIN32_WINNT_WIN7 = 0x0601; // note: already in core.sys.windows.winver, but not @nogc bool IsWindowsXPOrGreater() { diff --git a/source/glfw3/win32_window.d b/source/glfw3/win32_window.d index a4a3c3e..1503114 100644 --- a/source/glfw3/win32_window.d +++ b/source/glfw3/win32_window.d @@ -46,7 +46,7 @@ import core.sys.windows.windows; // Returns the window style for the specified window // -static DWORD getWindowStyle(const(_GLFWwindow)* window) { +private DWORD getWindowStyle(const(_GLFWwindow)* window) { DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; if (window.monitor) @@ -71,7 +71,7 @@ static DWORD getWindowStyle(const(_GLFWwindow)* window) { // Returns the extended window style for the specified window // -static DWORD getWindowExStyle(const(_GLFWwindow)* window) { +private DWORD getWindowExStyle(const(_GLFWwindow)* window) { DWORD style = WS_EX_APPWINDOW; if (window.monitor || window.floating) @@ -82,7 +82,7 @@ static DWORD getWindowExStyle(const(_GLFWwindow)* window) { // Returns the image whose area most closely matches the desired one // -static const(GLFWimage)* chooseImage(int count, const(GLFWimage)* images, int width, int height) { +private const(GLFWimage)* chooseImage(int count, const(GLFWimage)* images, int width, int height) { int i;int leastDiff = INT_MAX; const(GLFWimage)* closest = null; @@ -102,7 +102,7 @@ static const(GLFWimage)* chooseImage(int count, const(GLFWimage)* images, int wi // Creates an RGBA icon or cursor // -static HICON createIcon(const(GLFWimage)* image, int xhot, int yhot, GLFWbool icon) { +private HICON createIcon(const(GLFWimage)* image, int xhot, int yhot, GLFWbool icon) { int i; HDC dc; HICON handle; @@ -316,7 +316,7 @@ private extern(D) void enableCursor(_GLFWwindow* window) { // Returns whether the cursor is in the content area of the specified window // -static GLFWbool cursorInContentArea(_GLFWwindow* window) { +private GLFWbool cursorInContentArea(_GLFWwindow* window) { RECT area; POINT pos; @@ -413,7 +413,7 @@ private extern(D) void updateFramebufferTransparency(const(_GLFWwindow)* window) // Retrieves and translates modifier keys // -static int getKeyMods() { +private int getKeyMods() { int mods = 0; if (GetKeyState(VK_SHIFT) & 0x8000) @@ -488,7 +488,7 @@ private extern(D) void releaseMonitor(_GLFWwindow* window) { // Window callback function (handles window messages) // -static LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { +private LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { auto window = cast(_GLFWwindow*) GetPropW(hWnd, "GLFW"w.ptr); if (!window) { @@ -1164,7 +1164,7 @@ static LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Creates the GLFW window // -static int createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig, const(_GLFWfbconfig)* fbconfig) { +private int createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig, const(_GLFWfbconfig)* fbconfig) { int xpos;int ypos;int fullWidth;int fullHeight; WCHAR* wideTitle; DWORD style = getWindowStyle(window); diff --git a/source/glfw3/wl_init.d b/source/glfw3/wl_init.d index 67a3e95..3ff357b 100644 --- a/source/glfw3/wl_init.d +++ b/source/glfw3/wl_init.d @@ -52,11 +52,11 @@ import xkbcommon.xkbcommon; //public import wayland-client; //import wayland.native.util; -pragma(inline, true) extern(D) static int min(int n1, int n2) { +pragma(inline, true) extern(D) private int min(int n1, int n2) { return n1 < n2 ? n1 : n2; } -static _GLFWwindow* findWindowFromDecorationSurface(wl_surface* surface, int* which) { +private _GLFWwindow* findWindowFromDecorationSurface(wl_surface* surface, int* which) { int focus; _GLFWwindow* window = _glfw.windowListHead; if (!which) @@ -88,7 +88,7 @@ static _GLFWwindow* findWindowFromDecorationSurface(wl_surface* surface, int* wh return window; } -static void pointerHandleEnter(void* data, wl_pointer* pointer, uint serial, wl_surface* surface, wl_fixed_t sx, wl_fixed_t sy) { +private void pointerHandleEnter(void* data, wl_pointer* pointer, uint serial, wl_surface* surface, wl_fixed_t sx, wl_fixed_t sy) { // Happens in the case we just destroyed the surface. if (!surface) return; @@ -112,7 +112,7 @@ static void pointerHandleEnter(void* data, wl_pointer* pointer, uint serial, wl_ _glfwInputCursorEnter(window, GLFW_TRUE); } -static void pointerHandleLeave(void* data, wl_pointer* pointer, uint serial, wl_surface* surface) { +private void pointerHandleLeave(void* data, wl_pointer* pointer, uint serial, wl_surface* surface) { _GLFWwindow* window = _glfw.wl.pointerFocus; if (!window) @@ -126,7 +126,7 @@ static void pointerHandleLeave(void* data, wl_pointer* pointer, uint serial, wl_ _glfw.wl.cursorPreviousName = null; } -static void setCursor(_GLFWwindow* window, const(char)* name) { +private void setCursor(_GLFWwindow* window, const(char)* name) { wl_buffer* buffer; wl_cursor* cursor; wl_cursor_image* image; @@ -170,7 +170,7 @@ static void setCursor(_GLFWwindow* window, const(char)* name) { _glfw.wl.cursorPreviousName = name; } -static void pointerHandleMotion(void* data, wl_pointer* pointer, uint time, wl_fixed_t sx, wl_fixed_t sy) { +private void pointerHandleMotion(void* data, wl_pointer* pointer, uint time, wl_fixed_t sx, wl_fixed_t sy) { _GLFWwindow* window = _glfw.wl.pointerFocus; const(char)* cursorName = null; double x;double y; @@ -224,7 +224,7 @@ static void pointerHandleMotion(void* data, wl_pointer* pointer, uint time, wl_f setCursor(window, cursorName); } -static void pointerHandleButton(void* data, wl_pointer* pointer, uint serial, uint time, uint button, uint state) { +private void pointerHandleButton(void* data, wl_pointer* pointer, uint serial, uint time, uint button, uint state) { _GLFWwindow* window = _glfw.wl.pointerFocus; int glfwButton; @@ -313,7 +313,7 @@ static void pointerHandleButton(void* data, wl_pointer* pointer, uint serial, ui _glfw.wl.xkb.modifiers); } -static void pointerHandleAxis(void* data, wl_pointer* pointer, uint time, uint axis, wl_fixed_t value) { +private void pointerHandleAxis(void* data, wl_pointer* pointer, uint time, uint axis, wl_fixed_t value) { _GLFWwindow* window = _glfw.wl.pointerFocus; double x = 0.0;double y = 0.0; // Wayland scroll events are in pointer motion coordinate space (think two @@ -335,7 +335,7 @@ static void pointerHandleAxis(void* data, wl_pointer* pointer, uint time, uint a _glfwInputScroll(window, x, y); } -static const(wl_pointer_listener) pointerListener = wl_pointer_listener( +private const(wl_pointer_listener) pointerListener = wl_pointer_listener( &pointerHandleEnter, &pointerHandleLeave, &pointerHandleMotion, @@ -343,7 +343,7 @@ static const(wl_pointer_listener) pointerListener = wl_pointer_listener( &pointerHandleAxis, ); -static void keyboardHandleKeymap(void* data, wl_keyboard* keyboard, uint format, int fd, uint size) { +private void keyboardHandleKeymap(void* data, wl_keyboard* keyboard, uint format, int fd, uint size) { xkb_keymap* keymap; xkb_state* state; @@ -440,7 +440,7 @@ version (HAVE_XKBCOMMON_COMPOSE_H) { 1 << _glfw.wl.xkb.keymap_mod_get_index(_glfw.wl.xkb.keymap, "Mod2"); } -static void keyboardHandleEnter(void* data, wl_keyboard* keyboard, uint serial, wl_surface* surface, wl_array* keys) { +private void keyboardHandleEnter(void* data, wl_keyboard* keyboard, uint serial, wl_surface* surface, wl_array* keys) { // Happens in the case we just destroyed the surface. if (!surface) return; @@ -458,7 +458,7 @@ static void keyboardHandleEnter(void* data, wl_keyboard* keyboard, uint serial, _glfwInputWindowFocus(window, GLFW_TRUE); } -static void keyboardHandleLeave(void* data, wl_keyboard* keyboard, uint serial, wl_surface* surface) { +private void keyboardHandleLeave(void* data, wl_keyboard* keyboard, uint serial, wl_surface* surface) { _GLFWwindow* window = _glfw.wl.keyboardFocus; if (!window) @@ -469,7 +469,7 @@ static void keyboardHandleLeave(void* data, wl_keyboard* keyboard, uint serial, _glfwInputWindowFocus(window, GLFW_FALSE); } -static int toGLFWKeyCode(uint key) { +private int toGLFWKeyCode(uint key) { if (key < _glfw.wl.keycodes.length) return _glfw.wl.keycodes[key]; @@ -477,7 +477,7 @@ static int toGLFWKeyCode(uint key) { } version (HAVE_XKBCOMMON_COMPOSE_H) { -static xkb_keysym_t composeSymbol(xkb_keysym_t sym) { +private xkb_keysym_t composeSymbol(xkb_keysym_t sym) { if (sym == XKB_KEY_NoSymbol || !_glfw.wl.xkb.composeState) return sym; if (xkb_compose_state_feed(_glfw.wl.xkb.composeState, sym) @@ -497,7 +497,7 @@ static xkb_keysym_t composeSymbol(xkb_keysym_t sym) { } } -static GLFWbool inputChar(_GLFWwindow* window, uint key) { +private GLFWbool inputChar(_GLFWwindow* window, uint key) { uint code;uint numSyms; c_long cp; const(xkb_keysym_t)* syms; @@ -525,7 +525,7 @@ version (HAVE_XKBCOMMON_COMPOSE_H) { return _glfw.wl.xkb.keymap_key_repeats(_glfw.wl.xkb.keymap, syms[0]); } -static void keyboardHandleKey(void* data, wl_keyboard* keyboard, uint serial, uint time, uint key, uint state) { +private void keyboardHandleKey(void* data, wl_keyboard* keyboard, uint serial, uint time, uint key, uint state) { int keyCode; int action; _GLFWwindow* window = _glfw.wl.keyboardFocus; @@ -562,7 +562,7 @@ static void keyboardHandleKey(void* data, wl_keyboard* keyboard, uint serial, ui timerfd_settime(_glfw.wl.timerfd, 0, &timer, null); } -static void keyboardHandleModifiers(void* data, wl_keyboard* keyboard, uint serial, uint modsDepressed, uint modsLatched, uint modsLocked, uint group) { +private void keyboardHandleModifiers(void* data, wl_keyboard* keyboard, uint serial, uint modsDepressed, uint modsLatched, uint modsLocked, uint group) { xkb_mod_mask_t mask; uint modifiers = 0; @@ -600,7 +600,7 @@ static void keyboardHandleModifiers(void* data, wl_keyboard* keyboard, uint seri } version (WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { - static void keyboardHandleRepeatInfo(void* data, wl_keyboard* keyboard, int rate, int delay) { + private void keyboardHandleRepeatInfo(void* data, wl_keyboard* keyboard, int rate, int delay) { if (keyboard != _glfw.wl.keyboard) return; @@ -608,7 +608,7 @@ version (WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { _glfw.wl.keyboardRepeatDelay = delay; } - static const(wl_keyboard_listener) keyboardListener = wl_keyboard_listener( + private const(wl_keyboard_listener) keyboardListener = wl_keyboard_listener( &keyboardHandleKeymap, &keyboardHandleEnter, &keyboardHandleLeave, @@ -617,7 +617,7 @@ version (WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { &keyboardHandleRepeatInfo, ); } else { - static const(wl_keyboard_listener) keyboardListener = wl_keyboard_listener( + private const(wl_keyboard_listener) keyboardListener = wl_keyboard_listener( &keyboardHandleKeymap, &keyboardHandleEnter, &keyboardHandleLeave, @@ -627,7 +627,7 @@ version (WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { ); } -static void seatHandleCapabilities(void* data, wl_seat* seat, /*enum wl_seat_capability*/ uint caps) { +private void seatHandleCapabilities(void* data, wl_seat* seat, /*enum wl_seat_capability*/ uint caps) { if ((caps & WL_SEAT_CAPABILITY_POINTER) && !_glfw.wl.pointer) { _glfw.wl.pointer = wl_seat_get_pointer(seat); @@ -651,22 +651,22 @@ static void seatHandleCapabilities(void* data, wl_seat* seat, /*enum wl_seat_cap } } -static void seatHandleName(void* data, wl_seat* seat, const(char)* name) { +private void seatHandleName(void* data, wl_seat* seat, const(char)* name) { } -static const(wl_seat_listener) seatListener = wl_seat_listener( +private const(wl_seat_listener) seatListener = wl_seat_listener( &seatHandleCapabilities, &seatHandleName, ); -static void dataOfferHandleOffer(void* data, wl_data_offer* dataOffer, const(char)* mimeType) { +private void dataOfferHandleOffer(void* data, wl_data_offer* dataOffer, const(char)* mimeType) { } -static const(wl_data_offer_listener) dataOfferListener = wl_data_offer_listener( +private const(wl_data_offer_listener) dataOfferListener = wl_data_offer_listener( &dataOfferHandleOffer, ); -static void dataDeviceHandleDataOffer(void* data, wl_data_device* dataDevice, wl_data_offer* id) { +private void dataDeviceHandleDataOffer(void* data, wl_data_device* dataDevice, wl_data_offer* id) { if (_glfw.wl.dataOffer) wl_data_offer_destroy(_glfw.wl.dataOffer); @@ -674,22 +674,22 @@ static void dataDeviceHandleDataOffer(void* data, wl_data_device* dataDevice, wl wl_data_offer_add_listener(_glfw.wl.dataOffer, &dataOfferListener, null); } -static void dataDeviceHandleEnter(void* data, wl_data_device* dataDevice, uint serial, wl_surface* surface, wl_fixed_t x, wl_fixed_t y, wl_data_offer* id) { +private void dataDeviceHandleEnter(void* data, wl_data_device* dataDevice, uint serial, wl_surface* surface, wl_fixed_t x, wl_fixed_t y, wl_data_offer* id) { } -static void dataDeviceHandleLeave(void* data, wl_data_device* dataDevice) { +private void dataDeviceHandleLeave(void* data, wl_data_device* dataDevice) { } -static void dataDeviceHandleMotion(void* data, wl_data_device* dataDevice, uint time, wl_fixed_t x, wl_fixed_t y) { +private void dataDeviceHandleMotion(void* data, wl_data_device* dataDevice, uint time, wl_fixed_t x, wl_fixed_t y) { } -static void dataDeviceHandleDrop(void* data, wl_data_device* dataDevice) { +private void dataDeviceHandleDrop(void* data, wl_data_device* dataDevice) { } -static void dataDeviceHandleSelection(void* data, wl_data_device* dataDevice, wl_data_offer* id) { +private void dataDeviceHandleSelection(void* data, wl_data_device* dataDevice, wl_data_offer* id) { } -static const(wl_data_device_listener) dataDeviceListener = wl_data_device_listener( +private const(wl_data_device_listener) dataDeviceListener = wl_data_device_listener( &dataDeviceHandleDataOffer, &dataDeviceHandleEnter, &dataDeviceHandleLeave, @@ -698,15 +698,15 @@ static const(wl_data_device_listener) dataDeviceListener = wl_data_device_listen &dataDeviceHandleSelection, ); -static void wmBaseHandlePing(void* data, xdg_wm_base* wmBase, uint serial) { +private void wmBaseHandlePing(void* data, xdg_wm_base* wmBase, uint serial) { xdg_wm_base_pong(wmBase, serial); } -static const(xdg_wm_base_listener) wmBaseListener = xdg_wm_base_listener( +private const(xdg_wm_base_listener) wmBaseListener = xdg_wm_base_listener( &wmBaseHandlePing ); -static void registryHandleGlobal(void* data, wl_registry* registry, uint name, const(char)* interface_, uint version_) { +private void registryHandleGlobal(void* data, wl_registry* registry, uint name, const(char)* interface_, uint version_) { if (strcmp(interface_, "wl_compositor") == 0) { _glfw.wl.compositorVersion = min(3, version_); @@ -794,7 +794,7 @@ static void registryHandleGlobal(void* data, wl_registry* registry, uint name, c } } -static void registryHandleGlobalRemove(void* data, wl_registry* registry, uint name) { +private void registryHandleGlobalRemove(void* data, wl_registry* registry, uint name) { int i; _GLFWmonitor* monitor; @@ -810,14 +810,14 @@ static void registryHandleGlobalRemove(void* data, wl_registry* registry, uint n } -static const(wl_registry_listener) registryListener = wl_registry_listener( +private const(wl_registry_listener) registryListener = wl_registry_listener( ®istryHandleGlobal, ®istryHandleGlobalRemove ); // Create key code translation tables // -static void createKeyTables() { +private void createKeyTables() { int scancode; memset(_glfw.wl.keycodes.ptr, -1, typeof(_glfw.wl.keycodes).sizeof); diff --git a/source/glfw3/wl_monitor.d b/source/glfw3/wl_monitor.d index 2f1d090..7f30b5f 100644 --- a/source/glfw3/wl_monitor.d +++ b/source/glfw3/wl_monitor.d @@ -39,7 +39,7 @@ public import core.stdc.errno; public import core.stdc.math; -static void outputHandleGeometry(void* data, wl_output* output, int x, int y, int physicalWidth, int physicalHeight, int subpixel, const(char)* make, const(char)* model, int transform) { +private void outputHandleGeometry(void* data, wl_output* output, int x, int y, int physicalWidth, int physicalHeight, int subpixel, const(char)* make, const(char)* model, int transform) { auto monitor = cast(_GLFWmonitor*) data; char[1024] name; @@ -52,7 +52,7 @@ static void outputHandleGeometry(void* data, wl_output* output, int x, int y, in monitor.name = _glfw_strdup(name.ptr); } -static void outputHandleMode(void* data, wl_output* output, uint flags, int width, int height, int refresh) { +private void outputHandleMode(void* data, wl_output* output, uint flags, int width, int height, int refresh) { auto monitor = cast(_GLFWmonitor*) data; GLFWvidmode mode; @@ -72,19 +72,19 @@ static void outputHandleMode(void* data, wl_output* output, uint flags, int widt monitor.wl.currentMode = monitor.modeCount - 1; } -static void outputHandleDone(void* data, wl_output* output) { +private void outputHandleDone(void* data, wl_output* output) { auto monitor = cast(_GLFWmonitor*) data; _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); } -static void outputHandleScale(void* data, wl_output* output, int factor) { +private void outputHandleScale(void* data, wl_output* output, int factor) { auto monitor = cast(_GLFWmonitor*) data; monitor.wl.scale = factor; } -static const(wl_output_listener) outputListener = wl_output_listener( +private const(wl_output_listener) outputListener = wl_output_listener( &outputHandleGeometry, &outputHandleMode, &outputHandleDone, diff --git a/source/glfw3/wl_window.d b/source/glfw3/wl_window.d index 88b0452..e87ca06 100644 --- a/source/glfw3/wl_window.d +++ b/source/glfw3/wl_window.d @@ -42,11 +42,11 @@ public import core.sys.posix.sys.mman; public import core.sys.linux.timerfd; public import core.sys.posix.poll; -static void shellSurfaceHandlePing(void* data, wl_shell_surface* shellSurface, uint serial) { +private void shellSurfaceHandlePing(void* data, wl_shell_surface* shellSurface, uint serial) { wl_shell_surface_pong(shellSurface, serial); } -static void shellSurfaceHandleConfigure(void* data, wl_shell_surface* shellSurface, uint edges, int width, int height) { +private void shellSurfaceHandleConfigure(void* data, wl_shell_surface* shellSurface, uint edges, int width, int height) { auto window = cast(_GLFWwindow*) data; float aspectRatio; float targetRatio; @@ -89,16 +89,16 @@ static void shellSurfaceHandleConfigure(void* data, wl_shell_surface* shellSurfa _glfwInputWindowDamage(window); } -static void shellSurfaceHandlePopupDone(void* data, wl_shell_surface* shellSurface) { +private void shellSurfaceHandlePopupDone(void* data, wl_shell_surface* shellSurface) { } -static const(wl_shell_surface_listener) shellSurfaceListener = wl_shell_surface_listener( +private const(wl_shell_surface_listener) shellSurfaceListener = wl_shell_surface_listener( &shellSurfaceHandlePing, &shellSurfaceHandleConfigure, &shellSurfaceHandlePopupDone ); -static int createTmpfileCloexec(char* tmpname) { +private int createTmpfileCloexec(char* tmpname) { int fd; fd = mkostemp(tmpname, O_CLOEXEC); @@ -128,8 +128,8 @@ static int createTmpfileCloexec(char* tmpname) { * is set to ENOSPC. If posix_fallocate() is not supported, program may * receive SIGBUS on accessing mmap()'ed file contents instead. */ -static int createAnonymousFile(off_t size) { - static const(char)* template_ = "/glfw-shared-XXXXXX"; +private int createAnonymousFile(off_t size) { + private const(char)* template_ = "/glfw-shared-XXXXXX"; const(char)* path; char* name; int fd; @@ -197,7 +197,7 @@ version (SHM_ANON) { return fd; } -static wl_buffer* createShmBuffer(const(GLFWimage)* image) { +private wl_buffer* createShmBuffer(const(GLFWimage)* image) { wl_shm_pool* pool; wl_buffer* buffer; int stride = image.width * 4; @@ -249,7 +249,7 @@ static wl_buffer* createShmBuffer(const(GLFWimage)* image) { return buffer; } -static void createDecoration(_GLFWdecorationWayland* decoration, wl_surface* parent, wl_buffer* buffer, GLFWbool opaque, int x, int y, int width, int height) { +private void createDecoration(_GLFWdecorationWayland* decoration, wl_surface* parent, wl_buffer* buffer, GLFWbool opaque, int x, int y, int width, int height) { wl_region* region; decoration.surface = wl_compositor_create_surface(_glfw.wl.compositor); @@ -274,7 +274,7 @@ static void createDecoration(_GLFWdecorationWayland* decoration, wl_surface* par wl_surface_commit(decoration.surface); } -static void createDecorations(_GLFWwindow* window) { +private void createDecorations(_GLFWwindow* window) { ubyte[4] data = [ 224, 224, 224, 255 ]; const(GLFWimage) image = GLFWimage( 1, 1, data.ptr ); GLFWbool opaque = (data[3] == 255); @@ -305,7 +305,7 @@ static void createDecorations(_GLFWwindow* window) { window.wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH); } -static void destroyDecoration(_GLFWdecorationWayland* decoration) { +private void destroyDecoration(_GLFWdecorationWayland* decoration) { if (decoration.surface) wl_surface_destroy(decoration.surface); if (decoration.subsurface) @@ -317,14 +317,14 @@ static void destroyDecoration(_GLFWdecorationWayland* decoration) { decoration.viewport = null; } -static void destroyDecorations(_GLFWwindow* window) { +private void destroyDecorations(_GLFWwindow* window) { destroyDecoration(&window.wl.decorations.top); destroyDecoration(&window.wl.decorations.left); destroyDecoration(&window.wl.decorations.right); destroyDecoration(&window.wl.decorations.bottom); } -static void xdgDecorationHandleConfigure(void* data, zxdg_toplevel_decoration_v1* decoration, uint mode) { +private void xdgDecorationHandleConfigure(void* data, zxdg_toplevel_decoration_v1* decoration, uint mode) { _GLFWwindow* window = data; window.wl.decorations.serverSide = (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); @@ -333,12 +333,12 @@ static void xdgDecorationHandleConfigure(void* data, zxdg_toplevel_decoration_v1 createDecorations(window); } -static const(zxdg_toplevel_decoration_v1_listener) xdgDecorationListener = zxdg_toplevel_decoration_v1_listener( +private const(zxdg_toplevel_decoration_v1_listener) xdgDecorationListener = zxdg_toplevel_decoration_v1_listener( &xdgDecorationHandleConfigure, ); // Makes the surface considered as XRGB instead of ARGB. -static void setOpaqueRegion(_GLFWwindow* window) { +private void setOpaqueRegion(_GLFWwindow* window) { wl_region* region; region = wl_compositor_create_region(_glfw.wl.compositor); @@ -352,7 +352,7 @@ static void setOpaqueRegion(_GLFWwindow* window) { } -static void resizeWindow(_GLFWwindow* window) { +private void resizeWindow(_GLFWwindow* window) { int scale = window.wl.scale; int scaledWidth = window.wl.width * scale; int scaledHeight = window.wl.height * scale; @@ -390,7 +390,7 @@ static void resizeWindow(_GLFWwindow* window) { wl_surface_commit(window.wl.decorations.bottom.surface); } -static void checkScaleChange(_GLFWwindow* window) { +private void checkScaleChange(_GLFWwindow* window) { int scale = 1; int i; int monitorScale; @@ -416,7 +416,7 @@ static void checkScaleChange(_GLFWwindow* window) { } } -static void surfaceHandleEnter(void* data, wl_surface* surface, wl_output* output) { +private void surfaceHandleEnter(void* data, wl_surface* surface, wl_output* output) { _GLFWwindow* window = data; _GLFWmonitor* monitor = wl_output_get_user_data(output); @@ -433,7 +433,7 @@ static void surfaceHandleEnter(void* data, wl_surface* surface, wl_output* outpu checkScaleChange(window); } -static void surfaceHandleLeave(void* data, wl_surface* surface, wl_output* output) { +private void surfaceHandleLeave(void* data, wl_surface* surface, wl_output* output) { _GLFWwindow* window = data; _GLFWmonitor* monitor = wl_output_get_user_data(output); GLFWbool found; @@ -451,12 +451,12 @@ static void surfaceHandleLeave(void* data, wl_surface* surface, wl_output* outpu checkScaleChange(window); } -static const(wl_surface_listener) surfaceListener = wl_surface_listener( +private const(wl_surface_listener) surfaceListener = wl_surface_listener( &surfaceHandleEnter, &surfaceHandleLeave ); -static void setIdleInhibitor(_GLFWwindow* window, GLFWbool enable) { +private void setIdleInhibitor(_GLFWwindow* window, GLFWbool enable) { if (enable && !window.wl.idleInhibitor && _glfw.wl.idleInhibitManager) { window.wl.idleInhibitor = @@ -473,7 +473,7 @@ static void setIdleInhibitor(_GLFWwindow* window, GLFWbool enable) { } } -static GLFWbool createSurface(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig) { +private GLFWbool createSurface(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig) { window.wl.surface = wl_compositor_create_surface(_glfw.wl.compositor); if (!window.wl.surface) return GLFW_FALSE; @@ -500,7 +500,7 @@ static GLFWbool createSurface(_GLFWwindow* window, const(_GLFWwndconfig)* wndcon return GLFW_TRUE; } -static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor, int refreshRate) { +private void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor, int refreshRate) { if (window.wl.xdg.toplevel) { xdg_toplevel_set_fullscreen( @@ -520,7 +520,7 @@ static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor, int refres destroyDecorations(window); } -static GLFWbool createShellSurface(_GLFWwindow* window) { +private GLFWbool createShellSurface(_GLFWwindow* window) { if (!_glfw.wl.shell) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -566,7 +566,7 @@ static GLFWbool createShellSurface(_GLFWwindow* window) { return GLFW_TRUE; } -static void xdgToplevelHandleConfigure(void* data, xdg_toplevel* toplevel, int width, int height, wl_array* states) { +private void xdgToplevelHandleConfigure(void* data, xdg_toplevel* toplevel, int width, int height, wl_array* states) { _GLFWwindow* window = cast(_GLFWwindow*) data; float aspectRatio; float targetRatio; @@ -626,25 +626,25 @@ static void xdgToplevelHandleConfigure(void* data, xdg_toplevel* toplevel, int w _glfwInputWindowFocus(window, activated); } -static void xdgToplevelHandleClose(void* data, xdg_toplevel* toplevel) { +private void xdgToplevelHandleClose(void* data, xdg_toplevel* toplevel) { _GLFWwindow* window = data; _glfwInputWindowCloseRequest(window); } -static const(xdg_toplevel_listener) xdgToplevelListener = xdg_toplevel_listener( +private const(xdg_toplevel_listener) xdgToplevelListener = xdg_toplevel_listener( &xdgToplevelHandleConfigure, &xdgToplevelHandleClose ); -static void xdgSurfaceHandleConfigure(void* data, xdg_surface* surface, uint serial) { +private void xdgSurfaceHandleConfigure(void* data, xdg_surface* surface, uint serial) { xdg_surface_ack_configure(surface, serial); } -static const(xdg_surface_listener) xdgSurfaceListener = xdg_surface_listener( +private const(xdg_surface_listener) xdgSurfaceListener = xdg_surface_listener( &xdgSurfaceHandleConfigure ); -static void setXdgDecorations(_GLFWwindow* window) { +private void setXdgDecorations(_GLFWwindow* window) { if (_glfw.wl.decorationManager) { window.wl.xdg.decoration = @@ -664,7 +664,7 @@ static void setXdgDecorations(_GLFWwindow* window) { } } -static GLFWbool createXdgSurface(_GLFWwindow* window) { +private GLFWbool createXdgSurface(_GLFWwindow* window) { window.wl.xdg.surface = xdg_wm_base_get_xdg_surface(_glfw.wl.wmBase, window.wl.surface); if (!window.wl.xdg.surface) @@ -724,7 +724,7 @@ static GLFWbool createXdgSurface(_GLFWwindow* window) { return GLFW_TRUE; } -static void setCursorImage(_GLFWwindow* window, _GLFWcursorWayland* cursorWayland) { +private void setCursorImage(_GLFWwindow* window, _GLFWcursorWayland* cursorWayland) { itimerspec timer = {}; wl_cursor* wlCursor = cursorWayland.cursor; wl_cursor_image* image; @@ -768,7 +768,7 @@ static void setCursorImage(_GLFWwindow* window, _GLFWcursorWayland* cursorWaylan wl_surface_commit(surface); } -static void incrementCursorImage(_GLFWwindow* window) { +private void incrementCursorImage(_GLFWwindow* window) { _GLFWcursor* cursor; if (!window || window.wl.decorations.focus != mainWindow) @@ -783,7 +783,7 @@ static void incrementCursorImage(_GLFWwindow* window) { } } -static void handleEvents(int timeout) { +private void handleEvents(int timeout) { wl_display* display = _glfw.wl.display; pollfd* fds = [ [ wl_display_get_fd(display), POLLIN ], @@ -1262,7 +1262,7 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) *ypos = window.wl.cursorPosY; } -static GLFWbool isPointerLocked(_GLFWwindow* window); +private GLFWbool isPointerLocked(_GLFWwindow* window); void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) { if (isPointerLocked(window)) @@ -1334,7 +1334,7 @@ void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) { wl_buffer_destroy(cursor.wl.buffer); } -static void relativePointerHandleRelativeMotion(void* data, zwp_relative_pointer_v1* pointer, uint timeHi, uint timeLo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dxUnaccel, wl_fixed_t dyUnaccel) { +private void relativePointerHandleRelativeMotion(void* data, zwp_relative_pointer_v1* pointer, uint timeHi, uint timeLo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dxUnaccel, wl_fixed_t dyUnaccel) { _GLFWwindow* window = data; double xpos = window.virtualCursorPosX; double ypos = window.virtualCursorPosY; @@ -1356,14 +1356,14 @@ static void relativePointerHandleRelativeMotion(void* data, zwp_relative_pointer _glfwInputCursorPos(window, xpos, ypos); } -static const(zwp_relative_pointer_v1_listener) relativePointerListener = zwp_relative_pointer_v1_listener( +private const(zwp_relative_pointer_v1_listener) relativePointerListener = zwp_relative_pointer_v1_listener( &relativePointerHandleRelativeMotion ); -static void lockedPointerHandleLocked(void* data, zwp_locked_pointer_v1* lockedPointer) { +private void lockedPointerHandleLocked(void* data, zwp_locked_pointer_v1* lockedPointer) { } -static void unlockPointer(_GLFWwindow* window) { +private void unlockPointer(_GLFWwindow* window) { zwp_relative_pointer_v1* relativePointer = window.wl.pointerLock.relativePointer; zwp_locked_pointer_v1* lockedPointer = window.wl.pointerLock.lockedPointer; @@ -1374,17 +1374,17 @@ static void unlockPointer(_GLFWwindow* window) { window.wl.pointerLock.lockedPointer = null; } -static void lockPointer(_GLFWwindow* window); +private void lockPointer(_GLFWwindow* window); -static void lockedPointerHandleUnlocked(void* data, zwp_locked_pointer_v1* lockedPointer) { +private void lockedPointerHandleUnlocked(void* data, zwp_locked_pointer_v1* lockedPointer) { } -static const(zwp_locked_pointer_v1_listener) lockedPointerListener = zwp_locked_pointer_v1_listener( +private const(zwp_locked_pointer_v1_listener) lockedPointerListener = zwp_locked_pointer_v1_listener( &lockedPointerHandleLocked, &lockedPointerHandleUnlocked ); -static void lockPointer(_GLFWwindow* window) { +private void lockPointer(_GLFWwindow* window) { zwp_relative_pointer_v1* relativePointer; zwp_locked_pointer_v1* lockedPointer; @@ -1421,7 +1421,7 @@ static void lockPointer(_GLFWwindow* window) { null, 0, 0); } -static GLFWbool isPointerLocked(_GLFWwindow* window) { +private GLFWbool isPointerLocked(_GLFWwindow* window) { return window.wl.pointerLock.lockedPointer != null; } @@ -1483,7 +1483,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) { } } -static void dataSourceHandleTarget(void* data, wl_data_source* dataSource, const(char)* mimeType) { +private void dataSourceHandleTarget(void* data, wl_data_source* dataSource, const(char)* mimeType) { if (_glfw.wl.dataSource != dataSource) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -1492,7 +1492,7 @@ static void dataSourceHandleTarget(void* data, wl_data_source* dataSource, const } } -static void dataSourceHandleSend(void* data, wl_data_source* dataSource, const(char)* mimeType, int fd) { +private void dataSourceHandleSend(void* data, wl_data_source* dataSource, const(char)* mimeType, int fd) { const(char)* string = _glfw.wl.clipboardSendString; size_t len = _glfw.wl.clipboardSendSize; int ret; @@ -1537,7 +1537,7 @@ static void dataSourceHandleSend(void* data, wl_data_source* dataSource, const(c close(fd); } -static void dataSourceHandleCancelled(void* data, wl_data_source* dataSource) { +private void dataSourceHandleCancelled(void* data, wl_data_source* dataSource) { wl_data_source_destroy(dataSource); if (_glfw.wl.dataSource != dataSource) @@ -1550,7 +1550,7 @@ static void dataSourceHandleCancelled(void* data, wl_data_source* dataSource) { _glfw.wl.dataSource = null; } -static const(wl_data_source_listener) dataSourceListener = wl_data_source_listener( +private const(wl_data_source_listener) dataSourceListener = wl_data_source_listener( &dataSourceHandleTarget, &dataSourceHandleSend, &dataSourceHandleCancelled, @@ -1595,7 +1595,7 @@ void _glfwPlatformSetClipboardString(const(char)* string) { _glfw.wl.serial); } -static GLFWbool growClipboardString() { +private GLFWbool growClipboardString() { char* clipboard = _glfw.wl.clipboardString; clipboard = realloc(clipboard, _glfw.wl.clipboardSize * 2); diff --git a/source/glfw3/x11_init.d b/source/glfw3/x11_init.d index 6af799a..7f0f6e0 100644 --- a/source/glfw3/x11_init.d +++ b/source/glfw3/x11_init.d @@ -49,7 +49,7 @@ import core.stdc.config: c_long, c_ulong; // Translate an X11 key code to a GLFW key code. // -static int translateKeyCode(int scancode) { +private int translateKeyCode(int scancode) { int keySym; // Valid key code range is [8,255], according to the Xlib manual @@ -336,7 +336,7 @@ private extern(D) void createKeyTables() { // Check whether the IM has a usable style // -static GLFWbool hasUsableInputMethodStyle() { +private GLFWbool hasUsableInputMethodStyle() { GLFWbool found = GLFW_FALSE; XIMStyles* styles = null; @@ -358,7 +358,7 @@ static GLFWbool hasUsableInputMethodStyle() { // Check whether the specified atom is supported // -static Atom getSupportedAtom(Atom* supportedAtoms, c_ulong atomCount, const(char)* atomName) { +private Atom getSupportedAtom(Atom* supportedAtoms, c_ulong atomCount, const(char)* atomName) { const(Atom) atom = XInternAtom(_glfw.x11.display, atomName, False); for (uint i = 0; i < atomCount; i++) @@ -461,7 +461,7 @@ private extern(D) void detectEWMH() { // Look for and initialize supported X11 extensions // -static GLFWbool initExtensions() { +private GLFWbool initExtensions() { _glfw.x11.vidmode.handle = _glfw_dlopen("libXxf86vm.so.1"); if (_glfw.x11.vidmode.handle) { @@ -825,7 +825,7 @@ private extern(D) void getSystemContentScale(float* xscale, float* yscale) { // Create a blank cursor for hidden and disabled cursor modes // -static Cursor createHiddenCursor() { +private Cursor createHiddenCursor() { ubyte[16 * 16 * 4] pixels = 0; GLFWimage image = GLFWimage(16, 16, pixels.ptr); return _glfwCreateCursorX11(&image, 0, 0); @@ -833,7 +833,7 @@ static Cursor createHiddenCursor() { // Create a helper window for IPC // -static Window createHelperWindow() { +private Window createHelperWindow() { XSetWindowAttributes wa; wa.event_mask = PropertyChangeMask; @@ -846,7 +846,7 @@ static Window createHelperWindow() { // X error handler // -static int errorHandler(Display* display, XErrorEvent* event) { +private int errorHandler(Display* display, XErrorEvent* event) { _glfw.x11.errorCode = event.error_code; return 0; } diff --git a/source/glfw3/x11_monitor.d b/source/glfw3/x11_monitor.d index a30bd51..9f1df88 100644 --- a/source/glfw3/x11_monitor.d +++ b/source/glfw3/x11_monitor.d @@ -41,13 +41,13 @@ import core.stdc.config: c_long, c_ulong; // Check whether the display mode should be included in enumeration // -static GLFWbool modeIsGood(const(XRRModeInfo)* mi) { +private GLFWbool modeIsGood(const(XRRModeInfo)* mi) { return (mi.modeFlags & RR_Interlace) == 0; } // Calculates the refresh rate, in Hz, from the specified RandR mode info // -static int calculateRefreshRate(const(XRRModeInfo)* mi) { +private int calculateRefreshRate(const(XRRModeInfo)* mi) { if (mi.hTotal && mi.vTotal) return cast(int) round(cast(double) mi.dotClock / (cast(double) mi.hTotal * cast(double) mi.vTotal)); else @@ -56,7 +56,7 @@ static int calculateRefreshRate(const(XRRModeInfo)* mi) { // Returns the mode info for a RandR mode XID // -static const(XRRModeInfo)* getModeInfo(const(XRRScreenResources)* sr, RRMode id) { +private const(XRRModeInfo)* getModeInfo(const(XRRScreenResources)* sr, RRMode id) { for (int i = 0; i < sr.nmode; i++) { if (sr.modes[i].id == id) @@ -68,7 +68,7 @@ static const(XRRModeInfo)* getModeInfo(const(XRRScreenResources)* sr, RRMode id) // Convert RandR mode info to GLFW video mode // -static GLFWvidmode vidmodeFromModeInfo(const(XRRModeInfo)* mi, const(XRRCrtcInfo)* ci) { +private GLFWvidmode vidmodeFromModeInfo(const(XRRModeInfo)* mi, const(XRRCrtcInfo)* ci) { GLFWvidmode mode; if (ci.rotation == RR_Rotate_90 || ci.rotation == RR_Rotate_270) diff --git a/source/glfw3/x11_window.d b/source/glfw3/x11_window.d index c25aeb3..eeaa4da 100644 --- a/source/glfw3/x11_window.d +++ b/source/glfw3/x11_window.d @@ -72,7 +72,7 @@ enum _GLFW_XDND_VERSION = 5; // This avoids blocking other threads via the per-display Xlib lock that also // covers GLX functions // -static GLFWbool waitForEvent(double* timeout) { +private GLFWbool waitForEvent(double* timeout) { fd_set fds; const(int) fd = ConnectionNumber(_glfw.x11.display); int count = fd + 1; @@ -116,7 +116,7 @@ version (linux) { // Waits until a VisibilityNotify event arrives for the specified window or the // timeout period elapses (ICCCM section 4.2.2) // -static GLFWbool waitForVisibilityNotify(_GLFWwindow* window) { +private GLFWbool waitForVisibilityNotify(_GLFWwindow* window) { XEvent dummy; double timeout = 0.1; @@ -134,7 +134,7 @@ static GLFWbool waitForVisibilityNotify(_GLFWwindow* window) { // Returns whether the window is iconified // -static int getWindowState(_GLFWwindow* window) { +private int getWindowState(_GLFWwindow* window) { int result = WithdrawnState; struct _State { CARD32 state; @@ -157,7 +157,7 @@ static int getWindowState(_GLFWwindow* window) { // Returns whether the event is a selection event // -static Bool isSelectionEvent(Display* display, XEvent* event, XPointer pointer) { +private Bool isSelectionEvent(Display* display, XEvent* event, XPointer pointer) { if (event.xany.window != _glfw.x11.helperWindowHandle) return False; @@ -168,7 +168,7 @@ static Bool isSelectionEvent(Display* display, XEvent* event, XPointer pointer) // Returns whether it is a _NET_FRAME_EXTENTS event for the specified window // -static Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointer) { +private Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointer) { _GLFWwindow* window = cast(_GLFWwindow*) pointer; return event.type == PropertyNotify && event.xproperty.state == PropertyNewValue && @@ -178,7 +178,7 @@ static Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointe // Returns whether it is a property event for the specified selection transfer // -static Bool isSelPropNewValueNotify(Display* display, XEvent* event, XPointer pointer) { +private Bool isSelPropNewValueNotify(Display* display, XEvent* event, XPointer pointer) { XEvent* notification = cast(XEvent*) pointer; return event.type == PropertyNotify && event.xproperty.state == PropertyNewValue && @@ -188,7 +188,7 @@ static Bool isSelPropNewValueNotify(Display* display, XEvent* event, XPointer po // Translates an X event modifier state mask // -static int translateState(int state) { +private int translateState(int state) { int mods = 0; if (state & ShiftMask) @@ -209,7 +209,7 @@ static int translateState(int state) { // Translates an X11 key code to a GLFW key token // -static int translateKey(int scancode) { +private int translateKey(int scancode) { // Use the pre-filled LUT (see createKeyTables() in x11_init.c) if (scancode < 0 || scancode > 255) return GLFW_KEY_UNKNOWN; @@ -380,7 +380,7 @@ private extern(D) void updateWindowMode(_GLFWwindow* window) { // Splits and translates a text/uri-list into separate file paths // NOTE: This function destroys the provided string // -static char** parseUriList(char* text, int* count) { +private char** parseUriList(char* text, int* count) { const(char)* prefix = "file://"; char** paths = null; char* line; @@ -433,7 +433,7 @@ static char** parseUriList(char* text, int* count) { // Encode a Unicode code point to a UTF-8 stream // Based on cutef8 by Jeff Bezanson (Public Domain) // -static size_t encodeUTF8(char* s, uint ch) { +private size_t encodeUTF8(char* s, uint ch) { size_t count = 0; if (ch < 0x80) @@ -464,7 +464,7 @@ static size_t encodeUTF8(char* s, uint ch) { // Based on cutef8 by Jeff Bezanson (Public Domain) // version (X_HAVE_UTF8_STRING) { -static uint decodeUTF8(const(char)** s) { +private uint decodeUTF8(const(char)** s) { uint ch = 0;uint count = 0; static const(uint)* offsets = [ 0x00000000u, 0x00003080u, 0x000e2080u, @@ -485,7 +485,7 @@ static uint decodeUTF8(const(char)** s) { // Convert the specified Latin-1 string to UTF-8 // -static char* convertLatin1toUTF8(const(char)* source) { +private char* convertLatin1toUTF8(const(char)* source) { size_t size = 1; const(char)* sp; @@ -585,7 +585,7 @@ private extern(D) void enableCursor(_GLFWwindow* window) { // Create the X11 window (and its colormap) // -static GLFWbool createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig, Visual* visual, int depth) { +private GLFWbool createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* wndconfig, Visual* visual, int depth) { int width = wndconfig.width; int height = wndconfig.height; @@ -786,7 +786,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, const(_GLFWwndconfig)* w // Set the specified property to the selection converted to the requested target // -static Atom writeTargetToProperty(const(XSelectionRequestEvent)* request) { +private Atom writeTargetToProperty(const(XSelectionRequestEvent)* request) { char* selectionString = null; const(Atom)[2] formats = [ _glfw.x11.UTF8_STRING, XA_STRING ]; const(int) formatCount = formats.length; //sizeof / typeof(formats[0]).sizeof; @@ -945,7 +945,7 @@ private extern(D) void handleSelectionRequest(XEvent* event) { XSendEvent(_glfw.x11.display, request.requestor, False, 0, &reply); } -static const(char)* getSelectionString(Atom selection) { +private const(char)* getSelectionString(Atom selection) { char** selectionString = null; const(Atom)[2] targets = [ _glfw.x11.UTF8_STRING, XA_STRING ]; const(size_t) targetCount = targets.length; //targets.sizeof / typeof(targets[0]).sizeof; From 0ed7c9fc76bb1fced8d231a12d691031a19e5f7d Mon Sep 17 00:00:00 2001 From: dkorpel Date: Fri, 26 Mar 2021 12:43:29 +0100 Subject: [PATCH 09/17] reduce amout of public imports --- examples/empty-window/app.d | 2 +- source/glfw3/wgl_context.d | 2 +- source/glfw3/win32_init.d | 14 +++++++------- source/glfw3/win32_joystick.d | 2 +- source/glfw3/win32_monitor.d | 2 +- source/glfw3/win32_platform.d | 3 ++- source/glfw3/win32_thread.d | 2 +- source/glfw3/win32_time.d | 2 +- source/glfw3/win32_window.d | 6 ++---- 9 files changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/empty-window/app.d b/examples/empty-window/app.d index 5bd18ef..697fc24 100644 --- a/examples/empty-window/app.d +++ b/examples/empty-window/app.d @@ -118,7 +118,7 @@ void printMonitorState() { printf(" current video mode: %dx%d %dHz r%dg%db%d\n", mode.width, mode.height, mode.refreshRate, mode.redBits, mode.greenBits, mode.blueBits); printf(" position: %d, %d\n", xpos, ypos); glfwGetMonitorWorkarea(mt, &xpos, &ypos, &width, &height); - printf(" work area: %d, %d to %d, %d\n", xpos, ypos, width, height); + printf(" work area: (%d, %d), size (%d, %d)\n", xpos, ypos, width, height); } } diff --git a/source/glfw3/wgl_context.d b/source/glfw3/wgl_context.d index e4c21b9..896a2d0 100644 --- a/source/glfw3/wgl_context.d +++ b/source/glfw3/wgl_context.d @@ -31,7 +31,7 @@ extern(C): @nogc: nothrow: __gshared: // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; import core.stdc.string: memset; // header diff --git a/source/glfw3/win32_init.d b/source/glfw3/win32_init.d index 3f57d7b..28f1d4c 100644 --- a/source/glfw3/win32_init.d +++ b/source/glfw3/win32_init.d @@ -3,9 +3,6 @@ module glfw3.win32_init; extern(C): @nogc: nothrow: __gshared: -private template HasVersion(string versionId) { - mixin("version("~versionId~") {enum HasVersion = true;} else {enum HasVersion = false;}"); -} //======================================================================== // GLFW 3.3 Win32 - www.glfw.org //------------------------------------------------------------------------ @@ -35,7 +32,7 @@ private template HasVersion(string versionId) { // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; import core.stdc.stdlib; import core.stdc.string; @@ -44,7 +41,10 @@ private const(GUID) _glfw_GUID_DEVINTERFACE_HID = GUID(0x4d1e55b2,0xf16f,0x11cf, enum GUID_DEVINTERFACE_HID = _glfw_GUID_DEVINTERFACE_HID; -static if (HasVersion!"_GLFW_USE_HYBRID_HPG" || HasVersion!"_GLFW_USE_OPTIMUS_HPG") { +version(_GLFW_USE_HYBRID_HPG) version = _GLFW_USE_HPG; +version(_GLFW_USE_OPTIMUS_HPG) version = _GLFW_USE_HPG; + +version(_GLFW_USE_HPG) { // Executables (but not DLLs) exporting this symbol with this value will be // automatically directed to the high-performance GPU on Nvidia Optimus systems @@ -58,7 +58,7 @@ DWORD NvOptimusEnablement = 1; // int AmdPowerXpressRequestHighPerformance = 1; -} // _GLFW_USE_HYBRID_HPG +} version (_GLFW_BUILD_DLL) { @@ -68,7 +68,7 @@ extern(Windows) BOOL DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) return TRUE; } -} // _GLFW_BUILD_DLL +} // Load necessary libraries (DLLs) // diff --git a/source/glfw3/win32_joystick.d b/source/glfw3/win32_joystick.d index bbabb88..72beaa5 100644 --- a/source/glfw3/win32_joystick.d +++ b/source/glfw3/win32_joystick.d @@ -31,7 +31,7 @@ extern(C): @nogc: nothrow: __gshared: // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; import core.stdc.stdlib; // free import core.stdc.string; // memset diff --git a/source/glfw3/win32_monitor.d b/source/glfw3/win32_monitor.d index 63f86a6..70a9605 100644 --- a/source/glfw3/win32_monitor.d +++ b/source/glfw3/win32_monitor.d @@ -31,7 +31,7 @@ extern(C): @nogc: nothrow: __gshared: // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; import core.stdc.stdlib; import core.stdc.string; diff --git a/source/glfw3/win32_platform.d b/source/glfw3/win32_platform.d index c5b5eeb..51da1e6 100644 --- a/source/glfw3/win32_platform.d +++ b/source/glfw3/win32_platform.d @@ -103,7 +103,7 @@ version (all) { enum DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = cast(HANDLE) -4; // HACK: Define versionhelpers.h functions manually as MinGW lacks the header -private { +package { enum _WIN32_WINNT_WINXP = 0x0501; enum _WIN32_WINNT_VISTA = 0x0600; enum _WIN32_WINNT_WIN7 = 0x0601; @@ -224,6 +224,7 @@ struct VkWin32SurfaceCreateInfoKHR { alias PFN_vkCreateWin32SurfaceKHR = VkResult function(VkInstance, const(VkWin32SurfaceCreateInfoKHR)*, const(VkAllocationCallbacks)*, VkSurfaceKHR*); alias PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR = VkBool32 function(VkPhysicalDevice, uint32_t); +import glfw3.internal; public import glfw3.win32_joystick; public import glfw3.wgl_context; public import glfw3.egl_context; diff --git a/source/glfw3/win32_thread.d b/source/glfw3/win32_thread.d index 764e52e..483d316 100644 --- a/source/glfw3/win32_thread.d +++ b/source/glfw3/win32_thread.d @@ -31,7 +31,7 @@ extern(C): @nogc: nothrow: __gshared: // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; import core.stdc.assert_; import core.stdc.string: memset; diff --git a/source/glfw3/win32_time.d b/source/glfw3/win32_time.d index fd5c5ca..fa94e37 100644 --- a/source/glfw3/win32_time.d +++ b/source/glfw3/win32_time.d @@ -31,7 +31,7 @@ extern(C): @nogc: nothrow: __gshared: // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; ////////////////////////////////////////////////////////////////////////// diff --git a/source/glfw3/win32_window.d b/source/glfw3/win32_window.d index 1503114..3fdb917 100644 --- a/source/glfw3/win32_window.d +++ b/source/glfw3/win32_window.d @@ -33,16 +33,14 @@ extern(C): __gshared: // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== -public import glfw3.internal; +import glfw3.internal; -public import glfw3.win32_platform: IsWindowsVistaOrGreater, IsWindowsXPOrGreater, IsWindows7OrGreater; +import glfw3.win32_platform: IsWindowsVistaOrGreater, IsWindowsXPOrGreater, IsWindows7OrGreater; import core.stdc.limits; import core.stdc.stdlib; import core.stdc.string; import core.sys.windows.windows; -//public import windowsx; -//public import shellapi; // Returns the window style for the specified window // From 51fa3fe4b473f442ff511e1d3ecd33cac6ca9ba3 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Fri, 26 Mar 2021 12:48:02 +0100 Subject: [PATCH 10/17] reduce visibility of symbols in win32 modules --- source/glfw3/win32_init.d | 2 ++ source/glfw3/win32_joystick.d | 2 ++ source/glfw3/win32_monitor.d | 2 ++ source/glfw3/win32_platform.d | 2 ++ source/glfw3/win32_thread.d | 1 + source/glfw3/win32_time.d | 2 +- source/glfw3/win32_window.d | 1 + source/glfw3/window.d | 1 + 8 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/glfw3/win32_init.d b/source/glfw3/win32_init.d index 28f1d4c..79978a1 100644 --- a/source/glfw3/win32_init.d +++ b/source/glfw3/win32_init.d @@ -39,6 +39,8 @@ import core.stdc.string; private const(GUID) _glfw_GUID_DEVINTERFACE_HID = GUID(0x4d1e55b2,0xf16f,0x11cf,[0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30]); +package: + enum GUID_DEVINTERFACE_HID = _glfw_GUID_DEVINTERFACE_HID; version(_GLFW_USE_HYBRID_HPG) version = _GLFW_USE_HPG; diff --git a/source/glfw3/win32_joystick.d b/source/glfw3/win32_joystick.d index 72beaa5..0fe4091 100644 --- a/source/glfw3/win32_joystick.d +++ b/source/glfw3/win32_joystick.d @@ -35,6 +35,8 @@ import glfw3.internal; import core.stdc.stdlib; // free import core.stdc.string; // memset +package: + // header mixin template _GLFW_PLATFORM_JOYSTICK_STATE() {_GLFWjoystickWin32 win32;} mixin template _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE() {int dummyLibraryJoystick;} diff --git a/source/glfw3/win32_monitor.d b/source/glfw3/win32_monitor.d index 70a9605..9bd266b 100644 --- a/source/glfw3/win32_monitor.d +++ b/source/glfw3/win32_monitor.d @@ -38,6 +38,8 @@ import core.stdc.string; import core.stdc.limits; import core.stdc.wchar_; +package: + // Callback for EnumDisplayMonitors in createMonitor // extern(Windows) private BOOL monitorCallback(HMONITOR handle, HDC dc, RECT* rect, LPARAM data) { diff --git a/source/glfw3/win32_platform.d b/source/glfw3/win32_platform.d index 51da1e6..a0beaf7 100644 --- a/source/glfw3/win32_platform.d +++ b/source/glfw3/win32_platform.d @@ -40,6 +40,8 @@ public import glfw3.xinput; public import core.sys.windows.objbase; // GUID public import core.sys.windows.dbt; +package: + // TODO: make this @nogc nothrow upstream @nogc nothrow extern (Windows) ULONGLONG VerSetConditionMask(ULONGLONG, DWORD, BYTE); diff --git a/source/glfw3/win32_thread.d b/source/glfw3/win32_thread.d index 483d316..83fb914 100644 --- a/source/glfw3/win32_thread.d +++ b/source/glfw3/win32_thread.d @@ -35,6 +35,7 @@ import glfw3.internal; import core.stdc.assert_; import core.stdc.string: memset; +package: ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// diff --git a/source/glfw3/win32_time.d b/source/glfw3/win32_time.d index fa94e37..91f651f 100644 --- a/source/glfw3/win32_time.d +++ b/source/glfw3/win32_time.d @@ -32,7 +32,7 @@ extern(C): @nogc: nothrow: __gshared: //======================================================================== import glfw3.internal; - +package: ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// diff --git a/source/glfw3/win32_window.d b/source/glfw3/win32_window.d index 3fdb917..2e909d4 100644 --- a/source/glfw3/win32_window.d +++ b/source/glfw3/win32_window.d @@ -41,6 +41,7 @@ import core.stdc.limits; import core.stdc.stdlib; import core.stdc.string; import core.sys.windows.windows; +package: // Returns the window style for the specified window // diff --git a/source/glfw3/window.d b/source/glfw3/window.d index b5faddf..ad4732d 100644 --- a/source/glfw3/window.d +++ b/source/glfw3/window.d @@ -37,6 +37,7 @@ import glfw3.internal; import core.stdc.assert_; import core.stdc.string; import core.stdc.stdlib; +package: ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// From 5ba01c90342b6296c60d7182502b2e672efbcadb Mon Sep 17 00:00:00 2001 From: dkorpel Date: Fri, 26 Mar 2021 15:07:50 +0100 Subject: [PATCH 11/17] remove redundant preview switches --- dub.sdl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dub.sdl b/dub.sdl index c4086c7..8095130 100644 --- a/dub.sdl +++ b/dub.sdl @@ -11,12 +11,10 @@ subPackage "examples/empty-window" subPackage "examples/triangle-gl" //subPackage "examples/triangle-vulkan" -dflags "-preview=dip1000" "-preview=dip25" +dflags "-preview=dip1000" dflags "-preview=fieldwise" -dflags "-preview=markdown" dflags "-preview=fixAliasThis" dflags "-preview=intpromote" -dflags "-preview=dtorfields" dflags "-mixin=build/mixin.d" sourcePaths // by default dub includes everything in source/, which we don't want here From 3131471f0810fe40bc42821022a8861929856362 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Sat, 13 Mar 2021 16:05:04 +0100 Subject: [PATCH 12/17] Add Vulkan example --- dub.sdl | 2 +- examples/triangle-vulkan/README.md | 18 + examples/triangle-vulkan/app.d | 2196 +++++++++++++++++++++++ examples/triangle-vulkan/dub.sdl | 13 + examples/triangle-vulkan/screenshot.png | Bin 0 -> 9953 bytes 5 files changed, 2228 insertions(+), 1 deletion(-) create mode 100644 examples/triangle-vulkan/README.md create mode 100644 examples/triangle-vulkan/app.d create mode 100644 examples/triangle-vulkan/dub.sdl create mode 100644 examples/triangle-vulkan/screenshot.png diff --git a/dub.sdl b/dub.sdl index c4086c7..447e6e7 100644 --- a/dub.sdl +++ b/dub.sdl @@ -9,7 +9,7 @@ targetType "library" subPackage "examples/empty-window" subPackage "examples/triangle-gl" -//subPackage "examples/triangle-vulkan" +subPackage "examples/triangle-vulkan" dflags "-preview=dip1000" "-preview=dip25" dflags "-preview=fieldwise" diff --git a/examples/triangle-vulkan/README.md b/examples/triangle-vulkan/README.md new file mode 100644 index 0000000..325814f --- /dev/null +++ b/examples/triangle-vulkan/README.md @@ -0,0 +1,18 @@ +# Vulkan triangle example + +![Screenshot](screenshot.png) + +This example opens a window and draws a triangle using Vulkan. + +It is a translation of [triangle-vulkan.c](https://github.com/glfw/glfw/blob/33cd8b865d9289cfbcf3d95e6e68e4050b94fcd3/tests/triangle-vulkan.c) from the GLFW test suite. +Instead of [glad](https://github.com/glfw/glfw/blob/33cd8b865d9289cfbcf3d95e6e68e4050b94fcd3/deps/glad_vulkan.c) and glfw's vulkan module, it uses [erupteD](https://github.com/ParticlePeter/ErupteD) as the Vulkan function loader. + +From this folder, run it with: +``` +dub run +``` + +From the root of the repository, run it with: +``` +dub run glfw-d:triangle-vulkan +``` diff --git a/examples/triangle-vulkan/app.d b/examples/triangle-vulkan/app.d new file mode 100644 index 0000000..85c06e5 --- /dev/null +++ b/examples/triangle-vulkan/app.d @@ -0,0 +1,2196 @@ +/// Vulkan test application adapted from GLFW's test suite +/// +/// https://github.com/glfw/glfw/blob/33cd8b865d9289cfbcf3d95e6e68e4050b94fcd3/tests/triangle-vulkan.c +module app; + +package: nothrow: @nogc: + +import glfw3.api; +import erupted; +import erupted.vulkan_lib_loader; +import core.stdc.stdio; + +/* + * Draw a textured triangle with depth testing. This is written against Intel + * ICD. It does not do state transition nor object memory binding like it + * should. It also does no error checking. + */ +/* + * Copyright (c) 2015-2016 The Khronos Group Inc. + * Copyright (c) 2015-2016 Valve Corporation + * Copyright (c) 2015-2016 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Author: Chia-I Wu + * Author: Cody Northrop + * Author: Courtney Goeltzenleuchter + * Author: Ian Elliott + * Author: Jon Ashburn + * Author: Piers Daniell + * Author: Gwan-gyeong Mun + * Porter: Camilla Löwy + */ + +import core.stdc.stdio; +import core.stdc.stdlib; +import core.stdc.string; +import core.stdc.assert_; +//import core.stdc.signal; is missing SIGTRAP +import core.sys.posix.signal; + +version (Windows) { + import core.sys.windows.windows; +} + +enum DEMO_TEXTURE_COUNT = 1; +enum VERTEX_BUFFER_BIND_ID = 0; +enum APP_SHORT_NAME = "tri"; +enum APP_LONG_NAME = "The Vulkan Triangle Demo Program"; + +enum string ARRAY_SIZE(string a) = ` (sizeof(a) / sizeof(a[0]))`; + +auto ERR_EXIT(const(char)* err_msg, const(char)* err_class) { + printf(err_msg); + fflush(stdout); + return exit(1); +} + +immutable ubyte[] fragShaderCode = [ + 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, + 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x04, 0x00, 0x09, 0x00, + 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73, 0x65, 0x70, 0x61, 0x72, + 0x61, 0x74, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x6f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x00, 0x00, 0x04, 0x00, 0x09, 0x00, + 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x69, + 0x6e, 0x67, 0x5f, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x5f, + 0x34, 0x32, 0x30, 0x70, 0x61, 0x63, 0x6b, 0x00, 0x05, 0x00, 0x04, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x05, 0x00, 0x09, 0x00, 0x00, 0x00, 0x75, 0x46, 0x72, 0x61, + 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x00, 0x05, 0x00, 0x05, 0x00, + 0x11, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, + 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x57, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, + 0x38, 0x00, 0x01, 0x00 +]; + +immutable ubyte[] vertShaderCode = [ + 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, + 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, + 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73, + 0x65, 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x64, + 0x65, 0x72, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x00, 0x00, + 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73, + 0x68, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x6c, 0x61, 0x6e, 0x67, 0x75, + 0x61, 0x67, 0x65, 0x5f, 0x34, 0x32, 0x30, 0x70, 0x61, 0x63, 0x6b, 0x00, + 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x67, 0x6c, 0x5f, 0x50, 0x65, 0x72, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, + 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x07, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x69, 0x6e, 0x74, + 0x53, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07, 0x00, + 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x43, + 0x6c, 0x69, 0x70, 0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x00, + 0x05, 0x00, 0x03, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x03, 0x00, 0x17, 0x00, 0x00, 0x00, 0x70, 0x6f, 0x73, 0x00, + 0x05, 0x00, 0x05, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x56, + 0x65, 0x72, 0x74, 0x65, 0x78, 0x49, 0x44, 0x00, 0x05, 0x00, 0x06, 0x00, + 0x1d, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, + 0x6e, 0x63, 0x65, 0x49, 0x44, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, + 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, + 0x19, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x1b, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x41, 0x00, 0x05, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, + 0x1a, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, + 0x38, 0x00, 0x01, 0x00 +]; + +struct texture_object { + VkSampler sampler; + + VkImage image; + VkImageLayout imageLayout; + + VkDeviceMemory mem; + VkImageView view; + int tex_width, tex_height; +} + +private int validation_error = 0; + +extern(System) VkBool32 BreakCallback( + VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, ulong srcObject, size_t location, int msgCode, + const(char)* pLayerPrefix, const(char)* pMsg, void* pUserData +) { + version (Windows) { + DebugBreak(); + } else { + raise(SIGTRAP); + } + return false; +} + +struct SwapchainBuffers { + VkImage image; + VkCommandBuffer cmd; + VkImageView view; +} + +struct Demo { + GLFWwindow* window; + VkSurfaceKHR surface; + bool use_staging_buffer; + + VkInstance inst; + VkPhysicalDevice gpu; + VkDevice device; + VkQueue queue; + VkPhysicalDeviceProperties gpu_props; + VkPhysicalDeviceFeatures gpu_features; + VkQueueFamilyProperties* queue_props; + uint graphics_queue_node_index; + + uint enabled_extension_count; + uint enabled_layer_count; + const(char)*[64] extension_names; + const(char)*[64] enabled_layers; + + int width;int height; + VkFormat format; + VkColorSpaceKHR color_space; + + uint swapchainImageCount; + VkSwapchainKHR swapchain; + SwapchainBuffers* buffers; + + VkCommandPool cmd_pool; + + struct _Depth { + VkFormat format; + + VkImage image; + VkDeviceMemory mem; + VkImageView view; + }_Depth depth; + + texture_object[DEMO_TEXTURE_COUNT] textures; + + struct _Vertices { + VkBuffer buf; + VkDeviceMemory mem; + + VkPipelineVertexInputStateCreateInfo vi; + VkVertexInputBindingDescription[1] vi_bindings; + VkVertexInputAttributeDescription[2] vi_attrs; + }_Vertices vertices; + + VkCommandBuffer setup_cmd; // Command Buffer for initialization commands + VkCommandBuffer draw_cmd; // Command Buffer for drawing commands + VkPipelineLayout pipeline_layout; + VkDescriptorSetLayout desc_layout; + VkPipelineCache pipelineCache; + VkRenderPass render_pass; + VkPipeline pipeline; + + VkShaderModule vert_shader_module; + VkShaderModule frag_shader_module; + + VkDescriptorPool desc_pool; + VkDescriptorSet desc_set; + + VkFramebuffer* framebuffers; + + VkPhysicalDeviceMemoryProperties memory_properties; + + int curFrame; + int frameCount; + bool validate; + bool use_break; + VkDebugReportCallbackEXT msg_callback; + + float depthStencil; + float depthIncrement; + + uint current_buffer; + uint queue_count; +} + +extern(System) VkBool32 dbgFunc( + VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, ulong srcObject, size_t location, int msgCode, + const(char)* pLayerPrefix, const(char)* pMsg, void* pUserData +) { + char* message = cast(char*)malloc(strlen(pMsg) + 100); + + assert(message); + + validation_error = 1; + + if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { + sprintf(message, "ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode, + pMsg); + } else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) { + sprintf(message, "WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode, + pMsg); + } else { + return false; + } + + printf("%s\n", message); + fflush(stdout); + free(message); + + /* + * false indicates that layer should not bail-out of an + * API call that had validation failures. This may mean that the + * app dies inside the driver due to invalid parameter(s). + * That's what would happen without validation layers, so we'll + * keep that behavior here. + */ + return false; +} + +// Forward declaration: +private void demo_resize(Demo* demo); + +private bool memory_type_from_properties(Demo* demo, uint typeBits, VkFlags requirements_mask, uint* typeIndex) { + uint i; + // Search memtypes to find first index with those properties + for (i = 0; i < VK_MAX_MEMORY_TYPES; i++) { + if ((typeBits & 1) == 1) { + // Type is available, does it match user properties? + if ((demo.memory_properties.memoryTypes[i].propertyFlags & + requirements_mask) == requirements_mask) { + *typeIndex = i; + return true; + } + } + typeBits >>= 1; + } + // No memory types matched, return failure + return false; +} + +private void demo_flush_init_cmd(Demo* demo) { + VkResult err; + + if (demo.setup_cmd == VK_NULL_HANDLE) + return; + + err = vkEndCommandBuffer(demo.setup_cmd); + assert(!err); + + const(VkCommandBuffer)[1] cmd_bufs = [demo.setup_cmd]; + //VkFence_handle[1] _handleArray = [VK_NULL_HANDLE]; + //ubyte[8] _handleArrayBytes = 0; + //VkFence nullFence = cast(VkFence_handle) (_handleArrayBytes.ptr); + VkSubmitInfo submit_info = {sType: VK_STRUCTURE_TYPE_SUBMIT_INFO, + pNext: null, + waitSemaphoreCount: 0, + pWaitSemaphores: null, + pWaitDstStageMask: null, + commandBufferCount: cmd_bufs.length, + pCommandBuffers: cmd_bufs.ptr, + signalSemaphoreCount: 0, + pSignalSemaphores: null}; + + err = vkQueueSubmit(demo.queue, 1, &submit_info, VK_NULL_HANDLE); + assert(!err); + + err = vkQueueWaitIdle(demo.queue); + assert(!err); + + vkFreeCommandBuffers(demo.device, demo.cmd_pool, cmd_bufs.length, cmd_bufs.ptr); + demo.setup_cmd = VK_NULL_HANDLE; +} + +private void demo_set_image_layout( + Demo* demo, VkImage image, VkImageAspectFlags aspectMask, VkImageLayout old_image_layout, + VkImageLayout new_image_layout, VkAccessFlagBits srcAccessMask +) { + VkResult err; + + if (demo.setup_cmd == VK_NULL_HANDLE) { + const(VkCommandBufferAllocateInfo) cmd = { + sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, + pNext: null, + commandPool: demo.cmd_pool, + level: VK_COMMAND_BUFFER_LEVEL_PRIMARY, + commandBufferCount: 1, + }; + + err = vkAllocateCommandBuffers(demo.device, &cmd, &demo.setup_cmd); + assert(!err); + + VkCommandBufferBeginInfo cmd_buf_info = { + sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + pNext: null, + flags: 0, + pInheritanceInfo: null, + }; + err = vkBeginCommandBuffer(demo.setup_cmd, &cmd_buf_info); + assert(!err); + } + + VkImageMemoryBarrier image_memory_barrier = { + sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + pNext: null, + srcAccessMask: srcAccessMask, + dstAccessMask: 0, + oldLayout: old_image_layout, + newLayout: new_image_layout, + image: image, + subresourceRange: {aspectMask, 0, 1, 0, 1} + }; + + if (new_image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { + /* Make sure anything that was copying from this image has completed */ + image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + } + + if (new_image_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) { + image_memory_barrier.dstAccessMask = + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + } + + if (new_image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) { + image_memory_barrier.dstAccessMask = + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + } + + if (new_image_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { + /* Make sure any Copy or CPU writes to image are flushed */ + image_memory_barrier.dstAccessMask = + VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; + } + + VkImageMemoryBarrier* pmemory_barrier = &image_memory_barrier; + + VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; + VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; + + vkCmdPipelineBarrier(demo.setup_cmd, src_stages, dest_stages, 0, 0, null, + 0, null, 1, pmemory_barrier); +} + +private void demo_draw_build_cmd(Demo* demo) { + const(VkCommandBufferBeginInfo) cmd_buf_info = { + sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + pNext: null, + flags: 0, + pInheritanceInfo: null, + }; + VkClearColorValue colorValue; + colorValue.float32 = [0.2f, 0.2f, 0.2f, 0.2f]; + VkClearValue clearValueColor; + clearValueColor.color = colorValue; + const(VkClearValue)[2] clear_values = [ + clearValueColor, + {depthStencil: {demo.depthStencil, 0}}, + ]; + const(VkRenderPassBeginInfo) rp_begin = { + sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, + pNext: null, + renderPass: demo.render_pass, + framebuffer: demo.framebuffers[demo.current_buffer], + renderArea: {offset: {x: 0, y: 0}, extent: {width: demo.width, height: demo.height}}, + clearValueCount: 2, + pClearValues: clear_values.ptr, + }; + VkResult err; + + err = vkBeginCommandBuffer(demo.draw_cmd, &cmd_buf_info); + assert(!err); + + // We can use LAYOUT_UNDEFINED as a wildcard here because we don't care what + // happens to the previous contents of the image + VkImageMemoryBarrier image_memory_barrier = { + sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + pNext: null, + srcAccessMask: 0, + dstAccessMask: VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + oldLayout: VK_IMAGE_LAYOUT_UNDEFINED, + newLayout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + srcQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED, + dstQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED, + image: demo.buffers[demo.current_buffer].image, + subresourceRange: {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1} + }; + + vkCmdPipelineBarrier(demo.draw_cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, null, 0, + null, 1, &image_memory_barrier); + vkCmdBeginRenderPass(demo.draw_cmd, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); + vkCmdBindPipeline(demo.draw_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + demo.pipeline); + vkCmdBindDescriptorSets(demo.draw_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + demo.pipeline_layout, 0, 1, &demo.desc_set, 0, + null); + + VkViewport viewport; + memset(&viewport, 0, viewport.sizeof); + viewport.height = cast(float)demo.height; + viewport.width = cast(float)demo.width; + viewport.minDepth = cast(float)0.0f; + viewport.maxDepth = cast(float)1.0f; + vkCmdSetViewport(demo.draw_cmd, 0, 1, &viewport); + + VkRect2D scissor; + memset(&scissor, 0, scissor.sizeof); + scissor.extent.width = demo.width; + scissor.extent.height = demo.height; + scissor.offset.x = 0; + scissor.offset.y = 0; + vkCmdSetScissor(demo.draw_cmd, 0, 1, &scissor); + + VkDeviceSize[1] offsets = [0]; + vkCmdBindVertexBuffers(demo.draw_cmd, VERTEX_BUFFER_BIND_ID, 1, + &demo.vertices.buf, offsets.ptr); + + vkCmdDraw(demo.draw_cmd, 3, 1, 0, 0); + vkCmdEndRenderPass(demo.draw_cmd); + + VkImageMemoryBarrier prePresentBarrier = { + sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + pNext: null, + srcAccessMask: VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + dstAccessMask: VK_ACCESS_MEMORY_READ_BIT, + oldLayout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + newLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + srcQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED, + dstQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED, + subresourceRange: {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1} + }; + + prePresentBarrier.image = demo.buffers[demo.current_buffer].image; + VkImageMemoryBarrier* pmemory_barrier = &prePresentBarrier; + vkCmdPipelineBarrier(demo.draw_cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, null, 0, + null, 1, pmemory_barrier); + + err = vkEndCommandBuffer(demo.draw_cmd); + assert(!err); +} + +private void demo_draw(Demo* demo) { + VkResult err; + VkSemaphore imageAcquiredSemaphore;VkSemaphore drawCompleteSemaphore; + VkSemaphoreCreateInfo semaphoreCreateInfo = { + sType: VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, + pNext: null, + flags: 0, + }; + + err = vkCreateSemaphore(demo.device, &semaphoreCreateInfo, + null, &imageAcquiredSemaphore); + assert(!err); + + err = vkCreateSemaphore(demo.device, &semaphoreCreateInfo, + null, &drawCompleteSemaphore); + assert(!err); + + // Get the index of the next available swapchain image: + err = vkAcquireNextImageKHR(demo.device, demo.swapchain, ulong.max, + imageAcquiredSemaphore, + cast(VkFence)0, // TODO: Show use of fence + &demo.current_buffer); + if (err == VK_ERROR_OUT_OF_DATE_KHR) { + // demo->swapchain is out of date (e.g. the window was resized) and + // must be recreated: + demo_resize(demo); + demo_draw(demo); + vkDestroySemaphore(demo.device, imageAcquiredSemaphore, null); + vkDestroySemaphore(demo.device, drawCompleteSemaphore, null); + return; + } else if (err == VK_SUBOPTIMAL_KHR) { + // demo->swapchain is not as optimal as it could be, but the platform's + // presentation engine will still present the image correctly. + } else { + assert(!err); + } + + demo_flush_init_cmd(demo); + + // Wait for the present complete semaphore to be signaled to ensure + // that the image won't be rendered to until the presentation + // engine has fully released ownership to the application, and it is + // okay to render to the image. + + demo_draw_build_cmd(demo); + VkFence nullFence = VK_NULL_HANDLE; + VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; + VkSubmitInfo submit_info = {sType: VK_STRUCTURE_TYPE_SUBMIT_INFO, + pNext: null, + waitSemaphoreCount: 1, + pWaitSemaphores: &imageAcquiredSemaphore, + pWaitDstStageMask: &pipe_stage_flags, + commandBufferCount: 1, + pCommandBuffers: &demo.draw_cmd, + signalSemaphoreCount: 1, + pSignalSemaphores: &drawCompleteSemaphore}; + + err = vkQueueSubmit(demo.queue, 1, &submit_info, nullFence); + assert(!err); + + VkPresentInfoKHR present = { + sType: VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, + pNext: null, + waitSemaphoreCount: 1, + pWaitSemaphores: &drawCompleteSemaphore, + swapchainCount: 1, + pSwapchains: &demo.swapchain, + pImageIndices: &demo.current_buffer, + }; + + err = vkQueuePresentKHR(demo.queue, &present); + if (err == VK_ERROR_OUT_OF_DATE_KHR) { + // demo->swapchain is out of date (e.g. the window was resized) and + // must be recreated: + demo_resize(demo); + } else if (err == VK_SUBOPTIMAL_KHR) { + // demo->swapchain is not as optimal as it could be, but the platform's + // presentation engine will still present the image correctly. + } else { + assert(!err); + } + + err = vkQueueWaitIdle(demo.queue); + assert(err == VK_SUCCESS); + + vkDestroySemaphore(demo.device, imageAcquiredSemaphore, null); + vkDestroySemaphore(demo.device, drawCompleteSemaphore, null); +} + +private void demo_prepare_buffers(Demo* demo) { + VkResult err; + VkSwapchainKHR oldSwapchain = demo.swapchain; + + // Check the surface capabilities and formats + VkSurfaceCapabilitiesKHR surfCapabilities; + err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR( + demo.gpu, demo.surface, &surfCapabilities); + assert(!err); + + uint presentModeCount; + err = vkGetPhysicalDeviceSurfacePresentModesKHR( + demo.gpu, demo.surface, &presentModeCount, null); + assert(!err); + VkPresentModeKHR* presentModes = cast(VkPresentModeKHR*)malloc(presentModeCount * VkPresentModeKHR.sizeof); + assert(presentModes); + err = vkGetPhysicalDeviceSurfacePresentModesKHR( + demo.gpu, demo.surface, &presentModeCount, presentModes); + assert(!err); + + VkExtent2D swapchainExtent; + // width and height are either both 0xFFFFFFFF, or both not 0xFFFFFFFF. + if (surfCapabilities.currentExtent.width == 0xFFFFFFFF) { + // If the surface size is undefined, the size is set to the size + // of the images requested, which must fit within the minimum and + // maximum values. + swapchainExtent.width = demo.width; + swapchainExtent.height = demo.height; + + if (swapchainExtent.width < surfCapabilities.minImageExtent.width) { + swapchainExtent.width = surfCapabilities.minImageExtent.width; + } else if (swapchainExtent.width > surfCapabilities.maxImageExtent.width) { + swapchainExtent.width = surfCapabilities.maxImageExtent.width; + } + + if (swapchainExtent.height < surfCapabilities.minImageExtent.height) { + swapchainExtent.height = surfCapabilities.minImageExtent.height; + } else if (swapchainExtent.height > surfCapabilities.maxImageExtent.height) { + swapchainExtent.height = surfCapabilities.maxImageExtent.height; + } + } else { + // If the surface size is defined, the swap chain size must match + swapchainExtent = surfCapabilities.currentExtent; + demo.width = surfCapabilities.currentExtent.width; + demo.height = surfCapabilities.currentExtent.height; + } + + VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR; + + // Determine the number of VkImage's to use in the swap chain. + // Application desires to only acquire 1 image at a time (which is + // "surfCapabilities.minImageCount"). + uint desiredNumOfSwapchainImages = surfCapabilities.minImageCount; + // If maxImageCount is 0, we can ask for as many images as we want; + // otherwise we're limited to maxImageCount + if ((surfCapabilities.maxImageCount > 0) && + (desiredNumOfSwapchainImages > surfCapabilities.maxImageCount)) { + // Application must settle for fewer images than desired: + desiredNumOfSwapchainImages = surfCapabilities.maxImageCount; + } + + VkSurfaceTransformFlagsKHR preTransform; + if (surfCapabilities.supportedTransforms & + VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) { + preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + } else { + preTransform = surfCapabilities.currentTransform; + } + + const(VkSwapchainCreateInfoKHR) swapchain = { + sType: VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, + pNext: null, + surface: demo.surface, + minImageCount: desiredNumOfSwapchainImages, + imageFormat: demo.format, + imageColorSpace: demo.color_space, + imageExtent: {width: swapchainExtent.width, height: swapchainExtent.height}, + imageUsage: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + preTransform: cast(VkSurfaceTransformFlagBitsKHR) preTransform, + compositeAlpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, + imageArrayLayers: 1, + imageSharingMode: VK_SHARING_MODE_EXCLUSIVE, + queueFamilyIndexCount: 0, + pQueueFamilyIndices: null, + presentMode: swapchainPresentMode, + oldSwapchain: oldSwapchain, + clipped: true, + }; + uint i; + + err = vkCreateSwapchainKHR(demo.device, &swapchain, null, &demo.swapchain); + assert(!err); + + // If we just re-created an existing swapchain, we should destroy the old + // swapchain at this point. + // Note: destroying the swapchain also cleans up all its associated + // presentable images once the platform is done with them. + if (oldSwapchain != VK_NULL_HANDLE) { + vkDestroySwapchainKHR(demo.device, oldSwapchain, null); + } + + err = vkGetSwapchainImagesKHR(demo.device, demo.swapchain, + &demo.swapchainImageCount, null); + assert(!err); + + VkImage* swapchainImages = cast(VkImage*)malloc(demo.swapchainImageCount * VkImage.sizeof); + assert(swapchainImages); + err = vkGetSwapchainImagesKHR(demo.device, demo.swapchain, + &demo.swapchainImageCount, + swapchainImages); + assert(!err); + + demo.buffers = cast(SwapchainBuffers*) malloc(SwapchainBuffers.sizeof * demo.swapchainImageCount); + assert(demo.buffers); + + for (i = 0; i < demo.swapchainImageCount; i++) { + VkImageViewCreateInfo color_attachment_view = { + sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + pNext: null, + format: demo.format, + components: + { + r: VK_COMPONENT_SWIZZLE_R, + g: VK_COMPONENT_SWIZZLE_G, + b: VK_COMPONENT_SWIZZLE_B, + a: VK_COMPONENT_SWIZZLE_A, + }, + subresourceRange: { + aspectMask: VK_IMAGE_ASPECT_COLOR_BIT, + baseMipLevel: 0, + levelCount: 1, + baseArrayLayer: 0, + layerCount: 1 + }, + viewType: VK_IMAGE_VIEW_TYPE_2D, + flags: 0, + }; + + demo.buffers[i].image = swapchainImages[i]; + + color_attachment_view.image = demo.buffers[i].image; + + err = vkCreateImageView(demo.device, &color_attachment_view, null, + &demo.buffers[i].view); + assert(!err); + } + + demo.current_buffer = 0; + + if (null != presentModes) { + free(presentModes); + } +} + +private void demo_prepare_depth(Demo* demo) { + const(VkFormat) depth_format = VK_FORMAT_D16_UNORM; + const(VkImageCreateInfo) image = { + sType: VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + pNext: null, + imageType: VK_IMAGE_TYPE_2D, + format: depth_format, + extent: {demo.width, demo.height, 1}, + mipLevels: 1, + arrayLayers: 1, + samples: VK_SAMPLE_COUNT_1_BIT, + tiling: VK_IMAGE_TILING_OPTIMAL, + usage: VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + flags: 0, + }; + VkMemoryAllocateInfo mem_alloc = { + sType: VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + pNext: null, + allocationSize: 0, + memoryTypeIndex: 0, + }; + VkImageViewCreateInfo view = { + sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + pNext: null, + image: VK_NULL_HANDLE, + format: depth_format, + subresourceRange: { + aspectMask: VK_IMAGE_ASPECT_DEPTH_BIT, + baseMipLevel: 0, + levelCount: 1, + baseArrayLayer: 0, + layerCount: 1 + }, + flags: 0, + viewType: VK_IMAGE_VIEW_TYPE_2D, + }; + + VkMemoryRequirements mem_reqs; + VkResult err; + bool pass; + + demo.depth.format = depth_format; + + /* create image */ + err = vkCreateImage(demo.device, &image, null, &demo.depth.image); + assert(!err); + + /* get memory requirements for this object */ + vkGetImageMemoryRequirements(demo.device, demo.depth.image, &mem_reqs); + + /* select memory size and type */ + mem_alloc.allocationSize = mem_reqs.size; + pass = memory_type_from_properties(demo, mem_reqs.memoryTypeBits, + 0, /* No requirements */ + &mem_alloc.memoryTypeIndex); + assert(pass); + + /* allocate memory */ + err = vkAllocateMemory(demo.device, &mem_alloc, null, &demo.depth.mem); + assert(!err); + + /* bind memory */ + err = + vkBindImageMemory(demo.device, demo.depth.image, demo.depth.mem, 0); + assert(!err); + + demo_set_image_layout(demo, demo.depth.image, VK_IMAGE_ASPECT_DEPTH_BIT, + VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + cast(VkAccessFlagBits) 0); + + /* create image view */ + view.image = demo.depth.image; + err = vkCreateImageView(demo.device, &view, null, &demo.depth.view); + assert(!err); +} + +private void demo_prepare_texture_image( + Demo* demo, const(uint)* tex_colors, texture_object* tex_obj, + VkImageTiling tiling, VkImageUsageFlags usage, VkFlags required_props +) { + const(VkFormat) tex_format = VK_FORMAT_B8G8R8A8_UNORM; + const(int) tex_width = 2; + const(int) tex_height = 2; + VkResult err; + bool pass; + + tex_obj.tex_width = tex_width; + tex_obj.tex_height = tex_height; + + const(VkImageCreateInfo) image_create_info = { + sType: VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + pNext: null, + imageType: VK_IMAGE_TYPE_2D, + format: tex_format, + extent: {tex_width, tex_height, 1}, + mipLevels: 1, + arrayLayers: 1, + samples: VK_SAMPLE_COUNT_1_BIT, + tiling: tiling, + usage: usage, + flags: 0, + initialLayout: VK_IMAGE_LAYOUT_PREINITIALIZED + }; + VkMemoryAllocateInfo mem_alloc = { + sType: VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + pNext: null, + allocationSize: 0, + memoryTypeIndex: 0, + }; + + VkMemoryRequirements mem_reqs; + + err = vkCreateImage(demo.device, &image_create_info, null, &tex_obj.image); + assert(!err); + + vkGetImageMemoryRequirements(demo.device, tex_obj.image, &mem_reqs); + + mem_alloc.allocationSize = mem_reqs.size; + pass = memory_type_from_properties(demo, mem_reqs.memoryTypeBits, + required_props, &mem_alloc.memoryTypeIndex); + assert(pass); + + /* allocate memory */ + err = vkAllocateMemory(demo.device, &mem_alloc, null, &tex_obj.mem); + assert(!err); + + /* bind memory */ + err = vkBindImageMemory(demo.device, tex_obj.image, tex_obj.mem, 0); + assert(!err); + + if (required_props & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { + const(VkImageSubresource) subres = { + aspectMask: VK_IMAGE_ASPECT_COLOR_BIT, + mipLevel: 0, + arrayLayer: 0, + }; + VkSubresourceLayout layout; + void* data; + int x;int y; + + vkGetImageSubresourceLayout(demo.device, tex_obj.image, &subres, + &layout); + + err = vkMapMemory(demo.device, tex_obj.mem, 0, + mem_alloc.allocationSize, 0, &data); + assert(!err); + + for (y = 0; y < tex_height; y++) { + uint* row = cast(uint*)(cast(char*)data + layout.rowPitch * y); + for (x = 0; x < tex_width; x++) + row[x] = tex_colors[(x & 1) ^ (y & 1)]; + } + + vkUnmapMemory(demo.device, tex_obj.mem); + } + + tex_obj.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + demo_set_image_layout(demo, tex_obj.image, VK_IMAGE_ASPECT_COLOR_BIT, + VK_IMAGE_LAYOUT_PREINITIALIZED, tex_obj.imageLayout, + VK_ACCESS_HOST_WRITE_BIT); + /* setting the image layout does not reference the actual memory so no need + * to add a mem ref */ +} + +private void demo_destroy_texture_image(Demo* demo, texture_object* tex_obj) { + /* clean up staging resources */ + vkDestroyImage(demo.device, tex_obj.image, null); + vkFreeMemory(demo.device, tex_obj.mem, null); +} + +private void demo_prepare_textures(Demo* demo) { + const(VkFormat) tex_format = VK_FORMAT_B8G8R8A8_UNORM; + VkFormatProperties props; + const(uint)[2][DEMO_TEXTURE_COUNT] tex_colors = [ + [0xffff0000, 0xff00ff00], + ]; + uint i; + VkResult err; + + vkGetPhysicalDeviceFormatProperties(demo.gpu, tex_format, &props); + + for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { + if ((props.linearTilingFeatures & + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && + !demo.use_staging_buffer) { + /* Device can texture using linear textures */ + demo_prepare_texture_image( + demo, tex_colors[i].ptr, &demo.textures[i], VK_IMAGE_TILING_LINEAR, + VK_IMAGE_USAGE_SAMPLED_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + } else if (props.optimalTilingFeatures & + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { + /* Must use staging buffer to copy linear texture to optimized */ + texture_object staging_texture; + + memset(&staging_texture, 0, staging_texture.sizeof); + demo_prepare_texture_image( + demo, tex_colors[i].ptr, &staging_texture, VK_IMAGE_TILING_LINEAR, + VK_IMAGE_USAGE_TRANSFER_SRC_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + + demo_prepare_texture_image( + demo, tex_colors[i].ptr, &demo.textures[i], + VK_IMAGE_TILING_OPTIMAL, + (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + + demo_set_image_layout(demo, staging_texture.image, + VK_IMAGE_ASPECT_COLOR_BIT, + staging_texture.imageLayout, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + cast(VkAccessFlagBits) 0); + + demo_set_image_layout(demo, demo.textures[i].image, + VK_IMAGE_ASPECT_COLOR_BIT, + demo.textures[i].imageLayout, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + cast(VkAccessFlagBits) 0); + + VkImageCopy copy_region = { + srcSubresource: {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + srcOffset: {0, 0, 0}, + dstSubresource: {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + dstOffset: {0, 0, 0}, + extent: {staging_texture.tex_width, staging_texture.tex_height, 1}, + }; + vkCmdCopyImage( + demo.setup_cmd, staging_texture.image, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, demo.textures[i].image, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©_region); + + demo_set_image_layout(demo, demo.textures[i].image, + VK_IMAGE_ASPECT_COLOR_BIT, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + demo.textures[i].imageLayout, + cast(VkAccessFlagBits) 0); + + demo_flush_init_cmd(demo); + + demo_destroy_texture_image(demo, &staging_texture); + } else { + /* Can't support VK_FORMAT_B8G8R8A8_UNORM !? */ + assert(!"No support for B8G8R8A8_UNORM as texture image format"); + } + + const(VkSamplerCreateInfo) sampler = { + sType: VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, + pNext: null, + magFilter: VK_FILTER_NEAREST, + minFilter: VK_FILTER_NEAREST, + mipmapMode: VK_SAMPLER_MIPMAP_MODE_NEAREST, + addressModeU: VK_SAMPLER_ADDRESS_MODE_REPEAT, + addressModeV: VK_SAMPLER_ADDRESS_MODE_REPEAT, + addressModeW: VK_SAMPLER_ADDRESS_MODE_REPEAT, + mipLodBias: 0.0f, + anisotropyEnable: VK_FALSE, + maxAnisotropy: 1, + compareOp: VK_COMPARE_OP_NEVER, + minLod: 0.0f, + maxLod: 0.0f, + borderColor: VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE, + unnormalizedCoordinates: VK_FALSE, + }; + VkImageViewCreateInfo view = { + sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + pNext: null, + image: VK_NULL_HANDLE, + viewType: VK_IMAGE_VIEW_TYPE_2D, + format: tex_format, + components: + { + VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, + VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A, + }, + subresourceRange: {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}, + flags: 0, + }; + + /* create sampler */ + err = vkCreateSampler(demo.device, &sampler, null, + &demo.textures[i].sampler); + assert(!err); + + /* create image view */ + view.image = demo.textures[i].image; + err = vkCreateImageView(demo.device, &view, null, + &demo.textures[i].view); + assert(!err); + } +} + +private void demo_prepare_vertices(Demo* demo) { + // clang-format off + const(float)[5][3] vb = [ + /* position texcoord */ + [ -1.0f, -1.0f, 0.25f, 0.0f, 0.0f ], + [ 1.0f, -1.0f, 0.25f, 1.0f, 0.0f ], + [ 0.0f, 1.0f, 1.0f, 0.5f, 1.0f ], + ]; + // clang-format on + const(VkBufferCreateInfo) buf_info = { + sType: VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, + pNext: null, + size: vb.sizeof, + usage: VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, + flags: 0, + }; + VkMemoryAllocateInfo mem_alloc = { + sType: VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + pNext: null, + allocationSize: 0, + memoryTypeIndex: 0, + }; + VkMemoryRequirements mem_reqs; + VkResult err; + bool pass; // U_ASSERT_ONLY + void* data; + + memset(&demo.vertices, 0, typeof(demo.vertices).sizeof); + + err = vkCreateBuffer(demo.device, &buf_info, null, &demo.vertices.buf); + assert(!err); + + vkGetBufferMemoryRequirements(demo.device, demo.vertices.buf, &mem_reqs); + assert(!err); + + mem_alloc.allocationSize = mem_reqs.size; + pass = memory_type_from_properties(demo, mem_reqs.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + &mem_alloc.memoryTypeIndex); + assert(pass); + + err = vkAllocateMemory(demo.device, &mem_alloc, null, &demo.vertices.mem); + assert(!err); + + err = vkMapMemory(demo.device, demo.vertices.mem, 0, + mem_alloc.allocationSize, 0, &data); + assert(!err); + + memcpy(data, vb.ptr, vb.sizeof); + + vkUnmapMemory(demo.device, demo.vertices.mem); + + err = vkBindBufferMemory(demo.device, demo.vertices.buf, + demo.vertices.mem, 0); + assert(!err); + + demo.vertices.vi.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + demo.vertices.vi.pNext = null; + demo.vertices.vi.vertexBindingDescriptionCount = 1; + demo.vertices.vi.pVertexBindingDescriptions = demo.vertices.vi_bindings.ptr; + demo.vertices.vi.vertexAttributeDescriptionCount = 2; + demo.vertices.vi.pVertexAttributeDescriptions = demo.vertices.vi_attrs.ptr; + + demo.vertices.vi_bindings[0].binding = VERTEX_BUFFER_BIND_ID; + demo.vertices.vi_bindings[0].stride = typeof(vb[0]).sizeof; + demo.vertices.vi_bindings[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + demo.vertices.vi_attrs[0].binding = VERTEX_BUFFER_BIND_ID; + demo.vertices.vi_attrs[0].location = 0; + demo.vertices.vi_attrs[0].format = VK_FORMAT_R32G32B32_SFLOAT; + demo.vertices.vi_attrs[0].offset = 0; + + demo.vertices.vi_attrs[1].binding = VERTEX_BUFFER_BIND_ID; + demo.vertices.vi_attrs[1].location = 1; + demo.vertices.vi_attrs[1].format = VK_FORMAT_R32G32_SFLOAT; + demo.vertices.vi_attrs[1].offset = float.sizeof * 3; +} +private void demo_prepare_descriptor_layout(Demo* demo) { + const(VkDescriptorSetLayoutBinding) layout_binding = { + binding: 0, + descriptorType: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + descriptorCount: DEMO_TEXTURE_COUNT, + stageFlags: VK_SHADER_STAGE_FRAGMENT_BIT, + pImmutableSamplers: null, + }; + const(VkDescriptorSetLayoutCreateInfo) descriptor_layout = { + sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, + pNext: null, + bindingCount: 1, + pBindings: &layout_binding, + }; + VkResult err; + + err = vkCreateDescriptorSetLayout(demo.device, &descriptor_layout, null, + &demo.desc_layout); + assert(!err); + + const(VkPipelineLayoutCreateInfo) pPipelineLayoutCreateInfo = { + sType: VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, + pNext: null, + setLayoutCount: 1, + pSetLayouts: &demo.desc_layout, + }; + + err = vkCreatePipelineLayout(demo.device, &pPipelineLayoutCreateInfo, null, + &demo.pipeline_layout); + assert(!err); +} + +private void demo_prepare_render_pass(Demo* demo) { + const(VkAttachmentDescription)[2] attachments = [ + { + format: demo.format, + samples: VK_SAMPLE_COUNT_1_BIT, + loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, + storeOp: VK_ATTACHMENT_STORE_OP_STORE, + stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, + stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, + initialLayout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + finalLayout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + }, + { + format: demo.depth.format, + samples: VK_SAMPLE_COUNT_1_BIT, + loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, + storeOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, + stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, + stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, + initialLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + finalLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + }, + ]; + const(VkAttachmentReference) color_reference = { + attachment: 0, + layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + }; + const(VkAttachmentReference) depth_reference = { + attachment: 1, + layout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + }; + const(VkSubpassDescription) subpass = { + pipelineBindPoint: VK_PIPELINE_BIND_POINT_GRAPHICS, + flags: 0, + inputAttachmentCount: 0, + pInputAttachments: null, + colorAttachmentCount: 1, + pColorAttachments: &color_reference, + pResolveAttachments: null, + pDepthStencilAttachment: &depth_reference, + preserveAttachmentCount: 0, + pPreserveAttachments: null, + }; + const(VkRenderPassCreateInfo) rp_info = { + sType: VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, + pNext: null, + attachmentCount: 2, + pAttachments: attachments.ptr, + subpassCount: 1, + pSubpasses: &subpass, + dependencyCount: 0, + pDependencies: null, + }; + VkResult err; + + err = vkCreateRenderPass(demo.device, &rp_info, null, &demo.render_pass); + assert(!err); +} + +private VkShaderModule demo_prepare_shader_module(Demo* demo, const(ubyte)[] code) { + VkShaderModuleCreateInfo moduleCreateInfo; + VkShaderModule module_; + VkResult err; + + moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + moduleCreateInfo.pNext = null; + + moduleCreateInfo.codeSize = code.length; + moduleCreateInfo.pCode = cast(const(uint)*) code.ptr; + moduleCreateInfo.flags = 0; + err = vkCreateShaderModule(demo.device, &moduleCreateInfo, null, &module_); + assert(!err); + + return module_; +} + +private VkShaderModule demo_prepare_vs(Demo* demo) { + demo.vert_shader_module = demo_prepare_shader_module(demo, vertShaderCode[]); + return demo.vert_shader_module; +} + +private VkShaderModule demo_prepare_fs(Demo* demo) { + demo.frag_shader_module = demo_prepare_shader_module(demo, fragShaderCode[]); + return demo.frag_shader_module; +} + +private void demo_prepare_pipeline(Demo* demo) { + VkGraphicsPipelineCreateInfo pipeline; + VkPipelineCacheCreateInfo pipelineCache; + + VkPipelineVertexInputStateCreateInfo vi; + VkPipelineInputAssemblyStateCreateInfo ia; + VkPipelineRasterizationStateCreateInfo rs; + VkPipelineColorBlendStateCreateInfo cb; + VkPipelineDepthStencilStateCreateInfo ds; + VkPipelineViewportStateCreateInfo vp; + VkPipelineMultisampleStateCreateInfo ms; + VkDynamicState[VK_DYNAMIC_STATE_RANGE_SIZE] dynamicStateEnables; + VkPipelineDynamicStateCreateInfo dynamicState; + + VkResult err; + + memset(dynamicStateEnables.ptr, 0, dynamicStateEnables.sizeof); + memset(&dynamicState, 0, dynamicState.sizeof); + dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamicState.pDynamicStates = dynamicStateEnables.ptr; + + memset(&pipeline, 0, pipeline.sizeof); + pipeline.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipeline.layout = demo.pipeline_layout; + + vi = demo.vertices.vi; + + memset(&ia, 0, ia.sizeof); + ia.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + memset(&rs, 0, rs.sizeof); + rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rs.polygonMode = VK_POLYGON_MODE_FILL; + rs.cullMode = VK_CULL_MODE_BACK_BIT; + rs.frontFace = VK_FRONT_FACE_CLOCKWISE; + rs.depthClampEnable = VK_FALSE; + rs.rasterizerDiscardEnable = VK_FALSE; + rs.depthBiasEnable = VK_FALSE; + rs.lineWidth = 1.0f; + + memset(&cb, 0, cb.sizeof); + cb.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + VkPipelineColorBlendAttachmentState[1] att_state; + memset(att_state.ptr, 0, att_state.sizeof); + att_state[0].colorWriteMask = 0xf; + att_state[0].blendEnable = VK_FALSE; + cb.attachmentCount = 1; + cb.pAttachments = att_state.ptr; + + memset(&vp, 0, vp.sizeof); + vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + vp.viewportCount = 1; + dynamicStateEnables[dynamicState.dynamicStateCount++] = + VK_DYNAMIC_STATE_VIEWPORT; + vp.scissorCount = 1; + dynamicStateEnables[dynamicState.dynamicStateCount++] = + VK_DYNAMIC_STATE_SCISSOR; + + memset(&ds, 0, ds.sizeof); + ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + ds.depthTestEnable = VK_TRUE; + ds.depthWriteEnable = VK_TRUE; + ds.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; + ds.depthBoundsTestEnable = VK_FALSE; + ds.back.failOp = VK_STENCIL_OP_KEEP; + ds.back.passOp = VK_STENCIL_OP_KEEP; + ds.back.compareOp = VK_COMPARE_OP_ALWAYS; + ds.stencilTestEnable = VK_FALSE; + ds.front = ds.back; + + memset(&ms, 0, ms.sizeof); + ms.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + ms.pSampleMask = null; + ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + + // Two stages: vs and fs + pipeline.stageCount = 2; + VkPipelineShaderStageCreateInfo[2] shaderStages; + memset(&shaderStages, 0, 2 * VkPipelineShaderStageCreateInfo.sizeof); + + shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + shaderStages[0].module_ = demo_prepare_vs(demo); + shaderStages[0].pName = "main"; + + shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shaderStages[1].module_ = demo_prepare_fs(demo); + shaderStages[1].pName = "main"; + + pipeline.pVertexInputState = &vi; + pipeline.pInputAssemblyState = &ia; + pipeline.pRasterizationState = &rs; + pipeline.pColorBlendState = &cb; + pipeline.pMultisampleState = &ms; + pipeline.pViewportState = &vp; + pipeline.pDepthStencilState = &ds; + pipeline.pStages = shaderStages.ptr; + pipeline.renderPass = demo.render_pass; + pipeline.pDynamicState = &dynamicState; + + memset(&pipelineCache, 0, pipelineCache.sizeof); + pipelineCache.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; + + err = vkCreatePipelineCache(demo.device, &pipelineCache, null, + &demo.pipelineCache); + assert(!err); + err = vkCreateGraphicsPipelines(demo.device, demo.pipelineCache, 1, + &pipeline, null, &demo.pipeline); + assert(!err); + + vkDestroyPipelineCache(demo.device, demo.pipelineCache, null); + + vkDestroyShaderModule(demo.device, demo.frag_shader_module, null); + vkDestroyShaderModule(demo.device, demo.vert_shader_module, null); +} + +private void demo_prepare_descriptor_pool(Demo* demo) { + const(VkDescriptorPoolSize) type_count = { + type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + descriptorCount: DEMO_TEXTURE_COUNT, + }; + const(VkDescriptorPoolCreateInfo) descriptor_pool = { + sType: VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, + pNext: null, + maxSets: 1, + poolSizeCount: 1, + pPoolSizes: &type_count, + }; + VkResult err; + + err = vkCreateDescriptorPool(demo.device, &descriptor_pool, null, + &demo.desc_pool); + assert(!err); +} + +private void demo_prepare_descriptor_set(Demo* demo) { + VkDescriptorImageInfo[DEMO_TEXTURE_COUNT] tex_descs; + VkWriteDescriptorSet write; + VkResult err; + uint i; + + VkDescriptorSetAllocateInfo alloc_info = { + sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + pNext: null, + descriptorPool: demo.desc_pool, + descriptorSetCount: 1, + pSetLayouts: &demo.desc_layout}; + err = vkAllocateDescriptorSets(demo.device, &alloc_info, &demo.desc_set); + assert(!err); + + memset(&tex_descs, 0, tex_descs.sizeof); + for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { + tex_descs[i].sampler = demo.textures[i].sampler; + tex_descs[i].imageView = demo.textures[i].view; + tex_descs[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; + } + + memset(&write, 0, write.sizeof); + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstSet = demo.desc_set; + write.descriptorCount = DEMO_TEXTURE_COUNT; + write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write.pImageInfo = tex_descs.ptr; + + vkUpdateDescriptorSets(demo.device, 1, &write, 0, null); +} + +private void demo_prepare_framebuffers(Demo* demo) { + VkImageView[2] attachments; + attachments[1] = demo.depth.view; + + const(VkFramebufferCreateInfo) fb_info = { + sType: VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, + pNext: null, + renderPass: demo.render_pass, + attachmentCount: 2, + pAttachments: attachments.ptr, + width: demo.width, + height: demo.height, + layers: 1, + }; + VkResult err; + uint i; + + demo.framebuffers = cast(VkFramebuffer*)malloc(demo.swapchainImageCount * + VkFramebuffer.sizeof); + assert(demo.framebuffers); + + for (i = 0; i < demo.swapchainImageCount; i++) { + attachments[0] = demo.buffers[i].view; + err = vkCreateFramebuffer(demo.device, &fb_info, null, + &demo.framebuffers[i]); + assert(!err); + } +} + +private void demo_prepare(Demo* demo) { + VkResult err; + + const(VkCommandPoolCreateInfo) cmd_pool_info = { + sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, + pNext: null, + queueFamilyIndex: demo.graphics_queue_node_index, + flags: VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, + }; + err = vkCreateCommandPool(demo.device, &cmd_pool_info, null, + &demo.cmd_pool); + assert(!err); + + const(VkCommandBufferAllocateInfo) cmd = { + sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, + pNext: null, + commandPool: demo.cmd_pool, + level: VK_COMMAND_BUFFER_LEVEL_PRIMARY, + commandBufferCount: 1, + }; + err = vkAllocateCommandBuffers(demo.device, &cmd, &demo.draw_cmd); + assert(!err); + + demo_prepare_buffers(demo); + demo_prepare_depth(demo); + demo_prepare_textures(demo); + demo_prepare_vertices(demo); + demo_prepare_descriptor_layout(demo); + demo_prepare_render_pass(demo); + demo_prepare_pipeline(demo); + + demo_prepare_descriptor_pool(demo); + demo_prepare_descriptor_set(demo); + + demo_prepare_framebuffers(demo); +} + +private extern(C) void demo_error_callback(int error, const(char)* description) { + printf("GLFW error: %s\n", description); + fflush(stdout); +} + +private extern(C) void demo_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { + if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) + glfwSetWindowShouldClose(window, GLFW_TRUE); +} + +private extern(C) void demo_refresh_callback(GLFWwindow* window) { + Demo* demo = cast(Demo*) glfwGetWindowUserPointer(window); + demo_draw(demo); +} + +private extern(C) void demo_resize_callback(GLFWwindow* window, int width, int height) { + Demo* demo = cast(Demo*) glfwGetWindowUserPointer(window); + demo.width = width; + demo.height = height; + demo_resize(demo); +} + +private void demo_run(Demo* demo) { + while (!glfwWindowShouldClose(demo.window)) { + glfwPollEvents(); + + demo_draw(demo); + + if (demo.depthStencil > 0.99f) + demo.depthIncrement = -0.001f; + if (demo.depthStencil < 0.8f) + demo.depthIncrement = 0.001f; + + demo.depthStencil += demo.depthIncrement; + + // Wait for work to finish before updating MVP. + vkDeviceWaitIdle(demo.device); + demo.curFrame++; + if (demo.frameCount != int.max && demo.curFrame == demo.frameCount) + glfwSetWindowShouldClose(demo.window, GLFW_TRUE); + } +} + +private void demo_create_window(Demo* demo) { + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + + demo.window = glfwCreateWindow(demo.width, + demo.height, + APP_LONG_NAME, + null, + null); + if (!demo.window) { + // It didn't work, so try to give a useful error: + printf("Cannot create a window in which to draw!\n"); + fflush(stdout); + exit(1); + } + + glfwSetWindowUserPointer(demo.window, demo); + glfwSetWindowRefreshCallback(demo.window, &demo_refresh_callback); + glfwSetFramebufferSizeCallback(demo.window, &demo_resize_callback); + glfwSetKeyCallback(demo.window, &demo_key_callback); +} + +/* + * Return 1 (true) if all layer names specified in check_names + * can be found in given layer properties. + */ +static VkBool32 demo_check_layers( + uint check_count, const(char)** check_names, uint layer_count, VkLayerProperties* layers +) { + uint i;uint j; + for (i = 0; i < check_count; i++) { + VkBool32 found = 0; + for (j = 0; j < layer_count; j++) { + if (!strcmp(check_names[i], layers[j].layerName.ptr)) { + found = 1; + break; + } + } + if (!found) { + fprintf(stderr, "Cannot find layer: %s\n", check_names[i]); + return 0; + } + } + return 1; +} + +private void demo_init_vk(Demo* demo) { + VkResult err; + uint i = 0; + uint required_extension_count = 0; + uint instance_extension_count = 0; + uint instance_layer_count = 0; + uint validation_layer_count = 0; + const(char)** required_extensions = null; + const(char)** instance_validation_layers = null; + demo.enabled_extension_count = 0; + demo.enabled_layer_count = 0; + + const(char)*[1] instance_validation_layers_alt1 = [ + "VK_LAYER_LUNARG_standard_validation" + ]; + + const(char)*[7] instance_validation_layers_alt2 = [ + "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation", + "VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_image", + "VK_LAYER_LUNARG_core_validation", "VK_LAYER_LUNARG_swapchain", + "VK_LAYER_GOOGLE_unique_objects" + ]; + + /* Look for validation layers */ + VkBool32 validation_found = 0; + if (demo.validate) { + + err = vkEnumerateInstanceLayerProperties(&instance_layer_count, null); + assert(!err); + + instance_validation_layers = cast(const(char)**) instance_validation_layers_alt1; + if (instance_layer_count > 0) { + VkLayerProperties* instance_layers = cast(VkLayerProperties*) + malloc(VkLayerProperties.sizeof * instance_layer_count); + err = vkEnumerateInstanceLayerProperties(&instance_layer_count, instance_layers); + assert(!err); + + validation_found = demo_check_layers( + instance_validation_layers_alt1.length, + instance_validation_layers, instance_layer_count, + instance_layers); + if (validation_found) { + demo.enabled_layer_count = instance_validation_layers_alt1.length; + demo.enabled_layers[0] = "VK_LAYER_LUNARG_standard_validation"; + validation_layer_count = 1; + } else { + // use alternative set of validation layers + instance_validation_layers = + cast(const(char)**) instance_validation_layers_alt2; + demo.enabled_layer_count = instance_validation_layers_alt2.length; + validation_found = demo_check_layers( + instance_validation_layers_alt2.length, + instance_validation_layers, instance_layer_count, + instance_layers); + validation_layer_count = + instance_validation_layers_alt2.length; + for (i = 0; i < validation_layer_count; i++) { + demo.enabled_layers[i] = instance_validation_layers[i]; + } + } + free(instance_layers); + } + + if (!validation_found) { + ERR_EXIT("vkEnumerateInstanceLayerProperties failed to find " + ~ "required validation layer.\n\n" + ~ "Please look at the Getting Started guide for additional " + ~ "information.\n", + "vkCreateInstance Failure"); + } + } + + /* Look for instance extensions */ + required_extensions = glfwGetRequiredInstanceExtensions(&required_extension_count); + if (!required_extensions) { + ERR_EXIT("glfwGetRequiredInstanceExtensions failed to find the " + ~ "platform surface extensions.\n\nDo you have a compatible " + ~ "Vulkan installable client driver (ICD) installed?\nPlease " + ~ "look at the Getting Started guide for additional " + ~ "information.\n", + "vkCreateInstance Failure"); + } + + for (i = 0; i < required_extension_count; i++) { + demo.extension_names[demo.enabled_extension_count++] = required_extensions[i]; + assert(demo.enabled_extension_count < 64); + } + + err = vkEnumerateInstanceExtensionProperties(null, &instance_extension_count, null); + assert(!err); + + if (instance_extension_count > 0) { + VkExtensionProperties* instance_extensions = cast(VkExtensionProperties*) + malloc(VkExtensionProperties.sizeof * instance_extension_count); + err = vkEnumerateInstanceExtensionProperties( + null, &instance_extension_count, instance_extensions); + assert(!err); + for (i = 0; i < instance_extension_count; i++) { + if (!strcmp(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, + instance_extensions[i].extensionName.ptr)) { + if (demo.validate) { + demo.extension_names[demo.enabled_extension_count++] = + VK_EXT_DEBUG_REPORT_EXTENSION_NAME; + } + } + assert(demo.enabled_extension_count < 64); + } + + free(instance_extensions); + } + + + const(VkApplicationInfo) app = { + sType: VK_STRUCTURE_TYPE_APPLICATION_INFO, + pNext: null, + pApplicationName: APP_SHORT_NAME, + applicationVersion: 0, + pEngineName: APP_SHORT_NAME, + engineVersion: 0, + apiVersion: VK_API_VERSION_1_0, + }; + VkInstanceCreateInfo inst_info = { + sType: VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + pNext: null, + pApplicationInfo: &app, + enabledLayerCount: demo.enabled_layer_count, + ppEnabledLayerNames: cast(const(char*)*)instance_validation_layers, + enabledExtensionCount: demo.enabled_extension_count, + ppEnabledExtensionNames: cast(const(char*)*)demo.extension_names, + }; + + uint gpu_count; + + err = vkCreateInstance(&inst_info, null, &demo.inst); + if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { + ERR_EXIT("Cannot find a compatible Vulkan installable client driver " + ~ "(ICD).\n\nPlease look at the Getting Started guide for " + ~ "additional information.\n", + "vkCreateInstance Failure"); + } else if (err == VK_ERROR_EXTENSION_NOT_PRESENT) { + ERR_EXIT("Cannot find a specified extension library" + ~ ".\nMake sure your layers path is set appropriately\n", + "vkCreateInstance Failure"); + } else if (err) { + ERR_EXIT("vkCreateInstance failed.\n\nDo you have a compatible Vulkan " + ~ "installable client driver (ICD) installed?\nPlease look at " + ~ "the Getting Started guide for additional information.\n", + "vkCreateInstance Failure"); + } + + //gladLoadVulkanUserPtr(null, &glad_vulkan_callback, demo.inst); + loadInstanceLevelFunctions(demo.inst); + + /* Make initial call to query gpu_count, then second call for gpu info*/ + err = vkEnumeratePhysicalDevices(demo.inst, &gpu_count, null); + assert(!err && gpu_count > 0); + + if (gpu_count > 0) { + VkPhysicalDevice* physical_devices = + cast(VkPhysicalDevice*) malloc(VkPhysicalDevice.sizeof * gpu_count); + err = vkEnumeratePhysicalDevices(demo.inst, &gpu_count, physical_devices); + assert(!err); + /* For tri demo we just grab the first physical device */ + demo.gpu = physical_devices[0]; + free(physical_devices); + } else { + ERR_EXIT("vkEnumeratePhysicalDevices reported zero accessible devices." + ~ "\n\nDo you have a compatible Vulkan installable client" + ~ " driver (ICD) installed?\nPlease look at the Getting Started" + ~ " guide for additional information.\n", + "vkEnumeratePhysicalDevices Failure"); + } + + //gladLoadVulkanUserPtr(demo.gpu, &glad_vulkan_callback, demo.inst); + + /* Look for device extensions */ + uint device_extension_count = 0; + VkBool32 swapchainExtFound = 0; + demo.enabled_extension_count = 0; + + err = vkEnumerateDeviceExtensionProperties(demo.gpu, null, &device_extension_count, null); + assert(!err); + + if (device_extension_count > 0) { + VkExtensionProperties* device_extensions = cast(VkExtensionProperties*) + malloc(VkExtensionProperties.sizeof * device_extension_count); + err = vkEnumerateDeviceExtensionProperties( + demo.gpu, null, &device_extension_count, device_extensions); + assert(!err); + + for (i = 0; i < device_extension_count; i++) { + if (!strcmp(VK_KHR_SWAPCHAIN_EXTENSION_NAME, device_extensions[i].extensionName.ptr)) { + swapchainExtFound = 1; + demo.extension_names[demo.enabled_extension_count++] = + VK_KHR_SWAPCHAIN_EXTENSION_NAME; + } + assert(demo.enabled_extension_count < 64); + } + + free(device_extensions); + } + + if (!swapchainExtFound) { + ERR_EXIT("vkEnumerateDeviceExtensionProperties failed to find " + ~ "the " ~ VK_KHR_SWAPCHAIN_EXTENSION_NAME + ~ " extension.\n\nDo you have a compatible " + ~ "Vulkan installable client driver (ICD) installed?\nPlease " + ~ "look at the Getting Started guide for additional " + ~ "information.\n", + "vkCreateInstance Failure"); + } + + if (demo.validate) { + VkDebugReportCallbackCreateInfoEXT dbgCreateInfo; + dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; + dbgCreateInfo.flags = + VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT; + dbgCreateInfo.pfnCallback = demo.use_break ? &BreakCallback : &dbgFunc; + dbgCreateInfo.pUserData = demo; + dbgCreateInfo.pNext = null; + err = vkCreateDebugReportCallbackEXT(demo.inst, &dbgCreateInfo, null, + &demo.msg_callback); + switch (err) { + case VK_SUCCESS: + break; + case VK_ERROR_OUT_OF_HOST_MEMORY: + ERR_EXIT("CreateDebugReportCallback: out of host memory\n", + "CreateDebugReportCallback Failure"); + break; + default: + ERR_EXIT("CreateDebugReportCallback: unknown failure\n", + "CreateDebugReportCallback Failure"); + break; + } + } + + vkGetPhysicalDeviceProperties(demo.gpu, &demo.gpu_props); + + // Query with NULL data to get count + vkGetPhysicalDeviceQueueFamilyProperties(demo.gpu, &demo.queue_count, + null); + + demo.queue_props = cast(VkQueueFamilyProperties*)malloc( + demo.queue_count * VkQueueFamilyProperties.sizeof); + vkGetPhysicalDeviceQueueFamilyProperties(demo.gpu, &demo.queue_count, + demo.queue_props); + assert(demo.queue_count >= 1); + + vkGetPhysicalDeviceFeatures(demo.gpu, &demo.gpu_features); + + // Graphics queue and MemMgr queue can be separate. + // TODO: Add support for separate queues, including synchronization, + // and appropriate tracking for QueueSubmit +} + +private void demo_init_device(Demo* demo) { + VkResult err; + + float[1] queue_priorities = [0.0]; + const(VkDeviceQueueCreateInfo) queue = { + sType: VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, + pNext: null, + queueFamilyIndex: demo.graphics_queue_node_index, + queueCount: 1, + pQueuePriorities: queue_priorities.ptr}; + + + VkPhysicalDeviceFeatures features; + memset(&features, 0, features.sizeof); + if (demo.gpu_features.shaderClipDistance) { + features.shaderClipDistance = VK_TRUE; + } + + VkDeviceCreateInfo device = { + sType: VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + pNext: null, + queueCreateInfoCount: 1, + pQueueCreateInfos: &queue, + enabledLayerCount: 0, + ppEnabledLayerNames: null, + enabledExtensionCount: demo.enabled_extension_count, + ppEnabledExtensionNames: cast(const(char*)*)demo.extension_names, + pEnabledFeatures: &features, + }; + + err = vkCreateDevice(demo.gpu, &device, null, &demo.device); + assert(!err); +} + +private void demo_init_vk_swapchain(Demo* demo) { + VkResult err; + uint i; + + // Create a WSI surface for the window: + glfwCreateWindowSurface(demo.inst, demo.window, null, cast(ulong*) &demo.surface); // todo: ugly cast + + // Iterate over each queue to learn whether it supports presenting: + VkBool32* supportsPresent = cast(VkBool32*)malloc(demo.queue_count * VkBool32.sizeof); + for (i = 0; i < demo.queue_count; i++) { + vkGetPhysicalDeviceSurfaceSupportKHR(demo.gpu, i, demo.surface, &supportsPresent[i]); + } + + // Search for a graphics and a present queue in the array of queue + // families, try to find one that supports both + uint graphicsQueueNodeIndex = uint.max; + uint presentQueueNodeIndex = uint.max; + for (i = 0; i < demo.queue_count; i++) { + if ((demo.queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) { + if (graphicsQueueNodeIndex == uint.max) { + graphicsQueueNodeIndex = i; + } + + if (supportsPresent[i] == VK_TRUE) { + graphicsQueueNodeIndex = i; + presentQueueNodeIndex = i; + break; + } + } + } + if (presentQueueNodeIndex == uint.max) { + // If didn't find a queue that supports both graphics and present, then + // find a separate present queue. + for (i = 0; i < demo.queue_count; ++i) { + if (supportsPresent[i] == VK_TRUE) { + presentQueueNodeIndex = i; + break; + } + } + } + free(supportsPresent); + + // Generate error if could not find both a graphics and a present queue + if (graphicsQueueNodeIndex == uint.max || + presentQueueNodeIndex == uint.max) { + ERR_EXIT("Could not find a graphics and a present queue\n", + "Swapchain Initialization Failure"); + } + + // TODO: Add support for separate queues, including presentation, + // synchronization, and appropriate tracking for QueueSubmit. + // NOTE: While it is possible for an application to use a separate graphics + // and a present queues, this demo program assumes it is only using + // one: + if (graphicsQueueNodeIndex != presentQueueNodeIndex) { + ERR_EXIT("Could not find a common graphics and a present queue\n", + "Swapchain Initialization Failure"); + } + demo.graphics_queue_node_index = graphicsQueueNodeIndex; + + demo_init_device(demo); + loadDeviceLevelFunctions(demo.device); + vkGetDeviceQueue(demo.device, demo.graphics_queue_node_index, 0, &demo.queue); + + // Get the list of VkFormat's that are supported: + uint formatCount; + err = vkGetPhysicalDeviceSurfaceFormatsKHR(demo.gpu, demo.surface, + &formatCount, null); + assert(!err); + VkSurfaceFormatKHR* surfFormats = cast(VkSurfaceFormatKHR*)malloc(formatCount * VkSurfaceFormatKHR.sizeof); + err = vkGetPhysicalDeviceSurfaceFormatsKHR(demo.gpu, demo.surface, + &formatCount, surfFormats); + assert(!err); + // If the format list includes just one entry of VK_FORMAT_UNDEFINED, + // the surface has no preferred format. Otherwise, at least one + // supported format will be returned. + if (formatCount == 1 && surfFormats[0].format == VK_FORMAT_UNDEFINED) { + demo.format = VK_FORMAT_B8G8R8A8_UNORM; + } else { + assert(formatCount >= 1); + demo.format = surfFormats[0].format; + } + demo.color_space = surfFormats[0].colorSpace; + + demo.curFrame = 0; + + // Get Memory information and properties + vkGetPhysicalDeviceMemoryProperties(demo.gpu, &demo.memory_properties); +} + +private void demo_init_connection(Demo* demo) { + glfwSetErrorCallback(&demo_error_callback); + + if (!glfwInit()) { + printf("Cannot initialize GLFW.\nExiting ...\n"); + fflush(stdout); + exit(1); + } + + if (!glfwVulkanSupported()) { + printf("GLFW failed to find the Vulkan loader.\nExiting ...\n"); + fflush(stdout); + exit(1); + } + + //gladLoadVulkanUserPtr(null, &glad_vulkan_callback, null); +} + +private void demo_init(Demo* demo, const(int) argc, const(char)** argv) { + int i; + memset(demo, 0, typeof(*demo).sizeof); + demo.frameCount = int.max; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "--use_staging") == 0) { + demo.use_staging_buffer = true; + continue; + } + if (strcmp(argv[i], "--break") == 0) { + demo.use_break = true; + continue; + } + if (strcmp(argv[i], "--validate") == 0) { + demo.validate = true; + continue; + } + if (strcmp(argv[i], "--c") == 0 && demo.frameCount == int.max && + i < argc - 1 && sscanf(argv[i + 1], "%d", &demo.frameCount) == 1 && + demo.frameCount >= 0) { + i++; + continue; + } + + fprintf(stderr, "Usage:\n %s [--use_staging] [--validate] [--break] " + ~ "[--c ]\n", + APP_SHORT_NAME.ptr); + fflush(stderr); + exit(1); + } + + demo_init_connection(demo); + demo_init_vk(demo); + + demo.width = 300; + demo.height = 300; + demo.depthStencil = 1.0; + demo.depthIncrement = -0.01f; +} + +private void demo_cleanup(Demo* demo) { + uint i; + + for (i = 0; i < demo.swapchainImageCount; i++) { + vkDestroyFramebuffer(demo.device, demo.framebuffers[i], null); + } + free(demo.framebuffers); + vkDestroyDescriptorPool(demo.device, demo.desc_pool, null); + + if (demo.setup_cmd) { + vkFreeCommandBuffers(demo.device, demo.cmd_pool, 1, &demo.setup_cmd); + } + vkFreeCommandBuffers(demo.device, demo.cmd_pool, 1, &demo.draw_cmd); + vkDestroyCommandPool(demo.device, demo.cmd_pool, null); + + vkDestroyPipeline(demo.device, demo.pipeline, null); + vkDestroyRenderPass(demo.device, demo.render_pass, null); + vkDestroyPipelineLayout(demo.device, demo.pipeline_layout, null); + vkDestroyDescriptorSetLayout(demo.device, demo.desc_layout, null); + + vkDestroyBuffer(demo.device, demo.vertices.buf, null); + vkFreeMemory(demo.device, demo.vertices.mem, null); + + for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { + vkDestroyImageView(demo.device, demo.textures[i].view, null); + vkDestroyImage(demo.device, demo.textures[i].image, null); + vkFreeMemory(demo.device, demo.textures[i].mem, null); + vkDestroySampler(demo.device, demo.textures[i].sampler, null); + } + + for (i = 0; i < demo.swapchainImageCount; i++) { + vkDestroyImageView(demo.device, demo.buffers[i].view, null); + } + + vkDestroyImageView(demo.device, demo.depth.view, null); + vkDestroyImage(demo.device, demo.depth.image, null); + vkFreeMemory(demo.device, demo.depth.mem, null); + + vkDestroySwapchainKHR(demo.device, demo.swapchain, null); + free(demo.buffers); + + vkDestroyDevice(demo.device, null); + if (demo.validate) { + vkDestroyDebugReportCallbackEXT(demo.inst, demo.msg_callback, null); + } + vkDestroySurfaceKHR(demo.inst, demo.surface, null); + vkDestroyInstance(demo.inst, null); + + free(demo.queue_props); + + glfwDestroyWindow(demo.window); + glfwTerminate(); +} + +private void demo_resize(Demo* demo) { + uint i; + + // In order to properly resize the window, we must re-create the swapchain + // AND redo the command buffers, etc. + // + // First, perform part of the demo_cleanup() function: + + for (i = 0; i < demo.swapchainImageCount; i++) { + vkDestroyFramebuffer(demo.device, demo.framebuffers[i], null); + } + free(demo.framebuffers); + vkDestroyDescriptorPool(demo.device, demo.desc_pool, null); + + if (demo.setup_cmd) { + vkFreeCommandBuffers(demo.device, demo.cmd_pool, 1, &demo.setup_cmd); + demo.setup_cmd = VK_NULL_HANDLE; + } + vkFreeCommandBuffers(demo.device, demo.cmd_pool, 1, &demo.draw_cmd); + vkDestroyCommandPool(demo.device, demo.cmd_pool, null); + + vkDestroyPipeline(demo.device, demo.pipeline, null); + vkDestroyRenderPass(demo.device, demo.render_pass, null); + vkDestroyPipelineLayout(demo.device, demo.pipeline_layout, null); + vkDestroyDescriptorSetLayout(demo.device, demo.desc_layout, null); + + vkDestroyBuffer(demo.device, demo.vertices.buf, null); + vkFreeMemory(demo.device, demo.vertices.mem, null); + + for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { + vkDestroyImageView(demo.device, demo.textures[i].view, null); + vkDestroyImage(demo.device, demo.textures[i].image, null); + vkFreeMemory(demo.device, demo.textures[i].mem, null); + vkDestroySampler(demo.device, demo.textures[i].sampler, null); + } + + for (i = 0; i < demo.swapchainImageCount; i++) { + vkDestroyImageView(demo.device, demo.buffers[i].view, null); + } + + vkDestroyImageView(demo.device, demo.depth.view, null); + vkDestroyImage(demo.device, demo.depth.image, null); + vkFreeMemory(demo.device, demo.depth.mem, null); + + free(demo.buffers); + + // Second, re-perform the demo_prepare() function, which will re-create the + // swapchain: + demo_prepare(demo); +} + +extern(C) int main(const(int) argc, const(char)** argv) { + Demo demo; + + loadGlobalLevelFunctions(); + + demo_init(&demo, argc, argv); + demo_create_window(&demo); + demo_init_vk_swapchain(&demo); + + demo_prepare(&demo); + demo_run(&demo); + + demo_cleanup(&demo); + + return validation_error; +} diff --git a/examples/triangle-vulkan/dub.sdl b/examples/triangle-vulkan/dub.sdl new file mode 100644 index 0000000..6438651 --- /dev/null +++ b/examples/triangle-vulkan/dub.sdl @@ -0,0 +1,13 @@ +name "triangle-vulkan" +description "opens a GLFW window and draws a triangle using Vulkan" +authors "dkorpel" +copyright "Copyright © 2021, dkorpel" +license "Zlib" +targetType "executable" +targetName "triangle-vulkan" +targetPath "../../build" +dependency "glfw-d" path="../../" +dependency "erupted" version="~>2.1.12+v1.2.162" +sourceFiles "app.d" +versions "VK_VERSION_1_0" +//buildOptions "betterC" diff --git a/examples/triangle-vulkan/screenshot.png b/examples/triangle-vulkan/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..794f6739708379958dd943b684f2cb0696019186 GIT binary patch literal 9953 zcmYjXc|4Tg_a8eUlzk^HWXKZA7Aad=rjS8}tYeR{jeSiFNz{n43xgOln6hU1BzuO8 zu_mOkB*yOdOyBW({r;F2@AKSq&ikIbJoh>0KD~X@kn@=EF%SsEX>4Qw0fFdjfL{PB zGay+EUH=aJVe>Y!dIAD*zX5*!bnkt9pMyY>AY%i)dx3ArBx1^`?{?y=D{t-!@GA~! z6N#tL7<~1a1j6#u@~*P3o6?=I=BLs>>@~X1L}dSv3Q|tpV+mT&l}`E3l$((*y;yMd z`W^cuDW>D825Tn2o=cx+cfFVfFD?#f$Z{uaym=9C|G`-8`$ttP`Lszc!M~|ygxJU7 zd%vnm&s7QAUmH3tE%(fJlX0&4tdW7itdjTB1e4ZgK*+|BnNT9rd)YY*f%wWbl2CH5 zv$NCm@PfNV8S6)pp*OtcXV0GHu#uJ<&NocyU|x=qeBh>`sJY7Mt@7wB)6(LiEMUOI zKQK^3&A>1^P%?wP>fxdlc@oWk1>)d!l}kJavG%2N=i^R?piEcO^EUtq% zcR3p=$Vt#ZGJ#}_mEnynEG!)M($LbHnwk%Ki$OU|ph-%6m;_^_hg#O=C(1+(+M*j7 zqu?DsWot5pj3X~DzE7IHFJmmtd=4r}sv_lQ z$~FF>XR{@m<AeD#Sxvt!zZ;uHowZ3El$XKcV4vaTmRPH9(ye6ij&nD3?c79CHvIn+lJvc zPcYIkyh`|aB5oS3cb{?f5%>8*cO0?SM0QC7$=TM=sP||_gHYMHQ~JPSC|kY1V>#J7 zF!0=4ozPOmq$TK$2C{HvSK0W45MyLNlpS4rp@Vgj6077?wA~x5DV-OU?pq|84jI!x zqSFWE3d#Yg zc8#Z@y{YB(xk67{ab^V`Gi6!tS^|8W9K(H8udG%LIqL#LGp7nU*rWZm3>PLYdC$9H z^%GE#(j3RvmFa)VYb&_*UC}SoA;Jy?5R?0`Sf%UybiXvVc{=hVzeJqQ3rc48^10Mq zeK0rkR;lC1z~dx{i8ZX2Te_!O-rrVz5E?MgVLO#El`ZS-?143T-+-e`;n#Hy3=D=} z*l6vtv&SrdZWhxH>KVOzp5J*lG0(+iL{YY|d}K+kTNwzG6)cpiIed?D2sbV>HNc36 z9|jzDp#fqtylcsO!w$`7oR)C2_*CAx)>j#tgs+_HiPAiAxf&W8+?JM>=a7=mX758` zg|!y4g}fla8mw29q%>4mD&|Y|4IzgDrR&Ukk`1Ja3mpm3(a|%Ewkj+WK%hKuhK7b3 z+S*L1Z`t)s*wD4BTDO4pR+tWfk=Sk2Y^2AIAt5Hmq#h4=FKsk%>;LU^Wr^pzdGn^X zb+_$;hy)aE(F9@OCO~s*Gax2xHzXic1nHY69zzwCLo`fUC|VrlDm>&WPru3C%&yKwzc;Kw${__7 z#K7m1l=1=w!E{$X`)H{mH9dj@4sNPAB&9<54O2JhDVuRwkH5FtvH#$_^j~$ogqHM} zxR2;;+t9oUr`>g*q_+oq42a*WbM=X+-(;zNSVMqky$X{j@3p+4#e@lUwZG24cEb)~ ze#|MyvK)X% zLiLDZnH)HDv_g@V;-alS&MPPaR4V4mN`ZCWD`!-Z{UC1SM)fx@@+Tdo9x~bgf;VMl zvh!`&QuyrdG}o!CGcG-vjO|A!d6&wAv4MTPSN;O&jW-Hyp+gpeZ1-Mj_D)vxwhw(TE_Y zHxu$nN?Y4CcgH93>T0~Y8lgzkirwMFr`JW9x)0jAoqPUd1PEw_gvI^XDZg_YB3&}< zT{-+CzVh_5JXX-{vSI#)aM8|$7mpV%ThhPgxo|4?d~C$2$Zw$b32UD;$zyG=mgDfi$aaRJLpgRZJS(t8z#VWQQMMnqiHE$?!>1e93=f%_ zwhNnLEKzKE&s}e1ae+Sig>$t(@gC;nX;(TPY{mmBNZVJBuqskNN%sxGWl7?$9b0{Y zDv+&~zgiXGh1~wWM+%zSN+Lp0g#Gp6@Vb6<%6o_Jvp|b}E?p_GuIb+Cu*!1oM z8ux6LQJ*z%f~2GVG*3_>`ymMQU~Ce9Lhvho+BCg@O?KK5uNWV(izO1ZUg;D_#{Bkz@N(IBt<)Y=--ppj_1FKJ zDHUlIWGLi?CU^9+-+?7}!&!_``mD_q1O{bh6tvFve%LM0CoEER`1Y^hFp?+hh|jz9 zD8lxu!To*ht%(hUf~MGGSAv9o6@QhWxc-Nq!TX9tkI%-5(Yw2;5NYERehs#dU&qz* zS1e6EsA1~71Bxi~6mUhgtZUi$<4=xIDrRK#il4;ZfEh^vXE#)G@F7JaN2l}PQ^-P` z-HH-l2@72mlruA1Els9Lp=3_)`@;a(z_N{0q5}}ybFtU+kz?TG)8Pe-F{!udZ#PCM zF_U}E4}JDl|6V%2ypk_+oi(2|%EPO9xnT8LMO2pdIWClJE_-B_B@IF2C* z?)Be*ftghvi=TI`yBp6N+(gL<#^W;)jOquM(#DpmI=(g;lR~Dv#`~ZyXr4~CO=~c#Y(F_pqv_-4 z?oZq`gqh#%m)vsVfq|$Z%v6(Fw&$3ZQ-p+9MOjQtV(b#GYcKS4NGI8=ifkaZp9!=s ztVYyU2|giBrAGCPG=&ad6P*wLX8(xvs}_35wURf~;<&pLi<}7S?-2f7i%Qj>krRC| zi8ra?n4cGLxtO)8E%2I9=YpfVugV-}r7-4!5#|II#b=+W&0+HurLz2C7fCY}8w}A~ zY&iVxhJSCZs~GeQver)RS>;4(|*Zj zq{TEOBm&f67gHlJuTj^;H5^jjtEgaCzBs9vWbao|G1btE9(p^!U0pRgiD$V#l{eI3 zsMrh4kNt_NF30&}0-2c_qfHZ0SsnhO0DEBA94Z~Xw8DJSrt(NF56aj^eE7vXgx?@X zi1-EU_Qdt2weAao4b4BQz(pUBQuT$u`7ORJ&xnQpO4YCQ`qo65q789`tga?k8+n*5h*VY{w{schJv6j&m z^}ia}$THbiJg0H&;-sNqJ1eu=snEXI`MJt0XiuBDV5@)j!M;{sVqCD2$1@ zOA*OQS-vTmz!?pu99ne5DZxJBQ%*{iwLi=XUpo(N=kd-zga zsxZdj*lAS^p?|EoF}LXFgBldcq6F zido4dhq?+Pv9M>8VMJI{b#h6Haj2;^ahho06D4Cj;LaE{dVEj8_^yGEFNrajTv68} zzZ7C=mCw&KLN&KT#S*DgFj}=o7i4}4=aX*0+j;U~2>&+W+FFNfOvFlk z2}^D6ZXHs%;fg|mHHTAI?+z6E$@BR9`B&xY>n)e?FrZvLH%pgJ^E7*XHp;PUT|U` z7abDI?zntYuPVKn9NX3W;Mm=Xs9>%u6qSbt>meyVDLjst9#1Kg&z| zx>bmeAD&&m9c@XGOg+>KXqevEcea|;tOg-Qu8})lt*#>0?YK1&hMEVLs-3pX+yd*B zHg{TfLn@xV`+4<>O$y$cgK2R=)jd4W`RiVh{Lqx|E!074UuG@0{Z>O>m6e0QW$t0~ z<4`?L@=XCye<_Ri%O~?AZJ5QnFM4Hy@GM80TFQ3kyOt_2J>2_7fT~}%&`6oG1d8MY zHCMFI+4-h8+x~FZaP)99yfr0!i?L~I&2a0lBH|dtWDni69^m8S6Uh~Jpt83paYz?N z@oJ15UGtd>J!T^NO6aGG+u#IiJ9lT@qE(hxoQdr70wMX|$(!CpU*0wzNJlEF&mrmM3D5ErrRRxWntI1+oRa+oQP`tF9cr;fub?J4B#Vq^EBq zygpix`=3oFeXYbXj3-aOn7KT_{zb-g`p4N~hSU_Hln{58;`0U{ZWW0UgFC>t);^|q z7CA%bJ%%6P{<9Z41{Jx&q1&53^ziStvcrRJ=A!WI`>XxobLUi}pofP6q2M20?)Ja@ z5<5LIw(F7lZ*0Q7&ve9i=%AOBNZ)LlWao!o?Ln;y`NXy^%zD}(<2SRyMb1iu#jxn^ zOKfF_SQ<4xi3~h6A7_VdIX?^*QVjcZ_w&r*On4X$d29cdZcKV9MJl7^qv06eZq0-! zFvij8R(k{LUfw!067K)+b(`5ZTi_XJrf0xVsKrRI*pT z_fHmxj@~oyG4raYpX@XjluEMS${`XzW4e?%WtlKa`vUVDXMX+N5PK<+nUl-&O)}=n zn*yVnrSA4KKKVI^AA&2Q%PxEosav`tIT=&ab@-@aq%A2_C$3_t_O=5DGsA8|h@iK3;Rp#vmnZ8a5dWf?LIdz-816pwE()76?htX2`^JAuV zSW+uUGRYpX@66V?1#3zX;FQ>1RQWc`easf~VAt^@@zUr2xWYIn?R*ml?g4i zbu;pR1~2@oqm0$u3ct!a*H z!qVv7&q*7c@e&0VVar4r{+xK5W=oQJNrSLB4n24B&RB4Gli9J*hU0sf* zPai1Hzspa@Q!eBzWT4}RVa%F;gKtj$qomknkL}Hr$9xN7R-?r8j$g%P9j&`l=|LJ5 zQ7Y9!7gMrF-Sd*|o`*+V-s)T~nP{v*WLM;X(m@eEENAY`U%KC;7Ie)5St4%&avRT~ z+p~U07oh8slaS!_|1zjRiZn0n0yV8V^N5LsPG|40;@`ujNll{mfHGUy)~)lv3EQ6U z1=;!c7m;Ow3B;4(8cFGf8ug~Co${GfdY(JRCTuoX8|l(& zNPk{@&FP+Gd-9TH%`vG{S4Bk2dbUvz(TKpKl(?qnUHi#cZQin|g^pPAr7G?)8F=ymBg&&Wh31)c%5GMlODxf27*_s}GI zK5Do<%>Qe4>^_}`FR{ln$qCmP7!XUU|G9it;s!`Wsgk0>f0FeQUqB*Gl@$E>C#fk3 z#xto&0wacPzs{&&t-wQaIynZelA;pgR6Fy}{Tnk^Tr)G(eG#$bpEJEIfDk7;;NA@D z^UqN8&syt83_up#<*vtLDn&BZ%pKPp2c#DV&Ww#xwZ_b{#sID3RIQo;susptt)4_L zLM4>-c$Og(oav(O4iLgp38}SPPzepdiE(gtcjKuOJRVVK>g>oPW58to(L5k=U)q2^ z_D@o621u%@l4>;jKS`AbAfZmp(o!@BRnmh^1|)-2NgkT>p9F&jBr{YA3Vr;aq`C)? z{Gm$H&|Lo{Rb)UCNtGmKvr;8)#8^1{ZzF(@c}p*q;hl?Q6Fd|A9Kf02QA`i?q67+m zPomf42l};yc|z^!Jx)BqGg6E?VE*6#4H&f27Kjg$8lTI*-Kh~ncUEAnAH`Ek5$>8| z)TuBxHV3#01YEszou`JUL=->aNeAfMaTTn4)O{Ly5la;PSG(XC7YDcvKf-_N0Js7L zjQ|i3JKqna;|^5ym`KeiAi9@EJ-zH{m>GCZsv;pfY3=C&{q`!-O`1N1A0V)9hyNr- zvoAa9`_!oou6cxos^(6RkYu`52anr*#O==w6Q@ zk9uZC19SD>3FhUrs<}a|J^o)xo9e(6AViEK!|Q1V6ojl5JlL_sxg!JgfPuwPPs<|% ziGYD3zdp;5a&LqT=;h{(VfF8e0Cc{4+VW0yq zf#>@)Yyk{0TA1i@k>(%GinW3AVTr%I37}c3-)c1We9DfuqPf4teJ)U%fMn|33 zdU+YZN8wW!1h5^RBg_b3K>sMbI931y`U*$SIRFgk z>l|Tj>*b$-{>>u{`2Pv$KRCjG|DS-q=Me_{{{-~IXc$;=o*N%X%gnU!0xJ&JFzOk= zLR&y$tr^zZ?l^obZN4Jyy3xn6L{b}V0kV9UtB@d)J!uORpFiq55>JK)(8`n~JNNoI zfS$*ZJ5g)Tpi$4K|Ffp>VJ;(roB^Wx2KENV2ynp5QP20y|FfOBGwPd}Le5~O*(#KB zukUVyo95F-ZjjTxKA;nBI!hb5!Vjaq0sww-grAQ3&I1@n8#z;)eRsAP5o|`|o>>H7 zBss&Wh33zxHA7Q~2<}OwvFk|!Q_f(mQM6dtpxCXKF9KNLf3dMaiC8NT!QePrbMWKL zfA~lp>@GmXBqmz(h8MPO_3k)7OIj=zd*Qir)uch?Bff>BKQp@F!0e{+$#D9ggOfA^ z&{7Yo0nE`{a$Us!Gaz?l;N|EKs)4fV^k$&CCKY4bfdSs~d?E_yuV=6}SZnBM+9+cn zS>JrWd%6x&Ly5cp)A=5U4Yc0O1+acEuAZLq`}bG+h=0|?!t`;K$OL#?`XEqBdpNzV9k#M9(%JJqctO4j?WR#22AtHuLU1J!q1HZTkKx_hN^wSa3m;&^@YmU{Ak?e9QdgHDUG2Gr1=+R>cE+E0&%Cb{n`hCnB%E;0ZL>zY)aoaVu0?H zN;|(kc~XCMuO7oYq>rPYzi<{MB0_yfWSppTMd`ylzI#7)$&%L`8l@gAedn8BLN>EJ zG8_XQN=xS@a#L%cW<$J?FPb=8HQ@c42ISUFWZ7-h$7d%0@Fyp@d`d*arDDLsp3g&{ zJ!%79j{n*0P6y{W+m6(BHRX4j$O0w8RjocK?Aa1<3~Fu8z$fRi)#H!28hH`7`hQjH4Xr-FdR9*n zIhlO3Hl0C&nZIk?KiI&)T&hs@TCUAvBo}b*-5kg_++1Dlr{C7__!23#uu3h=;;z@&(4R|9rVMhE4_Eos~g zXPJ^Qc1INv1oK})f}bz)@R&b`n20!F2xE_}oV5B>n*Eu3VSlgI*h|xQSuYd4n!t$< z)w0Y&!onuFh!;4}^Fc+Dg&%#CV-I&G4_uzlNlTYTmAlkKOisq-nwwa`z`eb_zoS{W zc4l!7W8~!9IrwRynCm^p9B0wa z56RctFi`N2yV|^4!wY&`(|H3Wq-I00KC0+4(qRZzciC*{p2=(Z274e(rwVTjs+uJ$ zHCU7_Y9P%}MfQp&Q988T0Gw6s)RahKn3ffAj&yE=XK zjw(sUIPuZO3z;>s&b1_^c7GEX7?^=oOc6x-fWJGXw@u7_>wyoTQWl-$9QZqp_knBS zvV{Xs0X)_X^g3M`DA%uPDXMjR7Gxt*Cc`Ji#l=y;C6C?V$}oSwfYDe6N(Xr&Y}X?Q z2&X5kp>YKddLv_;KC1!w-`xdjLHXLdhKejjl2Nm;gP^+shBtaXgznGEBY6b@!&JUV zB5}hsU!ckrb;jg9Z%r)uoBEsjzQWaofm0#AXBL-UCPEjJ}rIMIu8+oD#$vn)r2Qnb^6>`fp`3ce>68K zGqwNG#g@{awYpY&dnv>N)5Bkq?=vxPRW z=d34*r)dTTt#Ukqm@Eb57^i*a#eXbvEzLhS$R)1TAK;3Ojinb5JWd)Ky1TuzRQb$4 zu*FC8rQ_>_+53bg|J+&yVRC<;B&%SR0fxU_k0biw>yw=y)oI3&fVtCd^QDaRn|U)${AmtYEZw6>WvknYGNyVSt?zV zN#R1{Vw~N%F)~&QxHmSr`A?sK(L$-{-#GUiY$LWj*du z$BV>PTLw?}q0p_>+y%eO(i~UmKt7^eOkO;nf$tPwI9!bv)3{;{VvTABmiO+D|4z!6 zedh-@;pU$H^KzDfAKNB53(LZ1g%@#c3J-E+4F zV;$9qt Date: Thu, 1 Apr 2021 19:56:39 +0200 Subject: [PATCH 13/17] add vulkan triangle example to Github Actions --- .github/workflows/d.yml | 3 +++ examples/triangle-gl/dub.sdl | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/d.yml b/.github/workflows/d.yml index c40b048..3484dea 100644 --- a/.github/workflows/d.yml +++ b/.github/workflows/d.yml @@ -27,3 +27,6 @@ jobs: - name: Build OpenGL triangle example run: dub -q build glfw-d:triangle-gl + + - name: Build Vulkan triangle example + run: dub -q build glfw-d:triangle-vulkan diff --git a/examples/triangle-gl/dub.sdl b/examples/triangle-gl/dub.sdl index bc0f319..428349f 100644 --- a/examples/triangle-gl/dub.sdl +++ b/examples/triangle-gl/dub.sdl @@ -4,7 +4,7 @@ authors "dkorpel" copyright "Copyright © 2021, dkorpel" license "Zlib" targetType "executable" -targetName "glfw-example" +targetName "triangle-gl" targetPath "../../build" dependency "glfw-d" path="../../" dependency "bindbc-opengl" version="~>0.13.0" From bb5a4d15bc5977d3fe6f25c561fd48f9b26e4bb1 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Thu, 1 Apr 2021 20:02:21 +0200 Subject: [PATCH 14/17] fix missing init symbol from linuxinput header --- dub.sdl | 1 + 1 file changed, 1 insertion(+) diff --git a/dub.sdl b/dub.sdl index f660d20..293a119 100644 --- a/dub.sdl +++ b/dub.sdl @@ -46,6 +46,7 @@ configuration "x11" { sourceFiles "source/glfw3/egl_context.d" sourceFiles "source/glfw3/osmesa_context.d" sourceFiles "source/glfw3/linux_joystick.d" + sourceFiles "source/glfw3/linuxinput.d" // missing symbol on ubuntu-dmd-2.085: glfw3.linuxinput.ff_effect.__init } configuration "windows" { From 873ec36174ea8c6f2518ccee54e2d1551c0cb41c Mon Sep 17 00:00:00 2001 From: dkorpel Date: Thu, 1 Apr 2021 20:06:59 +0200 Subject: [PATCH 15/17] fix function is not accessible from module --- examples/triangle-vulkan/app.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/triangle-vulkan/app.d b/examples/triangle-vulkan/app.d index 85c06e5..8007d88 100644 --- a/examples/triangle-vulkan/app.d +++ b/examples/triangle-vulkan/app.d @@ -3,7 +3,7 @@ /// https://github.com/glfw/glfw/blob/33cd8b865d9289cfbcf3d95e6e68e4050b94fcd3/tests/triangle-vulkan.c module app; -package: nothrow: @nogc: +nothrow: @nogc: import glfw3.api; import erupted; From 9c3fdb3f750dd0a72c4e081f758f626b3251c966 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Thu, 1 Apr 2021 20:28:55 +0200 Subject: [PATCH 16/17] update README --- README.md | 34 ++++++++++++++++++------------ examples/triangle-vulkan/README.md | 2 ++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bb90ef2..8d07bf8 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,12 @@ The translation is not affiliated with the original project. If you are using dub, add this package as a dependency. In `dub.sdl`: ``` -dependency "glfw-d" version="~>1.0.1" +dependency "glfw-d" version="~>1.0.2" ``` In `dub.json`: ``` "dependencies": { - "glfw-d": "~>1.0.1" + "glfw-d": "~>1.0.2" } ``` @@ -45,14 +45,16 @@ void main() { } ``` Example GLFW projects can be found in the [examples folder](https://github.com/dkorpel/glfw-d/tree/master/examples/). -You can run them from the root of the repository using: +You can run them from the root of this repository using: ``` dub run glfw-d:empty-window dub run glfw-d:triangle-gl +dub run glfw-d:triangle-vulkan ``` -Note that you probably want to use OpenGL / Vulkan bindings ([bindbc-opengl](https://code.dlang.org/packages/bindbc-opengl) or [erupted](https://code.dlang.org/packages/erupted)) in order to actually display anything in your window. -See also: the [tutorial on glfw.org](https://www.glfw.org/docs/latest/quick.html) +See also: the [tutorial on glfw.org](https://www.glfw.org/docs/latest/quick.html) for a quick introduction. + +If you have any trouble, feel free to open an [Issue](https://github.com/dkorpel/glfw-d/issues) or [Discussion](https://github.com/dkorpel/glfw-d/discussions). ## Reasons for using it Using GLFW in your D project usually involves depending on a binding to the C-library, (such as [bindbc-glfw](https://github.com/BindBC/bindbc-glfw) or [derelict-glfw3](https://github.com/DerelictOrg/DerelictGLFW3)). @@ -69,7 +71,7 @@ It's very easy for issues to arise: With this translation, you can simply use Dub, and your D compiler settings (C runtime, optimization flags, debug info) also apply to GLFW. Compile times are pretty short. -I get these results from the 'total' time of `time dub build glfw-d --force` on Debian Linux: +I get these results from the 'total' time of `time dub build glfw-d --force` on my Debian Linux box: | build type | time (s) | |--------------|----------| @@ -84,13 +86,13 @@ Dub caches builds, so these compile times only apply the first time. - The C sources are more battle-tested. There is a chance the translation introduced new bugs. - While GLFW is pretty stable, it is still being maintained by a group of contributors and new releases with new features and fixes come out. -Once GLFW 3.4 comes out, this translation will lag behind for who knows how long. -However, you can always switch back to compiling the C sources. +Once GLFW 3.4 comes out, this translation might get behind. +However, you can easily switch back to compiling the C sources if this becomes an issue. ### Todo - Thoroughly test on platforms So far I used this library for my own OpenGL application and succesfully ran it on Debian Linux with X11 and Windows 7, but there are aspects that are not yet tested. -I have not used this with Vulkan or OpenGL ES. +I have not used this with OpenGL ES. I haven't used the native api (`glfw3/apinative.d` here) or functions for custom cursor creation yet. - Add Wayland support @@ -147,13 +149,18 @@ versions "GLFW_EXPOSE_NATIVE_WIN32" "GLFW_EXPOSE_NATIVE_WGL" If you don't want to use dub, it is not hard to compile it manually since all source files you need are in a single folder: `source/glfw3`. Look in `dub.sdl` which source files and version identifier your desired platform uses, then pass them to a D compiler: ``` -# from the root of this repository +# From the root of this repository, enter the source folder cd source/glfw3 + +# Windows example: dmd -version=_GLFW_WIN32 -I../ -m64 -lib -of=../../build/glfw.lib context.d init.d input.d monitor.d vulkan.d window.d mappings.d internal.d api.d win32_platform.d win32_init.d win32_joystick.d win32_monitor.d win32_time.d win32_thread.d win32_window.d wgl_context.d egl_context.d osmesa_context.d directinput8.d + +# Linux example: +dmd -version=_GLFW_X11 -L=X11 -I../ -lib -of=../../build/glfw.a context.d init.d input.d monitor.d vulkan.d window.d mappings.d internal.d api.d x11_platform.d x11_init.d x11_monitor.d x11_window.d xkb_unicode.d posix_time.d posix_thread.d glx_context.d egl_context.d osmesa_context.d linux_joystick.d linuxinput.d ``` ### BetterC -Since it's a direct translation of a C codebase, it might compile [with `-betterC`](https://dlang.org/spec/betterc.html), but there might be linking errors because of certain C macros that are functions in druntime, such as: +Since it's a direct translation of a C codebase, it compiles [with `-betterC`](https://dlang.org/spec/betterc.html), but there might be linking errors because of certain C macros that are functions in druntime, such as: ``` core.sys.posix.sys.select.FD_SET core.sys.posix.sys.select.FD_ZERO @@ -161,6 +168,5 @@ core.sys.posix.sys.select.FD_ZERO This might or might not give linker errors in your application, depending on your compiler and settings. ## Building a shared library DLL -Building a shared library from the D sources should be possible, but I haven't tried it yet. -It may be as simple as adding `export` to functions that had `GLFWAPI` in the C sources, and adding a configuration with `targetType "sharedLibrary"` in `dub.sdl`, -but it also may be more difficult than that. +Building a shared library from the D sources could be possible, but it's not a supported use-case currently. +You're welcome to try it, but I can't guide you here. diff --git a/examples/triangle-vulkan/README.md b/examples/triangle-vulkan/README.md index 325814f..d34385f 100644 --- a/examples/triangle-vulkan/README.md +++ b/examples/triangle-vulkan/README.md @@ -16,3 +16,5 @@ From the root of the repository, run it with: ``` dub run glfw-d:triangle-vulkan ``` + +See also: [the GLFW Vulkan guide](https://www.glfw.org/docs/latest/vulkan_guide.html) From 49556dddef3f9781f727e25e3b81ec78c8d57480 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Thu, 1 Apr 2021 20:29:50 +0200 Subject: [PATCH 17/17] fix Vulkan errors of non-dispatchable null handles --- examples/triangle-vulkan/app.d | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/triangle-vulkan/app.d b/examples/triangle-vulkan/app.d index 8007d88..9a39272 100644 --- a/examples/triangle-vulkan/app.d +++ b/examples/triangle-vulkan/app.d @@ -400,7 +400,7 @@ private void demo_flush_init_cmd(Demo* demo) { signalSemaphoreCount: 0, pSignalSemaphores: null}; - err = vkQueueSubmit(demo.queue, 1, &submit_info, VK_NULL_HANDLE); + err = vkQueueSubmit(demo.queue, 1, &submit_info, VK_NULL_ND_HANDLE); assert(!err); err = vkQueueWaitIdle(demo.queue); @@ -623,7 +623,7 @@ private void demo_draw(Demo* demo) { // okay to render to the image. demo_draw_build_cmd(demo); - VkFence nullFence = VK_NULL_HANDLE; + VkFence nullFence = VK_NULL_ND_HANDLE; VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkSubmitInfo submit_info = {sType: VK_STRUCTURE_TYPE_SUBMIT_INFO, pNext: null, @@ -764,7 +764,7 @@ private void demo_prepare_buffers(Demo* demo) { // swapchain at this point. // Note: destroying the swapchain also cleans up all its associated // presentable images once the platform is done with them. - if (oldSwapchain != VK_NULL_HANDLE) { + if (oldSwapchain != VK_NULL_ND_HANDLE) { vkDestroySwapchainKHR(demo.device, oldSwapchain, null); } @@ -845,7 +845,7 @@ private void demo_prepare_depth(Demo* demo) { VkImageViewCreateInfo view = { sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, pNext: null, - image: VK_NULL_HANDLE, + image: VK_NULL_ND_HANDLE, format: depth_format, subresourceRange: { aspectMask: VK_IMAGE_ASPECT_DEPTH_BIT, @@ -1090,7 +1090,7 @@ private void demo_prepare_textures(Demo* demo) { VkImageViewCreateInfo view = { sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, pNext: null, - image: VK_NULL_HANDLE, + image: VK_NULL_ND_HANDLE, viewType: VK_IMAGE_VIEW_TYPE_2D, format: tex_format, components: