mirror of https://github.com/auygun/kaliber.git
Compare commits
6 Commits
41a1cfe6f5
...
b292f423ba
Author | SHA1 | Date |
---|---|---|
Attila Uygun | b292f423ba | |
Attila Uygun | 2985fed3d4 | |
Attila Uygun | 6619cd368b | |
Attila Uygun | ba1e5cc681 | |
Attila Uygun | f8df7d86f6 | |
Attila Uygun | 6e952e511e |
|
@ -23,6 +23,17 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
"preLaunchTask": "Build project",
|
"preLaunchTask": "Build project",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "C/C++: cl.exe build and debug active file",
|
||||||
|
"type": "cppvsdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}\\out\\debug\\demo.exe",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}\\out\\debug",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -173,7 +173,9 @@ config("warnings") {
|
||||||
# Disable the following warnings:
|
# Disable the following warnings:
|
||||||
"/wd4061", # enumerator in switch with a default case not explicitly
|
"/wd4061", # enumerator in switch with a default case not explicitly
|
||||||
# handled by a case label.
|
# handled by a case label.
|
||||||
"/wd4100", # unreferenced format parameter.
|
"/wd4100", # nonstandard extension used: nameless struct/union.
|
||||||
|
"/wd4201", # enumerator in switch with a default case not explicitly
|
||||||
|
# handled by a case label.
|
||||||
"/wd4324", # structure was padded due to alignment specifier
|
"/wd4324", # structure was padded due to alignment specifier
|
||||||
"/wd4371", # layout of class may have changed from a previous version of
|
"/wd4371", # layout of class may have changed from a previous version of
|
||||||
# the compiler due to better packing of member
|
# the compiler due to better packing of member
|
||||||
|
@ -185,6 +187,10 @@ config("warnings") {
|
||||||
# switch specified.
|
# switch specified.
|
||||||
|
|
||||||
# TODO: Not sure how I feel about these conversion warnings.
|
# TODO: Not sure how I feel about these conversion warnings.
|
||||||
|
"/Wv:18", # tmp
|
||||||
|
"/wd4191", # tmp:'type cast': unsafe conversion
|
||||||
|
"/wd4242", # tmp:conversion from 'int' to 'uint8_t'
|
||||||
|
"/wd4245", # tmp:conversion from 'int' to 'const unsigned int'
|
||||||
"/wd4244", # conversion, possible loss of data. 'int' to 'float'
|
"/wd4244", # conversion, possible loss of data. 'int' to 'float'
|
||||||
"/wd4267", # conversion, possible loss of data.
|
"/wd4267", # conversion, possible loss of data.
|
||||||
"/wd4305", # truncation from 'double' to 'float'.
|
"/wd4305", # truncation from 'double' to 'float'.
|
||||||
|
@ -232,6 +238,7 @@ config("warnings") {
|
||||||
defines = [
|
defines = [
|
||||||
"_CRT_NONSTDC_NO_DEPRECATE",
|
"_CRT_NONSTDC_NO_DEPRECATE",
|
||||||
"_SILENCE_CXX17_STRSTREAM_DEPRECATION_WARNING",
|
"_SILENCE_CXX17_STRSTREAM_DEPRECATION_WARNING",
|
||||||
|
"_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS",
|
||||||
]
|
]
|
||||||
} else if (is_mac) {
|
} else if (is_mac) {
|
||||||
cflags = [
|
cflags = [
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#endif
|
#endif
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <format>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
@ -38,6 +41,10 @@ LogMessage::~LogMessage() {
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "kaliber", "%d [%s:%d] %s",
|
__android_log_print(ANDROID_LOG_ERROR, "kaliber", "%d [%s:%d] %s",
|
||||||
verbosity_level_, filename.c_str(), line_, text.c_str());
|
verbosity_level_, filename.c_str(), line_, text.c_str());
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
std::string s = std::format("{} [{}:{}] {}", verbosity_level_,
|
||||||
|
filename.c_str(), line_, text.c_str());
|
||||||
|
OutputDebugStringA(s.c_str());
|
||||||
#else
|
#else
|
||||||
printf("%d [%s:%d] %s", verbosity_level_, filename.c_str(), line_,
|
printf("%d [%s:%d] %s", verbosity_level_, filename.c_str(), line_,
|
||||||
text.c_str());
|
text.c_str());
|
||||||
|
|
|
@ -1247,8 +1247,8 @@ class Matrix4 {
|
||||||
T fov_aspect,
|
T fov_aspect,
|
||||||
T width,
|
T width,
|
||||||
T height,
|
T height,
|
||||||
T near,
|
T near_,
|
||||||
T far) {
|
T far_) {
|
||||||
// Calc x and y scale from FOV.
|
// Calc x and y scale from FOV.
|
||||||
T scale =
|
T scale =
|
||||||
T(2.0) /
|
T(2.0) /
|
||||||
|
@ -1257,8 +1257,8 @@ class Matrix4 {
|
||||||
T x_scale = y_scale / (width / height);
|
T x_scale = y_scale / (width / height);
|
||||||
_M_SET_ROW(0, x_scale / T(2.0), 0, 0, 0);
|
_M_SET_ROW(0, x_scale / T(2.0), 0, 0, 0);
|
||||||
_M_SET_ROW(1, 0, (-y_scale) / T(2.0), 0, 0);
|
_M_SET_ROW(1, 0, (-y_scale) / T(2.0), 0, 0);
|
||||||
_M_SET_ROW(2, 0, 0, far / (far - near), 1);
|
_M_SET_ROW(2, 0, 0, far_ / (far_ - near_), 1);
|
||||||
_M_SET_ROW(3, 0, 0, -near * far / (far - near), 0);
|
_M_SET_ROW(3, 0, 0, -near_ * far_ / (far_ - near_), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateTranslation(const Vector3<T>& t) {
|
void CreateTranslation(const Vector3<T>& t) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ executable("demo") {
|
||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//assets",
|
# "//assets",
|
||||||
"//src/base",
|
"//src/base",
|
||||||
"//src/engine",
|
"//src/engine",
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "base/interpolation.h"
|
#include "base/interpolation.h"
|
||||||
#include "base/log.h"
|
#include "base/log.h"
|
||||||
|
#include "base/vecmath.h"
|
||||||
#include "engine/asset/font.h"
|
#include "engine/asset/font.h"
|
||||||
#include "engine/engine.h"
|
#include "engine/engine.h"
|
||||||
#include "engine/input_event.h"
|
#include "engine/input_event.h"
|
||||||
|
|
|
@ -80,6 +80,23 @@ source_set("engine") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target_os == "win") {
|
||||||
|
sources += [
|
||||||
|
"audio/audio_sink_null.h",
|
||||||
|
"platform/asset_file_linux.cc",
|
||||||
|
"platform/platform_win.cc",
|
||||||
|
"renderer/opengl/renderer_opengl_win.cc",
|
||||||
|
"renderer/vulkan/renderer_vulkan_win.cc",
|
||||||
|
"renderer/vulkan/vulkan_context_win.cc",
|
||||||
|
]
|
||||||
|
|
||||||
|
libs = [
|
||||||
|
# "gdi32.lib", # Graphics
|
||||||
|
"user32.lib", # Win32 API core functionality.
|
||||||
|
# "shell32.lib", # Drag and Drop
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//assets/engine",
|
"//assets/engine",
|
||||||
"//src/base",
|
"//src/base",
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "engine/audio/audio_sink_oboe.h"
|
#include "engine/audio/audio_sink_oboe.h"
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "engine/audio/audio_sink_alsa.h"
|
#include "engine/audio/audio_sink_alsa.h"
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include "engine/audio/audio_sink_null.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace base;
|
using namespace base;
|
||||||
|
@ -23,6 +25,10 @@ AudioMixer::AudioMixer()
|
||||||
audio_sink_{std::make_unique<AudioSinkOboe>(this)} {
|
audio_sink_{std::make_unique<AudioSinkOboe>(this)} {
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
audio_sink_{std::make_unique<AudioSinkAlsa>(this)} {
|
audio_sink_{std::make_unique<AudioSinkAlsa>(this)} {
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
// TODO: Implement AudioSinkWindows
|
||||||
|
audio_sink_{std::make_unique<AudioSinkNull>()},
|
||||||
|
audio_enabled_(false) {
|
||||||
#endif
|
#endif
|
||||||
bool res = audio_sink_->Initialize();
|
bool res = audio_sink_->Initialize();
|
||||||
CHECK(res) << "Failed to initialize audio sink.";
|
CHECK(res) << "Failed to initialize audio sink.";
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef ENGINE_AUDIO_AUDIO_SINK_NULL_H
|
||||||
|
#define ENGINE_AUDIO_AUDIO_SINK_NULL_H
|
||||||
|
|
||||||
|
#include "engine/audio/audio_sink.h"
|
||||||
|
|
||||||
|
namespace eng {
|
||||||
|
|
||||||
|
class AudioSinkNull final : public AudioSink {
|
||||||
|
public:
|
||||||
|
AudioSinkNull() = default;
|
||||||
|
~AudioSinkNull() final = default;
|
||||||
|
|
||||||
|
bool Initialize() final { return true; }
|
||||||
|
|
||||||
|
void Suspend() final {}
|
||||||
|
void Resume() final {}
|
||||||
|
|
||||||
|
size_t GetHardwareSampleRate() final { return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace eng
|
||||||
|
|
||||||
|
#endif // ENGINE_AUDIO_AUDIO_SINK_NULL_H
|
|
@ -108,6 +108,8 @@ void Engine::Initialize() {
|
||||||
|
|
||||||
thread_pool_.Initialize();
|
thread_pool_.Initialize();
|
||||||
|
|
||||||
|
platform_->CreateMainWindow();
|
||||||
|
|
||||||
CreateRendererInternal(RendererType::kVulkan);
|
CreateRendererInternal(RendererType::kVulkan);
|
||||||
|
|
||||||
CreateProjectionMatrix();
|
CreateProjectionMatrix();
|
||||||
|
@ -485,6 +487,7 @@ bool Engine::IsMobile() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::OnWindowCreated() {
|
void Engine::OnWindowCreated() {
|
||||||
|
if (renderer_)
|
||||||
renderer_->Initialize(platform_);
|
renderer_->Initialize(platform_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,8 +496,8 @@ void Engine::OnWindowDestroyed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::OnWindowResized(int width, int height) {
|
void Engine::OnWindowResized(int width, int height) {
|
||||||
if (width != renderer_->GetScreenWidth() ||
|
if (renderer_ && (width != renderer_->GetScreenWidth() ||
|
||||||
height != renderer_->GetScreenHeight()) {
|
height != renderer_->GetScreenHeight())) {
|
||||||
renderer_->OnWindowResized(width, height);
|
renderer_->OnWindowResized(width, height);
|
||||||
CreateProjectionMatrix();
|
CreateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include "third_party/minizip/unzip.h"
|
#include "third_party/minizip/unzip.h"
|
||||||
#elif defined(__linux__)
|
#else
|
||||||
#include "base/file.h"
|
#include "base/file.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class AssetFile {
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
unzFile archive_ = 0;
|
unzFile archive_ = 0;
|
||||||
size_t uncompressed_size_ = 0;
|
size_t uncompressed_size_ = 0;
|
||||||
#elif defined(__linux)
|
#else
|
||||||
base::ScopedFILE file_;
|
base::ScopedFILE file_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,13 @@ struct ANativeWindow;
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
|
// #include <WinSDKVer.h>
|
||||||
|
// #define _WIN32_WINNT 0x0601
|
||||||
|
// #include <SDKDDKVer.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
@ -28,9 +35,13 @@ class Platform {
|
||||||
Platform(android_app* app);
|
Platform(android_app* app);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
Platform();
|
Platform();
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
Platform(HINSTANCE instance, int cmd_show);
|
||||||
#endif
|
#endif
|
||||||
~Platform();
|
~Platform();
|
||||||
|
|
||||||
|
void CreateMainWindow();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
void Exit();
|
void Exit();
|
||||||
|
@ -62,6 +73,9 @@ class Platform {
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
Display* GetDisplay();
|
Display* GetDisplay();
|
||||||
Window GetWindow();
|
Window GetWindow();
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
HINSTANCE GetInstance();
|
||||||
|
HWND GetWindow();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -111,6 +125,14 @@ class Platform {
|
||||||
|
|
||||||
XVisualInfo* GetXVisualInfo(Display* display);
|
XVisualInfo* GetXVisualInfo(Display* display);
|
||||||
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
|
HINSTANCE instance_;
|
||||||
|
HWND wnd_;
|
||||||
|
int cmd_show_;
|
||||||
|
|
||||||
|
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Platform(const Platform&) = delete;
|
Platform(const Platform&) = delete;
|
||||||
|
|
|
@ -292,20 +292,18 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
|
||||||
DLOG(0) << "APP_CMD_INIT_WINDOW";
|
DLOG(0) << "APP_CMD_INIT_WINDOW";
|
||||||
if (app->window != NULL) {
|
if (app->window != NULL) {
|
||||||
platform->SetFrameRate(60);
|
platform->SetFrameRate(60);
|
||||||
if (platform->observer_)
|
|
||||||
platform->observer_->OnWindowCreated();
|
platform->observer_->OnWindowCreated();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case APP_CMD_TERM_WINDOW:
|
case APP_CMD_TERM_WINDOW:
|
||||||
DLOG(0) << "APP_CMD_TERM_WINDOW";
|
DLOG(0) << "APP_CMD_TERM_WINDOW";
|
||||||
if (platform->observer_)
|
|
||||||
platform->observer_->OnWindowDestroyed();
|
platform->observer_->OnWindowDestroyed();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case APP_CMD_CONFIG_CHANGED:
|
case APP_CMD_CONFIG_CHANGED:
|
||||||
DLOG(0) << "APP_CMD_CONFIG_CHANGED";
|
DLOG(0) << "APP_CMD_CONFIG_CHANGED";
|
||||||
if (platform->app_->window != NULL && platform->observer_)
|
if (platform->app_->window != NULL)
|
||||||
platform->observer_->OnWindowResized(
|
platform->observer_->OnWindowResized(
|
||||||
ANativeWindow_getWidth(app->window),
|
ANativeWindow_getWidth(app->window),
|
||||||
ANativeWindow_getHeight(app->window));
|
ANativeWindow_getHeight(app->window));
|
||||||
|
@ -319,7 +317,6 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
|
||||||
DLOG(0) << "APP_CMD_GAINED_FOCUS";
|
DLOG(0) << "APP_CMD_GAINED_FOCUS";
|
||||||
// platform->timer_.Reset();
|
// platform->timer_.Reset();
|
||||||
platform->has_focus_ = true;
|
platform->has_focus_ = true;
|
||||||
if (platform->observer_)
|
|
||||||
platform->observer_->GainedFocus(g_showing_interstitial_ad);
|
platform->observer_->GainedFocus(g_showing_interstitial_ad);
|
||||||
g_showing_interstitial_ad = false;
|
g_showing_interstitial_ad = false;
|
||||||
break;
|
break;
|
||||||
|
@ -327,7 +324,6 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
|
||||||
case APP_CMD_LOST_FOCUS:
|
case APP_CMD_LOST_FOCUS:
|
||||||
DLOG(0) << "APP_CMD_LOST_FOCUS";
|
DLOG(0) << "APP_CMD_LOST_FOCUS";
|
||||||
platform->has_focus_ = false;
|
platform->has_focus_ = false;
|
||||||
if (platform->observer_)
|
|
||||||
platform->observer_->LostFocus();
|
platform->observer_->LostFocus();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -370,8 +366,12 @@ Platform::Platform(android_app* app) {
|
||||||
reinterpret_cast<PFN_ANativeWindow_setFrameRateWithChangeStrategy>(
|
reinterpret_cast<PFN_ANativeWindow_setFrameRateWithChangeStrategy>(
|
||||||
dlsym(mLibAndroid, "ANativeWindow_setFrameRateWithChangeStrategy"));
|
dlsym(mLibAndroid, "ANativeWindow_setFrameRateWithChangeStrategy"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::CreateMainWindow() {
|
||||||
|
DCHECK(!app_->window);
|
||||||
Update();
|
Update();
|
||||||
|
DCHECK(app_->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
Platform::~Platform() {
|
Platform::~Platform() {
|
||||||
|
|
|
@ -39,7 +39,9 @@ Platform::Platform() {
|
||||||
LOG(0) << "Root path: " << root_path_.c_str();
|
LOG(0) << "Root path: " << root_path_.c_str();
|
||||||
LOG(0) << "Data path: " << data_path_.c_str();
|
LOG(0) << "Data path: " << data_path_.c_str();
|
||||||
LOG(0) << "Shared data path: " << shared_data_path_.c_str();
|
LOG(0) << "Shared data path: " << shared_data_path_.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::CreateMainWindow() {
|
||||||
bool res = CreateWindow(800, 1205);
|
bool res = CreateWindow(800, 1205);
|
||||||
CHECK(res) << "Failed to create window.";
|
CHECK(res) << "Failed to create window.";
|
||||||
|
|
||||||
|
@ -103,8 +105,10 @@ void Platform::Update() {
|
||||||
}
|
}
|
||||||
case ClientMessage: {
|
case ClientMessage: {
|
||||||
// WM_DELETE_WINDOW is the only registered type for now.
|
// WM_DELETE_WINDOW is the only registered type for now.
|
||||||
|
observer_->OnWindowDestroyed();
|
||||||
|
DestroyWindow();
|
||||||
should_exit_ = true;
|
should_exit_ = true;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
case ConfigureNotify: {
|
case ConfigureNotify: {
|
||||||
XConfigureEvent xce = e.xconfigure;
|
XConfigureEvent xce = e.xconfigure;
|
||||||
|
|
|
@ -0,0 +1,162 @@
|
||||||
|
#include "engine/platform/platform.h"
|
||||||
|
|
||||||
|
// #include <limits.h>
|
||||||
|
// #include <stdio.h>
|
||||||
|
// #include <cstring>
|
||||||
|
// #include <memory>
|
||||||
|
//
|
||||||
|
#include "base/log.h"
|
||||||
|
#include "base/vecmath.h"
|
||||||
|
#include "engine/input_event.h"
|
||||||
|
#include "engine/platform/platform_observer.h"
|
||||||
|
|
||||||
|
using namespace base;
|
||||||
|
|
||||||
|
namespace eng {
|
||||||
|
|
||||||
|
void KaliberMain(Platform* platform);
|
||||||
|
|
||||||
|
Platform::Platform(HINSTANCE instance, int cmd_show)
|
||||||
|
: instance_(instance), cmd_show_(cmd_show) {
|
||||||
|
LOG(0) << "Initializing platform.";
|
||||||
|
|
||||||
|
root_path_ = ".\\";
|
||||||
|
data_path_ = ".\\";
|
||||||
|
shared_data_path_ = ".\\";
|
||||||
|
|
||||||
|
char dest[MAX_PATH];
|
||||||
|
memset(dest, 0, sizeof(dest));
|
||||||
|
if (GetModuleFileNameA(NULL, dest, MAX_PATH) > 0) {
|
||||||
|
std::string path = dest;
|
||||||
|
std::size_t last_slash_pos = path.find_last_of('\\');
|
||||||
|
if (last_slash_pos != std::string::npos)
|
||||||
|
path = path.substr(0, last_slash_pos + 1);
|
||||||
|
|
||||||
|
root_path_ = path;
|
||||||
|
data_path_ = path;
|
||||||
|
shared_data_path_ = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(0) << "Root path: " << root_path_.c_str();
|
||||||
|
LOG(0) << "Data path: " << data_path_.c_str();
|
||||||
|
LOG(0) << "Shared data path: " << shared_data_path_.c_str();
|
||||||
|
|
||||||
|
WNDCLASSEXW wcex;
|
||||||
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||||
|
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
|
wcex.lpfnWndProc = WndProc;
|
||||||
|
wcex.cbClsExtra = 0;
|
||||||
|
wcex.cbWndExtra = 0;
|
||||||
|
wcex.hInstance = instance_;
|
||||||
|
wcex.hIcon = nullptr;
|
||||||
|
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||||
|
wcex.hbrBackground = nullptr;
|
||||||
|
wcex.lpszMenuName = nullptr;
|
||||||
|
wcex.lpszClassName = L"KaliberWndClass";
|
||||||
|
wcex.hIconSm = nullptr;
|
||||||
|
RegisterClassEx(&wcex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::CreateMainWindow() {
|
||||||
|
wnd_ = CreateWindow(L"KaliberWndClass", L"Kaliber", WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT, 0, 800, 1205, nullptr, nullptr, instance_,
|
||||||
|
this);
|
||||||
|
CHECK(wnd_);
|
||||||
|
|
||||||
|
ShowWindow(wnd_, cmd_show_);
|
||||||
|
UpdateWindow(wnd_);
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform::~Platform() {
|
||||||
|
LOG(0) << "Shutting down platform.";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::Update() {
|
||||||
|
MSG msg;
|
||||||
|
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||||
|
if (msg.message == WM_QUIT) {
|
||||||
|
should_exit_ = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::Exit() {
|
||||||
|
should_exit_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::Vibrate(int duration) {}
|
||||||
|
|
||||||
|
void Platform::ShowInterstitialAd() {}
|
||||||
|
|
||||||
|
void Platform::ShareFile(const std::string& file_name) {}
|
||||||
|
|
||||||
|
void Platform::SetKeepScreenOn(bool keep_screen_on) {}
|
||||||
|
|
||||||
|
HINSTANCE Platform::GetInstance() {
|
||||||
|
return instance_;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND Platform::GetWindow() {
|
||||||
|
return wnd_;
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK Platform::WndProc(HWND wnd,
|
||||||
|
UINT message,
|
||||||
|
WPARAM wparam,
|
||||||
|
LPARAM lparam) {
|
||||||
|
auto* platform =
|
||||||
|
reinterpret_cast<Platform*>(GetWindowLongPtr(wnd, GWL_USERDATA));
|
||||||
|
|
||||||
|
switch (message) {
|
||||||
|
case WM_CREATE:
|
||||||
|
SetWindowLongPtr(wnd, GWL_USERDATA,
|
||||||
|
(LONG_PTR)(((LPCREATESTRUCT)lparam)->lpCreateParams));
|
||||||
|
break;
|
||||||
|
case WM_SIZE:
|
||||||
|
platform->observer_->OnWindowResized(LOWORD(lparam), HIWORD(lparam));
|
||||||
|
break;
|
||||||
|
case WM_DESTROY:
|
||||||
|
platform->observer_->OnWindowDestroyed();
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_MOUSEMOVE: {
|
||||||
|
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
|
||||||
|
auto input_event =
|
||||||
|
std::make_unique<InputEvent>(InputEvent::kDrag, 0, v);
|
||||||
|
platform->observer_->AddInputEvent(std::move(input_event));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case WM_LBUTTONDOWN: {
|
||||||
|
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
|
||||||
|
auto input_event =
|
||||||
|
std::make_unique<InputEvent>(InputEvent::kDragStart, 0, v);
|
||||||
|
platform->observer_->AddInputEvent(std::move(input_event));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case WM_LBUTTONUP: {
|
||||||
|
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
|
||||||
|
auto input_event =
|
||||||
|
std::make_unique<InputEvent>(InputEvent::kDragEnd, 0, v);
|
||||||
|
platform->observer_->AddInputEvent(std::move(input_event));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return DefWindowProc(wnd, message, wparam, lparam);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace eng
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE instance,
|
||||||
|
HINSTANCE prev_instance,
|
||||||
|
PSTR cmd_line,
|
||||||
|
int cmd_show) {
|
||||||
|
eng::Platform platform(instance, cmd_show);
|
||||||
|
eng::KaliberMain(&platform);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -17,6 +17,16 @@
|
||||||
#define GL_ETC1_RGB8_OES 0x8D64
|
#define GL_ETC1_RGB8_OES 0x8D64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include "third_party/glew/glew.h"
|
||||||
|
#include "third_party/glew/wglew.h"
|
||||||
|
|
||||||
|
// Define the missing format for the etc1
|
||||||
|
#ifndef GL_ETC1_RGB8_OES
|
||||||
|
#define GL_ETC1_RGB8_OES 0x8D64
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // ENGINE_RENDERER_OPENGL_OPENGL_H
|
#endif // ENGINE_RENDERER_OPENGL_OPENGL_H
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#include "engine/renderer/opengl/renderer_opengl.h"
|
||||||
|
|
||||||
|
#include "base/log.h"
|
||||||
|
#include "engine/platform/platform.h"
|
||||||
|
|
||||||
|
namespace eng {
|
||||||
|
|
||||||
|
bool RendererOpenGL::Initialize(Platform* platform) {
|
||||||
|
LOG(0) << "Initializing renderer.";
|
||||||
|
|
||||||
|
return InitCommon();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererOpenGL::OnDestroy() {}
|
||||||
|
|
||||||
|
void RendererOpenGL::Shutdown() {
|
||||||
|
LOG(0) << "Shutting down renderer.";
|
||||||
|
is_initialized_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererOpenGL::Present() {
|
||||||
|
active_shader_id_ = 0;
|
||||||
|
active_texture_id_ = 0;
|
||||||
|
fps_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace eng
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include "engine/renderer/vulkan/renderer_vulkan.h"
|
||||||
|
|
||||||
|
#include "base/log.h"
|
||||||
|
#include "engine/platform/platform.h"
|
||||||
|
|
||||||
|
namespace eng {
|
||||||
|
|
||||||
|
bool RendererVulkan::Initialize(Platform* platform) {
|
||||||
|
LOG(0) << "Initializing renderer.";
|
||||||
|
|
||||||
|
// XWindowAttributes xwa;
|
||||||
|
// XGetWindowAttributes(platform->GetInstance(), platform->GetWindow(), &xwa);
|
||||||
|
RECT rect;
|
||||||
|
GetClientRect(platform->GetWindow(), &rect);
|
||||||
|
|
||||||
|
if (!context_.Initialize()) {
|
||||||
|
LOG(0) << "Failed to initialize Vulkan context.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!context_.CreateSurface(platform->GetInstance(), platform->GetWindow(),
|
||||||
|
rect.right, rect.bottom)) {
|
||||||
|
LOG(0) << "Vulkan context failed to create window.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return InitializeInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace eng
|
|
@ -703,7 +703,7 @@ bool VulkanContext::InitializeQueues(VkSurfaceKHR surface) {
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
VkFormat desired_format = VK_FORMAT_R8G8B8A8_UNORM;
|
VkFormat desired_format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) || defined(_WIN32)
|
||||||
VkFormat desired_format = VK_FORMAT_B8G8R8A8_UNORM;
|
VkFormat desired_format = VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
struct ANativeWindow;
|
struct ANativeWindow;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// #if defined(_WIN32)
|
||||||
|
// #include <windows.h>
|
||||||
|
// #endif
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
// Adapted from godot engin.
|
// Adapted from godot engin.
|
||||||
|
@ -27,6 +31,8 @@ class VulkanContext {
|
||||||
bool CreateWindow(ANativeWindow* window, int width, int height);
|
bool CreateWindow(ANativeWindow* window, int width, int height);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
bool CreateWindow(Display* display, ::Window window, int width, int height);
|
bool CreateWindow(Display* display, ::Window window, int width, int height);
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
bool CreateSurface(HINSTANCE hInstance, HWND hWnd, int width, int height);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ResizeWindow(int width, int height);
|
void ResizeWindow(int width, int height);
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
#include "engine/renderer/vulkan/vulkan_context.h"
|
||||||
|
|
||||||
|
// #if defined(_WIN32)
|
||||||
|
// #include <windows.h>
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
#include "base/log.h"
|
||||||
|
|
||||||
|
namespace eng {
|
||||||
|
|
||||||
|
const char* VulkanContext::GetPlatformSurfaceExtension() const {
|
||||||
|
return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VulkanContext::CreateSurface(HINSTANCE hInstance,
|
||||||
|
HWND hWnd,
|
||||||
|
int width,
|
||||||
|
int height) {
|
||||||
|
VkWin32SurfaceCreateInfoKHR create_info;
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.hinstance = hInstance;
|
||||||
|
create_info.hwnd = hWnd;
|
||||||
|
|
||||||
|
VkSurfaceKHR surface;
|
||||||
|
VkResult err =
|
||||||
|
vkCreateWin32SurfaceKHR(instance_, &create_info, nullptr, &surface);
|
||||||
|
if (err != VK_SUCCESS) {
|
||||||
|
LOG(0) << "vkCreateWin32SurfaceKHR failed with error "
|
||||||
|
<< std::to_string(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!queues_initialized_ && !InitializeQueues(surface))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
window_.surface = surface;
|
||||||
|
window_.width = width;
|
||||||
|
window_.height = height;
|
||||||
|
if (!UpdateSwapChain(&window_))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace eng
|
|
@ -7,6 +7,10 @@ config("third_party_config") {
|
||||||
if (target_os == "linux") {
|
if (target_os == "linux") {
|
||||||
defines = [ "VK_USE_PLATFORM_XLIB_KHR" ]
|
defines = [ "VK_USE_PLATFORM_XLIB_KHR" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target_os == "win") {
|
||||||
|
defines = [ "VK_USE_PLATFORM_WIN32_KHR" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source_set("third_party") {
|
source_set("third_party") {
|
||||||
|
@ -53,7 +57,8 @@ source_set("third_party") {
|
||||||
"glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp",
|
"glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp",
|
||||||
"glslang/glslang/MachineIndependent/propagateNoContraction.cpp",
|
"glslang/glslang/MachineIndependent/propagateNoContraction.cpp",
|
||||||
"glslang/glslang/MachineIndependent/reflection.cpp",
|
"glslang/glslang/MachineIndependent/reflection.cpp",
|
||||||
"glslang/glslang/OSDependent/Unix/ossource.cpp",
|
# "glslang/glslang/OSDependent/Unix/ossource.cpp",
|
||||||
|
"glslang/glslang/OSDependent/Windows/ossource.cpp",
|
||||||
"jsoncpp/json.h",
|
"jsoncpp/json.h",
|
||||||
"jsoncpp/jsoncpp.cpp",
|
"jsoncpp/jsoncpp.cpp",
|
||||||
"minimp3/minimp3.h",
|
"minimp3/minimp3.h",
|
||||||
|
@ -84,6 +89,16 @@ source_set("third_party") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target_os == "win") {
|
||||||
|
sources += [
|
||||||
|
"glew/glew.c",
|
||||||
|
"glew/glew.h",
|
||||||
|
"glew/wglew.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
libs = [ "opengl32.lib" ]
|
||||||
|
}
|
||||||
|
|
||||||
configs -= [ "//build:warnings" ]
|
configs -= [ "//build:warnings" ]
|
||||||
|
|
||||||
deps = []
|
deps = []
|
||||||
|
|
|
@ -213,8 +213,8 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right
|
||||||
case EbtInt64:
|
case EbtInt64:
|
||||||
if (rightUnionArray[i] == 0ll)
|
if (rightUnionArray[i] == 0ll)
|
||||||
newConstArray[i].setI64Const(0x7FFFFFFFFFFFFFFFll);
|
newConstArray[i].setI64Const(0x7FFFFFFFFFFFFFFFll);
|
||||||
else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == (long long)-0x8000000000000000ll)
|
else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == (long long)0x8000000000000000ll)
|
||||||
newConstArray[i].setI64Const((long long)-0x8000000000000000ll);
|
newConstArray[i].setI64Const((long long)0x8000000000000000ll);
|
||||||
else
|
else
|
||||||
newConstArray[i].setI64Const(leftUnionArray[i].getI64Const() / rightUnionArray[i].getI64Const());
|
newConstArray[i].setI64Const(leftUnionArray[i].getI64Const() / rightUnionArray[i].getI64Const());
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue