-
Notifications
You must be signed in to change notification settings - Fork 23
/
glheapdiagramlayer.h
92 lines (74 loc) · 3.09 KB
/
glheapdiagramlayer.h
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
#ifndef GLHEAPDIAGRAMLAYER_H
#define GLHEAPDIAGRAMLAYER_H
#include <memory>
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLShaderProgram>
#include "displayheapwindow.h"
#include "heaphistory.h"
#include "vertex.h"
// A "layer" -- a collection of bits of data, vertices, shaders etc. that
// allows easy drawing of an extra layer of the heap diagram.
class GLHeapDiagramLayer {
public:
GLHeapDiagramLayer(std::string vertex_shader_name,
std::string fragment_shader_name,
bool is_line_layer);
~GLHeapDiagramLayer();
void initializeGLStructures(
const HeapHistory& heap_history, QOpenGLFunctions *parent);
void paintLayer(ivec2 minimum_tick, ivec3 maximum_tick,
const QMatrix2x2 &heap_to_screen);
// Get a pointer to the HeapVertex vector so it can be filled.
std::vector<HeapVertex>* getVertexVector() { return &layer_vertices_; }
// In order to allow debugging of the individual layers, each derived
// class needs to provide a function that simulates the GLSL vertex
// shader in C++. Returns a vec4 with the (x, y, 0, 1) for the mapped
// vertex and a vec4 for the color.
virtual std::pair<vec4, vec4> vertexShaderSimulator(const HeapVertex&
vertex) = 0;
void refreshVertices(const HeapHistory& heap_history, bool bind, bool all = false);
void debugDumpVertexTransformation();
void setDebug(bool value) { dump_debug_ = value; }
protected:
void setupStandardUniforms();
virtual void loadVerticesFromHeapHistory(const HeapHistory& history, bool all) = 0;
void refreshGLBuffer(bool bind);
// Helper functions to set the uniforms for the shaders.
void setTickBaseUniforms(int32_t x, int32_t y);
void setHeapBaseUniforms(int32_t x, int32_t y, int32_t z);
void setHeapToScreenMatrix(const QMatrix2x2 &heap_to_screen);
std::string vertex_shader_name_;
std::string fragment_shader_name_;
bool is_initialized_ = false;
bool is_line_layer_ = false;
bool dump_debug_ = false;
// The vertices for this layer.
std::vector<HeapVertex> layer_vertices_;
// An ivec3 that is filled with the uint64_t of the base address of the
// displayed fraction of the heap.
int uniform_visible_heap_base_A_ = 0;
int uniform_visible_heap_base_B_ = 0;
int uniform_visible_heap_base_C_ = 0;
// The actual values that were set. Used for the internal C++ debug
// simulation of the GLSL code.
int32_t visible_heap_base_A_ = 0;
int32_t visible_heap_base_B_ = 0;
int32_t visible_heap_base_C_ = 0;
// The minimum tick is provided as ivec2.
int uniform_visible_tick_base_A_ = 0;
int uniform_visible_tick_base_B_ = 0;
// The actual values that were last set.
int32_t visible_tick_base_A_ = 0;
int32_t visible_tick_base_B_ = 0;
// The matrix to project heap vertices to the screen.
int uniform_vertex_to_screen_ = 0;
// Actual values for the matrix.
QMatrix2x2 vertex_to_screen_;
// VAO, VBO and shader for this layer.
QOpenGLBuffer layer_vertex_buffer_;
QOpenGLVertexArrayObject layer_vao_;
std::unique_ptr<QOpenGLShaderProgram> layer_shader_program_;
};
#endif // GLHEAPDIAGRAMLAYER_H