mirror of
https://github.com/holub/mame
synced 2025-04-20 23:42:22 +03:00
More work on bgfx data-driven shaders, nw
This commit is contained in:
parent
db72f23b7c
commit
3172371fcd
@ -1,26 +1,26 @@
|
||||
{ "name": "Test Shader Chain",
|
||||
"author": "Ryan Holtz",
|
||||
"sliders": [
|
||||
{ "type": "bool", "name": "adjustments", "text": "Enable Adjustments", "default": false },
|
||||
{ "type": "float", "name": "ratio_amount", "text": "Ratio Amount", "default": 0, "max": 1, "min": 0 },
|
||||
|
||||
{ "type": "color", "name": "red_ratios", "text": "Red Amount", "default": [ 1, 0, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
|
||||
{ "type": "color", "name": "grn_ratios", "text": "Green Amount", "default": [ 0, 1, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
|
||||
{ "type": "color", "name": "blu_ratios", "text": "Blue Amount", "default": [ 0, 0, 1 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
|
||||
{ "type": "color", "name": "tint", "text": "Tint", "default": [ 1, 1, 1 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
|
||||
{ "type": "color", "name": "phosphor", "text": "Phosphor Amount", "default": [ 0, 0, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
|
||||
{ "type": "vec2", "name": "shift", "text": "Frame Shift", "default": [ 0, 0 ], "max": [ 25, 25 ], "min": [ -25, -25 ] }
|
||||
{ "type": "int_enum", "name": "adjustments", "text": "Enable Adjustments", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "On", "Off" ] },
|
||||
{ "type": "float", "name": "ratio_amount", "text": "Ratio Amount", "default": 0, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "any" },
|
||||
{ "type": "color", "name": "red_ratios", "text": "Color Matrix, Red from ", "default": [ 200, 0, 0 ], "max": [ 400, 400, 400 ], "min": [ -400, -400, -400 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" },
|
||||
{ "type": "color", "name": "grn_ratios", "text": "Color Matrix, Green from ", "default": [ 0, 200, 0 ], "max": [ 400, 400, 400 ], "min": [ -400, -400, -400 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" },
|
||||
{ "type": "color", "name": "blu_ratios", "text": "Color Matrix, Blue from ", "default": [ 0, 0, 200 ], "max": [ 400, 400, 400 ], "min": [ -400, -400, -400 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" },
|
||||
{ "type": "color", "name": "tint", "text": "Tint ", "default": [ 100, 100, 100 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "any" },
|
||||
{ "type": "color", "name": "phosphor", "text": "Phosphor Life, ", "default": [ 0, 0, 0 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "any" },
|
||||
{ "type": "vec2", "name": "shift", "text": "Frame Shift ", "default": [ 0, 0 ], "max": [ 25, 25 ], "min": [ -25, -25 ], "step": 1, "scale": 1.0, "format": "%2.f", "screen": "raster" }
|
||||
],
|
||||
"parameters": [
|
||||
{ "name": "alternating", "type": "frame_mask", "period": 2 }
|
||||
],
|
||||
"targets": [
|
||||
{ "name": "native",
|
||||
"screen": true
|
||||
"mode": "native",
|
||||
"prescale": 1
|
||||
},
|
||||
{ "name": "previous",
|
||||
"screen": true,
|
||||
"prescale": true
|
||||
"mode": "native",
|
||||
"prescale": 1
|
||||
}
|
||||
],
|
||||
"passes": [
|
||||
@ -31,10 +31,10 @@
|
||||
{ "type": "slider", "name": "ratio_amount", "value": 0 }
|
||||
],
|
||||
"uniforms": [
|
||||
{ "name": "u_ratio_amount", "slider": "ratio_amount" },
|
||||
{ "name": "u_red_ratios", "slider": "red_ratios" },
|
||||
{ "name": "u_grn_ratios", "slider": "grn_ratios" },
|
||||
{ "name": "u_blu_ratios", "slider": "blu_ratios" }
|
||||
{ "uniform": "u_ratio_amount", "slider": "ratio_amount" },
|
||||
{ "uniform": "u_red_ratios", "slider": "red_ratios" },
|
||||
{ "uniform": "u_grn_ratios", "slider": "grn_ratios" },
|
||||
{ "uniform": "u_blu_ratios", "slider": "blu_ratios" }
|
||||
],
|
||||
"input": [
|
||||
{ "sampler": "s_tex", "texture": "screen" }
|
||||
@ -47,8 +47,8 @@
|
||||
{ "type": "slider", "name": "adjustments", "value": false }
|
||||
],
|
||||
"uniforms": [
|
||||
{ "name": "u_tint", "slider": "tint" },
|
||||
{ "name": "u_shift", "slider": "shift" }
|
||||
{ "uniform": "u_tint", "slider": "tint" },
|
||||
{ "uniform": "u_shift", "slider": "shift" }
|
||||
],
|
||||
"input": [
|
||||
{ "sampler": "s_tex", "texture": "native" }
|
||||
@ -62,8 +62,8 @@
|
||||
{ "type": "slider", "name": "phosphor", "value": [ 0, 0, 0 ] }
|
||||
],
|
||||
"uniforms": [
|
||||
{ "name": "u_passthrough", "value": [ 0 ] },
|
||||
{ "name": "u_phosphor", "slider": "phosphor" }
|
||||
{ "uniform": "u_passthrough", "value": [ 0 ] },
|
||||
{ "uniform": "u_phosphor", "slider": "phosphor" }
|
||||
],
|
||||
"input": [
|
||||
{ "sampler": "s_tex", "texture": "native" },
|
||||
@ -78,8 +78,8 @@
|
||||
{ "type": "slider", "name": "phosphor", "value": [ 0, 0, 0 ] }
|
||||
],
|
||||
"uniforms": [
|
||||
{ "name": "u_passthrough", "value": [ 1 ] },
|
||||
{ "name": "u_phosphor", "slider": "phosphor" }
|
||||
{ "uniform": "u_passthrough", "value": [ 1 ] },
|
||||
{ "uniform": "u_phosphor", "slider": "phosphor" }
|
||||
],
|
||||
"input": [
|
||||
{ "sampler": "s_tex", "texture": "native" },
|
||||
|
@ -120,29 +120,34 @@ function osdmodulesbuild()
|
||||
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/chain.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentry.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentryreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainmanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainreader.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/chain.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainmanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentry.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentryreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/entryuniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/inputpair.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/slider.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/sliderreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/parameter.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/shadermanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slider.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/sliderreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slideruniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slideruniformreader.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/valueuniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/valueuniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/writereader.cpp",
|
||||
}
|
||||
includedirs {
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -104,7 +104,7 @@ struct slider_state
|
||||
INT32 maxval; /* maximum value */
|
||||
INT32 incval; /* increment value */
|
||||
bool hidden; /* hidden or not */
|
||||
INT32 id; /* unique identifier */
|
||||
int id;
|
||||
char description[1]; /* textual description */
|
||||
};
|
||||
|
||||
|
@ -6,9 +6,14 @@
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#include "emu.h"
|
||||
|
||||
#include "slider.h"
|
||||
#include "parameter.h"
|
||||
#include "chainentry.h"
|
||||
#include "entryuniform.h"
|
||||
#include "texturemanager.h"
|
||||
#include "vertex.h"
|
||||
|
||||
#include "chain.h"
|
||||
|
||||
@ -19,6 +24,10 @@ bgfx_chain::bgfx_chain(std::string name, std::string author, std::vector<bgfx_sl
|
||||
, m_params(params)
|
||||
, m_entries(entries)
|
||||
{
|
||||
for (bgfx_slider* slider : m_sliders)
|
||||
{
|
||||
m_slider_map[slider->name()] = slider;
|
||||
}
|
||||
}
|
||||
|
||||
bgfx_chain::~bgfx_chain()
|
||||
@ -37,9 +46,79 @@ bgfx_chain::~bgfx_chain()
|
||||
}
|
||||
}
|
||||
|
||||
void bgfx_chain::submit(render_primitive* prim, int view)
|
||||
void bgfx_chain::process(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend)
|
||||
{
|
||||
//for (bgfx_chain_entry* entry : m_entries)
|
||||
//{
|
||||
//}
|
||||
for (bgfx_chain_entry* entry : m_entries)
|
||||
{
|
||||
bgfx::TransientVertexBuffer buffer;
|
||||
if (bgfx::checkAvailTransientVertexBuffer(6, ScreenVertex::ms_decl))
|
||||
{
|
||||
bgfx::allocTransientVertexBuffer(&buffer, 6, ScreenVertex::ms_decl);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ScreenVertex* vertex = reinterpret_cast<ScreenVertex*>(buffer.data);
|
||||
|
||||
const uint32_t r = uint32_t(prim->color.r * 255);
|
||||
const uint32_t g = uint32_t(prim->color.g * 255) << 8;
|
||||
const uint32_t b = uint32_t(prim->color.b * 255) << 16;
|
||||
const uint32_t a = uint32_t(prim->color.a * 255) << 24;
|
||||
UINT32 rgba = r | g | b | a;
|
||||
|
||||
vertex[0].m_x = prim->bounds.x0;
|
||||
vertex[0].m_y = prim->bounds.y0;
|
||||
vertex[0].m_z = 0;
|
||||
vertex[0].m_rgba = rgba;
|
||||
vertex[0].m_u = prim->texcoords.tl.u;
|
||||
vertex[0].m_v = prim->texcoords.tl.v;
|
||||
|
||||
vertex[1].m_x = prim->bounds.x1;
|
||||
vertex[1].m_y = prim->bounds.y0;
|
||||
vertex[1].m_z = 0;
|
||||
vertex[1].m_rgba = rgba;
|
||||
vertex[1].m_u = prim->texcoords.tr.u;
|
||||
vertex[1].m_v = prim->texcoords.tr.v;
|
||||
|
||||
vertex[2].m_x = prim->bounds.x1;
|
||||
vertex[2].m_y = prim->bounds.y1;
|
||||
vertex[2].m_z = 0;
|
||||
vertex[2].m_rgba = rgba;
|
||||
vertex[2].m_u = prim->texcoords.br.u;
|
||||
vertex[2].m_v = prim->texcoords.br.v;
|
||||
|
||||
vertex[3].m_x = prim->bounds.x1;
|
||||
vertex[3].m_y = prim->bounds.y1;
|
||||
vertex[3].m_z = 0;
|
||||
vertex[3].m_rgba = rgba;
|
||||
vertex[3].m_u = prim->texcoords.br.u;
|
||||
vertex[3].m_v = prim->texcoords.br.v;
|
||||
|
||||
vertex[4].m_x = prim->bounds.x0;
|
||||
vertex[4].m_y = prim->bounds.y1;
|
||||
vertex[4].m_z = 0;
|
||||
vertex[4].m_rgba = rgba;
|
||||
vertex[4].m_u = prim->texcoords.bl.u;
|
||||
vertex[4].m_v = prim->texcoords.bl.v;
|
||||
|
||||
vertex[5].m_x = prim->bounds.x0;
|
||||
vertex[5].m_y = prim->bounds.y0;
|
||||
vertex[5].m_z = 0;
|
||||
vertex[5].m_rgba = rgba;
|
||||
vertex[5].m_u = prim->texcoords.tl.u;
|
||||
vertex[5].m_v = prim->texcoords.tl.v;
|
||||
|
||||
bgfx::setVertexBuffer(&buffer);
|
||||
|
||||
bgfx::setViewClear(view
|
||||
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
||||
, 0x000000ff
|
||||
, 1.0f
|
||||
, 0
|
||||
);
|
||||
|
||||
entry->submit(prim, view, textures, screen_width, screen_height, blend);
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,13 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class render_primitive;
|
||||
class bgfx_slider;
|
||||
class bgfx_parameter;
|
||||
class bgfx_chain_entry;
|
||||
class render_primitive;
|
||||
class texture_manager;
|
||||
|
||||
class bgfx_chain
|
||||
{
|
||||
@ -25,14 +27,16 @@ public:
|
||||
bgfx_chain(std::string name, std::string author, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries);
|
||||
~bgfx_chain();
|
||||
|
||||
void submit(render_primitive* prim, int view);
|
||||
void process(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend = 0L);
|
||||
std::vector<bgfx_slider*>& sliders() { return m_sliders; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_author;
|
||||
std::vector<bgfx_slider*> m_sliders;
|
||||
std::vector<bgfx_parameter*> m_params;
|
||||
std::vector<bgfx_slider*> m_sliders;
|
||||
std::vector<bgfx_parameter*> m_params;
|
||||
std::vector<bgfx_chain_entry*> m_entries;
|
||||
std::map<std::string, bgfx_slider*> m_slider_map;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_CHAIN__
|
||||
|
@ -13,12 +13,15 @@
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
#include "chainentry.h"
|
||||
|
||||
#include "effect.h"
|
||||
#include "texture.h"
|
||||
#include "target.h"
|
||||
#include "chainentry.h"
|
||||
#include "entryuniform.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, std::vector<bgfx_input_pair>& inputs, bgfx_target* output)
|
||||
bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, std::vector<bgfx_input_pair>& inputs, std::vector<bgfx_entry_uniform*> uniforms, bgfx_target* output)
|
||||
: m_name(name)
|
||||
, m_effect(effect)
|
||||
, m_output(output)
|
||||
@ -27,18 +30,42 @@ bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, std::v
|
||||
{
|
||||
m_inputs.push_back(input);
|
||||
}
|
||||
for (bgfx_entry_uniform* uniform : uniforms)
|
||||
{
|
||||
m_uniforms.push_back(uniform);
|
||||
}
|
||||
}
|
||||
|
||||
bgfx_chain_entry::~bgfx_chain_entry()
|
||||
{
|
||||
for (bgfx_entry_uniform* uniform : m_uniforms)
|
||||
{
|
||||
delete uniform;
|
||||
}
|
||||
m_uniforms.clear();
|
||||
}
|
||||
|
||||
void bgfx_chain_entry::submit(render_primitive* prim, int view)
|
||||
void bgfx_chain_entry::submit(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend)
|
||||
{
|
||||
for (bgfx_input_pair input : m_inputs)
|
||||
{
|
||||
input.bind(m_effect);
|
||||
input.bind(m_effect, textures);
|
||||
}
|
||||
bgfx::setViewFrameBuffer(view, m_output->target());
|
||||
m_effect->submit(view);
|
||||
if (m_output != nullptr)
|
||||
{
|
||||
printf("Setting view to %s, %dx%d\n", m_output->name().c_str(), m_outptu->width, m_output->height());
|
||||
bgfx::setViewFrameBuffer(view, m_output->target());
|
||||
bgfx::setViewRect(view, 0, 0, m_output->width(), m_output->height());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Setting view to backbuffer, %dx%d\n", screen_width, screen_height);
|
||||
bgfx::setViewFrameBuffer(view, BGFX_INVALID_HANDLE);
|
||||
bgfx::setViewRect(view, 0, 0, screen_width, screen_height);
|
||||
}
|
||||
for (bgfx_entry_uniform* uniform : m_uniforms)
|
||||
{
|
||||
uniform->bind();
|
||||
}
|
||||
m_effect->submit(view, blend);
|
||||
}
|
||||
|
@ -21,25 +21,27 @@
|
||||
|
||||
class render_primitive;
|
||||
class bgfx_effect;
|
||||
class bgfx_texture;
|
||||
class bgfx_target;
|
||||
class bgfx_entry_uniform;
|
||||
class texture_manager;
|
||||
|
||||
class bgfx_chain_entry
|
||||
{
|
||||
public:
|
||||
bgfx_chain_entry(std::string name, bgfx_effect* effect, std::vector<bgfx_input_pair>& inputs, bgfx_target* output);
|
||||
bgfx_chain_entry(std::string name, bgfx_effect* effect, std::vector<bgfx_input_pair>& inputs, std::vector<bgfx_entry_uniform*> uniforms, bgfx_target* output);
|
||||
~bgfx_chain_entry();
|
||||
|
||||
void submit(render_primitive* prim, int view);
|
||||
void submit(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend = 0L);
|
||||
|
||||
// Getters
|
||||
std::string name() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
bgfx_effect* m_effect;
|
||||
std::vector<bgfx_input_pair> m_inputs;
|
||||
bgfx_target* m_output;
|
||||
std::string m_name;
|
||||
bgfx_effect* m_effect;
|
||||
std::vector<bgfx_input_pair> m_inputs;
|
||||
std::vector<bgfx_entry_uniform*> m_uniforms;
|
||||
bgfx_target* m_output;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_CHAIN_ENTRY__
|
||||
|
@ -16,9 +16,12 @@
|
||||
#include "targetmanager.h"
|
||||
#include "effectmanager.h"
|
||||
#include "chainentry.h"
|
||||
#include "entryuniform.h"
|
||||
#include "slider.h"
|
||||
#include "inputpair.h"
|
||||
#include "entryuniformreader.h"
|
||||
|
||||
bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects)
|
||||
bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders)
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
@ -32,13 +35,29 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, textur
|
||||
{
|
||||
std::string sampler = input_array[i]["sampler"].GetString();
|
||||
std::string texture = input_array[i]["texture"].GetString();
|
||||
inputs.push_back(bgfx_input_pair(i, sampler, textures.texture(texture)));
|
||||
inputs.push_back(bgfx_input_pair(i, sampler, texture));
|
||||
}
|
||||
}
|
||||
|
||||
bgfx_target* output = targets.target(value["output"].GetString());
|
||||
std::vector<bgfx_entry_uniform*> uniforms;
|
||||
if (value.HasMember("uniforms"))
|
||||
{
|
||||
const Value& uniform_array = value["uniforms"];
|
||||
for (UINT32 i = 0; i < uniform_array.Size(); i++)
|
||||
{
|
||||
uniforms.push_back(entry_uniform_reader::read_from_value(uniform_array[i], effect, sliders));
|
||||
}
|
||||
}
|
||||
|
||||
return new bgfx_chain_entry(value["name"].GetString(), effect, inputs, output);
|
||||
std::string output_name = value["output"].GetString();
|
||||
if (output_name != std::string("backbuffer"))
|
||||
{
|
||||
return new bgfx_chain_entry(value["name"].GetString(), effect, inputs, uniforms, targets.target(output_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new bgfx_chain_entry(value["name"].GetString(), effect, inputs, uniforms, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void chain_entry_reader::validate_parameters(const Value& value)
|
||||
@ -49,8 +68,8 @@ void chain_entry_reader::validate_parameters(const Value& value)
|
||||
{
|
||||
assert(value["name"].IsString());
|
||||
}
|
||||
assert(value.HasMember("shader"));
|
||||
assert(value["shader"].IsString());
|
||||
assert(value.HasMember("effect"));
|
||||
assert(value["effect"].IsString());
|
||||
assert(value.HasMember("output"));
|
||||
assert(value["output"].IsString());
|
||||
}
|
||||
|
@ -11,17 +11,20 @@
|
||||
#ifndef __DRAWBGFX_CHAIN_ENTRY_READER__
|
||||
#define __DRAWBGFX_CHAIN_ENTRY_READER__
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_chain_entry;
|
||||
class texture_manager;
|
||||
class target_manager;
|
||||
class effect_manager;
|
||||
class bgfx_slider;
|
||||
|
||||
class chain_entry_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_chain_entry* read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects);
|
||||
static bgfx_chain_entry* read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
#include <bgfx/bgfxplatform.h>
|
||||
#include <bgfx/bgfx.h>
|
||||
#include <bx/readerwriter.h>
|
||||
#include <bx/crtimpl.h>
|
||||
|
||||
@ -33,7 +31,7 @@ chain_manager::~chain_manager()
|
||||
m_chains.clear();
|
||||
}
|
||||
|
||||
bgfx_chain* chain_manager::chain(std::string name)
|
||||
bgfx_chain* chain_manager::chain(std::string name, running_machine& machine)
|
||||
{
|
||||
std::map<std::string, bgfx_chain*>::iterator iter = m_chains.find(name);
|
||||
if (iter != m_chains.end())
|
||||
@ -41,16 +39,16 @@ bgfx_chain* chain_manager::chain(std::string name)
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return load_chain(name);
|
||||
return load_chain(name, machine);
|
||||
}
|
||||
|
||||
bgfx_chain* chain_manager::load_chain(std::string name) {
|
||||
bgfx_chain* chain_manager::load_chain(std::string name, running_machine& machine) {
|
||||
std::string path = "bgfx/chains/" + name + ".json";
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
bx::open(&reader, path.c_str());
|
||||
|
||||
int32_t size = (uint32_t)bx::getSize(&reader);
|
||||
int32_t size(bx::getSize(&reader));
|
||||
|
||||
char* data = new char[size + 1];
|
||||
bx::read(&reader, reinterpret_cast<void*>(data), size);
|
||||
@ -59,7 +57,7 @@ bgfx_chain* chain_manager::load_chain(std::string name) {
|
||||
|
||||
Document document;
|
||||
document.Parse<0>(data);
|
||||
bgfx_chain* chain = chain_reader::read_from_value(document, m_textures, m_targets, m_effects, m_width, m_height);
|
||||
bgfx_chain* chain = chain_reader::read_from_value(document, machine, m_textures, m_targets, m_effects, m_width, m_height);
|
||||
|
||||
m_chains[name] = chain;
|
||||
|
||||
|
@ -17,12 +17,12 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
#include "texturemanager.h"
|
||||
#include "targetmanager.h"
|
||||
#include "effectmanager.h"
|
||||
|
||||
class running_machine;
|
||||
|
||||
class bgfx_chain;
|
||||
|
||||
class chain_manager {
|
||||
@ -38,10 +38,10 @@ public:
|
||||
~chain_manager();
|
||||
|
||||
// Getters
|
||||
bgfx_chain* chain(std::string name);
|
||||
bgfx_chain* chain(std::string name, running_machine& machine);
|
||||
|
||||
private:
|
||||
bgfx_chain* load_chain(std::string name);
|
||||
bgfx_chain* load_chain(std::string name, running_machine& machine);
|
||||
|
||||
texture_manager& m_textures;
|
||||
target_manager& m_targets;
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "emu.h"
|
||||
|
||||
@ -17,8 +18,16 @@
|
||||
#include "chainentryreader.h"
|
||||
#include "targetmanager.h"
|
||||
#include "chainreader.h"
|
||||
#include "target.h"
|
||||
#include "slider.h"
|
||||
|
||||
bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height)
|
||||
const chain_reader::string_to_enum chain_reader::STYLE_NAMES[chain_reader::STYLE_COUNT] = {
|
||||
{ "guest", TARGET_STYLE_GUEST },
|
||||
{ "native", TARGET_STYLE_NATIVE },
|
||||
{ "custom", TARGET_STYLE_CUSTOM }
|
||||
};
|
||||
|
||||
bgfx_chain* chain_reader::read_from_value(const Value& value, running_machine& machine, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height)
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
@ -32,10 +41,21 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
|
||||
const Value& slider_array = value["sliders"];
|
||||
for (UINT32 i = 0; i < slider_array.Size(); i++)
|
||||
{
|
||||
sliders.push_back(slider_reader::read_from_value(slider_array[i]));
|
||||
std::vector<bgfx_slider*> expanded_sliders = slider_reader::read_from_value(slider_array[i], machine);
|
||||
for (bgfx_slider* slider : expanded_sliders)
|
||||
{
|
||||
sliders.push_back(slider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Map sliders
|
||||
std::map<std::string, bgfx_slider*> slider_map;
|
||||
for (bgfx_slider* slider : sliders)
|
||||
{
|
||||
slider_map[slider->name()] = slider;
|
||||
}
|
||||
|
||||
// Parse parameters
|
||||
std::vector<bgfx_parameter*> parameters;
|
||||
if (value.HasMember("parameters"))
|
||||
@ -47,17 +67,6 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
|
||||
}
|
||||
}
|
||||
|
||||
// Parse chain entries
|
||||
std::vector<bgfx_chain_entry*> entries;
|
||||
if (value.HasMember("passes"))
|
||||
{
|
||||
const Value& entry_array = value["passes"];
|
||||
for (UINT32 i = 0; i < entry_array.Size(); i++)
|
||||
{
|
||||
entries.push_back(chain_entry_reader::read_from_value(entry_array[i], textures, targets, effects));
|
||||
}
|
||||
}
|
||||
|
||||
// Create targets
|
||||
if (value.HasMember("targets"))
|
||||
{
|
||||
@ -66,27 +75,52 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
|
||||
{
|
||||
assert(target_array[i].HasMember("name"));
|
||||
assert(target_array[i]["name"].IsString());
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
if (target_array[i].HasMember("screen") && target_array[i]["screen"].IsBool())
|
||||
uint32_t mode = uint32_t(get_enum_from_value(value, "mode", TARGET_STYLE_NATIVE, STYLE_NAMES, STYLE_COUNT));
|
||||
|
||||
float prescalef = 1.0f;
|
||||
float default_prescale = 1.0f;
|
||||
get_float(target_array[i], "prescale", &prescalef, &default_prescale);
|
||||
int prescale = (int)floor(prescalef + 0.5f);
|
||||
|
||||
uint16_t width = 0;
|
||||
uint16_t height = 0;
|
||||
switch (mode)
|
||||
{
|
||||
width = screen_width;
|
||||
height = screen_height;
|
||||
case TARGET_STYLE_GUEST:
|
||||
width = targets.guest_width();
|
||||
height = targets.guest_height();
|
||||
break;
|
||||
case TARGET_STYLE_NATIVE:
|
||||
width = screen_width;
|
||||
height = screen_height;
|
||||
break;
|
||||
case TARGET_STYLE_CUSTOM:
|
||||
assert(target_array[i].HasMember("width"));
|
||||
assert(target_array[i]["width"].IsNumber());
|
||||
assert(target_array[i].HasMember("height"));
|
||||
assert(target_array[i]["height"].IsNumber());
|
||||
width = uint32_t(target_array[i]["width"].GetDouble());
|
||||
height = uint32_t(target_array[i]["height"].GetDouble());
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(target_array[i].HasMember("width"));
|
||||
assert(target_array[i]["width"].IsDouble());
|
||||
assert(target_array[i].HasMember("height"));
|
||||
assert(target_array[i]["height"].IsDouble());
|
||||
width = uint32_t(target_array[i]["width"].GetDouble());
|
||||
height = uint32_t(target_array[i]["height"].GetDouble());
|
||||
}
|
||||
targets.create_target(target_array[i]["name"].GetString(), bgfx::TextureFormat::RGBA8, width, height);
|
||||
|
||||
width *= prescale;
|
||||
height *= prescale;
|
||||
|
||||
targets.create_target(target_array[i]["name"].GetString(), bgfx::TextureFormat::RGBA8, width, height, mode);
|
||||
}
|
||||
}
|
||||
|
||||
return new bgfx_chain(name, author, sliders, parameters, entries);
|
||||
// Parse chain entries
|
||||
std::vector<bgfx_chain_entry*> entries;
|
||||
if (value.HasMember("passes")) {
|
||||
const Value& entry_array = value["passes"];
|
||||
for (UINT32 i = 0; i < entry_array.Size(); i++) {
|
||||
entries.push_back(chain_entry_reader::read_from_value(entry_array[i], textures, targets, effects, slider_map));
|
||||
}
|
||||
}
|
||||
|
||||
return new bgfx_chain(name, author, sliders, parameters, entries);
|
||||
}
|
||||
|
||||
void chain_reader::validate_parameters(const Value& value)
|
||||
|
@ -21,10 +21,13 @@ class effect_manager;
|
||||
class chain_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_chain* read_from_value(const Value& value, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height);
|
||||
static bgfx_chain* read_from_value(const Value& value, running_machine& machine, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
|
||||
static const int STYLE_COUNT = 3;
|
||||
static const string_to_enum STYLE_NAMES[STYLE_COUNT];
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_CHAIN_READER__
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "effect.h"
|
||||
|
||||
#include "uniform.h"
|
||||
|
||||
bgfx_effect::bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, std::vector<bgfx_uniform*> uniforms)
|
||||
: m_state(state)
|
||||
{
|
||||
@ -29,13 +31,13 @@ bgfx_effect::~bgfx_effect()
|
||||
bgfx::destroyProgram(m_program_handle);
|
||||
}
|
||||
|
||||
void bgfx_effect::submit(int view)
|
||||
void bgfx_effect::submit(int view, uint64_t blend)
|
||||
{
|
||||
for (std::pair<std::string, bgfx_uniform*> uniform_pair : m_uniforms)
|
||||
{
|
||||
(uniform_pair.second)->upload();
|
||||
}
|
||||
bgfx::setState(m_state);
|
||||
bgfx::setState(m_state | blend);
|
||||
bgfx::submit(view, m_program_handle);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// effect.h - BGFX shader material to be applied to a mesh
|
||||
// vertex.h - BGFX screen vertex data
|
||||
//
|
||||
//============================================================
|
||||
|
||||
@ -13,28 +13,24 @@
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "uniform.h"
|
||||
class bgfx_uniform;
|
||||
|
||||
class bgfx_effect
|
||||
{
|
||||
public:
|
||||
bgfx_effect(uint64_t state, bgfx::ShaderHandle vertexShader, bgfx::ShaderHandle fragmentShader, std::vector<bgfx_uniform*> uniforms);
|
||||
~bgfx_effect();
|
||||
bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, 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; }
|
||||
void submit(int view, uint64_t blend = 0L);
|
||||
bgfx_uniform* uniform(std::string name);
|
||||
|
||||
private:
|
||||
uint64_t m_state;
|
||||
bgfx::ProgramHandle m_program_handle;
|
||||
std::map<std::string, bgfx_uniform*> m_uniforms;
|
||||
uint64_t m_state;
|
||||
bgfx::ProgramHandle m_program_handle;
|
||||
std::map<std::string, bgfx_uniform*> m_uniforms;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_EFFECT__
|
||||
|
@ -26,7 +26,11 @@ bgfx_effect* effect_reader::read_from_value(shader_manager& shaders, const Value
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
uint64_t blend = blend_reader::read_from_value(value["blend"]);
|
||||
uint64_t blend = 0;
|
||||
if (value.HasMember("blend"))
|
||||
{
|
||||
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"]);
|
||||
@ -57,7 +61,6 @@ bgfx_effect* effect_reader::read_from_value(shader_manager& shaders, const Value
|
||||
|
||||
void effect_reader::validate_parameters(const Value& value)
|
||||
{
|
||||
assert(value.HasMember("blend"));
|
||||
assert(value.HasMember("depth"));
|
||||
assert(value.HasMember("cull"));
|
||||
assert(value.HasMember("write"));
|
||||
|
33
src/osd/modules/render/bgfx/entryuniform.h
Normal file
33
src/osd/modules/render/bgfx/entryuniform.h
Normal file
@ -0,0 +1,33 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// entryuniform.h - BGFX shader chain uniform remapper
|
||||
//
|
||||
// Represents the mapping between a fixed value, a slider, or
|
||||
// other dynamic parameter and a chain effect shader uniform
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_ENTRY_UNIFORM__
|
||||
#define __DRAWBGFX_ENTRY_UNIFORM__
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
#include "uniform.h"
|
||||
|
||||
class bgfx_entry_uniform
|
||||
{
|
||||
public:
|
||||
bgfx_entry_uniform(bgfx_uniform* uniform) : m_uniform(uniform) { }
|
||||
virtual ~bgfx_entry_uniform() { }
|
||||
|
||||
virtual void bind() = 0;
|
||||
|
||||
protected:
|
||||
bgfx_uniform* m_uniform;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_ENTRY_UNIFORM__
|
39
src/osd/modules/render/bgfx/entryuniformreader.cpp
Normal file
39
src/osd/modules/render/bgfx/entryuniformreader.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// entryuniformreader.cpp - BGFX chain entry uniform reader
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#include "entryuniformreader.h"
|
||||
|
||||
#include "entryuniform.h"
|
||||
#include "effect.h"
|
||||
#include "slideruniformreader.h"
|
||||
#include "valueuniformreader.h"
|
||||
#include "uniform.h"
|
||||
|
||||
bgfx_entry_uniform* entry_uniform_reader::read_from_value(const Value& value, bgfx_effect* effect, std::map<std::string, bgfx_slider*>& sliders)
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
bgfx_uniform* uniform = effect->uniform(value["uniform"].GetString());
|
||||
|
||||
if (value.HasMember("slider"))
|
||||
{
|
||||
return slider_uniform_reader::read_from_value(value, uniform, sliders);
|
||||
}
|
||||
else if (value.HasMember("value"))
|
||||
{
|
||||
return value_uniform_reader::read_from_value(value, uniform);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void entry_uniform_reader::validate_parameters(const Value& value)
|
||||
{
|
||||
assert(value.HasMember("uniform"));
|
||||
assert(value["uniform"].IsString());
|
||||
}
|
32
src/osd/modules/render/bgfx/entryuniformreader.h
Normal file
32
src/osd/modules/render/bgfx/entryuniformreader.h
Normal file
@ -0,0 +1,32 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// entryuniformreader.h - BGFX chain entry uniform reader
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_ENTRY_UNIFORM_READER__
|
||||
#define __DRAWBGFX_ENTRY_UNIFORM_READER__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_entry_uniform;
|
||||
class bgfx_slider;
|
||||
class bgfx_effect;
|
||||
|
||||
class entry_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, bgfx_effect* effect, std::map<std::string, bgfx_slider*>& sliders);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_ENTRY_UNIFORM_READER__
|
@ -12,5 +12,5 @@ SAMPLER2D(s_tex, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(s_tex, v_texcoord0 + u_shift.xy) * u_tint * v_color0;
|
||||
gl_FragColor = texture2D(s_tex, v_texcoord0 + u_shift.xy) * (u_tint + vec4(0.0, 0.5, 0.0, 0.0)) * v_color0;
|
||||
}
|
||||
|
@ -12,15 +12,21 @@
|
||||
#include "inputpair.h"
|
||||
#include "texture.h"
|
||||
#include "effect.h"
|
||||
#include "uniform.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, bgfx_texture* texture)
|
||||
bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, std::string texture)
|
||||
: m_index(index)
|
||||
, m_sampler(sampler)
|
||||
, m_texture(texture)
|
||||
{
|
||||
}
|
||||
|
||||
void bgfx_input_pair::bind(bgfx_effect *effect)
|
||||
void bgfx_input_pair::bind(bgfx_effect *effect, texture_manager& textures)
|
||||
{
|
||||
bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), m_texture->handle());
|
||||
printf("Binding texture %s to uniform %s\n", m_texture.c_str(), m_sampler.c_str());
|
||||
bgfx_uniform *uniform = effect->uniform(m_sampler);
|
||||
bgfx::UniformHandle u_handle = uniform->handle();
|
||||
bgfx::TextureHandle t_handle = textures.texture(m_texture)->handle();
|
||||
bgfx::setTexture(m_index, u_handle, t_handle);
|
||||
}
|
||||
|
@ -14,24 +14,22 @@
|
||||
#ifndef __DRAWBGFX_INPUT_PAIR__
|
||||
#define __DRAWBGFX_INPUT_PAIR__
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class bgfx_effect;
|
||||
class bgfx_texture;
|
||||
class texture_manager;
|
||||
|
||||
class bgfx_input_pair
|
||||
{
|
||||
public:
|
||||
bgfx_input_pair(int index, std::string sampler, bgfx_texture* texture);
|
||||
bgfx_input_pair(int index, std::string sampler, std::string texture);
|
||||
|
||||
void bind(bgfx_effect *effect);
|
||||
void bind(bgfx_effect *effect, texture_manager& textures);
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
std::string m_sampler;
|
||||
bgfx_texture* m_texture;
|
||||
int m_index;
|
||||
std::string m_sampler;
|
||||
std::string m_texture;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_INPUT_PAIR__
|
||||
|
@ -34,5 +34,5 @@ void parameter_reader::validate_parameters(const Value& value)
|
||||
assert(value.HasMember("type"));
|
||||
assert(value["type"].IsString());
|
||||
assert(value.HasMember("period"));
|
||||
assert(value["period"].IsDouble());
|
||||
assert(value["period"].IsNumber());
|
||||
}
|
||||
|
@ -9,57 +9,104 @@
|
||||
#include "emu.h"
|
||||
|
||||
#include "slider.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
bgfx_slider::bgfx_slider(slider_type type, std::string name, std::string description, void *defaults, void *min, void *max)
|
||||
: m_type(type)
|
||||
, m_name(name)
|
||||
bgfx_slider::bgfx_slider(running_machine &machine, std::string name, int32_t min, int32_t def, int32_t max, int32_t step, slider_type type, screen_type screen, float scale, std::string format, std::string description, std::vector<std::string>& strings)
|
||||
: m_name(name)
|
||||
, m_step(step)
|
||||
, m_type(type)
|
||||
, m_screen_type(screen)
|
||||
, m_scale(scale)
|
||||
, m_format(format)
|
||||
, m_description(description)
|
||||
{
|
||||
m_data = global_alloc_array_clear<char>(storage_size(type));
|
||||
m_min = global_alloc_array_clear<char>(storage_size(type));
|
||||
m_max = global_alloc_array_clear<char>(storage_size(type));
|
||||
memcpy(m_data, defaults, size(type));
|
||||
memcpy(m_min, min, size(type));
|
||||
memcpy(m_max, max, size(type));
|
||||
m_min = min;
|
||||
m_default = def;
|
||||
m_max = max;
|
||||
|
||||
m_value = def;
|
||||
if (m_type != slider_type::SLIDER_INT && m_type != slider_type::SLIDER_INT_ENUM)
|
||||
{
|
||||
float temp = float(def) * scale;
|
||||
m_value = *reinterpret_cast<int32_t*>(&temp);
|
||||
}
|
||||
|
||||
for (std::string string : strings)
|
||||
{
|
||||
m_strings.push_back(string);
|
||||
}
|
||||
|
||||
m_slider_state = create_core_slider(machine);
|
||||
}
|
||||
|
||||
bgfx_slider::~bgfx_slider()
|
||||
{
|
||||
global_free(m_data);
|
||||
global_free(m_min);
|
||||
global_free(m_max);
|
||||
}
|
||||
|
||||
size_t bgfx_slider::storage_size(slider_type type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case SLIDER_INT:
|
||||
return 1 * sizeof(int);
|
||||
case SLIDER_BOOL:
|
||||
case SLIDER_FLOAT:
|
||||
case SLIDER_COLOR:
|
||||
case SLIDER_VEC2:
|
||||
return 4 * sizeof(float);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
static INT32 update_trampoline(running_machine &machine, void *arg, std::string *str, INT32 newval) {
|
||||
if (arg != nullptr) {
|
||||
return reinterpret_cast<bgfx_slider*>(arg)->update(str, newval);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t bgfx_slider::size(slider_type type)
|
||||
slider_state* bgfx_slider::create_core_slider(running_machine& machine)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case SLIDER_INT:
|
||||
return sizeof(int);
|
||||
case SLIDER_BOOL:
|
||||
case SLIDER_FLOAT:
|
||||
return sizeof(float);
|
||||
case SLIDER_COLOR:
|
||||
return sizeof(float) * 3;
|
||||
case SLIDER_VEC2:
|
||||
return sizeof(float) * 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
int size = sizeof(slider_state) + m_description.length();
|
||||
slider_state *state = reinterpret_cast<slider_state *>(auto_alloc_array_clear(machine, UINT8, size));
|
||||
|
||||
state->minval = m_min;
|
||||
state->defval = m_default;
|
||||
state->maxval = m_max;
|
||||
state->incval = m_step;
|
||||
state->update = update_trampoline;
|
||||
state->arg = this;
|
||||
state->hidden = false;
|
||||
state->id = 0; // fixme
|
||||
strcpy(state->description, m_description.c_str());
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
int32_t bgfx_slider::update(std::string *str, int32_t newval)
|
||||
{
|
||||
switch (m_type) {
|
||||
case SLIDER_INT_ENUM:
|
||||
{
|
||||
INT32 *val_ptr = reinterpret_cast<INT32 *>(&m_value);
|
||||
if (newval != SLIDER_NOCHANGE) {
|
||||
*val_ptr = newval;
|
||||
}
|
||||
if (str != nullptr) {
|
||||
*str = string_format(m_format, m_strings[*val_ptr]);
|
||||
}
|
||||
return *val_ptr;
|
||||
}
|
||||
|
||||
case SLIDER_INT:
|
||||
{
|
||||
int *val_ptr = reinterpret_cast<int *>(&m_value);
|
||||
if (newval != SLIDER_NOCHANGE) {
|
||||
*val_ptr = newval;
|
||||
}
|
||||
if (str != nullptr) {
|
||||
*str = string_format(m_format, *val_ptr);
|
||||
}
|
||||
return *val_ptr;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
float *val_ptr = reinterpret_cast<float *>(&m_value);
|
||||
if (newval != SLIDER_NOCHANGE)
|
||||
{
|
||||
*val_ptr = float(newval) * m_scale;
|
||||
}
|
||||
if (str != nullptr) {
|
||||
*str = string_format(m_format, *val_ptr);
|
||||
}
|
||||
return int32_t(floor(*val_ptr / m_scale + 0.5f));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,35 +15,62 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "uniform.h"
|
||||
#include "emu.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
class bgfx_slider
|
||||
{
|
||||
public:
|
||||
enum slider_type
|
||||
{
|
||||
SLIDER_BOOL,
|
||||
SLIDER_INT_ENUM,
|
||||
SLIDER_FLOAT,
|
||||
SLIDER_INT,
|
||||
SLIDER_COLOR,
|
||||
SLIDER_VEC2
|
||||
};
|
||||
|
||||
bgfx_slider(slider_type type, std::string name, std::string description, void *defaults, void *min, void *max);
|
||||
enum screen_type
|
||||
{
|
||||
SLIDER_SCREEN_TYPE_NONE = 0,
|
||||
SLIDER_SCREEN_TYPE_RASTER = 1,
|
||||
SLIDER_SCREEN_TYPE_VECTOR = 2,
|
||||
SLIDER_SCREEN_TYPE_VECTOR_OR_RASTER = SLIDER_SCREEN_TYPE_VECTOR | SLIDER_SCREEN_TYPE_RASTER,
|
||||
SLIDER_SCREEN_TYPE_LCD = 4,
|
||||
SLIDER_SCREEN_TYPE_LCD_OR_RASTER = SLIDER_SCREEN_TYPE_LCD | SLIDER_SCREEN_TYPE_RASTER,
|
||||
SLIDER_SCREEN_TYPE_LCD_OR_VECTOR = SLIDER_SCREEN_TYPE_LCD | SLIDER_SCREEN_TYPE_VECTOR,
|
||||
SLIDER_SCREEN_TYPE_ANY = SLIDER_SCREEN_TYPE_RASTER | SLIDER_SCREEN_TYPE_VECTOR | SLIDER_SCREEN_TYPE_LCD
|
||||
};
|
||||
|
||||
bgfx_slider(running_machine& machine, std::string name, int32_t min, int32_t def, int32_t max, int32_t step, slider_type type, screen_type screen, float scale, std::string format, std::string description, std::vector<std::string>& strings);
|
||||
~bgfx_slider();
|
||||
|
||||
static size_t size(slider_type type);
|
||||
static size_t storage_size(slider_type type);
|
||||
protected:
|
||||
int32_t update(std::string *str, int32_t newval);
|
||||
|
||||
slider_type m_type;
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
char* m_data;
|
||||
char* m_min;
|
||||
char* m_max;
|
||||
// Getters
|
||||
std::string name() const { return m_name; }
|
||||
slider_type type() const { return m_type; }
|
||||
int32_t value() const { return m_value; }
|
||||
float uniform_value() const { return *(reinterpret_cast<const float*>(&m_value)); }
|
||||
slider_state* core_slider() const { return m_slider_state; }
|
||||
|
||||
protected:
|
||||
slider_state* create_core_slider(running_machine &machine);
|
||||
|
||||
std::string m_name;
|
||||
int32_t m_min;
|
||||
int32_t m_default;
|
||||
int32_t m_max;
|
||||
int32_t m_step;
|
||||
slider_type m_type;
|
||||
screen_type m_screen_type;
|
||||
float m_scale;
|
||||
std::string m_format;
|
||||
std::string m_description;
|
||||
std::vector<std::string> m_strings;
|
||||
int32_t m_value;
|
||||
slider_state* m_slider_state;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_SLIDER__
|
||||
|
@ -6,69 +6,146 @@
|
||||
//
|
||||
//==============================================================
|
||||
|
||||
#include "emu.h"
|
||||
|
||||
#include "sliderreader.h"
|
||||
|
||||
#include "emu.h"
|
||||
#include "slider.h"
|
||||
|
||||
const slider_reader::string_to_enum slider_reader::TYPE_NAMES[slider_reader::TYPE_COUNT] = {
|
||||
{ "bool", uint64_t(bgfx_slider::slider_type::SLIDER_BOOL) },
|
||||
{ "float", uint64_t(bgfx_slider::slider_type::SLIDER_FLOAT) },
|
||||
{ "int", uint64_t(bgfx_slider::slider_type::SLIDER_INT) },
|
||||
{ "color", uint64_t(bgfx_slider::slider_type::SLIDER_COLOR) },
|
||||
{ "vec2", uint64_t(bgfx_slider::slider_type::SLIDER_VEC2) }
|
||||
{ "int_enum", uint64_t(bgfx_slider::slider_type::SLIDER_INT_ENUM) },
|
||||
{ "float", uint64_t(bgfx_slider::slider_type::SLIDER_FLOAT) },
|
||||
{ "int", uint64_t(bgfx_slider::slider_type::SLIDER_INT) },
|
||||
{ "color", uint64_t(bgfx_slider::slider_type::SLIDER_COLOR) },
|
||||
{ "vec2", uint64_t(bgfx_slider::slider_type::SLIDER_VEC2) }
|
||||
};
|
||||
|
||||
bgfx_slider* slider_reader::read_from_value(const Value& value)
|
||||
const slider_reader::string_to_enum slider_reader::SCREEN_NAMES[slider_reader::SCREEN_COUNT] = {
|
||||
{ "none", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_NONE) },
|
||||
{ "raster", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_RASTER) },
|
||||
{ "vector", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_VECTOR) },
|
||||
{ "crt", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_VECTOR_OR_RASTER) },
|
||||
{ "vector_raster", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_VECTOR_OR_RASTER) },
|
||||
{ "lcd", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_LCD) },
|
||||
{ "non_vector", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_LCD_OR_RASTER) },
|
||||
{ "lcd_raster", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_LCD_OR_RASTER) },
|
||||
{ "lcd_vector", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_LCD_OR_VECTOR) },
|
||||
{ "any", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_ANY) },
|
||||
{ "all", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_ANY) }
|
||||
};
|
||||
|
||||
std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, running_machine& machine)
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
bgfx_slider::slider_type type = bgfx_slider::slider_type(get_enum_from_value(value, "type", uint64_t(bgfx_slider::slider_type::SLIDER_FLOAT), TYPE_NAMES, TYPE_COUNT));
|
||||
std::string name = value["name"].GetString();
|
||||
int step = value["step"].GetInt();
|
||||
bgfx_slider::slider_type type = bgfx_slider::slider_type(get_enum_from_value(value, "type", uint64_t(bgfx_slider::slider_type::SLIDER_FLOAT), TYPE_NAMES, TYPE_COUNT));
|
||||
bgfx_slider::screen_type screen_type = bgfx_slider::screen_type(get_enum_from_value(value, "screen", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_ANY), SCREEN_NAMES, SCREEN_COUNT));
|
||||
float scale = value["scale"].GetFloat();
|
||||
std::string format = value["format"].GetString();
|
||||
std::string description = value["text"].GetString();
|
||||
|
||||
float defaults[4];
|
||||
float min[4];
|
||||
float max[4];
|
||||
get_values(value, "default", defaults);
|
||||
get_values(value, "min", min);
|
||||
get_values(value, "max", max);
|
||||
std::vector<std::string> strings;
|
||||
if (value.HasMember("strings"))
|
||||
{
|
||||
const Value& string_array = value["strings"];
|
||||
for (UINT32 i = 0; i < string_array.Size(); i++)
|
||||
{
|
||||
strings.push_back(std::string(string_array[i].GetString()));
|
||||
}
|
||||
}
|
||||
|
||||
return new bgfx_slider(type, name, description, defaults, min, max);
|
||||
int slider_count;
|
||||
std::vector<bgfx_slider*> sliders;
|
||||
switch (type)
|
||||
{
|
||||
case bgfx_slider::slider_type::SLIDER_FLOAT:
|
||||
case bgfx_slider::slider_type::SLIDER_INT:
|
||||
case bgfx_slider::slider_type::SLIDER_INT_ENUM:
|
||||
slider_count = 1;
|
||||
break;
|
||||
case bgfx_slider::slider_type::SLIDER_VEC2:
|
||||
slider_count = 2;
|
||||
break;
|
||||
case bgfx_slider::slider_type::SLIDER_COLOR:
|
||||
slider_count = 3;
|
||||
break;
|
||||
default:
|
||||
slider_count = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (slider_count > 1)
|
||||
{
|
||||
int min[3];
|
||||
int defaults[3];
|
||||
int max[3];
|
||||
get_values(value, "min", min, slider_count);
|
||||
get_values(value, "default", defaults, slider_count);
|
||||
get_values(value, "max", max, slider_count);
|
||||
for (int index = 0; index < slider_count; index++)
|
||||
{
|
||||
std::string desc;
|
||||
char full_name[1024]; // arbitrary
|
||||
snprintf(full_name, 1024, "%s%d", name.c_str(), index);
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
desc = description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "X" : "Red");
|
||||
break;
|
||||
case 1:
|
||||
desc = description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "Y" : "Green");
|
||||
break;
|
||||
case 2:
|
||||
desc = description + (type == bgfx_slider::slider_type::SLIDER_VEC2 ? "Invalid" : "Blue");
|
||||
break;
|
||||
default:
|
||||
desc = description + "Invalid";
|
||||
break;
|
||||
}
|
||||
sliders.push_back(new bgfx_slider(machine, full_name, min[index], defaults[index], max[index], step, type, screen_type, scale, format, desc, strings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int min = get_int(value, "min", 0);
|
||||
int def = get_int(value, "default", 0);
|
||||
int max = get_int(value, "max", 100);
|
||||
sliders.push_back(new bgfx_slider(machine, name + "0", min, def, max, step, type, screen_type, scale, format, description, strings));
|
||||
}
|
||||
return sliders;
|
||||
}
|
||||
|
||||
void slider_reader::get_values(const Value& value, std::string name, float* values)
|
||||
void slider_reader::get_values(const Value& value, std::string name, int* values, const int count)
|
||||
{
|
||||
const char* name_str = name.c_str();
|
||||
if (value.HasMember(name_str))
|
||||
assert(value.HasMember(name_str));
|
||||
assert(value[name_str].IsArray());
|
||||
|
||||
const Value& value_array = value[name_str];
|
||||
for (UINT32 i = 0; i < value_array.Size() && i < count; i++)
|
||||
{
|
||||
if (value[name_str].IsBool())
|
||||
{
|
||||
values[0] = value[name_str].GetBool() ? 1.0f : 0.0f;
|
||||
}
|
||||
else if (value[name_str].IsDouble())
|
||||
{
|
||||
values[0] = float(value[name_str].GetDouble());
|
||||
}
|
||||
else
|
||||
{
|
||||
const Value& value_array = value[name_str];
|
||||
for (UINT32 i = 0; i < value_array.Size() && i < 4; i++)
|
||||
{
|
||||
values[i] = float(value_array[i].GetDouble());
|
||||
}
|
||||
}
|
||||
values[i] = value_array[i].GetInt();
|
||||
}
|
||||
}
|
||||
|
||||
void slider_reader::validate_parameters(const Value& value)
|
||||
{
|
||||
assert(value.HasMember("type"));
|
||||
assert(value["type"].IsString());
|
||||
assert(value.HasMember("name"));
|
||||
assert(value["name"].IsString());
|
||||
assert(value.HasMember("min"));
|
||||
assert(value.HasMember("default"));
|
||||
assert(value.HasMember("max"));
|
||||
assert(value.HasMember("step"));
|
||||
assert(value["step"].IsInt());
|
||||
assert(value.HasMember("type"));
|
||||
assert(value["type"].IsString());
|
||||
assert(value.HasMember("screen"));
|
||||
assert(value["screen"].IsString());
|
||||
assert(value.HasMember("scale"));
|
||||
assert(value["scale"].IsFloat());
|
||||
assert(value.HasMember("format"));
|
||||
assert(value["format"].IsString());
|
||||
assert(value.HasMember("text"));
|
||||
assert(value["text"].IsString());
|
||||
assert(value.HasMember("default"));
|
||||
}
|
||||
|
@ -11,21 +11,26 @@
|
||||
#ifndef __DRAWBGFX_SLIDER_READER__
|
||||
#define __DRAWBGFX_SLIDER_READER__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_slider;
|
||||
class running_machine;
|
||||
|
||||
class slider_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_slider* read_from_value(const Value& value);
|
||||
static std::vector<bgfx_slider*> read_from_value(const Value& value, running_machine& machine);
|
||||
|
||||
private:
|
||||
static void get_values(const Value& value, std::string name, float* values);
|
||||
static void get_values(const Value& value, std::string name, int* values, const int count);
|
||||
static void validate_parameters(const Value& value);
|
||||
|
||||
static const int TYPE_COUNT = 5;
|
||||
static const string_to_enum TYPE_NAMES[TYPE_COUNT];
|
||||
static const int SCREEN_COUNT = 11;
|
||||
static const string_to_enum SCREEN_NAMES[SCREEN_COUNT];
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_SLIDER_READER__
|
||||
|
34
src/osd/modules/render/bgfx/slideruniform.cpp
Normal file
34
src/osd/modules/render/bgfx/slideruniform.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// slideruniform.cpp - BGFX shader chain slider uniform
|
||||
//
|
||||
// Represents the mapping between a slider and a chain
|
||||
// shader uniform for a given entry
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#include "slideruniform.h"
|
||||
|
||||
#include "slider.h"
|
||||
|
||||
bgfx_slider_uniform::bgfx_slider_uniform(bgfx_uniform* uniform, std::vector<bgfx_slider*> sliders)
|
||||
: bgfx_entry_uniform(uniform)
|
||||
{
|
||||
for (bgfx_slider* slider : sliders)
|
||||
{
|
||||
m_sliders.push_back(slider);
|
||||
}
|
||||
}
|
||||
|
||||
void bgfx_slider_uniform::bind()
|
||||
{
|
||||
float values[4];
|
||||
for (uint32_t i = 0; i < m_sliders.size(); i++)
|
||||
{
|
||||
values[i] = m_sliders[i]->uniform_value();
|
||||
}
|
||||
printf("Setting slider uniform %s to %f, %f, %f, %f (%s)\n", m_uniform->name().c_str(), values[0], values[1], values[2], values[3], m_sliders[0]->name().c_str());
|
||||
m_uniform->set(values, sizeof(float) * m_sliders.size());
|
||||
}
|
34
src/osd/modules/render/bgfx/slideruniform.h
Normal file
34
src/osd/modules/render/bgfx/slideruniform.h
Normal file
@ -0,0 +1,34 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// slideruniform.h - BGFX shader chain slider uniform
|
||||
//
|
||||
// Represents the mapping between a slider and a chain
|
||||
// shader uniform for a given entry
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_SLIDER_UNIFORM__
|
||||
#define __DRAWBGFX_SLIDER_UNIFORM__
|
||||
|
||||
#include "entryuniform.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class bgfx_slider;
|
||||
|
||||
class bgfx_slider_uniform : public bgfx_entry_uniform
|
||||
{
|
||||
public:
|
||||
bgfx_slider_uniform(bgfx_uniform* uniform, std::vector<bgfx_slider*> sliders);
|
||||
|
||||
virtual void bind() override;
|
||||
|
||||
private:
|
||||
std::vector<bgfx_slider*> m_sliders;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_SLIDER_UNIFORM__
|
42
src/osd/modules/render/bgfx/slideruniformreader.cpp
Normal file
42
src/osd/modules/render/bgfx/slideruniformreader.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//==================================================================
|
||||
//
|
||||
// slideruniformreader.cpp - BGFX chain entry slider mapper reader
|
||||
//
|
||||
//==================================================================
|
||||
|
||||
#include "slideruniformreader.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "slideruniform.h"
|
||||
#include "entryuniform.h"
|
||||
#include "slider.h"
|
||||
|
||||
bgfx_entry_uniform* slider_uniform_reader::read_from_value(const Value& value, bgfx_uniform* uniform, std::map<std::string, bgfx_slider*>& sliders)
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
std::string name = value["slider"].GetString();
|
||||
std::vector<bgfx_slider*> slider_list;
|
||||
slider_list.push_back(sliders[name + "0"]);
|
||||
|
||||
if (slider_list[0]->type() == bgfx_slider::slider_type::SLIDER_VEC2)
|
||||
{
|
||||
slider_list.push_back(sliders[name + "1"]);
|
||||
}
|
||||
else if (slider_list[0]->type() == bgfx_slider::slider_type::SLIDER_COLOR)
|
||||
{
|
||||
slider_list.push_back(sliders[name + "1"]);
|
||||
slider_list.push_back(sliders[name + "2"]);
|
||||
}
|
||||
|
||||
return new bgfx_slider_uniform(uniform, slider_list);
|
||||
}
|
||||
|
||||
void slider_uniform_reader::validate_parameters(const Value& value)
|
||||
{
|
||||
assert(value.HasMember("slider"));
|
||||
assert(value["slider"].IsString());
|
||||
}
|
32
src/osd/modules/render/bgfx/slideruniformreader.h
Normal file
32
src/osd/modules/render/bgfx/slideruniformreader.h
Normal file
@ -0,0 +1,32 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//================================================================
|
||||
//
|
||||
// slideruniformreader.h - BGFX chain entry slider mapper reader
|
||||
//
|
||||
//================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_SLIDER_UNIFORM_READER__
|
||||
#define __DRAWBGFX_SLIDER_UNIFORM_READER__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "entryuniform.h"
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_uniform;
|
||||
class bgfx_slider;
|
||||
|
||||
class slider_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, bgfx_uniform* uniform, std::map<std::string, bgfx_slider*>& sliders);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_SLIDER_UNIFORM_READER__
|
@ -38,14 +38,20 @@ void state_reader::validate_array_parameter(const Value& value, std::string type
|
||||
}
|
||||
}
|
||||
|
||||
void state_reader::validate_double_parameter(const Value& value, std::string typeName, std::string name)
|
||||
void state_reader::validate_float_parameter(const Value& value, std::string typeName, std::string name)
|
||||
{
|
||||
if (value.HasMember(name.c_str()))
|
||||
{
|
||||
assert(value[name.c_str()].IsDouble());
|
||||
assert(value[name.c_str()].IsFloat());
|
||||
}
|
||||
}
|
||||
|
||||
void state_reader::validate_int_parameter(const Value& value, std::string typeName, std::string name) {
|
||||
if (value.HasMember(name.c_str())) {
|
||||
assert(value[name.c_str()].IsInt());
|
||||
}
|
||||
}
|
||||
|
||||
void state_reader::validate_string_parameter(const Value& value, std::string typeName, std::string name)
|
||||
{
|
||||
if (value.HasMember(name.c_str()))
|
||||
@ -71,6 +77,13 @@ bool state_reader::get_bool(const Value& value, const std::string name, const bo
|
||||
return default_value;
|
||||
}
|
||||
|
||||
int state_reader::get_int(const Value& value, const std::string name, const int default_value) {
|
||||
if (value.HasMember(name.c_str())) {
|
||||
return int(floor(value[name.c_str()].GetDouble() + 0.5));
|
||||
}
|
||||
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()))
|
||||
|
@ -22,13 +22,15 @@ protected:
|
||||
};
|
||||
|
||||
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_float_parameter(const Value& value, std::string type_name, std::string name);
|
||||
static void validate_int_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 void get_float(const Value& value, const std::string name, float* out, float* default_value, const int count = 1);
|
||||
static int get_int(const Value& value, const std::string name, int default_value);
|
||||
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);
|
||||
|
@ -8,14 +8,16 @@
|
||||
|
||||
#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)))
|
||||
bgfx_target::bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter, uint32_t style)
|
||||
: bgfx_texture(name, format, width, height, BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | (filter ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT)), nullptr)
|
||||
, m_style(style)
|
||||
{
|
||||
m_target = bgfx::createFrameBuffer(1, &m_handle, false);
|
||||
}
|
||||
|
||||
bgfx_target::bgfx_target(std::string name, void *handle, uint32_t width, uint32_t height)
|
||||
: bgfx_texture(name, bgfx::TextureFormat::RGBA8, width, height, nullptr, BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT)
|
||||
bgfx_target::bgfx_target(std::string name, uint32_t width, uint32_t height, uint32_t style, void *handle)
|
||||
: bgfx_texture(name, bgfx::TextureFormat::RGBA8, width, height, BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT, nullptr)
|
||||
, m_style(style)
|
||||
{
|
||||
m_target = bgfx::createFrameBuffer(handle, width, height);
|
||||
}
|
||||
|
@ -13,19 +13,30 @@
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
enum
|
||||
{
|
||||
TARGET_STYLE_GUEST = 0,
|
||||
TARGET_STYLE_NATIVE,
|
||||
TARGET_STYLE_CUSTOM
|
||||
};
|
||||
|
||||
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);
|
||||
bgfx_target(std::string name, void *handle, uint32_t width, uint32_t height);
|
||||
bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter = false, uint32_t style = TARGET_STYLE_CUSTOM);
|
||||
bgfx_target(std::string name, uint32_t width, uint32_t height, uint32_t style, void *handle);
|
||||
virtual ~bgfx_target();
|
||||
|
||||
// Getters
|
||||
bgfx::FrameBufferHandle target() const { return m_target; }
|
||||
uint32_t style() const { return m_style; }
|
||||
bool filter() const { return m_filter; }
|
||||
virtual bool is_target() const override { return true; }
|
||||
|
||||
private:
|
||||
bgfx::FrameBufferHandle m_target;
|
||||
bgfx::FrameBufferHandle m_target;
|
||||
uint32_t m_style;
|
||||
bool m_filter;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_TARGET__
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "targetmanager.h"
|
||||
#include "target.h"
|
||||
|
||||
@ -34,7 +36,7 @@ bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat
|
||||
|
||||
bgfx_target* target_manager::create_target(std::string name, void *handle, uint32_t width, uint32_t height)
|
||||
{
|
||||
bgfx_target* target = new bgfx_target(name, handle, width, height);
|
||||
bgfx_target* target = new bgfx_target(name, width, height, TARGET_STYLE_CUSTOM, handle);
|
||||
m_targets[name] = target;
|
||||
|
||||
m_textures.add_texture(name, target);
|
||||
@ -51,3 +53,26 @@ bgfx_target* target_manager::target(std::string name)
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void target_manager::update_guest_targets(uint16_t width, uint16_t height)
|
||||
{
|
||||
if (width != m_guest_width || height != m_guest_height)
|
||||
{
|
||||
m_guest_width = width;
|
||||
m_guest_height = height;
|
||||
std::vector<bgfx_target*> to_resize;
|
||||
for (std::pair<std::string, bgfx_target*> target : m_targets)
|
||||
{
|
||||
if ((target.second)->style() == TARGET_STYLE_GUEST)
|
||||
{
|
||||
to_resize.push_back(target.second);
|
||||
}
|
||||
}
|
||||
|
||||
for (bgfx_target* target : to_resize)
|
||||
{
|
||||
m_targets[target->name()] = new bgfx_target(target->name(), target->format(), width, height, TARGET_STYLE_GUEST, target->filter());
|
||||
delete target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,20 +25,27 @@ class bgfx_target;
|
||||
|
||||
class target_manager {
|
||||
public:
|
||||
target_manager(texture_manager& textures) : m_textures(textures) { }
|
||||
target_manager(texture_manager& textures) : m_textures(textures), m_guest_width(16), m_guest_height(16) { }
|
||||
~target_manager();
|
||||
|
||||
bgfx_target* create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter = false);
|
||||
bgfx_target* create_target(std::string name, void *handle, uint32_t width, uint32_t height);
|
||||
|
||||
void update_guest_targets(uint16_t width, uint16_t height);
|
||||
|
||||
// Getters
|
||||
bgfx_target* target(std::string name);
|
||||
uint16_t guest_width() const { return m_guest_width; }
|
||||
uint16_t guest_height() const { return m_guest_height; }
|
||||
|
||||
private:
|
||||
bgfx_target* create_target(std::string name);
|
||||
|
||||
std::map<std::string, bgfx_target*> m_targets;
|
||||
texture_manager& m_textures;
|
||||
|
||||
uint16_t m_guest_width;
|
||||
uint16_t m_guest_height;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_TARGET_MANAGER__
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#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)
|
||||
bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, uint32_t flags, void* data)
|
||||
: m_name(name)
|
||||
, m_format(format)
|
||||
, m_width(width)
|
||||
@ -32,6 +32,17 @@ bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, u
|
||||
}
|
||||
}
|
||||
|
||||
bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, const bgfx::Memory* 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);
|
||||
m_handle = bgfx::createTexture2D(width, height, 1, format, flags, data);
|
||||
}
|
||||
|
||||
bgfx_texture::~bgfx_texture()
|
||||
{
|
||||
bgfx::destroyTexture(m_handle);
|
||||
|
@ -18,7 +18,8 @@
|
||||
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);
|
||||
bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, uint32_t flags, void* data);
|
||||
bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, const bgfx::Memory* data, uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP);
|
||||
virtual ~bgfx_texture();
|
||||
|
||||
// Getters
|
||||
|
@ -18,7 +18,7 @@ texture_manager::~texture_manager()
|
||||
{
|
||||
for (std::pair<std::string, bgfx_texture*> texture : m_textures)
|
||||
{
|
||||
if (!(texture.second)->is_target())
|
||||
if (texture.second != nullptr && !(texture.second)->is_target())
|
||||
{
|
||||
delete texture.second;
|
||||
}
|
||||
@ -33,7 +33,7 @@ void texture_manager::add_texture(std::string name, bgfx_texture* 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);
|
||||
bgfx_texture* texture = new bgfx_texture(name, format, width, height, flags, data);
|
||||
m_textures[name] = texture;
|
||||
return texture;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ bgfx_uniform::~bgfx_uniform()
|
||||
|
||||
void bgfx_uniform::upload()
|
||||
{
|
||||
if (m_type != bgfx::UniformType::Int1) // Avoid samplers; set separately!
|
||||
//if (m_type != bgfx::UniformType::Int1) // Avoid samplers; set separately!
|
||||
bgfx::setUniform(m_handle, m_data);
|
||||
}
|
||||
|
||||
|
25
src/osd/modules/render/bgfx/valueuniform.cpp
Normal file
25
src/osd/modules/render/bgfx/valueuniform.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// valueuniform.cpp - BGFX shader chain fixed uniform
|
||||
//
|
||||
// Represents the mapping between a fixed value and a chain
|
||||
// shader uniform for a given entry
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#include "valueuniform.h"
|
||||
|
||||
bgfx_value_uniform::bgfx_value_uniform(bgfx_uniform* uniform, float* values, const int count)
|
||||
: bgfx_entry_uniform(uniform)
|
||||
, m_count(count)
|
||||
{
|
||||
memcpy(m_values, values, sizeof(float) * count);
|
||||
}
|
||||
|
||||
void bgfx_value_uniform::bind()
|
||||
{
|
||||
printf("Setting value uniform %s to %f, %f, %f, %f (%s)\n", m_uniform->name().c_str(), m_values[0], m_values[1], m_values[2], m_values[3]);
|
||||
m_uniform->set(m_values, sizeof(float) * m_count);
|
||||
}
|
31
src/osd/modules/render/bgfx/valueuniform.h
Normal file
31
src/osd/modules/render/bgfx/valueuniform.h
Normal file
@ -0,0 +1,31 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// valueuniform.cpp - BGFX shader chain fixed uniform
|
||||
//
|
||||
// Represents the mapping between a fixed value and a chain
|
||||
// shader uniform for a given entry
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_VALUE_UNIFORM__
|
||||
#define __DRAWBGFX_VALUE_UNIFORM__
|
||||
|
||||
#include "entryuniform.h"
|
||||
|
||||
class bgfx_value_uniform : public bgfx_entry_uniform
|
||||
{
|
||||
public:
|
||||
bgfx_value_uniform(bgfx_uniform* uniform, float* values, const int count);
|
||||
|
||||
virtual void bind() override;
|
||||
|
||||
private:
|
||||
float m_values[4];
|
||||
const int m_count;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_VALUE_UNIFORM__
|
40
src/osd/modules/render/bgfx/valueuniformreader.cpp
Normal file
40
src/osd/modules/render/bgfx/valueuniformreader.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//==================================================================
|
||||
//
|
||||
// valueuniformreader.cpp - BGFX chain entry value mapper reader
|
||||
//
|
||||
//==================================================================
|
||||
|
||||
#include "valueuniformreader.h"
|
||||
|
||||
#include "entryuniform.h"
|
||||
#include "valueuniform.h"
|
||||
|
||||
bgfx_entry_uniform* value_uniform_reader::read_from_value(const Value& value, bgfx_uniform* uniform)
|
||||
{
|
||||
validate_parameters(value);
|
||||
|
||||
float values[4];
|
||||
int count = 1;
|
||||
if (value["value"].IsNumber())
|
||||
{
|
||||
values[0] = float(value["value"].GetDouble());
|
||||
}
|
||||
else
|
||||
{
|
||||
const Value& value_array = value["value"];
|
||||
count = int(value_array.Size());
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = float(value_array[i].GetDouble());
|
||||
}
|
||||
}
|
||||
return new bgfx_value_uniform(uniform, values, count);
|
||||
}
|
||||
|
||||
void value_uniform_reader::validate_parameters(const Value& value)
|
||||
{
|
||||
assert(value.HasMember("value"));
|
||||
assert(value["value"].IsArray() || value["value"].IsNumber());
|
||||
}
|
31
src/osd/modules/render/bgfx/valueuniformreader.h
Normal file
31
src/osd/modules/render/bgfx/valueuniformreader.h
Normal file
@ -0,0 +1,31 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//================================================================
|
||||
//
|
||||
// valueuniformreader.h - BGFX chain entry value mapper reader
|
||||
//
|
||||
//================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_VALUE_UNIFORM_READER__
|
||||
#define __DRAWBGFX_VALUE_UNIFORM_READER__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_entry_uniform;
|
||||
class bgfx_uniform;
|
||||
|
||||
class value_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, bgfx_uniform* uniform);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_VALUE_UNIFORM_READER__
|
35
src/osd/modules/render/bgfx/vertex.h
Normal file
35
src/osd/modules/render/bgfx/vertex.h
Normal file
@ -0,0 +1,35 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//============================================================
|
||||
//
|
||||
// vertex.h - BGFX screen vertex data
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_VERTEX__
|
||||
#define __DRAWBGFX_VERTEX__
|
||||
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
struct ScreenVertex {
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
UINT32 m_rgba;
|
||||
float m_u;
|
||||
float m_v;
|
||||
|
||||
static void init() {
|
||||
ms_decl.begin()
|
||||
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
||||
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
||||
.end();
|
||||
}
|
||||
|
||||
static bgfx::VertexDecl ms_decl;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_VERTEX__
|
@ -2214,7 +2214,7 @@ static void get_vector(const char *data, int count, float *out, bool report_erro
|
||||
static slider_state *slider_alloc(running_machine &machine, int id, const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg)
|
||||
{
|
||||
int size = sizeof(slider_state) + strlen(title);
|
||||
slider_state *state = (slider_state *)auto_alloc_array_clear(machine, UINT8, size);
|
||||
slider_state *state = reinterpret_cast<slider_state *>(auto_alloc_array_clear(machine, UINT8, size));
|
||||
|
||||
state->minval = minval;
|
||||
state->defval = defval;
|
||||
|
@ -271,7 +271,7 @@ struct slider_desc
|
||||
int step;
|
||||
int slider_type;
|
||||
int screen_type;
|
||||
int id;
|
||||
int id;
|
||||
float scale;
|
||||
const char * format;
|
||||
std::vector<const char *> strings;
|
||||
|
@ -40,6 +40,9 @@
|
||||
#include "bgfx/texture.h"
|
||||
#include "bgfx/target.h"
|
||||
#include "bgfx/chain.h"
|
||||
#include "bgfx/vertex.h"
|
||||
#include "bgfx/uniform.h"
|
||||
#include "bgfx/slider.h"
|
||||
|
||||
//============================================================
|
||||
// DEBUGGING
|
||||
@ -57,7 +60,8 @@ const uint32_t renderer_bgfx::WHITE_HASH = 0x87654321;
|
||||
// MACROS
|
||||
//============================================================
|
||||
|
||||
#define GIBBERISH (0)
|
||||
#define GIBBERISH (0)
|
||||
#define USE_NEW_SHADERS (0)
|
||||
|
||||
//============================================================
|
||||
// INLINES
|
||||
@ -135,7 +139,7 @@ int renderer_bgfx::create()
|
||||
m_targets = new target_manager(*m_textures);
|
||||
m_shaders = new shader_manager();
|
||||
m_effects = new effect_manager(*m_shaders);
|
||||
m_chains = new chain_manager(*m_textures, *m_targets, *m_effects, m_width[window().m_index], m_height[window().m_index]);
|
||||
//m_chains = new chain_manager(*m_textures, *m_targets, *m_effects, m_width[window().m_index], m_height[window().m_index]);
|
||||
|
||||
if (window().m_index != 0)
|
||||
{
|
||||
@ -158,7 +162,8 @@ int renderer_bgfx::create()
|
||||
m_screen_effect[2] = m_effects->effect("screen_multiply");
|
||||
m_screen_effect[3] = m_effects->effect("screen_add");
|
||||
|
||||
//m_screen_chain[0] = m_chains->chain("test");
|
||||
//m_screen_chain = m_chains->chain("test", window().machine());
|
||||
m_sliders_dirty = true;
|
||||
|
||||
uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT;
|
||||
m_texture_cache = m_textures->create_texture("#cache", bgfx::TextureFormat::RGBA8, CACHE_SIZE, CACHE_SIZE, nullptr, flags);
|
||||
@ -176,7 +181,7 @@ int renderer_bgfx::create()
|
||||
renderer_bgfx::~renderer_bgfx()
|
||||
{
|
||||
// Cleanup.
|
||||
delete m_chains;
|
||||
//delete m_chains;
|
||||
delete m_effects;
|
||||
delete m_shaders;
|
||||
delete m_textures;
|
||||
@ -210,7 +215,7 @@ int renderer_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt)
|
||||
// drawbgfx_window_draw
|
||||
//============================================================
|
||||
|
||||
bgfx::VertexDecl renderer_bgfx::ScreenVertex::ms_decl;
|
||||
bgfx::VertexDecl ScreenVertex::ms_decl;
|
||||
|
||||
void renderer_bgfx::put_packed_quad(render_primitive *prim, UINT32 hash, ScreenVertex* vertex)
|
||||
{
|
||||
@ -295,9 +300,32 @@ void renderer_bgfx::put_packed_quad(render_primitive *prim, UINT32 hash, ScreenV
|
||||
vertex[5].m_v = v[0];
|
||||
}
|
||||
|
||||
void renderer_bgfx::render_screen_quad(int view, render_primitive* prim)
|
||||
{
|
||||
uint32_t texture_flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP;
|
||||
if (video_config.filter == 0) {
|
||||
texture_flags |= BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT;
|
||||
}
|
||||
|
||||
const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK,
|
||||
prim->texture.width, prim->texture.height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base);
|
||||
|
||||
uint16_t tex_width(prim->texture.width);
|
||||
uint16_t tex_height(prim->texture.height);
|
||||
|
||||
bgfx_texture *texture = new bgfx_texture("screen", bgfx::TextureFormat::RGBA8, uint16_t(prim->texture.width), uint16_t(prim->texture.height), mem);
|
||||
m_textures->add_texture("screen", texture);
|
||||
|
||||
m_targets->update_guest_targets(tex_width, tex_height);
|
||||
m_screen_chain->process(prim, view, *m_textures, window().get_size().width(), window().get_size().height(), get_blend_state(PRIMFLAG_GET_BLENDMODE(prim->flags)));
|
||||
|
||||
m_textures->add_texture("screen", nullptr);
|
||||
delete texture;
|
||||
}
|
||||
|
||||
void renderer_bgfx::render_textured_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer)
|
||||
{
|
||||
ScreenVertex* vertex = (ScreenVertex*)buffer->data;
|
||||
ScreenVertex* vertex = reinterpret_cast<ScreenVertex*>(buffer->data);
|
||||
|
||||
UINT32 rgba = u32Color(prim->color.r * 255, prim->color.g * 255, prim->color.b * 255, prim->color.a * 255);
|
||||
|
||||
@ -342,7 +370,6 @@ void renderer_bgfx::render_textured_quad(int view, render_primitive* prim, bgfx:
|
||||
vertex[5].m_rgba = rgba;
|
||||
vertex[5].m_u = prim->texcoords.tl.u;
|
||||
vertex[5].m_v = prim->texcoords.tl.v;
|
||||
bgfx::setVertexBuffer(buffer);
|
||||
|
||||
uint32_t texture_flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP;
|
||||
if (video_config.filter == 0)
|
||||
@ -353,10 +380,12 @@ void renderer_bgfx::render_textured_quad(int view, render_primitive* prim, bgfx:
|
||||
const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK,
|
||||
prim->texture.width, prim->texture.height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base);
|
||||
|
||||
bgfx::TextureHandle texture = bgfx::createTexture2D((uint16_t)prim->texture.width, (uint16_t)prim->texture.height, 1, bgfx::TextureFormat::RGBA8, texture_flags, mem);
|
||||
bgfx::TextureHandle texture = bgfx::createTexture2D(uint16_t(prim->texture.width), uint16_t(prim->texture.height), 1, bgfx::TextureFormat::RGBA8, texture_flags, mem);
|
||||
|
||||
bgfx_effect** effects = PRIMFLAG_GET_SCREENTEX(prim->flags) ? m_screen_effect : m_gui_effect;
|
||||
|
||||
UINT32 blend = PRIMFLAG_GET_BLENDMODE(prim->flags);
|
||||
bgfx::setVertexBuffer(buffer);
|
||||
bgfx::setTexture(0, effects[blend]->uniform("s_tex")->handle(), texture);
|
||||
effects[blend]->submit(view);
|
||||
|
||||
@ -889,11 +918,18 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vertices > 0)
|
||||
{
|
||||
return BUFFER_PRE_FLUSH;
|
||||
}
|
||||
#if USE_NEW_SHADERS
|
||||
if (PRIMFLAG_GET_SCREENTEX((*prim)->flags))
|
||||
{
|
||||
render_screen_quad(view, *prim);
|
||||
}
|
||||
else
|
||||
{
|
||||
render_textured_quad(view, *prim, buffer);
|
||||
}
|
||||
#else
|
||||
render_textured_quad(view, *prim, buffer);
|
||||
#endif
|
||||
return BUFFER_EMPTY;
|
||||
}
|
||||
}
|
||||
@ -923,25 +959,26 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl
|
||||
return BUFFER_FLUSH;
|
||||
}
|
||||
|
||||
uint64_t renderer_bgfx::get_blend_state(UINT32 blend)
|
||||
{
|
||||
switch (blend)
|
||||
{
|
||||
case BLENDMODE_ALPHA:
|
||||
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
|
||||
case BLENDMODE_RGB_MULTIPLY:
|
||||
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO);
|
||||
case BLENDMODE_ADD:
|
||||
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_ONE);
|
||||
default:
|
||||
return 0L;
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
void renderer_bgfx::set_bgfx_state(UINT32 blend)
|
||||
{
|
||||
uint64_t flags = BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE | BGFX_STATE_DEPTH_TEST_ALWAYS;
|
||||
|
||||
switch (blend)
|
||||
{
|
||||
case BLENDMODE_NONE:
|
||||
bgfx::setState(flags);
|
||||
break;
|
||||
case BLENDMODE_ALPHA:
|
||||
bgfx::setState(flags | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA));
|
||||
break;
|
||||
case BLENDMODE_RGB_MULTIPLY:
|
||||
bgfx::setState(flags | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO));
|
||||
break;
|
||||
case BLENDMODE_ADD:
|
||||
bgfx::setState(flags | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_ONE));
|
||||
break;
|
||||
}
|
||||
bgfx::setState(flags | get_blend_state(blend));
|
||||
}
|
||||
|
||||
bool renderer_bgfx::update_atlas()
|
||||
@ -1105,5 +1142,24 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
|
||||
|
||||
slider_state* renderer_bgfx::get_slider_list()
|
||||
{
|
||||
return nullptr;
|
||||
slider_state *listhead = nullptr;
|
||||
#if USE_NEW_SHADERS
|
||||
slider_state **tailptr = &listhead;
|
||||
std::vector<bgfx_slider*> sliders = m_screen_chain->sliders();
|
||||
for (bgfx_slider* slider : sliders)
|
||||
{
|
||||
if (*tailptr == nullptr)
|
||||
{
|
||||
*tailptr = slider->core_slider();
|
||||
}
|
||||
else
|
||||
{
|
||||
(*tailptr)->next = slider->core_slider();
|
||||
tailptr = &(*tailptr)->next;
|
||||
}
|
||||
}
|
||||
(*tailptr)->next = nullptr;
|
||||
m_sliders_dirty = false;
|
||||
#endif
|
||||
return listhead;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "binpacker.h"
|
||||
#include "bgfx/vertex.h"
|
||||
|
||||
class texture_manager;
|
||||
class target_manager;
|
||||
@ -54,27 +55,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
struct ScreenVertex
|
||||
{
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
UINT32 m_rgba;
|
||||
float m_u;
|
||||
float m_v;
|
||||
|
||||
static void init()
|
||||
{
|
||||
ms_decl.begin()
|
||||
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
||||
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
||||
.end();
|
||||
}
|
||||
|
||||
static bgfx::VertexDecl ms_decl;
|
||||
};
|
||||
|
||||
void allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::TransientVertexBuffer *buffer);
|
||||
enum buffer_status
|
||||
{
|
||||
@ -85,6 +65,7 @@ private:
|
||||
};
|
||||
buffer_status buffer_primitives(int view, bool atlas_valid, render_primitive** prim, bgfx::TransientVertexBuffer* buffer);
|
||||
|
||||
void render_screen_quad(int view, render_primitive* prim);
|
||||
void render_textured_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer);
|
||||
|
||||
void put_packed_quad(render_primitive *prim, UINT32 hash, ScreenVertex* vertex);
|
||||
@ -92,8 +73,9 @@ private:
|
||||
void put_line(float x0, float y0, float x1, float y1, float r, UINT32 rgba, ScreenVertex* vertex, float fth = 1.0f);
|
||||
|
||||
void set_bgfx_state(UINT32 blend);
|
||||
uint64_t get_blend_state(UINT32 blend);
|
||||
|
||||
uint32_t u32Color(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
|
||||
static uint32_t u32Color(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
|
||||
|
||||
bool check_for_dirty_atlas();
|
||||
bool update_atlas();
|
||||
@ -115,7 +97,7 @@ private:
|
||||
|
||||
bgfx_effect* m_gui_effect[4];
|
||||
bgfx_effect* m_screen_effect[4];
|
||||
//bgfx_chain* m_screen_chain[4];
|
||||
bgfx_chain* m_screen_chain;
|
||||
|
||||
std::map<UINT32, rectangle_packer::packed_rectangle> m_hash_to_entry;
|
||||
std::vector<rectangle_packer::packable_rectangle> m_texinfo;
|
||||
@ -124,6 +106,7 @@ private:
|
||||
uint32_t m_width[16];
|
||||
uint32_t m_height[16];
|
||||
uint32_t m_white[16*16];
|
||||
|
||||
static const uint16_t CACHE_SIZE;
|
||||
static const uint32_t PACKABLE_SIZE;
|
||||
static const uint32_t WHITE_HASH;
|
||||
|
Loading…
Reference in New Issue
Block a user