Added swap chain caps.

This commit is contained in:
Branimir Karadžić 2014-09-23 20:35:39 -07:00
parent dd5492c29a
commit f4c7f69ed7
19 changed files with 117 additions and 52 deletions

View file

@ -94,8 +94,6 @@ static const InputBinding s_bindings[] =
int _main_(int /*_argc*/, char** /*_argv*/)
{
inputAddBindings("22-windows", s_bindings);
uint32_t width = 1280;
uint32_t height = 720;
uint32_t debug = BGFX_DEBUG_TEXT;
@ -104,6 +102,14 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::init();
bgfx::reset(width, height, reset);
const bgfx::Caps* caps = bgfx::getCaps();
bool swapChainSupported = 0 != (caps->supported & BGFX_CAPS_SWAP_CHAIN);
if (swapChainSupported)
{
inputAddBindings("22-windows", s_bindings);
}
// Enable debug text.
bgfx::setDebug(debug);
@ -234,7 +240,16 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/22-windows");
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Rendering into multiple windows.");
bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
bgfx::dbgTextPrintf(0, 5, 0x2f, "Press 'c' to create or 'd' to destroy window.");
if (swapChainSupported)
{
bgfx::dbgTextPrintf(0, 5, 0x2f, "Press 'c' to create or 'd' to destroy window.");
}
else
{
bool blink = uint32_t(time*3.0f)&1;
bgfx::dbgTextPrintf(0, 5, blink ? 0x1f : 0x01, " Multiple windows is not supported by `%s` renderer. ", bgfx::getRendererName(caps->rendererType) );
}
uint32_t count = 0;

View file

@ -276,7 +276,8 @@ namespace entry
);
clear(hwnd);
m_hwnd[_wparam] = hwnd;
m_hwnd[_wparam] = hwnd;
m_flags[_wparam] = msg->m_flags;
WindowHandle handle = { (uint16_t)_wparam };
m_eventQueue.postSizeEvent(handle, msg->m_width, msg->m_height);
m_eventQueue.postWindowEvent(handle, hwnd);

View file

@ -275,5 +275,6 @@
#define BGFX_CAPS_BLEND_INDEPENDENT UINT64_C(0x0000000000000080)
#define BGFX_CAPS_COMPUTE UINT64_C(0x0000000000000100)
#define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000200)
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400)
#endif // BGFX_DEFINES_H_HEADER_GUARD

View file

@ -1770,9 +1770,9 @@ namespace bgfx
BGFX_API_FUNC(void reset(uint32_t _width, uint32_t _height, uint32_t _flags) )
{
BX_WARN(0 != _width && 0 != _height, "Frame buffer resolution width or height cannot be 0 (width %d, height %d).", _width, _height);
m_resolution.m_width = bx::uint32_max(1, _width);
m_resolution.m_width = bx::uint32_max(1, _width);
m_resolution.m_height = bx::uint32_max(1, _height);
m_resolution.m_flags = _flags;
m_resolution.m_flags = _flags;
memset(m_fb, 0xff, sizeof(m_fb) );
}

View file

@ -23,6 +23,7 @@ namespace bgfx
void destroy();
void resize(uint32_t _width, uint32_t _height, bool _vsync);
static bool isSwapChainSupported();
SwapChainGL* createSwapChain(void* _nwh);
void destorySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);

View file

@ -91,6 +91,11 @@ namespace bgfx
BX_TRACE("resize context");
}
bool GlContext::isSwapChainSupported()
{
return false;
}
SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
{
BX_CHECK(false, "Shouldn't be called!");

View file

@ -237,6 +237,11 @@ EGL_IMPORT
eglSwapInterval(m_display, _vsync ? 1 : 0);
}
bool GlContext::isSwapChainSupported()
{
return false;
}
SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
{
BX_CHECK(false, "Shouldn't be called!");

View file

@ -27,6 +27,7 @@ namespace bgfx
void destroy();
void resize(uint32_t _width, uint32_t _height, bool _vsync);
static bool isSwapChainSupported();
SwapChainGL* createSwapChain(void* _nwh);
void destorySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);

View file

@ -212,6 +212,11 @@ namespace bgfx
}
}
bool GlContext::isSwapChainSupported()
{
return false;
}
SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
{
BX_CHECK(false, "Shouldn't be called!");

View file

@ -26,6 +26,7 @@ namespace bgfx
void destroy();
void resize(uint32_t _width, uint32_t _height, bool _vsync);
static bool isSwapChainSupported();
SwapChainGL* createSwapChain(void* _nwh);
void destorySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);

View file

@ -23,6 +23,7 @@ namespace bgfx
void destroy();
void resize(uint32_t _width, uint32_t _height, bool _vsync);
static bool isSwapChainSupported();
SwapChainGL* createSwapChain(void* _nwh);
void destorySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);

View file

@ -88,6 +88,11 @@ namespace bgfx
[glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval];
}
bool GlContext::isSwapChainSupported()
{
return false;
}
SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
{
BX_CHECK(false, "Shouldn't be called!");

View file

@ -158,6 +158,11 @@ namespace bgfx
s_ppapi.resize(_width, _height, _vsync);
}
bool GlContext::isSwapChainSupported()
{
return false;
}
SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
{
BX_CHECK(false, "Shouldn't be called!");

View file

@ -27,6 +27,7 @@ namespace bgfx
void destroy();
void resize(uint32_t _width, uint32_t _height, bool _vsync);
static bool isSwapChainSupported();
SwapChainGL* createSwapChain(void* _nwh);
void destorySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);

View file

@ -292,6 +292,11 @@ namespace bgfx
}
}
bool GlContext::isSwapChainSupported()
{
return true;
}
SwapChainGL* GlContext::createSwapChain(void* _nwh)
{
SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(_nwh);

View file

@ -71,6 +71,7 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z
void destroy();
void resize(uint32_t _width, uint32_t _height, bool _vsync);
static bool isSwapChainSupported();
SwapChainGL* createSwapChain(void* _nwh);
void destorySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);

View file

@ -611,6 +611,7 @@ namespace bgfx
| BGFX_CAPS_BLEND_INDEPENDENT
| BGFX_CAPS_COMPUTE
| (getIntelExtensions(m_device) ? BGFX_CAPS_FRAGMENT_ORDERING : 0)
| BGFX_CAPS_SWAP_CHAIN
);
g_caps.maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
g_caps.maxFBAttachments = bx::uint32_min(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);

View file

