From c4fa56092b472657087ae54d50fc6ca39a20cbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 1 Apr 2016 12:40:18 -0700 Subject: [PATCH] GL: Added clip control support. --- include/bgfx/bgfx.h | 2 ++ include/bgfx/c99/bgfx.h | 2 ++ src/bgfx.cpp | 4 ++++ src/renderer_gl.cpp | 11 +++++++++++ src/renderer_gl.h | 16 ++++++++++++++++ 5 files changed, 35 insertions(+) diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 28c232d5c..456b3c03c 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -499,6 +499,8 @@ namespace bgfx uint8_t numGPUs; //!< Number of enumerated GPUs. uint16_t vendorId; //!< Selected GPU vendor id. uint16_t deviceId; //!< Selected GPU device id. + bool homogeneousDepth; //!< True when NDC depth is in [-1, 1] range. + bool originBottomLeft; //!< True when NDC origin is at bottom left. /// GPU info. /// diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 736ac51f1..927933353 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -393,6 +393,8 @@ typedef struct bgfx_caps uint16_t maxViews; uint8_t maxFBAttachments; uint8_t numGPUs; + bool homogeneousDepth; + bool originBottomLeft; uint16_t vendorId; uint16_t deviceId; diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 3a839c828..3c91a05e5 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1151,6 +1151,10 @@ namespace bgfx } BX_TRACE("Max FB attachments: %d", g_caps.maxFBAttachments); + BX_TRACE("NDC depth [%d, 1], origin %s left." + , g_caps.homogeneousDepth ? -1 : 0 + , g_caps.originBottomLeft ? "bottom" : "top" + ); } TextureFormat::Enum getViableTextureFormat(const ImageContainer& _imageContainer) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index ca09b64eb..73d730ec8 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1818,6 +1818,17 @@ namespace bgfx { namespace gl ); } + if (s_extension[Extension::ARB_clip_control].m_supported) + { + GL_CHECK(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE) ); + g_caps.originBottomLeft = true; + } + else + { + g_caps.homogeneousDepth = true; + g_caps.originBottomLeft = true; + } + m_vaoSupport = !!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) || s_extension[Extension::ARB_vertex_array_object].m_supported || s_extension[Extension::OES_vertex_array_object].m_supported diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 65aebcbaa..2bc9da441 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -791,6 +791,22 @@ typedef uint64_t GLuint64; # define GL_CONSERVATIVE_RASTERIZATION_NV 0x9346 #endif // GL_CONSERVATIVE_RASTERIZATION_NV +#ifndef GL_NEGATIVE_ONE_TO_ONE +# define GL_NEGATIVE_ONE_TO_ONE 0x935E +#endif // GL_NEGATIVE_ONE_TO_ONE + +#ifndef GL_ZERO_TO_ONE +# define GL_ZERO_TO_ONE 0x935F +#endif // GL_ZERO_TO_ONE + +#ifndef GL_LOWER_LEFT +# define GL_LOWER_LEFT 0x8CA1 +#endif // GL_LOWER_LEFT + +#ifndef GL_UPPER_LEFT +# define GL_UPPER_LEFT 0x8CA2 +#endif // GL_UPPER_LEFT + // _KHR or _ARB... #define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 #define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243