Created
July 22, 2024 04:05
-
-
Save pollend/5b8e15b26aa274452c1682cc6c1de848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Forge/Config.h" | |
#include "Common_3/OS/Interfaces/IOperatingSystem.h" | |
#include "Common_3/Utilities/Interfaces/IFileSystem.h" | |
#include "Forge/Graphics/TF_GPUConfig.h" | |
#include <X11/Xlib.h> | |
#ifdef TF_TARGET_LINUX | |
#include <gtk/gtk.h> | |
#endif | |
// Reload | |
enum ReloadNotify | |
{ | |
RELOAD_RESIZE = 0x1, | |
RELOAD_SHADER = 0x2, | |
RELOAD_RENDERTARGET = 0x4, | |
RELOAD_ALL = UINT32_MAX, | |
RELOAD_COUNT = 3, | |
}; | |
COMPILE_ASSERT(RELOAD_TYPE_COUNT == 3); | |
enum AppExecResult { APP_SUCCESS = 0, APP_FAILURE = -1 }; | |
struct ReloadHandler { | |
ReloadNotify mNotify; | |
}; | |
struct InitDesc { | |
uint32_t mSelectedAPI; | |
}; | |
struct AppDesc { | |
const char *mName; | |
}; | |
struct FORGE_API SampleCallback { | |
bool (*Init)(); | |
void (*LoadHandler)(struct ReloadHandler *handler); | |
void (*UnLoadHandler)(struct ReloadHandler *pReloadDesc) = 0; | |
}; | |
static inline bool SampleDefaultLoadGpuConfiguration(struct GPUConfiguration* def) { | |
{ | |
FileStream fh = {}; | |
if (!fsOpenStreamFromPath(RD_GPU_CONFIG, "gpu.data", FM_READ, &fh)) { | |
LOGF(LogLevel::eWARNING, "gpu.data could not be found, setting preset "); | |
return false; | |
} | |
size_t fileSize = fsGetStreamFileSize(&fh); | |
char *buffer = (char *)tf_malloc(fileSize * sizeof(char)); | |
fsReadFromStream(&fh, (void *)buffer, fileSize); | |
tfLoadGPUData(def, {buffer, fileSize}); | |
tf_free(buffer); | |
} | |
{ | |
FileStream fh = {}; | |
if (!fsOpenStreamFromPath(RD_GPU_CONFIG, "gpu.cfg", FM_READ, &fh)) { | |
LOGF(LogLevel::eWARNING, "gpu.data could not be found, setting preset "); | |
return false; | |
} | |
size_t fileSize = fsGetStreamFileSize(&fh); | |
char *buffer = (char *)tf_malloc(fileSize * sizeof(char)); | |
fsReadFromStream(&fh, (void *)buffer, fileSize); | |
tfLoadGPUConfig(def, {buffer, fileSize}); | |
tf_free(buffer); | |
} | |
return true; | |
} | |
static inline AppExecResult AppExec(int argc, char** argv, struct AppDesc* desc, SampleCallback* callback) { | |
if (!initMemAlloc(desc->mName)) | |
return APP_FAILURE; | |
FileSystemInitDesc fsDesc = {}; | |
fsDesc.pAppName = desc->mName; | |
if (!initFileSystem(&fsDesc)) | |
return APP_FAILURE; | |
fsSetPathForResourceDir(pSystemFileIO, RM_DEBUG, RD_LOG, ""); | |
initLog(desc->mName, DEFAULT_LOG_LEVEL); | |
#if TF_USE_MTUNER | |
rmemInit(0); | |
#endif | |
#ifdef TF_TARGET_LINUX | |
gtk_init(&argc, &argv); | |
Display *display = XOpenDisplay(NULL); | |
int version; | |
int XRandrMajor; | |
int XRandrMinor; | |
bool gHasXRandr = XQueryExtension(display, "RANDR", &version, &version, &version) && | |
XRRQueryVersion(display, &XRandrMajor, &XRandrMinor); | |
int monitorCount = XScreenCount(display); | |
if (monitorCount == 0) | |
return APP_FAILURE; | |
if (!gHasXRandr) | |
LOGF(LogLevel::eWARNING, "XRANDR not supported on current platform"); | |
ASSERT(display); | |
#endif | |
if (!callback->Init()) | |
return APP_FAILURE; | |
return APP_SUCCESS; | |
} | |
//#if defined(TF_TARGET_LINUX) | |
// | |
//#define DEFINE_APPLICATION_MAIN(appClass) \ | |
// extern int DurangoMain(int argc, char** argv, IApp* app); \ | |
// \ | |
// int main(int argc, char** argv) \ | |
// { \ | |
// IApp::argc = argc; \ | |
// IApp::argv = (const char**)argv; \ | |
// static appClass app = {}; \ | |
// return DurangoMain(argc, argv, &app); \ | |
// } | |
// | |
//#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment