Panagiotis Christopoulos Charitos 15 rokov pred
rodič
commit
34d380d1ac

+ 1 - 0
src/Math/Vec4.h

@@ -33,6 +33,7 @@ class Vec4
 		/// @{
 		explicit Vec4();
 		explicit Vec4(float f);
+		explicit Vec4(float arr[]);
 		explicit Vec4(float x, float y, float z, float w);
 		explicit Vec4(const Vec2& v2, float z, float w);
 		explicit Vec4(const Vec3& v3, float w);

+ 15 - 2
src/Math/Vec4.inl.h

@@ -58,7 +58,7 @@ inline float Vec4::w() const
 	return vec.w;
 }
 
-// constructor []
+// default constructor
 inline Vec4::Vec4()
 {
 	#if defined(MATH_INTEL_SIMD)
@@ -78,11 +78,24 @@ inline Vec4::Vec4(float f)
 	#endif
 }
 
+// Constructor [float[]]
+inline Vec4::Vec4(float arr_[])
+{
+	#if defined(MATH_INTEL_SIMD)
+		mm = _mm_load_ps(arr_);
+	#else
+		arr[0] = arr_[0];
+		arr[1] = arr_[1];
+		arr[2] = arr_[2];
+		arr[3] = arr_[3];
+	#endif
+}
+
 // constructor [float, float, float, float]
 inline Vec4::Vec4(float x_, float y_, float z_, float w_)
 {
 	#if defined(MATH_INTEL_SIMD)
-		mm = _mm_set1_ps(f);
+		mm = _mm_set_ps(w_, z_, y_, x_);
 	#else
 		x() = x_;
 		y() = y_;

+ 34 - 4
src/Resources/Texture.cpp

@@ -2,6 +2,8 @@
 #include "Texture.h"
 #include "Image.h"
 #include "GlException.h"
+#include "Logger.h" /// @todo remove it
+#include "Math.h"  /// @todo remove it
 
 
 #define LAST_TEX_UNIT (textureUnitsNum - 1)
@@ -99,12 +101,40 @@ void Texture::load(const char* filename)
 				throw EXCEPTION("See file");
 		}
 
+		/*if(std::string("textures/stone.001.diff.tga") == filename)
+		{
+			Vec<uchar> buff(img.getWidth() * img.getHeight(), 0xFF);
+
+			glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &buff[0]);
+		}
+		else*/
+
 		glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &img.getData()[0]);
 		if(mipmappingEnabled)
 		{
 			glGenerateMipmap(target);
 		}
 
+		/// @todo delete this
+		if(std::string("textures/stone.001.diff.tga") == filename)
+		{
+			//setMipmapLevel(7);
+			//INFO(filename << " " << getBaseLevel() << " " << getMaxLevel() << " " << getWidth(1));
+
+			int w, h;
+
+			w = img.getWidth();
+			h = img.getHeight();
+			Vec<uchar> buff__(w * h * 3, 0x0F);
+			glTexSubImage2D(target, 0, 0, 0, w, h, format, type, &buff__[0]);
+
+			w = img.getWidth() / 2;
+			h = img.getHeight() / 2;
+			Vec<uchar> buff(w * h * 3, 0xFF);
+			glTexSubImage2D(target, 1, 0, 0, w, h, format, type, &buff[0]);
+		}
+
+
 		ON_GL_FAIL_THROW_EXCEPTION();
 	}
 	catch(std::exception& e)
@@ -177,11 +207,11 @@ void Texture::bind(uint unit) const
 //======================================================================================================================
 // getWidth                                                                                                            =
 //======================================================================================================================
-int Texture::getWidth() const
+int Texture::getWidth(uint level) const
 {
 	bind(LAST_TEX_UNIT);
 	int i;
-	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &i);
+	glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &i);
 	return i;
 }
 
@@ -189,11 +219,11 @@ int Texture::getWidth() const
 //======================================================================================================================
 // getHeight                                                                                                           =
 //======================================================================================================================
-int Texture::getHeight() const
+int Texture::getHeight(uint level) const
 {
 	bind(LAST_TEX_UNIT);
 	int i;
-	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &i);
+	glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &i);
 	return i;
 }
 

+ 2 - 2
src/Resources/Texture.h

