branches/osd/src/osd/windows/drawbgfx.c
| r0 | r32170 | |
| 1 | // license:BSD-3-Clause |
| 2 | // copyright-holders:Miodrag Milanovic |
| 3 | //============================================================ |
| 4 | // |
| 5 | // drawbgfx.c - BGFX drawer |
| 6 | // |
| 7 | //============================================================ |
| 8 | |
| 9 | // standard windows headers |
| 10 | #define __STDC_LIMIT_MACROS |
| 11 | #define __STDC_FORMAT_MACROS |
| 12 | #define __STDC_CONSTANT_MACROS |
| 13 | #define WIN32_LEAN_AND_MEAN |
| 14 | #include <windows.h> |
| 15 | |
| 16 | // MAME headers |
| 17 | #include "emu.h" |
| 18 | |
| 19 | // MAMEOS headers |
| 20 | #include "window.h" |
| 21 | |
| 22 | #include <bgfxplatform.h> |
| 23 | #include <bgfx.h> |
| 24 | |
| 25 | //============================================================ |
| 26 | // PROTOTYPES |
| 27 | //============================================================ |
| 28 | |
| 29 | // core functions |
| 30 | static void drawbgfx_exit(void); |
| 31 | static int drawbgfx_window_init(win_window_info *window); |
| 32 | static void drawbgfx_window_destroy(win_window_info *window); |
| 33 | static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window); |
| 34 | static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update); |
| 35 | |
| 36 | |
| 37 | |
| 38 | //============================================================ |
| 39 | // drawbgfx_init |
| 40 | //============================================================ |
| 41 | |
| 42 | int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks) |
| 43 | { |
| 44 | // fill in the callbacks |
| 45 | memset(callbacks, 0, sizeof(*callbacks)); |
| 46 | callbacks->exit = drawbgfx_exit; |
| 47 | callbacks->window_init = drawbgfx_window_init; |
| 48 | callbacks->window_get_primitives = drawbgfx_window_get_primitives; |
| 49 | callbacks->window_draw = drawbgfx_window_draw; |
| 50 | callbacks->window_destroy = drawbgfx_window_destroy; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | |
| 56 | //============================================================ |
| 57 | // drawbgfx_exit |
| 58 | //============================================================ |
| 59 | |
| 60 | static void drawbgfx_exit(void) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | //============================================================ |
| 67 | // drawbgfx_window_init |
| 68 | //============================================================ |
| 69 | |
| 70 | static int drawbgfx_window_init(win_window_info *window) |
| 71 | { |
| 72 | RECT client; |
| 73 | GetClientRect(window->m_hwnd, &client); |
| 74 | |
| 75 | bgfx::winSetHwnd(window->m_hwnd); |
| 76 | bgfx::init(); |
| 77 | bgfx::reset(rect_width(&client), rect_height(&client), BGFX_RESET_VSYNC); |
| 78 | |
| 79 | // Enable debug text. |
| 80 | bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT); |
| 81 | |
| 82 | window->m_drawdata = window->m_hwnd; |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | //============================================================ |
| 89 | // drawbgfx_window_destroy |
| 90 | //============================================================ |
| 91 | |
| 92 | static void drawbgfx_window_destroy(win_window_info *window) |
| 93 | { |
| 94 | // Shutdown bgfx. |
| 95 | bgfx::shutdown(); |
| 96 | window->m_drawdata = NULL; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | |
| 101 | //============================================================ |
| 102 | // drawbgfx_window_get_primitives |
| 103 | //============================================================ |
| 104 | |
| 105 | static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window) |
| 106 | { |
| 107 | RECT client; |
| 108 | GetClientRect(window->m_hwnd, &client); |
| 109 | window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect()); |
| 110 | return &window->m_target->get_primitives(); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | |
| 115 | //============================================================ |
| 116 | // drawbgfx_window_draw |
| 117 | //============================================================ |
| 118 | |
| 119 | static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update) |
| 120 | { |
| 121 | RECT client; |
| 122 | GetClientRect(window->m_hwnd, &client); |
| 123 | |
| 124 | bgfx::setViewClear(0 |
| 125 | , BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT |
| 126 | , 0x00000000 |
| 127 | , 1.0f |
| 128 | , 0 |
| 129 | ); |
| 130 | // Set view 0 default viewport. |
| 131 | bgfx::setViewRect(0, 0, 0, rect_width(&client), rect_height(&client)); |
| 132 | |
| 133 | // This dummy draw call is here to make sure that view 0 is cleared |
| 134 | // if no other draw calls are submitted to view 0. |
| 135 | bgfx::submit(0); |
| 136 | |
| 137 | // Use debug font to print information about this example. |
| 138 | //bgfx::dbgTextClear(); |
| 139 | //bgfx::dbgTextPrintf(0, 1, 0x4f, "MAME BGFX test"); |
| 140 | //bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text."); |
| 141 | |
| 142 | window->m_primlist->acquire_lock(); |
| 143 | |
| 144 | // now draw |
| 145 | for (render_primitive *prim = window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 146 | { |
| 147 | switch (prim->type) |
| 148 | { |
| 149 | /** |
| 150 | * Try to stay in one Begin/End block as long as possible, |
| 151 | * since entering and leaving one is most expensive.. |
| 152 | */ |
| 153 | case render_primitive::LINE: |
| 154 | // check if it's really a point |
| 155 | /* |
| 156 | if (((prim->bounds.x1 - prim->bounds.x0) == 0) && ((prim->bounds.y1 - prim->bounds.y0) == 0)) |
| 157 | { |
| 158 | curPrimitive=GL_POINTS; |
| 159 | } else { |
| 160 | curPrimitive=GL_LINES; |
| 161 | } |
| 162 | |
| 163 | if(pendingPrimitive!=GL_NO_PRIMITIVE && pendingPrimitive!=curPrimitive) |
| 164 | { |
| 165 | glEnd(); |
| 166 | pendingPrimitive=GL_NO_PRIMITIVE; |
| 167 | } |
| 168 | |
| 169 | if ( pendingPrimitive==GL_NO_PRIMITIVE ) |
| 170 | { |
| 171 | set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 172 | } |
| 173 | |
| 174 | glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a); |
| 175 | |
| 176 | if(pendingPrimitive!=curPrimitive) |
| 177 | { |
| 178 | glBegin(curPrimitive); |
| 179 | pendingPrimitive=curPrimitive; |
| 180 | } |
| 181 | |
| 182 | // check if it's really a point |
| 183 | if (curPrimitive==GL_POINTS) |
| 184 | { |
| 185 | glVertex2f(prim->bounds.x0+hofs, prim->bounds.y0+vofs); |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | glVertex2f(prim->bounds.x0+hofs, prim->bounds.y0+vofs); |
| 190 | glVertex2f(prim->bounds.x1+hofs, prim->bounds.y1+vofs); |
| 191 | }*/ |
| 192 | break; |
| 193 | |
| 194 | case render_primitive::QUAD: |
| 195 | /* |
| 196 | if(pendingPrimitive!=GL_NO_PRIMITIVE) |
| 197 | { |
| 198 | glEnd(); |
| 199 | pendingPrimitive=GL_NO_PRIMITIVE; |
| 200 | } |
| 201 | |
| 202 | glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a); |
| 203 | |
| 204 | set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 205 | |
| 206 | texture = texture_update(window, prim, 0); |
| 207 | |
| 208 | |
| 209 | sdl->texVerticex[0]=prim->bounds.x0 + hofs; |
| 210 | sdl->texVerticex[1]=prim->bounds.y0 + vofs; |
| 211 | sdl->texVerticex[2]=prim->bounds.x1 + hofs; |
| 212 | sdl->texVerticex[3]=prim->bounds.y0 + vofs; |
| 213 | sdl->texVerticex[4]=prim->bounds.x1 + hofs; |
| 214 | sdl->texVerticex[5]=prim->bounds.y1 + vofs; |
| 215 | sdl->texVerticex[6]=prim->bounds.x0 + hofs; |
| 216 | sdl->texVerticex[7]=prim->bounds.y1 + vofs; |
| 217 | |
| 218 | glDrawArrays(GL_QUADS, 0, 4); |
| 219 | */ |
| 220 | break; |
| 221 | |
| 222 | default: |
| 223 | throw emu_fatalerror("Unexpected render_primitive type"); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | window->m_primlist->release_lock(); |
| 228 | // Advance to next frame. Rendering thread will be kicked to |
| 229 | // process submitted rendering primitives. |
| 230 | bgfx::frame(); |
| 231 | |
| 232 | return 0; |
| 233 | } |