Bläddra i källkod

Fixed Linux build.

Branimir Karadzic 13 år sedan
förälder
incheckning
f9424d259a
2 ändrade filer med 77 tillägg och 90 borttagningar
  1. 74 75
      examples/06-bump/bump.cpp
  2. 3 15
      premake/premake4.lua

+ 74 - 75
examples/06-bump/bump.cpp

@@ -71,7 +71,7 @@ uint32_t packF4u(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f)
 	return packUint32(xx, yy, zz, ww);
 }
 
-void unpackF4u(float _result[3], uint32_t _packed)
+void unpackF4u(float _result[4], uint32_t _packed)
 {
 	uint8_t unpacked[4];
 	unpackUint32(unpacked, _packed);
@@ -177,13 +177,12 @@ static const bgfx::Memory* loadTexture(const char* _name)
 	return load(filePath);
 }
 
-template<typename Ty>
-void calcTangents(const uint16_t* _indices, uint32_t _numIndices, Ty* _vertices, uint16_t _numVertices)
-{
-	float* tangents = new float[6*_numVertices];
-	memset(tangents, 0, 6*_numVertices*sizeof(float) );
-
-	float* tan = tangents;
+template<typename Ty>
+void calcTangents(const uint16_t* _indices, uint32_t _numIndices, Ty* _vertices, uint16_t _numVertices)
+{
+	float* tangents = new float[6*_numVertices];
+	memset(tangents, 0, 6*_numVertices*sizeof(float) );
+
 	for (uint32_t ii = 0, num = _numIndices/3; ii < num; ++ii)
 	{
 		const uint16_t* indices = &_indices[ii*3];
@@ -191,67 +190,67 @@ void calcTangents(const uint16_t* _indices, uint32_t _numIndices, Ty* _vertices,
 		const Ty& v1 = _vertices[indices[1] ];
 		const Ty& v2 = _vertices[indices[2] ];
 
-		const float bax = v1.m_x - v0.m_x;
-		const float bay = v1.m_y - v0.m_y;
-		const float baz = v1.m_z - v0.m_z;
-		const float bau = v1.m_u - v0.m_u;
-		const float bav = v1.m_v - v0.m_v;
-
-		const float cax = v2.m_x - v0.m_x;
-		const float cay = v2.m_y - v0.m_y;
-		const float caz = v2.m_z - v0.m_z;
-		const float cau = v2.m_u - v0.m_u;
-		const float cav = v2.m_v - v0.m_v;
-
-		const float det = (bau * cav - bav * cau);
-		const float invDet = 1.0f / det;
-
-		const float tx = (bax * cav - cax * bav) * invDet;
-		const float ty = (bay * cav - cay * bav) * invDet;
-		const float tz = (baz * cav - caz * bav) * invDet;
-
-		const float bx = (cax * bau - bax * cau) * invDet;
-		const float by = (cay * bau - bay * cau) * invDet;
-		const float bz = (caz * bau - baz * cau) * invDet;
-
-		for (uint32_t jj = 0; jj < 3; ++jj)
-		{
-			float* tanu = &tangents[indices[jj]*6];
-			float* tanv = &tanu[3];
-			tanu[0] += tx;
-			tanu[1] += ty;
-			tanu[2] += tz;
-
-			tanv[0] += bx;
-			tanv[1] += by;
-			tanv[2] += bz;
-		}
-	}
-
-	for (uint32_t ii = 0; ii < _numVertices; ++ii)
-	{
-		Ty& v0 = _vertices[ii];
-		const float* tanu = &tangents[ii*6];
-		const float* tanv = &tangents[ii*6 + 3];
-
-		float normal[3];
-		unpackF4u(normal, v0.m_normal);
-		float ndt = vec3Dot(normal, tanu);
-
-		float nxt[3];
-		vec3Cross(nxt, normal, tanu);
-
-		float tmp[3];
-		tmp[0] = tanu[0] - normal[0] * ndt;
-		tmp[1] = tanu[1] - normal[1] * ndt;
-		tmp[2] = tanu[2] - normal[2] * ndt;
-
-		float tangent[3];
-		vec3Norm(tangent, tmp);
-
-		float tw = vec3Dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f;
-		v0.m_tangent = packF4u(tangent[0], tangent[1], tangent[2], tw);
-	}
+		const float bax = v1.m_x - v0.m_x;
+		const float bay = v1.m_y - v0.m_y;
+		const float baz = v1.m_z - v0.m_z;
+		const float bau = v1.m_u - v0.m_u;
+		const float bav = v1.m_v - v0.m_v;
+
+		const float cax = v2.m_x - v0.m_x;
+		const float cay = v2.m_y - v0.m_y;
+		const float caz = v2.m_z - v0.m_z;
+		const float cau = v2.m_u - v0.m_u;
+		const float cav = v2.m_v - v0.m_v;
+
+		const float det = (bau * cav - bav * cau);
+		const float invDet = 1.0f / det;
+
+		const float tx = (bax * cav - cax * bav) * invDet;
+		const float ty = (bay * cav - cay * bav) * invDet;
+		const float tz = (baz * cav - caz * bav) * invDet;
+
+		const float bx = (cax * bau - bax * cau) * invDet;
+		const float by = (cay * bau - bay * cau) * invDet;
+		const float bz = (caz * bau - baz * cau) * invDet;
+
+		for (uint32_t jj = 0; jj < 3; ++jj)
+		{
+			float* tanu = &tangents[indices[jj]*6];
+			float* tanv = &tanu[3];
+			tanu[0] += tx;
+			tanu[1] += ty;
+			tanu[2] += tz;
+
+			tanv[0] += bx;
+			tanv[1] += by;
+			tanv[2] += bz;
+		}
+	}
+
+	for (uint32_t ii = 0; ii < _numVertices; ++ii)
+	{
+		Ty& v0 = _vertices[ii];
+		const float* tanu = &tangents[ii*6];
+		const float* tanv = &tangents[ii*6 + 3];
+
+		float normal[4];
+		unpackF4u(normal, v0.m_normal);
+		float ndt = vec3Dot(normal, tanu);
+
+		float nxt[3];
+		vec3Cross(nxt, normal, tanu);
+
+		float tmp[3];
+		tmp[0] = tanu[0] - normal[0] * ndt;
+		tmp[1] = tanu[1] - normal[1] * ndt;
+		tmp[2] = tanu[2] - normal[2] * ndt;
+
+		float tangent[3];
+		vec3Norm(tangent, tmp);
+
+		float tw = vec3Dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f;
+		v0.m_tangent = packF4u(tangent[0], tangent[1], tangent[2], tw);
+	}
 }
 
 int _main_(int _argc, char** _argv)
@@ -317,8 +316,8 @@ int _main_(int _argc, char** _argv)
 	bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(mem);
 
 	// Create texture sampler uniforms.
-	bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
-	bgfx::UniformHandle u_texNormal = bgfx::createUniform("u_texNormal", bgfx::UniformType::Uniform1iv);
+	bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
+	bgfx::UniformHandle u_texNormal = bgfx::createUniform("u_texNormal", bgfx::UniformType::Uniform1iv);
 
 	uint16_t numLights = 4;
 	bgfx::UniformHandle u_lightPosRadius = bgfx::createUniform("u_lightPosRadius", bgfx::UniformType::Uniform4fv, numLights);
@@ -392,10 +391,10 @@ int _main_(int _argc, char** _argv)
 
 		float lightRgbInnerR[4][4] =
 		{
-			1.0f, 0.7f, 0.2f, 0.8f,
-			0.7f, 0.2f, 1.0f, 0.8f,
-			0.2f, 1.0f, 0.7f, 0.8f,
-			1.0f, 0.4f, 0.2f, 0.8f,
+			{ 1.0f, 0.7f, 0.2f, 0.8f },
+			{ 0.7f, 0.2f, 1.0f, 0.8f },
+			{ 0.2f, 1.0f, 0.7f, 0.8f },
+			{ 1.0f, 0.4f, 0.2f, 0.8f },
 		};
 
 		bgfx::setUniform(u_lightRgbInnerR, lightRgbInnerR, numLights);

+ 3 - 15
premake/premake4.lua

@@ -153,6 +153,7 @@ configuration { "mingw" }
 	defines { "WIN32" }
 	includedirs { BX_DIR .. "include/compat/mingw" }
 	buildoptions {
+		"-std=c++0x",
 		"-U__STRICT_ANSI__",
 		"-Wunused-value",
 		"-fdata-sections",
@@ -163,11 +164,6 @@ configuration { "mingw" }
 		"-Wl,--gc-sections",
 	}
 
-configuration { "*.cpp", "mingw" }
-	buildoptions {
-		"-std=c++0x"
-	}
-
 configuration { "x32", "mingw" }
 	targetdir (BGFX_BUILD_DIR .. "win32_mingw" .. "/bin")
 	objdir (BGFX_BUILD_DIR .. "win32_mingw" .. "/obj")
@@ -182,6 +178,7 @@ configuration { "x64", "mingw" }
 
 configuration { "linux" }
 	buildoptions {
+		"-std=c++0x",
 		"-U__STRICT_ANSI__",
 		"-Wunused-value",
 		"-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
@@ -191,11 +188,6 @@ configuration { "linux" }
 		"-Wl,--gc-sections",
 	}
 
-configuration { "*.cpp", "linux" }
-	buildoptions {
-		"-std=c++0x"
-	}
-
 configuration { "linux", "x32" }
 	targetdir (BGFX_BUILD_DIR .. "linux32_gcc" .. "/bin")
 	objdir (BGFX_BUILD_DIR .. "linux32_gcc" .. "/obj")
@@ -225,6 +217,7 @@ configuration { "nacl" }
 	defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" }
 	includedirs { BX_DIR .. "include/compat/nacl" }
 	buildoptions {
+		"-std=c++0x",
 		"-U__STRICT_ANSI__",
 		"-pthread",
 		"-fno-stack-protector",
@@ -240,11 +233,6 @@ configuration { "nacl" }
 		"-Wl,--gc-sections",
 	}
 
-configuration { "*.cpp", "nacl" }
-	buildoptions {
-		"-std=c++0x"
-	}
-
 configuration { "x32", "nacl" }
 	targetdir (BGFX_BUILD_DIR .. "nacl-x86" .. "/bin")
 	objdir (BGFX_BUILD_DIR .. "nacl-x86" .. "/obj")