Browse Source

- Moving material resource from mesh node to mesh resource
- Removing generation of mipmaps in empty tex creation

Panagiotis Christopoulos Charitos 15 năm trước cách đây
mục cha
commit
d431c58c8f

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 428 - 426
build/debug/Makefile


+ 8 - 8
src/Renderer/Bs.cpp

@@ -50,7 +50,7 @@ void Renderer::Bs::createRefractFbo()
 void Renderer::Bs::init()
 {
 	createFbo();
-	refractFai.createEmpty2D(r.width, r.height, GL_RGBA8, GL_RGBA, GL_FLOAT, false);
+	refractFai.createEmpty2D(r.width, r.height, GL_RGBA8, GL_RGBA, GL_FLOAT);
 	createRefractFbo();
 
 	refractSProg.loadRsrc("shaders/BsRefract.glsl");
@@ -71,16 +71,16 @@ void Renderer::Bs::run()
 	{
 		MeshNode* meshNode = (*it);
 
-		if(meshNode->material.get() == NULL)
+		if(meshNode->mesh->material.get() == NULL)
 		{
 			ERROR("Mesh \"" << meshNode->mesh->getRsrcName() << "\" doesnt have material" );
 			continue;
 		}
 
-		if(!meshNode->material->blends) continue;
+		if(!meshNode->mesh->material->blends) continue;
 
 		// refracts
-		if(meshNode->material->stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
+		if(meshNode->mesh->material->stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
 		{
 			// render to the temp FAI
 			refractFbo.bind();
@@ -90,7 +90,7 @@ void Renderer::Bs::run()
 			glStencilFunc(GL_ALWAYS, 0x1, 0x1);
 			glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
 
-			r.setupMaterial(*meshNode->material, *meshNode, *r.cam);
+			r.setupMaterial(*meshNode->mesh->material, *meshNode, *r.cam);
 			glDisable(GL_BLEND); // a hack
 			meshNode->render();
 
@@ -100,10 +100,10 @@ void Renderer::Bs::run()
 			glStencilFunc(GL_EQUAL, 0x1, 0x1);
 			glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
 
-			if(meshNode->material->blends)
+			if(meshNode->mesh->material->blends)
 			{
 				glEnable(GL_BLEND);
-				glBlendFunc(meshNode->material->blendingSfactor, meshNode->material->blendingDfactor);
+				glBlendFunc(meshNode->mesh->material->blendingSfactor, meshNode->mesh->material->blendingDfactor);
 			}
 			else
 				glDisable(GL_BLEND);
@@ -122,7 +122,7 @@ void Renderer::Bs::run()
 		else
 		{
 			fbo.bind();
-			r.setupMaterial(*meshNode->material, *meshNode, *r.cam);
+			r.setupMaterial(*meshNode->mesh->material, *meshNode, *r.cam);
 			meshNode->render();
 		}
 	}

+ 4 - 3
src/Renderer/Ez.cpp

@@ -52,11 +52,12 @@ void Renderer::Ms::Ez::run()
 	for(Vec<MeshNode*>::iterator it=app->getScene()->meshNodes.begin(); it!=app->getScene()->meshNodes.end(); it++)
 	{
 		MeshNode* meshNode = (*it);
-		if(meshNode->material->blends) continue;
+		if(meshNode->mesh->material->blends)
+			continue;
 
-		DEBUG_ERR(meshNode->material->dpMtl.get() == NULL);
+		DEBUG_ERR(meshNode->mesh->material->dpMtl.get() == NULL);
 
-		r.setupMaterial(*meshNode->material->dpMtl, *meshNode, *r.cam);
+		r.setupMaterial(*meshNode->mesh->material->dpMtl, *meshNode, *r.cam);
 		meshNode->renderDepth();
 	}
 

+ 1 - 1
src/Renderer/Hdr.cpp

@@ -24,7 +24,7 @@ void Renderer::Pps::Hdr::initFbos(Fbo& fbo, Texture& fai, int internalFormat)
 	fbo.setNumOfColorAttachements(1);
 
 	// create the texes
-	fai.createEmpty2D(width, height, internalFormat, GL_RGB, GL_FLOAT, false);
+	fai.createEmpty2D(width, height, internalFormat, GL_RGB, GL_FLOAT);
 	fai.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	//fai_.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);

+ 1 - 1
src/Renderer/Is.cpp

@@ -81,7 +81,7 @@ void Renderer::Is::initFbo()
 	fbo.setNumOfColorAttachements(1);
 
 	// create the txtrs
-	if(!fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT, false))
+	if(!fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT))
 		FATAL("Cannot create deferred shading illumination stage FAI");
 
 	// attach

+ 7 - 7
src/Renderer/Ms.cpp

@@ -18,10 +18,10 @@ void Renderer::Ms::init()
 	fbo.setNumOfColorAttachements(3);
 
 	// create the FAIs
-	if(!normalFai.createEmpty2D(r.width, r.height, GL_RG16F, GL_RG, GL_FLOAT, false) ||
-	   !diffuseFai.createEmpty2D(r.width, r.height, GL_RGB16F, GL_RGB, GL_FLOAT, false) ||
-	   !specularFai.createEmpty2D(r.width, r.height, GL_RGBA16F, GL_RGBA, GL_FLOAT, false) ||
-	   !depthFai.createEmpty2D(r.width, r.height, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false))
+	if(!normalFai.createEmpty2D(r.width, r.height, GL_RG16F, GL_RG, GL_FLOAT) ||
+	   !diffuseFai.createEmpty2D(r.width, r.height, GL_RGB16F, GL_RGB, GL_FLOAT) ||
+	   !specularFai.createEmpty2D(r.width, r.height, GL_RGBA16F, GL_RGBA, GL_FLOAT) ||
+	   !depthFai.createEmpty2D(r.width, r.height, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8))
 	   //!depthFai.createEmpty2D(r.width, r.height, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false))
 	{
 		FATAL("Failed to create one MS FAI. See prev error");
@@ -91,14 +91,14 @@ void Renderer::Ms::run()
 	for(Vec<MeshNode*>::iterator it=app->getScene()->meshNodes.begin(); it!=app->getScene()->meshNodes.end(); it++)
 	{
 		MeshNode* meshNode = (*it);
-		if(meshNode->material.get() == NULL)
+		if(meshNode->mesh->material.get() == NULL)
 		{
 			ERROR("Mesh \"" << meshNode->mesh->getRsrcName() << "\" doesnt have material" );
 			continue;
 		}
-		if(meshNode->material->blends) continue;
+		if(meshNode->mesh->material->blends) continue;
 
-		r.setupMaterial(*meshNode->material, *meshNode, cam);
+		r.setupMaterial(*meshNode->mesh->material, *meshNode, cam);
 		meshNode->render();
 	}
 

+ 1 - 1
src/Renderer/Pps.cpp

@@ -17,7 +17,7 @@ void Renderer::Pps::initPassFbo(Fbo& fbo, Texture& fai, const char* msg)
 
 	fbo.setNumOfColorAttachements(1);
 
-	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);
 	fai.setRepeat(false);
 
 	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);

+ 4 - 4
src/Renderer/Sm.cpp

@@ -21,7 +21,7 @@ void Renderer::Is::Sm::init()
 	fbo.bind();
 
 	// texture
-	shadowMap.createEmpty2D(resolution, resolution, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, true);
+	shadowMap.createEmpty2D(resolution, resolution, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT);
 	shadowMap.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	if(bilinearEnabled)
 	{
@@ -80,11 +80,11 @@ void Renderer::Is::Sm::run(const Camera& cam)
 	for(Vec<MeshNode*>::iterator it=app->getScene()->meshNodes.begin(); it!=app->getScene()->meshNodes.end(); it++)
 	{
 		MeshNode* meshNode = (*it);
-		if(meshNode->material->blends) continue;
+		if(meshNode->mesh->material->blends) continue;
 
-		DEBUG_ERR(meshNode->material->dpMtl.get() == NULL);
+		DEBUG_ERR(meshNode->mesh->material->dpMtl.get() == NULL);
 
-		r.setupMaterial(*meshNode->material->dpMtl, *meshNode, cam);
+		r.setupMaterial(*meshNode->mesh->material->dpMtl, *meshNode, cam);
 		meshNode->renderDepth();
 	}
 

+ 2 - 2
src/Renderer/Ssao.cpp

@@ -22,7 +22,7 @@ void Renderer::Pps::Ssao::initBlurFbo(Fbo& fbo, Texture& fai)
 	fbo.setNumOfColorAttachements(1);
 
 	// create the texes
-	fai.createEmpty2D(bwidth, bheight, GL_ALPHA8, GL_ALPHA, GL_FLOAT, false);
+	fai.createEmpty2D(bwidth, bheight, GL_ALPHA8, GL_ALPHA, GL_FLOAT);
 	fai.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
@@ -60,7 +60,7 @@ void Renderer::Pps::Ssao::init()
 	pass0Fbo.setNumOfColorAttachements(1);
 
 	// create the FAI
-	pass0Fai.createEmpty2D(width, height, GL_ALPHA8, GL_ALPHA, GL_FLOAT, false);
+	pass0Fai.createEmpty2D(width, height, GL_ALPHA8, GL_ALPHA, GL_FLOAT);
 	pass0Fai.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	pass0Fai.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 

+ 5 - 5
src/Resources/Core/RsrcPtr.cpp

@@ -12,12 +12,12 @@
 
 namespace RsrcContainers {
 
-extern RsrcContainer<Texture>    textures;
+extern RsrcContainer<Texture> textures;
 extern RsrcContainer<ShaderProg> shaderProgs;
-extern RsrcContainer<Material>   materials;
-extern RsrcContainer<Mesh>       meshes;
-extern RsrcContainer<Skeleton>   skeletons;
-extern RsrcContainer<SkelAnim>   skelAnims;
+extern RsrcContainer<Material> materials;
+extern RsrcContainer<Mesh> meshes;
+extern RsrcContainer<Skeleton> skeletons;
+extern RsrcContainer<SkelAnim> skelAnims;
 extern RsrcContainer<LightProps> lightProps;
 extern RsrcContainer<ParticleEmitterProps> particleEmitterProps;
 

+ 5 - 4
src/Resources/Core/RsrcPtr.h

@@ -1,13 +1,12 @@
-#ifndef RSRCPTR_H
-#define RSRCPTR_H
+#ifndef RSRC_PTR_H
+#define RSRC_PTR_H
 
 #include "Common.h"
 
 
 /**
  * This is a special smart pointer that points to Resource derivatives. It looks like auto_ptr but the main difference
- * is that when its out of scope it tries to unload the resource. The bad thing about this pointer it contains an ugly
- * hack. Without this hack we should have build our own version of auto_ptr
+ * is that when its out of scope it tries to unload the resource.
  */
 template<typename Type>
 class RsrcPtr
@@ -68,6 +67,7 @@ RsrcPtr<Type>::~RsrcPtr()
 template<typename Type>
 Type& RsrcPtr<Type>::operator*() const
 {
+	DEBUG_ERR(p == NULL);
 	return *p;
 }
 
@@ -75,6 +75,7 @@ Type& RsrcPtr<Type>::operator*() const
 template<typename Type>
 Type* RsrcPtr<Type>::operator->() const
 {
+	DEBUG_ERR(p == NULL);
 	return p;
 }
 

+ 1 - 0
src/Resources/Material.h

@@ -24,6 +24,7 @@
 class Material: public Resource
 {
 	friend class Renderer; ///< For the setupMaterial
+	friend class Mesh;
 	friend class MeshNode;
 
 	private:

+ 61 - 27
src/Resources/Mesh.cpp

@@ -3,6 +3,7 @@
 #include "Resource.h"
 #include "Scanner.h"
 #include "Parser.h"
+#include "Material.h"
 
 
 //======================================================================================================================
@@ -11,30 +12,26 @@
 bool Mesh::load(const char* filename)
 {
 	Scanner scanner;
-	if(!scanner.loadFile(filename)) return false;
+	if(!scanner.loadFile(filename))
+		return false;
 
 	const Scanner::Token* token;
 
-
-	//** MATERIAL **
+	/*
+	 * Material
+	 */
 	token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_STRING)
 	{
 		PARSE_ERR_EXPECTED("string");
 		return false;
 	}
-	materialName = token->getValue().getString();
+	if(strlen(token->getValue().getString()) > 0)
+		material.loadRsrc(token->getValue().getString());
 
-	//** DP_MATERIAL **
-	/*token = &scanner.getNextToken();
-	if(token->getCode() != Scanner::TC_STRING)
-	{
-		PARSE_ERR_EXPECTED("string");
-		return false;
-	}
-	dp_materialName = token->getValue().getString();*/
-
-	//** VERTS **
+	/*
+	 * Verts
+	 */
 	// verts num
 	token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_NUMBER || token->getDataType() != Scanner::DT_INT)
@@ -47,10 +44,13 @@ bool Mesh::load(const char* filename)
 	// read the verts
 	for(uint i=0; i<vertCoords.size(); i++)
 	{
-		if(!Parser::parseArrOfNumbers<float>(scanner, false, true, 3, &vertCoords[i][0])) return false;
+		if(!Parser::parseArrOfNumbers<float>(scanner, false, true, 3, &vertCoords[i][0]))
+			return false;
 	}
 
-	//** FACES **
+	/*
+	 * Faces
+	 */
 	// faces num
 	token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_NUMBER || token->getDataType() != Scanner::DT_INT)
@@ -62,10 +62,13 @@ bool Mesh::load(const char* filename)
 	// read the faces
 	for(uint i=0; i<tris.size(); i++)
 	{
-		if(!Parser::parseArrOfNumbers<uint>(scanner, false, true, 3, tris[i].vertIds)) return false;
+		if(!Parser::parseArrOfNumbers<uint>(scanner, false, true, 3, tris[i].vertIds))
+			return false;
 	}
 
-	//** UVS **
+	/*
+	 * Tex coords
+	 */
 	// UVs num
 	token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_NUMBER || token->getDataType() != Scanner::DT_INT)
@@ -77,10 +80,13 @@ bool Mesh::load(const char* filename)
 	// read the texCoords
 	for(uint i=0; i<texCoords.size(); i++)
 	{
-		if(!Parser::parseArrOfNumbers(scanner, false, true, 2, &texCoords[i][0])) return false;
+		if(!Parser::parseArrOfNumbers(scanner, false, true, 2, &texCoords[i][0]))
+			return false;
 	}
 
-	//** VERTEX WEIGHTS **
+	/*
+	 * Vert weights
+	 */
 	token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_NUMBER || token->getDataType() != Scanner::DT_INT)
 	{
@@ -153,11 +159,32 @@ bool Mesh::load(const char* filename)
 		return false;
 	}
 
