2
0
Эх сурвалжийг харах

Changing the renderer a bit. Wont compile

Panagiotis Christopoulos Charitos 13 жил өмнө
parent
commit
df55f8b259

+ 1 - 1
CMakeLists.txt

@@ -74,7 +74,7 @@ MESSAGE("++ AnKi window backend: ${ANKI_WINDOW_BACKEND}")
 # Build type
 IF(CMAKE_BUILD_TYPE STREQUAL Debug)
 ELSE()
-	SET(FLAGS "-s -flto ")
+	SET(FLAGS " -s -flto -ffast-math ")
 
 	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
 	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")

+ 5 - 2
include/anki/gl/Texture.h

@@ -75,7 +75,10 @@ private:
 /// The global texture manager
 typedef Singleton<TextureManager> TextureManagerSingleton;
 
-/// Class for effective binding
+/// Class for effective binding of textures
+///
+/// @note GL has some nonsense where you can bind different texture targets in 
+///       the same unit. This class doesn't support that
 class TextureUnits
 {
 public:
@@ -102,7 +105,7 @@ private:
 	/// Texture unit representation
 	struct Unit
 	{
-		/// Have the GL ID to save memory. -1 if no tex is binded to that unit
+		/// Have the GL ID to save memory. 0 if no tex is binded to that unit
 		GLuint tex;
 		
 		/// Born time. The bigger the value the latter the unit has been

+ 0 - 1
include/anki/renderer/Hdr.h

@@ -59,7 +59,6 @@ private:
 	F32 exposure = 4.0; ///< How bright is the HDR
 	U32 blurringIterationsCount = 2; ///< The blurring iterations
 	F32 blurringDist = 1.0; ///< Distance in blurring
-	F32 renderingQuality = 0.5;
 	Fbo hblurFbo;
 	Fbo vblurFbo;
 	ShaderProgramResourcePointer toneSProg;

+ 2 - 0
include/anki/renderer/Is.h

@@ -87,6 +87,8 @@ private:
 		Array<Tile, TILES_X_COUNT * TILES_Y_COUNT> tiles1d;
 	};
 
+	U32 width, height;
+
 	/// A texture of TILES_X_COUNT*TILES_Y_COUNT size and format RG16F. Used to
 	/// to fill the Tile::depth
 	Texture minMaxFai;

+ 1 - 12
include/anki/renderer/MainRenderer.h

@@ -32,11 +32,6 @@ public:
 		screenshotJpegQuality = x;
 	}
 
-	float getRenderingQuality() const
-	{
-		return renderingQuality;
-	}
-
 	const Dbg& getDbg() const
 	{
 		return dbg;
@@ -71,12 +66,6 @@ private:
 	int screenshotJpegQuality = 90; ///< The quality of the JPEG screenshots.
 							        ///< From 0 to 100
 
-	U32 windowWidth, windowHeight;
-
-	/// 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)
-	float renderingQuality;
-
 	std::unique_ptr<Deformer> deformer;
 
 	void takeScreenshotTga(const char* filename);
@@ -86,6 +75,6 @@ private:
 
 typedef Singleton<MainRenderer> MainRendererSingleton;
 
-} // end namespace
+} // end namespace anki
 
 #endif

+ 2 - 10
include/anki/renderer/Pps.h

@@ -15,7 +15,7 @@ class ShaderProgram;
 
 /// Post-processing stage.This stage is divided into 2 two parts. The first
 /// happens before blending stage and the second after
-class Pps: private RenderingPass
+class Pps: public SwitchableRenderingPass
 {
 public:
 	Pps(Renderer* r);
@@ -53,11 +53,6 @@ public:
 	{
 		return fai;
 	}
-
-	Bool getDrawFinalToDefaultFbo() const
-	{
-		return drawFinalToDefaultFbo;
-	}
 	/// @}
 
 private:
@@ -71,13 +66,10 @@ private:
 	Fbo fbo;
 	ShaderProgramResourcePointer prog;
 	Texture fai;
-	Bool drawFinalToDefaultFbo;
 
 	void initInternal(const RendererInitializer& initializer);
 };
 
-
-} // end namespace
-
+} // end namespace anki
 
 #endif

+ 15 - 4
include/anki/renderer/Renderer.h

@@ -72,8 +72,7 @@ struct RendererInitializer
 			U blurringIterationsNum = 2;
 			F32 sideBlurFactor = 1.0;
 		} bl;
-
-		Bool drawFinalToDefaultFbo = false;
+		Bool enabled = false;
 	} pps;
 
 	// Dbg
@@ -83,9 +82,9 @@ struct RendererInitializer
 	} dbg;
 
 	// the globals
-	U32 width; 
+	U32 width;
 	U32 height;
-	F32 mainRendererQuality = 1.0; ///< Only for MainRenderer
+	F32 renderingQuality = 1.0;
 	F32 lodDistance; ///< Distance that used to calculate the LOD
 
 	// funcs
@@ -217,6 +216,16 @@ public:
 	{
 		return planesUpdateTimestamp;
 	}
+
+	Bool getOffsceenRenderer() const
+	{
+		return isOffscreenRenderer;
+	}
+	
+	F32 getRenderingQuality() const
+	{
+		return renderingQuality;
+	}
 	/// @}
 
 	/// Init the renderer given an initialization class
@@ -286,11 +295,13 @@ protected:
 	U width;
 	/// Height of the rendering. Don't confuse with the window width
 	U height;
+	F32 renderingQuality;
 	Scene* scene; ///< Current scene
 	/// Max color attachments an FBO can accept
 	static int maxColorAtachments;
 	RenderableDrawer sceneDrawer;
 	F32 lodDistance; ///< Distance that used to calculate the LOD
+	Bool isOffscreenRenderer = true; ///< An onscreen renderer may fake that
 
 	/// @name Optimization vars
 	/// Used in other stages

+ 3 - 9
include/anki/renderer/RenderingPass.h

@@ -1,6 +1,8 @@
 #ifndef ANKI_RENDERER_RENDERING_PASS_H
 #define ANKI_RENDERER_RENDERING_PASS_H
 
+#include "anki/util/StdTypes.h"
+
 namespace anki {
 
 class Renderer;
@@ -36,17 +38,9 @@ public:
 	{
 		return enabled;
 	}
-	bool& getEnabled()
-	{
-		return enabled;
-	}
-	void setEnabled(const bool x)
-	{
-		enabled = x;
-	}
 
 protected:
-	bool enabled = false;
+	Bool enabled = false;
 };
 
 } // end namespace anki

+ 0 - 6
include/anki/renderer/Ssao.h

@@ -31,11 +31,6 @@ public:
 
 	/// @name Accessors
 	/// @{
-	float getRenderingQuality() const
-	{
-		return renderingQuality;
-	}
-
 	const Texture& getFai() const
 	{
 		return vblurFai;
@@ -45,7 +40,6 @@ public:
 private:
 	Texture vblurFai;
 	Texture hblurFai;
-	F32 renderingQuality;
 	U32 blurringIterationsCount;
 	Fbo vblurFbo;
 	Fbo hblurFbo;

+ 2 - 2
include/anki/resource/MeshLoader.h

@@ -57,9 +57,8 @@ public:
 	};
 
 	/// Triangle
-	class Triangle
+	struct Triangle
 	{
-	public:
 		/// An array with the vertex indexes in the mesh class
 		Array<uint, 3> vertIds;
 		Vec3 normal;
@@ -99,6 +98,7 @@ public:
 		return vertWeights;
 	}
 
+	// XXX Delete: Unused
 	const Vector<Triangle>& getTris() const
 	{
 		return tris;

+ 2 - 1
src/gl/Texture.cpp

@@ -132,7 +132,8 @@ U TextureUnits::choseUnit(const Texture& tex, Bool& allreadyBinded)
 		}
 	}
 
-	// Find the older unit and replace the texture
+	// Find the older unit and choose that. Why? Because that texture haven't 
+	// been used for some time 
 	//
 	U64 older = 0;
 	for(U i = 1; i < units.size(); ++i)

+ 5 - 3
src/renderer/Hdr.cpp

@@ -31,10 +31,11 @@ void Hdr::initInternal(const Renderer::Initializer& initializer)
 		return;
 	}
 
-	renderingQuality = initializer.pps.hdr.renderingQuality;
+	F32 renderingQuality = initializer.pps.hdr.renderingQuality 
+		* initializer.renderingQuality;
 
-	width = renderingQuality * r->getWidth();
-	height = renderingQuality * r->getHeight();
+	width = renderingQuality * (F32)initializer.width;
+	height = renderingQuality * (F32)initializer.height;
 	exposure = initializer.pps.hdr.exposure;
 	blurringDist = initializer.pps.hdr.blurringDist;
 	blurringIterationsCount = initializer.pps.hdr.blurringIterationsCount;
@@ -90,6 +91,7 @@ void Hdr::init(const RendererInitializer& initializer)
 //==============================================================================
 void Hdr::run()
 {
+	ANKI_ASSERT(enabled);
 	/*if(r.getFramesNum() % 2 == 0)
 	{
 		return;

+ 7 - 4
src/renderer/Is.cpp

@@ -289,6 +289,9 @@ void Is::init(const RendererInitializer& initializer)
 //==============================================================================
 void Is::initInternal(const RendererInitializer& initializer)
 {
+	width = initializer.renderingQuality * initializer.width;
+	height = initializer.renderingQuality * initializer.height;
+
 	//
 	// Init the passes
 	//
@@ -300,8 +303,8 @@ void Is::initInternal(const RendererInitializer& initializer)
 	std::string pps =
 		"#define TILES_X_COUNT " + std::to_string(TILES_X_COUNT) + "\n"
 		"#define TILES_Y_COUNT " + std::to_string(TILES_Y_COUNT) + "\n"
-		"#define RENDERER_WIDTH " + std::to_string(r->getWidth()) + "\n"
-		"#define RENDERER_HEIGHT " + std::to_string(r->getHeight()) + "\n"
+		"#define RENDERER_WIDTH " + std::to_string(width) + "\n"
+		"#define RENDERER_HEIGHT " + std::to_string(height) + "\n"
 		"#define MAX_LIGHTS_PER_TILE " + std::to_string(MAX_LIGHTS_PER_TILE)
 		+ "\n"
 		"#define MAX_POINT_LIGHTS " + std::to_string(MAX_POINT_LIGHTS) + "\n"
@@ -325,7 +328,7 @@ void Is::initInternal(const RendererInitializer& initializer)
 	//
 
 	// IS FBO
-	Renderer::createFai(r->getWidth(), r->getHeight(), GL_RGB8,
+	Renderer::createFai(width, height, GL_RGB8,
 		GL_RGB, GL_UNSIGNED_INT, fai);
 	fbo.create();
 	fbo.setColorAttachments({&fai});
@@ -670,7 +673,7 @@ void Is::lightPass()
 
 	// Prepare state
 	fbo.bind();
-	GlStateSingleton::get().setViewport(0, 0, r->getWidth(), r->getHeight());
+	GlStateSingleton::get().setViewport(0, 0, width, height);
 	GlStateSingleton::get().disable(GL_DEPTH_TEST);
 	GlStateSingleton::get().disable(GL_BLEND);
 

+ 3 - 10
src/renderer/MainRenderer.cpp

@@ -20,19 +20,12 @@ void MainRenderer::init(const Renderer::Initializer& initializer_)
 	ANKI_LOGI("Initializing main renderer...");
 	initGl();
 
-	sProg.load("shaders/Final.glsl");
+	isOffscreenRenderer = (renderingQuality < 0.9);
 
-	windowWidth = initializer_.width;
-	windowHeight = initializer_.height;
+	sProg.load("shaders/Final.glsl");
 
 	// init the offscreen Renderer
 	//
-	RendererInitializer initializer = initializer_;
-	renderingQuality = initializer.mainRendererQuality;
-	initializer.width *= renderingQuality;
-	initializer.height *= renderingQuality;
-	initializer.pps.drawFinalToDefaultFbo = (renderingQuality > 0.9);
-
 	Renderer::init(initializer);
 	dbg.init(initializer);
 	deformer.reset(new Deformer);
@@ -233,4 +226,4 @@ void MainRenderer::takeScreenshot(const char* filename)
 	//ANKI_LOGI("Screenshot \"" << filename << "\" saved");
 }
 
-} // end namespace
+} // end namespace anki

+ 12 - 4
src/renderer/Pps.cpp

@@ -17,12 +17,18 @@ Pps::~Pps()
 //==============================================================================
 void Pps::initInternal(const RendererInitializer& initializer)
 {
+	enabled = initializer.pps.enabled;
+	if(!enabled)
+	{
+		return;
+	}
+
 	ssao.init(initializer);
 	hdr.init(initializer);
 	drawFinalToDefaultFbo = initializer.pps.drawFinalToDefaultFbo;
 
 	// FBO
-	if(!drawFinalToDefaultFbo)
+	if(r->getOffscreenRenderer())
 	{
 		Renderer::createFai(r->getWidth(), r->getHeight(), GL_RGB, GL_RGB,
 			GL_FLOAT, fai);
@@ -67,6 +73,8 @@ void Pps::init(const Renderer::Initializer& initializer)
 //==============================================================================
 void Pps::run()
 {
+	ANKI_ASSERT(enabled);
+
 	// First SSAO because it depends on MS where HDR depends on IS
 	if(ssao.getEnabled())
 	{
@@ -78,13 +86,13 @@ void Pps::run()
 		hdr.run();
 	}
 
-	if(drawFinalToDefaultFbo)
+	if(r->getOffscreenRenderer())
 	{
-		Fbo::unbindAll();
+		fbo.bind();
 	}
 	else
 	{
-		fbo.bind();
+		Fbo::unbindAll();
 	}
 
 	GlStateSingleton::get().enable(GL_DEPTH_TEST, false);

+ 1 - 0
src/renderer/Renderer.cpp

@@ -21,6 +21,7 @@ void Renderer::init(const RendererInitializer& initializer)
 	width = initializer.width;
 	height = initializer.height;
 	lodDistance = initializer.lodDistance;
+	renderingQuality = initializer.renderingQuality;
 	framesNum = 0;
 
 	// a few sanity checks

+ 4 - 3
src/renderer/Ssao.cpp

@@ -38,11 +38,12 @@ void Ssao::initInternal(const RendererInitializer& initializer)
 		return;
 	}
 
-	renderingQuality = initializer.pps.ssao.renderingQuality;
+	F32 renderingQuality = initializer.pps.ssao.renderingQuality 
+		* initializer.renderingQuality;
 	blurringIterationsCount = initializer.pps.ssao.blurringIterationsNum;
 
-	width = renderingQuality * r->getWidth();
-	height = renderingQuality * r->getHeight();
+	width = renderingQuality * (F32)initializer.width;
+	height = renderingQuality * (F32)initializer.height;
 
 	//
 	// create FBOs

+ 1 - 1
tools/dae2anki/dae2anki.py

@@ -57,7 +57,7 @@ def compare_arr(a, b):
 	la = len(a)
 	lb = len(b)
 	if la != lb:
-		raise Exception("Arrays not the same")
+		raise Exception("Arrays don't have the same size")
 	for i in range(la):
 		if a[i] != b[i]:
 			return False