| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /**
- * The file contains functions and vars used for the deferred shading blending stage stage.
- * The blending stage comes after the illumination stage. All the objects that are transculent will be drawn here.
- */
- #include "renderer.h"
- #include "camera.h"
- #include "scene.h"
- #include "mesh.h"
- #include "r_private.h"
- #include "resource.h"
- #include "fbo.h"
- #include "mesh_node.h"
- #include "material.h"
- namespace r {
- namespace bs {
- /*
- =======================================================================================================================================
- VARS =
- =======================================================================================================================================
- */
- static fbo_t b_fbo; ///< blending models FBO
- static fbo_t r_fbo; ///< refracting models FBO
- static texture_t r_fai; ///< RGB for color and A for mask (0 doesnt pass, 1 pass)
- static shader_prog_t* r2b_shdr;
- /*
- =======================================================================================================================================
- InitBFBO =
- =======================================================================================================================================
- */
- static void InitB()
- {
- // create FBO
- b_fbo.Create();
- b_fbo.Bind();
- // inform FBO about the color buffers
- b_fbo.SetNumOfColorAttachements(1);
- // attach the texes
- glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r::is::fai.GetGLID(), 0 );
- glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, r::ms::depth_fai.GetGLID(), 0 );
- // test if success
- if( !b_fbo.IsGood() )
- FATAL( "Cannot create deferred shading blending stage FBO" );
- // unbind
- b_fbo.Unbind();
- }
- /*
- =======================================================================================================================================
- InitRFBO =
- =======================================================================================================================================
- */
- static void InitR()
- {
- // create FBO
- r_fbo.Create();
- r_fbo.Bind();
- // inform FBO about the color buffers
- r_fbo.SetNumOfColorAttachements(1);
- // texture
- r_fai.CreateEmpty2D( r::w * r::rendering_quality, r::h * r::rendering_quality, GL_RGBA, GL_RGBA );
- // attach the texes
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r_fai.GetGLID(), 0 );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r::ms::depth_fai.GetGLID(), 0 );
- // test if success
- if( !r_fbo.IsGood() )
- FATAL( "Cannot create deferred shading blending stage FBO" );
- // unbind
- r_fbo.Unbind();
- //r2b_shdr =
- }
- //=====================================================================================================================================
- // Init =
- //=====================================================================================================================================
- void Init()
- {
- InitB();
- InitR();
- }
- //=====================================================================================================================================
- // RunStage =
- //=====================================================================================================================================
- void RunStage( const camera_t& cam )
- {
- // OGL stuff
- r::SetProjectionViewMatrices( cam );
- r::SetViewport( 0, 0, r::w*r::rendering_quality, r::h*r::rendering_quality );
- glEnable( GL_DEPTH_TEST );
- glDepthMask( false );
- // render the meshes
- for( uint i=0; i<scene::mesh_nodes.size(); i++ )
- {
- mesh_node_t* mesh_node = scene::mesh_nodes[i];
- if( mesh_node->material->blends )
- {
- b_fbo.Bind();
- mesh_node->material->Setup();
- mesh_node->Render();
- }
- else if( mesh_node->material->refracts )
- {
- // write to the rFbo
- r_fbo.Bind();
- glClear( GL_COLOR_BUFFER_BIT );
- mesh_node->material->Setup();
- mesh_node->Render();
- b_fbo.Bind();
- }
- }
- // render the smodels
- /*for( uint i=0; i<scene::models.size(); i++ )
- Render<model_t, true>( scene::models[i] );*/
- // restore a few things
- glDepthMask( true );
- fbo_t::Unbind();
- }
- }} // end namespaces
|