Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,304 @@
#ifdef KINC_STEAMVR
#include <Kinc/graphics4/graphics.h>
#include <Kinc/graphics4/rendertarget.h>
#include <Kinc/math/quaternion.h>
#include <Kinc/math/vector.h>
#include <Kinc/vr/vrinterface.h>
#include <Kore/Input/Gamepad.h>
#include <Kore/Log.h>
// #include "Direct3D11.h"
#include <openvr.h>
#include <math.h>
#include <stdio.h>
using namespace Kore;
namespace {
vr::IVRSystem *hmd;
kinc_g4_render_target_t leftTexture;
kinc_g4_render_target_t rightTexture;
kinc_vr_sensor_state_t sensorStates[2];
kinc_vr_pose_state_t controller[vr::k_unMaxTrackedDeviceCount];
kinc_matrix4x4_t convert3x4(vr::HmdMatrix34_t &m) {
kinc_matrix4x4_t mat;
kinc_matrix4x4_set(&mat, 0, 0, m.m[0][0]);
kinc_matrix4x4_set(&mat, 0, 1, m.m[0][1]);
kinc_matrix4x4_set(&mat, 0, 2, m.m[0][2]);
kinc_matrix4x4_set(&mat, 0, 3, m.m[0][3]);
kinc_matrix4x4_set(&mat, 1, 0, m.m[1][0]);
kinc_matrix4x4_set(&mat, 1, 1, m.m[1][1]);
kinc_matrix4x4_set(&mat, 1, 2, m.m[1][2]);
kinc_matrix4x4_set(&mat, 1, 3, m.m[1][3]);
kinc_matrix4x4_set(&mat, 2, 0, m.m[2][0]);
kinc_matrix4x4_set(&mat, 2, 1, m.m[2][1]);
kinc_matrix4x4_set(&mat, 2, 2, m.m[2][2]);
kinc_matrix4x4_set(&mat, 2, 3, m.m[2][3]);
kinc_matrix4x4_set(&mat, 3, 0, 0);
kinc_matrix4x4_set(&mat, 3, 1, 0);
kinc_matrix4x4_set(&mat, 3, 2, 0);
kinc_matrix4x4_set(&mat, 3, 3, 1);
return mat;
}
kinc_matrix4x4_t convert4x4(vr::HmdMatrix44_t &m) {
kinc_matrix4x4_t mat;
kinc_matrix4x4_set(&mat, 0, 0, m.m[0][0]);
kinc_matrix4x4_set(&mat, 0, 1, m.m[0][1]);
kinc_matrix4x4_set(&mat, 0, 2, m.m[0][2]);
kinc_matrix4x4_set(&mat, 0, 3, m.m[0][3]);
kinc_matrix4x4_set(&mat, 1, 0, m.m[1][0]);
kinc_matrix4x4_set(&mat, 1, 1, m.m[1][1]);
kinc_matrix4x4_set(&mat, 1, 2, m.m[1][2]);
kinc_matrix4x4_set(&mat, 1, 3, m.m[1][3]);
kinc_matrix4x4_set(&mat, 2, 0, m.m[2][0]);
kinc_matrix4x4_set(&mat, 2, 1, m.m[2][1]);
kinc_matrix4x4_set(&mat, 2, 2, m.m[2][2]);
kinc_matrix4x4_set(&mat, 2, 3, m.m[2][3]);
kinc_matrix4x4_set(&mat, 3, 0, m.m[3][0]);
kinc_matrix4x4_set(&mat, 3, 1, m.m[3][1]);
kinc_matrix4x4_set(&mat, 3, 2, m.m[3][2]);
kinc_matrix4x4_set(&mat, 3, 3, m.m[3][3]);
return mat;
}
void getButtonEvent(const vr::VREvent_t &event) {
Gamepad *gamepad = Gamepad::get(event.trackedDeviceIndex);
switch (event.data.controller.button) {
case vr::k_EButton_Grip:
switch (event.eventType) {
case vr::VREvent_ButtonPress:
gamepad->Button(vr::k_EButton_Grip, 1);
break;
case vr::VREvent_ButtonUnpress:
gamepad->Button(vr::k_EButton_Grip, 0);
break;
}
break;
case vr::k_EButton_SteamVR_Trigger:
switch (event.eventType) {
case vr::VREvent_ButtonPress:
gamepad->Button(vr::k_EButton_SteamVR_Trigger, 1);
break;
case vr::VREvent_ButtonUnpress:
gamepad->Button(vr::k_EButton_SteamVR_Trigger, 0);
break;
}
break;
case vr::k_EButton_SteamVR_Touchpad:
// TODO: add axis
switch (event.eventType) {
case vr::VREvent_ButtonPress:
gamepad->Button(vr::k_EButton_SteamVR_Touchpad, 1);
break;
case vr::VREvent_ButtonUnpress:
gamepad->Button(vr::k_EButton_SteamVR_Touchpad, 0);
break;
case vr::VREvent_ButtonTouch:
break;
case vr::VREvent_ButtonUntouch:
break;
}
break;
case vr::k_EButton_ApplicationMenu:
switch (event.eventType) {
case vr::VREvent_ButtonPress:
gamepad->Button(vr::k_EButton_ApplicationMenu, 1);
break;
case vr::VREvent_ButtonUnpress:
gamepad->Button(vr::k_EButton_ApplicationMenu, 0);
break;
}
break;
}
}
void processVREvent(const vr::VREvent_t &event) {
switch (event.eventType) {
case vr::VREvent_None:
// log(Info, "The event is invalid.");
break;
case vr::VREvent_TrackedDeviceActivated:
// SetupRenderModelForTrackedDevice(event.trackedDeviceIndex);
// dprintf("Device %u attached. Setting up render model.\n", event.trackedDeviceIndex);
log(Info, "Device %u attached", event.trackedDeviceIndex);
break;
case vr::VREvent_TrackedDeviceDeactivated:
log(Info, "Device %u detached.", event.trackedDeviceIndex);
break;
case vr::VREvent_TrackedDeviceUpdated:
log(Info, "Device %u updated.", event.trackedDeviceIndex);
break;
}
// Get buttons
getButtonEvent(event);
}
void getPosition(const vr::HmdMatrix34_t *m, kinc_vector3_t *position) {
position->x = m->m[0][3];
position->y = m->m[1][3];
position->z = m->m[2][3];
}
void getOrientation(const vr::HmdMatrix34_t *m, kinc_quaternion_t *orientation) {
orientation->w = sqrt(fmax(0, 1 + m->m[0][0] + m->m[1][1] + m->m[2][2])) / 2;
orientation->x = sqrt(fmax(0, 1 + m->m[0][0] - m->m[1][1] - m->m[2][2])) / 2;
orientation->y = sqrt(fmax(0, 1 - m->m[0][0] + m->m[1][1] - m->m[2][2])) / 2;
orientation->z = sqrt(fmax(0, 1 - m->m[0][0] - m->m[1][1] + m->m[2][2])) / 2;
orientation->x = copysign(orientation->x, m->m[2][1] - m->m[1][2]);
orientation->y = copysign(orientation->y, m->m[0][2] - m->m[2][0]);
orientation->z = copysign(orientation->z, m->m[1][0] - m->m[0][1]);
}
void readSensorStates() {
vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
vr::TrackedDevicePose_t predictedPoses[vr::k_unMaxTrackedDeviceCount];
vr::VRCompositor()->WaitGetPoses(poses, vr::k_unMaxTrackedDeviceCount, predictedPoses, vr::k_unMaxTrackedDeviceCount);
for (int device = 0; device < vr::k_unMaxTrackedDeviceCount; ++device) {
if (poses[device].bPoseIsValid) {
if (hmd->GetTrackedDeviceClass(device) == vr::TrackedDeviceClass_HMD) {
kinc_vr_pose_state_t poseState;
poseState.linearVelocity.x = poses[device].vVelocity.v[0];
poseState.linearVelocity.y = poses[device].vVelocity.v[1];
poseState.linearVelocity.z = poses[device].vVelocity.v[2];
poseState.angularVelocity.x = poses[device].vAngularVelocity.v[0];
poseState.angularVelocity.y = poses[device].vAngularVelocity.v[1];
poseState.angularVelocity.z = poses[device].vAngularVelocity.v[2];
vr::HmdMatrix34_t m = poses[device].mDeviceToAbsoluteTracking;
// log(Info, "x: %f y: %f z: %f", m.m[0][3], m.m[1][3], m.m[2][3]);
getPosition(&m, &poseState.vrPose.position);
getOrientation(&m, &poseState.vrPose.orientation);
sensorStates[0].pose = poseState;
sensorStates[1].pose = poseState;
vr::HmdMatrix34_t leftEyeMatrix = hmd->GetEyeToHeadTransform(vr::Eye_Left);
vr::HmdMatrix34_t rightEyeMatrix = hmd->GetEyeToHeadTransform(vr::Eye_Right);
sensorStates[0].pose.vrPose.eye = convert3x4(leftEyeMatrix).Invert() * convert3x4(m).Invert();
sensorStates[1].pose.vrPose.eye = convert3x4(rightEyeMatrix).Invert() * convert3x4(m).Invert();
vr::HmdMatrix44_t leftProj = hmd->GetProjectionMatrix(vr::Eye_Left, 0.1f, 100.0f);
vr::HmdMatrix44_t rightProj = hmd->GetProjectionMatrix(vr::Eye_Right, 0.1f, 100.0f);
sensorStates[0].pose.vrPose.projection = convert4x4(leftProj);
sensorStates[1].pose.vrPose.projection = convert4x4(rightProj);
}
else if (hmd->GetTrackedDeviceClass(device) == vr::TrackedDeviceClass_Controller ||
hmd->GetTrackedDeviceClass(device) == vr::TrackedDeviceClass_GenericTracker) {
kinc_vr_pose_state_t poseState;
poseState.linearVelocity.x = poses[device].vVelocity.v[0];
poseState.linearVelocity.x = poses[device].vVelocity.v[1];
poseState.linearVelocity.x = poses[device].vVelocity.v[2];
poseState.angularVelocity.x = poses[device].vAngularVelocity.v[0];
poseState.angularVelocity.y = poses[device].vAngularVelocity.v[1];
poseState.angularVelocity.z = poses[device].vAngularVelocity.v[2];
vr::HmdMatrix34_t m = poses[device].mDeviceToAbsoluteTracking;
getPosition(&m, &poseState.vrPose.position);
getOrientation(&m, &poseState.vrPose.orientation);
// Kore::log(Kore::Info, "Pos of device %i %f %f %f", device, poseState.vrPose.position.x(), poseState.vrPose.position.y(),
// poseState.vrPose.position.z());
if (hmd->GetTrackedDeviceClass(device) == vr::TrackedDeviceClass_Controller)
poseState.trackedDevice = KINC_TRACKED_DEVICE_CONTROLLER;
else if (hmd->GetTrackedDeviceClass(device) == vr::TrackedDeviceClass_GenericTracker)
poseState.trackedDevice = KINC_TRACKED_DEVICE_VIVE_TRACKER;
controller[device] = poseState;
}
}
}
}
}
void *kinc_vr_interface_init(void *hinst, const char *title, const char *windowClassName) {
vr::HmdError error;
hmd = vr::VR_Init(&error, vr::VRApplication_Scene);
// vr::IVRRenderModels* renderModels = (vr::IVRRenderModels*)vr::VR_GetGenericInterface(vr::IVRRenderModels_Version, &error);
vr::VRCompositor();
uint32_t width, height;
hmd->GetRecommendedRenderTargetSize(&width, &height);
kinc_g4_render_target_init(&leftTexture, width, height, 0, false, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0);
kinc_g4_render_target_init(&rightTexture, width, height, 0, false, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0);
return nullptr;
}
void kinc_vr_interface_begin() {
vr::VREvent_t event;
while (hmd->PollNextEvent(&event, sizeof(event))) {
processVREvent(event);
}
for (vr::TrackedDeviceIndex_t unDevice = 0; unDevice < vr::k_unMaxTrackedDeviceCount; ++unDevice) {
vr::VRControllerState_t state;
if (hmd->GetControllerState(unDevice, &state, sizeof(state))) {
// m_rbShowTrackedDevice[unDevice] = state.ulButtonPressed == 0;
}
}
readSensorStates();
}
void kinc_vr_interface_begin_render(int eye) {
if (eye == 0) {
kinc_g4_render_target_t *renderTargets[1] = {&leftTexture};
kinc_g4_set_render_targets(renderTargets, 1);
}
else {
kinc_g4_render_target_t *renderTargets[1] = {&rightTexture};
kinc_g4_set_render_targets(renderTargets, 1);
}
}
void kinc_vr_interface_end_render(int eye) {}
kinc_vr_sensor_state_t kinc_vr_interface_get_sensor_state(int eye) {
return sensorStates[eye];
}
kinc_vr_pose_state_t kinc_vr_interface_get_controller(int index) {
return controller[index];
}
void kinc_vr_interface_warp_swap() {
#ifdef KINC_OPENGL
vr::Texture_t leftEyeTexture = {(void *)(uintptr_t)leftTexture.impl._texture, vr::TextureType_OpenGL, vr::ColorSpace_Gamma};
vr::VRCompositor()->Submit(vr::Eye_Left, &leftEyeTexture);
vr::Texture_t rightEyeTexture = {(void *)(uintptr_t)rightTexture.impl._texture, vr::TextureType_OpenGL, vr::ColorSpace_Gamma};
vr::VRCompositor()->Submit(vr::Eye_Right, &rightEyeTexture);
#else
vr::Texture_t leftEyeTexture = {(void *)(uintptr_t)leftTexture.impl.textureRender, vr::TextureType_DirectX, vr::ColorSpace_Gamma};
vr::VRCompositor()->Submit(vr::Eye_Left, &leftEyeTexture);
vr::Texture_t rightEyeTexture = {(void *)(uintptr_t)rightTexture.impl.textureRender, vr::TextureType_DirectX, vr::ColorSpace_Gamma};
vr::VRCompositor()->Submit(vr::Eye_Right, &rightEyeTexture);
#endif
}
void kinc_vr_interface_update_tracking_origin(kinc_tracking_origin_t origin) {}
void kinc_vr_interface_reset_hmd_pose() {}
void kinc_vr_interface_ovr_shutdown() {
vr::VR_Shutdown();
}
#endif