@@ -52,8 +52,8 @@ class Texture
 		void setAnisotropy(uint level);
 		void setMipmapLevel(uint level);
 		void genMipmap();
-		int getWidth() const;
-		int getHeight() const;
+		int getWidth(uint level = 0) const;
+		int getHeight(uint level = 0) const;
 		int getBaseLevel() const;
 		int getMaxLevel() const;
 		static uint getActiveTexUnit();

+ 1 - 0
src/Util/Vec.h

@@ -13,6 +13,7 @@ class Vec: public std::vector<Type>
 		Vec();
 		Vec(size_t size);
 		Vec(size_t size, Type val);
+		~Vec() {std::vector<Type>::clear();}
 		Type& operator[](size_t n);
 		const Type& operator[](size_t n) const;
 		size_t getSizeInBytes() const;

+ 1 - 20
unit-tests/Main.cpp

@@ -7,26 +7,7 @@
 int main(int argc, char** argv)
 {
 	// Init app
-	AppSingleton::getInstance().init(argc, argv);
-
-	// Init mainRenderer
-	RendererInitializer initializer;
-	initializer.ms.ez.enabled = false;
-	initializer.dbg.enabled = true;
-	initializer.is.sm.bilinearEnabled = true;
-	initializer.is.sm.enabled = true;
-	initializer.is.sm.pcfEnabled = true;
-	initializer.is.sm.resolution = 512;
-	initializer.pps.hdr.enabled = true;
-	initializer.pps.hdr.renderingQuality = 0.25;
-	initializer.pps.hdr.blurringDist = 1.0;
-	initializer.pps.hdr.blurringIterationsNum = 2;
-	initializer.pps.hdr.exposure = 4.0;
-	initializer.pps.ssao.blurringIterationsNum = 2;
-	initializer.pps.ssao.enabled = true;
-	initializer.pps.ssao.renderingQuality = 0.5;
-	initializer.mainRendererQuality = 1.0;
-	MainRendererSingleton::getInstance().init(initializer);
+	AppSingleton::getInstance().init(0, NULL);
 
 	// Tests
 	::testing::InitGoogleTest(&argc, argv);

+ 24 - 0
unit-tests/Math/Math.cpp

@@ -0,0 +1,24 @@
+#include <gtest/gtest.h>
+#include <iostream>
+#include "Math.h"
+
+
+TEST(MathTests, Init)
+{
+	Vec4 a, b;
+	EXPECT_EQ(a, Vec4(0.0));
+	EXPECT_EQ(b, Vec4(0.0));
+}
+
+
+TEST(MathTests, Addition)
+{
+	float arr0[] = {1.0001, -2.0, 0.00000012300123, 400.0};
+	float arr1[] = {1.0, 2.0, -3.0, 4.0};
+
+	Vec4 a(arr0), b(arr1);
+	EXPECT_EQ(a + b, Vec4(arr0[0] + arr1[0], arr0[1] + arr1[1], arr0[2] + arr1[2], arr0[3] + arr1[3]));
+
+	//a += b;
+	//EXPECT_EQ(a, Vec4(arr0[0] + arr0[0], arr0[1] + arr0[1], arr0[2] + arr0[2], arr0[3] + arr0[3]));
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1 - 2
unit-tests/build/Makefile


+ 1 - 1
unit-tests/build/gen.cfg.py

@@ -9,6 +9,6 @@ executableName = "anki-unit-tests"
 
 compiler = "g++"
 
-compilerFlags = "-DDEBUG_ENABLED=1 -DPLATFORM_LINUX -DREVISION=\\\"`svnversion -c ../..`\\\" -c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -pipe -g3 -pg -fsingle-precision-constant"
+compilerFlags = "-DDEBUG_ENABLED=1 -DPLATFORM_LINUX -DMATH_INTEL_SIMD -DREVISION=\\\"`svnversion -c ../..`\\\" -c -msse3 -mssse3 -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -pipe -g3 -pg -fsingle-precision-constant"
 
 linkerFlags = "-rdynamic -pg -L../../extern/lib-x86-64-linux -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lGLU -Wl,-Bdynamic -lGL -ljpeg -lSDL -lpng -lpython2.6 -lboost_system -lboost_python -lboost_filesystem -lboost_thread -lgtest"

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov