diff options
author | Mark Janes <mark.a.janes@intel.com> | 2017-10-27 15:45:21 -0700 |
---|---|---|
committer | Mark Janes <mark.a.janes@intel.com> | 2017-11-27 11:29:20 -0800 |
commit | e6eb6e2bff3110e4c09852967f482d25599391c5 (patch) | |
tree | ec7df4d1892e504636e610292eeea933935f1290 /retrace | |
parent | 1fb3f1973c0f3380ac8a942425fee02498005967 (diff) |
State: Allow color state to be edited
Diffstat (limited to 'retrace')
-rw-r--r-- | retrace/daemon/CMakeLists.txt | 2 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace.cpp | 5 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace.hpp | 3 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_context.cpp | 7 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_context.hpp | 4 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_interface.hpp | 3 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_render.cpp | 288 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_render.hpp | 5 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_skeleton.cpp | 5 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_stub.cpp | 16 | ||||
-rw-r--r-- | retrace/daemon/glframe_retrace_stub.hpp | 3 | ||||
-rw-r--r-- | retrace/daemon/glframe_state_override.cpp | 252 | ||||
-rw-r--r-- | retrace/daemon/glframe_state_override.hpp | 82 | ||||
-rw-r--r-- | retrace/daemon/playback.proto | 3 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_state_model.cpp | 4 | ||||
-rw-r--r-- | retrace/daemon/ui/glframe_state_model.hpp | 1 | ||||
-rw-r--r-- | retrace/daemon/ui/qml/StateControl.qml | 78 |
17 files changed, 455 insertions, 306 deletions
diff --git a/retrace/daemon/CMakeLists.txt b/retrace/daemon/CMakeLists.txt index bd86fde7..1a6436cd 100644 --- a/retrace/daemon/CMakeLists.txt +++ b/retrace/daemon/CMakeLists.txt @@ -75,6 +75,8 @@ set (RETRACE_SOURCES glframe_state.hpp glframe_state_enums.cpp glframe_state_enums.hpp + glframe_state_override.cpp + glframe_state_override.hpp glframe_stderr.hpp glframe_thread.hpp glframe_traits.hpp diff --git a/retrace/daemon/glframe_retrace.cpp b/retrace/daemon/glframe_retrace.cpp index f937a64c..787fe318 100644 --- a/retrace/daemon/glframe_retrace.cpp +++ b/retrace/daemon/glframe_retrace.cpp @@ -399,9 +399,10 @@ FrameRetrace::retraceState(const RenderSelection &selection, void FrameRetrace::setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value) { + int offset, + const std::string &value) { // reset to beginning of frame parser->setBookmark(frame_start.start); for (auto i : m_contexts) - i->setState(selection, item, value); + i->setState(selection, item, offset, value, m_tracker); } diff --git a/retrace/daemon/glframe_retrace.hpp b/retrace/daemon/glframe_retrace.hpp index 2b697cc3..20cfdf10 100644 --- a/retrace/daemon/glframe_retrace.hpp +++ b/retrace/daemon/glframe_retrace.hpp @@ -118,7 +118,8 @@ class FrameRetrace : public IFrameRetrace { OnFrameRetrace *callback); void setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value); + int offset, + const std::string &value); private: // these are global diff --git a/retrace/daemon/glframe_retrace_context.cpp b/retrace/daemon/glframe_retrace_context.cpp index d1dba4fe..09bcca6e 100644 --- a/retrace/daemon/glframe_retrace_context.cpp +++ b/retrace/daemon/glframe_retrace_context.cpp @@ -505,9 +505,12 @@ RetraceContext::retraceState(const RenderSelection &selection, void RetraceContext::setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value) { + int offset, + const std::string &value, + const StateTrack &tracker) { for (auto r : m_renders) { + r.second->retrace(tracker); if (isSelected(r.first, selection)) - r.second->setState(item, value); + r.second->setState(item, offset, value); } } diff --git a/retrace/daemon/glframe_retrace_context.hpp b/retrace/daemon/glframe_retrace_context.hpp index 3f8615c6..311c9d0d 100644 --- a/retrace/daemon/glframe_retrace_context.hpp +++ b/retrace/daemon/glframe_retrace_context.hpp @@ -112,7 +112,9 @@ class RetraceContext { OnFrameRetrace *callback); void setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value); + int offset, + const std::string &value, + const StateTrack &tracker); private: trace::AbstractParser *m_parser; diff --git a/retrace/daemon/glframe_retrace_interface.hpp b/retrace/daemon/glframe_retrace_interface.hpp index 5ef807e9..e6950de3 100644 --- a/retrace/daemon/glframe_retrace_interface.hpp +++ b/retrace/daemon/glframe_retrace_interface.hpp @@ -392,7 +392,8 @@ class IFrameRetrace { OnFrameRetrace *callback) = 0; virtual void setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value) = 0; + int offset, + const std::string &value) = 0; }; class FrameState { diff --git a/retrace/daemon/glframe_retrace_render.cpp b/retrace/daemon/glframe_retrace_render.cpp index cfa6aa24..429bcf2f 100644 --- a/retrace/daemon/glframe_retrace_render.cpp +++ b/retrace/daemon/glframe_retrace_render.cpp @@ -41,6 +41,7 @@ #include "retrace.hpp" #include "glstate_internal.hpp" #include "trace_parser.hpp" +#include "glframe_state_override.hpp" using glretrace::DEBUG; using glretrace::GlFunctions; @@ -150,203 +151,7 @@ class RetraceRender::UniformOverride { std::map<UniformKey, std::string> m_uniform_overrides; }; -class RetraceRender::StateOverride { - public: - StateOverride() {} - void setState(const StateKey &item, - const std::vector<float> &value); - void setState(const StateKey &item, - GLint value); - void saveState(); - void overrideState() const; - void restoreState() const; - - private: - struct Key { - uint32_t item; - uint32_t offset; - Key(uint32_t i, uint32_t o) : item(i), offset(o) {} - bool operator<(const Key &o) const { - if (item < o.item) - return true; - if (item > o.item) - return false; - return offset < o.offset; - } - }; - 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()) - // we have already saved the state - continue; - switch (glretrace::state_name_to_enum(i.first.name)) { - case GL_CULL_FACE: - save_enabled_state(i.first, GL_CULL_FACE); - break; - case GL_CULL_FACE_MODE: { - save_int_state(i.first, GL_CULL_FACE_MODE); - break; - } - case GL_BLEND: - save_enabled_state(i.first, GL_BLEND); - break; - case GL_BLEND_SRC: { - save_int_state(i.first, GL_BLEND_SRC); - break; - } - case GL_BLEND_DST: { - save_int_state(i.first, GL_BLEND_DST); - break; - } - case GL_INVALID_ENUM: - default: - assert(false); - break; - } - } -} - -void -RetraceRender::StateOverride::overrideState() const { - enact_state(m_overrides); -} - -void -RetraceRender::StateOverride::restoreState() const { - enact_state(m_saved_state); -} -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: { - enact_enabled_state(i.first, i.second, GL_CULL_FACE); - break; - } - case GL_CULL_FACE_MODE: { - GlFunctions::CullFace(i.second[0]); - assert(GL::GetError() == GL_NO_ERROR); - break; - } - case GL_BLEND: { - 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[0], dst); - assert(GL::GetError() == GL_NO_ERROR); - break; - } - case GL_BLEND_DST: { - GLint src; - GlFunctions::GetIntegerv(GL_BLEND_DST, &src); - assert(GL::GetError() == GL_NO_ERROR); - GlFunctions::BlendFunc(src, i.second[0]); - assert(GL::GetError() == GL_NO_ERROR); - break; - } - case GL_INVALID_ENUM: - default: - assert(false); - break; - } - } -} RetraceRender::RetraceRender(trace::AbstractParser *parser, retrace::Retracer *retracer, @@ -462,7 +267,6 @@ RetraceRender::retraceRenderTarget(const StateTrack &tracker, } m_uniform_override->overrideUniforms(); - m_state_override->saveState(); m_state_override->overrideState(); // retrace the final render @@ -556,7 +360,6 @@ RetraceRender::retrace(const StateTrack &tracker, } m_uniform_override->overrideUniforms(); - m_state_override->saveState(); m_state_override->overrideState(); // retrace the final render @@ -647,90 +450,17 @@ RetraceRender::onState(SelectionId selId, ExperimentId experimentCount, RenderId renderId, OnFrameRetrace *callback) const { - { - GL::GetError(); - GLboolean cull_enabled = GlFunctions::IsEnabled(GL_CULL_FACE); - GLenum e = GL::GetError(); - if (e == GL_NO_ERROR) { - callback->onState(selId, experimentCount, renderId, - StateKey("Rendering", "Cull State", "GL_CULL_FACE"), - {cull_enabled ? "true" : "false"}); - } - } - { - GLint cull; - GlFunctions::GetIntegerv(GL_CULL_FACE_MODE, &cull); - GLenum e = GL::GetError(); - if (e == GL_NO_ERROR) { - const std::string cull_str = state_enum_to_name(cull); - if (cull_str.size() > 0) { - callback->onState(selId, experimentCount, renderId, - StateKey("Rendering", "Cull State", - "GL_CULL_FACE_MODE"), {cull_str}); - } - } - } - { - GL::GetError(); - GLboolean enabled = GlFunctions::IsEnabled(GL_BLEND); - GLenum e = GL::GetError(); - if (e == GL_NO_ERROR) { - callback->onState(selId, experimentCount, renderId, - StateKey("Rendering", "Blend State", "GL_BLEND"), - {enabled ? "true" : "false"}); - } - } - { - GLint s; - GlFunctions::GetIntegerv(GL_BLEND_SRC, &s); - GLenum e = GL::GetError(); - if (e == GL_NO_ERROR) { - const std::string state_str = state_enum_to_name(s); - if (state_str.size() > 0) { - callback->onState(selId, experimentCount, renderId, - StateKey("Rendering", "Blend State", - "GL_BLEND_SRC"), {state_str}); - } - } - } - { - GLint s; - GlFunctions::GetIntegerv(GL_BLEND_DST, &s); - GLenum e = GL::GetError(); - if (e == GL_NO_ERROR) { - const std::string state_str = state_enum_to_name(s); - if (state_str.size() > 0) { - callback->onState(selId, experimentCount, renderId, - StateKey("Rendering", "Blend State", - "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); - } - } + m_state_override->onState(selId, experimentCount, renderId, callback); } void RetraceRender::setState(const StateKey &item, - const std::vector<std::string> &value) { - uint32_t e = state_name_to_enum(value[0]); - if (e != GL_INVALID_ENUM) + int offset, + const std::string &value) { + uint32_t e = state_name_to_enum(value); + if (e != GL_INVALID_ENUM) { + assert(offset == 0); 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); + } + m_state_override->setState(item, offset, std::stof(value)); } diff --git a/retrace/daemon/glframe_retrace_render.hpp b/retrace/daemon/glframe_retrace_render.hpp index ed9e49bc..cd34e010 100644 --- a/retrace/daemon/glframe_retrace_render.hpp +++ b/retrace/daemon/glframe_retrace_render.hpp @@ -48,6 +48,7 @@ class OnFrameRetrace; class ExperimentId; class MetricId; class PerfMetrics; +class StateOverride; class RetraceRender { public: @@ -90,7 +91,8 @@ class RetraceRender { void setUniform(const std::string &name, int index, const std::string &data); void setState(const StateKey &item, - const std::vector<std::string> &value); + int offset, + const std::string &value); static bool isRender(const trace::Call &c); static bool changesContext(const trace::Call &c); @@ -120,7 +122,6 @@ class RetraceRender { bool m_disabled, m_simple_shader; class UniformOverride; UniformOverride *m_uniform_override; - class StateOverride; StateOverride *m_state_override; }; diff --git a/retrace/daemon/glframe_retrace_skeleton.cpp b/retrace/daemon/glframe_retrace_skeleton.cpp index b4edeabf..3e21044a 100644 --- a/retrace/daemon/glframe_retrace_skeleton.cpp +++ b/retrace/daemon/glframe_retrace_skeleton.cpp @@ -418,10 +418,7 @@ FrameRetraceSkeleton::Run() { glretrace::StateKey k(item.group(), item.path(), item.name()); - std::vector<std::string> value; - for (auto v : state.value()) - value.push_back(v); - m_frame->setState(selection, k, value); + m_frame->setState(selection, k, state.offset(), state.value()); break; } } diff --git a/retrace/daemon/glframe_retrace_stub.cpp b/retrace/daemon/glframe_retrace_stub.cpp index cd973893..243c94d6 100644 --- a/retrace/daemon/glframe_retrace_stub.cpp +++ b/retrace/daemon/glframe_retrace_stub.cpp @@ -1021,9 +1021,11 @@ class SetStateRequest : public IRetraceRequest { public: SetStateRequest(const RenderSelection &selection, StateKey item, - const std::vector<std::string> &value) + int offset, + const std::string &value) : m_selection(selection), m_item(item), + m_offset(offset), m_value(value) {} void retrace(RetraceSocket *sock) { RetraceRequest msg; @@ -1035,15 +1037,16 @@ class SetStateRequest : public IRetraceRequest { item->set_name(m_item.name); auto selection = req->mutable_selection(); makeRenderSelection(m_selection, selection); - for (auto v : m_value) - req->add_value(v); + req->set_offset(m_offset); + req->set_value(m_value); sock->request(msg); } private: const RenderSelection m_selection; const StateKey m_item; - const std::vector<std::string> m_value; + const int m_offset; + const std::string m_value; }; class NullRequest : public IRetraceRequest { @@ -1326,6 +1329,7 @@ FrameRetraceStub::retraceState(const RenderSelection &selection, void FrameRetraceStub::setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value) { - m_thread->push(new SetStateRequest(selection, item, value)); + int offset, + const std::string &value) { + m_thread->push(new SetStateRequest(selection, item, offset, value)); } diff --git a/retrace/daemon/glframe_retrace_stub.hpp b/retrace/daemon/glframe_retrace_stub.hpp index 5fd5201d..999c35e1 100644 --- a/retrace/daemon/glframe_retrace_stub.hpp +++ b/retrace/daemon/glframe_retrace_stub.hpp @@ -98,7 +98,8 @@ class FrameRetraceStub : public IFrameRetrace { OnFrameRetrace *callback); virtual void setState(const RenderSelection &selection, const StateKey &item, - const std::vector<std::string> &value); + int offset, + const std::string &value); private: mutable std::mutex m_mutex; diff --git a/retrace/daemon/glframe_state_override.cpp b/retrace/daemon/glframe_state_override.cpp new file mode 100644 index 00000000..93438967 --- /dev/null +++ b/retrace/daemon/glframe_state_override.cpp @@ -0,0 +1,252 @@ +// Copyright (C) Intel Corp. 2017. All Rights Reserved. + +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: + +// The above copyright notice and this permission notice (including the +// next paragraph) shall be included in all copies or substantial +// portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// **********************************************************************/ +// * Authors: +// * Mark Janes <mark.a.janes@intel.com> +// **********************************************************************/ + +#include "glframe_state_override.hpp" + +#include <string> +#include <vector> + +#include "glframe_glhelper.hpp" +#include "glframe_state_enums.hpp" + +using glretrace::StateOverride; + +union IntFloat { + uint32_t i; + float f; +}; + +void +StateOverride::setState(const StateKey &item, + GLint value) { + auto &i = m_overrides[item]; + if (i.empty()) { + // save the prior state so we can restore it + getState(item, &i); + m_saved_state[item] = i; + } + assert(i.size() == 1); + i[0] = value; +} + +void +StateOverride::setState(const StateKey &item, + int offset, + float value) { + m_data_types[item] = kFloat; + auto &i = m_overrides[item]; + if (i.empty()) { + // save the prior state so we can restore it + getState(item, &i); + m_saved_state[item] = i; + } + IntFloat u; + u.f = value; + i[offset] = u.i; +} + +void +StateOverride::getState(const StateKey &item, + std::vector<uint32_t> *data) { + const auto n = state_name_to_enum(item.name); + switch (n) { + case GL_CULL_FACE: + case GL_BLEND: { + get_enabled_state(n, data); + break; + } + case GL_CULL_FACE_MODE: + case GL_BLEND_SRC: + case GL_BLEND_DST: { + get_integer_state(n, data); + break; + } + case GL_BLEND_COLOR: { + get_float_state(n, data); + break; + } + } +} + +void +StateOverride::get_enabled_state(GLint k, + std::vector<uint32_t> *data) { + GL::GetError(); + data->clear(); + data->resize(1); + (*data)[0] = GlFunctions::IsEnabled(k); + assert(!GL::GetError()); +} + + +void +StateOverride::get_integer_state(GLint k, + std::vector<uint32_t> *data) { + GL::GetError(); + data->clear(); + data->resize(1); + GlFunctions::GetIntegerv(k, reinterpret_cast<GLint*>(data->data())); + assert(!GL::GetError()); +} + +void +StateOverride::get_float_state(GLint k, std::vector<uint32_t> *data) { + GL::GetError(); + data->clear(); + data->resize(4); + GlFunctions::GetFloatv(k, reinterpret_cast<GLfloat*>(data->data())); + assert(!GL::GetError()); +} + +void +StateOverride::overrideState() const { + enact_state(m_overrides); +} + +void +StateOverride::restoreState() const { + enact_state(m_saved_state); +} + +void +StateOverride::enact_enabled_state(GLint setting, bool v) const { + if (v) + GlFunctions::Enable(setting); + else + GlFunctions::Disable(setting); + assert(GL::GetError() == GL_NO_ERROR); +} + +void +StateOverride::enact_state(const KeyMap &m) const { + GL::GetError(); + for (auto i : m) { + GL::GetError(); + const auto n = state_name_to_enum(i.first.name); + switch (n) { + case GL_CULL_FACE: + case GL_BLEND: { + enact_enabled_state(n, i.second[0]); + break; + } + case GL_CULL_FACE_MODE: { + GlFunctions::CullFace(i.second[0]); + assert(GL::GetError() == GL_NO_ERROR); + break; + } + case GL_BLEND_SRC: { + GLint dst; + GlFunctions::GetIntegerv(GL_BLEND_DST, &dst); + assert(GL::GetError() == GL_NO_ERROR); + GlFunctions::BlendFunc(i.second[0], dst); + assert(GL::GetError() == GL_NO_ERROR); + break; + } + case GL_BLEND_DST: { + GLint src; + GlFunctions::GetIntegerv(GL_BLEND_DST, &src); + assert(GL::GetError() == GL_NO_ERROR); + GlFunctions::BlendFunc(src, i.second[0]); + assert(GL::GetError() == GL_NO_ERROR); + break; + } + case GL_BLEND_COLOR: { + std::vector<float> f(4); + IntFloat u; + for (int j = 0; j < 4; ++j) { + u.i = i.second[j]; + f[j] = u.f; + } + GlFunctions::BlendColor(f[0], f[1], f[2], f[3]); + assert(GL::GetError() == GL_NO_ERROR); + break; + } + case GL_INVALID_ENUM: + default: + assert(false); + break; + } + } +} + +void floatStrings(const std::vector<uint32_t> &i, + std::vector<std::string> *s) { + s->clear(); + union { + uint32_t i; + float f; + } u; + for (auto d : i) { + u.i = d; + s->push_back(std::to_string(u.f)); + } +} + +void +StateOverride::onState(SelectionId selId, + ExperimentId experimentCount, + RenderId renderId, + OnFrameRetrace *callback) { + std::vector<uint32_t> data; + { + StateKey k("Rendering", "Cull State", "GL_CULL_FACE"); + getState(k, &data); + callback->onState(selId, experimentCount, renderId, + k, {data[0] ? "true" : "false"}); + } + { + StateKey k("Rendering", "Cull State", "GL_CULL_FACE_MODE"); + getState(k, &data); + callback->onState(selId, experimentCount, renderId, + k, {state_enum_to_name(data[0])}); + } + { + StateKey k("Rendering", "Blend State", "GL_BLEND"); + getState(k, &data); + callback->onState(selId, experimentCount, renderId, + k, {data[0] ? "true" : "false"}); + } + { + StateKey k("Rendering", "Blend State", "GL_BLEND_SRC"); + getState(k, &data); + callback->onState(selId, experimentCount, renderId, + k, {state_enum_to_name(data[0])}); + } + { + StateKey k("Rendering", "Blend State", "GL_BLEND_DST"); + getState(k, &data); + callback->onState(selId, experimentCount, renderId, + k, {state_enum_to_name(data[0])}); + } + { + StateKey k("Rendering", "Blend State", "GL_BLEND_COLOR"); + getState(k, &data); + std::vector<std::string> color; + floatStrings(data, &color); + callback->onState(selId, experimentCount, renderId, k, color); + } +} diff --git a/retrace/daemon/glframe_state_override.hpp b/retrace/daemon/glframe_state_override.hpp new file mode 100644 index 00000000..891ef697 --- /dev/null +++ b/retrace/daemon/glframe_state_override.hpp @@ -0,0 +1,82 @@ +// Copyright (C) Intel Corp. 2017. All Rights Reserved. + +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: + +// The above copyright notice and this permission notice (including the +// next paragraph) shall be included in all copies or substantial +// portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// **********************************************************************/ +// * Authors: +// * Mark Janes <mark.a.janes@intel.com> +// **********************************************************************/ + +#include <GL/gl.h> + +#include <map> +#include <vector> + +#include "glframe_retrace_interface.hpp" + + +namespace glretrace { + +class StateOverride { + public: + StateOverride() {} + void setState(const StateKey &item, + int offset, + float value); + void setState(const StateKey &item, + GLint value); + void saveState(); + void overrideState() const; + void restoreState() const; + + void onState(SelectionId selId, + ExperimentId experimentCount, + RenderId renderId, + OnFrameRetrace *callback); + + void getState(const StateKey &item, + std::vector<uint32_t> *data); + + private: + 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(GLint setting, bool v) const; + void enact_int_state(uint32_t 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); + void get_enabled_state(GLint k, std::vector<uint32_t> *data); + void get_integer_state(GLint k, std::vector<uint32_t> *data); + void get_float_state(GLint k, std::vector<uint32_t> *data); + + + KeyMap m_overrides; + KeyMap m_saved_state; + std::map<StateKey, Type> m_data_types; +}; + +} // namespace glretrace diff --git a/retrace/daemon/playback.proto b/retrace/daemon/playback.proto index 2460eddb..64ffc241 100644 --- a/retrace/daemon/playback.proto +++ b/retrace/daemon/playback.proto @@ -248,7 +248,8 @@ message StateResponse { message SetStateRequest { required RenderSelection selection = 1; required StateKey item = 2; - repeated string value = 3; + required uint32 offset = 3; + required string value = 4; } message RetraceRequest { diff --git a/retrace/daemon/ui/glframe_state_model.cpp b/retrace/daemon/ui/glframe_state_model.cpp index 2b357f1a..a8a9caa7 100644 --- a/retrace/daemon/ui/glframe_state_model.cpp +++ b/retrace/daemon/ui/glframe_state_model.cpp @@ -227,6 +227,7 @@ void QStateModel::setState(const QString &group, const QString &path, const QString &name, + int offset, const QString &value) { RenderSelection sel; sel.id = m_sel_count; @@ -242,7 +243,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, offset, value.toStdString()); emit stateExperiment(); } @@ -314,3 +315,4 @@ QStateModel::refresh() { } emit stateChanged(); } + diff --git a/retrace/daemon/ui/glframe_state_model.hpp b/retrace/daemon/ui/glframe_state_model.hpp index 5207e8dd..6d78b230 100644 --- a/retrace/daemon/ui/glframe_state_model.hpp +++ b/retrace/daemon/ui/glframe_state_model.hpp @@ -117,6 +117,7 @@ class QStateModel : public QObject, Q_INVOKABLE void setState(const QString &group, const QString &path, const QString &name, + int offset, const QString &value); Q_INVOKABLE void collapse(const QString &path); Q_INVOKABLE void expand(const QString &path); diff --git a/retrace/daemon/ui/qml/StateControl.qml b/retrace/daemon/ui/qml/StateControl.qml index 205e1c6f..4e349f62 100644 --- a/retrace/daemon/ui/qml/StateControl.qml +++ b/retrace/daemon/ui/qml/StateControl.qml @@ -53,12 +53,79 @@ Item { Row { visible: (modelData.valueType == QStateValue.KglColor) Text{ - text: "Color: " + text: "Red: " } - Repeater{ - model: modelData.value - Text{ - text: modelData + TextInput { + anchors.margins: 3 + validator: DoubleValidator{} + text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[0] : "" + Keys.onReturnPressed: { + if (!acceptableInput) { + text = modelData.value[0]; + return; + } + stateModel.setState(modelData.group, + modelData.path, + modelData.name, + 0, + text); + } + } + Text{ + text: "Blue: " + } + TextInput { + anchors.margins: 3 + validator: DoubleValidator{} + text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[1] : "" + Keys.onReturnPressed: { + if (!acceptableInput) { + text = modelData.value[1]; + return; + } + stateModel.setState(modelData.group, + modelData.path, + modelData.name, + 1, + text); + } + } + Text{ + text: "Green: " + } + TextInput { + anchors.margins: 3 + validator: DoubleValidator{} + text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[2] : "" + Keys.onReturnPressed: { + if (!acceptableInput) { + text = modelData.value[2]; + return; + } + stateModel.setState(modelData.group, + modelData.path, + modelData.name, + 2, + text); + } + } + Text{ + text: "Alpha: " + } + TextInput { + validator: DoubleValidator{} + anchors.margins: 3 + text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[3] : "" + Keys.onReturnPressed: { + if (!acceptableInput) { + text = modelData.value[3]; + return; + } + stateModel.setState(modelData.group, + modelData.path, + modelData.name, + 3, + text); } } } @@ -72,6 +139,7 @@ Item { stateModel.setState(modelData.group, modelData.path, modelData.name, + 0, modelData.choices[currentIndex]); } } |