summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/chainmanager.h
blob: 2c130354dc1df9c2c99c4bc930a96524bdfa4d66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
//
//  chainmanager.h - BGFX shader chain manager
//
//  Provides loading for BGFX shader effect chains, defined
//  by chain.h and read by chainreader.h
//
//============================================================

#pragma once

#ifndef __DRAWBGFX_CHAIN_MANAGER__
#define __DRAWBGFX_CHAIN_MANAGER__

#include <vector>
#include <map>
#include <string>

#include "texturemanager.h"
#include "targetmanager.h"
#include "effectmanager.h"
#include "../frontend/mame/ui/menuitem.h"
#include "render.h"

class running_machine;
class osd_window;
struct slider_state;
class slider_dirty_notifier;
class render_primitive;

class bgfx_chain;
class bgfx_slider;

class chain_desc
{
public:
	chain_desc(std::string name, std::string path)
		: m_name(name)
		, m_path(path)
	{
	}

	const std::string m_name;
	const std::string m_path;
};

class chain_manager
{
public:
	chain_manager(running_machine& machine, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t window_index, slider_dirty_notifier& slider_notifier);
	~chain_manager();

	uint32_t update_screen_textures(uint32_t view, render_primitive *starting_prim, osd_window& window);
	uint32_t process_screen_chains(uint32_t view, osd_window& window);

	// Getters
	running_machine& machine() const { return m_machine; }
	osd_options& options() const { return m_options; }
	texture_manager& textures() const { return m_textures; }
	target_manager& targets() const { return m_targets; }
	effect_manager& effects() const { return m_effects; }
	slider_dirty_notifier& slider_notifier() const { return m_slider_notifier; }
	uint32_t window_index() const { return m_window_index; }
	uint32_t screen_count() const { return m_screen_count; }
	bgfx_chain* screen_chain(uint32_t screen);
	bgfx_chain* load_chain(std::string name, uint32_t screen_index);
	bool has_applicable_chain(uint32_t screen);
	std::vector<ui::menu_item> get_slider_list();
	std::vector<std::vector<float>> slider_settings();

	// Setters
	void restore_slider_settings(int32_t id, std::vector<std::vector<float>>& settings);

	class screen_prim
	{
	public:
		screen_prim() : m_prim(nullptr), m_screen_width(0), m_screen_height(0), m_quad_width(0), m_quad_height(0)
			, m_tex_width(0), m_tex_height(0), m_rowpixels(0), m_palette_length(0), m_flags(0)
		{
		}

		screen_prim(render_primitive *prim)
		{
			m_prim = prim;
			m_screen_width = (uint16_t)floorf(prim->get_full_quad_width() + 0.5f);
			m_screen_height = (uint16_t)floorf(prim->get_full_quad_height() + 0.5f);
			m_quad_width = (uint16_t)floorf(prim->get_quad_width() + 0.5f);
			m_quad_height = (uint16_t)floorf(prim->get_quad_height() + 0.5f);
			m_tex_width = (float)prim->texture.width;
			m_tex_height = (float)prim->texture.height;
			m_rowpixels = prim->texture.rowpixels;
			m_palette_length = prim->texture.palette_length;
			m_flags = prim->flags;
		}

		render_primitive *m_prim;
		uint16_t m_screen_width;
		uint16_t m_screen_height;
		uint16_t m_quad_width;
		uint16_t m_quad_height;
		float m_tex_width;
		float m_tex_height;
		int m_rowpixels;
		uint32_t m_palette_length;
		uint32_t m_flags;
	};

private:
	void load_chains();
	void destroy_chains();
	void reload_chains();

	void init_texture_converters();

	void refresh_available_chains();
	void destroy_unloaded_chains();
	void find_available_chains(std::string root, std::string path);
	void parse_chain_selections(std::string chain_str);
	std::vector<std::string> split_option_string(std::string chain_str) const;

	void update_screen_count(uint32_t screen_count);

	int32_t slider_changed(int id, std::string *str, int32_t newval);
	void create_selection_slider(uint32_t screen_index);
	bool needs_sliders();

	uint32_t count_screens(render_primitive* prim);
	void process_screen_quad(uint32_t view, uint32_t screen, screen_prim &prim, osd_window& window);

	running_machine&            m_machine;
	osd_options&                m_options;
	texture_manager&            m_textures;
	target_manager&             m_targets;
	effect_manager&             m_effects;
	uint32_t                    m_window_index;
	slider_dirty_notifier&      m_slider_notifier;
	uint32_t                    m_screen_count;
	std::vector<chain_desc>     m_available_chains;
	std::vector<bgfx_chain*>    m_screen_chains;
	std::vector<std::string>    m_chain_names;
	std::vector<ui::menu_item>  m_selection_sliders;
	std::vector<std::unique_ptr<slider_state>> m_core_sliders;
	std::vector<int32_t>        m_current_chain;
	std::vector<bgfx_texture*>  m_screen_textures;
	std::vector<bgfx_texture*>  m_screen_palettes;
	std::vector<bgfx_effect*>   m_converters;
	bgfx_effect *               m_adjuster;
	std::vector<screen_prim>    m_screen_prims;
	std::vector<uint8_t>        m_palette_temp;

	static const uint32_t       CHAIN_NONE;
};

#endif // __DRAWBGFX_CHAIN_MANAGER__