Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples to use metal as default graphics API on mac #937

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/actor_animation/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
22 changes: 20 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,16 @@ int main(int _argc, char** _argv)
}
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -281,7 +292,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
5 changes: 4 additions & 1 deletion examples/camera_tracking/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -139,7 +143,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
4 changes: 4 additions & 0 deletions examples/custom_scene_viewer/ManualSceneDemo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
4 changes: 4 additions & 0 deletions examples/custom_shaders_uniforms/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
6 changes: 5 additions & 1 deletion 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,11 @@ int main(int _argc, char** _argv)
engineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
4 changes: 4 additions & 0 deletions examples/heightmap/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2 && buildDemScene != 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
4 changes: 4 additions & 0 deletions examples/lidar_visual/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
5 changes: 4 additions & 1 deletion examples/mesh_viewer/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -153,7 +157,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
5 changes: 4 additions & 1 deletion examples/mouse_picking/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -146,7 +150,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
4 changes: 4 additions & 0 deletions examples/ogre2_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ int main(int _argc, char** _argv)
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
4 changes: 4 additions & 0 deletions examples/particles_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
5 changes: 4 additions & 1 deletion examples/projector/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -191,7 +195,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
5 changes: 4 additions & 1 deletion examples/render_pass/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -209,7 +213,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
4 changes: 4 additions & 0 deletions examples/segmentation_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ int main(int _argc, char** _argv)
engineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
5 changes: 4 additions & 1 deletion examples/simple_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand All @@ -229,7 +233,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
4 changes: 4 additions & 0 deletions examples/thermal_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

#ifdef __APPLE__
GraphicsAPI graphicsApi = GraphicsAPI::METAL;
#else
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
#endif
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
Expand Down
Loading
Loading