trunk/src/osd/modules/render/drawbgfx.cpp
| r253578 | r253579 | |
| 32 | 32 | |
| 33 | 33 | #include "drawbgfx.h" |
| 34 | 34 | #include "bgfx/texturemanager.h" |
| 35 | #include "bgfx/targetmanager.h" |
| 35 | 36 | #include "bgfx/shadermanager.h" |
| 36 | 37 | #include "bgfx/effectmanager.h" |
| 37 | 38 | #include "bgfx/effect.h" |
| 38 | 39 | #include "bgfx/texture.h" |
| 40 | #include "bgfx/target.h" |
| 39 | 41 | |
| 40 | 42 | //============================================================ |
| 41 | 43 | // DEBUGGING |
| r253578 | r253579 | |
| 94 | 96 | // create renderer |
| 95 | 97 | |
| 96 | 98 | osd_dim wdim = window().get_size(); |
| 97 | | m_width = wdim.width(); |
| 98 | | m_height = wdim.height(); |
| 99 | m_width[window().m_index] = wdim.width(); |
| 100 | m_height[window().m_index] = wdim.height(); |
| 99 | 101 | if (window().m_index == 0) |
| 100 | 102 | { |
| 101 | 103 | #ifdef OSD_WINDOWS |
| r253578 | r253579 | |
| 104 | 106 | bgfx::sdlSetWindow(window().sdl_window()); |
| 105 | 107 | #endif |
| 106 | 108 | bgfx::init(); |
| 107 | | bgfx::reset(m_width, m_height, video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); |
| 109 | bgfx::reset(m_width[window().m_index], m_height[window().m_index], video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); |
| 108 | 110 | // Enable debug text. |
| 109 | 111 | bgfx::setDebug(BGFX_DEBUG_TEXT); //BGFX_DEBUG_STATS |
| 110 | | m_dimensions = osd_dim(m_width, m_height); |
| 112 | m_dimensions = osd_dim(m_width[0], m_height[0]); |
| 113 | |
| 114 | ScreenVertex::init(); |
| 111 | 115 | } |
| 112 | | else |
| 113 | | { |
| 114 | | #ifdef OSD_WINDOWS |
| 115 | | m_framebuffer = bgfx::createFrameBuffer(window().m_hwnd, m_width, m_height); |
| 116 | | #else |
| 117 | | m_framebuffer = bgfx::createFrameBuffer(sdlNativeWindowHandle(window().sdl_window()), m_width, m_height); |
| 118 | | #endif |
| 119 | | bgfx::touch(window().m_index); |
| 120 | | } |
| 121 | 116 | |
| 122 | | ScreenVertex::init(); |
| 123 | | |
| 124 | 117 | m_textures = new texture_manager(); |
| 118 | m_targets = new target_manager(*m_textures); |
| 125 | 119 | m_shaders = new shader_manager(); |
| 126 | 120 | m_effects = new effect_manager(*m_shaders); |
| 127 | 121 | |
| 122 | if (window().m_index != 0) |
| 123 | { |
| 124 | #ifdef OSD_WINDOWS |
| 125 | m_framebuffer = m_targets->create_target("backbuffer", window().m_hwnd, m_width[window().m_index], m_height[window().m_index]); |
| 126 | #else |
| 127 | m_framebuffer = m_targets->create_target("backbuffer", sdlNativeWindowHandle(window().sdl_window()), m_width[window().m_index], m_height[window().m_index]); |
| 128 | #endif |
| 129 | bgfx::touch(window().m_index); |
| 130 | } |
| 131 | |
| 128 | 132 | // Create program from shaders. |
| 129 | | printf("1\n"); fflush(stdout); |
| 130 | 133 | m_gui_effect[0] = m_effects->effect("gui_opaque"); |
| 131 | | printf("2\n"); fflush(stdout); |
| 132 | 134 | m_gui_effect[1] = m_effects->effect("gui_blend"); |
| 133 | | printf("3\n"); fflush(stdout); |
| 134 | 135 | m_gui_effect[2] = m_effects->effect("gui_multiply"); |
| 135 | | printf("4\n"); fflush(stdout); |
| 136 | 136 | m_gui_effect[3] = m_effects->effect("gui_add"); |
| 137 | | printf("5\n"); fflush(stdout); |
| 138 | 137 | |
| 139 | 138 | m_screen_effect[0] = m_effects->effect("screen_opaque"); |
| 140 | | printf("6\n"); fflush(stdout); |
| 141 | 139 | m_screen_effect[1] = m_effects->effect("screen_blend"); |
| 142 | | printf("7\n"); fflush(stdout); |
| 143 | 140 | m_screen_effect[2] = m_effects->effect("screen_multiply"); |
| 144 | | printf("8\n"); fflush(stdout); |
| 145 | 141 | m_screen_effect[3] = m_effects->effect("screen_add"); |
| 146 | | printf("9\n"); fflush(stdout); |
| 147 | 142 | |
| 148 | 143 | uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT; |
| 149 | 144 | m_texture_cache = m_textures->create_texture("#cache", bgfx::TextureFormat::RGBA8, CACHE_SIZE, CACHE_SIZE, nullptr, flags); |
| r253578 | r253579 | |
| 160 | 155 | |
| 161 | 156 | renderer_bgfx::~renderer_bgfx() |
| 162 | 157 | { |
| 163 | | if (window().m_index > 0) |
| 164 | | { |
| 165 | | bgfx::destroyFrameBuffer(m_framebuffer); |
| 166 | | } |
| 167 | | |
| 168 | 158 | // Cleanup. |
| 159 | delete m_targets; |
| 160 | delete m_textures; |
| 169 | 161 | delete m_effects; |
| 170 | 162 | delete m_shaders; |
| 171 | | delete m_textures; |
| 172 | 163 | |
| 173 | 164 | bgfx::shutdown(); |
| 174 | 165 | } |
| r253578 | r253579 | |
| 741 | 732 | int index = window().m_index; |
| 742 | 733 | // Set view 0 default viewport. |
| 743 | 734 | osd_dim wdim = window().get_size(); |
| 744 | | int width = wdim.width(); |
| 745 | | int height = wdim.height(); |
| 735 | m_width[index] = wdim.width(); |
| 736 | m_height[index] = wdim.height(); |
| 746 | 737 | if (index == 0) |
| 747 | 738 | { |
| 748 | | if ((m_dimensions != osd_dim(width, height))) |
| 739 | if ((m_dimensions != osd_dim(m_width[index], m_height[index]))) |
| 749 | 740 | { |
| 750 | | bgfx::reset(width, height, video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); |
| 751 | | m_dimensions = osd_dim(width, height); |
| 741 | bgfx::reset(m_width[index], m_height[index], video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); |
| 742 | m_dimensions = osd_dim(m_width[index], m_height[index]); |
| 752 | 743 | } |
| 753 | 744 | } |
| 754 | 745 | else |
| 755 | 746 | { |
| 756 | | if ((m_dimensions != osd_dim(width, height))) |
| 747 | if ((m_dimensions != osd_dim(m_width[index], m_height[index]))) |
| 757 | 748 | { |
| 758 | 749 | bgfx::reset(window().m_main->get_size().width(), window().m_main->get_size().height(), video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); |
| 759 | | if (bgfx::isValid(m_framebuffer)) |
| 760 | | { |
| 761 | | bgfx::destroyFrameBuffer(m_framebuffer); |
| 762 | | } |
| 750 | delete m_framebuffer; |
| 763 | 751 | #ifdef OSD_WINDOWS |
| 764 | | m_framebuffer = bgfx::createFrameBuffer(window().m_hwnd, width, height); |
| 752 | m_framebuffer = m_targets->create_target("backbuffer", window().m_hwnd, m_width[index], m_height[index]); |
| 765 | 753 | #else |
| 766 | | m_framebuffer = bgfx::createFrameBuffer(sdlNativeWindowHandle(window().sdl_window()), width, height); |
| 754 | m_framebuffer = m_targets->create_target("backbuffer", sdlNativeWindowHandle(window().sdl_window()), m_width[index], m_height[index]); |
| 767 | 755 | #endif |
| 768 | | bgfx::setViewFrameBuffer(index, m_framebuffer); |
| 769 | | m_dimensions = osd_dim(width, height); |
| 756 | bgfx::setViewFrameBuffer(index, m_framebuffer->target()); |
| 757 | m_dimensions = osd_dim(m_width[index], m_height[index]); |
| 770 | 758 | bgfx::setViewClear(index |
| 771 | 759 | , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH |
| 772 | 760 | , 0x000000ff |
| r253578 | r253579 | |
| 779 | 767 | } |
| 780 | 768 | } |
| 781 | 769 | |
| 782 | | if (index != 0) |
| 783 | | { |
| 784 | | bgfx::setViewFrameBuffer(index, m_framebuffer); |
| 785 | | } |
| 786 | | bgfx::setViewSeq(index, true); |
| 787 | | bgfx::setViewRect(index, 0, 0, width, height); |
| 770 | if (index != 0) |
| 771 | { |
| 772 | bgfx::setViewFrameBuffer(index, m_framebuffer->target()); |
| 773 | } |
| 774 | bgfx::setViewSeq(index, true); |
| 775 | bgfx::setViewRect(index, 0, 0, m_width[index], m_height[index]); |
| 788 | 776 | |
| 789 | 777 | // Setup view transform. |
| 790 | 778 | { |
| r253578 | r253579 | |
| 793 | 781 | |
| 794 | 782 | float left = 0.0f; |
| 795 | 783 | float top = 0.0f; |
| 796 | | float right = width; |
| 797 | | float bottom = height; |
| 784 | float right = m_width[index]; |
| 785 | float bottom = m_height[index]; |
| 798 | 786 | float proj[16]; |
| 799 | 787 | bx::mtxOrtho(proj, left, right, bottom, top, 0.0f, 100.0f); |
| 800 | 788 | bgfx::setViewTransform(index, view, proj); |
| r253578 | r253579 | |
| 806 | 794 | , 0 |
| 807 | 795 | ); |
| 808 | 796 | |
| 809 | | // This dummy draw call is here to make sure that view 0 is cleared |
| 810 | | // if no other draw calls are submitted to view 0. |
| 811 | | bgfx::touch(index); |
| 812 | | |
| 813 | 797 | window().m_primlist->acquire_lock(); |
| 814 | 798 | |
| 815 | 799 | // Mark our texture atlas as dirty if we need to do so |
| r253578 | r253579 | |
| 839 | 823 | } |
| 840 | 824 | |
| 841 | 825 | window().m_primlist->release_lock(); |
| 826 | |
| 827 | // This dummy draw call is here to make sure that view 0 is cleared |
| 828 | // if no other draw calls are submitted to view 0. |
| 829 | bgfx::touch(index); |
| 830 | |
| 842 | 831 | // Advance to next frame. Rendering thread will be kicked to |
| 843 | 832 | // process submitted rendering primitives. |
| 844 | 833 | if (index==0) bgfx::frame(); |