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.
moRenderManager.cpp
Ir a la documentación de este archivo.
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 
44 }
45 
46 moDisplay::moDisplay( int w, int h) {
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 
70  return (*this);
71 }
72 
73 
74 
75 
76 
78 
79  SetType( MO_OBJECT_RESOURCE );
80  SetResourceType( MO_RESOURCETYPE_RENDER );
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 
99  m_OutputConfiguration.m_RenderResolution.width = 0;
100  m_OutputConfiguration.m_RenderResolution.height = 0;
101 
102  m_OutputConfiguration.m_OutputResolution.width = 0;
103  m_OutputConfiguration.m_OutputResolution.height = 0;
104 
105  m_pFramesPool = new moBucketsPool();
106 
107  m_RenderLock.Unlock();
108 }
109 
111  delete m_pFramesPool;
112  m_RenderLock.Unlock();
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){
151  m_pGLManager = m_pResourceManager->GetGLMan();
152  m_pFBManager = m_pResourceManager->GetFBMan();
153  m_pTextureManager = m_pResourceManager->GetTextureMan();
154  m_pSHManager = m_pResourceManager->GetShaderMan();
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 
168  if ( m_render_to_texture_mode == RENDERMANAGER_MODE_VDPAU ) {
169 
170  m_pDecoderManager = m_pResourceManager->GetDecoderMan();
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  MODebug2->Message( moText("moRenderManager::Init > GL_MAX_COLOR_ATTACHMENTS: ") + IntToStr(GL_MAX_COLOR_ATTACHMENTS) );
219 
220  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
221  MODebug2->Message( moText("moRenderManager::Init > Max Texture Size: ") + IntToStr(max_tex_size) );
222  glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, &max_tex_rect_size);
223  MODebug2->Message( moText("moRenderManager::Init > Max Texture Rectangle Size: ") + IntToStr(max_tex_rect_size) );
224  glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &max_tex_buf_size);
225  MODebug2->Message( moText("moRenderManager::Init > Max Texture Buffer Size: ") + IntToStr(max_tex_buf_size) );
226  //glGetInteger64v(GL_MAX_TEXTURE_BUFFER_SIZE, &max_tex_buf_size64);
227  //MODebug2->Message( moText("moRenderManager::Init > Max Texture Buffer Size (64): ") + IntToStr(max_tex_buf_size64) );
228  //glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_ARB, &max_tex_buf_size_arb);
229  //MODebug2->Message( moText("moRenderManager::Init > Max Texture Buffer Size Arb: ") + IntToStr(max_tex_buf_size_arb) );
230 
231 #endif
232  if (m_render_tex_moid[0]==-1) {
233  m_render_tex_moid[0] = m_pTextureManager->AddTexture("render_texture", m_render_width, m_render_height);
234  } else {
235  //resize textures
236  m_pTextureManager->GetTexture( m_render_tex_moid[0])->BuildEmpty(m_render_width, m_render_height);
237  }
238 
239 
240  if (m_render_tex_moid[1]==-1) {
241  m_render_tex_moid[1] = m_pTextureManager->AddTexture("screen_texture", m_render_width, m_render_height);
242  } else {
243  //resize textures
244  m_pTextureManager->GetTexture( m_render_tex_moid[1])->BuildEmpty(m_render_width, m_render_height);
245  }
246 
247 
248  if (m_render_tex_moid[2]==-1) {
249  m_render_tex_moid[2] = m_pTextureManager->AddTexture("effects_texture", m_render_width, m_render_height);
250  } else {
251  //resize textures
252  m_pTextureManager->GetTexture( m_render_tex_moid[2])->BuildEmpty(m_render_width, m_render_height);
253  }
254 
255 
256  if (m_render_tex_moid[3]==-1) {
257  m_render_tex_moid[3] = m_pTextureManager->AddTexture("final_texture", m_render_width, m_render_height);
258  } else {
259  //resize textures
260  m_pTextureManager->GetTexture( m_render_tex_moid[3])->BuildEmpty(m_render_width, m_render_height);
261  }
262 
263 
264 
265  if (m_render_tex_moid[4]==-1) {
266  m_render_tex_moid[4] = m_pTextureManager->AddTexture("left_texture", m_render_width/2, m_render_height);
267  } else {
268  //resize textures
269  m_pTextureManager->GetTexture( m_render_tex_moid[4])->BuildEmpty(m_render_width, m_render_height);
270  }
271  if (m_render_tex_moid[5]==-1) {
272  m_render_tex_moid[5] = m_pTextureManager->AddTexture("right_texture", m_render_width/2, m_render_height);
273  } else {
274  //resize textures
275  m_pTextureManager->GetTexture( m_render_tex_moid[5])->BuildEmpty(m_render_width, m_render_height);
276  }
277 
278 
279  if (m_OutputConfiguration.m_RenderResolution.width==0) m_OutputConfiguration.m_RenderResolution.width = m_render_width;
280  if (m_OutputConfiguration.m_RenderResolution.height==0) m_OutputConfiguration.m_RenderResolution.height = m_render_height;
281 
282  if (m_OutputConfiguration.m_OutputResolution.width==0) m_OutputConfiguration.m_OutputResolution.width = m_screen_width;
283  if (m_OutputConfiguration.m_OutputResolution.height==0) m_OutputConfiguration.m_OutputResolution.height = m_screen_height;
284 
285  m_pGLManager->SetMoldeoGLState();
286  m_pGLManager->SetPerspectiveView(m_screen_width, m_screen_height);
287 
289 
290  if ( /*IsRenderToFBOEnabled()*/ GLEW_EXT_framebuffer_object )
291  {
292  m_pGLManager->SetFrameBufferObjectActive();
293  MODebug2->Message( moText("moRenderManager::Init > Using framebuffer_object: creating one fbo per predefined textures (4). ") );
294  m_fbo_idx = m_pFBManager->CreateFBO();
295 
296  MOuint attach_point;
297  for (int i = 0; i < 4; i++)
298  {
299  m_pFBManager->GetFBO(m_fbo_idx)->AddTexture(m_render_width, m_render_height,
300  m_pTextureManager->GetTexParam(m_render_tex_moid[i]),
301  m_pTextureManager->GetGLId(m_render_tex_moid[i]), attach_point);
302 
303  moTexture* pRenderTex = m_pTextureManager->GetTexture(m_render_tex_moid[i]);
304  if (pRenderTex) {
305  pRenderTex->SetFBO(m_pFBManager->GetFBO(m_fbo_idx));
306  pRenderTex->SetFBOAttachPoint(attach_point);
307  m_render_attach_points[i] = attach_point;
308  }
309  }
310  m_pFBManager->GetFBO(m_fbo_idx)->AddDepthStencilBuffer();
311 
312  } else MODebug2->Message( moText("moRenderManager::Init > Framebuffer objects unavailable.") );
313  return true;
314 }
315 
317 {
318  if (IsRenderToFBOEnabled()) m_pFBManager->DeleteFBO(m_fbo_idx);
319 
320  m_pGLManager = NULL;
321  m_pFBManager = NULL;
322  m_pTextureManager = NULL;
323 
324  return true;
325 }
326 
328 {
329  return (m_render_to_texture_mode == RENDERMANAGER_MODE_FRAMEBUFFER) && GLEW_EXT_framebuffer_object;
330 }
331 
333 {
334  return (m_screen_width == m_render_width) && (m_screen_height == m_render_height);
335 }
336 
338 {
339  m_render_to_texture_mode = p_render_to_texture_mode;
340 }
341 
343 {
344 }
345 
347 {
348  Lock();
349  if (m_pGLManager)
350  m_pGLManager->SaveGLState();
351 }
352 
354 {
355  if (m_pGLManager)
356  m_pGLManager->RestoreGLState();
357  Unlock();
358 }
359 
361 {
362 }
363 
365 {
366  Lock();
367  m_pGLManager->SaveGLState();
368 }
369 
371 {
372  m_pGLManager->RestoreGLState();
373  Unlock();
374 }
375 
377 {
378  if (IsRenderToFBOEnabled())
379  if (m_pFBManager) m_pFBManager->BindFBO(m_fbo_idx, m_render_attach_points[0]);
380 }
381 
383 {
384  Lock();
385  if (m_pGLManager) m_pGLManager->SaveGLState();
386  if (m_pGLManager) m_pGLManager->SetPerspectiveView(m_render_width, m_render_height);
387  m_saved_screen = false;
388 }
389 
390 int
392 
393  if (p_pObj==NULL || p_pCamera==NULL) return 0;
394  if (!m_pTextureManager) return 0;
395  if (!m_pGLManager) return 0;
396  if (!m_pSHManager) return 0;
397  if ( !m_pSHManager->GetRenderShader().Initialized() ) return 0;
398 /*
399  const float vx[] = {
400  -0.5f, -0.5f, 0.0f,
401  -0.5f, 0.5f, 0.0f,
402  0.5f, 0.5f, 0.0f,
403 
404  0.5f, 0.5f, 0.0f,
405  0.5f, -0.5f, 0.0f,
406  -0.5f, -0.5f, 0.0f
407  };
408  const float cx[] = {
409  1.0f, 0.5f, 0.5f,
410  0.5f, 1.0f, 0.5f,
411  0.5f, 0.5f, 1.0f,
412 
413  0.5f, 0.5f, 1.0f,
414  1.0f, 1.0f, 1.0f,
415  1.0f, 1.0f, 1.0f
416  };
417  const float tx[] = {
418  0.0f, 1.0f,
419  0.0f, 0.0f,
420  1.0f, 0.0f,
421 
422  1.0f, 0.0f,
423  1.0f, 1.0f,
424  0.0f, 1.0f
425  };*/
426 
427  //moGLManager* pGLMan = m_pGLManager;
428 
429  moGeometry& Geo( p_pObj->m_Geometry );
430  moMaterial& Mat( p_pObj->m_Material );
431  //const moGLMatrixf& PMatrix( p_src.GetProjection() );
432  moGLMatrixf& PMatrix( *p_pCamera );
433  const moGLMatrixf& MMatrix( p_pObj->GetModelMatrix() );
434  moGLMatrixf Result;
435  Result = MMatrix*PMatrix;
436 
437 
438  MOuint color_index = m_pSHManager->GetRSHColorIndex();
439  MOuint opacity_index = m_pSHManager->GetRSHOpacityIndex();
440  MOuint colors_index = m_pSHManager->GetRSHColorsIndex();
441  MOuint position_index = m_pSHManager->GetRSHPositionIndex();
442  MOuint normal_index = m_pSHManager->GetRSHNormalIndex();
443  MOuint texcoord_index = m_pSHManager->GetRSHTexCoordIndex();
444  MOuint texcoordedge_index = m_pSHManager->GetRSHTexCoordEdgeIndex();
445  MOuint matrix_index = m_pSHManager->GetRSHProjectionMatrixIndex();
446  MOuint texture_index = m_pSHManager->GetRSHTextureIndex();
447  MOuint wireframe_index = m_pSHManager->GetRSHWireframeWidthIndex();
448  MOuint tex_wsegments_index = m_pSHManager->GetRSHTexWSegmentsIndex();
449  MOuint tex_hsegments_index = m_pSHManager->GetRSHTexHSegmentsIndex();
450  MOuint light_index = m_pSHManager->GetRSHLightIndex();
451 
452  if ( m_pSHManager->GetRenderShader().Initialized() ) {
453  m_pSHManager->GetRenderShader().StartShader();
454  } else return 0;
455  //m_pGLManager->SetDefaultPerspectiveView( ScreenWidth(), ScreenHeight() );
456  //moGLMatrixf& PMatrix( pGLMan->GetProjectionMatrix() );
457  //moGLMatrixf& MMatrix( pGLMan->GetModelMatrix() );
458  const moFaceArray& Faces(Geo.GetFaces());
459  //const moVertexArray& Vertices(Geo.GetVertices());
460  const float* Gpx = Geo.GetVerticesBuffer();
461  const float* Gcx = Geo.GetColorBuffer();
462  const float* Gtx = Geo.GetVerticesUVBuffer();
463  const float* Gnx = Geo.GetNormalsBuffer();
464 
465  int facesCount = Faces.Count();
466 
467 
468  //PMatrix.MakeIdentity();
469  //MMatrix.MakeIdentity();
470  //MMatrix.Scale( 0.5, 0.5, 0.5 );
471  //MMatrix.Rotate( ((float)steps/(float)stepi)*1.0*moMathf::DEG_TO_RAD, 1.0, 1.0, 1.0 );
472  //MMatrix.Translate( 0.5f, 0.5f, -steps/1000.0f-3.0f );
473  //MMatrix.Translate( 0.0f, 0.0f, -4.0f );
474  //MODebug2->Message( "model:\n"+MMatrix.ToJSON() );
475  //MODebug2->Message( "projection\n"+PMatrix.ToJSON() );
476  //Result = MMatrix*PMatrix;
477 
478  const float *pfv = Result.GetPointer();
479  //MODebug2->Message( "Result:\n"+Result.ToJSON() );
480 
481  moTexture* pMap = Mat.m_Map;
482  if (pMap) {
483  //int Tglid = pMap->GetGLId();
484  glEnable( GL_TEXTURE_2D );
485  glActiveTexture( GL_TEXTURE0 );
486  glBindTexture( GL_TEXTURE_2D, Mat.m_MapGLId );
487  //MODebug2->Message( "Tglid:\n"+IntToStr(Tglid) );
488  }
489  glUniformMatrix4fv( matrix_index, 1, GL_FALSE, pfv );
490  glUniform1i( texture_index, 0 );
491  glUniform1f( wireframe_index, Mat.m_fWireframeWidth );
492  glUniform1f( tex_wsegments_index, Mat.m_fTextWSegments );
493  glUniform1f( tex_hsegments_index, Mat.m_fTextHSegments );
494  glUniform3fv( light_index, 1, &Mat.m_vLight[0] );
495  glUniform3fv( color_index, 1, &Mat.m_Color[0] );
496  glUniform1f( opacity_index, Mat.m_fOpacity );
497 
498  glEnableVertexAttribArray( position_index );
499  glVertexAttribPointer( position_index, 3, GL_FLOAT, false, 0, &Gpx[0] ); // Set data type and location.
500 
501  glEnableVertexAttribArray( colors_index );
502  glVertexAttribPointer( colors_index, 3, GL_FLOAT, false, 0, &Gcx[0] );
503 
504  glEnableVertexAttribArray( texcoord_index );
505  glVertexAttribPointer( texcoord_index, 2, GL_FLOAT, false, 0, &Gtx[0] ); // Set data type and location.
506 
507  glEnableVertexAttribArray( texcoordedge_index );
508  glVertexAttribPointer( texcoordedge_index, 2, GL_FLOAT, false, 0, &Gtx[0] ); // Set data type and location.
509  //int vertexCount = p_src.m_Geometry.GetVertices().Count();
510  //int facesCount = p_src.m_Geometry.GetFaces().Count();
511  glEnableVertexAttribArray( normal_index );
512  glVertexAttribPointer( normal_index, 3, GL_FLOAT, false, 0, &Gnx[0] );
513 
514  switch(Mat.m_PolygonMode) {
515 
516  case MO_POLYGONMODE_LINE:
517  for(int i = 0; i < facesCount*3; i += 3)
518  glDrawArrays(GL_LINE_LOOP, i, 3);
519  break;
520 
522  glDrawArrays(GL_POINTS, 0, facesCount*3 );
523  break;
524 
525  case MO_POLYGONMODE_FILL:
526  default:
527  glDrawArrays( GL_TRIANGLES, 0, facesCount*3 ); //
528  break;
529 
530  }
531 
532  glDisableVertexAttribArray( position_index );
533  glDisableVertexAttribArray( colors_index );
534  glDisableVertexAttribArray( texcoord_index );
535  glDisableVertexAttribArray( texcoordedge_index );
536  glDisableVertexAttribArray( normal_index );
537 
538  if (m_pSHManager->GetRenderShader().Initialized()) {
539  m_pSHManager->GetRenderShader().StopShader();
540  }
541 
542 
543  return 1;
544 }
545 
546 
548 {
549  if (m_pGLManager) m_pGLManager->RestoreGLState();
550  Unlock();
551 }
552 
554 {
556 /*
557  moBucket *pbucket=NULL;
558  void* pbuffer;
559  int size;
560 
561  if (m_pFramesPool)
562  if(!m_pFramesPool->IsFull()) {
563 
564  moTexture* pFinalTexture = m_pTextureManager->GetTexture( m_pTextureManager->m_preview_texture_idx );
565 
566  size = pFinalTexture->GetWidth() * pFinalTexture->GetHeight() * 3;
567 
568  pbucket = new moBucket();
569  if(pbucket!=NULL) {
570 
572  pbucket->BuildBucket( size, 0 );
573 
575  pFinalTexture->GetBuffer( (void*)pbucket->GetBuffer(), GL_BGR_EXT, GL_UNSIGNED_BYTE );
576 
577  if(m_pFramesPool->AddBucket( pbucket )) {
578 
579  //Width = 720;
580  //Height = 480;
581  }
582  }
583  }
584 
585 */
586 /*
587  if (IsRenderToFBOEnabled())
588  m_pFBManager->UnbindFBO();*/
589 }
590 
591 void moRenderManager::DrawTexture(MOint p_resolution, MOint p_tex_num)
592 {
593  if (p_resolution == MO_SCREEN_RESOLUTION) DrawTexture(m_screen_width, m_screen_height, p_tex_num);
594  else if (p_resolution == MO_RENDER_RESOLUTION) DrawTexture(m_render_width, m_render_height, p_tex_num);
595 }
596 
597 void moRenderManager::DrawTexture( MOint p_width, MOint p_height, MOint p_tex_num )
598 {
599  if (ValidSourceTexNum(p_tex_num) && m_pGLManager )
600  {
601  Lock();
602 
603  m_pGLManager->SaveGLState();
604 
605  m_pGLManager->SetOrthographicView(p_width, p_height, 0.0, p_width, 0.0, p_height );
606 
607  moTexture* ptex = m_pTextureManager->GetTexture( m_render_tex_moid[p_tex_num] );
608 
609  glBindTexture(GL_TEXTURE_2D, ptex->GetGLId());
610 #ifndef OPENGLESV2
611  glBegin(GL_QUADS);
612  glTexCoord2f(0, 0.0);
613  glVertex2f(0, 0);
614 
615  glTexCoord2f(ptex->GetMaxCoordS(), 0.0);
616  glVertex2f(p_width, 0);
617 
618  glTexCoord2f(ptex->GetMaxCoordT(), ptex->GetMaxCoordS());
619  glVertex2f(p_width, p_height);
620 
621  glTexCoord2f(0, ptex->GetMaxCoordT());
622  glVertex2f(0, p_height);
623  glEnd();
624 #else
625 
626 #endif
627  glBindTexture(GL_TEXTURE_2D, 0);
628 
629  m_pGLManager->RestoreGLState();
630 
631  Unlock();
632  }
633 }
634 
636 {
637  if (!m_saved_screen)
638  {
639  CopyRenderToTexture(1);
640  m_saved_screen = true;
641  }
642 }
643 
646 
647 //moText pathname, moText& screenshot_result
648 bool moRenderManager::PreviewShot( bool shot_start ) {
649 
650 /*start absolute timer, one shot each*/
651  if( shot_start && !m_PreviewShotTimer.Started()) {
652  m_PreviewShotTimer.Stop();
653  m_PreviewShotTimer.Start();
654  m_PreviewShotIteration = 0;
655  }
656 
657  if( m_PreviewShotTimer.Started()) {
658  if (m_PreviewShotTimer.Duration()>=1000) {
659 
660  moText sshot = m_pResourceManager->GetDataMan()->GetDataPath()+moSlash+moText("previewshots");
661  moText preview_shot_filename = moText("preview_shot_")+IntToStr(m_PreviewShotIteration,7);
662  moText result;
663  m_pResourceManager->GetRenderMan()->Screenshot( sshot, result, "JPG", preview_shot_filename );
664  MODebug2->Message( "moRenderManager::PreviewShot() > " + result );
665  m_PreviewShotIteration+=1;
666  m_PreviewShotTimer.Stop();
667  m_PreviewShotTimer.Start();
668  if (m_PreviewShotIteration==previewshotmax) {
669  m_PreviewShotTimer.Stop();
670  }
671  }
672  }
673 
674  return true;
675 }
676 
677 bool moRenderManager::Screenshot( moText pathname, moText& screenshot_result, const moText& image_format, const moText& file_pattern ) {
678 
679  if (m_render_tex_moid[MO_SCREEN_TEX]) {
680 
681  moTexture* TexScreen = m_pTextureManager->GetTexture( m_render_tex_moid[MO_SCREEN_TEX] );
682 
683  if (TexScreen) {
685  glBindTexture(GL_TEXTURE_2D, TexScreen->GetGLId() );
689  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, TexScreen->GetWidth(), TexScreen->GetHeight(), 0 );
690  glBindTexture(GL_TEXTURE_2D, 0);
691 
692 
693  time_t rawtime;
694  char strbuffer[0x100];
695  struct tm * timeinfo;
696 
697  //srand(2);
698  //int randcode = rand();
699 
700 
701  time(&rawtime);
702  timeinfo = localtime ( &rawtime );
703  strftime ( strbuffer, 80, "%Y-%m-%d-%H-%M-%S", timeinfo );
704  moText datetime = strbuffer;
705  strftime ( strbuffer, 80, "%Y-%m-%d", timeinfo );
706  moText date = strbuffer;
707 
708 
709  moText screenshot_filename;
710  moText pat_date = moText("{DATE}");
711  moText pat_date_time = moText("{DATETIME}");
712  moText pat_number = moText("{####}");
713  screenshot_filename = file_pattern;
714  //screenshot_filename.Replace( pat_date, date );
715  //screenshot_filename.Replace( pat_date_time, datetime );
716  //screenshot_filename.Replace( pat_number, IntToStr( screenshots_c, 4 ) );
717  if (screenshot_filename=="") {
718  screenshot_filename= "screen_" + IntToStr( screenshots_c, 7 );
719  screenshots_c+= 1;
720  }
721 
722  if (
723  screenshot_filename=="image_{DATETIME}_{####}.png"
724  ) {
725 
726  //=="image_{DATETIME}_{####}.png")
727  screenshot_filename= "screen_" + IntToStr( screenshots_c, 7 );
728  screenshots_c+= 1;
729 
730  }
731 
732 
733 
734  moText screenshot_name;
735  moText screenshot_path;
736  if (pathname=="") {
737  screenshot_path = m_pResourceManager->GetDataMan()->GetDataPath() + moSlash + moText("moldeo_screenshots");
738 
739  //screenshot_name = screenshot_path + moSlash + moText(datetime)+ moText("_") + IntToStr(screenshots_c);
740  screenshot_name = screenshot_path + moSlash + screenshot_filename;
741  } else {
742  screenshot_path = pathname;
743  //screenshot_name = screenshot_path + moSlash + moText(datetime)+ moText("_")+ IntToStr(screenshots_c);
744  screenshot_name = screenshot_path + moSlash + screenshot_filename;
745  }
746 
748  //if ( !moDirectory( screenshot_path ).Exists() ) {
749  if (!moFileManager::DirectoryExists(screenshot_path)) {
750  if (!moFileManager::CreateDirectory(screenshot_path) ) {
751  MODebug2->Error("could not create directory: "+ screenshot_path);
752  return false;
753  }
754  }
755 
757  screenshot_result = TexScreen->CreateThumbnail( image_format, m_pResourceManager->GetRenderMan()->ScreenWidth(), m_pResourceManager->GetRenderMan()->ScreenHeight(), screenshot_name );
758 
759  }
760 
761  }
762 
763 
764  return true;
765 
766 }
767 
768 
769 
771 {
772  if (ValidDestTexNum(p_tex_num))
773  {
774 
775  if (IsRenderToFBOEnabled())
776  {
777  m_pFBManager->BindFBO(m_fbo_idx);
778  m_pFBManager->SetReadTexture(m_render_attach_points[0]);
779  }
780  else m_pFBManager->BindScreenFB();
781 
782  moTexture* pScreenText;
783 
784  pScreenText = m_pTextureManager->GetTexture( m_render_tex_moid[p_tex_num] );
785 
786  if (pScreenText) {
787  glBindTexture(GL_TEXTURE_2D, pScreenText->GetGLId() );
788  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, m_render_width, m_render_height, 0);
789  glBindTexture(GL_TEXTURE_2D, 0);
790  }
791 
792  if (IsRenderToFBOEnabled()) m_pFBManager->UnbindFBO();
793  else m_pFBManager->UnbindScreenFB();
794  }
795 }
796 
798 {
799  if (ValidSourceTexNum(p_tex_num)) return m_pTextureManager->GetGLId(m_render_tex_moid[p_tex_num]);
800  else return -1;
801 }
802 
803 
805 {
806  return GLEW_ARB_multitexture;
807 }
808 
810 {
811  return GLEW_EXT_framebuffer_object;
812 }
813 
815 {
816  return GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shading_language_100;
817 
818 }
819 
821  return !(GLEW_ARB_texture_non_power_of_two);
822 }
823 
825 /*
826  GLint params[4];
827 
828  glGetIntegerv( GL_VIEWPORT, &params[0]);
829 
830  m_screen_width = params[2];
831  m_screen_height = params[3];
832 */
833  return m_screen_width;
834 }
835 
837 /*
838  GLint params[4];
839 
840  glGetIntegerv( GL_VIEWPORT, &params[0]);
841 
842  m_screen_width = params[2];
843  m_screen_height = params[3];
844 */
845  return m_screen_height;
846 }
847 
849  return m_interface_width;
850 }
851 
853 
854  return m_interface_height;
855 }
856 
857 
859 
860  float prop = 1.0;
861  int w = ScreenWidth();
862  int h = ScreenHeight();
863 
864  if ( w == 0 || h == 0 ) {
865  w = 1; h = 1; prop = 1.0;
866  }
867  else {
868  prop = (float) h / (float) w;
869  }
870 
871  return prop;
872 
873 }
874 
875 
877  return m_render_width;
878 }
879 
881  return m_render_height;
882 }
883 
885 
886  float prop = 1.0;
887  int w = RenderWidth();
888  int h = RenderHeight();
889 
890  if ( w == 0 || h == 0 ) {
891  w = 1; h = 1; prop = 1.0;
892  }
893  else {
894  prop = (float) h / (float) w;
895  }
896 
897  return prop;
898 
899 }
900 
901 void moRenderManager::SetView( int p_width, int p_height ) {
902 
903  glViewport(0, 0, p_width, p_height);
904  m_screen_width = p_width;
905  m_screen_height = p_height;
906  m_pGLManager->SetPerspectiveView(m_screen_width, m_screen_height);
907 
908 
909 
910 }
911 
912 
913 void moRenderManager::SetInterfaceView( int p_width, int p_height ) {
914  m_interface_width = p_width;
915  m_interface_height = p_height;
916 
917 }
moVector3f m_vLight
Definition: moGUIManager.h:250
sólo líneas
Definition: moTypes.h:475
virtual MOboolean Finish()
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
float m_fTextWSegments
Definition: moGUIManager.h:248
int CreateLayer(moEffect *p_scene_effect)
MOboolean FramebufferObjectSupported() const
moRenderManagerMode
virtual ~moDisplay()
#define MOboolean
Definition: moTypes.h:385
Matrices para transformaciones en Open GL.
Definition: moGLManager.h:71
MOboolean IsTextureNonPowerOf2Disabled() const
int Render(moObject3D *p_pObj, moCamera3D *p_pCamera)
virtual float * GetVerticesBuffer()
MOint RenderTexGLId(MOint p_tex_num)
MOboolean ShadersSupported() const
int previewshotmax
MOboolean RenderResEqualScreenRes()
moVector3iArray moFaceArray
Definition: moGUIManager.h:78
#define MO_RENDER_RESOLUTION
MOfloat GetMaxCoordS() const
Definition: moTexture.h:296
virtual const moFaceArray & GetFaces() const
Definition: moGUIManager.h:168
MOuint GetHeight() const
Definition: moTexture.h:261
static bool CreateDirectory(moDirectory Dir)
void DrawTexture(MOint p_resolution, MOint p_tex_num)
MOint ScreenHeight() const
MOboolean IsRenderToFBOEnabled()
#define MO_SCREEN_RESOLUTION
virtual MOboolean Init()
moResolution m_DisplayResolution
moPolygonModes m_PolygonMode
Definition: moGUIManager.h:276
moText CreateThumbnail(moText p_bufferformat, int w, int h, moText newfilename=moText(""))
Definition: moTexture.cpp:856
clase de para manejar textos
Definition: moText.h:75
void SetFBOAttachPoint(MOuint p_fbo_attach_point)
Definition: moTexture.h:203
void SetInterfaceView(int p_width, int p_height)
MOint ScreenWidth() const
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
moMaterial m_Material
Definition: moGUIManager.h:317
float RenderProportion() const
moText0 moText
Definition: moText.h:291
float ScreenProportion() const
void SetOutputConfiguration(moRenderOutputConfiguration p_output_configuration)
moGeometry m_Geometry
Definition: moGUIManager.h:316
#define MO_SCREEN_TEX
Definition: moTypes.h:421
#define MOint
Definition: moTypes.h:388
MOint InterfaceWidth() const
moTexture * m_Map
Definition: moGUIManager.h:274
moColor m_Color
Definition: moGUIManager.h:273
clase base para el manejo de una textura
Definition: moTexture.h:78
Administrador de moBucket &#39;s.
Definition: moBuckets.h:152
void CopyRenderToTexture(MOint p_tex_num)
const moGLMatrixf & GetModelMatrix() const
MOint InterfaceHeight() const
float m_fWireframeWidth
Definition: moGUIManager.h:247
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
void SetView(int p_width, int p_height)
MOuint GetWidth() const
Definition: moTexture.h:256
void RenderLayer(int layer_id)
MOfloat GetMaxCoordT() const
Definition: moTexture.h:301
MOint RenderWidth() const
bool PreviewShot(bool shot_start=false)
MOuint GetGLId() const
Definition: moTexture.h:224
int screenshots_c
virtual ~moRenderManager()
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
clase base para objetos dibujables
Definition: moEffect.h:82
moDefineDynamicArray(moRenderClips) moDefineDynamicArray(moDisplays) moDisplay
MOboolean MultiTextureSupported() const
MOint RenderHeight() const
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
moRenderOutputConfiguration & GetOutputConfiguration()
static bool DirectoryExists(moText dirname)
virtual float * GetNormalsBuffer()
MOint m_MapGLId
Definition: moGUIManager.h:275
bool Screenshot(moText pathname, moText &screenshot_result, const moText &image_format="PNG", const moText &file_pattern="image_{DATETIME}_{####}.png")
void SetRenderToTexMode(moRenderManagerMode p_render_to_texture_mode)