@@ -69,6 +69,12 @@ struct gl_sampler_data {
69
69
size_t sz ;
70
70
};
71
71
72
+ /* per-bind data containing the framebuffer and 1D texture to render for smoothing. */
73
+
74
+ struct sm_fb {
75
+ GLuint fbo , tex ;
76
+ };
77
+
72
78
/* GLSL uniform bind */
73
79
74
80
struct gl_bind {
@@ -78,7 +84,7 @@ struct gl_bind {
78
84
int src_type ;
79
85
void (* * transformations )(struct gl_data * , void * * , void * data );
80
86
size_t t_sz ;
81
- void * udata ;
87
+ struct sm_fb sm ;
82
88
};
83
89
84
90
/* GL screen framebuffer object */
@@ -112,6 +118,7 @@ struct gl_data {
112
118
copy_desktop , smooth_pass , premultiply_alpha , check_fullscreen ,
113
119
clickthrough ;
114
120
void * * t_data ;
121
+ size_t t_count ;
115
122
float gravity_step , target_spu , fr , ur , smooth_distance , smooth_ratio ,
116
123
smooth_factor , fft_scale , fft_cutoff ;
117
124
struct {
@@ -465,10 +472,9 @@ static struct gl_bind_src bind_sources[] = {
465
472
};
466
473
467
474
#define window (t , sz ) (0.53836 - (0.46164 * cos(TWOPI * (double) t / (double)(sz - 1))))
468
- #define ALLOC_ONCE (u , udata , ...) \
475
+ #define ALLOC_ONCE (u , udata , sz ) \
469
476
if (*udata == NULL) { \
470
- u = malloc(sizeof(*u)); \
471
- *u = (typeof(*u)) __VA_ARGS__; \
477
+ u = calloc(sz, sizeof(typeof(*u))); \
472
478
*udata = u; \
473
479
} else u = (typeof(u)) *udata;
474
480
@@ -529,18 +535,16 @@ void transform_gravity(struct gl_data* d, void** udata, void* data) {
529
535
float * b = s -> buf ;
530
536
size_t sz = s -> sz , t ;
531
537
532
- struct {
533
- float * applied ;
534
- }* u ;
535
- ALLOC_ONCE (u , udata , { .applied = calloc (sz , sizeof (float )) });
538
+ float * applied ;
539
+ ALLOC_ONCE (applied , udata , sz );
536
540
537
541
float g = d -> gravity_step * (1.0F / d -> ur );
538
542
539
543
for (t = 0 ; t < sz ; ++ t ) {
540
- if (b [t ] >= u -> applied [t ]) {
541
- u -> applied [t ] = b [t ] - g ;
542
- } else u -> applied [t ] -= g ;
543
- b [t ] = u -> applied [t ];
544
+ if (b [t ] >= applied [t ]) {
545
+ applied [t ] = b [t ] - g ;
546
+ } else applied [t ] -= g ;
547
+ b [t ] = applied [t ];
544
548
}
545
549
}
546
550
@@ -553,20 +557,18 @@ void transform_average(struct gl_data* d, void** udata, void* data) {
553
557
float v ;
554
558
bool use_window = d -> avg_window ;
555
559
556
- struct {
557
- float * bufs ;
558
- }* u ;
559
- ALLOC_ONCE (u , udata , { .bufs = calloc (tsz , sizeof (float )) });
560
+ float * bufs ;
561
+ ALLOC_ONCE (bufs , udata , tsz );
560
562
561
- memmove (u -> bufs , & u -> bufs [sz ], (tsz - sz ) * sizeof (float ));
562
- memcpy (& u -> bufs [tsz - sz ], b , sz * sizeof (float ));
563
+ memmove (bufs , & bufs [sz ], (tsz - sz ) * sizeof (float ));
564
+ memcpy (& bufs [tsz - sz ], b , sz * sizeof (float ));
563
565
564
566
#define DO_AVG (w ) \
565
567
do { \
566
568
for (t = 0; t < sz; ++t) { \
567
569
v = 0.0F; \
568
570
for (f = 0; f < d->avg_frames; ++f) { \
569
- v += w * u-> bufs[(f * sz) + t]; \
571
+ v += w * bufs[(f * sz) + t]; \
570
572
} \
571
573
b[t] = v / d->avg_frames; \
572
574
} \
@@ -1038,7 +1040,7 @@ struct renderer* rd_new(const char** paths, const char* entry,
1038
1040
.src_type = src -> src_type ,
1039
1041
.transformations = malloc (1 ),
1040
1042
.t_sz = 0 ,
1041
- .udata = NULL
1043
+ .sm = {}
1042
1044
};
1043
1045
})
1044
1046
},
@@ -1091,6 +1093,7 @@ struct renderer* rd_new(const char** paths, const char* entry,
1091
1093
};
1092
1094
1093
1095
ext_process (& ext , se_buf );
1096
+ ext_free (& ext );
1094
1097
1095
1098
munmap ((void * ) map , st .st_size );
1096
1099
@@ -1122,6 +1125,7 @@ struct renderer* rd_new(const char** paths, const char* entry,
1122
1125
1123
1126
loading_presets = true;
1124
1127
ext_process (& ext , se_buf );
1128
+ ext_free (& ext );
1125
1129
loading_presets = false;
1126
1130
1127
1131
munmap ((void * ) map , st .st_size );
@@ -1319,7 +1323,8 @@ struct renderer* rd_new(const char** paths, const char* entry,
1319
1323
}
1320
1324
1321
1325
{
1322
- gl -> t_data = malloc (sizeof (void * ) * t_count );
1326
+ gl -> t_data = malloc (sizeof (void * ) * t_count );
1327
+ gl -> t_count = t_count ;
1323
1328
size_t t ;
1324
1329
for (t = 0 ; t < t_count ; ++ t ) {
1325
1330
gl -> t_data [t ] = NULL ;
@@ -1544,20 +1549,10 @@ bool rd_update(struct renderer* r, float* lb, float* rb, size_t bsz, bool modifi
1544
1549
setup = true;
1545
1550
}
1546
1551
1547
- /* Per-bind data containing the framebuffer and 1D texture to render to for
1548
- this smoothing step. */
1549
-
1550
- struct sm_fb {
1551
- GLuint fbo , tex ;
1552
- };
1553
-
1554
1552
/* Allocate and setup our per-bind data, if needed */
1555
1553
1556
- struct sm_fb * sm ;
1557
- if (!bind -> udata ) {
1558
- sm = malloc (sizeof (struct sm_fb ));
1559
- bind -> udata = sm ;
1560
-
1554
+ struct sm_fb * sm = & bind -> sm ;
1555
+ if (sm -> tex == 0 ) {
1561
1556
glGenTextures (1 , & sm -> tex );
1562
1557
glGenFramebuffers (1 , & sm -> fbo );
1563
1558
@@ -1582,7 +1577,6 @@ bool rd_update(struct renderer* r, float* lb, float* rb, size_t bsz, bool modifi
1582
1577
}
1583
1578
} else {
1584
1579
/* Just bind our data if it was already allocated and setup */
1585
- sm = (struct sm_fb * ) bind -> udata ;
1586
1580
glBindFramebuffer (GL_FRAMEBUFFER , sm -> fbo );
1587
1581
glBindTexture (GL_TEXTURE_1D , sm -> tex );
1588
1582
}
@@ -1716,8 +1710,14 @@ struct gl_wcb* rd_get_wcb (struct renderer* r) { return r->gl->wcb; }
1716
1710
void rd_destroy (struct renderer * r ) {
1717
1711
r -> gl -> wcb -> destroy (r -> gl -> w );
1718
1712
if (r -> gl -> interpolate ) free (r -> gl -> interpolate_buf [0 ]);
1719
- if (r -> gl -> t_data ) free (r -> gl -> t_data );
1720
1713
size_t t , b ;
1714
+ if (r -> gl -> t_data ) {
1715
+ for (t = 0 ; t < r -> gl -> t_count ; ++ t ) {
1716
+ if (r -> gl -> t_data [t ])
1717
+ free (r -> gl -> t_data [t ]);
1718
+ }
1719
+ free (r -> gl -> t_data );
1720
+ }
1721
1721
for (t = 0 ; t < r -> gl -> stages_sz ; ++ t ) {
1722
1722
struct gl_sfbo * stage = & r -> gl -> stages [t ];
1723
1723
for (b = 0 ; b < stage -> binds_sz ; ++ b ) {
0 commit comments