Fix cocktail mode crash

This commit is contained in:
therealmogminer@gmail.com 2016-03-21 18:26:50 +01:00
parent a99df78801
commit 124b4ab8a7
4 changed files with 32 additions and 13 deletions

View File

@ -62,7 +62,7 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
put_screen_buffer(prim, &buffer);
bgfx::setVertexBuffer(&buffer);
setup_auto_uniforms(prim, textures, screen_width, screen_height, rotation_type, swap_xy);
setup_auto_uniforms(prim, textures, screen_width, screen_height, rotation_type, swap_xy, screen);
for (bgfx_entry_uniform* uniform : m_uniforms)
{
@ -85,14 +85,19 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
}
}
void bgfx_chain_entry::setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height)
void bgfx_chain_entry::setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height, int32_t screen)
{
float width = screen_width;
float height = screen_height;
if (m_inputs.size() > 0)
{
width = float(textures.provider(m_inputs[0].texture())->width());
height = float(textures.provider(m_inputs[0].texture())->height());
std::string name = m_inputs[0].texture();
if (name == "previous")
{
name = name + std::to_string(screen);
}
width = float(textures.provider(name)->width());
height = float(textures.provider(name)->height());
}
bgfx_uniform* screen_dims = m_effect->uniform("u_screen_dims");
@ -140,9 +145,9 @@ void bgfx_chain_entry::setup_swapxy_uniform(bool swap_xy)
}
}
void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy)
void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen)
{
setup_screensize_uniforms(textures, screen_width, screen_height);
setup_screensize_uniforms(textures, screen_width, screen_height, screen);
setup_sourcesize_uniform(prim);
setup_rotationtype_uniform(rotation_type);
setup_swapxy_uniform(swap_xy);

View File

@ -43,8 +43,8 @@ public:
bool skip();
private:
void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy);
void setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height);
void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen);
void setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height, int32_t screen);
void setup_sourcesize_uniform(render_primitive* prim);
void setup_rotationtype_uniform(uint32_t rotation_type);
void setup_swapxy_uniform(bool swap_xy);

View File

@ -765,6 +765,7 @@ int renderer_bgfx::handle_screen_chains()
int renderer_bgfx::draw(int update)
{
m_screens.clear();
int window_index = window().m_index;
int post_view_index = handle_screen_chains();
int view_index = window_index;
@ -837,7 +838,7 @@ int renderer_bgfx::draw(int update)
bool atlas_valid = update_atlas();
render_primitive *prim = window().m_primlist->first();
int32_t screen = 0;
std::vector<screen_device*> screens;
while (prim != nullptr)
{
UINT32 blend = PRIMFLAG_GET_BLENDMODE(prim->flags);
@ -845,13 +846,24 @@ int renderer_bgfx::draw(int update)
bgfx::TransientVertexBuffer buffer;
allocate_buffer(prim, blend, &buffer);
buffer_status status = buffer_primitives(view_index, atlas_valid, &prim, &buffer, screen);
if (status == BUFFER_SCREEN)
int32_t screen = 0;
if (PRIMFLAG_GET_SCREENTEX(prim->flags))
{
screen++;
for (screen = 0; screen < screens.size(); screen++)
{
if (screens[screen] == prim->container->screen())
{
break;
}
}
if (screen == screens.size())
{
screens.push_back(prim->container->screen());
}
}
buffer_status status = buffer_primitives(view_index, atlas_valid, &prim, &buffer, screen);
if (status != BUFFER_EMPTY && status != BUFFER_SCREEN)
{
bgfx::setVertexBuffer(&buffer);

View File

@ -92,6 +92,8 @@ private:
const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(UINT32 format, int width, int height, int rowpixels, const rgb_t *palette, void *base);
UINT32 get_texture_hash(render_primitive *prim);
std::vector<screen_device*> m_screens;
bgfx_target* m_framebuffer;
bgfx_texture* m_texture_cache;