瀏覽代碼

First phase of new renderer integration. It wont run

Panagiotis Christopoulos Charitos 15 年之前
父節點
當前提交
91ebc77468
共有 44 個文件被更改,包括 1260 次插入3420 次删除
  1. 3 0
      README
  2. 509 374
      build/debug/Makefile
  3. 1 1
      build/debug/gen.cfg.py
  4. 24 11
      src/Main.cpp
  5. 8 7
      src/Misc/collision.cpp
  6. 3 1
      src/Misc/skybox.cpp
  7. 0 85
      src/Renderer/Bs.cpp
  8. 0 117
      src/Renderer/Bs2.cpp
  9. 0 132
      src/Renderer/BulletDebuger.cpp
  10. 0 37
      src/Renderer/BulletDebuger.h
  11. 66 281
      src/Renderer/Dbg.cpp
  12. 1 1
      src/Renderer/Hdr.cpp
  13. 4 65
      src/Renderer/Is.cpp
  14. 0 127
      src/Renderer/IsShadows.cpp
  15. 10 5
      src/Renderer/MainRenderer.cpp
  16. 1 1
      src/Renderer/MainRenderer.h
  17. 15 42
      src/Renderer/Ms.cpp
  18. 0 96
      src/Renderer/MsEarlyz.cpp
  19. 42 91
      src/Renderer/Pps.cpp
  20. 0 139
      src/Renderer/PpsHdr.cpp
  21. 0 107
      src/Renderer/PpsLscatt.cpp
  22. 0 194
      src/Renderer/PpsSsao.cpp
  23. 97 405
      src/Renderer/Renderer.cpp
  24. 404 174
      src/Renderer/Renderer.h
  25. 12 2
      src/Renderer/RendererInitializer.h
  26. 1 1
      src/Renderer/Sm.cpp
  27. 1 1
      src/Renderer/Ssao.cpp
  28. 0 88
      src/Renderer2/Dbg.cpp
  29. 0 11
      src/Renderer2/Is.cpp
  30. 0 100
      src/Renderer2/Ms.cpp
  31. 0 95
      src/Renderer2/Pps.cpp
  32. 0 179
      src/Renderer2/Renderer.cpp
  33. 0 412
      src/Renderer2/Renderer.hpp
  34. 6 5
      src/Resources/Material.cpp
  35. 10 4
      src/Resources/Material.h
  36. 1 1
      src/Resources/ShaderProg.cpp
  37. 14 8
      src/Resources/Texture.cpp
  38. 3 2
      src/Scene/Camera.cpp
  39. 3 2
      src/Scene/Controllers/SkelAnimCtrl.cpp
  40. 6 4
      src/Scene/Light.cpp
  41. 3 2
      src/Scene/MeshNode.cpp
  42. 5 5
      src/Scene/ParticleEmitter.cpp
  43. 3 2
      src/Scene/SkelNode.cpp
  44. 4 3
      src/Ui/Ui.cpp

+ 3 - 0
README

@@ -0,0 +1,3 @@
+For build info see build/README
+
+Currently there are no assets (models, textures, materials etc) so even if you compile it the application will crash if you try to run it

File diff suppressed because it is too large
+ 509 - 374
build/debug/Makefile


+ 1 - 1
build/debug/gen.cfg.py

@@ -1,4 +1,4 @@
-sourcePaths = [ "../../src/Math/", "../../src/Util/Tokenizer/", "../../src/Misc/", "../../src/", "../../src/Renderer/", "../../src/Scene/", "../../src/Ui/", "../../src/Resources/", "../../src/Util/", "../../src/Scene/Controllers/", "../../src/Physics/", "../../src/Renderer/BufferObjects/", "../../src/Renderer2/", "../../src/Resources/Helpers/" ]
+sourcePaths = [ "../../src/Math/", "../../src/Util/Tokenizer/", "../../src/Misc/", "../../src/", "../../src/Renderer/", "../../src/Scene/", "../../src/Ui/", "../../src/Resources/", "../../src/Util/", "../../src/Scene/Controllers/", "../../src/Physics/", "../../src/Renderer/BufferObjects/", "../../src/Resources/Helpers/" ]
 
 
 includePaths = list(sourcePaths)
 includePaths = list(sourcePaths)
 #includePaths.extend( [ "../../../bullet_svn/src/", "/usr/include/SDL" ] )
 #includePaths.extend( [ "../../../bullet_svn/src/", "/usr/include/SDL" ] )

+ 24 - 11
src/Main.cpp

@@ -29,12 +29,13 @@
 #include "SkelAnimCtrl.h"
 #include "SkelAnimCtrl.h"
 #include "SkelNode.h"
 #include "SkelNode.h"
 #include "LightProps.h"
 #include "LightProps.h"
-#include "BulletDebuger.h"
 #include "PhyCommon.h"
 #include "PhyCommon.h"
 #include "Parser.h"
 #include "Parser.h"
 #include "ParticleEmitter.h"
 #include "ParticleEmitter.h"
 #include "PhyCharacter.h"
 #include "PhyCharacter.h"
-#include "Renderer.hpp"
+#include "Renderer.h"
+#include "RendererInitializer.h"
+#include "MainRenderer.h"
 
 
 App* app = NULL;
 App* app = NULL;
 
 
@@ -47,7 +48,6 @@ ParticleEmitter* partEmitter;
 
 
 
 
 // Physics
 // Physics
-BulletDebuger debugDrawer;
 Vec<btRigidBody*> boxes;
 Vec<btRigidBody*> boxes;
 
 
 #define ARRAY_SIZE_X 5
 #define ARRAY_SIZE_X 5
@@ -202,11 +202,25 @@ void init()
 	app->initWindow();
 	app->initWindow();
 	uint ticks = app->getTicks();
 	uint ticks = app->getTicks();
 
 
-	R::init();
+	RendererInitializer initializer;
+	initializer.width = 1280;
+	initializer.height = 800;
+	initializer.dbg.enabled = true;
+	initializer.is.sm.bilinearEnabled = true;
+	initializer.is.sm.enabled = true;
+	initializer.is.sm.pcfEnabled = true;
+	initializer.is.sm.resolution = 512;
+	initializer.pps.hdr.enabled = true;
+	initializer.pps.hdr.renderingQuality = 0.5;
+	initializer.pps.ssao.bluringQuality = 1.0;
+	initializer.pps.ssao.enabled = true;
+	initializer.pps.ssao.renderingQuality = 0.5;
+	initializer.mainRendererQuality = 1.0;
+	app->getMainRenderer()->init( initializer );
 	Ui::init();
 	Ui::init();
 
 
 	// camera
 	// camera
-	Camera* cam = new Camera( R::aspectRatio*toRad(60.0), toRad(60.0), 0.5, 200.0 );
+	Camera* cam = new Camera( app->getMainRenderer()->getAspectRatio()*toRad(60.0), toRad(60.0), 0.5, 200.0 );
 	cam->moveLocalY( 3.0 );
 	cam->moveLocalY( 3.0 );
 	cam->moveLocalZ( 5.7 );
 	cam->moveLocalZ( 5.7 );
 	cam->moveLocalX( -0.3 );
 	cam->moveLocalX( -0.3 );
@@ -293,7 +307,6 @@ int main( int argc, char* argv[] )
 	{
 	{
 		int ticks_ = App::getTicks();
 		int ticks_ = App::getTicks();
 		I::handleEvents();
 		I::handleEvents();
-		R::prepareNextFrame();
 
 
 		float dist = 0.2;
 		float dist = 0.2;
 		float ang = toRad(3.0);
 		float ang = toRad(3.0);
@@ -359,7 +372,7 @@ int main( int argc, char* argv[] )
 		app->getScene()->getPhyWorld()->getDynamicsWorld()->stepSimulation( app->timerTick );
 		app->getScene()->getPhyWorld()->getDynamicsWorld()->stepSimulation( app->timerTick );
 		app->getScene()->getPhyWorld()->getDynamicsWorld()->debugDrawWorld();
 		app->getScene()->getPhyWorld()->getDynamicsWorld()->debugDrawWorld();
 
 
-		R::render( *app->getActiveCam() );
+		app->getMainRenderer()->render( *app->getActiveCam() );
 
 
 		//map.octree.root->bounding_box.render();
 		//map.octree.root->bounding_box.render();
 
 
@@ -367,14 +380,14 @@ int main( int argc, char* argv[] )
 		Ui::setColor( Vec4(1.0, 1.0, 1.0, 1.0) );
 		Ui::setColor( Vec4(1.0, 1.0, 1.0, 1.0) );
 		Ui::setPos( -0.98, 0.95 );
 		Ui::setPos( -0.98, 0.95 );
 		Ui::setFontWidth( 0.03 );
 		Ui::setFontWidth( 0.03 );
-		Ui::printf( "frame:%d fps:%dms\n", R::framesNum, (App::getTicks()-ticks_) );
+		Ui::printf( "frame:%d fps:%dms\n", app->getMainRenderer()->getFramesNum(), (App::getTicks()-ticks_) );
 		//Ui::print( "Movement keys: arrows,w,a,s,d,q,e,shift,space\nSelect objects: keys 1 to 5\n" );
 		//Ui::print( "Movement keys: arrows,w,a,s,d,q,e,shift,space\nSelect objects: keys 1 to 5\n" );
 		/*Ui::printf( "Mover: Pos(%.2f %.2f %.2f) Angs(%.2f %.2f %.2f)", mover->translationWspace.x, mover->translationWspace.y, mover->translationWspace.z,
 		/*Ui::printf( "Mover: Pos(%.2f %.2f %.2f) Angs(%.2f %.2f %.2f)", mover->translationWspace.x, mover->translationWspace.y, mover->translationWspace.z,
 								 toDegrees(Euler(mover->rotationWspace).x), toDegrees(Euler(mover->rotationWspace).y), toDegrees(Euler(mover->rotationWspace).z) );*/
 								 toDegrees(Euler(mover->rotationWspace).x), toDegrees(Euler(mover->rotationWspace).y), toDegrees(Euler(mover->rotationWspace).z) );*/
 
 
 		if( I::keys[SDL_SCANCODE_ESCAPE] ) break;
 		if( I::keys[SDL_SCANCODE_ESCAPE] ) break;
 		if( I::keys[SDL_SCANCODE_F11] ) app->togleFullScreen();
 		if( I::keys[SDL_SCANCODE_F11] ) app->togleFullScreen();
-		if( I::keys[SDL_SCANCODE_F12] == 1 ) R::takeScreenshot("gfx/screenshot.jpg");
+		if( I::keys[SDL_SCANCODE_F12] == 1 )  app->getMainRenderer()->takeScreenshot( "gfx/screenshot.jpg" );
 
 
 
 
 		/*char str[128];
 		/*char str[128];
@@ -383,14 +396,14 @@ int main( int argc, char* argv[] )
 
 
 		// std stuff follow
 		// std stuff follow
 		app->swapBuffers();
 		app->swapBuffers();
-		R::printLastError();
+		Renderer::printLastError();
 		if( 1 )
 		if( 1 )
 		{
 		{
 			//if( R::framesNum == 10 ) R::takeScreenshot("gfx/screenshot.tga");
 			//if( R::framesNum == 10 ) R::takeScreenshot("gfx/screenshot.tga");
 			app->waitForNextFrame();
 			app->waitForNextFrame();
 		}
 		}
 		else
 		else
-			if( R::framesNum == 5000 ) break;
+			if( app->getMainRenderer()->getFramesNum() == 5000 ) break;
 	}while( true );
 	}while( true );
 	INFO( "Exiting main loop (" << App::getTicks()-ticks << ")" );
 	INFO( "Exiting main loop (" << App::getTicks()-ticks << ")" );
 
 

+ 8 - 7
src/Misc/collision.cpp

@@ -1,6 +1,7 @@
 #include <float.h>
 #include <float.h>
 #include "collision.h"
 #include "collision.h"
-#include "Renderer.h"
+#include "MainRenderer.h"
+#include "App.h"
 
 
 
 
 static int render_seperation_lock = 0;
 static int render_seperation_lock = 0;
@@ -819,7 +820,7 @@ void plane_t::Render()
 	q.setFrom2Vec3( Vec3( 0.0, 0.0, 1.0 ), normal );
 	q.setFrom2Vec3( Vec3( 0.0, 0.0, 1.0 ), normal );
 	Mat3 rotate( q );
 	Mat3 rotate( q );
 	Mat4 transform( translate, rotate );
 	Mat4 transform( translate, rotate );
-	R::multMatrix( transform );
+	app->getMainRenderer()->multMatrix( transform );
 
 
 	glColor4fv( &Vec4(1.0f, 1.0f, 1.0f, 0.5f)[0] );
 	glColor4fv( &Vec4(1.0f, 1.0f, 1.0f, 0.5f)[0] );
 
 
@@ -911,7 +912,7 @@ void bsphere_t::Render()
 
 
 	glColor4fv( &Vec4(1.0, 1.0, 1.0, 0.2)[0] );
 	glColor4fv( &Vec4(1.0, 1.0, 1.0, 0.2)[0] );
 
 
-	R::Dbg::renderSphere( radius, 24 );
+	app->getMainRenderer()->dbg.renderSphere( radius, 24 );
 
 
 	glPopMatrix();
 	glPopMatrix();
 }
 }
@@ -1195,7 +1196,7 @@ void aabb_t::Render()
 
 
 	glColor3fv( &Vec3( 1.0, 1.0, 1.0 )[0] );
 	glColor3fv( &Vec3( 1.0, 1.0, 1.0 )[0] );
 
 
-	R::Dbg::renderCube();
+	app->getMainRenderer()->dbg.renderCube();
 
 
 	glPopMatrix();
 	glPopMatrix();
 
 
@@ -1639,14 +1640,14 @@ void obb_t::Render()
 	glPushMatrix();
 	glPushMatrix();
 
 
 	glTranslatef( center.x, center.y, center.z ); // translate
 	glTranslatef( center.x, center.y, center.z ); // translate
-	R::multMatrix( Mat4(rotation) ); // rotate
+	app->getMainRenderer()->multMatrix( Mat4(rotation) ); // rotate
 	glScalef( extends.x, extends.y, extends.z ); // scale
 	glScalef( extends.x, extends.y, extends.z ); // scale
 
 
 	glColor3fv( &Vec3(1.0f, 1.0f, 1.0f)[0] );
 	glColor3fv( &Vec3(1.0f, 1.0f, 1.0f)[0] );
 
 
-	R::Dbg::renderCube( false, 2.0f );
+	app->getMainRenderer()->dbg.renderCube( false, 2.0 );
 
 
-	R::color3( Vec3( 0.0, 1.0, 0.0 ) );
+	app->getMainRenderer()->color3( Vec3( 0.0, 1.0, 0.0 ) );
 	glBegin( GL_POINTS );
 	glBegin( GL_POINTS );
 		glVertex3fv( &Vec3(1.0, 1.0, 1.0)[0] );
 		glVertex3fv( &Vec3(1.0, 1.0, 1.0)[0] );
 	glEnd();
 	glEnd();

+ 3 - 1
src/Misc/skybox.cpp

@@ -5,6 +5,7 @@
 #include "Camera.h"
 #include "Camera.h"
 #include "Scene.h"
 #include "Scene.h"
 #include "App.h"
 #include "App.h"
+#include "MainRenderer.h"
 
 
 
 
 static float coords [][4][3] =
 static float coords [][4][3] =
@@ -68,7 +69,8 @@ void Skybox::Render( const Mat3& rotation )
 	// set the rotation matrix
 	// set the rotation matrix
 	Mat3 tmp( rotation );
 	Mat3 tmp( rotation );
 	tmp.rotateYAxis(rotation_ang);
 	tmp.rotateYAxis(rotation_ang);
-	R::loadMatrix( Mat4( tmp ) );
+	app->getMainRenderer()->loadMatrix( Mat4( tmp ) );
+
 	rotation_ang += 0.0001;
 	rotation_ang += 0.0001;
 	if( rotation_ang >= 2*PI ) rotation_ang = 0.0;
 	if( rotation_ang >= 2*PI ) rotation_ang = 0.0;
 
 

+ 0 - 85
src/Renderer/Bs.cpp

@@ -1,85 +0,0 @@
-/**
- * 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 "Resource.h"
-#include "Fbo.h"
-#include "MeshNode.h"
-#include "Material.h"
-#include "App.h"
-
-
-namespace R {
-namespace Bs {
-
-//=====================================================================================================================================
-// VARS                                                                                                                               =
-//=====================================================================================================================================
-static Fbo fbo; ///< blending models FBO
-
-
-//=====================================================================================================================================
-// init                                                                                                                               =
-//=====================================================================================================================================
-void init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform FBO about the color buffers
-	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::depthFai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create deferred shading blending stage FBO" );
-
-	// unbind
-	fbo.unbind();
-}
-
-
-//=====================================================================================================================================
-// runStage                                                                                                                           =
-//=====================================================================================================================================
-void runStage( const Camera& cam )
-{
-	// OGL stuff
-	R::setProjectionViewMatrices( cam );
-	R::setViewport( 0, 0, R::w, R::h );
-
-	glEnable( GL_DEPTH_TEST );
-	glDepthMask( false );
-
-
-
-	// render the meshes
-	for( uint i=0; i<app->getScene()->meshNodes.size(); i++ )
-	{
-		MeshNode* meshNode = app->getScene()->meshNodes[i];
-		if( meshNode->material->blends && !meshNode->material->blends )
-		{
-			fbo.bind();
-			meshNode->material->setup();
-			meshNode->render();
-		}
-
-	}
-
-
-	// restore a few things
-	glDepthMask( true );
-	Fbo::unbind();
-}
-
-
-}} // end namespaces

+ 0 - 117
src/Renderer/Bs2.cpp

@@ -1,117 +0,0 @@
-/**
- * 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 "Resource.h"
-#include "Fbo.h"
-#include "MeshNode.h"
-#include "Material.h"
-#include "App.h"
-
-
-namespace R {
-namespace Bs {
-
-//=====================================================================================================================================
-// VARS                                                                                                                               =
-//=====================================================================================================================================
-static Fbo intermid_fbo, fbo;
-
-static Texture fai; ///< RGB for color and A for mask (0 doesnt pass, 1 pass)
-static ShaderProg* shaderProg;
-
-
-//=====================================================================================================================================
-// init2                                                                                                                              =
-//=====================================================================================================================================
-void init2()
-{
-	//** 1st FBO **
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform FBO about the color buffers
-	fbo.setNumOfColorAttachements(1);
-
-	// attach the texes
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, R::Pps::fai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, R::Ms::depthFai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create deferred shading blending stage FBO" );
-
-	// unbind
-	fbo.unbind();
-
-
-	//** 2nd FBO **
-	intermid_fbo.create();
-	intermid_fbo.bind();
-
-	// texture
-	intermid_fbo.setNumOfColorAttachements(1);
-	fai.createEmpty2D( R::w, R::h, GL_RGBA8, GL_RGBA );
-	glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0 );
-
-	// attach the texes
-	glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_2D, R::Ms::depthFai.getGlId(), 0 );
-
-	// test if success
-	if( !intermid_fbo.isGood() )
-		FATAL( "Cannot create deferred shading blending stage FBO" );
-
-	// unbind
-	intermid_fbo.unbind();
-
-	shaderProg = Rsrc::shaders.load( "shaders/bs_refract.glsl" );
-}
-
-
-//=====================================================================================================================================
-// runStage2                                                                                                                          =
-//=====================================================================================================================================
-void runStage2( const Camera& cam )
-{
-	R::setProjectionViewMatrices( cam );
-	R::setViewport( 0, 0, R::w, R::h );
-
-
-	glDepthMask( false );
-
-
-	// render the meshes
-	for( uint i=0; i<app->getScene()->meshNodes.size(); i++ )
-	{
-		MeshNode* mesh_node = app->getScene()->meshNodes[i];
-		if( mesh_node->material->refracts )
-		{
-			// write to the rFbo
-			intermid_fbo.bind();
-			glEnable( GL_DEPTH_TEST );
-			glClear( GL_COLOR_BUFFER_BIT );
-			mesh_node->material->setup();
-			mesh_node->render();
-
-			fbo.bind();
-			glDisable( GL_DEPTH_TEST );
-			shaderProg->bind();
-			shaderProg->locTexUnit( shaderProg->findUniVar("fai")->getLoc(), fai, 0 );
-			R::DrawQuad( 0 );
-		}
-	}
-
-
-	// restore a few things
-	glDepthMask( true );
-	Fbo::unbind();
-}
-
-
-}} // end namespaces

+ 0 - 132
src/Renderer/BulletDebuger.cpp

@@ -1,132 +0,0 @@
-#include "BulletDebuger.h"
-#include "Renderer.h"
-
-BulletDebuger::BulletDebuger() :
-	m_debugMode( 0 )
-{
-}
-
-void BulletDebuger::drawLine( const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor )
-{
-	glBegin( GL_LINES);
-	glColor3f( fromColor.getX(), fromColor.getY(), fromColor.getZ() );
-	glVertex3d( from.getX(), from.getY(), from.getZ() );
-	glColor3f( toColor.getX(), toColor.getY(), toColor.getZ() );
-	glVertex3d( to.getX(), to.getY(), to.getZ() );
-	glEnd();
-}
-
-void BulletDebuger::drawLine( const btVector3& from, const btVector3& to, const btVector3& color )
-{
-	drawLine( from, to, color, color );
-}
-
-void BulletDebuger::drawSphere( const btVector3& p, btScalar radius, const btVector3& color )
-{
-	glColor4f( color.getX(), color.getY(), color.getZ(), btScalar( 1.0f ) );
-	glPushMatrix();
-	glTranslatef( p.getX(), p.getY(), p.getZ() );
-
-	int lats = 5;
-	int longs = 5;
-
-	int i, j;
-	for( i = 0; i <= lats; i++ )
-	{
-		btScalar lat0 = SIMD_PI * ( -btScalar( 0.5 ) + ( btScalar )( i - 1 ) / lats );
-		btScalar z0 = radius * sin( lat0 );
-		btScalar zr0 = radius * cos( lat0 );
-
-		btScalar lat1 = SIMD_PI * ( -btScalar( 0.5 ) + (btScalar)i / lats );
-		btScalar z1 = radius * sin( lat1 );
-		btScalar zr1 = radius * cos( lat1 );
-
-		glBegin( GL_QUAD_STRIP);
-		for( j = 0; j <= longs; j++ )
-		{
-			btScalar lng = 2 * SIMD_PI * ( btScalar )( j - 1 ) / longs;
-			btScalar x = cos( lng );
-			btScalar y = sin( lng );
-
-			glNormal3f( x * zr0, y * zr0, z0 );
-			glVertex3f( x * zr0, y * zr0, z0 );
-			glNormal3f( x * zr1, y * zr1, z1 );
-			glVertex3f( x * zr1, y * zr1, z1 );
-		}
-		glEnd();
-	}
-
-	glPopMatrix();
-}
-
-void BulletDebuger::drawBox( const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha )
-{
-	btVector3 halfExtent = ( boxMax - boxMin ) * btScalar( 0.5f );
-	btVector3 center = ( boxMax + boxMin ) * btScalar( 0.5f );
-	//glEnable(GL_BLEND);     // Turn blending On
-	//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-	glColor4f( color.getX(), color.getY(), color.getZ(), alpha );
-	glPushMatrix();
-	glTranslatef( center.getX(), center.getY(), center.getZ() );
-	glScaled( 2 * halfExtent[0], 2 * halfExtent[1], 2 * halfExtent[2] );
-	//	glutSolidCube(1.0);
-	glPopMatrix();
-	//glDisable(GL_BLEND);
-}
-
-void BulletDebuger::drawTriangle( const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& color, btScalar alpha )
-{
-	//	if (m_debugMode > 0)
-	{
-		const btVector3 n = btCross( b - a, c - a ).normalized();
-		glBegin( GL_TRIANGLES);
-		glColor4f( color.getX(), color.getY(), color.getZ(), alpha );
-		glNormal3d( n.getX(), n.getY(), n.getZ() );
-		glVertex3d( a.getX(), a.getY(), a.getZ() );
-		glVertex3d( b.getX(), b.getY(), b.getZ() );
-		glVertex3d( c.getX(), c.getY(), c.getZ() );
-		glEnd();
-	}
-}
-
-void BulletDebuger::setDebugMode( int debugMode )
-{
-	m_debugMode = debugMode;
-
-}
-
-void BulletDebuger::draw3dText( const btVector3& location, const char* textString )
-{
-	glRasterPos3f( location.x(), location.y(), location.z() );
-	//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),textString);
-}
-
-void BulletDebuger::reportErrorWarning( const char* warningString )
-{
-	printf( "%s\n", warningString );
-}
-
-void BulletDebuger::drawContactPoint( const btVector3& pointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime,
-                                      const btVector3& color )
-{
-
-	{
-		btVector3 to = pointOnB + normalOnB * distance;
-		const btVector3&from = pointOnB;
-		glColor4f( color.getX(), color.getY(), color.getZ(), 1.f );
-		//glColor4f(0,0,0,1.f);
-
-		glBegin( GL_LINES);
-		glVertex3d( from.getX(), from.getY(), from.getZ() );
-		glVertex3d( to.getX(), to.getY(), to.getZ() );
-		glEnd();
-
-		glRasterPos3f( from.x(), from.y(), from.z() );
-		char buf[12];
-		sprintf( buf, " %d", lifeTime );
-		//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
-
-
-	}
-}
-

+ 0 - 37
src/Renderer/BulletDebuger.h

@@ -1,37 +0,0 @@
-#ifndef _BULLETDEBUGER_H_
-#define _BULLETDEBUGER_H_
-
-#include "Common.h"
-#include <LinearMath/btIDebugDraw.h>
-
-
-
-class BulletDebuger: public btIDebugDraw
-{
-	private:
-		int m_debugMode;
-
-	public:
-		BulletDebuger();
-
-		virtual void	drawLine(const btVector3& from,const btVector3& to,const btVector3& fromColor, const btVector3& toColor);
-		virtual void	drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
-
-		virtual void	drawSphere (const btVector3& p, btScalar radius, const btVector3& color);
-		virtual void	drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha);
-
-		virtual void	drawTriangle(const btVector3& a,const btVector3& b,const btVector3& c,const btVector3& color,btScalar alpha);
-
-		virtual void	drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color);
-
-		virtual void	reportErrorWarning(const char* warningString);
-
-		virtual void	draw3dText(const btVector3& location,const char* textString);
-
-		virtual void	setDebugMode(int debugMode);
-
-		virtual int		getDebugMode() const { return m_debugMode; }
-};
-
-
-#endif

+ 66 - 281
src/Renderer/Dbg.cpp

@@ -1,244 +1,26 @@
 #include "Renderer.h"
 #include "Renderer.h"
-#include "Fbo.h"
+#include "App.h"
 #include "Scene.h"
 #include "Scene.h"
-#include "Texture.h"
-#include "Fbo.h"
-#include "SceneNode.h"
 #include "SkelNode.h"
 #include "SkelNode.h"
-#include "App.h"
-#include "PhyCommon.h"
-
-extern btDefaultCollisionConfiguration* collisionConfiguration;
-extern btCollisionDispatcher* dispatcher;
-extern btDbvtBroadphase* broadphase;
-extern btSequentialImpulseConstraintSolver* sol;
-extern btDiscreteDynamicsWorld* dynamicsWorld;
-
-void renderscene( int pass )
-{
-	return;
-	btScalar m[16];
-	btMatrix3x3 rot;
-	rot.setIdentity();
-	const int numObjects = dynamicsWorld->getNumCollisionObjects();
-	btVector3 wireColor( 1, 0, 0 );
-	for( int i = 0; i < numObjects; i++ )
-	{
-		btCollisionObject* colObj = dynamicsWorld->getCollisionObjectArray()[i];
-		btRigidBody* body = btRigidBody::upcast( colObj );
-		if( body && body->getMotionState() )
-		{
-			MotionState* myMotionState = (MotionState*)body->getMotionState();
-			myMotionState->getWorldTransform().getOpenGLMatrix( m );
-			rot = myMotionState->getWorldTransform().getBasis();
-		}
-		else
-		{
-			colObj->getWorldTransform().getOpenGLMatrix( m );
-			rot = colObj->getWorldTransform().getBasis();
-		}
-
-		glPushMatrix();
-		glMultMatrixf(m);
-
-		R::Dbg::renderCube( true, 2.0 );
-
-		glPopMatrix();
-	}
-}
-
-
-
-
-
-
-namespace R {
-namespace Dbg {
-
-
-static void renderSun();
-
-//=====================================================================================================================================
-// DATA VARS                                                                                                                          =
-//=====================================================================================================================================
-bool showAxis = true;
-bool showFnormals = false;
-bool showVnormals = false;
-bool showLights = true;
-bool showSkeletons = false;
-bool showCameras = true;
-bool showBvolumes = true;
-
-static Fbo fbo;
-
-class DbgShaderProg: public ShaderProg
-{
-	public:
-		struct
-		{
-			int color;
-		}uniLocs;
-};
-
-static DbgShaderProg sProg;
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// init                                                                                                                               =
+// Constructor                                                                                                                        =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
-
-	// attach the textures
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, R::Pps::fai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, R::Ms::depthFai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create debug FBO" );
-
-	// unbind
-	fbo.unbind();
-
-	// shader
-	sProg.customLoad( "shaders/Dbg.glsl" );
-}
-
-
-float projectRadius( float r, const Vec3& location, const Camera& cam )
+Renderer::Dbg::Dbg( Renderer& r_ ):
+	RenderingStage( r_ ),
+	showAxisEnabled( false ),
+	showLightsEnabled( false ),
+	showSkeletonsEnabled( false ),
+	showCamerasEnabled( false )
 {
 {
-	Vec3 axis = cam.getWorldTransform().getRotation().getXAxis();
-	float c = axis.dot( cam.getWorldTransform().getOrigin() );
-	float dist = axis.dot( location ) - c;
-
-	/*if( dist > 0.0 )
-		return 0.0;*/
-
-	Vec3 p( 0.0, fabs(r), -dist );
-	Vec4 projected = cam.getProjectionMatrix() * Vec4( p, 1.0 );
-	float pr = projected.y / projected.w;
-
-	/*if ( pr > 1.0 )
-		pr = 1.0;*/
-
-	return pr;
-}
-
-
-//=====================================================================================================================================
-// runStage                                                                                                                           =
-//=====================================================================================================================================
-void runStage( const Camera& cam )
-{
-	fbo.bind();
-
-	sProg.bind();
-
-	// OGL stuff
-	R::setProjectionViewMatrices( cam );
-	R::setViewport( 0, 0, R::w, R::h );
-
-	glEnable( GL_DEPTH_TEST );
-	glDisable( GL_BLEND );
-
-	//R::renderGrid();
-	for( uint i=0; i<app->getScene()->nodes.size(); i++ )
-	{
-		if
-		(
-			(app->getScene()->nodes[i]->type == SceneNode::NT_LIGHT && showLights) ||
-			(app->getScene()->nodes[i]->type == SceneNode::NT_CAMERA && showCameras) ||
-			app->getScene()->nodes[i]->type == SceneNode::NT_PARTICLE_EMITTER
-		)
-		{
-			app->getScene()->nodes[i]->render();
-		}
-		else if( app->getScene()->nodes[i]->type == SceneNode::NT_SKELETON && showSkeletons )
-		{
-			SkelNode* skel_node = static_cast<SkelNode*>( app->getScene()->nodes[i] );
-			glDisable( GL_DEPTH_TEST );
-			skel_node->render();
-			glEnable( GL_DEPTH_TEST );
-		}
-	}
-
-	// the sun
-	//RenderSun();
-
-	renderscene(1);
-
-
-	glDisable( GL_DEPTH_TEST );
-
-	glPushMatrix();
-	R::multMatrix( Mat4( Vec3(5.0, 2.0, 2.0), Mat3::getIdentity(), 1.0 ) );
-	R::color3( Vec3(1,0,0) );
-	R::Dbg::renderSphere( 1.2, 16 );
-	glPopMatrix();
-
-
-	glMatrixMode( GL_PROJECTION );
-	glPushMatrix();
-	glLoadIdentity();
-	glOrtho( -1, 1, -1, 1, -1, 1 );
-	glMatrixMode( GL_MODELVIEW );
-	glPushMatrix();
-	glLoadIdentity();
-
-
-	Vec3 c = Vec3(5.0, 2.0, 2.0);
-	float r = 1.2;
-
-	Vec4 p = Vec4( c, 1.0 );
-	p = app->getActiveCam()->getProjectionMatrix() * (app->getActiveCam()->getViewMatrix() * p);
-	p /= p.w;
-	//p = p/2 + 0.5;
-
-	glPointSize( 10 );
-	glBegin( GL_POINTS );
-		R::color3( Vec3(0.0,1.0,0.0) );
-		glVertex2fv( &p[0] );
-	glEnd();
-
-
-	/*Vec4 g = Vec4( Vec3(c) + Vec3(r,0,0), 1.0 );
-	g = app->activeCam->getProjectionMatrix() * (app->activeCam->getViewMatrix() * g);
-	g /= g.w;
-	float len = Vec2(p-g).getLength();
-	//g = g/2 + 0.5;
-
-	glPointSize( 10 );
-	glBegin( GL_POINTS );
-		R::color3( Vec3(1.0,1.0,1.0) );
-		glVertex2fv( &(g)[0] );
-	glEnd();*/
-	float pr = projectRadius( r, c, cam );
-	//PRINT( pr );
-	glPointSize( 10 );
-	glBegin( GL_POINTS );
-		R::color3( Vec3(1.0,0.0,1.0) );
-		glVertex2fv( &( Vec2(p) + Vec2(pr,0.0) )[0] );
-	glEnd();
-
-	glPopMatrix();
-	glMatrixMode( GL_PROJECTION );
-	glPopMatrix();
-
-	// unbind
-	fbo.unbind();
 }
 }
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
 // renderGrid                                                                                                                         =
 // renderGrid                                                                                                                         =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void renderGrid()
+void Renderer::Dbg::renderGrid()
 {
 {
 	float col0[] = { 0.5, 0.5, 0.5 };
 	float col0[] = { 0.5, 0.5, 0.5 };
 	float col1[] = { 0.0, 0.0, 1.0 };
 	float col1[] = { 0.0, 0.0, 1.0 };
@@ -278,33 +60,10 @@ void renderGrid()
 }
 }
 
 
 
 
-//=====================================================================================================================================
-// renderQuad                                                                                                                         =
-//=====================================================================================================================================
-void renderQuad( float w, float h )
-{
-	float wdiv2 = w/2, hdiv2 = h/2;
-	float points [][2] = { {wdiv2,hdiv2}, {-wdiv2,hdiv2}, {-wdiv2,-hdiv2}, {wdiv2,-hdiv2} };
-	float uvs [][2] = { {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0} };
-
-	glBegin( GL_QUADS );
-		glNormal3fv( &(-Vec3( 0.0, 0.0, 1.0 ))[0] );
-		glTexCoord2fv( uvs[0] );
-		glVertex2fv( points[0] );
-		glTexCoord2fv( uvs[1] );
-		glVertex2fv( points[1] );
-		glTexCoord2fv( uvs[2] );
-		glVertex2fv( points[2] );
-		glTexCoord2fv( uvs[3] );
-		glVertex2fv( points[3] );
-	glEnd();
-}
-
-
 //=====================================================================================================================================
 //=====================================================================================================================================
 // renderSphere                                                                                                                       =
 // renderSphere                                                                                                                       =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void renderSphere( float radius, int complexity )
+void Renderer::Dbg::renderSphere( float radius, int complexity )
 {
 {
 	const float twopi  = M::PI*2;
 	const float twopi  = M::PI*2;
 	const float pidiv2 = M::PI/2;
 	const float pidiv2 = M::PI/2;
@@ -379,7 +138,7 @@ void renderSphere( float radius, int complexity )
 //=====================================================================================================================================
 //=====================================================================================================================================
 // renderCube                                                                                                                         =
 // renderCube                                                                                                                         =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void renderCube( bool cols, float size )
+void Renderer::Dbg::renderCube( bool cols, float size )
 {
 {
 	Vec3 maxPos( 0.5 * size );
 	Vec3 maxPos( 0.5 * size );
 	Vec3 minPos( -0.5 * size );
 	Vec3 minPos( -0.5 * size );
@@ -448,45 +207,71 @@ void renderCube( bool cols, float size )
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// RenderSun                                                                                                                          =
+// init                                                                                                                               =
 //=====================================================================================================================================
 //=====================================================================================================================================
-static void renderSun()
+void Renderer::Dbg::init()
 {
 {
-	glPushMatrix();
+	// create FBO
+	fbo.create();
+	fbo.bind();
 
 
-	R::multMatrix( Mat4( app->getScene()->getSunPos(), Mat3::getIdentity(), 50.0 ) );
+	// inform in what buffers we draw
+	fbo.setNumOfColorAttachements(1);
 
 
-	R::color3( Vec3(1.0, 1.0, 0.0) );
-	R::Dbg::renderSphere( 1.0/8.0, 8 );
+	// attach the textures
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r.pps.fai.getGlId(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0 );
+
+	// test if success
+	if( !fbo.isGood() )
+		FATAL( "Cannot create debug FBO" );
 
 
-	glPopMatrix();
+	// unbind
+	fbo.unbind();
+
+	// shader
+	sProg.customLoad( "shaders/Dbg.glsl" );
+}
 
 
 
 
-/*	/////////////////////////////////////////////////////
-	glMatrixMode( GL_PROJECTION );
-	glPushMatrix();
-	glLoadIdentity();
-	glOrtho( 0, 1, 0, 1, -1, 1 );
-	glMatrixMode( GL_MODELVIEW );
-	glPushMatrix();
-	glLoadIdentity();
+//=====================================================================================================================================
+// runStage                                                                                                                           =
+//=====================================================================================================================================
+void Renderer::Dbg::run()
+{
+	if( !enabled ) return;
 
 
+	const Camera& cam = *r.cam;
 
 
-	Vec4 p = Vec4( app->getScene()->getSunPos(), 1.0 );
-	p = mainCam->getProjectionMatrix() * (mainCam->getViewMatrix() * p);
-	p /= p.w;
-	p = p/2 + 0.5;
+	fbo.bind();
+	sProg.bind();
 
 
-	glPointSize( 10 );
-	glBegin( GL_POINTS );
-		R::color3( Vec3(0.0,1.0,0.0) );
-		glVertex3fv( &p[0] );
-	glEnd();
+	// OGL stuff
+	r.setProjectionViewMatrices( cam );
+	r.setViewport( 0, 0, r.width, r.height );
 
 
-	glPopMatrix();
-	glMatrixMode( GL_PROJECTION );
-	glPopMatrix();*/
-}
+	glEnable( GL_DEPTH_TEST );
+	glDisable( GL_BLEND );
 
 
+	//R::renderGrid();
+	for( uint i=0; i<app->getScene()->nodes.size(); i++ )
+	{
+		if
+		(
+			(app->getScene()->nodes[i]->type == SceneNode::NT_LIGHT && showLightsEnabled) ||
+			(app->getScene()->nodes[i]->type == SceneNode::NT_CAMERA && showCamerasEnabled) ||
+			app->getScene()->nodes[i]->type == SceneNode::NT_PARTICLE_EMITTER
+		)
+		{
+			app->getScene()->nodes[i]->render();
+		}
+		else if( app->getScene()->nodes[i]->type == SceneNode::NT_SKELETON && showSkeletonsEnabled )
+		{
+			SkelNode* skel_node = static_cast<SkelNode*>( app->getScene()->nodes[i] );
+			glDisable( GL_DEPTH_TEST );
+			skel_node->render();
+			glEnable( GL_DEPTH_TEST );
+		}
+	}
+}
 
 
-} } // end namespaces

+ 1 - 1
src/Renderer2/Hdr.cpp → src/Renderer/Hdr.cpp

@@ -1,4 +1,4 @@
-#include "Renderer.hpp"
+#include "Renderer.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================

File diff suppressed because it is too large
+ 4 - 65
src/Renderer/Is.cpp


+ 0 - 127
src/Renderer/IsShadows.cpp

@@ -1,127 +0,0 @@
-#include "Renderer.h"
-#include "Texture.h"
-#include "Scene.h"
-#include "Resource.h"
-#include "Fbo.h"
-#include "Material.h"
-#include "MeshNode.h"
-#include "App.h"
-
-namespace R {
-namespace Is {
-namespace Shad {
-
-/*
-=======================================================================================================================================
-DATA VARS                                                                                                                             =
-=======================================================================================================================================
-*/
-bool pcf = true;
-bool bilinear = true;
-
-static Fbo fbo;
-
-
-// exportable vars
-int shadowResolution = 512;
-Texture shadowMap;
-
-
-/*
-=======================================================================================================================================
-init                                                                                                                                  =
-=======================================================================================================================================
-*/
-void init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// texture
-	shadowMap.createEmpty2D( shadowResolution, shadowResolution, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT );
-	shadowMap.texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-	if( bilinear ) shadowMap.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-	else           shadowMap.texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	shadowMap.texParameter( GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
-	shadowMap.texParameter( GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
-	/// If you dont want to use the FFP for comparing the shadwomap (the above two lines) then you can make the comparision inside the
-	/// glsl shader. The GL_LEQUAL means that: shadow = ( R <= Dt ) ? 1.0 : 0.0; . The R is given by: R = _tex_coord2.z/_tex_coord2.w;
-	/// and the Dt = shadow2D(shadow_depth_map, _shadow_uv ).r (see lp_generic.frag). Hardware filters like GL_LINEAR cannot be applied.
-
-	// inform the we wont write to color buffers
-	fbo.setNumOfColorAttachements(0);
-
-	// attach the texture
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadowMap.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create shadow FBO" );
-
-	// unbind
-	fbo.unbind();
-}
-
-
-/*
-=======================================================================================================================================
-runPass                                                                                                                               =
-render Scene only with depth and store the result in the shadow map                                                                   =
-=======================================================================================================================================
-*/
-void runPass( const Camera& cam )
-{
-	// FBO
-	fbo.bind();
-
-	// matrix
-	glMatrixMode( GL_PROJECTION );
-	glPushMatrix();
-	glMatrixMode( GL_MODELVIEW );
-	glPushMatrix();
-	glPushAttrib( GL_VIEWPORT_BIT );
-
-	glClear( GL_DEPTH_BUFFER_BIT );
-	R::setProjectionViewMatrices( cam );
-	R::setViewport( 0, 0, shadowResolution, shadowResolution );
-
-	// disable color & blend & enable depth test
-	glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
-	glEnable( GL_DEPTH_TEST );
-	glDisable( GL_BLEND );
-
-	// for artifacts
-	glPolygonOffset( 2.0, 2.0 ); // keep the values as low as possible!!!!
-	glEnable( GL_POLYGON_OFFSET_FILL );
-
-	// render all meshes
-	for( uint i=0; i<app->getScene()->meshNodes.size(); i++ )
-	{
-		MeshNode* mesh_node = app->getScene()->meshNodes[i];
-		if( mesh_node->material->blends || mesh_node->material->refracts ) continue;
-
-		DEBUG_ERR( mesh_node->material->dpMtl == NULL );
-
-		//meshNode->material->dpMtl->setup();
-		//meshNode->renderDepth();
-		mesh_node->material->setup();
-		mesh_node->render();
-	}
-
-	glDisable( GL_POLYGON_OFFSET_FILL );
-
-	glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
-
-	glPopAttrib();
-	glMatrixMode( GL_MODELVIEW );
-	glPopMatrix();
-	glMatrixMode( GL_PROJECTION );
-	glPopMatrix();
-
-	// FBO
-	fbo.unbind();
-}
-
-
-}}} // end namespaces

+ 10 - 5
src/Renderer2/MainRenderer.cpp → src/Renderer/MainRenderer.cpp

@@ -8,7 +8,7 @@
 //=====================================================================================================================================
 //=====================================================================================================================================
 // init                                                                                                                               =
 // init                                                                                                                               =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void MainRenderer::init( const RendererInitializer& initializer )
+void MainRenderer::init( const RendererInitializer& initializer_ )
 {
 {
 	INFO( "Main renderer initializing..." );
 	INFO( "Main renderer initializing..." );
 
 
@@ -42,7 +42,7 @@ void MainRenderer::init( const RendererInitializer& initializer )
 	glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &Texture::textureUnitsNum );
 	glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &Texture::textureUnitsNum );
 
 
 	//
 	//
-	// Set default OpenGL
+	// Set GL
 	//
 	//
 	glClearColor( 0.1, 0.1, 0.1, 0.0 );
 	glClearColor( 0.1, 0.1, 0.1, 0.0 );
 	glClearDepth( 1.0 );
 	glClearDepth( 1.0 );
@@ -57,12 +57,17 @@ void MainRenderer::init( const RendererInitializer& initializer )
 	glDisable( GL_BLEND );
 	glDisable( GL_BLEND );
 	glPolygonMode( GL_FRONT, GL_FILL );
 	glPolygonMode( GL_FRONT, GL_FILL );
 
 
+	glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAtachments );
+	sProg.customLoad( "shaders/final.glsl" );
+
 	//
 	//
-	// init the rest
+	// init the offscreen Renderer
 	//
 	//
-	glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAtachments );
+	RendererInitializer initializer = initializer_;
+	renderingQuality = initializer.mainRendererQuality;
+	initializer.width = app->getWindowWidth() * renderingQuality;
+	initializer.height = app->getWindowHeight() * renderingQuality;
 	Renderer::init( initializer );
 	Renderer::init( initializer );
-	sProg.customLoad( "shaders/final.glsl" );
 
 
 	INFO( "Main renderer initialization ends" );
 	INFO( "Main renderer initialization ends" );
 }
 }

+ 1 - 1
src/Renderer2/MainRenderer.h → src/Renderer/MainRenderer.h

@@ -2,7 +2,7 @@
 #define _MAINRENDERER_H_
 #define _MAINRENDERER_H_
 
 
 #include "Common.h"
 #include "Common.h"
-#include "Renderer.hpp"
+#include "Renderer.h"
 
 
 
 
 /**
 /**

+ 15 - 42
src/Renderer/Ms.cpp

@@ -1,36 +1,14 @@
-/**
- * The file contains functions and vars used for the deferred shading material stage.
- */
-
 #include "Renderer.h"
 #include "Renderer.h"
-#include "Camera.h"
+#include "App.h"
 #include "Scene.h"
 #include "Scene.h"
-#include "Mesh.h"
-#include "Fbo.h"
-#include "Material.h"
+#include "Camera.h"
 #include "MeshNode.h"
 #include "MeshNode.h"
-#include "App.h"
-
-
-namespace R {
-namespace Ms {
-
-
-/*
-=======================================================================================================================================
-VARS                                                                                                                                  =
-=======================================================================================================================================
-*/
-static Fbo fbo;
-
-Texture normalFai, diffuseFai, specularFai, depthFai;
-
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
 // init                                                                                                                               =
 // init                                                                                                                               =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void init()
+void Renderer::Ms::init()
 {
 {
 	// create FBO
 	// create FBO
 	fbo.create();
 	fbo.create();
@@ -41,18 +19,14 @@ void init()
 
 
 	// create the FAIs
 	// create the FAIs
 	const int internal_format = GL_RGBA16F_ARB;
 	const int internal_format = GL_RGBA16F_ARB;
-	if( !normalFai.createEmpty2D( R::w, R::h, internal_format, GL_RGBA ) ||
-	    !diffuseFai.createEmpty2D( R::w, R::h, internal_format, GL_RGBA ) ||
-	    !specularFai.createEmpty2D( R::w, R::h, internal_format, GL_RGBA ) ||
-	    !depthFai.createEmpty2D( R::w, R::h, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT ) )
+	if( !normalFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
+	    !diffuseFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
+	    !specularFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
+	    !depthFai.createEmpty2D( r.width, r.height, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT ) )
 	{
 	{
 		FATAL( "Failed to create one MS FAI. See prev error" );
 		FATAL( "Failed to create one MS FAI. See prev error" );
 	}
 	}
 
 
-	
-	// you could use the above for SSAO but the difference is very little.
-	//depthFai.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-	//depthFai.texParameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 
 
 	// attach the buffers to the FBO
 	// attach the buffers to the FBO
 	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, normalFai.getGlId(), 0 );
 	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, normalFai.getGlId(), 0 );
@@ -64,13 +38,13 @@ void init()
 
 
 	// test if success
 	// test if success
 	if( !fbo.isGood() )
 	if( !fbo.isGood() )
-		FATAL( "Cannot create deferred shading material pass FBO" );
+		FATAL( "Cannot create deferred shading material stage FBO" );
 
 
 	// unbind
 	// unbind
 	fbo.unbind();
 	fbo.unbind();
 
 
 #if defined( _EARLY_Z_ )
 #if defined( _EARLY_Z_ )
-	R::Ms::earlyz::init();
+	r.Ms::earlyz::init();
 #endif
 #endif
 }
 }
 
 
@@ -78,11 +52,13 @@ void init()
 //=====================================================================================================================================
 //=====================================================================================================================================
 // runStage                                                                                                                           =
 // runStage                                                                                                                           =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void runStage( const Camera& cam )
+void Renderer::Ms::run()
 {
 {
+	Camera& cam = *r.cam;
+
 	#if defined( _EARLY_Z_ )
 	#if defined( _EARLY_Z_ )
 		// run the early z pass
 		// run the early z pass
-		R::Ms::earlyz::runPass( cam );
+		r.Ms::earlyz::runPass( cam );
 	#endif
 	#endif
 
 
 	fbo.bind();
 	fbo.bind();
@@ -90,8 +66,8 @@ void runStage( const Camera& cam )
 	#if !defined( _EARLY_Z_ )
 	#if !defined( _EARLY_Z_ )
 		glClear( GL_DEPTH_BUFFER_BIT );
 		glClear( GL_DEPTH_BUFFER_BIT );
 	#endif
 	#endif
-	R::setProjectionViewMatrices( cam );
-	R::setViewport( 0, 0, R::w, R::h );
+	r.setProjectionViewMatrices( cam );
+	r.setViewport( 0, 0, r.width, r.height );
 
 
 	//glEnable( GL_DEPTH_TEST );
 	//glEnable( GL_DEPTH_TEST );
 	app->getScene()->skybox.Render( cam.getViewMatrix().getRotationPart() );
 	app->getScene()->skybox.Render( cam.getViewMatrix().getRotationPart() );
@@ -122,6 +98,3 @@ void runStage( const Camera& cam )
 
 
 	fbo.unbind();
 	fbo.unbind();
 }
 }
-
-
-}} // end namespaces

+ 0 - 96
src/Renderer/MsEarlyz.cpp

@@ -1,96 +0,0 @@
-/*
-The file contains functions and vars used for the deferred shading/material stage/early z pass.
-*/
-
-#include "Renderer.h"
-#include "Resource.h"
-#include "Texture.h"
-#include "Scene.h"
-#include "Fbo.h"
-
-#if defined(_EARLY_Z_)
-
-namespace R {
-namespace ms {
-namespace earlyz {
-
-
-/*
-=======================================================================================================================================
-VARS                                                                                                                                  =
-=======================================================================================================================================
-*/
-static Fbo fbo;
-
-static ShaderProg* shdr_dp, * shdr_dp_grass; // passes for solid objects and grass-like
-
-
-/*
-=======================================================================================================================================
-init                                                                                                                                  =
-=======================================================================================================================================
-*/
-void init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform the we wont write to color buffers
-	fbo.setNumOfColorAttachements(0);
-
-	// attach the texture
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, R::Ms::depthFai.glId, 0 );
-
-	// test if success
-	if( !fbo.CheckStatus() )
-		FATAL( "Cannot create earlyZ FBO" );
-
-	// unbind
-	fbo.unbind();
-
-	// shaders
-	shdr_dp = Rsrc::shaders.load( "shaders/dp.glsl" );
-	shdr_dp_grass = Rsrc::shaders.load( "shaders/dp_grass.glsl" );
-}
-
-
-/*
-=======================================================================================================================================
-runPass                                                                                                                               =
-=======================================================================================================================================
-*/
-void runPass( const Camera& cam )
-{
-	/*// FBO
-	fbo.bind();
-
-	// matrix
-	glClear( GL_DEPTH_BUFFER_BIT );
-	R::setProjectionViewMatrices( cam );
-	R::setViewport( 0, 0, R::w * R::renderingQuality, R::h * R::renderingQuality );
-
-	// disable color & blend & enable depth test
-	glColorMask( false, false, false, false );
-	glEnable( GL_DEPTH_TEST );
-	glDisable( GL_BLEND );
-
-
-	// render all meshes
-	for( uint i=0; i<Scene::meshes.size(); i++ )
-		renderDepth<Mesh>( *Scene::meshes[i], shdr_dp, shdr_dp_grass );
-
-	// render all smodels
-	for( uint i=0; i<Scene::models.size(); i++ )
-		renderDepth<model_t>( *Scene::models[i], shdr_dp, shdr_dp_grass );
-
-	glColorMask( true, true, true, true );
-
-	// end
-	fbo.unbind();*/
-}
-
-
-}}} // end namespaces
-
-#endif

+ 42 - 91
src/Renderer/Pps.cpp

@@ -1,59 +1,20 @@
 #include "Renderer.h"
 #include "Renderer.h"
-#include "Resource.h"
-#include "Texture.h"
-#include "Fbo.h"
 
 
-namespace R {
-namespace Pps {
 
 
-namespace edgeaa {
-	bool enabled = false;
-}
-
-/*
-=======================================================================================================================================
-VARS                                                                                                                                  =
-=======================================================================================================================================
-*/
-
-static Fbo fbo; // yet another FBO
-
-Texture fai;
-
-// shader stuff
-
-class PpsShaderProg: public ShaderProg
-{
-	public:
-		struct
-		{
-			int isFai;
-			int ppsSsaoFai;
-			int msNormalFai;
-			int hdrFai;
-			int lscattFai;
-		} uniLocs;
-};
-
-static PpsShaderProg sProg;
-
-
-/*
-=======================================================================================================================================
-init                                                                                                                                  =
-=======================================================================================================================================
-*/
-void init()
+//=====================================================================================================================================
+// init                                                                                                                               =
+//=====================================================================================================================================
+void Renderer::Pps::init()
 {
 {
 	// create FBO
 	// create FBO
 	fbo.create();
 	fbo.create();
 	fbo.bind();
 	fbo.bind();
 
 
 	// inform in what buffers we draw
 	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
+	fbo.setNumOfColorAttachements( 1 );
 
 
 	// create the texes
 	// create the texes
-	fai.createEmpty2D( R::w, R::h, GL_RGB, GL_RGB );
+	fai.createEmpty2D( r.width, r.height, GL_RGB, GL_RGB );
 
 
 	// attach
 	// attach
 	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
 	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
@@ -66,48 +27,54 @@ void init()
 
 
 
 
 	// init the shader and it's vars
 	// init the shader and it's vars
-	sProg.customLoad( "shaders/Pps.glsl" );
+	string pps = "";
+	if( ssao.enabled )
+	{
+		pps += "#define _SSAO_\n";
+	}
+
+	if( hdr.enabled )
+	{
+		pps += "#define _HDR_\n";
+	}
+
+	sProg.customLoad( "shaders/Pps.glsl", pps.c_str() );
 	sProg.bind();
 	sProg.bind();
 
 
-	sProg.uniLocs.isFai = sProg.findUniVar( "isFai" )->getLoc();
+	sProg.uniVars.isFai = sProg.findUniVar( "isFai" );
 
 
-	if( R::Pps::Ssao::enabled )
+	if( ssao.enabled )
 	{
 	{
-		R::Pps::Ssao::init();
-		sProg.uniLocs.ppsSsaoFai = sProg.findUniVar( "ppsSsaoFai" )->getLoc();
+		ssao.init();
+		sProg.uniVars.ppsSsaoFai = sProg.findUniVar( "ppsSsaoFai" );
 	}
 	}
 
 
-	if( R::Pps::Hdr::enabled )
+	if( hdr.enabled )
 	{
 	{
-		R::Pps::Hdr::init();
-		sProg.uniLocs.hdrFai = sProg.findUniVar( "ppsHdrFai" )->getLoc();
+		hdr.init();
+		sProg.uniVars.hdrFai = sProg.findUniVar( "ppsHdrFai" );
 	}
 	}
 
 
-	if( R::Pps::edgeaa::enabled )
-		sProg.uniLocs.msNormalFai = sProg.findUniVar( "msNormalFai" )->getLoc();
-
-	if( R::Pps::Lscatt::enabled )
+	/// @ todo enable lscatt
+	/*if( R::Pps::Lscatt::enabled )
 	{
 	{
 		R::Pps::Lscatt::init();
 		R::Pps::Lscatt::init();
-		sProg.uniLocs.lscattFai = sProg.findUniVar( "ppsLscattFai" )->getLoc();
-	}
+		sProg.uniVars.lscattFai = sProg.findUniVar( "ppsLscattFai" )->getLoc();
+	}*/
 
 
 }
 }
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// runStage                                                                                                                           =
+// run                                                                                                                                =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void runStage( const Camera& cam )
+void Renderer::Pps::run()
 {
 {
-	if( R::Pps::Ssao::enabled )
-		R::Pps::Ssao::runPass( cam );
+	if( ssao.enabled )
+		ssao.run();
 
 
-	if( R::Pps::Hdr::enabled )
-		R::Pps::Hdr::runPass( cam );
-
-	if( R::Pps::Lscatt::enabled )
-		R::Pps::Lscatt::runPass( cam );
+	if( hdr.enabled )
+		hdr.run();
 
 
 	fbo.bind();
 	fbo.bind();
 
 
@@ -115,41 +82,25 @@ void runStage( const Camera& cam )
 	glDisable( GL_DEPTH_TEST );
 	glDisable( GL_DEPTH_TEST );
 	glDisable( GL_BLEND );
 	glDisable( GL_BLEND );
 
 
-	R::setViewport( 0, 0, R::w, R::h );
+	Renderer::setViewport( 0, 0, r.width, r.height );
 
 
 	// set shader
 	// set shader
 	sProg.bind();
 	sProg.bind();
+	sProg.uniVars.isFai->setTexture( r.is.fai, 0 );
 
 
-	sProg.locTexUnit( sProg.uniLocs.isFai, R::Is::fai, 0 );
-
-	if( R::Pps::Ssao::enabled )
-	{
-		sProg.locTexUnit( sProg.uniLocs.ppsSsaoFai, R::Pps::Ssao::fai, 1 );
-	}
-
-	if( R::Pps::edgeaa::enabled )
+	if( hdr.enabled )
 	{
 	{
-		sProg.locTexUnit( sProg.uniLocs.msNormalFai, R::Ms::normalFai, 2 );
+		sProg.uniVars.hdrFai->setTexture( hdr.fai, 1 );
 	}
 	}
 
 
-	if( R::Pps::Hdr::enabled )
+	if( ssao.enabled )
 	{
 	{
-		sProg.locTexUnit( sProg.uniLocs.hdrFai, R::Pps::Hdr::fai, 3 );
+		sProg.uniVars.ppsSsaoFai->setTexture( ssao.fai, 2 );
 	}
 	}
 
 
-	if( R::Pps::Lscatt::enabled )
-	{
-		sProg.locTexUnit( sProg.uniLocs.lscattFai, R::Pps::Lscatt::fai, 4 );
-	}
-
-
 	// draw quad
 	// draw quad
-	R::DrawQuad( 0 );
+	Renderer::drawQuad( 0 );
 
 
 	// unbind FBO
 	// unbind FBO
 	fbo.unbind();
 	fbo.unbind();
 }
 }
-
-
-}} // end namespaces
-

+ 0 - 139
src/Renderer/PpsHdr.cpp

@@ -1,139 +0,0 @@
-/*
-The file contains functions and vars used for the deferred shading/post-processing stage/bloom passes.
-*/
-
-#include "Renderer.h"
-#include "Resource.h"
-#include "Texture.h"
-#include "Scene.h"
-#include "Fbo.h"
-
-namespace R {
-namespace Pps {
-namespace Hdr {
-
-
-//=====================================================================================================================================
-// VARS                                                                                                                               =
-//=====================================================================================================================================
-bool enabled = true;
-
-static Fbo pass0Fbo, pass1Fbo, pass2Fbo; // yet another FBO and another, damn
-
-float renderingQuality = 0.5; // 1/4 of the image
-static uint w, h; // render width and height
-
-// hdr images
-Texture pass0Fai; // for vertical blur pass
-Texture pass1Fai; // with the horizontal blur
-Texture fai; ///< The final fai
-
-class HdrShaderProg: public ShaderProg
-{
-	public:
-		struct
-		{
-			int fai;
-		} uniLocs;
-};
-
-static HdrShaderProg pass0SProg, pass1SProg, pass2SProg;
-
-
-//=====================================================================================================================================
-// initFbos                                                                                                                           =
-//=====================================================================================================================================
-static void initFbos( Fbo& fbo, Texture& fai, int internalFormat )
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
-
-	// create the texes
-	fai.createEmpty2D( w, h, internalFormat, GL_RGB );
-	fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	//fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-	fai.texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-
-	// attach
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create deferred shading post-processing stage HDR passes FBO" );
-
-	// unbind
-	fbo.unbind();
-}
-
-
-//=====================================================================================================================================
-// init                                                                                                                               =
-//=====================================================================================================================================
-void init()
-{
-	w = R::Pps::Hdr::renderingQuality * R::w;
-	h = R::Pps::Hdr::renderingQuality * R::h;
-
-	initFbos( pass0Fbo, pass0Fai, GL_RGB );
-	initFbos( pass1Fbo, pass1Fai, GL_RGB );
-	initFbos( pass2Fbo, fai, GL_RGB );
-
-	fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-
-	// init shaders
-	if( !pass0SProg.customLoad( "shaders/PpsHdr.glsl", ("#define _PPS_HDR_PASS_0_\n#define IS_FAI_WIDTH " + Util::floatToStr(R::w) + "\n").c_str() ) )
-		FATAL( "See prev error" );
-	pass0SProg.uniLocs.fai = pass0SProg.findUniVar("fai")->getLoc();
-
-	if( !pass1SProg.customLoad( "shaders/PpsHdr.glsl", ("#define _PPS_HDR_PASS_1_\n#define PASS0_HEIGHT " + Util::floatToStr(h) + "\n").c_str() ) )
-		FATAL( "See prev error" );
-	pass1SProg.uniLocs.fai = pass1SProg.findUniVar("fai")->getLoc();
-
-	if( !pass2SProg.customLoad( "shaders/PpsHdr.glsl", "#define _PPS_HDR_PASS_2_\n" ) )
-		FATAL( "See prev error" );
-	pass2SProg.uniLocs.fai = pass2SProg.findUniVar("fai")->getLoc();
-}
-
-
-//=====================================================================================================================================
-// runPass                                                                                                                            =
-//=====================================================================================================================================
-void runPass( const Camera& /*cam*/ )
-{
-	R::setViewport( 0, 0, w, h );
-
-	glDisable( GL_BLEND );
-	glDisable( GL_DEPTH_TEST );
-
-
-	// pass 0
-	pass0Fbo.bind();
-	pass0SProg.bind();
-	pass0SProg.locTexUnit( pass0SProg.uniLocs.fai, R::Is::fai, 0 );
-	R::DrawQuad( 0 );
-
-
-	// pass 1
-	pass1Fbo.bind();
-	pass1SProg.bind();
-	pass1SProg.locTexUnit( pass1SProg.uniLocs.fai, pass0Fai, 0 );
-	R::DrawQuad( 0 );
-
-
-	// pass 2
-	pass2Fbo.bind();
-	pass2SProg.bind();
-	pass2SProg.locTexUnit( pass2SProg.uniLocs.fai, pass1Fai, 0 );
-	R::DrawQuad( 0 );
-
-	// end
-	Fbo::unbind();
-}
-
-
-}}} // end namespaces
-

+ 0 - 107
src/Renderer/PpsLscatt.cpp

@@ -1,107 +0,0 @@
-#include "Renderer.h"
-#include "Resource.h"
-#include "Texture.h"
-#include "Scene.h"
-#include "Fbo.h"
-#include "App.h"
-
-namespace R {
-namespace Pps {
-namespace Lscatt {
-
-
-/*
-=======================================================================================================================================
-VARS                                                                                                                                  =
-=======================================================================================================================================
-*/
-static Fbo fbo; // yet another FBO
-
-float renderingQuality = 1.0;
-bool enabled = false;
-
-Texture fai;
-
-static ShaderProg sProg;
-static int msDepthFaiUniLoc;
-static int isFaiUniLoc;
-
-
-/*
-=======================================================================================================================================
-init                                                                                                                                  =
-=======================================================================================================================================
-*/
-void init()
-{
-	if( renderingQuality<0.0 || renderingQuality>1.0 ) ERROR("Incorect R::pps:lscatt::rendering_quality");
-	float wwidth = R::Pps::Lscatt::renderingQuality * R::w;
-	float wheight = R::Pps::Lscatt::renderingQuality * R::h;
-
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
-
-	// create the texes
-	fai.createEmpty2D( wwidth, wheight, GL_RGB, GL_RGB );
-	fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-	fai.texParameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-
-	// attach
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create deferred shading post-processing stage light scattering pass FBO" );
-
-	// unbind
-	fbo.unbind();
-
-
-	// init shaders
-	sProg.customLoad( "shaders/PpsLscatt.glsl" );
-	msDepthFaiUniLoc = sProg.findUniVar( "msDepthFai" )->getLoc();
-	isFaiUniLoc = sProg.findUniVar( "isFai" )->getLoc();
-}
-
-
-/*
-=======================================================================================================================================
-runPass                                                                                                                               =
-=======================================================================================================================================
-*/
-void runPass( const Camera& cam )
-{
-	fbo.bind();
-
-	R::setViewport( 0, 0, R::w * renderingQuality, R::h * renderingQuality );
-
-	glDisable( GL_BLEND );
-	glDisable( GL_DEPTH_TEST );
-
-	// set the shader
-	sProg.bind();
-
-	sProg.locTexUnit( msDepthFaiUniLoc, R::Ms::depthFai, 0 );
-	sProg.locTexUnit( isFaiUniLoc, R::Is::fai, 1 );
-
-	// pass the light
-	Vec4 p = Vec4( app->getScene()->getSunPos(), 1.0 );
-	p = cam.getProjectionMatrix() * (cam.getViewMatrix() * p);
-	p /= p.w;
-	p = p/2 + 0.5;
-	glUniform2fv( sProg.findUniVar("lightPosScreenSpace")->getLoc(), 1, &p[0] );
-
-	// Draw quad
-	R::DrawQuad( 0 );
-
-	// end
-	fbo.unbind();
-}
-
-
-}}} // end namespaces
-

+ 0 - 194
src/Renderer/PpsSsao.cpp

@@ -1,194 +0,0 @@
-/*
-The file contains functions and vars used for the deferred shading/post-processing stage/SSAO pass.
-*/
-
-#include "Renderer.h"
-#include "Resource.h"
-#include "Texture.h"
-#include "Scene.h"
-#include "Fbo.h"
-#include "Camera.h"
-
-namespace R {
-namespace Pps {
-namespace Ssao {
-
-
-//=====================================================================================================================================
-// VARS                                                                                                                               =
-//=====================================================================================================================================
-bool enabled = true;
-
-static Fbo pass0Fbo, pass1Fbo, pass2Fbo;
-
-float renderingQuality = 0.75; // the renderingQuality of the SSAO fai. Chose low so it can blend
-float bluringQuality = 1.0;
-
-static uint w, h;
-static uint bw, bh;
-
-Texture pass0Fai, pass1Fai, fai;
-
-static ShaderProg ssaoSProg, blurSProg, blurSProg2;
-
-static Texture* noiseMap;
-
-
-//=====================================================================================================================================
-// initBlurFbos                                                                                                                       =
-//=====================================================================================================================================
-static void initBlurFbos()
-{
-	// create FBO
-	pass1Fbo.create();
-	pass1Fbo.bind();
-
-	// inform in what buffers we draw
-	pass1Fbo.setNumOfColorAttachements(1);
-
-	// create the texes
-	pass1Fai.createEmpty2D( bw, bh, GL_ALPHA8, GL_ALPHA );
-	pass1Fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	pass1Fai.texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-
-	// attach
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, pass1Fai.getGlId(), 0 );
-
-	// test if success
-	if( !pass1Fbo.isGood() )
-		FATAL( "Cannot create deferred shading post-processing stage SSAO blur FBO" );
-
-	// unbind
-	pass1Fbo.unbind();
-
-
-
-	// create FBO
-	pass2Fbo.create();
-	pass2Fbo.bind();
-
-	// inform in what buffers we draw
-	pass2Fbo.setNumOfColorAttachements(1);
-
-	// create the texes
-	fai.createEmpty2D( bw, bh, GL_ALPHA8, GL_ALPHA );
-	fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-	fai.texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-
-	// attach
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
-
-	// test if success
-	if( !pass2Fbo.isGood() )
-		FATAL( "Cannot create deferred shading post-processing stage SSAO blur FBO" );
-
-	// unbind
-	pass2Fbo.unbind();
-}
-
-
-/*
-=======================================================================================================================================
-init                                                                                                                                  =
-=======================================================================================================================================
-*/
-void init()
-{
-	w = R::Pps::Ssao::renderingQuality * R::w;
-	h = R::Pps::Ssao::renderingQuality * R::h;
-	bw = w * bluringQuality;
-	bh = h * bluringQuality;
-
-	// create FBO
-	pass0Fbo.create();
-	pass0Fbo.bind();
-
-	// inform in what buffers we draw
-	pass0Fbo.setNumOfColorAttachements(1);
-
-	// create the texes
-	pass0Fai.createEmpty2D( w, h, GL_ALPHA8, GL_ALPHA );
-	pass0Fai.texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	pass0Fai.texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-
-	// attach
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, pass0Fai.getGlId(), 0 );
-
-	// test if success
-	if( !pass0Fbo.isGood() )
-		FATAL( "Cannot create deferred shading post-processing stage SSAO pass FBO" );
-
-	// unbind
-	pass0Fbo.unbind();
-
-
-	// init shaders
-	ssaoSProg.customLoad( "shaders/PpsSsao.glsl" );
-
-	// load noise map and disable temporaly the texture compression and enable mipmapping
-	bool texCompr = R::textureCompression;
-	bool mipmaping = R::mipmapping;
-	R::textureCompression = false;
-	R::mipmapping = true;
-	noiseMap = Rsrc::textures.load( "gfx/noise3.tga" );
-	noiseMap->texParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
-	noiseMap->texParameter( GL_TEXTURE_WRAP_T, GL_REPEAT );
-	//noise_map->texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-	//noise_map->texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-	R::textureCompression = texCompr;
-	R::mipmapping = mipmaping;
-
-	// blur FBO
-	initBlurFbos();
-	blurSProg.customLoad( "shaders/PpsSsaoBlur.glsl", ("#define _PPS_SSAO_PASS_0_\n#define PASS0_FAI_WIDTH " + Util::floatToStr(w) + "\n").c_str() );
-	blurSProg2.customLoad( "shaders/PpsSsaoBlur.glsl", ("#define _PPS_SSAO_PASS_1_\n#define PASS1_FAI_HEIGHT " + Util::floatToStr(bh) + "\n").c_str() );
-}
-
-
-/*
-=======================================================================================================================================
-runPass                                                                                                                               =
-=======================================================================================================================================
-*/
-void runPass( const Camera& cam )
-{
-	pass0Fbo.bind();
-
-	R::setViewport( 0, 0, w, h );
-
-	glDisable( GL_BLEND );
-	glDisable( GL_DEPTH_TEST );
-
-	// fill SSAO FAI
-	ssaoSProg.bind();
-	glUniform2fv( ssaoSProg.findUniVar("camerarange")->getLoc(), 1, &(Vec2(cam.getZNear(), cam.getZFar()))[0] );
-	ssaoSProg.locTexUnit( ssaoSProg.findUniVar("msDepthFai")->getLoc(), R::Ms::depthFai, 0 );
-	ssaoSProg.locTexUnit( ssaoSProg.findUniVar("noiseMap")->getLoc(), *noiseMap, 1 );
-	ssaoSProg.locTexUnit( ssaoSProg.findUniVar("msNormalFai")->getLoc(), R::Ms::normalFai, 2 );
-	R::DrawQuad( 0 ); // Draw quad
-
-	/*glBindFramebuffer( GL_READ_FRAMEBUFFER, pass0Fbo.getGlId() );
-	glBindFramebuffer( GL_DRAW_FRAMEBUFFER, pass1Fbo.getGlId() );
-	glBlitFramebuffer( 0, 0, w, h, 0, 0, bw, bh, GL_COLOR_BUFFER_BIT, GL_NEAREST);*/
-
-	R::setViewport( 0, 0, bw, bh );
-
-	// second pass. blur
-	pass1Fbo.bind();
-	blurSProg.bind();
-	blurSProg.locTexUnit( blurSProg.findUniVar("tex")->getLoc(), pass0Fai, 0 );
-	R::DrawQuad( 0 ); // Draw quad
-
-	// third pass. blur
-	pass2Fbo.bind();
-	blurSProg2.bind();
-	blurSProg2.locTexUnit( blurSProg2.findUniVar("tex")->getLoc(), pass1Fai, 0 );
-	R::DrawQuad( 0 ); // Draw quad
-
-
-	// end
-	Fbo::unbind();
-}
-
-
-}}} // end namespaces

+ 97 - 405
src/Renderer/Renderer.cpp

@@ -1,305 +1,139 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <jpeglib.h>
 #include "Renderer.h"
 #include "Renderer.h"
-#include "Texture.h"
-#include "Scene.h"
-#include "Camera.h"
-#include "App.h"
+#include "Camera.h" /// @todo remove this
+#include "RendererInitializer.h"
 
 
-namespace R {
 
 
-
-/*
-=======================================================================================================================================
-data vars                                                                                                                             =
-=======================================================================================================================================
-*/
-
-// misc
-uint w, h;
-uint framesNum = 0;
-float aspectRatio;
-
-int maxColorAtachments = 0;
-float renderingQuality = 1.0;
-int screenshotJpegQuality = 90;
-
-static ShaderProg* shdr_final;
-
-// for the pps and is quad rendering
-float quadVertCoords [][2] = { {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0} };
-
-
-/**
- * Standard shader preprocessor defines. Used to pass some global params to the shaders. The standard shader preprocessor defines
- * go on top of the shader code and its defines
- */
-string std_shader_preproc_defines;
-
-// texture
-bool mipmapping = true;
-int maxAnisotropy = 8;
-int maxTextureUnits = -1;
-bool textureCompression = false;
+//=====================================================================================================================================
+// Vars                                                                                                                               =
+//=====================================================================================================================================
+bool Renderer::textureCompression = false;
+int  Renderer::maxTextureUnits = -1;
+bool Renderer::mipmapping = true;
+int  Renderer::maxAnisotropy = 8;
+float Renderer::quadVertCoords [][2] = { {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0} };
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// DrawQuad                                                                                                                           =
+// Constructor                                                                                                                        =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void DrawQuad( int vertCoordsUniLoc )
+Renderer::Renderer():
+	width( 640 ),
+	height( 480 ),
+	ms( *this ),
+	is( *this ),
+	pps( *this ),
+	dbg( *this )
 {
 {
-	DEBUG_ERR( vertCoordsUniLoc == -1 );
-	/*glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 2, GL_FLOAT, 0, quadVertCoords );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableClientState( GL_VERTEX_ARRAY );*/
-	glVertexAttribPointer( vertCoordsUniLoc, 2, GL_FLOAT, false, 0, quadVertCoords );
-	glEnableVertexAttribArray( vertCoordsUniLoc );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableVertexAttribArray( vertCoordsUniLoc );
 }
 }
 
 
-
-/*
-=======================================================================================================================================
-BuildStdShaderPreProcStr                                                                                                              =
-I pass all the static vars (vars that do not change at all) with defines so I dont have to update uniform vars                        =
-=======================================================================================================================================
-*/
-static void buildStdShaderPreProcStr()
+//=====================================================================================================================================
+// init                                                                                                                               =
+//=====================================================================================================================================
+void Renderer::init( const RendererInitializer& initializer )
 {
 {
-	string& tmp = std_shader_preproc_defines;
-
-	tmp  = "#version 150 compatibility\n";
-	tmp += "precision lowp float;\n";
-	tmp += "#pragma optimize(on)\n";
-	tmp += "#pragma debug(off)\n";
-	tmp += "#define R_W " + Util::floatToStr(R::w) + "\n";
-	tmp += "#define R_H " + Util::floatToStr(R::h) + "\n";
-	//tmp += "#define R_Q " + floatToStr(R::renderingQuality) + "\n";
-	tmp += "#define SHADOWMAP_SIZE " + Util::intToStr(R::Is::Shad::shadowResolution) + "\n";
-	if( R::Is::Shad::pcf )
-		tmp += "#define _SHADOW_MAPPING_PCF_\n";
-	if( R::Pps::Ssao::enabled )
-	{
-		tmp += "#define _SSAO_\n";
-		tmp += "#define SSAO_RENDERING_QUALITY " + Util::floatToStr(R::Pps::Ssao::renderingQuality) + "\n";
-	}
-	if( R::Pps::edgeaa::enabled )
-		tmp += "#define _EDGEAA_\n";
-	if( R::Pps::Hdr::enabled )
-	{
-		tmp += "#define _HDR_\n";
-		tmp += "#define HDR_RENDERING_QUALITY " + Util::floatToStr(R::Pps::Hdr::renderingQuality) + "\n";
-	}
-	if( R::Pps::Lscatt::enabled )
+	// set from the initializer
+	is.sm.enabled = initializer.is.sm.enabled;
+	is.sm.pcfEnabled = initializer.is.sm.pcfEnabled;
+	is.sm.bilinearEnabled = initializer.is.sm.bilinearEnabled;
+	is.sm.resolution = initializer.is.sm.resolution;
+	pps.hdr.enabled = initializer.pps.hdr.enabled;
+	pps.hdr.renderingQuality = initializer.pps.hdr.renderingQuality;
+	pps.ssao.enabled = initializer.pps.ssao.enabled;
+	pps.ssao.renderingQuality = initializer.pps.ssao.renderingQuality;
+	pps.ssao.bluringQuality = initializer.pps.ssao.bluringQuality;
+	dbg.enabled = initializer.dbg.enabled;
+	width = initializer.width;
+	height = initializer.height;
+
+	aspectRatio = float(width)/height;
+
+	// a few sanity checks
+	if( width < 1 || height < 1 )
 	{
 	{
-		tmp += "#define _LSCATT_\n";
-		tmp += "#define LSCATT_RENDERING_QUALITY " + Util::floatToStr(R::Pps::Lscatt::renderingQuality) + "\n";
+		FATAL( "Incorrect width" );
 	}
 	}
+
+	// init the stages. Careful with the order!!!!!!!!!!
+	ms.init();
+	is.init();
+	pps.init();
+	dbg.init();
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-init                                                                                                                                  =
-=======================================================================================================================================
-*/
-void init()
+//=====================================================================================================================================
+// render                                                                                                                             =
+//=====================================================================================================================================
+void Renderer::render( Camera& cam_ )
 {
 {
-	INFO( "Renderer initializing..." );
-
-	GLenum err = glewInit();
-	if( err != GLEW_OK )
-		FATAL( "GLEW initialization failed" );
-
-	// print GL info
-	INFO( "OpenGL info: OGL " << glGetString(GL_VERSION) << ", GLSL " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
-
-	if( !glewIsSupported("GL_VERSION_3_1") )
-		WARNING( "OpenGL ver 3.1 not supported. The application may crash (and burn)" );
-
-	if( !glewIsSupported("GL_EXT_framebuffer_object") )
-		WARNING( "Framebuffer objects not supported. The application may crash (and burn)" );
-
-	if( !glewIsSupported("GL_EXT_packed_depth_stencil") )
-		WARNING( "GL_EXT_packed_depth_stencil not supported. The application may crash (and burn)" );
+	cam = &cam_;
 
 
-	if( !glewIsSupported("GL_ARB_vertex_buffer_object") )
-		WARNING( "Vertex buffer objects not supported. The application may crash (and burn)" );
+	ms.run();
+	is.run();
+	pps.run();
+	dbg.run();
 
 
-	if( !glewIsSupported("GL_ARB_texture_non_power_of_two") )
-		WARNING( "Textures of non power of two not supported. The application may crash (and burn)" );
-
-	if( !glewIsSupported("GL_ARB_vertex_buffer_object") )
-		WARNING( "Vertex Buffer Objects not supported. The application may crash (and burn)" );
-
-	w = app->getWindowWidth() * renderingQuality;
-	h = app->getWindowHeight() * renderingQuality;
-	aspectRatio = float(w)/h;
-
-	glClearColor( 0.1, 0.1, 0.1, 0.0 );
-	glClearDepth( 1.0 );
-	glClearStencil( 0 );
-	glDepthFunc( GL_LEQUAL );
-
-	// query for maxColorAtachments
-	glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAtachments );
-
-	// get max texture units
-	glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits );
-
-	// CullFace is always on
-	glCullFace( GL_BACK );
-	glEnable( GL_CULL_FACE );
-
-	// defaults
-	glDisable( GL_LIGHTING );
-	glDisable( GL_TEXTURE_2D );
-	glDisable( GL_BLEND );
-	glPolygonMode( GL_FRONT, GL_FILL );
-
-	// Hints
-	//glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_FASTEST );
-	//glHint( GL_LINE_SMOOTH_HINT, GL_FASTEST );
-	//glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
-	//glHint( GL_POINT_SMOOTH_HINT, GL_FASTEST );
-	//glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST );
-	//glHint( GL_TEXTURE_COMPRESSION_HINT, GL_NICEST );
-
-	// execute this after the cvars are set and before the other inits (be cause these inits contain shader loads)
-	buildStdShaderPreProcStr();
-
-	//
-	// init deferred stages. WARNING: the order of the inits is crucial!!!!!
-	//
-
-	// disable mipmapping
-	bool mipmapping_ = mipmapping;
-	mipmapping = false;
-
-	R::Ms::init();
-	R::Is::init();
-	R::Bs::init();
-	R::Pps::init();
-	R::Bs::init2();
-	R::Dbg::init();
-
-	mipmapping = mipmapping_;
-
-	// misc
-	shdr_final = Rsrc::shaders.load( "shaders/final.glsl" );
-
-	INFO( "Renderer initialization ends" );
+	++framesNum;
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-render                                                                                                                                =
-=======================================================================================================================================
-*/
-void render( const Camera& cam )
+//=====================================================================================================================================
+// drawQuad                                                                                                                           =
+//=====================================================================================================================================
+void Renderer::drawQuad( int vertCoordsUniLoc )
 {
 {
-	R::Ms::runStage( cam );
-	R::Is::runStage( cam );
-	R::Bs::runStage( cam );
-	R::Pps::runStage( cam );
-	R::Bs::runStage2( cam );
-	R::Dbg::runStage( cam );
-
-	//R::setViewport( 0, 0, App::windowW, App::windowH );
-	R::setViewport( 0, 0, app->getWindowWidth(), app->getWindowHeight() );
-
-	glDisable( GL_DEPTH_TEST );
-	glDisable( GL_BLEND );
-
-	shdr_final->bind();
-	shdr_final->locTexUnit( shdr_final->findUniVar("rasterImage")->getLoc(), R::Pps::fai, 0 );
-
-	/*const int step = 100;
-	if( R::framesNum < step )
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::Ms::diffuseFai, 0 );
-	else if( R::framesNum < step*2 )
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::Ms::normalFai, 0 );
-	else if( R::framesNum < step*3 )
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::Ms::specularFai, 0 );
-	else if( R::framesNum < step*4 )
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::Ms::depthFai, 0 );
-	else if( R::framesNum < step*5 )
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::pps::ssao::bluredFai, 0 );
-	else if( R::framesNum < step*6 )
-	{
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::pps::hdr::pass2Fai, 0 );
-	}
-	else
-		shdr_final->locTexUnit( shdr_final->getUniLoc(0), R::pps::fai, 0 );*/
-
-
-	R::DrawQuad( 0 );
+	DEBUG_ERR( vertCoordsUniLoc == -1 );
+	glVertexAttribPointer( vertCoordsUniLoc, 2, GL_FLOAT, false, 0, quadVertCoords );
+	glEnableVertexAttribArray( vertCoordsUniLoc );
+	glDrawArrays( GL_QUADS, 0, 4 );
+	glDisableVertexAttribArray( vertCoordsUniLoc );
 }
 }
 
 
-
-/*
-=======================================================================================================================================
-setProjectionMatrix                                                                                                                   =
-=======================================================================================================================================
-*/
-void setProjectionMatrix( const Camera& cam )
+//=====================================================================================================================================
+// setProjectionMatrix                                                                                                                =
+//=====================================================================================================================================
+void Renderer::setProjectionMatrix( const Camera& cam )
 {
 {
 	glMatrixMode( GL_PROJECTION );
 	glMatrixMode( GL_PROJECTION );
 	loadMatrix( cam.getProjectionMatrix() );
 	loadMatrix( cam.getProjectionMatrix() );
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-setViewMatrix                                                                                                                         =
-=======================================================================================================================================
-*/
-void setViewMatrix( const Camera& cam )
+//=====================================================================================================================================
+// setViewMatrix                                                                                                                      =
+//=====================================================================================================================================
+void Renderer::setViewMatrix( const Camera& cam )
 {
 {
 	glMatrixMode( GL_MODELVIEW );
 	glMatrixMode( GL_MODELVIEW );
 	loadMatrix( cam.getViewMatrix() );
 	loadMatrix( cam.getViewMatrix() );
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-unproject                                                                                                                             =
-my version of gluUnproject                                                                                                            =
-=======================================================================================================================================
-*/
-bool unproject( float winX, float winY, float winZ, // window screen coords
-                const Mat4& modelview_mat, const Mat4& projection_mat, const int* view,
-                float& objX, float& objY, float& objZ )
+//=====================================================================================================================================
+// unproject                                                                                                                          =
+//=====================================================================================================================================
+Vec3 Renderer::unproject( const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat, const int view[4] )
 {
 {
-	Mat4 inv_pm = projection_mat * modelview_mat;
-	inv_pm.invert();
+	Mat4 invPm = projectionMat * modelViewMat;
+	invPm.invert();
 
 
 	// the vec is in ndc space meaning: -1<=vec.x<=1 -1<=vec.y<=1 -1<=vec.z<=1
 	// the vec is in ndc space meaning: -1<=vec.x<=1 -1<=vec.y<=1 -1<=vec.z<=1
 	Vec4 vec;
 	Vec4 vec;
-	vec.x = (2.0*(winX-view[0]))/view[2] - 1.0;
-	vec.y = (2.0*(winY-view[1]))/view[3] - 1.0;
-	vec.z = 2.0*winZ - 1.0;
+	vec.x = (2.0*(windowCoords.x-view[0]))/view[2] - 1.0;
+	vec.y = (2.0*(windowCoords.y-view[1]))/view[3] - 1.0;
+	vec.z = 2.0*windowCoords.z - 1.0;
 	vec.w = 1.0;
 	vec.w = 1.0;
 
 
-	Vec4 final = inv_pm * vec;
+	Vec4 final = invPm * vec;
 	final /= final.w;
 	final /= final.w;
-	objX = final.x;
-	objY = final.y;
-	objZ = final.z;
-	return true;
+	return Vec3( final );
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-ortho                                                                                                                                 =
-=======================================================================================================================================
-*/
-Mat4 ortho( float left, float right, float bottom, float top, float near, float far )
+//=====================================================================================================================================
+// ortho                                                                                                                              =
+//=====================================================================================================================================
+Mat4 Renderer::ortho( float left, float right, float bottom, float top, float near, float far )
 {
 {
 	float difx = right-left;
 	float difx = right-left;
 	float dify = top-bottom;
 	float dify = top-bottom;
@@ -330,164 +164,22 @@ Mat4 ortho( float left, float right, float bottom, float top, float near, float
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-prepareNextFrame                                                                                                                      =
-=======================================================================================================================================
-*/
-void prepareNextFrame()
-{
-	framesNum++;
-}
-
-
-/*
-=======================================================================================================================================
-printLastError                                                                                                                        =
-=======================================================================================================================================
-*/
-void printLastError()
-{
-	GLenum errid = glGetError();
-	if( errid != GL_NO_ERROR )
-		ERROR( "OpenGL Error: " << gluErrorString( errid ) );
-}
-
-
 //=====================================================================================================================================
 //=====================================================================================================================================
 // getLastError                                                                                                                       =
 // getLastError                                                                                                                       =
 //=====================================================================================================================================
 //=====================================================================================================================================
-const uchar* getLastError()
+const uchar* Renderer::getLastError()
 {
 {
 	return gluErrorString( glGetError() );
 	return gluErrorString( glGetError() );
 }
 }
 
 
 
 
-/*
-=======================================================================================================================================
-TakeScreenshotTGA                                                                                                                     =
-=======================================================================================================================================
-*/
-static bool TakeScreenshotTGA( const char* filename )
-{
-	// open file and check
-	fstream fs;
-	fs.open( filename, ios::out|ios::binary );
-	if( !fs.good() )
-	{
-		ERROR( "Cannot create screenshot. File \"" << filename << "\"" );
-		return false;
-	}
-
-	// write headers
-	unsigned char tga_header_uncompressed[12] = {0,0,2,0,0,0,0,0,0,0,0,0};
-	unsigned char header[6];
-
-	header[1] = R::w / 256;
-	header[0] = R::w % 256;
-	header[3] = R::h / 256;
-	header[2] = R::h % 256;
-	header[4] = 24;
-	header[5] = 0;
-
-	fs.write( (char*)tga_header_uncompressed, 12 );
-	fs.write( (char*)header, 6 );
-
-	// write the buffer
-	char* buffer = (char*)calloc( R::w*R::h*3, sizeof(char) );
-
-	glReadPixels( 0, 0, R::w, R::h, GL_BGR, GL_UNSIGNED_BYTE, buffer );
-	fs.write( buffer, R::w*R::h*3 );
-
-	// end
-	fs.close();
-	free( buffer );
-	return true;
-}
-
-
-/*
-=======================================================================================================================================
-TakeScreenshotJPEG                                                                                                                    =
-=======================================================================================================================================
-*/
-static bool TakeScreenshotJPEG( const char* filename )
-{
-	// open file
-	FILE* outfile = fopen( filename, "wb" );
-
-	if( !outfile )
-	{
-		ERROR( "Cannot open file \"" << filename << "\"" );
-		return false;
-	}
-
-	// set jpg params
-	jpeg_compress_struct cinfo;
-	jpeg_error_mgr       jerr;
-
-	cinfo.err = jpeg_std_error( &jerr );
-	jpeg_create_compress( &cinfo );
-	jpeg_stdio_dest( &cinfo, outfile );
-
-	cinfo.image_width      = R::w;
-	cinfo.image_height     = R::h;
-	cinfo.input_components = 3;
-	cinfo.in_color_space   = JCS_RGB;
-	jpeg_set_defaults( &cinfo);
-	jpeg_set_quality ( &cinfo, screenshotJpegQuality, true );
-	jpeg_start_compress( &cinfo, true );
-
-	// read from OGL
-	char* buffer = (char*)malloc( R::w*R::h*3*sizeof(char) );
-	glReadPixels( 0, 0, R::w, R::h, GL_RGB, GL_UNSIGNED_BYTE, buffer );
-
-	// write buffer to file
-	JSAMPROW row_pointer;
-
-	while( cinfo.next_scanline < cinfo.image_height )
-	{
-		row_pointer = (JSAMPROW) &buffer[ (R::h-1-cinfo.next_scanline)*3*R::w ];
-		jpeg_write_scanlines( &cinfo, &row_pointer, 1 );
-	}
-
-	jpeg_finish_compress(&cinfo);
-
-	// done
-	free( buffer );
-	fclose( outfile );
-	return true;
-}
-
-
-/*
-=======================================================================================================================================
-takeScreenshot                                                                                                                        =
-=======================================================================================================================================
-*/
-void takeScreenshot( const char* filename )
+//=====================================================================================================================================
+// printLastError                                                                                                                     =
+//=====================================================================================================================================
+void Renderer::printLastError()
 {
 {
-	string ext = Util::getFileExtension( filename );
-	bool ret;
-
-	// exec from this extension
-	if( ext == "tga" )
-	{
-		ret = TakeScreenshotTGA( filename );
-	}
-	else if( ext == "jpg" || ext == "jpeg" )
-	{
-		ret = TakeScreenshotJPEG( filename );
-	}
-	else
-	{
-		ERROR( "File \"" << filename << "\": Unsupported extension. Watch for capital" );
-		return;
-	}
-	if( !ret ) ERROR( "In taking screenshot" )
-	else PRINT( "Screenshot \"" << filename << "\" saved" );
+	GLenum errid = glGetError();
+	if( errid != GL_NO_ERROR )
+		ERROR( "OpenGL Error: " << gluErrorString( errid ) );
 }
 }
 
 
-
-} // end namespace
-

+ 404 - 174
src/Renderer/Renderer.h

@@ -1,185 +1,415 @@
-#ifndef _RENDERER_H_
-#define _RENDERER_H_
+#ifndef _RENDERER_HPP_
+#define _RENDERER_HPP_
 
 
 #include "Common.h"
 #include "Common.h"
-#include <GL/glew.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
 #include "Math.h"
 #include "Math.h"
+#include "Fbo.h"
+#include "Texture.h"
 #include "ShaderProg.h"
 #include "ShaderProg.h"
-#include "Camera.h"
-
-
 
 
 class Camera;
 class Camera;
+class PointLight;
+class SpotLight;
+class RendererInitializer;
 
 
-/// renderer namespace
-namespace R { // begin namespace
-
-
-extern uint  w; ///< width of the rendering. Dont confuse with the window width
-extern uint  h; ///< height of the rendering. Dont confuse with the window width
-extern float renderingQuality; ///< The global rendering quality of the raster image. From 0.0(low) to 1.0(high)
-extern uint  framesNum;
-extern float aspectRatio;
-extern int   screenshotJpegQuality; ///< The quality of the JPEG screenshots. From 0 to 100
-
-extern int  maxColorAtachments; ///< Max color attachments a FBO can accept
-
-// texture stuff
-extern bool textureCompression; ///< Used in Texture::load to enable texture compression. Decreases video memory usage
-extern int  maxTextureUnits; ///< Used in Texture::bind so we wont bind in a nonexistent texture unit. Readonly
-extern bool mipmapping; ///< Used in Texture::load. Enables mipmapping increases video memory usage
-extern int  maxAnisotropy; ///< Max texture anisotropy. Used in Texture::load
-
-// misc
-extern void takeScreenshot( const char* filename ); ///< Save the colorbuffer as 24bit uncompressed TGA image
-extern void init(); ///< Inits the renderer subsystem. Setting OpenGL and executes "R::*::init" functions among other things
-extern void prepareNextFrame(); ///< Runs before rendering
-extern const uchar* getLastError(); ///< getLastError
-extern void printLastError(); ///< prints last OpenGL error
-inline const string& getStdShaderPreprocDefines() { extern string std_shader_preproc_defines; return std_shader_preproc_defines; }
-extern void render( const Camera& cam ); ///< The spine function of the renderer
-
-extern float quadVertCoords [][2];
-extern void DrawQuad( int vertCoords_uni_loc );
-
-// matrices
-//extern
-
-// ogl and glu wrappers
-inline void   multMatrix( const Mat4& m4 ) { glMultMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
-inline void   multMatrix( const Transform& trf ) { glMultMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
-inline void   loadMatrix( const Mat4& m4 ) { glLoadMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
-inline void   loadMatrix( const Transform& trf ) { glLoadMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
-
-inline void   color3( const Vec3& v ) { glColor3fv( &((Vec3&)v)[0] ); } ///< OpenGL wrapper
-inline void   color4( const Vec4& v ) { glColor4fv( &((Vec4&)v)[0] ); } ///< OpenGL wrapper
-inline void   noShaders() { ShaderProg::unbind(); } ///< unbind shaders
-extern bool   unproject( float winX, float winY, float winZ, const Mat4& modelview_mat, const Mat4& projection_mat, const int* view, float& objX, float& objY, float& objZ ); ///< My version of gluUnproject
-extern Mat4   ortho( float left, float right, float bottom, float top, float near, float far );
-
-// Matrix stuff
-extern void setProjectionMatrix( const Camera& cam );
-extern void setViewMatrix( const Camera& cam );
-inline void setProjectionViewMatrices( const Camera& cam ) { setProjectionMatrix(cam); setViewMatrix(cam); }
-inline void setViewport( uint x, uint y, uint w, uint h ) { glViewport(x,y,w,h); }
-
-// externals that have global scope in other namespaces
-
-/// material stage namespace
-namespace Ms
-{
-	extern Texture normalFai, diffuseFai, specularFai, depthFai;
-
-	extern void init();
-	extern void runStage( const Camera& cam );
-
-#if defined( _EARLY_Z_ )
-	/// EarlyZ depth pass namespace
-	namespace earlyz
-	{
-		extern void init(); ///< Inits the the earlyz FBO with R::Ms::depthFai
-		extern void runPass( const Camera& cam ); ///< Renders the Scene's depth in the R::ms:depthFai
-	}
-#endif
-}
 
 
-/// illumination stage namespace
-namespace Is
+/**
+ * Offscreen renderer
+ *
+ * It is a class and not a namespace because we may need external renderers for security cameras for example
+ */
+class Renderer
 {
 {
-	extern Texture fai;
-
-	extern void init();
-	extern void runStage( const Camera& cam );
-
-	/// illumination stage shadows namesapce
-	namespace Shad
-	{
-		extern void init();
-		extern void runPass( const Camera& cam );
-		extern Texture shadowMap;
-		extern int shadowResolution;
-		extern bool pcf; ///< PCF on/off
-		extern bool bilinear; ///< Shadowmap bilinear filtering on/off
-	}
-}
-
-/// blending stage namespace
-namespace Bs
-{
-	extern Texture faiBsScene;
-
-	extern void init2();
-	extern void runStage2( const Camera& cam );
-	extern void init();
-	extern void runStage( const Camera& cam );
-}
+	//===================================================================================================================================
+	// The rendering stages                                                                                                             =
+	//===================================================================================================================================
+	public:
+		/**
+		 * Rendering stage
+		 */
+		class RenderingStage
+		{
+			protected:
+				Renderer& r; ///< Just so that the stage can know the father class
+
+			public:
+				RenderingStage( Renderer& r_ ): r(r_) {}
+		};
+
+		/**
+		 * Material stage
+		 */
+		class Ms: private RenderingStage
+		{
+			friend class Renderer;
+
+			private:
+				Fbo fbo;
+
+				void init();
+				void run();
+
+			public:
+				Texture normalFai;
+				Texture diffuseFai;
+				Texture specularFai;
+				Texture depthFai;
+
+				Ms( Renderer& r_ ): RenderingStage( r_ ) {}
+		}; // end Ms
+
+		/**
+		 * Illumination stage
+		 */
+		class Is: private RenderingStage
+		{
+			friend class Renderer;
+
+			public:
+				/**
+				 * Shadowmapping pass
+				 */
+				class Sm: private RenderingStage
+				{
+					friend class Is;
+					friend class Renderer;
+
+					PROPERTY_R( bool, enabled, isEnabled ) ///< @ref PROPERTY_R : If false thene there is no shadowmapping at all
+					PROPERTY_R( bool, pcfEnabled, isPcfEnabled ) ///< @ref PROPERTY_R : Enable Percentage Closer Filtering
+					PROPERTY_R( bool, bilinearEnabled, isBilinearEnabled ) ///< @ref PROPERTY_R : Enable bilinear filtering in shadowMap. Better quality
+					PROPERTY_R( int, resolution, getResolution ) ///< Shadowmap resolution. The higher the more quality the shadows are
+
+					private:
+						Fbo fbo; ///< Illumination stage shadowmapping FBO
+						Texture shadowMap;
+
+						void init();
+
+						/**
+						 * Render the scene only with depth and store the result in the shadowMap
+						 * @param cam The light camera
+						 */
+						void run( const Camera& cam );
+
+					public:
+						Sm( Renderer& r_ ): RenderingStage( r_ ) {}
+				}; // end Sm
+
+			private:
+				/// Illumination stage ambient pass shader program
+				class AmbientShaderProg: public ShaderProg
+				{
+					public:
+						struct
+						{
+							const ShaderProg::UniVar* ambientCol;
+							const ShaderProg::UniVar* sceneColMap;
+						} uniVars;
+				};
+
+				/// Illumination stage light pass shader program
+				class LightShaderProg: public ShaderProg
+				{
+					public:
+						struct
+						{
+							const ShaderProg::UniVar* msNormalFai;
+							const ShaderProg::UniVar* msDiffuseFai;
+							const ShaderProg::UniVar* msSpecularFai;
+							const ShaderProg::UniVar* msDepthFai;
+							const ShaderProg::UniVar* planes;
+							const ShaderProg::UniVar* lightPos;
+							const ShaderProg::UniVar* lightInvRadius;
+							const ShaderProg::UniVar* lightDiffuseCol;
+							const ShaderProg::UniVar* lightSpecularCol;
+							const ShaderProg::UniVar* lightTex;
+							const ShaderProg::UniVar* texProjectionMat;
+							const ShaderProg::UniVar* shadowMap;
+						} uniVars;
+				};
+
+				Fbo fbo; ///< This FBO writes to the Is::fai
+				uint stencilRb; ///< Illumination stage stencil buffer
+				AmbientShaderProg ambientPassSProg; ///< Illumination stage ambient pass shader program
+				LightShaderProg pointLightSProg; ///< Illumination stage point light shader program
+				LightShaderProg spotLightNoShadowSProg; ///< Illumination stage spot light w/o shadow shader program
+				LightShaderProg spotLightShadowSProg; ///< Illumination stage spot light w/ shadow shader program
+				Vec3 viewVectors[4];
+				Vec2 planes;
+				static float sMOUvSCoords []; ///< Illumination stage stencil masking optimizations UV sphere vertex coords
+				static uint  sMOUvSVboId; ///< Illumination stage stencil masking optimizations UV sphere VBO id
+
+				static void initSMOUvS(); ///< Init the illumination stage stencil masking optimizations uv sphere (eg create the @ref sMOUvSVboId VBO)
+				void renderSMOUvS( const PointLight& light ); ///< Render the illumination stage stencil masking optimizations uv sphere
+				void calcViewVector(); ///< Calc the view vector that we will use inside the shader to calculate the frag pos in view space
+				void calcPlanes(); ///< Calc the planes that we will use inside the shader to calculate the frag pos in view space
+				void setStencilMask( const PointLight& light );
+				void setStencilMask( const SpotLight& light );
+				void ambientPass( const Vec3& color );
+				void pointLightPass( const PointLight& light );
+				void spotLightPass( const SpotLight& light );
+				void initFbo();
+				void init();
+				void run();
+
+			public:
+				Texture fai;
+				Sm sm;
+
+				Is( Renderer& r_ ): RenderingStage( r_ ), sm(r) {}
+		}; // end Is
+
+		/**
+		 * Post-processing stage
+		 *
+		 * This stage is divided into 2 two parts. The first happens before blending stage and the second after.
+		 */
+		class Pps: private RenderingStage
+		{
+			friend class Renderer;
+
+			PROPERTY_R( bool, enabled, isEnabled )
+			PROPERTY_R( float, renderingQuality, getRenderingQuality )
+
+			public:
+				/**
+				 * High dynamic range lighting pass
+				 */
+				class Hdr: private RenderingStage
+				{
+					friend class Pps;
+					friend class Renderer;
+
+					PROPERTY_R( bool, enabled, isEnabled )
+					PROPERTY_R( float, renderingQuality, getRenderingQuality )
+
+					private:
+						Fbo pass0Fbo, pass1Fbo, pass2Fbo;
+						class HdrShaderProg: public ShaderProg
+						{
+							public:
+								struct
+								{
+									const ShaderProg::UniVar* fai;
+								} uniVars;
+						};
+						HdrShaderProg pass0SProg, pass1SProg, pass2SProg;
+
+						void initFbos( Fbo& fbo, Texture& fai, int internalFormat );
+						void init();
+						void run();
+
+					public:
+						Texture pass0Fai; ///< Vertical blur pass FAI
+						Texture pass1Fai; ///< pass0Fai with the horizontal blur FAI
+						Texture fai; ///< The final FAI
+
+						Hdr( Renderer& r_ ): RenderingStage(r_) {}
+				}; // end Hrd
+
+				/**
+				 * Screen space ambient occlusion pass
+				 *
+				 * Three passes:
+				 * - Calc ssao factor
+				 * - Blur vertically
+				 * - Blur horizontally
+				 */
+				class Ssao: private RenderingStage
+				{
+					friend class Pps;
+					friend class Renderer;
+
+					PROPERTY_R( bool, enabled, isEnabled )
+					PROPERTY_R( float, renderingQuality, getRenderingQuality )
+					PROPERTY_R( float, bluringQuality, getBluringQuality )
+
+					private:
+						Fbo pass0Fbo, pass1Fbo, pass2Fbo;
+						uint width, height, bwidth, bheight;
+						Texture* noiseMap;
+
+						class SsaoShaderProg: public ShaderProg
+						{
+							public:
+								struct
+								{
+									const ShaderProg::UniVar* camerarange;
+									const ShaderProg::UniVar* msDepthFai;
+									const ShaderProg::UniVar* noiseMap;
+									const ShaderProg::UniVar* msNormalFai;
+								} uniVars;
+						};
+						SsaoShaderProg ssaoSProg;
+
+						class BlurSProg: public ShaderProg
+						{
+							public:
+								struct
+								{
+									const ShaderProg::UniVar* fai;
+								} uniVars;
+						};
+						BlurSProg blurSProg, blurSProg2;
+
+						void initBlurFbo( Fbo& fbo, Texture& fai );
+						void init();
+						void run();
+
+					public:
+						Texture pass0Fai, pass1Fai, fai /** The final FAI */;
+
+						Ssao( Renderer& r_ ): RenderingStage(r_) {}
+				}; // end Ssao
+
+				private:
+					class PpsShaderProg: public ShaderProg
+					{
+						public:
+							struct
+							{
+								const ShaderProg::UniVar* isFai;
+								const ShaderProg::UniVar* ppsSsaoFai;
+								const ShaderProg::UniVar* msNormalFai;
+								const ShaderProg::UniVar* hdrFai;
+								const ShaderProg::UniVar* lscattFai;
+
+							} uniVars;
+					};
+					PpsShaderProg sProg;
+					Fbo fbo;
+
+					void init();
+					void run();
+
+				public:
+					Texture fai;
+					Hdr hdr;
+					Ssao ssao;
+
+					Pps( Renderer& r_ ): RenderingStage(r_), hdr(r_), ssao(r_) {}
+		}; // end Pps
+
+		/**
+		 * Debugging stage
+		 */
+		class Dbg: public RenderingStage
+		{
+			friend class Renderer;
+
+			PROPERTY_R( bool, enabled, isEnabled )
+			PROPERTY_RW( bool, showAxisEnabled, setShowAxis, isShowAxisEnabled )
+			PROPERTY_RW( bool, showLightsEnabled, setShowLights, isShowLightsEnabled )
+			PROPERTY_RW( bool, showSkeletonsEnabled, setShowSkeletons, isShowSkeletonsEnabled )
+			PROPERTY_RW( bool, showCamerasEnabled, setShowCameras, isShowCamerasEnabled )
+
+			private:
+				Fbo fbo;
+				ShaderProg sProg; /// @todo move Dbg to GL 3
+
+				void init();
+				void run();
+
+			public:
+				Dbg( Renderer& r_ );
+				void renderGrid();
+				void renderSphere( float radius, int complexity );
+				void renderCube( bool cols = false, float size = 1.0 );
+		}; // end Dbg
+
+
+	//===================================================================================================================================
+	//                                                                                                                                  =
+	//===================================================================================================================================
+	PROPERTY_R( uint, width, getWidth ) ///< Width of the rendering. Dont confuse with the window width
+	PROPERTY_R( uint, height, getHeight ) ///< Height of the rendering. Dont confuse with the window width
+	PROPERTY_R( uint, framesNum, getFramesNum )
+	PROPERTY_R( float, aspectRatio, getAspectRatio )
+
+	protected:
+		// the rest
+		Camera* cam; ///< Current camera
+		static float quadVertCoords [][2];
+
+		static void drawQuad( int vertCoordsUniLoc );
+
+	public:
+		// the stages as data members
+		Ms ms; ///< Material rendering stage
+		Is is; ///< Illumination rendering stage
+		Pps pps; ///< Postprocessing rendering stage
+		Dbg dbg; ///< Debugging rendering stage
+
+		// texture stuff
+		static bool textureCompression; ///< Used in Texture::load to enable texture compression. Decreases video memory usage
+		static int  maxTextureUnits; ///< Used in Texture::bind so we wont bind in a nonexistent texture unit. Readonly
+		static bool mipmapping; ///< Used in Texture::load. Enables mipmapping increases video memory usage
+		static int  maxAnisotropy; ///< Max texture anisotropy. Used in Texture::load
+		// matrices & viewing
+		Mat4 modelViewMat; ///< This changes once for every mesh rendering
+		Mat4 projectionMat; ///< This changes once every frame
+		Mat4 modelViewProjectionMat; ///< This changes just like @ref modelViewMat
+		Mat3 normalMat; ///< The rotation part of modelViewMat
+
+		Renderer();
+
+		/**
+		 * Init the renderer given an initialization class
+		 * @param initializer The initializer class
+		 */
+		void init( const RendererInitializer& initializer );
+
+		/**
+		 * This function does all the rendering stages and produces a final FAI
+		 * @param cam The camera from where the rendering will be done
+		 */
+		void render( Camera& cam );
+
+		/**
+		 * My version of gluUnproject
+		 * @param windowCoords Window screen coords
+		 * @param modelViewMat The modelview matrix
+		 * @param projectionMat The projection matrix
+		 * @param view The view vector
+		 * @return The unprojected coords coords
+		 */
+		static Vec3 unproject( const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat, const int view[4] );
+
+		/**
+		 * It returns an orthographic projection matrix
+		 * @param left left vertical clipping plane
+		 * @param right right vertical clipping plane
+		 * @param bottom bottom horizontal clipping plane
+		 * @param top top horizontal clipping plane
+		 * @param near nearer distance of depth clipping plane
+		 * @param far farther distance of depth clipping plane
+		 * @return A 4x4 projection matrix
+		 */
+		static Mat4 ortho( float left, float right, float bottom, float top, float near, float far );
+
+		/**
+		 * Get last OpenGL error string
+		 * @return An error string or NULL if not error
+		 */
+		static const uchar* getLastError();
+
+		/**
+		 * Print last OpenGL error or nothing if there is no error
+		 */
+		static void printLastError();
+
+		// to be removed
+		static void color3( const Vec3& v ) { glColor3fv( &((Vec3&)v)[0] ); } ///< OpenGL wrapper
+		static void color4( const Vec4& v ) { glColor4fv( &((Vec4&)v)[0] ); } ///< OpenGL wrapper
+		static void setProjectionMatrix( const Camera& cam );
+		static void setViewMatrix( const Camera& cam );
+		static void noShaders() { ShaderProg::unbind(); } ///< unbind shaders @todo remove this. From now on there will be only shaders
+		static void setProjectionViewMatrices( const Camera& cam ) { setProjectionMatrix(cam); setViewMatrix(cam); }
+		static void setViewport( uint x, uint y, uint w, uint h ) { glViewport(x,y,w,h); }
+		static void multMatrix( const Mat4& m4 ) { glMultMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
+		static void multMatrix( const Transform& trf ) { glMultMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
+		static void loadMatrix( const Mat4& m4 ) { glLoadMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
+		static void loadMatrix( const Transform& trf ) { glLoadMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
+};
 
 
-/// pre-processing stage namespace
-namespace Pps
-{
-	extern void init();
-	extern void runStage( const Camera& cam );
-
-	namespace Ssao
-	{
-		extern bool enabled;
-		extern void init();
-		extern void runPass( const Camera& cam );
-		extern Texture pass0Fai;
-		extern Texture pass1Fai;
-		extern Texture fai;
-		extern float renderingQuality;
-	}
-
-	namespace edgeaa
-	{
-		extern bool enabled;
-	}
-
-	namespace Hdr
-	{
-		extern bool    enabled;
-		extern void    init();
-		extern void    runPass( const Camera& cam );
-		extern Texture pass0Fai;
-		extern Texture pass1Fai;
-		extern Texture fai;
-		extern float   renderingQuality;
-	}
-
-	namespace Lscatt
-	{
-		extern bool enabled;
-		extern void init();
-		extern void runPass( const Camera& cam );
-		extern Texture fai;
-		extern float renderingQuality;
-	}
-
-	extern Texture fai;
-}
-
-/// debug stage namespace
-namespace Dbg
-{
-	extern bool showAxis;
-	extern bool showFnormals;
-	extern bool showVnormals;
-	extern bool showLights;
-	extern bool showSkeletons;
-	extern bool showCameras;
-	extern bool showBvolumes;
-
-	extern void init();
-	extern void runStage( const Camera& cam );
-
-	extern void renderGrid();
-	extern void renderSphere( float radius, int precision );
-	extern void renderCube( bool cols = false, float size = 1.0f );
-	extern void renderQuad( float w, float h );
-}
-
-} // end namespace
 #endif
 #endif

+ 12 - 2
src/Renderer2/RendererInitializer.h → src/Renderer/RendererInitializer.h

@@ -1,7 +1,7 @@
 #ifndef _RENDERERINITIALIZER_H_
 #ifndef _RENDERERINITIALIZER_H_
 #define _RENDERERINITIALIZER_H_
 #define _RENDERERINITIALIZER_H_
 
 
-#include <Common.h>
+#include "Common.h"
 
 
 /**
 /**
  * A struct to initialize the renderer. It contains a few extra params for the MainRenderer
  * A struct to initialize the renderer. It contains a few extra params for the MainRenderer
@@ -47,7 +47,17 @@ struct RendererInitializer
 	} dbg;
 	} dbg;
 
 
 	// the globals
 	// the globals
-	int width, height;
+	int width; ///< Ignored by MainRenderer
+	int height; ///< Ignored by MainRenderer
+	float mainRendererQuality; ///< Only for MainRenderer
+
+	// funcs
+	RendererInitializer() {}
+
+	RendererInitializer( const RendererInitializer& initializer )
+	{
+		memcpy( this, &initializer, sizeof(RendererInitializer) );
+	}
 };
 };
 
 
 #endif
 #endif

+ 1 - 1
src/Renderer2/Sm.cpp → src/Renderer/Sm.cpp

@@ -1,4 +1,4 @@
-#include "Renderer.hpp"
+#include "Renderer.h"
 #include "App.h"
 #include "App.h"
 #include "Scene.h"
 #include "Scene.h"
 #include "MeshNode.h"
 #include "MeshNode.h"

+ 1 - 1
src/Renderer2/Ssao.cpp → src/Renderer/Ssao.cpp

@@ -1,4 +1,4 @@
-#include "Renderer.hpp"
+#include "Renderer.h"
 #include "Camera.h"
 #include "Camera.h"
 
 
 
 

+ 0 - 88
src/Renderer2/Dbg.cpp

@@ -1,88 +0,0 @@
-#include "Renderer.hpp"
-#include "App.h"
-#include "Scene.h"
-#include "SkelNode.h"
-
-
-//=====================================================================================================================================
-// Constructor                                                                                                                        =
-//=====================================================================================================================================
-Renderer::Dbg::Dbg( Renderer& r_ ):
-	RenderingStage( r_ ),
-	showAxisEnabled( false ),
-	showLightsEnabled( false ),
-	showSkeletonsEnabled( false ),
-	showCamerasEnabled( false )
-{
-}
-
-
-//=====================================================================================================================================
-// init                                                                                                                               =
-//=====================================================================================================================================
-void Renderer::Dbg::init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
-
-	// attach the textures
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r.pps.fai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create debug FBO" );
-
-	// unbind
-	fbo.unbind();
-
-	// shader
-	sProg.customLoad( "shaders/Dbg.glsl" );
-}
-
-
-//=====================================================================================================================================
-// runStage                                                                                                                           =
-//=====================================================================================================================================
-void Renderer::Dbg::run()
-{
-	if( !enabled ) return;
-
-	const Camera& cam = *r.cam;
-
-	fbo.bind();
-	sProg.bind();
-
-	// OGL stuff
-	r.setProjectionViewMatrices( cam );
-	r.setViewport( 0, 0, r.width, r.height );
-
-	glEnable( GL_DEPTH_TEST );
-	glDisable( GL_BLEND );
-
-	//R::renderGrid();
-	for( uint i=0; i<app->getScene()->nodes.size(); i++ )
-	{
-		if
-		(
-			(app->getScene()->nodes[i]->type == SceneNode::NT_LIGHT && showLightsEnabled) ||
-			(app->getScene()->nodes[i]->type == SceneNode::NT_CAMERA && showCamerasEnabled) ||
-			app->getScene()->nodes[i]->type == SceneNode::NT_PARTICLE_EMITTER
-		)
-		{
-			app->getScene()->nodes[i]->render();
-		}
-		else if( app->getScene()->nodes[i]->type == SceneNode::NT_SKELETON && showSkeletonsEnabled )
-		{
-			SkelNode* skel_node = static_cast<SkelNode*>( app->getScene()->nodes[i] );
-			glDisable( GL_DEPTH_TEST );
-			skel_node->render();
-			glEnable( GL_DEPTH_TEST );
-		}
-	}
-}
-

File diff suppressed because it is too large
+ 0 - 11
src/Renderer2/Is.cpp


+ 0 - 100
src/Renderer2/Ms.cpp

@@ -1,100 +0,0 @@
-#include "Renderer.hpp"
-#include "App.h"
-#include "Scene.h"
-#include "Camera.h"
-#include "MeshNode.h"
-
-
-//=====================================================================================================================================
-// init                                                                                                                               =
-//=====================================================================================================================================
-void Renderer::Ms::init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(3);
-
-	// create the FAIs
-	const int internal_format = GL_RGBA16F_ARB;
-	if( !normalFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
-	    !diffuseFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
-	    !specularFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
-	    !depthFai.createEmpty2D( r.width, r.height, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT ) )
-	{
-		FATAL( "Failed to create one MS FAI. See prev error" );
-	}
-
-
-	// attach the buffers to the FBO
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, normalFai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, diffuseFai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, specularFai.getGlId(), 0 );
-
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create deferred shading material stage FBO" );
-
-	// unbind
-	fbo.unbind();
-
-#if defined( _EARLY_Z_ )
-	r.Ms::earlyz::init();
-#endif
-}
-
-
-//=====================================================================================================================================
-// runStage                                                                                                                           =
-//=====================================================================================================================================
-void Renderer::Ms::run()
-{
-	Camera& cam = *r.cam;
-
-	#if defined( _EARLY_Z_ )
-		// run the early z pass
-		r.Ms::earlyz::runPass( cam );
-	#endif
-
-	fbo.bind();
-
-	#if !defined( _EARLY_Z_ )
-		glClear( GL_DEPTH_BUFFER_BIT );
-	#endif
-	r.setProjectionViewMatrices( cam );
-	r.setViewport( 0, 0, r.width, r.height );
-
-	//glEnable( GL_DEPTH_TEST );
-	app->getScene()->skybox.Render( cam.getViewMatrix().getRotationPart() );
-	//glDepthFunc( GL_LEQUAL );
-
-	#if defined( _EARLY_Z_ )
-		glDepthMask( false );
-		glDepthFunc( GL_EQUAL );
-	#endif
-
-	// render the meshes
-	for( uint i=0; i<app->getScene()->meshNodes.size(); i++ )
-	{
-		MeshNode* meshNode = app->getScene()->meshNodes[i];
-		DEBUG_ERR( meshNode->material == NULL );
-		if( meshNode->material->blends || meshNode->material->refracts ) continue;
-		meshNode->material->setup();
-		meshNode->render();
-	}
-
-	glPolygonMode( GL_FRONT, GL_FILL ); // the rendering above fucks the polygon mode
-
-
-	#if defined( _EARLY_Z_ )
-		glDepthMask( true );
-		glDepthFunc( GL_LESS );
-	#endif
-
-	fbo.unbind();
-}

+ 0 - 95
src/Renderer2/Pps.cpp

@@ -1,95 +0,0 @@
-#include "Renderer.hpp"
-
-
-//=====================================================================================================================================
-// init                                                                                                                               =
-//=====================================================================================================================================
-void Renderer::Pps::init()
-{
-	// create FBO
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements( 1 );
-
-	// create the texes
-	fai.createEmpty2D( r.width, r.height, GL_RGB, GL_RGB );
-
-	// attach
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
-
-	// test if success
-	if( !fbo.isGood() )
-		FATAL( "Cannot create post-processing stage FBO" );
-
-	fbo.unbind();
-
-
-	// init the shader and it's vars
-	sProg.customLoad( "shaders/Pps.glsl" );
-	sProg.bind();
-
-	sProg.uniVars.isFai = sProg.findUniVar( "isFai" );
-
-	if( ssao.enabled )
-	{
-		ssao.init();
-		sProg.uniVars.ppsSsaoFai = sProg.findUniVar( "ppsSsaoFai" );
-	}
-
-	if( hdr.enabled )
-	{
-		hdr.init();
-		sProg.uniVars.hdrFai = sProg.findUniVar( "ppsHdrFai" );
-	}
-
-	/// @ todo enable lscatt
-	/*if( R::Pps::Lscatt::enabled )
-	{
-		R::Pps::Lscatt::init();
-		sProg.uniVars.lscattFai = sProg.findUniVar( "ppsLscattFai" )->getLoc();
-	}*/
-
-}
-
-
-//=====================================================================================================================================
-// run                                                                                                                                =
-//=====================================================================================================================================
-void Renderer::Pps::run()
-{
-	if( ssao.enabled )
-		ssao.run();
-
-	if( hdr.enabled )
-		hdr.run();
-
-	fbo.bind();
-
-	// set GL
-	glDisable( GL_DEPTH_TEST );
-	glDisable( GL_BLEND );
-
-	Renderer::setViewport( 0, 0, r.width, r.height );
-
-	// set shader
-	sProg.bind();
-	sProg.uniVars.isFai->setTexture( r.is.fai, 0 );
-
-	if( hdr.enabled )
-	{
-		sProg.uniVars.hdrFai->setTexture( hdr.fai, 1 );
-	}
-
-	if( ssao.enabled )
-	{
-		sProg.uniVars.ppsSsaoFai->setTexture( ssao.fai, 2 );
-	}
-
-	// draw quad
-	Renderer::drawQuad( 0 );
-
-	// unbind FBO
-	fbo.unbind();
-}

+ 0 - 179
src/Renderer2/Renderer.cpp

@@ -1,179 +0,0 @@
-#include "Renderer.hpp"
-#include "Camera.h" /// @todo remove this
-#include "RendererInitializer.h"
-
-
-//=====================================================================================================================================
-// Vars                                                                                                                               =
-//=====================================================================================================================================
-bool Renderer::textureCompression = false;
-int  Renderer::maxTextureUnits = -1;
-bool Renderer::mipmapping = true;
-int  Renderer::maxAnisotropy = 8;
-float Renderer::quadVertCoords [][2] = { {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0} };
-
-
-//=====================================================================================================================================
-// Constructor                                                                                                                        =
-//=====================================================================================================================================
-Renderer::Renderer():
-	width( 640 ),
-	height( 480 ),
-	ms( *this ),
-	is( *this ),
-	pps( *this ),
-	dbg( *this )
-{
-}
-
-//=====================================================================================================================================
-// init                                                                                                                               =
-//=====================================================================================================================================
-void Renderer::init( const RendererInitializer& initializer )
-{
-	// set from the initializer
-	is.sm.enabled = initializer.is.sm.enabled;
-	is.sm.pcfEnabled = initializer.is.sm.pcfEnabled;
-	is.sm.bilinearEnabled = initializer.is.sm.bilinearEnabled;
-	is.sm.resolution = initializer.is.sm.resolution;
-	pps.hdr.enabled = initializer.pps.hdr.enabled;
-	pps.hdr.renderingQuality = initializer.pps.hdr.renderingQuality;
-	pps.ssao.enabled = initializer.pps.ssao.enabled;
-	pps.ssao.renderingQuality = initializer.pps.ssao.renderingQuality;
-	pps.ssao.bluringQuality = initializer.pps.ssao.bluringQuality;
-	dbg.enabled = initializer.dbg.enabled;
-	width = initializer.width;
-	height = initializer.height;
-
-	aspectRatio = float(width)/height;
-
-	// init the stages. Careful with the order!!!!!!!!!!
-	ms.init();
-	is.init();
-	pps.init();
-	dbg.init();
-}
-
-
-//=====================================================================================================================================
-// render                                                                                                                             =
-//=====================================================================================================================================
-void Renderer::render( Camera& cam_ )
-{
-	cam = &cam_;
-
-	ms.run();
-	is.run();
-	pps.run();
-	dbg.run();
-
-	++framesNum;
-}
-
-
-//=====================================================================================================================================
-// drawQuad                                                                                                                           =
-//=====================================================================================================================================
-void Renderer::drawQuad( int vertCoordsUniLoc )
-{
-	DEBUG_ERR( vertCoordsUniLoc == -1 );
-	glVertexAttribPointer( vertCoordsUniLoc, 2, GL_FLOAT, false, 0, quadVertCoords );
-	glEnableVertexAttribArray( vertCoordsUniLoc );
-	glDrawArrays( GL_QUADS, 0, 4 );
-	glDisableVertexAttribArray( vertCoordsUniLoc );
-}
-
-//=====================================================================================================================================
-// setProjectionMatrix                                                                                                                =
-//=====================================================================================================================================
-void Renderer::setProjectionMatrix( const Camera& cam )
-{
-	glMatrixMode( GL_PROJECTION );
-	loadMatrix( cam.getProjectionMatrix() );
-}
-
-
-//=====================================================================================================================================
-// setViewMatrix                                                                                                                      =
-//=====================================================================================================================================
-void Renderer::setViewMatrix( const Camera& cam )
-{
-	glMatrixMode( GL_MODELVIEW );
-	loadMatrix( cam.getViewMatrix() );
-}
-
-
-//=====================================================================================================================================
-// unproject                                                                                                                          =
-//=====================================================================================================================================
-Vec3 Renderer::unproject( const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat, const int view[4] )
-{
-	Mat4 invPm = projectionMat * modelViewMat;
-	invPm.invert();
-
-	// the vec is in ndc space meaning: -1<=vec.x<=1 -1<=vec.y<=1 -1<=vec.z<=1
-	Vec4 vec;
-	vec.x = (2.0*(windowCoords.x-view[0]))/view[2] - 1.0;
-	vec.y = (2.0*(windowCoords.y-view[1]))/view[3] - 1.0;
-	vec.z = 2.0*windowCoords.z - 1.0;
-	vec.w = 1.0;
-
-	Vec4 final = invPm * vec;
-	final /= final.w;
-	return Vec3( final );
-}
-
-
-//=====================================================================================================================================
-// ortho                                                                                                                              =
-//=====================================================================================================================================
-Mat4 Renderer::ortho( float left, float right, float bottom, float top, float near, float far )
-{
-	float difx = right-left;
-	float dify = top-bottom;
-	float difz = far-near;
-	float tx = -(right+left) / difx;
-	float ty = -(top+bottom) / dify;
-	float tz = -(far+near) / difz;
-	Mat4 m;
-
-	m(0,0) = 2.0 / difx;
-	m(0,1) = 0.0;
-	m(0,2) = 0.0;
-	m(0,3) = tx;
-	m(1,0) = 0.0;
-	m(1,1) = 2.0 / dify;
-	m(1,2) = 0.0;
-	m(1,3) = ty;
-	m(2,0) = 0.0;
-	m(2,1) = 0.0;
-	m(2,2) = -2.0 / difz;
-	m(2,3) = tz;
-	m(3,0) = 0.0;
-	m(3,1) = 0.0;
-	m(3,2) = 0.0;
-	m(3,3) = 1.0;
-
-	return m;
-}
-
-
-//=====================================================================================================================================
-// getLastError                                                                                                                       =
-//=====================================================================================================================================
-const uchar* Renderer::getLastError()
-{
-	return gluErrorString( glGetError() );
-}
-
-
-//=====================================================================================================================================
-// printLastError                                                                                                                     =
-//=====================================================================================================================================
-void Renderer::printLastError()
-{
-	GLenum errid = glGetError();
-	if( errid != GL_NO_ERROR )
-		ERROR( "OpenGL Error: " << gluErrorString( errid ) );
-}
-

+ 0 - 412
src/Renderer2/Renderer.hpp

@@ -1,412 +0,0 @@
-#ifndef _RENDERER_HPP_
-#define _RENDERER_HPP_
-
-#include "Common.h"
-#include "Math.h"
-#include "Fbo.h"
-#include "Texture.h"
-#include "ShaderProg.h"
-
-class Camera;
-class PointLight;
-class SpotLight;
-class RendererInitializer;
-
-
-/**
- * Offscreen renderer
- *
- * It is a class and not a namespace because we may need external renderers for security cameras for example
- */
-class Renderer
-{
-	//===================================================================================================================================
-	// The rendering stages                                                                                                             =
-	//===================================================================================================================================
-	public:
-		/**
-		 * Rendering stage
-		 */
-		class RenderingStage
-		{
-			protected:
-				Renderer& r; ///< Just so that the stage can know the father class
-
-			public:
-				RenderingStage( Renderer& r_ ): r(r_) {}
-		};
-
-		/**
-		 * Material stage
-		 */
-		class Ms: private RenderingStage
-		{
-			friend class Renderer;
-
-			private:
-				Fbo fbo;
-
-				void init();
-				void run();
-
-			public:
-				Texture normalFai;
-				Texture diffuseFai;
-				Texture specularFai;
-				Texture depthFai;
-
-				Ms( Renderer& r_ ): RenderingStage( r_ ) {}
-		}; // end Ms
-
-		/**
-		 * Illumination stage
-		 */
-		class Is: private RenderingStage
-		{
-			friend class Renderer;
-
-			public:
-				/**
-				 * Shadowmapping pass
-				 */
-				class Sm: private RenderingStage
-				{
-					friend class Is;
-					friend class Renderer;
-
-					PROPERTY_R( bool, enabled, isEnabled ) ///< @ref PROPERTY_R : If false thene there is no shadowmapping at all
-					PROPERTY_R( bool, pcfEnabled, isPcfEnabled ) ///< @ref PROPERTY_R : Enable Percentage Closer Filtering
-					PROPERTY_R( bool, bilinearEnabled, isBilinearEnabled ) ///< @ref PROPERTY_R : Enable bilinear filtering in shadowMap. Better quality
-					PROPERTY_R( int, resolution, getResolution ) ///< Shadowmap resolution. The higher the more quality the shadows are
-
-					private:
-						Fbo fbo; ///< Illumination stage shadowmapping FBO
-						Texture shadowMap;
-
-						void init();
-
-						/**
-						 * Render the scene only with depth and store the result in the shadowMap
-						 * @param cam The light camera
-						 */
-						void run( const Camera& cam );
-
-					public:
-						Sm( Renderer& r_ ): RenderingStage( r_ ) {}
-				}; // end Sm
-
-			private:
-				/// Illumination stage ambient pass shader program
-				class AmbientShaderProg: public ShaderProg
-				{
-					public:
-						struct
-						{
-							const ShaderProg::UniVar* ambientCol;
-							const ShaderProg::UniVar* sceneColMap;
-						} uniVars;
-				};
-
-				/// Illumination stage light pass shader program
-				class LightShaderProg: public ShaderProg
-				{
-					public:
-						struct
-						{
-							const ShaderProg::UniVar* msNormalFai;
-							const ShaderProg::UniVar* msDiffuseFai;
-							const ShaderProg::UniVar* msSpecularFai;
-							const ShaderProg::UniVar* msDepthFai;
-							const ShaderProg::UniVar* planes;
-							const ShaderProg::UniVar* lightPos;
-							const ShaderProg::UniVar* lightInvRadius;
-							const ShaderProg::UniVar* lightDiffuseCol;
-							const ShaderProg::UniVar* lightSpecularCol;
-							const ShaderProg::UniVar* lightTex;
-							const ShaderProg::UniVar* texProjectionMat;
-							const ShaderProg::UniVar* shadowMap;
-						} uniVars;
-				};
-
-				Fbo fbo; ///< This FBO writes to the Is::fai
-				uint stencilRb; ///< Illumination stage stencil buffer
-				AmbientShaderProg ambientPassSProg; ///< Illumination stage ambient pass shader program
-				LightShaderProg pointLightSProg; ///< Illumination stage point light shader program
-				LightShaderProg spotLightNoShadowSProg; ///< Illumination stage spot light w/o shadow shader program
-				LightShaderProg spotLightShadowSProg; ///< Illumination stage spot light w/ shadow shader program
-				Vec3 viewVectors[4];
-				Vec2 planes;
-				static float sMOUvSCoords []; ///< Illumination stage stencil masking optimizations UV sphere vertex coords
-				static uint  sMOUvSVboId; ///< Illumination stage stencil masking optimizations UV sphere VBO id
-
-				static void initSMOUvS(); ///< Init the illumination stage stencil masking optimizations uv sphere (eg create the @ref sMOUvSVboId VBO)
-				void renderSMOUvS( const PointLight& light ); ///< Render the illumination stage stencil masking optimizations uv sphere
-				void calcViewVector(); ///< Calc the view vector that we will use inside the shader to calculate the frag pos in view space
-				void calcPlanes(); ///< Calc the planes that we will use inside the shader to calculate the frag pos in view space
-				void setStencilMask( const PointLight& light );
-				void setStencilMask( const SpotLight& light );
-				void ambientPass( const Vec3& color );
-				void pointLightPass( const PointLight& light );
-				void spotLightPass( const SpotLight& light );
-				void initFbo();
-				void init();
-				void run();
-
-			public:
-				Texture fai;
-				Sm sm;
-
-				Is( Renderer& r_ ): RenderingStage( r_ ), sm(r) {}
-		}; // end Is
-
-		/**
-		 * Post-processing stage
-		 *
-		 * This stage is divided into 2 two parts. The first happens before blending stage and the second after.
-		 */
-		class Pps: private RenderingStage
-		{
-			friend class Renderer;
-
-			PROPERTY_R( bool, enabled, isEnabled )
-			PROPERTY_R( float, renderingQuality, getRenderingQuality )
-
-			public:
-				/**
-				 * High dynamic range lighting pass
-				 */
-				class Hdr: private RenderingStage
-				{
-					friend class Pps;
-					friend class Renderer;
-
-					PROPERTY_R( bool, enabled, isEnabled )
-					PROPERTY_R( float, renderingQuality, getRenderingQuality )
-
-					private:
-						Fbo pass0Fbo, pass1Fbo, pass2Fbo;
-						class HdrShaderProg: public ShaderProg
-						{
-							public:
-								struct
-								{
-									const ShaderProg::UniVar* fai;
-								} uniVars;
-						};
-						HdrShaderProg pass0SProg, pass1SProg, pass2SProg;
-
-						void initFbos( Fbo& fbo, Texture& fai, int internalFormat );
-						void init();
-						void run();
-
-					public:
-						Texture pass0Fai; ///< Vertical blur pass FAI
-						Texture pass1Fai; ///< pass0Fai with the horizontal blur FAI
-						Texture fai; ///< The final FAI
-
-						Hdr( Renderer& r_ ): RenderingStage(r_) {}
-				}; // end Hrd
-
-				/**
-				 * Screen space ambient occlusion pass
-				 *
-				 * Three passes:
-				 * - Calc ssao factor
-				 * - Blur vertically
-				 * - Blur horizontally
-				 */
-				class Ssao: private RenderingStage
-				{
-					friend class Pps;
-					friend class Renderer;
-
-					PROPERTY_R( bool, enabled, isEnabled )
-					PROPERTY_R( float, renderingQuality, getRenderingQuality )
-					PROPERTY_R( float, bluringQuality, getBluringQuality )
-
-					private:
-						Fbo pass0Fbo, pass1Fbo, pass2Fbo;
-						uint width, height, bwidth, bheight;
-						Texture* noiseMap;
-
-						class SsaoShaderProg: public ShaderProg
-						{
-							public:
-								struct
-								{
-									const ShaderProg::UniVar* camerarange;
-									const ShaderProg::UniVar* msDepthFai;
-									const ShaderProg::UniVar* noiseMap;
-									const ShaderProg::UniVar* msNormalFai;
-								} uniVars;
-						};
-						SsaoShaderProg ssaoSProg;
-
-						class BlurSProg: public ShaderProg
-						{
-							public:
-								struct
-								{
-									const ShaderProg::UniVar* fai;
-								} uniVars;
-						};
-						BlurSProg blurSProg, blurSProg2;
-
-						void initBlurFbo( Fbo& fbo, Texture& fai );
-						void init();
-						void run();
-
-					public:
-						Texture pass0Fai, pass1Fai, fai /** The final FAI */;
-
-						Ssao( Renderer& r_ ): RenderingStage(r_) {}
-				}; // end Ssao
-
-				private:
-					class PpsShaderProg: public ShaderProg
-					{
-						public:
-							struct
-							{
-								const ShaderProg::UniVar* isFai;
-								const ShaderProg::UniVar* ppsSsaoFai;
-								const ShaderProg::UniVar* msNormalFai;
-								const ShaderProg::UniVar* hdrFai;
-								const ShaderProg::UniVar* lscattFai;
-
-							} uniVars;
-					};
-					PpsShaderProg sProg;
-					Fbo fbo;
-
-					void init();
-					void run();
-
-				public:
-					Texture fai;
-					Hdr hdr;
-					Ssao ssao;
-
-					Pps( Renderer& r_ ): RenderingStage(r_), hdr(r_), ssao(r_) {}
-		}; // end Pps
-
-		/**
-		 * Debugging stage
-		 */
-		class Dbg: public RenderingStage
-		{
-			friend class Renderer;
-
-			PROPERTY_R( bool, enabled, isEnabled )
-			PROPERTY_RW( bool, showAxisEnabled, setShowAxis, isShowAxisEnabled )
-			PROPERTY_RW( bool, showLightsEnabled, setShowLights, isShowLightsEnabled )
-			PROPERTY_RW( bool, showSkeletonsEnabled, setShowSkeletons, isShowSkeletonsEnabled )
-			PROPERTY_RW( bool, showCamerasEnabled, setShowCameras, isShowCamerasEnabled )
-
-			private:
-				Fbo fbo;
-				ShaderProg sProg; /// @todo move Dbg to GL 3
-
-				void init();
-				void run();
-
-			public:
-				Dbg( Renderer& r_ );
-				static void renderGrid();
-				static void renderSphere( float radius, int complexity );
-				static void renderCube( bool cols, float size );
-		}; // end Dbg
-
-
-	//===================================================================================================================================
-	//                                                                                                                                  =
-	//===================================================================================================================================
-	PROPERTY_R( uint, width, getWidth ) ///< Width of the rendering. Dont confuse with the window width
-	PROPERTY_R( uint, height, getHeight ) ///< Height of the rendering. Dont confuse with the window width
-	PROPERTY_R( uint, framesNum, getFramesNum )
-	PROPERTY_R( float, aspectRatio, getAspectRatio )
-
-	protected:
-		// the rest
-		Camera* cam; ///< Current camera
-		static float quadVertCoords [][2];
-
-		static void drawQuad( int vertCoordsUniLoc );
-
-	public:
-		// the stages as data members
-		Ms ms; ///< Material rendering stage
-		Is is; ///< Illumination rendering stage
-		Pps pps; ///< Postprocessing rendering stage
-		Dbg dbg; ///< Debugging rendering stage
-
-		// texture stuff
-		static bool textureCompression; ///< Used in Texture::load to enable texture compression. Decreases video memory usage
-		static int  maxTextureUnits; ///< Used in Texture::bind so we wont bind in a nonexistent texture unit. Readonly
-		static bool mipmapping; ///< Used in Texture::load. Enables mipmapping increases video memory usage
-		static int  maxAnisotropy; ///< Max texture anisotropy. Used in Texture::load
-		// matrices & viewing
-		Mat4 modelViewMat; ///< This changes once for every mesh rendering
-		Mat4 projectionMat; ///< This changes once every frame
-		Mat4 modelViewProjectionMat; ///< This changes just like @ref modelViewMat
-		Mat3 normalMat; ///< The rotation part of modelViewMat
-
-		Renderer();
-
-		/**
-		 * Init the renderer given an initialization class
-		 * @param initializer The initializer class
-		 */
-		void init( const RendererInitializer& initializer );
-
-		/**
-		 * This function does all the rendering stages and produces a final FAI
-		 * @param cam The camera from where the rendering will be done
-		 */
-		void render( Camera& cam );
-
-		/**
-		 * My version of gluUnproject
-		 * @param windowCoords Window screen coords
-		 * @param modelViewMat The modelview matrix
-		 * @param projectionMat The projection matrix
-		 * @param view The view vector
-		 * @return The unprojected coords coords
-		 */
-		static Vec3 unproject( const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat, const int view[4] );
-
-		/**
-		 * It returns an orthographic projection matrix
-		 * @param left left vertical clipping plane
-		 * @param right right vertical clipping plane
-		 * @param bottom bottom horizontal clipping plane
-		 * @param top top horizontal clipping plane
-		 * @param near nearer distance of depth clipping plane
-		 * @param far farther distance of depth clipping plane
-		 * @return A 4x4 projection matrix
-		 */
-		static Mat4 ortho( float left, float right, float bottom, float top, float near, float far );
-
-		/**
-		 * Get last OpenGL error string
-		 * @return An error string or NULL if not error
-		 */
-		static const uchar* getLastError();
-
-		/**
-		 * Print last OpenGL error or nothing if there is no error
-		 */
-		static void printLastError();
-
-		static void setProjectionMatrix( const Camera& cam );
-		static void setViewMatrix( const Camera& cam );
-		static void noShaders() { ShaderProg::unbind(); } ///< unbind shaders @todo remove this. From now on there will be only shaders
-		static void setProjectionViewMatrices( const Camera& cam ) { setProjectionMatrix(cam); setViewMatrix(cam); }
-		static void setViewport( uint x, uint y, uint w, uint h ) { glViewport(x,y,w,h); }
-		static void multMatrix( const Mat4& m4 ) { glMultMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
-		static void multMatrix( const Transform& trf ) { glMultMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
-		static void loadMatrix( const Mat4& m4 ) { glLoadMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
-		static void loadMatrix( const Transform& trf ) { glLoadMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
-};
-
-#endif

+ 6 - 5
src/Resources/Material.cpp

@@ -5,7 +5,8 @@
 #include "Parser.h"
 #include "Parser.h"
 #include "Texture.h"
 #include "Texture.h"
 #include "ShaderProg.h"
 #include "ShaderProg.h"
-#include "Renderer.h"
+#include "App.h"
+#include "MainRenderer.h"
 
 
 
 
 /// Customized @ref ERROR used in @ref Material class
 /// Customized @ref ERROR used in @ref Material class
@@ -238,19 +239,19 @@ bool Material::load( const char* filename )
 						}
 						}
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "IS_FAI" ) )
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "IS_FAI" ) )
 						{
 						{
-							var.value.texture = &R::Is::fai;
+							var.value.texture = &app->getMainRenderer()->is.fai;
 						}
 						}
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "MS_NORMAL_FAI" ) )
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "MS_NORMAL_FAI" ) )
 						{
 						{
-							var.value.texture = &R::Ms::normalFai;
+							var.value.texture = &app->getMainRenderer()->ms.normalFai;
 						}
 						}
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "MS_DEPTH_FAI" ) )
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "MS_DEPTH_FAI" ) )
 						{
 						{
-							var.value.texture = &R::Ms::depthFai;
+							var.value.texture = &app->getMainRenderer()->ms.depthFai;
 						}
 						}
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "PPS_FAI" ) )
 						else if( token->getCode() == Scanner::TC_IDENTIFIER && !strcmp( token->getValue().getString(), "PPS_FAI" ) )
 						{
 						{
-							var.value.texture = &R::Pps::fai;
+							var.value.texture = &app->getMainRenderer()->pps.fai;
 						}
 						}
 						else
 						else
 						{
 						{

+ 10 - 4
src/Resources/Material.h

@@ -18,13 +18,19 @@ class Material: public Resource
 		class UserDefinedVar
 		class UserDefinedVar
 		{
 		{
 			public:
 			public:
+				enum SpecialValue
+				{
+					SV_IS_FAI
+				};
+
 				struct Value       // unfortunately we cannot use union because of Vec3 and Vec4
 				struct Value       // unfortunately we cannot use union because of Vec3 and Vec4
 				{
 				{
 					Texture* texture;
 					Texture* texture;
-					float    float_;
-					Vec2     vec2;
-					Vec3     vec3;
-					Vec4     vec4;
+					float float_;
+					Vec2 vec2;
+					Vec3 vec3;
+					Vec4 vec4;
+					SpecialValue speciaValue;
 					Value(): texture(NULL) {}
 					Value(): texture(NULL) {}
 				};
 				};
 
 

+ 1 - 1
src/Resources/ShaderProg.cpp

@@ -252,7 +252,7 @@ bool ShaderProg::customLoad( const char* filename, const char* extraSource )
 	if( !pars.parseFile( filename ) ) return false;
 	if( !pars.parseFile( filename ) ) return false;
 
 
 	// 1) create and compile the shaders
 	// 1) create and compile the shaders
-	string preprocSource = R::getStdShaderPreprocDefines() + extraSource;
+	string preprocSource = stdSourceCode + extraSource;
 	uint vertGlId = createAndCompileShader( pars.getOutput().getVertShaderSource().c_str(), preprocSource.c_str(), GL_VERTEX_SHADER );
 	uint vertGlId = createAndCompileShader( pars.getOutput().getVertShaderSource().c_str(), preprocSource.c_str(), GL_VERTEX_SHADER );
 	if( vertGlId == 0 ) return false;
 	if( vertGlId == 0 ) return false;
 
 

+ 14 - 8
src/Resources/Texture.cpp

@@ -3,6 +3,9 @@
 #include "Image.h"
 #include "Image.h"
 
 
 
 
+//=====================================================================================================================================
+// Statics                                                                                                                            =
+//=====================================================================================================================================
 int Texture::textureUnitsNum = -1;
 int Texture::textureUnitsNum = -1;
 bool Texture::mipmappingEnabled = true;
 bool Texture::mipmappingEnabled = true;
 bool Texture::compressionEnabled = true;
 bool Texture::compressionEnabled = true;
@@ -37,7 +40,7 @@ bool Texture::load( const char* filename )
 	// bind the texture
 	// bind the texture
 	glGenTextures( 1, &glId );
 	glGenTextures( 1, &glId );
 	bind(0);
 	bind(0);
-	if( R::mipmapping )
+	if( mipmappingEnabled )
 	{
 	{
 		glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
 		glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
 	}
 	}
@@ -48,7 +51,7 @@ bool Texture::load( const char* filename )
 
 
 	glTexParameteri( type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 	glTexParameteri( type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
 
-	glTexParameterf( type, GL_TEXTURE_MAX_ANISOTROPY_EXT, R::maxAnisotropy );
+	glTexParameterf( type, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropyLevel );
 
 
 	// leave to GL_REPEAT. There is not real performance impact
 	// leave to GL_REPEAT. There is not real performance impact
 	glTexParameteri( type, GL_TEXTURE_WRAP_S, GL_REPEAT );
 	glTexParameteri( type, GL_TEXTURE_WRAP_S, GL_REPEAT );
@@ -57,7 +60,7 @@ bool Texture::load( const char* filename )
 	int format = (img.bpp==32) ? GL_RGBA : GL_RGB;
 	int format = (img.bpp==32) ? GL_RGBA : GL_RGB;
 
 
 	int intFormat; // the internal format of the image
 	int intFormat; // the internal format of the image
-	if( R::textureCompression )
+	if( compressionEnabled )
 	{
 	{
 		//int_format = (img.bpp==32) ? GL_COMPRESSED_RGBA_S3TC_DXT1_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
 		//int_format = (img.bpp==32) ? GL_COMPRESSED_RGBA_S3TC_DXT1_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
 		intFormat = (img.bpp==32) ? GL_COMPRESSED_RGBA : GL_COMPRESSED_RGB;
 		intFormat = (img.bpp==32) ? GL_COMPRESSED_RGBA : GL_COMPRESSED_RGB;
@@ -68,7 +71,7 @@ bool Texture::load( const char* filename )
 	}
 	}
 
 
 	glTexImage2D( type, 0, intFormat, img.width, img.height, 0, format, GL_UNSIGNED_BYTE, img.data );
 	glTexImage2D( type, 0, intFormat, img.width, img.height, 0, format, GL_UNSIGNED_BYTE, img.data );
-	if( R::mipmapping )
+	if( mipmappingEnabled )
 	{
 	{
 		glGenerateMipmap(type);
 		glGenerateMipmap(type);
 	}
 	}
@@ -93,8 +96,10 @@ bool Texture::createEmpty2D( float width_, float height_, int internalFormat, in
 	glGenTextures( 1, &glId );
 	glGenTextures( 1, &glId );
 	bind();
 	bind();
 
 
-	if( R::mipmapping ) glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-	else                glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+	if( mipmappingEnabled )
+		glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+	else
+		glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 
 
 	texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 	texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 	texParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
 	texParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
@@ -103,7 +108,8 @@ bool Texture::createEmpty2D( float width_, float height_, int internalFormat, in
 	// allocate to vram
 	// allocate to vram
 	glTexImage2D( type, 0, internalFormat, width_, height_, 0, format_, type_, NULL );
 	glTexImage2D( type, 0, internalFormat, width_, height_, 0, format_, type_, NULL );
 
 
-	if( R::mipmapping ) glGenerateMipmap(type);
+	if( mipmappingEnabled )
+		glGenerateMipmap( type );
 
 
 	GLenum errid = glGetError();
 	GLenum errid = glGetError();
 	if( errid != GL_NO_ERROR )
 	if( errid != GL_NO_ERROR )
@@ -147,7 +153,7 @@ void Texture::unload()
 //=====================================================================================================================================
 //=====================================================================================================================================
 void Texture::bind( uint unit ) const
 void Texture::bind( uint unit ) const
 {
 {
-	if( unit>=(uint)R::maxTextureUnits )
+	if( unit >= static_cast<uint>(textureUnitsNum) )
 		WARNING("Max tex units passed");
 		WARNING("Max tex units passed");
 
 
 	glActiveTexture( GL_TEXTURE0+unit );
 	glActiveTexture( GL_TEXTURE0+unit );

+ 3 - 2
src/Scene/Camera.cpp

@@ -1,5 +1,6 @@
 #include "Camera.h"
 #include "Camera.h"
-#include "Renderer.h"
+#include "MainRenderer.h"
+#include "App.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
@@ -22,7 +23,7 @@ void Camera::setAll( float fovx_, float fovy_, float znear_, float zfar_ )
 void Camera::render()
 void Camera::render()
 {
 {
 	glPushMatrix();
 	glPushMatrix();
-	R::multMatrix( Mat4( getWorldTransform() ) );
+	app->getMainRenderer()->multMatrix( Mat4( getWorldTransform() ) );
 
 
 	const float camLen = 1.0;
 	const float camLen = 1.0;
 	float tmp0 = camLen / tan( (PI - fovX)*0.5 ) + 0.001;
 	float tmp0 = camLen / tan( (PI - fovX)*0.5 ) + 0.001;

+ 3 - 2
src/Scene/Controllers/SkelAnimCtrl.cpp

@@ -2,7 +2,8 @@
 #include "SkelAnim.h"
 #include "SkelAnim.h"
 #include "SkelNode.h"
 #include "SkelNode.h"
 #include "Skeleton.h"
 #include "Skeleton.h"
-#include "Renderer.h"
+#include "App.h"
+#include "MainRenderer.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
@@ -160,7 +161,7 @@ void SkelAnimCtrl::update( float )
 
 
 	interpolate( skelAnim, frame );
 	interpolate( skelAnim, frame );
 	updateBoneTransforms();
 	updateBoneTransforms();
-	if( R::Dbg::showSkeletons )
+	if( app->getMainRenderer()->dbg.isShowSkeletonsEnabled() )
 	{
 	{
 		deform();
 		deform();
 	}
 	}

+ 6 - 4
src/Scene/Light.cpp

@@ -1,7 +1,8 @@
 #include "Light.h"
 #include "Light.h"
 #include "collision.h"
 #include "collision.h"
-#include "Renderer.h"
 #include "LightProps.h"
 #include "LightProps.h"
+#include "App.h"
+#include "MainRenderer.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
@@ -45,10 +46,11 @@ void Light::deinit()
 static void RenderSphere( const Mat4& tsl, const Vec3& col )
 static void RenderSphere( const Mat4& tsl, const Vec3& col )
 {
 {
 	glPushMatrix();
 	glPushMatrix();
-	R::multMatrix( tsl );
 
 
-	R::color3( col );
-	R::Dbg::renderSphere( 1.0/8.0, 8 );
+	/// @todo move to GL 3.x
+	app->getMainRenderer()->multMatrix( tsl );
+	app->getMainRenderer()->color3( col );
+	app->getMainRenderer()->dbg.renderSphere( 1.0/8.0, 8 );
 
 
 	glPopMatrix();
 	glPopMatrix();
 }
 }

+ 3 - 2
src/Scene/MeshNode.cpp

@@ -1,12 +1,13 @@
 #include "MeshNode.h"
 #include "MeshNode.h"
 #include "Resource.h"
 #include "Resource.h"
 #include "Mesh.h"
 #include "Mesh.h"
-#include "Renderer.h"
 #include "Material.h"
 #include "Material.h"
 #include "SkelNode.h"
 #include "SkelNode.h"
 #include "Skeleton.h"
 #include "Skeleton.h"
 #include "MeshSkelNodeCtrl.h"
 #include "MeshSkelNodeCtrl.h"
 #include "SkelAnimCtrl.h"
 #include "SkelAnimCtrl.h"
+#include "App.h"
+#include "MainRenderer.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
@@ -42,7 +43,7 @@ void MeshNode::deinit()
 void MeshNode::render( Material* mtl ) const
 void MeshNode::render( Material* mtl ) const
 {
 {
 	glPushMatrix();
 	glPushMatrix();
-	R::multMatrix( Mat4(getWorldTransform()) );
+	app->getMainRenderer()->multMatrix( Mat4(getWorldTransform()) );
 
 
 	// if we have skeleton controller
 	// if we have skeleton controller
 	if( meshSkelCtrl )
 	if( meshSkelCtrl )

+ 5 - 5
src/Scene/ParticleEmitter.cpp

@@ -1,5 +1,5 @@
 #include "ParticleEmitter.h"
 #include "ParticleEmitter.h"
-#include "Renderer.h"
+#include "MainRenderer.h"
 #include "PhyCommon.h"
 #include "PhyCommon.h"
 #include "App.h"
 #include "App.h"
 #include "Scene.h"
 #include "Scene.h"
@@ -13,7 +13,7 @@ void ParticleEmitter::Particle::render()
 	if( lifeTillDeath < 0 ) return;
 	if( lifeTillDeath < 0 ) return;
 
 
 	glPushMatrix();
 	glPushMatrix();
-	R::multMatrix( getWorldTransform() );
+	app->getMainRenderer()->multMatrix( getWorldTransform() );
 
 
 	glBegin( GL_POINTS );
 	glBegin( GL_POINTS );
 		glVertex3fv( &(Vec3(0.0))[0] );
 		glVertex3fv( &(Vec3(0.0))[0] );
@@ -169,16 +169,16 @@ void ParticleEmitter::update()
 void ParticleEmitter::render()
 void ParticleEmitter::render()
 {
 {
 	glPushMatrix();
 	glPushMatrix();
-	R::multMatrix( getWorldTransform() );
+	app->getMainRenderer()->multMatrix( getWorldTransform() );
 
 
-	R::color3( Vec3(1.0) );
+	app->getMainRenderer()->color3( Vec3(1.0) );
 
 
 	/*glEnableClientState( GL_VERTEX_ARRAY );
 	/*glEnableClientState( GL_VERTEX_ARRAY );
 	glVertexPointer( 3, GL_FLOAT, 0, vertPositions );
 	glVertexPointer( 3, GL_FLOAT, 0, vertPositions );
 	glDrawElements( GL_LINES, sizeof(vertIndices)/sizeof(uint), GL_UNSIGNED_INT, vertIndices );
 	glDrawElements( GL_LINES, sizeof(vertIndices)/sizeof(uint), GL_UNSIGNED_INT, vertIndices );
 	glDisableClientState( GL_VERTEX_ARRAY );*/
 	glDisableClientState( GL_VERTEX_ARRAY );*/
 	glPolygonMode( GL_FRONT, GL_LINE );
 	glPolygonMode( GL_FRONT, GL_LINE );
-	R::Dbg::renderCube();
+	app->getMainRenderer()->dbg.renderCube();
 	glPolygonMode( GL_FRONT, GL_FILL );
 	glPolygonMode( GL_FRONT, GL_FILL );
 
 
 	glPopMatrix();
 	glPopMatrix();

+ 3 - 2
src/Scene/SkelNode.cpp

@@ -1,8 +1,9 @@
 #include "SkelNode.h"
 #include "SkelNode.h"
-#include "Renderer.h"
 #include "SkelAnim.h"
 #include "SkelAnim.h"
 #include "Skeleton.h"
 #include "Skeleton.h"
 #include "SkelAnimCtrl.h"
 #include "SkelAnimCtrl.h"
+#include "App.h"
+#include "MainRenderer.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
@@ -40,7 +41,7 @@ void SkelNode::deinit()
 void SkelNode::render()
 void SkelNode::render()
 {
 {
 	glPushMatrix();
 	glPushMatrix();
-	R::multMatrix( Mat4(getWorldTransform()) );
+	app->getMainRenderer()->multMatrix( Mat4(getWorldTransform()) );
 
 
 	//glPointSize( 4.0f );
 	//glPointSize( 4.0f );
 	//glLineWidth( 2.0f );
 	//glLineWidth( 2.0f );

+ 4 - 3
src/Ui/Ui.cpp

@@ -1,7 +1,8 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include "Ui.h"
 #include "Ui.h"
-#include "Renderer.h"
+#include "MainRenderer.h"
+#include "App.h"
 #include "Texture.h"
 #include "Texture.h"
 #include "Resource.h"
 #include "Resource.h"
 
 
@@ -53,7 +54,7 @@ static void SetGL()
 
 
 	glMatrixMode( GL_PROJECTION );
 	glMatrixMode( GL_PROJECTION );
 	glPushMatrix();
 	glPushMatrix();
-	R::loadMatrix( R::ortho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) );
+	app->getMainRenderer()->loadMatrix( Renderer::ortho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) );
 
 
 	glMatrixMode( GL_MODELVIEW );
 	glMatrixMode( GL_MODELVIEW );
 	glPushMatrix();
 	glPushMatrix();
@@ -177,7 +178,7 @@ void setFontWidth( float w_ )
 	// width
 	// width
 	fontW = w_;
 	fontW = w_;
 	// height
 	// height
-	fontH = fontW * R::aspectRatio;
+	fontH = fontW * app->getMainRenderer()->getAspectRatio();
 }
 }
 
 
 
 

Some files were not shown because too many files changed in this diff