libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moRenderManager.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moRenderManager.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 <moRenderManager.h>
33 #include <moEffect.h>
34 
35 
36 #include "moArray.h"
37 moDefineDynamicArray( moRenderClips )
38 moDefineDynamicArray( moDisplays )
39 
41  m_DisplayResolution.width = 0;
42  m_DisplayResolution.height = 0;
43  m_DisplayResolution.aspect = 1.0;
44 }
45 
46 moDisplay::moDisplay( int w, int h) {
47  m_DisplayResolution.width = w;
48  m_DisplayResolution.height = h;
49  m_DisplayResolution.aspect = 1.0;
50  if ( !(h==0) != !(w==0) ) {
51  m_DisplayResolution.aspect = (int)(h==0) - (int) (w==0);
52  }
53  if (h!=0 && w!=0) {
54  m_DisplayResolution.aspect =(float)w;
55  m_DisplayResolution.aspect*= 1.0 / ((float)h);
56  }
57 }
58 
60  (*this)=p_src;
61 }
62 
64 
65 }
66 moDisplay&
68 
69  m_DisplayResolution = p_src.m_DisplayResolution;
70  return (*this);
71 }
72 
73 
74 
75 
76 
78 
81  SetName("rendermanager");
82  SetLabelName("rendermanager");
83 
84  m_pResourceManager = NULL;
85  m_pGLManager = NULL;
86  m_pFBManager = NULL;
87  m_pTextureManager = NULL;
88  m_pDecoderManager = NULL;
89  m_pSHManager = NULL;
90 
91 
92  m_render_tex_moid[0] = -1;
93  m_render_tex_moid[1] = -1;
94  m_render_tex_moid[2] = -1;
95  m_render_tex_moid[3] = -1;
96  m_render_tex_moid[4] = -1;
97  m_render_tex_moid[5] = -1;
98 
101 
104 
106 
108 }
109 
111  delete m_pFramesPool;
113 }
114 
116  return m_RenderLock.Lock();
117 }
118 
120  //it is not necessary to check who has unlocked the process ??
121  return m_RenderLock.Unlock();
122 }
123 
125 
126  m_OutputConfiguration = p_output_configuration;
127 
128 }
129 
131 
132  return m_OutputConfiguration;
133 
134 }
135 
136 int moRenderManager::CreateLayer( moEffect* p_scene_effect ) {
137  p_scene_effect = NULL;
138  return 0;
139 }
140 
141 void moRenderManager::RenderLayer( int layer_id ) {
142  layer_id = 0;
143 }
144 
146  MOint p_screen_width, MOint p_screen_height,
147  MOint p_render_width, MOint p_render_height)
148 {
149 
150  if (m_pResourceManager){
155  }
156  if (!(m_pGLManager && m_pFBManager && m_pTextureManager && m_pSHManager)) return false;
157 
158  m_render_to_texture_mode = p_render_to_texture_mode;
159  m_render_width = p_render_width;
160  m_render_height = p_render_height;
161  m_screen_width = p_screen_width;
162  m_screen_height = p_screen_height;
163 
164  MODebug2->Message(moText("moRenderManager::Init > Setting Render Manager Mode to:")+ IntToStr(m_render_to_texture_mode));
165  MODebug2->Message(moText("moRenderManager::Init > Setting Render Manager for Render: ")+ IntToStr(m_render_width)+"x"+ IntToStr(m_render_height)
166  + " for Screen: " + IntToStr(m_screen_width)+"x"+ IntToStr(m_screen_height) );
167 
169 
171  if (m_pDecoderManager!=NULL) {
172  MODebug2->Message("moRenderManager::Init > Decoder Manager Acquired.");
173  }
174  }
175 
176 /*
177  if ( m_pGLManager->CreateContext( m_screen_width, m_screen_height )) {
178  MODebug2->Error("moRenderManager::Init > Couldn't create GL Context");
179  return false;
180  } else {
181  MODebug2->Message("moRenderManager::Init > GL Context Created");
182  }
183 */
184  /*** GLEW INIT */
185 #ifndef OPENGLESV2
186  MODebug2->Message("moRenderManager::Init > Initializing glew.");
187  GLenum err = glewInit();
188  if (GLEW_OK != err)
189  {
190  // Problem: glewInit failed, something is seriously wrong.
191  MODebug2->Error(moText("moRenderManager::Init > GLEW Error: ")+ moText((char*)glewGetErrorString(err)));
192  cout << glewGetErrorString(err) << endl;
193  return false;
194 
195  }
196  MODebug2->Message("moRenderManager::Init > glew initialized succesfully!");
197 
198  GLint max_tex_size = 0.0f;
199  GLint max_tex_rect_size = 0.0f;
200  GLint max_tex_buf_size = 0.0f;
201 // GLint64 max_tex_buf_size64 = 0.0f;
202 // GLint max_tex_buf_size_arb = 0.0f;
203 
204 
205  MODebug2->Message( moText("moRenderManager::Init > Using GLEW ") + moText((char*)glewGetString(GLEW_VERSION)) );
206  MODebug2->Message( moText("moRenderManager::Init > glActiveTextureARB: ") + IntToStr( (long)glActiveTextureARB) );
207  MODebug2->Message( moText("moRenderManager::Init > glMultiTexCoord2fARB: ") + IntToStr( (long)glMultiTexCoord2fARB ) );
208  MODebug2->Message( moText("moRenderManager::Init > GLEW_ARB_texture_non_power_of_two: ") + IntToStr(GLEW_ARB_texture_non_power_of_two) );
209  MODebug2->Message( moText("moRenderManager::Init > GLEW_ARB_color_buffer_float: ") + IntToStr(GLEW_ARB_color_buffer_float) );
210  MODebug2->Message( moText("moRenderManager::Init > GLEW_ARB_multitexture: ") + IntToStr(GLEW_ARB_multitexture) );
211  MODebug2->Message( moText("moRenderManager::Init > GL_EXT_gpu_shader4: ") + IntToStr(GL_EXT_gpu_shader4) );
212  MODebug2->Message( moText("moRenderManager::Init > GLEW_EXT_geometry_shader4: ") + IntToStr(GLEW_EXT_geometry_shader4) );
213  MODebug2->Message( moText("moRenderManager::Init > GLEW_ARB_imaging: ") + IntToStr(GLEW_ARB_imaging) );
214  MODebug2->Message( moText("moRenderManager::Init > GLEW_ARB_shading_language_100: ") + IntToStr(GLEW_ARB_shading_language_100) );
215  MODebug2->Message( moText("moRenderManager::Init > GLEW_EXT_framebuffer_object: ") + IntToStr(GLEW_EXT_framebuffer_object) );
216  MODebug2->Message( moText("moRenderManager::Init > GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB: ") + IntToStr(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB) );
217  MODebug2->Message( moText("moRenderManager::Init > GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB: ") + IntToStr(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB) );
218 
219  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
220  MODebug2->Message( moText("moRenderManager::Init > Max Texture Size: ") + IntToStr(max_tex_size) );
221  glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, &max_tex_rect_size);
222  MODebug2->Message( moText("moRenderManager::Init > Max Texture Rectangle Size: ") + IntToStr(max_tex_rect_size) );
223  glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &max_tex_buf_size);
224  MODebug2->Message( moText("moRenderManager::Init > Max Texture Buffer Size: ") + IntToStr(max_tex_buf_size) );
225  //glGetInteger64v(GL_MAX_TEXTURE_BUFFER_SIZE, &max_tex_buf_size64);
226  //MODebug2->Message( moText("moRenderManager::Init > Max Texture Buffer Size (64): ") + IntToStr(max_tex_buf_size64) );
227  //glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_ARB, &max_tex_buf_size_arb);
228  //MODebug2->Message( moText("moRenderManager::Init > Max Texture Buffer Size Arb: ") + IntToStr(max_tex_buf_size_arb) );
229 
230 #endif
231  if (m_render_tex_moid[0]==-1) {
233  } else {
234  //resize textures
236  }
237 
238 
239  if (m_render_tex_moid[1]==-1) {
241  } else {
242  //resize textures
244  }
245 
246 
247  if (m_render_tex_moid[2]==-1) {
249  } else {
250  //resize textures
252  }
253 
254 
255  if (m_render_tex_moid[3]==-1) {
257  } else {
258  //resize textures
260  }
261 
262 
263 
264  if (m_render_tex_moid[4]==-1) {
266  } else {
267  //resize textures
269  }
270  if (m_render_tex_moid[5]==-1) {
272  } else {
273  //resize textures
275  }
276 
277 
280 
283 
286 
288 
289  if ( /*IsRenderToFBOEnabled()*/ GLEW_EXT_framebuffer_object )
290  {
292  MODebug2->Message( moText("moRenderManager::Init > Using framebuffer_object: creating one fbo per predefined textures (4). ") );
294 
295  MOuint attach_point;
296  for (int i = 0; i < 4; i++)
297  {
300  m_pTextureManager->GetGLId(m_render_tex_moid[i]), attach_point);
301 
303  if (pRenderTex) {
304  pRenderTex->SetFBO(m_pFBManager->GetFBO(m_fbo_idx));
305  pRenderTex->SetFBOAttachPoint(attach_point);
306  m_render_attach_points[i] = attach_point;
307  }
308  }
310 
311  } else MODebug2->Message( moText("moRenderManager::Init > Framebuffer objects unavailable.") );
312  return true;
313 }
314 
316 {
318 
319  m_pGLManager = NULL;
320  m_pFBManager = NULL;
321  m_pTextureManager = NULL;
322 
323  return true;
324 }
325 
327 {
328  return (m_render_to_texture_mode == RENDERMANAGER_MODE_FRAMEBUFFER) && GLEW_EXT_framebuffer_object;
329 }
330 
332 {
334 }
335 
337 {
338  m_render_to_texture_mode = p_render_to_texture_mode;
339 }
340 
342 {
343 }
344 
346 {
347  Lock();
348  if (m_pGLManager)
350 }
351 
353 {
354  if (m_pGLManager)
356  Unlock();
357 }
358 
360 {
361 }
362 
364 {
365  Lock();
367 }
368 
370 {
372  Unlock();
373 }
374 
376 {
377  if (IsRenderToFBOEnabled())
379 }
380 
382 {
383  Lock();
386  m_saved_screen = false;
387 }
388 
389 int
391 
392  if (p_pObj==NULL || p_pCamera==NULL) return 0;
393  if (!m_pTextureManager) return 0;
394  if (!m_pGLManager) return 0;
395  if (!m_pSHManager) return 0;
396  if ( !m_pSHManager->GetRenderShader().Initialized() ) return 0;
397 /*
398  const float vx[] = {
399  -0.5f, -0.5f, 0.0f,
400  -0.5f, 0.5f, 0.0f,
401  0.5f, 0.5f, 0.0f,
402 
403  0.5f, 0.5f, 0.0f,
404  0.5f, -0.5f, 0.0f,
405  -0.5f, -0.5f, 0.0f
406  };
407  const float cx[] = {
408  1.0f, 0.5f, 0.5f,
409  0.5f, 1.0f, 0.5f,
410  0.5f, 0.5f, 1.0f,
411 
412  0.5f, 0.5f, 1.0f,
413  1.0f, 1.0f, 1.0f,
414  1.0f, 1.0f, 1.0f
415  };
416  const float tx[] = {
417  0.0f, 1.0f,
418  0.0f, 0.0f,
419  1.0f, 0.0f,
420 
421  1.0f, 0.0f,
422  1.0f, 1.0f,
423  0.0f, 1.0f
424  };*/
425 
426  //moGLManager* pGLMan = m_pGLManager;
427 
428  moGeometry& Geo( p_pObj->m_Geometry );
429  moMaterial& Mat( p_pObj->m_Material );
430  //const moGLMatrixf& PMatrix( p_src.GetProjection() );
431  moGLMatrixf& PMatrix( *p_pCamera );
432  const moGLMatrixf& MMatrix( p_pObj->GetModelMatrix() );
433  moGLMatrixf Result;
434  Result = MMatrix*PMatrix;
435 
436 
437  MOuint color_index = m_pSHManager->GetRSHColorIndex();
438  MOuint opacity_index = m_pSHManager->GetRSHOpacityIndex();
439  MOuint colors_index = m_pSHManager->GetRSHColorsIndex();
440  MOuint position_index = m_pSHManager->GetRSHPositionIndex();
441  MOuint normal_index = m_pSHManager->GetRSHNormalIndex();
442  MOuint texcoord_index = m_pSHManager->GetRSHTexCoordIndex();
443  MOuint texcoordedge_index = m_pSHManager->GetRSHTexCoordEdgeIndex();
445  MOuint texture_index = m_pSHManager->GetRSHTextureIndex();
446  MOuint wireframe_index = m_pSHManager->GetRSHWireframeWidthIndex();
447  MOuint tex_wsegments_index = m_pSHManager->GetRSHTexWSegmentsIndex();
448  MOuint tex_hsegments_index = m_pSHManager->GetRSHTexHSegmentsIndex();
449  MOuint light_index = m_pSHManager->GetRSHLightIndex();
450 
453  } else return 0;
454  //m_pGLManager->SetDefaultPerspectiveView( ScreenWidth(), ScreenHeight() );
455  //moGLMatrixf& PMatrix( pGLMan->GetProjectionMatrix() );
456  //moGLMatrixf& MMatrix( pGLMan->GetModelMatrix() );
457  const moFaceArray& Faces(Geo.GetFaces());
458  //const moVertexArray& Vertices(Geo.GetVertices());
459  const float* Gpx = Geo.GetVerticesBuffer();
460  const float* Gcx = Geo.GetColorBuffer();
461  const float* Gtx = Geo.GetVerticesUVBuffer();
462  const float* Gnx = Geo.GetNormalsBuffer();
463 
464  int facesCount = Faces.Count();
465 
466 
467  //PMatrix.MakeIdentity();
468  //MMatrix.MakeIdentity();
469  //MMatrix.Scale( 0.5, 0.5, 0.5 );
470  //MMatrix.Rotate( ((float)steps/(float)stepi)*1.0*moMathf::DEG_TO_RAD, 1.0, 1.0, 1.0 );
471  //MMatrix.Translate( 0.5f, 0.5f, -steps/1000.0f-3.0f );
472  //MMatrix.Translate( 0.0f, 0.0f, -4.0f );
473  //MODebug2->Message( "model:\n"+MMatrix.ToJSON() );
474  //MODebug2->Message( "projection\n"+PMatrix.ToJSON() );
475  //Result = MMatrix*PMatrix;
476 
477  const float *pfv = Result.GetPointer();
478  //MODebug2->Message( "Result:\n"+Result.ToJSON() );
479 
480  moTexture* pMap = Mat.m_Map;
481  if (pMap) {
482  //int Tglid = pMap->GetGLId();
483  glEnable( GL_TEXTURE_2D );
484  glActiveTexture( GL_TEXTURE0 );
485  glBindTexture( GL_TEXTURE_2D, Mat.m_MapGLId );
486  //MODebug2->Message( "Tglid:\n"+IntToStr(Tglid) );
487  }
488  glUniformMatrix4fv( matrix_index, 1, GL_FALSE, pfv );
489  glUniform1i( texture_index, 0 );
490  glUniform1f( wireframe_index, Mat.m_fWireframeWidth );
491  glUniform1f( tex_wsegments_index, Mat.m_fTextWSegments );
492  glUniform1f( tex_hsegments_index, Mat.m_fTextHSegments );
493  glUniform3fv( light_index, 1, &Mat.m_vLight[0] );
494  glUniform3fv( color_index, 1, &Mat.m_Color[0] );
495  glUniform1f( opacity_index, Mat.m_fOpacity );
496 
497  glEnableVertexAttribArray( position_index );
498  glVertexAttribPointer( position_index, 3, GL_FLOAT, false, 0, &Gpx[0] ); // Set data type and location.
499 
500  glEnableVertexAttribArray( colors_index );
501  glVertexAttribPointer( colors_index, 3, GL_FLOAT, false, 0, &Gcx[0] );
502 
503  glEnableVertexAttribArray( texcoord_index );
504  glVertexAttribPointer( texcoord_index, 2, GL_FLOAT, false, 0, &Gtx[0] ); // Set data type and location.
505 
506  glEnableVertexAttribArray( texcoordedge_index );
507  glVertexAttribPointer( texcoordedge_index, 2, GL_FLOAT, false, 0, &Gtx[0] ); // Set data type and location.
508  //int vertexCount = p_src.m_Geometry.GetVertices().Count();
509  //int facesCount = p_src.m_Geometry.GetFaces().Count();
510  glEnableVertexAttribArray( normal_index );
511  glVertexAttribPointer( normal_index, 3, GL_FLOAT, false, 0, &Gnx[0] );
512 
513  switch(Mat.m_PolygonMode) {
514 
515  case MO_POLYGONMODE_LINE:
516  for(int i = 0; i < facesCount*3; i += 3)
517  glDrawArrays(GL_LINE_LOOP, i, 3);
518  break;
519 
521  glDrawArrays(GL_POINTS, 0, facesCount*3 );
522  break;
523 
524  case MO_POLYGONMODE_FILL:
525  default:
526  glDrawArrays( GL_TRIANGLES, 0, facesCount*3 ); //
527  break;
528 
529  }
530 
531  glDisableVertexAttribArray( position_index );
532  glDisableVertexAttribArray( colors_index );
533  glDisableVertexAttribArray( texcoord_index );
534  glDisableVertexAttribArray( texcoordedge_index );
535  glDisableVertexAttribArray( normal_index );
536 
539  }
540 
541 
542  return 1;
543 }
544 
545 
547 {
549  Unlock();
550 }
551 
553 {
555 /*
556  moBucket *pbucket=NULL;
557  void* pbuffer;
558  int size;
559 
560  if (m_pFramesPool)
561  if(!m_pFramesPool->IsFull()) {
562 
563  moTexture* pFinalTexture = m_pTextureManager->GetTexture( m_pTextureManager->m_preview_texture_idx );
564 
565  size = pFinalTexture->GetWidth() * pFinalTexture->GetHeight() * 3;
566 
567  pbucket = new moBucket();
568  if(pbucket!=NULL) {
569 
571  pbucket->BuildBucket( size, 0 );
572 
574  pFinalTexture->GetBuffer( (void*)pbucket->GetBuffer(), GL_BGR_EXT, GL_UNSIGNED_BYTE );
575 
576  if(m_pFramesPool->AddBucket( pbucket )) {
577 
578  //Width = 720;
579  //Height = 480;
580  }
581  }
582  }
583 
584 */
585 /*
586  if (IsRenderToFBOEnabled())
587  m_pFBManager->UnbindFBO();*/
588 }
589 
590 void moRenderManager::DrawTexture(MOint p_resolution, MOint p_tex_num)
591 {
592  if (p_resolution == MO_SCREEN_RESOLUTION) DrawTexture(m_screen_width, m_screen_height, p_tex_num);
593  else if (p_resolution == MO_RENDER_RESOLUTION) DrawTexture(m_render_width, m_render_height, p_tex_num);
594 }
595 
596 void moRenderManager::DrawTexture( MOint p_width, MOint p_height, MOint p_tex_num )
597 {
598  if (ValidSourceTexNum(p_tex_num) && m_pGLManager )
599  {
600  Lock();
601 
603 
604  m_pGLManager->SetOrthographicView(p_width, p_height, 0.0, p_width, 0.0, p_height );
605 
607 
608  glBindTexture(GL_TEXTURE_2D, ptex->GetGLId());
609 #ifndef OPENGLESV2
610  glBegin(GL_QUADS);
611  glTexCoord2f(0, 0.0);
612  glVertex2f(0, 0);
613 
614  glTexCoord2f(ptex->GetMaxCoordS(), 0.0);
615  glVertex2f(p_width, 0);
616 
617  glTexCoord2f(ptex->GetMaxCoordT(), ptex->GetMaxCoordS());
618  glVertex2f(p_width, p_height);
619 
620  glTexCoord2f(0, ptex->GetMaxCoordT());
621  glVertex2f(0, p_height);
622  glEnd();
623 #else
624 
625 #endif
626  glBindTexture(GL_TEXTURE_2D, 0);
627 
629 
630  Unlock();
631  }
632 }
633 
635 {
636  if (!m_saved_screen)
637  {
639  m_saved_screen = true;
640  }
641 }
642 
645 
646 //moText pathname, moText& screenshot_result
647 bool moRenderManager::PreviewShot( bool shot_start ) {
648 
649 /*start absolute timer, one shot each*/
650  if( shot_start && !m_PreviewShotTimer.Started()) {
654  }
655 
656  if( m_PreviewShotTimer.Started()) {
657  if (m_PreviewShotTimer.Duration()>=1000) {
658 
659  moText sshot = m_pResourceManager->GetDataMan()->GetDataPath()+moSlash+moText("previewshots");
660  moText preview_shot_filename = moText("preview_shot_")+IntToStr(m_PreviewShotIteration,7);
661  moText result;
662  m_pResourceManager->GetRenderMan()->Screenshot( sshot, result, "JPG", preview_shot_filename );
663  MODebug2->Message( "moRenderManager::PreviewShot() > " + result );
669  }
670  }
671  }
672 
673  return true;
674 }
675 
676 bool moRenderManager::Screenshot( moText pathname, moText& screenshot_result, const moText& image_format, const moText& file_pattern ) {
677 
679 
680  moTexture* TexScreen = m_pTextureManager->GetTexture( m_render_tex_moid[MO_SCREEN_TEX] );
681 
682  if (TexScreen) {
684  glBindTexture(GL_TEXTURE_2D, TexScreen->GetGLId() );
688  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, TexScreen->GetWidth(), TexScreen->GetHeight(), 0 );
689  glBindTexture(GL_TEXTURE_2D, 0);
690 
691 
692  time_t rawtime;
693  char strbuffer[0x100];
694  struct tm * timeinfo;
695 
696  //srand(2);
697  //int randcode = rand();
698 
699 
700  time(&rawtime);
701  timeinfo = localtime ( &rawtime );
702  strftime ( strbuffer, 80, "%Y-%m-%d-%H-%M-%S", timeinfo );
703  moText datetime = strbuffer;
704  strftime ( strbuffer, 80, "%Y-%m-%d", timeinfo );
705  moText date = strbuffer;
706 
707 
708  moText screenshot_filename;
709  moText pat_date = moText("{DATE}");
710  moText pat_date_time = moText("{DATETIME}");
711  moText pat_number = moText("{####}");
712  screenshot_filename = file_pattern;
713  //screenshot_filename.Replace( pat_date, date );
714  //screenshot_filename.Replace( pat_date_time, datetime );
715  //screenshot_filename.Replace( pat_number, IntToStr( screenshots_c, 4 ) );
716  if (screenshot_filename=="") {
717  screenshot_filename= "screen_" + IntToStr( screenshots_c, 7 );
718  screenshots_c+= 1;
719  }
720 
721  if (
722  screenshot_filename=="image_{DATETIME}_{####}.png"
723  ) {
724 
725  //=="image_{DATETIME}_{####}.png")
726  screenshot_filename= "screen_" + IntToStr( screenshots_c, 7 );
727  screenshots_c+= 1;
728 
729  }
730 
731 
732 
733  moText screenshot_name;
734  moText screenshot_path;
735  if (pathname=="") {
736  screenshot_path = m_pResourceManager->GetDataMan()->GetDataPath() + moSlash + moText("moldeo_screenshots");
737 
738  //screenshot_name = screenshot_path + moSlash + moText(datetime)+ moText("_") + IntToStr(screenshots_c);
739  screenshot_name = screenshot_path + moSlash + screenshot_filename;
740  } else {
741  screenshot_path = pathname;
742  //screenshot_name = screenshot_path + moSlash + moText(datetime)+ moText("_")+ IntToStr(screenshots_c);
743  screenshot_name = screenshot_path + moSlash + screenshot_filename;
744  }
745 
747  //if ( !moDirectory( screenshot_path ).Exists() ) {
748  if (!moFileManager::DirectoryExists(screenshot_path)) {
749  if (!moFileManager::CreateDirectory(screenshot_path) ) {
750  MODebug2->Error("could not create directory: "+ screenshot_path);
751  return false;
752  }
753  }
754 
756  screenshot_result = TexScreen->CreateThumbnail( image_format, m_pResourceManager->GetRenderMan()->ScreenWidth(), m_pResourceManager->GetRenderMan()->ScreenHeight(), screenshot_name );
757 
758  }
759 
760  }
761 
762 
763  return true;
764 
765 }
766 
767 
768 
770 {
771  if (ValidDestTexNum(p_tex_num))
772  {
773 
774  if (IsRenderToFBOEnabled())
775  {
778  }
779  else m_pFBManager->BindScreenFB();
780 
781  moTexture* pScreenText;
782 
783  pScreenText = m_pTextureManager->GetTexture( m_render_tex_moid[p_tex_num] );
784 
785  if (pScreenText) {
786  glBindTexture(GL_TEXTURE_2D, pScreenText->GetGLId() );
787  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, m_render_width, m_render_height, 0);
788  glBindTexture(GL_TEXTURE_2D, 0);
789  }
790 
793  }
794 }
795 
797 {
798  if (ValidSourceTexNum(p_tex_num)) return m_pTextureManager->GetGLId(m_render_tex_moid[p_tex_num]);
799  else return -1;
800 }
801 
802 
804 {
805  return GLEW_ARB_multitexture;
806 }
807 
809 {
810  return GLEW_EXT_framebuffer_object;
811 }
812 
814 {
815  return GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shading_language_100;
816 
817 }
818 
820  return !(GLEW_ARB_texture_non_power_of_two);
821 }
822 
824 /*
825  GLint params[4];
826 
827  glGetIntegerv( GL_VIEWPORT, &params[0]);
828 
829  m_screen_width = params[2];
830  m_screen_height = params[3];
831 */
832  return m_screen_width;
833 }
834 
836 /*
837  GLint params[4];
838 
839  glGetIntegerv( GL_VIEWPORT, &params[0]);
840 
841  m_screen_width = params[2];
842  m_screen_height = params[3];
843 */
844  return m_screen_height;
845 }
846 
848  return m_interface_width;
849 }
850 
852 
853  return m_interface_height;
854 }
855 
856 
858 
859  float prop = 1.0;
860  int w = ScreenWidth();
861  int h = ScreenHeight();
862 
863  if ( w == 0 || h == 0 ) {
864  w = 1; h = 1; prop = 1.0;
865  }
866  else {
867  prop = (float) h / (float) w;
868  }
869 
870  return prop;
871 
872 }
873 
874 
876  return m_render_width;
877 }
878 
880  return m_render_height;
881 }
882 
884 
885  float prop = 1.0;
886  int w = RenderWidth();
887  int h = RenderHeight();
888 
889  if ( w == 0 || h == 0 ) {
890  w = 1; h = 1; prop = 1.0;
891  }
892  else {
893  prop = (float) h / (float) w;
894  }
895 
896  return prop;
897 
898 }
899 
900 void moRenderManager::SetView( int p_width, int p_height ) {
901 
902  glViewport(0, 0, p_width, p_height);
903  m_screen_width = p_width;
904  m_screen_height = p_height;
906 
907 
908 
909 }
910 
911 
912 void moRenderManager::SetInterfaceView( int p_width, int p_height ) {
913  m_interface_width = p_width;
914  m_interface_height = p_height;
915 
916 }
moVector3f m_vLight
Definition: moGUIManager.h:250
MOboolean FramebufferObjectSupported() const
moTextureManager * m_pTextureManager
void SetPerspectiveView(MOint p_width, MOint p_height, double fovy=60.0, double aspect=1.0, double znear=0.1, double zfar=4000.0)
moTexParam GetTexParam(MOuint p_moid)
MOboolean Initialized()
Pregunta si está inicializado.
Definition: moAbstract.cpp:153
bool Unlock()
Definition: moLock.cpp:137
sólo líneas
Definition: moTypes.h:475
void BindScreenFB()
MOuint GetRSHTexHSegmentsIndex()
virtual MOboolean Finish()
MOuint GetRSHProjectionMatrixIndex()
moShaderManager * m_pSHManager
virtual float * GetVerticesUVBuffer()
virtual float * GetColorBuffer()
float m_fTextHSegments
Definition: moGUIManager.h:249
void Error(moText p_text)
Anuncia y registra un error.
Definition: moAbstract.cpp:79
void SetName(const moText &p_name)
float m_fTextWSegments
Definition: moGUIManager.h:248
virtual const moFaceArray & GetFaces() const
Definition: moGUIManager.h:168
virtual long Duration()
Devuelve el valor del reloj del temporizador.
Definition: moTimer.cpp:81
int CreateLayer(moEffect *p_scene_effect)
MOuint GetRSHTexCoordEdgeIndex()
moRenderManagerMode
void UnbindScreenFB()
moShaderGLSL & GetRenderShader()
virtual ~moDisplay()
MOboolean ValidDestTexNum(MOint p_tex_num) const
moRenderManager * GetRenderMan()
#define MOboolean
Definition: moTypes.h:385
MOuint GetRSHNormalIndex()
Matrices para transformaciones en Open GL.
Definition: moGLManager.h:71
int Render(moObject3D *p_pObj, moCamera3D *p_pCamera)
virtual float * GetVerticesBuffer()
MOint RenderTexGLId(MOint p_tex_num)
MOboolean IsTextureNonPowerOf2Disabled() const
int previewshotmax
MOint AddTexture(MOuint p_type, moText p_name, moTexParam p_tex_param=MODefTex2DParams)
void SetResourceType(moResourceType p_restype)
MOuint GetRSHLightIndex()
float RenderProportion() const
MOboolean RenderResEqualScreenRes()
MOboolean BuildEmpty(MOuint p_width, MOuint p_height)
Definition: moTexture.cpp:113
moVector3iArray moFaceArray
Definition: moGUIManager.h:78
MOuint GetRSHTextureIndex()
#define MO_RENDER_RESOLUTION
MOuint GetRSHColorIndex()
MOint InterfaceHeight() const
void SetReadTexture(MOuint p_attach_point)
static bool CreateDirectory(moDirectory Dir)
virtual void StopShader()
moGLManager * GetGLMan()
MOint m_render_tex_moid[6]
void DrawTexture(MOint p_resolution, MOint p_tex_num)
moShaderManager * GetShaderMan()
MOboolean m_saved_screen
MOboolean IsRenderToFBOEnabled()
#define MO_SCREEN_RESOLUTION
virtual MOboolean Init()
MOboolean DeleteFBO(MOuint p_fbo)
Definition: moFBManager.cpp:80
const moGLMatrixf & GetModelMatrix() const
moPolygonModes m_PolygonMode
Definition: moGUIManager.h:276
moText CreateThumbnail(moText p_bufferformat, int w, int h, moText newfilename=moText(""))
Definition: moTexture.cpp:829
clase de para manejar textos
Definition: moText.h:75
moTexture * GetTexture(MOuint p_moid)
MOuint GetRSHOpacityIndex()
void SetFBOAttachPoint(MOuint p_fbo_attach_point)
Definition: moTexture.h:203
moResourceManager * m_pResourceManager
Puntero al administrador de recursos.
void SetInterfaceView(int p_width, int p_height)
void Stop()
Detiene el temporizador.
Definition: moTimer.h:219
MOint RenderHeight() const
MOuint CreateFBO()
Definition: moFBManager.cpp:72
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
Definition: moTypes.h:532
moDisplay & operator=(const moDisplay &p_src)
void SetFBO(moFBO *p_fbo)
Definition: moTexture.h:191
moRenderManagerMode m_render_to_texture_mode
moMaterial m_Material
Definition: moGUIManager.h:317
moText0 moText
Definition: moText.h:291
MOuint AddTexture(MOuint p_width, MOuint p_height, const moTexParam &p_param, MOuint p_glid, MOuint &p_attach_point)
Definition: moFBO.cpp:174
void SetOutputConfiguration(moRenderOutputConfiguration p_output_configuration)
moGeometry m_Geometry
Definition: moGUIManager.h:316
bool Lock()
Definition: moLock.cpp:101
moDecoderManager * GetDecoderMan()
MOfloat GetMaxCoordT() const
Definition: moTexture.h:301
#define MO_SCREEN_TEX
Definition: moTypes.h:421
#define MOint
Definition: moTypes.h:388
MOuint GetRSHTexCoordIndex()
void SaveGLState()
MOuint GetRSHPositionIndex()
moTexture * m_Map
Definition: moGUIManager.h:274
MOuint GetGLId(MOuint p_moid)
moColor m_Color
Definition: moGUIManager.h:273
MOboolean AddDepthStencilBuffer()
Definition: moFBO.cpp:86
MOuint GetGLId() const
Definition: moTexture.h:224
MOint InterfaceWidth() const
void SetFrameBufferObjectActive(bool active=true)
clase base para el manejo de una textura
Definition: moTexture.h:78
Administrador de moBucket 's.
Definition: moBuckets.h:152
void RestoreGLState()
void CopyRenderToTexture(MOint p_tex_num)
moFBManager * GetFBMan()
void SetLabelName(const moText &p_labelname)
MOboolean ValidSourceTexNum(MOint p_tex_num) const
MOuint GetRSHColorsIndex()
void UnbindFBO()
MOint ScreenHeight() const
MOfloat GetMaxCoordS() const
Definition: moTexture.h:296
float m_fWireframeWidth
Definition: moGUIManager.h:247
moFBO * GetFBO(MOuint p_fbo)
Definition: moFBManager.h:93
MOint RenderWidth() const
Base abstracta de base para las geometrías.
Definition: moGUIManager.h:127
static moDebug * MODebug2
Clase de impresión de errores para depuración
Definition: moAbstract.h:225
virtual void Start()
Inicia el temporizador.
Definition: moTimer.cpp:75
void SetMoldeoGLState()
moDataManager * GetDataMan()
void SetView(int p_width, int p_height)
MOuint GetHeight() const
Definition: moTexture.h:261
moGLManager * m_pGLManager
void RenderLayer(int layer_id)
bool PreviewShot(bool shot_start=false)
moBucketsPool * m_pFramesPool
int screenshots_c
float ScreenProportion() const
virtual ~moRenderManager()
moDecoderManager * m_pDecoderManager
MOuint GetRSHTexWSegmentsIndex()
moTimerAbsolute m_PreviewShotTimer
moText GetDataPath()
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
bool Started() const
Devuelve el estado del temporizador.
Definition: moTimer.h:248
clase base para objetos dibujables
Definition: moEffect.h:82
moDefineDynamicArray(moRenderClips) moDefineDynamicArray(moDisplays) moDisplay
MOuint GetRSHWireframeWidthIndex()
MOuint m_render_attach_points[4]
moRenderOutputConfiguration m_OutputConfiguration
virtual void StartShader()
MOboolean ShadersSupported() const
MOboolean MultiTextureSupported() const
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)
moRenderOutputConfiguration & GetOutputConfiguration()
MOint ScreenWidth() const
moFBManager * m_pFBManager
static bool DirectoryExists(moText dirname)
void SetType(moMoldeoObjectType p_type)
virtual float * GetNormalsBuffer()
MOint m_MapGLId
Definition: moGUIManager.h:275
moResolution m_OutputResolution
normal mode need this
bool Screenshot(moText pathname, moText &screenshot_result, const moText &image_format="PNG", const moText &file_pattern="image_{DATETIME}_{####}.png")
moTextureManager * GetTextureMan()
MOboolean BindFBO(MOuint p_fbo)
void SetRenderToTexMode(moRenderManagerMode p_render_to_texture_mode)