-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectmrendernode.cpp
More file actions
executable file
·95 lines (76 loc) · 2.67 KB
/
projectmrendernode.cpp
File metadata and controls
executable file
·95 lines (76 loc) · 2.67 KB
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
#include "projectmrendernode.h"
ProjectMRenderNode::ProjectMRenderNode(int x, int y, const int width, const int height)
: m_width(width), m_height(height) {
initializeOpenGLFunctions();
QOpenGLContext* qtContext = QOpenGLContext::currentContext();
if (!qtContext) {
qWarning() << "No OpenGL context is currently active!";
return;
}
m_projectMRenderContext = new QOpenGLContext();
m_projectMRenderContext->setFormat(qtContext->format());
m_projectMRenderContext->setShareContext(qtContext);
m_projectMRenderContext->create();
m_projectMRenderContext->makeCurrent(qtContext->surface());
m_projectM = std::make_unique<projectm_handle>(projectm_create());
if (!m_projectM) {
qFatal() << "ProjectM failed to initialize!";
exit(1);
}
}
ProjectMRenderNode::~ProjectMRenderNode() {
projectm_destroy(*m_projectM);
m_projectM = nullptr;
}
void ProjectMRenderNode::render(const RenderState* state) {
Q_UNUSED(state);
const QOpenGLContext* qtContext = QOpenGLContext::currentContext();
if (!qtContext) {
qWarning() << "No OpenGL context is active!";
return;
}
if (!m_projectMRenderContext) {
qWarning() << "projectM's context is not valid!";
return;
}
//Makes the projectm context the current one
m_projectMRenderContext->makeCurrent(qtContext->surface());
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //set clear color to black
glEnable(GL_SCISSOR_TEST);
glViewport(0, 0, 200, 100);
glScissor(m_x, m_y, m_width, m_height); //restrict clear area
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_CLEAR_VALUE);
glDisable(GL_SCISSOR_TEST);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(10.0f, 10.0f, 0.0f);
if (m_projectM) {
//renders frame
projectm_opengl_render_frame(*m_projectM);
if (shouldUpdateSize) {
projectm_set_window_size(*m_projectM, m_width, m_height);
shouldUpdateSize = false;
}
}
glPopMatrix();
glViewport(10, 10, 200, 100);
m_projectMRenderContext->doneCurrent();
}
void ProjectMRenderNode::setSize(const int width, const int height) {
if (m_width != width || m_height != height) {
m_width = width;
m_height = height;
shouldUpdateSize = true;
}
}
void ProjectMRenderNode::setPosition(const int x, const int y) {
if (m_x != x || m_y != y) {
m_x = x;
m_y = y;
}
}
void ProjectMRenderNode::setAudioData(const float* pcm, const int samples) const {
if (m_projectM) {
projectm_pcm_add_float(*m_projectM, pcm, samples / sizeof(float), PROJECTM_STEREO);
}
}