Files
WickedEngine/WickedEngine/wiHelper.h
T
Turánszki János f1ced24f05 Multi swapchain support (#257)
* multi swapchain draft

* uwp fix

* swapchain resize handling

* swapchain buffercount

* vsync toggle

* tests fix

* update

* everything removed from graphicsdevice regarding global screen params, engine refactor

* added GetSwapChainTexture() function to graphics device; screenshot() now requires swapChain

* linux fix: vulkan device needs window handle for instance creation

* refactor

* removed unused includes

* shader refactor and lensflare fix

* swapchain clearcolor and other refactors

* vulkan: no vector allocation in submit

* tests fix

* refactors

* lens flare canvas size fix

* gui refactor for canvas support

* refactors

* removed global canvas state

* msaa fix

* fixes

* refactor to minimize interface changes

* gui changes

* checkbox fix

* gui fixes

* fixes

* input system will accept window handle

* editor fixes

* refactor and removed resolution related system events

* small editor update

* refactor: renderpath inherits from canvas

* fixed tests duh

* image refactor

* image fix

* removed every using namespace std

* pushconstant fix

* editor: object picking only when necessary

* removed include

* dx12: copy fence waiting performed on CPU

* dx12 copyallocator update

* vulkan: copy allocator with timeline semaphores

* missing include

* dx12 copy allocator update

* refactor

* editor update

* vulkan copy allocator fix

* dx12 update

* vulkan, dx12 fixes

* version bump

* vsync event helper

* documentation update

* updated vulkan, dx12, dxc
2021-04-22 11:36:22 +02:00

113 lines
3.6 KiB
C++

#pragma once
#include "CommonInclude.h"
#include "wiGraphicsDevice.h"
#include <string>
#include <vector>
#include <functional>
namespace wiHelper
{
template <class T>
constexpr void hash_combine(std::size_t& seed, const T& v)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
constexpr size_t string_hash(const char* input)
{
// https://stackoverflow.com/questions/2111667/compile-time-string-hashing
size_t hash = sizeof(size_t) == 8 ? 0xcbf29ce484222325 : 0x811c9dc5;
const size_t prime = sizeof(size_t) == 8 ? 0x00000100000001b3 : 0x01000193;
while (*input)
{
hash ^= static_cast<size_t>(*input);
hash *= prime;
++input;
}
return hash;
}
std::string toUpper(const std::string& s);
void messageBox(const std::string& msg, const std::string& caption = "Warning!");
void screenshot(const wiGraphics::SwapChain& swapchain, const std::string& name = "");
// Save raw pixel data from the texture to memory
bool saveTextureToMemory(const wiGraphics::Texture& texture, std::vector<uint8_t>& texturedata);
// Save texture to memory as a file format
bool saveTextureToMemoryFile(const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector<uint8_t>& filedata);
// Save raw texture data to memory as file format
bool saveTextureToMemoryFile(const std::vector<uint8_t>& textureData, const wiGraphics::TextureDesc& desc, const std::string& fileExtension, std::vector<uint8_t>& filedata);
// Save texture to file format
bool saveTextureToFile(const wiGraphics::Texture& texture, const std::string& fileName);
// Save raw texture data to file format
bool saveTextureToFile(const std::vector<uint8_t>& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName);
std::string getCurrentDateTimeAsString();
void SplitPath(const std::string& fullPath, std::string& dir, std::string& fileName);
std::string GetFileNameFromPath(const std::string& path);
std::string GetDirectoryFromPath(const std::string& path);
std::string GetExtensionFromFileName(const std::string& filename);
std::string ReplaceExtension(const std::string& filename, const std::string& extension);
void MakePathRelative(const std::string& rootdir, std::string& path);
void MakePathAbsolute(std::string& path);
void DirectoryCreate(const std::string& path);
bool FileRead(const std::string& fileName, std::vector<uint8_t>& data);
bool FileWrite(const std::string& fileName, const uint8_t* data, size_t size);
bool FileExists(const std::string& fileName);
struct FileDialogParams
{
enum TYPE
{
OPEN,
SAVE,
} type = OPEN;
std::string description;
std::vector<std::string> extensions;
};
void FileDialog(const FileDialogParams& params, std::function<void(std::string fileName)> onSuccess);
// Converts a file into a C++ header file that contains the file contents as byte array.
// dataName : the byte array's name
bool Bin2H(const uint8_t* data, size_t size, const std::string& dst_filename, const char* dataName);
void StringConvert(const std::string& from, std::wstring& to);
void StringConvert(const std::wstring& from, std::string& to);
// Parameter - to - must be pre-allocated!
// returns result string length
int StringConvert(const char* from, wchar_t* to);
// Parameter - to - must be pre-allocated!
// returns result string length
int StringConvert(const wchar_t* from, char* to);
// Puts the current thread to sleeping state for a given time (OS can overtake)
void Sleep(float milliseconds);
// Spins for the given time and does nothing (OS can not overtake)
void Spin(float milliseconds);
};