branches/osd/src/lib/bgfx/bgfx.cpp
| r32173 | r32174 | |
| 503 | 503 | |
| 504 | 504 | struct Mem |
| 505 | 505 | { |
| 506 | Mem(const void* _data, size_t _size) |
| 507 | : data(_data) |
| 508 | , size(_size) |
| 509 | { |
| 510 | } |
| 511 | |
| 506 | 512 | const void* data; |
| 507 | | const size_t size; |
| 513 | size_t size; |
| 508 | 514 | }; |
| 509 | 515 | |
| 510 | 516 | const Memory* fragMem[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; |
| r32173 | r32174 | |
| 514 | 520 | |
| 515 | 521 | const Mem mem[] = |
| 516 | 522 | { |
| 517 | | { fs_clear0_dx9, sizeof(fs_clear0_dx9) }, |
| 518 | | { fs_clear1_dx9, sizeof(fs_clear1_dx9) }, |
| 519 | | { fs_clear2_dx9, sizeof(fs_clear2_dx9) }, |
| 520 | | { fs_clear3_dx9, sizeof(fs_clear3_dx9) }, |
| 521 | | { fs_clear4_dx9, sizeof(fs_clear4_dx9) }, |
| 522 | | { fs_clear5_dx9, sizeof(fs_clear5_dx9) }, |
| 523 | | { fs_clear6_dx9, sizeof(fs_clear6_dx9) }, |
| 524 | | { fs_clear7_dx9, sizeof(fs_clear7_dx9) }, |
| 523 | Mem(fs_clear0_dx9, sizeof(fs_clear0_dx9) ), |
| 524 | Mem(fs_clear1_dx9, sizeof(fs_clear1_dx9) ), |
| 525 | Mem(fs_clear2_dx9, sizeof(fs_clear2_dx9) ), |
| 526 | Mem(fs_clear3_dx9, sizeof(fs_clear3_dx9) ), |
| 527 | Mem(fs_clear4_dx9, sizeof(fs_clear4_dx9) ), |
| 528 | Mem(fs_clear5_dx9, sizeof(fs_clear5_dx9) ), |
| 529 | Mem(fs_clear6_dx9, sizeof(fs_clear6_dx9) ), |
| 530 | Mem(fs_clear7_dx9, sizeof(fs_clear7_dx9) ), |
| 525 | 531 | }; |
| 526 | 532 | |
| 527 | 533 | for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii) |
| 528 | 534 | { |
| 529 | | fragMem[ii] = makeRef(mem[ii].data, mem[ii].size); |
| 535 | fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) ); |
| 530 | 536 | } |
| 531 | 537 | } |
| 532 | 538 | else if (RendererType::Direct3D11 == g_caps.rendererType) |
| r32173 | r32174 | |
| 535 | 541 | |
| 536 | 542 | const Mem mem[] = |
| 537 | 543 | { |
| 538 | | { fs_clear0_dx11, sizeof(fs_clear0_dx11) }, |
| 539 | | { fs_clear1_dx11, sizeof(fs_clear1_dx11) }, |
| 540 | | { fs_clear2_dx11, sizeof(fs_clear2_dx11) }, |
| 541 | | { fs_clear3_dx11, sizeof(fs_clear3_dx11) }, |
| 542 | | { fs_clear4_dx11, sizeof(fs_clear4_dx11) }, |
| 543 | | { fs_clear5_dx11, sizeof(fs_clear5_dx11) }, |
| 544 | | { fs_clear6_dx11, sizeof(fs_clear6_dx11) }, |
| 545 | | { fs_clear7_dx11, sizeof(fs_clear7_dx11) }, |
| 544 | Mem(fs_clear0_dx11, sizeof(fs_clear0_dx11) ), |
| 545 | Mem(fs_clear1_dx11, sizeof(fs_clear1_dx11) ), |
| 546 | Mem(fs_clear2_dx11, sizeof(fs_clear2_dx11) ), |
| 547 | Mem(fs_clear3_dx11, sizeof(fs_clear3_dx11) ), |
| 548 | Mem(fs_clear4_dx11, sizeof(fs_clear4_dx11) ), |
| 549 | Mem(fs_clear5_dx11, sizeof(fs_clear5_dx11) ), |
| 550 | Mem(fs_clear6_dx11, sizeof(fs_clear6_dx11) ), |
| 551 | Mem(fs_clear7_dx11, sizeof(fs_clear7_dx11) ), |
| 546 | 552 | }; |
| 547 | 553 | |
| 548 | 554 | for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii) |
| 549 | 555 | { |
| 550 | | fragMem[ii] = makeRef(mem[ii].data, mem[ii].size); |
| 556 | fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) ); |
| 551 | 557 | } |
| 552 | 558 | } |
| 553 | 559 | else if (RendererType::OpenGLES == g_caps.rendererType |
| r32173 | r32174 | |
| 557 | 563 | |
| 558 | 564 | const Mem mem[] = |
| 559 | 565 | { |
| 560 | | { fs_clear0_glsl, sizeof(fs_clear0_glsl) }, |
| 561 | | { fs_clear1_glsl, sizeof(fs_clear1_glsl) }, |
| 562 | | { fs_clear2_glsl, sizeof(fs_clear2_glsl) }, |
| 563 | | { fs_clear3_glsl, sizeof(fs_clear3_glsl) }, |
| 564 | | { fs_clear4_glsl, sizeof(fs_clear4_glsl) }, |
| 565 | | { fs_clear5_glsl, sizeof(fs_clear5_glsl) }, |
| 566 | | { fs_clear6_glsl, sizeof(fs_clear6_glsl) }, |
| 567 | | { fs_clear7_glsl, sizeof(fs_clear7_glsl) }, |
| 566 | Mem(fs_clear0_glsl, sizeof(fs_clear0_glsl) ), |
| 567 | Mem(fs_clear1_glsl, sizeof(fs_clear1_glsl) ), |
| 568 | Mem(fs_clear2_glsl, sizeof(fs_clear2_glsl) ), |
| 569 | Mem(fs_clear3_glsl, sizeof(fs_clear3_glsl) ), |
| 570 | Mem(fs_clear4_glsl, sizeof(fs_clear4_glsl) ), |
| 571 | Mem(fs_clear5_glsl, sizeof(fs_clear5_glsl) ), |
| 572 | Mem(fs_clear6_glsl, sizeof(fs_clear6_glsl) ), |
| 573 | Mem(fs_clear7_glsl, sizeof(fs_clear7_glsl) ), |
| 568 | 574 | }; |
| 569 | 575 | |
| 570 | 576 | for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii) |
| 571 | 577 | { |
| 572 | | fragMem[ii] = makeRef(mem[ii].data, mem[ii].size); |
| 578 | fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) ); |
| 573 | 579 | } |
| 574 | 580 | } |
| 575 | 581 | |
| r32173 | r32174 | |
| 693 | 699 | BX_WARN(invalidHandle != m_key.m_program, "Program with invalid handle"); |
| 694 | 700 | if (invalidHandle != m_key.m_program) |
| 695 | 701 | { |
| 696 | | m_key.m_depth = _depth; |
| 697 | | m_key.m_view = _id; |
| 698 | | m_key.m_seq = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id]; |
| 702 | m_key.m_depth = _depth; |
| 703 | m_key.m_view = _id; |
| 704 | m_key.m_seq = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id]; |
| 699 | 705 | s_ctx->m_seq[_id]++; |
| 706 | |
| 700 | 707 | uint64_t key = m_key.encodeDraw(); |
| 701 | | m_sortKeys[m_num] = key; |
| 708 | m_sortKeys[m_num] = key; |
| 702 | 709 | m_sortValues[m_num] = m_numRenderItems; |
| 703 | 710 | ++m_num; |
| 704 | 711 | |
| r32173 | r32174 | |
| 743 | 750 | viewMask >>= ntz; |
| 744 | 751 | id += ntz; |
| 745 | 752 | |
| 746 | | m_key.m_view = id; |
| 747 | | m_key.m_seq = s_ctx->m_seq[id] & s_ctx->m_seqMask[id]; |
| 753 | m_key.m_view = id; |
| 754 | m_key.m_seq = s_ctx->m_seq[id] & s_ctx->m_seqMask[id]; |
| 748 | 755 | s_ctx->m_seq[id]++; |
| 756 | |
| 749 | 757 | uint64_t key = m_key.encodeDraw(); |
| 750 | | m_sortKeys[m_num] = key; |
| 758 | m_sortKeys[m_num] = key; |
| 751 | 759 | m_sortValues[m_num] = m_numRenderItems; |
| 752 | 760 | ++m_num; |
| 753 | 761 | } |
| r32173 | r32174 | |
| 788 | 796 | m_key.m_program = _handle.idx; |
| 789 | 797 | if (invalidHandle != m_key.m_program) |
| 790 | 798 | { |
| 791 | | m_key.m_depth = 0; |
| 792 | | m_key.m_view = _id; |
| 793 | | m_key.m_seq = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id]; |
| 799 | m_key.m_depth = 0; |
| 800 | m_key.m_view = _id; |
| 801 | m_key.m_seq = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id]; |
| 794 | 802 | s_ctx->m_seq[_id]++; |
| 803 | |
| 795 | 804 | uint64_t key = m_key.encodeCompute(); |
| 796 | | m_sortKeys[m_num] = key; |
| 805 | m_sortKeys[m_num] = key; |
| 797 | 806 | m_sortValues[m_num] = m_numRenderItems; |
| 798 | 807 | ++m_num; |
| 799 | 808 | |
| r32173 | r32174 | |
| 1088 | 1097 | CHECK_HANDLE_LEAK(m_textureHandle); |
| 1089 | 1098 | CHECK_HANDLE_LEAK(m_frameBufferHandle); |
| 1090 | 1099 | CHECK_HANDLE_LEAK(m_uniformHandle); |
| 1091 | | |
| 1092 | 1100 | #undef CHECK_HANDLE_LEAK |
| 1093 | 1101 | } |
| 1094 | 1102 | } |
| r32173 | r32174 | |
| 1775 | 1783 | FrameBufferHandle handle; |
| 1776 | 1784 | _cmdbuf.read(handle); |
| 1777 | 1785 | |
| 1778 | | uint8_t num; |
| 1779 | | _cmdbuf.read(num); |
| 1786 | bool window; |
| 1787 | _cmdbuf.read(window); |
| 1780 | 1788 | |
| 1781 | | TextureHandle textureHandles[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; |
| 1782 | | for (uint32_t ii = 0; ii < num; ++ii) |
| 1789 | if (window) |
| 1783 | 1790 | { |
| 1784 | | _cmdbuf.read(textureHandles[ii]); |
| 1791 | void* nwh; |
| 1792 | _cmdbuf.read(nwh); |
| 1793 | |
| 1794 | uint16_t width; |
| 1795 | _cmdbuf.read(width); |
| 1796 | |
| 1797 | uint16_t height; |
| 1798 | _cmdbuf.read(height); |
| 1799 | |
| 1800 | TextureFormat::Enum depthFormat; |
| 1801 | _cmdbuf.read(depthFormat); |
| 1802 | |
| 1803 | m_renderCtx->createFrameBuffer(handle, nwh, width, height, depthFormat); |
| 1785 | 1804 | } |
| 1805 | else |
| 1806 | { |
| 1807 | uint8_t num; |
| 1808 | _cmdbuf.read(num); |
| 1786 | 1809 | |
| 1787 | | m_renderCtx->createFrameBuffer(handle, num, textureHandles); |
| 1810 | TextureHandle textureHandles[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; |
| 1811 | for (uint32_t ii = 0; ii < num; ++ii) |
| 1812 | { |
| 1813 | _cmdbuf.read(textureHandles[ii]); |
| 1814 | } |
| 1815 | |
| 1816 | m_renderCtx->createFrameBuffer(handle, num, textureHandles); |
| 1817 | } |
| 1788 | 1818 | } |
| 1789 | 1819 | break; |
| 1790 | 1820 | |
| r32173 | r32174 | |
| 2473 | 2503 | return handle; |
| 2474 | 2504 | } |
| 2475 | 2505 | |
| 2506 | FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat) |
| 2507 | { |
| 2508 | BGFX_CHECK_MAIN_THREAD(); |
| 2509 | return s_ctx->createFrameBuffer(_nwh, _width, _height, _depthFormat); |
| 2510 | } |
| 2511 | |
| 2476 | 2512 | void destroyFrameBuffer(FrameBufferHandle _handle) |
| 2477 | 2513 | { |
| 2478 | 2514 | BGFX_CHECK_MAIN_THREAD(); |
| r32173 | r32174 | |
| 3166 | 3202 | return handle.c; |
| 3167 | 3203 | } |
| 3168 | 3204 | |
| 3205 | BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat) |
| 3206 | { |
| 3207 | union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; |
| 3208 | handle.cpp = bgfx::createFrameBuffer(_nwh, _width, _height, bgfx::TextureFormat::Enum(_depthFormat) ); |
| 3209 | return handle.c; |
| 3210 | } |
| 3211 | |
| 3169 | 3212 | BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle) |
| 3170 | 3213 | { |
| 3171 | 3214 | union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; |
| r32173 | r32174 | |
| 3220 | 3263 | bgfx::setViewClear(_id, _flags, _rgba, _depth, _stencil); |
| 3221 | 3264 | } |
| 3222 | 3265 | |
| 3223 | | BGFX_C_API void bgfx_set_view_clear_mrt7(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) |
| 3266 | BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) |
| 3224 | 3267 | { |
| 3225 | 3268 | bgfx::setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); |
| 3226 | 3269 | } |
branches/osd/src/lib/bgfx/renderer_gl.cpp
| r32173 | r32174 | |
| 344 | 344 | |
| 345 | 345 | ATI_meminfo, |
| 346 | 346 | |
| 347 | CHROMIUM_color_buffer_float_rgb, |
| 348 | CHROMIUM_color_buffer_float_rgba, |
| 347 | 349 | CHROMIUM_depth_texture, |
| 348 | 350 | CHROMIUM_framebuffer_multisample, |
| 349 | 351 | CHROMIUM_texture_compression_dxt3, |
| r32173 | r32174 | |
| 356 | 358 | EXT_compressed_ETC1_RGB8_sub_texture, |
| 357 | 359 | EXT_debug_label, |
| 358 | 360 | EXT_debug_marker, |
| 361 | EXT_draw_buffers, |
| 359 | 362 | EXT_frag_depth, |
| 360 | 363 | EXT_framebuffer_blit, |
| 361 | 364 | EXT_framebuffer_object, |
| r32173 | r32174 | |
| 499 | 502 | |
| 500 | 503 | { "ATI_meminfo", false, true }, |
| 501 | 504 | |
| 505 | { "CHROMIUM_color_buffer_float_rgb", false, true }, |
| 506 | { "CHROMIUM_color_buffer_float_rgba", false, true }, |
| 502 | 507 | { "CHROMIUM_depth_texture", false, true }, |
| 503 | 508 | { "CHROMIUM_framebuffer_multisample", false, true }, |
| 504 | 509 | { "CHROMIUM_texture_compression_dxt3", false, true }, |
| r32173 | r32174 | |
| 511 | 516 | { "EXT_compressed_ETC1_RGB8_sub_texture", false, true }, // GLES2 extension. |
| 512 | 517 | { "EXT_debug_label", false, true }, |
| 513 | 518 | { "EXT_debug_marker", false, true }, |
| 519 | { "EXT_draw_buffers", false, true }, // GLES2 extension. |
| 514 | 520 | { "EXT_frag_depth", false, true }, // GLES2 extension. |
| 515 | 521 | { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, |
| 516 | 522 | { "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, |
| r32173 | r32174 | |
| 826 | 832 | struct RendererContextGL : public RendererContextI |
| 827 | 833 | { |
| 828 | 834 | RendererContextGL() |
| 829 | | : m_rtMsaa(false) |
| 835 | : m_numWindows(1) |
| 836 | , m_rtMsaa(false) |
| 830 | 837 | , m_capture(NULL) |
| 831 | 838 | , m_captureSize(0) |
| 832 | 839 | , m_maxAnisotropy(0.0f) |
| r32173 | r32174 | |
| 1169 | 1176 | g_caps.maxTextureSize = glGet(GL_MAX_TEXTURE_SIZE); |
| 1170 | 1177 | |
| 1171 | 1178 | if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) |
| 1172 | | || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) |
| 1179 | || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) |
| 1180 | || s_extension[Extension::EXT_draw_buffers].m_supported) |
| 1173 | 1181 | { |
| 1174 | 1182 | g_caps.maxFBAttachments = bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); |
| 1175 | 1183 | } |
| r32173 | r32174 | |
| 1376 | 1384 | { |
| 1377 | 1385 | if (m_flip) |
| 1378 | 1386 | { |
| 1387 | for (uint32_t ii = 1, num = m_numWindows; ii < num; ++ii) |
| 1388 | { |
| 1389 | m_glctx.swap(m_frameBuffers[m_windows[ii].idx].m_swapChain); |
| 1390 | } |
| 1379 | 1391 | m_glctx.swap(); |
| 1380 | 1392 | } |
| 1381 | 1393 | } |
| r32173 | r32174 | |
| 1491 | 1503 | m_frameBuffers[_handle.idx].create(_num, _textureHandles); |
| 1492 | 1504 | } |
| 1493 | 1505 | |
| 1506 | void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) BX_OVERRIDE |
| 1507 | { |
| 1508 | uint16_t denseIdx = m_numWindows++; |
| 1509 | m_windows[denseIdx] = _handle; |
| 1510 | m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); |
| 1511 | } |
| 1512 | |
| 1494 | 1513 | void destroyFrameBuffer(FrameBufferHandle _handle) BX_OVERRIDE |
| 1495 | 1514 | { |
| 1496 | | m_frameBuffers[_handle.idx].destroy(); |
| 1515 | uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy(); |
| 1516 | if (UINT16_MAX != denseIdx) |
| 1517 | { |
| 1518 | --m_numWindows; |
| 1519 | if (m_numWindows > 1) |
| 1520 | { |
| 1521 | FrameBufferHandle handle = m_windows[m_numWindows]; |
| 1522 | m_windows[denseIdx] = handle; |
| 1523 | m_frameBuffers[handle.idx].m_denseIdx = denseIdx; |
| 1524 | } |
| 1525 | } |
| 1497 | 1526 | } |
| 1498 | 1527 | |
| 1499 | 1528 | void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) BX_OVERRIDE |
| r32173 | r32174 | |
| 1655 | 1684 | frameBuffer.resolve(); |
| 1656 | 1685 | } |
| 1657 | 1686 | |
| 1687 | m_glctx.makeCurrent(NULL); |
| 1688 | |
| 1658 | 1689 | if (!isValid(_fbh) ) |
| 1659 | 1690 | { |
| 1660 | 1691 | GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) ); |
| r32173 | r32174 | |
| 1662 | 1693 | else |
| 1663 | 1694 | { |
| 1664 | 1695 | FrameBufferGL& frameBuffer = m_frameBuffers[_fbh.idx]; |
| 1665 | | GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) ); |
| 1666 | | _height = frameBuffer.m_height; |
| 1696 | if (UINT16_MAX != frameBuffer.m_denseIdx) |
| 1697 | { |
| 1698 | m_glctx.makeCurrent(frameBuffer.m_swapChain); |
| 1699 | GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); |
| 1700 | } |
| 1701 | else |
| 1702 | { |
| 1703 | m_glctx.makeCurrent(NULL); |
| 1704 | GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) ); |
| 1705 | _height = frameBuffer.m_height; |
| 1706 | } |
| 1667 | 1707 | } |
| 1668 | 1708 | |
| 1669 | 1709 | m_fbh = _fbh; |
| r32173 | r32174 | |
| 1764 | 1804 | |
| 1765 | 1805 | #if BX_PLATFORM_IOS |
| 1766 | 1806 | // iOS: need to figure out how to deal with FBO created by context. |
| 1767 | | m_backBufferFbo = m_glctx.m_fbo; |
| 1768 | | m_msaaBackBufferFbo = m_glctx.m_fbo; |
| 1807 | m_backBufferFbo = m_msaaBackBufferFbo = m_glctx.getFbo(); |
| 1769 | 1808 | #endif // BX_PLATFORM_IOS |
| 1770 | 1809 | } |
| 1771 | 1810 | else |
| r32173 | r32174 | |
| 2203 | 2242 | } |
| 2204 | 2243 | } |
| 2205 | 2244 | |
| 2245 | uint16_t m_numWindows; |
| 2246 | FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; |
| 2247 | |
| 2206 | 2248 | IndexBufferGL m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; |
| 2207 | 2249 | VertexBufferGL m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; |
| 2208 | 2250 | ShaderGL m_shaders[BGFX_CONFIG_MAX_SHADERS]; |
| r32173 | r32174 | |
| 3387 | 3429 | && bx::findIdentifierMatch(code, s_OES_standard_derivatives) |
| 3388 | 3430 | ; |
| 3389 | 3431 | |
| 3432 | bool usesFragData = !!bx::findIdentifierMatch(code, "gl_FragData"); |
| 3433 | |
| 3390 | 3434 | bool usesFragDepth = !!bx::findIdentifierMatch(code, "gl_FragDepth"); |
| 3391 | 3435 | |
| 3392 | 3436 | bool usesShadowSamplers = !!bx::findIdentifierMatch(code, s_EXT_shadow_samplers); |
| r32173 | r32174 | |
| 3404 | 3448 | writeString(&writer, "#extension GL_OES_standard_derivatives : enable\n"); |
| 3405 | 3449 | } |
| 3406 | 3450 | |
| 3451 | if (usesFragData) |
| 3452 | { |
| 3453 | BX_WARN(s_extension[Extension::EXT_draw_buffers].m_supported, "EXT_draw_buffers is used but not supported by GLES2 driver."); |
| 3454 | writeString(&writer |
| 3455 | , "#extension GL_EXT_draw_buffers : enable\n" |
| 3456 | ); |
| 3457 | } |
| 3458 | |
| 3407 | 3459 | bool insertFragDepth = false; |
| 3408 | 3460 | if (usesFragDepth) |
| 3409 | 3461 | { |
| r32173 | r32174 | |
| 3700 | 3752 | GL_CHECK(glGenFramebuffers(1, &m_fbo[0]) ); |
| 3701 | 3753 | GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) ); |
| 3702 | 3754 | |
| 3755 | // m_denseIdx = UINT16_MAX; |
| 3703 | 3756 | bool needResolve = false; |
| 3704 | 3757 | |
| 3705 | 3758 | GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; |
| r32173 | r32174 | |
| 3807 | 3860 | GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) ); |
| 3808 | 3861 | } |
| 3809 | 3862 | |
| 3810 | | void FrameBufferGL::destroy() |
| 3863 | void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) |
| 3811 | 3864 | { |
| 3865 | BX_UNUSED(_depthFormat); |
| 3866 | m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh); |
| 3867 | m_width = _width; |
| 3868 | m_height = _height; |
| 3869 | m_denseIdx = _denseIdx; |
| 3870 | } |
| 3871 | |
| 3872 | uint16_t FrameBufferGL::destroy() |
| 3873 | { |
| 3812 | 3874 | GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) ); |
| 3813 | 3875 | memset(m_fbo, 0, sizeof(m_fbo) ); |
| 3814 | 3876 | m_num = 0; |
| 3877 | |
| 3878 | if (NULL != m_swapChain) |
| 3879 | { |
| 3880 | s_renderGL->m_glctx.destorySwapChain(m_swapChain); |
| 3881 | m_swapChain = NULL; |
| 3882 | } |
| 3883 | |
| 3884 | uint16_t denseIdx = m_denseIdx; |
| 3885 | m_denseIdx = UINT16_MAX; |
| 3886 | |
| 3887 | return denseIdx; |
| 3815 | 3888 | } |
| 3816 | 3889 | |
| 3817 | 3890 | void FrameBufferGL::resolve() |
| r32173 | r32174 | |
| 3840 | 3913 | |
| 3841 | 3914 | void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) |
| 3842 | 3915 | { |
| 3916 | m_glctx.makeCurrent(NULL); |
| 3917 | |
| 3843 | 3918 | const GLuint defaultVao = s_renderGL->m_vao; |
| 3844 | 3919 | if (0 != defaultVao) |
| 3845 | 3920 | { |
| r32173 | r32174 | |
| 4733 | 4808 | } |
| 4734 | 4809 | } |
| 4735 | 4810 | |
| 4811 | m_glctx.makeCurrent(NULL); |
| 4736 | 4812 | int64_t now = bx::getHPCounter(); |
| 4737 | 4813 | elapsed += now; |
| 4738 | 4814 | |
branches/osd/src/lib/bgfx/renderer_d3d9.cpp
| r32173 | r32174 | |
| 259 | 259 | RendererContextD3D9() |
| 260 | 260 | : m_d3d9(NULL) |
| 261 | 261 | , m_device(NULL) |
| 262 | | , m_backBufferColor(NULL) |
| 263 | | , m_backBufferDepthStencil(NULL) |
| 264 | 262 | , m_captureTexture(NULL) |
| 265 | 263 | , m_captureSurface(NULL) |
| 266 | 264 | , m_captureResolve(NULL) |
| r32173 | r32174 | |
| 292 | 290 | m_params.FullScreen_RefreshRateInHz = 0; |
| 293 | 291 | m_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; |
| 294 | 292 | m_params.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 295 | | m_params.hDeviceWindow = g_bgfxHwnd; |
| 293 | m_params.hDeviceWindow = NULL; |
| 296 | 294 | m_params.Windowed = true; |
| 297 | 295 | |
| 298 | 296 | RECT rect; |
| r32173 | r32174 | |
| 304 | 302 | BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll."); |
| 305 | 303 | |
| 306 | 304 | #if BGFX_CONFIG_DEBUG_PIX |
| 307 | | m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker"); |
| 305 | m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker"); |
| 308 | 306 | m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent"); |
| 309 | | m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent"); |
| 307 | m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent"); |
| 310 | 308 | |
| 311 | 309 | BX_CHECK(NULL != m_D3DPERF_SetMarker |
| 312 | 310 | && NULL != m_D3DPERF_BeginEvent |
| r32173 | r32174 | |
| 373 | 371 | |
| 374 | 372 | uint32_t behaviorFlags[] = |
| 375 | 373 | { |
| 376 | | D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE|D3DCREATE_FPU_PRESERVE, |
| 377 | | D3DCREATE_MIXED_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE, |
| 378 | | D3DCREATE_SOFTWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE, |
| 374 | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_PUREDEVICE, |
| 375 | D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, |
| 376 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, |
| 379 | 377 | }; |
| 380 | 378 | |
| 381 | 379 | for (uint32_t ii = 0; ii < BX_COUNTOF(behaviorFlags) && NULL == m_device; ++ii) |
| r32173 | r32174 | |
| 402 | 400 | |
| 403 | 401 | BGFX_FATAL(m_device, Fatal::UnableToInitialize, "Unable to create Direct3D9 device."); |
| 404 | 402 | |
| 403 | m_numWindows = 1; |
| 404 | |
| 405 | 405 | #if BGFX_CONFIG_RENDERER_DIRECT3D9EX |
| 406 | 406 | if (NULL != m_d3d9ex) |
| 407 | 407 | { |
| r32173 | r32174 | |
| 711 | 711 | m_frameBuffers[_handle.idx].create(_num, _textureHandles); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) BX_OVERRIDE |
| 715 | { |
| 716 | uint16_t denseIdx = m_numWindows++; |
| 717 | m_windows[denseIdx] = _handle; |
| 718 | m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); |
| 719 | } |
| 720 | |
| 714 | 721 | void destroyFrameBuffer(FrameBufferHandle _handle) BX_OVERRIDE |
| 715 | 722 | { |
| 716 | | m_frameBuffers[_handle.idx].destroy(); |
| 723 | uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy(); |
| 724 | if (UINT16_MAX != denseIdx) |
| 725 | { |
| 726 | --m_numWindows; |
| 727 | if (m_numWindows > 1) |
| 728 | { |
| 729 | FrameBufferHandle handle = m_windows[m_numWindows]; |
| 730 | m_windows[denseIdx] = handle; |
| 731 | m_frameBuffers[handle.idx].m_denseIdx = denseIdx; |
| 732 | } |
| 733 | } |
| 717 | 734 | } |
| 718 | 735 | |
| 719 | 736 | void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) BX_OVERRIDE |
| r32173 | r32174 | |
| 902 | 919 | |
| 903 | 920 | void updateResolution(const Resolution& _resolution) |
| 904 | 921 | { |
| 905 | | if (m_params.BackBufferWidth != _resolution.m_width |
| 906 | | || m_params.BackBufferHeight != _resolution.m_height |
| 907 | | || m_flags != _resolution.m_flags) |
| 922 | if (m_params.BackBufferWidth != _resolution.m_width |
| 923 | || m_params.BackBufferHeight != _resolution.m_height |
| 924 | || m_flags != _resolution.m_flags) |
| 908 | 925 | { |
| 909 | 926 | m_flags = _resolution.m_flags; |
| 910 | 927 | |
| r32173 | r32174 | |
| 921 | 938 | m_params.BackBufferFormat = dm.Format; |
| 922 | 939 | #endif // BX_PLATFORM_WINDOWS |
| 923 | 940 | |
| 924 | | m_params.BackBufferWidth = _resolution.m_width; |
| 941 | m_params.BackBufferWidth = _resolution.m_width; |
| 925 | 942 | m_params.BackBufferHeight = _resolution.m_height; |
| 926 | 943 | m_params.FullScreen_RefreshRateInHz = BGFX_RESET_FULLSCREEN == (m_flags&BGFX_RESET_FULLSCREEN_MASK) ? 60 : 0; |
| 927 | 944 | m_params.PresentationInterval = !!(m_flags&BGFX_RESET_VSYNC) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; |
| r32173 | r32174 | |
| 929 | 946 | updateMsaa(); |
| 930 | 947 | |
| 931 | 948 | Msaa& msaa = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; |
| 932 | | m_params.MultiSampleType = msaa.m_type; |
| 949 | m_params.MultiSampleType = msaa.m_type; |
| 933 | 950 | m_params.MultiSampleQuality = msaa.m_quality; |
| 934 | 951 | |
| 935 | 952 | m_resolution = _resolution; |
| r32173 | r32174 | |
| 1033 | 1050 | } |
| 1034 | 1051 | #endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX |
| 1035 | 1052 | |
| 1036 | | HRESULT hr; |
| 1037 | | hr = m_device->Present(NULL, NULL, NULL, NULL); |
| 1053 | for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) |
| 1054 | { |
| 1055 | HRESULT hr; |
| 1056 | if (0 == ii) |
| 1057 | { |
| 1058 | hr = m_swapChain->Present(NULL, NULL, g_bgfxHwnd, NULL, 0); |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | hr = m_frameBuffers[m_windows[ii].idx].present(); |
| 1063 | } |
| 1038 | 1064 | |
| 1039 | 1065 | #if BX_PLATFORM_WINDOWS |
| 1040 | | if (isLost(hr) ) |
| 1041 | | { |
| 1042 | | do |
| 1066 | if (isLost(hr) ) |
| 1043 | 1067 | { |
| 1044 | | do |
| 1068 | do |
| 1045 | 1069 | { |
| 1070 | do |
| 1071 | { |
| 1072 | hr = m_device->TestCooperativeLevel(); |
| 1073 | } |
| 1074 | while (D3DERR_DEVICENOTRESET != hr); |
| 1075 | |
| 1076 | reset(); |
| 1046 | 1077 | hr = m_device->TestCooperativeLevel(); |
| 1047 | 1078 | } |
| 1048 | | while (D3DERR_DEVICENOTRESET != hr); |
| 1079 | while (FAILED(hr) ); |
| 1049 | 1080 | |
| 1050 | | reset(); |
| 1051 | | hr = m_device->TestCooperativeLevel(); |
| 1081 | break; |
| 1052 | 1082 | } |
| 1053 | | while (FAILED(hr) ); |
| 1083 | else if (FAILED(hr) ) |
| 1084 | { |
| 1085 | BX_TRACE("Present failed with err 0x%08x.", hr); |
| 1086 | } |
| 1087 | #endif // BX_PLATFORM_ |
| 1054 | 1088 | } |
| 1055 | | else if (FAILED(hr) ) |
| 1056 | | { |
| 1057 | | BX_TRACE("Present failed with err 0x%08x.", hr); |
| 1058 | | } |
| 1059 | | #endif // BX_PLATFORM_ |
| 1060 | 1089 | } |
| 1061 | 1090 | } |
| 1062 | 1091 | |
| r32173 | r32174 | |
| 1082 | 1111 | |
| 1083 | 1112 | DX_RELEASE(m_backBufferColor, 0); |
| 1084 | 1113 | DX_RELEASE(m_backBufferDepthStencil, 0); |
| 1114 | DX_RELEASE(m_swapChain, 0); |
| 1085 | 1115 | |
| 1086 | 1116 | capturePreReset(); |
| 1087 | 1117 | |
| r32173 | r32174 | |
| 1108 | 1138 | |
| 1109 | 1139 | void postReset() |
| 1110 | 1140 | { |
| 1111 | | DX_CHECK(m_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) ); |
| 1141 | DX_CHECK(m_device->GetSwapChain(0, &m_swapChain) ); |
| 1142 | DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) ); |
| 1112 | 1143 | DX_CHECK(m_device->GetDepthStencilSurface(&m_backBufferDepthStencil) ); |
| 1113 | 1144 | |
| 1114 | 1145 | capturePostReset(); |
| r32173 | r32174 | |
| 1179 | 1210 | { |
| 1180 | 1211 | if (m_flags&BGFX_RESET_CAPTURE) |
| 1181 | 1212 | { |
| 1182 | | uint32_t width = m_params.BackBufferWidth; |
| 1213 | uint32_t width = m_params.BackBufferWidth; |
| 1183 | 1214 | uint32_t height = m_params.BackBufferHeight; |
| 1184 | | D3DFORMAT fmt = m_params.BackBufferFormat; |
| 1215 | D3DFORMAT fmt = m_params.BackBufferFormat; |
| 1185 | 1216 | |
| 1186 | 1217 | DX_CHECK(m_device->CreateTexture(width |
| 1187 | 1218 | , height |
| r32173 | r32174 | |
| 1567 | 1598 | IDirect3DDevice9* m_device; |
| 1568 | 1599 | D3DPOOL m_pool; |
| 1569 | 1600 | |
| 1601 | IDirect3DSwapChain9* m_swapChain; |
| 1602 | uint16_t m_numWindows; |
| 1603 | FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; |
| 1604 | |
| 1570 | 1605 | IDirect3DSurface9* m_backBufferColor; |
| 1571 | 1606 | IDirect3DSurface9* m_backBufferDepthStencil; |
| 1572 | 1607 | |
| r32173 | r32174 | |
| 2502 | 2537 | } |
| 2503 | 2538 | } |
| 2504 | 2539 | |
| 2505 | | void FrameBufferD3D9::destroy() |
| 2540 | void FrameBufferD3D9::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) |
| 2506 | 2541 | { |
| 2507 | | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2508 | | { |
| 2509 | | m_colorHandle[ii].idx = invalidHandle; |
| 2542 | BX_UNUSED(_width, _height, _depthFormat); |
| 2510 | 2543 | |
| 2511 | | IDirect3DSurface9* ptr = m_color[ii]; |
| 2512 | | if (NULL != ptr) |
| 2513 | | { |
| 2514 | | ptr->Release(); |
| 2515 | | m_color[ii] = NULL; |
| 2516 | | } |
| 2517 | | } |
| 2544 | m_hwnd = (HWND)_nwh; |
| 2545 | DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&s_renderD3D9->m_params, &m_swapChain) ); |
| 2546 | DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_color[0]) ); |
| 2547 | m_colorHandle[0].idx = invalidHandle; |
| 2548 | m_depthStencil = NULL; |
| 2549 | m_denseIdx = _denseIdx; |
| 2550 | m_num = 1; |
| 2551 | m_needResolve = false; |
| 2552 | } |
| 2518 | 2553 | |
| 2519 | | if (NULL != m_depthStencil) |
| 2554 | uint16_t FrameBufferD3D9::destroy() |
| 2555 | { |
| 2556 | if (NULL != m_hwnd) |
| 2520 | 2557 | { |
| 2521 | | if (0 == m_num) |
| 2558 | DX_RELEASE(m_color[0], 0); |
| 2559 | DX_RELEASE(m_swapChain, 0); |
| 2560 | } |
| 2561 | else |
| 2562 | { |
| 2563 | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2522 | 2564 | { |
| 2523 | | IDirect3DSurface9* ptr = m_color[0]; |
| 2565 | m_colorHandle[ii].idx = invalidHandle; |
| 2566 | |
| 2567 | IDirect3DSurface9* ptr = m_color[ii]; |
| 2524 | 2568 | if (NULL != ptr) |
| 2525 | 2569 | { |
| 2526 | 2570 | ptr->Release(); |
| 2527 | | m_color[0] = NULL; |
| 2571 | m_color[ii] = NULL; |
| 2528 | 2572 | } |
| 2529 | 2573 | } |
| 2530 | 2574 | |
| 2531 | | m_depthStencil->Release(); |
| 2532 | | m_depthStencil = NULL; |
| 2575 | if (NULL != m_depthStencil) |
| 2576 | { |
| 2577 | if (0 == m_num) |
| 2578 | { |
| 2579 | IDirect3DSurface9* ptr = m_color[0]; |
| 2580 | if (NULL != ptr) |
| 2581 | { |
| 2582 | ptr->Release(); |
| 2583 | m_color[0] = NULL; |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | m_depthStencil->Release(); |
| 2588 | m_depthStencil = NULL; |
| 2589 | } |
| 2533 | 2590 | } |
| 2534 | 2591 | |
| 2592 | m_hwnd = NULL; |
| 2535 | 2593 | m_num = 0; |
| 2536 | 2594 | m_depthHandle.idx = invalidHandle; |
| 2595 | |
| 2596 | uint16_t denseIdx = m_denseIdx; |
| 2597 | m_denseIdx = UINT16_MAX; |
| 2598 | |
| 2599 | return denseIdx; |
| 2537 | 2600 | } |
| 2538 | 2601 | |
| 2602 | HRESULT FrameBufferD3D9::present() |
| 2603 | { |
| 2604 | return m_swapChain->Present(NULL, NULL, m_hwnd, NULL, 0); |
| 2605 | } |
| 2606 | |
| 2539 | 2607 | void FrameBufferD3D9::resolve() const |
| 2540 | 2608 | { |
| 2541 | 2609 | if (m_needResolve) |
| r32173 | r32174 | |
| 2556 | 2624 | |
| 2557 | 2625 | void FrameBufferD3D9::preReset() |
| 2558 | 2626 | { |
| 2559 | | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2627 | if (NULL != m_hwnd) |
| 2560 | 2628 | { |
| 2561 | | m_color[ii]->Release(); |
| 2562 | | m_color[ii] = NULL; |
| 2629 | DX_RELEASE(m_color[0], 0); |
| 2630 | DX_RELEASE(m_swapChain, 0); |
| 2563 | 2631 | } |
| 2564 | | |
| 2565 | | if (isValid(m_depthHandle) ) |
| 2632 | else |
| 2566 | 2633 | { |
| 2567 | | if (0 == m_num) |
| 2634 | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2568 | 2635 | { |
| 2569 | | m_color[0]->Release(); |
| 2570 | | m_color[0] = NULL; |
| 2636 | m_color[ii]->Release(); |
| 2637 | m_color[ii] = NULL; |
| 2571 | 2638 | } |
| 2572 | 2639 | |
| 2573 | | m_depthStencil->Release(); |
| 2574 | | m_depthStencil = NULL; |
| 2640 | if (isValid(m_depthHandle) ) |
| 2641 | { |
| 2642 | if (0 == m_num) |
| 2643 | { |
| 2644 | m_color[0]->Release(); |
| 2645 | m_color[0] = NULL; |
| 2646 | } |
| 2647 | |
| 2648 | m_depthStencil->Release(); |
| 2649 | m_depthStencil = NULL; |
| 2650 | } |
| 2575 | 2651 | } |
| 2576 | 2652 | } |
| 2577 | 2653 | |
| 2578 | 2654 | void FrameBufferD3D9::postReset() |
| 2579 | 2655 | { |
| 2580 | | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2656 | if (NULL != m_hwnd) |
| 2581 | 2657 | { |
| 2582 | | TextureD3D9& texture = s_renderD3D9->m_textures[m_colorHandle[ii].idx]; |
| 2583 | | if (NULL != texture.m_surface) |
| 2584 | | { |
| 2585 | | m_color[ii] = texture.m_surface; |
| 2586 | | m_color[ii]->AddRef(); |
| 2587 | | } |
| 2588 | | else |
| 2589 | | { |
| 2590 | | DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_color[ii]) ); |
| 2591 | | } |
| 2658 | DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&s_renderD3D9->m_params, &m_swapChain) ); |
| 2659 | DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_color[0]) ); |
| 2592 | 2660 | } |
| 2593 | | |
| 2594 | | if (isValid(m_depthHandle) ) |
| 2661 | else |
| 2595 | 2662 | { |
| 2596 | | TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx]; |
| 2597 | | if (NULL != texture.m_surface) |
| 2663 | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2598 | 2664 | { |
| 2599 | | m_depthStencil = texture.m_surface; |
| 2600 | | m_depthStencil->AddRef(); |
| 2665 | TextureHandle th = m_colorHandle[ii]; |
| 2666 | |
| 2667 | if (isValid(th) ) |
| 2668 | { |
| 2669 | TextureD3D9& texture = s_renderD3D9->m_textures[th.idx]; |
| 2670 | if (NULL != texture.m_surface) |
| 2671 | { |
| 2672 | m_color[ii] = texture.m_surface; |
| 2673 | m_color[ii]->AddRef(); |
| 2674 | } |
| 2675 | else |
| 2676 | { |
| 2677 | DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_color[ii]) ); |
| 2678 | } |
| 2679 | } |
| 2601 | 2680 | } |
| 2602 | | else |
| 2681 | |
| 2682 | if (isValid(m_depthHandle) ) |
| 2603 | 2683 | { |
| 2604 | | DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_depthStencil) ); |
| 2605 | | } |
| 2684 | TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx]; |
| 2685 | if (NULL != texture.m_surface) |
| 2686 | { |
| 2687 | m_depthStencil = texture.m_surface; |
| 2688 | m_depthStencil->AddRef(); |
| 2689 | } |
| 2690 | else |
| 2691 | { |
| 2692 | DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_depthStencil) ); |
| 2693 | } |
| 2606 | 2694 | |
| 2607 | | if (0 == m_num) |
| 2608 | | { |
| 2609 | | createNullColorRT(); |
| 2695 | if (0 == m_num) |
| 2696 | { |
| 2697 | createNullColorRT(); |
| 2698 | } |
| 2610 | 2699 | } |
| 2611 | 2700 | } |
| 2612 | 2701 | } |
branches/osd/src/lib/bgfx/renderer_d3d11.cpp
| r32173 | r32174 | |
| 515 | 515 | }; |
| 516 | 516 | |
| 517 | 517 | memset(&m_scd, 0, sizeof(m_scd) ); |
| 518 | | m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; |
| 518 | m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; |
| 519 | 519 | m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; |
| 520 | 520 | m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; |
| 521 | 521 | m_scd.BufferDesc.RefreshRate.Numerator = 60; |
| r32173 | r32174 | |
| 573 | 573 | ); |
| 574 | 574 | BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain."); |
| 575 | 575 | |
| 576 | m_numWindows = 1; |
| 577 | |
| 576 | 578 | if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) |
| 577 | 579 | { |
| 578 | 580 | ID3D11InfoQueue* infoQueue; |
| r32173 | r32174 | |
| 792 | 794 | m_frameBuffers[_handle.idx].create(_num, _textureHandles); |
| 793 | 795 | } |
| 794 | 796 | |
| 797 | void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) BX_OVERRIDE |
| 798 | { |
| 799 | uint16_t denseIdx = m_numWindows++; |
| 800 | m_windows[denseIdx] = _handle; |
| 801 | m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); |
| 802 | } |
| 803 | |
| 795 | 804 | void destroyFrameBuffer(FrameBufferHandle _handle) BX_OVERRIDE |
| 796 | 805 | { |
| 797 | | m_frameBuffers[_handle.idx].destroy(); |
| 806 | uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy(); |
| 807 | if (UINT16_MAX != denseIdx) |
| 808 | { |
| 809 | --m_numWindows; |
| 810 | if (m_numWindows > 1) |
| 811 | { |
| 812 | FrameBufferHandle handle = m_windows[m_numWindows]; |
| 813 | m_windows[denseIdx] = handle; |
| 814 | m_frameBuffers[handle.idx].m_denseIdx = denseIdx; |
| 815 | } |
| 816 | } |
| 798 | 817 | } |
| 799 | 818 | |
| 800 | 819 | void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) BX_OVERRIDE |
| r32173 | r32174 | |
| 1013 | 1032 | if (NULL != m_swapChain) |
| 1014 | 1033 | { |
| 1015 | 1034 | uint32_t syncInterval = !!(m_flags & BGFX_RESET_VSYNC); |
| 1035 | for (uint32_t ii = 1, num = m_numWindows; ii < num; ++ii) |
| 1036 | { |
| 1037 | DX_CHECK(m_frameBuffers[m_windows[ii].idx].m_swapChain->Present(syncInterval, 0) ); |
| 1038 | } |
| 1016 | 1039 | DX_CHECK(m_swapChain->Present(syncInterval, 0) ); |
| 1017 | 1040 | } |
| 1018 | 1041 | } |
| r32173 | r32174 | |
| 1820 | 1843 | IDXGIAdapter* m_adapter; |
| 1821 | 1844 | DXGI_ADAPTER_DESC m_adapterDesc; |
| 1822 | 1845 | IDXGIFactory* m_factory; |
| 1846 | |
| 1823 | 1847 | IDXGISwapChain* m_swapChain; |
| 1848 | uint16_t m_numWindows; |
| 1849 | FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; |
| 1850 | |
| 1824 | 1851 | ID3D11Device* m_device; |
| 1825 | 1852 | ID3D11DeviceContext* m_deviceCtx; |
| 1826 | 1853 | ID3D11RenderTargetView* m_backBufferColor; |
| r32173 | r32174 | |
| 2442 | 2469 | { |
| 2443 | 2470 | m_rtv[ii] = NULL; |
| 2444 | 2471 | } |
| 2445 | | m_dsv = NULL; |
| 2472 | m_dsv = NULL; |
| 2473 | m_swapChain = NULL; |
| 2446 | 2474 | |
| 2447 | 2475 | m_num = 0; |
| 2448 | 2476 | for (uint32_t ii = 0; ii < _num; ++ii) |
| r32173 | r32174 | |
| 2475 | 2503 | } |
| 2476 | 2504 | } |
| 2477 | 2505 | |
| 2478 | | void FrameBufferD3D11::destroy() |
| 2506 | void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) |
| 2479 | 2507 | { |
| 2508 | BX_UNUSED(_depthFormat); |
| 2509 | |
| 2510 | DXGI_SWAP_CHAIN_DESC scd; |
| 2511 | memcpy(&scd, &s_renderD3D11->m_scd, sizeof(DXGI_SWAP_CHAIN_DESC) ); |
| 2512 | scd.BufferDesc.Width = _width; |
| 2513 | scd.BufferDesc.Height = _height; |
| 2514 | scd.OutputWindow = (HWND)_nwh; |
| 2515 | |
| 2516 | HRESULT hr; |
| 2517 | hr = s_renderD3D11->m_factory->CreateSwapChain(s_renderD3D11->m_device |
| 2518 | , &scd |
| 2519 | , &m_swapChain |
| 2520 | ); |
| 2521 | BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain."); |
| 2522 | |
| 2523 | ID3D11Resource* ptr; |
| 2524 | DX_CHECK(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&ptr) ); |
| 2525 | DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(ptr, NULL, &m_rtv[0]) ); |
| 2526 | DX_RELEASE(ptr, 0); |
| 2527 | m_srv[0] = NULL; |
| 2528 | m_dsv = NULL; |
| 2529 | m_denseIdx = _denseIdx; |
| 2530 | m_num = 1; |
| 2531 | } |
| 2532 | |
| 2533 | uint16_t FrameBufferD3D11::destroy() |
| 2534 | { |
| 2480 | 2535 | for (uint32_t ii = 0, num = m_num; ii < num; ++ii) |
| 2481 | 2536 | { |
| 2482 | 2537 | DX_RELEASE(m_srv[ii], 0); |
| r32173 | r32174 | |
| 2484 | 2539 | } |
| 2485 | 2540 | |
| 2486 | 2541 | DX_RELEASE(m_dsv, 0); |
| 2542 | DX_RELEASE(m_swapChain, 0); |
| 2487 | 2543 | |
| 2488 | 2544 | m_num = 0; |
| 2545 | |
| 2546 | uint16_t denseIdx = m_denseIdx; |
| 2547 | m_denseIdx = UINT16_MAX; |
| 2548 | |
| 2549 | return denseIdx; |
| 2489 | 2550 | } |
| 2490 | 2551 | |
| 2491 | 2552 | void FrameBufferD3D11::resolve() |
branches/osd/src/lib/bgfx/bgfx_p.h
| r32173 | r32174 | |
| 640 | 640 | }; |
| 641 | 641 | |
| 642 | 642 | #define SORT_KEY_RENDER_DRAW UINT64_C(0x0000000800000000) |
| 643 | |
| 644 | BX_STATIC_ASSERT(BGFX_CONFIG_MAX_VIEWS <= 32); |
| 645 | BX_STATIC_ASSERT( (BGFX_CONFIG_MAX_PROGRAMS & (BGFX_CONFIG_MAX_PROGRAMS-1) ) == 0); // must be power of 2 |
| 646 | |
| 643 | 647 | struct SortKey |
| 644 | 648 | { |
| 645 | 649 | uint64_t encodeDraw() |
| r32173 | r32174 | |
| 1422 | 1426 | |
| 1423 | 1427 | void resetFreeHandles() |
| 1424 | 1428 | { |
| 1425 | | m_numFreeIndexBufferHandles = 0; |
| 1426 | | m_numFreeVertexDeclHandles = 0; |
| 1429 | m_numFreeIndexBufferHandles = 0; |
| 1430 | m_numFreeVertexDeclHandles = 0; |
| 1427 | 1431 | m_numFreeVertexBufferHandles = 0; |
| 1428 | | m_numFreeShaderHandles = 0; |
| 1429 | | m_numFreeProgramHandles = 0; |
| 1430 | | m_numFreeTextureHandles = 0; |
| 1431 | | m_numFreeFrameBufferHandles = 0; |
| 1432 | | m_numFreeUniformHandles = 0; |
| 1432 | m_numFreeShaderHandles = 0; |
| 1433 | m_numFreeProgramHandles = 0; |
| 1434 | m_numFreeTextureHandles = 0; |
| 1435 | m_numFreeFrameBufferHandles = 0; |
| 1436 | m_numFreeUniformHandles = 0; |
| 1433 | 1437 | } |
| 1434 | 1438 | |
| 1435 | 1439 | SortKey m_key; |
| r32173 | r32174 | |
| 1479 | 1483 | uint16_t m_numFreeTextureHandles; |
| 1480 | 1484 | uint16_t m_numFreeFrameBufferHandles; |
| 1481 | 1485 | uint16_t m_numFreeUniformHandles; |
| 1486 | uint16_t m_numFreeWindowHandles; |
| 1482 | 1487 | |
| 1483 | 1488 | IndexBufferHandle m_freeIndexBufferHandle[BGFX_CONFIG_MAX_INDEX_BUFFERS]; |
| 1484 | 1489 | VertexDeclHandle m_freeVertexDeclHandle[BGFX_CONFIG_MAX_VERTEX_DECLS]; |
| r32173 | r32174 | |
| 1696 | 1701 | virtual void updateTextureEnd() = 0; |
| 1697 | 1702 | virtual void destroyTexture(TextureHandle _handle) = 0; |
| 1698 | 1703 | virtual void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const TextureHandle* _textureHandles) = 0; |
| 1704 | virtual void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) = 0; |
| 1699 | 1705 | virtual void destroyFrameBuffer(FrameBufferHandle _handle) = 0; |
| 1700 | 1706 | virtual void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) = 0; |
| 1701 | 1707 | virtual void destroyUniform(UniformHandle _handle) = 0; |
| r32173 | r32174 | |
| 2464 | 2470 | BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles) ) |
| 2465 | 2471 | { |
| 2466 | 2472 | FrameBufferHandle handle = { m_frameBufferHandle.alloc() }; |
| 2467 | | BX_WARN(isValid(handle), "Failed to allocate render target handle."); |
| 2473 | BX_WARN(isValid(handle), "Failed to allocate frame buffer handle."); |
| 2468 | 2474 | |
| 2469 | 2475 | if (isValid(handle) ) |
| 2470 | 2476 | { |
| 2471 | 2477 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateFrameBuffer); |
| 2472 | 2478 | cmdbuf.write(handle); |
| 2479 | cmdbuf.write(false); |
| 2473 | 2480 | cmdbuf.write(_num); |
| 2474 | 2481 | |
| 2475 | 2482 | FrameBufferRef& ref = m_frameBufferRef[handle.idx]; |
| 2476 | | memset(ref.m_th, 0xff, sizeof(ref.m_th) ); |
| 2483 | ref.m_window = false; |
| 2484 | memset(ref.un.m_th, 0xff, sizeof(ref.un.m_th) ); |
| 2477 | 2485 | for (uint32_t ii = 0; ii < _num; ++ii) |
| 2478 | 2486 | { |
| 2479 | 2487 | TextureHandle handle = _handles[ii]; |
| 2480 | 2488 | |
| 2481 | 2489 | cmdbuf.write(handle); |
| 2482 | 2490 | |
| 2483 | | ref.m_th[ii] = handle; |
| 2491 | ref.un.m_th[ii] = handle; |
| 2484 | 2492 | textureIncRef(handle); |
| 2485 | 2493 | } |
| 2486 | 2494 | } |
| r32173 | r32174 | |
| 2488 | 2496 | return handle; |
| 2489 | 2497 | } |
| 2490 | 2498 | |
| 2499 | BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat) ) |
| 2500 | { |
| 2501 | FrameBufferHandle handle = { m_frameBufferHandle.alloc() }; |
| 2502 | BX_WARN(isValid(handle), "Failed to allocate frame buffer handle."); |
| 2503 | |
| 2504 | if (isValid(handle) ) |
| 2505 | { |
| 2506 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateFrameBuffer); |
| 2507 | cmdbuf.write(handle); |
| 2508 | cmdbuf.write(true); |
| 2509 | cmdbuf.write(_nwh); |
| 2510 | cmdbuf.write(_width); |
| 2511 | cmdbuf.write(_height); |
| 2512 | cmdbuf.write(_depthFormat); |
| 2513 | |
| 2514 | FrameBufferRef& ref = m_frameBufferRef[handle.idx]; |
| 2515 | ref.m_window = true; |
| 2516 | ref.un.m_nwh = _nwh; |
| 2517 | } |
| 2518 | |
| 2519 | return handle; |
| 2520 | } |
| 2521 | |
| 2491 | 2522 | BGFX_API_FUNC(void destroyFrameBuffer(FrameBufferHandle _handle) ) |
| 2492 | 2523 | { |
| 2493 | 2524 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyFrameBuffer); |
| r32173 | r32174 | |
| 2495 | 2526 | m_submit->free(_handle); |
| 2496 | 2527 | |
| 2497 | 2528 | FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; |
| 2498 | | for (uint32_t ii = 0; ii < BX_COUNTOF(ref.m_th); ++ii) |
| 2529 | if (!ref.m_window) |
| 2499 | 2530 | { |
| 2500 | | TextureHandle th = ref.m_th[ii]; |
| 2501 | | if (isValid(th) ) |
| 2531 | for (uint32_t ii = 0; ii < BX_COUNTOF(ref.un.m_th); ++ii) |
| 2502 | 2532 | { |
| 2503 | | textureDecRef(th); |
| 2533 | TextureHandle th = ref.un.m_th[ii]; |
| 2534 | if (isValid(th) ) |
| 2535 | { |
| 2536 | textureDecRef(th); |
| 2537 | } |
| 2504 | 2538 | } |
| 2505 | 2539 | } |
| 2506 | 2540 | } |
| r32173 | r32174 | |
| 2614 | 2648 | Rect& rect = m_rect[_id]; |
| 2615 | 2649 | rect.m_x = _x; |
| 2616 | 2650 | rect.m_y = _y; |
| 2617 | | rect.m_width = bx::uint16_max(_width, 1); |
| 2651 | rect.m_width = bx::uint16_max(_width, 1); |
| 2618 | 2652 | rect.m_height = bx::uint16_max(_height, 1); |
| 2619 | 2653 | } |
| 2620 | 2654 | |
| r32173 | r32174 | |
| 2634 | 2668 | Rect& scissor = m_scissor[_id]; |
| 2635 | 2669 | scissor.m_x = _x; |
| 2636 | 2670 | scissor.m_y = _y; |
| 2637 | | scissor.m_width = _width; |
| 2671 | scissor.m_width = _width; |
| 2638 | 2672 | scissor.m_height = _height; |
| 2639 | 2673 | } |
| 2640 | 2674 | |
| r32173 | r32174 | |
| 2850 | 2884 | TextureHandle textureHandle = BGFX_INVALID_HANDLE; |
| 2851 | 2885 | if (isValid(_handle) ) |
| 2852 | 2886 | { |
| 2853 | | textureHandle = m_frameBufferRef[_handle.idx].m_th[_attachment]; |
| 2887 | const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; |
| 2888 | BX_CHECK(!ref.m_window, "Can't sample window frame buffer."); |
| 2889 | textureHandle = ref.un.m_th[_attachment]; |
| 2854 | 2890 | BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment); |
| 2855 | 2891 | } |
| 2856 | 2892 | |
| r32173 | r32174 | |
| 2878 | 2914 | TextureHandle textureHandle = BGFX_INVALID_HANDLE; |
| 2879 | 2915 | if (isValid(_handle) ) |
| 2880 | 2916 | { |
| 2881 | | textureHandle = m_frameBufferRef[_handle.idx].m_th[_attachment]; |
| 2917 | const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; |
| 2918 | BX_CHECK(!ref.m_window, "Can't sample window frame buffer."); |
| 2919 | textureHandle = ref.un.m_th[_attachment]; |
| 2882 | 2920 | BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment); |
| 2883 | 2921 | } |
| 2884 | 2922 | |
| r32173 | r32174 | |
| 3014 | 3052 | |
| 3015 | 3053 | struct FrameBufferRef |
| 3016 | 3054 | { |
| 3017 | | TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; |
| 3055 | union un |
| 3056 | { |
| 3057 | TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; |
| 3058 | void* m_nwh; |
| 3059 | } un; |
| 3060 | bool m_window; |
| 3018 | 3061 | }; |
| 3019 | 3062 | |
| 3020 | 3063 | typedef stl::unordered_map<stl::string, UniformHandle> UniformHashMap; |
branches/osd/src/lib/bgfx/glcontext_wgl.cpp
| r32173 | r32174 | |
| 24 | 24 | # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func |
| 25 | 25 | # include "glimports.h" |
| 26 | 26 | |
| 27 | struct SwapChainGL |
| 28 | { |
| 29 | SwapChainGL(void* _nwh) |
| 30 | : m_hwnd( (HWND)_nwh) |
| 31 | { |
| 32 | m_hdc = GetDC(m_hwnd); |
| 33 | } |
| 34 | |
| 35 | ~SwapChainGL() |
| 36 | { |
| 37 | wglMakeCurrent(NULL, NULL); |
| 38 | wglDeleteContext(m_context); |
| 39 | ReleaseDC(m_hwnd, m_hdc); |
| 40 | } |
| 41 | |
| 42 | void makeCurrent() |
| 43 | { |
| 44 | wglMakeCurrent(m_hdc, m_context); |
| 45 | } |
| 46 | |
| 47 | void swapBuffers() |
| 48 | { |
| 49 | SwapBuffers(m_hdc); |
| 50 | } |
| 51 | |
| 52 | HWND m_hwnd; |
| 53 | HDC m_hdc; |
| 54 | HGLRC m_context; |
| 55 | }; |
| 56 | |
| 27 | 57 | static HGLRC createContext(HDC _hdc) |
| 28 | 58 | { |
| 29 | 59 | PIXELFORMATDESCRIPTOR pfd; |
| r32173 | r32174 | |
| 121 | 151 | |
| 122 | 152 | HGLRC context = createContext(hdc); |
| 123 | 153 | |
| 124 | | wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); |
| 125 | | wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); |
| 154 | wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); |
| 155 | wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); |
| 126 | 156 | wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); |
| 127 | | wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); |
| 157 | wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); |
| 128 | 158 | |
| 129 | 159 | if (NULL != wglGetExtensionsStringARB) |
| 130 | 160 | { |
| r32173 | r32174 | |
| 151 | 181 | }; |
| 152 | 182 | |
| 153 | 183 | int result; |
| 154 | | int pixelFormat; |
| 155 | 184 | uint32_t numFormats = 0; |
| 156 | 185 | do |
| 157 | 186 | { |
| 158 | | result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &pixelFormat, &numFormats); |
| 187 | result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &m_pixelFormat, &numFormats); |
| 159 | 188 | if (0 == result |
| 160 | 189 | || 0 == numFormats) |
| 161 | 190 | { |
| r32173 | r32174 | |
| 165 | 194 | |
| 166 | 195 | } while (0 == numFormats); |
| 167 | 196 | |
| 168 | | PIXELFORMATDESCRIPTOR pfd; |
| 169 | | DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); |
| 197 | DescribePixelFormat(m_hdc, m_pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &m_pfd); |
| 170 | 198 | |
| 171 | 199 | BX_TRACE("Pixel format:\n" |
| 172 | 200 | "\tiPixelType %d\n" |
| r32173 | r32174 | |
| 174 | 202 | "\tcAlphaBits %d\n" |
| 175 | 203 | "\tcDepthBits %d\n" |
| 176 | 204 | "\tcStencilBits %d\n" |
| 177 | | , pfd.iPixelType |
| 178 | | , pfd.cColorBits |
| 179 | | , pfd.cAlphaBits |
| 180 | | , pfd.cDepthBits |
| 181 | | , pfd.cStencilBits |
| 205 | , m_pfd.iPixelType |
| 206 | , m_pfd.cColorBits |
| 207 | , m_pfd.cAlphaBits |
| 208 | , m_pfd.cDepthBits |
| 209 | , m_pfd.cStencilBits |
| 182 | 210 | ); |
| 183 | 211 | |
| 184 | | result = SetPixelFormat(m_hdc, pixelFormat, &pfd); |
| 212 | result = SetPixelFormat(m_hdc, m_pixelFormat, &m_pfd); |
| 185 | 213 | // When window is created by SDL and SDL_WINDOW_OPENGL is set SetPixelFormat |
| 186 | 214 | // will fail. Just warn and continue. In case it failed for some other reason |
| 187 | 215 | // create context will fail and it will error out there. |
| r32173 | r32174 | |
| 213 | 241 | m_context = wglCreateContextAttribsARB(m_hdc, 0, contextAttrs); |
| 214 | 242 | } |
| 215 | 243 | BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create context 0x%08x.", GetLastError() ); |
| 244 | |
| 245 | BX_STATIC_ASSERT(sizeof(contextAttrs) == sizeof(m_contextAttrs) ); |
| 246 | memcpy(m_contextAttrs, contextAttrs, sizeof(contextAttrs) ); |
| 216 | 247 | } |
| 217 | 248 | |
| 218 | 249 | wglMakeCurrent(NULL, NULL); |
| r32173 | r32174 | |
| 261 | 292 | } |
| 262 | 293 | } |
| 263 | 294 | |
| 264 | | void GlContext::swap() |
| 295 | SwapChainGL* GlContext::createSwapChain(void* _nwh) |
| 265 | 296 | { |
| 266 | | if (NULL != g_bgfxHwnd) |
| 297 | SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(_nwh); |
| 298 | |
| 299 | int result = SetPixelFormat(swapChain->m_hdc, m_pixelFormat, &m_pfd); |
| 300 | BX_WARN(result, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() ); BX_UNUSED(result); |
| 301 | |
| 302 | swapChain->m_context = wglCreateContextAttribsARB(swapChain->m_hdc, m_context, m_contextAttrs); |
| 303 | BX_CHECK(NULL != swapChain->m_context, "Create swap chain failed: %x", glGetError() ); |
| 304 | return swapChain; |
| 305 | } |
| 306 | |
| 307 | void GlContext::destorySwapChain(SwapChainGL* _swapChain) |
| 308 | { |
| 309 | BX_DELETE(g_allocator, _swapChain); |
| 310 | } |
| 311 | |
| 312 | void GlContext::makeCurrent(SwapChainGL* _swapChain) |
| 313 | { |
| 314 | if (NULL == _swapChain) |
| 267 | 315 | { |
| 268 | 316 | wglMakeCurrent(m_hdc, m_context); |
| 269 | | SwapBuffers(m_hdc); |
| 270 | 317 | } |
| 318 | else |
| 319 | { |
| 320 | _swapChain->makeCurrent(); |
| 321 | } |
| 271 | 322 | } |
| 272 | 323 | |
| 324 | void GlContext::swap(SwapChainGL* _swapChain) |
| 325 | { |
| 326 | if (NULL == _swapChain) |
| 327 | { |
| 328 | if (NULL != g_bgfxHwnd) |
| 329 | { |
| 330 | wglMakeCurrent(m_hdc, m_context); |
| 331 | SwapBuffers(m_hdc); |
| 332 | } |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | _swapChain->makeCurrent(); |
| 337 | _swapChain->swapBuffers(); |
| 338 | } |
| 339 | } |
| 340 | |
| 273 | 341 | void GlContext::import() |
| 274 | 342 | { |
| 275 | 343 | BX_TRACE("Import:"); |