소스 검색

Working on the new renderer

Panagiotis Christopoulos Charitos 15 년 전
부모
커밋
dbdf7b411a
8개의 변경된 파일142개의 추가작업 그리고 53개의 파일을 삭제
  1. 2 2
      docs/Doxyfile
  2. BIN
      docs/renderer-flow.odg
  3. 13 9
      src/Renderer2/Is.cpp
  4. 15 15
      src/Renderer2/MainRenderer.cpp
  5. 11 1
      src/Renderer2/MainRenderer.h
  6. 16 1
      src/Renderer2/Renderer.cpp
  7. 43 25
      src/Renderer2/Renderer.hpp
  8. 42 0
      src/Renderer2/RendererInitializer.h

+ 2 - 2
docs/Doxyfile

@@ -139,7 +139,7 @@ STRIP_FROM_INC_PATH    =
 # (but less readable) file names. This can be useful is your file systems 
 # doesn't support long names like on DOS, Mac, or CD-ROM.
 
-SHORT_NAMES            = YES
+SHORT_NAMES            = NO
 
 # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
 # will interpret the first line (until the first dot) of a JavaDoc-style 
@@ -532,7 +532,7 @@ WARNINGS               = YES
 # for undocumented members. If EXTRACT_ALL is set to YES then this flag will 
 # automatically be disabled.
 
-WARN_IF_UNDOCUMENTED   = YES
+WARN_IF_UNDOCUMENTED   = NO
 
 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 
 # potential errors in the documentation, such as not documenting some 

BIN
docs/renderer-flow.odg


+ 13 - 9
src/Renderer2/Is.cpp

@@ -180,9 +180,11 @@ void Renderer::Is::init()
 
 	// init the rest
 	initFbo();
-	if( sMOUvSVboId == 0 ) initSMOUvS();
+	if( sMOUvSVboId == 0 )
+		initSMOUvS();
 
-	sm.init();
+	if( sm.enabled )
+		sm.init();
 }
 
 
@@ -378,7 +380,7 @@ void Renderer::Is::spotLightPass( const SpotLight& light )
 	//
 	// generate the shadow map (if needed)
 	//
-	if( light.castsShadow )
+	if( light.castsShadow && sm.enabled )
 	{
 		sm.run( light.camera );
 
@@ -396,8 +398,10 @@ void Renderer::Is::spotLightPass( const SpotLight& light )
 	//
 	const LightShaderProg* shdr; // because of the huge name
 
-	if( light.castsShadow )  shdr = &spotLightShadowSProg;
-	else                     shdr = &spotLightNoShadowSProg;
+	if( light.castsShadow && sm.enabled )
+		shdr = &spotLightShadowSProg;
+	else
+		shdr = &spotLightNoShadowSProg;
 
 	shdr->bind();
 
@@ -429,17 +433,17 @@ void Renderer::Is::spotLightPass( const SpotLight& light )
 
 
 	//
-	// set texture matrix for shadowmap projection
+	// set texture matrix for texture & shadowmap projection
 	//
 	// Bias * P_light * V_light * inv( V_cam )
-	static Mat4 bias_m4( 0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0 );
+	static Mat4 biasMat4( 0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0 );
 	Mat4 texProjectionMat;
-	texProjectionMat = bias_m4 * light.camera.getProjectionMatrix() * light.camera.getViewMatrix() * Mat4(cam.getWorldTransform());
+	texProjectionMat = biasMat4 * light.camera.getProjectionMatrix() * light.camera.getViewMatrix() * Mat4(cam.getWorldTransform());
 	glUniformMatrix4fv( shdr->uniLocs.texProjectionMat, 1, true, &texProjectionMat[0] );
 
 	// the shadow stuff
 	// render depth to texture and then bind it
-	if( light.castsShadow )
+	if( light.castsShadow && sm.enabled )
 	{
 		shdr->locTexUnit( shdr->uniLocs.shadowMap, sm.shadowMap, 5 );
 	}

+ 15 - 15
src/Renderer2/MainRenderer.cpp

@@ -3,12 +3,12 @@
 #include <jpeglib.h>
 #include "MainRenderer.h"
 #include "App.h"
-
+#include "RendererInitializer.h"
 
 //=====================================================================================================================================
 // init                                                                                                                               =
 //=====================================================================================================================================
-void MainRenderer::init()
+void MainRenderer::init( const RendererInitializer& initializer )
 {
 	INFO( "Main renderer initializing..." );
 
@@ -57,7 +57,7 @@ void MainRenderer::init()
 	// init the rest
 	//
 	glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorAtachments );
-	Renderer::init();
+	Renderer::init( initializer );
 	sProg.customLoad( "shaders/final.glsl" );
 
 	INFO( "Main renderer initialization ends" );
@@ -101,10 +101,10 @@ bool MainRenderer::takeScreenshotTga( const char* filename )
 	unsigned char tgaHeaderUncompressed[12] = {0,0,2,0,0,0,0,0,0,0,0,0};
 	unsigned char header[6];
 
-	header[1] = width / 256;
-	header[0] = width % 256;
-	header[3] = height / 256;
-	header[2] = height % 256;
+	header[1] = getWidth() / 256;
+	header[0] = getWidth() % 256;
+	header[3] = getHeight() / 256;
+	header[2] = getHeight() % 256;
 	header[4] = 24;
 	header[5] = 0;
 
@@ -112,10 +112,10 @@ bool MainRenderer::takeScreenshotTga( const char* filename )
 	fs.write( (char*)header, 6 );
 
 	// write the buffer
-	char* buffer = (char*)calloc( width*height*3, sizeof(char) );
+	char* buffer = (char*)calloc( getWidth()*getHeight()*3, sizeof(char) );
 
-	glReadPixels( 0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, buffer );
-	fs.write( buffer, width*height*3 );
+	glReadPixels( 0, 0, getWidth(), getHeight(), GL_BGR, GL_UNSIGNED_BYTE, buffer );
+	fs.write( buffer, getWidth()*getHeight()*3 );
 
 	// end
 	fs.close();
@@ -146,8 +146,8 @@ bool MainRenderer::takeScreenshotJpeg( const char* filename )
 	jpeg_create_compress( &cinfo );
 	jpeg_stdio_dest( &cinfo, outfile );
 
-	cinfo.image_width      = width;
-	cinfo.image_height     = height;
+	cinfo.image_width      = getWidth();
+	cinfo.image_height     = getHeight();
 	cinfo.input_components = 3;
 	cinfo.in_color_space   = JCS_RGB;
 	jpeg_set_defaults( &cinfo);
@@ -155,15 +155,15 @@ bool MainRenderer::takeScreenshotJpeg( const char* filename )
 	jpeg_start_compress( &cinfo, true );
 
 	// read from OGL
-	char* buffer = (char*)malloc( width*height*3*sizeof(char) );
-	glReadPixels( 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer );
+	char* buffer = (char*)malloc( getWidth()*getHeight()*3*sizeof(char) );
+	glReadPixels( 0, 0, getWidth(), getHeight(), GL_RGB, GL_UNSIGNED_BYTE, buffer );
 
 	// write buffer to file
 	JSAMPROW row_pointer;
 
 	while( cinfo.next_scanline < cinfo.image_height )
 	{
-		row_pointer = (JSAMPROW) &buffer[ (height-1-cinfo.next_scanline)*3*width ];
+		row_pointer = (JSAMPROW) &buffer[ (getHeight()-1-cinfo.next_scanline)*3*getWidth() ];
 		jpeg_write_scanlines( &cinfo, &row_pointer, 1 );
 	}
 

+ 11 - 1
src/Renderer2/MainRenderer.h

@@ -13,6 +13,11 @@ class MainRenderer: public Renderer
 	PROPERTY_RW( int, screenshotJpegQuality, setScreenshotJpegQuality, getScreenshotJpegQuality ) ///< The quality of the JPEG screenshots. From 0 to 100
 	PROPERTY_R( int, maxColorAtachments, getMaxColorAtachments ) ///< Max color attachments a FBO can accept
 
+	/**
+	 * The global rendering quality of the raster image. Its a percentage of the application's window size. From 0.0(low) to 1.0(high)
+	 */
+	PROPERTY_R( float, renderingQuality, getRenderingQuality )
+
 	private:
 		ShaderProg sProg; ///< Final pass' shader program
 
@@ -22,7 +27,12 @@ class MainRenderer: public Renderer
 	public:
 		MainRenderer(): screenshotJpegQuality( 90 ) {}
 
-		void init();
+		void init( const RendererInitializer& initializer );
+
+		/**
+		 * The same as Renderer::render but in addition it renders the final FAI to the framebuffer
+		 * @param cam @see Renderer::render
+		 */
 		void render( Camera& cam );
 		void takeScreenshot( const char* filename ); ///< Save the colorbuffer as 24bit uncompressed TGA image
 };

+ 16 - 1
src/Renderer2/Renderer.cpp

@@ -1,5 +1,6 @@
 #include "Renderer.hpp"
 #include "Camera.h" /// @todo remove this
+#include "RendererInitializer.h"
 
 
 //=====================================================================================================================================
@@ -28,8 +29,22 @@ Renderer::Renderer():
 //=====================================================================================================================================
 // init                                                                                                                               =
 //=====================================================================================================================================
-void Renderer::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!!!!!!!!!!

+ 43 - 25
src/Renderer2/Renderer.hpp

@@ -10,6 +10,7 @@
 class Camera;
 class PointLight;
 class SpotLight;
+class RendererInitializer;
 
 
 /**
@@ -72,6 +73,12 @@ class Renderer
 				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
@@ -86,10 +93,6 @@ class Renderer
 						void run( const Camera& cam );
 
 					public:
-						bool pcfEnabled;
-						bool bilinearEnabled;
-						int  resolution; ///< Shadowmap resolution. The higher the more quality
-
 						Sm( Renderer& r_ ): RenderingStage( r_ ) {}
 				}; // end Sm
 
@@ -113,7 +116,7 @@ class Renderer
 						struct
 						{
 							int msNormalFai, msDiffuseFai, msSpecularFai, msDepthFai, planes, lightPos, lightInvRadius, lightDiffuseCol, lightSpecularCol, lightTex, texProjectionMat, shadowMap;
-						}uniLocs;
+						} uniLocs;
 				};
 				AmbientShaderProg ambientPassSProg; ///< Illumination stage ambient pass shader program
 				LightShaderProg pointLightSProg; ///< Illumination stage point light shader program
@@ -154,6 +157,9 @@ class Renderer
 		{
 			friend class Renderer;
 
+			PROPERTY_R( bool, enabled, isEnabled )
+			PROPERTY_R( float, renderingQuality, getRenderingQuality )
+
 			public:
 				/**
 				 * High dynamic range lighting pass
@@ -161,6 +167,10 @@ class Renderer
 				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;
@@ -186,8 +196,6 @@ class Renderer
 						void run();
 
 					public:
-						bool enabled;
-						float renderingQuality;
 						Texture pass0Fai; ///< Vertical blur pass FAI
 						Texture pass1Fai; ///< pass0Fai with the horizontal blur FAI
 						Texture fai; ///< The final FAI
@@ -206,6 +214,11 @@ class Renderer
 				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;
@@ -232,9 +245,6 @@ class Renderer
 						void run();
 
 					public:
-						bool enabled;
-						float renderingQuality;
-						float bluringQuality;
 						Texture pass0Fai, pass1Fai, fai /** The final FAI */;
 						ShaderProg ssaoSProg, blurSProg, blurSProg2;
 
@@ -289,37 +299,36 @@ class Renderer
 				static void renderGrid();
 				static void renderSphere( float radius, int complexity );
 				static void renderCube( bool cols, float size );
-		};
+		}; // end Dbg
 
-		// 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
 
 	//===================================================================================================================================
 	//                                                                                                                                  =
 	//===================================================================================================================================
+	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:
-		// quality
-		uint  width; ///< width of the rendering. Dont confuse with the window width
-		uint  height; ///< height of the rendering. Dont confuse with the window width
-		float renderingQuality; ///< The global rendering quality of the raster image. From 0.0(low) to 1.0(high)
+		// 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
-		// other
-		uint  framesNum;
-		float aspectRatio;
-
 		// matrices & viewing
 		Mat4 modelViewMat; ///< This changes once for every mesh rendering
 		Mat4 projectionMat; ///< This changes once every frame
@@ -328,7 +337,16 @@ class Renderer
 
 		Renderer();
 
-		void init();
+		/**
+		 * 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 );
 
 		/**

+ 42 - 0
src/Renderer2/RendererInitializer.h

@@ -3,9 +3,51 @@
 
 #include <Common.h>
 
+/**
+ * A struct to initialize the renderer. It contains a few extra params for the MainRenderer
+ */
 struct RendererInitializer
 {
+	// Is
+	struct Is
+	{
+		// Sm
+		struct Sm
+		{
+			bool enabled;
+			bool pcfEnabled;
+			bool bilinearEnabled;
+			int resolution;
+		} sm;
+	} is;
 
+	// Pps
+	struct Pps
+	{
+		// Hdr
+		struct Hdr
+		{
+			bool enabled;
+			float renderingQuality;
+		} hdr;
+
+		// Ssao
+		struct Ssao
+		{
+			bool enabled;
+			float renderingQuality;
+			float bluringQuality;
+		} ssao;
+	} pps;
+
+	// Dbg
+	struct Dbg
+	{
+		bool enabled;
+	} dbg;
+
+	// the globals
+	int width, height;
 };
 
 #endif