gfx-shader: Fix some crash/problematic locations

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-12-18 07:49:56 +01:00
parent 24edee795a
commit d13778b017

View file

@ -48,6 +48,9 @@ void gfx::shader::shader::load_shader_params()
{ {
_shader_params.clear(); _shader_params.clear();
if (!_shader)
return;
if (gs::effect_technique tech = _shader.get_technique(_shader_tech); tech != nullptr) { if (gs::effect_technique tech = _shader.get_technique(_shader_tech); tech != nullptr) {
for (size_t idx = 0; idx < tech.count_passes(); idx++) { for (size_t idx = 0; idx < tech.count_passes(); idx++) {
auto pass = tech.get_pass(idx); auto pass = tech.get_pass(idx);
@ -159,7 +162,7 @@ bool gfx::shader::shader::on_shader_changed(obs_properties_t* props, obs_propert
if (!have_tech && (_shader.count_techniques() > 0)) { if (!have_tech && (_shader.count_techniques() > 0)) {
obs_data_set_string(data, ST_SHADER_TECHNIQUE, _shader.get_technique(0).name().c_str()); obs_data_set_string(data, ST_SHADER_TECHNIQUE, _shader.get_technique(0).name().c_str());
//on_technique_changed(props, prop, data); //on_technique_changed(props, prop, data);
} else { } else if (_shader.count_techniques() == 0) {
obs_data_set_string(data, ST_SHADER_TECHNIQUE, ""); obs_data_set_string(data, ST_SHADER_TECHNIQUE, "");
} }
} }
@ -171,11 +174,13 @@ bool gfx::shader::shader::on_technique_changed(obs_properties_t* props, obs_prop
{ {
// Clear parameter options. // Clear parameter options.
auto grp = obs_property_group_content(obs_properties_get(props, ST_PARAMETERS)); auto grp = obs_property_group_content(obs_properties_get(props, ST_PARAMETERS));
if (auto p = obs_properties_first(grp); p != nullptr) { while (true) {
do { if (auto p = obs_properties_first(grp); p != nullptr) {
obs_properties_remove_by_name(grp, obs_property_name(p)); std::string name = obs_property_name(p) ? obs_property_name(p) : "";
p = obs_properties_first(grp); obs_properties_remove_by_name(grp, name.c_str());
} while (p != nullptr); } else {
break;
}
} }
// Don't go further if there is no shader. // Don't go further if there is no shader.
@ -188,6 +193,7 @@ bool gfx::shader::shader::on_technique_changed(obs_properties_t* props, obs_prop
// Rebuild new parameters. // Rebuild new parameters.
for (auto kv : _shader_params) { for (auto kv : _shader_params) {
kv.second->properties(grp, data); kv.second->properties(grp, data);
kv.second->update(data);
} }
return true; return true;
@ -319,22 +325,6 @@ bool gfx::shader::shader::tick(float_t time)
// Update State // Update State
_time += time; _time += time;
// Update Shader
if (_shader) {
if (gs::effect_parameter el = _shader.get_parameter("Time"); el != nullptr) {
if (el.get_type() == gs::effect_parameter::type::Float4) {
el.set_float4(
_time, time, 0,
static_cast<float_t>(static_cast<double_t>(_random())
/ static_cast<double_t>(std::numeric_limits<unsigned long long>::max())));
}
}
for (auto kv : _shader_params) {
kv.second->assign();
}
}
return false; return false;
} }
@ -346,6 +336,19 @@ void gfx::shader::shader::render()
uint32_t szw = width(); uint32_t szw = width();
uint32_t szh = height(); uint32_t szh = height();
for (auto kv : _shader_params) {
kv.second->assign();
}
if (gs::effect_parameter el = _shader.get_parameter("Time"); el != nullptr) {
if (el.get_type() == gs::effect_parameter::type::Float4) {
el.set_float4(
_time, 0, 0,
static_cast<float_t>(static_cast<double_t>(_random())
/ static_cast<double_t>(std::numeric_limits<unsigned long long>::max())));
}
}
while (gs_effect_loop(_shader.get_object(), _shader_tech.c_str())) { while (gs_effect_loop(_shader.get_object(), _shader_tech.c_str())) {
gs_draw_sprite(nullptr, 0, szw, szh); gs_draw_sprite(nullptr, 0, szw, szh);
} }