@ -432,58 +432,59 @@ namespace bgfx
| BGFX_CAPS_TEXTURE_COMPARE_LEQUAL
| BGFX_CAPS_VERTEX_ATTRIB_HALF
| BGFX_CAPS_FRAGMENT_DEPTH
| BGFX_CAPS_SWAP_CHAIN
);
g_caps.maxTextureSize = bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight);
m_caps.NumSimultaneousRTs = bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);
g_caps.maxFBAttachments = (uint8_t)m_caps.NumSimultaneousRTs;
#if BGFX_CONFIG_RENDERER_USE_EXTENSIONS
BX_TRACE("Extended formats:");
for (uint32_t ii = 0; ii < ExtendedFormat::Count; ++ii)
if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) )
{
ExtendedFormat& fmt = s_extendedFormats[ii];
fmt.m_supported = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, fmt.m_usage, fmt.m_type, fmt.m_fmt) );
const char* fourcc = (const char*)&fmt.m_fmt;
BX_TRACE("\t%2d: %c%c%c%c %s", ii, fourcc[0], fourcc[1], fourcc[2], fourcc[3], fmt.m_supported ? "supported" : "");
BX_UNUSED(fourcc);
BX_TRACE("Extended formats:");
for (uint32_t ii = 0; ii < ExtendedFormat::Count; ++ii)
{
ExtendedFormat& fmt = s_extendedFormats[ii];
fmt.m_supported = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, fmt.m_usage, fmt.m_type, fmt.m_fmt) );
const char* fourcc = (const char*)&fmt.m_fmt;
BX_TRACE("\t%2d: %c%c%c%c %s", ii, fourcc[0], fourcc[1], fourcc[2], fourcc[3], fmt.m_supported ? "supported" : "");
BX_UNUSED(fourcc);
}
m_instancing = false
|| s_extendedFormats[ExtendedFormat::Inst].m_supported
|| (m_caps.VertexShaderVersion >= D3DVS_VERSION(3, 0) )
;
if (m_amd
&& s_extendedFormats[ExtendedFormat::Inst].m_supported)
{ // AMD only
m_device->SetRenderState(D3DRS_POINTSIZE, D3DFMT_INST);
}
if (s_extendedFormats[ExtendedFormat::Intz].m_supported)
{
s_textureFormat[TextureFormat::D24].m_fmt = D3DFMT_INTZ;
s_textureFormat[TextureFormat::D32].m_fmt = D3DFMT_INTZ;
}
s_textureFormat[TextureFormat::BC4].m_fmt = s_extendedFormats[ExtendedFormat::Ati1].m_supported ? D3DFMT_ATI1 : D3DFMT_UNKNOWN;
s_textureFormat[TextureFormat::BC5].m_fmt = s_extendedFormats[ExtendedFormat::Ati2].m_supported ? D3DFMT_ATI2 : D3DFMT_UNKNOWN;
g_caps.supported |= m_instancing ? BGFX_CAPS_INSTANCING : 0;
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
g_caps.formats[ii] = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
, m_deviceType
, adapterFormat
, 0
, D3DRTYPE_TEXTURE
, s_textureFormat[ii].m_fmt
) ) ? 1 : 0;
}
}
m_instancing = false
|| s_extendedFormats[ExtendedFormat::Inst].m_supported
|| (m_caps.VertexShaderVersion >= D3DVS_VERSION(3, 0) )
;
if (m_amd
&& s_extendedFormats[ExtendedFormat::Inst].m_supported)
{
// AMD only
m_device->SetRenderState(D3DRS_POINTSIZE, D3DFMT_INST);
}
if (s_extendedFormats[ExtendedFormat::Intz].m_supported)
{
s_textureFormat[TextureFormat::D24].m_fmt = D3DFMT_INTZ;
s_textureFormat[TextureFormat::D32].m_fmt = D3DFMT_INTZ;
}
s_textureFormat[TextureFormat::BC4].m_fmt = s_extendedFormats[ExtendedFormat::Ati1].m_supported ? D3DFMT_ATI1 : D3DFMT_UNKNOWN;
s_textureFormat[TextureFormat::BC5].m_fmt = s_extendedFormats[ExtendedFormat::Ati2].m_supported ? D3DFMT_ATI2 : D3DFMT_UNKNOWN;
g_caps.supported |= m_instancing ? BGFX_CAPS_INSTANCING : 0;
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
g_caps.formats[ii] = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
, m_deviceType
, adapterFormat
, 0
, D3DRTYPE_TEXTURE
, s_textureFormat[ii].m_fmt
) ) ? 1 : 0;
}
#endif // BGFX_CONFIG_RENDERER_USE_EXTENSIONS
uint32_t index = 1;
for (const D3DFORMAT* fmt = &s_checkColorFormats[index]; *fmt != D3DFMT_UNKNOWN; ++fmt, ++index)
{

View file

@ -1187,6 +1187,8 @@ namespace bgfx
|| s_extension[Extension::OES_vertex_array_object].m_supported
;
m_vaoSupport &= false;
if (BX_ENABLED(BX_PLATFORM_NACL) )
{
m_vaoSupport &= NULL != glGenVertexArrays
@ -1240,6 +1242,11 @@ namespace bgfx
: 0
;
g_caps.supported |= GlContext::isSwapChainSupported()
? BGFX_CAPS_SWAP_CHAIN
: 0
;
if (s_extension[Extension::EXT_texture_filter_anisotropic].m_supported)
{
GL_CHECK(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_maxAnisotropy) );
@ -3871,9 +3878,12 @@ namespace bgfx
uint16_t FrameBufferGL::destroy()
{
GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) );
memset(m_fbo, 0, sizeof(m_fbo) );
m_num = 0;
if (0 != m_num)
{
GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) );
memset(m_fbo, 0, sizeof(m_fbo) );
m_num = 0;
}
if (NULL != m_swapChain)
{