瀏覽代碼

- Thank to Joan for making it build to MacOS
- Updating CMake files to link to MacOS
- Fixing incorrect offset calculation on AnKi textures loading
- Fising incorrect placement of the mipmaps depth in the ankitexture.py
- Lens flare seem to work. Tweaking begins

Panagiotis Christopoulos Charitos 12 年之前
父節點
當前提交
89465c34c0

+ 10 - 3
include/anki/core/NativeWindow.h

@@ -14,20 +14,27 @@ struct ContextImpl;
 /// Window initializer
 struct NativeWindowInitializer
 {
+	U32 width = 640;
+	U32 height = 768;
 	Array<U32, 4> rgbaBits = {{8, 8, 8, 8}};
 	U32 depthBits = 24;
 	U32 stencilBits = 8;
 	U32 samplesCount = 0;
 	static const Bool doubleBuffer = true;
+	/// Create a fullscreen window with the desktop's resolution
 	Bool fullscreenDesktopRez = false;
 
+	/// @name GL context properties
+	/// @{
+
+	/// Minor OpenGL version. Used to create core profile context
 	U32 minorVersion = 0;
-	U32 majorVersion = 0;
+	/// Major OpenGL version. Used to create core profile context
+	U32 majorVersion = 0; 
 	Bool useGles = false; ///< Use OpenGL ES
 	Bool debugContext = false; ///< Enables KHR_debug
+	/// @}
 
-	U32 width = 640;
-	U32 height = 768;
 	std::string title = "Untitled window";
 };
 

+ 1 - 1
include/anki/resource/Material.h

@@ -177,7 +177,7 @@ class MaterialProperties
 public:
 	/// @name Accessors
 	/// @{
-	uint getRenderingStage() const
+	U32 getRenderingStage() const
 	{
 		return renderingStage;
 	}

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

@@ -107,7 +107,7 @@ public:
 		return vertWeights;
 	}
 
-	const Vector<ushort>& getIndices() const
+	const Vector<U16>& getIndices() const
 	{
 		return vertIndices;
 	}

+ 4 - 4
include/anki/resource/SkelAnim.h

@@ -90,12 +90,12 @@ class SkelAnim
 public:
 	/// @name Accessors
 	/// @{
-	const Vector<uint>& getKeyframes() const
+	const Vector<U32>& getKeyframes() const
 	{
 		return keyframes;
 	}
 
-	uint getFramesNum() const
+	U32 getFramesNum() const
 	{
 		return framesNum;
 	}
@@ -110,8 +110,8 @@ public:
 	void load(const char* filename);
 
 private:
-	Vector<uint> keyframes;
-	uint framesNum;
+	Vector<U32> keyframes;
+	U32 framesNum;
 	Vector<BoneAnim> boneAnims;
 };
 

+ 1 - 1
include/anki/resource/Skeleton.h

@@ -27,7 +27,7 @@ public:
 
 private:
 	std::string name; ///< The name of the bone
-	static const uint MAX_CHILDS_PER_BONE = 4; ///< Please dont change this
+	static const U32 MAX_CHILDS_PER_BONE = 4; ///< Please dont change this
 
 	// see the class notes
 	Mat4 transform;

+ 2 - 2
include/anki/scene/SkinNode.h

@@ -138,7 +138,7 @@ public:
 	/// @{
 	SkinPatchNode(const ModelPatchBase* modelPatch_,
 		const char* name, SceneGraph* scene, // Scene
-		uint movableFlags, Movable* movParent, // Movable
+		U32 movableFlags, Movable* movParent, // Movable
 		CollisionShape* spatialCs); // Spatial
 	/// @}
 
@@ -188,7 +188,7 @@ public:
 	/// @{
 	SkinNode(const char* skinFname,
 		const char* name, SceneGraph* scene, // SceneNode
-		uint movableFlags, Movable* movParent); // Movable
+		U32 movableFlags, Movable* movParent); // Movable
 
 	~SkinNode();
 	/// @}

+ 8 - 4
src/CMakeLists.txt

@@ -12,13 +12,17 @@ ENDFOREACH()
 
 ADD_LIBRARY(anki Dummy.cpp)
 
-IF(ANKI_WINDOW_BACKEND STREQUAL "GLXX11" OR ANKI_WINDOW_BACKEND STREQUAL "MACOS")
-	SET(ANKI_LIBS ${ANKI_LIBS} ankiglew GL)
+# Set the platform GL libraries
+IF(ANKI_WINDOW_BACKEND STREQUAL "GLXX11")
+	SET(_GL GL ankiglew)
+ELSEIF(ANKI_WINDOW_BACKEND STREQUAL "MACOS")
+	FIND_PACKAGE(OpenGL REQUIRED)
+	SET(_GL ${OPENGL_LIBRARIES} ankiglew)
 ELSE()
-	SET(ANKI_LIBS ${ANKI_LIBS} GLESv2 EGL mali)
+	SET(_GL GLESv2 EGL mali)
 ENDIF()
 
-TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} ankitinyxml2 ankilua ankibullet ${_ANKI_LIBPNG} ${ANKI_GPERFTOOLS_LIBS} pthread)
+TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} ankitinyxml2 ankilua ankibullet ${_ANKI_LIBPNG} ${ANKI_GPERFTOOLS_LIBS} pthread ${_GL})
 
 SET_TARGET_PROPERTIES(anki PROPERTIES LINKER_LANGUAGE CXX)
 

+ 5 - 5
src/renderer/DebugDrawer.cpp

@@ -267,12 +267,12 @@ void DebugDrawer::drawCube(F32 size)
 		Vec3(maxPos.x(), minPos.y(), minPos.z())   // right bottom back
 	}};
 
-	static const Array<uint, 24> indeces = {{
+	static const Array<U32, 24> indeces = {{
 		0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 
 		6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7}};
 
 	begin();
-		for(uint id : indeces)
+		for(U32 id : indeces)
 		{
 			pushBackVertex(points[id]);
 		}
@@ -333,7 +333,7 @@ void CollisionDebugDrawer::visit(const Aabb& aabb)
 
 	Mat4 trf = Mat4::getIdentity();
 	// Scale
-	for(uint i = 0; i < 3; ++i)
+	for(U32 i = 0; i < 3; ++i)
 	{
 		trf(i, i) = max[i] - min[i];
 	}
@@ -371,11 +371,11 @@ void CollisionDebugDrawer::visit(const Frustum& f)
 				Vec3(tmp0, tmp1, -camLen) // 4: top right
 			};
 
-			const uint indeces[] = {0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2,
+			const U32 indeces[] = {0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2,
 				3, 3, 4, 4, 1};
 
 			dbg->begin();
-			for(uint i = 0; i < sizeof(indeces) / sizeof(uint); i++)
+			for(U32 i = 0; i < sizeof(indeces) / sizeof(U32); i++)
 			{
 				dbg->pushBackVertex(points[indeces[i]]);
 			}

+ 26 - 10
src/resource/Image.cpp

@@ -470,11 +470,35 @@ static PtrSize calcSizeOfSegment(const AnkiTextureHeader& header,
 	U width = header.width;
 	U height = header.height;
 	U mips = header.mipLevels;
+	U layers;
+
+	switch(header.type)
+	{
+	case Image::TT_2D:
+		layers = 1;
+		break;
+	case Image::TT_CUBE:
+		layers = 6;
+		break;
+	case Image::TT_2D_ARRAY:
+	case Image::TT_3D:
+		layers = header.depth;
+		break;
+	default:
+		ANKI_ASSERT(0);
+		break;
+	}
 
 	while(mips-- != 0)
 	{
-		out += calcSurfaceSize(width, height, comp, 
-			(Image::ColorFormat)header.colorFormat);
+		U l = layers;
+
+		while(l-- != 0)
+		{
+			out += calcSurfaceSize(width, height, comp, 
+				(Image::ColorFormat)header.colorFormat);
+		}
+
 		width /= 2;
 		height /= 2;
 	}
@@ -532,13 +556,6 @@ static void loadAnkiTexture(
 		throw ANKI_EXCEPTION("Incorrect header: color format");
 	}
 
-#if 1
-	if(header.type == Image::TT_2D_ARRAY)
-	{
-		preferredCompression = Image::DC_RAW;
-	}
-#endif
-
 	if((header.compressionFormats & preferredCompression) == 0)
 	{
 		throw ANKI_EXCEPTION("File does not contain the wanted compression");
@@ -723,7 +740,6 @@ void Image::load(const char* filename)
 			}
 			else
 			{
-				printf("%d\n", bpp);
 				throw ANKI_EXCEPTION("Unsupported color type");
 			}
 		}

+ 2 - 2
src/resource/Material.cpp

@@ -263,9 +263,9 @@ void Material::parseMaterialTag(const XmlElement& materialEl)
 	XmlElement shaderProgramEl = materialEl.getChildElement("shaderProgram");
 	MaterialShaderProgramCreator mspc(shaderProgramEl, ENABLE_UBOS);
 
-	for(uint level = 0; level < levelsOfDetail; ++level)
+	for(U32 level = 0; level < levelsOfDetail; ++level)
 	{
-		for(uint pid = 0; pid < passes.size(); ++pid)
+		for(U32 pid = 0; pid < passes.size(); ++pid)
 		{
 			std::stringstream src;
 

+ 6 - 6
src/resource/MeshLoader.cpp

@@ -98,7 +98,7 @@ void MeshLoader::load(const char* filename)
 		// Tex coords
 		for(Vec2& texCoord : texCoords)
 		{
-			for(uint i = 0; i < 2; i++)
+			for(U32 i = 0; i < 2; i++)
 			{
 				texCoord[i] = file.readF32();
 			}
@@ -112,7 +112,7 @@ void MeshLoader::load(const char* filename)
 		for(VertexWeight& vw : vertWeights)
 		{
 			// get the bone connections num
-			uint boneConnections = file.readU32();
+			U32 boneConnections = file.readU32();
 
 			// we treat as error if one vert doesnt have a bone
 			if(boneConnections < 1)
@@ -123,17 +123,17 @@ void MeshLoader::load(const char* filename)
 			// and here is another possible error
 			if(boneConnections > VertexWeight::MAX_BONES_PER_VERT)
 			{
-				uint tmp = VertexWeight::MAX_BONES_PER_VERT;
+				U32 tmp = VertexWeight::MAX_BONES_PER_VERT;
 				throw ANKI_EXCEPTION("Cannot have more than "
 					+ std::to_string(tmp) + " bones per vertex");
 			}
 			vw.bonesNum = boneConnections;
 
 			// for all the weights of the current vertes
-			for(uint i = 0; i < vw.bonesNum; i++)
+			for(U32 i = 0; i < vw.bonesNum; i++)
 			{
 				// read bone id
-				uint boneId = file.readU32();
+				U32 boneId = file.readU32();
 				vw.boneIds[i] = boneId;
 
 				// read the weight of that bone
@@ -246,7 +246,7 @@ void MeshLoader::createVertTangents()
 	vertTangents.resize(vertCoords.size(), Vec4(0.0)); // alloc
 	Vector<Vec3> bitagents(vertCoords.size(), Vec3(0.0));
 
-	for(uint i = 0; i < tris.size(); i++)
+	for(U32 i = 0; i < tris.size(); i++)
 	{
 		const Triangle& tri = tris[i];
 		const I i0 = tri.vertIds[0];

+ 8 - 1
src/resource/TextureResource.cpp

@@ -155,7 +155,14 @@ void TextureResource::load(const Image& img)
 	init.anisotropyLevel = TextureManagerSingleton::get().getAnisotropyLevel();
 
 	// genMipmaps
-	init.genMipmaps = driverShouldGenMipmaps;
+	if(init.mipmapsCount == 1 || driverShouldGenMipmaps)
+	{
+		init.genMipmaps = true;
+	}
+	else
+	{
+		init.genMipmaps = false;
+	}
 
 	// Now assign the data
 	for(U layer = 0; layer < layers; layer++)

+ 2 - 2
testapp/Main.cpp

@@ -189,7 +189,7 @@ void init()
 
 #if 1
 	// Vase point lights
-	F32 x = 8.5;
+	F32 x = 8.5; 
 	F32 y = 2.25;
 	F32 z = 2.49;
 	Array<Vec3, 4> vaseLightPos = {{Vec3(x, y, -z - 1.4), Vec3(x, y, z),
@@ -470,7 +470,7 @@ void mainLoop()
 
 		// Sleep
 		//
-#if 0
+#if 1
 		timer.stop();
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		{

+ 11 - 9
tools/texture/ankitexture.py

@@ -510,13 +510,15 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path):
 
 	# For each compression
 	for compression in range(0, 3):
-		# For each image
-		for in_file in in_files:
-			tmp_width = width
-			tmp_height = height
 
-			# For each level
-			while tmp_width >= 4 and tmp_height >= 4:
+		tmp_width = width
+		tmp_height = height
+
+		# For each level
+		while tmp_width >= 4 and tmp_height >= 4:
+
+			# For each image
+			for in_file in in_files:
 				size_str = "%dx%d" % (tmp_width, tmp_height)
 				in_base_fname = os.path.join(tmp_dir, get_base_fname(in_file)) \
 						+ "." + size_str
@@ -535,9 +537,9 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path):
 				if compression == 2:
 					write_etc(tex_file, in_base_fname + ".pkm", \
 							tmp_width, tmp_height, color_format)
-				
-				tmp_width = tmp_width / 2
-				tmp_height = tmp_height / 2
+			
+			tmp_width = tmp_width / 2
+			tmp_height = tmp_height / 2
 
 def main():
 	""" The main """