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.
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;
497  m_TextureFilterLabelName = "";
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  }
523  CheckDestTexAttachStatus();
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) {
599  m_uniform_idx = m_shader->m_Config.GetParamIndex( "uniform" );
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++ ) {
605  moValue vb = m_shader->m_Config.GetParam(m_uniform_idx).GetValues().Get(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 
650  if (m_use_screen_tex) m_renderman->SaveScreen();
651 
652  BindDestFBO();
653 
654  m_shader->StartShader();
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 
682  if (m_use_screen_tex) m_renderman->SaveScreen();
683 
684  BindDestFBO();
685 
686  m_shader->StartShader();
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 
712  if (m_use_screen_tex) m_renderman->SaveScreen();
713 
714  BindDestFBO();
715 
716  m_shader->StartShader();
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) {
736  moTextFilterParam p_params;
737  Apply( p_src_mob, p_tempo, 1.0, p_params);
738 }
739 
740 void moTextureFilter::Apply( moMoldeoObject *p_src_mob, moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam& p_params ) {
741  if (p_src_mob==NULL) return;
742  if (m_shader==NULL) return;
743 
744  MOint w = m_dest_tex[0]->GetWidth();
745  MOint h = m_dest_tex[0]->GetHeight();
746  SetGLConf(w, h);
747 
748  if (m_use_screen_tex) m_renderman->SaveScreen();
749 
750  BindDestFBO();
751 
752  m_shader->StartShader();
753  SetupShader(w, h, p_tempo, p_fade, p_params, p_src_mob);
754 
755  BindSrcTex( p_src_mob );
756  m_shader->DrawGrid(w, h, m_src_tex.Count());
757  UnbindSrcTex();
758 
759  m_shader->StopShader();
760 
761  UnbindDestFBO();
762 
763  RestoreGLConf();
764 }
765 
766 
767 void moTextureFilter::Apply( moMoldeoObject *p_src_mob, MOfloat p_fade, const moTextFilterParam& p_params ) {
768 
769  Apply( p_src_mob, NULL, p_fade, p_params );
770 
771 }
772 
773 
774 void moTextureFilter::SetupShader(MOint w, MOint h, moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam& p_params, moMoldeoObject* p_src_object)
775 {
776  for (MOuint i = 0; i < m_src_tex.Count(); i++)
777  {
778  if (-1 < m_src_tex_unit[i]) {
779  if ( m_shader && m_shader->GetType() == (MOuint)MO_SHADER_GLSL ) {
780  glUniform1iARB(m_src_tex_unit[i], i);
781  }
782  }
783  if (-1 < m_src_tex_offset[i]) {
784  if (m_glman->RectTexture(m_src_tex[i]->GetTexTarget())) glUniform2fARB(m_src_tex_offset[i], 1.0, 1.0);
785  else glUniform2fARB(m_src_tex_offset[i], 1.0 / float(m_src_tex[i]->GetWidth()), 1.0 / float(m_src_tex[i]->GetHeight()));
786  }
787  }
788 
789 
790  if (p_tempo != NULL)
791  {
792 
793  if (-1 < m_tempo_angle) {
794  float a = p_tempo->ang;
795  float f = fmod(float(a), float(2.0 * moMathf::PI)) / (2.0 * moMathf::PI);
796 
797  glUniform2fARB(m_tempo_angle, a, f);
798  }
799 
800  if (-1<m_tempo_dt) {
801  glUniform1fARB(m_tempo_dt, p_tempo->dt );
802  }
803  if (-1<m_tempo_syncro) {
804  glUniform1fARB(m_tempo_syncro, p_tempo->syncro );
805  }
806  if (-1<m_tempo_delta) {
807  glUniform1fARB(m_tempo_delta, p_tempo->delta );
808  }
809  if (-1<m_tempo_ticks) {
810  glUniform1fARB(m_tempo_ticks, (float)p_tempo->ticks );
811  }
812  //moDebugManager::Push("m_tempo_angle:" + FloatToStr(a));
813  //(m_shader->GetType() == (MOuint)MO_SHADER_GLSL) ? glUniform2fARB(m_tempo_angle, a, f) : m_tempo_angle=0;/*cgGLSetParameter2f( (CGparameter)m_tempo_angle, a, f)*/
814  }
815  else {
816  glUniform2fARB(m_tempo_angle, 0.0, 0.0);
817  glUniform1fARB(m_tempo_dt, 0.0);
818  //(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 )*/
819  }
820  if (-1 < m_dest_tex_size) {
821  glUniform2fARB(m_dest_tex_size, w, h);
822 
823  }
824 
825  if (-1 < m_fade_const) {
826  glUniform1fARB(m_fade_const, p_fade);
827  }
828 
830  if (p_src_object) {
831  //do something
832  //p_src_object = NULL;
833  }
834 
835  if (-1 < m_random_uniform) {
836  float seed = 0.0f;
837  float r = moMathf::UnitRandom(seed);
838 
839  glUniform2fARB(m_random_uniform, r, seed);
840  }
841 
842 
844  if (p_src_object && m_shader) {
845 
846  moShaderGLSL* pglsl = (moShaderGLSL*)m_shader;
847  //do something
848  //p_src_object = NULL;
849  if (m_uniform_idx>-1) {
850  for( int u=0; u<m_shader->m_Config.GetParam(m_uniform_idx).GetValuesCount(); u++ ) {
851  moValue vb = m_shader->m_Config.GetParam(m_uniform_idx).GetValues().Get(u);
852  moText uniform_var_name = vb.GetSubValue(0).GetData()->Text();
853  moText uniform_var_type = vb.GetSubValue(1).GetData()->Text();
854 
855  if (m_uniform_variables_idx[u]>-1) {
856  int paramidx = p_src_object->GetConfig()->GetParamIndex(uniform_var_name);
857  if (uniform_var_type=="FLOAT") {
858  if (paramidx>-1) {
859  float p_float = p_src_object->GetConfig()->Eval( uniform_var_name );
860  glUniform1fARB( m_uniform_variables_idx[u], p_float );
861  } else {
862  int inletidx = p_src_object->GetInletIndex(uniform_var_name);
863  if (inletidx>-1) {
864  float p_float = p_src_object->GetInlets()->Get(inletidx)->GetData()->Float();
865  glUniform1fARB( m_uniform_variables_idx[u], p_float );
866  }
867  }
868  } else
869  if (uniform_var_type=="INT") {
870  if (paramidx>-1) {
871  int p_int = p_src_object->GetConfig()->Int( uniform_var_name );
872  glUniform1iARB( m_uniform_variables_idx[u], p_int );
873  } else {
874  int inletidx = p_src_object->GetInletIndex(uniform_var_name);
875  if (inletidx>-1) {
876  int p_int = p_src_object->GetInlets()->Get(inletidx)->GetData()->Int();
877  glUniform1iARB( m_uniform_variables_idx[u], p_int );
878  }
879  }
880  }
911  }
912  }
913 
914 
915 
916  }
917  }
918 
919  m_DefParams = p_params;
920  m_DefParams.setParamValues();
921  //MODebug2->Message( moText("setParamValues > m_par_flt1: ") + IntToStr(m_DefParams.m_par_flt1) );
922 
923 }
924 
926 {
927  m_blend_on = glIsEnabled(GL_BLEND);
928 #ifndef OPENGLESV2
929  glGetIntegerv(GL_POLYGON_MODE, &m_poly_mode);
930 #endif
931  glDisable(GL_BLEND);
932 #ifndef OPENGLESV2
933  glPolygonMode(GL_FRONT, GL_FILL);
934 #endif
935  m_glman->SaveView();
936  m_glman->SetOrthographicView(w, h, 0.0, w, 0.0, h);
937 }
938 
940 {
941  m_glman->RestoreView();
942 
943  if (m_blend_on) glEnable(GL_BLEND);
944 #ifndef OPENGLESV2
945  glPolygonMode(GL_FRONT, m_poly_mode);
946 #endif
947 }
948 
950 {
951  moFBO* fbo = m_dest_tex[0]->GetFBO();
952  if (fbo != NULL)
953  {
954  // Attach destination textures to attachements points of fbo (0, 1, 2, etc)...
955  moTexture* ptex;
956 
957  fbo->Bind();
958 
959  if (m_reattach_dest_tex) fbo->ClearAttachements();
960 
961  GLsizei n = m_dest_tex.Count();
962  int i, j;
963  for (i = 0; i < n; i++)
964  {
965  ptex = m_dest_tex[i];
966  if (m_reattach_dest_tex)
967  {
968  fbo->AttachTexture(ptex->GetWidth(), ptex->GetHeight(), ptex->GetTexParam(), ptex->GetGLId(), i);
969  m_draw_buffers[i] = fbo->GetColorAttachPoint(i);
970  }
971  else
972  {
973  j = ptex->GetFBOAttachPoint();
974  m_draw_buffers[i] = fbo->GetColorAttachPoint(j);
975  }
976  }
977 #ifndef OPENGLESV2
978  glDrawBuffers(n, m_draw_buffers);
979 #endif
980  }
981 }
982 
984 {
985  moFBO* fbo = m_dest_tex[0]->GetFBO();
986  if (fbo != NULL) fbo->Unbind();
987 }
988 
990 {
991  //if (m_shader->GetType()==MO_SHADER_GLSL)
992  for (MOuint i = 0; i < m_src_tex.Count(); i++)
993  {
994  glActiveTextureARB(GL_TEXTURE0_ARB + i);
995  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, (GLint)p_i));
996  }
997 }
998 
1000 {
1001  //if (m_shader->GetType()==MO_SHADER_GLSL)
1002  for (MOuint i = 0; i < m_src_tex.Count(); i++)
1003  {
1004  glActiveTextureARB(GL_TEXTURE0_ARB + i);
1005  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, p_cycle));
1006  }
1007 }
1008 
1010 {
1011  //if (m_shader->GetType()==MO_SHADER_GLSL)
1012  for (MOuint i = 0; i < m_src_tex.Count(); i++)
1013  {
1014  glActiveTextureARB(GL_TEXTURE0_ARB + i);
1015  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, p_tempo));
1016  }
1017 }
1018 
1020 
1021  if (p_mob==NULL) return;
1022 
1023  moTempo* src_tempo = NULL;
1024  moEffectState fs;
1025 
1026  if ( p_mob->GetType()==MO_OBJECT_EFFECT
1027  || p_mob->GetType()==MO_OBJECT_PREEFFECT
1028  || p_mob->GetType()==MO_OBJECT_POSTEFFECT
1029  || p_mob->GetType()==MO_OBJECT_MASTEREFFECT ) {
1030 
1031  moEffect* pFx = (moEffect*) p_mob;
1032 
1033  if (pFx) {
1034  fs = pFx->GetEffectState();
1035  src_tempo = &fs.tempo;
1036  }
1037 
1038  }
1039 
1040  for (MOuint i = 0; i < m_src_tex.Count(); i++)
1041  {
1042  glActiveTextureARB(GL_TEXTURE0_ARB + i);
1043  //glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, p_mob));
1044  glBindTexture(m_src_tex[i]->GetTexTarget(), m_src_tex.GetGLId(i, src_tempo));
1045  }
1046 }
1047 
1048 
1050 {
1051  for (MOuint i = m_src_tex.Count(); 0 < i; i--)
1052  {
1053  glActiveTextureARB(GL_TEXTURE0_ARB + i - 1);
1054  glBindTexture(m_src_tex[i-1]->GetTexTarget(), 0);
1055  }
1056 }
1057 
1059 {
1060  m_reattach_dest_tex = false;
1061  for (MOuint i = 0; i < m_dest_tex.Count(); i++)
1062  if ((int)m_dest_tex[i]->GetFBOAttachPoint() == MO_UNDEFINED)
1063  {
1064  m_reattach_dest_tex = true;
1065  break;
1066  }
1067 }
#define BLUM
Valor de un Parámetro.
Definition: moValue.h:501
int MatIdx(int i, int j)
MOuint GetFBOAttachPoint() const
Definition: moTexture.h:213
#define RLUM
Tempo, beat, ritmo.
Definition: moTempo.h:44
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
#define MAX_UNIFORM_VARS
virtual ~moColorMatrix()
MOfloat m_MatrixChg[16]
void ClearAttachements()
Definition: moFBO.cpp:260
#define MO_UNDEFINED
Definition: moTypes.h:379
#define MOboolean
Definition: moTypes.h:385
void SetZShearMatrix(float dx, float dy)
void BindSrcTex(MOuint p_i)
int GetParamIndex(moText p_paramname)
Devuelve el �ndice correspondiente al par�metro por nombre.
Definition: moConfig.cpp:1008
void SetXRotateMatrix(float rs, float rc)
MOint Int(moParamReference p_paramreference)
Acceso r�pido a un valor entero.
Definition: moConfig.cpp:1042
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
moInlets * GetInlets()
void PrintVertShaderLog()
virtual MOboolean Init()
Inicializa el objeto.
Definition: moAbstract.cpp:141
MOuint GetHeight() const
Definition: moTexture.h:261
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]
MOint GetInletIndex(moText p_connector_name) const
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]
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:88
MOboolean m_PreserveLuminance
void Unbind()
Definition: moFBO.cpp:120
moText0 moText
Definition: moText.h:291
#define MOint
Definition: moTypes.h:388
Clase Base para Objetos Moldeo ( moEffect, moIODevice, moResource, moConsole )
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
const MOlong PI
Definition: moMath.cpp:44
Objeto dibujable, efecto ( efectos en el orden de dibujado )
Definition: moTypes.h:528
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
moConfig * GetConfig()
#define GLUM
moText Text()
Definition: moValue.cpp:539
MOuint GetWidth() const
Definition: moTexture.h:256
moTexParam GetTexParam() const
Definition: moTexture.h:307
moDefineDynamicArray(moTextureFilterArray) moColorMatrix
void XFormPoint(float &tx, float &ty, float &tz)
MOulong ticks
tiempo en milisegundos (obsoleto) se usa moTimer ahora.
Definition: moTempo.h:60
MOdouble dt
incremento diferencial de tiempo
Definition: moTempo.h:73
void SetZRotateMatrix(float rs, float rc)
virtual MOboolean Finish()
MOuint GetGLId() const
Definition: moTexture.h:224
virtual void Finish()
moMoldeoObjectType GetType() 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
void PrintFragShaderLog()
void Copy(moColorMatrix &p_mat)
MOdouble ang
Definition: moTempo.h:81
static Real UnitRandom(unsigned int uiSeed=0)
Definition: moMath.h:380
void Bind()
Definition: moFBO.cpp:114