First take on render API reorg, nw

This commit is contained in:
therealmogminer@gmail.com 2016-02-18 15:57:34 +01:00
parent dadf8e7d79
commit 9a47a870df
128 changed files with 3432 additions and 2321 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
!/3rdparty/
!/benchmarks/
!/artwork/
!/bgfx/
!/docs/
!/hash/
!/hlsl/

22
bgfx/effects/gui_add.json Normal file
View File

@ -0,0 +1,22 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1",
"srcAlpha": "srcAlpha",
"dstAlpha": "1"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_gui",
"fragment": "fs_gui",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] }
]
}

View File

@ -0,0 +1,22 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1-srcAlpha",
"srcAlpha": "srcAlpha",
"dstAlpha": "1-srcAlpha"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_gui",
"fragment": "fs_gui",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] }
]
}

View File

@ -0,0 +1,22 @@
{
"blend": {
"equation": "add",
"srcColor": "dstColor",
"dstColor": "0",
"srcAlpha": "dstAlpha",
"dstAlpha": "0"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_gui",
"fragment": "fs_gui",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] }
]
}

View File

@ -0,0 +1,22 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_gui",
"fragment": "fs_gui",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] }
]
}

View File

@ -0,0 +1,23 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1",
"srcAlpha": "srcAlpha",
"dstAlpha": "1"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_screen",
"fragment": "fs_screen",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "u_tint", "type": "vec4", "values": [ 1.0, 1.0, 1.0, 1.0 ] }
]
}

View File

@ -0,0 +1,23 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1-srcAlpha",
"srcAlpha": "srcAlpha",
"dstAlpha": "1-srcAlpha"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_screen",
"fragment": "fs_screen",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "u_tint", "type": "vec4", "values": [ 1.0, 1.0, 1.0, 1.0 ] }
]
}

View File

@ -0,0 +1,23 @@
{
"blend": {
"equation": "add",
"srcColor": "dstColor",
"dstColor": "0",
"srcAlpha": "dstAlpha",
"dstAlpha": "0"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_screen",
"fragment": "fs_screen",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "u_tint", "type": "vec4", "values": [ 1.0, 1.0, 1.0, 1.0 ] }
]
}

View File

@ -0,0 +1,23 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_screen",
"fragment": "fs_screen",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "u_tint", "type": "vec4", "values": [ 1.0, 1.0, 1.0, 1.0 ] }
]
}

View File

@ -103,6 +103,23 @@ function osdmodulesbuild()
files {
MAME_DIR .. "src/osd/modules/render/drawbgfx.cpp",
MAME_DIR .. "src/osd/modules/render/binpacker.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/blendreader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/cullreader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/depthreader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/effect.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/effectmanager.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/effectreader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/pass.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/passreader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/shadermanager.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/statereader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/target.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/targetmanager.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/texture.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/texturemanager.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/uniform.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/uniformreader.cpp",
MAME_DIR .. "src/osd/modules/render/bgfx/writereader.cpp",
}
includedirs {
MAME_DIR .. "3rdparty/bgfx/include",

View File

@ -384,6 +384,7 @@ project ("osd_" .. _OPTIONS["osd"])
MAME_DIR .. "src/osd/sdl/video.h",
MAME_DIR .. "src/osd/sdl/window.cpp",
MAME_DIR .. "src/osd/sdl/window.h",
MAME_DIR .. "src/osd/modules/osdwindow.cpp",
MAME_DIR .. "src/osd/modules/osdwindow.h",
MAME_DIR .. "src/osd/sdl/output.cpp",
MAME_DIR .. "src/osd/sdl/watchdog.cpp",

View File

@ -152,15 +152,17 @@ project ("osd_" .. _OPTIONS["osd"])
}
files {
MAME_DIR .. "src/osd/modules/render/drawd3d.cpp",
MAME_DIR .. "src/osd/modules/render/drawd3d.h",
MAME_DIR .. "src/osd/modules/render/d3d/d3d9intf.cpp",
MAME_DIR .. "src/osd/modules/render/d3d/d3dintf.h",
MAME_DIR .. "src/osd/modules/render/d3d/d3dhlsl.cpp",
MAME_DIR .. "src/osd/modules/render/d3d/d3dcomm.h",
MAME_DIR .. "src/osd/modules/render/d3d/d3dhlsl.h",
MAME_DIR .. "src/osd/modules/render/d3d/d3dintf.h",
MAME_DIR .. "src/osd/modules/render/drawd3d.cpp",
MAME_DIR .. "src/osd/modules/render/drawd3d.h",
MAME_DIR .. "src/osd/modules/render/drawgdi.cpp",
MAME_DIR .. "src/osd/modules/render/drawgdi.h",
MAME_DIR .. "src/osd/modules/render/drawnone.cpp",
MAME_DIR .. "src/osd/modules/render/drawnone.h",
MAME_DIR .. "src/osd/windows/input.cpp",
MAME_DIR .. "src/osd/windows/input.h",
MAME_DIR .. "src/osd/windows/output.cpp",
@ -169,6 +171,7 @@ project ("osd_" .. _OPTIONS["osd"])
MAME_DIR .. "src/osd/windows/video.h",
MAME_DIR .. "src/osd/windows/window.cpp",
MAME_DIR .. "src/osd/windows/window.h",
MAME_DIR .. "src/osd/modules/osdwindow.cpp",
MAME_DIR .. "src/osd/modules/osdwindow.h",
MAME_DIR .. "src/osd/windows/winmenu.cpp",
MAME_DIR .. "src/osd/windows/winmain.cpp",

Binary file not shown.

Binary file not shown.

BIN
shaders/dx11/fs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shaders/dx11/vs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shaders/dx9/fs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shaders/dx9/vs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shaders/gles/fs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shaders/glsl/fs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shaders/metal/fs_screen.bin Normal file

Binary file not shown.

Binary file not shown.

View File

@ -17,9 +17,9 @@
#include "ui/sliders.h"
ui_menu_sliders::ui_menu_sliders(running_machine &machine, render_container *container, bool _menuless_mode) : ui_menu(machine, container)
ui_menu_sliders::ui_menu_sliders(running_machine &machine, render_container *container, bool menuless_mode) : ui_menu(machine, container)
{
menuless_mode = hidden = _menuless_mode;
m_menuless_mode = m_hidden = menuless_mode;
}
ui_menu_sliders::~ui_menu_sliders()
@ -35,7 +35,7 @@ void ui_menu_sliders::handle()
const ui_menu_event *menu_event;
/* process the menu */
menu_event = process(UI_MENU_PROCESS_LR_REPEAT | (hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0));
menu_event = process(UI_MENU_PROCESS_LR_REPEAT | (m_hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0));
if (menu_event != nullptr)
{
/* handle keys if there is a valid item selected */
@ -49,10 +49,10 @@ void ui_menu_sliders::handle()
{
/* toggle visibility */
case IPT_UI_ON_SCREEN_DISPLAY:
if (menuless_mode)
if (m_menuless_mode)
ui_menu::stack_pop(machine());
else
hidden = !hidden;
m_hidden = !m_hidden;
break;
/* decrease value */
@ -103,19 +103,25 @@ void ui_menu_sliders::handle()
}
/* if we are selecting an invalid item and we are hidden, skip to the next one */
else if (hidden)
else if (m_hidden)
{
/* if we got here via up or page up, select the previous item */
if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP)
{
selected = (selected + item.size() - 1) % item.size();
do
{
selected = (selected + item.size() - 1) % item.size();
} while(((slider_state&)item[selected]).hidden);
validate_selection(-1);
}
/* otherwise select the next item */
else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN)
{
selected = (selected + 1) % item.size();
do
{
selected = (selected + 1) % item.size();
} while(((slider_state&)item[selected]).hidden);
validate_selection(1);
}
}
@ -252,5 +258,5 @@ UINT32 ui_menu_sliders::ui_handler(running_machine &machine, render_container *c
ui_menu::stack_pop(machine);
ui_menu_sliders *uim = dynamic_cast<ui_menu_sliders *>(menu_stack);
return uim && uim->menuless_mode ? 0 : UI_HANDLER_CANCEL;
return uim && uim->m_menuless_mode ? 0 : UI_HANDLER_CANCEL;
}

View File

@ -13,6 +13,8 @@
#ifndef __UI_SLIDERS_H__
#define __UI_SLIDERS_H__
#include <map>
class ui_menu_sliders : public ui_menu {
public:
ui_menu_sliders(running_machine &machine, render_container *container, bool menuless_mode = false);
@ -25,7 +27,8 @@ public:
static UINT32 ui_handler(running_machine &machine, render_container *container, UINT32 state);
private:
bool menuless_mode, hidden;
bool m_menuless_mode;
bool m_hidden;
};

View File

@ -103,7 +103,8 @@ struct slider_state
INT32 defval; /* default value */
INT32 maxval; /* maximum value */
INT32 incval; /* increment value */
char description[1]; /* textual description */
bool hidden; /* hidden or not */
char description[1]; /* textual description */
};
@ -121,7 +122,7 @@ public:
running_machine &machine() const { return m_machine; }
bool single_step() const { return m_single_step; }
ui_options &options() { return m_ui_options; }
// setters
void set_single_step(bool single_step) { m_single_step = single_step; }

View File

@ -15,32 +15,32 @@
const options_entry osd_options::s_option_entries[] =
{
{ NULL, NULL, OPTION_HEADER, "OSD KEYBOARD MAPPING OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD KEYBOARD MAPPING OPTIONS" },
#ifdef SDLMAME_MACOSX
{ OSDOPTION_UIMODEKEY, "DEL", OPTION_STRING, "Key to toggle keyboard mode" },
#else
{ OSDOPTION_UIMODEKEY, "SCRLOCK", OPTION_STRING, "Key to toggle keyboard mode" },
#endif // SDLMAME_MACOSX
{ NULL, NULL, OPTION_HEADER, "OSD FONT OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD FONT OPTIONS" },
{ OSD_FONT_PROVIDER, OSDOPTVAL_AUTO, OPTION_STRING, "provider for ui font: " },
{ NULL, NULL, OPTION_HEADER, "OSD CLI OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD CLI OPTIONS" },
{ OSDCOMMAND_LIST_MIDI_DEVICES ";mlist", "0", OPTION_COMMAND, "list available MIDI I/O devices" },
{ OSDCOMMAND_LIST_NETWORK_ADAPTERS ";nlist", "0", OPTION_COMMAND, "list available network adapters" },
{ NULL, NULL, OPTION_HEADER, "OSD DEBUGGING OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD DEBUGGING OPTIONS" },
{ OSDOPTION_DEBUGGER, OSDOPTVAL_AUTO, OPTION_STRING, "debugger used: " },
{ OSDOPTION_DEBUGGER_FONT ";dfont", OSDOPTVAL_AUTO, OPTION_STRING, "specifies the font to use for debugging" },
{ OSDOPTION_DEBUGGER_FONT_SIZE ";dfontsize", "0", OPTION_FLOAT, "specifies the font size to use for debugging" },
{ OSDOPTION_WATCHDOG ";wdog", "0", OPTION_INTEGER, "force the program to terminate if no updates within specified number of seconds" },
{ NULL, NULL, OPTION_HEADER, "OSD PERFORMANCE OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD PERFORMANCE OPTIONS" },
{ OSDOPTION_MULTITHREADING ";mt", "0", OPTION_BOOLEAN, "enable multithreading; this enables rendering and blitting on a separate thread" },
{ OSDOPTION_NUMPROCESSORS ";np", OSDOPTVAL_AUTO, OPTION_STRING, "number of processors; this overrides the number the system reports" },
{ OSDOPTION_BENCH, "0", OPTION_INTEGER, "benchmark for the given number of emulated seconds; implies -video none -sound none -nothrottle" },
{ NULL, NULL, OPTION_HEADER, "OSD VIDEO OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD VIDEO OPTIONS" },
// OS X can be trusted to have working hardware OpenGL, so default to it on for the best user experience
{ OSDOPTION_VIDEO, OSDOPTVAL_AUTO, OPTION_STRING, "video output method: " },
{ OSDOPTION_NUMSCREENS "(1-4)", "1", OPTION_INTEGER, "number of screens to create; usually, you want just one" },
@ -52,7 +52,7 @@ const options_entry osd_options::s_option_entries[] =
{ OSDOPTION_SYNCREFRESH ";srf", "0", OPTION_BOOLEAN, "enable using the start of VBLANK for throttling instead of the game time" },
// per-window options
{ NULL, NULL, OPTION_HEADER, "OSD PER-WINDOW VIDEO OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD PER-WINDOW VIDEO OPTIONS" },
{ OSDOPTION_SCREEN, OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_ASPECT ";screen_aspect", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio for all screens; 'auto' here will try to make a best guess" },
{ OSDOPTION_RESOLUTION ";r", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution for all screens; format is <width>x<height>[@<refreshrate>] or 'auto'" },
@ -79,15 +79,15 @@ const options_entry osd_options::s_option_entries[] =
{ OSDOPTION_VIEW "3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the fourth screen" },
// full screen options
{ NULL, NULL, OPTION_HEADER, "OSD FULL SCREEN OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD FULL SCREEN OPTIONS" },
{ OSDOPTION_SWITCHRES, "0", OPTION_BOOLEAN, "enable resolution switching" },
{ NULL, NULL, OPTION_HEADER, "OSD ACCELERATED VIDEO OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD ACCELERATED VIDEO OPTIONS" },
{ OSDOPTION_FILTER ";glfilter;flt", "1", OPTION_BOOLEAN, "enable bilinear filtering on screen output" },
{ OSDOPTION_PRESCALE, "1", OPTION_INTEGER, "scale screen rendering by this amount in software" },
#if USE_OPENGL
{ NULL, NULL, OPTION_HEADER, "OpenGL-SPECIFIC OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OpenGL-SPECIFIC OPTIONS" },
{ OSDOPTION_GL_FORCEPOW2TEXTURE, "0", OPTION_BOOLEAN, "force power of two textures (default no)" },
{ OSDOPTION_GL_NOTEXTURERECT, "0", OPTION_BOOLEAN, "don't use OpenGL GL_ARB_texture_rectangle (default on)" },
{ OSDOPTION_GL_VBO, "1", OPTION_BOOLEAN, "enable OpenGL VBO, if available (default on)" },
@ -116,12 +116,12 @@ const options_entry osd_options::s_option_entries[] =
{ OSDOPTION_SHADER_SCREEN "9", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 9" },
#endif
{ NULL, NULL, OPTION_HEADER, "OSD SOUND OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "OSD SOUND OPTIONS" },
{ OSDOPTION_SOUND, OSDOPTVAL_AUTO, OPTION_STRING, "sound output method: " },
{ OSDOPTION_AUDIO_LATENCY "(1-5)", "2", OPTION_INTEGER, "set audio latency (increase to reduce glitches, decrease for responsiveness)" },
#ifdef SDLMAME_MACOSX
{ NULL, NULL, OPTION_HEADER, "CoreAudio-SPECIFIC OPTIONS" },
{ nullptr, nullptr, OPTION_HEADER, "CoreAudio-SPECIFIC OPTIONS" },
{ OSDOPTION_AUDIO_OUTPUT, OSDOPTVAL_AUTO, OPTION_STRING, "Audio output device" },
{ OSDOPTION_AUDIO_EFFECT "0", OSDOPTVAL_NONE, OPTION_STRING, "AudioUnit effect 0" },
{ OSDOPTION_AUDIO_EFFECT "1", OSDOPTVAL_NONE, OPTION_STRING, "AudioUnit effect 1" },
@ -136,7 +136,7 @@ const options_entry osd_options::s_option_entries[] =
#endif
// End of list
{ NULL }
{ nullptr }
};
osd_options::osd_options()
@ -151,11 +151,11 @@ osd_options::osd_options()
//-------------------------------------------------
osd_common_t::osd_common_t(osd_options &options)
: osd_output(), m_machine(NULL),
: osd_output(), m_machine(nullptr),
m_options(options),
m_print_verbose(false),
m_sound(NULL),
m_debugger(NULL)
m_sound(nullptr),
m_debugger(nullptr)
{
osd_output::push(this);
}
@ -240,7 +240,7 @@ void osd_common_t::register_options()
update_option(OSD_DEBUG_PROVIDER, dnames);
// Register video options and update options
video_options_add("none", NULL);
video_options_add("none", nullptr);
video_register();
update_option(OSDOPTION_VIDEO, m_video_names);
}
@ -426,7 +426,7 @@ void osd_common_t::set_mastervolume(int attenuation)
// while (attenuation++ < 0)
// volume /= 1.122018454; // = (10 ^ (1/20)) = 1dB
//
if (m_sound != NULL)
if (m_sound != nullptr)
m_sound->set_mastervolume(attenuation);
}
@ -458,7 +458,7 @@ void osd_common_t::customize_input_type_list(simple_list<input_type_entry> &type
osd_font *osd_common_t::font_open(const char *name, int &height)
{
return NULL;
return nullptr;
}
@ -490,9 +490,9 @@ bool osd_common_t::font_get_bitmap(osd_font *font, unicode_char chnum, bitmap_ar
// list of OS-dependent slider values.
//-------------------------------------------------
void *osd_common_t::get_slider_list()
slider_state* osd_common_t::get_slider_list()
{
return NULL;
return nullptr;
}
//-------------------------------------------------

View File

@ -187,7 +187,7 @@ public:
virtual bool font_get_bitmap(osd_font *font, unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
// video overridables
virtual void *get_slider_list() override;
virtual slider_state *get_slider_list() override;
// command option overrides
virtual bool execute_command(const char *command) override;

View File

@ -0,0 +1,57 @@
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont, Couriersud
//============================================================
//
// osdwindow.cpp - SDL window handling
//
//============================================================
// standard windows headers
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include "osdwindow.h"
#include "render/drawnone.h"
#include "render/drawbgfx.h"
#include "render/drawogl.h"
#if OSD_WINDOWS
#include "render/drawgdi.h"
#include "render/drawd3d.h"
#else
#include "render/draw13.h"
#include "render/drawsdl.h"
#endif
osd_renderer* osd_renderer::make_for_type(int mode, osd_window* window, int extra_flags)
{
switch(mode)
{
case VIDEO_MODE_NONE:
return new renderer_none(window);
case VIDEO_MODE_BGFX:
return new renderer_bgfx(window);
#if (USE_OPENGL)
case VIDEO_MODE_OPENGL:
return new renderer_ogl(window);
#endif
#if OSD_WINDOWS
case VIDEO_MODE_GDI:
return new renderer_gdi(window);
case VIDEO_MODE_D3D:
{
osd_renderer *renderer = new renderer_d3d9(window);
return renderer;
}
#else
case VIDEO_MODE_SDL2ACCEL:
return new renderer_sdl2(window, extra_flags);
case VIDEO_MODE_SOFT:
return new renderer_sdl1(window, extra_flags);
#endif
default:
return nullptr;
}
}

View File

@ -9,13 +9,122 @@
#ifndef __OSDWINDOW__
#define __OSDWINDOW__
#include "video.h"
#include "render.h"
#include "emu.h"
//============================================================
// TYPE DEFINITIONS
//============================================================
class osd_options;
class render_primitive_list;
enum
{
VIDEO_MODE_NONE,
VIDEO_MODE_GDI,
VIDEO_MODE_BGFX,
#if (USE_OPENGL)
VIDEO_MODE_OPENGL,
#endif
VIDEO_MODE_SDL2ACCEL,
VIDEO_MODE_D3D,
VIDEO_MODE_SOFT
};
class osd_dim
{
public:
osd_dim(const int &w, const int &h)
: m_w(w), m_h(h)
{
}
int width() const { return m_w; }
int height() const { return m_h; }
bool operator!=(const osd_dim &other) { return (m_w != other.width()) || (m_h != other.height()); }
bool operator==(const osd_dim &other) { return (m_w == other.width()) && (m_h == other.height()); }
private:
int m_w;
int m_h;
};
class osd_rect
{
public:
osd_rect()
: m_x(0), m_y(0), m_d(0,0)
{
}
osd_rect(const int x, const int y, const int &w, const int &h)
: m_x(x), m_y(y), m_d(w,h)
{
}
osd_rect(const int x, const int y, const osd_dim &d)
: m_x(x), m_y(y), m_d(d)
{
}
int top() const { return m_y; }
int left() const { return m_x; }
int width() const { return m_d.width(); }
int height() const { return m_d.height(); }
osd_dim dim() const { return m_d; }
int bottom() const { return m_y + m_d.height(); }
int right() const { return m_x + m_d.width(); }
osd_rect move_by(int dx, int dy) const { return osd_rect(m_x + dx, m_y + dy, m_d); }
osd_rect resize(int w, int h) const { return osd_rect(m_x, m_y, w, h); }
private:
int m_x;
int m_y;
osd_dim m_d;
};
class osd_monitor_info
{
public:
osd_monitor_info(void *handle, const char *monitor_device, float aspect)
: m_next(NULL), m_handle(handle), m_aspect(aspect)
{
strncpy(m_name, monitor_device, ARRAY_LENGTH(m_name) - 1);
}
virtual ~osd_monitor_info() { }
virtual void refresh() = 0;
const void *oshandle() { return m_handle; }
const osd_rect &position_size() { return m_pos_size; }
const osd_rect &usuable_position_size() { return m_usuable_pos_size; }
const char *devicename() { return m_name[0] ? m_name : "UNKNOWN"; }
float aspect();
void set_aspect(const float a) { m_aspect = a; }
bool is_primary() { return m_is_primary; }
osd_monitor_info * next() { return m_next; } // pointer to next monitor in list
static osd_monitor_info *pick_monitor(osd_options &options, int index);
static osd_monitor_info *list;
// FIXME: should be private!
osd_monitor_info *m_next; // pointer to next monitor in list
protected:
osd_rect m_pos_size;
osd_rect m_usuable_pos_size;
bool m_is_primary;
char m_name[64];
private:
void * m_handle; // handle to the monitor
float m_aspect; // computed/configured aspect ratio of the physical device
};
class osd_window_config
{
public:
@ -33,8 +142,7 @@ class osd_window
public:
osd_window()
:
#ifdef OSD_SDL
#else
#ifndef OSD_SDL
m_hwnd(0), m_dc(0), m_focus_hwnd(0), m_resize_state(0),
#endif
m_primlist(nullptr),
@ -110,27 +218,24 @@ public:
/* Interface to be implemented by render code */
virtual int create() = 0;
virtual int init(running_machine &machine) = 0;
virtual render_primitive_list *get_primitives() = 0;
virtual int draw(const int update) = 0;
#ifdef OSD_SDL
virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) = 0;
#else
virtual void save() = 0;
virtual void record() = 0;
virtual void toggle_fsfx() = 0;
#endif
virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) { return 0; };
virtual void save() { };
virtual void record() { };
virtual void toggle_fsfx() { };
virtual void destroy() = 0;
static osd_renderer* make_for_type(int mode, osd_window *window, int extra_flags = FLAG_NONE);
protected:
/* Internal flags */
static const int FI_CHANGED = 0x010000;
private:
osd_window *m_window;
int m_flags;
osd_window *m_window;
int m_flags;
};

View File

@ -0,0 +1,43 @@
#include <bgfx/bgfx.h>
#include "blendreader.h"
const blend_reader::string_to_enum blend_reader::EQUATION_NAMES[blend_reader::EQUATION_COUNT] = {
{ "add", BGFX_STATE_BLEND_EQUATION_ADD },
{ "sub", BGFX_STATE_BLEND_EQUATION_SUB },
{ "subtract", BGFX_STATE_BLEND_EQUATION_SUB },
{ "revSub", BGFX_STATE_BLEND_EQUATION_REVSUB },
{ "revSubtract", BGFX_STATE_BLEND_EQUATION_REVSUB },
{ "min", BGFX_STATE_BLEND_EQUATION_MIN },
{ "max", BGFX_STATE_BLEND_EQUATION_MAX }
};
const blend_reader::string_to_enum blend_reader::FUNCTION_NAMES[blend_reader::FUNCTION_COUNT] = {
{ "0", BGFX_STATE_BLEND_ZERO },
{ "zero", BGFX_STATE_BLEND_ZERO },
{ "1", BGFX_STATE_BLEND_ONE },
{ "one", BGFX_STATE_BLEND_ONE },
{ "srcColor", BGFX_STATE_BLEND_SRC_COLOR },
{ "1-srcColor", BGFX_STATE_BLEND_INV_SRC_COLOR },
{ "invSrcColor", BGFX_STATE_BLEND_INV_SRC_COLOR },
{ "dstColor", BGFX_STATE_BLEND_DST_COLOR },
{ "1-dstColor", BGFX_STATE_BLEND_INV_DST_COLOR },
{ "invDstColor", BGFX_STATE_BLEND_INV_DST_COLOR },
{ "srcAlpha", BGFX_STATE_BLEND_SRC_ALPHA },
{ "1-srcAlpha", BGFX_STATE_BLEND_INV_SRC_ALPHA },
{ "invSrcAlpha", BGFX_STATE_BLEND_INV_SRC_ALPHA },
{ "dstAlpha", BGFX_STATE_BLEND_DST_ALPHA },
{ "1-dstAlpha", BGFX_STATE_BLEND_INV_DST_ALPHA },
{ "invDstAlpha", BGFX_STATE_BLEND_INV_DST_ALPHA }
};
uint64_t blend_reader::read_from_value(const Value& value)
{
uint64_t equation = get_enum_from_value(value, "equation", BGFX_STATE_BLEND_EQUATION_ADD, EQUATION_NAMES, EQUATION_COUNT);
uint64_t srccolor = get_enum_from_value(value, "srcColor", BGFX_STATE_BLEND_ONE, FUNCTION_NAMES, FUNCTION_COUNT);
uint64_t dstcolor = get_enum_from_value(value, "dstColor", BGFX_STATE_BLEND_ZERO, FUNCTION_NAMES, FUNCTION_COUNT);
uint64_t srcalpha = get_enum_from_value(value, "srcAlpha", BGFX_STATE_BLEND_ONE, FUNCTION_NAMES, FUNCTION_COUNT);
uint64_t dstalpha = get_enum_from_value(value, "dstAlpha", BGFX_STATE_BLEND_ZERO, FUNCTION_NAMES, FUNCTION_COUNT);
return BGFX_STATE_BLEND_EQUATION(equation) | BGFX_STATE_BLEND_FUNC_SEPARATE(srccolor, dstcolor, srcalpha, dstalpha);
}

View File

@ -0,0 +1,23 @@
#pragma once
#ifndef __DRAWBGFX_BLEND_READER__
#define __DRAWBGFX_BLEND_READER__
#include <bgfx/bgfx.h>
#include "statereader.h"
using namespace rapidjson;
class blend_reader : public state_reader {
public:
static uint64_t read_from_value(const Value& value);
private:
static const int EQUATION_COUNT = 7;
static const string_to_enum EQUATION_NAMES[EQUATION_COUNT];
static const int FUNCTION_COUNT = 16;
static const string_to_enum FUNCTION_NAMES[FUNCTION_COUNT];
};
#endif // __DRAWBGFX_BLEND_READER__

View File

@ -0,0 +1,14 @@
#include <bgfx/bgfx.h>
#include "cullreader.h"
const cull_reader::string_to_enum cull_reader::MODE_NAMES[cull_reader::MODE_COUNT] = {
{ "none", 0 },
{ "cw", BGFX_STATE_CULL_CW },
{ "ccw", BGFX_STATE_CULL_CCW }
};
uint64_t cull_reader::read_from_value(const Value& value)
{
return get_enum_from_value(value, "mode", BGFX_STATE_CULL_CCW, MODE_NAMES, MODE_COUNT);
}

View File

@ -0,0 +1,17 @@
#pragma once
#ifndef __DRAWBGFX_CULL_READER__
#define __DRAWBGFX_CULL_READER__
#include "statereader.h"
class cull_reader : public state_reader {
public:
static uint64_t read_from_value(const Value& value);
private:
static const int MODE_COUNT = 3;
static const string_to_enum MODE_NAMES[MODE_COUNT];
};
#endif // __DRAWBGFX_CULL_READER__

View File

@ -0,0 +1,28 @@
#include <bgfx/bgfx.h>
#include "depthreader.h"
const depth_reader::string_to_enum depth_reader::FUNCTION_NAMES[depth_reader::FUNCTION_COUNT] = {
{ "never", BGFX_STATE_DEPTH_TEST_NEVER },
{ "less", BGFX_STATE_DEPTH_TEST_LESS },
{ "equal", BGFX_STATE_DEPTH_TEST_EQUAL },
{ "lequal", BGFX_STATE_DEPTH_TEST_LEQUAL },
{ "greater", BGFX_STATE_DEPTH_TEST_GREATER },
{ "notequal", BGFX_STATE_DEPTH_TEST_NOTEQUAL },
{ "gequal", BGFX_STATE_DEPTH_TEST_GEQUAL },
{ "always", BGFX_STATE_DEPTH_TEST_ALWAYS }
};
uint64_t depth_reader::read_from_value(const Value& value)
{
uint64_t write_enable = 0;
if (value.HasMember("writeEnable"))
{
assert(value["writeEnable"].IsBool());
write_enable = value["writeEnable"].GetBool() ? BGFX_STATE_DEPTH_WRITE: 0;
}
uint64_t function = get_enum_from_value(value, "function", BGFX_STATE_DEPTH_TEST_ALWAYS, FUNCTION_NAMES, FUNCTION_COUNT);
return write_enable | function;
}

View File

@ -0,0 +1,17 @@
#pragma once
#ifndef __DRAWBGFX_DEPTH_READER__
#define __DRAWBGFX_DEPTH_READER__
#include "statereader.h"
class depth_reader : public state_reader {
public:
static uint64_t read_from_value(const Value& value);
private:
static const int FUNCTION_COUNT = 8;
static const string_to_enum FUNCTION_NAMES[FUNCTION_COUNT];
};
#endif // __DRAWBGFX_DEPTH_READER__

View File

@ -0,0 +1,44 @@
#include "effect.h"
bgfx_effect::bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, std::vector<bgfx_uniform*> uniforms)
: m_state(state)
{
m_program_handle = bgfx::createProgram(vertex_shader, fragment_shader, false);
for (int i = 0; i < uniforms.size(); i++)
{
m_uniforms[uniforms[i]->name()] = uniforms[i];
}
}
bgfx_effect::~bgfx_effect()
{
for (std::pair<std::string, bgfx_uniform*> uniform : m_uniforms)
{
delete uniform.second;
}
m_uniforms.clear();
bgfx::destroyProgram(m_program_handle);
}
void bgfx_effect::submit(int view)
{
for (std::pair<std::string, bgfx_uniform*> uniform_pair : m_uniforms)
{
(uniform_pair.second)->upload();
}
bgfx::setState(m_state);
bgfx::submit(view, m_program_handle);
}
bgfx_uniform* bgfx_effect::uniform(std::string name)
{
std::map<std::string, bgfx_uniform*>::iterator iter = m_uniforms.find(name);
if (iter != m_uniforms.end())
{
return iter->second;
}
return nullptr;
}

View File

@ -0,0 +1,32 @@
#pragma once
#ifndef __DRAWBGFX_EFFECT__
#define __DRAWBGFX_EFFECT__
#include <bgfx/bgfx.h>
#include <string>
#include <vector>
#include <map>
#include "uniform.h"
class bgfx_effect
{
public:
bgfx_effect(uint64_t state, bgfx::ShaderHandle vertexShader, bgfx::ShaderHandle fragmentShader, std::vector<bgfx_uniform*> uniforms);
~bgfx_effect();
void submit(int view);
// Getters
bgfx_uniform* uniform(std::string name);
bgfx::ProgramHandle get_program() const { return m_program_handle; }
private:
uint64_t m_state;
bgfx::ProgramHandle m_program_handle;
std::map<std::string, bgfx_uniform*> m_uniforms;
};
#endif // __DRAWBGFX_EFFECT__

View File

@ -0,0 +1,55 @@
#include "emu.h"
#include <rapidjson/document.h>
#include <bgfx/bgfxplatform.h>
#include <bgfx/bgfx.h>
#include <bx/readerwriter.h>
#include "effectmanager.h"
#include "effectreader.h"
#include "effect.h"
using namespace rapidjson;
effect_manager::~effect_manager()
{
for (std::pair<std::string, bgfx_effect*> effect : m_effects)
{
delete effect.second;
}
m_effects.clear();
}
bgfx_effect* effect_manager::effect(std::string name)
{
std::map<std::string, bgfx_effect*>::iterator iter = m_effects.find(name);
if (iter != m_effects.end())
{
return iter->second;
}
return load_effect(name);
}
bgfx_effect* effect_manager::load_effect(std::string name) {
std::string path = "bgfx/effects/" + name + ".json";
bx::CrtFileReader reader;
bx::open(&reader, path.c_str());
int32_t size = (uint32_t)bx::getSize(&reader);
char* data = new char[size + 1];
bx::read(&reader, reinterpret_cast<void*>(data), size);
bx::close(&reader);
data[size] = 0;
Document document;
document.Parse<0>(data);
bgfx_effect* effect = effect_reader::read_from_value(m_shaders, document);
m_effects[name] = effect;
return effect;
}

View File

@ -0,0 +1,30 @@
#pragma once
#ifndef __DRAWBGFX_EFFECT_MANAGER__
#define __DRAWBGFX_EFFECT_MANAGER__
#include <map>
#include <string>
#include <bgfx/bgfx.h>
#include "shadermanager.h"
class bgfx_effect;
class effect_manager {
public:
effect_manager(shader_manager& shaders) : m_shaders(shaders) { }
~effect_manager();
// Getters
bgfx_effect* effect(std::string name);
private:
bgfx_effect* load_effect(std::string name);
shader_manager& m_shaders;
std::map<std::string, bgfx_effect*> m_effects;
};
#endif // __DRAWBGFX_EFFECT_MANAGER__

View File

@ -0,0 +1,69 @@
#include <string>
#include <bgfx/bgfx.h>
#include "emu.h"
#include "effect.h"
#include "blendreader.h"
#include "depthreader.h"
#include "cullreader.h"
#include "writereader.h"
#include "shadermanager.h"
#include "uniformreader.h"
#include "effectreader.h"
bgfx_effect* effect_reader::read_from_value(shader_manager& shaders, const Value& value)
{
validate_parameters(value);
uint64_t blend = blend_reader::read_from_value(value["blend"]);
uint64_t depth = depth_reader::read_from_value(value["depth"]);
uint64_t cull = cull_reader::read_from_value(value["cull"]);
uint64_t write = write_reader::read_from_value(value["write"]);
std::vector<bgfx_uniform*> uniforms;
const Value& uniform_array = value["uniforms"];
for (UINT32 i = 0; i < uniform_array.Size(); i++)
{
uniforms.push_back(uniform_reader::read_from_value(uniform_array[i]));
}
std::string vertex_name(value["vertex"].GetString());
bgfx::ShaderHandle vertex_shader = shaders.shader(vertex_name);
std::string fragment_name("");
if (value.HasMember("fragment"))
{
fragment_name = value["fragment"].GetString();
}
else if (value.HasMember("pixel"))
{
fragment_name = value["pixel"].GetString();
}
bgfx::ShaderHandle fragment_shader = shaders.shader(fragment_name);
return new bgfx_effect(blend | depth | cull | write, vertex_shader, fragment_shader, uniforms);
}
void effect_reader::validate_parameters(const Value& value)
{
assert(value.HasMember("blend"));
assert(value.HasMember("depth"));
assert(value.HasMember("cull"));
assert(value.HasMember("write"));
assert(value.HasMember("vertex"));
assert(value["vertex"].IsString());
assert(value.HasMember("fragment") || value.HasMember("pixel"));
if (value.HasMember("fragment"))
{
assert(value["fragment"].IsString());
}
if (value.HasMember("pixel"))
{
assert(value["pixel"].IsString());
}
assert(value.HasMember("uniform"));
assert(value["uniform"].IsArray());
}

View File

@ -0,0 +1,20 @@
#pragma once
#ifndef __DRAWBGFX_EFFECT_READER__
#define __DRAWBGFX_EFFECT_READER__
#include "statereader.h"
class bgfx_effect;
class shader_manager;
class effect_reader : public state_reader
{
public:
static bgfx_effect* read_from_value(shader_manager& shaders, const Value& value);
private:
static void validate_parameters(const Value& value);
};
#endif // __DRAWBGFX_EFFECT_READER__

View File

@ -5,7 +5,7 @@ $input v_color0, v_texcoord0
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
SAMPLER2D(s_tex, 0);
SAMPLER2D(s_tex, 0);
void main()
{

View File

@ -1,11 +0,0 @@
$input v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_FragColor = v_color0;
}

View File

@ -1,11 +0,0 @@
$input v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_FragColor = v_color0;
}

View File

@ -0,0 +1,16 @@
$input v_color0, v_texcoord0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
SAMPLER2D(s_tex, 0);
uniform vec4 u_tint;
void main()
{
vec4 texel = texture2D(s_tex, v_texcoord0);
gl_FragColor = texel * v_color0 * u_tint;
}

View File

@ -0,0 +1,33 @@
#include "emu.h"
#include <bgfx/bgfx.h>
#include "effect.h"
#include "texture.h"
#include "target.h"
#include "pass.h"
bgfx_pass::bgfx_pass(std::string name, bgfx_effect* effect, std::vector<bgfx_texture*>& inputs, bgfx_target* output)
: m_name(name)
, m_effect(effect)
, m_output(output)
{
for (bgfx_texture* input : inputs)
{
m_inputs.push_back(input);
}
}
bgfx_pass::~bgfx_pass()
{
}
void bgfx_pass::submit(render_primitive* prim, int view)
{
for (int index = 0; index < m_inputs.size(); index++)
{
bgfx::setTexture(index, m_effect->uniform(m_inputs[index]->name())->handle(), m_inputs[index]->handle());
}
bgfx::setViewFrameBuffer(view, m_output->target());
m_effect->submit(view);
}

View File

@ -0,0 +1,32 @@
#pragma once
#ifndef __DRAWBGFX_PASS__
#define __DRAWBGFX_PASS__
#include <string>
#include <vector>
class render_primitive;
class bgfx_effect;
class bgfx_texture;
class bgfx_target;
class bgfx_pass
{
public:
bgfx_pass(std::string name, bgfx_effect* effect, std::vector<bgfx_texture*>& inputs, bgfx_target* output);
~bgfx_pass();
void submit(render_primitive* prim, int view);
// Getters
std::string name() const { return m_name; }
private:
std::string m_name;
bgfx_effect* m_effect;
std::vector<bgfx_texture*> m_inputs;
bgfx_target* m_output;
};
#endif // __DRAWBGFX_PASS__

View File

@ -0,0 +1,49 @@
#include <string>
#include "emu.h"
#include "passreader.h"
#include "texturemanager.h"
#include "targetmanager.h"
#include "effectmanager.h"
#include "pass.h"
bgfx_pass* pass_reader::read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects)
{
validate_parameters(value);
bgfx_effect* effect = effects.effect(value["effect"].GetString());
std::vector<bgfx_texture*> inputs;
if (value.HasMember("input"))
{
const Value& input_array = value["input"];
for (UINT32 i = 0; i < input_array.Size(); i++)
{
inputs.push_back(textures.texture(input_array[i].GetString()));
}
}
bgfx_target* output = targets.target(value["output"].GetString());
return new bgfx_pass(value["name"].GetString(), effect, inputs, output);
}
void pass_reader::validate_parameters(const Value& value)
{
assert(value.HasMember("name"));
assert(value["name"].IsString());
assert(value.HasMember("output"));
assert(value["output"].IsString());
assert(value.HasMember("effect"));
assert(value["effect"].IsString());
if (value.HasMember("input"))
{
const Value& input_array = value["input"];
for (int i = 0; i < input_array.Size(); i++)
{
assert(uniform_array[i].IsString());
}
}
}

View File

@ -0,0 +1,22 @@
#pragma once
#ifndef __DRAWBGFX_PASS_READER__
#define __DRAWBGFX_PASS_READER__
#include "statereader.h"
class bgfx_pass;
class texture_manager;
class target_manager;
class effect_manager;
class pass_reader : public state_reader
{
public:
static bgfx_pass* read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects);
private:
static void validate_parameters(const Value& value);
};
#endif // __DRAWBGFX_PASS_READER__

View File

@ -0,0 +1,73 @@
#include "emu.h"
#include <bgfx/bgfxplatform.h>
#include <bgfx/bgfx.h>
#include <bx/fpumath.h>
#include <bx/readerwriter.h>
#include "shadermanager.h"
shader_manager::~shader_manager()
{
for (std::pair<std::string, bgfx::ShaderHandle> shader : m_shaders)
{
bgfx::destroyShader(shader.second);
}
m_shaders.clear();
}
bgfx::ShaderHandle shader_manager::shader(std::string name)
{
std::map<std::string, bgfx::ShaderHandle>::iterator iter = m_shaders.find(name);
if (iter != m_shaders.end())
{
return iter->second;
}
return load_shader(name);
}
bgfx::ShaderHandle shader_manager::load_shader(std::string name) {
std::string shader_path = "shaders/dx9/";
switch (bgfx::getRendererType())
{
case bgfx::RendererType::Direct3D11:
case bgfx::RendererType::Direct3D12:
shader_path = "shaders/dx11/";
break;
case bgfx::RendererType::OpenGL:
shader_path = "shaders/glsl/";
break;
case bgfx::RendererType::Metal:
shader_path = "shaders/metal/";
break;
case bgfx::RendererType::OpenGLES:
shader_path = "shaders/gles/";
break;
default:
break;
}
bgfx::ShaderHandle handle = bgfx::createShader(load_mem(shader_path + name + ".bin"));
m_shaders[name] = handle;
return handle;
}
const bgfx::Memory* shader_manager::load_mem(std::string name) {
bx::CrtFileReader reader;
bx::open(&reader, name.c_str());
uint32_t size = (uint32_t)bx::getSize(&reader);
const bgfx::Memory* mem = bgfx::alloc(size + 1);
bx::read(&reader, mem->data, size);
bx::close(&reader);
mem->data[mem->size - 1] = '\0';
return mem;
}

View File

@ -0,0 +1,26 @@
#pragma once
#ifndef __DRAWBGFX_SHADER_MANAGER__
#define __DRAWBGFX_SHADER_MANAGER__
#include <map>
#include <string>
#include <bgfx/bgfx.h>
class shader_manager {
public:
shader_manager() {}
~shader_manager();
// Getters
bgfx::ShaderHandle shader(std::string name);
private:
bgfx::ShaderHandle load_shader(std::string name);
static const bgfx::Memory* load_mem(std::string name);
std::map<std::string, bgfx::ShaderHandle> m_shaders;
};
#endif // __DRAWBGFX_SHADER_MANAGER__

View File

@ -0,0 +1,107 @@
#include "statereader.h"
uint64_t state_reader::get_enum_from_value(const Value& value, std::string name, const uint64_t default_value, const string_to_enum* enums, const int count)
{
if (value.HasMember(name.c_str()))
{
assert(value[name.c_str()].IsString());
return get_param_from_string(value[name.c_str()].GetString(), enums, count);
}
else
{
return default_value;
}
}
uint64_t state_reader::get_param_from_string(std::string value, const string_to_enum* enums, const int count)
{
for (int i = 0; i < count; i++)
{
if (value == enums[i].m_string)
{
return enums[i].m_enum;
}
}
assert(false);
return 0;
}
void state_reader::validate_array_parameter(const Value& value, std::string typeName, std::string paramName, const int count)
{
const char* name = paramName.c_str();
if (value.HasMember(name))
{
assert(value[name].IsArray());
assert(value[name].Size() == count);
}
}
void state_reader::validate_double_parameter(const Value& value, std::string typeName, std::string name)
{
if (value.HasMember(name.c_str()))
{
assert(value[name.c_str()].IsDouble());
}
}
void state_reader::validate_string_parameter(const Value& value, std::string typeName, std::string name)
{
if (value.HasMember(name.c_str()))
{
assert(value[name.c_str()].IsString());
}
}
void state_reader::validate_boolean_parameter(const Value& value, std::string typeName, std::string name)
{
if (value.HasMember(name.c_str()))
{
assert(value[name.c_str()].IsBool());
}
}
bool state_reader::get_bool(const Value& value, const std::string name, const bool default_value)
{
if (value.HasMember(name.c_str()))
{
return value[name.c_str()].GetBool();
}
return default_value;
}
void state_reader::get_float(const Value& value, const std::string name, float* out, float* default_value, int count)
{
if (value.HasMember(name.c_str()))
{
if (count == 1)
{
*out = (float) value[name.c_str()].GetDouble();
return;
}
else
{
get_vec_values(value[name.c_str()], out, count);
}
}
for (int def = 0; def < count; def++)
{
out[def] = default_value[def];
}
}
void state_reader::get_vec_values(const Value& value_array, float* data, const unsigned int count)
{
for (unsigned int i = 0; i < count && i < value_array.Size(); i++)
{
data[i] = (float) value_array[i].GetDouble();
}
}
std::string state_reader::get_string(const Value& value, const std::string name, const std::string default_value)
{
if (value.HasMember(name.c_str()))
{
return std::string(value[name.c_str()].GetString());
}
return default_value;
}

View File

@ -0,0 +1,38 @@
#pragma once
#ifndef __DRAWBGFX_STATE_READER__
#define __DRAWBGFX_STATE_READER__
#include "emu.h"
#include <string>
#include "rapidjson/document.h"
using namespace rapidjson;
class state_reader
{
protected:
struct string_to_enum
{
std::string m_string;
const UINT64 m_enum;
};
static void validate_array_parameter(const Value& value, std::string type_name, std::string name, const int count);
static void validate_double_parameter(const Value& value, std::string type_name, std::string name);
static void validate_string_parameter(const Value& value, std::string type_name, std::string name);
static void validate_boolean_parameter(const Value& value, std::string type_name, std::string name);
static bool get_bool(const Value& value, const std::string name, const bool default_value);
static void get_float(const Value& value, const std::string name, float* out, float* default_value, const int count = 1);
static std::string get_string(const Value& value, const std::string name, const std::string default_value);
static uint64_t get_enum_from_value(const Value& value, std::string name, const uint64_t default_value, const string_to_enum* enums, const int count);
static uint64_t get_param_from_string(std::string value, const string_to_enum* enums, const int count);
private:
static void get_vec_values(const Value& value_array, float* data, const unsigned int count);
};
#endif // __DRAWBGFX_STATE_READER__

View File

@ -0,0 +1,12 @@
#include "target.h"
bgfx_target::bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter)
: bgfx_texture(name, format, width, height, nullptr, BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | (filter ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT)))
{
m_target = bgfx::createFrameBuffer(1, &m_handle, false);
}
bgfx_target::~bgfx_target()
{
bgfx::destroyFrameBuffer(m_target);
}

View File

@ -0,0 +1,21 @@
#pragma once
#ifndef __DRAWBGFX_TARGET__
#define __DRAWBGFX_TARGET__
#include "texture.h"
class bgfx_target : public bgfx_texture
{
public:
bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter = false);
virtual ~bgfx_target();
// Getters
bgfx::FrameBufferHandle target() const { return m_target; }
private:
bgfx::FrameBufferHandle m_target;
};
#endif // __DRAWBGFX_TARGET__

View File

@ -0,0 +1,33 @@
#include <bgfx/bgfx.h>
#include "targetmanager.h"
#include "target.h"
target_manager::~target_manager()
{
for (std::pair<std::string, bgfx_target*> target : m_targets)
{
delete target.second;
}
m_targets.clear();
}
bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter)
{
bgfx_target* target = new bgfx_target(name, format, width, height, filter);
m_targets[name] = target;
m_textures.add_texture(name, target);
return target;
}
bgfx_target* target_manager::target(std::string name)
{
std::map<std::string, bgfx_target*>::iterator iter = m_targets.find(name);
if (iter != m_targets.end())
{
return iter->second;
}
return nullptr;
}

View File

@ -0,0 +1,32 @@
#pragma once
#ifndef __DRAWBGFX_TARGET_MANAGER__
#define __DRAWBGFX_TARGET_MANAGER__
#include <map>
#include <string>
#include <bgfx/bgfx.h>
#include "texturemanager.h"
class bgfx_target;
class target_manager {
public:
target_manager(texture_manager& textures) : m_textures(textures) { }
~target_manager();
bgfx_target* create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter = false);
// Getters
bgfx_target* target(std::string name);
private:
bgfx_target* create_target(std::string name);
std::map<std::string, bgfx_target*> m_targets;
texture_manager& m_textures;
};
#endif // __DRAWBGFX_TARGET_MANAGER__

View File

