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
moTextureManager.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moTextureManager.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  Andres Colubri
29 
30 *******************************************************************************/
31 
32 #include "moTextureManager.h"
33 #include <FreeImage.h>
34 #include <moDataManager.h>
35 #include <moFileManager.h>
36 
37 #include "moArray.h"
38 moDefineDynamicArray(moTextureBuffers)
39 moDefineDynamicArray(moTextureFrames)
40 
41 void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message);
42 
48 void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
49 
50  if(fif != FIF_UNKNOWN) {
51  //printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
52  }
53  moDebugManager::Error(moText("FreeImage error:") + moText(message));
54 
55 }
56 
57 
58 //===========================================
59 //
60 // moTextureBuffer
61 //
62 //===========================================
63 
65 
66  //m_type = MO_TYPE_TEXTUREBUFFER;
67  m_ImagesProcessed = 0;
68  m_ActualImage = 0;
69  m_pResourceManager = NULL;
70  m_pDirectory = NULL;
71  m_bLoadCompleted = false;
72  m_pBufferLevels = new moTextureFrames* [100];
73  for( int i=0; i<100; i++ ) {
74  m_pBufferLevels[i] = new moTextureFrames [10];
75  for( int j = 0; j<10; j++ ) {
76  m_pBufferLevels[i][j].Init( 0 , NULL );
77  }
78  }
79 
80  LevelDiagram = NULL;
83  LevelDiagram = new MObyte [ 100 * 100 * 3];
84 
85 }
86 
88  Finish();
89 }
90 
92 
93  if (!m_pResourceManager)
94  return false;
95 
96 
97 
98  return m_bInitialized;
99 }
100 
101 MOboolean
102 moTextureBuffer::Init( moText p_foldername, moTextureBufferFormat p_bufferformat, int p_pattern_width, int p_pattern_height, moResourceManager* p_pResourceManager ) {
103 
104  moText str_format;
105 
106  pattern_width = p_pattern_width;
107  pattern_height = p_pattern_height;
108 
109  if (p_bufferformat==MO_TEXTURE_BUFFER_FORMAT_LEVELS) {
110 
111  str_format = "LEVELS";
112 
113  } else if (p_bufferformat==MO_TEXTURE_BUFFER_FORMAT_PATTERNS) {
114 
115  str_format = "PATTERNS";
116 
117  }
118 
119  return Init( p_foldername, str_format, p_pResourceManager );
120 }
121 
122 MOboolean
123 moTextureBuffer::Init( moText p_foldername, moText p_bufferformat, moResourceManager* p_pResourceManager ) {
124  m_pResourceManager = p_pResourceManager;
125 
126  m_FolderName = p_foldername;
127  m_BufferPath = m_pResourceManager->GetDataMan()->GetDataPath() + (moText)p_foldername;
128  m_BufferFormat = p_bufferformat;
129 
130 
131  m_pDirectory = m_pResourceManager->GetFileMan()->GetDirectory( m_BufferPath );
132 
133  if (!m_pDirectory) return false;
134 
135  //BuildEmpty( width, height);
136 
137  /*
138  moShaderManager* SM = m_pResourceManager->GetShaderMan();
139  moTextureManager* TM = m_pResourceManager->GetTextureMan();
140 
141  m_pShaderCopy = SM->GetShader(SM->GetShaderIndex(moText("shaders/Copy.cfg"),true) );
142  */
143  m_Frames.Init( 0, NULL);
144 
145  max_luminance = 0;//100
146  min_luminance = 100;//0
147 
148  max_contrast = 0;
149  min_contrast = 0;
150 
151  for( int L=0; L<100*100*3; L++) {
152  LevelDiagram[L] = 0;
153  }
154 
155  m_bInitialized = true;
156 
157  return Init();
158 }
159 
161  for(MOuint i=0; i<m_Frames.Count(); i++) {
162  moTextureMemory* pTextureMemory = m_Frames[i];
163  if (pTextureMemory)
164  pTextureMemory->Finish();
165  delete pTextureMemory;
166  }
167  m_Frames.Empty();
168 
169  for(int j=0 ; j<100; j++) {
170  if (m_pBufferLevels[j]!=NULL) {
171  for(int k=0 ; k<10; k++) {
172  m_pBufferLevels[j][k].Empty();
173  }
174  delete [] m_pBufferLevels[j];
175  }
176  }
177  m_pBufferLevels = NULL;
178 
179  if (LevelDiagram) {
180  delete [] LevelDiagram;
181  LevelDiagram = NULL;
182  }
183 
184  m_pResourceManager = NULL;
185  return true;
186 }
187 
188 MOboolean
190  return m_bLoadCompleted;
191 }
192 
194 
195  //carga los frames desde los archivos
196  moFile* pFile;
197 
198  MOint counter = 0;
199 
200  if (!m_pDirectory) return false;
201 
202  if (m_ActualImage>=(MOint)m_pDirectory->GetFiles().Count()) {
203  m_bLoadCompleted = true;
204  return true;
205  }
206 
207  if (m_ActualImage==0)
208  pFile = m_pDirectory->FindFirst();
209  else
210  pFile = m_pDirectory->Find(m_ActualImage);
211 
212  if (pFile)
213  do {
214  if ( pFile->GetType()==MO_FILETYPE_LOCAL && pFile->Exists()) {
215 
216  //LOAD AND UNCOMPRESS IMAGE
217  FREE_IMAGE_FORMAT fif;
218  fif = FreeImage_GetFileType( pFile->GetCompletePath(), 0);
219 
220  if( fif == FIF_UNKNOWN ) {
221  // try to guess the file format from the file extension
222  fif = FreeImage_GetFIFFromFilename(pFile->GetCompletePath());
223  }
224 
225  if( (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif) ) {
226  //decodificamos el archivo
227  FIBITMAP* pImage;
228  pImage = FreeImage_Load( fif, pFile->GetCompletePath(), 0);
229 
230  //ONCE LOADED SAVE ON EVERY VIDEOBUFFER
231  if (pImage) {
232 
233  //for(MOuint b = 0; b<m_VideoBuffers.Count(); b++) {
234 
235  //moVideoBuffer* pVideoBuffer = m_VideoBuffers[b];
236 
237  //if (pVideoBuffer)
238  //LoadImage( , pImage, m_ActualImage );
239  MODebug2->Push( moText("moTextureBuffer::UpdateImages > Trying to load image:") + (moText)pFile->GetCompletePath() );
240  if ( LoadImage( m_FolderName + moSlash + pFile->GetFileName() , pImage, m_ActualImage ) ) {
241  m_ImagesProcessed++;
242  if ( m_ActualImage == (m_pDirectory->GetFiles().Count()-2) ) {
243  MODebug2->Log( moText(" ####TEXTUREBUFFER LEVEL HISTOGRAM####"));
244  moText barra;
245  moText nivel;
246  barra = moText("###################################################################################");
247 
248  for(int k=0; k<100; k++) {
249  nivel = barra;
250  nivel.Left( m_pBufferLevels[k][0].Count() );
251  MODebug2->Log( moText(" level:") + IntToStr(k) + (moText)nivel );
252  }
253  }
254  }
255 
256  //}
257  FreeImage_Unload(pImage);
258  pImage = NULL;
259 
260  }
261  }
262  }
263 
264  m_ActualImage++;
265  counter++;
266  if (counter==maxfiles && maxfiles!=(-1))
267  break;
268 
269  } while ( (pFile = m_pDirectory->FindNext()) );
270 
271  return true;
272 }
273 
274 
275 MOboolean
276 moTextureBuffer::LoadImage( moText p_ImageName, moBitmap* pImage, int indeximage ) {
277 
278  MOboolean res = false;
279  FIBITMAP* _pImage = (FIBITMAP*)pImage;
280  FIBITMAP* pImageResult = NULL;
281 // FIBITMAP* pImageCropped = NULL;
282  FIBITMAP* pImageScaled = NULL;
283 
284  if (indeximage<0) {
285  MODebug2->Error("moTextureBuffer::LoadImage > indeximage invalid or unused for: " + p_ImageName);
286  return false;
287  }
288  /*
289  if ( m_width!=FreeImage_GetWidth(_pImage) || m_height!=FreeImage_GetHeight(_pImage) ) {
290  //CROP MODE
291  pImageCropped = FreeImage_Copy( _pImage, m_XSource , m_YSource , m_XSource + m_SourceWidth , m_YSource+m_SourceHeight );
292  pImageResult = pImageCropped;
293 
294  } else
295  */
296 
297  pImageResult = _pImage;
298 
299  int w, h;
300  if ( ( FreeImage_GetWidth(_pImage) % 4 ) != 0 || ( FreeImage_GetHeight(_pImage) % 4) == 0 ) {
301 
302  w = FreeImage_GetWidth(_pImage) / 4;
303  w = w * 4;
304 
305  h = FreeImage_GetHeight(_pImage) / 4;
306  h = h * 4;
307 
308  pImageScaled = FreeImage_Rescale( pImageResult, w, h, FILTER_BICUBIC );
309  if (pImageScaled) {
310  //FreeImage_Unload(pImageResult);
311  pImageResult = pImageScaled;
312  }
313  }
314 
315 
316  //if (!GLEW_ARB_texture_non_power_of_two) {
317  if (RenderMan()->IsTextureNonPowerOf2Disabled()) {
318 
319  w = FreeImage_GetWidth(pImageResult);
320  h = FreeImage_GetHeight(pImageResult);
321 
322  int i;
323  for (i = 1; i < w; i *= 2);
324  w = i;
325 
326  for (i = 1; i < h; i *= 2);
327  h = i;
328 
329  w = momin(512,w);
330  h = momin(512,h);
331 
332  pImageScaled = FreeImage_Rescale( pImageResult, w, h, FILTER_BICUBIC );
333  if (pImageScaled) {
334  //FreeImage_Unload(pImageResult);
335  pImageResult = pImageScaled;
336  }
337  }
338 
339  FreeImage_AdjustContrast( pImageResult, 0 );
340  FreeImage_AdjustBrightness( pImageResult, 0 );
341 
342 
343 
344  //RESCALE: NOTE NECESARRY HERE
345  //quizas podamos definir un máximo para el tamaño tanto ancho como alto
346  //o como proporción
347  //forzar proporcion y esas cosas....
348  /*
349  if ( m_width != m_SourceWidth || m_height != m_SourceHeight ) {
350 
351  //FILTER_BOX Box, pulse, Fourier window, 1st order (constant) B-Spline
352  //FILTER_BILINEAR Bilinear filter
353  //FILTER_BSPLINE 4th order (cubic) B-Spline
354  //FILTER_BICUBIC Mitchell and Netravali's two-param cubic filter
355  //FILTER_CATMULLROM Catmull-Rom spline, Overhauser spline
356  //FILTER_LANCZOS3
357  pImageScaled = FreeImage_Rescale( pImageResult, m_width, m_height, FILTER_BICUBIC );
358  if (pImageScaled) {
359  FreeImage_Unload(pImageResult);
360  pImageResult = pImageScaled;
361  }
362  }
363  */
364 
365  moTextureMemory* pTextureMemory = NULL;
366 
367  int idx = m_pResourceManager->GetTextureMan()->AddTexture( MO_TYPE_TEXTUREMEMORY, p_ImageName );
368 
369  if (idx>-1) {
370 
371  pTextureMemory = (moTextureMemory*) m_pResourceManager->GetTextureMan()->GetTexture(idx);
372 
373  if (pTextureMemory) {
374  if (pTextureMemory->BuildFromBitmap( pImageResult, m_BufferFormat )) {
375 
376  m_Frames.Add(pTextureMemory);
377 
378  int contrastlevel = pTextureMemory->GetContrast() / 2000;
379  int luminancelevel = (int)((float)pTextureMemory->GetLuminance() / (float)2.56 ) - 1;
380 
381  MODebug2->Message( moText("moTextureBuffer::LoadImage success : ") + (moText)pTextureMemory->GetName());
382  #ifdef _DEBUG
383  MODebug2->Message( moText("moTextureBuffer::LoadImage success : ") + (moText)pTextureMemory->GetName()
384  + moText(" width:") + IntToStr(pTextureMemory->GetWidth())
385  + moText(" height:") + IntToStr(pTextureMemory->GetHeight())
386  + moText(" luminance:") + IntToStr(pTextureMemory->GetLuminance())
387  + moText(" luminancelevel:") + IntToStr(luminancelevel) +
388  + moText(" contrast:") + IntToStr(pTextureMemory->GetContrast())
389  + moText(" contrastlevel:") + IntToStr(contrastlevel) );
390  #endif
391 
392  contrastlevel = 0;
393 
394  if (luminancelevel>=100) {
395  MODebug2->Error( moText("moTextureBuffer::LoadImage Error: luminance out of bound:")+ IntToStr(pTextureMemory->GetLuminance()) );
396  } else {
397  if (max_luminance<luminancelevel) {
398  max_luminance = luminancelevel;
399  } else if (min_luminance>luminancelevel) {
400  min_luminance = luminancelevel;
401  }
402  }
403  if (contrastlevel>=10) {
404  MODebug2->Error( moText("moTextureBuffer::LoadImage Error: contrast out of bound:")+ IntToStr(pTextureMemory->GetContrast()) );
405  }
406  if (0<=luminancelevel && luminancelevel<100 && 0<=contrastlevel && contrastlevel<10) {
407 
408  m_pBufferLevels[luminancelevel][contrastlevel].Add( pTextureMemory );
409 
410  int icc = momin( m_pBufferLevels[luminancelevel][contrastlevel].Count(), 99 );
411  LevelDiagram[ (luminancelevel + icc*100)*3 ] = 250;
412  LevelDiagram[ (luminancelevel+1 + icc*100)*3 ] = 250;
413  LevelDiagram[ (luminancelevel+2 + icc*100)*3 ] = 250;
414  }
415 
416  res = true;
417  } else {
418  res = false;
419  MODebug2->Error( moText("moTextureBuffer::LoadImage Error loading image:")+(moText)pTextureMemory->GetName());
420  }
421  }
422  }
423 
424  if (pImageResult!=_pImage)
425  FreeImage_Unload(pImageResult);
426 
427  //m_nFrames = m_Frames.Count();
428  //m_fFramesPerSecond = 25.0;
429 
430  return (res);
431 }
432 /*
433 MOboolean moTextureBuffer::LoadFromVideo( moText p_moviefile ) {
434  //
435  return true;
436 }
437 */
438 
439 moTextureFrames&
440 moTextureBuffer::GetBufferPatterns( moTexture* p_ImageReference, int x, int y, int width, int height ) {
441 
442  int index = 0;
443 
444  if (p_ImageReference && x>=0 && y>=0 && width>0 && height>0 ) {
445  return m_pBufferPatterns[index+0];
446  }
447 
448  return m_pBufferPatterns[index];
449 }
450 
451 moTextureFrames&
452 moTextureBuffer::GetBufferPatterns( const moTexture& p_ImageReference, int x, int y, int width, int height ) {
453 
454  int index = 0;
455  if (p_ImageReference.GetMOId() && x>=0 && y>=0 && width>0 && height>0 ) {
456  return m_pBufferPatterns[index+0];
457  }
458  return m_pBufferPatterns[index];
459 }
460 
461 
462 moTextureFrames& moTextureBuffer::GetBufferLevels( int L, int C ) {
463 
464  if (0<=L && L<100 && 0<=C && C<10) {
465  return m_pBufferLevels[L][C];
466  } else {
467  //devolvemos el oscuro
468  return m_pBufferLevels[99][0];
469  }
470 
471 }
472 
473 
474 /*
475 */
477 
478  if ( p_i<m_Frames.Count()) {
479 
480  moTextureMemory* pTextureMemory = m_Frames[p_i];
481 
482  //GLId = pTextureMemory->GetReference();
483  pTextureMemory->GetReference();
484  return pTextureMemory->GetGLId();
485 
486  } else {
487  MODebug2->Error(moText("moTextureBuffer::GetFrame Error: p_i out of range: p_i:") + IntToStr(p_i) + moText(" count:") + IntToStr(m_Frames.Count()) );
488  return -1;
489  }
490 
491 }
492 
493 
495 
496  if ( p_i<m_Frames.Count()) {
497 
498  moTextureMemory* pTextureMemory = m_Frames[p_i];
499 
500  //GLId = pTextureMemory->GetReference();
501  pTextureMemory->ReleaseReference();
502  }
503 }
504 
506  if ( p_i<m_Frames.Count()) {
507 
508  moTextureMemory* pTextureMemory = m_Frames[p_i];
509  return pTextureMemory;
510  }
511  return NULL;
512 }
513 
514 
515 //===========================================
516 //
517 // moTextureManager
518 //
519 //===========================================
520 
522 {
525 
526  SetName("texturemanager");
527  SetLabelName("texturemanager");
528 
529  // In your main program ...
530  FreeImage_SetOutputMessage(FreeImageErrorHandler);
531 
532  m_glmanager = NULL;
533  m_fbmanager = NULL;
534 
535  m_textures_buffers.Init(0,NULL);
536 }
537 
539 {
540  Finish();
541 }
542 
544 {
545  if (m_pResourceManager){
548  } else return false;
549 
550  m_textures_array.Init( 0, NULL );
551 
552  m_preview_texture_idx = AddTexture("preview_texture", 1024, 1024);
553  //AddTexture("texture_clip1", 1024, 768);
554  //AddTexture("texture_clip2", 1024, 768);
555  //AddTexture("texture_clip3", 1024, 768);
556  int m_id_default = AddTexture( "default", 256, 256);
557  moTexture* DefaultTexture = GetTexture(m_id_default);
559  moSlash +
560  moText("icons") +
561  moSlash +
562  moText("moldeologo.png");
563  MODebug2->Message(moText("moTextureManager::Init > loading default file:")+logoFile);
564 
565  if (DefaultTexture) if (!DefaultTexture->BuildFromFile(logoFile)) {
566  MODebug2->Error("moTextureManager::Init > error loading " + logoFile );
567  }
568 
569  m_id_default = AddTexture( "moldeonegro", 1800, 600);
570  DefaultTexture = GetTexture(m_id_default);
571  logoFile = m_pResourceManager->GetDataMan()->GetAppDataPath() +
572  moSlash +
573  moText("icons") +
574  moSlash +
575  moText("moldeonegro.png");
576  MODebug2->Message(moText("moTextureManager::Init > loading logo file:")+logoFile);
577 
578  m_id_default = AddTexture( "moldeotrans", 1800, 600);
579  DefaultTexture = GetTexture(m_id_default);
580  logoFile = m_pResourceManager->GetDataMan()->GetAppDataPath() +
581  moSlash +
582  moText("icons") +
583  moSlash +
584  moText("moldeotrans.png");
585  MODebug2->Message(moText("moTextureManager::Init > loading logo file:")+logoFile);
586 
587 
588  if (DefaultTexture) if (!DefaultTexture->BuildFromFile(logoFile)) {
589  MODebug2->Error("moTextureManager::Init > error loading " + logoFile );
590  }
591 
592  return (m_glmanager && m_fbmanager);
593 }
594 
596 {
597  m_textures_array.Finish();
598 
599  m_glmanager = NULL;
600  m_fbmanager = NULL;
601 
602  return true;
603 }
604 
606 {
607  MOint moid = GetTextureMOId(param->GetValue().GetSubValue(0).Text(), false);
608  if (-1 < moid) return moid;
609  else
610  if (p_create_tex) return AddTexture(param);
611  else return -1;
612 }
613 
615 {
616  MOint moid = GetTextureMOId( value->GetSubValue(0).Text(), false);
617  if (-1 < moid) return moid;
618  else
619  if (p_create_tex) return AddTexture(value);
620  else return -1;
621 }
622 
623 MOint moTextureManager::GetTextureMOId(moText p_name, MOboolean p_create_tex, bool p_refresh)
624 {
625  moTexture* ptex;
626  if (p_name.Trim() == moText("")) return -1;
627  for (MOuint i = 0; i < m_textures_array.Count(); i++)
628  {
629  ptex = m_textures_array[i];
630  if ((ptex != NULL) && (!stricmp(ptex->GetName(), p_name))) {
631  if (p_refresh) ptex->Refresh();
632  return i;
633  }
634  }
635 
636  if (p_create_tex) return AddTexture(p_name);
637  else return -1;
638 }
639 
640 void
642 
643  moTexture* ptex;
644 
645  for (MOuint i = 0; i < m_textures_array.Count(); i++)
646  {
647  ptex = m_textures_array[i];
648  if (ptex) {
649  if (ptex->IsBuildedFromFile() && ptex->GetName()!="default" ) {
650  moDebugManager::Message( moText("Refreshing:") + ptex->GetName() );
651  ptex->Refresh();
652  }
653  }
654  }
655 }
656 
657 MOint moTextureManager::GetTextureBuffer( moText p_foldername, MOboolean p_create_tex, moText p_bufferformat ) {
658 
659  moTextureBuffer* ptexbuffer;
660  if (p_foldername.Trim() == moText("")) return -1;
661  for (MOuint i = 0; i < m_textures_buffers.Count(); i++)
662  {
663  ptexbuffer = m_textures_buffers[i];
664  if ((ptexbuffer != NULL) && (!stricmp(ptexbuffer->GetName(), p_foldername))) return i;
665  }
666  if (p_create_tex) return AddTextureBuffer( p_foldername, p_bufferformat );
667  else return -1;
668 
669 }
670 
671 
673  if (0<=idx && idx<(int)m_textures_array.Count()) {
674  return m_textures_buffers[idx];
675  } else return NULL;
676 }
677 
678 
680 {
681  moTexture* ptex;
682  for (MOuint i = 0; i < m_textures_array.Count(); i++)
683  {
684  ptex = m_textures_array[i];
685  if ((ptex != NULL) && (ptex->GetGLId() == p_glid)) return i;
686  }
687  return -1;
688 }
689 
691 {
692  moTexture* ptex = CreateTexture(p_type, p_name, p_tex_param);
693  if (ptex != NULL)
694  {
695  m_textures_array.Add(ptex);
696  ptex->SetMOId(m_textures_array.Count() - 1);
697  return ptex->GetMOId();
698  }
699  else return -1;
700 }
701 
703 {
704  moValue* pValue = &p_param->GetValue();
705  return AddTexture( pValue );
706 }
707 
709 {
710  moText name = p_value->GetSubValue(0).Text();
711  MOuint type = GetTypeForFile(name);
712  moTextureMultiple* ptex_mult;
713  moMovie* ptex_mov;
714  moVideoBuffer* ptex_videobuffer;
715  moCircularVideoBuffer* ptex_circularvideobuffer;
716 
717  moTexture* ptex = CreateTexture(type, name);
718  if (ptex != NULL)
719  {
720  MOboolean res = false;
721  if (type == MO_TYPE_TEXTURE) res = ptex->Load( p_value );
722  else if (type == MO_TYPE_TEXTURE_MULTIPLE)
723  {
724  ptex_mult = (moTextureMultiple*)ptex;
725  res = CreateMultipleTex(ptex_mult, p_value);
726  }
727  else if (type == MO_TYPE_MOVIE)
728  {
729  ptex_mov = (moMovie*)ptex;
730  res = ptex_mov->Load(p_value);
731  }
732  else if (type == MO_TYPE_VIDEOBUFFER)
733  {
734  ptex_videobuffer = (moVideoBuffer*)ptex;
735  res = ptex_videobuffer->Load(p_value);
736  }
737  else if (type == MO_TYPE_CIRCULARVIDEOBUFFER)
738  {
739  ptex_circularvideobuffer = (moCircularVideoBuffer*)ptex;
740  res = ptex_circularvideobuffer->Load(p_value);
741  }
742  if (res)
743  {
744  m_textures_array.Add(ptex);
745  ptex->SetMOId(m_textures_array.Count() - 1);
746  return ptex->GetMOId();
747  }
748  else
749  {
750  delete ptex;
751  return -1;
752  }
753  }
754  else return -1;
755 }
756 
757 MOint moTextureManager::AddTexture(moText p_name, MOuint p_width, MOuint p_height, moTexParam p_tex_param)
758 {
759  moTexture* ptex = CreateTexture(MO_TYPE_TEXTURE, p_name, p_tex_param);
760  if (ptex != NULL)
761  {
762  MOboolean res = ptex->BuildEmpty(p_width, p_height);
763  if (res)
764  {
765  m_textures_array.Add(ptex);
766  ptex->SetMOId(m_textures_array.Count() - 1);
767  return ptex->GetMOId();
768  }
769  else
770  {
771  delete ptex;
772  return -1;
773  }
774  }
775  else return -1;
776 }
777 
778 MOint moTextureManager::AddTexture(moText p_name, MOuint p_width, MOuint p_height, GLvoid* p_buffer, GLenum p_pixel_format, GLenum p_pixel_type, moTexParam p_tex_param)
779 {
780  moTexture* ptex = CreateTexture(MO_TYPE_TEXTURE, p_name, p_tex_param);
781  if (ptex != NULL)
782  {
783  MOboolean res = ptex->BuildFromBuffer(p_width, p_height, p_buffer, p_pixel_format, p_pixel_type);
784  if (res)
785  {
786  m_textures_array.Add(ptex);
787  ptex->SetMOId(m_textures_array.Count() - 1);
788  return ptex->GetMOId();
789  }
790  else
791  {
792  delete ptex;
793  return -1;
794  }
795  }
796  else return -1;
797 }
798 
800 {
801  moText name = p_filename;
802  MOuint type = GetTypeForFile(name);
803 
804  moMovie* ptex_mov;
805 
806  moTexture* ptex = CreateTexture(type, name);
807  p_filename = m_pResourceManager->GetDataMan()->GetDataPath() + moSlash + (moText)p_filename;
808 
809  moFile TexFileName( p_filename );
810  p_filename = TexFileName.GetAbsolutePath();
811 
812  if (ptex != NULL)
813  {
814  MOboolean res = false;
815  if (type == MO_TYPE_TEXTURE) {
816 
817  res = ptex->BuildFromFile(p_filename);
818 
819  } else if (type == MO_TYPE_MOVIE) {
820 
821  ptex_mov = (moMovie*)ptex;
822  res = ptex_mov->LoadMovieFile(p_filename);
823 
824  }
825 
826 
827  if (res) {
828 
829  m_textures_array.Add(ptex);
830  ptex->SetMOId(m_textures_array.Count() - 1);
831  return ptex->GetMOId();
832 
833  } else {
834  MODebug2->Error("moTextureManager::AddTexture > filename: " + p_filename + " failed BuildFromFile()/LoadMovieFile()");
835  DeleteTexture(ptex->GetMOId());
836  return -1;
837  }
838  }
839  else return -1;
840 }
841 
842 MOint moTextureManager::AddTextureBuffer( moText p_foldername, moText p_bufferformat ) {
843 
844  moTextureBuffer* ptexbuffer = new moTextureBuffer();
845  if (ptexbuffer) {
846 
847  if ( ptexbuffer->Init( p_foldername, p_bufferformat, m_pResourceManager ) ) {
848  m_textures_buffers.Add( ptexbuffer );
849  MODebug2->Push( moText("TextureBuffer created:") + (moText)p_foldername + moText(" idx:") +IntToStr((m_textures_buffers.Count() - 1)) );
850  return (m_textures_buffers.Count() - 1);
851  } else {
852  MODebug2->Error( moText("moTextureManager::AddTextureBuffer Error: Initializing texturebuffer: ") + (moText)p_foldername );
853  }
854 
855  } else {
856  MODebug2->Error( moText("moTextureManager::AddTextureBuffer Error: Creating texturebuffer: ") + (moText)p_foldername );
857  }
858 
859  return -1;
860 
861 }
862 
864 {
865  if (ValidTexture(p_moid))
866  {
867  moTexture* ptex = m_textures_array[p_moid];
868  if (ptex)
869  delete ptex;
870  m_textures_array.Remove(p_moid);
871  for (MOuint i = p_moid; i < m_textures_array.Count(); i++) m_textures_array[i]->SetMOId(i);
872  return true;
873  }
874  else return false;
875 }
876 
878 {
879  moText extension = p_filename;
880  moText begin = p_filename;
881  begin.Left(7);
882 
883  moFile FileName(p_filename);
884  extension = FileName.GetExtension();
885 
886  if (!stricmp(extension,".tga")
887  || !stricmp(extension,".jpg")
888  || !stricmp(extension,".png")
889  || !stricmp(extension,".bmp")
890  || !stricmp(extension,".tif")
891  || !stricmp(extension,".xpm"))
892  return MO_TYPE_TEXTURE;
893  if (!stricmp(begin,"multiple"))
895  if (!stricmp(extension,".mkv")
896  || !stricmp(extension,".ogg")
897  || !stricmp(extension,".ogv")
898  || !stricmp(extension,".avi")
899  || !stricmp(extension,".mov")
900  || !stricmp(extension,".mpg")
901  || !stricmp(extension,".mpeg")
902  || !stricmp(extension,".mts")
903  || !stricmp(extension,".m2ts")
904  || !stricmp(extension,".vob")
905  || !stricmp(extension,".m2v")
906  || !stricmp(extension,".mp4")
907  || !stricmp(extension,".web")
908  || !stricmp(extension,".webm"))
909  return MO_TYPE_MOVIE;
910 
911  return MO_TYPE_TEXTURE;
912 }
913 
915 {
916  moTexture* ptex;
917  moTextureMemory* ptex_mem;
918  moTextureMultiple* ptex_mult;
919  moMovie* ptex_movie;
920  moVideoBuffer* ptex_videobuffer;
921  moCircularVideoBuffer* ptex_circularvideobuffer;
922 
923  MOuint new_moid = m_textures_array.Count();
924 
925  if ( p_name.Trim().Length() == 0 ) {
927  MODebug2->Error( moText("moTextureManager::CreateTexture > untitled texture name.") );
928  return NULL;
929  }
930 
931  if (p_type == MO_TYPE_TEXTURE)
932  {
933  ptex = new moTexture();
934  }
935  else if (p_type == MO_TYPE_TEXTUREMEMORY)
936  {
937  ptex_mem = new moTextureMemory();
938  ptex = (moTexture*)ptex_mem;
939  }
940  else if (p_type == MO_TYPE_TEXTURE_MULTIPLE)
941  {
942  ptex_mult = new moTextureMultiple();
943  ptex = (moTexture*)ptex_mult;
944  }
945  else if (p_type == MO_TYPE_MOVIE)
946  {
947  ptex_movie = new moMovie();
948  ptex = (moTexture*)ptex_movie;
949  }
950  else if (p_type == MO_TYPE_VIDEOBUFFER)
951  {
952  ptex_videobuffer = new moVideoBuffer();
953  ptex = (moTexture*)ptex_videobuffer;
954  }
955  else if (p_type == MO_TYPE_CIRCULARVIDEOBUFFER)
956  {
957  ptex_circularvideobuffer = new moCircularVideoBuffer();
958  ptex = (moTexture*)ptex_circularvideobuffer;
959  }
960  else return NULL;
961 
962  ptex->Init(p_name, new_moid, m_pResourceManager, p_param);
963  return ptex;
964 }
965 
967 {
968  moValue* pValue = &p_param->GetValue();
969  return CreateMultipleTex(p_tex_mult, pValue);
970 }
971 
973 {
974  moText texfn;
975  MOint moid;
976  MOuint nfiles = p_value->GetSubValueCount() - 1;
977 
978  for (MOuint i = 0; i < nfiles; i++)
979  {
980  texfn = p_value->GetSubValue(i + 1).Text();
981  moid = GetTextureMOId(texfn, true);
982  if (-1 < moid) p_tex_mult->AddFrame(GetTexture(moid));
983  }
984 
985  return 0 < p_tex_mult->GetTextureCount();
986 }
987 
989  return ValidTexture(p_moid) ? m_textures_array[p_moid]->GetType() : MO_UNDEFINED;
990 
991 }
992 
994  return ValidTexture(p_moid) ? m_textures_array[p_moid]->GetGLId() : 0;
995 }
996 
997 
999 {
1000  if (Events==NULL) return;
1001  //if ( GetId() == MO_MOLDEOOBJECT_UNDEFINED_ID ) return;
1002 
1004  for(MOuint k=0; k<m_textures_buffers.Count(); k++) {
1005 
1006 
1007  moTextureBuffer* pTextureBuffer = m_textures_buffers[k];
1008 
1009  if (pTextureBuffer && !pTextureBuffer->LoadCompleted()) {
1010 
1011  MODebug2->Push( pTextureBuffer->GetName() + moText(":") + IntToStr(pTextureBuffer->GetImagesProcessed() ));
1012  pTextureBuffer->UpdateImages( 1 );
1013  }
1014 
1015 
1016  }
1017 
1018 }
1019 
virtual void ReleaseFrame(MOuint p_i)
void moBitmap
Definition: moTexture.h:44
void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message)
MOint GetTextureBuffer(moText p_foldername, MOboolean p_create_tex=true, moText p_bufferformat="JPGAVERAGE")
virtual ~moTextureBuffer()
Valor de un Parámetro.
Definition: moValue.h:501
moFile * FindFirst()
Definition: moFile.cpp:314
Parámetros internos de una textura.
Definition: moTypes.h:543
moFileType GetType()
Definition: moFile.cpp:442
buffer de texturas
Definition: moTexture.h:59
static void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
moTextureArray m_textures_array
MOboolean Refresh()
Definition: moTexture.cpp:823
moTextureBufferFormat
Buffer de imágenes.
void Error(moText p_text)
Anuncia y registra un error.
Definition: moAbstract.cpp:79
virtual MOboolean Finish()
Definition: moTexture.cpp:1354
void SetName(const moText &p_name)
moFile * FindNext()
Definition: moFile.cpp:325
moValueBase & GetSubValue(MOint p_indexsubvalue=0)
Definition: moValue.h:539
buffer de video
Definition: moTexture.h:57
MOboolean BuildFromBuffer(MOuint p_width, MOuint p_height, const GLvoid *p_buffer, GLenum p_format=GL_RGBA, GLenum p_type=GL_UNSIGNED_BYTE)
Definition: moTexture.cpp:136
moDefineDynamicArray(moTextureBuffers) moDefineDynamicArray(moTextureFrames) void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif
MOboolean LoadImage(moText p_ImageName, moBitmap *pImage, int indeximage)
#define MO_UNDEFINED
Definition: moTypes.h:379
#define MOboolean
Definition: moTypes.h:385
una textura animada basada en una película
Definition: moTexture.h:853
static void Error(moText p_text)
Anuncia un error.
MOboolean Load(moParam *p_param)
Definition: moTexture.cpp:2180
moText0 & Left(MOuint)
Definition: moText.cpp:484
MOboolean LoadCompleted()
virtual moTextureMemory * GetTexture(MOuint p_i)
function x(bx)
Definition: jquery.js:30
void SetMOId(MOuint p_moid)
Definition: moTexture.h:240
MOint AddTexture(MOuint p_type, moText p_name, moTexParam p_tex_param=MODefTex2DParams)
textura múltiple
Definition: moTexture.h:55
void SetResourceType(moResourceType p_restype)
virtual int GetFrame(MOuint p_i)
moGLManager * m_glmanager
MOboolean BuildEmpty(MOuint p_width, MOuint p_height)
Definition: moTexture.cpp:113
void ReleaseReference()
Definition: moTexture.cpp:1341
MOboolean LoadMovieFile(moText p_filename)
Definition: moTexture.cpp:2122
#define MObyte
Definition: moTypes.h:400
moFile * Find(MOint index)
Definition: moFile.cpp:352
moText GetExtension()
Get absolute path and filename "/D/PP/myFileName.txt".
Definition: moFile.cpp:543
int GetLuminance()
Definition: moTexture.h:500
moFBManager * m_fbmanager
moGLManager * GetGLMan()
MOboolean Exists()
Definition: moFile.cpp:436
moText GetFileName()
Definition: moFile.cpp:477
void AddFrame(moTexture *p_texture)
Definition: moTexture.cpp:1868
Lista de eventos.
Definition: moEventList.h:139
clase de para manejar textos
Definition: moText.h:75
moTexture * GetTexture(MOuint p_moid)
moResourceManager * m_pResourceManager
Puntero al administrador de recursos.
moTextureBuffers m_textures_buffers
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
Definition: moTypes.h:532
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
void Log(moText p_text)
Escribe un mensaje en el archivo de registro (log)
Definition: moAbstract.cpp:123
moText0 & Trim()
Definition: moText.cpp:604
MOboolean UpdateImages(int maxfiles=-1)
moText GetName() const
Definition: moTexture.h:245
moText0 moText
Definition: moText.h:291
Buffer de imágenes para video.
virtual MOboolean Init()
Inicializa el objeto.
MOboolean DeleteTexture(MOuint p_moid)
#define MOint
Definition: moTypes.h:388
const char * message
moFileArray & GetFiles()
Definition: moFile.cpp:381
moFileManager * GetFileMan()
MOuint GetGLId(MOuint p_moid)
int GetContrast()
Definition: moTexture.h:498
MOboolean ValidTexture(MOuint p_moid)
MOuint GetGLId() const
Definition: moTexture.h:224
MOuint GetTypeForFile(moText p_filename)
MOint GetTextureMOId(moParam *param, MOboolean p_create_tex)
clase base para el manejo de una textura
Definition: moTexture.h:78
moDirectory * GetDirectory(moText p_Path)
moText GetCompletePath()
Get inmediate folder name: return "PP" for "PP/myFileName.txt".
Definition: moFile.cpp:538
Administrador de recursos.
película
Definition: moTexture.h:56
MOuint Length() const
Definition: moText.cpp:347
MOboolean CreateMultipleTex(moTextureMultiple *p_tex_mult, moParam *p_param)
moTextureFrames & GetBufferPatterns(moTexture *p_ImageReference, int x, int y, int width=0, int height=0)
moFBManager * GetFBMan()
void SetLabelName(const moText &p_labelname)
function L
Definition: jquery.js:16
MOuint GetMOId() const
Definition: moTexture.h:235
TEXTURA BASE.
Definition: moTexture.h:54
static moDebug * MODebug2
Clase de impresión de errores para depuración.
Definition: moAbstract.h:225
moMoldeoObjectType GetType() const
virtual void Update(moEventList *Events)
moDataManager * GetDataMan()
virtual MOboolean Init(moText p_name, MOuint p_moid, moResourceManager *p_res, moTexParam p_param=MODefTex2DParams)
Definition: moTexture.cpp:85
moText Text()
Definition: moValue.cpp:539
MOboolean BuildFromFile(moText p_filename)
Definition: moTexture.cpp:142
moTextureFrames & GetBufferLevels(int L, int C)
moTypes h
Definition: all_0.js:5
virtual MOboolean Init()
void Push(moText p_text)
Apila el mensaje dentro de la pila de mensajes.
Definition: moAbstract.h:115
MOuint GetHeight() const
Definition: moTexture.h:261
moValue & GetValue(MOint i=-1)
Definition: moParam.cpp:1204
MOboolean Load(moParam *p_param)
Definition: moTexture.cpp:358
Secuencia de texturas.
Definition: moTexture.h:744
#define RenderMan()
MOint AddTextureBuffer(moText p_foldername, moText p_bufferformat="JPGAVERAGE")
moText GetAppDataPath()
MOuint GetTextureCount()
Definition: moTexture.h:810
moText GetDataPath()
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
MOboolean IsBuildedFromFile() const
Definition: moTexture.h:363
virtual MOboolean BuildFromBitmap(moBitmap *p_bitmap, moText p_bufferformat="JPG")
Guarda el bitmap con el formato elegido en memoria, luego construye la textura opengl.
Definition: moTexture.cpp:1297
clase base para el manejo de una textura con su copia comprimida en memoria
Definition: moTexture.h:442
MOuint GetSubValueCount()
Definition: moValue.h:545
MOboolean m_bInitialized
Valor de inicialización.
Definition: moAbstract.h:223
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
Buffer Circular de imágenes para video.
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
moTexture * CreateTexture(MOuint p_type, moText p_name, moTexParam p_param=MODefTex2DParams)
virtual MOboolean Finish()
void SetType(moMoldeoObjectType p_type)
var k
Definition: jquery.js:29
moPort const
Definition: all_14.js:19
moTextureManager * GetTextureMan()