diff --git a/source/MaterialXRender/ShaderRenderer.cpp b/source/MaterialXRender/ShaderRenderer.cpp index 99f27c6b37..315d6fdca7 100644 --- a/source/MaterialXRender/ShaderRenderer.cpp +++ b/source/MaterialXRender/ShaderRenderer.cpp @@ -25,10 +25,11 @@ const float DEFAULT_FAR_PLANE = 100.0f; // ShaderRenderer methods // -ShaderRenderer::ShaderRenderer(unsigned int width, unsigned int height, Image::BaseType baseType) : +ShaderRenderer::ShaderRenderer(unsigned int width, unsigned int height, Image::BaseType baseType, ConventionAPI conventionAPI) : _width(width), _height(height), - _baseType(baseType) + _baseType(baseType), + _conventionAPI(conventionAPI) { // Initialize a default camera. float fH = std::tan(DEFAULT_FIELD_OF_VIEW / 360.0f * PI) * DEFAULT_NEAR_PLANE; @@ -36,11 +37,14 @@ ShaderRenderer::ShaderRenderer(unsigned int width, unsigned int height, Image::B _camera = Camera::create(); _camera->setViewMatrix(Camera::createViewMatrix(DEFAULT_EYE_POSITION, DEFAULT_TARGET_POSITION, DEFAULT_UP_VECTOR)); - #if defined (__APPLE__) + if (_conventionAPI == ShaderRenderer::ConventionAPI::METAL) + { _camera->setProjectionMatrix(Camera::createPerspectiveMatrixZP(-fW, fW, -fH, fH, DEFAULT_NEAR_PLANE, DEFAULT_FAR_PLANE)); - #else + } + else // ConventionAPI::OPENGL (default) + { _camera->setProjectionMatrix(Camera::createPerspectiveMatrix(-fW, fW, -fH, fH, DEFAULT_NEAR_PLANE, DEFAULT_FAR_PLANE)); - #endif + } } void ShaderRenderer::createProgram(ShaderPtr) diff --git a/source/MaterialXRender/ShaderRenderer.h b/source/MaterialXRender/ShaderRenderer.h index 2c6f5fbf87..53f35bb072 100644 --- a/source/MaterialXRender/ShaderRenderer.h +++ b/source/MaterialXRender/ShaderRenderer.h @@ -30,6 +30,12 @@ using ShaderRendererPtr = std::shared_ptr; class MX_RENDER_API ShaderRenderer { public: + /// API viewing conventions designation (default to OpenGL). + enum class ConventionAPI + { + OPENGL = 0, + METAL = 1 + }; /// A map with name and source code for each shader stage. using StageMap = StringMap; @@ -123,13 +129,16 @@ class MX_RENDER_API ShaderRenderer /// @} protected: - ShaderRenderer(unsigned int width, unsigned int height, Image::BaseType baseType); + ShaderRenderer(unsigned int width, unsigned int height, Image::BaseType baseType, + ConventionAPI conventionAPI = ConventionAPI::OPENGL); protected: unsigned int _width; unsigned int _height; Image::BaseType _baseType; + ConventionAPI _conventionAPI; + CameraPtr _camera; ImageHandlerPtr _imageHandler; GeometryHandlerPtr _geometryHandler; diff --git a/source/MaterialXRenderGlsl/GlslRenderer.cpp b/source/MaterialXRenderGlsl/GlslRenderer.cpp index e81ded996e..982ea230e4 100644 --- a/source/MaterialXRenderGlsl/GlslRenderer.cpp +++ b/source/MaterialXRenderGlsl/GlslRenderer.cpp @@ -25,7 +25,7 @@ GlslRendererPtr GlslRenderer::create(unsigned int width, unsigned int height, Im } GlslRenderer::GlslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType) : - ShaderRenderer(width, height, baseType), + ShaderRenderer(width, height, baseType, ConventionAPI::OPENGL), _initialized(false), _screenColor(DEFAULT_SCREEN_COLOR_LIN_REC709) { diff --git a/source/MaterialXRenderMsl/MslRenderer.mm b/source/MaterialXRenderMsl/MslRenderer.mm index 284aabbb8f..0cd5720656 100644 --- a/source/MaterialXRenderMsl/MslRenderer.mm +++ b/source/MaterialXRenderMsl/MslRenderer.mm @@ -29,7 +29,7 @@ } MslRenderer::MslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType) : - ShaderRenderer(width, height, baseType), + ShaderRenderer(width, height, baseType, ConventionAPI::METAL), _initialized(false), _screenColor(DEFAULT_SCREEN_COLOR_LIN_REC709) {