-	createAllNormals();
-	if(texCoords.size() > 0) createVertTangents();
-	createVertIndeces();
-	createVbos();
-	calcBSphere();
+	if(isRenderable())
+	{
+		createAllNormals();
+		if(texCoords.size() > 0)
+			createVertTangents();
+		createVertIndeces();
+		createVbos();
+		calcBSphere();
+
+		/*
+		 * Sanity checks continued
+		 */
+		if(material->stdAttribVars[Material::SAV_TEX_COORDS] != NULL && !vbos.texCoords.isCreated())
+		{
+			ERROR("The shader program (\"" << material->shaderProg->getRsrcName() <<
+						 "\") needs texture coord information that the mesh (\"" <<
+						 getRsrcName() << "\") doesn't have");
+		}
+
+		if(material->hasHWSkinning() && !vbos.vertWeights.isCreated())
+		{
+			ERROR("The shader program (\"" << material->shaderProg->getRsrcName() <<
+						 "\") needs vertex weights that the mesh (\"" <<
+						 getRsrcName() << "\") doesn't have");
+		}
+	}
 
 	return true;
 }
@@ -299,8 +326,6 @@ void Mesh::createVertTangents()
 
 		vertTangents[i] = Vec4(t, w);
 	}
-
-	bitagents.clear();
 }
 
 
@@ -328,3 +353,12 @@ void Mesh::calcBSphere()
 {
 	bsphere.Set(&vertCoords[0], 0, vertCoords.size());
 }
+
+
+//======================================================================================================================
+// isRenderable                                                                                                        =
+//======================================================================================================================
+bool Mesh::isRenderable() const
+{
+	return material.get() != NULL;
+}

+ 41 - 16
src/Resources/Mesh.h

@@ -1,19 +1,26 @@
-#ifndef _MESH_H_
-#define _MESH_H_
+#ifndef MESH_H
+#define MESH_H
 
 #include "Common.h"
 #include "Math.h"
 #include "Vbo.h"
 #include "Resource.h"
 #include "collision.h"
+#include "RsrcPtr.h"
+
+
+class Material;
 
 
 /**
- * Mesh @ref Resource
+ * Mesh @ref Resource. If the material name is empty then the mesh wont be rendered and no VBOs will be created
  */
 class Mesh: public Resource
 {
 	public:
+		/**
+		 * Vertex weight for skeletan animation
+		 */
 		class VertexWeight
 		{
 			public:
@@ -25,6 +32,9 @@ class Mesh: public Resource
 				float weights[MAX_BONES_PER_VERT];
 		};
 
+		/**
+		 * Triangle
+		 */
 		class Triangle
 		{
 			public:
@@ -32,7 +42,10 @@ class Mesh: public Resource
 				Vec3 normal;
 		};
 
-		struct
+		/**
+		 * The VBOs in a structure
+		 */
+		struct Vbos
 		{
 			Vbo vertCoords;
 			Vbo vertNormals;
@@ -40,28 +53,34 @@ class Mesh: public Resource
 			Vbo texCoords;
 			Vbo vertIndeces;
 			Vbo vertWeights;
-		} vbos;
+		};
 
 	public:
-		Vec<Vec3>         vertCoords;
-		Vec<Vec3>         vertNormals;
-		Vec<Vec4>         vertTangents;
-		Vec<Vec2>         texCoords;    ///< One for every vert so we can use vertex arrays & VBOs
-		Vec<VertexWeight> vertWeights;
-		Vec<Triangle>     tris;
-		Vec<ushort>       vertIndeces; ///< Used for vertex arrays & VBOs
-		string            materialName;
-		bsphere_t         bsphere;
+		Vec<Vec3>         vertCoords; ///< Required
+		Vec<Vec3>         vertNormals; ///< Generated if renderable
+		Vec<Vec4>         vertTangents; ///< Generated if renderable
+		Vec<Vec2>         texCoords;    ///< Optional. One for every vert so we can use vertex arrays & VBOs
+		Vec<VertexWeight> vertWeights; ///< Optional
+		Vec<Triangle>     tris; ///< Required
+		Vec<ushort>       vertIndeces; ///< Generated if renderable. Used for vertex arrays & VBOs
+		Vbos              vbos; ///< Generated if renderable
+		RsrcPtr<Material> material; ///< Required. If empty then mesh not renderable
+		bsphere_t         bsphere; ///< @todo
 
 		Mesh();
 		~Mesh() {}
 		bool load(const char* filename);
 		void unload();
 
-	protected:
+		/**
+		 * The mesh is renderable when the material is loaded
+		 */
+		bool isRenderable() const;
+
+	private:
 		void createFaceNormals();
 		void createVertNormals();
-		void createAllNormals() { createFaceNormals(); createVertNormals(); }
+		void createAllNormals();
 		void createVertTangents();
 		void createVertIndeces();
 		void createVbos();
@@ -74,4 +93,10 @@ inline Mesh::Mesh():
 {}
 
 
+inline void Mesh::createAllNormals()
+{
+	createFaceNormals();
+	createVertNormals();
+}
+
 #endif

+ 18 - 25
src/Resources/Texture.cpp

@@ -4,9 +4,7 @@
 #include "Image.h"
 
 
-#define STD_CHECKS \
-	DEBUG_ERR(lastBindTexUnit != getActiveTexUnit()); \
-	DEBUG_ERR(glId != getBindedTexId(getActiveTexUnit())); ///@todo
+#define LAST_TEX_UNIT (textureUnitsNum - 1)
 
 
 //======================================================================================================================
@@ -41,12 +39,12 @@ bool Texture::load(const char* filename)
 	}
 
 	Image img;
-	if(!img.load(filename)) return false;
-
+	if(!img.load(filename))
+		return false;
 
 	// bind the texture
 	glGenTextures(1, &glId);
-	bind(0);
+	bind(LAST_TEX_UNIT);
 	if(mipmappingEnabled)
 		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
 	else
@@ -98,31 +96,23 @@ bool Texture::load(const char* filename)
 //======================================================================================================================
 // createEmpty2D                                                                                                       =
 //======================================================================================================================
-bool Texture::createEmpty2D(float width_, float height_, int internalFormat, int format_, GLenum type_, bool mimapping)
+bool Texture::createEmpty2D(float width_, float height_, int internalFormat, int format_, GLenum type_)
 {
 	target = GL_TEXTURE_2D;
-	DEBUG_ERR(internalFormat>0 && internalFormat<=4); // deprecated internal format
+	DEBUG_ERR(internalFormat > 0 && internalFormat <= 4); // deprecated internal format
 	DEBUG_ERR(isLoaded());
 
 	// GL stuff
 	glGenTextures(1, &glId);
-	bind();
-
-	if(mimapping)
-		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-	else
-		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	bind(LAST_TEX_UNIT);
 
+	setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	setRepeat(true);
 
-
 	// allocate to vram
 	glTexImage2D(target, 0, internalFormat, width_, height_, 0, format_, type_, NULL);
 
-	if(mimapping)
-		glGenerateMipmap(target);
-
 	return GL_OK();
 }
 
@@ -136,7 +126,7 @@ bool Texture::createEmpty2DMsaa(int samplesNum, int internalFormat, int width_,
 	DEBUG_ERR(isLoaded());
 
 	glGenTextures(1, &glId);
-	bind();
+	bind(LAST_TEX_UNIT);
 	
 	// allocate
 	glTexImage2DMultisample(target, samplesNum, internalFormat, width_, height_, false);
@@ -176,7 +166,7 @@ void Texture::bind(uint unit) const
 //======================================================================================================================
 int Texture::getWidth() const
 {
-	bind();
+	bind(LAST_TEX_UNIT);
 	int i;
 	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &i);
 	return i;
@@ -188,7 +178,7 @@ int Texture::getWidth() const
 //======================================================================================================================
 int Texture::getHeight() const
 {
-	bind();
+	bind(LAST_TEX_UNIT);
 	int i;
 	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &i);
 	return i;
@@ -200,7 +190,7 @@ int Texture::getHeight() const
 //======================================================================================================================
 void Texture::setTexParameter(GLenum paramName, GLint value) const
 {
-	bind();
+	bind(LAST_TEX_UNIT);
 	glTexParameteri(target, paramName, value);
 }
 
@@ -210,7 +200,7 @@ void Texture::setTexParameter(GLenum paramName, GLint value) const
 //======================================================================================================================
 void Texture::texParameter(GLenum paramName, GLfloat value) const
 {
-	bind();
+	bind(LAST_TEX_UNIT);
 	glTexParameterf(target, paramName, value);
 }
 
@@ -220,7 +210,7 @@ void Texture::texParameter(GLenum paramName, GLfloat value) const
 //======================================================================================================================
 void Texture::setRepeat(bool repeat) const
 {
-	bind();
+	bind(LAST_TEX_UNIT);
 	if(repeat)
 	{
 		setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -239,7 +229,10 @@ void Texture::setRepeat(bool repeat) const
 //======================================================================================================================
 int Texture::getBaseLevel() const
 {
-
+	bind(LAST_TEX_UNIT);
+	int level;
+	glGetTexParameteriv(target, GL_TEXTURE_BASE_LEVEL, &level);
+	return level;
 }
 
 

+ 12 - 3
src/Resources/Texture.h

@@ -12,6 +12,8 @@
  *
  * It loads or creates an image and then loads it in the GPU. Its an OpenGL container. It supports compressed and
  * uncompressed TGAs and all formats of PNG (PNG loading comes through SDL_image)
+ *
+ * @note The last texture unit is reserved and you cannot use it
  */
 class Texture: public Resource
 {
@@ -28,7 +30,7 @@ class Texture: public Resource
 
 		bool load(const char* filename);
 		void unload();
-		bool createEmpty2D(float width, float height, int internalFormat, int format, GLenum type_, bool mipmapping);
+		bool createEmpty2D(float width, float height, int internalFormat, int format, GLenum type_);
 		bool createEmpty2DMsaa(int samplesNum, int internalFormat, int width_, int height_, bool mimapping);
 
 		void bind(uint texUnit = 0) const;
@@ -39,13 +41,20 @@ class Texture: public Resource
 		static uint getActiveTexUnit();
 		static uint getBindedTexId(uint unit);
 
-	protected:
+	private:
 		GLuint glId; ///< Identification for OGL
 		GLenum target; ///< GL_TEXTURE_2D, GL_TEXTURE_3D... etc
-		static int  textureUnitsNum; ///< This needs to be filled in OpenGL initialization
+
+		/**
+		 * @name Variables set by the renderer
+		 * Set upon OpenGL initialization
+		 */
+		/**@{*/
+		static int  textureUnitsNum;
 		static bool mipmappingEnabled;
 		static bool compressionEnabled;
 		static int  anisotropyLevel;
+		/**@}*/
 
 		bool isLoaded() const;
 };

+ 0 - 16
src/Scene/MeshNode.cpp

@@ -16,22 +16,6 @@
 void MeshNode::init(const char* filename)
 {
 	mesh.loadRsrc(filename);
-	material.loadRsrc(mesh->materialName.c_str());
-
-	// sanity checks
-	if(material->stdAttribVars[Material::SAV_TEX_COORDS]!=NULL && !mesh->vbos.texCoords.isCreated())
-	{
-		ERROR("The shader program (\"" << material->shaderProg->getRsrcName() <<
-		       "\") needs texture coord information that the mesh (\"" <<
-		       mesh->getRsrcName() << "\") doesn't have");
-	}
-
-	if(material->hasHWSkinning() && !mesh->vbos.vertWeights.isCreated())
-	{
-		ERROR("The shader program (\"" << material->shaderProg->getRsrcName() <<
-		       "\") needs vertex weights that the mesh (\"" <<
-		       mesh->getRsrcName() << "\") doesn't have");
-	}
 }
 
 

+ 2 - 4
src/Scene/MeshNode.h

@@ -18,14 +18,12 @@ class MeshNode: public SceneNode
 	public:
 		// resources
 		RsrcPtr<Mesh> mesh;
-		RsrcPtr<Material> material;
-		RsrcPtr<Material> dpMaterial; ///< Depth pass material
 		// controllers
 		MeshSkelNodeCtrl* meshSkelCtrl;
 		// funcs
 		MeshNode();
-		virtual void render() { render(material.get()); }
-		virtual void renderDepth() { render(material->dpMtl.get()); }
+		virtual void render() { render(mesh->material.get()); }
+		virtual void renderDepth() { render(mesh->material->dpMtl.get()); }
 		void init(const char* filename);
 };
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác