summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author therealmogminer@gmail.com <therealmogminer@gmail.com>2016-03-18 16:53:21 +0100
committer therealmogminer@gmail.com <therealmogminer@gmail.com>2016-03-18 16:53:21 +0100
commitc383078ba572a56bea6c21e97721fb6c00684232 (patch)
tree1e89aeffffcd044ffa3af8ed016347814a9bce9b
parent03b2de3556b3f6cbe78560bbd8b8641d76882338 (diff)
Hopefully fix crashes on SDL, nw
-rw-r--r--src/osd/modules/render/bgfx/chainentry.cpp12
-rw-r--r--src/osd/modules/render/bgfx/chainentry.h2
-rw-r--r--src/osd/modules/render/bgfx/chainreader.cpp3
-rw-r--r--src/osd/modules/render/bgfx/target.cpp32
-rw-r--r--src/osd/modules/render/bgfx/target.h4
-rw-r--r--src/osd/modules/render/bgfx/targetmanager.cpp30
-rw-r--r--src/osd/modules/render/bgfx/targetmanager.h2
-rw-r--r--src/osd/modules/render/drawbgfx.cpp29
8 files changed, 58 insertions, 56 deletions
diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp
index fdd56aac3ab..6ca690c812d 100644
--- a/src/osd/modules/render/bgfx/chainentry.cpp
+++ b/src/osd/modules/render/bgfx/chainentry.cpp
@@ -48,7 +48,10 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
{
bgfx::setViewSeq(view, true);
- setup_view(view, screen_width, screen_height);
+ if (!setup_view(view, screen_width, screen_height))
+ {
+ return;
+ }
for (bgfx_input_pair input : m_inputs)
{
@@ -140,7 +143,7 @@ void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manag
setup_swapxy_uniform(swap_xy);
}
-void bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t screen_height)
+bool bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t screen_height)
{
bgfx::FrameBufferHandle handle = BGFX_INVALID_HANDLE;
uint16_t width = screen_width;
@@ -148,6 +151,10 @@ void bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t scre
if (m_targets.target(m_output) != nullptr)
{
bgfx_target* output = m_targets.target(m_output);
+ if (output->width() == 0)
+ {
+ return false;
+ }
handle = output->target();
width = output->width() * output->prescale_x();
height = output->height() * output->prescale_y();
@@ -164,6 +171,7 @@ void bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t scre
bgfx::setViewTransform(view, viewMat, projMat);
bgfx::setViewClear(view, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0);
+ return true;
}
void bgfx_chain_entry::put_screen_buffer(render_primitive* prim, bgfx::TransientVertexBuffer* buffer)
diff --git a/src/osd/modules/render/bgfx/chainentry.h b/src/osd/modules/render/bgfx/chainentry.h
index 5467f90ab5b..83f834cca15 100644
--- a/src/osd/modules/render/bgfx/chainentry.h
+++ b/src/osd/modules/render/bgfx/chainentry.h
@@ -50,7 +50,7 @@ private:
void setup_rotationtype_uniform(uint32_t rotation_type);
void setup_swapxy_uniform(bool swap_xy);
- void setup_view(int view, uint16_t screen_width, uint16_t screen_height);
+ bool setup_view(int view, uint16_t screen_width, uint16_t screen_height);
void put_screen_buffer(render_primitive* prim, bgfx::TransientVertexBuffer* buffer);
std::string m_name;
diff --git a/src/osd/modules/render/bgfx/chainreader.cpp b/src/osd/modules/render/bgfx/chainreader.cpp
index 68ba24183e3..af679b1b15d 100644
--- a/src/osd/modules/render/bgfx/chainreader.cpp
+++ b/src/osd/modules/render/bgfx/chainreader.cpp
@@ -89,7 +89,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
bool bilinear = get_bool(target_array[i], "bilinear", true);
bool double_buffer = get_bool(target_array[i], "doublebuffer", true);
bool prescale = get_bool(target_array[i], "prescale", false);
-
+
uint16_t width = 0;
uint16_t height = 0;
switch (mode)
@@ -119,6 +119,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
prescale_x = options.bgfx_prescale_x();
prescale_y = options.bgfx_prescale_y();
}
+
targets.create_target(target_array[i]["name"].GetString(), bgfx::TextureFormat::RGBA8, width, height, prescale_x, prescale_y, mode, double_buffer, bilinear);
}
}
diff --git a/src/osd/modules/render/bgfx/target.cpp b/src/osd/modules/render/bgfx/target.cpp
index a71074f44d0..4b651d3d12c 100644
--- a/src/osd/modules/render/bgfx/target.cpp
+++ b/src/osd/modules/render/bgfx/target.cpp
@@ -8,7 +8,7 @@
#include "target.h"
-bgfx_target::bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t prescale_x, uint32_t prescale_y, uint32_t style, bool double_buffer, bool filter)
+bgfx_target::bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t prescale_x, uint32_t prescale_y, uint32_t style, bool double_buffer, bool filter, bool init)
: m_name(name)
, m_format(format)
, m_targets(nullptr)
@@ -21,17 +21,23 @@ bgfx_target::bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uin
, m_style(style)
, m_filter(filter)
, m_current_page(0)
+ , m_initialized(false)
, m_page_count(double_buffer ? 2 : 1)
{
- uint32_t wrap_mode = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP;
- uint32_t filter_mode = filter ? (BGFX_TEXTURE_MIN_ANISOTROPIC | BGFX_TEXTURE_MAG_ANISOTROPIC) : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT);
-
- m_textures = new bgfx::TextureHandle[m_page_count];
- m_targets = new bgfx::FrameBufferHandle[m_page_count];
- for (int page = 0; page < m_page_count; page++)
+ if (init)
{
- m_textures[page] = bgfx::createTexture2D(width * prescale_x, height * prescale_y, 1, format, wrap_mode | filter_mode | BGFX_TEXTURE_RT);
- m_targets[page] = bgfx::createFrameBuffer(1, &m_textures[page], false);
+ uint32_t wrap_mode = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP;
+ uint32_t filter_mode = filter ? (BGFX_TEXTURE_MIN_ANISOTROPIC | BGFX_TEXTURE_MAG_ANISOTROPIC) : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT);
+
+ m_textures = new bgfx::TextureHandle[m_page_count];
+ m_targets = new bgfx::FrameBufferHandle[m_page_count];
+ for (int page = 0; page < m_page_count; page++)
+ {
+ m_textures[page] = bgfx::createTexture2D(width * prescale_x, height * prescale_y, 1, format, wrap_mode | filter_mode | BGFX_TEXTURE_RT);
+ m_targets[page] = bgfx::createFrameBuffer(1, &m_textures[page], false);
+ }
+
+ m_initialized = true;
}
}
@@ -48,6 +54,7 @@ bgfx_target::bgfx_target(void *handle, uint16_t width, uint16_t height)
, m_style(TARGET_STYLE_CUSTOM)
, m_filter(false)
, m_current_page(0)
+ , m_initialized(true)
, m_page_count(0)
{
m_targets = new bgfx::FrameBufferHandle[1];
@@ -58,6 +65,8 @@ bgfx_target::bgfx_target(void *handle, uint16_t width, uint16_t height)
bgfx_target::~bgfx_target()
{
+ if (!m_initialized) return;
+
if (m_page_count > 0)
{
for (int page = 0; page < m_page_count; page++)
@@ -77,6 +86,8 @@ bgfx_target::~bgfx_target()
void bgfx_target::page_flip()
{
+ if (!m_initialized) return;
+
if (m_double_buffer)
{
m_current_page = 1 - m_current_page;
@@ -85,11 +96,14 @@ void bgfx_target::page_flip()
bgfx::FrameBufferHandle bgfx_target::target()
{
+ if (!m_initialized) return BGFX_INVALID_HANDLE;
return m_targets[m_current_page];
}
bgfx::TextureHandle bgfx_target::texture() const
{
+ if (!m_initialized) return BGFX_INVALID_HANDLE;
+
if (m_double_buffer)
{
return m_textures[1 - m_current_page];
diff --git a/src/osd/modules/render/bgfx/target.h b/src/osd/modules/render/bgfx/target.h
index 9900fc77f8e..9d0481a0c7f 100644
--- a/src/osd/modules/render/bgfx/target.h
+++ b/src/osd/modules/render/bgfx/target.h
@@ -27,7 +27,7 @@ enum
class bgfx_target : public bgfx_texture_handle_provider
{
public:
- bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t prescale_x, uint32_t prescale_y, uint32_t style, bool double_buffer, bool filter);
+ bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t prescale_x, uint32_t prescale_y, uint32_t style, bool double_buffer, bool filter, bool init = true);
bgfx_target(void *handle, uint16_t width, uint16_t height);
virtual ~bgfx_target();
@@ -68,6 +68,8 @@ private:
uint32_t m_current_page;
+ bool m_initialized;
+
const uint32_t m_page_count;
};
diff --git a/src/osd/modules/render/bgfx/targetmanager.cpp b/src/osd/modules/render/bgfx/targetmanager.cpp
index ede2ceefaa3..d726d8592b3 100644
--- a/src/osd/modules/render/bgfx/targetmanager.cpp
+++ b/src/osd/modules/render/bgfx/targetmanager.cpp
@@ -27,7 +27,7 @@ target_manager::~target_manager()
bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, uint32_t prescale_x, uint32_t prescale_y, uint32_t style, bool double_buffer, bool filter)
{
- bgfx_target* target = new bgfx_target(name, format, width, height, prescale_x, prescale_y, style, double_buffer, filter);
+ bgfx_target* target = new bgfx_target(name, format, width, height, prescale_x, prescale_y, style, double_buffer, filter, width > 0 && height > 0);
m_targets[name] = target;
m_textures.add_provider(name, target);
@@ -58,22 +58,28 @@ void target_manager::update_guest_targets(uint16_t width, uint16_t 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)
{
- bgfx_target* target_ptr = target.second;
- std::string name = target_ptr->name();
- const bgfx::TextureFormat::Enum format = target_ptr->format();
- const bool double_buffered = target_ptr->double_buffered();
- const bool filter = target_ptr->filter();
- const uint32_t prescale_x = target_ptr->prescale_x();
- const uint32_t prescale_y = target_ptr->prescale_y();
- delete target_ptr;
-
- target.second = new bgfx_target(name, format, width, height, prescale_x, prescale_y, TARGET_STYLE_GUEST, double_buffered, filter);
- m_textures.add_provider(name, target.second);
+ to_resize.push_back(target.second);
}
}
+
+ for (bgfx_target* target : to_resize)
+ {
+ std::string name = target->name();
+ const bgfx::TextureFormat::Enum format = target->format();
+ const bool double_buffered = target->double_buffered();
+ const bool filter = target->filter();
+ const uint32_t prescale_x = target->prescale_x();
+ const uint32_t prescale_y = target->prescale_y();
+ delete target;
+
+ m_targets[name] = new bgfx_target(name, format, width, height, prescale_x, prescale_y, TARGET_STYLE_GUEST, double_buffered, filter);
+ m_textures.add_provider(name, m_targets[name]);
+ }
}
}
diff --git a/src/osd/modules/render/bgfx/targetmanager.h b/src/osd/modules/render/bgfx/targetmanager.h
index e957c85fee5..3d892f921ed 100644
--- a/src/osd/modules/render/bgfx/targetmanager.h
+++ b/src/osd/modules/render/bgfx/targetmanager.h
@@ -25,7 +25,7 @@ class bgfx_target;
class target_manager {
public:
- target_manager(texture_manager& textures) : m_textures(textures), m_guest_width(16), m_guest_height(16) { }
+ target_manager(texture_manager& textures) : m_textures(textures), m_guest_width(0), m_guest_height(0) { }
~target_manager();
bgfx_target* create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, uint32_t prescale_x, uint32_t prescale_y, uint32_t style, bool double_buffer, bool filter);
diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp
index f5fbf9f3876..f2a909d5773 100644
--- a/src/osd/modules/render/drawbgfx.cpp
+++ b/src/osd/modules/render/drawbgfx.cpp
@@ -132,7 +132,6 @@ int renderer_bgfx::create()
bgfx::sdlSetWindow(window().sdl_window());
#endif
std::string backend(options.bgfx_backend());
- printf("1\n"); fflush(stdout);
if (backend == "auto")
{
bgfx::init();
@@ -822,7 +821,6 @@ int renderer_bgfx::draw(int update)
if (status != BUFFER_EMPTY)
{
- //printf("Drawing with gui effect\n"); fflush(stdout);
bgfx::setVertexBuffer(&buffer);
bgfx::setTexture(0, m_gui_effect[blend]->uniform("s_tex")->handle(), m_texture_cache->texture());
m_gui_effect[blend]->submit(view_index);
@@ -833,7 +831,6 @@ int renderer_bgfx::draw(int update)
prim = prim->next();
}
}
- //printf("Done\n\n\n"); fflush(stdout);
window().m_primlist->release_lock();
@@ -861,7 +858,6 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl
switch ((*prim)->type)
{
case render_primitive::LINE:
- //printf("Putting a line at vertex index %d, vertices now %d\n", vertices, vertices + 30); fflush(stdout);
put_line((*prim)->bounds.x0, (*prim)->bounds.y0, (*prim)->bounds.x1, (*prim)->bounds.y1, 1.0f, u32Color((*prim)->color.r * 255, (*prim)->color.g * 255, (*prim)->color.b * 255, (*prim)->color.a * 255), (ScreenVertex*)buffer->data + vertices, 1.0f);
vertices += 30;
break;
@@ -870,7 +866,6 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl
if ((*prim)->texture.base == nullptr)
{
put_packed_quad(*prim, WHITE_HASH, (ScreenVertex*)buffer->data + vertices);
- //printf("Putting a blank quad at vertex index %d, vertices now %d\n", vertices, vertices + 6); fflush(stdout);
vertices += 6;
}
else
@@ -879,29 +874,23 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl
if (atlas_valid && (*prim)->packable(PACKABLE_SIZE) && hash != 0 && m_hash_to_entry[hash].hash())
{
put_packed_quad(*prim, hash, (ScreenVertex*)buffer->data + vertices);
- //printf("Putting a packable quad at vertex index %d, vertices now %d\n", vertices, vertices + 6); fflush(stdout);
vertices += 6;
}
else
{
if (vertices > 0)
{
- //printf("Pre-flushing buffer\n");
return BUFFER_PRE_FLUSH;
}
if (PRIMFLAG_GET_SCREENTEX((*prim)->flags))
{
- //render_screen_quad(view, *prim);
- //printf("Rendering a screen quad at vertex index %d\n", vertices); fflush(stdout);
render_post_screen_quad(view, *prim, buffer);
}
else
{
- //printf("Rendering an unpackable quad at vertex index %d\n", vertices); fflush(stdout);
render_textured_quad(view, *prim, buffer);
}
- //printf("Ignored %d vertices\n", vertices); fflush(stdout);
return BUFFER_EMPTY;
}
}
@@ -920,7 +909,6 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl
*prim = (*prim)->next();
}
- //printf("Rendered %d vertices\n", vertices); fflush(stdout);
if (*prim == nullptr)
{
return BUFFER_DONE;
@@ -1063,7 +1051,6 @@ bool renderer_bgfx::check_for_dirty_atlas()
void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::TransientVertexBuffer *buffer)
{
int vertices = 0;
- //printf("Allocating buffer\n");
bool mode_switched = false;
while (prim != nullptr && !mode_switched)
{
@@ -1071,7 +1058,6 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
{
case render_primitive::LINE:
vertices += 30;
- //printf("Encountered a line, vertices now %d\n", vertices);
break;
case render_primitive::QUAD:
@@ -1080,25 +1066,12 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
if (prim->texture.base == nullptr)
{
vertices += 6;
- //printf("Encountered a blank quad, vertices now %d\n", vertices);
}
else
{
if (vertices == 0)
{
vertices += 6;
- if (!PRIMFLAG_GET_SCREENTEX(prim->flags))
- {
- //printf("Encountered a screen quad, vertices now %d\n", vertices);
- }
- else
- {
- //printf("Encountered an unpackable quad, vertices now %d\n", vertices);
- }
- }
- else
- {
- //printf("Encountered an unpackable/screen quad with %d vertices left in the buffer, ending loop.\n", vertices);
}
mode_switched = true;
}
@@ -1106,7 +1079,6 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
else
{
vertices += 6;
- //printf("Encountered a packable quad, vertices now %d\n", vertices);
}
break;
default:
@@ -1124,7 +1096,6 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::
if (vertices > 0 && bgfx::checkAvailTransientVertexBuffer(vertices, ScreenVertex::ms_decl))
{
- //printf("Allocating %d transient vertices\n", vertices);
bgfx::allocTransientVertexBuffer(buffer, vertices, ScreenVertex::ms_decl);
}
}