mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-02-16 11:50:19 -05:00
Detect available MSAA texture formats.
This commit is contained in:
parent
ea8ae40898
commit
818c231d49
7 changed files with 95 additions and 56 deletions
|
@ -359,13 +359,15 @@
|
|||
#define BGFX_CAPS_HIDPI UINT64_C(0x0000000000008000) //!< HiDPI rendering is supported.
|
||||
|
||||
///
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00) //!< Texture format is not supported.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_COLOR UINT8_C(0x01) //!< Texture format is supported.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB UINT8_C(0x02) //!< Texture as sRGB format is supported.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_EMULATED UINT8_C(0x04) //!< Texture format is emulated.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT8_C(0x08) //!< Texture format can be used from vertex shader.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT8_C(0x10) //!< Texture format can be used as image from compute shader.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT8_C(0x20) //!< Texture format can be used as frame buffer.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00) //!< Texture format is not supported.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_COLOR UINT8_C(0x01) //!< Texture format is supported.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB UINT8_C(0x02) //!< Texture as sRGB format is supported.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_EMULATED UINT8_C(0x04) //!< Texture format is emulated.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT8_C(0x08) //!< Texture format can be used from vertex shader.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT8_C(0x10) //!< Texture format can be used as image from compute shader.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT8_C(0x20) //!< Texture format can be used as frame buffer.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT8_C(0x40) //!< Texture format can be used as MSAA frame buffer.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT8_C(0x80) //!< Texture can be sampled as MSAA.
|
||||
|
||||
///
|
||||
#define BGFX_VIEW_NONE UINT8_C(0x00) //!<
|
||||
|
|
28
src/bgfx.cpp
28
src/bgfx.cpp
|
@ -910,24 +910,28 @@ namespace bgfx
|
|||
}
|
||||
|
||||
BX_TRACE("Supported texture formats:");
|
||||
BX_TRACE("\t +--------- x = supported / * = emulated");
|
||||
BX_TRACE("\t |+-------- sRGB format");
|
||||
BX_TRACE("\t ||+------- vertex format");
|
||||
BX_TRACE("\t |||+------ image");
|
||||
BX_TRACE("\t ||||+----- framebuffer");
|
||||
BX_TRACE("\t ||||| +-- name");
|
||||
BX_TRACE("\t +----------- x = supported / * = emulated");
|
||||
BX_TRACE("\t |+---------- sRGB format");
|
||||
BX_TRACE("\t ||+--------- vertex format");
|
||||
BX_TRACE("\t |||+-------- image");
|
||||
BX_TRACE("\t ||||+------- framebuffer");
|
||||
BX_TRACE("\t |||||+------ MSAA framebuffer");
|
||||
BX_TRACE("\t ||||||+----- MSAA texture");
|
||||
BX_TRACE("\t ||||||| +-- name");
|
||||
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
|
||||
{
|
||||
if (TextureFormat::Unknown != ii
|
||||
&& TextureFormat::UnknownDepth != ii)
|
||||
{
|
||||
uint8_t flags = g_caps.formats[ii];
|
||||
BX_TRACE("\t[%c%c%c%c%c] %s"
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB ? 'l' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' '
|
||||
BX_TRACE("\t[%c%c%c%c%c%c%c] %s"
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB ? 'l' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA ? '+' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_MSAA ? 'm' : ' '
|
||||
, getName(TextureFormat::Enum(ii) )
|
||||
);
|
||||
BX_UNUSED(flags);
|
||||
|
|
|
@ -124,6 +124,8 @@ typedef GLuint (GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count,
|
|||
typedef GLenum (GL_APIENTRYP PFNGLGETERRORPROC) (void);
|
||||
typedef void (GL_APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *data);
|
||||
typedef void (GL_APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
|
||||
typedef void (GL_APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params);
|
||||
typedef void (GL_APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params);
|
||||
typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
|
||||
typedef void (GL_APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
|
||||
typedef void (GL_APIENTRYP PFNGLGETPOINTERVPROC) (GLenum pname, void **params);
|
||||
|
@ -299,6 +301,8 @@ GL_IMPORT______(true, PFNGLGETDEBUGMESSAGELOGPROC, glGetDebugMes
|
|||
GL_IMPORT______(false, PFNGLGETERRORPROC, glGetError);
|
||||
GL_IMPORT______(false, PFNGLGETFLOATVPROC, glGetFloatv);
|
||||
GL_IMPORT______(false, PFNGLGETINTEGERVPROC, glGetIntegerv);
|
||||
GL_IMPORT______(false, PFNGLGETINTERNALFORMATIVPROC, glGetInternalformativ);
|
||||
GL_IMPORT______(false, PFNGLGETINTERNALFORMATI64VPROC, glGetInternalformati64v);
|
||||
GL_IMPORT______(true, PFNGLGETOBJECTLABELPROC, glGetObjectLabel);
|
||||
GL_IMPORT______(true, PFNGLGETOBJECTPTRLABELPROC, glGetObjectPtrLabel);
|
||||
GL_IMPORT______(true, PFNGLGETPOINTERVPROC, glGetPointerv);
|
||||
|
|
|
@ -1264,6 +1264,20 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
support |= 0 != (data.OutFormatSupport & (0
|
||||
| D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
|
||||
) )
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
support |= 0 != (data.OutFormatSupport & (0
|
||||
| D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD
|
||||
) )
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -934,6 +934,20 @@ namespace bgfx { namespace d3d12
|
|||
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
support |= 0 != (data.Support1 & (0
|
||||
| D3D12_FORMAT_SUPPORT1_MULTISAMPLE_RENDERTARGET
|
||||
) )
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
support |= 0 != (data.Support1 & (0
|
||||
| D3D12_FORMAT_SUPPORT1_MULTISAMPLE_LOAD
|
||||
) )
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -148,26 +148,6 @@ namespace bgfx { namespace d3d9
|
|||
D3DCULL_CCW,
|
||||
};
|
||||
|
||||
static const D3DFORMAT s_checkColorFormats[] =
|
||||
{
|
||||
D3DFMT_UNKNOWN,
|
||||
D3DFMT_A8R8G8B8, D3DFMT_UNKNOWN,
|
||||
D3DFMT_R32F, D3DFMT_R16F, D3DFMT_G16R16, D3DFMT_A8R8G8B8, D3DFMT_UNKNOWN,
|
||||
|
||||
D3DFMT_UNKNOWN, // terminator
|
||||
};
|
||||
|
||||
static D3DFORMAT s_colorFormat[] =
|
||||
{
|
||||
D3DFMT_UNKNOWN, // ignored
|
||||
D3DFMT_A8R8G8B8,
|
||||
D3DFMT_A2B10G10R10,
|
||||
D3DFMT_A16B16G16R16,
|
||||
D3DFMT_A16B16G16R16F,
|
||||
D3DFMT_R16F,
|
||||
D3DFMT_R32F,
|
||||
};
|
||||
|
||||
static const D3DTEXTUREADDRESS s_textureAddress[] =
|
||||
{
|
||||
D3DTADDRESS_WRAP,
|
||||
|
@ -630,27 +610,18 @@ namespace bgfx { namespace d3d9
|
|||
, s_textureFormat[ii].m_fmt
|
||||
) ) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
||||
|
||||
support |= SUCCEEDED(m_d3d9->CheckDeviceMultiSampleType(m_adapter
|
||||
, m_deviceType
|
||||
, s_textureFormat[ii].m_fmt
|
||||
, true
|
||||
, D3DMULTISAMPLE_2_SAMPLES
|
||||
, NULL
|
||||
) ) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
||||
|
||||
g_caps.formats[ii] = support;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t index = 1;
|
||||
for (const D3DFORMAT* fmt = &s_checkColorFormats[index]; *fmt != D3DFMT_UNKNOWN; ++fmt, ++index)
|
||||
{
|
||||
for (; *fmt != D3DFMT_UNKNOWN; ++fmt)
|
||||
{
|
||||
if (SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, *fmt) ) )
|
||||
{
|
||||
s_colorFormat[index] = *fmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (; *fmt != D3DFMT_UNKNOWN; ++fmt);
|
||||
}
|
||||
}
|
||||
|
||||
m_fmtDepth = D3DFMT_D24S8;
|
||||
|
||||
#elif BX_PLATFORM_XBOX360
|
||||
|
|
|
@ -451,6 +451,8 @@ namespace bgfx { namespace gl
|
|||
ARB_half_float_pixel,
|
||||
ARB_half_float_vertex,
|
||||
ARB_instanced_arrays,
|
||||
ARB_internalformat_query,
|
||||
ARB_internalformat_query2,
|
||||
ARB_invalidate_subdata,
|
||||
ARB_map_buffer_range,
|
||||
ARB_multi_draw_indirect,
|
||||
|
@ -646,6 +648,8 @@ namespace bgfx { namespace gl
|
|||
{ "ARB_half_float_pixel", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
|
||||
{ "ARB_half_float_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 30, 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 },
|
||||
{ "ARB_invalidate_subdata", BGFX_CONFIG_RENDERER_OPENGL >= 43, true },
|
||||
{ "ARB_map_buffer_range", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
|
||||
{ "ARB_multi_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 43, true },
|
||||
|
@ -1596,6 +1600,32 @@ namespace bgfx { namespace gl
|
|||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
if (NULL != glGetInternalformativ)
|
||||
{
|
||||
GLint maxSamples;
|
||||
GL_CHECK(glGetInternalformativ(GL_RENDERBUFFER
|
||||
, s_textureFormat[ii].m_internalFmt
|
||||
, GL_SAMPLES
|
||||
, 1
|
||||
, &maxSamples
|
||||
) );
|
||||
supported |= maxSamples > 0
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
GL_CHECK(glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE
|
||||
, s_textureFormat[ii].m_internalFmt
|
||||
, GL_SAMPLES
|
||||
, 1
|
||||
, &maxSamples
|
||||
) );
|
||||
supported |= maxSamples > 0
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
}
|
||||
|
||||
g_caps.formats[ii] = supported;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue