74cb74d3c9
- namespace refactor (example: wiGraphics:: -> wi::graphics) - provided namespace compatibility macro for old user code: WICKEDENGINE_BACKWARDS_COMPATIBILITY_0_59 - resource manager will return `Resource` instead of `shared_ptr<Resource>` objects - MAD shader optimizations - implemented alpha to coverage with alpha tested materials when MSAA is enabled - alpha testing fix with transparent shadow maps - TLAS and scene buffers will be recreated less frequently when things get added/removed from the scene
104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
#pragma once
|
|
// This file includes platform, os specific libraries and supplies common platform specific resources
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif // NOMINMAX
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
#include <SDKDDKVer.h>
|
|
#include <windows.h>
|
|
#include <tchar.h>
|
|
|
|
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
|
|
#define PLATFORM_UWP
|
|
#define wiLoadLibrary(name) LoadPackagedLibrary(_T(name),0)
|
|
#define wiGetProcAddress(handle,name) GetProcAddress(handle, name)
|
|
#include <winrt/Windows.UI.Core.h>
|
|
#include <winrt/Windows.Graphics.Display.h>
|
|
#include <winrt/Windows.ApplicationModel.Core.h>
|
|
#else
|
|
#define PLATFORM_WINDOWS_DESKTOP
|
|
#define wiLoadLibrary(name) LoadLibraryA(name)
|
|
#define wiGetProcAddress(handle,name) GetProcAddress(handle, name)
|
|
#endif // UWP
|
|
|
|
#else
|
|
|
|
#define PLATFORM_LINUX
|
|
#define wiLoadLibrary(name) dlopen(name, RTLD_LAZY)
|
|
#define wiGetProcAddress(handle,name) dlsym(handle, name)
|
|
typedef void* HMODULE;
|
|
|
|
#endif // _WIN32
|
|
|
|
#ifdef SDL2
|
|
#include <SDL2/SDL.h>
|
|
#include <SDL_vulkan.h>
|
|
#include "sdl2.h"
|
|
#endif
|
|
|
|
|
|
namespace wi::platform
|
|
{
|
|
#ifdef _WIN32
|
|
#ifdef PLATFORM_UWP
|
|
using window_type = const winrt::Windows::UI::Core::CoreWindow*;
|
|
#else
|
|
using window_type = HWND;
|
|
#endif // PLATFORM_UWP
|
|
#elif SDL2
|
|
using window_type = SDL_Window*;
|
|
#else
|
|
using window_type = int;
|
|
#endif // _WIN32
|
|
|
|
inline void Exit()
|
|
{
|
|
#ifdef _WIN32
|
|
#ifndef PLATFORM_UWP
|
|
PostQuitMessage(0);
|
|
#else
|
|
winrt::Windows::ApplicationModel::Core::CoreApplication::Exit();
|
|
#endif // PLATFORM_UWP
|
|
#endif // _WIN32
|
|
#ifdef SDL2
|
|
SDL_Quit();
|
|
#endif
|
|
}
|
|
|
|
struct WindowProperties
|
|
{
|
|
int width = 0;
|
|
int height = 0;
|
|
float dpi = 96;
|
|
};
|
|
inline void GetWindowProperties(window_type window, WindowProperties* dest)
|
|
{
|
|
#ifdef PLATFORM_WINDOWS_DESKTOP
|
|
dest->dpi = (float)GetDpiForWindow(window);
|
|
RECT rect;
|
|
GetClientRect(window, &rect);
|
|
dest->width = int(rect.right - rect.left);
|
|
dest->height = int(rect.bottom - rect.top);
|
|
#endif // WINDOWS_DESKTOP
|
|
|
|
#ifdef PLATFORM_UWP
|
|
dest->dpi = winrt::Windows::Graphics::Display::DisplayInformation::GetForCurrentView().LogicalDpi();
|
|
float dpiscale = dest->dpi / 96.f;
|
|
dest->width = uint32_t(window->Bounds().Width * dpiscale);
|
|
dest->height = uint32_t(window->Bounds().Height * dpiscale);
|
|
#endif // PLATFORM_UWP
|
|
|
|
#ifdef PLATFORM_LINUX
|
|
int window_width, window_height;
|
|
SDL_GetWindowSize(window, &window_width, &window_height);
|
|
SDL_Vulkan_GetDrawableSize(window, &dest->width, &dest->height);
|
|
dest->dpi = ((float) dest->width / (float) window_width) * 96.0;
|
|
#endif // PLATFORM_LINUX
|
|
}
|
|
}
|