Skip to content

Commit

Permalink
Update examples to use metal as default graphics API on mac (#937)
Browse files Browse the repository at this point in the history
* Use metal as default on apple, fix compile warning, remove optix
* Add defaultGraphicsAPI utility function

---------

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Nov 1, 2023
1 parent adb0f1c commit 451e34e
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/actor_animation/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
18 changes: 16 additions & 2 deletions examples/boundingbox_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@ void buildScene(ScenePtr _scene, BoundingBoxType _type)

//////////////////////////////////////////////////
std::vector<CameraPtr> createCameras(const std::string &_engineName,
const std::map<std::string, std::string>& _params,
BoundingBoxType _type)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
gzwarn << "Engine '" << _engineName
Expand Down Expand Up @@ -271,6 +272,12 @@ int main(int _argc, char** _argv)
}
}

GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -281,7 +288,14 @@ int main(int _argc, char** _argv)
{
try
{
cameras = createCameras(engineName, bboxType);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

cameras = createCameras(engineName, params, bboxType);
}
catch (...)
{
Expand Down
3 changes: 1 addition & 2 deletions examples/camera_tracking/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -139,7 +139,6 @@ int main(int _argc, char** _argv)
std::vector<NodePtr> nodes;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");

for (auto engineName : engineNames)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_scene_viewer/ManualSceneDemo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_shaders_uniforms/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
4 changes: 2 additions & 2 deletions examples/depth_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void buildScene(ScenePtr _scene)
camera->SetImageFormat(PixelFormat::PF_FLOAT32_RGBA);
camera->SetNearClipPlane(0.15);
camera->SetFarClipPlane(10.0);
camera->SetAntiAliasing(2);
camera->SetAntiAliasing(2);
camera->CreateDepthTexture();

root->AddChild(camera);
Expand Down Expand Up @@ -154,7 +154,7 @@ int main(int _argc, char** _argv)
engineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
2 changes: 1 addition & 1 deletion examples/heightmap/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2 && buildDemScene != 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
2 changes: 1 addition & 1 deletion examples/lidar_visual/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
3 changes: 1 addition & 2 deletions examples/mesh_viewer/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -153,7 +153,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");

for (auto engineName : engineNames)
{
Expand Down
3 changes: 1 addition & 2 deletions examples/mouse_picking/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -146,7 +146,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");

for (auto engineName : engineNames)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/ogre2_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ int main(int _argc, char** _argv)
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
2 changes: 1 addition & 1 deletion examples/particles_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
3 changes: 1 addition & 2 deletions examples/projector/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -191,7 +191,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");
for (auto engineName : engineNames)
{
try
Expand Down
3 changes: 1 addition & 2 deletions examples/render_pass/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -209,7 +209,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");
for (auto engineName : engineNames)
{
try
Expand Down
2 changes: 1 addition & 1 deletion examples/segmentation_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int main(int _argc, char** _argv)
engineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
3 changes: 1 addition & 2 deletions examples/simple_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -229,7 +229,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");

for (auto engineName : engineNames)
{
Expand Down
46 changes: 39 additions & 7 deletions examples/simple_demo_qml/ThreadRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void RenderThread::Print(const QSurfaceFormat &_format)
return "CompatibilityProfile";
default:
return "Invalid OpenGLContextProfile";
}
}
};

auto renderableTypeToString = [] (QSurfaceFormat::RenderableType _value) -> std::string
Expand All @@ -146,7 +146,7 @@ void RenderThread::Print(const QSurfaceFormat &_format)
return "OpenVG";
default:
return "Invalid RenderableType";
}
}
};

auto swapBehaviorToString = [] (QSurfaceFormat::SwapBehavior _value) -> std::string
Expand All @@ -161,7 +161,7 @@ void RenderThread::Print(const QSurfaceFormat &_format)
return "DoubleBuffer";
default:
return "Invalid SwapBehavior";
}
}
};

// surface format info
Expand Down Expand Up @@ -200,7 +200,7 @@ QSurfaceFormat RenderThread::CreateSurfaceFormat()
format.setProfile(QSurfaceFormat::CoreProfile);
format.setRenderableType(QSurfaceFormat::OpenGL);

return format;
return format;
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -272,8 +272,25 @@ TextureNode::TextureNode(QQuickWindow *_window)
, window(_window)
{
// Our texture node must have a texture, so use the default 0 texture.
// createTextureFromNativeObject()
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
# ifndef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# endif
this->texture = this->window->createTextureFromId(0, QSize(1, 1));
# ifndef _WIN32
# pragma GCC diagnostic pop
# endif
#else
int texId = 0;
this->texture =
this->window->createTextureFromNativeObject(
QQuickWindow::NativeObjectTexture,
static_cast<void *>(&texId),
0,
QSize(1, 1));
#endif

this->setTexture(this->texture);
this->setFiltering(QSGTexture::Linear);
}
Expand Down Expand Up @@ -314,8 +331,23 @@ void TextureNode::PrepareNode()
this->texture = nullptr;
// note: include QQuickWindow::TextureHasAlphaChannel if the rendered content
// has alpha.
// createTextureFromNativeObject
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
# ifndef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# endif
this->texture = this->window->createTextureFromId(newId, size);
# ifndef _WIN32
# pragma GCC diagnostic pop
# endif
#else
this->texture =
this->window->createTextureFromNativeObject(
QQuickWindow::NativeObjectTexture,
static_cast<void *>(&newId),
0,
size);
#endif
this->setTexture(this->texture);

this->markDirty(DirtyMaterial);
Expand All @@ -342,7 +374,7 @@ void ThreadRenderer::Ready()
this->renderThread->surface->setFormat(this->renderThread->context->format());
this->renderThread->surface->create();

// carry out any initialisation before moving to thread
// carry out any initialisation before moving to thread
this->renderThread->InitialiseOnMainThread();

// Move to Render thread
Expand Down
1 change: 0 additions & 1 deletion examples/text_geom/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back("ogre");
engineNames.push_back("optix");
for (auto engineName : engineNames)
{
try
Expand Down
2 changes: 1 addition & 1 deletion examples/thermal_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
3 changes: 1 addition & 2 deletions examples/transform_control/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -132,7 +132,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");

for (auto engineName : engineNames)
{
Expand Down
3 changes: 1 addition & 2 deletions examples/view_control/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -178,7 +178,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(ogreEngineName);
engineNames.push_back("optix");
for (auto engineName : engineNames)
{
try
Expand Down
3 changes: 1 addition & 2 deletions examples/visualization_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int main(int _argc, char** _argv)
engine = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
GraphicsAPI graphicsApi = defaultGraphicsAPI();
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -259,7 +259,6 @@ int main(int _argc, char** _argv)
std::vector<CameraPtr> cameras;

engineNames.push_back(engine);
engineNames.push_back("optix");

for (auto engineName : engineNames)
{
Expand Down
Loading

0 comments on commit 451e34e

Please sign in to comment.