Bladeren bron

rename Buffer.uploadVector to uploadFloats and error on low precision

Nicolas Cannasse 2 jaren geleden
bovenliggende
commit
eb0ee22a2b

+ 2 - 2
h2d/RenderContext.hx

@@ -581,7 +581,7 @@ class RenderContext extends h3d.impl.RenderContext {
 		beforeDraw();
 		var nverts = Std.int(bufPos / stride);
 		var tmp = new h3d.Buffer(nverts, hxd.BufferFormat.XY_UV_RGBA, [Dynamic]);
-		tmp.uploadVector(buffer, 0, nverts);
+		tmp.uploadFloats(buffer, 0, nverts);
 		engine.renderQuadBuffer(tmp);
 		tmp.dispose();
 		bufPos = 0;
@@ -754,7 +754,7 @@ class RenderContext extends h3d.impl.RenderContext {
 			var k = new hxd.FloatBuffer();
 			for( v in [0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] )
 				k.push(v);
-			fixedBuffer.uploadVector(k, 0, 4);
+			fixedBuffer.uploadFloats(k, 0, 4);
 		}
 		engine.renderQuadBuffer(fixedBuffer);
 		return true;

+ 1 - 1
h2d/SpriteBatch.hx

@@ -430,7 +430,7 @@ class SpriteBatch extends Drawable {
 		bufferVertices = pos>>3;
 		if( buffer != null && !buffer.isDisposed() ) {
 			if( buffer.vertices >= bufferVertices ){
-				buffer.uploadVector(tmpBuf, 0, bufferVertices);
+				buffer.uploadFloats(tmpBuf, 0, bufferVertices);
 				return;
 			}
 			buffer.dispose();

+ 5 - 3
h3d/Buffer.hx

@@ -60,9 +60,11 @@ class Buffer {
 		}
 	}
 
-	public function uploadVector( buf : hxd.FloatBuffer, bufPos : Int, vertices : Int, startVertice = 0 ) {
+	public function uploadFloats( buf : hxd.FloatBuffer, bufPos : Int, vertices : Int, startVertice = 0 ) {
 		if( startVertice < 0 || vertices < 0 || startVertice + vertices > this.vertices )
 			throw "Invalid vertices count";
+		if( format.hasLowPrecision )
+			throw "Can't upload floats on low precision buffer";
 		mem.driver.uploadBufferData(vbuf, startVertice, vertices, buf, bufPos);
 	}
 
@@ -81,13 +83,13 @@ class Buffer {
 	public static function ofFloats( v : hxd.FloatBuffer, format : hxd.BufferFormat, ?flags ) {
 		var nvert = Std.int(v.length / format.stride);
 		var b = new Buffer(nvert, format, flags);
-		b.uploadVector(v, 0, nvert);
+		b.uploadFloats(v, 0, nvert);
 		return b;
 	}
 
 	public static function ofSubFloats( v : hxd.FloatBuffer, vertices : Int, format : hxd.BufferFormat, ?flags ) {
 		var b = new Buffer(vertices, format, flags);
-		b.uploadVector(v, 0, vertices);
+		b.uploadFloats(v, 0, vertices);
 		return b;
 	}
 

+ 1 - 1
h3d/parts/GpuParticles.hx

@@ -887,7 +887,7 @@ class GpuParticles extends h3d.scene.MultiMaterial {
 		if( firstPart <= lastPart ) {
 			uploadedCount += lastPart - firstPart + 1;
 			var primitive = primitives[groups.indexOf(g)];
-			primitive.buffer.uploadVector(vbuf, (firstPart) * 4 * STRIDE, (lastPart - firstPart + 1) * 4, (firstPart) * 4);
+			primitive.buffer.uploadFloats(vbuf, (firstPart) * 4 * STRIDE, (lastPart - firstPart + 1) * 4, (firstPart) * 4);
 		}
 	}
 

+ 1 - 1
h3d/prim/DynamicPrimitive.hx

@@ -63,7 +63,7 @@ class DynamicPrimitive extends Primitive {
 		if( indexes == null )
 			indexes = alloc.allocIndexBuffer(hxd.Math.imax(minISize, isize));
 
-		buffer.uploadVector(vbuf, 0, vsize);
+		buffer.uploadFloats(vbuf, 0, vsize);
 		indexes.upload(ibuf, 0, isize);
 	}
 

+ 1 - 1
h3d/scene/MeshBatch.hx

@@ -351,7 +351,7 @@ class MeshBatch extends MultiMaterial {
 					upload = true;
 				}
 				if( upload )
-					buf.uploadVector(p.data, start * p.paramsCount * 4, count * p.paramsCount);
+					buf.uploadFloats(p.data, start * p.paramsCount * 4, count * p.paramsCount);
 				if( psBytes != null ) {
 					if( p.instanceBuffers == null ) p.instanceBuffers = [];
 					var buf = p.instanceBuffers[index];

+ 1 - 1
h3d/scene/pbr/LightBuffer.hx

@@ -302,7 +302,7 @@ class LightBuffer {
 		s.DIR_SHADOW_COUNT = dirLightsShadow.length;
 		s.POINT_SHADOW_COUNT = pointLightsShadow.length;
 		s.SPOT_SHADOW_COUNT = spotLightsShadow.length;
-		s.lightInfos.uploadVector(lightInfos, 0, s.lightInfos.vertices, 0);
+		s.lightInfos.uploadFloats(lightInfos, 0, s.lightInfos.vertices, 0);
 
 		var pbrIndirect = @:privateAccess pbrRenderer.pbrIndirect;
 		s.USE_INDIRECT = pbrRenderer.env != null && pbrIndirect.irrLut != null;

+ 4 - 0
hxd/BufferFormat.hx

@@ -112,6 +112,7 @@ class BufferFormat {
 	public var uid(default,null) : Int;
 	public var stride(default,null) : Int;
 	public var strideBytes(default,null) : Int;
+	public var hasLowPrecision(default,null) : Bool;
 	var inputs : Array<BufferInput>;
 	var mappings : Array<Array<BufferMapping>>;
 
@@ -119,12 +120,15 @@ class BufferFormat {
 		uid = _UID++;
 		stride = 0;
 		this.inputs = inputs.copy();
+		hasLowPrecision = false;
 		for( i in inputs ) {
 			stride += i.type.getSize();
 			strideBytes += i.getBytesSize();
 			// 4 bytes align
 			if( strideBytes & 3 != 0 )
 				strideBytes += 4 - (strideBytes & 3);
+			if( i.precision != F32 )
+				hasLowPrecision = true;
 		}
 	}
 

+ 1 - 1
hxd/impl/Allocator.hx

@@ -32,7 +32,7 @@ class Allocator {
 
 	public function ofSubFloats( v : hxd.FloatBuffer, vertices : Int, format, flags : BufferFlags = Dynamic ) {
 		var b = allocBuffer(vertices, format, flags);
-		b.uploadVector(v, 0, vertices);
+		b.uploadFloats(v, 0, vertices);
 		return b;
 	}