Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

glw: Add support for fragmentshaders on image widget

This includes backdrop, frontdrop, image, icon and repeatedimage widgets
  • Loading branch information...
commit 509ba2d865684cd97e00e75ac65a56520190b80a 1 parent acc917b
Andreas Öman andoma authored

Showing 2 changed files with 48 additions and 12 deletions. Show diff stats Hide diff stats

  1. +36 7 src/ui/glw/glw_image.c
  2. +12 5 src/ui/glw/glw_opengl_shaders.c
43 src/ui/glw/glw_image.c
@@ -70,15 +70,15 @@ typedef struct glw_image {
70 70 #define GI_MODE_ALPHA_EDGES 3
71 71 #define GI_MODE_BORDER_ONLY_SCALING 4
72 72
73   - uint8_t gi_update;
74 73
75 74 uint8_t gi_alpha_edge;
76 75
77   - uint8_t gi_is_ready;
  76 + uint8_t gi_is_ready : 1;
  77 + uint8_t gi_update : 1;
  78 + uint8_t gi_need_reload : 1;
  79 + uint8_t gi_loading_new_url : 1;
  80 + uint8_t gi_recompile : 1;
78 81
79   - uint8_t gi_need_reload;
80   -
81   - uint8_t gi_loading_new_url;
82 82 int16_t gi_fixed_size;
83 83
84 84 glw_renderer_t gi_gr;
@@ -105,6 +105,9 @@ typedef struct glw_image {
105 105 int gi_switch_cnt;
106 106 int gi_switch_tgt;
107 107
  108 + glw_program_t *gi_prog;
  109 + rstr_t *gi_fs;
  110 +
108 111 } glw_image_t;
109 112
110 113 static glw_class_t glw_image, glw_icon, glw_backdrop, glw_repeatedimage,
@@ -161,6 +164,21 @@ glw_image_dtor(glw_t *w)
161 164 if(gi->gi_pending != NULL)
162 165 glw_tex_deref(w->glw_root, gi->gi_pending);
163 166 glw_renderer_free(&gi->gi_gr);
  167 + rstr_release(gi->gi_fs);
  168 + glw_destroy_program(w->glw_root, gi->gi_prog);
  169 +}
  170 +
  171 +
  172 +/**
  173 + *
  174 + */
  175 +static void
  176 +glw_image_set_fs(glw_t *w, rstr_t *fs)
  177 +{
  178 + glw_image_t *gi = (glw_image_t *)w;
  179 + rstr_set(&gi->gi_fs, fs);
  180 + gi->gi_recompile = 1;
  181 +
164 182 }
165 183
166 184 /**
@@ -242,6 +260,12 @@ glw_image_render(glw_t *w, const glw_rctx_t *rc)
242 260 float blur = 1 - (rc->rc_sharpness * w->glw_sharpness);
243 261 glw_rctx_t rc0;
244 262
  263 + if(gi->gi_recompile) {
  264 + glw_destroy_program(w->glw_root, gi->gi_prog);
  265 + gi->gi_prog = glw_make_program(w->glw_root, NULL, rstr_get(gi->gi_fs));
  266 + gi->gi_recompile = 0;
  267 + }
  268 +
245 269 alpha_self = rc->rc_alpha * w->glw_alpha * gi->gi_alpha_self * gi->gi_autofade;
246 270
247 271 if(gi->gi_mode == GI_MODE_NORMAL || gi->gi_mode == GI_MODE_ALPHA_EDGES) {
@@ -291,7 +315,7 @@ glw_image_render(glw_t *w, const glw_rctx_t *rc)
291 315 glw_renderer_draw(&gi->gi_gr, w->glw_root, &rc0,
292 316 &glt->glt_texture,
293 317 &gi->gi_col_mul, &gi->gi_col_off, alpha_self, blur,
294   - NULL);
  318 + gi->gi_prog);
295 319
296 320 if(gi->gi_bitmap_flags & GLW_IMAGE_ADDITIVE)
297 321 glw_blendmode(w->glw_root, GLW_BLEND_NORMAL);
@@ -316,7 +340,7 @@ glw_image_render(glw_t *w, const glw_rctx_t *rc)
316 340 glw_renderer_draw(&gi->gi_gr, w->glw_root, rc,
317 341 &glt->glt_texture,
318 342 &gi->gi_col_mul, &gi->gi_col_off, alpha_self, blur,
319   - NULL);
  343 + gi->gi_prog);
320 344
321 345 if(gi->gi_bitmap_flags & GLW_IMAGE_ADDITIVE)
322 346 glw_blendmode(w->glw_root, GLW_BLEND_NORMAL);
@@ -1388,6 +1412,7 @@ static glw_class_t glw_image = {
1388 1412 .gc_set_sources = set_sources,
1389 1413 .gc_set_alpha_self = set_alpha_self,
1390 1414 .gc_get_identity = get_identity,
  1415 + .gc_set_fs = glw_image_set_fs,
1391 1416 };
1392 1417
1393 1418 GLW_REGISTER_CLASS(glw_image);
@@ -1414,6 +1439,7 @@ static glw_class_t glw_icon = {
1414 1439 .gc_set_size_scale = set_size_scale,
1415 1440 .gc_set_default_size = set_default_size,
1416 1441 .gc_get_identity = get_identity,
  1442 + .gc_set_fs = glw_image_set_fs,
1417 1443 };
1418 1444
1419 1445 GLW_REGISTER_CLASS(glw_icon);
@@ -1440,6 +1466,7 @@ static glw_class_t glw_backdrop = {
1440 1466 .gc_set_sources = set_sources,
1441 1467 .gc_set_alpha_self = set_alpha_self,
1442 1468 .gc_get_identity = get_identity,
  1469 + .gc_set_fs = glw_image_set_fs,
1443 1470 };
1444 1471
1445 1472 GLW_REGISTER_CLASS(glw_backdrop);
@@ -1467,6 +1494,7 @@ static glw_class_t glw_frontdrop = {
1467 1494 .gc_set_sources = set_sources,
1468 1495 .gc_set_alpha_self = set_alpha_self,
1469 1496 .gc_get_identity = get_identity,
  1497 + .gc_set_fs = glw_image_set_fs,
1470 1498 };
1471 1499
1472 1500 GLW_REGISTER_CLASS(glw_frontdrop);
@@ -1491,6 +1519,7 @@ static glw_class_t glw_repeatedimage = {
1491 1519 .gc_set_source = set_source,
1492 1520 .gc_set_alpha_self = set_alpha_self,
1493 1521 .gc_get_identity = get_identity,
  1522 + .gc_set_fs = glw_image_set_fs,
1494 1523 };
1495 1524
1496 1525 GLW_REGISTER_CLASS(glw_repeatedimage);
17 src/ui/glw/glw_opengl_shaders.c
@@ -68,10 +68,17 @@ static glw_program_t *
68 68 get_program(const glw_backend_root_t *gbr,
69 69 const struct glw_backend_texture *t0,
70 70 const struct glw_backend_texture *t1,
71   - float blur, int flags)
  71 + float blur, int flags,
  72 + glw_program_t *up)
72 73 {
73 74 glw_program_t *gp;
74 75
  76 + if(up != NULL) {
  77 + if(t0 != NULL)
  78 + glBindTexture(gbr->gbr_primary_texture_mode, t0->tex);
  79 + return up;
  80 + }
  81 +
75 82 if(t0 == NULL) {
76 83
77 84 if(t1 != NULL) {
@@ -136,8 +143,8 @@ render_unlocked(glw_root_t *gr)
136 143 for(i = 0; i < gbr->gbr_num_render_jobs; i++, rj++) {
137 144
138 145 const struct glw_backend_texture *t0 = rj->t0;
139   - glw_program_t *gp = get_program(gbr, t0, rj->t1, rj->blur, rj->flags);
140   -
  146 + glw_program_t *gp = get_program(gbr, t0, rj->t1, rj->blur, rj->flags, NULL);
  147 + abort(); // Fix user programs
141 148 if(gp == NULL)
142 149 continue;
143 150
@@ -311,11 +318,11 @@ shader_render(struct glw_root *root,
311 318 const uint16_t *indices,
312 319 int num_triangles,
313 320 int flags,
314   - glw_program_t *p,
  321 + glw_program_t *up,
315 322 const glw_rctx_t *rc)
316 323 {
317 324 glw_backend_root_t *gbr = &root->gr_be;
318   - glw_program_t *gp = p ?: get_program(gbr, t0, t1, blur, flags);
  325 + glw_program_t *gp = get_program(gbr, t0, t1, blur, flags, up);
319 326
320 327 if(gp == NULL)
321 328 return;

0 comments on commit 509ba2d

Please sign in to comment.
Something went wrong with that request. Please try again.