View File

@ -0,0 +1 @@
#include "Windows.h"

View File

@ -0,0 +1,25 @@
#pragma once
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
struct HMONITOR__;
struct HWND__;
int kinc_windows_get_display_for_monitor(struct HMONITOR__ *monitor);
bool kinc_windows_set_display_mode(int display_index, int width, int height, int bpp, int frequency);
void kinc_windows_restore_display(int display_index);
void kinc_windows_restore_displays();
void kinc_windows_hide_windows();
void kinc_windows_destroy_windows();
struct HWND__ *kinc_windows_window_handle(int window_index);
int kinc_windows_window_index_from_hwnd(struct HWND__ *handle);
int kinc_windows_manual_width(int window);
int kinc_windows_manual_height(int window);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,31 @@
#ifdef KINC_NO_CLIB
#ifndef NDEBUG
void _wassert(wchar_t const *message, wchar_t const *filename, unsigned line) {
__debugbreak();
}
void _RTC_CheckStackVars(void) {}
void _RTC_InitBase(void) {}
void _RTC_Shutdown(void) {}
void _RTC_AllocaHelper(void) {}
void _RTC_CheckStackVars2(void) {}
void __GSHandlerCheck(void) {}
void __fastcall __security_check_cookie(_In_ uintptr_t _StackCookie) {}
uintptr_t __security_cookie;
int _fltused = 1;
void __report_rangecheckfailure(void) {}
void __chkstk(void) {}
#endif
#endif

