diff options
author | Mark Janes <mark.a.janes@intel.com> | 2017-10-25 16:06:07 -0700 |
---|---|---|
committer | Mark Janes <mark.a.janes@intel.com> | 2017-11-27 11:29:18 -0800 |
commit | 1fb3f1973c0f3380ac8a942425fee02498005967 (patch) | |
tree | 842868a64677618c6363f5ce660f18ca1c628f68 /retrace | |
parent | 696c1701df1c4c34eea9280767a77dd9185ae0f0 (diff) |
State: Support glBlendColor
Diffstat (limited to 'retrace')
-rw-r--r-- | retrace/daemon/glframe_retrace.cpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_context.cpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_context.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_interface.hpp | 4 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_render.cpp | 167 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_render.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_skeleton.cpp | 12 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_skeleton.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_stub.cpp | 16 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_stub.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_state_enums.cpp | 4 | ||||
-rw-r--r-- | retrace/daemon/playback.proto | 4 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_metrics_model.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_retrace_model.cpp | 2 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_retrace_model.hpp | 2 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_state_model.cpp | 50 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_state_model.hpp | 15 | ||||
-rw-r--r-- | retrace/daemon/ui/qml/StateControl.qml | 18 |
19 files changed, 233 insertions, 77 deletions
diff --git a/retrace/daemon/glframe_retrace.cpp b/retrace/daemon/glframe_retrace.cpp index 23a71adc..f937a64c 100644 --- a/retrace/daemon/glframe_retrace.cpp +++ b/retrace/daemon/glframe_retrace.cpp @@ -399,7 +399,7 @@ FrameRetrace::retraceState(const RenderSelection &selection, void FrameRetrace::setState(const RenderSelection &selection, const StateKey &item, - const std::string &value) { + const std::vector<std::string> &value) { // reset to beginning of frame parser->setBookmark(frame_start.start); for (auto i : m_contexts) diff --git a/retrace/daemon/glframe_retrace.hpp b/retrace/daemon/glframe_retrace.hpp index fc1e9d68..2b697cc3 100644 --- a/retrace/daemon/glframe_retrace.hpp +++ b/retrace/daemon/glframe_retrace.hpp @@ -118,7 +118,7 @@ class FrameRetrace : public IFrameRetrace { OnFrameRetrace *callback); void setState(const RenderSelection &selection, const StateKey &item, - const std::string &value); + const std::vector<std::string> &value); private: // these are global diff --git a/retrace/daemon/glframe_retrace_context.cpp b/retrace/daemon/glframe_retrace_context.cpp index bcfbf03b..d1dba4fe 100644 --- a/retrace/daemon/glframe_retrace_context.cpp +++ b/retrace/daemon/glframe_retrace_context.cpp @@ -505,7 +505,7 @@ RetraceContext::retraceState(const RenderSelection &selection, void RetraceContext::setState(const RenderSelection &selection, const StateKey &item, - const std::string &value) { + const std::vector<std::string> &value) { for (auto r : m_renders) { if (isSelected(r.first, selection)) r.second->setState(item, value); diff --git a/retrace/daemon/glframe_retrace_context.hpp b/retrace/daemon/glframe_retrace_context.hpp index e991677e..3f8615c6 100644 --- a/retrace/daemon/glframe_retrace_context.hpp +++ b/retrace/daemon/glframe_retrace_context.hpp @@ -112,7 +112,7 @@ class RetraceContext { OnFrameRetrace *callback); void setState(const RenderSelection &selection, const StateKey &item, - const std::string &value); + const std::vector<std::string> &value); private: trace::AbstractParser *m_parser; diff --git a/retrace/daemon/glframe_retrace_interface.hpp b/retrace/daemon/glframe_retrace_interface.hpp index 5b1fba45..5ef807e9 100644 --- a/retrace/daemon/glframe_retrace_interface.hpp +++ b/retrace/daemon/glframe_retrace_interface.hpp @@ -331,7 +331,7 @@ class OnFrameRetrace { ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value) = 0; + const std::vector<std::string> &value) = 0; }; // Serializable asynchronous retrace requests. @@ -392,7 +392,7 @@ class IFrameRetrace { OnFrameRetrace *callback) = 0; virtual void setState(const RenderSelection &selection, const StateKey &item, - const std::string &value) = 0; + const std::vector<std::string> &value) = 0; }; class FrameState { diff --git a/retrace/daemon/glframe_retrace_render.cpp b/retrace/daemon/glframe_retrace_render.cpp index 0b65508e..cfa6aa24 100644 --- a/retrace/daemon/glframe_retrace_render.cpp +++ b/retrace/daemon/glframe_retrace_render.cpp @@ -154,9 +154,9 @@ class RetraceRender::StateOverride { public: StateOverride() {} void setState(const StateKey &item, - const std::string &value) { - m_overrides[item] = state_name_to_enum(value); - } + const std::vector<float> &value); + void setState(const StateKey &item, + GLint value); void saveState(); void overrideState() const; void restoreState() const; @@ -174,13 +174,82 @@ class RetraceRender::StateOverride { return offset < o.offset; } }; - typedef std::map<StateKey, uint32_t> KeyMap; + enum Type { + kUnknown, + kBool, + kFloat, + kEnum + }; + + typedef std::map<StateKey, std::vector<uint32_t>> KeyMap; void enact_state(const KeyMap &m) const; + void enact_enabled_state(const StateKey &k, + const std::vector<uint32_t> &v, + GLint setting) const; + void enact_int_state(const StateKey &k, const std::vector<uint32_t> &v) const; + void save_enabled_state(const StateKey &k, GLint v); + void save_int_state(const StateKey &k, GLint v); KeyMap m_overrides; KeyMap m_saved_state; + std::map<StateKey, Type> m_data_types; }; void +RetraceRender::StateOverride::setState(const StateKey &item, + GLint value) { + auto &i = m_overrides[item]; + if (i.empty()) { + i.push_back(value); + return; + } + assert(i.size() == 1); + i[0] = value; +} + +void +RetraceRender::StateOverride::setState(const StateKey &item, + const std::vector<float> &value) { + m_data_types[item] = kFloat; + auto &i = m_overrides[item]; + if (i.empty()) + i.resize(value.size()); + assert(i.size() == value.size()); + + union { + uint32_t i; + float f; + } u; + for (int j = 0; j < value.size(); ++j) { + u.f = value[j]; + i[j] = u.i; + } +} + +void +RetraceRender::StateOverride::save_enabled_state(const StateKey &k, GLint v) { + if (m_data_types[k] == kUnknown) + m_data_types[k] = kBool; + assert(m_data_types[k] == kBool); + assert(GL::GetError() == GL_NO_ERROR); + assert(m_saved_state[k].empty()); + m_saved_state[k].push_back(static_cast<uint32_t>(GlFunctions::IsEnabled(v))); + assert(GL::GetError() == GL_NO_ERROR); +} + +void +RetraceRender::StateOverride::save_int_state(const StateKey &k, GLint v) { + if (m_data_types[k] == kUnknown) + m_data_types[k] = kEnum; + assert(m_data_types[k] == kEnum); + assert(GL::GetError() == GL_NO_ERROR); + assert(m_saved_state[k].empty()); + GLint data; + GlFunctions::GetIntegerv(v, &data); + assert(GL::GetError() == GL_NO_ERROR); + m_saved_state[k].push_back(static_cast<uint32_t>(data)); +} + +void RetraceRender::StateOverride::saveState() { for (auto i : m_overrides) { if (m_saved_state.find(i.first) != m_saved_state.end()) @@ -188,34 +257,21 @@ RetraceRender::StateOverride::saveState() { continue; switch (glretrace::state_name_to_enum(i.first.name)) { case GL_CULL_FACE: - assert(GL::GetError() == GL_NO_ERROR); - m_saved_state[i.first] = GlFunctions::IsEnabled(GL_CULL_FACE); - assert(GL::GetError() == GL_NO_ERROR); + save_enabled_state(i.first, GL_CULL_FACE); break; case GL_CULL_FACE_MODE: { - assert(GL::GetError() == GL_NO_ERROR); - GLint cull; - GlFunctions::GetIntegerv(GL_CULL_FACE_MODE, &cull); - assert(GL::GetError() == GL_NO_ERROR); - m_saved_state[i.first] = cull; + save_int_state(i.first, GL_CULL_FACE_MODE); break; } case GL_BLEND: - m_saved_state[i.first] = GlFunctions::IsEnabled(GL_BLEND); - assert(GL::GetError() == GL_NO_ERROR); + save_enabled_state(i.first, GL_BLEND); break; case GL_BLEND_SRC: { - GLint s; - GlFunctions::GetIntegerv(GL_BLEND_SRC, &s); - assert(GL::GetError() == GL_NO_ERROR); - m_saved_state[i.first] = s; + save_int_state(i.first, GL_BLEND_SRC); break; } case GL_BLEND_DST: { - GLint s; - GlFunctions::GetIntegerv(GL_BLEND_DST, &s); - assert(GL::GetError() == GL_NO_ERROR); - m_saved_state[i.first] = s; + save_int_state(i.first, GL_BLEND_DST); break; } case GL_INVALID_ENUM: @@ -237,36 +293,42 @@ RetraceRender::StateOverride::restoreState() const { } void +RetraceRender::StateOverride::enact_enabled_state( + const StateKey &k, + const std::vector<uint32_t> &v, + GLint setting) const { + assert(m_data_types.find(k)->second == kBool); + assert(v.size() == 1); + if (v[0]) + GlFunctions::Enable(setting); + else + GlFunctions::Disable(setting); + assert(GL::GetError() == GL_NO_ERROR); +} + +void RetraceRender::StateOverride::enact_state(const KeyMap &m) const { GL::GetError(); for (auto i : m) { switch (glretrace::state_name_to_enum(i.first.name)) { case GL_CULL_FACE: { - if (i.second) - GlFunctions::Enable(GL_CULL_FACE); - else - GlFunctions::Disable(GL_CULL_FACE); - assert(GL::GetError() == GL_NO_ERROR); + enact_enabled_state(i.first, i.second, GL_CULL_FACE); break; } case GL_CULL_FACE_MODE: { - GlFunctions::CullFace(i.second); + GlFunctions::CullFace(i.second[0]); assert(GL::GetError() == GL_NO_ERROR); break; } case GL_BLEND: { - if (i.second) - GlFunctions::Enable(GL_BLEND); - else - GlFunctions::Disable(GL_BLEND); - assert(GL::GetError() == GL_NO_ERROR); + enact_enabled_state(i.first, i.second, GL_BLEND); break; } case GL_BLEND_SRC: { GLint dst; GlFunctions::GetIntegerv(GL_BLEND_DST, &dst); assert(GL::GetError() == GL_NO_ERROR); - GlFunctions::BlendFunc(i.second, dst); + GlFunctions::BlendFunc(i.second[0], dst); assert(GL::GetError() == GL_NO_ERROR); break; } @@ -274,7 +336,7 @@ RetraceRender::StateOverride::enact_state(const KeyMap &m) const { GLint src; GlFunctions::GetIntegerv(GL_BLEND_DST, &src); assert(GL::GetError() == GL_NO_ERROR); - GlFunctions::BlendFunc(src, i.second); + GlFunctions::BlendFunc(src, i.second[0]); assert(GL::GetError() == GL_NO_ERROR); break; } @@ -592,7 +654,7 @@ RetraceRender::onState(SelectionId selId, if (e == GL_NO_ERROR) { callback->onState(selId, experimentCount, renderId, StateKey("Rendering", "Cull State", "GL_CULL_FACE"), - cull_enabled ? "true" : "false"); + {cull_enabled ? "true" : "false"}); } } { @@ -604,7 +666,7 @@ RetraceRender::onState(SelectionId selId, if (cull_str.size() > 0) { callback->onState(selId, experimentCount, renderId, StateKey("Rendering", "Cull State", - "GL_CULL_FACE_MODE"), cull_str); + "GL_CULL_FACE_MODE"), {cull_str}); } } } @@ -615,7 +677,7 @@ RetraceRender::onState(SelectionId selId, if (e == GL_NO_ERROR) { callback->onState(selId, experimentCount, renderId, StateKey("Rendering", "Blend State", "GL_BLEND"), - enabled ? "true" : "false"); + {enabled ? "true" : "false"}); } } { @@ -627,7 +689,7 @@ RetraceRender::onState(SelectionId selId, if (state_str.size() > 0) { callback->onState(selId, experimentCount, renderId, StateKey("Rendering", "Blend State", - "GL_BLEND_SRC"), state_str); + "GL_BLEND_SRC"), {state_str}); } } } @@ -640,14 +702,35 @@ RetraceRender::onState(SelectionId selId, if (state_str.size() > 0) { callback->onState(selId, experimentCount, renderId, StateKey("Rendering", "Blend State", - "GL_BLEND_DST"), state_str); + "GL_BLEND_DST"), {state_str}); } } } + { + GLfloat s[4]; + GlFunctions::GetFloatv(GL_BLEND_COLOR, s); + GLenum e = GL::GetError(); + if (e == GL_NO_ERROR) { + std::vector<std::string> color; + color.push_back(std::to_string(s[0])); + color.push_back(std::to_string(s[1])); + color.push_back(std::to_string(s[2])); + color.push_back(std::to_string(s[3])); + callback->onState(selId, experimentCount, renderId, + StateKey("Rendering", "Blend State", + "GL_BLEND_COLOR"), color); + } + } } void RetraceRender::setState(const StateKey &item, - const std::string &value) { - m_state_override->setState(item, value); + const std::vector<std::string> &value) { + uint32_t e = state_name_to_enum(value[0]); + if (e != GL_INVALID_ENUM) + return m_state_override->setState(item, e); + std::vector<float> d; + for (auto i : value) + d.push_back(std::stof(i)); + m_state_override->setState(item, d); } diff --git a/retrace/daemon/glframe_retrace_render.hpp b/retrace/daemon/glframe_retrace_render.hpp index 70d7a8a1..ed9e49bc 100644 --- a/retrace/daemon/glframe_retrace_render.hpp +++ b/retrace/daemon/glframe_retrace_render.hpp @@ -90,7 +90,7 @@ class RetraceRender { void setUniform(const std::string &name, int index, const std::string &data); void setState(const StateKey &item, - const std::string &value); + const std::vector<std::string> &value); static bool isRender(const trace::Call &c); static bool changesContext(const trace::Call &c); diff --git a/retrace/daemon/glframe_retrace_skeleton.cpp b/retrace/daemon/glframe_retrace_skeleton.cpp index 4b3ae135..b4edeabf 100644 --- a/retrace/daemon/glframe_retrace_skeleton.cpp +++ b/retrace/daemon/glframe_retrace_skeleton.cpp @@ -400,7 +400,7 @@ FrameRetraceSkeleton::Run() { state_resp->set_selection_count(-1); state_resp->set_render_id(-1); state_resp->set_experiment_count(-1); - state_resp->set_value(""); + state_resp->add_value(""); auto r_item = state_resp->mutable_item(); r_item->set_group(""); r_item->set_path(""); @@ -418,7 +418,10 @@ FrameRetraceSkeleton::Run() { glretrace::StateKey k(item.group(), item.path(), item.name()); - m_frame->setState(selection, k, state.value()); + std::vector<std::string> value; + for (auto v : state.value()) + value.push_back(v); + m_frame->setState(selection, k, value); break; } } @@ -644,7 +647,7 @@ FrameRetraceSkeleton::onState(SelectionId selectionCount, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value) { + const std::vector<std::string> &value) { RetraceResponse proto_response; auto response = proto_response.mutable_state(); response->set_render_id(renderId()); @@ -654,6 +657,7 @@ FrameRetraceSkeleton::onState(SelectionId selectionCount, r_item->set_group(item.group); r_item->set_path(item.path); r_item->set_name(item.name); - response->set_value(value); + for (auto i : value) + response->add_value(i); writeResponse(m_socket, proto_response, &m_buf); } diff --git a/retrace/daemon/glframe_retrace_skeleton.hpp b/retrace/daemon/glframe_retrace_skeleton.hpp index 5f5cfe62..73c7aac8 100644 --- a/retrace/daemon/glframe_retrace_skeleton.hpp +++ b/retrace/daemon/glframe_retrace_skeleton.hpp @@ -100,7 +100,7 @@ class FrameRetraceSkeleton : public Thread, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value); + const std::vector<std::string> &value); protected: bool m_force_upload; // for unit test diff --git a/retrace/daemon/glframe_retrace_stub.cpp b/retrace/daemon/glframe_retrace_stub.cpp index 1bddfcde..cd973893 100644 --- a/retrace/daemon/glframe_retrace_stub.cpp +++ b/retrace/daemon/glframe_retrace_stub.cpp @@ -978,7 +978,7 @@ class StateRequest : public IRetraceRequest { m_callback->onState(SelectionId(SelectionId::INVALID_SELECTION), ExperimentId(ExperimentId::INVALID_EXPERIMENT-1), RenderId(RenderId::INVALID_RENDER), - glretrace::StateKey(), ""); + glretrace::StateKey(), std::vector<std::string>()); break; } @@ -1001,8 +1001,11 @@ class StateRequest : public IRetraceRequest { const RenderId rid(state_response.render_id()); auto &item = state_response.item(); glretrace::StateKey k(item.group(), item.path(), item.name()); + std::vector<std::string> value; + for (auto v : state_response.value()) + value.push_back(v); m_callback->onState(selection, experiment, rid, - k, state_response.value()); + k, value); } } @@ -1018,7 +1021,7 @@ class SetStateRequest : public IRetraceRequest { public: SetStateRequest(const RenderSelection &selection, StateKey item, - const std::string &value) + const std::vector<std::string> &value) : m_selection(selection), m_item(item), m_value(value) {} @@ -1032,14 +1035,15 @@ class SetStateRequest : public IRetraceRequest { item->set_name(m_item.name); auto selection = req->mutable_selection(); makeRenderSelection(m_selection, selection); - req->set_value(m_value); + for (auto v : m_value) + req->add_value(v); sock->request(msg); } private: const RenderSelection m_selection; const StateKey m_item; - const std::string m_value; + const std::vector<std::string> m_value; }; class NullRequest : public IRetraceRequest { @@ -1322,6 +1326,6 @@ FrameRetraceStub::retraceState(const RenderSelection &selection, void FrameRetraceStub::setState(const RenderSelection &selection, const StateKey &item, - const std::string &value) { + const std::vector<std::string> &value) { m_thread->push(new SetStateRequest(selection, item, value)); } diff --git a/retrace/daemon/glframe_retrace_stub.hpp b/retrace/daemon/glframe_retrace_stub.hpp index 1c7b9c26..5fd5201d 100644 --- a/retrace/daemon/glframe_retrace_stub.hpp +++ b/retrace/daemon/glframe_retrace_stub.hpp @@ -98,7 +98,7 @@ class FrameRetraceStub : public IFrameRetrace { OnFrameRetrace *callback); virtual void setState(const RenderSelection &selection, const StateKey &item, - const std::string &value); + const std::vector<std::string> &value); private: mutable std::mutex m_mutex; diff --git a/retrace/daemon/glframe_state_enums.cpp b/retrace/daemon/glframe_state_enums.cpp index 59719d05..1ec9428a 100644 --- a/retrace/daemon/glframe_state_enums.cpp +++ b/retrace/daemon/glframe_state_enums.cpp @@ -57,6 +57,7 @@ glretrace::state_name_to_enum(const std::string &value) { {"GL_ONE_MINUS_CONSTANT_COLOR", GL_ONE_MINUS_CONSTANT_COLOR}, {"GL_CONSTANT_ALPHA", GL_CONSTANT_ALPHA}, {"GL_ONE_MINUS_CONSTANT_ALPHA", GL_ONE_MINUS_CONSTANT_ALPHA}, + {"GL_BLEND_COLOR", GL_BLEND_COLOR}, {"true", 1}, {"false", 0} }; @@ -144,8 +145,9 @@ glretrace::state_name_to_choices(const std::string &n) { "GL_CONSTANT_ALPHA", "GL_ONE_MINUS_CONSTANT_ALPHA"}; case GL_INVALID_ENUM: - default: assert(false); + default: + return {}; } } diff --git a/retrace/daemon/playback.proto b/retrace/daemon/playback.proto index 503831b7..2460eddb 100644 --- a/retrace/daemon/playback.proto +++ b/retrace/daemon/playback.proto @@ -242,13 +242,13 @@ message StateResponse { required uint32 render_id = 2; required uint32 experiment_count = 3; required StateKey item = 4; - required string value = 5; + repeated string value = 5; } message SetStateRequest { required RenderSelection selection = 1; required StateKey item = 2; - required string value = 3; + repeated string value = 3; } message RetraceRequest { diff --git a/retrace/daemon/ui/glframe_metrics_model.hpp b/retrace/daemon/ui/glframe_metrics_model.hpp index f3078d86..9264e1be 100644 --- a/retrace/daemon/ui/glframe_metrics_model.hpp +++ b/retrace/daemon/ui/glframe_metrics_model.hpp @@ -135,7 +135,7 @@ class QMetricsModel : public QObject, OnFrameRetrace, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value) { assert(false); } + const std::vector<std::string> &value) { assert(false); } void filter(const QString& f); diff --git a/retrace/daemon/ui/glframe_retrace_model.cpp b/retrace/daemon/ui/glframe_retrace_model.cpp index 70288111..ce0ca4ab 100644 --- a/retrace/daemon/ui/glframe_retrace_model.cpp +++ b/retrace/daemon/ui/glframe_retrace_model.cpp @@ -629,7 +629,7 @@ FrameRetraceModel::onState(SelectionId selectionCount, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value) { + const std::vector<std::string> &value) { m_stateModel->onState(selectionCount, experimentCount, renderId, item, value); } diff --git a/retrace/daemon/ui/glframe_retrace_model.hpp b/retrace/daemon/ui/glframe_retrace_model.hpp index 3908d55c..7bab4d58 100644 --- a/retrace/daemon/ui/glframe_retrace_model.hpp +++ b/retrace/daemon/ui/glframe_retrace_model.hpp @@ -187,7 +187,7 @@ class FrameRetraceModel : public QObject, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value); + const std::vector<std::string> &value); int frameCount() const { ScopedLock s(m_protect); return m_frame_count; } float maxMetric() const { ScopedLock s(m_protect); return m_max_metric; } diff --git a/retrace/daemon/ui/glframe_state_model.cpp b/retrace/daemon/ui/glframe_state_model.cpp index e94ce39f..2b357f1a 100644 --- a/retrace/daemon/ui/glframe_state_model.cpp +++ b/retrace/daemon/ui/glframe_state_model.cpp @@ -57,17 +57,20 @@ QStateValue::QStateValue(QObject *parent, m_path(_path.c_str()), m_name(_name.c_str()), m_value(kUninitializedValue), - m_visible(true) { + m_visible(true), + m_type(QStateValue::KglDirectory) { moveToThread(parent->thread()); for (auto c : _choices) m_choices.append(QVariant(c.c_str())); - m_indent = static_cast<int>(std::count(_path.begin(), _path.end(), '/')); + m_indent = static_cast<int>(std::count(_path.begin(), _path.end(), '/')) + + _name.length() > 0; if (_name.length() == 0) m_name = _path.substr(_path.find_last_of("/") + 1).c_str(); } void QStateValue::insert(const std::string &value) { + m_type = QStateValue::KglEnum; int value_index = 0; QVariant qvalue(value.c_str()); for (auto c : m_choices) { @@ -79,7 +82,7 @@ QStateValue::insert(const std::string &value) { assert(value_index < m_choices.size()); if (m_value == kUninitializedValue) { - // selected renders have different values + // first render, display the value m_value = value_index; return; } @@ -89,6 +92,32 @@ QStateValue::insert(const std::string &value) { m_value = kMixedValue; } +void +QStateValue::insert(const std::string &red, + const std::string &blue, + const std::string &green, + const std::string &alpha) { + m_type = QStateValue::KglColor; + QStringList color; + color.append(QString::fromStdString(red)); + color.append(QString::fromStdString(blue)); + color.append(QString::fromStdString(green)); + color.append(QString::fromStdString(alpha)); + + if (m_value == kUninitializedValue) { + // selected renders have different values + m_value = color; + return; + } + + if (m_value != color) { + // selected renders have different values + for (auto c : color) + c = "###"; + m_value = color; + } +} + QStateModel::QStateModel() {} QStateModel::QStateModel(IFrameRetrace *retrace) : m_retrace(retrace) {} @@ -130,7 +159,7 @@ void QStateModel::onState(SelectionId selectionCount, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value) { + const std::vector<std::string> &value) { if (selectionCount == SelectionId(SelectionId::INVALID_SELECTION)) { refresh(); return; @@ -182,7 +211,16 @@ void QStateModel::onState(SelectionId selectionCount, state_value = m_state_by_name.find(item); m_for_deletion.push_back(i); } - state_value->second->insert(value); + if (value.size() == 1) { + state_value->second->insert(value[0]); + return; + } + if (value.size() == 4) { + // color value + state_value->second->insert(value[0], value[1], value[2], value[3]); + return; + } + assert(false); } void @@ -204,7 +242,7 @@ QStateModel::setState(const QString &group, } StateKey key(group.toStdString(), path.toStdString(), name.toStdString()); - m_retrace->setState(sel, key, value.toStdString()); + m_retrace->setState(sel, key, {value.toStdString()}); emit stateExperiment(); } diff --git a/retrace/daemon/ui/glframe_state_model.hpp b/retrace/daemon/ui/glframe_state_model.hpp index a08fd440..5207e8dd 100644 --- a/retrace/daemon/ui/glframe_state_model.hpp +++ b/retrace/daemon/ui/glframe_state_model.hpp @@ -52,6 +52,7 @@ class QStateValue : public QObject, NoCopy, NoAssign, NoMove { Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QVariant value READ value CONSTANT) Q_PROPERTY(QVariant indent READ indent CONSTANT) + Q_PROPERTY(QStateType valueType READ valueType CONSTANT) Q_PROPERTY(QVariant visible READ visible WRITE setVisible @@ -59,6 +60,14 @@ class QStateValue : public QObject, NoCopy, NoAssign, NoMove { Q_PROPERTY(QList<QVariant> choices READ choices CONSTANT) public: + enum QStateType { + KglDirectory, + KglEnum, + KglFloat, + KglColor + }; + Q_ENUMS(QStateType); + explicit QStateValue(QObject *parent = 0); QStateValue(QObject *parent, const std::string &_group, @@ -66,10 +75,13 @@ class QStateValue : public QObject, NoCopy, NoAssign, NoMove { const std::string &_name, const std::vector<std::string> &_choices); void insert(const std::string &value); + void insert(const std::string &red, const std::string &blue, + const std::string &green, const std::string &alpha); QString group() const { return m_group; } QString path() const { return m_path; } QString name() const { return m_name; } + QStateType valueType() const { return m_type; } QVariant value() const { return m_value; } QVariant indent() const { return m_indent; } QVariant visible() const { return m_visible; } @@ -82,6 +94,7 @@ class QStateValue : public QObject, NoCopy, NoAssign, NoMove { private: QString m_group, m_path, m_name; QVariant m_value, m_indent, m_visible; + QStateType m_type; QList<QVariant> m_choices; }; @@ -99,7 +112,7 @@ class QStateModel : public QObject, ExperimentId experimentCount, RenderId renderId, StateKey item, - const std::string &value); + const std::vector<std::string> &value); void clear(); Q_INVOKABLE void setState(const QString &group, const QString &path, diff --git a/retrace/daemon/ui/qml/StateControl.qml b/retrace/daemon/ui/qml/StateControl.qml index c0673b29..205e1c6f 100644 --- a/retrace/daemon/ui/qml/StateControl.qml +++ b/retrace/daemon/ui/qml/StateControl.qml @@ -27,7 +27,7 @@ Item { anchors.bottom: nameText.bottom width: nameText.height height: nameText.height - visible: modelData.choices.length == 0 + visible: (modelData.valueType == QStateValue.KglDirectory) property var collapsed: false color: collapse.collapsed ? "red" : "green" MouseArea { @@ -50,12 +50,24 @@ Item { anchors.verticalCenter: parent.verticalCenter text: modelData.name + " : " } + Row { + visible: (modelData.valueType == QStateValue.KglColor) + Text{ + text: "Color: " + } + Repeater{ + model: modelData.value + Text{ + text: modelData + } + } + } ComboBoxFitContents { id: combo anchors.verticalCenter: parent.verticalCenter model: modelData.choices - currentIndex: modelData.value - visible: (modelData.choices.length > 0) + currentIndex: (modelData.valueType == QStateValue.KglEnum ? modelData.value : 0) + visible: (modelData.valueType == QStateValue.KglEnum) onActivated: { stateModel.setState(modelData.group, modelData.path, |