Răsfoiți Sursa

Primitive : Added getMaterialIndexStart and getMaterialIndexCount to avoid allocation from getMaterialIndexes.

TothBenoit 7 luni în urmă
părinte
comite
8c9623c099
5 a modificat fișierele cu 24 adăugiri și 13 ștergeri
  1. 6 2
      h3d/prim/HMDModel.hx
  2. 1 2
      h3d/prim/Instanced.hx
  3. 9 1
      h3d/prim/Primitive.hx
  4. 6 6
      h3d/scene/MeshBatch.hx
  5. 2 2
      hxd/fmt/fbx/Writer.hx

+ 6 - 2
h3d/prim/HMDModel.hx

@@ -53,8 +53,12 @@ class HMDModel extends MeshPrimitive {
 		curMaterial = material + lod * data.indexCounts.length;
 	}
 
-	override function getMaterialIndexes(material:Int, lod:Int=0):{count:Int, start:Int} {
-		return { start : indexesTriPos[material + lod * data.indexCounts.length]*3, count : lods[lod].indexCounts[material] };
+	override function getMaterialIndexStart( material : Int, lod : Int = 0 ) : Int {
+		return indexesTriPos[material + lod * data.indexCounts.length]*3;
+	}
+
+	override function getMaterialIndexCount( material : Int, lod : Int = 0 ) : Int {
+		return lods[lod].indexCounts[material];
 	}
 
 	public function getDataBuffers(fmt, ?defaults,?material) {

+ 1 - 2
h3d/prim/Instanced.hx

@@ -65,8 +65,7 @@ class Instanced extends Primitive {
 			commands.setCommand(0, 0, 0);
 			return;
 		}
-		var infos = primitive.getMaterialIndexes(material, lod);
-		commands.setCommand(count, infos.count, infos.start);
+		commands.setCommand(count, primitive.getMaterialIndexStart(material, lod), primitive.getMaterialIndexCount(material, lod));
 	}
 
 	override function render( engine : h3d.Engine ) {

+ 9 - 1
h3d/prim/Primitive.hx

@@ -96,7 +96,15 @@ class Primitive {
 	**/
 	public function getMaterialIndexes( material : Int, lod : Int = 0 ) : { count : Int, start : Int } {
 		if ( lod != 0 ) return { start : 0, count : 0 };
-		return { start : 0, count : indexes == null ? triCount() * 3 : indexes.count };
+		return { start : getMaterialIndexStart(material, lod), count : getMaterialIndexCount(material, lod) };
+	}
+
+	public function getMaterialIndexStart( material : Int, lod : Int = 0 ) : Int {
+		return 0;
+	}
+
+	public function getMaterialIndexCount( material : Int, lod : Int = 0 ) : Int {
+		return indexes == null ? triCount() * 3 : indexes.count;
 	}
 
 	@:noCompletion public function buildNormalsDisplay() : Primitive {

+ 6 - 6
h3d/scene/MeshBatch.hx

@@ -331,7 +331,8 @@ class MeshBatch extends MultiMaterial {
 		for( index in 0...materials.length ) {
 			var mat = materials[index];
 			if( mat == null ) continue;
-			var matInfo = @:privateAccess instanced.primitive.getMaterialIndexes(index);
+			var matCount = @:privateAccess instanced.primitive.getMaterialIndexCount(index);
+			var matStart = @:privateAccess instanced.primitive.getMaterialIndexStart(index);
 			for( p in mat.getPasses() ) @:privateAccess {
 				var ctx = scene.renderer.getPassByName(p.name);
 				if( ctx == null ) throw "Could't find renderer pass "+p.name;
@@ -342,8 +343,8 @@ class MeshBatch extends MultiMaterial {
 				var shader = output.shaderCache.makeBatchShader(rt, shaders, instancedParams);
 
 				var b = new BatchData();
-				b.indexCount = matInfo.count;
-				b.indexStart = matInfo.start;
+				b.indexCount = matCount;
+				b.indexStart = matStart;
 				b.paramsCount = shader.paramsSize;
 				b.maxInstance = Std.int( ( useStorageBuffer ? MAX_STORAGE_BUFFER_ELEMENTS : MAX_BUFFER_ELEMENTS ) / b.paramsCount);
 				b.bufferFormat = hxd.BufferFormat.VEC4_DATA;
@@ -757,9 +758,8 @@ class MeshBatch extends MultiMaterial {
 					matInfos = alloc.allocBuffer( materialCount, hxd.BufferFormat.VEC4_DATA, Uniform );
 					var pos : Int = 0;
 					for ( i in 0...materials.length ) {
-						var matInfo = prim.getMaterialIndexes(i);
-						tmpMatInfos[pos++] = matInfo.count;
-						tmpMatInfos[pos++] = matInfo.start;
+						tmpMatInfos[pos++] = prim.getMaterialIndexCount(i);
+						tmpMatInfos[pos++] = prim.getMaterialIndexStart(i);
 						pos += 2;
 					}
 					matInfos.uploadFloats( tmpMatInfos, 0, materialCount );

+ 2 - 2
hxd/fmt/fbx/Writer.hx

@@ -681,8 +681,8 @@ class Writer {
 
 				var hmd = Std.downcast(mesh.primitive, h3d.prim.HMDModel);
 				if (hmd != null) {
-					var materials = hmd.getMaterialIndexes(idx);
-					for (i in 0...Std.int(materials.count / 3))
+					var count = hmd.getMaterialIndexCount(idx);
+					for (i in 0...Std.int(count / 3))
 						materialIndexes.push(idx);
 				}