View File

@ -0,0 +1,201 @@
#include <kinc/backend/Windows.h>
#include <kinc/display.h>
#include <kinc/error.h>
#include <kinc/log.h>
#undef RegisterClass
#define MAXIMUM_DISPLAYS 16
typedef struct {
struct HMONITOR__ *monitor;
char name[32];
bool primary, available, mode_changed;
int index, x, y, width, height, ppi, frequency, bpp;
} DisplayData;
static DisplayData displays[MAXIMUM_DISPLAYS];
static DEVMODEA original_modes[MAXIMUM_DISPLAYS];
static int screen_counter = 0;
static bool display_initialized = false;
typedef enum { MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2, MDT_DEFAULT = MDT_EFFECTIVE_DPI } MONITOR_DPI_TYPE;
typedef HRESULT(WINAPI *GetDpiForMonitorType)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
static GetDpiForMonitorType MyGetDpiForMonitor = NULL;
static BOOL CALLBACK EnumerationCallback(HMONITOR monitor, HDC hdc_unused, LPRECT rect_unused, LPARAM lparam) {
MONITORINFOEXA info;
memset(&info, 0, sizeof(MONITORINFOEXA));
info.cbSize = sizeof(MONITORINFOEXA);
if (GetMonitorInfoA(monitor, (MONITORINFO *)&info) == FALSE) {
return FALSE;
}
int free_slot = 0;
for (; free_slot < MAXIMUM_DISPLAYS; ++free_slot) {
if (displays[free_slot].monitor == monitor) {
return FALSE;
}
if (displays[free_slot].monitor == NULL) {
break;
}
}
DisplayData *display = &displays[free_slot];
strncpy(display->name, info.szDevice, 31);
display->name[31] = 0;
display->index = free_slot;
display->monitor = monitor;
display->primary = (info.dwFlags & MONITORINFOF_PRIMARY) != 0;
display->available = true;
display->x = info.rcMonitor.left;
display->y = info.rcMonitor.top;
display->width = info.rcMonitor.right - info.rcMonitor.left;
display->height = info.rcMonitor.bottom - info.rcMonitor.top;
HDC hdc = CreateDCA(NULL, display->name, NULL, NULL);
display->ppi = GetDeviceCaps(hdc, LOGPIXELSX);
int scale = GetDeviceCaps(hdc, SCALINGFACTORX);
DeleteDC(hdc);
if (MyGetDpiForMonitor != NULL) {
unsigned dpiX, dpiY;
MyGetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
display->ppi = (int)dpiX;
}
memset(&original_modes[free_slot], 0, sizeof(DEVMODEA));
original_modes[free_slot].dmSize = sizeof(DEVMODEA);
EnumDisplaySettingsA(display->name, ENUM_CURRENT_SETTINGS, &original_modes[free_slot]);
display->frequency = original_modes[free_slot].dmDisplayFrequency;
display->bpp = original_modes[free_slot].dmBitsPerPel;
++screen_counter;
return TRUE;
}
void kinc_display_init() {
if (display_initialized) {
return;
}
HMODULE shcore = LoadLibraryA("Shcore.dll");
if (shcore != NULL) {
MyGetDpiForMonitor = (GetDpiForMonitorType)GetProcAddress(shcore, "GetDpiForMonitor");
}
memset(displays, 0, sizeof(DisplayData) * MAXIMUM_DISPLAYS);
EnumDisplayMonitors(NULL, NULL, EnumerationCallback, 0);
display_initialized = true;
}
int kinc_windows_get_display_for_monitor(struct HMONITOR__ *monitor) {
for (int i = 0; i < MAXIMUM_DISPLAYS; ++i) {
if (displays[i].monitor == monitor) {
return i;
}
}
kinc_error_message("Display for monitor not found");
return -1;
}
int kinc_count_displays() {
return screen_counter;
}
int kinc_primary_display() {
for (int i = 0; i < MAXIMUM_DISPLAYS; ++i) {
DisplayData *display = &displays[i];
if (display->available && display->primary) {
return i;
}
}
kinc_error_message("No primary display defined");
return -1;
}
kinc_display_mode_t kinc_display_available_mode(int display_index, int mode_index) {
DEVMODEA dev_mode = {0};
dev_mode.dmSize = sizeof(DEVMODEA);
EnumDisplaySettingsA(displays[display_index].name, mode_index, &dev_mode);
kinc_display_mode_t mode;
mode.x = displays[display_index].x;
mode.y = displays[display_index].y;
mode.width = dev_mode.dmPelsWidth;
mode.height = dev_mode.dmPelsHeight;
mode.frequency = dev_mode.dmDisplayFrequency;
mode.bits_per_pixel = dev_mode.dmBitsPerPel;
mode.pixels_per_inch = displays[display_index].ppi * mode.width / original_modes[display_index].dmPelsWidth;
return mode;
}
int kinc_display_count_available_modes(int display_index) {
DEVMODEA dev_mode = {0};
dev_mode.dmSize = sizeof(DEVMODEA);
int i = 0;
for (; EnumDisplaySettingsA(displays[display_index].name, i, &dev_mode) != FALSE; ++i)
;
return i;
}
bool kinc_windows_set_display_mode(int display_index, int width, int height, int bpp, int frequency) {
DisplayData *display = &displays[display_index];
display->mode_changed = true;
DEVMODEA mode = {0};
mode.dmSize = sizeof(mode);
strcpy((char *)mode.dmDeviceName, display->name);
mode.dmPelsWidth = width;
mode.dmPelsHeight = height;
mode.dmBitsPerPel = bpp;
mode.dmDisplayFrequency = frequency;
mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
bool success = ChangeDisplaySettingsA(&mode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
if (!success) {
mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
success = ChangeDisplaySettingsA(&mode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
}
return success;
}
void kinc_windows_restore_display(int display) {
if (displays[display].mode_changed) {
ChangeDisplaySettingsA(&original_modes[display], 0);
}
}
void kinc_windows_restore_displays() {
for (int i = 0; i < MAXIMUM_DISPLAYS; ++i) {
kinc_windows_restore_display(i);
}
}
bool kinc_display_available(int display_index) {
if (display_index < 0 || display_index >= MAXIMUM_DISPLAYS) {
return false;
}
return displays[display_index].available;
}
const char *kinc_display_name(int display_index) {
return displays[display_index].name;
}
kinc_display_mode_t kinc_display_current_mode(int display_index) {
DisplayData *display = &displays[display_index];
kinc_display_mode_t mode;
mode.x = display->x;
mode.y = display->y;
mode.width = display->width;
mode.height = display->height;
mode.pixels_per_inch = display->ppi;
mode.frequency = display->frequency;
mode.bits_per_pixel = display->bpp;
return mode;
}

View File

@ -0,0 +1,111 @@
#include <kinc/log.h>
#include <kinc/network/http.h>
#include <stdio.h>
#include <stdlib.h>
#include <winhttp.h>
static const wchar_t *convert(int method) {
switch (method) {
case KINC_HTTP_GET:
default:
return L"GET";
case KINC_HTTP_POST:
return L"POST";
case KINC_HTTP_PUT:
return L"PUT";
case KINC_HTTP_DELETE:
return L"DELETE";
}
}
static char *returnData = NULL;
static int returnDataSize = 0;
void kinc_http_request(const char *url, const char *path, const char *data, int port, bool secure, int method, const char *header,
kinc_http_callback_t callback, void *callbackdata) {
// based on https://docs.microsoft.com/en-us/windows/desktop/winhttp/winhttp-sessions-overview
HINTERNET hSession = WinHttpOpen(L"WinHTTP via Kore/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
HINTERNET hConnect = NULL;
if (hSession) {
wchar_t wurl[4096];
MultiByteToWideChar(CP_UTF8, 0, url, -1, wurl, 4096);
hConnect = WinHttpConnect(hSession, wurl, port, 0);
}
HINTERNET hRequest = NULL;
if (hConnect) {
wchar_t wpath[4096];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, 4096);
hRequest =
WinHttpOpenRequest(hConnect, convert(method), wpath, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, secure ? WINHTTP_FLAG_SECURE : 0);
}
BOOL bResults = FALSE;
if (hRequest) {
wchar_t wheader[4096];
if (header) {
MultiByteToWideChar(CP_UTF8, 0, header, -1, wheader, 4096);
}
DWORD optionalLength = (data != 0 && strlen(data) > 0) ? (DWORD)strlen(data) : 0;
bResults = WinHttpSendRequest(hRequest, header == 0 ? WINHTTP_NO_ADDITIONAL_HEADERS : wheader, header == 0 ? 0 : -1L,
data == 0 ? WINHTTP_NO_REQUEST_DATA : (LPVOID)data, optionalLength, optionalLength, 0);
}
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL);
int returnDataIndex = 0;
if (bResults) {
DWORD dwSize;
do {
dwSize = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Error %d in WinHttpQueryDataAvailable.\n", GetLastError());
}
if ((int)dwSize + 1 > returnDataSize - returnDataIndex) {
int newReturnDataSize = (returnDataIndex + dwSize + 1) * 2;
char *newReturnData = (char *)malloc(newReturnDataSize);
if (newReturnData == 0) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Out of memory\n");
}
memcpy(newReturnData, returnData, returnDataSize);
returnDataSize = newReturnDataSize;
returnData = newReturnData;
}
DWORD dwDownloaded = 0;
if (!WinHttpReadData(hRequest, (LPVOID)(&returnData[returnDataIndex]), dwSize, &dwDownloaded)) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Error %d in WinHttpReadData.\n", GetLastError());
}
returnDataIndex += dwSize;
} while (dwSize > 0);
}
else {
callback(1, 404, NULL, callbackdata);
return;
}
returnData[returnDataIndex] = 0;
if (!bResults) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Error %d has occurred.\n", GetLastError());
}
if (hRequest) {
WinHttpCloseHandle(hRequest);
}
if (hConnect) {
WinHttpCloseHandle(hConnect);
}
if (hSession) {
WinHttpCloseHandle(hSession);
}
callback(0, 200, returnData, callbackdata);
}

View File

@ -0,0 +1,52 @@
#include <kinc/backend/Windows.h>
#include <kinc/system.h>
#include <kinc/window.h>
#include <kinc/input/mouse.h>
void kinc_internal_mouse_lock(int window) {
kinc_mouse_hide();
HWND handle = kinc_windows_window_handle(window);
SetCapture(handle);
RECT rect;
GetWindowRect(handle, &rect);
ClipCursor(&rect);
}
void kinc_internal_mouse_unlock(void) {
kinc_mouse_show();
ReleaseCapture();
ClipCursor(NULL);
}
bool kinc_mouse_can_lock(void) {
return true;
}
void kinc_mouse_show() {
// Work around the internal counter of ShowCursor
while (ShowCursor(true) < 0) {
}
}
void kinc_mouse_hide() {
// Work around the internal counter of ShowCursor
while (ShowCursor(false) >= 0) {
}
}
void kinc_mouse_set_position(int window, int x, int y) {
POINT point;
point.x = x;
point.y = y;
ClientToScreen(kinc_windows_window_handle(window), &point);
SetCursorPos(point.x, point.y);
}
void kinc_mouse_get_position(int window, int *x, int *y) {
POINT point;
GetCursorPos(&point);
ScreenToClient(kinc_windows_window_handle(window), &point);
*x = point.x;
*y = point.y;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,298 @@
#include <kinc/video.h>
#ifdef KINC_DIRECT3D12
void kinc_video_init(kinc_video_t *video, const char *filename) {}
void kinc_video_destroy(kinc_video_t *video) {}
kinc_g4_texture_t *kinc_video_current_image(kinc_video_t *video) {
return NULL;
}
int kinc_video_width(kinc_video_t *video) {
return 64;
}
int kinc_video_height(kinc_video_t *video) {
return 64;
}
void kinc_video_play(kinc_video_t *video, bool loop) {}
void kinc_video_pause(kinc_video_t *video) {}
void kinc_video_stop(kinc_video_t *video) {}
void kinc_video_update(kinc_video_t *video, double time) {}
double kinc_video_duration(kinc_video_t *video) {
return 0.0;
}
double kinc_video_position(kinc_video_t *video) {
return 0.0;
}
bool kinc_video_finished(kinc_video_t *video) {
return true;
}
bool kinc_video_paused(kinc_video_t *video) {
return true;
}
#else
#ifndef KINC_NO_DIRECTSHOW
#include <streams.h>
namespace {
IGraphBuilder *graphBuilder;
IMediaControl *mediaControl;
IMediaPosition *mediaPosition;
IMediaEvent *mediaEvent;
struct __declspec(uuid("{71771540-2017-11cf-ae24-0020afd79767}")) CLSID_TextureRenderer;
}
class CTextureRenderer : public CBaseVideoRenderer {
public:
CTextureRenderer(LPUNKNOWN pUnk, HRESULT *phr);
~CTextureRenderer();
public:
HRESULT CheckMediaType(const CMediaType *pmt); // Format acceptable?
HRESULT SetMediaType(const CMediaType *pmt); // Video format notification
HRESULT DoRenderSample(IMediaSample *pMediaSample); // New video sample
// BOOL m_bUseDynamicTextures;
// LONG m_lVidWidth; // Video width
// LONG m_lVidHeight; // Video Height
// LONG m_lVidPitch; // Video Pitch
kinc_g4_texture_t image;
int width;
int height;
uint8_t *pixels;
};
CTextureRenderer::CTextureRenderer(LPUNKNOWN pUnk, HRESULT *phr) : CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer), TEXT("Texture Renderer"), pUnk, phr) {
// Store and AddRef the texture for our use.
ASSERT(phr);
if (phr)
*phr = S_OK;
}
CTextureRenderer::~CTextureRenderer() {
// Do nothing
}
HRESULT CTextureRenderer::CheckMediaType(const CMediaType *pmt) {
HRESULT hr = E_FAIL;
VIDEOINFO *pvi = 0;
CheckPointer(pmt, E_POINTER);
// Reject the connection if this is not a video type
if (*pmt->FormatType() != FORMAT_VideoInfo) {
return E_INVALIDARG;
}
// Only accept RGB24 video
pvi = (VIDEOINFO *)pmt->Format();
if (IsEqualGUID(*pmt->Type(), MEDIATYPE_Video) && IsEqualGUID(*pmt->Subtype(), MEDIASUBTYPE_RGB24)) {
hr = S_OK;
}
return hr;
}
HRESULT CTextureRenderer::SetMediaType(const CMediaType *pmt) {
VIDEOINFO *info = (VIDEOINFO *)pmt->Format();
width = info->bmiHeader.biWidth;
height = abs(info->bmiHeader.biHeight);
kinc_g4_texture_init(&image, width, height, KINC_IMAGE_FORMAT_RGBA32);
pixels = (uint8_t *)malloc(width * height * 3);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
pixels[y * width * 3 + x * 3 + 0] = 0;
pixels[y * width * 3 + x * 3 + 1] = 0;
pixels[y * width * 3 + x * 3 + 2] = 0;
}
}
return S_OK;
}
HRESULT CTextureRenderer::DoRenderSample(IMediaSample *sample) {
BYTE *videoPixels;
sample->GetPointer(&videoPixels);
int videoPitch = (width * 3 + 3) & ~(3);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
pixels[y * width * 3 + x * 3 + 0] = videoPixels[(height - y - 1) * videoPitch + x * 3 + 2];
pixels[y * width * 3 + x * 3 + 1] = videoPixels[(height - y - 1) * videoPitch + x * 3 + 1];
pixels[y * width * 3 + x * 3 + 2] = videoPixels[(height - y - 1) * videoPitch + x * 3 + 0];
}
}
return S_OK;
}
void kinc_video_init(kinc_video_t *video, const char *filename) {
video->impl.duration = 1000 * 10;
video->impl.position = 0;
video->impl.finished = false;
video->impl.paused = false;
// image = new Graphics4::Texture(100, 100, Graphics4::Image::RGBA32, false);
HRESULT hr = S_OK;
IBaseFilter *pFSrc; // Source Filter
IPin *pFSrcPinOut; // Source Filter Output Pin
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, __uuidof(IGraphBuilder), (void **)&graphBuilder);
video->impl.renderer = new CTextureRenderer(NULL, &hr);
hr = graphBuilder->AddFilter((CTextureRenderer *)video->impl.renderer, L"TEXTURERENDERER");
wchar_t wideFilename[2048];
mbstowcs(wideFilename, filename, 2048 - 1);
hr = graphBuilder->AddSourceFilter(wideFilename, L"SOURCE", &pFSrc);
hr = pFSrc->FindPin(L"Output", &pFSrcPinOut);
hr = graphBuilder->Render(pFSrcPinOut);
graphBuilder->QueryInterface(&mediaControl);
graphBuilder->QueryInterface(&mediaPosition);
graphBuilder->QueryInterface(&mediaEvent);
mediaPosition->get_Duration(&video->impl.duration);
video->impl.position = 0;
}
void kinc_video_destroy(kinc_video_t *video) {}
kinc_g4_texture_t *kinc_video_current_image(kinc_video_t *video) {
CTextureRenderer *renderer = (CTextureRenderer *)video->impl.renderer;
uint8_t *pixels = kinc_g4_texture_lock(&renderer->image);
int stride = kinc_g4_texture_stride(&renderer->image);
for (int y = 0; y < renderer->height; ++y) {
for (int x = 0; x < renderer->width; ++x) {
pixels[y * stride + x * 4 + 0] = renderer->pixels[y * renderer->width * 3 + x * 3 + 0];
pixels[y * stride + x * 4 + 1] = renderer->pixels[y * renderer->width * 3 + x * 3 + 1];
pixels[y * stride + x * 4 + 2] = renderer->pixels[y * renderer->width * 3 + x * 3 + 2];
pixels[y * stride + x * 4 + 3] = 255;
}
}
kinc_g4_texture_unlock(&renderer->image);
mediaPosition->get_CurrentPosition(&video->impl.position);
return &renderer->image;
}
int kinc_video_width(kinc_video_t *video) {
CTextureRenderer *renderer = (CTextureRenderer *)video->impl.renderer;
return renderer->width;
}
int kinc_video_height(kinc_video_t *video) {
CTextureRenderer *renderer = (CTextureRenderer *)video->impl.renderer;
return renderer->height;
}
void kinc_video_play(kinc_video_t *video, bool loop) {
mediaControl->Run();
}
void kinc_video_pause(kinc_video_t *video) {
mediaControl->Pause();
}
void kinc_video_stop(kinc_video_t *video) {
mediaControl->Stop();
}
void kinc_video_update(kinc_video_t *video, double time) {
mediaPosition->put_CurrentPosition(time);
}
double kinc_video_duration(kinc_video_t *video) {
return video->impl.duration;
}
double kinc_video_position(kinc_video_t *video) {
return video->impl.position;
}
bool kinc_video_finished(kinc_video_t *video) {
return video->impl.finished;
}
bool kinc_video_paused(kinc_video_t *video) {
return video->impl.paused;
}
#else
void kinc_video_init(kinc_video_t *video, const char *filename) {}
void kinc_video_destroy(kinc_video_t *video) {}
kinc_g4_texture_t *kinc_video_current_image(kinc_video_t *video) {
return NULL;
}
int kinc_video_width(kinc_video_t *video) {
return 64;
}
int kinc_video_height(kinc_video_t *video) {
return 64;
}
void kinc_video_play(kinc_video_t *video, bool loop) {}
void kinc_video_pause(kinc_video_t *video) {}
void kinc_video_stop(kinc_video_t *video) {}
void kinc_video_update(kinc_video_t *video, double time) {}
double kinc_video_duration(kinc_video_t *video) {
return 0.0;
}
double kinc_video_position(kinc_video_t *video) {
return 0.0;
}
bool kinc_video_finished(kinc_video_t *video) {
return true;
}
bool kinc_video_paused(kinc_video_t *video) {
return true;
}
#endif
#endif
void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency) {}
void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t *stream) {}
void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {}
static float samples[2];
float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) {
samples[0] = 0.0f;
samples[1] = 0.0f;
return samples;
}
bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) {
return true;
}

