50 if ( !(h==0) != !(w==0) ) {
81 SetName(
"rendermanager");
82 SetLabelName(
"rendermanager");
84 m_pResourceManager = NULL;
87 m_pTextureManager = NULL;
88 m_pDecoderManager = NULL;
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;
99 m_OutputConfiguration.m_RenderResolution.width = 0;
100 m_OutputConfiguration.m_RenderResolution.height = 0;
102 m_OutputConfiguration.m_OutputResolution.width = 0;
103 m_OutputConfiguration.m_OutputResolution.height = 0;
107 m_RenderLock.Unlock();
111 delete m_pFramesPool;
112 m_RenderLock.Unlock();
116 return m_RenderLock.Lock();
121 return m_RenderLock.Unlock();
126 m_OutputConfiguration = p_output_configuration;
132 return m_OutputConfiguration;
137 p_scene_effect = NULL;
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();
156 if (!(m_pGLManager && m_pFBManager && m_pTextureManager && m_pSHManager))
return false;
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;
166 +
" for Screen: " +
IntToStr(m_screen_width)+
"x"+
IntToStr(m_screen_height) );
170 m_pDecoderManager = m_pResourceManager->GetDecoderMan();
171 if (m_pDecoderManager!=NULL) {
172 MODebug2->
Message(
"moRenderManager::Init > Decoder Manager Acquired.");
187 GLenum err = glewInit();
192 cout << glewGetErrorString(err) << endl;
196 MODebug2->
Message(
"moRenderManager::Init > glew initialized succesfully!");
198 GLint max_tex_size = 0.0f;
199 GLint max_tex_rect_size = 0.0f;
200 GLint max_tex_buf_size = 0.0f;
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) );
220 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
222 glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, &max_tex_rect_size);
224 glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &max_tex_buf_size);
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);
236 m_pTextureManager->GetTexture( m_render_tex_moid[0])->BuildEmpty(m_render_width, m_render_height);
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);
244 m_pTextureManager->GetTexture( m_render_tex_moid[1])->BuildEmpty(m_render_width, m_render_height);
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);
252 m_pTextureManager->GetTexture( m_render_tex_moid[2])->BuildEmpty(m_render_width, m_render_height);
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);
260 m_pTextureManager->GetTexture( m_render_tex_moid[3])->BuildEmpty(m_render_width, m_render_height);
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);
269 m_pTextureManager->GetTexture( m_render_tex_moid[4])->BuildEmpty(m_render_width, m_render_height);
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);
275 m_pTextureManager->GetTexture( m_render_tex_moid[5])->BuildEmpty(m_render_width, m_render_height);
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;
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;
285 m_pGLManager->SetMoldeoGLState();
286 m_pGLManager->SetPerspectiveView(m_screen_width, m_screen_height);
290 if ( GLEW_EXT_framebuffer_object )
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();
297 for (
int i = 0; i < 4; i++)
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);
303 moTexture* pRenderTex = m_pTextureManager->GetTexture(m_render_tex_moid[i]);
305 pRenderTex->
SetFBO(m_pFBManager->GetFBO(m_fbo_idx));
307 m_render_attach_points[i] = attach_point;
310 m_pFBManager->GetFBO(m_fbo_idx)->AddDepthStencilBuffer();
318 if (IsRenderToFBOEnabled()) m_pFBManager->DeleteFBO(m_fbo_idx);
322 m_pTextureManager = NULL;
334 return (m_screen_width == m_render_width) && (m_screen_height == m_render_height);
339 m_render_to_texture_mode = p_render_to_texture_mode;
350 m_pGLManager->SaveGLState();
356 m_pGLManager->RestoreGLState();
367 m_pGLManager->SaveGLState();
372 m_pGLManager->RestoreGLState();
378 if (IsRenderToFBOEnabled())
379 if (m_pFBManager) m_pFBManager->BindFBO(m_fbo_idx, m_render_attach_points[0]);
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;
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;
435 Result = MMatrix*PMatrix;
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();
452 if ( m_pSHManager->GetRenderShader().Initialized() ) {
453 m_pSHManager->GetRenderShader().StartShader();
465 int facesCount = Faces.Count();
478 const float *pfv = Result.GetPointer();
484 glEnable( GL_TEXTURE_2D );
485 glActiveTexture( GL_TEXTURE0 );
486 glBindTexture( GL_TEXTURE_2D, Mat.
m_MapGLId );
489 glUniformMatrix4fv( matrix_index, 1, GL_FALSE, pfv );
490 glUniform1i( texture_index, 0 );
494 glUniform3fv( light_index, 1, &Mat.
m_vLight[0] );
495 glUniform3fv( color_index, 1, &Mat.
m_Color[0] );
498 glEnableVertexAttribArray( position_index );
499 glVertexAttribPointer( position_index, 3, GL_FLOAT,
false, 0, &Gpx[0] );
501 glEnableVertexAttribArray( colors_index );
502 glVertexAttribPointer( colors_index, 3, GL_FLOAT,
false, 0, &Gcx[0] );
504 glEnableVertexAttribArray( texcoord_index );
505 glVertexAttribPointer( texcoord_index, 2, GL_FLOAT,
false, 0, &Gtx[0] );
507 glEnableVertexAttribArray( texcoordedge_index );
508 glVertexAttribPointer( texcoordedge_index, 2, GL_FLOAT,
false, 0, &Gtx[0] );
511 glEnableVertexAttribArray( normal_index );
512 glVertexAttribPointer( normal_index, 3, GL_FLOAT,
false, 0, &Gnx[0] );
517 for(
int i = 0; i < facesCount*3; i += 3)
518 glDrawArrays(GL_LINE_LOOP, i, 3);
522 glDrawArrays(GL_POINTS, 0, facesCount*3 );
527 glDrawArrays( GL_TRIANGLES, 0, facesCount*3 );
532 glDisableVertexAttribArray( position_index );
533 glDisableVertexAttribArray( colors_index );
534 glDisableVertexAttribArray( texcoord_index );
535 glDisableVertexAttribArray( texcoordedge_index );
536 glDisableVertexAttribArray( normal_index );
538 if (m_pSHManager->GetRenderShader().Initialized()) {
539 m_pSHManager->GetRenderShader().StopShader();
549 if (m_pGLManager) m_pGLManager->RestoreGLState();
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);
599 if (ValidSourceTexNum(p_tex_num) && m_pGLManager )
603 m_pGLManager->SaveGLState();
605 m_pGLManager->SetOrthographicView(p_width, p_height, 0.0, p_width, 0.0, p_height );
607 moTexture* ptex = m_pTextureManager->GetTexture( m_render_tex_moid[p_tex_num] );
609 glBindTexture(GL_TEXTURE_2D, ptex->
GetGLId());
612 glTexCoord2f(0, 0.0);
616 glVertex2f(p_width, 0);
619 glVertex2f(p_width, p_height);
622 glVertex2f(0, p_height);
627 glBindTexture(GL_TEXTURE_2D, 0);
629 m_pGLManager->RestoreGLState();
639 CopyRenderToTexture(1);
640 m_saved_screen =
true;
651 if( shot_start && !m_PreviewShotTimer.Started()) {
652 m_PreviewShotTimer.Stop();
653 m_PreviewShotTimer.Start();
654 m_PreviewShotIteration = 0;
657 if( m_PreviewShotTimer.Started()) {
658 if (m_PreviewShotTimer.Duration()>=1000) {
660 moText sshot = m_pResourceManager->GetDataMan()->GetDataPath()+moSlash+
moText(
"previewshots");
661 moText preview_shot_filename =
moText(
"preview_shot_")+
IntToStr(m_PreviewShotIteration,7);
663 m_pResourceManager->GetRenderMan()->Screenshot( sshot, result,
"JPG", preview_shot_filename );
665 m_PreviewShotIteration+=1;
666 m_PreviewShotTimer.Stop();
667 m_PreviewShotTimer.Start();
669 m_PreviewShotTimer.Stop();
681 moTexture* TexScreen = m_pTextureManager->GetTexture( m_render_tex_moid[MO_SCREEN_TEX] );
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);
694 char strbuffer[0x100];
695 struct tm * timeinfo;
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 );
709 moText screenshot_filename;
713 screenshot_filename = file_pattern;
717 if (screenshot_filename==
"") {
723 screenshot_filename==
"image_{DATETIME}_{####}.png" 737 screenshot_path = m_pResourceManager->GetDataMan()->GetDataPath() + moSlash +
moText(
"moldeo_screenshots");
740 screenshot_name = screenshot_path + moSlash + screenshot_filename;
742 screenshot_path = pathname;
744 screenshot_name = screenshot_path + moSlash + screenshot_filename;
751 MODebug2->
Error(
"could not create directory: "+ screenshot_path);
757 screenshot_result = TexScreen->
CreateThumbnail( image_format, m_pResourceManager->GetRenderMan()->ScreenWidth(), m_pResourceManager->GetRenderMan()->ScreenHeight(), screenshot_name );
772 if (ValidDestTexNum(p_tex_num))
775 if (IsRenderToFBOEnabled())
777 m_pFBManager->BindFBO(m_fbo_idx);
778 m_pFBManager->SetReadTexture(m_render_attach_points[0]);
780 else m_pFBManager->BindScreenFB();
784 pScreenText = m_pTextureManager->GetTexture( m_render_tex_moid[p_tex_num] );
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);
792 if (IsRenderToFBOEnabled()) m_pFBManager->UnbindFBO();
793 else m_pFBManager->UnbindScreenFB();
799 if (ValidSourceTexNum(p_tex_num))
return m_pTextureManager->GetGLId(m_render_tex_moid[p_tex_num]);
806 return GLEW_ARB_multitexture;
811 return GLEW_EXT_framebuffer_object;
816 return GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shading_language_100;
821 return !(GLEW_ARB_texture_non_power_of_two);
833 return m_screen_width;
845 return m_screen_height;
849 return m_interface_width;
854 return m_interface_height;
861 int w = ScreenWidth();
862 int h = ScreenHeight();
864 if ( w == 0 || h == 0 ) {
865 w = 1; h = 1; prop = 1.0;
868 prop = (float) h / (
float) w;
877 return m_render_width;
881 return m_render_height;
887 int w = RenderWidth();
888 int h = RenderHeight();
890 if ( w == 0 || h == 0 ) {
891 w = 1; h = 1; prop = 1.0;
894 prop = (float) h / (
float) w;
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);
914 m_interface_width = p_width;
915 m_interface_height = p_height;
virtual MOboolean Finish()
virtual float * GetVerticesUVBuffer()
virtual float * GetColorBuffer()
void Error(moText p_text)
Anuncia y registra un error.
int CreateLayer(moEffect *p_scene_effect)
MOboolean FramebufferObjectSupported() const
Matrices para transformaciones en Open GL.
MOboolean IsTextureNonPowerOf2Disabled() const
int Render(moObject3D *p_pObj, moCamera3D *p_pCamera)
virtual float * GetVerticesBuffer()
MOint RenderTexGLId(MOint p_tex_num)
MOboolean ShadersSupported() const
MOboolean RenderResEqualScreenRes()
moVector3iArray moFaceArray
#define MO_RENDER_RESOLUTION
MOfloat GetMaxCoordS() const
virtual const moFaceArray & GetFaces() const
static bool CreateDirectory(moDirectory Dir)
void DrawTexture(MOint p_resolution, MOint p_tex_num)
MOint ScreenHeight() const
MOboolean IsRenderToFBOEnabled()
#define MO_SCREEN_RESOLUTION
moResolution m_DisplayResolution
moPolygonModes m_PolygonMode
moText CreateThumbnail(moText p_bufferformat, int w, int h, moText newfilename=moText(""))
clase de para manejar textos
void SetFBOAttachPoint(MOuint p_fbo_attach_point)
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 )
moDisplay & operator=(const moDisplay &p_src)
void SetFBO(moFBO *p_fbo)
float RenderProportion() const
float ScreenProportion() const
void SetOutputConfiguration(moRenderOutputConfiguration p_output_configuration)
MOint InterfaceWidth() const
clase base para el manejo de una textura
Administrador de moBucket 's.
void CopyRenderToTexture(MOint p_tex_num)
const moGLMatrixf & GetModelMatrix() const
MOint InterfaceHeight() const
Base abstracta de base para las geometrías.
static moDebug * MODebug2
Clase de impresión de errores para depuración.
void SetView(int p_width, int p_height)
void RenderLayer(int layer_id)
MOfloat GetMaxCoordT() const
MOint RenderWidth() const
bool PreviewShot(bool shot_start=false)
virtual ~moRenderManager()
LIBMOLDEO_API moText0 IntToStr(int a)
clase base para objetos dibujables
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.
moRenderOutputConfiguration & GetOutputConfiguration()
static bool DirectoryExists(moText dirname)
virtual float * GetNormalsBuffer()
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)