浏览代码

Fixing some bugs

Panagiotis Christopoulos Charitos 11 年之前
父节点
当前提交
454957d733

+ 2 - 0
include/anki/resource/Material.h

@@ -43,6 +43,8 @@ typedef VisitableCommonBase<
 /// that share the same name
 class MaterialVariable: public MateriaVariableVisitable, public NonCopyable
 {
+	friend class Material;
+
 public:
 	using Base = MateriaVariableVisitable;
 

+ 1 - 1
shaders/IsLp.frag.glsl

@@ -257,7 +257,7 @@ void main()
 #endif
 
 #if 0
-	if(spotTexLightsCount > 0)
+	if(pointLightsCount > 0)
 	{
 		outColor += vec3(0.1);
 	}

+ 3 - 1
src/gl/GlBufferHandle.cpp

@@ -233,7 +233,9 @@ void GlBufferHandle::bindVertexBuffer(
 			m_stride(stride),
 			m_offset(offset),
 			m_attribLocation(attribLocation)
-		{}
+		{
+			ANKI_ASSERT(m_elementSize != 0);
+		}
 
 		Error operator()(GlCommandBuffer*)
 		{

+ 6 - 5
src/gl/GlCommon.cpp

@@ -134,7 +134,8 @@ static void writeShaderBlockMemoryMatrix(
 		matrix.transpose();
 		for(U j = 0; j < sizeof(T) / sizeof(Vec); j++)
 		{
-			ANKI_ASSERT(subbuff + sizeof(Vec) <= static_cast<U8*>(buffEnd));
+			ANKI_ASSERT(
+				(subbuff + sizeof(Vec)) <= static_cast<const U8*>(buffEnd));
 
 			Vec* out = reinterpret_cast<Vec*>(subbuff);
 			*out = matrix.getRow(j);
@@ -172,12 +173,12 @@ void writeShaderBlockMemory(
 			buffBegin, buffEnd);
 		break;
 	case ShaderVariableDataType::MAT3:
-		writeShaderBlockMemorySimple<Mat3>(varBlkInfo, elements, elementsCount,
-			buffBegin, buffEnd);
+		writeShaderBlockMemoryMatrix<Mat3, Vec3>(varBlkInfo, elements, 
+			elementsCount, buffBegin, buffEnd);
 		break;
 	case ShaderVariableDataType::MAT4:
-		writeShaderBlockMemorySimple<Mat4>(varBlkInfo, elements, elementsCount,
-			buffBegin, buffEnd);
+		writeShaderBlockMemoryMatrix<Mat4, Vec4>(varBlkInfo, elements, 
+			elementsCount, buffBegin, buffEnd);
 		break;
 	default:
 		ANKI_ASSERT(0);

+ 2 - 2
src/renderer/MainRenderer.cpp

@@ -94,8 +94,8 @@ Error MainRenderer::render(SceneGraph& scene)
 			rt = &getIs()._getRt();
 		}
 
-		//rt = &getMs()._getRt1();
-		//rt = &getPps().getSsao().getRt();
+		//rt = &getMs()._getRt0();
+		//rt = &getIs()._getRt();
 
 		rt->setFilter(lastJobs, GlTextureHandle::Filter::LINEAR);
 		rt->bind(lastJobs, 0);

+ 2 - 0
src/resource/Material.cpp

@@ -669,6 +669,8 @@ Error Material::populateVariables(const MaterialProgramCreator& loader)
 				}
 
 				mtlvar = tvar;
+				mtlvar->m_varBlkInfo.m_arraySize = 1;
+				mtlvar->m_textureUnit = in.m_binding;
 			}
 			break;
 		case ShaderVariableDataType::FLOAT:

+ 61 - 9
src/resource/MaterialProgramCreator.cpp

@@ -7,6 +7,7 @@
 #include "anki/util/Assert.h"
 #include "anki/misc/Xml.h"
 #include "anki/util/Logger.h"
+#include "anki/util/Functions.h"
 #include <algorithm>
 
 namespace anki {
@@ -365,9 +366,9 @@ Error MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 		{
 			I64 tmp;
 			ANKI_CHECK(arrSizeEl.getI64(tmp));
-			if(tmp == 0)
+			if(tmp <= 0)
 			{
-				ANKI_LOGE("Array size for some reason is zero");
+				ANKI_LOGE("Incorrect arraySize value %d", tmp);
 				return ErrorCode::USER_DATA;
 			}
 
@@ -396,7 +397,7 @@ Error MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 		}
 		else
 		{
-			inpvar.m_instanced = 0;
+			inpvar.m_instanced = false;
 		}
 
 		// If one input var is instanced notify the whole program that 
@@ -488,18 +489,69 @@ Error MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 				m_uniformBlockReferencedMask |= glshaderbit;
 				inpvar.m_inBlock = true;
 
+				// std140 rules
 				inpvar.m_offset = m_blockSize;
-				if(inpvar.m_type == ShaderVariableDataType::FLOAT 
-					|| inpvar.m_type == ShaderVariableDataType::VEC2
-					|| inpvar.m_type == ShaderVariableDataType::VEC3
-					|| inpvar.m_type == ShaderVariableDataType::VEC4)
+
+				if(inpvar.m_type == ShaderVariableDataType::FLOAT)
+				{
+					inpvar.m_arrayStride = sizeof(Vec4);
+
+					if(inpvar.m_arraySize == 1)
+					{
+						// No need to align the inpvar.m_offset
+						m_blockSize += sizeof(F32);
+					}
+					else
+					{
+						alignRoundUp(sizeof(Vec4), inpvar.m_offset);
+						m_blockSize += sizeof(Vec4) * inpvar.m_arraySize;
+					}
+				}
+				else if(inpvar.m_type == ShaderVariableDataType::VEC2)
+				{
+					inpvar.m_arrayStride = sizeof(Vec4);
+
+					if(inpvar.m_arraySize == 1)
+					{
+						alignRoundUp(sizeof(Vec2), inpvar.m_offset);
+						m_blockSize += sizeof(Vec2);
+					}
+					else
+					{
+						alignRoundUp(sizeof(Vec4), inpvar.m_offset);
+						m_blockSize += sizeof(Vec4) * inpvar.m_arraySize;
+					}
+				}
+				else if(inpvar.m_type == ShaderVariableDataType::VEC3)
+				{
+					alignRoundUp(sizeof(Vec4), inpvar.m_offset);
+					inpvar.m_arrayStride = sizeof(Vec4);
+
+					if(inpvar.m_arraySize == 1)
+					{
+						m_blockSize += sizeof(Vec3);
+					}
+					else
+					{
+						m_blockSize += sizeof(Vec4) * inpvar.m_arraySize;
+					}
+				}
+				else if(inpvar.m_type == ShaderVariableDataType::VEC4)
 				{
 					inpvar.m_arrayStride = sizeof(Vec4);
+					alignRoundUp(sizeof(Vec4), inpvar.m_offset);
 					m_blockSize += sizeof(Vec4) * inpvar.m_arraySize;
 				}
-				else if(inpvar.m_type == ShaderVariableDataType::MAT3
-					|| inpvar.m_type == ShaderVariableDataType::MAT4)
+				else if(inpvar.m_type == ShaderVariableDataType::MAT3)
+				{
+					alignRoundUp(sizeof(Vec4), inpvar.m_offset);
+					inpvar.m_arrayStride = sizeof(Vec4) * 3;
+					m_blockSize += sizeof(Vec4) * 3 * inpvar.m_arraySize;
+					inpvar.m_matrixStride = sizeof(Vec4);				
+				}
+				else if(inpvar.m_type == ShaderVariableDataType::MAT4)
 				{
+					alignRoundUp(sizeof(Vec4), inpvar.m_offset);
 					inpvar.m_arrayStride = sizeof(Mat4);
 					m_blockSize += sizeof(Mat4) * inpvar.m_arraySize;
 					inpvar.m_matrixStride = sizeof(Vec4);				

+ 1 - 0
src/resource/Mesh.cpp

@@ -227,6 +227,7 @@ void Mesh::getBufferInfo(const VertexAttribute attrib,
 				+ m_texChannelsCount * sizeof(HVec2) + sizeof(U16) 
 				+ sizeof(U16) * 4;
 		}
+		break;
 	case VertexAttribute::INDICES:
 		v = m_indicesBuff;
 		break;

+ 3 - 9
testapp/Main.cpp

@@ -55,12 +55,6 @@ Error init()
 		app->setTimerTick(0.0);
 	}
 
-#if 0
-	painter = new UiPainter(Vec2(AppSingleton::get().getWindowWidth(),
-		AppSingleton::get().getWindowHeight()));
-	painter->setFont("engine-rsrc/ModernAntiqua.ttf", 25, 25);
-#endif
-
 	// camera
 	err = scene.newSceneNode<PerspectiveCamera>("main-camera", cam);
 	if(err) return err;
@@ -109,7 +103,7 @@ Error init()
 	spot->setLocalTransform(Transform(Vec4(8.27936, 5.86285, 1.85526, 0.0),
 		Mat3x4(Quat(-0.125117, 0.620465, 0.154831, 0.758544)), 1.0));
 	spot->setDiffuseColor(Vec4(1.0));
-	spot->setSpecularColor(Vec4(-1.0));
+	spot->setSpecularColor(Vec4(1.2));
 	spot->setDistance(30.0);
 	spot->setShadowEnabled(true);
 
@@ -235,7 +229,7 @@ Error init()
 	{
 		ScriptResourcePointer script;
 
-		err = script.load("maps/sponza/scene.lua", &resources);
+		err = script.load("maps/adis/scene.lua", &resources);
 		if(err) return err;
 
 		err = app->getScriptManager().evalString(script->getSource());
@@ -532,7 +526,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("tilesXCount", 16);
 	config.set("tilesYCount", 16);
 
-	config.set("fullscreenDesktopResolution", false);
+	config.set("fullscreenDesktopResolution", true);
 	config.set("debugContext", false);
 
 	app = new App;

+ 4 - 4
tools/scene/Main.cpp

@@ -196,27 +196,27 @@ static void writeNodeTransform(const Exporter& exporter, std::ofstream& file,
 		<< ":getSceneNodeBase():getMoveComponent():setLocalOrigin(pos)\n";
 
 	file << "rot = Mat3x4.new()\n";
-	file << "rot:setAll("
+	file << "rot:setAll(";
 	for(unsigned j = 0; j < 3; j++)
 	{
 		for(unsigned i = 0; i < 4; i++)
 		{
 			if(i == 3)
 			{
-				file << "0.0"
+				file << "0";
 			}
 			else
 			{
 				file << m[j][i];
 			}
 
-			if(i != 2 || j != 2)
+			if(!(i == 3 && j == 2))
 			{
 				file << ", ";
 			}
 		}
 	}
-	file << ")\n"
+	file << ")\n";
 
 	file << node 
 		<< ":getSceneNodeBase():getMoveComponent():setLocalRotation(rot)\n";

+ 16 - 6
tools/texture/ankitexture.py

@@ -194,6 +194,10 @@ def parse_commandline():
 			action = "store_true", default = False, 
 			help = "remove alpha channel")
 
+	parser.add_option("--no-uncompressed", dest = "no_uncompressed", 
+			action = "store_true", default = True, 
+			help = "don't store uncompressed data")
+
 	(options, args) = parser.parse_args()
 
 	if not options.inp or not options.out or not options.convert_path:
@@ -211,7 +215,8 @@ def parse_commandline():
 		parser.error("Unrecognized type: " + options.type)
 
 	return (options.inp.split(":"), options.out, options.fast, \
-			typ, options.normal, options.convert_path, options.no_alpha)
+			typ, options.normal, options.convert_path, options.no_alpha, \
+			options.no_uncompressed)
 
 def identify_image(in_file):
 	""" Return the size of the input image and the internal format """
@@ -508,7 +513,8 @@ def write_etc(out_file, fname, width, height, color_format):
 
 	out_file.write(data)
 
-def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha):
+def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha, \
+		no_uncompressed):
 	""" This is the function that does all the work """
 
 	# Invoke app named "identify" to get internal format and width and height
@@ -550,6 +556,10 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha):
 	# Write header
 	ak_format = "8sIIIIIIII"
 
+	data_compression = DC_S3TC | DC_ETC2
+	if not no_uncompressed:
+		data_compression = data_compression | DC_RAW
+
 	buff = struct.pack(ak_format, 
 			b"ANKITEX1",
 			width,
@@ -557,7 +567,7 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha):
 			len(in_files),
 			typ,
 			color_format,
-			DC_RAW | DC_S3TC | DC_ETC2,
+			data_compression,
 			normal,
 			len(mips_fnames))
 
@@ -588,7 +598,7 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha):
 						+ "." + size_str
 
 				# Write RAW
-				if compression == 0:
+				if compression == 0 and not no_uncompressed:
 					write_raw(tex_file, in_base_fname + ".tga", \
 							tmp_width, tmp_height, color_format)
 				# Write S3TC
@@ -608,7 +618,7 @@ def main():
 
 	# Parse cmd line args
 	(in_files, out, fast, typ, normal, convert_path, \
-			no_alpha) = parse_commandline();
+			no_alpha, no_uncompressed) = parse_commandline();
 
 	if typ == TT_CUBE and len(in_files) != 6:
 		raise Exception("Not enough images for cube generation")
@@ -629,7 +639,7 @@ def main():
 	# Do the work
 	try:
 		convert(in_files, out, fast, typ, normal, tmp_dir, \
-				convert_path, no_alpha)
+				convert_path, no_alpha, no_uncompressed)
 	finally:
 		shutil.rmtree(tmp_dir)