View File

@ -0,0 +1,31 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
void *renderer;
double duration;
double position;
bool finished;
bool paused;
} kinc_video_impl_t;
typedef struct kinc_internal_video_sound_stream {
int nothing;
} kinc_internal_video_sound_stream_t;
void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency);
void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t *stream);
void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count);
float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream);
bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,487 @@
#include <kinc/display.h>
#include <kinc/graphics4/graphics.h>
#include <kinc/window.h>
#include <kinc/backend/Windows.h>
#ifdef KINC_VR
#include <kinc/vr/vrinterface.h>
#endif
#undef CreateWindow
struct HWND__;
typedef unsigned long DWORD;
typedef struct {
struct HWND__ *handle;
int display_index;
bool mouseInside;
int index;
int x, y, mode, bpp, frequency, features;
int manualWidth, manualHeight;
void (*resizeCallback)(int x, int y, void *data);
void *resizeCallbackData;
void (*ppiCallback)(int ppi, void *data);
void *ppiCallbackData;
bool (*closeCallback)(void *data);
void *closeCallbackData;
} WindowData;
LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
#define MAXIMUM_WINDOWS 16
static WindowData windows[MAXIMUM_WINDOWS] = {0};
static int window_counter = 0;
#ifdef KINC_OCULUS
const wchar_t *windowClassName = L"ORT";
#else
const wchar_t *windowClassName = L"KoreWindow";
#endif
#ifdef KINC_VULKAN
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_win32.h>
VkResult kinc_vulkan_create_surface(VkInstance instance, int window_index, VkSurfaceKHR *surface) {
VkWin32SurfaceCreateInfoKHR createInfo = {0};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.hinstance = GetModuleHandle(NULL);
createInfo.hwnd = windows[window_index].handle;
return vkCreateWin32SurfaceKHR(instance, &createInfo, NULL, surface);
}
#include <assert.h>
void kinc_vulkan_get_instance_extensions(const char **names, int *index, int max) {
assert(*index + 1 < max);
names[(*index)++] = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
}
VkBool32 kinc_vulkan_get_physical_device_presentation_support(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) {
return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamilyIndex);
}
#endif
static void RegisterWindowClass(HINSTANCE hInstance, const wchar_t *className) {
WNDCLASSEXW wc = {sizeof(WNDCLASSEXA),
CS_OWNDC /*CS_CLASSDC*/,
KoreWindowsMessageProcedure,
0L,
0L,
hInstance,
LoadIconW(hInstance, MAKEINTRESOURCEW(107)),
LoadCursor(NULL, IDC_ARROW),
0,
0,
className,
0};
RegisterClassExW(&wc);
}
static DWORD getStyle(int features) {
DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;
if ((features & KINC_WINDOW_FEATURE_RESIZEABLE) && ((features & KINC_WINDOW_FEATURE_BORDERLESS) == 0)) {
style |= WS_SIZEBOX;
}
if (features & KINC_WINDOW_FEATURE_MAXIMIZABLE) {
style |= WS_MAXIMIZEBOX;
}
if (features & KINC_WINDOW_FEATURE_MINIMIZABLE) {
style |= WS_MINIMIZEBOX;
}
if ((features & KINC_WINDOW_FEATURE_BORDERLESS) == 0) {
style |= WS_CAPTION | WS_SYSMENU;
}
return style;
}
static DWORD getExStyle(int features) {
DWORD exStyle = WS_EX_APPWINDOW;
if ((features & KINC_WINDOW_FEATURE_BORDERLESS) == 0) {
exStyle |= WS_EX_WINDOWEDGE;
}
if (features & KINC_WINDOW_FEATURE_ON_TOP) {
exStyle |= WS_EX_TOPMOST;
}
return exStyle;
}
int kinc_windows_window_index_from_hwnd(struct HWND__ *handle) {
for (int i = 0; i < MAXIMUM_WINDOWS; ++i) {
if (windows[i].handle == handle) {
return i;
}
}
return -1;
}
int kinc_count_windows() {
return window_counter;
}
int kinc_window_x(int window_index) {
RECT rect;
GetWindowRect(windows[window_index].handle, &rect);
windows[window_index].x = rect.left;
return windows[window_index].x;
}
int kinc_window_y(int window_index) {
RECT rect;
GetWindowRect(windows[window_index].handle, &rect);
windows[window_index].y = rect.top;
return windows[window_index].y;
}
int kinc_window_width(int window_index) {
RECT rect;
GetClientRect(windows[window_index].handle, &rect);
return rect.right;
}
int kinc_window_height(int window_index) {
RECT rect;
GetClientRect(windows[window_index].handle, &rect);
return rect.bottom;
}
static DWORD getDwStyle(kinc_window_mode_t mode, int features) {
switch (mode) {
case KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN: {
return WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;
}
case KINC_WINDOW_MODE_FULLSCREEN:
return WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;
case KINC_WINDOW_MODE_WINDOW:
default:
return getStyle(features);
}
}
static DWORD getDwExStyle(kinc_window_mode_t mode, int features) {
switch (mode) {
case KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN: {
return WS_EX_APPWINDOW;
}
case KINC_WINDOW_MODE_FULLSCREEN:
return WS_EX_APPWINDOW;
case KINC_WINDOW_MODE_WINDOW:
default:
return getExStyle(features);
}
}
static int createWindow(const wchar_t *title, int x, int y, int width, int height, int bpp, int frequency, int features, kinc_window_mode_t windowMode,
int target_display_index) {
HINSTANCE inst = GetModuleHandleW(NULL);
if (window_counter == 0) {
RegisterWindowClass(inst, windowClassName);
}
int display_index = target_display_index == -1 ? kinc_primary_display() : target_display_index;
#ifdef KINC_VR
int dstx = 0;
int dsty = 0;
char titleutf8[1024];
char classNameutf8[1024];
WideCharToMultiByte(CP_UTF8, 0, title, -1, titleutf8, 1024 - 1, NULL, NULL);
WideCharToMultiByte(CP_UTF8, 0, windowClassName, -1, classNameutf8, 1024 - 1, NULL, NULL);
HWND hwnd = (HWND)kinc_vr_interface_init(inst, titleutf8, classNameutf8);
#else
RECT WindowRect;
WindowRect.left = 0;
WindowRect.right = width;
WindowRect.top = 0;
WindowRect.bottom = height;
if (windowMode == KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
kinc_windows_set_display_mode(display_index, width, height, bpp, frequency);
}
AdjustWindowRectEx(&WindowRect, getDwStyle(windowMode, features), FALSE, getDwExStyle(windowMode, features));
kinc_display_mode_t display_mode = kinc_display_current_mode(display_index);
int dstx = display_mode.x;
int dsty = display_mode.y;
int dstw = width;
int dsth = height;
switch (windowMode) {
case KINC_WINDOW_MODE_WINDOW:
dstx += x < 0 ? (display_mode.width - width) / 2 : x;
dsty += y < 0 ? (display_mode.height - height) / 2 : y;
dstw = WindowRect.right - WindowRect.left;
dsth = WindowRect.bottom - WindowRect.top;
break;
case KINC_WINDOW_MODE_FULLSCREEN:
dstw = display_mode.width;
dsth = display_mode.height;
break;
case KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
break;
}
HWND hwnd = CreateWindowExW(getDwExStyle(windowMode, features), windowClassName, title, getDwStyle(windowMode, features), dstx, dsty, dstw, dsth, NULL, NULL,
inst, NULL);
#endif
SetCursor(LoadCursor(NULL, IDC_ARROW));
DragAcceptFiles(hwnd, true);
windows[window_counter].handle = hwnd;
windows[window_counter].x = dstx;
windows[window_counter].y = dsty;
windows[window_counter].mode = windowMode;
windows[window_counter].display_index = display_index;
windows[window_counter].bpp = bpp;
windows[window_counter].frequency = frequency;
windows[window_counter].features = features;
windows[window_counter].manualWidth = width;
windows[window_counter].manualHeight = height;
windows[window_counter].index = window_counter;
return window_counter++;
}
void kinc_window_resize(int window_index, int width, int height) {
WindowData *win = &windows[window_index];
win->manualWidth = width;
win->manualHeight = height;
switch (win->mode) {
case KINC_WINDOW_MODE_WINDOW: {
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
AdjustWindowRectEx(&rect, getDwStyle((kinc_window_mode_t)win->mode, win->features), FALSE, getDwExStyle((kinc_window_mode_t)win->mode, win->features));
SetWindowPos(win->handle, NULL, kinc_window_x(window_index), kinc_window_y(window_index), rect.right - rect.left, rect.bottom - rect.top, 0);
break;
}
case KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN: {
int display_index = kinc_window_display(window_index);
kinc_display_mode_t display_mode = kinc_display_current_mode(display_index);
kinc_windows_set_display_mode(display_index, width, height, win->bpp, win->frequency);
SetWindowPos(win->handle, NULL, display_mode.x, display_mode.y, display_mode.width, display_mode.height, 0);
break;
}
}
}
void kinc_window_move(int window_index, int x, int y) {
WindowData *win = &windows[window_index];
if (win->mode != 0) {
return;
}
win->x = x;
win->y = y;
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = kinc_window_width(window_index);
rect.bottom = kinc_window_height(window_index);
AdjustWindowRectEx(&rect, getDwStyle((kinc_window_mode_t)win->mode, win->features), FALSE, getDwExStyle((kinc_window_mode_t)win->mode, win->features));
SetWindowPos(win->handle, NULL, x, y, rect.right - rect.left, rect.bottom - rect.top, 0);
}
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame);
void kinc_window_change_framebuffer(int window, kinc_framebuffer_options_t *frame) {
kinc_internal_change_framebuffer(window, frame);
}
void kinc_window_change_features(int window_index, int features) {
WindowData *win = &windows[window_index];
win->features = features;
SetWindowLongW(win->handle, GWL_STYLE, getStyle(features));
SetWindowLongW(win->handle, GWL_EXSTYLE, getExStyle(features));
HWND on_top = (features & KINC_WINDOW_FEATURE_ON_TOP) ? HWND_TOPMOST : HWND_NOTOPMOST;
SetWindowPos(win->handle, on_top, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
kinc_window_show(window_index);
}
void kinc_window_change_mode(int window_index, kinc_window_mode_t mode) {
WindowData *win = &windows[window_index];
int display_index = kinc_window_display(window_index);
kinc_display_mode_t display_mode = kinc_display_current_mode(display_index);
switch (mode) {
case KINC_WINDOW_MODE_WINDOW:
kinc_windows_restore_display(display_index);
kinc_window_change_features(window_index, win->features);
kinc_window_show(window_index);
break;
case KINC_WINDOW_MODE_FULLSCREEN: {
kinc_windows_restore_display(display_index);
SetWindowLongW(win->handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP);
SetWindowLongW(win->handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
SetWindowPos(win->handle, NULL, display_mode.x, display_mode.y, display_mode.width, display_mode.height, 0);
kinc_window_show(window_index);
break;
}
case KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
kinc_windows_set_display_mode(display_index, win->manualWidth, win->manualHeight, win->bpp, win->frequency);
SetWindowLongW(win->handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP);
SetWindowLongW(win->handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
SetWindowPos(win->handle, NULL, display_mode.x, display_mode.y, display_mode.width, display_mode.height, 0);
kinc_window_show(window_index);
break;
}
win->mode = mode;
}
kinc_window_mode_t kinc_window_get_mode(int window_index) {
return (kinc_window_mode_t)windows[window_index].mode;
}
void kinc_window_destroy(int window_index) {
WindowData *win = &windows[window_index];
if (win->handle != NULL) {
kinc_g4_internal_destroy_window(window_index);
DestroyWindow(win->handle);
win->handle = NULL;
--window_counter;
}
}
void kinc_windows_hide_windows(void) {
for (int i = 0; i < MAXIMUM_WINDOWS; ++i) {
if (windows[i].handle != NULL) {
ShowWindow(windows[i].handle, SW_HIDE);
UpdateWindow(windows[i].handle);
}
}
}
void kinc_windows_destroy_windows(void) {
for (int i = 0; i < MAXIMUM_WINDOWS; ++i) {
kinc_window_destroy(i);
}
UnregisterClassW(windowClassName, GetModuleHandleW(NULL));
}
void kinc_window_show(int window_index) {
ShowWindow(windows[window_index].handle, SW_SHOWDEFAULT);
UpdateWindow(windows[window_index].handle);
}
void kinc_window_hide(int window_index) {
ShowWindow(windows[window_index].handle, SW_HIDE);
UpdateWindow(windows[window_index].handle);
}
void kinc_window_set_title(int window_index, const char *title) {
wchar_t buffer[1024];
MultiByteToWideChar(CP_UTF8, 0, title, -1, buffer, 1024);
SetWindowTextW(windows[window_index].handle, buffer);
}
int kinc_window_create(kinc_window_options_t *win, kinc_framebuffer_options_t *frame) {
kinc_window_options_t defaultWin;
kinc_framebuffer_options_t defaultFrame;
if (win == NULL) {
kinc_window_options_set_defaults(&defaultWin);
win = &defaultWin;
}
if (frame == NULL) {
kinc_framebuffer_options_set_defaults(&defaultFrame);
frame = &defaultFrame;
}
if (win->title == NULL) {
win->title = "";
}
wchar_t wbuffer[1024];
MultiByteToWideChar(CP_UTF8, 0, win->title, -1, wbuffer, 1024);
int windowId = createWindow(wbuffer, win->x, win->y, win->width, win->height, frame->color_bits, frame->frequency, win->window_features, win->mode,
win->display_index);
kinc_g4_set_antialiasing_samples(frame->samples_per_pixel);
bool vsync = frame->vertical_sync;
#ifdef KINC_OCULUS
vsync = false;
#endif
kinc_g4_internal_init_window(windowId, frame->depth_bits, frame->stencil_bits, vsync);
if (win->visible) {
kinc_window_show(windowId);
}
return windowId;
}
void kinc_window_set_resize_callback(int window_index, void (*callback)(int x, int y, void *data), void *data) {
windows[window_index].resizeCallback = callback;
windows[window_index].resizeCallbackData = data;
}
void kinc_window_set_ppi_changed_callback(int window_index, void (*callback)(int ppi, void *data), void *data) {
windows[window_index].ppiCallback = callback;
windows[window_index].ppiCallbackData = data;
}
void kinc_window_set_close_callback(int window_index, bool (*callback)(void *data), void *data) {
windows[window_index].closeCallback = callback;
windows[window_index].closeCallbackData = data;
}
int kinc_window_display(int window_index) {
return kinc_windows_get_display_for_monitor(MonitorFromWindow(windows[window_index].handle, MONITOR_DEFAULTTOPRIMARY));
}
struct HWND__ *kinc_windows_window_handle(int window_index) {
return windows[window_index].handle;
}
int kinc_windows_manual_width(int window) {
return windows[window].manualWidth;
}
int kinc_windows_manual_height(int window) {
return windows[window].manualHeight;
}
void kinc_internal_call_resize_callback(int window_index, int width, int height) {
if (windows[window_index].resizeCallback != NULL) {
windows[window_index].resizeCallback(width, height, windows[window_index].resizeCallbackData);
}
}
void kinc_internal_call_ppi_changed_callback(int window_index, int ppi) {
if (windows[window_index].ppiCallback != NULL) {
windows[window_index].ppiCallback(ppi, windows[window_index].ppiCallbackData);
}
}
bool kinc_internal_call_close_callback(int window_index) {
if (windows[window_index].closeCallback != NULL) {
return windows[window_index].closeCallback(windows[window_index].closeCallbackData);
}
return true;
}

View File

@ -0,0 +1,47 @@
// Windows 7
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
#define NOATOM
// #define NOCLIPBOARD
#define NOCOLOR
#define NOCOMM
// #define NOCTLMGR
#define NODEFERWINDOWPOS
#define NODRAWTEXT
// #define NOGDI
#define NOGDICAPMASKS
#define NOHELP
#define NOICONS
#define NOKANJI
#define NOKEYSTATES
// #define NOMB
#define NOMCX
#define NOMEMMGR
#define NOMENUS
#define NOMETAFILE
#define NOMINMAX
// #define NOMSG
// #define NONLS
#define NOOPENFILE
#define NOPROFILER
#define NORASTEROPS
#define NOSCROLL
#define NOSERVICE
// #define NOSHOWWINDOW
#define NOSOUND
// #define NOSYSCOMMANDS
#define NOSYSMETRICS
#define NOTEXTMETRIC
// #define NOUSER
// #define NOVIRTUALKEYCODES
#define NOWH
// #define NOWINMESSAGES
// #define NOWINOFFSETS
// #define NOWINSTYLES
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "VrInterface_SteamVR.cpp.h"
#include "video.cpp.h"

View File

@ -0,0 +1,126 @@
// Windows 7
#define WINVER 0x0601
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0601
#define NOATOM
//#define NOCLIPBOARD
#define NOCOLOR
#define NOCOMM
//#define NOCTLMGR
#define NODEFERWINDOWPOS
#define NODRAWTEXT
//#define NOGDI
#define NOGDICAPMASKS
#define NOHELP
#define NOICONS
#define NOKANJI
#define NOKEYSTATES
//#define NOMB
#define NOMCX
#define NOMEMMGR
#define NOMENUS
#define NOMETAFILE
#define NOMINMAX
//#define NOMSG
//#define NONLS
#define NOOPENFILE
#define NOPROFILER
#define NORASTEROPS
#define NOSCROLL
#define NOSERVICE
//#define NOSHOWWINDOW
#define NOSOUND
//#define NOSYSCOMMANDS
#define NOSYSMETRICS
#define NOTEXTMETRIC
//#define NOUSER
//#define NOVIRTUALKEYCODES
#define NOWH
//#define NOWINMESSAGES
//#define NOWINOFFSETS
//#define NOWINSTYLES
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Windowsx.h>
// Some types for features exclusive to later versions of Windows are copied in here.
// Use with care, make sure not to break backwards-compatibility when using them.
typedef DWORD POINTER_INPUT_TYPE;
typedef UINT32 POINTER_FLAGS;
typedef enum tagPOINTER_BUTTON_CHANGE_TYPE {
POINTER_CHANGE_NONE,
POINTER_CHANGE_FIRSTBUTTON_DOWN,
POINTER_CHANGE_FIRSTBUTTON_UP,
POINTER_CHANGE_SECONDBUTTON_DOWN,
POINTER_CHANGE_SECONDBUTTON_UP,
POINTER_CHANGE_THIRDBUTTON_DOWN,
POINTER_CHANGE_THIRDBUTTON_UP,
POINTER_CHANGE_FOURTHBUTTON_DOWN,
POINTER_CHANGE_FOURTHBUTTON_UP,
POINTER_CHANGE_FIFTHBUTTON_DOWN,
POINTER_CHANGE_FIFTHBUTTON_UP,
} POINTER_BUTTON_CHANGE_TYPE;
typedef struct tagPOINTER_INFO {
POINTER_INPUT_TYPE pointerType;
UINT32 pointerId;
UINT32 frameId;
POINTER_FLAGS pointerFlags;
HANDLE sourceDevice;
HWND hwndTarget;
POINT ptPixelLocation;
POINT ptHimetricLocation;
POINT ptPixelLocationRaw;
POINT ptHimetricLocationRaw;
DWORD dwTime;
UINT32 historyCount;
INT32 InputData;
DWORD dwKeyStates;
UINT64 PerformanceCount;
POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
} POINTER_INFO;
typedef UINT32 PEN_FLAGS;
typedef UINT32 PEN_MASK;
typedef struct tagPOINTER_PEN_INFO {
POINTER_INFO pointerInfo;
PEN_FLAGS penFlags;
PEN_MASK penMask;
UINT32 pressure;
UINT32 rotation;
INT32 tiltX;
INT32 tiltY;
} POINTER_PEN_INFO;
#define WM_POINTERUPDATE 0x0245
#define WM_POINTERDOWN 0x0246
#define WM_POINTERUP 0x0247
#define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam))
enum tagPOINTER_INPUT_TYPE {
PT_POINTER = 1, // Generic pointer
PT_TOUCH = 2, // Touch
PT_PEN = 3, // Pen
PT_MOUSE = 4, // Mouse
PT_TOUCHPAD = 5, // Touchpad
};
#include <stdio.h>
#include "Windows.c.h"
#include "base.c.h"
#include "display.c.h"
#include "http.c.h"
#include "mouse.c.h"
#include "system.c.h"
#include "window.c.h"