summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/renderer_gl.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/renderer_gl.cpp')
-rw-r--r--3rdparty/bgfx/src/renderer_gl.cpp3094
1 files changed, 2141 insertions, 953 deletions
diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp
index 7f0afda9a04..ff860faec25 100644
--- a/3rdparty/bgfx/src/renderer_gl.cpp
+++ b/3rdparty/bgfx/src/renderer_gl.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ * Copyright 2011-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include "bgfx_p.h"
@@ -9,11 +9,20 @@
# include "renderer_gl.h"
# include <bx/timer.h>
# include <bx/uint32_t.h>
+# include "emscripten.h"
namespace bgfx { namespace gl
{
static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
+ inline void setViewType(ViewId _view, const bx::StringView _str)
+ {
+ if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION || BGFX_CONFIG_PROFILER) )
+ {
+ bx::memCopy(&s_viewName[_view][3], _str.getPtr(), _str.getLength() );
+ }
+ }
+
struct PrimInfo
{
GLenum m_type;
@@ -177,97 +186,139 @@ namespace bgfx { namespace gl
GLenum m_internalFmt;
GLenum m_internalFmtSrgb;
GLenum m_fmt;
+ GLenum m_fmtSrgb;
GLenum m_type;
- bool m_supported;
+ bool m_supported;
+ GLint m_mapping[4];
};
+// In desktop OpenGL 4+ and OpenGL ES 3.0+, specific GL formats GL_x_INTEGER are used for integer textures.
+// For older desktop OpenGL contexts, GL names without _INTEGER suffix were used.
+// See http://docs.gl/gl4/glTexImage2D, http://docs.gl/gl3/glTexImage2D, http://docs.gl/es3/glTexImage2D
+#if BGFX_CONFIG_RENDERER_OPENGL >= 40 || BGFX_CONFIG_RENDERER_OPENGLES
+# define RED_INTEGER GL_RED_INTEGER
+# define RG_INTEGER GL_RG_INTEGER
+# define RGB_INTEGER GL_RGB_INTEGER
+# define RGBA_INTEGER GL_RGBA_INTEGER
+#else
+# define RED_INTEGER GL_RED
+# define RG_INTEGER GL_RG
+# define RGB_INTEGER GL_RGB
+# define RGBA_INTEGER GL_RGBA
+#endif
+
static TextureFormatInfo s_textureFormat[] =
{
- { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false }, // BC1
- { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false }, // BC2
- { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false }, // BC3
- { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false }, // BC4
- { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false }, // BC5
- { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false }, // BC6H
- { GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false }, // BC7
- { GL_ETC1_RGB8_OES, GL_ZERO, GL_ETC1_RGB8_OES, GL_ZERO, false }, // ETC1
- { GL_COMPRESSED_RGB8_ETC2, GL_ZERO, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false }, // ETC2
- { GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false }, // ETC2A
- { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false }, // ETC2A1
- { GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12
- { GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14
- { GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12A
- { GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A
- { GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22
- { GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24
- { GL_ATC_RGB_AMD, GL_ZERO, GL_ATC_RGB_AMD, GL_ZERO, false }, // ATC
- { GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, false }, // ATCE
- { GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, false }, // ATCI
- { GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_SRGB8_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_ZERO, false }, // ASTC4x4
- { GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_SRGB8_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_ZERO, false }, // ASTC5x5
- { GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_SRGB8_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_ZERO, false }, // ASTC6x6
- { GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_SRGB8_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_ZERO, false }, // ASTC8x5
- { GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_SRGB8_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_ZERO, false }, // ASTC8x6
- { GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_SRGB8_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_ZERO, false }, // ASTC10x5
- { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown
- { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1
- { GL_ALPHA, GL_ZERO, GL_ALPHA, GL_UNSIGNED_BYTE, false }, // A8
- { GL_R8, GL_ZERO, GL_RED, GL_UNSIGNED_BYTE, false }, // R8
- { GL_R8I, GL_ZERO, GL_RED, GL_BYTE, false }, // R8I
- { GL_R8UI, GL_ZERO, GL_RED, GL_UNSIGNED_BYTE, false }, // R8U
- { GL_R8_SNORM, GL_ZERO, GL_RED, GL_BYTE, false }, // R8S
- { GL_R16, GL_ZERO, GL_RED, GL_UNSIGNED_SHORT, false }, // R16
- { GL_R16I, GL_ZERO, GL_RED, GL_SHORT, false }, // R16I
- { GL_R16UI, GL_ZERO, GL_RED, GL_UNSIGNED_SHORT, false }, // R16U
- { GL_R16F, GL_ZERO, GL_RED, GL_HALF_FLOAT, false }, // R16F
- { GL_R16_SNORM, GL_ZERO, GL_RED, GL_SHORT, false }, // R16S
- { GL_R32I, GL_ZERO, GL_RED, GL_INT, false }, // R32I
- { GL_R32UI, GL_ZERO, GL_RED, GL_UNSIGNED_INT, false }, // R32U
- { GL_R32F, GL_ZERO, GL_RED, GL_FLOAT, false }, // R32F
- { GL_RG8, GL_ZERO, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8
- { GL_RG8I, GL_ZERO, GL_RG, GL_BYTE, false }, // RG8I
- { GL_RG8UI, GL_ZERO, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8U
- { GL_RG8_SNORM, GL_ZERO, GL_RG, GL_BYTE, false }, // RG8S
- { GL_RG16, GL_ZERO, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16
- { GL_RG16I, GL_ZERO, GL_RG, GL_SHORT, false }, // RG16I
- { GL_RG16UI, GL_ZERO, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16U
- { GL_RG16F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG16F
- { GL_RG16_SNORM, GL_ZERO, GL_RG, GL_SHORT, false }, // RG16S
- { GL_RG32I, GL_ZERO, GL_RG, GL_INT, false }, // RG32I
- { GL_RG32UI, GL_ZERO, GL_RG, GL_UNSIGNED_INT, false }, // RG32U
- { GL_RG32F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG32F
- { GL_RGB8, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, false }, // RGB8
- { GL_RGB8I, GL_ZERO, GL_RGB, GL_BYTE, false }, // RGB8I
- { GL_RGB8UI, GL_ZERO, GL_RGB, GL_UNSIGNED_BYTE, false }, // RGB8U
- { GL_RGB8_SNORM, GL_ZERO, GL_RGB, GL_BYTE, false }, // RGB8S
- { GL_RGB9_E5, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, false }, // RGB9E5F
- { GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8
- { GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
- { GL_RGBA8I, GL_ZERO, GL_RGBA, GL_BYTE, false }, // RGBA8I
- { GL_RGBA8UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8U
- { GL_RGBA8_SNORM, GL_ZERO, GL_RGBA, GL_BYTE, false }, // RGBA8S
- { GL_RGBA16, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT, false }, // RGBA16
- { GL_RGBA16I, GL_ZERO, GL_RGBA, GL_SHORT, false }, // RGBA16I
- { GL_RGBA16UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT, false }, // RGBA16U
- { GL_RGBA16F, GL_ZERO, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F
- { GL_RGBA16_SNORM, GL_ZERO, GL_RGBA, GL_SHORT, false }, // RGBA16S
- { GL_RGBA32I, GL_ZERO, GL_RGBA, GL_INT, false }, // RGBA32I
- { GL_RGBA32UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32U
- { GL_RGBA32F, GL_ZERO, GL_RGBA, GL_FLOAT, false }, // RGBA32F
- { GL_RGB565, GL_ZERO, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5
- { GL_RGBA4, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false }, // RGBA4
- { GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false }, // RGB5A1
- { GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2
- { GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // RG11B10F
- { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth
- { GL_DEPTH_COMPONENT16, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16
- { GL_DEPTH_COMPONENT24, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24
- { GL_DEPTH24_STENCIL8, GL_ZERO, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8
- { GL_DEPTH_COMPONENT32, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D32
- { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D16F
- { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D24F
- { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D32F
- { GL_STENCIL_INDEX8, GL_ZERO, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false }, // D0S8
+#define $_ -1
+#define $0 GL_ZERO
+#define $1 GL_ONE
+#define $R GL_RED
+#define $G GL_GREEN
+#define $B GL_BLUE
+#define $A GL_ALPHA
+ { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC1
+ { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC2
+ { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC3
+ { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC4
+ { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC5
+ { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC6H
+ { GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC7
+ { GL_ETC1_RGB8_OES, GL_ZERO, GL_ETC1_RGB8_OES, GL_ETC1_RGB8_OES, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC1
+ { GL_COMPRESSED_RGB8_ETC2, GL_ZERO, GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC2
+ { GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC2A
+ { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC2A1
+ { GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC12
+ { GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC14
+ { GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC12A
+ { GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC14A
+ { GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC22
+ { GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC24
+ { GL_ATC_RGB_AMD, GL_ZERO, GL_ATC_RGB_AMD, GL_ATC_RGB_AMD, GL_ZERO, false, { $_, $_, $_, $_ } }, // ATC
+ { GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, false, { $_, $_, $_, $_ } }, // ATCE
+ { GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, false, { $_, $_, $_, $_ } }, // ATCI
+ { GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_SRGB8_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC4x4
+ { GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_COMPRESSED_SRGB8_ASTC_5x4_KHR, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC5x4
+ { GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_SRGB8_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC5x5
+ { GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_COMPRESSED_SRGB8_ASTC_6x5_KHR, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC6x5
+ { GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_SRGB8_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC6x6
+ { GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_SRGB8_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC8x5
+ { GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_SRGB8_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC8x6
+ { GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_COMPRESSED_SRGB8_ASTC_8x8_KHR, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC8x8
+ { GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_SRGB8_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x5
+ { GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_COMPRESSED_SRGB8_ASTC_10x6_KHR, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x6
+ { GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_COMPRESSED_SRGB8_ASTC_10x8_KHR, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x8
+ { GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_COMPRESSED_SRGB8_ASTC_10x10_KHR, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x10
+ { GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_COMPRESSED_SRGB8_ASTC_12x10_KHR, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC12x10
+ { GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_COMPRESSED_SRGB8_ASTC_12x12_KHR, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC12x12
+ { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // Unknown
+ { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // R1
+ { GL_ALPHA, GL_ZERO, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // A8
+ { GL_R8, GL_ZERO, GL_RED, GL_RED, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // R8
+ { GL_R8I, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // R8I
+ { GL_R8UI, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // R8U
+ { GL_R8_SNORM, GL_ZERO, GL_RED, GL_RED, GL_BYTE, false, { $_, $_, $_, $_ } }, // R8S
+ { GL_R16, GL_ZERO, GL_RED, GL_RED, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // R16
+ { GL_R16I, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_SHORT, false, { $_, $_, $_, $_ } }, // R16I
+ { GL_R16UI, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // R16U
+ { GL_R16F, GL_ZERO, GL_RED, GL_RED, GL_HALF_FLOAT, false, { $_, $_, $_, $_ } }, // R16F
+ { GL_R16_SNORM, GL_ZERO, GL_RED, GL_RED, GL_SHORT, false, { $_, $_, $_, $_ } }, // R16S
+ { GL_R32I, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_INT, false, { $_, $_, $_, $_ } }, // R32I
+ { GL_R32UI, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // R32U
+ { GL_R32F, GL_ZERO, GL_RED, GL_RED, GL_FLOAT, false, { $_, $_, $_, $_ } }, // R32F
+ { GL_RG8, GL_ZERO, GL_RG, GL_RG, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RG8
+ { GL_RG8I, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // RG8I
+ { GL_RG8UI, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RG8U
+ { GL_RG8_SNORM, GL_ZERO, GL_RG, GL_RG, GL_BYTE, false, { $_, $_, $_, $_ } }, // RG8S
+ { GL_RG16, GL_ZERO, GL_RG, GL_RG, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RG16
+ { GL_RG16I, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_SHORT, false, { $_, $_, $_, $_ } }, // RG16I
+ { GL_RG16UI, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RG16U
+ { GL_RG16F, GL_ZERO, GL_RG, GL_RG, GL_HALF_FLOAT, false, { $_, $_, $_, $_ } }, // RG16F
+ { GL_RG16_SNORM, GL_ZERO, GL_RG, GL_RG, GL_SHORT, false, { $_, $_, $_, $_ } }, // RG16S
+ { GL_RG32I, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_INT, false, { $_, $_, $_, $_ } }, // RG32I
+ { GL_RG32UI, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // RG32U
+ { GL_RG32F, GL_ZERO, GL_RG, GL_RG, GL_FLOAT, false, { $_, $_, $_, $_ } }, // RG32F
+ { GL_RGB8, GL_SRGB8, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGB8
+ { GL_RGB8I, GL_ZERO, RGB_INTEGER, GL_RGB_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGB8I
+ { GL_RGB8UI, GL_ZERO, RGB_INTEGER, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGB8U
+ { GL_RGB8_SNORM, GL_ZERO, GL_RGB, GL_RGB, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGB8S
+ { GL_RGB9_E5, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, false, { $_, $_, $_, $_ } }, // RGB9E5F
+ { GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // BGRA8
+ { GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8
+ { GL_RGBA8I, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8I
+ { GL_RGBA8UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8U
+ { GL_RGBA8_SNORM, GL_ZERO, GL_RGBA, GL_RGBA, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8S
+ { GL_RGBA16, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16
+ { GL_RGBA16I, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16I
+ { GL_RGBA16UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16U
+ { GL_RGBA16F, GL_ZERO, GL_RGBA, GL_RGBA, GL_HALF_FLOAT, false, { $_, $_, $_, $_ } }, // RGBA16F
+ { GL_RGBA16_SNORM, GL_ZERO, GL_RGBA, GL_RGBA, GL_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16S
+ { GL_RGBA32I, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_INT, false, { $_, $_, $_, $_ } }, // RGBA32I
+ { GL_RGBA32UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // RGBA32U
+ { GL_RGBA32F, GL_ZERO, GL_RGBA, GL_RGBA, GL_FLOAT, false, { $_, $_, $_, $_ } }, // RGBA32F
+ { GL_RGB565, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false, { $_, $_, $_, $_ } }, // B5G6R5
+ { GL_RGB565, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false, { $_, $_, $_, $_ } }, // R5G6B5
+ { GL_RGBA4, GL_ZERO, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false, { $_, $_, $_, $_ } }, // BGRA4
+ { GL_RGBA4, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false, { $_, $_, $_, $_ } }, // RGBA4
+ { GL_RGB5_A1, GL_ZERO, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false, { $_, $_, $_, $_ } }, // BGR5A1
+ { GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false, { $_, $_, $_, $_ } }, // RGB5A1
+ { GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false, { $_, $_, $_, $_ } }, // RGB10A2
+ { GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false, { $_, $_, $_, $_ } }, // RG11B10F
+ { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // UnknownDepth
+ { GL_DEPTH_COMPONENT16, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // D16
+ { GL_DEPTH_COMPONENT24, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // D24
+ { GL_DEPTH24_STENCIL8, GL_ZERO, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false, { $_, $_, $_, $_ } }, // D24S8
+ { GL_DEPTH_COMPONENT32, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // D32
+ { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false, { $_, $_, $_, $_ } }, // D16F
+ { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false, { $_, $_, $_, $_ } }, // D24F
+ { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false, { $_, $_, $_, $_ } }, // D32F
+ { GL_STENCIL_INDEX8, GL_ZERO, GL_STENCIL_INDEX, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // D0S8
+#undef $_
+#undef $0
+#undef $1
+#undef $R
+#undef $G
+#undef $B
+#undef $A
};
BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) );
@@ -296,11 +347,19 @@ namespace bgfx { namespace gl
GL_ZERO, // ATCE
GL_ZERO, // ATCI
GL_ZERO, // ASTC4x4
+ GL_ZERO, // ASTC5x4
GL_ZERO, // ASTC5x5
+ GL_ZERO, // ASTC6x5
GL_ZERO, // ASTC6x6
GL_ZERO, // ASTC8x5
GL_ZERO, // ASTC8x6
+ GL_ZERO, // ASTC8x8
GL_ZERO, // ASTC10x5
+ GL_ZERO, // ASTC10x6
+ GL_ZERO, // ASTC10x8
+ GL_ZERO, // ASTC10x10
+ GL_ZERO, // ASTC12x10
+ GL_ZERO, // ASTC12x12
GL_ZERO, // Unknown
GL_ZERO, // R1
GL_ALPHA, // A8
@@ -346,8 +405,11 @@ namespace bgfx { namespace gl
GL_RGBA32I, // RGBA32I
GL_RGBA32UI, // RGBA32U
GL_RGBA32F, // RGBA32F
+ GL_RGB565, // B5G6R5
GL_RGB565, // R5G6B5
+ GL_RGBA4, // BGRA4
GL_RGBA4, // RGBA4
+ GL_RGB5_A1, // BGR5A1
GL_RGB5_A1, // RGB5A1
GL_RGB10_A2, // RGB10A2
GL_R11F_G11F_B10F, // RG11B10F
@@ -386,11 +448,19 @@ namespace bgfx { namespace gl
GL_ZERO, // ATCE
GL_ZERO, // ATCI
GL_ZERO, // ASTC4x4
+ GL_ZERO, // ASTC5x4
GL_ZERO, // ASTC5x5
+ GL_ZERO, // ASTC6x5
GL_ZERO, // ASTC6x6
GL_ZERO, // ASTC8x5
GL_ZERO, // ASTC8x6
+ GL_ZERO, // ASTC8x8
GL_ZERO, // ASTC10x5
+ GL_ZERO, // ASTC10x6
+ GL_ZERO, // ASTC10x8
+ GL_ZERO, // ASTC10x10
+ GL_ZERO, // ASTC12x10
+ GL_ZERO, // ASTC12x12
GL_ZERO, // Unknown
GL_ZERO, // R1
GL_ALPHA, // A8
@@ -436,8 +506,11 @@ namespace bgfx { namespace gl
GL_RGBA32I, // RGBA32I
GL_RGBA32UI, // RGBA32U
GL_RGBA32F, // RGBA32F
+ GL_RGB565, // B5G6R5
GL_RGB565, // R5G6B5
+ GL_RGBA4, // BGRA4
GL_RGBA4, // RGBA4
+ GL_RGB5_A1, // BGR5A1
GL_RGB5_A1, // RGB5A1
GL_RGB10_A2, // RGB10A2
GL_R11F_G11F_B10F, // RG11B10F
@@ -490,6 +563,7 @@ namespace bgfx { namespace gl
ARB_get_program_binary,
ARB_half_float_pixel,
ARB_half_float_vertex,
+ ARB_indirect_parameters,
ARB_instanced_arrays,
ARB_internalformat_query,
ARB_internalformat_query2,
@@ -500,12 +574,14 @@ namespace bgfx { namespace gl
ARB_occlusion_query,
ARB_occlusion_query2,
ARB_program_interface_query,
+ ARB_provoking_vertex,
ARB_sampler_objects,
ARB_seamless_cube_map,
ARB_shader_bit_encoding,
ARB_shader_image_load_store,
ARB_shader_storage_buffer_object,
ARB_shader_texture_lod,
+ ARB_shader_viewport_layer_array,
ARB_texture_compression_bptc,
ARB_texture_compression_rgtc,
ARB_texture_cube_map_array,
@@ -576,6 +652,8 @@ namespace bgfx { namespace gl
EXT_texture_type_2_10_10_10_REV,
EXT_timer_query,
EXT_unpack_subimage,
+ EXT_sRGB,
+ EXT_multisampled_render_to_texture,
GOOGLE_depth_texture,
@@ -597,6 +675,8 @@ namespace bgfx { namespace gl
NV_conservative_raster,
NV_copy_image,
NV_draw_buffers,
+ NV_draw_instanced,
+ NV_instanced_arrays,
NV_occlusion_query,
NV_texture_border_clamp,
NVX_gpu_memory_info,
@@ -608,6 +688,7 @@ namespace bgfx { namespace gl
OES_depth_texture,
OES_element_index_uint,
OES_fragment_precision_high,
+ OES_fbo_render_mipmap,
OES_get_program_binary,
OES_required_internalformat,
OES_packed_depth_stencil,
@@ -700,6 +781,7 @@ namespace bgfx { namespace gl
{ "ARB_get_program_binary", BGFX_CONFIG_RENDERER_OPENGL >= 41, true },
{ "ARB_half_float_pixel", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "ARB_half_float_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
+ { "ARB_indirect_parameters", BGFX_CONFIG_RENDERER_OPENGL >= 46, true },
{ "ARB_instanced_arrays", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
{ "ARB_internalformat_query", BGFX_CONFIG_RENDERER_OPENGL >= 42, true },
{ "ARB_internalformat_query2", BGFX_CONFIG_RENDERER_OPENGL >= 43, true },
@@ -710,12 +792,14 @@ namespace bgfx { namespace gl
{ "ARB_occlusion_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
{ "ARB_occlusion_query2", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
{ "ARB_program_interface_query", BGFX_CONFIG_RENDERER_OPENGL >= 43, true },
+ { "ARB_provoking_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 32, true },
{ "ARB_sampler_objects", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
{ "ARB_seamless_cube_map", BGFX_CONFIG_RENDERER_OPENGL >= 32, true },
{ "ARB_shader_bit_encoding", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
{ "ARB_shader_image_load_store", BGFX_CONFIG_RENDERER_OPENGL >= 42, true },
{ "ARB_shader_storage_buffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 43, true },
{ "ARB_shader_texture_lod", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
+ { "ARB_shader_viewport_layer_array", false, true },
{ "ARB_texture_compression_bptc", BGFX_CONFIG_RENDERER_OPENGL >= 44, true },
{ "ARB_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "ARB_texture_cube_map_array", BGFX_CONFIG_RENDERER_OPENGL >= 40, true },
@@ -760,7 +844,7 @@ namespace bgfx { namespace gl
{ "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "EXT_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
- { "EXT_gpu_shader4", false, true },
+ { "EXT_gpu_shader4", BGFX_CONFIG_RENDERER_OPENGL >= 31, true },
{ "EXT_multi_draw_indirect", false, true }, // GLES3.1 extension.
{ "EXT_occlusion_query_boolean", false, true }, // GLES2 extension.
{ "EXT_packed_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
@@ -786,6 +870,8 @@ namespace bgfx { namespace gl
{ "EXT_texture_type_2_10_10_10_REV", false, true },
{ "EXT_timer_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true },
{ "EXT_unpack_subimage", false, true },
+ { "EXT_sRGB", false, true }, // GLES2 extension.
+ { "EXT_multisampled_render_to_texture", false, true }, // GLES2 extension.
{ "GOOGLE_depth_texture", false, true },
@@ -807,6 +893,8 @@ namespace bgfx { namespace gl
{ "NV_conservative_raster", false, true },
{ "NV_copy_image", false, true },
{ "NV_draw_buffers", false, true }, // GLES2 extension.
+ { "NV_draw_instanced", false, true }, // GLES2 extension.
+ { "NV_instanced_arrays", false, true }, // GLES2 extension.
{ "NV_occlusion_query", false, true },
{ "NV_texture_border_clamp", false, true }, // GLES2 extension.
{ "NVX_gpu_memory_info", false, true },
@@ -818,6 +906,7 @@ namespace bgfx { namespace gl
{ "OES_depth_texture", false, true },
{ "OES_element_index_uint", false, true },
{ "OES_fragment_precision_high", false, true },
+ { "OES_fbo_render_mipmap", false, true },
{ "OES_get_program_binary", false, true },
{ "OES_required_internalformat", false, true },
{ "OES_packed_depth_stencil", false, true },
@@ -882,6 +971,13 @@ namespace bgfx { namespace gl
NULL
};
+ static const char* s_ARB_shader_viewport_layer_array[] =
+ {
+ "gl_ViewportIndex",
+ "gl_Layer",
+ NULL
+ };
+
static const char* s_EXT_shadow_samplers[] =
{
"shadow2D",
@@ -1005,6 +1101,14 @@ namespace bgfx { namespace gl
{
}
+ static void GL_APIENTRY stubPushDebugGroup(GLenum /*_source*/, GLuint /*_id*/, GLsizei /*_length*/, const char* /*_message*/)
+ {
+ }
+
+ static void GL_APIENTRY stubPopDebugGroup()
+ {
+ }
+
static void GL_APIENTRY stubObjectLabel(GLenum /*_identifier*/, GLuint /*_name*/, GLsizei /*_length*/, const char* /*_label*/)
{
}
@@ -1013,20 +1117,30 @@ namespace bgfx { namespace gl
{
}
- static void GL_APIENTRY stubMultiDrawArraysIndirect(GLenum _mode, const void* _indirect, GLsizei _drawcount, GLsizei _stride)
+ static void GL_APIENTRY stubFramebufferTexture(GLenum _target, GLenum _attachment, GLuint _texture, GLint _level)
+ {
+ GL_CHECK(glFramebufferTextureLayer(_target
+ , _attachment
+ , _texture
+ , _level
+ , 0
+ ) );
+ }
+
+ static void GL_APIENTRY stubMultiDrawArraysIndirect(GLenum _mode, const void* _indirect, GLsizei _drawCount, GLsizei _stride)
{
const uint8_t* args = (const uint8_t*)_indirect;
- for (GLsizei ii = 0; ii < _drawcount; ++ii)
+ for (GLsizei ii = 0; ii < _drawCount; ++ii)
{
GL_CHECK(glDrawArraysIndirect(_mode, (void*)args) );
args += _stride;
}
}
- static void GL_APIENTRY stubMultiDrawElementsIndirect(GLenum _mode, GLenum _type, const void* _indirect, GLsizei _drawcount, GLsizei _stride)
+ static void GL_APIENTRY stubMultiDrawElementsIndirect(GLenum _mode, GLenum _type, const void* _indirect, GLsizei _drawCount, GLsizei _stride)
{
const uint8_t* args = (const uint8_t*)_indirect;
- for (GLsizei ii = 0; ii < _drawcount; ++ii)
+ for (GLsizei ii = 0; ii < _drawCount; ++ii)
{
GL_CHECK(glDrawElementsIndirect(_mode, _type, (void*)args) );
args += _stride;
@@ -1039,10 +1153,22 @@ namespace bgfx { namespace gl
typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
+ void flushGlError()
+ {
+ for (GLenum err = glGetError(); err != 0; err = glGetError() );
+ }
+
+ GLenum getGlError()
+ {
+ GLenum err = glGetError();
+ flushGlError();
+ return err;
+ }
+
static const char* getGLString(GLenum _name)
{
const char* str = (const char*)glGetString(_name);
- glGetError(); // ignore error if glGetString returns NULL.
+ getGlError(); // ignore error if glGetString returns NULL.
if (NULL != str)
{
return str;
@@ -1054,7 +1180,7 @@ namespace bgfx { namespace gl
static uint32_t getGLStringHash(GLenum _name)
{
const char* str = (const char*)glGetString(_name);
- glGetError(); // ignore error if glGetString returns NULL.
+ getGlError(); // ignore error if glGetString returns NULL.
if (NULL != str)
{
return bx::hash<bx::HashMurmur2A>(str, (uint32_t)bx::strLen(str) );
@@ -1139,22 +1265,97 @@ namespace bgfx { namespace gl
{
GLint result = 0;
glGetIntegerv(_pname, &result);
- GLenum err = glGetError();
+ GLenum err = getGlError();
BX_WARN(0 == err, "glGetIntegerv(0x%04x, ...) failed with GL error: 0x%04x.", _pname, err);
return 0 == err ? result : 0;
}
+ static uint64_t s_currentlyEnabledVertexAttribArrays = 0;
+ static uint64_t s_vertexAttribArraysPendingDisable = 0;
+ static uint64_t s_vertexAttribArraysPendingEnable = 0;
+
+ void lazyEnableVertexAttribArray(GLuint index)
+ {
+ if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
+ {
+ if (index >= 64)
+ {
+ // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize
+ // out redundant API calls to glEnable/DisableVertexAttribArray.
+ GL_CHECK(glEnableVertexAttribArray(index) );
+ return;
+ }
+
+ const uint64_t mask = UINT64_C(1) << index;
+ s_vertexAttribArraysPendingEnable |= mask & (~s_currentlyEnabledVertexAttribArrays);
+ s_vertexAttribArraysPendingDisable &= ~mask;
+ }
+ else
+ {
+ GL_CHECK(glEnableVertexAttribArray(index) );
+ }
+ }
+
+ void lazyDisableVertexAttribArray(GLuint index)
+ {
+ if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
+ {
+ if (index >= 64)
+ {
+ // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize
+ // out redundant API calls to glEnable/DisableVertexAttribArray.
+ GL_CHECK(glDisableVertexAttribArray(index) );
+ return;
+ }
+
+ const uint64_t mask = UINT64_C(1) << index;
+ s_vertexAttribArraysPendingDisable |= mask & s_currentlyEnabledVertexAttribArrays;
+ s_vertexAttribArraysPendingEnable &= ~mask;
+ }
+ else
+ {
+ GL_CHECK(glDisableVertexAttribArray(index) );
+ }
+ }
+
+ void applyLazyEnabledVertexAttributes()
+ {
+ if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
+ {
+ while (s_vertexAttribArraysPendingDisable)
+ {
+ uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingDisable);
+ uint64_t mask = ~(UINT64_C(1) << index);
+ s_vertexAttribArraysPendingDisable &= mask;
+ s_currentlyEnabledVertexAttribArrays &= mask;
+ GL_CHECK(glDisableVertexAttribArray(index) );
+ }
+
+ while (s_vertexAttribArraysPendingEnable)
+ {
+ uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingEnable);
+ uint64_t mask = UINT64_C(1) << index;
+ s_vertexAttribArraysPendingEnable &= ~mask;
+ s_currentlyEnabledVertexAttribArrays |= mask;
+ GL_CHECK(glEnableVertexAttribArray(index) );
+ }
+ }
+ }
+
void setTextureFormat(TextureFormat::Enum _format, GLenum _internalFmt, GLenum _fmt, GLenum _type = GL_ZERO)
{
TextureFormatInfo& tfi = s_textureFormat[_format];
tfi.m_internalFmt = _internalFmt;
tfi.m_fmt = _fmt;
+ tfi.m_fmtSrgb = _fmt;
tfi.m_type = _type;
}
- void flushGlError()
+ void setTextureFormatSrgb(TextureFormat::Enum _format, GLenum _internalFmtSrgb, GLenum _fmtSrgb)
{
- for (GLenum err = glGetError(); err != 0; err = glGetError() );
+ TextureFormatInfo& tfi = s_textureFormat[_format];
+ tfi.m_internalFmtSrgb = _internalFmtSrgb;
+ tfi.m_fmtSrgb = _fmtSrgb;
}
static void texSubImage(
@@ -1409,6 +1610,10 @@ namespace bgfx { namespace gl
? tfi.m_internalFmtSrgb
: tfi.m_internalFmt
;
+ GLenum fmt = _srgb
+ ? tfi.m_fmtSrgb
+ : tfi.m_fmt
+ ;
GLsizei bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(_format) );
GLsizei size = (_dim*_dim*bpp)/8;
@@ -1441,7 +1646,7 @@ namespace bgfx { namespace gl
uint32_t block = bx::uint32_max(4, dim);
size = (block*block*bpp)/8;
compressedTexImage(target, ii, internalFmt, dim, dim, 0, 0, size, data);
- err |= glGetError();
+ err |= getGlError();
}
}
else
@@ -1450,14 +1655,164 @@ namespace bgfx { namespace gl
{
dim = bx::uint32_max(1, dim);
size = (dim*dim*bpp)/8;
- texImage(target, 0, ii, internalFmt, dim, dim, 0, 0, tfi.m_fmt, tfi.m_type, data);
- err |= glGetError();
+ texImage(target, 0, ii, internalFmt, dim, dim, 0, 0, fmt, tfi.m_type, data);
+ err |= getGlError();
}
}
return err;
}
+#if BX_PLATFORM_EMSCRIPTEN
+ static bool isTextureFormatValidPerSpec(
+ TextureFormat::Enum _format
+ , bool _srgb
+ , bool _mipAutogen
+ )
+ {
+ // Avoid creating test textures for WebGL, that causes error noise in the browser
+ // console; instead examine the supported texture formats from the spec.
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();
+
+ EmscriptenWebGLContextAttributes attrs;
+ EMSCRIPTEN_CHECK(emscripten_webgl_get_context_attributes(ctx, &attrs) );
+
+ const int glesVersion = attrs.majorVersion + 1;
+
+ switch(_format)
+ {
+ case TextureFormat::A8:
+ case TextureFormat::R8: // Luminance
+ case TextureFormat::B5G6R5:
+ case TextureFormat::R5G6B5:
+ case TextureFormat::BGRA4:
+ case TextureFormat::RGBA4:
+ case TextureFormat::BGR5A1:
+ case TextureFormat::RGB5A1:
+ // GLES2 formats without sRGB.
+ return !_srgb;
+
+ case TextureFormat::D16:
+ // GLES2 formats without sRGB, depth textures do not support mipmaps.
+ return !_srgb
+ && !_mipAutogen
+ ;
+
+ case TextureFormat::R16F:
+ case TextureFormat::R32F:
+ case TextureFormat::RG8:
+ case TextureFormat::RG16F:
+ case TextureFormat::RG32F:
+ case TextureFormat::RGB10A2:
+ case TextureFormat::RG11B10F:
+ // GLES3 formats without sRGB
+ return !_srgb
+ && glesVersion >= 3
+ ;
+
+ case TextureFormat::R8I:
+ case TextureFormat::R8U:
+ case TextureFormat::R16I:
+ case TextureFormat::R16U:
+ case TextureFormat::R32I:
+ case TextureFormat::R32U:
+ case TextureFormat::RG8I:
+ case TextureFormat::RG8U:
+ case TextureFormat::RG16I:
+ case TextureFormat::RG16U:
+ case TextureFormat::RG32I:
+ case TextureFormat::RG32U:
+ case TextureFormat::RGB8I:
+ case TextureFormat::RGB8U:
+ case TextureFormat::RGBA8I:
+ case TextureFormat::RGBA8U:
+ case TextureFormat::RGBA16I:
+ case TextureFormat::RGBA16U:
+ case TextureFormat::RGBA32I:
+ case TextureFormat::RGBA32U:
+ case TextureFormat::D32F:
+ case TextureFormat::R8S:
+ case TextureFormat::RG8S:
+ case TextureFormat::RGB8S:
+ case TextureFormat::RGBA8S:
+ case TextureFormat::RGB9E5F:
+ // GLES3 formats without sRGB that are not texture filterable or color renderable.
+ return !_srgb && glesVersion >= 3
+ && !_mipAutogen
+ ;
+
+ case TextureFormat::D24:
+ case TextureFormat::D24S8:
+ case TextureFormat::D32:
+ // GLES3 formats without sRGB, depth textures do not support mipmaps.
+ return !_srgb && !_mipAutogen
+ && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "WEBGL_depth_texture") )
+ ;
+
+ case TextureFormat::D16F:
+ case TextureFormat::D24F:
+ // GLES3 depth formats without sRGB, depth textures do not support mipmaps.
+ return !_srgb
+ && !_mipAutogen
+ && glesVersion >= 3
+ ;
+
+ case TextureFormat::RGBA16F:
+ case TextureFormat::RGBA32F:
+ // GLES3 formats without sRGB
+ return !_srgb
+ && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "OES_texture_half_float") )
+ ;
+
+ case TextureFormat::RGB8:
+ case TextureFormat::RGBA8:
+ // sRGB formats
+ return !_srgb
+ || glesVersion >= 3
+ || emscripten_webgl_enable_extension(ctx, "EXT_sRGB")
+ ;
+
+ case TextureFormat::BC1:
+ case TextureFormat::BC2:
+ case TextureFormat::BC3:
+ return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_s3tc")
+ && (!_srgb || emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_s3tc_srgb") )
+ ;
+
+ case TextureFormat::PTC12:
+ case TextureFormat::PTC14:
+ case TextureFormat::PTC12A:
+ case TextureFormat::PTC14A:
+ return !_srgb
+ && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_pvrtc")
+ ;
+
+ case TextureFormat::ETC1:
+ return !_srgb
+ && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc1")
+ ;
+
+ case TextureFormat::ETC2:
+ case TextureFormat::ETC2A:
+ case TextureFormat::ETC2A1:
+ return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc");
+
+ case TextureFormat::ASTC4x4:
+ case TextureFormat::ASTC5x5:
+ case TextureFormat::ASTC6x6:
+ case TextureFormat::ASTC8x5:
+ case TextureFormat::ASTC8x6:
+ case TextureFormat::ASTC10x5:
+ return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_astc");
+
+ default:
+ break;
+ }
+
+ return false;
+ }
+#endif // BX_PLATFORM_EMSCRIPTEN
+
static bool isTextureFormatValid(
TextureFormat::Enum _format
, bool _srgb = false
@@ -1466,6 +1821,13 @@ namespace bgfx { namespace gl
, GLsizei _dim = 16
)
{
+#if BX_PLATFORM_EMSCRIPTEN
+ // On web platform read the validity of textures based on the available GL context and extensions
+ // to avoid developer unfriendly console error noise that would come from probing.
+ BX_UNUSED(_array, _dim);
+ return isTextureFormatValidPerSpec(_format, _srgb, _mipAutogen);
+#else
+ // On other platforms probe the supported textures.
const TextureFormatInfo& tfi = s_textureFormat[_format];
GLenum internalFmt = _srgb
? tfi.m_internalFmtSrgb
@@ -1476,8 +1838,6 @@ namespace bgfx { namespace gl
return false;
}
-BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
-
const GLenum target = _array
? GL_TEXTURE_2D_ARRAY
: GL_TEXTURE_2D
@@ -1491,13 +1851,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (_array)
{
glTexStorage3D(target
- , 1 + GLsizei(bx::log2(float(_dim) ) )
+ , 1 + GLsizei(bx::log2( (int32_t)_dim) )
, internalFmt
, _dim
, _dim
, _dim
);
- err = glGetError();
+ err = getGlError();
}
if (0 == err)
@@ -1516,13 +1876,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
&& _mipAutogen)
{
glGenerateMipmap(target);
- err = glGetError();
+ err = getGlError();
}
}
GL_CHECK(glDeleteTextures(1, &id) );
return 0 == err;
+#endif
}
static bool isImageFormatValid(TextureFormat::Enum _format, GLsizei _dim = 16)
@@ -1540,7 +1901,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GLenum err = 0;
glTexStorage2D(GL_TEXTURE_2D, 1, s_imageFormat[_format], _dim, _dim);
- err |= glGetError();
+ err |= getGlError();
if (0 == err)
{
glBindImageTexture(0
@@ -1551,7 +1912,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, GL_READ_WRITE
, s_imageFormat[_format]
);
- err |= glGetError();
+ err |= getGlError();
}
GL_CHECK(glDeleteTextures(1, &id) );
@@ -1559,6 +1920,135 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
return 0 == err;
}
+#if BX_PLATFORM_EMSCRIPTEN
+ static bool isFramebufferFormatValidPerSpec(
+ TextureFormat::Enum _format
+ , bool _srgb
+ , bool _writeOnly
+ )
+ {
+ // Avoid creating test textures for WebGL, that causes error noise in the browser console; instead examine the supported texture formats from the spec.
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();
+
+ EmscriptenWebGLContextAttributes attrs;
+ EMSCRIPTEN_CHECK(emscripten_webgl_get_context_attributes(ctx, &attrs) );
+
+ const int glesVersion = attrs.majorVersion + 1;
+
+ switch(_format)
+ {
+ // GLES2 textures
+ case TextureFormat::B5G6R5:
+ case TextureFormat::R5G6B5:
+ case TextureFormat::BGRA4:
+ case TextureFormat::RGBA4:
+ case TextureFormat::BGR5A1:
+ case TextureFormat::RGB5A1:
+ case TextureFormat::D16:
+ return !_srgb;
+
+ // GLES2 renderbuffers not a texture in GLES3
+ case TextureFormat::D0S8:
+ return !_srgb
+ && _writeOnly
+ ;
+
+ // GLES2 textures that are not renderbuffers
+ case TextureFormat::RGB8:
+ case TextureFormat::RGBA8:
+ return !_srgb
+ && (!_writeOnly || glesVersion >= 3)
+ ;
+
+ // GLES3 EXT_color_buffer_float renderbuffer formats
+ case TextureFormat::R16F:
+ case TextureFormat::RG16F:
+ case TextureFormat::R32F:
+ case TextureFormat::RG32F:
+ case TextureFormat::RG11B10F:
+ if (_writeOnly)
+ {
+ return emscripten_webgl_enable_extension(ctx, "EXT_color_buffer_float");
+ }
+
+ return !_srgb && glesVersion >= 3;
+
+ // GLES2 float extension:
+ case TextureFormat::RGBA16F:
+ if (_writeOnly && emscripten_webgl_enable_extension(ctx, "EXT_color_buffer_half_float") )
+ {
+ return true;
+ }
+ BX_FALLTHROUGH;
+
+ case TextureFormat::RGBA32F:
+ if (_writeOnly)
+ {
+ return emscripten_webgl_enable_extension(ctx, "EXT_color_buffer_float") || emscripten_webgl_enable_extension(ctx, "WEBGL_color_buffer_float");
+ }
+
+ // GLES3 formats without sRGB
+ return !_srgb
+ && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "OES_texture_half_float") )
+ ;
+
+ case TextureFormat::D24:
+ case TextureFormat::D24S8:
+ // GLES3 formats without sRGB, depth textures do not support mipmaps.
+ return !_srgb
+ && (glesVersion >= 3 || (!_writeOnly && emscripten_webgl_enable_extension(ctx, "WEBGL_depth_texture") ) )
+ ;
+
+ case TextureFormat::D32:
+ // GLES3 formats without sRGB, depth textures do not support mipmaps.
+ return !_srgb
+ && !_writeOnly
+ && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "WEBGL_depth_texture") )
+ ;
+
+ // GLES3 textures
+ case TextureFormat::R8:
+ case TextureFormat::RG8:
+ case TextureFormat::R8I:
+ case TextureFormat::R8U:
+ case TextureFormat::R16I:
+ case TextureFormat::R16U:
+ case TextureFormat::R32I:
+ case TextureFormat::R32U:
+ case TextureFormat::RG8I:
+ case TextureFormat::RG8U:
+ case TextureFormat::RGBA8I:
+ case TextureFormat::RGBA8U:
+ case TextureFormat::RG16I:
+ case TextureFormat::RG16U:
+ case TextureFormat::RG32I:
+ case TextureFormat::RG32U:
+ case TextureFormat::RGBA16I:
+ case TextureFormat::RGBA16U:
+ case TextureFormat::RGBA32I:
+ case TextureFormat::RGBA32U:
+ case TextureFormat::RGB10A2:
+ case TextureFormat::D16F:
+ case TextureFormat::D24F:
+ case TextureFormat::D32F:
+ return !_srgb
+ && glesVersion >= 3
+ ;
+
+ case TextureFormat::BGRA8:
+ return !_srgb
+ && _writeOnly
+ && glesVersion >= 3
+ ;
+
+ default:
+ break;
+ }
+
+ return false;
+ }
+#endif
+
static bool isFramebufferFormatValid(
TextureFormat::Enum _format
, bool _srgb = false
@@ -1566,6 +2056,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, GLsizei _dim = 16
)
{
+#if BX_PLATFORM_EMSCRIPTEN
+ // On web platform read the validity of framebuffers based on the available GL context and extensions
+ // to avoid developer unfriendly console error noise that would come from probing.
+ BX_UNUSED(_dim);
+ return isFramebufferFormatValidPerSpec(_format, _srgb, _writeOnly);
+#else
+ // On other platforms probe the supported textures.
const TextureFormatInfo& tfi = s_textureFormat[_format];
GLenum internalFmt = _srgb
? tfi.m_internalFmtSrgb
@@ -1590,7 +2087,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glDeleteRenderbuffers(1, &rbo);
- GLenum err = glGetError();
+ GLenum err = getGlError();
return 0 == err;
}
@@ -1632,7 +2129,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, id
, 0
);
- err = glGetError();
+ err = getGlError();
if (0 == err)
{
@@ -1645,6 +2142,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glDeleteTextures(1, &id) );
return GL_FRAMEBUFFER_COMPLETE == err;
+#endif
}
static void getFilters(uint32_t _flags, bool _hasMips, GLenum& _magFilter, GLenum& _minFilter)
@@ -1656,8 +2154,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
_minFilter = s_textureFilterMin[min][_hasMips ? mip+1 : 0];
}
- void updateExtension(const char* _name)
+ void updateExtension(const bx::StringView& _name)
{
+ bx::StringView ext(_name);
+ if (0 == bx::strCmp(ext, "GL_", 3) ) // skip GL_
+ {
+ ext.set(ext.getPtr()+3, ext.getTerm() );
+ }
+
bool supported = false;
for (uint32_t ii = 0; ii < Extension::Count; ++ii)
{
@@ -1665,22 +2169,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (!extension.m_supported
&& extension.m_initialize)
{
- const char* ext = _name;
- if (0 == bx::strCmp(ext, "GL_", 3) ) // skip GL_
- {
- ext += 3;
- }
-
if (0 == bx::strCmp(ext, extension.m_name) )
{
- extension.m_supported = true;
+#if BX_PLATFORM_EMSCRIPTEN
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();
+ supported = emscripten_webgl_enable_extension(ctx, extension.m_name);
+#else
supported = true;
+#endif
+ extension.m_supported = supported;
break;
}
}
}
- BX_TRACE("GL_EXTENSION %s: %s", supported ? " (supported)" : "", _name);
+ BX_TRACE("GL_EXTENSION %s: %.*s", supported ? " (supported)" : "", _name.getLength(), _name.getPtr() );
BX_UNUSED(supported);
}
@@ -1696,6 +2199,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{ "Advanced Micro Devices, Inc.", BGFX_PCI_ID_AMD },
{ "Intel", BGFX_PCI_ID_INTEL },
{ "ATI Technologies Inc.", BGFX_PCI_ID_AMD },
+ { "ARM", BGFX_PCI_ID_ARM },
};
struct Workaround
@@ -1738,6 +2242,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, m_hash( (BX_PLATFORM_WINDOWS<<1) | BX_ARCH_64BIT)
, m_backBufferFbo(0)
, m_msaaBackBufferFbo(0)
+ , m_msaaBlitProgram(0)
+ , m_clearQuadColor(BGFX_INVALID_HANDLE)
+ , m_clearQuadDepth(BGFX_INVALID_HANDLE)
{
bx::memSet(m_msaaBackBufferRbos, 0, sizeof(m_msaaBackBufferRbos) );
}
@@ -1768,13 +2275,39 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::memSet(m_uniforms, 0, sizeof(m_uniforms) );
bx::memSet(&m_resolution, 0, sizeof(m_resolution) );
- setRenderContextSize(_init.resolution.width, _init.resolution.height);
+ setRenderContextSize(_init.resolution.width, _init.resolution.height, _init.resolution.reset);
m_vendor = getGLString(GL_VENDOR);
m_renderer = getGLString(GL_RENDERER);
m_version = getGLString(GL_VERSION);
m_glslVersion = getGLString(GL_SHADING_LANGUAGE_VERSION);
+ {
+ if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
+ {
+ int32_t majorGlVersion = 0;
+ int32_t minorGlVersion = 0;
+ const char* version = m_version;
+
+ while (*version && !bx::isNumeric(*version) )
+ {
+ ++version;
+ }
+
+ bx::fromString(&majorGlVersion, version);
+ bx::fromString(&minorGlVersion, version + 2);
+ int32_t glVersion = majorGlVersion*10 + minorGlVersion;
+
+ BX_TRACE("WebGL context version %d (%d.%d).", glVersion, majorGlVersion, minorGlVersion);
+
+ m_gles3 = glVersion >= 30;
+ }
+ else
+ {
+ m_gles3 = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30);
+ }
+ }
+
for (uint32_t ii = 0; ii < BX_COUNTOF(s_vendorIds); ++ii)
{
const VendorId& vendorId = s_vendorIds[ii];
@@ -1838,6 +2371,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_GET(GL_MAX_RENDERBUFFER_SIZE, 1);
GL_GET(GL_MAX_COLOR_ATTACHMENTS, 1);
GL_GET(GL_MAX_DRAW_BUFFERS, 1);
+
#undef GL_GET
BX_TRACE(" Vendor: %s", m_vendor);
@@ -1872,40 +2406,25 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) )
{
const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
- glGetError(); // ignore error if glGetString returns NULL.
+ getGlError(); // ignore error if glGetString returns NULL.
if (NULL != extensions)
{
- char name[1024];
- const char* pos = extensions;
- const char* end = extensions + bx::strLen(extensions);
- uint32_t index = 0;
- while (pos < end)
- {
- uint32_t len;
- const bx::StringView space = bx::strFind(pos, ' ');
- if (!space.isEmpty() )
- {
- len = bx::uint32_min(sizeof(name), (uint32_t)(space.getPtr() - pos) );
- }
- else
- {
- len = bx::uint32_min(sizeof(name), (uint32_t)bx::strLen(pos) );
- }
-
- bx::strCopy(name, BX_COUNTOF(name), pos, len);
- name[len] = '\0';
+ bx::StringView ext(extensions);
- updateExtension(name);
+ while (!ext.isEmpty() )
+ {
+ const bx::StringView space = bx::strFind(ext, ' ');
+ const bx::StringView token = bx::StringView(ext.getPtr(), space.getPtr() );
+ updateExtension(token);
- pos += len+1;
- ++index;
+ ext.set(space.getPtr() + (space.isEmpty() ? 0 : 1), ext.getTerm() );
}
}
else if (NULL != glGetStringi)
{
GLint numExtensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
- glGetError(); // ignore error if glGetIntegerv returns NULL.
+ getGlError(); // ignore error if glGetIntegerv returns NULL.
for (GLint index = 0; index < numExtensions; ++index)
{
@@ -2021,19 +2540,38 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) )
{
- setTextureFormat(TextureFormat::D32, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
-
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) )
+ if (m_gles3)
{
- setTextureFormat(TextureFormat::RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT);
+ setTextureFormat(TextureFormat::R16F, GL_R16F, GL_RED, 0x140B /* == GL_HALF_FLOAT, but bgfx overwrites it globally with GL_HALF_FLOAT_OES */);
+ setTextureFormat(TextureFormat::RG16F, GL_RG16F, GL_RG, 0x140B /* == GL_HALF_FLOAT, but bgfx overwrites it globally with GL_HALF_FLOAT_OES */);
+ setTextureFormat(TextureFormat::RGBA16F, GL_RGBA16F, GL_RGBA, 0x140B /* == GL_HALF_FLOAT, but bgfx overwrites it globally with GL_HALF_FLOAT_OES */);
+ }
+ else
+ {
+ setTextureFormat(TextureFormat::RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT); // Note: this is actually GL_HALF_FLOAT_OES and not GL_HALF_FLOAT if compiling for GLES target.
setTextureFormat(TextureFormat::RGBA32F, GL_RGBA, GL_RGBA, GL_FLOAT);
// internalFormat and format must match:
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml
setTextureFormat(TextureFormat::RGBA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+ setTextureFormat(TextureFormat::B5G6R5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV);
setTextureFormat(TextureFormat::R5G6B5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV);
+ setTextureFormat(TextureFormat::BGRA4, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV);
setTextureFormat(TextureFormat::RGBA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV);
+ setTextureFormat(TextureFormat::BGR5A1, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV);
setTextureFormat(TextureFormat::RGB5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV);
+ if (s_extension[Extension::EXT_sRGB].m_supported)
+ {
+ setTextureFormatSrgb(TextureFormat::RGBA8, GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT);
+ setTextureFormatSrgb(TextureFormat::RGB8, GL_SRGB_EXT, GL_SRGB_EXT);
+ }
+
+ if (s_extension[Extension::EXT_texture_swizzle].m_supported)
+ {
+ s_textureFormat[TextureFormat::R5G6B5].m_mapping[0] = GL_BLUE;
+ s_textureFormat[TextureFormat::R5G6B5].m_mapping[2] = GL_RED;
+ }
+
if (s_extension[Extension::OES_texture_half_float].m_supported
|| s_extension[Extension::OES_texture_float ].m_supported)
{
@@ -2050,17 +2588,40 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
s_textureFilter[TextureFormat::RG32F] = linear32F;
s_textureFilter[TextureFormat::RGBA32F] = linear32F;
}
+ }
- if (BX_ENABLED(BX_PLATFORM_IOS) || BX_ENABLED(BX_PLATFORM_EMSCRIPTEN))
- {
- setTextureFormat(TextureFormat::D16, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT);
- setTextureFormat(TextureFormat::D24S8, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
- }
+ if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
+ && (s_extension[Extension::WEBGL_depth_texture].m_supported
+ || s_extension[Extension::MOZ_WEBGL_depth_texture].m_supported
+ || s_extension[Extension::WEBKIT_WEBGL_depth_texture].m_supported) )
+ {
+ setTextureFormat(TextureFormat::D16, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT);
+ setTextureFormat(TextureFormat::D24, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); // N.b. OpenGL ES does not guarantee that there are 24 bits available here, could be 16. See https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/
+ setTextureFormat(TextureFormat::D32, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); // N.b. same as above.
+ setTextureFormat(TextureFormat::D24S8, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
+ }
+
+ // OpenGL ES 3.0 depth formats.
+ if (m_gles3)
+ {
+ setTextureFormat(TextureFormat::D16, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT);
+ setTextureFormat(TextureFormat::D24, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
+ setTextureFormat(TextureFormat::D32, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
+ setTextureFormat(TextureFormat::D24S8, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
+ setTextureFormat(TextureFormat::D16F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT); // GLES 3.0 does not have D16F, overshoot to D32F
+ setTextureFormat(TextureFormat::D24F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT); // GLES 3.0 does not have D24F, overshoot to D32F
+ setTextureFormat(TextureFormat::D32F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT);
+ setTextureFormat(TextureFormat::D0S8, GL_STENCIL_INDEX8, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE); // Only works as renderbuffer, not as texture
}
}
+ else
+ {
+ setTextureFormat(TextureFormat::R5G6B5, GL_BGR, GL_BGR, GL_UNSIGNED_SHORT_5_6_5);
+ setTextureFormatSrgb(TextureFormat::R5G6B5, GL_ZERO, GL_BGR);
+ }
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
- || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ || m_gles3)
{
setTextureFormat(TextureFormat::R8I, GL_R8I, GL_RED_INTEGER, GL_BYTE);
setTextureFormat(TextureFormat::R8U, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE);
@@ -2109,14 +2670,26 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
{
- setTextureFormat(TextureFormat::RGBA4, GL_ZERO, GL_ZERO, GL_ZERO);
- setTextureFormat(TextureFormat::RGB5A1, GL_ZERO, GL_ZERO, GL_ZERO);
-
- if (!isTextureFormatValid(TextureFormat::R8) )
+ // OpenGL ES does not have reversed BGRA4 and BGR5A1 support.
+ setTextureFormat(TextureFormat::BGRA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
+ setTextureFormat(TextureFormat::RGBA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
+ setTextureFormat(TextureFormat::BGR5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
+ setTextureFormat(TextureFormat::RGB5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
+ setTextureFormat(TextureFormat::B5G6R5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
+ setTextureFormat(TextureFormat::R5G6B5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
+
+ if (!m_gles3)
{
- // GL core has to use GL_R8 Issue#208, GLES2 has to use GL_LUMINANCE issue#226
- s_textureFormat[TextureFormat::R8].m_internalFmt = GL_LUMINANCE;
- s_textureFormat[TextureFormat::R8].m_fmt = GL_LUMINANCE;
+ // OpenGL ES 2.0 uses unsized internal formats.
+ s_textureFormat[TextureFormat::RGB8].m_internalFmt = GL_RGB;
+
+ // OpenGL ES 2.0 does not have R8 texture format, only L8. Open GL ES 2.0 extension https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_rg.txt
+ // adds support for R8 to GLES 2.0 core contexts. For those use L8 instead.
+ if (!s_extension[Extension::EXT_texture_rg].m_supported)
+ {
+ s_textureFormat[TextureFormat::R8].m_internalFmt = GL_LUMINANCE;
+ s_textureFormat[TextureFormat::R8].m_fmt = GL_LUMINANCE;
+ }
}
}
@@ -2148,6 +2721,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
+ const TextureFormat::Enum fmt = TextureFormat::Enum(ii);
+
uint16_t supported = BGFX_CAPS_FORMAT_TEXTURE_NONE;
supported |= s_textureFormat[ii].m_supported
? BGFX_CAPS_FORMAT_TEXTURE_2D
@@ -2156,30 +2731,33 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
- supported |= isTextureFormatValid(TextureFormat::Enum(ii), true)
+ supported |= isTextureFormatValid(fmt, true)
? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB
| BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB
| BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
- supported |= isTextureFormatValid(TextureFormat::Enum(ii), false, true)
- ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ if (!bimg::isCompressed(bimg::TextureFormat::Enum(fmt) ) )
+ {
+ supported |= isTextureFormatValid(fmt, false, true)
+ ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
+ }
supported |= computeSupport
- && isImageFormatValid(TextureFormat::Enum(ii) )
- ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE
+ && isImageFormatValid(fmt)
+ ? (BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE)
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
- supported |= isFramebufferFormatValid(TextureFormat::Enum(ii) )
+ supported |= isFramebufferFormatValid(fmt)
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
- supported |= isFramebufferFormatValid(TextureFormat::Enum(ii), false, true)
+ supported |= isFramebufferFormatValid(fmt, false, true)
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
@@ -2193,7 +2771,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, 1
, &maxSamples
);
- GLenum err = glGetError();
+ GLenum err = getGlError();
supported |= 0 == err && maxSamples > 0
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
: BGFX_CAPS_FORMAT_TEXTURE_NONE
@@ -2205,7 +2783,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, 1
, &maxSamples
);
- err = glGetError();
+ err = getGlError();
supported |= 0 == err && maxSamples > 0
? BGFX_CAPS_FORMAT_TEXTURE_MSAA
: BGFX_CAPS_FORMAT_TEXTURE_NONE
@@ -2215,17 +2793,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
g_caps.formats[ii] = supported;
}
- g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::OES_texture_3D].m_supported
? BGFX_CAPS_TEXTURE_3D
: 0
;
- g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::EXT_shadow_samplers].m_supported
? BGFX_CAPS_TEXTURE_COMPARE_ALL
: 0
;
- g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::OES_vertex_half_float].m_supported
? BGFX_CAPS_VERTEX_ATTRIB_HALF
: 0
@@ -2236,7 +2814,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
? BGFX_CAPS_VERTEX_ATTRIB_UINT10
: 0
;
- g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::EXT_frag_depth].m_supported
? BGFX_CAPS_FRAGMENT_DEPTH
: 0
@@ -2249,7 +2827,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
? BGFX_CAPS_FRAGMENT_ORDERING
: 0
;
- g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::OES_element_index_uint].m_supported
? BGFX_CAPS_INDEX32
: 0
@@ -2277,6 +2855,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
: 0
;
+ g_caps.supported |= s_extension[Extension::ARB_indirect_parameters].m_supported
+ ? BGFX_CAPS_DRAW_INDIRECT_COUNT
+ : 0
+ ;
+
if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
|| NULL == glPolygonMode)
{
@@ -2288,14 +2871,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|| s_extension[Extension:: NV_copy_image].m_supported
|| s_extension[Extension::OES_copy_image].m_supported)
{
- m_blitSupported = NULL != glCopyImageSubData;
- g_caps.supported |= m_blitSupported
- ? BGFX_CAPS_TEXTURE_BLIT
- : 0
- ;
+ m_blitSupported = NULL != glCopyImageSubData;
}
- g_caps.supported |= m_readBackSupported
+ g_caps.supported |= m_blitSupported || BX_ENABLED(BGFX_GL_CONFIG_BLIT_EMULATION)
+ ? BGFX_CAPS_TEXTURE_BLIT
+ : 0
+ ;
+
+ g_caps.supported |= (m_readBackSupported || BX_ENABLED(BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION) )
? BGFX_CAPS_TEXTURE_READ_BACK
: 0
;
@@ -2303,14 +2887,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
g_caps.supported |= false
|| s_extension[Extension::EXT_texture_array].m_supported
|| s_extension[Extension::EXT_gpu_shader4].m_supported
- || (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
+ || (m_gles3 && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
? BGFX_CAPS_TEXTURE_2D_ARRAY
: 0
;
g_caps.supported |= false
|| s_extension[Extension::EXT_gpu_shader4].m_supported
- || (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
+ || (m_gles3 && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
? BGFX_CAPS_VERTEX_ID
: 0
;
@@ -2323,20 +2907,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
;
g_caps.limits.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) );
- g_caps.limits.maxTextureLayers = uint16_t(bx::max(glGet(GL_MAX_ARRAY_TEXTURE_LAYERS), 1) );
+ g_caps.limits.maxTextureLayers = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) || s_extension[Extension::EXT_texture_array].m_supported ? uint16_t(bx::max(glGet(GL_MAX_ARRAY_TEXTURE_LAYERS), 1) ) : 1;
g_caps.limits.maxComputeBindings = computeSupport ? BGFX_MAX_COMPUTE_BINDINGS : 0;
g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS;
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
- || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ || m_gles3
|| s_extension[Extension::EXT_draw_buffers ].m_supported
|| s_extension[Extension::WEBGL_draw_buffers].m_supported)
{
g_caps.limits.maxFBAttachments = uint8_t(bx::uint32_clamp(
- glGet(GL_MAX_DRAW_BUFFERS)
- , 1
- , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)
- );
+ glGet(GL_MAX_DRAW_BUFFERS)
+ , 1
+ , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)
+ );
}
// if (s_extension[Extension::ARB_clip_control].m_supported)
@@ -2351,7 +2935,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
m_vaoSupport = !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
- && (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ && (m_gles3
|| s_extension[Extension::ARB_vertex_array_object].m_supported
|| s_extension[Extension::OES_vertex_array_object].m_supported
);
@@ -2361,17 +2945,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glGenVertexArrays(1, &m_vao) );
}
- m_samplerObjectSupport = !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
- && (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
- || s_extension[Extension::ARB_sampler_objects].m_supported
- );
+ m_samplerObjectSupport = false
+ || m_gles3
+ || s_extension[Extension::ARB_sampler_objects].m_supported
+ ;
- m_shadowSamplersSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ m_shadowSamplersSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::EXT_shadow_samplers].m_supported
;
m_programBinarySupport = !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
- && (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ && (m_gles3
|| s_extension[Extension::ARB_get_program_binary].m_supported
|| s_extension[Extension::OES_get_program_binary].m_supported
|| s_extension[Extension::IMG_shader_binary ].m_supported
@@ -2382,7 +2966,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|| s_extension[Extension::EXT_texture_swizzle].m_supported
;
- m_depthTextureSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ m_depthTextureSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::ANGLE_depth_texture ].m_supported
|| s_extension[Extension::CHROMIUM_depth_texture ].m_supported
|| s_extension[Extension::GOOGLE_depth_texture ].m_supported
@@ -2422,12 +3006,18 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_atocSupport = s_extension[Extension::ARB_multisample].m_supported;
m_conservativeRasterSupport = s_extension[Extension::NV_conservative_raster].m_supported;
+ m_imageLoadStoreSupport = false
+ || s_extension[Extension::ARB_shader_image_load_store].m_supported
+ || s_extension[Extension::EXT_shader_image_load_store].m_supported
+ ;
+
g_caps.supported |= 0
| (m_atocSupport ? BGFX_CAPS_ALPHA_TO_COVERAGE : 0)
| (m_conservativeRasterSupport ? BGFX_CAPS_CONSERVATIVE_RASTER : 0)
| (m_occlusionQuerySupport ? BGFX_CAPS_OCCLUSION_QUERY : 0)
| (m_depthTextureSupport ? BGFX_CAPS_TEXTURE_COMPARE_LEQUAL : 0)
| (computeSupport ? BGFX_CAPS_COMPUTE : 0)
+ | (m_imageLoadStoreSupport ? BGFX_CAPS_IMAGE_RW : 0)
;
g_caps.supported |= m_glctx.getCaps();
@@ -2449,11 +3039,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
if (s_extension[Extension::ARB_texture_multisample].m_supported
- || s_extension[Extension::ANGLE_framebuffer_multisample].m_supported)
+ || s_extension[Extension::ANGLE_framebuffer_multisample].m_supported
+ || s_extension[Extension::EXT_multisampled_render_to_texture].m_supported)
{
GL_CHECK(glGetIntegerv(GL_MAX_SAMPLES, &m_maxMsaa) );
}
+#if BGFX_CONFIG_RENDERER_OPENGLES && (BGFX_CONFIG_RENDERER_OPENGLES < 30)
+ if (!m_maxMsaa && s_extension[Extension::IMG_multisampled_render_to_texture].m_supported)
+ {
+ GL_CHECK(glGetIntegerv(GL_MAX_SAMPLES_IMG, &m_maxMsaa) );
+ }
+#endif // BGFX_CONFIG_RENDERER_OPENGLES < 30
+
if (s_extension[Extension::OES_read_format].m_supported
&& (s_extension[Extension::IMG_read_format].m_supported || s_extension[Extension::EXT_read_format_bgra].m_supported) )
{
@@ -2464,15 +3062,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_readPixelsFmt = GL_RGBA;
}
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ if (m_gles3)
{
g_caps.supported |= BGFX_CAPS_INSTANCING;
}
else
{
if (s_extension[Extension::ANGLE_instanced_arrays].m_supported
- || s_extension[Extension::ARB_instanced_arrays].m_supported
- || s_extension[Extension::EXT_instanced_arrays].m_supported)
+ || s_extension[Extension:: ARB_instanced_arrays].m_supported
+ || s_extension[Extension:: EXT_instanced_arrays].m_supported
+ || (s_extension[Extension:: NV_instanced_arrays].m_supported && s_extension[Extension::NV_draw_instanced].m_supported)
+ )
{
if (NULL != glVertexAttribDivisor
&& NULL != glDrawArraysInstanced
@@ -2480,6 +3080,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
g_caps.supported |= BGFX_CAPS_INSTANCING;
}
+ else if (NULL != glVertexAttribDivisorNV
+ && NULL != glDrawArraysInstancedNV
+ && NULL != glDrawElementsInstancedNV)
+ {
+ glVertexAttribDivisor = glVertexAttribDivisorNV;
+ glDrawArraysInstanced = glDrawArraysInstancedNV;
+ glDrawElementsInstanced = glDrawElementsInstancedNV;
+
+ g_caps.supported |= BGFX_CAPS_INSTANCING;
+ }
}
if (0 == (g_caps.supported & BGFX_CAPS_INSTANCING) )
@@ -2490,6 +3100,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
+ g_caps.supported |= s_extension[Extension::ARB_shader_viewport_layer_array].m_supported
+ ? BGFX_CAPS_VIEWPORT_LAYER_ARRAY
+ : 0
+ ;
+
+ g_caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0;
+
if (s_extension[Extension::ARB_debug_output].m_supported
|| s_extension[Extension::KHR_debug].m_supported)
{
@@ -2509,17 +3126,32 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
+ if (NULL == glPushDebugGroup
+ || NULL == glPopDebugGroup)
+ {
+ glPushDebugGroup = stubPushDebugGroup;
+ glPopDebugGroup = stubPopDebugGroup;
+ }
+
if (s_extension[Extension::ARB_seamless_cube_map].m_supported)
{
GL_CHECK(glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) );
}
+ if (NULL != glProvokingVertex
+ && s_extension[Extension::ARB_provoking_vertex].m_supported)
+ {
+ GL_CHECK(glProvokingVertex(GL_FIRST_VERTEX_CONVENTION) );
+ }
+
if (NULL == glInsertEventMarker
|| !s_extension[Extension::EXT_debug_marker].m_supported)
{
glInsertEventMarker = stubInsertEventMarker;
}
+ m_maxLabelLen = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 32) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 43) || s_extension[Extension::KHR_debug].m_supported ? uint16_t(glGet(GL_MAX_LABEL_LENGTH) ) : 0;
+
setGraphicsDebuggerPresent(s_extension[Extension::EXT_debug_tool].m_supported);
if (NULL == glObjectLabel)
@@ -2532,6 +3164,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
glInvalidateFramebuffer = stubInvalidateFramebuffer;
}
+ if (NULL == glFramebufferTexture)
+ {
+ glFramebufferTexture = stubFramebufferTexture;
+ }
+
if (m_timerQuerySupport)
{
m_gpuTimer.create();
@@ -2634,7 +3271,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (m_needPresent)
{
// Ensure the back buffer is bound as the source of the flip
- GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo));
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
m_glctx.swap();
m_needPresent = false;
@@ -2652,20 +3289,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_indexBuffers[_handle.idx].destroy();
}
- void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override
+ void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override
{
- VertexDecl& decl = m_vertexDecls[_handle.idx];
- bx::memCopy(&decl, &_decl, sizeof(VertexDecl) );
- dump(decl);
+ VertexLayout& layout = m_vertexLayouts[_handle.idx];
+ bx::memCopy(&layout, &_layout, sizeof(VertexLayout) );
+ dump(layout);
}
- void destroyVertexDecl(VertexDeclHandle /*_handle*/) override
+ void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override
{
}
- void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) override
+ void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) override
{
- m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags);
+ m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _layoutHandle, _flags);
}
void destroyVertexBuffer(VertexBufferHandle _handle) override
@@ -2690,8 +3327,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override
{
- VertexDeclHandle decl = BGFX_INVALID_HANDLE;
- m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags);
+ VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE;
+ m_vertexBuffers[_handle.idx].create(_size, NULL, layoutHandle, _flags);
}
void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override
@@ -2772,31 +3409,28 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glBindTexture(texture.m_target, 0) );
}
- else
+ else if (BX_ENABLED(BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION) )
{
const TextureGL& texture = m_textures[_handle.idx];
const bool compressed = bimg::isCompressed(bimg::TextureFormat::Enum(texture.m_textureFormat) );
- if(!compressed)
+ if (!compressed)
{
- Attachment attachment[1];
- attachment[0].handle = _handle;
- attachment[0].mip = 0;
- attachment[0].layer = 0;
+ Attachment at[1];
+ at[0].init(_handle);
FrameBufferGL frameBuffer;
- frameBuffer.create(1, attachment);
+ frameBuffer.create(BX_COUNTOF(at), at);
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) );
GL_CHECK(glFramebufferTexture2D(
GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, texture.m_id
- , attachment[0].mip
+ , at[0].mip
) );
- if (!BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
- && !BX_ENABLED(BX_PLATFORM_IOS))
+ if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || m_gles3)
{
GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0) );
}
@@ -2828,7 +3462,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::StaticMemoryBlockWriter writer(mem->data, mem->size);
uint32_t magic = BGFX_CHUNK_MAGIC_TEX;
- bx::write(&writer, magic);
+ bx::write(&writer, magic, bx::ErrorAssert{});
TextureCreate tc;
tc.m_width = _width;
@@ -2839,7 +3473,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
tc.m_cubeMap = false;
tc.m_mem = NULL;
- bx::write(&writer, tc);
+ bx::write(&writer, tc, bx::ErrorAssert{});
texture.destroy();
texture.create(mem, texture.m_flags, 0);
@@ -2927,6 +3561,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
width = frameBuffer.m_width;
height = frameBuffer.m_height;
}
+
m_glctx.makeCurrent(swapChain);
uint32_t length = width*height*4;
@@ -2970,30 +3605,50 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::memCopy(m_uniforms[_loc], _data, _size);
}
- void setMarker(const char* _marker, uint32_t _size) override
+ void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override
{
- GL_CHECK(glInsertEventMarker(_size, _marker) );
+ m_occlusionQuery.invalidate(_handle);
}
- void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override
+ void setMarker(const char* _marker, uint16_t _len) override
{
- m_occlusionQuery.invalidate(_handle);
+ GL_CHECK(glInsertEventMarker(_len, _marker) );
}
- virtual void setName(Handle _handle, const char* _name) override
+ virtual void setName(Handle _handle, const char* _name, uint16_t _len) override
{
+ uint16_t len = bx::min(_len, m_maxLabelLen);
+
switch (_handle.type)
{
+ case Handle::IndexBuffer:
+ GL_CHECK(glObjectLabel(GL_BUFFER, m_indexBuffers[_handle.idx].m_id, len, _name) );
+ break;
+
case Handle::Shader:
- GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, -1, _name) );
+ GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, len, _name) );
break;
case Handle::Texture:
- GL_CHECK(glObjectLabel(GL_TEXTURE, m_textures[_handle.idx].m_id, -1, _name) );
+ {
+ GLint id = m_textures[_handle.idx].m_id;
+ if (0 != id)
+ {
+ GL_CHECK(glObjectLabel(GL_TEXTURE, id, len, _name) );
+ }
+ else
+ {
+ GL_CHECK(glObjectLabel(GL_RENDERBUFFER, m_textures[_handle.idx].m_rbo, len, _name) );
+ }
+ }
+ break;
+
+ case Handle::VertexBuffer:
+ GL_CHECK(glObjectLabel(GL_BUFFER, m_vertexBuffers[_handle.idx].m_id, len, _name) );
break;
default:
- BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
+ BX_ASSERT(false, "Invalid handle type?! %d", _handle.type);
break;
}
}
@@ -3001,7 +3656,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;
-
void blitSetup(TextVideoMemBlitter& _blitter) override
{
if (0 != m_vao)
@@ -3024,30 +3678,26 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) );
ProgramGL& program = m_program[_blitter.m_program.idx];
- GL_CHECK(glUseProgram(program.m_id) );
- GL_CHECK(glUniform1i(program.m_sampler[0], 0) );
+ setProgram(program.m_id);
+ setUniform1i(program.m_sampler[0], 0);
float proj[16];
- bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, true);
+ bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, g_caps.homogeneousDepth);
- GL_CHECK(glUniformMatrix4fv(program.m_predefined[0].m_loc
+ setUniformMatrix4fv(program.m_predefined[0].m_loc
, 1
, GL_FALSE
, proj
- ) );
+ );
GL_CHECK(glActiveTexture(GL_TEXTURE0) );
GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_textures[_blitter.m_texture.idx].m_id) );
if (!BX_ENABLED(BX_PLATFORM_OSX) )
{
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
- || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ if (m_samplerObjectSupport)
{
- if (m_samplerObjectSupport)
- {
- GL_CHECK(glBindSampler(0, 0) );
- }
+ GL_CHECK(glBindSampler(0, 0) );
}
}
}
@@ -3058,7 +3708,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 < numVertices)
{
m_indexBuffers[_blitter.m_ib->handle.idx].update(0, _numIndices*2, _blitter.m_ib->data);
- m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data);
+ m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_layout.m_stride, _blitter.m_vb->data);
VertexBufferGL& vb = m_vertexBuffers[_blitter.m_vb->handle.idx];
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
@@ -3068,7 +3718,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
ProgramGL& program = m_program[_blitter.m_program.idx];
program.bindAttributesBegin();
- program.bindAttributes(_blitter.m_decl, 0);
+ program.bindAttributes(_blitter.m_layout, 0);
program.bindAttributesEnd();
GL_CHECK(glDrawElements(GL_TRIANGLES
@@ -3135,19 +3785,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void setShaderUniform4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
- GL_CHECK(glUniform4fv(_regIndex
+ setUniform4fv(_regIndex
, _numRegs
, (const GLfloat*)_val
- ) );
+ );
}
void setShaderUniform4x4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
- GL_CHECK(glUniformMatrix4fv(_regIndex
+ setUniformMatrix4fv(_regIndex
, _numRegs
, GL_FALSE
, (const GLfloat*)_val
- ) );
+ );
}
uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint16_t _discard = BGFX_CLEAR_NONE, bool _msaa = true)
@@ -3192,6 +3842,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (UINT16_MAX != frameBuffer.m_denseIdx)
{
m_glctx.makeCurrent(frameBuffer.m_swapChain);
+ GL_CHECK(glFrontFace(GL_CW) );
+
frameBuffer.m_needPresent = true;
m_currentFbo = 0;
}
@@ -3225,29 +3877,177 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void createMsaaFbo(uint32_t _width, uint32_t _height, uint32_t _msaa)
{
if (0 == m_msaaBackBufferFbo // iOS
- && 1 < _msaa)
+ && 1 < _msaa
+ && !m_glctx.m_msaaContext)
{
- GL_CHECK(glGenFramebuffers(1, &m_msaaBackBufferFbo) );
- GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) );
- GL_CHECK(glGenRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) );
- GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[0]) );
- GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_RGBA8, _width, _height) );
- GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[1]) );
- GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_DEPTH24_STENCIL8, _width, _height) );
- GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_msaaBackBufferRbos[0]) );
-
- GLenum attachment = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ GLenum storageFormat = m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER
+ ? GL_SRGB8_ALPHA8
+ : GL_RGBA8
+ ;
+
+ GLenum attachment = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || m_gles3
? GL_DEPTH_STENCIL_ATTACHMENT
: GL_DEPTH_ATTACHMENT
;
- GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, m_msaaBackBufferRbos[1]) );
-
- BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)
- , "glCheckFramebufferStatus failed 0x%08x"
- , glCheckFramebufferStatus(GL_FRAMEBUFFER)
- );
+ GL_CHECK(glGenFramebuffers(1, &m_msaaBackBufferFbo) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) );
+
+ if (m_gles3)
+ {
+ GL_CHECK(glGenTextures(BX_COUNTOF(m_msaaBackBufferTextures), m_msaaBackBufferTextures) );
+ GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_msaaBackBufferTextures[0]) );
+ GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, 1, storageFormat, _width, _height) );
+ GL_CHECK(glFramebufferTexture2DMultisampleEXT(
+ GL_FRAMEBUFFER
+ , GL_COLOR_ATTACHMENT0
+ , GL_TEXTURE_2D
+ , m_msaaBackBufferTextures[0]
+ , 0
+ , _msaa
+ ) );
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) );
+
+ GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_msaaBackBufferTextures[1]) );
+ GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH24_STENCIL8, _width, _height) );
+ GL_CHECK(glFramebufferTexture2DMultisampleEXT(
+ GL_FRAMEBUFFER
+ , attachment
+ , GL_TEXTURE_2D
+ , m_msaaBackBufferTextures[1]
+ , 0
+ , _msaa
+ ) );
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
+
+ BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)
+ , "glCheckFramebufferStatus failed 0x%08x"
+ , glCheckFramebufferStatus(GL_FRAMEBUFFER)
+ );
+
+ if (0 == m_msaaBlitProgram)
+ {
+ static const char* msaa_blit_vs =
+ R"(#version 300 es
+ precision highp float;
+ out vec2 UV;
+ void main()
+ {
+ float x = -1.0 + float( (gl_VertexID & 1) << 2);
+ float y = -1.0 + float( (gl_VertexID & 2) << 1);
+ gl_Position = vec4(x, y, 0, 1);
+ UV = vec2(gl_Position.x + 1.0, gl_Position.y + 1.0) * 0.5;
+ }
+ )";
+
+ static const char* msaa_blit_fs =
+ R"(#version 300 es
+ precision mediump float;
+ in vec2 UV;
+ uniform sampler2D msaaTexture;
+ out vec4 oFragColor;
+ void main()
+ {
+ oFragColor = texture(msaaTexture, UV);
+ }
+ )";
+
+ const GLchar *const vs = msaa_blit_vs;
+ const GLchar *const fs = msaa_blit_fs;
+
+ GLuint shader_vs = glCreateShader(GL_VERTEX_SHADER);
+ {
+ BX_WARN(0 != shader_vs, "Failed to create msaa Blit Vertex shader.");
+ GL_CHECK(glShaderSource(shader_vs, 1, &vs, NULL) );
+ GL_CHECK(glCompileShader(shader_vs) );
+
+ GLint compiled = 0;
+ GL_CHECK(glGetShaderiv(shader_vs, GL_COMPILE_STATUS, &compiled) );
+ BX_WARN(0 == shader_vs, "Unable to compile msaa Blit Vertex shader.");
+ }
+
+ GLuint shader_fs = glCreateShader(GL_FRAGMENT_SHADER);
+ {
+ BX_WARN(0 != shader_fs, "Failed to create msaa Blit Fragment shader.");
+ GL_CHECK(glShaderSource(shader_fs, 1, &fs, NULL) );
+ GL_CHECK(glCompileShader(shader_fs) );
+
+ GLint compiled = 0;
+ GL_CHECK(glGetShaderiv(shader_fs, GL_COMPILE_STATUS, &compiled) );
+ BX_WARN(0 == shader_vs, "Unable to compile msaa Blit Fragment shader.");
+ }
+
+ m_msaaBlitProgram = glCreateProgram();
+
+ if (m_msaaBlitProgram)
+ {
+ GL_CHECK(glAttachShader(m_msaaBlitProgram, shader_vs) );
+ GL_CHECK(glAttachShader(m_msaaBlitProgram, shader_fs) );
+ GL_CHECK(glLinkProgram(m_msaaBlitProgram) );
+
+ GLint linked = 0;
+ GL_CHECK(glGetProgramiv(m_msaaBlitProgram, GL_LINK_STATUS, &linked) );
+
+ if (0 == linked)
+ {
+ char log[1024];
+ GL_CHECK(glGetProgramInfoLog(
+ m_msaaBlitProgram
+ , sizeof(log)
+ , NULL
+ , log
+ ) );
+ BX_TRACE("%d: %s", linked, log);
+ }
+
+ GL_CHECK(glDetachShader(m_msaaBlitProgram, shader_vs) );
+ GL_CHECK(glDeleteShader(shader_vs) );
+
+ GL_CHECK(glDetachShader(m_msaaBlitProgram, shader_fs) );
+ GL_CHECK(glDeleteShader(shader_fs) );
+ }
+ }
+ }
+ else
+ {
+ GL_CHECK(glGenRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) );
+
+ GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[0]) );
+ GL_CHECK(glRenderbufferStorageMultisample(
+ GL_RENDERBUFFER
+ , _msaa
+ , storageFormat
+ , _width
+ , _height
+ ) );
+
+ GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[1]) );
+ GL_CHECK(glRenderbufferStorageMultisample(
+ GL_RENDERBUFFER
+ , _msaa
+ , GL_DEPTH24_STENCIL8
+ , _width
+ , _height
+ ) );
+
+ GL_CHECK(glFramebufferRenderbuffer(
+ GL_FRAMEBUFFER
+ , GL_COLOR_ATTACHMENT0
+ , GL_RENDERBUFFER
+ , m_msaaBackBufferRbos[0]
+ ) );
+ GL_CHECK(glFramebufferRenderbuffer(
+ GL_FRAMEBUFFER
+ , attachment
+ , GL_RENDERBUFFER
+ , m_msaaBackBufferRbos[1]
+ ) );
+
+ BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)
+ , "glCheckFramebufferStatus failed 0x%08x"
+ , glCheckFramebufferStatus(GL_FRAMEBUFFER)
+ );
+ }
}
}
@@ -3259,11 +4059,28 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glDeleteFramebuffers(1, &m_msaaBackBufferFbo) );
m_msaaBackBufferFbo = 0;
- if (0 != m_msaaBackBufferRbos[0])
+ if (m_gles3)
{
- GL_CHECK(glDeleteRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) );
- m_msaaBackBufferRbos[0] = 0;
- m_msaaBackBufferRbos[1] = 0;
+ if (0 != m_msaaBackBufferTextures[0])
+ {
+ GL_CHECK(glDeleteTextures(BX_COUNTOF(m_msaaBackBufferTextures), m_msaaBackBufferTextures) );
+ m_msaaBackBufferTextures[0] = 0;
+ m_msaaBackBufferTextures[1] = 0;
+ }
+ if (0 != m_msaaBlitProgram)
+ {
+ GL_CHECK(glDeleteProgram(m_msaaBlitProgram) );
+ m_msaaBlitProgram = 0;
+ }
+ }
+ else
+ {
+ if (0 != m_msaaBackBufferRbos[0])
+ {
+ GL_CHECK(glDeleteRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) );
+ m_msaaBackBufferRbos[0] = 0;
+ m_msaaBackBufferRbos[1] = 0;
+ }
}
}
}
@@ -3277,23 +4094,37 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_msaaBackBufferFbo) );
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
- uint32_t width = m_resolution.width;
- uint32_t height = m_resolution.height;
- GLenum filter = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30)
+
+ const uint32_t width = m_resolution.width;
+ const uint32_t height = m_resolution.height;
+ const GLenum filter = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || !m_gles3
? GL_NEAREST
: GL_LINEAR
;
- GL_CHECK(glBlitFramebuffer(0
- , 0
- , width
- , height
- , 0
- , 0
- , width
- , height
- , GL_COLOR_BUFFER_BIT
- , filter
- ) );
+
+ if (m_gles3)
+ {
+ GL_CHECK(glUseProgram(m_msaaBlitProgram) );
+ GL_CHECK(glActiveTexture(GL_TEXTURE0) );
+ GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_msaaBackBufferTextures[0]) );
+ GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, 3) );
+ }
+ else
+ {
+ GL_CHECK(glBlitFramebuffer(
+ 0
+ , 0
+ , width
+ , height
+ , 0
+ , 0
+ , width
+ , height
+ , GL_COLOR_BUFFER_BIT
+ , filter
+ ) );
+ }
+
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
}
}
@@ -3305,7 +4136,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
if (!m_glctx.isValid() )
{
- m_glctx.create(_width, _height);
+ m_glctx.create(_width, _height, _flags);
#if BX_PLATFORM_IOS
// iOS: need to figure out how to deal with FBO created by context.
@@ -3330,8 +4161,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void invalidateCache()
{
- if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
- && m_samplerObjectSupport)
+ if (m_samplerObjectSupport)
{
m_samplerStateCache.invalidate();
}
@@ -3339,110 +4169,108 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void setSamplerState(uint32_t _stage, uint32_t _numMips, uint32_t _flags, const float _rgba[4])
{
- if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
- && m_samplerObjectSupport)
+ BX_ASSERT(m_samplerObjectSupport, "Cannot use Sampler Objects");
+
+ if (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) )
{
- if (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) )
- {
- const uint32_t index = (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT;
+ const uint32_t index = (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT;
- _flags &= ~BGFX_SAMPLER_RESERVED_MASK;
- _flags &= BGFX_SAMPLER_BITS_MASK;
- _flags |= _numMips<<BGFX_SAMPLER_RESERVED_SHIFT;
+ _flags &= ~BGFX_SAMPLER_RESERVED_MASK;
+ _flags &= BGFX_SAMPLER_BITS_MASK;
+ _flags |= _numMips<<BGFX_SAMPLER_RESERVED_SHIFT;
- GLuint sampler;
+ GLuint sampler;
- bool hasBorderColor = false;
- bx::HashMurmur2A murmur;
- uint32_t hash;
+ bool hasBorderColor = false;
+ bx::HashMurmur2A murmur;
+ uint32_t hash;
- murmur.begin();
- murmur.add(_flags);
- if (!needBorderColor(_flags) )
- {
- murmur.add(-1);
- hash = murmur.end();
+ murmur.begin();
+ murmur.add(_flags);
+ if (!needBorderColor(_flags) )
+ {
+ murmur.add(-1);
+ hash = murmur.end();
- sampler = m_samplerStateCache.find(hash);
+ sampler = m_samplerStateCache.find(hash);
+ }
+ else
+ {
+ murmur.add(index);
+ hash = murmur.end();
+
+ if (NULL != _rgba)
+ {
+ hasBorderColor = true;
+ sampler = UINT32_MAX;
}
else
{
- murmur.add(index);
- hash = murmur.end();
-
- if (NULL != _rgba)
- {
- hasBorderColor = true;
- sampler = UINT32_MAX;
- }
- else
- {
- sampler = m_samplerStateCache.find(hash);
- }
+ sampler = m_samplerStateCache.find(hash);
}
+ }
- if (UINT32_MAX == sampler)
- {
- sampler = m_samplerStateCache.add(hash);
+ if (UINT32_MAX == sampler)
+ {
+ sampler = m_samplerStateCache.add(hash);
- GL_CHECK(glSamplerParameteri(sampler
- , GL_TEXTURE_WRAP_S
- , s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]
- ) );
- GL_CHECK(glSamplerParameteri(sampler
- , GL_TEXTURE_WRAP_T
- , s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]
- ) );
- GL_CHECK(glSamplerParameteri(sampler
- , GL_TEXTURE_WRAP_R
- , s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT]
- ) );
+ GL_CHECK(glSamplerParameteri(sampler
+ , GL_TEXTURE_WRAP_S
+ , s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]
+ ) );
+ GL_CHECK(glSamplerParameteri(sampler
+ , GL_TEXTURE_WRAP_T
+ , s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]
+ ) );
+ GL_CHECK(glSamplerParameteri(sampler
+ , GL_TEXTURE_WRAP_R
+ , s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT]
+ ) );
- GLenum minFilter;
- GLenum magFilter;
- getFilters(_flags, 1 < _numMips, magFilter, minFilter);
- GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, magFilter) );
- GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, minFilter) );
+ GLenum minFilter;
+ GLenum magFilter;
+ getFilters(_flags, 1 < _numMips, magFilter, minFilter);
+ GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, magFilter) );
+ GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, minFilter) );
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
- {
- GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_LOD_BIAS, float(BGFX_CONFIG_MIP_LOD_BIAS) ) );
- }
+ if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
+ {
+ GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_LOD_BIAS, float(BGFX_CONFIG_MIP_LOD_BIAS) ) );
+ }
- if (m_borderColorSupport
- && hasBorderColor)
- {
- GL_CHECK(glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, _rgba) );
- }
+ if (m_borderColorSupport
+ && hasBorderColor)
+ {
+ GL_CHECK(glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, _rgba) );
+ }
- if (0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) )
- && 0.0f < m_maxAnisotropy)
+ if (0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) )
+ && 0.0f < m_maxAnisotropy)
+ {
+ GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_maxAnisotropy) );
+ }
+
+ if (m_gles3
+ || m_shadowSamplersSupport)
+ {
+ const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
+ if (0 == cmpFunc)
{
- GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_maxAnisotropy) );
+ GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE) );
}
-
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
- || m_shadowSamplersSupport)
+ else
{
- const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
- if (0 == cmpFunc)
- {
- GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE) );
- }
- else
- {
- GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE) );
- GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, s_cmpFunc[cmpFunc]) );
- }
+ GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE) );
+ GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, s_cmpFunc[cmpFunc]) );
}
}
-
- GL_CHECK(glBindSampler(_stage, sampler) );
- }
- else
- {
- GL_CHECK(glBindSampler(_stage, 0) );
}
+
+ GL_CHECK(glBindSampler(_stage, sampler) );
+ }
+ else
+ {
+ GL_CHECK(glBindSampler(_stage, 0) );
}
}
@@ -3522,10 +4350,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void* data = BX_ALLOC(g_allocator, length);
if (g_callback->cacheRead(_id, data, length) )
{
+ bx::Error err;
bx::MemoryReader reader(data, length);
GLenum format;
- bx::read(&reader, format);
+ bx::read(&reader, format, &err);
GL_CHECK(glProgramBinary(programId, format, reader.getDataPtr(), (GLsizei)reader.remaining() ) );
}
@@ -3598,36 +4427,51 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
uint32_t loc = _uniformBuffer.read();
-#define CASE_IMPLEMENT_UNIFORM(_uniform, _glsuffix, _dxsuffix, _type) \
- case UniformType::_uniform: \
- { \
- _type* value = (_type*)data; \
- GL_CHECK(glUniform##_glsuffix(loc, num, value) ); \
- } \
- break;
-
-#define CASE_IMPLEMENT_UNIFORM_T(_uniform, _glsuffix, _dxsuffix, _type) \
- case UniformType::_uniform: \
- { \
- _type* value = (_type*)data; \
- GL_CHECK(glUniform##_glsuffix(loc, num, GL_FALSE, value) ); \
- } \
- break;
-
switch (type)
{
-// case ConstantType::Int1:
-// {
-// int* value = (int*)data;
-// BX_TRACE("Int1 sampler %d, loc %d (num %d, copy %d)", *value, loc, num, copy);
-// GL_CHECK(glUniform1iv(loc, num, value) );
-// }
-// break;
+#if BX_PLATFORM_EMSCRIPTEN
+ // For WebAssembly the array forms glUniform1iv/glUniform4fv are much slower compared to glUniform1i/glUniform4f
+ // since they need to marshal an array over from Wasm to JS, so optimize the case when there is exactly one
+ // uniform to upload.
+ case UniformType::Sampler:
+ if (num > 1)
+ {
+ setUniform1iv(loc, num, (int32_t*)data);
+ }
+ else
+ {
+ setUniform1i(loc, *(int32_t*)data);
+ }
+ break;
+
+ case UniformType::Vec4:
+ if (num > 1)
+ {
+ setUniform4fv(loc, num, (float*)data);
+ }
+ else
+ {
+ float* vec4 = (float*)data;
+ setUniform4f(loc, vec4[0], vec4[1], vec4[2], vec4[3]);
+ }
+ break;
+#else
+ case UniformType::Sampler:
+ setUniform1iv(loc, num, (int32_t*)data);
+ break;
+
+ case UniformType::Vec4:
+ setUniform4fv(loc, num, (float*)data);
+ break;
+#endif // BX_PLATFORM_EMSCRIPTEN
- CASE_IMPLEMENT_UNIFORM(Int1, 1iv, I, int);
- CASE_IMPLEMENT_UNIFORM(Vec4, 4fv, F, float);
- CASE_IMPLEMENT_UNIFORM_T(Mat3, Matrix3fv, F, float);
- CASE_IMPLEMENT_UNIFORM_T(Mat4, Matrix4fv, F, float);
+ case UniformType::Mat3:
+ setUniformMatrix3fv(loc, num, GL_FALSE, (float*)data);
+ break;
+
+ case UniformType::Mat4:
+ setUniformMatrix4fv(loc, num, GL_FALSE, (float*)data);
+ break;
case UniformType::End:
break;
@@ -3636,10 +4480,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
break;
}
-
-#undef CASE_IMPLEMENT_UNIFORM
-#undef CASE_IMPLEMENT_UNIFORM_T
-
}
}
@@ -3739,57 +4579,46 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glDisable(GL_STENCIL_TEST) );
}
- VertexBufferGL& vb = m_vertexBuffers[_clearQuad.m_vb->handle.idx];
- VertexDecl& vertexDecl = m_vertexDecls[_clearQuad.m_vb->decl.idx];
-
- {
- struct Vertex
- {
- float m_x;
- float m_y;
- float m_z;
- };
-
- Vertex* vertex = (Vertex*)_clearQuad.m_vb->data;
- BX_CHECK(vertexDecl.m_stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", vertexDecl.m_stride, sizeof(Vertex) );
-
- const float depth = _clear.m_depth * 2.0f - 1.0f;
-
- vertex->m_x = -1.0f;
- vertex->m_y = -1.0f;
- vertex->m_z = depth;
- vertex++;
- vertex->m_x = 1.0f;
- vertex->m_y = -1.0f;
- vertex->m_z = depth;
- vertex++;
- vertex->m_x = -1.0f;
- vertex->m_y = 1.0f;
- vertex->m_z = depth;
- vertex++;
- vertex->m_x = 1.0f;
- vertex->m_y = 1.0f;
- vertex->m_z = depth;
- }
-
- vb.update(0, 4*_clearQuad.m_decl.m_stride, _clearQuad.m_vb->data);
+ VertexBufferGL& vb = m_vertexBuffers[_clearQuad.m_vb.idx];
+ VertexLayout& layout = _clearQuad.m_layout;
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
ProgramGL& program = m_program[_clearQuad.m_program[numMrt-1].idx];
- GL_CHECK(glUseProgram(program.m_id) );
+ setProgram(program.m_id);
program.bindAttributesBegin();
- program.bindAttributes(vertexDecl, 0);
+ program.bindAttributes(layout, 0);
program.bindAttributesEnd();
- float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4];
+ if (m_clearQuadColor.idx == kInvalidHandle)
+ {
+ const UniformRegInfo* infoClearColor = m_uniformReg.find("bgfx_clear_color");
+ if (NULL != infoClearColor)
+ {
+ m_clearQuadColor = infoClearColor->m_handle;
+ }
+ }
+
+ if (m_clearQuadDepth.idx == kInvalidHandle)
+ {
+ const UniformRegInfo* infoClearDepth = m_uniformReg.find("bgfx_clear_depth");
+ if (NULL != infoClearDepth)
+ {
+ m_clearQuadDepth = infoClearDepth->m_handle;
+ }
+ }
+
+ float mrtClearDepth[4] = { g_caps.homogeneousDepth ? (_clear.m_depth * 2.0f - 1.0f) : _clear.m_depth };
+ updateUniform(m_clearQuadDepth.idx, mrtClearDepth, sizeof(float)*4);
+
+ float mrtClearColor[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4];
if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags)
{
for (uint32_t ii = 0; ii < numMrt; ++ii)
{
uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]);
- bx::memCopy(mrtClear[ii], _palette[index], 16);
+ bx::memCopy(mrtClearColor[ii], _palette[index], 16);
}
}
else
@@ -3804,11 +4633,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
for (uint32_t ii = 0; ii < numMrt; ++ii)
{
- bx::memCopy(mrtClear[ii], rgba, 16);
+ bx::memCopy(mrtClearColor[ii], rgba, 16);
}
}
- GL_CHECK(glUniform4fv(0, numMrt, mrtClear[0]) );
+ updateUniform(m_clearQuadColor.idx, mrtClearColor[0], numMrt * sizeof(float) * 4);
+
+ commit(*program.m_constantBuffer);
GL_CHECK(glDrawArrays(GL_TRIANGLE_STRIP
, 0
@@ -3817,6 +4648,95 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
+ void setProgram(GLuint program)
+ {
+ m_uniformStateCache.saveCurrentProgram(program);
+ GL_CHECK(glUseProgram(program) );
+ }
+
+ // Cache uniform uploads to avoid redundant uploading of state that is
+ // already set to a shader program
+ void setUniform1i(uint32_t loc, int value)
+ {
+ if (m_uniformStateCache.updateUniformCache(loc, value) )
+ {
+ GL_CHECK(glUniform1i(loc, value) );
+ }
+ }
+
+ void setUniform1iv(uint32_t loc, int num, const int *data)
+ {
+ bool changed = false;
+ for(int i = 0; i < num; ++i)
+ {
+ if (m_uniformStateCache.updateUniformCache(loc+i, data[i]) )
+ {
+ changed = true;
+ }
+ }
+ if (changed)
+ {
+ GL_CHECK(glUniform1iv(loc, num, data) );
+ }
+ }
+
+ void setUniform4f(uint32_t loc, float x, float y, float z, float w)
+ {
+ UniformStateCache::f4 f; f.val[0] = x; f.val[1] = y; f.val[2] = z; f.val[3] = w;
+ if (m_uniformStateCache.updateUniformCache(loc, f) )
+ {
+ GL_CHECK(glUniform4f(loc, x, y, z, w) );
+ }
+ }
+
+ void setUniform4fv(uint32_t loc, int num, const float *data)
+ {
+ bool changed = false;
+ for(int i = 0; i < num; ++i)
+ {
+ if (m_uniformStateCache.updateUniformCache(loc+i, *(const UniformStateCache::f4*)&data[4*i]) )
+ {
+ changed = true;
+ }
+ }
+ if (changed)
+ {
+ GL_CHECK(glUniform4fv(loc, num, data) );
+ }
+ }
+
+ void setUniformMatrix3fv(uint32_t loc, int num, GLboolean transpose, const float *data)
+ {
+ bool changed = false;
+ for(int i = 0; i < num; ++i)
+ {
+ if (m_uniformStateCache.updateUniformCache(loc+i, *(const UniformStateCache::f3x3*)&data[9*i]) )
+ {
+ changed = true;
+ }
+ }
+ if (changed)
+ {
+ GL_CHECK(glUniformMatrix3fv(loc, num, transpose, data) );
+ }
+ }
+
+ void setUniformMatrix4fv(uint32_t loc, int num, GLboolean transpose, const float *data)
+ {
+ bool changed = false;
+ for(int i = 0; i < num; ++i)
+ {
+ if (m_uniformStateCache.updateUniformCache(loc+i, *(const UniformStateCache::f4x4*)&data[16*i]) )
+ {
+ changed = true;
+ }
+ }
+ if (changed)
+ {
+ GL_CHECK(glUniformMatrix4fv(loc, num, transpose, data) );
+ }
+ }
+
void* m_renderdocdll;
uint16_t m_numWindows;
@@ -3827,7 +4747,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
ShaderGL m_shaders[BGFX_CONFIG_MAX_SHADERS];
ProgramGL m_program[BGFX_CONFIG_MAX_PROGRAMS];
TextureGL m_textures[BGFX_CONFIG_MAX_TEXTURES];
- VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS];
+ VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS];
FrameBufferGL m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS];
UniformRegistry m_uniformReg;
void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS];
@@ -3836,6 +4756,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
OcclusionQueryGL m_occlusionQuery;
SamplerStateCache m_samplerStateCache;
+ UniformStateCache m_uniformStateCache;
TextVideoMem m_textVideoMem;
bool m_rtMsaa;
@@ -3850,6 +4771,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
float m_maxAnisotropyDefault;
int32_t m_maxMsaa;
GLuint m_vao;
+ uint16_t m_maxLabelLen;
bool m_blitSupported;
bool m_readBackSupported;
bool m_vaoSupport;
@@ -3864,6 +4786,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bool m_occlusionQuerySupport;
bool m_atocSupport;
bool m_conservativeRasterSupport;
+ bool m_imageLoadStoreSupport;
bool m_flip;
uint64_t m_hash;
@@ -3871,14 +4794,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GLenum m_readPixelsFmt;
GLuint m_backBufferFbo;
GLuint m_msaaBackBufferFbo;
- GLuint m_msaaBackBufferRbos[2];
+ union {
+ GLuint m_msaaBackBufferRbos[2];
+ GLuint m_msaaBackBufferTextures[2];
+ };
+ GLuint m_msaaBlitProgram;
GlContext m_glctx;
bool m_needPresent;
+ UniformHandle m_clearQuadColor;
+ UniformHandle m_clearQuadDepth;
+
const char* m_vendor;
const char* m_renderer;
const char* m_version;
const char* m_glslVersion;
+ bool m_gles3;
Workaround m_workaround;
@@ -3908,7 +4839,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
static void frameBufferValidate()
{
GLenum complete = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- BX_CHECK(GL_FRAMEBUFFER_COMPLETE == complete
+ BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == complete
, "glCheckFramebufferStatus failed 0x%08x: %s"
, complete
, glEnumName(complete)
@@ -3982,7 +4913,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
#undef GLSL_TYPE
- BX_CHECK(false, "Unknown GLSL type? %x", _type);
+ BX_ASSERT(false, "Unknown GLSL type? %x", _type);
return "UNKNOWN GLSL TYPE!";
}
@@ -4020,7 +4951,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
case GL_INT:
case GL_UNSIGNED_INT:
- return UniformType::Int1;
+ return UniformType::Sampler;
case GL_FLOAT:
case GL_FLOAT_VEC2:
@@ -4076,10 +5007,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
case GL_IMAGE_CUBE:
case GL_INT_IMAGE_CUBE:
case GL_UNSIGNED_INT_IMAGE_CUBE:
- return UniformType::Int1;
+ return UniformType::Sampler;
};
- BX_CHECK(false, "Unrecognized GL type 0x%04x.", _type);
+ BX_ASSERT(false, "Unrecognized GL type 0x%04x.", _type);
return UniformType::End;
}
@@ -4153,7 +5084,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 != m_id)
{
- GL_CHECK(glUseProgram(0) );
+ s_renderGL->setProgram(0);
GL_CHECK(glDeleteProgram(m_id) );
m_id = 0;
}
@@ -4442,27 +5373,36 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_used[used++] = ii;
}
}
- BX_CHECK(used < BX_COUNTOF(m_used), "Out of bounds %d > array size %d.", used, Attrib::Count);
+ BX_ASSERT(used < BX_COUNTOF(m_used), "Out of bounds %d > array size %d.", used, Attrib::Count);
m_usedCount = (uint8_t)used;
used = 0;
- for (uint32_t ii = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii)
+ for (uint32_t ii = 0, baseVertex = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii, baseVertex += 16)
{
- GLuint loc = glGetAttribLocation(m_id, s_instanceDataName[ii]);
- if (GLuint(-1) != loc )
+ GLint loc = glGetAttribLocation(m_id, s_instanceDataName[ii]);
+ if (-1 != loc)
{
BX_TRACE("instance data %s: %d", s_instanceDataName[ii], loc);
- m_instanceData[used++] = loc;
+ m_instanceData[used] = loc;
+ m_instanceOffset[used] = uint16_t(baseVertex);
+
+ used++;
}
}
- BX_CHECK(used < BX_COUNTOF(m_instanceData), "Out of bounds %d > array size %d."
- , used
- , BX_COUNTOF(m_instanceData)
- );
- m_instanceData[used] = 0xffff;
+ BX_ASSERT(used < BX_COUNTOF(m_instanceData)
+ , "Out of bounds %d > array size %d."
+ , used
+ , BX_COUNTOF(m_instanceData)
+ );
+ m_instanceData[used] = -1;
+ }
+
+ void ProgramGL::bindAttributesBegin()
+ {
+ bx::memCopy(m_unboundUsedAttrib, m_used, sizeof(m_unboundUsedAttrib) );
}
- void ProgramGL::bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex)
+ void ProgramGL::bindAttributes(const VertexLayout& _layout, uint32_t _baseVertex)
{
for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii)
{
@@ -4473,24 +5413,24 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
AttribType::Enum type;
bool normalized;
bool asInt;
- _vertexDecl.decode(attr, num, type, normalized, asInt);
+ _layout.decode(attr, num, type, normalized, asInt);
if (-1 != loc)
{
- if (UINT16_MAX != _vertexDecl.m_attributes[attr])
+ if (UINT16_MAX != _layout.m_attributes[attr])
{
- GL_CHECK(glEnableVertexAttribArray(loc) );
+ lazyEnableVertexAttribArray(loc);
GL_CHECK(glVertexAttribDivisor(loc, 0) );
- uint32_t baseVertex = _baseVertex*_vertexDecl.m_stride + _vertexDecl.m_offset[attr];
- if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 31) )
- && (AttribType::Uint8 == type || AttribType::Int16 == type)
+ uint32_t baseVertex = _baseVertex*_layout.m_stride + _layout.m_offset[attr];
+ if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || s_renderGL->m_gles3)
+ && !isFloat(type)
&& !normalized)
{
GL_CHECK(glVertexAttribIPointer(loc
, num
, s_attribType[type]
- , _vertexDecl.m_stride
+ , _layout.m_stride
, (void*)(uintptr_t)baseVertex)
);
}
@@ -4500,7 +5440,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, num
, s_attribType[type]
, normalized
- , _vertexDecl.m_stride
+ , _layout.m_stride
, (void*)(uintptr_t)baseVertex)
);
}
@@ -4511,38 +5451,53 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
- void ProgramGL::unbindAttributes()
+ void ProgramGL::bindInstanceData(uint32_t _stride, uint32_t _baseVertex) const
{
- for(uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii)
+ for (uint32_t ii = 0; -1 != m_instanceData[ii]; ++ii)
+ {
+ GLint loc = m_instanceData[ii];
+ lazyEnableVertexAttribArray(loc);
+
+ const uint32_t baseVertex = _baseVertex + m_instanceOffset[ii];
+ GL_CHECK(glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, _stride, (void*)(uintptr_t)baseVertex) );
+ GL_CHECK(glVertexAttribDivisor(loc, 1) );
+ }
+ }
+
+ void ProgramGL::bindAttributesEnd()
+ {
+ for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii)
{
- if(Attrib::Count == m_unboundUsedAttrib[ii])
+ if (Attrib::Count != m_unboundUsedAttrib[ii])
{
- Attrib::Enum attr = Attrib::Enum(m_used[ii]);
+ Attrib::Enum attr = Attrib::Enum(m_unboundUsedAttrib[ii]);
GLint loc = m_attributes[attr];
- GL_CHECK(glDisableVertexAttribArray(loc));
+ lazyDisableVertexAttribArray(loc);
}
}
+
+ applyLazyEnabledVertexAttributes();
}
- void ProgramGL::bindInstanceData(uint32_t _stride, uint32_t _baseVertex) const
+ void ProgramGL::unbindAttributes()
{
- uint32_t baseVertex = _baseVertex;
- for (uint32_t ii = 0; 0xffff != m_instanceData[ii]; ++ii)
+ for(uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii)
{
- GLint loc = m_instanceData[ii];
- GL_CHECK(glEnableVertexAttribArray(loc) );
- GL_CHECK(glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, _stride, (void*)(uintptr_t)baseVertex) );
- GL_CHECK(glVertexAttribDivisor(loc, 1) );
- baseVertex += 16;
+ if (Attrib::Count == m_unboundUsedAttrib[ii])
+ {
+ Attrib::Enum attr = Attrib::Enum(m_used[ii]);
+ GLint loc = m_attributes[attr];
+ lazyDisableVertexAttribArray(loc);
+ }
}
}
void ProgramGL::unbindInstanceData() const
{
- for(uint32_t ii = 0; 0xffff != m_instanceData[ii]; ++ii)
+ for(uint32_t ii = 0; -1 != m_instanceData[ii]; ++ii)
{
GLint loc = m_instanceData[ii];
- GL_CHECK(glDisableVertexAttribArray(loc));
+ lazyDisableVertexAttribArray(loc);
}
}
@@ -4554,7 +5509,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void VertexBufferGL::destroy()
{
- GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
+ GL_CHECK(glBindBuffer(m_target, 0) );
GL_CHECK(glDeleteBuffers(1, &m_id) );
}
@@ -4571,20 +5526,28 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
const bool writeOnly = 0 != (m_flags&BGFX_TEXTURE_RT_WRITE_ONLY);
const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE );
const bool srgb = 0 != (m_flags&BGFX_TEXTURE_SRGB);
+ const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK);
const bool textureArray = false
|| _target == GL_TEXTURE_2D_ARRAY
|| _target == GL_TEXTURE_CUBE_MAP_ARRAY
;
- if (!writeOnly)
+ if (!writeOnly
+ || (renderTarget && textureArray) )
{
GL_CHECK(glGenTextures(1, &m_id) );
- BX_CHECK(0 != m_id, "Failed to generate texture id.");
+ BX_ASSERT(0 != m_id, "Failed to generate texture id.");
GL_CHECK(glBindTexture(_target, m_id) );
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) );
const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat];
- m_fmt = tfi.m_fmt;
+
+ const GLenum fmt = srgb
+ ? s_textureFormat[m_textureFormat].m_fmtSrgb
+ : s_textureFormat[m_textureFormat].m_fmt
+ ;
+
+ m_fmt = fmt;
m_type = tfi.m_type;
const bool swizzle = true
@@ -4655,8 +5618,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
- const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK);
-
if (renderTarget)
{
uint32_t msaaQuality = ( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT);
@@ -4665,10 +5626,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
const bool msaaSample = 0 != (m_flags&BGFX_TEXTURE_MSAA_SAMPLE);
if (!msaaSample
- && (0 != msaaQuality || writeOnly) )
+ && (0 != msaaQuality || writeOnly)
+ && !textureArray)
{
GL_CHECK(glGenRenderbuffers(1, &m_rbo) );
- BX_CHECK(0 != m_rbo, "Failed to generate renderbuffer id.");
+ BX_ASSERT(0 != m_rbo, "Failed to generate renderbuffer id.");
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_rbo) );
if (0 == msaaQuality)
@@ -4679,7 +5641,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, _height
) );
}
- else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3)
{
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER
, msaaQuality
@@ -4709,22 +5671,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (bimg::imageParse(imageContainer, _mem->data, _mem->size) )
{
- uint8_t numMips = imageContainer.m_numMips;
- const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) );
- numMips -= startLod;
- const uint16_t numLayers = imageContainer.m_numLayers;
- uint32_t textureWidth;
- uint32_t textureHeight;
- uint32_t textureDepth;
- {
- const bimg::ImageBlockInfo& ibi = bimg::getBlockInfo(bimg::TextureFormat::Enum(imageContainer.m_format) );
- textureWidth = bx::uint32_max(ibi.blockWidth, imageContainer.m_width >>startLod);
- textureHeight = bx::uint32_max(ibi.blockHeight, imageContainer.m_height>>startLod);
- textureDepth = 1 < imageContainer.m_depth
- ? imageContainer.m_depth
- : imageContainer.m_numLayers
- ;
- }
+ const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1);
+
+ bimg::TextureInfo ti;
+ bimg::imageGetSize(
+ &ti
+ , uint16_t(imageContainer.m_width >>startLod)
+ , uint16_t(imageContainer.m_height>>startLod)
+ , uint16_t(imageContainer.m_depth >>startLod)
+ , imageContainer.m_cubeMap
+ , 1 < imageContainer.m_numMips
+ , imageContainer.m_numLayers
+ , imageContainer.m_format
+ );
+ ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips);
m_requestedFormat = uint8_t(imageContainer.m_format);
m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) );
@@ -4746,7 +5706,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
target = GL_TEXTURE_3D;
}
- const bool textureArray = 1 < numLayers;
+ const bool textureArray = 1 < ti.numLayers;
if (textureArray)
{
switch (target)
@@ -4758,16 +5718,18 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
if (!init(target
- , textureWidth
- , textureHeight
- , textureDepth
- , numMips
- , _flags
- ) )
+ , ti.width
+ , ti.height
+ , textureArray ? ti.numLayers : ti.depth
+ , ti.numMips
+ , _flags
+ ) )
{
return;
}
+ m_numLayers = ti.numLayers;
+
target = isCubeMap()
? GL_TEXTURE_CUBE_MAP_POSITIVE_X
: m_target
@@ -4777,6 +5739,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
? s_textureFormat[m_textureFormat].m_internalFmtSrgb
: s_textureFormat[m_textureFormat].m_internalFmt
;
+ const GLenum fmt = srgb
+ ? s_textureFormat[m_textureFormat].m_fmtSrgb
+ : s_textureFormat[m_textureFormat].m_fmt
+ ;
const bool swizzle = true
&& TextureFormat::BGRA8 == m_requestedFormat
@@ -4795,9 +5761,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, getName( (TextureFormat::Enum)m_textureFormat)
, srgb ? "+sRGB " : ""
, getName( (TextureFormat::Enum)m_requestedFormat)
- , numLayers
- , textureWidth
- , textureHeight
+ , ti.numLayers
+ , ti.width
+ , ti.height
, imageContainer.m_cubeMap ? 6 : (1 < imageContainer.m_depth ? imageContainer.m_depth : 0)
, 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : ""
);
@@ -4813,22 +5779,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
uint8_t* temp = NULL;
if (convert)
{
- temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4);
+ temp = (uint8_t*)BX_ALLOC(g_allocator, ti.width*ti.height*4);
}
- const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1);
+ const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1);
for (uint16_t side = 0; side < numSides; ++side)
{
- uint32_t width = textureWidth;
- uint32_t height = textureHeight;
- uint32_t depth = imageContainer.m_depth;
+ uint32_t width = ti.width;
+ uint32_t height = ti.height;
+ uint32_t depth = ti.depth;
GLenum imageTarget = imageContainer.m_cubeMap && !textureArray
? target+side
: target
;
- for (uint8_t lod = 0, num = numMips; lod < num; ++lod)
+ for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod)
{
width = bx::uint32_max(1, width);
height = bx::uint32_max(1, height);
@@ -4880,7 +5846,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, height
, depth
, 0
- , m_fmt
+ , fmt
, m_type
, data
) );
@@ -4888,10 +5854,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
else if (!computeWrite)
{
- if (compressed)
+ if (compressed
+ && !convert)
{
- uint32_t size = bx::uint32_max(1, (width + 3)>>2)
- * bx::uint32_max(1, (height + 3)>>2)
+ uint32_t size = bx::max<uint32_t>(1, (width + 3)>>2)
+ * bx::max<uint32_t>(1, (height + 3)>>2)
* 4*4* bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) )/8
;
@@ -4916,7 +5883,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, height
, depth
, 0
- , m_fmt
+ , fmt
, m_type
, NULL
) );
@@ -4929,6 +5896,23 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
+ GLint mapping[4] = {
+ s_textureFormat[m_textureFormat].m_mapping[0],
+ s_textureFormat[m_textureFormat].m_mapping[1],
+ s_textureFormat[m_textureFormat].m_mapping[2],
+ s_textureFormat[m_textureFormat].m_mapping[3],
+ };
+ if (s_renderGL->m_textureSwizzleSupport
+ && (-1 != mapping[0] || -1 != mapping[1] || -1 != mapping[2] || -1 != mapping[3]) )
+ {
+ mapping[0] = -1 == mapping[0] ? GL_RED : mapping[0];
+ mapping[1] = -1 == mapping[1] ? GL_GREEN : mapping[1];
+ mapping[2] = -1 == mapping[2] ? GL_BLUE : mapping[2];
+ mapping[3] = -1 == mapping[3] ? GL_ALPHA : mapping[3];
+
+ GL_CHECK(glTexParameteriv(m_target, GL_TEXTURE_SWIZZLE_RGBA, mapping));
+ }
+
if (NULL != temp)
{
BX_FREE(g_allocator, temp);
@@ -4988,8 +5972,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|| swizzle
;
- const uint32_t width = _rect.m_width;
- const uint32_t height = _rect.m_height;
+ Rect rect;
+ rect.setIntersect(_rect
+ , {
+ 0, 0,
+ uint16_t(bx::max(1u, m_width >> _mip) ),
+ uint16_t(bx::max(1u, m_height >> _mip) ),
+ });
+
+ uint32_t width = rect.m_width;
+ uint32_t height = rect.m_height;
uint8_t* temp = NULL;
if (convert
@@ -5002,7 +5994,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glPixelStorei(GL_UNPACK_ROW_LENGTH, srcpitch*8/bpp) );
}
- if (compressed)
+ if (compressed
+ && !convert)
{
const uint8_t* data = _mem->data;
@@ -5011,16 +6004,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bimg::imageCopy(temp, width, height, 1, bpp, srcpitch, data);
data = temp;
}
-
+ const GLenum internalFmt = (0 != (m_flags & BGFX_TEXTURE_SRGB) )
+ ? s_textureFormat[m_textureFormat].m_internalFmtSrgb
+ : s_textureFormat[m_textureFormat].m_internalFmt
+ ;
GL_CHECK(compressedTexSubImage(target+_side
, _mip
- , _rect.m_x
- , _rect.m_y
+ , rect.m_x
+ , rect.m_y
, _z
- , _rect.m_width
- , _rect.m_height
+ , rect.m_width
+ , rect.m_height
, _depth
- , m_fmt
+ , internalFmt
, _mem->size
, data
) );
@@ -5046,11 +6042,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(texSubImage(target+_side
, _mip
- , _rect.m_x
- , _rect.m_y
+ , rect.m_x
+ , rect.m_y
, _z
- , _rect.m_width
- , _rect.m_height
+ , rect.m_width
+ , rect.m_height
, _depth
, m_fmt
, m_type
@@ -5072,7 +6068,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void TextureGL::setSamplerState(uint32_t _flags, const float _rgba[4])
{
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30)
+ if (!s_renderGL->m_gles3
&& !s_textureFilter[m_textureFormat])
{
// Force point sampling when texture format doesn't support linear sampling.
@@ -5115,7 +6111,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glTexParameteri(target, GL_TEXTURE_WRAP_S, s_textureAddress[(flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]) );
GL_CHECK(glTexParameteri(target, GL_TEXTURE_WRAP_T, s_textureAddress[(flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]) );
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3
|| s_extension[Extension::APPLE_texture_max_level].m_supported)
{
GL_CHECK(glTexParameteri(targetMsaa, GL_TEXTURE_MAX_LEVEL, numMips-1) );
@@ -5149,7 +6145,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, s_renderGL->m_maxAnisotropy) );
}
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
+ if (s_renderGL->m_gles3
|| s_renderGL->m_shadowSamplersSupport)
{
const uint32_t cmpFunc = (flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
@@ -5179,29 +6175,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glActiveTexture(GL_TEXTURE0+_stage) );
GL_CHECK(glBindTexture(m_target, m_id) );
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES)
- && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) )
+ if (s_renderGL->m_samplerObjectSupport)
{
- // GLES2 doesn't have support for sampler object.
- setSamplerState(flags, _palette[index]);
- }
- else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
- && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL < 31) )
- {
- // In case that GL 2.1 sampler object is supported via extension.
- if (s_renderGL->m_samplerObjectSupport)
- {
- s_renderGL->setSamplerState(_stage, m_numMips, flags, _palette[index]);
- }
- else
- {
- setSamplerState(flags, _palette[index]);
- }
+ s_renderGL->setSamplerState(_stage, m_numMips, flags, _palette[index]);
}
else
{
- // Everything else has sampler object.
- s_renderGL->setSamplerState(_stage, m_numMips, flags, _palette[index]);
+ setSamplerState(flags, _palette[index]);
}
}
@@ -5230,8 +6210,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::MemoryReader reader(_mem->data, _mem->size);
m_hash = bx::hash<bx::HashMurmur2A>(_mem->data, _mem->size);
+ bx::ErrorAssert err;
+
uint32_t magic;
- bx::read(&reader, magic);
+ bx::read(&reader, magic, &err);
if (isShaderType(magic, 'C') )
{
@@ -5247,7 +6229,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
uint32_t hashIn;
- bx::read(&reader, hashIn);
+ bx::read(&reader, hashIn, &err);
uint32_t hashOut;
@@ -5257,11 +6239,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
else
{
- bx::read(&reader, hashOut);
+ bx::read(&reader, hashOut, &err);
}
uint16_t count;
- bx::read(&reader, count);
+ bx::read(&reader, count, &err);
BX_TRACE("%s Shader consts %d"
, getShaderTypeName(magic)
@@ -5271,27 +6253,39 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
for (uint32_t ii = 0; ii < count; ++ii)
{
uint8_t nameSize = 0;
- bx::read(&reader, nameSize);
+ bx::read(&reader, nameSize, &err);
char name[256];
- bx::read(&reader, &name, nameSize);
+ bx::read(&reader, &name, nameSize, &err);
name[nameSize] = '\0';
uint8_t type;
- bx::read(&reader, type);
+ bx::read(&reader, type, &err);
uint8_t num;
- bx::read(&reader, num);
+ bx::read(&reader, num, &err);
uint16_t regIndex;
- bx::read(&reader, regIndex);
+ bx::read(&reader, regIndex, &err);
uint16_t regCount;
- bx::read(&reader, regCount);
+ bx::read(&reader, regCount, &err);
+
+ if (!isShaderVerLess(magic, 8) )
+ {
+ uint16_t texInfo = 0;
+ bx::read(&reader, texInfo, &err);
+ }
+
+ if (!isShaderVerLess(magic, 10) )
+ {
+ uint16_t texFormat = 0;
+ bx::read(&reader, texFormat, &err);
+ }
}
uint32_t shaderSize;
- bx::read(&reader, shaderSize);
+ bx::read(&reader, shaderSize, &err);
m_id = glCreateShader(m_type);
BX_WARN(0 != m_id, "Failed to create shader.");
@@ -5301,22 +6295,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 != m_id)
{
if (GL_COMPUTE_SHADER != m_type
- && 0 != bx::strCmp(code, "#version 430", 12) )
+ && 0 != bx::strCmp(code, "#version", 8) ) // #2000
{
int32_t tempLen = code.getLength() + (4<<10);
char* temp = (char*)alloca(tempLen);
bx::StaticMemoryBlockWriter writer(temp, tempLen);
- bx::Error err;
-
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES)
- && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) )
+ && !s_renderGL->m_gles3)
{
bx::write(&writer
, "#define centroid\n"
"#define flat\n"
"#define noperspective\n"
"#define smooth\n"
+ , &err
);
bool usesDerivatives = s_extension[Extension::OES_standard_derivatives].m_supported
@@ -5336,7 +6329,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (usesDerivatives)
{
- bx::write(&writer, "#extension GL_OES_standard_derivatives : enable\n");
+ bx::write(&writer, "#extension GL_OES_standard_derivatives : enable\n", &err);
}
if (usesFragData)
@@ -5345,7 +6338,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|| s_extension[Extension::WEBGL_draw_buffers].m_supported
, "EXT_draw_buffers is used but not supported by GLES2 driver."
);
- bx::write(&writer, "#extension GL_EXT_draw_buffers : enable\n");
+ bx::write(&writer, "#extension GL_EXT_draw_buffers : enable\n", &err);
}
bool insertFragDepth = false;
@@ -5357,13 +6350,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::write(&writer
, "#extension GL_EXT_frag_depth : enable\n"
"#define bgfx_FragDepth gl_FragDepthEXT\n"
+ , &err
);
char str[128];
bx::snprintf(str, BX_COUNTOF(str), "%s float gl_FragDepthEXT;\n"
, s_extension[Extension::OES_fragment_precision_high].m_supported ? "highp" : "mediump"
);
- bx::write(&writer, str);
+ bx::write(&writer, str, &err);
}
else
{
@@ -5379,6 +6373,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, "#extension GL_EXT_shadow_samplers : enable\n"
"#define shadow2D shadow2DEXT\n"
"#define shadow2DProj shadow2DProjEXT\n"
+ , &err
);
}
else
@@ -5387,13 +6382,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, "#define sampler2DShadow sampler2D\n"
"#define shadow2D(_sampler, _coord) step(_coord.z, texture2D(_sampler, _coord.xy).x)\n"
"#define shadow2DProj(_sampler, _coord) step(_coord.z/_coord.w, texture2DProj(_sampler, _coord).x)\n"
+ , &err
);
}
}
if (usesTexture3D)
{
- bx::write(&writer, "#extension GL_OES_texture_3D : enable\n");
+ bx::write(&writer, "#extension GL_OES_texture_3D : enable\n", &err);
}
if (usesTextureLod)
@@ -5413,17 +6409,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
"#define texture2DGrad texture2DGradARB\n"
"#define texture2DProjGrad texture2DProjGradARB\n"
"#define textureCubeGrad textureCubeGradARB\n"
+ , &err
);
}
else
{
- if(s_extension[Extension::EXT_shader_texture_lod].m_supported)
+ if (s_extension[Extension::EXT_shader_texture_lod].m_supported)
{
bx::write(&writer
, "#extension GL_EXT_shader_texture_lod : enable\n"
"#define texture2DLod texture2DLodEXT\n"
"#define texture2DProjLod texture2DProjLodEXT\n"
"#define textureCubeLod textureCubeLodEXT\n"
+ , &err
);
}
else
@@ -5432,6 +6430,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, "#define texture2DLod(_sampler, _coord, _level) texture2D(_sampler, _coord)\n"
"#define texture2DProjLod(_sampler, _coord, _level) texture2DProj(_sampler, _coord)\n"
"#define textureCubeLod(_sampler, _coord, _level) textureCube(_sampler, _coord)\n"
+ , &err
);
}
}
@@ -5441,11 +6440,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
if (s_extension[Extension::INTEL_fragment_shader_ordering].m_supported)
{
- bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n");
+ bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n", &err);
}
else
{
- bx::write(&writer, "#define beginFragmentShaderOrdering()\n");
+ bx::write(&writer, "#define beginFragmentShaderOrdering()\n", &err);
}
}
@@ -5453,8 +6452,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, m_type == GL_FRAGMENT_SHADER ? "mediump" : "highp"
);
- bx::write(&writer, code);
- bx::write(&writer, '\0');
+ bx::write(&writer, code, &err);
+ bx::write(&writer, '\0', &err);
if (insertFragDepth)
{
@@ -5478,7 +6477,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
// Replace all instances of gl_FragDepth with bgfx_FragDepth.
for (bx::StringView fragDepth = bx::findIdentifierMatch(temp, "gl_FragDepth")
; !fragDepth.isEmpty()
- ; fragDepth = bx::findIdentifierMatch(fragDepth, "gl_FragDepth")
+ ; fragDepth = bx::findIdentifierMatch(fragDepth.getPtr(), "gl_FragDepth")
)
{
char* insert = const_cast<char*>(fragDepth.getPtr() );
@@ -5493,8 +6492,33 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
&& s_extension[Extension::ARB_shader_texture_lod].m_supported
&& !bx::findIdentifierMatch(code, s_ARB_shader_texture_lod).isEmpty()
;
- const bool usesGpuShader4 = !bx::findIdentifierMatch(code, s_EXT_gpu_shader4).isEmpty();
- const bool usesGpuShader5 = !bx::findIdentifierMatch(code, s_ARB_gpu_shader5).isEmpty();
+
+ const bool usesVertexID = true
+ && !s_extension[Extension::EXT_gpu_shader4].m_supported
+ && !bx::findIdentifierMatch(code, "gl_VertexID").isEmpty()
+ ;
+
+ const bool usesInstanceID = true
+ && !s_extension[Extension::EXT_gpu_shader4].m_supported
+ && !bx::findIdentifierMatch(code, "gl_InstanceID").isEmpty()
+ ;
+
+ const bool usesGpuShader4 = true
+ && s_extension[Extension::EXT_gpu_shader4].m_supported
+ && !bx::findIdentifierMatch(code, s_EXT_gpu_shader4).isEmpty()
+ ;
+
+ // GpuShader5 extension is not supported on the fragment shader!
+ const bool usesGpuShader5 = true
+ && m_type != GL_FRAGMENT_SHADER
+ && !bx::findIdentifierMatch(code, s_ARB_gpu_shader5).isEmpty()
+ ;
+
+ const bool usesViewportLayerArray = true
+ && s_extension[Extension::ARB_shader_viewport_layer_array].m_supported
+ && !bx::findIdentifierMatch(code, s_ARB_shader_viewport_layer_array).isEmpty()
+ ;
+
const bool usesIUsamplers = !bx::findIdentifierMatch(code, s_uisamplers).isEmpty();
const bool usesUint = !bx::findIdentifierMatch(code, s_uint).isEmpty();
const bool usesTexelFetch = !bx::findIdentifierMatch(code, s_texelFetch).isEmpty();
@@ -5508,6 +6532,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
: usesTextureArray
|| usesTexture3D
|| usesIUsamplers
+ || usesVertexID
|| usesUint
|| usesTexelFetch
|| usesGpuShader5
@@ -5516,12 +6541,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
: 120
;
- if (0 != version)
- {
- bx::write(&writer, &err, "#version %d\n", version);
- }
+ version = 0 == bx::strCmp(code, "#version 430", 12) ? 430 : version;
- if (usesTextureLod)
+ bx::write(&writer, &err, "#version %d\n", version);
+
+ if (430 > version && usesTextureLod)
{
if (m_type == GL_FRAGMENT_SHADER)
{
@@ -5530,68 +6554,83 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
"#define texture2DGrad texture2DGradARB\n"
"#define texture2DProjGrad texture2DProjGradARB\n"
"#define textureCubeGrad textureCubeGradARB\n"
+ , &err
);
}
}
+ if (usesInstanceID)
+ {
+ bx::write(&writer, "#extension GL_ARB_draw_instanced : enable\n", &err);
+ }
+
if (usesGpuShader4)
{
- bx::write(&writer, "#extension GL_EXT_gpu_shader4 : enable\n");
+ bx::write(&writer, "#extension GL_EXT_gpu_shader4 : enable\n", &err);
}
if (usesGpuShader5)
{
- bx::write(&writer, "#extension GL_ARB_gpu_shader5 : enable\n");
+ bx::write(&writer, "#extension GL_ARB_gpu_shader5 : enable\n", &err);
+ }
+
+ if (usesViewportLayerArray)
+ {
+ bx::write(&writer, "#extension GL_ARB_shader_viewport_layer_array : enable\n", &err);
}
if (usesPacking)
{
- bx::write(&writer, "#extension GL_ARB_shading_language_packing : enable\n");
+ bx::write(&writer, "#extension GL_ARB_shading_language_packing : enable\n", &err);
}
if (usesTextureMS)
{
- bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n");
+ bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n", &err);
}
if (usesTextureArray)
{
- bx::write(&writer, "#extension GL_EXT_texture_array : enable\n");
+ bx::write(&writer, "#extension GL_EXT_texture_array : enable\n", &err);
if (BX_ENABLED(BX_PLATFORM_OSX) )
{
- bx::write(&writer, "#define texture2DArrayLodEXT texture2DArray\n");
+ bx::write(&writer, "#define texture2DArrayLod texture2DArray\n", &err);
}
else
{
- bx::write(&writer, "#define texture2DArrayLodEXT texture2DArrayLod\n");
+ bx::write(&writer, "#define texture2DArrayLodEXT texture2DArrayLod\n", &err);
+ bx::write(&writer, "#define textureArray texture\n", &err);
}
}
if (usesTexture3D)
{
- bx::write(&writer, "#define texture3DEXT texture3D\n");
+ bx::write(&writer, "#define texture3DEXT texture3D\n", &err);
if (BX_ENABLED(BX_PLATFORM_OSX) )
{
- bx::write(&writer, "#define texture3DLodEXT texture3D\n");
+ bx::write(&writer, "#define texture3DLodEXT texture3D\n", &err);
}
else
{
- bx::write(&writer, "#define texture3DLodEXT texture3DLod\n");
+ bx::write(&writer, "#define texture3DLodEXT texture3DLod\n", &err);
}
}
if (130 <= version)
{
- if (m_type == GL_FRAGMENT_SHADER)
+ if (430 > version)
{
- bx::write(&writer, "#define varying in\n");
- }
- else
- {
- bx::write(&writer, "#define attribute in\n");
- bx::write(&writer, "#define varying out\n");
+ if (m_type == GL_FRAGMENT_SHADER)
+ {
+ bx::write(&writer, "#define varying in\n", &err);
+ }
+ else
+ {
+ bx::write(&writer, "#define attribute in\n", &err);
+ bx::write(&writer, "#define varying out\n", &err);
+ }
}
uint32_t fragData = 0;
@@ -5611,52 +6650,68 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 != fragData)
{
bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData);
- bx::write(&writer, "#define gl_FragData bgfx_FragData\n");
+ bx::write(&writer, "#define gl_FragData bgfx_FragData\n", &err);
}
- else
+ else if (!bx::findIdentifierMatch(code, "gl_FragColor").isEmpty() )
{
- bx::write(&writer, "out vec4 bgfx_FragColor;\n");
- bx::write(&writer, "#define gl_FragColor bgfx_FragColor\n");
+ bx::write(&writer
+ , "out vec4 bgfx_FragColor;\n"
+ "#define gl_FragColor bgfx_FragColor\n"
+ , &err
+ );
}
}
else
{
if (m_type == GL_FRAGMENT_SHADER)
{
- bx::write(&writer, "#define in varying\n");
+ bx::write(&writer, "#define in varying\n", &err);
}
else
{
bx::write(&writer
, "#define in attribute\n"
"#define out varying\n"
+ , &err
);
}
}
- bx::write(&writer,
- "#define lowp\n"
- "#define mediump\n"
- "#define highp\n"
+ bx::write(&writer
+ , "#define lowp\n"
+ "#define mediump\n"
+ "#define highp\n"
+ , &err
);
if (!usesInterpQ)
{
- bx::write(&writer,
- "#define centroid\n"
- "#define flat\n"
- "#define noperspective\n"
- "#define smooth\n"
+ bx::write(&writer
+ ,
+ "#define centroid\n"
+ "#define flat\n"
+ "#define noperspective\n"
+ "#define smooth\n"
+ , &err
);
}
- bx::write(&writer, code);
- bx::write(&writer, '\0');
+ if (version == 430)
+ {
+ int32_t verLen = bx::strLen("#version 430\n");
+ bx::write(&writer, code.getPtr()+verLen, code.getLength()-verLen, &err);
+ }
+ else
+ {
+ bx::write(&writer, code, &err);
+ }
+
+ bx::write(&writer, '\0', &err);
}
else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 31)
- || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ || s_renderGL->m_gles3)
{
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ if (s_renderGL->m_gles3)
{
bx::write(&writer, &err
, "#version 300 es\n"
@@ -5666,7 +6721,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
else
{
- bx::write(&writer, "#version 140\n");
+ bx::write(&writer, "#version 140\n", &err);
}
bx::write(&writer
@@ -5676,33 +6731,47 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
"#define texture2DGrad textureGrad\n"
"#define texture3DGrad textureGrad\n"
"#define textureCubeGrad textureGrad\n"
+ , &err
);
if (m_type == GL_FRAGMENT_SHADER)
{
bx::write(&writer
- , "#define varying in\n"
- "#define texture2D texture\n"
- "#define texture2DProj textureProj\n"
+ , "#define varying in\n"
+ "#define texture2D texture\n"
+ "#define texture2DArray texture\n"
+ "#define texture2DProj textureProj\n"
+ , &err
);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
{
- bx::write(&writer, "#define shadow2D(_sampler, _coord) vec2(textureProj(_sampler, vec4(_coord, 1.0) ) )\n");
- bx::write(&writer, "#define shadow2DProj(_sampler, _coord) vec2(textureProj(_sampler, _coord) ) )\n");
+ bx::write(&writer
+ , "#define shadow2D(_sampler, _coord) vec2(textureProj(_sampler, vec4(_coord, 1.0) ) )\n"
+ "#define shadow2DProj(_sampler, _coord) vec2(textureProj(_sampler, _coord) )\n"
+ , &err
+ );
}
else
{
- bx::write(&writer, "#define shadow2D(_sampler, _coord) (textureProj(_sampler, vec4(_coord, 1.0) ) )\n");
- bx::write(&writer, "#define shadow2DProj(_sampler, _coord) (textureProj(_sampler, _coord) ) )\n");
+ bx::write(&writer
+ , "#define shadow2D(_sampler, _coord) (textureProj(_sampler, vec4(_coord, 1.0) ) )\n"
+ "#define shadow2DProj(_sampler, _coord) (textureProj(_sampler, _coord) )\n"
+ , &err
+ );
}
- bx::write(&writer, "#define texture3D texture\n");
- bx::write(&writer, "#define textureCube texture\n");
+ bx::write(&writer
+ , "#define texture3D texture\n"
+ "#define textureCube texture\n"
+ , &err
+ );
uint32_t fragData = 0;
- if (!bx::findIdentifierMatch(code, "gl_FragData").isEmpty() )
+ bool patchedFragData = s_renderGL->m_gles3 && !bx::findIdentifierMatch(code, "bgfx_FragData").isEmpty();
+
+ if (!patchedFragData && !bx::findIdentifierMatch(code, "gl_FragData").isEmpty() )
{
for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
{
@@ -5718,30 +6787,37 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
if (s_extension[Extension::INTEL_fragment_shader_ordering].m_supported)
{
- bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n");
+ bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n", &err);
}
else
{
- bx::write(&writer, "#define beginFragmentShaderOrdering()\n");
+ bx::write(&writer, "#define beginFragmentShaderOrdering()\n", &err);
}
}
if (!bx::findIdentifierMatch(code, s_ARB_texture_multisample).isEmpty() )
{
- bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n");
+ bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n", &err);
}
if (0 != fragData)
{
- bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData);
- bx::write(&writer, "#define gl_FragData bgfx_FragData\n");
+ if (!patchedFragData)
+ {
+ bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData);
+ bx::write(&writer, "#define gl_FragData bgfx_FragData\n", &err);
+ }
}
- else
+ else if (!patchedFragData)
{
- bx::write(&writer
- , "out vec4 bgfx_FragColor;\n"
- "#define gl_FragColor bgfx_FragColor\n"
- );
+ if (bx::findIdentifierMatch(code, "bgfx_FragColor").isEmpty() )
+ {
+ bx::write(&writer
+ , "out vec4 bgfx_FragColor;\n"
+ "#define gl_FragColor bgfx_FragColor\n"
+ , &err
+ );
+ }
}
}
else
@@ -5749,20 +6825,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::write(&writer
, "#define attribute in\n"
"#define varying out\n"
+ , &err
);
}
- if (!BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
+ if (!s_renderGL->m_gles3)
{
bx::write(&writer
, "#define lowp\n"
"#define mediump\n"
"#define highp\n"
+ , &err
);
}
- bx::write(&writer, code.getPtr(), code.getLength() );
- bx::write(&writer, '\0');
+ bx::write(&writer, code.getPtr(), code.getLength(), &err);
+ bx::write(&writer, '\0', &err);
}
code.set(temp);
@@ -5776,21 +6854,31 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::write(&writer
, "#version 430\n"
- "#define texture2DLod textureLod\n"
- "#define texture3DLod textureLod\n"
- "#define textureCubeLod textureLod\n"
- "#define texture2DGrad textureGrad\n"
- "#define texture3DGrad textureGrad\n"
- "#define textureCubeGrad textureGrad\n"
+ "#define texture2DLod textureLod\n"
+ "#define texture2DLodOffset textureLodOffset\n"
+ "#define texture2DArrayLod textureLod\n"
+ "#define texture2DArrayLodOffset textureLodOffset\n"
+ "#define texture3DLod textureLod\n"
+ "#define textureCubeLod textureLod\n"
+ "#define texture2DGrad textureGrad\n"
+ "#define texture3DGrad textureGrad\n"
+ "#define textureCubeGrad textureGrad\n"
+ , &err
);
- bx::write(&writer, code.getPtr()+bx::strLen("#version 430"), codeLen);
- bx::write(&writer, '\0');
+ int32_t verLen = bx::strLen("#version 430\n");
+ bx::write(&writer, code.getPtr()+verLen, codeLen-verLen, &err);
+ bx::write(&writer, '\0', &err);
code = temp;
}
- GL_CHECK(glShaderSource(m_id, 1, (const GLchar**)&code, NULL) );
+ {
+ const GLchar* str = (const GLchar*)code.getPtr();
+ int32_t len = code.getLength();
+ GL_CHECK(glShaderSource(m_id, 1, &str, &len) );
+ }
+
GL_CHECK(glCompileShader(m_id) );
GLint compiled = 0;
@@ -5798,33 +6886,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 == compiled)
{
- LineReader lineReader(code);
- bx::Error err;
- for (int32_t line = 1; err.isOk(); ++line)
+ bx::LineReader lineReader(code);
+ for (int32_t line = 1; !lineReader.isDone(); ++line)
{
- char str[4096];
- int32_t len = bx::read(&lineReader, str, BX_COUNTOF(str)-1, &err);
-
- if (err.isOk() )
- {
- str[len] = '\0';
- bx::StringView eol = bx::strFindEol(str);
- if (eol.getPtr() != str)
- {
- *const_cast<char*>(eol.getPtr() ) = '\0';
- }
- BX_TRACE("%3d %s", line, str);
- }
+ bx::StringView str = lineReader.next();
+ BX_TRACE("%3d %.*s", line, str.getLength(), str.getPtr() );
+ BX_UNUSED(str, line);
}
GLsizei len;
char log[1024];
GL_CHECK(glGetShaderInfoLog(m_id, sizeof(log), &len, log) );
- BX_TRACE("Failed to compile shader. %d: %s", compiled, log);
GL_CHECK(glDeleteShader(m_id) );
m_id = 0;
- BGFX_FATAL(false, bgfx::Fatal::InvalidShader, "Failed to compile shader.");
+ BGFX_FATAL(false, bgfx::Fatal::InvalidShader, "Failed to compile shader. %d: %s", compiled, log);
}
else if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& s_extension[Extension::ANGLE_translated_shader_source].m_supported
@@ -5906,7 +6982,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
attachment = GL_DEPTH_ATTACHMENT;
}
}
- else
+ else if (Access::Write == at.access)
{
buffers[colorIdx] = attachment;
++colorIdx;
@@ -5914,8 +6990,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 != texture.m_rbo)
{
-#if !(BGFX_CONFIG_RENDERER_OPENGL >= 30 || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
- if (GL_DEPTH_STENCIL_ATTACHMENT == attachment)
+ if (!(BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || s_renderGL->m_gles3)
+ && GL_DEPTH_STENCIL_ATTACHMENT == attachment)
{
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
@@ -5929,7 +7005,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
) );
}
else
-#endif
{
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attachment
@@ -5938,17 +7013,30 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
) );
}
}
- else if (Access::Write == at.access)
+ else
{
- if (1 < texture.m_depth
- && !texture.isCubeMap())
+ if (1 < texture.m_numLayers
+ && !texture.isCubeMap() )
{
- GL_CHECK(glFramebufferTextureLayer(GL_FRAMEBUFFER
- , attachment
- , texture.m_id
- , at.mip
- , at.layer
- ) );
+ if (1 < at.numLayers)
+ {
+ BX_ASSERT(0 == at.layer, "Can't use start layer > 0 when binding multiple layers to a framebuffer.");
+
+ GL_CHECK(glFramebufferTexture(GL_FRAMEBUFFER
+ , attachment
+ , texture.m_id
+ , at.mip
+ ) );
+ }
+ else
+ {
+ GL_CHECK(glFramebufferTextureLayer(GL_FRAMEBUFFER
+ , attachment
+ , texture.m_id
+ , at.mip
+ , at.layer
+ ) );
+ }
}
else
{
@@ -5965,10 +7053,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
) );
}
}
- else
- {
- BX_CHECK(false, "");
- }
needResolve |= (0 != texture.m_rbo) && (0 != texture.m_id);
}
@@ -5976,22 +7060,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_num = uint8_t(colorIdx);
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 31) )
+ if (0 == colorIdx && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
{
- if (0 == colorIdx)
- {
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
- {
- // When only depth is attached disable draw buffer to avoid
- // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER.
- GL_CHECK(glDrawBuffer(GL_NONE) );
- }
- }
- else
- {
- GL_CHECK(glDrawBuffers(colorIdx, buffers) );
- }
+ // When only depth is attached disable draw buffer to avoid
+ // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER.
+ GL_CHECK(glDrawBuffer(GL_NONE) );
+ }
+ else if (g_caps.limits.maxFBAttachments > 0)
+ {
+ GL_CHECK(glDrawBuffers(colorIdx, buffers) );
+ }
+ if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3)
+ {
// Disable read buffer to avoid GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER.
GL_CHECK(glReadBuffer(GL_NONE) );
}
@@ -6014,23 +7095,42 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (0 != texture.m_id)
{
- GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
- if (!bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) )
+
+ GLenum attachment = GL_INVALID_ENUM;
+ bimg::TextureFormat::Enum format = bimg::TextureFormat::Enum(texture.m_textureFormat);
+ if (bimg::isDepth(format) )
+ {
+ const bimg::ImageBlockInfo& info = bimg::getBlockInfo(format);
+ if (0 < info.stencilBits)
+ {
+ attachment = GL_DEPTH_STENCIL_ATTACHMENT;
+ }
+ else if (0 == info.depthBits)
+ {
+ attachment = GL_STENCIL_ATTACHMENT;
+ }
+ else
+ {
+ attachment = GL_DEPTH_ATTACHMENT;
+ }
+ }
+ else
{
+ attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
++colorIdx;
+ }
- GLenum target = texture.isCubeMap()
- ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + at.layer
- : texture.m_target
- ;
+ GLenum target = texture.isCubeMap()
+ ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + at.layer
+ : texture.m_target
+ ;
- GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
- , attachment
- , target
- , texture.m_id
- , at.mip
- ) );
- }
+ GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
+ , attachment
+ , target
+ , texture.m_id
+ , at.mip
+ ) );
}
}
}
@@ -6045,7 +7145,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat)
{
BX_UNUSED(_format, _depthFormat);
- m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh);
+ m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh, _width, _height);
m_width = _width;
m_height = _height;
m_numTh = 0;
@@ -6055,7 +7155,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
uint16_t FrameBufferGL::destroy()
{
- if (0 != m_num)
+ if (0 != m_fbo[0])
{
GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) );
m_num = 0;
@@ -6089,14 +7189,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
const TextureGL& texture = s_renderGL->m_textures[at.handle.idx];
+ const bool writeOnly = 0 != (texture.m_flags&BGFX_TEXTURE_RT_WRITE_ONLY);
bimg::TextureFormat::Enum format = bimg::TextureFormat::Enum(texture.m_textureFormat);
+
if (!bimg::isDepth(format) )
{
+ GL_CHECK(glDisable(GL_SCISSOR_TEST) );
+
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) );
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo[1]) );
+
GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIdx) );
GL_CHECK(glDrawBuffer(GL_COLOR_ATTACHMENT0 + colorIdx) );
+
colorIdx++;
+
GL_CHECK(glBlitFramebuffer(0
, 0
, m_width
@@ -6109,11 +7216,35 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, GL_LINEAR
) );
}
+ else if (!writeOnly)
+ {
+ GL_CHECK(glDisable(GL_SCISSOR_TEST) );
+
+ GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) );
+ GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo[1]) );
+
+ GL_CHECK(glBlitFramebuffer(0
+ , 0
+ , m_width
+ , m_height
+ , 0
+ , 0
+ , m_width
+ , m_height
+ , GL_DEPTH_BUFFER_BIT
+ , GL_NEAREST
+ ) );
+ }
}
}
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) );
- GL_CHECK(glReadBuffer(GL_NONE) );
+
+ if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3)
+ {
+ GL_CHECK(glReadBuffer(GL_NONE) );
+ }
+
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) );
}
@@ -6255,16 +7386,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
const TextureGL& src = m_textures[bi.m_src.idx];
const TextureGL& dst = m_textures[bi.m_dst.idx];
- uint32_t srcWidth = bx::uint32_min(src.m_width, bi.m_srcX + bi.m_width) - bi.m_srcX;
- uint32_t srcHeight = bx::uint32_min(src.m_height, bi.m_srcY + bi.m_height) - bi.m_srcY;
- uint32_t srcDepth = bx::uint32_min(src.m_depth, bi.m_srcZ + bi.m_depth) - bi.m_srcZ;
- uint32_t dstWidth = bx::uint32_min(dst.m_width, bi.m_dstX + bi.m_width) - bi.m_dstX;
- uint32_t dstHeight = bx::uint32_min(dst.m_height, bi.m_dstY + bi.m_height) - bi.m_dstY;
- uint32_t dstDepth = bx::uint32_min(dst.m_depth, bi.m_dstZ + bi.m_depth) - bi.m_dstZ;
- uint32_t width = bx::uint32_min(srcWidth, dstWidth);
- uint32_t height = bx::uint32_min(srcHeight, dstHeight);
- uint32_t depth = bx::uint32_min(srcDepth, dstDepth);
-
GL_CHECK(glCopyImageSubData(src.m_id
, src.m_target
, bi.m_srcMip
@@ -6277,10 +7398,56 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
, bi.m_dstX
, bi.m_dstY
, bi.m_dstZ
- , width
- , height
- , bx::uint32_imax(depth, 1)
+ , bi.m_width
+ , bi.m_height
+ , bx::uint32_imax(bi.m_depth, 1)
+ ) );
+ }
+ }
+ else if (BX_ENABLED(BGFX_GL_CONFIG_BLIT_EMULATION) )
+ {
+ while (_bs.hasItem(_view) )
+ {
+ const BlitItem& bi = _bs.advance();
+
+ const TextureGL& src = m_textures[bi.m_src.idx];
+ const TextureGL& dst = m_textures[bi.m_dst.idx];
+
+ BX_ASSERT(0 == bi.m_srcZ && 0 == bi.m_dstZ && 1 >= bi.m_depth
+ , "Blitting 3D regions is not supported"
+ );
+
+ GLuint fbo;
+ GL_CHECK(glGenFramebuffers(1, &fbo) );
+
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo) );
+
+ GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
+ , GL_COLOR_ATTACHMENT0
+ , GL_TEXTURE_2D
+ , src.m_id
+ , bi.m_srcMip
) );
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == status, "glCheckFramebufferStatus failed 0x%08x", status);
+ BX_UNUSED(status);
+
+ GL_CHECK(glActiveTexture(GL_TEXTURE0) );
+ GL_CHECK(glBindTexture(GL_TEXTURE_2D, dst.m_id) );
+
+ GL_CHECK(glCopyTexSubImage2D(GL_TEXTURE_2D
+ , bi.m_dstMip
+ , bi.m_dstX
+ , bi.m_dstY
+ , bi.m_srcX
+ , bi.m_srcY
+ , bi.m_width
+ , bi.m_height
+ ) );
+
+ GL_CHECK(glDeleteFramebuffers(1, &fbo) );
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_currentFbo) );
}
}
}
@@ -6292,6 +7459,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
renderDocTriggerCapture();
}
+ m_glctx.makeCurrent(NULL);
+
+ BGFX_GL_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorView);
+
if (1 < m_numWindows
&& m_vaoSupport)
{
@@ -6301,8 +7472,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_vao = 0;
}
- m_glctx.makeCurrent(NULL);
-
const GLuint defaultVao = m_vao;
if (0 != defaultVao)
{
@@ -6322,17 +7491,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (m_timerQuerySupport
&& !BX_ENABLED(BX_PLATFORM_OSX) )
{
- frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS);
+ frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS, _render->m_frameNum);
}
if (0 < _render->m_iboffset)
{
+ BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource);
TransientIndexBuffer* ib = _render->m_transientIb;
m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true);
}
if (0 < _render->m_vboffset)
{
+ BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource);
TransientVertexBuffer* vb = _render->m_transientVb;
m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true);
}
@@ -6347,12 +7518,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
RenderBind currentBind;
currentBind.clear();
- const bool hmdEnabled = false;
static ViewState viewState;
- viewState.reset(_render, hmdEnabled);
+ viewState.reset(_render);
- uint16_t programIdx = kInvalidHandle;
- uint16_t boundProgramIdx = kInvalidHandle;
+ ProgramHandle currentProgram = BGFX_INVALID_HANDLE;
+ ProgramHandle boundProgram = BGFX_INVALID_HANDLE;
SortKey key;
uint16_t view = UINT16_MAX;
FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS };
@@ -6406,18 +7576,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_occlusionQuery.resolve(_render);
}
- uint8_t eye = 0;
-
if (0 == (_render->m_debug&BGFX_DEBUG_IFH) )
{
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) );
- bool viewRestart = false;
- uint8_t restartState = 0;
viewState.m_rect = _render->m_view[0].m_rect;
-
int32_t numItems = _render->m_numRenderItems;
- for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;)
+
+ for (int32_t item = 0; item < numItems;)
{
const uint64_t encodedKey = _render->m_sortKeys[item];
const bool isCompute = key.decode(encodedKey, _render->m_viewRemap);
@@ -6435,17 +7601,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
if (viewChanged)
{
- if (1 == restartState)
+ view = key.m_view;
+ currentProgram = BGFX_INVALID_HANDLE;
+
+ if (item > 1)
{
- restartState = 2;
- item = restartItem;
- restartItem = numItems;
- view = UINT16_MAX;
- continue;
+ profiler.end();
}
- view = key.m_view;
- programIdx = kInvalidHandle;
+ BGFX_GL_PROFILER_END();
if (_render->m_view[view].m_fbh.idx != fbh.idx)
{
@@ -6454,55 +7618,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
resolutionHeight = setFrameBuffer(fbh, resolutionHeight, discardFlags);
}
- viewRestart = ( (BGFX_VIEW_STEREO == (_render->m_view[view].m_flags & BGFX_VIEW_STEREO) ) );
- viewRestart &= hmdEnabled;
- if (viewRestart)
- {
- if (0 == restartState)
- {
- restartState = 1;
- restartItem = item - 1;
- }
-
- eye = (restartState - 1) & 1;
- restartState &= 1;
- }
- else
- {
- eye = 0;
- }
-
- if (item > 1)
- {
- profiler.end();
- }
+ setViewType(view, " ");
+ BGFX_GL_PROFILER_BEGIN(view, kColorView);
profiler.begin(view);
viewState.m_rect = _render->m_view[view].m_rect;
- if (viewRestart)
- {
- if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
- {
- char* viewName = s_viewName[view];
- viewName[3] = ' ';
- viewName[4] = eye ? 'R' : 'L';
- GL_CHECK(glInsertEventMarker(0, viewName) );
- }
-
- viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2;
- viewState.m_rect.m_width /= 2;
- }
- else
- {
- if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
- {
- char* viewName = s_viewName[view];
- viewName[3] = ' ';
- viewName[4] = ' ';
- GL_CHECK(glInsertEventMarker(0, viewName) );
- }
- }
const Rect& scissorRect = _render->m_view[view].m_scissor;
viewHasScissor = !scissorRect.isZero();
@@ -6537,20 +7658,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
wasCompute = true;
- if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
- {
- char* viewName = s_viewName[view];
- viewName[3] = 'C';
- GL_CHECK(glInsertEventMarker(0, viewName) );
- }
+ setViewType(view, "C");
+ BGFX_GL_PROFILER_END();
+ BGFX_GL_PROFILER_BEGIN(view, kColorCompute);
}
if (computeSupported)
{
const RenderCompute& compute = renderItem.compute;
- ProgramGL& program = m_program[key.m_program];
- GL_CHECK(glUseProgram(program.m_id) );
+ ProgramGL& program = m_program[key.m_program.idx];
+ setProgram(program.m_id);
GLbitfield barrier = 0;
for (uint32_t ii = 0; ii < maxComputeBindings; ++ii)
@@ -6569,24 +7687,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
case Binding::Image:
{
- if (Access::Read == bind.m_access)
- {
- TextureGL& texture = m_textures[bind.m_idx];
- texture.commit(ii, uint32_t(texture.m_flags), _render->m_colorPalette);
- }
- else
- {
- const TextureGL& texture = m_textures[bind.m_idx];
- GL_CHECK(glBindImageTexture(ii
- , texture.m_id
- , bind.m_mip
- , texture.isCubeMap() ? GL_TRUE : GL_FALSE
- , 0
- , s_access[bind.m_access]
- , s_imageFormat[bind.m_format])
- );
- barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
- }
+ const TextureGL& texture = m_textures[bind.m_idx];
+ GL_CHECK(glBindImageTexture(ii
+ , texture.m_id
+ , bind.m_mip
+ , texture.isCubeMap() || texture.m_target == GL_TEXTURE_2D_ARRAY ? GL_TRUE : GL_FALSE
+ , 0
+ , s_access[bind.m_access]
+ , s_imageFormat[bind.m_format])
+ );
+ barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
}
break;
@@ -6620,10 +7730,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
commit(*program.m_constantBuffer);
}
- viewState.setPredefined<1>(this, view, eye, program, _render, compute);
+ viewState.setPredefined<1>(this, view, program, _render, compute);
if (isValid(compute.m_indirectBuffer) )
{
+ barrier |= GL_COMMAND_BARRIER_BIT;
const VertexBufferGL& vb = m_vertexBuffers[compute.m_indirectBuffer.idx];
if (currentState.m_indirectBuffer.idx != compute.m_indirectBuffer.idx)
{
@@ -6667,12 +7778,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
wasCompute = false;
- if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
- {
- char* viewName = s_viewName[view];
- viewName[3] = ' ';
- GL_CHECK(glInsertEventMarker(0, viewName) );
- }
+ setViewType(view, " ");
+ BGFX_GL_PROFILER_END();
+ BGFX_GL_PROFILER_BEGIN(view, kColorDraw);
}
const RenderDraw& draw = renderItem.draw;
@@ -6799,22 +7907,31 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
- if ( (0
+ if ( ( (0
+ | BGFX_STATE_ALPHA_REF_MASK
+ | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE
+ | BGFX_STATE_BLEND_EQUATION_MASK
+ | BGFX_STATE_BLEND_INDEPENDENT
+ | BGFX_STATE_BLEND_MASK
+ | BGFX_STATE_CONSERVATIVE_RASTER
| BGFX_STATE_CULL_MASK
- | BGFX_STATE_WRITE_Z
+ | BGFX_STATE_FRONT_CCW
| BGFX_STATE_DEPTH_TEST_MASK
- | BGFX_STATE_WRITE_RGB
- | BGFX_STATE_WRITE_A
- | BGFX_STATE_BLEND_MASK
- | BGFX_STATE_BLEND_EQUATION_MASK
- | BGFX_STATE_ALPHA_REF_MASK
- | BGFX_STATE_PT_MASK
- | BGFX_STATE_POINT_SIZE_MASK
- | BGFX_STATE_MSAA
| BGFX_STATE_LINEAA
- | BGFX_STATE_CONSERVATIVE_RASTER
+ | BGFX_STATE_MSAA
+ | BGFX_STATE_POINT_SIZE_MASK
+ | BGFX_STATE_PT_MASK
+ | BGFX_STATE_WRITE_A
+ | BGFX_STATE_WRITE_RGB
+ | BGFX_STATE_WRITE_Z
) & changedFlags)
+ || blendFactor != draw.m_rgba)
{
+ if (BGFX_STATE_FRONT_CCW & changedFlags)
+ {
+ GL_CHECK(glFrontFace( (BGFX_STATE_FRONT_CCW & newFlags) ? GL_CCW : GL_CW) );
+ }
+
if (BGFX_STATE_CULL_MASK & changedFlags)
{
if (BGFX_STATE_CULL_CCW & newFlags)
@@ -6911,10 +8028,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
if ( ( (0
- | BGFX_STATE_BLEND_MASK
+ | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE
| BGFX_STATE_BLEND_EQUATION_MASK
| BGFX_STATE_BLEND_INDEPENDENT
- | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE
+ | BGFX_STATE_BLEND_MASK
) & changedFlags)
|| blendFactor != draw.m_rgba)
{
@@ -6931,9 +8048,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
if ( ( (0
- | BGFX_STATE_BLEND_MASK
| BGFX_STATE_BLEND_EQUATION_MASK
- | BGFX_STATE_BLEND_INDEPENDENT) & newFlags)
+ | BGFX_STATE_BLEND_INDEPENDENT
+ | BGFX_STATE_BLEND_MASK
+ ) & newFlags)
|| blendFactor != draw.m_rgba)
{
const bool enabled = !!(BGFX_STATE_BLEND_MASK & newFlags);
@@ -7041,23 +8159,23 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bool bindAttribs = false;
rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd);
- if (key.m_program != programIdx)
+ if (key.m_program.idx != currentProgram.idx)
{
- programIdx = key.m_program;
- GLuint id = kInvalidHandle == programIdx ? 0 : m_program[programIdx].m_id;
+ currentProgram = key.m_program;
+ GLuint id = isValid(currentProgram) ? m_program[currentProgram.idx].m_id : 0;
// Skip rendering if program index is valid, but program is invalid.
- programIdx = 0 == id ? kInvalidHandle : programIdx;
+ currentProgram = 0 == id ? ProgramHandle{kInvalidHandle} : currentProgram;
- GL_CHECK(glUseProgram(id) );
+ setProgram(id);
programChanged =
constantsChanged =
bindAttribs = true;
}
- if (kInvalidHandle != programIdx)
+ if (isValid(currentProgram) )
{
- ProgramGL& program = m_program[programIdx];
+ ProgramGL& program = m_program[currentProgram.idx];
if (constantsChanged
&& NULL != program.m_constantBuffer)
@@ -7065,9 +8183,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
commit(*program.m_constantBuffer);
}
- viewState.setPredefined<1>(this, view, eye, program, _render, draw);
+ viewState.setPredefined<1>(this, view, program, _render, draw);
{
+ GLbitfield barrier = 0;
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
{
const Binding& bind = renderBind.m_bind[stage];
@@ -7081,6 +8200,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
switch (bind.m_type)
{
+ case Binding::Image:
+ {
+ const TextureGL& texture = m_textures[bind.m_idx];
+ GL_CHECK(glBindImageTexture(stage
+ , texture.m_id
+ , bind.m_mip
+ , texture.isCubeMap() || texture.m_target == GL_TEXTURE_2D_ARRAY ? GL_TRUE : GL_FALSE
+ , 0
+ , s_access[bind.m_access]
+ , s_imageFormat[bind.m_format])
+ );
+ barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
+ }
+ break;
+
case Binding::Texture:
{
TextureGL& texture = m_textures[bind.m_idx];
@@ -7107,22 +8241,33 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
current = bind;
}
+
+ if (0 != barrier)
+ {
+ GL_CHECK(glMemoryBarrier(barrier) );
+ }
}
{
- bool diffStreamHandles = false;
- for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
+ for (uint32_t idx = 0, streamMask = draw.m_streamMask
; 0 != streamMask
- ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
+ ; streamMask >>= 1, idx += 1
)
{
+ const uint32_t ntz = bx::uint32_cnttz(streamMask);
streamMask >>= ntz;
idx += ntz;
if (currentState.m_stream[idx].m_handle.idx != draw.m_stream[idx].m_handle.idx)
{
- diffStreamHandles = true;
- break;
+ currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle;
+ bindAttribs = true;
+ }
+
+ if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex)
+ {
+ currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex;
+ bindAttribs = true;
}
}
@@ -7130,24 +8275,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|| currentState.m_streamMask != draw.m_streamMask
|| currentState.m_instanceDataBuffer.idx != draw.m_instanceDataBuffer.idx
|| currentState.m_instanceDataOffset != draw.m_instanceDataOffset
- || currentState.m_instanceDataStride != draw.m_instanceDataStride
- || diffStreamHandles)
+ || currentState.m_instanceDataStride != draw.m_instanceDataStride)
{
- currentState.m_streamMask = draw.m_streamMask;
- currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx;
- currentState.m_instanceDataOffset = draw.m_instanceDataOffset;
- currentState.m_instanceDataStride = draw.m_instanceDataStride;
-
- for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
- ; 0 != streamMask
- ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
- )
- {
- streamMask >>= ntz;
- idx += ntz;
-
- currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle;
- }
+ currentState.m_streamMask = draw.m_streamMask;
+ currentState.m_instanceDataBuffer = draw.m_instanceDataBuffer;
+ currentState.m_instanceDataOffset = draw.m_instanceDataOffset;
+ currentState.m_instanceDataStride = draw.m_instanceDataStride;
bindAttribs = true;
}
@@ -7156,10 +8289,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
currentState.m_indexBuffer = draw.m_indexBuffer;
- uint16_t handle = draw.m_indexBuffer.idx;
- if (kInvalidHandle != handle)
+ if (isValid(draw.m_indexBuffer) )
{
- IndexBufferGL& ib = m_indexBuffers[handle];
+ IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx];
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib.m_id) );
}
else
@@ -7168,62 +8300,52 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
- if (0 != currentState.m_streamMask)
+ if (currentState.m_startIndex != draw.m_startIndex)
{
- bool diffStartVertex = false;
- for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
- ; 0 != streamMask
- ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
- )
- {
- streamMask >>= ntz;
- idx += ntz;
-
- if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex)
- {
- diffStartVertex = true;
- break;
- }
- }
+ currentState.m_startIndex = draw.m_startIndex;
+ }
- if (bindAttribs || diffStartVertex)
+ if (0 != currentState.m_streamMask)
+ {
+ if (bindAttribs)
{
- if(kInvalidHandle != boundProgramIdx)
+ if (isValid(boundProgram) )
{
- ProgramGL& boundProgram = m_program[boundProgramIdx];
- boundProgram.unbindAttributes();
+ m_program[boundProgram.idx].unbindAttributes();
+ m_program[boundProgram.idx].unbindInstanceData();
}
- boundProgramIdx = programIdx;
+ boundProgram = currentProgram;
program.bindAttributesBegin();
if (UINT8_MAX != draw.m_streamMask)
{
- for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
+ for (uint32_t idx = 0, streamMask = draw.m_streamMask
; 0 != streamMask
- ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
+ ; streamMask >>= 1, idx += 1
)
{
+ const uint32_t ntz = bx::uint32_cnttz(streamMask);
streamMask >>= ntz;
idx += ntz;
- currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex;
-
const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx];
- uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx;
+ const uint16_t decl = isValid(draw.m_stream[idx].m_layoutHandle)
+ ? draw.m_stream[idx].m_layoutHandle.idx
+ : vb.m_layoutHandle.idx;
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
- program.bindAttributes(m_vertexDecls[decl], draw.m_stream[idx].m_startVertex);
+ program.bindAttributes(m_vertexLayouts[decl], draw.m_stream[idx].m_startVertex);
}
}
- program.bindAttributesEnd();
-
if (isValid(draw.m_instanceDataBuffer) )
{
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[draw.m_instanceDataBuffer.idx].m_id) );
program.bindInstanceData(draw.m_instanceDataStride, draw.m_instanceDataOffset);
}
+
+ program.bindAttributesEnd();
}
}
}
@@ -7233,19 +8355,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
uint32_t numVertices = draw.m_numVertices;
if (UINT32_MAX == numVertices)
{
- for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
+ for (uint32_t idx = 0, streamMask = draw.m_streamMask
; 0 != streamMask
- ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
+ ; streamMask >>= 1, idx += 1
)
{
+ const uint32_t ntz = bx::uint32_cnttz(streamMask);
streamMask >>= ntz;
idx += ntz;
const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx];
- uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx;
- const VertexDecl& vertexDecl = m_vertexDecls[decl];
+ uint16_t decl = !isValid(vb.m_layoutHandle) ? draw.m_stream[idx].m_layoutHandle.idx : vb.m_layoutHandle.idx;
+ const VertexLayout& layout = m_vertexLayouts[decl];
- numVertices = bx::uint32_min(numVertices, vb.m_size/vertexDecl.m_stride);
+ numVertices = bx::uint32_min(numVertices, vb.m_size/layout.m_stride);
}
}
@@ -7269,6 +8392,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
GL_CHECK(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, vb.m_id) );
}
+ uint32_t numOffsetIndirect = 0;
+ if (isValid(draw.m_numIndirectBuffer) )
+ {
+ if (currentState.m_numIndirectBuffer.idx != draw.m_numIndirectBuffer.idx)
+ {
+ const IndexBufferGL& nb = m_indexBuffers[draw.m_numIndirectBuffer.idx];
+ currentState.m_numIndirectBuffer = draw.m_numIndirectBuffer;
+ GL_CHECK(glBindBuffer(GL_PARAMETER_BUFFER_ARB, nb.m_id) );
+ }
+
+ numOffsetIndirect = draw.m_numIndirectIndex * sizeof(uint32_t);
+ }
+
if (isValid(draw.m_indexBuffer) )
{
const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx];
@@ -7284,11 +8420,24 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
;
uintptr_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE;
- GL_CHECK(glMultiDrawElementsIndirect(prim.m_type, indexFormat
- , (void*)args
- , numDrawIndirect
- , BGFX_CONFIG_DRAW_INDIRECT_STRIDE
- ) );
+
+ if (isValid(draw.m_numIndirectBuffer) )
+ {
+ GL_CHECK(glMultiDrawElementsIndirectCount(prim.m_type, indexFormat
+ , (void*)args
+ , numOffsetIndirect
+ , numDrawIndirect
+ , BGFX_CONFIG_DRAW_INDIRECT_STRIDE
+ ) );
+ }
+ else
+ {
+ GL_CHECK(glMultiDrawElementsIndirect(prim.m_type, indexFormat
+ , (void*)args
+ , numDrawIndirect
+ , BGFX_CONFIG_DRAW_INDIRECT_STRIDE
+ ) );
+ }
}
else
{
@@ -7298,11 +8447,24 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
;
uintptr_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE;
- GL_CHECK(glMultiDrawArraysIndirect(prim.m_type
- , (void*)args
- , numDrawIndirect
- , BGFX_CONFIG_DRAW_INDIRECT_STRIDE
- ) );
+
+ if (isValid(draw.m_numIndirectBuffer) )
+ {
+ GL_CHECK(glMultiDrawArraysIndirectCount(prim.m_type
+ , (void*)args
+ , numOffsetIndirect
+ , numDrawIndirect
+ , BGFX_CONFIG_DRAW_INDIRECT_STRIDE
+ ) );
+ }
+ else
+ {
+ GL_CHECK(glMultiDrawArraysIndirect(prim.m_type
+ , (void*)args
+ , numDrawIndirect
+ , BGFX_CONFIG_DRAW_INDIRECT_STRIDE
+ ) );
+ }
}
}
else
@@ -7311,14 +8473,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
{
currentState.m_indirectBuffer.idx = kInvalidHandle;
GL_CHECK(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0) );
+
+ if (isValid(currentState.m_numIndirectBuffer) )
+ {
+ currentState.m_numIndirectBuffer.idx = kInvalidHandle;
+ GL_CHECK(glBindBuffer(GL_PARAMETER_BUFFER_ARB, 0) );
+ }
}
if (isValid(draw.m_indexBuffer) )
{
- const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx];
- const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32);
- const uint32_t indexSize = hasIndex16 ? 2 : 4;
- const GLenum indexFormat = hasIndex16
+ const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx];
+ const bool isIndex16 = draw.isIndex16();
+ const uint32_t indexSize = isIndex16 ? 2 : 4;
+ const GLenum indexFormat = isIndex16
? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
;
@@ -7339,10 +8507,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
else if (prim.m_min <= draw.m_numIndices)
{
- numIndices = draw.m_numIndices;
+ numIndices = draw.m_numIndices;
numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub;
- numInstances = draw.m_numInstances;
- numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
+ numInstances = draw.m_numInstances;
+ numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
GL_CHECK(glDrawElementsInstanced(prim.m_type
, numIndices
@@ -7355,8 +8523,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
else
{
numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub;
- numInstances = draw.m_numInstances;
- numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
+ numInstances = draw.m_numInstances;
+ numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
GL_CHECK(glDrawArraysInstanced(prim.m_type
, 0
@@ -7371,11 +8539,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_occlusionQuery.end();
}
- if(isValid(draw.m_instanceDataBuffer))
- {
- program.unbindInstanceData();
- }
-
statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted;
statsNumPrimsRendered[primIndex] += numPrimsRendered;
statsNumInstances[primIndex] += numInstances;
@@ -7384,10 +8547,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
- if(kInvalidHandle != boundProgramIdx)
+ if (isValid(boundProgram) )
+ {
+ m_program[boundProgram.idx].unbindAttributes();
+ boundProgram = BGFX_INVALID_HANDLE;
+ }
+
+ if (wasCompute)
{
- ProgramGL& boundProgram = m_program[boundProgramIdx];
- boundProgram.unbindAttributes();
+ setViewType(view, "C");
+ BGFX_GL_PROFILER_END();
+ BGFX_GL_PROFILER_BEGIN(view, kColorCompute);
}
submitBlit(bs, BGFX_CONFIG_MAX_VIEWS);
@@ -7414,6 +8584,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
}
+ BGFX_GL_PROFILER_END();
+
m_glctx.makeCurrent(NULL);
int64_t timeEnd = bx::getHPCounter();
int64_t frameTime = timeEnd - timeBegin;
@@ -7453,12 +8625,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
perfStats.numCompute = statsKeyType[1];
perfStats.numBlit = _render->m_numBlitItems;
perfStats.maxGpuLatency = maxGpuLatency;
+ perfStats.gpuFrameNum = result.m_frameNum;
bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) );
perfStats.gpuMemoryMax = -INT64_MAX;
perfStats.gpuMemoryUsed = -INT64_MAX;
if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) )
{
+ BGFX_GL_PROFILER_BEGIN_LITERAL("debugstats", kColorFrame);
+
m_needPresent = true;
TextVideoMem& tvm = m_textVideoMem;
@@ -7473,9 +8648,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
tvm.clear();
uint16_t pos = 0;
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f
- , " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " "
+ , " %s / " BX_COMPILER_NAME
+ " / " BX_CPU_NAME
+ " / " BX_ARCH_NAME
+ " / " BX_PLATFORM_NAME
+ " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")"
, getRendererName()
+ , BGFX_API_VERSION
+ , BGFX_REV_NUMBER
);
+
tvm.printf(0, pos++, 0x8f, " Vendor: %s ", m_vendor);
tvm.printf(0, pos++, 0x8f, " Renderer: %s ", m_renderer);
tvm.printf(0, pos++, 0x8f, " Version: %s ", m_version);
@@ -7627,10 +8809,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
}
blit(this, _textVideoMemBlitter, tvm);
+
+ BGFX_GL_PROFILER_END();
}
else if (_render->m_debug & BGFX_DEBUG_TEXT)
{
+ BGFX_GL_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame);
+
blit(this, _textVideoMemBlitter, _render->m_textVideoMem);
+
+ BGFX_GL_PROFILER_END();
}
}
} } // namespace bgfx