Fix errors when compiling with MSVC
This commit is contained in:
parent
7a905fcea6
commit
94953c62f0
34 changed files with 186 additions and 440 deletions
|
@ -67,6 +67,7 @@ macro(manual_download)
|
|||
set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
|
||||
set(BUILD_EXTERNAL 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)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace std {
|
|||
template <>
|
||||
struct hash<file::Path> {
|
||||
std::size_t operator()(const file::Path& k) const {
|
||||
return hash<std::string>()(k);
|
||||
return (std::hash<std::string>()(k.string()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "renderer.hpp"
|
||||
#include "assetptr.hpp"
|
||||
|
||||
class Texture;
|
||||
class MaterialNode;
|
||||
|
||||
enum class DataType {
|
||||
|
@ -29,6 +29,8 @@ inline bool operator==(const MaterialConnector& a, const MaterialConnector& b) {
|
|||
return a.name == b.name;
|
||||
}
|
||||
|
||||
class Texture;
|
||||
|
||||
struct MaterialProperty {
|
||||
std::string name;
|
||||
DataType type;
|
||||
|
|
|
@ -30,7 +30,7 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path) {
|
|||
}
|
||||
|
||||
auto mesh = std::make_unique<Mesh>();
|
||||
mesh->path = path;
|
||||
mesh->path = path.string();
|
||||
|
||||
enum MeshType : int {
|
||||
Static,
|
||||
|
@ -221,7 +221,7 @@ std::unique_ptr<Texture> load_texture(const file::Path path) {
|
|||
Expects(height > 0);
|
||||
|
||||
auto texture = std::make_unique<Texture>();
|
||||
texture->path = path;
|
||||
texture->path = path.string();
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
|
||||
|
@ -264,7 +264,7 @@ std::unique_ptr<Material> load_material(const file::Path path) {
|
|||
file->read_as_stream() >> j;
|
||||
|
||||
auto mat = std::make_unique<Material>();
|
||||
mat->path = path;
|
||||
mat->path = path.string();
|
||||
|
||||
if(!j.count("version") || j["version"] != 2) {
|
||||
console::error(System::Core, "Material {} failed the version check!", path);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "assetptr.hpp"
|
||||
#include "screen.hpp"
|
||||
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
|
@ -93,12 +92,16 @@ struct Light {
|
|||
|
||||
struct Camera {
|
||||
float fov = 75.0f;
|
||||
float near = 0.1f;
|
||||
float exposure = 1.0;
|
||||
float near = 1.0f;
|
||||
float exposure = 1.0f;
|
||||
|
||||
Matrix4x4 view, perspective;
|
||||
};
|
||||
|
||||
namespace ui {
|
||||
class Screen;
|
||||
}
|
||||
|
||||
struct UI {
|
||||
int width = 1920, height = 1080;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
#include <sol.hpp>
|
||||
#endif
|
||||
|
||||
|
@ -199,7 +199,7 @@ public:
|
|||
@param identifier The identifier of the new 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.
|
||||
@param identifier The identifier of the window to remove.
|
||||
|
@ -210,7 +210,7 @@ public:
|
|||
@param identifier The window that has been resized.
|
||||
@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.
|
||||
@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.
|
||||
@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.
|
||||
@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.
|
||||
bool update_physics = true;
|
||||
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
sol::state lua;
|
||||
#endif
|
||||
|
||||
|
@ -349,7 +349,7 @@ private:
|
|||
|
||||
struct Window {
|
||||
int identifier = -1;
|
||||
Extent extent;
|
||||
prism::Extent extent;
|
||||
bool quitRequested = false;
|
||||
|
||||
std::unique_ptr<Renderer> renderer = nullptr;
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <array>
|
||||
#include <filesystem>
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
namespace file {
|
||||
enum class Domain {
|
||||
System,
|
||||
|
@ -130,4 +132,11 @@ namespace file {
|
|||
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;
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Weverything"
|
||||
|
||||
#if defined(PLATFORM_MACOS) || defined(PLATFORM_IOS) || defined(PLATFORM_TVOS)
|
||||
#include <btBulletDynamicsCommon.h>
|
||||
#else
|
||||
#include <bullet/btBulletDynamicsCommon.h>
|
||||
#endif
|
||||
#include <memory>
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#include "vector.hpp"
|
||||
#include "object.hpp"
|
||||
|
|
|
@ -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.
|
||||
@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.
|
||||
@param index The window to close.
|
||||
|
@ -90,19 +90,19 @@ namespace platform {
|
|||
float get_monitor_dpi();
|
||||
|
||||
/// 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.
|
||||
Rectangle get_monitor_work_area();
|
||||
prism::Rectangle get_monitor_work_area();
|
||||
|
||||
/// 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.
|
||||
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.
|
||||
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.
|
||||
bool is_window_focused(const int index);
|
||||
|
@ -111,10 +111,10 @@ namespace platform {
|
|||
void set_window_focused(const int index);
|
||||
|
||||
/// 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.
|
||||
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.
|
||||
void set_window_title(const int index, const std::string_view title);
|
||||
|
@ -126,10 +126,10 @@ namespace platform {
|
|||
int get_keycode(const InputButton key);
|
||||
|
||||
/// 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.
|
||||
Offset get_screen_cursor_position();
|
||||
prism::Offset get_screen_cursor_position();
|
||||
|
||||
/// Queries whether or not the mouse button requested is pressed or not.
|
||||
bool get_mouse_button_down(const int button);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
#include <sol.hpp>
|
||||
#endif
|
||||
|
||||
|
@ -258,7 +258,7 @@ public:
|
|||
// script
|
||||
std::string script_path;
|
||||
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
sol::environment env;
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
#include <sol.hpp>
|
||||
#endif
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace ui {
|
|||
|
||||
void add_listener(const std::string& id, std::function<void()> callback);
|
||||
|
||||
Extent extent;
|
||||
prism::Extent extent;
|
||||
bool view_changed = false;
|
||||
|
||||
GFXBuffer* glyph_buffer = nullptr;
|
||||
|
@ -45,7 +45,7 @@ namespace ui {
|
|||
|
||||
std::string script_path;
|
||||
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
sol::environment env;
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -148,7 +148,7 @@ Scene* Engine::load_scene(const file::Path path) {
|
|||
for(auto& [obj, toParent] : parentQueue)
|
||||
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["scene"] = scene.get();
|
||||
|
||||
|
@ -163,7 +163,7 @@ Scene* Engine::load_scene(const file::Path path) {
|
|||
|
||||
_scenes.push_back(std::move(scene));
|
||||
_current_scene = _scenes.back().get();
|
||||
_path_to_scene[path] = _scenes.back().get();
|
||||
_path_to_scene[path.string()] = _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;
|
||||
}
|
||||
|
||||
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(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);
|
||||
|
||||
auto window = get_window(identifier);
|
||||
|
@ -466,7 +466,7 @@ void Engine::process_key_up(const unsigned int 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.y >= 0);
|
||||
|
||||
|
@ -820,7 +820,7 @@ void Engine::stop_animation(Object target) {
|
|||
}
|
||||
|
||||
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.new_usertype<Cutscene>("Cutscene");
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
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) {
|
||||
console::error(System::File, "Failed to open file handle from {}!", path);
|
||||
return {};
|
||||
|
|
|
@ -78,7 +78,7 @@ void ui::Screen::process_mouse(const int x, const int y) {
|
|||
Expects(x >= 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) {
|
||||
if(x > element.absolute_x &&
|
||||
y > element.absolute_y &&
|
||||
|
@ -196,7 +196,7 @@ ui::Screen::Screen(const file::Path path) {
|
|||
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["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) {
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS)
|
||||
#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS)
|
||||
auto func = env["process_event"];
|
||||
func(type, data);
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@ set(CMAKE_FOLDER "GFX Backends")
|
|||
|
||||
add_library(GFX INTERFACE)
|
||||
target_include_directories(GFX INTERFACE public)
|
||||
target_link_libraries(GFX INTERFACE Utility)
|
||||
|
||||
add_custom_target(GFXInterface SOURCES
|
||||
public/gfx.hpp
|
||||
|
|
|
@ -18,7 +18,7 @@ struct GFXRenderPassBeginInfo {
|
|||
float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f;
|
||||
} clear_color;
|
||||
|
||||
Rectangle render_area;
|
||||
prism::Rectangle render_area;
|
||||
|
||||
GFXRenderPass* render_pass = nullptr;
|
||||
GFXFramebuffer* framebuffer = nullptr;
|
||||
|
@ -132,7 +132,7 @@ struct GFXDrawCommand {
|
|||
} set_viewport;
|
||||
|
||||
struct SetScissorData {
|
||||
Rectangle rect;
|
||||
prism::Rectangle rect;
|
||||
} set_scissor;
|
||||
|
||||
struct GenerateMipmapData {
|
||||
|
@ -284,7 +284,7 @@ public:
|
|||
commands.push_back(command);
|
||||
}
|
||||
|
||||
void set_scissor(const Rectangle rect) {
|
||||
void set_scissor(const prism::Rectangle rect) {
|
||||
GFXDrawCommand command;
|
||||
command.type = GFXCommandType::SetScissor;
|
||||
command.data.set_scissor.rect = rect;
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
// misc operations
|
||||
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:
|
||||
void createInstance(std::vector<const char*> layers, std::vector<const char*> extensions);
|
||||
|
|
|
@ -542,16 +542,16 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
|||
vkDeviceWaitIdle(device);
|
||||
|
||||
// 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();
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
|
||||
|
@ -754,7 +754,7 @@ GFXSize GFXVulkan::get_alignment(GFXSize size) {
|
|||
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());
|
||||
|
||||
uint32_t imageIndex = 0;
|
||||
|
@ -831,8 +831,8 @@ void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) {
|
|||
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.extent = { command.data.set_render_pass.viewport.width, command.data.set_render_pass.viewport.height };
|
||||
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.render_area.extent.width, command.data.set_render_pass.render_area.extent.height };
|
||||
|
||||
std::vector<VkClearValue> clearColors;
|
||||
if (renderPass != nullptr) {
|
||||
|
@ -888,7 +888,7 @@ void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) {
|
|||
case GFXCommandType::SetPushConstant:
|
||||
{
|
||||
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;
|
||||
case GFXCommandType::BindShaderBuffer:
|
||||
|
|
|
@ -21,8 +21,12 @@ enum class Level {
|
|||
};
|
||||
|
||||
namespace console {
|
||||
template<typename Arg>
|
||||
void internal_format(std::string& msg, const Arg& arg) {
|
||||
inline void internal_format(std::string& msg, const std::string& 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("{}");
|
||||
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) {
|
||||
auto msg = std::string(format);
|
||||
|
||||
((internal_format<Args>(msg, args)), ...);
|
||||
((internal_format(msg, args)), ...);
|
||||
|
||||
process_message(level, system, msg);
|
||||
}
|
||||
|
|
|
@ -136,6 +136,6 @@ protected:
|
|||
// If no path markers, return current working directory.
|
||||
// Otherwise, strip file name and return path leading up to it.
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ class GFXTexture;
|
|||
|
||||
class GaussianHelper {
|
||||
public:
|
||||
GaussianHelper(GFX* gfx, const Extent extent);
|
||||
GaussianHelper(GFX* gfx, const prism::Extent extent);
|
||||
|
||||
GFXTexture* render(GFXCommandBuffer* commandBuffer,GFXTexture* source);
|
||||
|
||||
|
@ -23,5 +23,5 @@ public:
|
|||
GFXFramebuffer* fboA = nullptr, *fboB = nullptr;
|
||||
|
||||
private:
|
||||
Extent extent;
|
||||
prism::Extent extent;
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@ class ImGuiPass : public Pass {
|
|||
public:
|
||||
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;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
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,
|
||||
[[maybe_unused]] GFXCommandBuffer* commandBuffer) {}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
#include "file.hpp"
|
||||
#include "pass.hpp"
|
||||
#include "matrix.hpp"
|
||||
|
@ -85,8 +87,8 @@ class Renderer {
|
|||
public:
|
||||
Renderer(GFX* gfx, const bool enable_imgui = true);
|
||||
|
||||
void resize(const Extent extent);
|
||||
void resize_viewport(const Extent extent);
|
||||
void resize(const prism::Extent extent);
|
||||
void resize_viewport(const prism::Extent extent);
|
||||
|
||||
void set_screen(ui::Screen* screen);
|
||||
void init_screen(ui::Screen* screen);
|
||||
|
@ -145,15 +147,15 @@ public:
|
|||
GFXTexture* viewportColorTexture = nullptr;
|
||||
|
||||
bool viewport_mode = false;
|
||||
Extent viewport_extent;
|
||||
prism::Extent viewport_extent;
|
||||
|
||||
bool gui_only_mode = false;
|
||||
|
||||
Extent get_extent() const {
|
||||
prism::Extent get_extent() const {
|
||||
return viewport_mode ? viewport_extent : extent;
|
||||
}
|
||||
|
||||
Extent get_render_extent() const {
|
||||
prism::Extent get_render_extent() const {
|
||||
const auto extent = get_extent();
|
||||
|
||||
return {static_cast<uint32_t>(std::max(int(extent.width * render_options.render_scale), 1)),
|
||||
|
@ -186,7 +188,7 @@ private:
|
|||
void createBRDF();
|
||||
|
||||
GFX* gfx = nullptr;
|
||||
Extent extent;
|
||||
prism::Extent extent;
|
||||
|
||||
ui::Screen* current_screen = nullptr;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ private:
|
|||
void create_pipelines();
|
||||
void create_offscreen_resources();
|
||||
|
||||
Extent extent;
|
||||
prism::Extent extent;
|
||||
Renderer* renderer = nullptr;
|
||||
|
||||
GFXTexture* area_image = nullptr;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "gfx_commandbuffer.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
|
||||
GFXRenderPassCreateInfo renderPassInfo = {};
|
||||
renderPassInfo.attachments.push_back(GFXPixelFormat::RGBA_32F);
|
||||
|
|
|
@ -21,7 +21,7 @@ void ImGuiPass::initialize() {
|
|||
create_font_texture();
|
||||
}
|
||||
|
||||
void ImGuiPass::resize(const Extent extent) {
|
||||
void ImGuiPass::resize(const prism::Extent extent) {
|
||||
GFXGraphicsPipelineCreateInfo createInfo;
|
||||
createInfo.label = "ImGui";
|
||||
createInfo.shaders.vertex_path = "imgui.vert";
|
||||
|
|
|
@ -97,7 +97,7 @@ Renderer::Renderer(GFX* gfx, const bool enable_imgui) : gfx(gfx) {
|
|||
createBRDF();
|
||||
}
|
||||
|
||||
void Renderer::resize(const Extent extent) {
|
||||
void Renderer::resize(const prism::Extent extent) {
|
||||
this->extent = extent;
|
||||
|
||||
if(!viewport_mode) {
|
||||
|
@ -117,7 +117,7 @@ void Renderer::resize(const Extent extent) {
|
|||
pass->resize(extent);
|
||||
}
|
||||
|
||||
void Renderer::resize_viewport(const Extent extent) {
|
||||
void Renderer::resize_viewport(const prism::Extent extent) {
|
||||
this->viewport_extent = extent;
|
||||
|
||||
createOffscreenResources();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#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_msl.hpp>
|
||||
#include <SPIRV/GlslangToSpv.h>
|
||||
|
@ -112,22 +112,20 @@ const TBuiltInResource DefaultTBuiltInResource = {
|
|||
/* .maxTaskWorkGroupSizeY_NV = */ 1,
|
||||
/* .maxTaskWorkGroupSizeZ_NV = */ 1,
|
||||
/* .maxMeshViewCountNV = */ 4,
|
||||
/* .maxDualSourceDrawBuffersEXT = */ 4,
|
||||
|
||||
#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS)
|
||||
/* .maxDualSourceDrawBuffersEXT = */ 1,
|
||||
#endif
|
||||
/* .limits = */ TLimits{
|
||||
/* .nonInductiveForLoops = */ true,
|
||||
/* .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) {
|
||||
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);
|
||||
|
||||
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)) {
|
||||
std::cout << Shader.getInfoLog() << std::endl;
|
||||
|
|
|
@ -2,28 +2,30 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
/// A 2D extent.
|
||||
struct Extent {
|
||||
Extent() : width(0), height(0) {}
|
||||
Extent(const uint32_t width, const uint32_t height) : width(width), height(height) {}
|
||||
namespace prism {
|
||||
/// A 2D extent.
|
||||
struct Extent {
|
||||
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.
|
||||
struct Offset {
|
||||
Offset() : x(0), y(0) {}
|
||||
Offset(const int32_t x, const int32_t y) : x(x), y(y) {}
|
||||
/// A 2D offset.
|
||||
struct Offset {
|
||||
Offset() : x(0), y(0) {}
|
||||
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.
|
||||
struct Rectangle {
|
||||
Rectangle() {}
|
||||
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) {}
|
||||
/// A 2D rectangle defined by a offset and an etent.
|
||||
struct Rectangle {
|
||||
Rectangle() {}
|
||||
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) {}
|
||||
|
||||
Offset offset;
|
||||
Extent extent;
|
||||
};
|
||||
Offset offset;
|
||||
Extent extent;
|
||||
};
|
||||
}
|
||||
|
|
8
extern/imgui/include/imconfig.h
vendored
8
extern/imgui/include/imconfig.h
vendored
|
@ -68,10 +68,10 @@
|
|||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
ImVec2(const 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)); } \
|
||||
ImVec2(const 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)); }
|
||||
ImVec2(const prism::Offset& f) { x = static_cast<float>(f.x); y = static_cast<float>(f.y); } \
|
||||
operator prism::Offset() const { return prism::Offset(static_cast<int32_t>(x), static_cast<int32_t>(y)); } \
|
||||
ImVec2(const prism::Extent& f) { x = static_cast<float>(f.width); y = static_cast<float>(f.height); } \
|
||||
operator prism::Extent() const { return prism::Extent(static_cast<uint32_t>(x), static_cast<uint32_t>(y)); }
|
||||
|
||||
/*#define IM_VEC4_CLASS_EXTRA \
|
||||
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
|
||||
|
|
|
@ -1,63 +1,9 @@
|
|||
#include "file.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
#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;
|
||||
void file::set_domain_path(const file::Domain domain, const file::Path path) {
|
||||
domain_data[(int)domain] = path.string();
|
||||
}
|
||||
|
||||
std::string file::clean_path(const std::string_view path) {
|
||||
auto p = replaceSubstring(std::string(path), "%20", " ");
|
||||
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;
|
||||
file::Path file::get_writeable_directory() {
|
||||
return "";
|
||||
}
|
|
@ -2,57 +2,22 @@
|
|||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#include <fmt/printf.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#undef far
|
||||
#undef near
|
||||
|
||||
#include "platform.hpp"
|
||||
|
||||
#include <gfx_vulkan.hpp>
|
||||
#include <gfx_dummy.hpp>
|
||||
#include <gfx_opengl.hpp>
|
||||
|
||||
typedef HGLRC WINAPI wglCreateContextAttribsARB_type(HDC hdc, HGLRC hShareContext,
|
||||
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 <@APP_INCLUDE@>
|
||||
#include <engine.hpp>
|
||||
|
||||
GFX* ginterface = nullptr;
|
||||
#if @IS_GAME@
|
||||
@GAME_CLASS@* game = nullptr;
|
||||
#else
|
||||
@EDITOR_CLASS@* editor = nullptr;
|
||||
#endif
|
||||
@APP_CLASS@* app = nullptr;
|
||||
|
||||
HINSTANCE instance = NULL;
|
||||
HWND window = NULL;
|
||||
|
@ -64,11 +29,7 @@ int defaultWidth, defaultHeight;
|
|||
|
||||
bool shouldConfineMouse = false;
|
||||
|
||||
#include <GL/GL.h>
|
||||
|
||||
#pragma comment (lib, "opengl32.lib")
|
||||
|
||||
const wchar_t CLASS_NAME[] = L"@GAME_NAME@";
|
||||
const wchar_t CLASS_NAME[] = L"@APP_NAME@";
|
||||
|
||||
wchar_t* convertToUnicode(const char* str) {
|
||||
size_t ret = 0;
|
||||
|
@ -81,24 +42,22 @@ wchar_t* convertToUnicode(const char* str) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
void platform::openWindow(const char* title, int x, int y, int width, int height, WindowFlags flags) {
|
||||
RECT wr = {0, 0, width, height};
|
||||
int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) {
|
||||
RECT wr = {rect.offset.x, rect.offset.y, rect.extent.width, rect.extent.height};
|
||||
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
|
||||
defaultWidth = width;
|
||||
defaultHeight = height;
|
||||
defaultWidth = rect.extent.width;
|
||||
defaultHeight = rect.extent.height;
|
||||
|
||||
std::string new_title = title + std::string(" (") + ginterface->getName() + ")";
|
||||
|
||||
wchar_t* title_uni = convertToUnicode(new_title.c_str());
|
||||
wchar_t* title_uni = convertToUnicode(title.data());
|
||||
|
||||
window = CreateWindowEx(
|
||||
0,
|
||||
CLASS_NAME,
|
||||
title_uni,
|
||||
flags == WindowFlags::Resizable ? WS_OVERLAPPEDWINDOW : (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX), // Window style
|
||||
x,
|
||||
y,
|
||||
rect.offset.x,
|
||||
rect.offset.y,
|
||||
wr.right - wr.left,
|
||||
wr.bottom - wr.top,
|
||||
NULL,
|
||||
|
@ -111,16 +70,18 @@ void platform::openWindow(const char* title, int x, int y, int width, int height
|
|||
|
||||
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
|
||||
}
|
||||
|
||||
bool showingCursor = true;
|
||||
|
||||
void platform::setCaptureMouse(bool capture) {
|
||||
void platform::capture_mouse(const bool capture) {
|
||||
shouldConfineMouse = capture;
|
||||
|
||||
// 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;
|
||||
GetCursorPos(&p);
|
||||
ScreenToClient(window, &p);
|
||||
|
@ -143,105 +104,26 @@ std::tuple<int, int> platform::getCursorPosition() {
|
|||
return {p.x, p.y};
|
||||
}
|
||||
|
||||
std::tuple<int, int> platform::getWindowPosition() {
|
||||
prism::Offset platform::get_window_position(const int identifier) {
|
||||
RECT rect;
|
||||
GetWindowRect(window, &rect);
|
||||
|
||||
return {rect.left, rect.top};
|
||||
}
|
||||
|
||||
std::tuple<int, int> platform::getWindowSize() {
|
||||
prism::Extent platform::get_window_size(const int identifier) {
|
||||
RECT rect;
|
||||
GetClientRect(window, &rect);
|
||||
|
||||
int width = rect.right - rect.left;
|
||||
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);
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
|
||||
{
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) {
|
||||
AllocConsole();
|
||||
FILE* stream;
|
||||
freopen_s(&stream, "CONOUT$", "w", stdout);
|
||||
|
@ -258,30 +140,21 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow
|
|||
instance = hInstance;
|
||||
cmdShow = nCmdShow;
|
||||
|
||||
engine = new Engine();
|
||||
engine = new Engine(0, nullptr);
|
||||
|
||||
ginterface = new GFXVulkan();
|
||||
if(ginterface->initialize()) {
|
||||
engine->setGFX(ginterface);
|
||||
if(ginterface->initialize(GFXCreateInfo())) {
|
||||
engine->set_gfx(ginterface);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if @IS_GAME@
|
||||
game = new @GAME_CLASS@();
|
||||
engine->setGame(game);
|
||||
#else
|
||||
editor = new @EDITOR_CLASS@();
|
||||
engine->setEditor(editor);
|
||||
#endif
|
||||
app = new @APP_CLASS@();
|
||||
engine->set_app(app);
|
||||
|
||||
app::open(engine);
|
||||
app_main(engine);
|
||||
|
||||
#if @IS_GAME@
|
||||
game->initializeRender();
|
||||
#else
|
||||
editor->initializeRender();
|
||||
#endif
|
||||
app->initialize_render();
|
||||
|
||||
MSG msg = { };
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -290,11 +163,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow
|
|||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
#if @IS_GAME@
|
||||
delete game;
|
||||
#else
|
||||
delete editor;
|
||||
#endif
|
||||
delete app;
|
||||
|
||||
delete ginterface;
|
||||
delete engine;
|
||||
|
@ -308,59 +177,9 @@ int timeout = 0;
|
|||
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
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:
|
||||
{
|
||||
engine->prepareQuit();
|
||||
engine->prepare_quit();
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
return 0;
|
||||
|
@ -388,19 +207,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
HCURSOR arrowCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
SetCursor(arrowCursor);
|
||||
|
||||
#if @IS_GAME@
|
||||
|
||||
#else
|
||||
editor->beginFrame();
|
||||
#endif
|
||||
engine->begin_frame(1.0f / 60.0f);
|
||||
engine->update(1.0f / 60.0f);
|
||||
engine->render();
|
||||
engine->render(0);
|
||||
|
||||
if(ginterface->requiredContext() == GFXContext::OpenGL)
|
||||
SwapBuffers(windowDC);
|
||||
|
||||
if(engine->isQuitting()) {
|
||||
engine->prepareQuit();
|
||||
if(engine->is_quitting()) {
|
||||
engine->prepare_quit();
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
}
|
||||
|
@ -410,41 +222,17 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
int xPos = GET_X_LPARAM(lParam);
|
||||
int yPos = GET_Y_LPARAM(lParam);
|
||||
|
||||
engine->processMouse(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);
|
||||
engine->process_mouse_down(0, {xPos, yPos});
|
||||
}
|
||||
return 0;
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
engine->processKey((unsigned int)wParam);
|
||||
engine->process_key_down((unsigned int)wParam);
|
||||
}
|
||||
return 0;
|
||||
case WM_KEYUP:
|
||||
{
|
||||
engine->processKeyUp((unsigned int)wParam);
|
||||
engine->process_key_up((unsigned int)wParam);
|
||||
}
|
||||
return 0;
|
||||
case WM_SIZE:
|
||||
|
@ -458,7 +246,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
if(width == defaultWidth && height == defaultHeight) {
|
||||
// don't resize when the window was first created!!
|
||||
} 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);
|
||||
}
|
||||
|
||||
void platform::setWindowTitle(const char* title) {
|
||||
std::string new_title = title + std::string(" (") + ginterface->getName() + ")";
|
||||
|
||||
SetWindowTextA(window, new_title.c_str());
|
||||
void platform::set_window_title(const int identifier, const std::string_view title) {
|
||||
SetWindowTextA(window, title.data());
|
||||
}
|
|
@ -39,7 +39,7 @@ int platform::get_keycode(const InputButton 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 int BUFSIZE = 1024;
|
||||
char buffer[BUFSIZE] = { 0 };
|
||||
|
|
Reference in a new issue