Skip to content

Commit

Permalink
Expose launch args to render sessions
Browse files Browse the repository at this point in the history
Summary: This is an alternative implementation of D50209756. Read that diff and discussion for all the context on this change.

Reviewed By: corporateshark

Differential Revision: D50285937

fbshipit-source-id: 450c1a30de21cb3293b765d95823f0a8e13c1e98
  • Loading branch information
Thiago Goulart authored and facebook-github-bot committed Oct 14, 2023
1 parent 99e95be commit c425844
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions shell/ios/main.m → shell/ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

#import "AppDelegate.h"

#import <shell/shared/platform/Platform.h>

int main(int argc, char* argv[]) {
igl::shell::Platform::initializeCommandLineArgs(argc, argv);

@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
Expand Down
8 changes: 6 additions & 2 deletions shell/mac/main.m → shell/mac/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#import <Cocoa/Cocoa.h>

int main(int argc, const char* argv[]) {
return NSApplicationMain(argc, argv);
#import <shell/shared/platform/Platform.h>

int main(int argc, char* argv[]) {
igl::shell::Platform::initializeCommandLineArgs(argc, argv);

return NSApplicationMain(argc, (const char**)argv);
}
25 changes: 25 additions & 0 deletions shell/shared/platform/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#include <shell/shared/imageLoader/ImageLoader.h>
#include <shell/shared/platform/Platform.h>

namespace {

int g_argc = 0;
char** g_argv = nullptr;
bool g_argsInitialized = false;

} // namespace

namespace igl::shell {

Platform::~Platform() = default;
Expand Down Expand Up @@ -40,4 +48,21 @@ std::shared_ptr<ITexture> Platform::loadTexture(const char* filename,
return tex;
}

int Platform::argc() {
IGL_ASSERT_MSG(g_argsInitialized, "Accessing command line args before they are initialized.");
return g_argc;
}

char** Platform::argv() {
IGL_ASSERT_MSG(g_argsInitialized, "Accessing command line args before they are initialized.");
return g_argv;
}

void Platform::initializeCommandLineArgs(int argc, char** argv) {
IGL_ASSERT_MSG(!g_argsInitialized, "Must not initialize command line arguments more than once.");
g_argc = argc;
g_argv = argv;
g_argsInitialized = true;
}

} // namespace igl::shell
8 changes: 8 additions & 0 deletions shell/shared/platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class Platform {
igl::TextureFormat format = igl::TextureFormat::RGBA_SRGB,
igl::TextureDesc::TextureUsageBits usage = igl::TextureDesc::TextureUsageBits::Sampled);

// 'argc' and 'argv' are the exact arguments received in 'main()'.
static int argc();
static char** argv();

// Don't call this from the application level. The shell framework will use this API to expose
// command line arguments for the application.
static void initializeCommandLineArgs(int argc, char** argv);

public:
Extension* createAndInitializeExtension(const char* name) noexcept;

Expand Down
2 changes: 2 additions & 0 deletions shell/windows/opengl/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ static void RunApplicationMode(uint32_t majorVersion, uint32_t minorVersion) {
}

int main(int argc, char* argv[]) {
igl::shell::Platform::initializeCommandLineArgs(argc, argv);

uint32_t majorVersion = 4;
uint32_t minorVersion = 6;
if (argc == 2) {
Expand Down
2 changes: 2 additions & 0 deletions shell/windows/opengles/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ igl::SurfaceTextures createSurfaceTextures(igl::IDevice& device) {
}

int main(int argc, char* argv[]) {
igl::shell::Platform::initializeCommandLineArgs(argc, argv);

uint32_t majorVersion = 3;
uint32_t minorVersion = 1;
if (argc == 2) {
Expand Down
2 changes: 2 additions & 0 deletions shell/windows/vulkan/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ igl::SurfaceTextures getVulkanSurfaceTextures(igl::IDevice& device) {
}

int main(int argc, char* argv[]) {
igl::shell::Platform::initializeCommandLineArgs(argc, argv);

using WindowPtr = std::unique_ptr<GLFWwindow, decltype(&glfwDestroyWindow)>;

WindowPtr vulkanWindow(initWindow(), &glfwDestroyWindow);
Expand Down

0 comments on commit c425844

Please sign in to comment.