@@ -26,17 +26,22 @@ static uint32_t intermediate_textures[SHADER_PRESET_MAX_PASSES - 1];
2626static uint32_t intermediate_fbos[SHADER_PRESET_MAX_PASSES - 1 ];
2727static int intermediate_widths[SHADER_PRESET_MAX_PASSES - 1 ];
2828static int intermediate_heights[SHADER_PRESET_MAX_PASSES - 1 ];
29+ static bool intermediate_filter_linears[SHADER_PRESET_MAX_PASSES - 1 ];
2930static bool intermediate_float_framebuffers[SHADER_PRESET_MAX_PASSES - 1 ];
3031static uint32_t pass_history_textures[SHADER_PRESET_MAX_PASSES][SHADER_PRESET_MAX_HISTORY_TEXTURES];
3132static int pass_history_widths[SHADER_PRESET_MAX_PASSES];
3233static int pass_history_heights[SHADER_PRESET_MAX_PASSES];
34+ static bool pass_history_filter_linears[SHADER_PRESET_MAX_PASSES];
3335static int pass_history_counts[SHADER_PRESET_MAX_PASSES];
3436static int pass_history_write_indices[SHADER_PRESET_MAX_PASSES];
3537static bool pass_history_float_framebuffers[SHADER_PRESET_MAX_PASSES];
3638static int source_width = 1 ;
3739static int source_height = 1 ;
40+ static bool source_filter_linear = false ;
3841static int pass_width = 1 ;
3942static int pass_height = 1 ;
43+ static bool pass_filter_linear = false ;
44+ static bool feedback_filter_linear = false ;
4045static bool pass_float_framebuffer = false ;
4146static bool initialized = false ;
4247static const char * framebuffer_name = " shader-chain framebuffer" ;
@@ -98,8 +103,11 @@ bool ogl_shader_chain_init(const char* name)
98103 framebuffer_name = name ? name : " shader-chain framebuffer" ;
99104 source_width = 1 ;
100105 source_height = 1 ;
106+ source_filter_linear = false ;
101107 pass_width = 1 ;
102108 pass_height = 1 ;
109+ pass_filter_linear = false ;
110+ feedback_filter_linear = false ;
103111 pass_float_framebuffer = false ;
104112
105113 glGenTextures (1 , &source_texture);
@@ -127,13 +135,15 @@ bool ogl_shader_chain_init(const char* name)
127135 intermediate_fbos[i] = 0 ;
128136 intermediate_widths[i] = 1 ;
129137 intermediate_heights[i] = 1 ;
138+ intermediate_filter_linears[i] = false ;
130139 intermediate_float_framebuffers[i] = false ;
131140 }
132141
133142 for (int i = 0 ; i < SHADER_PRESET_MAX_PASSES; i++)
134143 {
135144 pass_history_widths[i] = 1 ;
136145 pass_history_heights[i] = 1 ;
146+ pass_history_filter_linears[i] = false ;
137147 pass_history_counts[i] = 0 ;
138148 pass_history_write_indices[i] = 0 ;
139149 pass_history_float_framebuffers[i] = false ;
@@ -175,6 +185,7 @@ void ogl_shader_chain_destroy(void)
175185
176186 pass_history_widths[i] = 1 ;
177187 pass_history_heights[i] = 1 ;
188+ pass_history_filter_linears[i] = false ;
178189 pass_history_counts[i] = 0 ;
179190 pass_history_write_indices[i] = 0 ;
180191 pass_history_float_framebuffers[i] = false ;
@@ -197,8 +208,12 @@ void ogl_shader_chain_destroy(void)
197208 source_texture = 0 ;
198209 source_width = 1 ;
199210 source_height = 1 ;
211+ source_filter_linear = false ;
200212 pass_width = 1 ;
201213 pass_height = 1 ;
214+ pass_filter_linear = false ;
215+ feedback_filter_linear = false ;
216+ pass_float_framebuffer = false ;
202217 initialized = false ;
203218}
204219
@@ -225,11 +240,16 @@ bool ogl_shader_chain_update_source_texture(const OglShaderChainSourceTexture* t
225240 resize_texture_2d (source_texture, width, height, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, NULL , texture->filter_linear );
226241 source_width = width;
227242 source_height = height;
243+ source_filter_linear = texture->filter_linear ;
228244 }
229245
230246 glBindTexture (GL_TEXTURE_2D, source_texture);
231247 glTexSubImage2D (GL_TEXTURE_2D, 0 , 0 , 0 , width, height, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels );
232- configure_texture_2d (texture->filter_linear );
248+ if (source_filter_linear != texture->filter_linear )
249+ {
250+ configure_texture_2d (texture->filter_linear );
251+ source_filter_linear = texture->filter_linear ;
252+ }
233253
234254 return true ;
235255}
@@ -249,10 +269,20 @@ bool ogl_shader_chain_resize_pass_texture(const OglShaderChainFramebufferTexture
249269
250270 if (pass_width == width && pass_height == height && pass_float_framebuffer == texture->float_framebuffer )
251271 {
252- glBindTexture (GL_TEXTURE_2D, pass_texture);
253- configure_texture_2d (texture->filter_linear );
254- glBindTexture (GL_TEXTURE_2D, feedback_texture);
255- configure_texture_2d (texture->filter_linear );
272+ if (pass_filter_linear != texture->filter_linear )
273+ {
274+ glBindTexture (GL_TEXTURE_2D, pass_texture);
275+ configure_texture_2d (texture->filter_linear );
276+ pass_filter_linear = texture->filter_linear ;
277+ }
278+
279+ if (feedback_filter_linear != texture->filter_linear )
280+ {
281+ glBindTexture (GL_TEXTURE_2D, feedback_texture);
282+ configure_texture_2d (texture->filter_linear );
283+ feedback_filter_linear = texture->filter_linear ;
284+ }
285+
256286 return true ;
257287 }
258288
@@ -267,6 +297,8 @@ bool ogl_shader_chain_resize_pass_texture(const OglShaderChainFramebufferTexture
267297 {
268298 pass_width = width;
269299 pass_height = height;
300+ pass_filter_linear = texture->filter_linear ;
301+ feedback_filter_linear = texture->filter_linear ;
270302 pass_float_framebuffer = texture->float_framebuffer ;
271303 clear_feedback_texture ();
272304 }
@@ -292,8 +324,13 @@ bool ogl_shader_chain_resize_intermediate_texture(int index, const OglShaderChai
292324
293325 if (intermediate_widths[index] == width && intermediate_heights[index] == height && intermediate_float_framebuffers[index] == texture->float_framebuffer )
294326 {
295- glBindTexture (GL_TEXTURE_2D, intermediate_textures[index]);
296- configure_texture_2d (texture->filter_linear );
327+ if (intermediate_filter_linears[index] != texture->filter_linear )
328+ {
329+ glBindTexture (GL_TEXTURE_2D, intermediate_textures[index]);
330+ configure_texture_2d (texture->filter_linear );
331+ intermediate_filter_linears[index] = texture->filter_linear ;
332+ }
333+
297334 return true ;
298335 }
299336
@@ -302,6 +339,7 @@ bool ogl_shader_chain_resize_intermediate_texture(int index, const OglShaderChai
302339
303340 intermediate_widths[index] = width;
304341 intermediate_heights[index] = height;
342+ intermediate_filter_linears[index] = texture->filter_linear ;
305343 intermediate_float_framebuffers[index] = texture->float_framebuffer ;
306344 return true ;
307345}
@@ -534,27 +572,6 @@ void ogl_shader_chain_apply_preset_uniforms(int index, const OglShaderChainUnifo
534572 if (!state->program )
535573 return ;
536574
537- if (state->uniform_source >= 0 )
538- glUniform1i (state->uniform_source , 0 );
539-
540- if (state->uniform_original >= 0 )
541- glUniform1i (state->uniform_original , 1 );
542-
543- if (state->uniform_feedback >= 0 )
544- glUniform1i (state->uniform_feedback , 2 );
545-
546- for (int i = 0 ; i < SHADER_PRESET_MAX_HISTORY_TEXTURES; i++)
547- {
548- if (state->uniform_source_history [i] >= 0 )
549- glUniform1i (state->uniform_source_history [i], 3 + i);
550- }
551-
552- for (int i = 0 ; i < SHADER_PRESET_MAX_PASS_OUTPUT_TEXTURES; i++)
553- {
554- if (state->uniform_pass_output [i] >= 0 )
555- glUniform1i (state->uniform_pass_output [i], 3 + SHADER_PRESET_MAX_HISTORY_TEXTURES + i);
556- }
557-
558575 if (state->uniform_source_size >= 0 )
559576 glUniform4f (state->uniform_source_size , (float )uniforms->input_width , (float )uniforms->input_height , safe_inverse (uniforms->input_width ), safe_inverse (uniforms->input_height ));
560577
@@ -671,7 +688,6 @@ bool ogl_shader_chain_store_pass_history(int index, uint32_t texture, int width,
671688
672689 glBindTexture (GL_TEXTURE_2D, target_texture);
673690 glCopyTexSubImage2D (GL_TEXTURE_2D, 0 , 0 , 0 , 0 , 0 , pass_history_widths[index], pass_history_heights[index]);
674- configure_texture_2d (filter_linear);
675691
676692 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0 , 0 );
677693 glBindFramebuffer (GL_FRAMEBUFFER, 0 );
@@ -896,6 +912,7 @@ static void release_intermediate_textures(int keep_count)
896912 intermediate_textures[i] = 0 ;
897913 intermediate_widths[i] = 1 ;
898914 intermediate_heights[i] = 1 ;
915+ intermediate_filter_linears[i] = false ;
899916 intermediate_float_framebuffers[i] = false ;
900917 }
901918}
@@ -957,39 +974,50 @@ static bool resize_pass_history_textures(int index, int width, int height, bool
957974 height = 1 ;
958975
959976 bool same_size = pass_history_widths[index] == width && pass_history_heights[index] == height && pass_history_float_framebuffers[index] == float_framebuffer;
977+ bool same_filter = pass_history_filter_linears[index] == filter_linear;
960978 int internal_format = float_framebuffer ? GL_RGBA16F : GL_RGBA8;
961979 uint32_t type = float_framebuffer ? GL_FLOAT : GL_UNSIGNED_BYTE;
962- bool created = false ;
980+ bool needs_create = false ;
981+
982+ for (int i = 0 ; i < SHADER_PRESET_MAX_HISTORY_TEXTURES; i++)
983+ {
984+ if (!pass_history_textures[index][i])
985+ needs_create = true ;
986+ }
987+
988+ bool resize = !same_size || needs_create;
963989
964990 for (int i = 0 ; i < SHADER_PRESET_MAX_HISTORY_TEXTURES; i++)
965991 {
966992 if (!pass_history_textures[index][i])
967- {
968993 glGenTextures (1 , &pass_history_textures[index][i]);
969- created = true ;
970- }
971994
972995 if (!pass_history_textures[index][i])
973996 return false ;
974997
975- if (same_size && !created )
998+ if (resize )
976999 {
977- glBindTexture (GL_TEXTURE_2D, pass_history_textures[index][i]);
978- configure_texture_2d (filter_linear);
1000+ resize_texture_2d (pass_history_textures[index][i], width, height, internal_format, GL_RGBA, type, NULL , filter_linear);
9791001 }
980- else
1002+ else if (!same_filter)
9811003 {
982- resize_texture_2d (pass_history_textures[index][i], width, height, internal_format, GL_RGBA, type, NULL , filter_linear);
1004+ glBindTexture (GL_TEXTURE_2D, pass_history_textures[index][i]);
1005+ configure_texture_2d (filter_linear);
9831006 }
9841007 }
9851008
986- if (!same_size || created )
1009+ if (resize )
9871010 {
9881011 pass_history_widths[index] = width;
9891012 pass_history_heights[index] = height;
1013+ pass_history_filter_linears[index] = filter_linear;
9901014 pass_history_float_framebuffers[index] = float_framebuffer;
9911015 clear_pass_history_textures (index);
9921016 }
1017+ else if (!same_filter)
1018+ {
1019+ pass_history_filter_linears[index] = filter_linear;
1020+ }
9931021
9941022 return true ;
9951023}
0 commit comments