-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu-stats-gl.cpp
710 lines (612 loc) · 20.8 KB
/
cpu-stats-gl.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <cstdlib>
#include <iterator>
#include <math.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <atomic>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <thread>
#include "led-matrix.h"
// Define interval for auto blanking - set to zero to disable
#define BLANKINTERVAL 0
// params
#define LOAD_MIN 0
#define LOAD_MAX 8
#define DOWNLOAD_MIN 0 // in bytes/s
#define DOWNLOAD_MAX 8000000 // in bytes/s
#define UPLOAD_MIN 0 // in bytes/s
#define UPLOAD_MAX 3500000 // in bytes/s
// UDP port to listen for status updates
#define PORT 1234
// Animation speed: how fast are received values are changing values passed to
// the shader.
// set to 0 to disable
#define ANIMSTEP 0.010f
// Resolution, three panels with 64x64 each.
#define W 192
#define H 64
// That's it up here, but you might also want to change the settings for your
// RGB matrix in line 462 below
float normalize(float lower, float x, float higher);
// settings
float p_factor = 0.5f;
// lowest, current, max
float load = normalize(LOAD_MIN, LOAD_MIN, LOAD_MAX);
float download = normalize(DOWNLOAD_MIN, DOWNLOAD_MIN, DOWNLOAD_MAX);
float upload = normalize(UPLOAD_MIN, UPLOAD_MIN, UPLOAD_MAX);
bool on = true; // homekit integration
unsigned int brightness = 100;
float normalize(float lower, float x, float higher) {
return (x - lower) / (higher - lower);
}
float normalize(int lower, float x, int higher) {
return (x - float(lower)) / float(higher - lower);
}
float normalize(int lower, int x, int higher) {
return float(x - lower) / float(higher - lower);
}
using rgb_matrix::Canvas;
using rgb_matrix::RGBMatrix;
using namespace rgb_matrix;
float t = 0.f;
float updateTime = -10.0f;
volatile bool interrupt_received = false;
static void InterruptHandler(int signo) { interrupt_received = true; }
static const std::string SHADER_HEADER = "#define environment 2\n";
static const std::string SHADER_HEADER_TESTING = "#define environment 0\n";
static const EGLint configAttribs[] = {EGL_SURFACE_TYPE,
EGL_PBUFFER_BIT,
EGL_BLUE_SIZE,
8,
EGL_GREEN_SIZE,
8,
EGL_RED_SIZE,
8,
EGL_DEPTH_SIZE,
8,
EGL_SAMPLE_BUFFERS,
1,
EGL_SAMPLES,
4,
EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT,
EGL_NONE};
// Width and height of the desired framebuffer
static const EGLint pbufferAttribs[] = {
EGL_WIDTH, W, EGL_HEIGHT, H, EGL_NONE,
};
static const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE};
static const GLfloat vertices[] = {
-1.0f,
-1.0f,
0.0f,
-1.0f,
1.0f,
0.0f,
-0.33333333333f,
-1.0f,
0.0f,
-0.33333333333f,
1.0f,
0.0f,
-0.33333333333f,
-1.0f,
0.0f,
-0.33333333333f,
1.0f,
0.0f,
0.33333333333f,
-1.0f,
0.0f,
0.33333333333f,
1.0f,
0.0f,
0.33333333333f,
-1.0f,
0.0f,
0.33333333333f,
1.0f,
0.0f,
1.0f,
-1.0f,
0.0f,
1.0f,
1.0f,
0.0f,
};
static const GLfloat vcoords[] = {
0.0f, 0.0f, -0.866f, 0.5f,
0.0, -1.0f, -0.866, -0.5f,
0.0f, 0.0f, 0.0f, -1.0f,
0.866f, 0.5f, 0.866f, -0.5f,
0.0f, 0.0f, 0.866f, 0.5f,
-0.866f, 0.5f, 0.0f, 1.0f,
};
std::string loadFile(std::string path) {
std::cout << "loading file: " + path << std::endl;
std::ifstream ifs(path);
std::string content((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
if (content.length() <= 0)
std::cout << "WARNING: content of " + path + "is 0" << std::endl;
return content;
}
static const char *eglGetErrorStr() {
switch (eglGetError()) {
case EGL_SUCCESS:
return "The last function succeeded without error.";
case EGL_NOT_INITIALIZED:
return "EGL is not initialized, or could not be initialized, for the "
"specified EGL display connection.";
case EGL_BAD_ACCESS:
return "EGL cannot access a requested resource (for example a context "
"is bound in another thread).";
case EGL_BAD_ALLOC:
return "EGL failed to allocate resources for the requested operation.";
case EGL_BAD_ATTRIBUTE:
return "An unrecognized attribute or attribute value was passed in the "
"attribute list.";
case EGL_BAD_CONTEXT:
return "An EGLContext argument does not name a valid EGL rendering "
"context.";
case EGL_BAD_CONFIG:
return "An EGLConfig argument does not name a valid EGL frame buffer "
"configuration.";
case EGL_BAD_CURRENT_SURFACE:
return "The current surface of the calling thread is a window, pixel "
"buffer or pixmap that is no longer valid.";
case EGL_BAD_DISPLAY:
return "An EGLDisplay argument does not name a valid EGL display "
"connection.";
case EGL_BAD_SURFACE:
return "An EGLSurface argument does not name a valid surface (window, "
"pixel buffer or pixmap) configured for GL rendering.";
case EGL_BAD_MATCH:
return "Arguments are inconsistent (for example, a valid context "
"requires buffers not supplied by a valid surface).";
case EGL_BAD_PARAMETER:
return "One or more argument values are invalid.";
case EGL_BAD_NATIVE_PIXMAP:
return "A NativePixmapType argument does not refer to a valid native "
"pixmap.";
case EGL_BAD_NATIVE_WINDOW:
return "A NativeWindowType argument does not refer to a valid native "
"window.";
case EGL_CONTEXT_LOST:
return "A power management event has occurred. The application must "
"destroy all contexts and reinitialise OpenGL ES state and "
"objects to continue rendering.";
default:
break;
}
return "Unknown error!";
}
std::string asString(const std::chrono::system_clock::time_point &tp) {
// convert to system time:
std::time_t t = std::chrono::system_clock::to_time_t(tp);
std::string ts = std::ctime(&t); // convert to calendar time
ts.resize(ts.size() - 1); // skip trailing newline
return ts;
}
#define BUFLEN 128
void receiveUDP() {
struct sockaddr_in si_me, si_other;
int s, i, slen = sizeof(si_other);
char buf[BUFLEN + 1];
memset((char *)&si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_port = htons(PORT);
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 1000;
while (!interrupt_received) {
if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
usleep(500000);
printf("Error creating socket.\n");
continue;
}
if (bind(s, (struct sockaddr *)&si_me, sizeof(si_me)) == -1) {
usleep(500000);
printf("Error binding socket.\n");
continue;
}
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
usleep(500000);
printf("Error setting socket timeout.\n");
continue;
}
while (!interrupt_received) {
int nIn = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *)&si_other,
(socklen_t *)&slen);
if (nIn <= 0) {
usleep(0);
continue;
}
updateTime = t;
buf[nIn] = 0;
int i = 0;
int j = 0;
while (i < nIn) {
float entryf = atof(buf + i);
int entryi = atoi(buf + i);
// std::cout << "e: " << entry << " @ " << j << std::endl;
if (entryi >= 0)
switch (j) {
case 0:
load = normalize(LOAD_MIN, entryf, LOAD_MAX);
break;
case 1:
download = normalize(DOWNLOAD_MIN, entryi, DOWNLOAD_MAX);
break;
case 2:
upload = normalize(UPLOAD_MIN, entryi, UPLOAD_MAX);
break;
case 3:
on = entryi == 1;
break;
case 4:
brightness = entryi;
break;
default:
break;
}
j++;
while (buf[i] != ',' && i < nIn)
i++;
i++;
}
}
close(s);
}
}
bool checkShader(GLuint shader) {
GLint success;
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success) {
char errorLog[512];
glGetShaderInfoLog(shader, 512, NULL, errorLog);
fprintf(stderr, "Shader compilation failed!\n%s\n", errorLog);
return false;
}
return true;
}
void pixel(int r, int g, int b) {
float rf = (r / 255.0);
float gf = (g / 255.0);
float bf = (b / 255.0);
int code = (int)std::round(36 * (rf * 5) + 6 * (gf * 5) + (bf * 5) + 16);
printf("\033[1;48;5;%im \033[0m", code);
}
void print_w_linenumbers(std::string text) {
std::stringstream ss(text);
std::string to;
int lineNumber = 1;
while (std::getline(ss, to, '\n')) {
std::cout << std::setfill(' ') << std::setw(5) << lineNumber << ": " << to
<< std::endl;
lineNumber++;
}
}
int main(int argc, char *argv[]) {
std::string vertexPath = "shader/vertex.original.glsl";
std::string fragmentPath = "shader/fragment.template.glsl";
std::string renderFunctionPath = "shader/render.smoke2.glsl";
EGLDisplay display;
unsigned int debug = 0;
bool print = false;
bool printShaderOnly = false;
int major, minor;
int desiredWidth, desiredHeight;
GLuint program, vert, frag, vbo, vbocoord;
int pos_id, fragcoord_id, load_id, upload_id, download_id, age_id, time_id;
if (argc >= 2) {
for (int i = 1; i < argc; i++) {
std::string option = std::string(argv[i]);
if (option == "-p")
print = true;
else if (option.rfind("-v", 0) == 0)
debug = option.length() - 1;
else if (option == "--fragment") { // pretty useless
fragmentPath = std::string(argv[i + 1]);
} else if (option == "--vertex") { // pretty useless
vertexPath = std::string(argv[i + 1]);
} else if (option == "--render") { // very useful!!
renderFunctionPath = std::string(argv[i + 1]);
} else if (option ==
"--print-shader") { // lets you output the shader code and copy
// it for glslsandbox
printShaderOnly = true;
}
}
}
if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
fprintf(stderr, "Failed to get EGL display! Error: %s\n", eglGetErrorStr());
return EXIT_FAILURE;
}
if (eglInitialize(display, &major, &minor) == EGL_FALSE) {
fprintf(stderr, "Failed to get EGL version! Error: %s\n", eglGetErrorStr());
eglTerminate(display);
return EXIT_FAILURE;
}
printf("Initialized EGL version: %d.%d\n", major, minor);
EGLint numConfigs;
EGLConfig config;
if (!eglChooseConfig(display, configAttribs, &config, 1, &numConfigs)) {
fprintf(stderr, "Failed to get EGL config! Error: %s\n", eglGetErrorStr());
eglTerminate(display);
return EXIT_FAILURE;
}
EGLSurface surface = eglCreatePbufferSurface(display, config, pbufferAttribs);
if (surface == EGL_NO_SURFACE) {
fprintf(stderr, "Failed to create EGL surface! Error: %s\n",
eglGetErrorStr());
eglTerminate(display);
return EXIT_FAILURE;
}
eglBindAPI(EGL_OPENGL_API);
EGLContext context =
eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
if (context == EGL_NO_CONTEXT) {
fprintf(stderr, "Failed to create EGL context! Error: %s\n",
eglGetErrorStr());
eglDestroySurface(display, surface);
eglTerminate(display);
return EXIT_FAILURE;
}
eglMakeCurrent(display, surface, surface, context);
desiredWidth = pbufferAttribs[1];
desiredHeight = pbufferAttribs[3];
glViewport(0, 0, desiredWidth, desiredHeight);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
printf("GL Viewport size: %dx%d\n", viewport[2], viewport[3]);
if (desiredWidth != viewport[2] || desiredHeight != viewport[3]) {
fprintf(stderr, "Error! The glViewport/glGetIntegerv are not working! "
"EGL might be faulty!\n");
}
// Clear whole screen (front buffer)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Shader program
std::string header = SHADER_HEADER;
if (printShaderOnly) {
header = SHADER_HEADER_TESTING;
}
std::string vertexCode = header + loadFile(vertexPath);
std::string fragmentCode = header + loadFile(fragmentPath);
if (renderFunctionPath.length() > 0) {
std::string functionBody = loadFile(renderFunctionPath);
std::size_t found = fragmentCode.find("// RENDER ENDS HERE");
if (found == std::string::npos) {
std::cout << "not found" << std::endl;
return EXIT_FAILURE;
}
fragmentCode = fragmentCode.insert(found, functionBody);
}
static const char *cVertexCode = vertexCode.c_str();
static const char *cFragmentCode = fragmentCode.c_str();
program = glCreateProgram();
glUseProgram(program);
vert = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vert, 1, &cVertexCode, NULL);
glCompileShader(vert);
if (!checkShader(vert))
return EXIT_FAILURE;
frag = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(frag, 1, &cFragmentCode, NULL);
glCompileShader(frag);
if (!checkShader(frag))
return EXIT_FAILURE;
glAttachShader(program, frag);
glAttachShader(program, vert);
glLinkProgram(program);
// https://www.khronos.org/opengl/wiki/Example/GLSL_Program_Link_Error_Testing
GLint isLinked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
if (isLinked == GL_FALSE) {
char infoLog[512];
glGetProgramInfoLog(program, 512, NULL, infoLog);
std::cout << infoLog << std::endl;
glDeleteProgram(program);
print_w_linenumbers(fragmentCode);
return EXIT_FAILURE;
}
glUseProgram(program);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 36 * sizeof(float), vertices, GL_STATIC_DRAW);
glGenBuffers(1, &vbocoord);
glBindBuffer(GL_ARRAY_BUFFER, vbocoord);
glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(float), vcoords, GL_STATIC_DRAW);
// Get vertex attribute and uniform locations
pos_id = glGetAttribLocation(program, "aPos");
fragcoord_id = glGetAttribLocation(program, "coord");
load_id = glGetUniformLocation(program, "load");
upload_id = glGetUniformLocation(program, "upload");
download_id = glGetUniformLocation(program, "download");
time_id = glGetUniformLocation(program, "time");
age_id = glGetUniformLocation(program, "age");
if (debug >= 1) {
printf("Location of position: %d\n", pos_id);
printf("Location of fragecoord: %d\n", fragcoord_id);
printf("Location of load: %d\n", load_id);
printf("Location of upload: %d\n", upload_id);
printf("Location of download: %d\n", download_id);
printf("Location of time: %d\n", time_id);
printf("Location of age: %d\n", age_id);
printf("load: %d | %f | %d\n", LOAD_MIN, load, LOAD_MAX);
printf("down: %d | %f | %d\n", DOWNLOAD_MIN, download, DOWNLOAD_MAX);
printf("up: %d | %f | %d\n", UPLOAD_MIN, upload, UPLOAD_MAX);
}
if (printShaderOnly) {
glDeleteProgram(program);
std::cout << fragmentCode << std::endl;
return EXIT_SUCCESS;
}
// Set our vertex data
glEnableVertexAttribArray(pos_id);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(pos_id, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float),
(void *)0);
glEnableVertexAttribArray(fragcoord_id);
glBindBuffer(GL_ARRAY_BUFFER, vbocoord);
glVertexAttribPointer(fragcoord_id, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),
(void *)0);
// LED Matrix settings
RGBMatrix::Options defaults;
rgb_matrix::RuntimeOptions runtime;
runtime.daemon = -1;
defaults.hardware_mapping = "adafruit-hat-pwm";
defaults.led_rgb_sequence = "BGR";
// performance numbers
defaults.pwm_bits = 8; // Default is 11. Lower require less CPU.
defaults.pwm_dither_bits =
1; // The lower bits can be time-dithered for higher refresh rate.
defaults.pwm_lsb_nanoseconds =
150; // Higher numbers provide better quality (more accurate color, less
// ghosting), but have a negative impact on the frame rate. Default
// 130
defaults.scan_mode = 1; // Scan mode: 0=progressive, 1=interlaced.
defaults.panel_type = "FM6126A";
defaults.rows = 64;
defaults.cols = 192;
defaults.chain_length = 1;
// defaults.limit_refresh_rate_hz = 90;
defaults.parallel = 1;
if (debug >= 3) {
defaults.show_refresh_rate = true;
}
// defaults.brightness = 60;
runtime.drop_privileges = 0;
runtime.gpio_slowdown = 2;
RGBMatrix *matrix =
rgb_matrix::CreateMatrixFromFlags(&argc, &argv, &defaults, &runtime);
if (matrix == NULL)
return EXIT_FAILURE;
FrameCanvas *canvas = matrix->CreateFrameCanvas();
signal(SIGTERM, InterruptHandler);
signal(SIGINT, InterruptHandler);
unsigned char *buffer = (unsigned char *)malloc(W * H * 3);
std::thread networking(receiveUDP);
int lastTime = (int)std::time(NULL);
int nbFrames = 0;
matrix->StartRefresh();
bool last_frame_on = true;
float effective_load = 0.0f;
float effective_download = 0.0f;
float effective_upload = 0.0f;
printf("Rendering!\n");
while (!interrupt_received) {
t += 0.01f;
if (print) {
printf("\033c");
sleep(1);
}
if (ANIMSTEP == 0.0) {
effective_load = load;
effective_download = download;
effective_upload = upload;
} else {
if (load > effective_load && load - ANIMSTEP > effective_load)
effective_load += ANIMSTEP;
else if (load < effective_load)
effective_load -= ANIMSTEP;
if (download > effective_download &&
download - ANIMSTEP > effective_download)
effective_download += ANIMSTEP;
else if (download < effective_download)
effective_download -= ANIMSTEP;
if (upload > effective_upload && upload - ANIMSTEP > effective_upload)
effective_upload += ANIMSTEP;
else if (upload < effective_upload)
effective_upload -= ANIMSTEP;
}
float age = float(t - updateTime);
if (debug >= 2) {
int currentTime = (int)std::time(NULL);
nbFrames++;
if ((currentTime - lastTime) >=
1.0) { // If last prinf() was more than 1 sec ago
printf("%f ms/frame -> %i/s | time: %4.3f | age: %4.3f | load: %4.3f | "
"down: %4.3f | up: %4.3f | on: %d\n",
1000.0 / float(nbFrames), nbFrames, t, age, effective_load,
effective_download, effective_upload, on);
nbFrames = 0;
lastTime += 1;
}
}
// skip if we are off
if (!on) {
if (last_frame_on) {
printf("Killing matrix and creating a new one\n");
canvas->Clear();
delete matrix;
matrix = rgb_matrix::CreateMatrixFromFlags(&argc, &argv, &defaults,
&runtime);
if (matrix == NULL)
return EXIT_FAILURE;
canvas = matrix->CreateFrameCanvas();
}
last_frame_on = false;
usleep(1000);
continue;
}
if (!last_frame_on)
matrix->StartRefresh();
last_frame_on = true;
// Grab the interval since last update
int quiet = int(t - updateTime);
if ((quiet > BLANKINTERVAL) && (BLANKINTERVAL > 0)) {
canvas->Clear();
canvas = matrix->SwapOnVSync(canvas);
sleep(5);
} else {
matrix->SetBrightness(brightness);
glUniform1f(time_id, t);
glUniform1f(age_id, age);
glUniform1f(load_id, effective_load);
glUniform1f(download_id, effective_download);
glUniform1f(upload_id, effective_upload);
// ACTION
glDrawArrays(GL_TRIANGLE_STRIP, 0, 12);
glReadPixels(0, 0, W, H, GL_RGB, GL_UNSIGNED_BYTE, buffer);
for (int x = 0; x < W; x++) {
for (int y = 0; y < H; y++) {
int index = 3 * (x + y * W);
canvas->SetPixel(x, y, buffer[index], buffer[index + 1],
buffer[index + 2]);
if (x % 2 == 0 && print)
pixel(buffer[index], buffer[index + 1], buffer[index + 2]);
}
if (x % 2 == 0 && print)
std::cout << std::endl;
}
canvas = matrix->SwapOnVSync(canvas);
}
}
networking.join();
free(buffer);
canvas->Clear();
// Cleanup
eglDestroyContext(display, context);
eglDestroySurface(display, surface);
eglTerminate(display);
return EXIT_SUCCESS;
}