Previous 199869 Revisions Next

r32170 Thursday 18th September, 2014 at 07:58:07 UTC by Miodrag Milanović
(OSD BRANCH) Started BGFX integration
[/branches/osd/src/osd/windows]drawbgfx.c* video.c video.h window.c windows.mak winmain.c

branches/osd/src/osd/windows/video.h
r32169r32170
2222#define VIDEO_MODE_GDI      1
2323#define VIDEO_MODE_DDRAW    2
2424#define VIDEO_MODE_D3D      3
25#define VIDEO_MODE_BGFX     4
2526
2627
2728
branches/osd/src/osd/windows/window.c
r32169r32170
3939extern int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks);
4040extern int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks);
4141extern int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks);
42extern int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks);
4243
4344
4445//============================================================
r32169r32170
240241   }
241242   if (video_config.mode == VIDEO_MODE_GDI)
242243      drawgdi_init(machine(), &draw);
244   if (video_config.mode == VIDEO_MODE_BGFX)
245      drawbgfx_init(machine(), &draw);
243246   if (video_config.mode == VIDEO_MODE_NONE)
244247      drawnone_init(machine(), &draw);
245248
branches/osd/src/osd/windows/windows.mak
r32169r32170
353353   $(WINOBJ)/drawdd.o \
354354   $(WINOBJ)/drawgdi.o \
355355   $(WINOBJ)/drawnone.o \
356   $(WINOBJ)/drawbgfx.o \
356357   $(WINOBJ)/input.o \
357358   $(WINOBJ)/output.o \
358359   $(OSDOBJ)/modules/sound/direct_sound.o \
r32169r32170
385386# add a stub resource file
386387RESFILE = $(WINOBJ)/mame.res
387388
389INCPATH += -I$(LIBSRC)/bgfx/include
388390#-------------------------------------------------
389391# QT Debug library
390392#-------------------------------------------------
branches/osd/src/osd/windows/winmain.c
r32169r32170
537537   video_options_add("gdi", NULL);
538538   video_options_add("ddraw", NULL);
539539   video_options_add("d3d", NULL);
540   video_options_add("bgfx", NULL);
540541   //video_options_add("auto", NULL); // making d3d video default one
541542}
542543
branches/osd/src/osd/windows/drawbgfx.c
r0r32170
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
30static void drawbgfx_exit(void);
31static int drawbgfx_window_init(win_window_info *window);
32static void drawbgfx_window_destroy(win_window_info *window);
33static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window);
34static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update);
35
36
37
38//============================================================
39//  drawbgfx_init
40//============================================================
41
42int 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
60static void drawbgfx_exit(void)
61{
62}
63
64
65
66//============================================================
67//  drawbgfx_window_init
68//============================================================
69
70static 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
92static 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
105static 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
119static 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}
Property changes on: branches/osd/src/osd/windows/drawbgfx.c
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain
branches/osd/src/osd/windows/video.c
r32169r32170
391391      video_config.mode = VIDEO_MODE_DDRAW;
392392   else if (strcmp(stemp, "gdi") == 0)
393393      video_config.mode = VIDEO_MODE_GDI;
394   else if (strcmp(stemp, "bgfx") == 0)
395      video_config.mode = VIDEO_MODE_BGFX;
394396   else if (strcmp(stemp, "none") == 0)
395397   {
396398      video_config.mode = VIDEO_MODE_NONE;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team