Kaynağa Gözat

- Finalizing the Texture
- Work on the new renderer

Panagiotis Christopoulos Charitos 13 yıl önce
ebeveyn
işleme
25a292f4e1

+ 2 - 7
anki/gl/Texture.cpp

@@ -16,7 +16,7 @@ TextureManager::TextureManager()
 {
 	GLint tmp;
 	glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &tmp);
-	units.resize(tmp - 1, nullptr);
+	units.resize(tmp, nullptr);
 	
 	activeUnit = -1;
 	mipmapping = true;
@@ -110,8 +110,6 @@ Texture::~Texture()
 //==============================================================================
 void Texture::create(const Initializer& init)
 {
-	TextureManagerSingleton::get().lock();
-
 	// Sanity checks
 	//
 	ANKI_ASSERT(!isLoaded());
@@ -128,8 +126,7 @@ void Texture::create(const Initializer& init)
 	height = init.height;
 
 	// Bind
-	glActiveTexture(GL_TEXTURE0 
-		+ TextureManagerSingleton::get().getMaxUnitsCount() - 1);
+	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(target, glId);
 
 	switch(internalFormat)
@@ -178,8 +175,6 @@ void Texture::create(const Initializer& init)
 			GLint(init.anisotropyLevel));
 	}
 
-	TextureManagerSingleton::get().unlock();
-
 	ANKI_CHECK_GL_ERROR();
 }
 

+ 20 - 17
anki/gl/Texture.h

@@ -68,19 +68,9 @@ public:
 	/// texture
 	void textureDeleted(Texture* tex);
 
-	void lock()
-	{
-		mtx.lock();
-	}
-	void unlock()
-	{
-		mtx.unlock();
-	}
-
 private:
 	/// Texture units. The last is reserved and only used in Texture::create
 	std::vector<Texture*> units;
-	std::mutex mtx; ///< A mutex that locks the texture manager
 	uint activeUnit;
 
 	/// @name Hints
@@ -99,14 +89,15 @@ private:
 typedef Singleton<TextureManager> TextureManagerSingleton;
 
 
-/// Texture class
-///
-/// @note ITS NOT THREAD SAFE
+/// @brief Texture class
+/// Generally its not thread safe and a few methods can be called by other 
+/// threads. See the docs for each method
 class Texture
 {
 	friend class TextureManager;
 
 public:
+	/// @brief Texture filtering type
 	enum TextureFilteringType
 	{
 		TFT_NEAREST,
@@ -114,7 +105,7 @@ public:
 		TFT_TRILINEAR
 	};
 
-	/// Texture initializer struct
+	/// @brief Texture initializer struct
 	struct Initializer
 	{
 		uint width;
@@ -130,13 +121,16 @@ public:
 		size_t dataSize; ///< For compressed textures
 	};
 
-	/// Default constructor
+	/// @brief Default constructor
+	/// Thread safe
 	Texture();
 
-	/// Desrcuctor
+	/// @brief Desrcuctor
+	/// Thread unsafe
 	~Texture();
 
 	/// @name Accessors
+	/// Thread safe
 	/// @{
 	GLuint getGlId() const
 	{
@@ -178,15 +172,24 @@ public:
 	}
 	/// @}
 
-	/// Create a texture
+	/// @brief Create a texture
+	/// Thread safe
 	void create(const Initializer& init);
 
+	/// @brief Bind the texture to a unit that the texture manager will decide
+	/// Thread unsafe
 	void bind() const;
+
+	/// @brief Change the filtering type
+	/// Thread unsafe
 	void setFiltering(TextureFilteringType filterType)
 	{
 		bind();
 		setFilteringNoBind(filterType);
 	}
+
+	/// @brief Generate new mipmaps
+	/// Thread unsafe
 	void genMipmap();
 
 private:

+ 11 - 27
anki/renderer/Bs.cpp

@@ -1,12 +1,6 @@
-#include <boost/ptr_container/ptr_vector.hpp>
 #include "anki/renderer/Bs.h"
 #include "anki/renderer/Renderer.h"
-#include "anki/scene/Scene.h"
-#include "anki/resource/ShaderProgram.h"
-#include "anki/resource/Model.h"
-#include "anki/scene/ModelNode.h"
-#include "anki/resource/Material.h"
-#include "anki/resource/Mesh.h"
+#include "anki/resource/ShaderProgramResource.h"
 
 
 namespace anki {
@@ -24,11 +18,10 @@ void Bs::createFbo()
 	{
 		fbo.create();
 		fbo.bind();
-	
-		std::array<const Texture*, 1> fais = {{&r.getPps().getPrePassFai()}};
-		fbo.setColorAttachments(fais);
-		fbo.setOtherAttachments(GL_DEPTH_STENCIL_ATTACHMENT, 
-			r.getMs().getDepthFai());
+
+		fbo.setColorAttachments({&r->getPps().getPrePassFai()});
+		fbo.setOtherAttachment(GL_DEPTH_STENCIL_ATTACHMENT, 
+			r->getMs().getDepthFai());
 
 		fbo.checkIfGood();
 		fbo.unbind();
@@ -40,8 +33,6 @@ void Bs::createFbo()
 }
 
 
-//==============================================================================
-// createRefractFbo                                                            =
 //==============================================================================
 void Bs::createRefractFbo()
 {
@@ -50,39 +41,32 @@ void Bs::createRefractFbo()
 		refractFbo.create();
 		refractFbo.bind();
 
-		refractFbo.setNumOfColorAttachements(1);
-
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-			GL_TEXTURE_2D, refractFai.getGlId(), 0);
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
-			GL_TEXTURE_2D, r.getMs().getDepthFai().getGlId(), 0);
+		refractFbo.setColorAttachments({&refractFai});
+		refractFbo.setOtherAttachment(GL_DEPTH_STENCIL_ATTACHMENT, 
+			r->getMs().getDepthFai());
 
 		refractFbo.checkIfGood();
-
 		refractFbo.unbind();
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION("Failed to create blending stage refract FBO");
+		throw ANKI_EXCEPTION("Failed to create blending stage refract FBO") 
+			<< e;
 	}
 }
 
 
-//==============================================================================
-// init                                                                        =
 //==============================================================================
 void Bs::init(const RendererInitializer& /*initializer*/)
 {
 	createFbo();
-	Renderer::createFai(r.getWidth(), r.getHeight(), GL_RGBA8, GL_RGBA,
+	Renderer::createFai(r->getWidth(), r->getHeight(), GL_RGBA8, GL_RGBA,
 		GL_FLOAT, refractFai);
 	createRefractFbo();
 	refractSProg.load("shaders/BsRefract.glsl");
 }
 
 
-//==============================================================================
-// run                                                                         =
 //==============================================================================
 void Bs::run()
 {

+ 2 - 12
anki/renderer/Dbg.cpp

@@ -6,12 +6,6 @@
 namespace anki {
 
 
-//==============================================================================
-Dbg::Dbg(Renderer& r_)
-	: SwitchableRenderingPass(r_)
-{}
-
-
 //==============================================================================
 void Dbg::init(const RendererInitializer& initializer)
 {
@@ -25,12 +19,8 @@ void Dbg::init(const RendererInitializer& initializer)
 		fbo.create();
 		fbo.bind();
 
-		fbo.setNumOfColorAttachements(1);
-
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-			GL_TEXTURE_2D, r.getPps().getPostPassFai().getGlId(), 0);
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
-			GL_TEXTURE_2D, r.getMs().getDepthFai().getGlId(), 0);
+		fbo.setColorAttachments({&r->getPps().getPostPassFai()});
+		fbo.setOtherAttachment(GL_DEPTH_ATTACHMENT, r->getMs().getDepthFai());
 
 		fbo.checkIfGood();
 		fbo.unbind();

+ 3 - 4
anki/renderer/Dbg.h

@@ -1,11 +1,8 @@
 #ifndef ANKI_RENDERER_DBG_H
 #define ANKI_RENDERER_DBG_H
 
-#include <boost/array.hpp>
-#include <map>
 #include "anki/renderer/RenderingPass.h"
 #include "anki/gl/Fbo.h"
-#include "anki/renderer/Drawer.h"
 
 
 namespace anki {
@@ -15,7 +12,9 @@ namespace anki {
 class Dbg: public SwitchableRenderingPass
 {
 public:
-	Dbg(Renderer& r_);
+	Dbg(Renderer* r_)
+		: SwitchableRenderingPass(r_)
+	{}
 	
 	void init(const RendererInitializer& initializer);
 	void run();

+ 2 - 2
anki/renderer/Deformer.cpp

@@ -50,10 +50,10 @@ void Deformer::deform(SkinNode& skinNode, SkinPatchNode& node) const
 
 	// Uniforms
 	//
-	sProg->findUniformVariableByName("skinningRotations").set(
+	sProg->findUniformVariableByName("skinningRotations")->set(
 		&skinNode.getBoneRotations()[0], skinNode.getBoneRotations().size());
 
-	sProg->findUniformVariableByName("skinningTranslations").set(
+	sProg->findUniformVariableByName("skinningTranslations")->set(
 		&skinNode.getBoneTranslations()[0],
 		skinNode.getBoneTranslations().size());
 

+ 19 - 14
anki/renderer/Deformer.h

@@ -7,29 +7,34 @@
 namespace anki {
 
 
-class ShaderProgram;
+class ShaderProgramResource;
 class SkinPatchNode;
 class SkinNode;
 
 
-/// SkinPatchNode deformer. It gets a SkinPatchNode and using transform
-/// feedback it deforms its vertex attributes
+/// SkinPatchNode deformer
+///
+/// It gets a SkinPatchNode and using transform feedback it deforms its vertex 
+/// attributes
 class Deformer
 {
-	public:
-		Deformer()
-		{
-			init();
-		}
-		~Deformer();
+public:
+	Deformer()
+	{
+		init();
+	}
+	~Deformer();
 
-		void deform(SkinNode& node, SkinPatchNode& subNode) const;
+	void deform(SkinNode& node, SkinPatchNode& subNode) const;
 
-	private:
-		ShaderProgramResourcePointer tfHwSkinningAllSProg;
-		ShaderProgramResourcePointer tfHwSkinningPosSProg;
+private:
+	/// Shader program that deforms all attribs
+	ShaderProgramResourcePointer tfHwSkinningAllSProg;
 
-		void init();
+	/// Shader program that deforms only the position attribute
+	ShaderProgramResourcePointer tfHwSkinningPosSProg;
+
+	void init();
 };
 
 

+ 1 - 0
anki/renderer/Renderer.h

@@ -16,6 +16,7 @@
 #include "anki/gl/GlException.h"
 #include "anki/gl/GlStateMachine.h"
 #include "anki/gl/TimeQuery.h"
+#include "anki/renderer/Drawer.h"
 #include <boost/scoped_ptr.hpp>