summaryrefslogtreecommitdiff
path: root/retrace/daemon/glframe_retrace_render.hpp
blob: cd34e0103e91077d1a8eb85b1d27ee87e8a253c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**************************************************************************
 *
 * Copyright 2015 Intel Corporation
 * 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 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
 * AUTHORS OR COPYRIGHT HOLDERS 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>
 **************************************************************************/

#ifndef _GLFRAME_RETRACE_RENDER_HPP_
#define _GLFRAME_RETRACE_RENDER_HPP_

#include <string>
#include <vector>

#include "glframe_retrace.hpp"

namespace trace {
class Parser;
}

namespace retrace {
class Retracer;
}

namespace glretrace {

class StateTrack;
class OnFrameRetrace;
class ExperimentId;
class MetricId;
class PerfMetrics;
class StateOverride;

class RetraceRender {
 public:
  RetraceRender(trace::AbstractParser *parser,
                retrace::Retracer *retracer,
                StateTrack *tracker);
  ~RetraceRender();

  struct CallbackContext {
    CallbackContext(SelectionId s, ExperimentId e,
                    RenderId r, OnFrameRetrace *c)
        : selection(s), experiment(e), render(r), callback(c) {}
    SelectionId selection;
    ExperimentId experiment;
    RenderId render;
    OnFrameRetrace *callback;
  };

  void retraceRenderTarget(const StateTrack &tracker,
                           RenderTargetType type) const;
  void retrace(StateTrack *tracker) const;
  void retrace(const StateTrack &tracker,
               const CallbackContext *uniform_context = NULL,
               const CallbackContext *state_context = NULL) const;
  bool endsFrame() const { return m_end_of_frame; }
  bool replaceShaders(StateTrack *tracker,
                      const std::string &vs,
                      const std::string &fs,
                      const std::string &tessControl,
                      const std::string &tessEval,
                      const std::string &geom,
                      const std::string &comp,
                      std::string *message);
  void revertShaders();
  void disableDraw(bool disable);
  void simpleShader(bool simple);
  void onApi(SelectionId selId,
             RenderId renderId,
             OnFrameRetrace *callback);
  void setUniform(const std::string &name, int index,
                  const std::string &data);
  void setState(const StateKey &item,
                int offset,
                const std::string &value);

  static bool isRender(const trace::Call &c);
  static bool changesContext(const trace::Call &c);
  static bool endsFrame(const trace::Call &c);
  static int currentRenderBuffer();

 private:
  void overrideUniforms() const;
  void onState(SelectionId selId,
               ExperimentId experimentCount,
               RenderId renderId,
               OnFrameRetrace *callback) const;

  trace::AbstractParser *m_parser;
  retrace::Retracer *m_retracer;
  RenderBookmark m_bookmark;
  std::string m_original_vs, m_original_fs,
    m_original_tess_control, m_original_tess_eval,
    m_original_geom,
    m_original_comp,
    m_modified_fs, m_modified_vs,
    m_modified_tess_eval, m_modified_tess_control,
    m_modified_geom, m_modified_comp;
  int m_rt_program, m_retrace_program, m_original_program;
  bool m_end_of_frame, m_highlight_rt, m_changes_context;
  std::vector<std::string> m_api_calls;
  bool m_disabled, m_simple_shader;
  class UniformOverride;
  UniformOverride *m_uniform_override;
  StateOverride *m_state_override;
};

}  // namespace glretrace

#endif  // _GLFRAME_RETRACE_RENDER_HPP_