@ -0,0 +1,30 @@
#include "emu.h"
#include "texture.h"
bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, void* data, uint32_t flags)
: m_name(name)
, m_format(format)
, m_width(width)
, m_height(height)
{
bgfx::TextureInfo info;
bgfx::calcTextureSize(info, width, height, 1, false, 1, format);
if (data != nullptr)
{
m_handle = bgfx::createTexture2D(width, height, 1, format, flags, bgfx::copy(data, info.storageSize));
}
else
{
m_handle = bgfx::createTexture2D(width, height, 1, format, flags);
const bgfx::Memory* memory = bgfx::alloc(info.storageSize);
memset(memory->data, 0, info.storageSize);
bgfx::updateTexture2D(m_handle, 0, 0, 0, width, height, memory, info.storageSize / height);
}
}
bgfx_texture::~bgfx_texture()
{
bgfx::destroyTexture(m_handle);
}

View File

@ -0,0 +1,31 @@
#pragma once
#ifndef __DRAWBGFX_TEXTURE__
#define __DRAWBGFX_TEXTURE__
#include <bgfx/bgfx.h>
#include <string>
class bgfx_texture
{
public:
bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, void* data = nullptr, uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP);
virtual ~bgfx_texture();
// Getters
std::string name() const { return m_name; }
bgfx::TextureFormat::Enum format() const { return m_format; }
uint32_t width() const { return m_width; }
uint32_t height() const { return m_height; }
bgfx::TextureHandle handle() const { return m_handle; }
protected:
std::string m_name;
bgfx::TextureFormat::Enum m_format;
uint32_t m_width;
uint32_t m_height;
bgfx::TextureHandle m_handle;
};
#endif // __DRAWBGFX_TEXTURE__

View File

@ -0,0 +1,36 @@
#include <bgfx/bgfx.h>
#include "texturemanager.h"
#include "texture.h"
texture_manager::~texture_manager()
{
for (std::pair<std::string, bgfx_texture*> texture : m_textures)
{
delete texture.second;
}
m_textures.clear();
}
void texture_manager::add_texture(std::string name, bgfx_texture* texture)
{
m_textures[name] = texture;
}
bgfx_texture* texture_manager::create_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, void* data, uint32_t flags)
{
bgfx_texture* texture = new bgfx_texture(name, format, width, height, data, flags);
m_textures[name] = texture;
return texture;
}
bgfx_texture* texture_manager::texture(std::string name)
{
std::map<std::string, bgfx_texture*>::iterator iter = m_textures.find(name);
if (iter != m_textures.end())
{
return iter->second;
}
return nullptr;
}

View File

@ -0,0 +1,30 @@
#pragma once
#ifndef __DRAWBGFX_TEXTURE_MANAGER__
#define __DRAWBGFX_TEXTURE_MANAGER__
#include <map>
#include <string>
#include <bgfx/bgfx.h>
class bgfx_texture;
class texture_manager {
public:
texture_manager() { }
~texture_manager();
bgfx_texture* create_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, void* data = nullptr, uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP);
void add_texture(std::string name, bgfx_texture* texture);
// Getters
bgfx_texture* texture(std::string name);
private:
bgfx_texture* create_texture(std::string name);
std::map<std::string, bgfx_texture*> m_textures;
};
#endif // __DRAWBGFX_TEXTURE_MANAGER__

View File

@ -0,0 +1,72 @@
#include "uniform.h"
bgfx_uniform::bgfx_uniform(std::string name, bgfx::UniformType::Enum type)
: m_name(name)
, m_type(type)
{
m_handle = bgfx::createUniform(m_name.c_str(), m_type);
m_data_size = get_size_for_type(type);
if (m_data_size > 0)
{
m_data = new uint8_t[m_data_size];
}
}
bgfx_uniform::~bgfx_uniform()
{
bgfx::destroyUniform(m_handle);
delete [] m_data;
}
void bgfx_uniform::upload()
{
bgfx::setUniform(m_handle, m_data);
}
bgfx_uniform* bgfx_uniform::set(float* value)
{
return set(value, get_size_for_type(bgfx::UniformType::Vec4));
}
bgfx_uniform* bgfx_uniform::set_int(int value)
{
return set(&value, get_size_for_type(bgfx::UniformType::Int1));
}
bgfx_uniform* bgfx_uniform::set_mat3(float* value)
{
return set(value, get_size_for_type(bgfx::UniformType::Mat3));
}
bgfx_uniform* bgfx_uniform::set_mat4(float* value)
{
return set(value, get_size_for_type(bgfx::UniformType::Mat4));
}
bgfx_uniform* bgfx_uniform::set(void* data, size_t size)
{
int min_size = (size < m_data_size) ? size : m_data_size;
memcpy(m_data, data, min_size);
return this;
}
size_t bgfx_uniform::get_size_for_type(bgfx::UniformType::Enum type)
{
switch (type)
{
case bgfx::UniformType::Vec4:
return sizeof(float) * 4;
case bgfx::UniformType::Int1:
return sizeof(int);
case bgfx::UniformType::Mat3:
return sizeof(float) * 3 * 3;
case bgfx::UniformType::Mat4:
return sizeof(float) * 4 * 4;
default:
return 0;
}
}

View File

@ -0,0 +1,40 @@
#pragma once
#ifndef __DRAWBGFX_UNIFORM__
#define __DRAWBGFX_UNIFORM__
#include <bgfx/bgfx.h>
#include <string>
class bgfx_uniform
{
public:
bgfx_uniform(std::string name, bgfx::UniformType::Enum type);
virtual ~bgfx_uniform();
virtual void upload();
// Getters
std::string name() { return m_name; }
bgfx::UniformType::Enum type() const { return m_type; }
bgfx::UniformHandle handle() const { return m_handle; }
// Setters
bgfx_uniform* set(float* value);
bgfx_uniform* set_int(int value);
bgfx_uniform* set_mat3(float* value);
bgfx_uniform* set_mat4(float* value);
bgfx_uniform* set(void* data, size_t size);
static size_t get_size_for_type(bgfx::UniformType::Enum type);
protected:
bgfx::UniformHandle m_handle;
std::string m_name;
bgfx::UniformType::Enum m_type;
uint8_t* m_data;
size_t m_data_size;
};
#endif // __DRAWBGFX_UNIFORM__

View File

@ -0,0 +1,45 @@
#include "uniformreader.h"
#include "uniform.h"
const uniform_reader::string_to_enum uniform_reader::TYPE_NAMES[uniform_reader::TYPE_COUNT] = {
{ "int", bgfx::UniformType::Int1 },
{ "vec4", bgfx::UniformType::Vec4 },
{ "mat3", bgfx::UniformType::Mat3 },
{ "mat4", bgfx::UniformType::Mat4 },
{ "camera", bgfx::UniformType::Mat4 }
};
bgfx_uniform* uniform_reader::read_from_value(const Value& value)
{
assert(value.HasMember("name"));
assert(value["name"].IsString());
const char* name = value["name"].GetString();
assert(value.HasMember("type"));
bgfx::UniformType::Enum type = bgfx::UniformType::Enum(get_enum_from_value(value, "type", bgfx::UniformType::Vec4, TYPE_NAMES, TYPE_COUNT));
const size_t type_size = bgfx_uniform::get_size_for_type(type);
assert(value.HasMember("values"));
assert(value["values"].IsArray());
const Value& value_array = value["values"];
const size_t array_size = value_array.Size() * sizeof(float);
const size_t alloc_size = (type_size > array_size) ? type_size : array_size;
float* data = reinterpret_cast<float*>(new char[alloc_size]);
unsigned int index = 0;
for (; index < type_size / 4 && index < value_array.Size(); index++)
{
data[index] = (float)value_array[index].GetDouble();
}
for (; index < type_size / 4; index++) {
data[index] = 0.0f;
}
bgfx_uniform* uniform = new bgfx_uniform(name, type);
uniform->set((void*)data, type_size);
delete [] data;
return uniform;
}

View File

@ -0,0 +1,33 @@
#pragma once
#ifndef __DRAWBGFX_UNIFORM_READER__
#define __DRAWBGFX_UNIFORM_READER__
#include <bgfx/bgfx.h>
#include "statereader.h"
class bgfx_uniform;
enum uniform_type
{
TYPE_INT1 = bgfx::UniformType::Int1,
TYPE_VEC4 = bgfx::UniformType::Vec4,
TYPE_MAT3 = bgfx::UniformType::Mat3,
TYPE_MAT4 = bgfx::UniformType::Mat4,
TYPE_CAMERA, // Alias for the current ortho camera, used to auto-bind on material load
TYPE_COUNT = 5
};
class uniform_reader : public state_reader
{
public:
static bgfx_uniform* read_from_value(const Value& value);
private:
static const int TYPE_COUNT = uniform_type::TYPE_COUNT;
static const string_to_enum TYPE_NAMES[TYPE_COUNT];
};
#endif // __DRAWBGFX_UNIFORM_READER__

View File

@ -1,13 +0,0 @@
$input a_position, a_color0
$output v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_color0 = a_color0;
}

View File

@ -1,5 +1,5 @@
$input a_position, a_color0
$output v_color0
$input a_position, a_texcoord0, a_color0
$output v_texcoord0, v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
@ -9,5 +9,6 @@ $output v_color0
void main()
{
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_texcoord0 = a_texcoord0;
v_color0 = a_color0;
}

View File

@ -0,0 +1,24 @@
#include <bgfx/bgfx.h>
#include "writereader.h"
const write_reader::string_to_enum write_reader::RGB_NAMES[write_reader::RGB_COUNT] = {
{ "true", BGFX_STATE_RGB_WRITE },
{ "false", 0 },
{ "1", BGFX_STATE_RGB_WRITE },
{ "0", 0 }
};
const write_reader::string_to_enum write_reader::ALPHA_NAMES[write_reader::ALPHA_COUNT] = {
{ "true", BGFX_STATE_ALPHA_WRITE },
{ "false", 0 },
{ "1", BGFX_STATE_ALPHA_WRITE },
{ "0", 0 }
};
uint64_t write_reader::read_from_value(const Value& value)
{
uint64_t rgb = get_enum_from_value(value, "rgb", 0, RGB_NAMES, RGB_COUNT);
uint64_t alpha = get_enum_from_value(value, "alpha", 0, ALPHA_NAMES, ALPHA_COUNT);
return rgb | alpha;
}

View File

@ -0,0 +1,19 @@
#pragma once
#ifndef __DRAWBGFX_WRITE_READER__
#define __DRAWBGFX_WRITE_READER__
#include "statereader.h"
class write_reader : public state_reader {
public:
static uint64_t read_from_value(const Value& value);
private:
static const int RGB_COUNT = 4;
static const int ALPHA_COUNT = 4;
static const string_to_enum RGB_NAMES[RGB_COUNT];
static const string_to_enum ALPHA_NAMES[ALPHA_COUNT];
};
#endif // __DRAWBGFX_WRITE_READER__

View File

@ -27,13 +27,11 @@
typedef IDirect3D9 *(WINAPI *direct3dcreate9_ptr)(UINT SDKVersion);
namespace d3d
{
//============================================================
// PROTOTYPES
//============================================================
static void set_interfaces(base *d3dptr);
static void set_interfaces(d3d_base *d3dptr);
//============================================================
// INLINES
@ -64,7 +62,7 @@ static inline void convert_present_params(const present_parameters *params, D3DP
// drawd3d9_init
//============================================================
base *drawd3d9_init(void)
d3d_base *drawd3d9_init(void)
{
bool post_available = true;
@ -119,7 +117,7 @@ base *drawd3d9_init(void)
}
// allocate an object to hold our data
auto d3dptr = global_alloc(base);
auto d3dptr = global_alloc(d3d_base);
d3dptr->version = 9;
d3dptr->d3dobj = d3d9;
d3dptr->dllhandle = dllhandle;
@ -137,20 +135,20 @@ base *drawd3d9_init(void)
// Direct3D interfaces
//============================================================
static HRESULT check_device_format(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, D3DFORMAT adapterformat, DWORD usage, D3DRESOURCETYPE restype, D3DFORMAT format)
static HRESULT check_device_format(d3d_base *d3dptr, UINT adapter, D3DDEVTYPE devtype, D3DFORMAT adapterformat, DWORD usage, D3DRESOURCETYPE restype, D3DFORMAT format)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_CheckDeviceFormat(d3d9, adapter, devtype, adapterformat, usage, restype, format);
}
static HRESULT check_device_type(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, D3DFORMAT format, D3DFORMAT backformat, BOOL windowed)
static HRESULT check_device_type(d3d_base *d3dptr, UINT adapter, D3DDEVTYPE devtype, D3DFORMAT format, D3DFORMAT backformat, BOOL windowed)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_CheckDeviceType(d3d9, adapter, devtype, format, backformat, windowed);
}
static HRESULT create_device(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, HWND focus, DWORD behavior, present_parameters *params, device **dev)
static HRESULT create_device(d3d_base *d3dptr, UINT adapter, D3DDEVTYPE devtype, HWND focus, DWORD behavior, present_parameters *params, device **dev)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
D3DPRESENT_PARAMETERS d3d9params;
@ -158,28 +156,28 @@ static HRESULT create_device(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, HWN
return IDirect3D9_CreateDevice(d3d9, adapter, devtype, focus, behavior, &d3d9params, (IDirect3DDevice9 **)dev);
}
static HRESULT enum_adapter_modes(base *d3dptr, UINT adapter, D3DFORMAT format, UINT index, D3DDISPLAYMODE *mode)
static HRESULT enum_adapter_modes(d3d_base *d3dptr, UINT adapter, D3DFORMAT format, UINT index, D3DDISPLAYMODE *mode)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_EnumAdapterModes(d3d9, adapter, format, index, mode);
}
static UINT get_adapter_count(base *d3dptr)
static UINT get_adapter_count(d3d_base *d3dptr)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_GetAdapterCount(d3d9);
}
static HRESULT get_adapter_display_mode(base *d3dptr, UINT adapter, D3DDISPLAYMODE *mode)
static HRESULT get_adapter_display_mode(d3d_base *d3dptr, UINT adapter, D3DDISPLAYMODE *mode)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_GetAdapterDisplayMode(d3d9, adapter, mode);
}
static HRESULT get_adapter_identifier(base *d3dptr, UINT adapter, DWORD flags, adapter_identifier *identifier)
static HRESULT get_adapter_identifier(d3d_base *d3dptr, UINT adapter, DWORD flags, adapter_identifier *identifier)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
D3DADAPTER_IDENTIFIER9 id;
@ -197,21 +195,21 @@ static HRESULT get_adapter_identifier(base *d3dptr, UINT adapter, DWORD flags, a
}
static UINT get_adapter_mode_count(base *d3dptr, UINT adapter, D3DFORMAT format)
static UINT get_adapter_mode_count(d3d_base *d3dptr, UINT adapter, D3DFORMAT format)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_GetAdapterModeCount(d3d9, adapter, format);
}
static HMONITOR get_adapter_monitor(base *d3dptr, UINT adapter)
static HMONITOR get_adapter_monitor(d3d_base *d3dptr, UINT adapter)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
return IDirect3D9_GetAdapterMonitor(d3d9, adapter);
}
static HRESULT get_caps_dword(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, caps_index which, DWORD *value)
static HRESULT get_caps_dword(d3d_base *d3dptr, UINT adapter, D3DDEVTYPE devtype, caps_index which, DWORD *value)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
D3DCAPS9 caps;
@ -237,7 +235,7 @@ static HRESULT get_caps_dword(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, ca
}
static ULONG release(base *d3dptr)
static ULONG release(d3d_base *d3dptr)
{
IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
ULONG result = IDirect3D9_Release(d3d9);
@ -469,7 +467,7 @@ static HRESULT device_test_cooperative_level(device *dev)
}
static const device_interface d3d9_device_interface =
static const d3d_device_interface d3d9_device_interface =
{
device_begin_scene,
device_clear,
@ -611,7 +609,7 @@ static const vertex_buffer_interface d3d9_vertex_buffer_interface =
// set_interfaces
//============================================================
static void set_interfaces(base *d3dptr)
static void set_interfaces(d3d_base *d3dptr)
{
d3dptr->d3d = d3d9_interface;
d3dptr->device = d3d9_device_interface;
@ -619,5 +617,3 @@ static void set_interfaces(base *d3dptr)
d3dptr->texture = d3d9_texture_interface;
d3dptr->vertexbuf = d3d9_vertex_buffer_interface;
}
}

View File

@ -13,10 +13,9 @@
// FORWARD DECLARATIONS
//============================================================
namespace d3d
{
class texture_info;
class renderer;
class renderer_d3d9;
struct d3d_base;
//============================================================
// TYPE DEFINITIONS
@ -51,12 +50,12 @@ public:
} c;
};
class texture_manager
class d3d_texture_manager
{
public:
texture_manager() { }
texture_manager(renderer *d3d);
~texture_manager();
d3d_texture_manager() { }
d3d_texture_manager(renderer_d3d9 *d3d);
~d3d_texture_manager();
void update_textures();
@ -81,10 +80,10 @@ public:
texture_info * get_default_texture() { return m_default_texture; }
texture_info * get_vector_texture() { return m_vector_texture; }
renderer * get_d3d() { return m_renderer; }
renderer_d3d9 * get_d3d() { return m_renderer; }
private:
renderer * m_renderer;
renderer_d3d9 * m_renderer;
texture_info * m_texlist; // list of active textures
int m_dynamic_supported; // are dynamic textures supported?
@ -108,7 +107,7 @@ private:
class texture_info
{
public:
texture_info(texture_manager *manager, const render_texinfo *texsource, int prescale, UINT32 flags);
texture_info(d3d_texture_manager *manager, const render_texinfo *texsource, int prescale, UINT32 flags);
~texture_info();
render_texinfo & get_texinfo() { return m_texinfo; }
@ -151,9 +150,9 @@ private:
void compute_size(int texwidth, int texheight);
void compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height);
texture_manager * m_texture_manager; // texture manager pointer
d3d_texture_manager * m_texture_manager; // texture manager pointer
renderer * m_renderer; // renderer pointer
renderer_d3d9 * m_renderer; // renderer pointer
texture_info * m_next; // next texture in the list
texture_info * m_prev; // prev texture in the list
@ -174,17 +173,17 @@ private:
texture * m_d3dfinaltex; // Direct3D final (post-scaled) texture
};
/* d3d::poly_info holds information about a single polygon/d3d primitive */
/* poly_info holds information about a single polygon/d3d primitive */
class poly_info
{
public:
poly_info() { }
void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, d3d::texture_info *texture, UINT32 modmode,
UINT32 flags, texture_info *texture, UINT32 modmode,
float prim_width, float prim_height);
void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, d3d::texture_info *texture, UINT32 modmode,
UINT32 flags, texture_info *texture, UINT32 modmode,
float line_time, float line_length,
float prim_width, float prim_height);
@ -193,7 +192,7 @@ public:
UINT32 get_vertcount() { return m_numverts; }
UINT32 get_flags() { return m_flags; }
d3d::texture_info * get_texture() { return m_texture; }
texture_info * get_texture() { return m_texture; }
DWORD get_modmode() { return m_modmode; }
float get_line_time() { return m_line_time; }
@ -219,16 +218,14 @@ private:
float m_prim_height; // used by quads
};
} // d3d
/* vertex describes a single vertex */
struct vertex
{
float x, y, z; // X,Y,Z coordinates
float rhw; // RHW when no HLSL, padding when HLSL
D3DCOLOR color; // diffuse color
float u0, v0; // texture stage 0 coordinates
float u1, v1; // additional info for vector data
float x, y, z; // X,Y,Z coordinates
float rhw; // RHW when no HLSL, padding when HLSL
D3DCOLOR color; // diffuse color
float u0, v0; // texture stage 0 coordinates
float u1, v1; // additional info for vector data
};
@ -239,5 +236,64 @@ struct line_aa_step
float weight; // weight contribution
};
/* cache_target is a simple linked list containing only a rednerable target and texture, used for phosphor effects */
class cache_target
{
public:
// construction/destruction
cache_target() { }
~cache_target();
bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y);
surface *last_target;
texture *last_texture;
int target_width;
int target_height;
int width;
int height;
int screen_index;
cache_target *next;
cache_target *prev;
};
/* render_target is the information about a Direct3D render target chain */
class d3d_render_target
{
public:
// construction/destruction
d3d_render_target() { }
~d3d_render_target();
bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y);
int next_index(int index) { return ++index > 1 ? 0 : index; }
int target_width;
int target_height;
int prescale_x;
int prescale_y;
int width;
int height;
int screen_index;
int page_index;
surface *prescale_target[2];
texture *prescale_texture[2];
surface *native_target[2];
texture *native_texture[2];
d3d_render_target *next;
d3d_render_target *prev;
surface *bloom_target[11];
texture *bloom_texture[11];
};
#endif

View File

@ -14,16 +14,6 @@
// Windows NT shipped with DirectX 3.0a
// Windows 95 shipped with DirectX 2
// standard windows headers
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <mmsystem.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <math.h>
#undef interface
// MAME headers
#include "emu.h"
#include "render.h"
@ -35,12 +25,12 @@
#include "screen.h"
// MAMEOS headers
#include "d3dintf.h"
#include "winmain.h"
#include "window.h"
#include "d3dcomm.h"
#include "modules/render/drawd3d.h"
#include "d3dcomm.h"
#include "strconv.h"
#include "d3dhlsl.h"
//============================================================
@ -48,10 +38,8 @@
//============================================================
static slider_state *g_slider_list;
static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx);
static file_error open_next(renderer_d3d9 *d3d, emu_file &file, const char *templ, const char *extension, int idx);
namespace d3d
{
//============================================================
// PROTOTYPES
//============================================================
@ -108,7 +96,7 @@ shaders::~shaders()
currcache = cachehead;
}
render_target *currtarget = targethead;
d3d_render_target *currtarget = targethead;
while(targethead != NULL)
{
targethead = currtarget->next;
@ -565,14 +553,14 @@ void shaders::remove_render_target(texture_info *texture)
void shaders::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
{
render_target *target = find_render_target(width, height, screen_index, page_index);
d3d_render_target *target = find_render_target(width, height, screen_index, page_index);
if (target != NULL)
{
remove_render_target(target);
}
}
void shaders::remove_render_target(render_target *rt)
void shaders::remove_render_target(d3d_render_target *rt)
{
if (rt != NULL)
{
@ -645,7 +633,7 @@ void shaders::set_texture(texture_info *texture)
// shaders::init
//============================================================
void shaders::init(base *d3dintf, running_machine *machine, d3d::renderer *renderer)
void shaders::init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *renderer)
{
if (!d3dintf->post_fx_available)
{
@ -1165,13 +1153,13 @@ void shaders::init_effect_info(poly_info *poly)
// shaders::find_render_target
//============================================================
render_target* shaders::find_render_target(texture_info *info)
d3d_render_target* shaders::find_render_target(texture_info *info)
{
UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata;
UINT32 screen_index = screen_index_data >> 1;
UINT32 page_index = screen_index_data & 1;
render_target *curr = targethead;
d3d_render_target *curr = targethead;
while (curr != NULL && (
curr->screen_index != screen_index ||
curr->page_index != page_index ||
@ -1189,9 +1177,9 @@ render_target* shaders::find_render_target(texture_info *info)
// shaders::find_render_target
//============================================================
render_target* shaders::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
d3d_render_target* shaders::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
{
render_target *curr = targethead;
d3d_render_target *curr = targethead;
while (curr != NULL && (
curr->width != width ||
curr->height != height ||
@ -1223,7 +1211,7 @@ cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int hei
return curr;
}
int shaders::ntsc_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::ntsc_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1290,7 +1278,7 @@ rgb_t shaders::apply_color_convolution(rgb_t color)
MAX(0, MIN(255, static_cast<int>(b * 255.0f))));
}
int shaders::color_convolution_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::color_convolution_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1305,7 +1293,7 @@ int shaders::color_convolution_pass(render_target *rt, int source_index, poly_in
return next_index;
}
int shaders::prescale_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::prescale_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1319,7 +1307,7 @@ int shaders::prescale_pass(render_target *rt, int source_index, poly_info *poly,
return next_index;
}
int shaders::deconverge_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::deconverge_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1342,7 +1330,7 @@ int shaders::deconverge_pass(render_target *rt, int source_index, poly_info *pol
return next_index;
}
int shaders::defocus_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::defocus_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1362,7 +1350,7 @@ int shaders::defocus_pass(render_target *rt, int source_index, poly_info *poly,
return next_index;
}
int shaders::phosphor_pass(render_target *rt, cache_target *ct, int source_index, poly_info *poly, int vertnum)
int shaders::phosphor_pass(d3d_render_target *rt, cache_target *ct, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1393,7 +1381,7 @@ int shaders::phosphor_pass(render_target *rt, cache_target *ct, int source_index
return next_index;
}
int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int vertnum, bool prepare_bloom)
int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum, bool prepare_bloom)
{
int next_index = source_index;
@ -1440,7 +1428,7 @@ int shaders::post_pass(render_target *rt, int source_index, poly_info *poly, int
return next_index;
}
int shaders::downsample_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::downsample_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1485,7 +1473,7 @@ int shaders::downsample_pass(render_target *rt, int source_index, poly_info *pol
return next_index;
}
int shaders::bloom_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::bloom_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1557,7 +1545,7 @@ int shaders::bloom_pass(render_target *rt, int source_index, poly_info *poly, in
return next_index;
}
int shaders::distortion_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::distortion_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1601,7 +1589,7 @@ int shaders::distortion_pass(render_target *rt, int source_index, poly_info *pol
return next_index;
}
int shaders::vector_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::vector_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1618,7 +1606,7 @@ int shaders::vector_pass(render_target *rt, int source_index, poly_info *poly, i
return next_index;
}
int shaders::vector_buffer_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::vector_buffer_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1635,7 +1623,7 @@ int shaders::vector_buffer_pass(render_target *rt, int source_index, poly_info *
return next_index;
}
int shaders::screen_pass(render_target *rt, int source_index, poly_info *poly, int vertnum)
int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
int next_index = source_index;
@ -1698,7 +1686,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
curr_render_target = find_render_target(curr_texture);
render_target *rt = curr_render_target;
d3d_render_target *rt = curr_render_target;
if (rt == NULL)
{
return;
@ -1744,7 +1732,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
{
curr_render_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
render_target *rt = curr_render_target;
d3d_render_target *rt = curr_render_target;
if (rt == NULL)
{
return;
@ -1766,7 +1754,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
{
curr_render_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
render_target *rt = curr_render_target;
d3d_render_target *rt = curr_render_target;
if (rt == NULL)
{
return;
@ -1844,7 +1832,7 @@ bool shaders::register_prescaled_texture(texture_info *texture)
//============================================================
// shaders::add_cache_target - register a cache target
//============================================================
bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
{
cache_target* target = (cache_target*)global_alloc_clear<cache_target>();
@ -1879,7 +1867,7 @@ bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int
return true;
}
render_target* shaders::get_vector_target()
d3d_render_target* shaders::get_vector_target()
{
if (!vector_enable)
{
@ -1902,13 +1890,13 @@ void shaders::create_vector_target(render_primitive *prim)
// shaders::add_render_target - register a render target
//============================================================
bool shaders::add_render_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale)
bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int xprescale, int yprescale)
{
UINT32 screen_index = 0;
UINT32 page_index = 0;
if (info != NULL)
{
render_target *existing_target = find_render_target(info);
d3d_render_target *existing_target = find_render_target(info);
if (existing_target != NULL)
{
remove_render_target(existing_target);
@ -1920,14 +1908,14 @@ bool shaders::add_render_target(renderer* d3d, texture_info* info, int width, in
}
else
{
render_target *existing_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
d3d_render_target *existing_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
if (existing_target != NULL)
{
remove_render_target(existing_target);
}
}
render_target* target = (render_target*)global_alloc_clear<render_target>();
d3d_render_target* target = (d3d_render_target*)global_alloc_clear<d3d_render_target>();
if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
{
@ -2069,7 +2057,7 @@ void shaders::delete_resources(bool reset)
currcache = cachehead;
}
render_target *currtarget = targethead;
d3d_render_target *currtarget = targethead;
while(targethead != NULL)
{
targethead = currtarget->next;
@ -2229,6 +2217,7 @@ static slider_state *slider_alloc(running_machine &machine, const char *title, I
state->incval = incval;
state->update = update;
state->arg = arg;
state->hidden = false;
strcpy(state->description, title);
return state;
@ -3040,7 +3029,7 @@ void uniform::update()
shaders *shadersys = m_shader->m_shaders;
hlsl_options *options = shadersys->options;
renderer *d3d = shadersys->d3d;
renderer_d3d9 *d3d = shadersys->d3d;
switch (m_id)
{
@ -3531,16 +3520,14 @@ ULONG effect::release()
return m_effect->Release();
}
}
//============================================================
// get_slider_list
//============================================================
void *windows_osd_interface::get_slider_list()
slider_state *windows_osd_interface::get_slider_list()
{
return (void*)g_slider_list;
return g_slider_list;
}
@ -3551,7 +3538,7 @@ void *windows_osd_interface::get_slider_list()
// scheme
//-------------------------------------------------
static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx)
static file_error open_next(renderer_d3d9 *d3d, emu_file &file, const char *templ, const char *extension, int idx)
{
UINT32 origflags = file.openflags();

Some files were not shown because too many files have changed in this diff Show More