Archived
1
Fork 0

Fix errors when compiling with MSVC

This commit is contained in:
redstrate 2020-08-13 07:48:50 -04:00
parent 7a905fcea6
commit 94953c62f0
34 changed files with 186 additions and 440 deletions

View file

@ -67,6 +67,7 @@ macro(manual_download)
set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "" FORCE) set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
set(BUILD_EXTERNAL OFF CACHE BOOL "" FORCE) set(BUILD_EXTERNAL OFF CACHE BOOL "" FORCE)
set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE) set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE)
set(USE_MSVC_RUNTIME_LIBRARY_DLL ON CACHE BOOL "" FORCE)
add_definitions(-DLUA_USE_APPLE) add_definitions(-DLUA_USE_APPLE)

View file

@ -13,7 +13,7 @@ namespace std {
template <> template <>
struct hash<file::Path> { struct hash<file::Path> {
std::size_t operator()(const file::Path& k) const { std::size_t operator()(const file::Path& k) const {
return hash<std::string>()(k); return (std::hash<std::string>()(k.string()));
} }
}; };
} }

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "renderer.hpp" #include "renderer.hpp"
#include "assetptr.hpp"
class Texture;
class MaterialNode; class MaterialNode;
enum class DataType { enum class DataType {
@ -29,6 +29,8 @@ inline bool operator==(const MaterialConnector& a, const MaterialConnector& b) {
return a.name == b.name; return a.name == b.name;
} }
class Texture;
struct MaterialProperty { struct MaterialProperty {
std::string name; std::string name;
DataType type; DataType type;

View file

@ -30,7 +30,7 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path) {
} }
auto mesh = std::make_unique<Mesh>(); auto mesh = std::make_unique<Mesh>();
mesh->path = path; mesh->path = path.string();
enum MeshType : int { enum MeshType : int {
Static, Static,
@ -221,7 +221,7 @@ std::unique_ptr<Texture> load_texture(const file::Path path) {
Expects(height > 0); Expects(height > 0);
auto texture = std::make_unique<Texture>(); auto texture = std::make_unique<Texture>();
texture->path = path; texture->path = path.string();
texture->width = width; texture->width = width;
texture->height = height; texture->height = height;
@ -264,7 +264,7 @@ std::unique_ptr<Material> load_material(const file::Path path) {
file->read_as_stream() >> j; file->read_as_stream() >> j;
auto mat = std::make_unique<Material>(); auto mat = std::make_unique<Material>();
mat->path = path; mat->path = path.string();
if(!j.count("version") || j["version"] != 2) { if(!j.count("version") || j["version"] != 2) {
console::error(System::Core, "Material {} failed the version check!", path); console::error(System::Core, "Material {} failed the version check!", path);

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "assetptr.hpp" #include "assetptr.hpp"
#include "screen.hpp"
class btCollisionShape; class btCollisionShape;
class btRigidBody; class btRigidBody;
@ -93,12 +92,16 @@ struct Light {
struct Camera { struct Camera {
float fov = 75.0f; float fov = 75.0f;
float near = 0.1f; float near = 1.0f;
float exposure = 1.0; float exposure = 1.0f;
Matrix4x4 view, perspective; Matrix4x4 view, perspective;
}; };
namespace ui {
class Screen;
}
struct UI { struct UI {
int width = 1920, height = 1080; int width = 1920, height = 1080;

View file

@ -8,7 +8,7 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
#include <sol.hpp> #include <sol.hpp>
#endif #endif
@ -199,7 +199,7 @@ public:
@param identifier The identifier of the new window. @param identifier The identifier of the new window.
@param extent The extent of the window. @param extent The extent of the window.
*/ */
void add_window(void* native_handle, const int identifier, const Extent extent); void add_window(void* native_handle, const int identifier, const prism::Extent extent);
/** Removes the window from engine management. Should be called before the window is actually closed. /** Removes the window from engine management. Should be called before the window is actually closed.
@param identifier The identifier of the window to remove. @param identifier The identifier of the window to remove.
@ -210,7 +210,7 @@ public:
@param identifier The window that has been resized. @param identifier The window that has been resized.
@param extent The new extent of the window. @param extent The new extent of the window.
*/ */
void resize(const int identifier, const Extent extent); void resize(const int identifier, const prism::Extent extent);
/** Called when a key has been pressed. /** Called when a key has been pressed.
@param keyCode A platform-specific key code. @param keyCode A platform-specific key code.
@ -231,7 +231,7 @@ public:
@param offset The mouse position relative to the window where the click occured. @param offset The mouse position relative to the window where the click occured.
@note This function is only intended for debug purposes and all production code should be using the Input system instead. @note This function is only intended for debug purposes and all production code should be using the Input system instead.
*/ */
void process_mouse_down(const int button, const Offset offset); void process_mouse_down(const int button, const prism::Offset offset);
/** Pushes a UI event for the current screen. Does nothing if there is no screen set. /** Pushes a UI event for the current screen. Does nothing if there is no screen set.
@param name The name of the event. @param name The name of the event.
@ -323,7 +323,7 @@ public:
/// If physics should upate. This is a control indepentent of the pause state. /// If physics should upate. This is a control indepentent of the pause state.
bool update_physics = true; bool update_physics = true;
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
sol::state lua; sol::state lua;
#endif #endif
@ -349,7 +349,7 @@ private:
struct Window { struct Window {
int identifier = -1; int identifier = -1;
Extent extent; prism::Extent extent;
bool quitRequested = false; bool quitRequested = false;
std::unique_ptr<Renderer> renderer = nullptr; std::unique_ptr<Renderer> renderer = nullptr;

View file

@ -7,6 +7,8 @@
#include <array> #include <array>
#include <filesystem> #include <filesystem>
#include "log.hpp"
namespace file { namespace file {
enum class Domain { enum class Domain {
System, System,
@ -130,4 +132,11 @@ namespace file {
inline Path internal_domain = "/internal", app_domain = "/app"; inline Path internal_domain = "/internal", app_domain = "/app";
} }
namespace console {
inline void internal_format(std::string& msg, const file::Path& arg) {
auto pos = msg.find_first_of("{}");
msg.replace(pos, 2, arg.string());
}
}
inline std::array<std::string, 3> domain_data; inline std::array<std::string, 3> domain_data;

View file

@ -1,15 +1,7 @@
#pragma once #pragma once
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#if defined(PLATFORM_MACOS) || defined(PLATFORM_IOS) || defined(PLATFORM_TVOS)
#include <btBulletDynamicsCommon.h> #include <btBulletDynamicsCommon.h>
#else
#include <bullet/btBulletDynamicsCommon.h>
#endif
#include <memory> #include <memory>
#pragma clang diagnostic pop
#include "vector.hpp" #include "vector.hpp"
#include "object.hpp" #include "object.hpp"

View file

@ -73,7 +73,7 @@ namespace platform {
@note On platforms that do not support the Windowing feature, calling open_window more than once is not supported. In this case, the same identifier is returned. @note On platforms that do not support the Windowing feature, calling open_window more than once is not supported. In this case, the same identifier is returned.
@return A valid window identifier. @return A valid window identifier.
*/ */
int open_window(const std::string_view title, const Rectangle rect, const WindowFlags flags); int open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags);
/** Closes a window. /** Closes a window.
@param index The window to close. @param index The window to close.
@ -90,19 +90,19 @@ namespace platform {
float get_monitor_dpi(); float get_monitor_dpi();
/// Get the monitor resolution. /// Get the monitor resolution.
Rectangle get_monitor_resolution(); prism::Rectangle get_monitor_resolution();
/// Get the monitor work area. For example on macOS this may exclude the areas of the menu bar and dock. /// Get the monitor work area. For example on macOS this may exclude the areas of the menu bar and dock.
Rectangle get_monitor_work_area(); prism::Rectangle get_monitor_work_area();
/// Get the window position. /// Get the window position.
Offset get_window_position(const int index); prism::Offset get_window_position(const int index);
/// Get the window size, note that in hidpi scenarios this is the non-scaled resolution. /// Get the window size, note that in hidpi scenarios this is the non-scaled resolution.
Extent get_window_size(const int index); prism::Extent get_window_size(const int index);
/// Get the window's drawable size. Always use this instead of manually multiplying the window size by the content scale. /// Get the window's drawable size. Always use this instead of manually multiplying the window size by the content scale.
Extent get_window_drawable_size(const int index); prism::Extent get_window_drawable_size(const int index);
/// Query whether or not the window is focused. /// Query whether or not the window is focused.
bool is_window_focused(const int index); bool is_window_focused(const int index);
@ -111,10 +111,10 @@ namespace platform {
void set_window_focused(const int index); void set_window_focused(const int index);
/// Sets the window position to the offset provided. /// Sets the window position to the offset provided.
void set_window_position(const int index, const Offset offset); void set_window_position(const int index, const prism::Offset offset);
/// Sets the window to the specified size. The platform will handle the subsequent resize events. /// Sets the window to the specified size. The platform will handle the subsequent resize events.
void set_window_size(const int index, const Extent extent); void set_window_size(const int index, const prism::Extent extent);
/// Sets the window title. /// Sets the window title.
void set_window_title(const int index, const std::string_view title); void set_window_title(const int index, const std::string_view title);
@ -126,10 +126,10 @@ namespace platform {
int get_keycode(const InputButton key); int get_keycode(const InputButton key);
/// Returns the current moue cursor position, relative to the window. /// Returns the current moue cursor position, relative to the window.
Offset get_cursor_position(); prism::Offset get_cursor_position();
/// Returns the current moue cursor position, relative to the monitor. /// Returns the current moue cursor position, relative to the monitor.
Offset get_screen_cursor_position(); prism::Offset get_screen_cursor_position();
/// Queries whether or not the mouse button requested is pressed or not. /// Queries whether or not the mouse button requested is pressed or not.
bool get_mouse_button_down(const int button); bool get_mouse_button_down(const int button);

View file

@ -5,7 +5,7 @@
#include <array> #include <array>
#include <functional> #include <functional>
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
#include <sol.hpp> #include <sol.hpp>
#endif #endif
@ -258,7 +258,7 @@ public:
// script // script
std::string script_path; std::string script_path;
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
sol::environment env; sol::environment env;
#endif #endif
}; };

View file

@ -5,7 +5,7 @@
#include <map> #include <map>
#include <functional> #include <functional>
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
#include <sol.hpp> #include <sol.hpp>
#endif #endif
@ -36,7 +36,7 @@ namespace ui {
void add_listener(const std::string& id, std::function<void()> callback); void add_listener(const std::string& id, std::function<void()> callback);
Extent extent; prism::Extent extent;
bool view_changed = false; bool view_changed = false;
GFXBuffer* glyph_buffer = nullptr; GFXBuffer* glyph_buffer = nullptr;
@ -45,7 +45,7 @@ namespace ui {
std::string script_path; std::string script_path;
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
sol::environment env; sol::environment env;
#endif #endif
}; };

View file

@ -148,7 +148,7 @@ Scene* Engine::load_scene(const file::Path path) {
for(auto& [obj, toParent] : parentQueue) for(auto& [obj, toParent] : parentQueue)
scene->get<Data>(obj).parent = scene->find_object(toParent); scene->get<Data>(obj).parent = scene->find_object(toParent);
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
scene->env = sol::environment(lua, sol::create, lua.globals()); scene->env = sol::environment(lua, sol::create, lua.globals());
scene->env["scene"] = scene.get(); scene->env["scene"] = scene.get();
@ -163,7 +163,7 @@ Scene* Engine::load_scene(const file::Path path) {
_scenes.push_back(std::move(scene)); _scenes.push_back(std::move(scene));
_current_scene = _scenes.back().get(); _current_scene = _scenes.back().get();
_path_to_scene[path] = _scenes.back().get(); _path_to_scene[path.string()] = _scenes.back().get();
return _scenes.back().get(); return _scenes.back().get();
} }
@ -402,7 +402,7 @@ void Engine::save_prefab(const Object root, const std::string_view path) {
out << j; out << j;
} }
void Engine::add_window(void* native_handle, const int identifier, const Extent extent) { void Engine::add_window(void* native_handle, const int identifier, const prism::Extent extent) {
Expects(native_handle != nullptr); Expects(native_handle != nullptr);
Expects(identifier >= 0); Expects(identifier >= 0);
@ -429,7 +429,7 @@ void Engine::remove_window(const int identifier) {
}); });
} }
void Engine::resize(const int identifier, const Extent extent) { void Engine::resize(const int identifier, const prism::Extent extent) {
Expects(identifier >= 0); Expects(identifier >= 0);
auto window = get_window(identifier); auto window = get_window(identifier);
@ -466,7 +466,7 @@ void Engine::process_key_up(const unsigned int keyCode) {
_imgui->process_key_up(keyCode); _imgui->process_key_up(keyCode);
} }
void Engine::process_mouse_down(const int button, const Offset offset) { void Engine::process_mouse_down(const int button, const prism::Offset offset) {
Expects(offset.x >= 0); Expects(offset.x >= 0);
Expects(offset.y >= 0); Expects(offset.y >= 0);
@ -820,7 +820,7 @@ void Engine::stop_animation(Object target) {
} }
void Engine::create_lua_interface() { void Engine::create_lua_interface() {
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table, sol::lib::string, sol::lib::math); lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table, sol::lib::string, sol::lib::math);
lua.new_usertype<Cutscene>("Cutscene"); lua.new_usertype<Cutscene>("Cutscene");

View file

@ -23,7 +23,7 @@ std::optional<file::File> file::open(const file::Path path, const bool binary_mo
fixed_path = domain_data[static_cast<int>(Domain::Internal)] / path.lexically_relative(root_path(path)); fixed_path = domain_data[static_cast<int>(Domain::Internal)] / path.lexically_relative(root_path(path));
} }
FILE* file = fopen(fixed_path.c_str(), binary_mode ? "rb" : "r"); FILE* file = fopen(fixed_path.string().c_str(), binary_mode ? "rb" : "r");
if(file == nullptr) { if(file == nullptr) {
console::error(System::File, "Failed to open file handle from {}!", path); console::error(System::File, "Failed to open file handle from {}!", path);
return {}; return {};

View file

@ -78,7 +78,7 @@ void ui::Screen::process_mouse(const int x, const int y) {
Expects(x >= 0); Expects(x >= 0);
Expects(y >= 0); Expects(y >= 0);
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
for(auto& element : elements) { for(auto& element : elements) {
if(x > element.absolute_x && if(x > element.absolute_x &&
y > element.absolute_y && y > element.absolute_y &&
@ -196,7 +196,7 @@ ui::Screen::Screen(const file::Path path) {
elements.push_back(ue); elements.push_back(ue);
} }
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
env = sol::environment(engine->lua, sol::create, engine->lua.globals()); env = sol::environment(engine->lua, sol::create, engine->lua.globals());
env["screen"] = this; env["screen"] = this;
@ -213,7 +213,7 @@ void ui::Screen::add_listener(const std::string& id, std::function<void()> callb
} }
void ui::Screen::process_event(const std::string& type, const std::string data) { void ui::Screen::process_event(const std::string& type, const std::string data) {
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) #if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
auto func = env["process_event"]; auto func = env["process_event"];
func(type, data); func(type, data);
#endif #endif

View file

@ -2,6 +2,7 @@ set(CMAKE_FOLDER "GFX Backends")
add_library(GFX INTERFACE) add_library(GFX INTERFACE)
target_include_directories(GFX INTERFACE public) target_include_directories(GFX INTERFACE public)
target_link_libraries(GFX INTERFACE Utility)
add_custom_target(GFXInterface SOURCES add_custom_target(GFXInterface SOURCES
public/gfx.hpp public/gfx.hpp

View file

@ -18,7 +18,7 @@ struct GFXRenderPassBeginInfo {
float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f; float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f;
} clear_color; } clear_color;
Rectangle render_area; prism::Rectangle render_area;
GFXRenderPass* render_pass = nullptr; GFXRenderPass* render_pass = nullptr;
GFXFramebuffer* framebuffer = nullptr; GFXFramebuffer* framebuffer = nullptr;
@ -132,7 +132,7 @@ struct GFXDrawCommand {
} set_viewport; } set_viewport;
struct SetScissorData { struct SetScissorData {
Rectangle rect; prism::Rectangle rect;
} set_scissor; } set_scissor;
struct GenerateMipmapData { struct GenerateMipmapData {
@ -284,7 +284,7 @@ public:
commands.push_back(command); commands.push_back(command);
} }
void set_scissor(const Rectangle rect) { void set_scissor(const prism::Rectangle rect) {
GFXDrawCommand command; GFXDrawCommand command;
command.type = GFXCommandType::SetScissor; command.type = GFXCommandType::SetScissor;
command.data.set_scissor.rect = rect; command.data.set_scissor.rect = rect;

View file

@ -52,7 +52,7 @@ public:
// misc operations // misc operations
GFXSize get_alignment(const GFXSize size) override; GFXSize get_alignment(const GFXSize size) override;
void render(GFXCommandBuffer* command_buffer, const int identifier) override; void submit(GFXCommandBuffer* command_buffer, const int identifier) override;
private: private:
void createInstance(std::vector<const char*> layers, std::vector<const char*> extensions); void createInstance(std::vector<const char*> layers, std::vector<const char*> extensions);

View file

@ -542,16 +542,16 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate
vkDeviceWaitIdle(device); vkDeviceWaitIdle(device);
// setup shader modules // setup shader modules
auto vertex_shader = file::read_file(FileDomain::ShaderData, std::string(info.shaders.vertex_path.data()) + ".spv"); auto vertex_shader = file::open(file::internal_domain / (std::string(info.shaders.vertex_path) + ".spv"));
vertex_shader->read_all(); vertex_shader->read_all();
auto fragment_shader = file::read_file(FileDomain::ShaderData, std::string(info.shaders.fragment_path.data()) + ".spv"); auto fragment_shader = file::open(file::internal_domain / (std::string(info.shaders.fragment_path) + ".spv"));
fragment_shader->read_all(); fragment_shader->read_all();
auto vertex_module = createShaderModule(vertex_shader->unsigned_data(), vertex_shader->size()); auto vertex_module = createShaderModule(vertex_shader->cast_data<unsigned char>(), vertex_shader->size());
name_object(device, VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)vertex_module, info.shaders.vertex_path); name_object(device, VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)vertex_module, info.shaders.vertex_path);
auto fragment_module = createShaderModule(fragment_shader->unsigned_data(), fragment_shader->size()); auto fragment_module = createShaderModule(fragment_shader->cast_data<unsigned char>(), fragment_shader->size());
name_object(device, VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)fragment_module, info.shaders.fragment_path); name_object(device, VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)fragment_module, info.shaders.fragment_path);
VkPipelineShaderStageCreateInfo vertShaderStageInfo = {}; VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
@ -754,7 +754,7 @@ GFXSize GFXVulkan::get_alignment(GFXSize size) {
return (size + minUboAlignment / 2) & ~int(minUboAlignment - 1); return (size + minUboAlignment / 2) & ~int(minUboAlignment - 1);
} }
void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) { void GFXVulkan::submit(GFXCommandBuffer *command_buffer, const int identifier) {
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, std::numeric_limits<uint64_t>::max()); vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, std::numeric_limits<uint64_t>::max());
uint32_t imageIndex = 0; uint32_t imageIndex = 0;
@ -831,8 +831,8 @@ void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) {
vkCmdSetScissor(commandBuffers[imageIndex], 0, 1, &scissor); vkCmdSetScissor(commandBuffers[imageIndex], 0, 1, &scissor);
} }
renderPassInfo.renderArea.offset = { command.data.set_render_pass.viewport.x, command.data.set_render_pass.viewport.y }; renderPassInfo.renderArea.offset = { command.data.set_render_pass.render_area.offset.x, command.data.set_render_pass.render_area.offset.y };
renderPassInfo.renderArea.extent = { command.data.set_render_pass.viewport.width, command.data.set_render_pass.viewport.height }; renderPassInfo.renderArea.extent = { command.data.set_render_pass.render_area.extent.width, command.data.set_render_pass.render_area.extent.height };
std::vector<VkClearValue> clearColors; std::vector<VkClearValue> clearColors;
if (renderPass != nullptr) { if (renderPass != nullptr) {
@ -888,7 +888,7 @@ void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) {
case GFXCommandType::SetPushConstant: case GFXCommandType::SetPushConstant:
{ {
if(currentPipeline != nullptr) if(currentPipeline != nullptr)
vkCmdPushConstants(commandBuffers[imageIndex], currentPipeline->layout, VK_SHADER_STAGE_ALL, 0, command.data.set_push_constant.size, command.data.set_push_constant.bytes); vkCmdPushConstants(commandBuffers[imageIndex], currentPipeline->layout, VK_SHADER_STAGE_ALL, 0, command.data.set_push_constant.size, command.data.set_push_constant.bytes.data());
} }
break; break;
case GFXCommandType::BindShaderBuffer: case GFXCommandType::BindShaderBuffer:

View file

@ -21,8 +21,12 @@ enum class Level {
}; };
namespace console { namespace console {
template<typename Arg> inline void internal_format(std::string& msg, const std::string& arg) {
void internal_format(std::string& msg, const Arg& arg) { auto pos = msg.find_first_of("{}");
msg.replace(pos, 2, arg);
}
inline void internal_format(std::string& msg, const char*& arg) {
auto pos = msg.find_first_of("{}"); auto pos = msg.find_first_of("{}");
msg.replace(pos, 2, arg); msg.replace(pos, 2, arg);
} }
@ -33,7 +37,7 @@ namespace console {
void internal_print(const Level level, const System system, const std::string_view format, Args&&... args) { void internal_print(const Level level, const System system, const std::string_view format, Args&&... args) {
auto msg = std::string(format); auto msg = std::string(format);
((internal_format<Args>(msg, args)), ...); ((internal_format(msg, args)), ...);
process_message(level, system, msg); process_message(level, system, msg);
} }

View file

@ -136,6 +136,6 @@ protected:
// If no path markers, return current working directory. // If no path markers, return current working directory.
// Otherwise, strip file name and return path leading up to it. // Otherwise, strip file name and return path leading up to it.
virtual std::string getDirectory(const std::string) const { virtual std::string getDirectory(const std::string) const {
return file::get_domain_path(file::Domain::Internal); return file::get_domain_path(file::Domain::Internal).string();
} }
}; };

View file

@ -11,7 +11,7 @@ class GFXTexture;
class GaussianHelper { class GaussianHelper {
public: public:
GaussianHelper(GFX* gfx, const Extent extent); GaussianHelper(GFX* gfx, const prism::Extent extent);
GFXTexture* render(GFXCommandBuffer* commandBuffer,GFXTexture* source); GFXTexture* render(GFXCommandBuffer* commandBuffer,GFXTexture* source);
@ -23,5 +23,5 @@ public:
GFXFramebuffer* fboA = nullptr, *fboB = nullptr; GFXFramebuffer* fboA = nullptr, *fboB = nullptr;
private: private:
Extent extent; prism::Extent extent;
}; };

View file

@ -15,7 +15,7 @@ class ImGuiPass : public Pass {
public: public:
void initialize() override; void initialize() override;
void resize(const Extent extent) override; void resize(const prism::Extent extent) override;
void render_post(GFXCommandBuffer* command_buffer, const int index) override; void render_post(GFXCommandBuffer* command_buffer, const int index) override;

View file

@ -17,7 +17,7 @@ public:
virtual void initialize() {} virtual void initialize() {}
virtual void resize([[maybe_unused]] const Extent extent) {} virtual void resize([[maybe_unused]] const prism::Extent extent) {}
virtual void render_scene([[maybe_unused]] Scene& scene, virtual void render_scene([[maybe_unused]] Scene& scene,
[[maybe_unused]] GFXCommandBuffer* commandBuffer) {} [[maybe_unused]] GFXCommandBuffer* commandBuffer) {}

View file

@ -2,6 +2,8 @@
#include <string_view> #include <string_view>
#include <vector> #include <vector>
#include <cmath>
#include "file.hpp" #include "file.hpp"
#include "pass.hpp" #include "pass.hpp"
#include "matrix.hpp" #include "matrix.hpp"
@ -85,8 +87,8 @@ class Renderer {
public: public:
Renderer(GFX* gfx, const bool enable_imgui = true); Renderer(GFX* gfx, const bool enable_imgui = true);
void resize(const Extent extent); void resize(const prism::Extent extent);
void resize_viewport(const Extent extent); void resize_viewport(const prism::Extent extent);
void set_screen(ui::Screen* screen); void set_screen(ui::Screen* screen);
void init_screen(ui::Screen* screen); void init_screen(ui::Screen* screen);
@ -145,15 +147,15 @@ public:
GFXTexture* viewportColorTexture = nullptr; GFXTexture* viewportColorTexture = nullptr;
bool viewport_mode = false; bool viewport_mode = false;
Extent viewport_extent; prism::Extent viewport_extent;
bool gui_only_mode = false; bool gui_only_mode = false;
Extent get_extent() const { prism::Extent get_extent() const {
return viewport_mode ? viewport_extent : extent; return viewport_mode ? viewport_extent : extent;
} }
Extent get_render_extent() const { prism::Extent get_render_extent() const {
const auto extent = get_extent(); const auto extent = get_extent();
return {static_cast<uint32_t>(std::max(int(extent.width * render_options.render_scale), 1)), return {static_cast<uint32_t>(std::max(int(extent.width * render_options.render_scale), 1)),
@ -186,7 +188,7 @@ private:
void createBRDF(); void createBRDF();
GFX* gfx = nullptr; GFX* gfx = nullptr;
Extent extent; prism::Extent extent;
ui::Screen* current_screen = nullptr; ui::Screen* current_screen = nullptr;

View file

@ -26,7 +26,7 @@ private:
void create_pipelines(); void create_pipelines();
void create_offscreen_resources(); void create_offscreen_resources();
Extent extent; prism::Extent extent;
Renderer* renderer = nullptr; Renderer* renderer = nullptr;
GFXTexture* area_image = nullptr; GFXTexture* area_image = nullptr;

View file

@ -3,7 +3,7 @@
#include "gfx_commandbuffer.hpp" #include "gfx_commandbuffer.hpp"
#include "gfx.hpp" #include "gfx.hpp"
GaussianHelper::GaussianHelper(GFX* gfx, const Extent extent) : extent(extent) { GaussianHelper::GaussianHelper(GFX* gfx, const prism::Extent extent) : extent(extent) {
// render pass // render pass
GFXRenderPassCreateInfo renderPassInfo = {}; GFXRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.attachments.push_back(GFXPixelFormat::RGBA_32F); renderPassInfo.attachments.push_back(GFXPixelFormat::RGBA_32F);

View file

@ -21,7 +21,7 @@ void ImGuiPass::initialize() {
create_font_texture(); create_font_texture();
} }
void ImGuiPass::resize(const Extent extent) { void ImGuiPass::resize(const prism::Extent extent) {
GFXGraphicsPipelineCreateInfo createInfo; GFXGraphicsPipelineCreateInfo createInfo;
createInfo.label = "ImGui"; createInfo.label = "ImGui";
createInfo.shaders.vertex_path = "imgui.vert"; createInfo.shaders.vertex_path = "imgui.vert";

View file

@ -97,7 +97,7 @@ Renderer::Renderer(GFX* gfx, const bool enable_imgui) : gfx(gfx) {
createBRDF(); createBRDF();
} }
void Renderer::resize(const Extent extent) { void Renderer::resize(const prism::Extent extent) {
this->extent = extent; this->extent = extent;
if(!viewport_mode) { if(!viewport_mode) {
@ -117,7 +117,7 @@ void Renderer::resize(const Extent extent) {
pass->resize(extent); pass->resize(extent);
} }
void Renderer::resize_viewport(const Extent extent) { void Renderer::resize_viewport(const prism::Extent extent) {
this->viewport_extent = extent; this->viewport_extent = extent;
createOffscreenResources(); createOffscreenResources();

View file

@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) #if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) || defined(PLATFORM_WINDOWS)
#include <spirv_cpp.hpp> #include <spirv_cpp.hpp>
#include <spirv_msl.hpp> #include <spirv_msl.hpp>
#include <SPIRV/GlslangToSpv.h> #include <SPIRV/GlslangToSpv.h>
@ -112,22 +112,20 @@ const TBuiltInResource DefaultTBuiltInResource = {
/* .maxTaskWorkGroupSizeY_NV = */ 1, /* .maxTaskWorkGroupSizeY_NV = */ 1,
/* .maxTaskWorkGroupSizeZ_NV = */ 1, /* .maxTaskWorkGroupSizeZ_NV = */ 1,
/* .maxMeshViewCountNV = */ 4, /* .maxMeshViewCountNV = */ 4,
/* .maxDualSourceDrawBuffersEXT = */ 4,
#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) /* .limits = */ TLimits{
/* .maxDualSourceDrawBuffersEXT = */ 1, /* .nonInductiveForLoops = */ true,
#endif /* .whileLoops = */ true,
/* .doWhileLoops = */ true,
/* .generalUniformIndexing = */ true,
/* .generalAttributeMatrixVectorIndexing = */ true,
/* .generalVaryingIndexing = */ true,
/* .generalSamplerIndexing = */ true,
/* .generalVariableIndexing = */ true,
/* .generalConstantMatrixVectorIndexing = */ true,
}};
/* .limits = */ {
/* .nonInductiveForLoops = */ 1,
/* .whileLoops = */ 1,
/* .doWhileLoops = */ 1,
/* .generalUniformIndexing = */ 1,
/* .generalAttributeMatrixVectorIndexing = */ 1,
/* .generalVaryingIndexing = */ 1,
/* .generalSamplerIndexing = */ 1,
/* .generalVariableIndexing = */ 1,
/* .generalConstantMatrixVectorIndexing = */ 1,
}};
const std::vector<unsigned int> CompileGLSL(const std::string& filename, EShLanguage ShaderType, bool skinned, bool cubemap) { const std::vector<unsigned int> CompileGLSL(const std::string& filename, EShLanguage ShaderType, bool skinned, bool cubemap) {
std::string newString = "#version 430 core\n"; std::string newString = "#version 430 core\n";
@ -163,7 +161,7 @@ const std::vector<unsigned int> CompileGLSL(const std::string& filename, EShLang
EShMessages messages = (EShMessages) (EShMsgSpvRules); EShMessages messages = (EShMessages) (EShMsgSpvRules);
DirStackFileIncluder includer; DirStackFileIncluder includer;
includer.pushExternalLocalDirectory(file::get_domain_path(file::Domain::Internal)); includer.pushExternalLocalDirectory(file::get_domain_path(file::Domain::Internal).string());
if (!Shader.parse(&Resources, 100, false, (EShMessages)0, includer)) { if (!Shader.parse(&Resources, 100, false, (EShMessages)0, includer)) {
std::cout << Shader.getInfoLog() << std::endl; std::cout << Shader.getInfoLog() << std::endl;

View file

@ -2,28 +2,30 @@
#include <cstdint> #include <cstdint>
/// A 2D extent. namespace prism {
struct Extent { /// A 2D extent.
Extent() : width(0), height(0) {} struct Extent {
Extent(const uint32_t width, const uint32_t height) : width(width), height(height) {} Extent() : width(0), height(0) {}
Extent(const uint32_t width, const uint32_t height) : width(width), height(height) {}
uint32_t width = 0, height = 0; uint32_t width = 0, height = 0;
}; };
/// A 2D offset. /// A 2D offset.
struct Offset { struct Offset {
Offset() : x(0), y(0) {} Offset() : x(0), y(0) {}
Offset(const int32_t x, const int32_t y) : x(x), y(y) {} Offset(const int32_t x, const int32_t y) : x(x), y(y) {}
int32_t x = 0, y = 0; int32_t x = 0, y = 0;
}; };
/// A 2D rectangle defined by a offset and an etent. /// A 2D rectangle defined by a offset and an etent.
struct Rectangle { struct Rectangle {
Rectangle() {} Rectangle() {}
Rectangle(const Offset offset, const Extent extent) : offset(offset), extent(extent) {} Rectangle(const Offset offset, const Extent extent) : offset(offset), extent(extent) {}
Rectangle(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) : offset(x, y), extent(width, height) {} Rectangle(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) : offset(x, y), extent(width, height) {}
Offset offset; Offset offset;
Extent extent; Extent extent;
}; };
}

View file

@ -68,10 +68,10 @@
// This will be inlined as part of ImVec2 and ImVec4 class declarations. // This will be inlined as part of ImVec2 and ImVec4 class declarations.
#define IM_VEC2_CLASS_EXTRA \ #define IM_VEC2_CLASS_EXTRA \
ImVec2(const Offset& f) { x = static_cast<float>(f.x); y = static_cast<float>(f.y); } \ ImVec2(const prism::Offset& f) { x = static_cast<float>(f.x); y = static_cast<float>(f.y); } \
operator Offset() const { return Offset(static_cast<int32_t>(x), static_cast<int32_t>(y)); } \ operator prism::Offset() const { return prism::Offset(static_cast<int32_t>(x), static_cast<int32_t>(y)); } \
ImVec2(const Extent& f) { x = static_cast<float>(f.width); y = static_cast<float>(f.height); } \ ImVec2(const prism::Extent& f) { x = static_cast<float>(f.width); y = static_cast<float>(f.height); } \
operator Extent() const { return Extent(static_cast<uint32_t>(x), static_cast<uint32_t>(y)); } operator prism::Extent() const { return prism::Extent(static_cast<uint32_t>(x), static_cast<uint32_t>(y)); }
/*#define IM_VEC4_CLASS_EXTRA \ /*#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \

View file

@ -1,63 +1,9 @@
#include "file.hpp" #include "file.hpp"
#include <array> void file::set_domain_path(const file::Domain domain, const file::Path path) {
domain_data[(int)domain] = path.string();
#include "string_utils.hpp"
#include "log.hpp"
struct DomainData {
std::string path;
};
std::array<DomainData, 3> domain_data;
void file::initialize_domain(const FileDomain domain, const AccessMode mode, const std::string_view path) {
domain_data[(int)domain].path = path;
} }
std::string file::clean_path(const std::string_view path) { file::Path file::get_writeable_directory() {
auto p = replaceSubstring(std::string(path), "%20", " "); return "";
p = replaceSubstring(p, "%7C", "|");
// this is a path returned by an editor, so skip it
// TODO: find a better way to do this!! NOO!!
if (p.find("file:///") != std::string::npos)
return p.substr(7, p.length());
else
return p;
}
/*
* converts an absolute path to a domain relative one
*/
std::string file::get_relative_path(const FileDomain domain, const std::string_view path) {
auto p = removeSubstring(std::string(path), domain_data[(int)domain].path + "/");
return p;
}
std::string file::get_writeable_path(const std::string_view path) {
return std::string(path);
}
std::optional<File> file::read_file(const FileDomain domain, const std::string_view path, bool binary_mode) {
auto s = std::string(path);
s = domain_data[(int)domain].path + "/" + s;
FILE* file = fopen(s.c_str(), binary_mode ? "rb" : "r");
if (file == nullptr) {
console::error(System::File, "Failed to open file handle from {}!", s);
return {};
}
File f;
f.handle = file;
return f;
}
std::string file::get_file_path(const FileDomain domain, const std::string_view path) {
auto s = std::string(path);
return domain_data[(int)domain].path + "/" + s;
} }

View file

@ -2,57 +2,22 @@
#define UNICODE #define UNICODE
#endif #endif
#include <fmt/printf.h> #define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
#undef far
#undef near
#include "platform.hpp" #include "platform.hpp"
#include <gfx_vulkan.hpp> #include <gfx_vulkan.hpp>
#include <gfx_dummy.hpp>
#include <gfx_opengl.hpp>
typedef HGLRC WINAPI wglCreateContextAttribsARB_type(HDC hdc, HGLRC hShareContext, #include <@APP_INCLUDE@>
const int *attribList);
wglCreateContextAttribsARB_type *wglCreateContextAttribsARB;
// See https://www.opengl.org/registry/specs/ARB/wgl_create_context.txt for all values
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
typedef BOOL WINAPI wglChoosePixelFormatARB_type(HDC hdc, const int *piAttribIList,
const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
wglChoosePixelFormatARB_type *wglChoosePixelFormatARB;
// See https://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt for all values
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_TYPE_RGBA_ARB 0x202B
#if @IS_GAME@
#include <@GAME_INCLUDE@>
#else
#include <@EDITOR_INCLUDE@>
#endif
#include <engine.hpp> #include <engine.hpp>
GFX* ginterface = nullptr; GFX* ginterface = nullptr;
#if @IS_GAME@ @APP_CLASS@* app = nullptr;
@GAME_CLASS@* game = nullptr;
#else
@EDITOR_CLASS@* editor = nullptr;
#endif
HINSTANCE instance = NULL; HINSTANCE instance = NULL;
HWND window = NULL; HWND window = NULL;
@ -64,11 +29,7 @@ int defaultWidth, defaultHeight;
bool shouldConfineMouse = false; bool shouldConfineMouse = false;
#include <GL/GL.h> const wchar_t CLASS_NAME[] = L"@APP_NAME@";
#pragma comment (lib, "opengl32.lib")
const wchar_t CLASS_NAME[] = L"@GAME_NAME@";
wchar_t* convertToUnicode(const char* str) { wchar_t* convertToUnicode(const char* str) {
size_t ret = 0; size_t ret = 0;
@ -81,24 +42,22 @@ wchar_t* convertToUnicode(const char* str) {
return buf; return buf;
} }
void platform::openWindow(const char* title, int x, int y, int width, int height, WindowFlags flags) { int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) {
RECT wr = {0, 0, width, height}; RECT wr = {rect.offset.x, rect.offset.y, rect.extent.width, rect.extent.height};
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
defaultWidth = width; defaultWidth = rect.extent.width;
defaultHeight = height; defaultHeight = rect.extent.height;
std::string new_title = title + std::string(" (") + ginterface->getName() + ")"; wchar_t* title_uni = convertToUnicode(title.data());
wchar_t* title_uni = convertToUnicode(new_title.c_str());
window = CreateWindowEx( window = CreateWindowEx(
0, 0,
CLASS_NAME, CLASS_NAME,
title_uni, title_uni,
flags == WindowFlags::Resizable ? WS_OVERLAPPEDWINDOW : (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX), // Window style flags == WindowFlags::Resizable ? WS_OVERLAPPEDWINDOW : (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX), // Window style
x, rect.offset.x,
y, rect.offset.y,
wr.right - wr.left, wr.right - wr.left,
wr.bottom - wr.top, wr.bottom - wr.top,
NULL, NULL,
@ -111,16 +70,18 @@ void platform::openWindow(const char* title, int x, int y, int width, int height
ShowWindow(window, cmdShow); ShowWindow(window, cmdShow);
engine->addWindow(window, width, height); engine->add_window(window, 0, rect.extent);
return 0;
} }
void platform::closeWindow() { void platform::close_window(const int identifier) {
// does nothing // does nothing
} }
bool showingCursor = true; bool showingCursor = true;
void platform::setCaptureMouse(bool capture) { void platform::capture_mouse(const bool capture) {
shouldConfineMouse = capture; shouldConfineMouse = capture;
// the reason why we do this is because windows expects a ShowCursor(false) to be followed by a ShowCursor(true), // the reason why we do this is because windows expects a ShowCursor(false) to be followed by a ShowCursor(true),
@ -135,7 +96,7 @@ void platform::setCaptureMouse(bool capture) {
} }
} }
std::tuple<int, int> platform::getCursorPosition() { prism::Offset platform::get_cursor_position() {
POINT p; POINT p;
GetCursorPos(&p); GetCursorPos(&p);
ScreenToClient(window, &p); ScreenToClient(window, &p);
@ -143,105 +104,26 @@ std::tuple<int, int> platform::getCursorPosition() {
return {p.x, p.y}; return {p.x, p.y};
} }
std::tuple<int, int> platform::getWindowPosition() { prism::Offset platform::get_window_position(const int identifier) {
RECT rect; RECT rect;
GetWindowRect(window, &rect); GetWindowRect(window, &rect);
return {rect.left, rect.top}; return {rect.left, rect.top};
} }
std::tuple<int, int> platform::getWindowSize() { prism::Extent platform::get_window_size(const int identifier) {
RECT rect; RECT rect;
GetClientRect(window, &rect); GetClientRect(window, &rect);
int width = rect.right - rect.left; int width = rect.right - rect.left;
int height = rect.bottom- rect.top; int height = rect.bottom- rect.top;
return {width, height}; return {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
} }
static void
init_opengl_extensions(void)
{
// Before we can load extensions, we need a dummy OpenGL context, created using a dummy window.
// We use a dummy window because you can only set the pixel format for a window once. For the
// real window, we want to use wglChoosePixelFormatARB (so we can potentially specify options
// that aren't available in PIXELFORMATDESCRIPTOR), but we can't load and use that before we
// have a context.
WNDCLASSA window_class = {};
window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
window_class.lpfnWndProc = DefWindowProcA;
window_class.hInstance = GetModuleHandle(0);
window_class.lpszClassName = "Dummy_WGL_djuasiodwa";
if (!RegisterClassA(&window_class)) {
fmt::print("Failed to register dummy OpenGL window.\n");
}
HWND dummy_window = CreateWindowExA(
0,
window_class.lpszClassName,
"Dummy OpenGL Window",
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
window_class.hInstance,
0);
if (!dummy_window) {
fmt::print("Failed to create dummy OpenGL window.\n");
}
HDC dummy_dc = GetDC(dummy_window);
PIXELFORMATDESCRIPTOR pfd = {};
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.cColorBits = 32;
pfd.cAlphaBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
if (!pixel_format) {
fmt::print("Failed to find a suitable pixel format.\n");
}
if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) {
fmt::print("Failed to set the pixel format.");
}
HGLRC dummy_context = wglCreateContext(dummy_dc);
if (!dummy_context) {
fmt::print("Failed to create a dummy OpenGL rendering context.\n");
}
if (!wglMakeCurrent(dummy_dc, dummy_context)) {
fmt::print("Failed to activate dummy OpenGL rendering context.\n");
}
wglCreateContextAttribsARB = (wglCreateContextAttribsARB_type*)wglGetProcAddress(
"wglCreateContextAttribsARB");
wglChoosePixelFormatARB = (wglChoosePixelFormatARB_type*)wglGetProcAddress(
"wglChoosePixelFormatARB");
wglMakeCurrent(dummy_dc, 0);
wglDeleteContext(dummy_context);
ReleaseDC(dummy_window, dummy_dc);
DestroyWindow(dummy_window);
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) {
{
AllocConsole(); AllocConsole();
FILE* stream; FILE* stream;
freopen_s(&stream, "CONOUT$", "w", stdout); freopen_s(&stream, "CONOUT$", "w", stdout);
@ -258,30 +140,21 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow
instance = hInstance; instance = hInstance;
cmdShow = nCmdShow; cmdShow = nCmdShow;
engine = new Engine(); engine = new Engine(0, nullptr);
ginterface = new GFXVulkan(); ginterface = new GFXVulkan();
if(ginterface->initialize()) { if(ginterface->initialize(GFXCreateInfo())) {
engine->setGFX(ginterface); engine->set_gfx(ginterface);
} else { } else {
return -1; return -1;
} }
#if @IS_GAME@ app = new @APP_CLASS@();
game = new @GAME_CLASS@(); engine->set_app(app);
engine->setGame(game);
#else
editor = new @EDITOR_CLASS@();
engine->setEditor(editor);
#endif
app::open(engine); app_main(engine);
#if @IS_GAME@ app->initialize_render();
game->initializeRender();
#else
editor->initializeRender();
#endif
MSG msg = { }; MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0)) while (GetMessage(&msg, NULL, 0, 0))
@ -290,11 +163,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow
DispatchMessage(&msg); DispatchMessage(&msg);
} }
#if @IS_GAME@ delete app;
delete game;
#else
delete editor;
#endif
delete ginterface; delete ginterface;
delete engine; delete engine;
@ -308,59 +177,9 @@ int timeout = 0;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) { switch (uMsg) {
case WM_CREATE:
{
if(ginterface->requiredContext() == GFXContext::OpenGL) {
fmt::print("Creating OpenGL context...\n");
init_opengl_extensions();
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
32, // Colordepth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24, // Number of bits for the depthbuffer
8, // Number of bits for the stencilbuffer
0, // Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
HDC ourWindowHandleToDeviceContext = GetDC(hwnd);
int letWindowsChooseThisPixelFormat;
letWindowsChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext, &pfd);
SetPixelFormat(ourWindowHandleToDeviceContext,letWindowsChooseThisPixelFormat, &pfd);
int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0,
};
HGLRC ourOpenGLRenderingContext = wglCreateContextAttribsARB(ourWindowHandleToDeviceContext,0, attribs);
wglMakeCurrent (ourWindowHandleToDeviceContext, ourOpenGLRenderingContext);
windowDC = GetDC(hwnd);
MessageBoxA(0,(char*)glGetString(GL_VERSION), "OPENGL VERSION",0);
}
}
return 0;
case WM_DESTROY: case WM_DESTROY:
{ {
engine->prepareQuit(); engine->prepare_quit();
PostQuitMessage(0); PostQuitMessage(0);
} }
return 0; return 0;
@ -388,19 +207,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
HCURSOR arrowCursor = LoadCursor(NULL, IDC_ARROW); HCURSOR arrowCursor = LoadCursor(NULL, IDC_ARROW);
SetCursor(arrowCursor); SetCursor(arrowCursor);
#if @IS_GAME@ engine->begin_frame(1.0f / 60.0f);
#else
editor->beginFrame();
#endif
engine->update(1.0f / 60.0f); engine->update(1.0f / 60.0f);
engine->render(); engine->render(0);
if(ginterface->requiredContext() == GFXContext::OpenGL) if(engine->is_quitting()) {
SwapBuffers(windowDC); engine->prepare_quit();
if(engine->isQuitting()) {
engine->prepareQuit();
PostQuitMessage(0); PostQuitMessage(0);
} }
} }
@ -410,41 +222,17 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
int xPos = GET_X_LPARAM(lParam); int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam); int yPos = GET_Y_LPARAM(lParam);
engine->processMouse(0, xPos, yPos); engine->process_mouse_down(0, {xPos, yPos});
}
return 0;
case WM_LBUTTONUP:
{
engine->processMouseReleased(0);
}
return 0;
case WM_RBUTTONDOWN:
{
engine->processMouse(1, 0, 0);
}
return 0;
case WM_RBUTTONUP:
{
engine->processMouseReleased(1);
}
return 0;
case WM_MOUSEMOVE:
{
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
engine->processMouseMove(xPos, yPos);
} }
return 0; return 0;
case WM_KEYDOWN: case WM_KEYDOWN:
{ {
engine->processKey((unsigned int)wParam); engine->process_key_down((unsigned int)wParam);
} }
return 0; return 0;
case WM_KEYUP: case WM_KEYUP:
{ {
engine->processKeyUp((unsigned int)wParam); engine->process_key_up((unsigned int)wParam);
} }
return 0; return 0;
case WM_SIZE: case WM_SIZE:
@ -458,7 +246,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if(width == defaultWidth && height == defaultHeight) { if(width == defaultWidth && height == defaultHeight) {
// don't resize when the window was first created!! // don't resize when the window was first created!!
} else { } else {
engine->resize(width, height); engine->resize(0, {static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
} }
} }
@ -468,8 +256,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hwnd, uMsg, wParam, lParam); return DefWindowProc(hwnd, uMsg, wParam, lParam);
} }
void platform::setWindowTitle(const char* title) { void platform::set_window_title(const int identifier, const std::string_view title) {
std::string new_title = title + std::string(" (") + ginterface->getName() + ")"; SetWindowTextA(window, title.data());
SetWindowTextA(window, new_title.c_str());
} }

View file

@ -39,7 +39,7 @@ int platform::get_keycode(const InputButton key) {
return inputToKeyCode[key]; return inputToKeyCode[key];
} }
void platform::open_dialog(const bool existing, const std::function<void(std::string)> returnFunction) { void platform::open_dialog(const bool existing, const std::function<void(std::string)> returnFunction, const bool openDirectory) {
const auto openDialog = [returnFunction] { const auto openDialog = [returnFunction] {
const int BUFSIZE = 1024; const int BUFSIZE = 1024;
char buffer[BUFSIZE] = { 0 }; char buffer[BUFSIZE] = { 0 };