libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moTextureFilter.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moTextureFilter.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moTextureFilter.h"
33 #include "moEffect.h"
34 #include "moArray.h"
35 moDefineDynamicArray(moTextureFilterArray)
36 
38 {
39  ZeroMatrix();
40 }
41 
43 {
44  Finish();
45 }
46 
48 {
49 }
50 
52 {
53 }
54 
56 {
57  int i, j;
58  for (j = 0; j < 4; j++)
59  for (i = 0; i < 4; i++)
60  m_Matrix[MatIdx(i, j)] = p_mat.m_Matrix[MatIdx(i, j)];
61 }
62 
64 {
65  int i, j;
66  for (j = 0; j < 4; j++)
67  for (i = 0; i < 4; i++)
68  m_MatrixChg[MatIdx(i, j)] = p_mat.m_Matrix[MatIdx(i, j)];
69 
71 }
72 
74 {
75  for (int j = 0; j < 4; j++)
76  for (int i = 0; i < 4; i++)
77  m_Matrix[MatIdx(i, j)] = 0.0;
78 }
79 
81 {
82  for (int j = 0; j < 4; j++)
83  for (int i = 0; i < 4; i++)
84  m_Matrix[MatIdx(i, j)] = i == j;
85 }
86 
87 void moColorMatrix::SetXRotateMatrix(float rs, float rc)
88 {
89  m_MatrixChg[MatIdx(0, 0)] = 1.0;
90  m_MatrixChg[MatIdx(0, 1)] = 0.0;
91  m_MatrixChg[MatIdx(0, 2)] = 0.0;
92  m_MatrixChg[MatIdx(0, 3)] = 0.0;
93 
94  m_MatrixChg[MatIdx(1, 0)] = 0.0;
95  m_MatrixChg[MatIdx(1, 1)] = rc;
96  m_MatrixChg[MatIdx(1, 2)] = rs;
97  m_MatrixChg[MatIdx(1, 3)] = 0.0;
98 
99  m_MatrixChg[MatIdx(2, 0)] = 0.0;
100  m_MatrixChg[MatIdx(2, 1)] = -rs;
101  m_MatrixChg[MatIdx(2, 2)] = rc;
102  m_MatrixChg[MatIdx(2, 3)] = 0.0;
103 
104  m_MatrixChg[MatIdx(3, 0)] = 0.0;
105  m_MatrixChg[MatIdx(3, 1)] = 0.0;
106  m_MatrixChg[MatIdx(3, 2)] = 0.0;
107  m_MatrixChg[MatIdx(3, 3)] = 1.0;
108 }
109 
110 void moColorMatrix::SetYRotateMatrix(float rs, float rc)
111 {
112  m_MatrixChg[MatIdx(0, 0)] = rc;
113  m_MatrixChg[MatIdx(0, 1)] = 0.0;
114  m_MatrixChg[MatIdx(0, 2)] = -rs;
115  m_MatrixChg[MatIdx(0, 3)] = 0.0;
116 
117  m_MatrixChg[MatIdx(1, 0)] = 0.0;
118  m_MatrixChg[MatIdx(1, 1)] = 1.0;
119  m_MatrixChg[MatIdx(1, 2)] = 0.0;
120  m_MatrixChg[MatIdx(1, 3)] = 0.0;
121 
122  m_MatrixChg[MatIdx(2, 0)] = rs;
123  m_MatrixChg[MatIdx(2, 1)] = 0.0;
124  m_MatrixChg[MatIdx(2, 2)] = rc;
125  m_MatrixChg[MatIdx(2, 3)] = 0.0;
126 
127  m_MatrixChg[MatIdx(3, 0)] = 0.0;
128  m_MatrixChg[MatIdx(3, 1)] = 0.0;
129  m_MatrixChg[MatIdx(3, 2)] = 0.0;
130  m_MatrixChg[MatIdx(3, 3)] = 1.0;
131 }
132 
133 void moColorMatrix::SetZRotateMatrix(float rs, float rc)
134 {
135  m_MatrixChg[MatIdx(0, 0)] = rc;
136  m_MatrixChg[MatIdx(0, 1)] = rs;
137  m_MatrixChg[MatIdx(0, 2)] = 0.0;
138  m_MatrixChg[MatIdx(0, 3)] = 0.0;
139 
140  m_MatrixChg[MatIdx(1, 0)] = -rs;
141  m_MatrixChg[MatIdx(1, 1)] = rc;
142  m_MatrixChg[MatIdx(1, 2)] = 0.0;
143  m_MatrixChg[MatIdx(1, 3)] = 0.0;
144 
145  m_MatrixChg[MatIdx(2, 0)] = 0.0;
146  m_MatrixChg[MatIdx(2, 1)] = 0.0;
147  m_MatrixChg[MatIdx(2, 2)] = 1.0;
148  m_MatrixChg[MatIdx(2, 3)] = 0.0;
149 
150  m_MatrixChg[MatIdx(3, 0)] = 0.0;
151  m_MatrixChg[MatIdx(3, 1)] = 0.0;
152  m_MatrixChg[MatIdx(3, 2)] = 0.0;
153  m_MatrixChg[MatIdx(3, 3)] = 1.0;
154 }
155 
156 void moColorMatrix::SetZShearMatrix(float dx, float dy)
157 {
158  m_MatrixChg[MatIdx(0, 0)] = 1.0;
159  m_MatrixChg[MatIdx(0, 1)] = 0.0;
160  m_MatrixChg[MatIdx(0, 2)] = dx;
161  m_MatrixChg[MatIdx(0, 3)] = 0.0;
162 
163  m_MatrixChg[MatIdx(1, 0)] = 0.0;
164  m_MatrixChg[MatIdx(1, 1)] = 1.0;
165  m_MatrixChg[MatIdx(1, 2)] = dy;
166  m_MatrixChg[MatIdx(1, 3)] = 0.0;
167 
168  m_MatrixChg[MatIdx(2, 0)] = 0.0;
169  m_MatrixChg[MatIdx(2, 1)] = 0.0;
170  m_MatrixChg[MatIdx(2, 2)] = 1.0;
171  m_MatrixChg[MatIdx(2, 3)] = 0.0;
172 
173  m_MatrixChg[MatIdx(3, 0)] = 0.0;
174  m_MatrixChg[MatIdx(3, 1)] = 0.0;
175  m_MatrixChg[MatIdx(3, 2)] = 0.0;
176  m_MatrixChg[MatIdx(3, 3)] = 1.0;
177 }
178 
179 void moColorMatrix::XFormPoint(float &tx, float &ty, float &tz)
180 {
181  float x = RLUM;
182  float y = GLUM;
183  float z = BLUM;
184 
185  tx = x * m_Matrix[MatIdx(0, 0)] + y * m_Matrix[MatIdx(1, 0)] + z * m_Matrix[MatIdx(2, 0)] + m_Matrix[MatIdx(3, 0)];
186  ty = x * m_Matrix[MatIdx(0, 1)] + y * m_Matrix[MatIdx(1, 1)] + z * m_Matrix[MatIdx(2, 1)] + m_Matrix[MatIdx(3, 1)];
187  tz = x * m_Matrix[MatIdx(0, 2)] + y * m_Matrix[MatIdx(1, 2)] + z * m_Matrix[MatIdx(2, 2)] + m_Matrix[MatIdx(3, 2)];
188 }
189 
191 {
192  int i, j, k;
193 
194  for (j = 0; j < 4; j++)
195  for (i = 0; i < 4; i++)
196  {
197  m_MatrixTemp[MatIdx(i, j)] = 0.0;
198  for (k = 0; k < 4; k++)
199  m_MatrixTemp[MatIdx(i, j)] += m_Matrix[MatIdx(i, k)]* m_MatrixChg[MatIdx(k, j)];
200  }
201 
202  for (j = 0; j < 4; j++)
203  for (i = 0; i < 4; i++)
204  m_Matrix[MatIdx(i, j)] = m_MatrixTemp[MatIdx(i, j)];
205 }
206 
208 {
209 
210  m_PreserveLuminance = true;
211 }
212 
214 {
215  Finish();
216 }
217 
218 void moHueSatIntMatrix::Init(MOboolean p_PreserveLuminance,
219  MOfloat p_min_int, MOfloat p_max_int,
220  MOfloat p_min_sat, MOfloat p_max_sat,
221  MOfloat p_min_hue, MOfloat p_max_hue)
222 {
224 
225  m_PreserveLuminance = p_PreserveLuminance;
226 
227  m_min_int = p_min_int;
228  m_max_int = p_max_int;
229 
230  m_min_sat = p_min_sat;
231  m_max_sat = p_max_sat;
232 
233  m_min_hue = p_min_hue;
234  m_max_hue = p_max_hue;
235 }
236 
238 {
240 }
241 
243 {
244  m_int = m_min_int + p_int * (m_max_int - m_min_int);
245  m_sat = m_min_sat + p_sat * (m_max_sat - m_min_sat);
246  m_hue = m_min_hue + p_hue * (m_max_hue - m_min_hue);
247 
248  m_int = momax(1e-3, m_int);
249 
250  IdentityMatrix();
251  IntensityMatrix();
252  SaturateMatrix();
254  else SimpleHueRotateMatrix();
255 }
256 
258 {
259  m_MatrixChg[MatIdx(0, 0)] = m_int;
260  m_MatrixChg[MatIdx(0, 1)] = 0.0;
261  m_MatrixChg[MatIdx(0, 2)] = 0.0;
262  m_MatrixChg[MatIdx(0, 3)] = 0.0;
263 
264  m_MatrixChg[MatIdx(1, 0)] = 0.0;
265  m_MatrixChg[MatIdx(1, 1)] = m_int;
266  m_MatrixChg[MatIdx(1, 2)] = 0.0;
267  m_MatrixChg[MatIdx(1, 3)] = 0.0;
268 
269  m_MatrixChg[MatIdx(2, 0)] = 0.0;
270  m_MatrixChg[MatIdx(2, 1)] = 0.0;
271  m_MatrixChg[MatIdx(2, 2)] = m_int;
272  m_MatrixChg[MatIdx(2, 3)] = 0.0;
273 
274  m_MatrixChg[MatIdx(3, 0)] = 0.0;
275  m_MatrixChg[MatIdx(3, 1)] = 0.0;
276  m_MatrixChg[MatIdx(3, 2)] = 0.0;
277  m_MatrixChg[MatIdx(3, 3)] = 1.0;
278 
279  ApplyChgMatrix();
280 }
281 
283 {
284  MOfloat a, b, c, d, e, f, g, h, i;
285  MOfloat rs = (1.0 - m_sat);
286 
287  a = (rs * RLUM + m_sat);
288  b = (rs * RLUM);
289  c = (rs * RLUM);
290  d = (rs * GLUM);
291  e = (rs * GLUM + m_sat);
292  f = (rs * GLUM);
293  g = (rs * BLUM);
294  h = (rs * BLUM);
295  i = (rs * BLUM + m_sat);
296 
297  m_MatrixChg[MatIdx(0, 0)] = a;
298  m_MatrixChg[MatIdx(0, 1)] = b;
299  m_MatrixChg[MatIdx(0, 2)] = c;
300  m_MatrixChg[MatIdx(0, 3)] = 0.0;
301 
302  m_MatrixChg[MatIdx(1, 0)] = d;
303  m_MatrixChg[MatIdx(1, 1)] = e;
304  m_MatrixChg[MatIdx(1, 2)] = f;
305  m_MatrixChg[MatIdx(1, 3)] = 0.0;
306 
307  m_MatrixChg[MatIdx(2, 0)] = g;
308  m_MatrixChg[MatIdx(2, 1)] = h;
309  m_MatrixChg[MatIdx(2, 2)] = i;
310  m_MatrixChg[MatIdx(2, 3)] = 0.0;
311 
312  m_MatrixChg[MatIdx(3, 0)] = 0.0;
313  m_MatrixChg[MatIdx(3, 1)] = 0.0;
314  m_MatrixChg[MatIdx(3, 2)] = 0.0;
315  m_MatrixChg[MatIdx(3, 3)] = 1.0;
316 
317  ApplyChgMatrix();
318 }
319 
320 // Hue rotation that preserves luminance.
322 {
323  float mag;
324  float lx, ly, lz;
325  float xrs, xrc;
326  float yrs, yrc;
327  float zrs, zrc;
328  float zsx, zsy;
329 
330  // rotate the grey vector into positive Z.
331  mag = sqrt(2.0);
332  xrs = 1.0 / mag;
333  xrc = 1.0 / mag;
334  SetXRotateMatrix(xrs, xrc);
335  ApplyChgMatrix();
336 
337  mag = sqrt(3.0);
338  yrs = -1.0 / mag;
339  yrc = sqrt(2.0) / mag;
340  SetYRotateMatrix(yrs, yrc);
341  ApplyChgMatrix();
342 
343  // shear the space to make the luminance plane horizontal.
344  XFormPoint(lx, ly, lz);
345  zsx = lx / lz;
346  zsy = ly / lz;
347  SetZShearMatrix(zsx, zsy);
348  ApplyChgMatrix();
349 
350  // rotate the hue.
351  zrs = sin(m_hue);
352  zrc = cos(m_hue);
353  SetZRotateMatrix(zrs, zrc);
354  ApplyChgMatrix();
355 
356  // unshear the space to put the luminance plane back.
357  SetZShearMatrix(-zsx, -zsy);
358  ApplyChgMatrix();
359 
360  // rotate the grey vector back into place.
361  SetYRotateMatrix(-yrs, yrc);
362  ApplyChgMatrix();
363  SetXRotateMatrix(-xrs,xrc);
364  ApplyChgMatrix();
365 }
366 
368 {
369  MOfloat mag;
370  MOfloat xrs, xrc;
371  MOfloat yrs, yrc;
372  MOfloat zrs, zrc;
373 
374  // rotate the grey vector into positive Z.
375  mag = sqrt(2.0);
376  xrs = 1.0/mag;
377  xrc = 1.0/mag;
378  SetXRotateMatrix(xrs, xrc);
379  ApplyChgMatrix();
380 
381  mag = sqrt(3.0);
382  yrs = -1.0/mag;
383  yrc = sqrt(2.0)/mag;
384  SetYRotateMatrix(yrs, yrc);
385  ApplyChgMatrix();
386 
387  // rotate the hue
388  zrs = sin(m_hue);
389  zrc = cos(m_hue);
390  SetZRotateMatrix(zrs, zrc);
391  ApplyChgMatrix();
392 
393  // rotate the grey vector back into place.
394  SetYRotateMatrix(-yrs, yrc);
395  ApplyChgMatrix();
396  SetXRotateMatrix(-xrs, xrc);
397  ApplyChgMatrix();
398 }
399 
401 {
402 }
403 
405 {
406  Finish();
407 }
408 
409 void moBrightContMatrix::Init(MOfloat p_min_bright, MOfloat p_max_bright,
410  MOfloat p_min_cont, MOfloat p_max_cont)
411 {
413 
414  m_min_bright = p_min_bright;
415  m_max_bright = p_max_bright;
416 
417  m_min_cont = p_min_cont;
418  m_max_cont = p_max_cont;
419 }
420 
422 {
424 }
425 
427 {
428  m_bright = m_min_bright + p_bright * (m_max_bright - m_min_bright);
429  m_cont = m_min_cont + p_cont * (m_max_cont - m_min_cont);
430 
431  IdentityMatrix();
433  ContrastMatrix();
434 }
435 
437 {
438  m_MatrixChg[MatIdx(0, 0)] = 1.0;
439  m_MatrixChg[MatIdx(0, 1)] = 0.0;
440  m_MatrixChg[MatIdx(0, 2)] = 0.0;
441  m_MatrixChg[MatIdx(0, 3)] = 0.0;
442 
443  m_MatrixChg[MatIdx(1, 0)] = 0.0;
444  m_MatrixChg[MatIdx(1, 1)] = 1.0;
445  m_MatrixChg[MatIdx(1, 2)] = 0.0;
446  m_MatrixChg[MatIdx(1, 3)] = 0.0;
447 
448  m_MatrixChg[MatIdx(2, 0)] = 0.0;
449  m_MatrixChg[MatIdx(2, 1)] = 0.0;
450  m_MatrixChg[MatIdx(2, 2)] = 1.0;
451  m_MatrixChg[MatIdx(2, 3)] = 0.0;
452 
453  m_MatrixChg[MatIdx(3, 0)] = m_bright;
454  m_MatrixChg[MatIdx(3, 1)] = m_bright;
455  m_MatrixChg[MatIdx(3, 2)] = m_bright;
456  m_MatrixChg[MatIdx(3, 3)] = 1.0;
457 
458  ApplyChgMatrix();
459 }
460 
462 {
463  m_MatrixChg[MatIdx(0, 0)] = m_cont;
464  m_MatrixChg[MatIdx(0, 1)] = 0.0;
465  m_MatrixChg[MatIdx(0, 2)] = 0.0;
466  m_MatrixChg[MatIdx(0, 3)] = 0.0;
467 
468  m_MatrixChg[MatIdx(1, 0)] = 0.0;
469  m_MatrixChg[MatIdx(1, 1)] = m_cont;
470  m_MatrixChg[MatIdx(1, 2)] = 0.0;
471  m_MatrixChg[MatIdx(1, 3)] = 0.0;
472 
473  m_MatrixChg[MatIdx(2, 0)] = 0.0;
474  m_MatrixChg[MatIdx(2, 1)] = 0.0;
475  m_MatrixChg[MatIdx(2, 2)] = m_cont;
476  m_MatrixChg[MatIdx(2, 3)] = 0.0;
477 
478  m_MatrixChg[MatIdx(3, 0)] = (1.0 - m_cont) * 0.5;
479  m_MatrixChg[MatIdx(3, 1)] = (1.0 - m_cont) * 0.5;
480  m_MatrixChg[MatIdx(3, 2)] = (1.0 - m_cont) * 0.5;
481  m_MatrixChg[MatIdx(3, 3)] = 1.0;
482 
483  ApplyChgMatrix();
484 }
485 
486 //===========================================
487 //
488 // moTextureFilter
489 //
490 //===========================================
491 
492 
494  m_glman = NULL;
495  m_renderman = NULL;
496  m_shader = NULL;
498  m_uniform_idx = -1;
499 }
500 
501 
502 MOboolean moTextureFilter::Init(moGLManager* p_glman, moRenderManager* p_renderman, moTextureArray &p_src_tex, moTextureArray &p_dest_tex, moShader *p_shader, const moTextFilterParam& p_params)
503 {
504  MOuint i;
505  moText uname;
506 
507  m_glman = p_glman;
508  m_renderman = p_renderman;
509 
510  if (p_shader) {
511 
512  }
513 
514  m_use_screen_tex = false;
515  for (i = 0; i < p_src_tex.Count(); i++)
516  {
517  m_src_tex.Add(p_src_tex[i]);
518  if (p_src_tex[i]->GetName() == moText("screen_texture")) m_use_screen_tex = true;
519  }
520  for (i = 0; i < p_dest_tex.Count(); i++) {
521  m_dest_tex.Add(p_dest_tex[i]);
522  }
524 
525  m_shader = p_shader;
526  moShaderGLSL* pglsl = NULL;
527 
528 #ifdef SHADER_CG
529  moShaderCG* pcg = NULL;
530 #endif
531 
532  if (m_shader->GetType()==MO_SHADER_CG) {
533 #ifdef SHADER_CG
534  pcg = (moShaderCG*)m_shader;
535 #endif
536  } else {
537  pglsl = (moShaderGLSL*)m_shader;
538  }
539 
540 
541  if (pglsl) {
542  pglsl->PrintVertShaderLog();
543  pglsl->PrintFragShaderLog();
544  }
545 
546  // Gettting uniform parameters.
547  for (i = 0; i < m_src_tex.Count(); i++)
548  {
549  uname = moText("src_tex_unit") + IntToStr(i);
550 
551  if (pglsl) m_src_tex_unit[i] = pglsl->GetUniformID(uname);
552 
553  uname = moText("src_tex_offset") + IntToStr(i);
554 
555  if (pglsl) m_src_tex_offset[i] = pglsl->GetUniformID(uname);
556 
557  }
558 
559  uname = moText("tempo_angle");
560  if (pglsl) m_tempo_angle = pglsl->GetUniformID(uname);
561 
562  uname = moText("dest_tex_size");
563  if (pglsl) m_dest_tex_size = pglsl->GetUniformID(uname);
564 
565  uname = moText("fade_const");
566  if (pglsl) m_fade_const = pglsl->GetUniformID(uname);
567 
568  uname = moText("tempo_dt");
569  if (pglsl) m_tempo_dt = pglsl->GetUniformID(uname);
570 
571  uname = moText("tempo_delta");
572  if (pglsl) m_tempo_delta = pglsl->GetUniformID(uname);
573 
574  uname = moText("tempo_syncro");
575  if (pglsl) m_tempo_syncro = pglsl->GetUniformID(uname);
576 
577  uname = moText("tempo_ticks");
578  if (pglsl) m_tempo_ticks = pglsl->GetUniformID(uname);
579 
580  uname = moText("dest_tex_size");
581  if (pglsl) m_dest_tex_size = pglsl->GetUniformID(uname);
582 
583  uname = moText("fade_const");
584  if (pglsl) m_fade_const = pglsl->GetUniformID(uname);
585 
586  uname = moText("random_uniform");
587  if (pglsl) m_random_uniform = pglsl->GetUniformID(uname);
588  //MODebug2->Message("moTextureFilter::Init >"+uname+" idx:"+IntToStr(m_random_uniform));
589 
590  m_uniform_idx = -1;
591  for(int u=0; u<MAX_UNIFORM_VARS; u++ ) {
592  m_uniform_variables_idx[u] = -1;
593  }
594 
595  if (m_shader) {
596  //do something
597  //p_src_object = NULL;
598  if (m_uniform_idx==-1) {
600  //MODebug2->Message("moTextureFilter::Init > founded uniform param in: m_uniform_idx:"+IntToStr(m_uniform_idx));
601  }
602 
603  if (m_uniform_idx>-1) {
604  for( int u=0; u<m_shader->m_Config.GetParam(m_uniform_idx).GetValuesCount(); u++ ) {
606  moText uniform_var_name = vb.GetSubValue(0).GetData()->Text();
607  moText uniform_var_type = vb.GetSubValue(1).GetData()->Text();
608  uname = uniform_var_name;
609  if (m_uniform_variables_idx[u]==-1 && pglsl) {
610  m_uniform_variables_idx[u] = pglsl->GetUniformID(uname);
611  //MODebug2->Message("moTextureFilter::Init > setting uniform id for ("+uname+","+uniform_var_type+") in:"+IntToStr(m_uniform_variables_idx[u]));
612  }
613  }
614  }
615  }
616 
617 
618  m_DefParams = p_params;
619  if (pglsl) {
620  m_DefParams.getParamIDs(pglsl);
621  }
622 
623 
624 
625  return true;
626 }
627 
629 {
630  //if (m_DefParams != NULL)
631  //{
632  // delete m_DefParams;
633  // m_DefParams = NULL;
634  //}
635  return true;
636 }
637 
639  moTextFilterParam p_params;
640  Apply( p_i, 1.0, p_params);
641 }
642 
643 void moTextureFilter::Apply( MOuint p_i, MOfloat p_fade, const moTextFilterParam& p_params)
644 {
645  MOint w = m_dest_tex[0]->GetWidth();
646  MOint h = m_dest_tex[0]->GetHeight();
647  SetGLConf(w, h);
648 // moShaderGLSL* pglsl = (moShaderGLSL*)m_shader;
649 
651 
652  BindDestFBO();
653 
655  SetupShader(w, h, NULL, p_fade, p_params);
656 
657  BindSrcTex(p_i);
658  m_shader->DrawGrid(w, h, m_src_tex.Count());
659  UnbindSrcTex();
660 
661  m_shader->StopShader();
662 
663  UnbindDestFBO();
664 
665  RestoreGLConf();
666 }
667 
668 
670  moTextFilterParam p_params;
671  Apply( p_cycle, 1.0, p_params);
672 }
673 
674 void moTextureFilter::Apply(MOfloat p_cycle, MOfloat p_fade, const moTextFilterParam& p_params)
675 {
676  MOint w = m_dest_tex[0]->GetWidth();
677  MOint h = m_dest_tex[0]->GetHeight();
678  SetGLConf(w, h);
679 // moShaderGLSL* pglsl = (moShaderGLSL*)m_shader;
680 
681 
683 
684  BindDestFBO();
685 
687  SetupShader(w, h, NULL, p_fade, p_params);
688 
689  BindSrcTex(p_cycle);
690  m_shader->DrawGrid(w, h, m_src_tex.Count());
691  UnbindSrcTex();
692 
693  m_shader->StopShader();
694 
695  UnbindDestFBO();
696 
697  RestoreGLConf();
698 }
699 
701  moTextFilterParam p_params;
702  Apply( p_tempo, 1.0, p_params);
703 }
704 
705 void moTextureFilter::Apply(moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam& p_params)
706 {
707  MOint w = m_dest_tex[0]->GetWidth();
708  MOint h = m_dest_tex[0]->GetHeight();
709  SetGLConf(w, h);
710 // moShaderGLSL* pglsl = (moShaderGLSL*)m_shader;
711 
713 
714  BindDestFBO();
715 
717  SetupShader(w, h, p_tempo, p_fade, p_params);
718 
719  BindSrcTex(p_tempo);
720  m_shader->DrawGrid(w, h, m_src_tex.Count());
721  UnbindSrcTex();
722 
723  m_shader->StopShader();
724 
725  UnbindDestFBO();
726 
727  RestoreGLConf();
728 }
729 
731  moTextFilterParam p_params;
732  Apply( p_src_mob, 1.0, p_params);
733 }
734 
735 void moTextureFilter::Apply( moMoldeoObject *p_src_mob, moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam& p_params ) {
736  if (p_src_mob==NULL) return;
737  if (m_shader==NULL) return;
738 
739  MOint w = m_dest_tex[0]->GetWidth();
740  MOint h = m_dest_tex[0]->GetHeight();
741  SetGLConf(w, h);
742 
744 
745  BindDestFBO();
746 
748  SetupShader(w, h, p_tempo, p_fade, p_params, p_src_mob);
749 
750  BindSrcTex( p_src_mob );
751  m_shader->DrawGrid(w, h, m_src_tex.Count());
752  UnbindSrcTex();
753 
754  m_shader->StopShader();
755 
756  UnbindDestFBO();
757 
758  RestoreGLConf();
759 }
760 
761 
762 void moTextureFilter::Apply( moMoldeoObject *p_src_mob, MOfloat p_fade, const moTextFilterParam& p_params ) {
763 
764  Apply( p_src_mob, NULL, p_fade, p_params );
765 
766 }
767 
768 
769 void moTextureFilter::SetupShader(MOint w, MOint h, moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam& p_params, moMoldeoObject* p_src_object)
770 {
771  for (MOuint i = 0; i < m_src_tex.Count(); i++)
772  {
773  if (-1 < m_src_tex_unit[i]) {
774  if ( m_shader && m_shader->GetType() == (MOuint)MO_SHADER_GLSL ) {
775  glUniform1iARB(m_src_tex_unit[i], i);
776  }
777  }
778  if (-1 < m_src_tex_offset[i]) {
779  if (m_glman->RectTexture(m_src_tex[i]->GetTexTarget())) glUniform2fARB(m_src_tex_offset[i], 1.0, 1.0);
780  else glUniform2fARB(m_src_tex_offset[i], 1.0 / float(m_src_tex[i]->GetWidth()), 1.0 / float(m_src_tex[i]->GetHeight()));
781  }
782  }
783 
784 
785  if (p_tempo != NULL)
786  {
787 
788  if (-1 < m_tempo_angle) {
789  float a = p_tempo->ang;
790  float f = fmod(float(a), float(2.0 * moMathf::PI)) / (2.0 * moMathf::PI);
791 
792  glUniform2fARB(m_tempo_angle, a, f);
793  }
794 
795  if (-1<m_tempo_dt) {
796  glUniform1fARB(m_tempo_dt, p_tempo->dt );
797  }
798  if (-1<m_tempo_syncro) {
799  glUniform1fARB(m_tempo_syncro, p_tempo->syncro );
800  }
801  if (-1<m_tempo_delta) {
802  glUniform1fARB(m_tempo_delta, p_tempo->delta );
803  }
804  if (-1<m_tempo_ticks) {
805  glUniform1fARB(m_tempo_ticks, (float)p_tempo->ticks );
806  }
807  //moDebugManager::Push("m_tempo_angle:" + FloatToStr(a));
808  //(m_shader->GetType() == (MOuint)MO_SHADER_GLSL) ? glUniform2fARB(m_tempo_angle, a, f) : m_tempo_angle=0;/*cgGLSetParameter2f( (CGparameter)m_tempo_angle, a, f)*/
809  }
810  else {
811  glUniform2fARB(m_tempo_angle, 0.0, 0.0);
812  glUniform1fARB(m_tempo_dt, 0.0);
813  //(m_shader->GetType() == (MOuint)MO_SHADER_GLSL) ? glUniform2fARB(m_tempo_angle, 0.0, 0.0) : m_tempo_angle=0;/*cgGLSetParameter2f( (CGparameter)m_tempo_angle, 0.0, 0.0 )*/
814  }
815  if (-1 < m_dest_tex_size) {
816  glUniform2fARB(m_dest_tex_size, w, h);
817 
818  }
819 
820  if (-1 < m_fade_const) {
821  glUniform1fARB(m_fade_const, p_fade);
822  }
823 
825  if (p_src_object) {
826  //do something
827  p_src_object = NULL;
828  }
829 
830  if (-1 < m_random_uniform) {
831  float seed = 0.0f;
832  float r = moMathf::UnitRandom(seed);
833 
834  glUniform2fARB(m_random_uniform, r, seed);
835  }
836 
837 
839  if (p_src_object && m_shader) {
840 
842  //do something
843  //p_src_object = NULL;
844  if (m_uniform_idx>-1) {
845  for( int u=0; u<m_shader->m_Config.GetParam(m_uniform_idx).GetValuesCount(); u++ ) {
847  moText uniform_var_name = vb.GetSubValue(0).GetData()->Text();
848  moText uniform_var_type = vb.GetSubValue(1).GetData()->Text();
849 
850  if (m_uniform_variables_idx[u]>-1) {
851  int paramidx = p_src_object->GetConfig()->GetParamIndex(uniform_var_name);
852  if (uniform_var_type=="FLOAT") {
853  if (paramidx>-1) {
854  float p_float = p_src_object->GetConfig()->Eval( uniform_var_name );
855  glUniform1fARB( m_uniform_variables_idx[u], p_float );
856  } else {
857  int inletidx = p_src_object->GetInletIndex(uniform_var_name);
858  if (inletidx>-1) {
859  float p_float = p_src_object->GetInlets()->Get(inletidx)->GetData()->Float();
860  glUniform1fARB( m_uniform_variables_idx[u], p_float );
861  }
862  }
863  } else
864  if (uniform_var_type=="INT") {
865  if (paramidx>-1) {
866  int p_int = p_src_object->GetConfig()->Int( uniform_var_name );
867  glUniform1iARB( m_uniform_variables_idx[u], p_int );
868  } else {
869  int inletidx = p_src_object->GetInletIndex(uniform_var_name);
870  if (inletidx>-1) {
871  int p_int = p_src_object->GetInlets()->Get(inletidx)->GetData()->Int();
872  glUniform1iARB( m_uniform_variables_idx[u], p_int );
873  }
874  }
875  }
906  }
907  }
908 
909 
910 
911  }
912  }
913 
914  m_DefParams = p_params;
916  MODebug2->Message( moText("setParamValues > m_par_flt1: ") + IntToStr(m_DefParams.m_par_flt1) );
917 
918 }
919 
921 {
922  m_blend_on = glIsEnabled(GL_BLEND);
923 #ifndef OPENGLESV2
924  glGetIntegerv(GL_POLYGON_MODE, &m_poly_mode);
925 #endif
926  glDisable(GL_BLEND);
927 #ifndef OPENGLESV2
928  glPolygonMode(GL_FRONT, GL_FILL);
929 #endif
930  m_glman->SaveView();
931  m_glman->SetOrthographicView(w, h, 0.0, w, 0.0, h);
932 }
933 
935 {
936  m_glman->RestoreView();
937 
938  if (m_blend_on) glEnable(GL_BLEND);
939 #ifndef OPENGLESV2
940  glPolygonMode(GL_FRONT, m_poly_mode);
941 #endif
942 }
943 
945 {
946  moFBO* fbo = m_dest_tex[0]->GetFBO();
947  if (fbo != NULL)
948  {
949  // Attach destination textures to attachements points of fbo (0, 1, 2, etc)...
950  moTexture* ptex;
951 
952  fbo->Bind();
953 
955 
956  GLsizei n = m_dest_tex.Count();
957  int i, j;
958  for (i = 0; i < n; i++)
959  {
960  ptex = m_dest_tex[i];
962  {
963  fbo->AttachTexture(ptex->GetWidth(), ptex->GetHeight(), ptex->GetTexParam(), ptex->GetGLId(), i);
965  }
966  else
967  {
968  j = ptex->GetFBOAttachPoint();
970  }
971  }
972 #ifndef OPENGLESV2
973  glDrawBuffers(n, m_draw_buffers);
974 #endif
975  }
976 }
977 
979 {
980  moFBO* fbo = m_dest_tex[0]->GetFBO();
981  if (fbo != NULL) fbo->Unbind();
982 }
983 
985 {
986  //if (m_shader->GetType()==MO_SHADER_GLSL)
987  for (MOuint i = 0; i < m_src_tex.Count(); i++)
988  {
989  glActiveTextureARB(GL_TEXTURE0_ARB + i);
990  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, (GLint)p_i));
991  }
992 }
993 
995 {
996  //if (m_shader->GetType()==MO_SHADER_GLSL)
997  for (MOuint i = 0; i < m_src_tex.Count(); i++)
998  {
999  glActiveTextureARB(GL_TEXTURE0_ARB + i);
1000  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, p_cycle));
1001  }
1002 }
1003 
1005 {
1006  //if (m_shader->GetType()==MO_SHADER_GLSL)
1007  for (MOuint i = 0; i < m_src_tex.Count(); i++)
1008  {
1009  glActiveTextureARB(GL_TEXTURE0_ARB + i);
1010  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, p_tempo));
1011  }
1012 }
1013 
1015 
1016  if (p_mob==NULL) return;
1017 
1018  moTempo* src_tempo = NULL;
1019  moEffectState fs;
1020 
1021  if ( p_mob->GetType()==MO_OBJECT_EFFECT
1022  || p_mob->GetType()==MO_OBJECT_PREEFFECT
1023  || p_mob->GetType()==MO_OBJECT_POSTEFFECT
1024  || p_mob->GetType()==MO_OBJECT_MASTEREFFECT ) {
1025 
1026  moEffect* pFx = (moEffect*) p_mob;
1027 
1028  if (pFx) {
1029  fs = pFx->GetEffectState();
1030  src_tempo = &fs.tempo;
1031  }
1032 
1033  }
1034 
1035  for (MOuint i = 0; i < m_src_tex.Count(); i++)
1036  {
1037  glActiveTextureARB(GL_TEXTURE0_ARB + i);
1038  //glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, p_mob));
1039  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, src_tempo));
1040  }
1041 }
1042 
1043 
1045 {
1046  for (MOuint i = m_src_tex.Count(); 0 < i; i--)
1047  {
1048  glActiveTextureARB(GL_TEXTURE0_ARB + i - 1);
1049  glBindTexture(m_src_tex[i-1]->GetTexTarget(), 0);
1050  }
1051 }
1052 
1054 {
1055  m_reattach_dest_tex = false;
1056  for (MOuint i = 0; i < m_dest_tex.Count(); i++)
1057  if ((int)m_dest_tex[i]->GetFBOAttachPoint() == MO_UNDEFINED)
1058  {
1059  m_reattach_dest_tex = true;
1060  break;
1061  }
1062 }
1063 
moGLManager * m_glman
#define BLUM
Valor de un Parámetro.
Definition: moValue.h:501
int MatIdx(int i, int j)
var b
Definition: jquery.js:16
#define RLUM
MOboolean m_reattach_dest_tex
Tempo, beat, ritmo.
Definition: moTempo.h:44
g[c]
Definition: jquery.js:71
moConfig m_Config
Definition: moShader.h:286
moValueBase & GetSubValue(MOint p_indexsubvalue=0)
Definition: moValue.h:539
MOdouble Eval(moParamReference p_paramreference, double x,...)
Acceso rápido a evaluar la función.
Definition: moConfig.cpp:1125
var c
Definition: jquery.js:29
#define MAX_UNIFORM_VARS
virtual ~moColorMatrix()
MOfloat m_MatrixChg[16]
void ClearAttachements()
Definition: moFBO.cpp:260
moTextureIndex m_dest_tex
#define MO_UNDEFINED
Definition: moTypes.h:379
#define MOboolean
Definition: moTypes.h:385
void SetZShearMatrix(float dx, float dy)
void BindSrcTex(MOuint p_i)
void SaveView()
int GetParamIndex(moText p_paramname)
Devuelve el índice correspondiente al parámetro por nombre.
Definition: moConfig.cpp:1008
function a
Definition: jquery.js:41
MOuint GetType()
Definition: moShader.h:249
void SetXRotateMatrix(float rs, float rc)
MOint Int(moParamReference p_paramreference)
Acceso rápido a un valor entero.
Definition: moConfig.cpp:1042
function x(bx)
Definition: jquery.js:30
f
Definition: jquery.js:71
void SetYRotateMatrix(float rs, float rc)
MOuint AttachTexture(MOuint p_width, MOuint p_height, const moTexParam &p_param, MOuint p_glid, MOuint p_attach_point)
Definition: moFBO.cpp:218
MOboolean RectTexture(GLenum p_target) const
moInlets * GetInlets()
moTextureIndex m_src_tex
void PrintVertShaderLog()
virtual MOboolean Init()
Inicializa el objeto.
Definition: moAbstract.cpp:141
Objeto indefinido.
Definition: moTypes.h:527
GLint GetUniformID(const moText &uName)
MOdouble syncro
Syncronización o factor fraccionario, 1.0 predeterminado, sino KX donde K puede ser fraccional (un nú...
Definition: moTempo.h:79
void Apply(MOuint p_i, MOfloat p_fade, const moTextFilterParam &p_params)
void SetGLConf(MOint w, MOint h)
MOfloat m_Matrix[16]
virtual void StartShader()
Definition: moShader.cpp:228
void Update(MOfloat p_bright, MOfloat p_cont)
#define MOfloat
Definition: moTypes.h:403
MOdouble delta
variacion de frecuencia entre 0X y 2X, delta es real
Definition: moTempo.h:69
MOfloat m_MatrixTemp[16]
void RestoreView()
Definition: moFBO.h:60
clase de para manejar textos
Definition: moText.h:75
void Multiply(moColorMatrix &p_mat)
virtual const moEffectState & GetEffectState()
Definition: moEffect.cpp:59
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
MOboolean m_PreserveLuminance
void Unbind()
Definition: moFBO.cpp:120
moText0 moText
Definition: moText.h:291
MOuint GetGLId(MOuint p_idx)
moText m_TextureFilterLabelName
#define MOint
Definition: moTypes.h:388
Clase Base para Objetos Moldeo ( moEffect, moIODevice, moResource, moConsole )
MOuint GetGLId() const
Definition: moTexture.h:224
virtual void StopShader()
Definition: moShader.cpp:233
Objeto dibujable, pre-efecto ( primeros efectos en el orden de dibujado )
Definition: moTypes.h:529
clase base para el manejo de una textura
Definition: moTexture.h:78
GLenum m_draw_buffers[MO_MAX_COLOR_ATTACHMENTS_EXT]
moRenderManager * m_renderman
const MOlong PI
Definition: moMath.cpp:44
Objeto dibujable, efecto ( efectos en el orden de dibujado )
Definition: moTypes.h:528
function e
Definition: jquery.js:71
MOint GetColorAttachPoint(MOuint p_attach_point)
Definition: moFBO.cpp:153
void SetupShader(MOint w, MOint h, moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam &p_params, moMoldeoObject *p_src_object=NULL)
manejador de operaciones comunes de Open GL
Definition: moGLManager.h:154
static moDebug * MODebug2
Clase de impresión de errores para depuración.
Definition: moAbstract.h:225
moConfig * GetConfig()
function d
Definition: jquery.js:41
#define GLUM
moMoldeoObjectType GetType() const
moShader * m_shader
moText Text()
Definition: moValue.cpp:539
moTypes h
Definition: all_0.js:5
moValues & GetValues()
Definition: moParam.cpp:1060
MOint Add(moText p_name, moTextureManager *p_tex_man)
moDefineDynamicArray(moTextureFilterArray) moColorMatrix
MOuint GetHeight() const
Definition: moTexture.h:261
MOuint GetFBOAttachPoint() const
Definition: moTexture.h:213
void XFormPoint(float &tx, float &ty, float &tz)
moParam & GetParam(MOint p_paramindex=-1)
Devuelve el parámetro por índice.
Definition: moConfig.cpp:984
MOulong ticks
tiempo en milisegundos (obsoleto) se usa moTimer ahora.
Definition: moTempo.h:60
MOdouble dt
incremento diferencial de tiempo
Definition: moTempo.h:73
GLint m_src_tex_unit[MO_MAX_TEXTURE_UNITS]
void SetZRotateMatrix(float rs, float rc)
virtual MOboolean Finish()
virtual void Finish()
MOint GetInletIndex(moText p_connector_name) const
void Update(MOfloat p_int, MOfloat p_sat, MOfloat p_hue)
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
moData * GetData()
Definition: moValue.cpp:945
void getParamIDs(void *p_shader)
clase base para objetos dibujables
Definition: moEffect.h:82
virtual void Init()
Objeto dibujable, post-efecto ( últímos efectos en el orden de dibujado )
Definition: moTypes.h:530
int m_uniform_variables_idx[MAX_UNIFORM_VARS]
idx of uniform parameters variables in moMoldeoObject
moTextFilterParam m_DefParams
idx of uniform variables in shader code moShader
GLint m_src_tex_offset[MO_MAX_TEXTURE_UNITS]
void DrawGrid(MOint w, MOint h, MOint l)
Definition: moShader.h:283
void PrintFragShaderLog()
void Copy(moColorMatrix &p_mat)
MOuint GetValuesCount() const
Definition: moParam.cpp:1065
MOdouble ang
Definition: moTempo.h:81
MOuint GetWidth() const
Definition: moTexture.h:256
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
void SetOrthographicView(MOint p_width=0, MOint p_height=0, float left=0.0, float right=1.0, float bottom=0.0, float top=1.0, float znear=-1.0, float zfar=1.0)
GLboolean m_blend_on
MOboolean m_use_screen_tex
var k
Definition: jquery.js:29
static Real UnitRandom(unsigned int uiSeed=0)
Definition: moMath.h:380
void Bind()
Definition: moFBO.cpp:114
moTexParam GetTexParam() const
Definition: moTexture.h:307