Przeglądaj źródła

- Changes in the resource manager
- Finalizing the Bs code. Needs testing

Panagiotis Christopoulos Charitos 15 lat temu
rodzic
commit
67c5eb46f8

Plik diff jest za duży
+ 400 - 344
build/debug/Makefile


+ 2 - 3
docs/readme

@@ -258,9 +258,8 @@ ToDo list
 	- How to make floating particles like smoke. But first try with one body and
 	- How to make floating particles like smoke. But first try with one body and
 	  manualy setting the gravity
 	  manualy setting the gravity
 	- What the btCollisionObject::setActivationState takes as parameter?
 	- What the btCollisionObject::setActivationState takes as parameter?
-- Enable depth test before skybox rendering to see what happens -> Forgot to
   disable the test
   disable the test
-- Re-enable the stencil tex in Ms.cpp
+- Re-enable the stencil tex in Ms.cpp and replace all the stencil buffers with
+  that (Smo, Bs) to save memory
 - See if the restrictions in FBOs (all FAIs same size) still apply
 - See if the restrictions in FBOs (all FAIs same size) still apply
-- Remove the EXT from some GL funcs -> done
 
 

+ 44 - 0
shaders/BsBpSphere.glsl

@@ -0,0 +1,44 @@
+#pragma anki vertShaderBegins
+
+attribute vec3 position;
+attribute vec3 normal;
+//attribute vec2 texCoords;
+
+uniform mat4 modelViewProjectionMat;
+uniform mat3 normalMat;
+
+//varying vec2 texCoords_v2f;
+varying vec3 normalV2f;
+
+void main()
+{
+	//texCoords_v2f = texCoords;
+	normalV2f = normalMat * normal;
+	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
+}
+
+#pragma anki fragShaderBegins
+
+#pragma anki include "shaders/pack.glsl"
+
+uniform sampler2D ppsPrePassFai;
+uniform sampler2D noiseMap;
+//varying vec2 texCoords_v2f;
+varying vec3 normalV2f;
+uniform vec2 rendererSize;  
+
+void main()
+{
+	/*vec3 _noise = DecodeNormal(texture2D(noiseMap, gl_FragCoord.xy*vec2(1.0/R_W, 1.0/R_H)).rg).rgb;
+	_noise = _noise * 2 - 1;
+	_noise *= 7.0;*/
+
+	vec4 col = texture2D(ppsPrePassFai, (gl_FragCoord.xy+(normalV2f.z*50))*vec2(1.0/rendererSize.x, 1.0/rendererSize.y)) * 0.75;
+	//vec4 _texel = texture2D(isFai, gl_FragCoord.xy*vec2(1.0/R_W, 1.0/R_H));
+
+	gl_FragData[0].rgb = col.rgb;
+
+	//if(normalV2f.z > 0.5) discard;
+
+	//gl_FragData[0] = vec4(normalV2f.z);
+}

+ 2 - 7
shaders/bs_refract.glsl → shaders/BsRefract.glsl

@@ -4,16 +4,11 @@
 
 
 #pragma anki fragShaderBegins
 #pragma anki fragShaderBegins
 
 
-uniform sampler2D fai;
+uniform sampler2D fbo;
 
 
 varying vec2 texCoords;
 varying vec2 texCoords;
 
 
-
-
 void main()
 void main()
 {
 {
-	vec4 _color = texture2D( fai, texCoords );
-	if( _color.a == 0.0 ) discard;
-
-	gl_FragData[0].rgb = _color.rgb;
+	gl_FragData[0].rgb = texture2D(fai, texCoords).rgb;
 }
 }

+ 0 - 40
shaders/simple_texturing.glsl

@@ -1,40 +0,0 @@
-#pragma anki vertShaderBegins
-
-attribute vec3 position;
-attribute vec3 normal;
-//attribute vec2 texCoords;
-
-//varying vec2 texCoords_v2f;
-varying vec3 normal_v2f;
-
-void main()
-{
-	//texCoords_v2f = texCoords;
-	normal_v2f = gl_NormalMatrix * normal;
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
-}
-
-#pragma anki fragShaderBegins
-
-#pragma anki include "shaders/pack.glsl"
-
-uniform sampler2D isFai, noise_map;
-//varying vec2 texCoords_v2f;
-varying vec3 normal_v2f;
-uniform vec2 rendererSize;
-
-void main()
-{
-	/*vec3 _noise = DecodeNormal( texture2D( noise_map, gl_FragCoord.xy*vec2( 1.0/R_W, 1.0/R_H ) ).rg ).rgb;
-	_noise = _noise * 2 - 1;
-	_noise *= 7.0;*/
-
-	vec4 _texel = texture2D( isFai, (gl_FragCoord.xy+(normal_v2f.z*50))*vec2( 1.0/rendererSize.x, 1.0/rendererSize.y ) ) * 0.75;
-	//vec4 _texel = texture2D( isFai, gl_FragCoord.xy*vec2( 1.0/R_W, 1.0/R_H ) );
-
-	gl_FragData[0] = _texel;
-
-	//if( normal_v2f.z > 0.5 ) discard;
-
-	//gl_FragData[0] = vec4( normal_v2f.z );
-}

+ 2 - 2
src/Main.cpp

@@ -261,7 +261,7 @@ void init()
 	imp = new SkelModelNode();
 	imp = new SkelModelNode();
 	imp->init("models/imp/imp.smdl");
 	imp->init("models/imp/imp.smdl");
 	imp->setLocalTransform(Transform(Vec3(0.0, 2.11, 0.0), Mat3(Euler(-M::PI/2, 0.0, 0.0)), 0.7));
 	imp->setLocalTransform(Transform(Vec3(0.0, 2.11, 0.0), Mat3(Euler(-M::PI/2, 0.0, 0.0)), 0.7));
-	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->skelAnim = Rsrc::skelAnims.load("models/imp/walk.imp.anim");
+	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->skelAnim = Resource::skelAnims.load("models/imp/walk.imp.anim");
 	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->step = 0.8;
 	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->step = 0.8;
 
 
 	// particle emitter
 	// particle emitter
@@ -277,7 +277,7 @@ void init()
 
 
 	//
 	//
 	//floor_ = new floor_t;
 	//floor_ = new floor_t;
-	//floor_->material = Rsrc::materials.load("materials/default.mtl");
+	//floor_->material = Resource::materials.load("materials/default.mtl");
 
 
 	const char* skybox_fnames [] = { "textures/env/hellsky4_forward.tga", "textures/env/hellsky4_back.tga", "textures/env/hellsky4_left.tga",
 	const char* skybox_fnames [] = { "textures/env/hellsky4_forward.tga", "textures/env/hellsky4_back.tga", "textures/env/hellsky4_left.tga",
 																	 "textures/env/hellsky4_right.tga", "textures/env/hellsky4_up.tga", "textures/env/hellsky4_down.tga" };
 																	 "textures/env/hellsky4_right.tga", "textures/env/hellsky4_up.tga", "textures/env/hellsky4_down.tga" };

+ 1 - 1
src/Misc/map.cpp

@@ -196,7 +196,7 @@ bool map_t::load(const char* filename)
 		// strings is what we want in this case... please let it be G-Strings
 		// strings is what we want in this case... please let it be G-Strings
 		if(token->getCode() == Scanner::TC_STRING)
 		if(token->getCode() == Scanner::TC_STRING)
 		{
 		{
-			Mesh* mesh = Rsrc::meshes.load(token->getValue().getString());
+			Mesh* mesh = Resource::meshes.load(token->getValue().getString());
 			if(!mesh) return false;
 			if(!mesh) return false;
 
 
 			meshes.push_back(mesh);
 			meshes.push_back(mesh);

+ 3 - 3
src/Misc/skybox.cpp

@@ -35,14 +35,14 @@ bool Skybox::load(const char* filenames[6])
 {
 {
 	for(int i=0; i<6; i++)
 	for(int i=0; i<6; i++)
 	{
 	{
-		textures[i] = Rsrc::textures.load(filenames[i]);
+		textures[i] = Resource::textures.load(filenames[i]);
 	}
 	}
 
 
-	noise = Rsrc::textures.load("gfx/noise2.tga");
+	noise = Resource::textures.load("gfx/noise2.tga");
 	noise->setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
 	noise->setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
 	noise->setTexParameter(GL_TEXTURE_WRAP_T, GL_REPEAT);
 	noise->setTexParameter(GL_TEXTURE_WRAP_T, GL_REPEAT);
 
 
-	shader = Rsrc::shaders.load("shaders/ms_mp_skybox.glsl");
+	shader = Resource::shaders.load("shaders/ms_mp_skybox.glsl");
 
 
 	return true;
 	return true;
 }
 }

+ 45 - 6
src/Renderer/Bs.cpp

@@ -14,10 +14,12 @@ void Renderer::Bs::createFbo()
 
 
 	fbo.setNumOfColorAttachements(1);
 	fbo.setNumOfColorAttachements(1);
 
 
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.prePassFai.getGlId(), 0);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, r.is.stencilRb);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.prePassFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
 
-	if(!fbo.isGood()) FATAL("Cannot create deferred shading blending stage FBO");
+	if(!fbo.isGood())
+		FATAL("Cannot create deferred shading blending stage FBO");
 
 
 	fbo.unbind();
 	fbo.unbind();
 }
 }
@@ -33,9 +35,12 @@ void Renderer::Bs::createRefractFbo()
 
 
 	refractFbo.setNumOfColorAttachements(1);
 	refractFbo.setNumOfColorAttachements(1);
 
 
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, refractFai.getGlId(), 0);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, r.is.stencilRb);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, refractFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
 
-	if(!refractFbo.isGood()) FATAL("Cannot create deferred shading blending stage FBO");
+	if(!refractFbo.isGood())
+		FATAL("Cannot create deferred shading blending stage FBO");
 
 
 	refractFbo.unbind();
 	refractFbo.unbind();
 }
 }
@@ -48,6 +53,8 @@ void Renderer::Bs::init()
 {
 {
 	createFbo();
 	createFbo();
 	createRefractFbo();
 	createRefractFbo();
+
+	refractSProg = Resource::shaders.load("shaders/BsRefract.glsl");
 }
 }
 
 
 
 
@@ -58,7 +65,6 @@ void Renderer::Bs::run()
 {
 {
 	Renderer::setViewport(0, 0, r.width, r.height);
 	Renderer::setViewport(0, 0, r.width, r.height);
 
 
-	glEnable(GL_DEPTH_TEST);
 	glDepthMask(false);
 	glDepthMask(false);
 
 
 	// render the meshes
 	// render the meshes
@@ -73,11 +79,44 @@ void Renderer::Bs::run()
 		// refracts
 		// refracts
 		if(meshNode->material->stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
 		if(meshNode->material->stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
 		{
 		{
+			// render to the temp FAI
+			refractFbo.bind();
+
+			glEnable(GL_STENCIL_TEST);
+			glStencilFunc(GL_ALWAYS, 0x1, 0x1);
+			glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+			glClear(GL_STENCIL_BUFFER_BIT);
+
+			r.setupMaterial(*meshNode->material, *meshNode, *r.cam);
+			glDisable(GL_BLEND); // a hack
+			meshNode->render();
+
+			// render the temp FAI to prePassFai
+			fbo.bind();
+
+			glStencilFunc(GL_EQUAL, 0x1, 0x1);
+			glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+
+			if(meshNode->material->blends)
+			{
+				glEnable(GL_BLEND);
+				glBlendFunc(meshNode->material->blendingSfactor, meshNode->material->blendingDfactor);
+			}
+			else
+				glDisable(GL_BLEND);
+
+			refractSProg->bind();
+			refractSProg->findUniVar("fai")->setTexture(refractFai, 0);
+
+			Renderer::drawQuad(0);
 
 
+			// cleanup
+			glDisable(GL_STENCIL_TEST);
 		}
 		}
 		else
 		else
 		{
 		{
 			fbo.bind();
 			fbo.bind();
+			r.setupMaterial(*meshNode->material, *meshNode, *r.cam);
 			meshNode->render();
 			meshNode->render();
 		}
 		}
 	}
 	}

+ 102 - 63
src/Renderer/BufferObjects/BufferObject.h

@@ -16,47 +16,32 @@ class BufferObject
 		GLenum usage; ///< GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 		GLenum usage; ///< GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 
 
 	public:
 	public:
-		BufferObject(): glId(0) {}
-		virtual ~BufferObject() { if(glId!=0) deleteBuff(); }
+		BufferObject();
+		virtual ~BufferObject();
 
 
 		/**
 		/**
 		 * Accessor. Throws an assertion error in BO is not created
 		 * Accessor. Throws an assertion error in BO is not created
 		 * @return The OpenGL ID of the buffer
 		 * @return The OpenGL ID of the buffer
 		 */
 		 */
-		uint getGlId() const
-		{
-			DEBUG_ERR(!isCreated());
-			return glId;
-		}
+		uint getGlId() const;
 
 
 		/**
 		/**
 		 * Accessor. Throws an assertion error in BO is not created
 		 * Accessor. Throws an assertion error in BO is not created
 		 * @return
 		 * @return
 		 */
 		 */
-		GLenum getBufferTarget() const
-		{
-			DEBUG_ERR(!isCreated());
-			return target;
-		}
+		GLenum getBufferTarget() const;
 
 
 		/**
 		/**
 		 * Accessor. Throws an assertion error in BO is not created
 		 * Accessor. Throws an assertion error in BO is not created
 		 * @return GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 		 * @return GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 		 */
 		 */
-		GLenum getBufferUsage() const
-		{
-			DEBUG_ERR(!isCreated());
-			return usage;
-		}
+		GLenum getBufferUsage() const;
 
 
 		/**
 		/**
 		 * @brief Checks if BO is created
 		 * @brief Checks if BO is created
 		 * @return True if BO is already created
 		 * @return True if BO is already created
 		 */
 		 */
-		bool isCreated() const
-		{
-			return glId != 0;
-		}
+		bool isCreated() const;
 
 
 		/**
 		/**
 		 * Creates a new BO with the given params and checks if everything went OK
 		 * Creates a new BO with the given params and checks if everything went OK
@@ -66,60 +51,114 @@ class BufferObject
 		 * @param usage_ It should be: GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW only!!!!!!!!!
 		 * @param usage_ It should be: GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW only!!!!!!!!!
 		 * @return True on success
 		 * @return True on success
 		 */
 		 */
-		bool create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
-		{
-			DEBUG_ERR(isCreated()); // BO already initialized
-			DEBUG_ERR(usage_!=GL_STREAM_DRAW && usage_!=GL_STATIC_DRAW && usage_!=GL_DYNAMIC_DRAW); // unacceptable usage_
-			DEBUG_ERR(sizeInBytes < 1); // unacceptable sizeInBytes
-
-			usage = usage_;
-			target = target_;
-
-			glGenBuffers(1, &glId);
-			bind();
-			glBufferData(target, sizeInBytes, dataPtr, usage);
-
-			// make a check
-			int bufferSize = 0;
-			glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufferSize);
-			if(sizeInBytes != (uint)bufferSize)
-			{
-				deleteBuff();
-				ERROR("Data size mismatch");
-				return false;
-			}
-
-			unbind();
-			return true;
-		}
+		bool create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_);
 
 
 		/**
 		/**
 		 * Throws an assertion error in BO is not created
 		 * Throws an assertion error in BO is not created
 		 */
 		 */
-		void bind() const
-		{
-			DEBUG_ERR(!isCreated());
-			glBindBuffer(target, glId);
-		}
+		void bind() const;
 
 
 		/**
 		/**
 		 * Throws an assertion error in BO is not created
 		 * Throws an assertion error in BO is not created
 		 */
 		 */
-		void unbind() const
-		{
-			DEBUG_ERR(!isCreated());
-			glBindBuffer(target, 0);
-		}
+		void unbind() const;
 
 
 		/**
 		/**
 		 * Self explanatory. Throws an assertion error in BO is not created
 		 * Self explanatory. Throws an assertion error in BO is not created
 		 */
 		 */
-		void deleteBuff()
-		{
-			DEBUG_ERR(!isCreated());
-			glDeleteBuffers(1, &glId);
-			glId = 0;
-		}
+		void deleteBuff();
 };
 };
 
 
+
+//======================================================================================================================
+// Inlines                                                                                                             =
+//======================================================================================================================
+
+inline BufferObject::BufferObject():
+	glId(0)
+{}
+
+
+inline BufferObject::~BufferObject()
+{
+	if(glId!=0)
+		deleteBuff();
+}
+
+inline uint BufferObject::getGlId() const
+{
+	DEBUG_ERR(!isCreated());
+	return glId;
+}
+
+
+inline GLenum BufferObject::getBufferTarget() const
+{
+	DEBUG_ERR(!isCreated());
+	return target;
+}
+
+
+inline GLenum BufferObject::getBufferUsage() const
+{
+	DEBUG_ERR(!isCreated());
+	return usage;
+}
+
+
+inline bool BufferObject::isCreated() const
+{
+	return glId != 0;
+}
+
+
+inline bool BufferObject::create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
+{
+	DEBUG_ERR(isCreated()); // BO already initialized
+	DEBUG_ERR(usage_!=GL_STREAM_DRAW && usage_!=GL_STATIC_DRAW && usage_!=GL_DYNAMIC_DRAW); // unacceptable usage_
+	DEBUG_ERR(sizeInBytes < 1); // unacceptable sizeInBytes
+
+	usage = usage_;
+	target = target_;
+
+	glGenBuffers(1, &glId);
+	bind();
+	glBufferData(target, sizeInBytes, dataPtr, usage);
+
+	// make a check
+	int bufferSize = 0;
+	glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufferSize);
+	if(sizeInBytes != (uint)bufferSize)
+	{
+		deleteBuff();
+		ERROR("Data size mismatch");
+		return false;
+	}
+
+	unbind();
+	return true;
+}
+
+
+inline void BufferObject::bind() const
+{
+	DEBUG_ERR(!isCreated());
+	glBindBuffer(target, glId);
+}
+
+
+inline void BufferObject::unbind() const
+{
+	DEBUG_ERR(!isCreated());
+	glBindBuffer(target, 0);
+}
+
+
+inline void BufferObject::deleteBuff()
+{
+	DEBUG_ERR(!isCreated());
+	glDeleteBuffers(1, &glId);
+	glId = 0;
+}
+
 #endif
 #endif

+ 91 - 50
src/Renderer/BufferObjects/Fbo.h

@@ -5,74 +5,115 @@
 #include "Common.h"
 #include "Common.h"
 
 
 
 
-/// The class is created as a wrapper to avoid common mistakes
+/**
+ * The class is actually a wrapper to avoid common mistakes
+ */
 class Fbo
 class Fbo
 {
 {
 	PROPERTY_R(uint, glId, getGlId) ///< OpenGL identification
 	PROPERTY_R(uint, glId, getGlId) ///< OpenGL identification
 
 
 	public:
 	public:
-		Fbo(): glId(0) {}
+		Fbo();
 
 
-		/// Creates a new FBO
-		void create()
-		{
-			DEBUG_ERR(glId != 0); // FBO already initialized
-			glGenFramebuffers(1, &glId);
-		}
+		/**
+		 * Creates a new FBO
+		 */
+		void create();
 
 
-		/// Binds FBO
-		void bind() const
-		{
-			DEBUG_ERR(glId == 0);  // FBO unitialized
-			glBindFramebuffer(GL_FRAMEBUFFER, glId);
-		}
+		/**
+		 * Binds FBO
+		 */
+		void bind() const;
 
 
-		/// Unbinds the FBO. Actualy unbinds all FBOs
-		static void unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); }
+		/**
+		 * Unbinds the FBO. Actually unbinds all FBOs
+		 */
+		static void unbind();
 
 
 		/**
 		/**
 		 * Checks the status of an initialized FBO
 		 * Checks the status of an initialized FBO
 		 * @return True if FBO is ok and false if not
 		 * @return True if FBO is ok and false if not
 		 */
 		 */
-		bool isGood() const
-		{
-			DEBUG_ERR(glId == 0);  // FBO unitialized
-			DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
-
-			return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
-		}
-
-		/// Set the number of color attachements of the FBO
-		void setNumOfColorAttachements(uint num) const
-		{
-			DEBUG_ERR(glId == 0);  // FBO unitialized
-			DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
-
-			if(num == 0)
-			{
-				glDrawBuffer(GL_NONE);
-				glReadBuffer(GL_NONE);
-			}
-			else
-			{
-				static GLenum colorAttachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
-				                                     GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
-				                                     GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
-
-				glDrawBuffers(num, colorAttachments);
-			}
-		}
+		bool isGood() const;
+
+		/**
+		 * Set the number of color attachements of the FBO
+		 */
+		void setNumOfColorAttachements(uint num) const;
 
 
 		/**
 		/**
 		 * Returns the GL id of the current attached FBO
 		 * Returns the GL id of the current attached FBO
 		 * @return Returns the GL id of the current attached FBO
 		 * @return Returns the GL id of the current attached FBO
 		 */
 		 */
-		static uint getCurrentFbo()
-		{
-			int fboGlId;
-			glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fboGlId);
-			return (uint)fboGlId;
-		}
+		static uint getCurrentFbo();
 };
 };
 
 
+
+//======================================================================================================================
+// Inlines                                                                                                             =
+//======================================================================================================================
+
+inline Fbo::Fbo():
+	glId(0)
+{}
+
+
+inline void Fbo::create()
+{
+	DEBUG_ERR(glId != 0); // FBO already initialized
+	glGenFramebuffers(1, &glId);
+}
+
+
+inline void Fbo::bind() const
+{
+	DEBUG_ERR(glId == 0);  // FBO not initialized
+	glBindFramebuffer(GL_FRAMEBUFFER, glId);
+}
+
+
+inline void Fbo::unbind()
+{
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+}
+
+
+inline bool Fbo::isGood() const
+{
+	DEBUG_ERR(glId == 0);  // FBO not initialized
+	DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
+
+	return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
+}
+
+
+inline void Fbo::setNumOfColorAttachements(uint num) const
+{
+	DEBUG_ERR(glId == 0);  // FBO not initialized
+	DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
+
+	if(num == 0)
+	{
+		glDrawBuffer(GL_NONE);
+		glReadBuffer(GL_NONE);
+	}
+	else
+	{
+		static GLenum colorAttachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
+																				 GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
+																				 GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
+
+		DEBUG_ERR(num > sizeof(colorAttachments)/sizeof(GLenum));
+		glDrawBuffers(num, colorAttachments);
+	}
+}
+
+
+inline uint Fbo::getCurrentFbo()
+{
+	int fboGlId;
+	glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fboGlId);
+	return (uint)fboGlId;
+}
+
 #endif
 #endif

+ 21 - 11
src/Renderer/BufferObjects/Vbo.h

@@ -13,21 +13,31 @@ class Vbo: public BufferObject
 		/**
 		/**
 		 * It adds an extra check over @ref BufferObject::create. See @ref BufferObject::create for details
 		 * It adds an extra check over @ref BufferObject::create. See @ref BufferObject::create for details
 		 */
 		 */
-		bool create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
-		{
-			DEBUG_ERR(target_!=GL_ARRAY_BUFFER && target_!=GL_ELEMENT_ARRAY_BUFFER); // unacceptable target_
-
-			return BufferObject::create(target_, sizeInBytes, dataPtr, usage_);
-		}
+		bool create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_);
 
 
 		/**
 		/**
 		 * Unbinds all VBOs, meaning both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER targets
 		 * Unbinds all VBOs, meaning both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER targets
 		 */
 		 */
-		static void unbindAllTargets()
-		{
-			glBindBufferARB(GL_ARRAY_BUFFER, 0);
-			glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
-		}
+		static void unbindAllTargets();
 };
 };
 
 
+
+//======================================================================================================================
+// Inlines                                                                                                             =
+//======================================================================================================================
+
+inline bool Vbo::create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
+{
+	DEBUG_ERR(target_!=GL_ARRAY_BUFFER && target_!=GL_ELEMENT_ARRAY_BUFFER); // unacceptable target_
+
+	return BufferObject::create(target_, sizeInBytes, dataPtr, usage_);
+}
+
+
+inline void Vbo::unbindAllTargets()
+{
+	glBindBufferARB(GL_ARRAY_BUFFER, 0);
+	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
+}
+
 #endif
 #endif

+ 2 - 2
src/Renderer/Dbg.cpp

@@ -187,8 +187,8 @@ void Renderer::Dbg::init()
 	fbo.setNumOfColorAttachements(1);
 	fbo.setNumOfColorAttachements(1);
 
 
 	// attach the textures
 	// attach the textures
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.postPassFai.getGlId(), 0);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.postPassFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!fbo.isGood())
 	if(!fbo.isGood())

+ 1 - 1
src/Renderer/Ez.cpp

@@ -25,7 +25,7 @@ void Renderer::Ms::Ez::init()
 
 
 	fbo.setNumOfColorAttachements(0);
 	fbo.setNumOfColorAttachements(0);
 
 
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
 
 	if(!fbo.isGood())
 	if(!fbo.isGood())
 		FATAL("Cannot create shadowmapping FBO");
 		FATAL("Cannot create shadowmapping FBO");

+ 1 - 1
src/Renderer/Hdr.cpp

@@ -29,7 +29,7 @@ void Renderer::Pps::Hdr::initFbos(Fbo& fbo, Texture& fai, int internalFormat)
 	fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
 
 	// attach
 	// attach
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!fbo.isGood())
 	if(!fbo.isGood())

+ 3 - 10
src/Renderer/Is.cpp

@@ -70,7 +70,7 @@ void Renderer::Is::initFbo()
 	glGenRenderbuffers(1, &stencilRb);
 	glGenRenderbuffers(1, &stencilRb);
 	glBindRenderbuffer(GL_RENDERBUFFER, stencilRb);
 	glBindRenderbuffer(GL_RENDERBUFFER, stencilRb);
 	glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, r.width, r.height);
 	glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, r.width, r.height);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRb);
 
 
 	// inform in what buffers we draw
 	// inform in what buffers we draw
 	fbo.setNumOfColorAttachements(1);
 	fbo.setNumOfColorAttachements(1);
@@ -80,7 +80,7 @@ void Renderer::Is::initFbo()
 		FATAL("Cannot create deferred shading illumination stage FAI");
 		FATAL("Cannot create deferred shading illumination stage FAI");
 
 
 	// attach
 	// attach
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!fbo.isGood())
 	if(!fbo.isGood())
@@ -251,13 +251,6 @@ void Renderer::Is::spotLightPass(const SpotLight& light)
 
 
 	light.lightProps->getTexture()->setRepeat(false);
 	light.lightProps->getTexture()->setRepeat(false);
 
 
-	/*
-	 * Before we render disable anisotropic in the light.texture because it produces artifacts.
-	 * todo see if this is necessary with future drivers
-	 */
-	light.lightProps->getTexture()->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	light.lightProps->getTexture()->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
 	// shader prog
 	// shader prog
 	const LightShaderProg* shdr; // because of the huge name
 	const LightShaderProg* shdr; // because of the huge name
 
 
@@ -290,7 +283,7 @@ void Renderer::Is::spotLightPass(const SpotLight& light)
 	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);
 	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;
 	Mat4 texProjectionMat;
 	texProjectionMat = biasMat4 * light.camera.getProjectionMatrix() *
 	texProjectionMat = biasMat4 * light.camera.getProjectionMatrix() *
-	                   Mat4::combineTransformations(light.camera.getViewMatrix(), Mat4(cam.getWorldTransform())) ;
+	                   Mat4::combineTransformations(light.camera.getViewMatrix(), Mat4(cam.getWorldTransform()));
 	shdr->uniVars.texProjectionMat->setMat4(&texProjectionMat);
 	shdr->uniVars.texProjectionMat->setMat4(&texProjectionMat);
 
 
 	// the shadowmap
 	// the shadowmap

+ 6 - 6
src/Renderer/Ms.cpp

@@ -29,13 +29,13 @@ void Renderer::Ms::init()
 
 
 
 
 	// attach the buffers to the FBO
 	// attach the buffers to the FBO
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, normalFai.getGlId(), 0);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, diffuseFai.getGlId(), 0);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, specularFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, normalFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, diffuseFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, specularFai.getGlId(), 0);
 
 
-	//glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
-	//glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
+	//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
+	//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!fbo.isGood())
 	if(!fbo.isGood())

+ 1 - 1
src/Renderer/Pps.cpp

@@ -19,7 +19,7 @@ void Renderer::Pps::initPassFbo(Fbo& fbo, Texture& fai, const char* msg)
 
 
 	fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT, false);
 	fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT, false);
 
 
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
 
 
 	if(!fbo.isGood())
 	if(!fbo.isGood())
 		FATAL(msg);
 		FATAL(msg);

+ 3 - 11
src/Renderer/Renderer.h

@@ -370,7 +370,7 @@ class Renderer
 			private:
 			private:
 				Fbo fbo;
 				Fbo fbo;
 				Fbo refractFbo;
 				Fbo refractFbo;
-				ShaderProg refractSProg;
+				ShaderProg* refractSProg;
 				Texture refractFai;
 				Texture refractFai;
 
 
 				void createFbo();
 				void createFbo();
@@ -451,7 +451,7 @@ class Renderer
 		 * @return The unprojected coords coords
 		 * @return The unprojected coords coords
 		 */
 		 */
 		static Vec3 unproject(const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat,
 		static Vec3 unproject(const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat,
-		                       const int view[4]);
+		                      const int view[4]);
 
 
 		/**
 		/**
 		 * It returns an orthographic projection matrix
 		 * It returns an orthographic projection matrix
@@ -465,14 +465,6 @@ class Renderer
 		 */
 		 */
 		static Mat4 ortho(float left, float right, float bottom, float top, float near, float far);
 		static Mat4 ortho(float left, float right, float bottom, float top, float near, float far);
 
 
-		/**
-		 * @name Funcs that control the FFP state
-		 */
-		/**@{*/
-		static void enableStencilTest();
-		static void disableStencilTest();
-		/**@}*/
-
 
 
 	//====================================================================================================================
 	//====================================================================================================================
 	// Protected                                                                                                         =
 	// Protected                                                                                                         =
@@ -485,6 +477,7 @@ class Renderer
 
 
 		static void drawQuad(int vertCoordsUniLoc);
 		static void drawQuad(int vertCoordsUniLoc);
 		void setupMaterial(const Material& mtl, const SceneNode& sceneNode, const Camera& cam);
 		void setupMaterial(const Material& mtl, const SceneNode& sceneNode, const Camera& cam);
+		static void setViewport(uint x, uint y, uint w, uint h) { glViewport(x,y,w,h); }
 
 
 		// to be removed
 		// to be removed
 	public:
 	public:
@@ -494,7 +487,6 @@ class Renderer
 		static void setViewMatrix(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 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 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 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 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 Mat4& m4) { glLoadMatrixf(&(m4.getTransposed())(0, 0)); } ///< OpenGL wrapper

+ 1 - 1
src/Renderer/Sm.cpp

@@ -43,7 +43,7 @@ void Renderer::Is::Sm::init()
 	fbo.setNumOfColorAttachements(0);
 	fbo.setNumOfColorAttachements(0);
 
 
 	// attach the texture
 	// attach the texture
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowMap.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowMap.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!fbo.isGood())
 	if(!fbo.isGood())

+ 3 - 3
src/Renderer/Ssao.cpp

@@ -26,7 +26,7 @@ void Renderer::Pps::Ssao::initBlurFbo(Fbo& fbo, Texture& fai)
 	fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
 
 	// attach
 	// attach
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!fbo.isGood())
 	if(!fbo.isGood())
@@ -65,7 +65,7 @@ void Renderer::Pps::Ssao::init()
 	pass0Fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	pass0Fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
 
 	// attach
 	// attach
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pass0Fai.getGlId(), 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pass0Fai.getGlId(), 0);
 
 
 	// test if success
 	// test if success
 	if(!pass0Fbo.isGood())
 	if(!pass0Fbo.isGood())
@@ -106,7 +106,7 @@ void Renderer::Pps::Ssao::init()
 	bool mipmaping = Texture::mipmappingEnabled;
 	bool mipmaping = Texture::mipmappingEnabled;
 	Texture::compressionEnabled = false;
 	Texture::compressionEnabled = false;
 	Texture::mipmappingEnabled = true;
 	Texture::mipmappingEnabled = true;
-	noiseMap = Rsrc::textures.load("gfx/noise3.tga");
+	noiseMap = Resource::textures.load("gfx/noise3.tga");
 	noiseMap->setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
 	noiseMap->setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
 	noiseMap->setTexParameter(GL_TEXTURE_WRAP_T, GL_REPEAT);
 	noiseMap->setTexParameter(GL_TEXTURE_WRAP_T, GL_REPEAT);
 	//noise_map->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	//noise_map->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);

+ 5 - 3
src/Resources/LightProps.cpp

@@ -97,9 +97,11 @@ Scanner scanner;
 				return false;
 				return false;
 			}
 			}
 				
 				
-			texture = Rsrc::textures.load(token->getValue().getString());
-			texture->setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, 0);
+			texture = Resource::textures.load(token->getValue().getString());
 			texture->setRepeat(false);
 			texture->setRepeat(false);
+			texture->setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, 0);
+			texture->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+			texture->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 		}
 		}
 		// end of file
 		// end of file
 		else if(token->getCode() == Scanner::TC_EOF)
 		else if(token->getCode() == Scanner::TC_EOF)
@@ -125,5 +127,5 @@ Scanner scanner;
 void LightProps::unload()
 void LightProps::unload()
 {
 {
 	if(texture != NULL)
 	if(texture != NULL)
-		Rsrc::textures.unload(texture);
+		Resource::textures.unload(texture);
 }
 }

+ 5 - 5
src/Resources/Material.cpp

@@ -115,7 +115,7 @@ bool Material::load(const char* filename)
 				PARSE_ERR_EXPECTED("string");
 				PARSE_ERR_EXPECTED("string");
 				return false;
 				return false;
 			}
 			}
-			shaderProg = Rsrc::shaders.load(token->getValue().getString());
+			shaderProg = Resource::shaders.load(token->getValue().getString());
 		}
 		}
 		//** DEPTH_MATERIAL **
 		//** DEPTH_MATERIAL **
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DEPTH_PASS_MATERIAL"))
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DEPTH_PASS_MATERIAL"))
@@ -128,7 +128,7 @@ bool Material::load(const char* filename)
 				PARSE_ERR_EXPECTED("string");
 				PARSE_ERR_EXPECTED("string");
 				return false;
 				return false;
 			}
 			}
-			dpMtl = Rsrc::materials.load(token->getValue().getString());
+			dpMtl = Resource::materials.load(token->getValue().getString());
 		}
 		}
 		//** BLENDS **
 		//** BLENDS **
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "BLENDS"))
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "BLENDS"))
@@ -261,7 +261,7 @@ bool Material::load(const char* filename)
 						token = &scanner.getNextToken();
 						token = &scanner.getNextToken();
 						if(token->getCode() == Scanner::TC_STRING)
 						if(token->getCode() == Scanner::TC_STRING)
 						{
 						{
-							var.value.texture = Rsrc::textures.load(token->getValue().getString());
+							var.value.texture = Resource::textures.load(token->getValue().getString());
 							if(var.value.texture == NULL)
 							if(var.value.texture == NULL)
 								return false;
 								return false;
 						}
 						}
@@ -404,12 +404,12 @@ Material::Material()
 //======================================================================================================================
 //======================================================================================================================
 void Material::unload()
 void Material::unload()
 {
 {
-	Rsrc::shaders.unload(shaderProg);
+	Resource::shaders.unload(shaderProg);
 
 
 	// loop all user defined vars and unload the textures
 	// loop all user defined vars and unload the textures
 	for(uint i=0; i<userDefinedVars.size(); i++)
 	for(uint i=0; i<userDefinedVars.size(); i++)
 	{
 	{
-		Rsrc::textures.unload(userDefinedVars[i].value.texture);
+		Resource::textures.unload(userDefinedVars[i].value.texture);
 	}
 	}
 }
 }
 
 

+ 10 - 16
src/Resources/Resource.cpp

@@ -7,20 +7,14 @@
 #include "LightProps.h"
 #include "LightProps.h"
 
 
 
 
-namespace Rsrc {
+//======================================================================================================================
+// Statics                                                                                                             =
+//======================================================================================================================
+ResourceContainer<Texture>    Resource::textures;
+ResourceContainer<ShaderProg> Resource::shaders;
+ResourceContainer<Material>   Resource::materials;
+ResourceContainer<Mesh>       Resource::meshes;
+ResourceContainer<Skeleton>   Resource::skeletons;
+ResourceContainer<SkelAnim>   Resource::skelAnims;
+ResourceContainer<LightProps> Resource::lightProps;
 
 
-
-/*
-=======================================================================================================================================
-DATA OBJECTS                                                                                                           =
-=======================================================================================================================================
-*/
-Container<Texture>    textures;
-Container<ShaderProg> shaders;
-Container<Material>   materials;
-Container<Mesh>       meshes;
-Container<Skeleton>   skeletons;
-Container<SkelAnim>   skelAnims;
-Container<LightProps> lightProps;
-
-} // end namespace

+ 19 - 161
src/Resources/Resource.h

@@ -3,6 +3,7 @@
 
 
 #include "Common.h"
 #include "Common.h"
 #include "Util.h"
 #include "Util.h"
+#include "ResourceContainer.h"
 
 
 
 
 // forward decls
 // forward decls
@@ -14,32 +15,35 @@ class Skeleton;
 class SkelAnim;
 class SkelAnim;
 class LightProps;
 class LightProps;
 
 
-namespace Rsrc {
-template< typename Type > class Container;
-}
-
 
 
 /**
 /**
  * Every class that it is considered a resource should be derived by this one. This step is not necessary because of the
  * Every class that it is considered a resource should be derived by this one. This step is not necessary because of the
- * Container template but ensures that loading will be made by the resource manager and not the class itself
+ * ResourceContainer template but ensures that loading will be made by the resource manager and not the class itself
  */
  */
 class Resource
 class Resource
 {
 {
+	friend class ResourceContainer<Texture>;
+	friend class ResourceContainer<ShaderProg>;
+	friend class ResourceContainer<Material>;
+	friend class ResourceContainer<Mesh>;
+	friend class ResourceContainer<Skeleton>;
+	friend class ResourceContainer<SkelAnim>;
+	friend class ResourceContainer<LightProps>;
+	friend class ShaderProg;
+
 	PROPERTY_R(string, path, getRsrcPath);
 	PROPERTY_R(string, path, getRsrcPath);
 	PROPERTY_R(string, name, getRsrcName);
 	PROPERTY_R(string, name, getRsrcName);
 	PROPERTY_R(uint, usersNum, getRsrcUsersNum);
 	PROPERTY_R(uint, usersNum, getRsrcUsersNum);
 
 
-	// friends
-	friend class Rsrc::Container<Texture>;
-	friend class Rsrc::Container<Material>;
-	friend class Rsrc::Container<ShaderProg>;
-	friend class Rsrc::Container<Skeleton>;
-	friend class Rsrc::Container<Mesh>;
-	friend class Rsrc::Container<SkelAnim>;
-	friend class Rsrc::Container<LightProps>;
-	friend class ShaderProg;
-
 	public:
 	public:
+		static ResourceContainer<Texture>    textures;
+		static ResourceContainer<ShaderProg> shaders;
+		static ResourceContainer<Material>   materials;
+		static ResourceContainer<Mesh>       meshes;
+		static ResourceContainer<Skeleton>   skeletons;
+		static ResourceContainer<SkelAnim>   skelAnims;
+		static ResourceContainer<LightProps> lightProps;
+
 		/**
 		/**
 		 * @param filename The file to load
 		 * @param filename The file to load
 		 * @return True on success
 		 * @return True on success
@@ -50,150 +54,4 @@ class Resource
 		Resource(): usersNum(0) {}
 		Resource(): usersNum(0) {}
 		virtual ~Resource() {};
 		virtual ~Resource() {};
 };
 };
-
-
-/// resource namespace
-namespace Rsrc {
-
-
-extern Container<Texture>    textures;
-extern Container<ShaderProg> shaders;
-extern Container<Material>   materials;
-extern Container<Mesh>       meshes;
-extern Container<Skeleton>   skeletons;
-extern Container<SkelAnim>   skelAnims;
-extern Container<LightProps> lightProps;
-
-
-/// resource container template class
-template<typename Type> class Container: public Vec<Type*>
-{
-	private:
-		typedef typename Container<Type>::iterator Iterator; ///< Just to save me time from typing
-		typedef Vec<Type*> BaseClass;
-
-		/**
-		 * Search inside the container by name
-		 * @param name The name of the resource
-		 * @return The iterator of the content end of vector if not found
-		 */
-		Iterator findByName(const char* name)
-		{
-			Iterator it = BaseClass::begin();
-			while(it != BaseClass::end())
-			{
-				if((*it).name == name)
-					return it;
-				++it;
-			}
-
-			return it;
-		}
-
-
-		/**
-		 * Search inside the container by name and path
-		 * @param name The name of the resource
-		 * @param path The path of the resource
-		 * @return The iterator of the content end of vector if not found
-		 */
-		Iterator findByNameAndPath(const char* name, const char* path)
-		{
-			Iterator it = BaseClass::begin();
-			while(it != BaseClass::end())
-			{
-				if((*it)->name == name && (*it)->path == path)
-					return it;
-				++it;
-			}
-
-			return it;
-		}
-
-
-		/**
-	   * Search inside the container by pointer
-		 * @param name The name of the resource object
-		 * @return The iterator of the content end of vector if not found
-		 */
-		Iterator findByPtr(Type* ptr)
-		{
-			Iterator it = BaseClass::begin();
-			while(it != BaseClass::end())
-			{
-				if(ptr == (*it))
-					return it;
-				++it;
-			}
-
-			return it;
-		}
-
-		public:
-		/**
-		 * load an object and register it. If its already loaded return its pointer
-		 * @param fname The filename that initializes the object
-		 * @return A pointer of a new resource or NULL on fail
-		 */
-		Type* load(const char* fname)
-		{
-			char* name = Util::cutPath(fname);
-			string path = Util::getPath(fname);
-			Iterator it = findByNameAndPath(name, path.c_str());
-
-			// if already loaded then inc the users and return the pointer
-			if(it != BaseClass::end())
-			{
-				++ (*it)->usersNum;
-				return (*it);
-			}
-
-			// else create new, loaded and update the container
-			Type* new_instance = new Type();
-			new_instance->name = name;
-			new_instance->path = path;
-			new_instance->usersNum = 1;
-
-			if(!new_instance->load(fname))
-			{
-				ERROR("Cannot load \"" << fname << '\"');
-				delete new_instance;
-				return NULL;
-			}
-			BaseClass::push_back(new_instance);
-
-			return new_instance;
-		}
-
-
-		/**
-		 * unload item. If nobody else uses it then delete it completely
-		 * @param x Pointer to the instance we want to unload
-		 */
-		void unload(Type* x)
-		{
-			Iterator it = findByPtr(x);
-			if(it == BaseClass::end())
-			{
-				ERROR("Cannot find resource with pointer 0x" << x);
-				return;
-			}
-
-			Type* del_ = (*it);
-			DEBUG_ERR(del_->usersNum < 1); // WTF?
-
-			--del_->usersNum;
-
-			// if no other users then call unload and update the container
-			if(del_->usersNum == 0)
-			{
-				del_->unload();
-				delete del_;
-				BaseClass::erase(it);
-			}
-		}
-}; // end class Container
-
-
-} // end namespace
 #endif
 #endif

+ 56 - 0
src/Resources/ResourceContainer.h

@@ -0,0 +1,56 @@
+#ifndef RESOURCECONTAINER_H
+#define RESOURCECONTAINER_H
+
+#include "Common.h"
+
+
+/**
+ * Resource container template class
+ */
+template<typename Type> class ResourceContainer: public Vec<Type*>
+{
+	private:
+		typedef typename ResourceContainer<Type>::iterator Iterator; ///< Just to save me time from typing
+		typedef Vec<Type*> BaseClass;
+
+	public:
+		/**
+		 * load an object and register it. If its already loaded return its pointer
+		 * @param fname The filename that initializes the object
+		 * @return A pointer of a new resource or NULL on fail
+		 */
+		Type* load(const char* fname);
+
+		/**
+		 * unload item. If nobody else uses it then delete it completely
+		 * @param x Pointer to the instance we want to unload
+		 */
+		void unload(Type* x);
+
+	private:
+		/**
+		 * Search inside the container by name
+		 * @param name The name of the resource
+		 * @return The iterator of the content end of vector if not found
+		 */
+		Iterator findByName(const char* name);
+
+		/**
+		 * Search inside the container by name and path
+		 * @param name The name of the resource
+		 * @param path The path of the resource
+		 * @return The iterator of the content end of vector if not found
+		 */
+		Iterator findByNameAndPath(const char* name, const char* path);
+
+		/**
+	   * Search inside the container by pointer
+		 * @param name The name of the resource object
+		 * @return The iterator of the content end of vector if not found
+		 */
+		Iterator findByPtr(Type* ptr);
+}; // end class ResourceContainer
+
+#include "ResourceContainer.inl.h"
+
+#endif

+ 113 - 0
src/Resources/ResourceContainer.inl.h

@@ -0,0 +1,113 @@
+#include "ResourceContainer.h"
+
+
+//======================================================================================================================
+// findByName                                                                                                          =
+//======================================================================================================================
+template<typename Type> typename ResourceContainer<Type>::Iterator ResourceContainer<Type>::findByName(const char* name)
+{
+	Iterator it = BaseClass::begin();
+	while(it != BaseClass::end())
+	{
+		if((*it).name == name)
+			return it;
+		++it;
+	}
+
+	return it;
+}
+
+
+//======================================================================================================================
+// findByNameAndPath                                                                                                   =
+//======================================================================================================================
+template<typename Type> typename ResourceContainer<Type>::Iterator ResourceContainer<Type>::findByNameAndPath(const char* name, const char* path)
+{
+	Iterator it = BaseClass::begin();
+	while(it != BaseClass::end())
+	{
+		if((*it)->name == name && (*it)->path == path)
+			return it;
+		++it;
+	}
+
+	return it;
+}
+
+
+//======================================================================================================================
+// findByPtr                                                                                                           =
+//======================================================================================================================
+template<typename Type> typename ResourceContainer<Type>::Iterator ResourceContainer<Type>::findByPtr(Type* ptr)
+{
+	Iterator it = BaseClass::begin();
+	while(it != BaseClass::end())
+	{
+		if(ptr == (*it))
+			return it;
+		++it;
+	}
+
+	return it;
+}
+
+
+//======================================================================================================================
+// load                                                                                                                =
+//======================================================================================================================
+template<typename Type> Type* ResourceContainer<Type>::load(const char* fname)
+{
+	char* name = Util::cutPath(fname);
+	string path = Util::getPath(fname);
+	Iterator it = findByNameAndPath(name, path.c_str());
+
+	// if already loaded then inc the users and return the pointer
+	if(it != BaseClass::end())
+	{
+		++ (*it)->usersNum;
+		return (*it);
+	}
+
+	// else create new, loaded and update the container
+	Type* newInstance = new Type();
+	newInstance->name = name;
+	newInstance->path = path;
+	newInstance->usersNum = 1;
+
+	if(!newInstance->load(fname))
+	{
+		ERROR("Cannot load \"" << fname << '\"');
+		delete newInstance;
+		return NULL;
+	}
+	BaseClass::push_back(newInstance);
+
+	return newInstance;
+}
+
+
+//======================================================================================================================
+// unload                                                                                                              =
+//======================================================================================================================
+template<typename Type> void ResourceContainer<Type>::unload(Type* x)
+{
+	Iterator it = findByPtr(x);
+	if(it == BaseClass::end())
+	{
+		ERROR("Cannot find resource with pointer 0x" << x);
+		return;
+	}
+
+	Type* del_ = (*it);
+	DEBUG_ERR(del_->usersNum < 1); // WTF?
+
+	--del_->usersNum;
+
+	// if no other users then call unload and update the container
+	if(del_->usersNum == 0)
+	{
+		del_->unload();
+		delete del_;
+		BaseClass::erase(it);
+	}
+}

+ 3 - 3
src/Scene/Light.cpp

@@ -10,7 +10,7 @@
 //======================================================================================================================
 //======================================================================================================================
 void PointLight::init(const char* filename)
 void PointLight::init(const char* filename)
 {
 {
-	lightProps = Rsrc::lightProps.load(filename);
+	lightProps = Resource::lightProps.load(filename);
 	radius = lightProps->getRadius();
 	radius = lightProps->getRadius();
 }
 }
 
 
@@ -20,7 +20,7 @@ void PointLight::init(const char* filename)
 //======================================================================================================================
 //======================================================================================================================
 void SpotLight::init(const char* filename)
 void SpotLight::init(const char* filename)
 {
 {
-	lightProps = Rsrc::lightProps.load(filename);
+	lightProps = Resource::lightProps.load(filename);
 	camera.setAll(lightProps->getFovX(), lightProps->getFovY(), 0.2, lightProps->getDistance());
 	camera.setAll(lightProps->getFovX(), lightProps->getFovY(), 0.2, lightProps->getDistance());
 	castsShadow = lightProps->castsShadow();
 	castsShadow = lightProps->castsShadow();
 	if(lightProps->getTexture() == NULL)
 	if(lightProps->getTexture() == NULL)
@@ -36,7 +36,7 @@ void SpotLight::init(const char* filename)
 //======================================================================================================================
 //======================================================================================================================
 void Light::deinit()
 void Light::deinit()
 {
 {
-	Rsrc::lightProps.unload(lightProps);
+	Resource::lightProps.unload(lightProps);
 }
 }
 
 
 
 

+ 4 - 4
src/Scene/MeshNode.cpp

@@ -15,8 +15,8 @@
 //======================================================================================================================
 //======================================================================================================================
 void MeshNode::init(const char* filename)
 void MeshNode::init(const char* filename)
 {
 {
-	mesh = Rsrc::meshes.load(filename);
-	material = Rsrc::materials.load(mesh->materialName.c_str());
+	mesh = Resource::meshes.load(filename);
+	material = Resource::materials.load(mesh->materialName.c_str());
 
 
 	// sanity checks
 	// sanity checks
 	if(material->stdAttribVars[Material::SAV_TEX_COORDS]!=NULL && mesh->vbos.texCoords.getGlId()==0)
 	if(material->stdAttribVars[Material::SAV_TEX_COORDS]!=NULL && mesh->vbos.texCoords.getGlId()==0)
@@ -33,8 +33,8 @@ void MeshNode::init(const char* filename)
 //======================================================================================================================
 //======================================================================================================================
 void MeshNode::deinit()
 void MeshNode::deinit()
 {
 {
-	Rsrc::meshes.unload(mesh);
-	Rsrc::materials.unload(material);
+	Resource::meshes.unload(mesh);
+	Resource::materials.unload(material);
 }
 }
 
 
 
 

+ 2 - 2
src/Scene/SkelNode.cpp

@@ -21,7 +21,7 @@ SkelNode::SkelNode():
 //======================================================================================================================
 //======================================================================================================================
 void SkelNode::init(const char* filename)
 void SkelNode::init(const char* filename)
 {
 {
-	skeleton = Rsrc::skeletons.load(filename);
+	skeleton = Resource::skeletons.load(filename);
 	skelAnimCtrl = new SkelAnimCtrl(this);
 	skelAnimCtrl = new SkelAnimCtrl(this);
 }
 }
 
 
@@ -31,7 +31,7 @@ void SkelNode::init(const char* filename)
 //======================================================================================================================
 //======================================================================================================================
 void SkelNode::deinit()
 void SkelNode::deinit()
 {
 {
-	Rsrc::skeletons.unload(skeleton);
+	Resource::skeletons.unload(skeleton);
 }
 }
 
 
 
 

+ 14 - 15
src/Ui/Ui.cpp

@@ -43,7 +43,6 @@ static void SetGL()
 
 
 	glEnable(GL_BLEND);
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glDisable(GL_LIGHTING);
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_DEPTH_TEST);
 	glColor4fv(color);
 	glColor4fv(color);
 
 
@@ -96,22 +95,22 @@ static void drawChar(char c)
 		c = '~'+1;
 		c = '~'+1;
 	}
 	}
 
 
-	const int charsPerLine = 16; // the chars that font_map.tga has per line
-	const int linesNum     = 8; // the lines of chars in font_map.tga
+	const int CHARS_PER_LINE = 16; // the chars that font_map.tga has per line
+	const int LINES_NUM      = 8; // the lines of chars in font_map.tga
 
 
 	// the uvs
 	// the uvs
-	float charWidth = 1.0/float(charsPerLine);
-	float charHeight = 1.0/float(linesNum);
-	float uvTop = float(linesNum - (c-' ')/charsPerLine) / float(linesNum);
-	float uvLeft = float((c-' ')%charsPerLine) / float(charsPerLine);
+	float charWidth = 1.0/float(CHARS_PER_LINE);
+	float charHeight = 1.0/float(LINES_NUM);
+	float uvTop = float(LINES_NUM - (c-' ')/CHARS_PER_LINE) / float(LINES_NUM);
+	float uvLeft = float((c-' ')%CHARS_PER_LINE) / float(CHARS_PER_LINE);
 	float uvRight = uvLeft + charWidth;
 	float uvRight = uvLeft + charWidth;
 	float uvBottom = uvTop - charHeight;
 	float uvBottom = uvTop - charHeight;
-	float uvs[4][2] = { {uvLeft, uvTop}, {uvLeft, uvBottom}, {uvRight, uvBottom}, {uvRight, uvTop} };
+	float uvs[4][2] = {{uvLeft, uvTop}, {uvLeft, uvBottom}, {uvRight, uvBottom}, {uvRight, uvTop}};
 
 
 	// the coords
 	// the coords
-	float fwh = fontW/2.0;
-	float fhh = fontH/2.0;
-	float coords[4][2] = { {-fwh, fhh}, {-fwh, -fhh}, {fwh, -fhh}, {fwh, fhh} }; // fron top left counterclockwise
+	float fwh = fontW/2.0 + crntX;
+	float fhh = fontH/2.0 + crntY;
+	float coords[4][2] = {{-fwh, fhh}, {-fwh, -fhh}, {fwh, -fhh}, {fwh, fhh}}; // from top left counterclockwise
 
 
 
 
 	if(italic)
 	if(italic)
@@ -160,10 +159,10 @@ non static funcs
 // exec after init SDL
 // exec after init SDL
 void init()
 void init()
 {
 {
-	fontMap = Rsrc::textures.load("gfx/fontmapa.tga");
+	fontMap = Resource::textures.load("gfx/fontmapa.tga");
 	fontMap->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	fontMap->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	//font_map->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	//font_map->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	shader = Rsrc::shaders.load("shaders/txt.glsl");
+	shader = Resource::shaders.load("shaders/txt.glsl");
 	setPos(0.0, 0.0);
 	setPos(0.0, 0.0);
 	setFontWidth(0.05);
 	setFontWidth(0.05);
 	setColor(Vec4(1.0, 1.0, 1.0, 1.0));
 	setColor(Vec4(1.0, 1.0, 1.0, 1.0));
@@ -215,11 +214,11 @@ void printf(const char* format, ...)
 void print(const char* text)
 void print(const char* text)
 {
 {
 	SetGL();
 	SetGL();
-	glTranslatef(crntX, crntY, 0.0);
+	//glTranslatef(crntX, crntY, 0.0);
 	for(char* pc=const_cast<char*>(text); *pc!='\0'; pc++)
 	for(char* pc=const_cast<char*>(text); *pc!='\0'; pc++)
 	{
 	{
 		glLoadIdentity();
 		glLoadIdentity();
-		glTranslatef(crntX, crntY, 0.0);
+		//glTranslatef(crntX, crntY, 0.0);
 		drawChar(*pc);
 		drawChar(*pc);
 	}
 	}
 	RestoreGL();
 	RestoreGL();

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików