فهرست منبع

Adding command and count offset for indirect draw.

TothBenoit 4 ماه پیش
والد
کامیت
dbb12e2d68
3فایلهای تغییر یافته به همراه9 افزوده شده و 3 حذف شده
  1. 1 1
      h3d/impl/DX12Driver.hx
  2. 4 2
      h3d/impl/GlDriver.hx
  3. 4 0
      h3d/impl/InstanceBuffer.hx

+ 1 - 1
h3d/impl/DX12Driver.hx

@@ -2463,7 +2463,7 @@ class DX12Driver extends h3d.impl.Driver {
 			if ( commands.countBuffer != null )
 				transition(commands.countBuffer, INDIRECT_ARGUMENT);
 			flushTransitions();
-			frame.commandList.executeIndirect(indirectCommand, commands.commandCount, commands.data.res, 0, commands.countBuffer != null ? commands.countBuffer.res : null, 0);
+			frame.commandList.executeIndirect(indirectCommand, commands.commandCount, commands.data.res, commands.offset, commands.countBuffer != null ? commands.countBuffer.res : null, commands.countOffset);
 		} else {
 			frame.commandList.drawIndexedInstanced(commands.indexCount, commands.commandCount, commands.startIndex, 0, 0);
 		}

+ 4 - 2
h3d/impl/GlDriver.hx

@@ -1621,14 +1621,16 @@ class GlDriver extends Driver {
 		}
 		#if !js
 		if( hasMultiIndirect && commands.data != null ) {
+			var commandOffset : hl.Bytes = hl.Api.unsafeCast(commands.offset * InstanceBuffer.ELEMENT_SIZE);
 			gl.bindBuffer(GL.DRAW_INDIRECT_BUFFER, commands.data);
 			#if (hlsdl >= version("1.15.0"))
 			if ( commands.countBuffer != null && hasMultiIndirectCount ) {
+				var countOffset : hl.Bytes = hl.Api.unsafeCast(commands.countOffset * 4);
 				gl.bindBuffer(GL.PARAMETER_BUFFER, commands.countBuffer);
-				gl.multiDrawElementsIndirectCount(drawMode, kind, null, null, commands.commandCount, 0);
+				gl.multiDrawElementsIndirectCount(drawMode, kind, commandOffset, countOffset, commands.commandCount, 0);
 			} else
 			#end
-			gl.multiDrawElementsIndirect(drawMode, kind, null, commands.commandCount, 0);
+			gl.multiDrawElementsIndirect(drawMode, kind, commandOffset, commands.commandCount, 0);
 			gl.bindBuffer(GL.DRAW_INDIRECT_BUFFER, null);
 			return;
 		}

+ 4 - 0
h3d/impl/InstanceBuffer.hx

@@ -16,6 +16,10 @@ class InstanceBuffer {
 	var countBuffer : Dynamic;
 	var data : Dynamic;
 	var driver : h3d.impl.Driver;
+
+	var offset : Int = 0;
+	var countOffset : Int;
+
 	var indexCount : Int;
 	var startIndex : Int;
 	public var triCount(default,null) : Int = 0;