@@ -325,7 +325,7 @@ class RenderContext extends h3d.impl.RenderContext {
/**
Retrieves the current filter scale factor.
-
+
@param into The 2D Point instance into which the scale is written. Creates a new Point if null.
@returns The current filter resolution scale or `{ 1, 1 }` point.
**/
@@ -580,7 +580,7 @@ class RenderContext extends h3d.impl.RenderContext {
if( bufPos == 0 ) return;
beforeDraw();
var nverts = Std.int(bufPos / stride);
- var tmp = new h3d.Buffer(nverts, stride, [Quads,Dynamic,RawFormat]);
+ var tmp = new h3d.Buffer(nverts, stride, [Dynamic,RawFormat]);
tmp.uploadVector(buffer, 0, nverts);
engine.renderQuadBuffer(tmp);
tmp.dispose();
@@ -750,7 +750,7 @@ class RenderContext extends h3d.impl.RenderContext {
baseShader.uvPos.set(tile.u, tile.v, tile.u2 - tile.u, tile.v2 - tile.v);
if( fixedBuffer == null || fixedBuffer.isDisposed() ) {
- fixedBuffer = new h3d.Buffer(4, 8, [Quads, RawFormat]);
+ fixedBuffer = new h3d.Buffer(4, 8, [RawFormat]);
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);
@@ -438,7 +438,7 @@ class SpriteBatch extends Drawable {
}
empty = bufferVertices == 0;
if( bufferVertices > 0 )
- buffer = h3d.Buffer.ofSubFloats(tmpBuf, 8, bufferVertices, [Dynamic, Quads, RawFormat]);
+ buffer = h3d.Buffer.ofSubFloats(tmpBuf, 8, bufferVertices, [Dynamic, RawFormat]);
override function draw( ctx : RenderContext ) {
@@ -511,8 +511,8 @@ class TileLayerContent extends h3d.prim.Primitive {
if( tmp == null ) clear();
if( tmp.length > 0 ) {
buffer = tmp.length < useAllocatorLimit
- ? hxd.impl.Allocator.get().ofFloats(tmp, 8, RawQuads)
- : h3d.Buffer.ofFloats(tmp, 8, [Quads, RawFormat]);
+ ? hxd.impl.Allocator.get().ofFloats(tmp, 8, RawFormat)
+ : h3d.Buffer.ofFloats(tmp, 8, [RawFormat]);
@@ -5,14 +5,6 @@ enum BufferFlag {
Indicate that the buffer content will be often modified.
Dynamic;
- /**
- The buffer contains only triangles. Imply Managed. Make sure the position is aligned on 3 vertices multiples.
- **/
- Triangles;
- The buffer contains only quads. Imply Managed. Make sure the position is aligned on 4 vertices multiples.
- Quads;
Directly map the buffer content to the shader inputs, without assuming [pos:vec3,normal:vec3,uv:vec2] default prefix.
@@ -142,11 +142,11 @@ class Engine {
public inline function renderTriBuffer( b : Buffer, start = 0, max = -1 ) {
- return renderBuffer(b, mem.triIndexes, 3, start, max);
+ return renderBuffer(b, mem.getTriIndexes(b.vertices), 3, start, max);
public inline function renderQuadBuffer( b : Buffer, start = 0, max = -1 ) {
- return renderBuffer(b, mem.quadIndexes, 2, start, max);
+ return renderBuffer(b, mem.getQuadIndexes(b.vertices), 2, start, max);
// we use preallocated indexes so all the triangles are stored inside our buffers
@@ -14,8 +14,10 @@ class MemoryManager {
var textures : Array<h3d.mat.Texture>;
var depths : Array<h3d.mat.DepthBuffer>;
- public var triIndexes(default,null) : Indexes;
- public var quadIndexes(default,null) : Indexes;
+ var triIndexes16 : Indexes;
+ var quadIndexes16 : Indexes;
+ var triIndexes32 : Indexes;
+ var quadIndexes32 : Indexes;
public var usedMemory(default, null) : Float = 0;
public var texMemory(default, null) : Float = 0;
@@ -34,7 +36,7 @@ class MemoryManager {
function initIndexes() {
var indices = new hxd.IndexBuffer();
for( i in 0...SIZE ) indices.push(i);
- triIndexes = h3d.Indexes.alloc(indices);
+ triIndexes16 = h3d.Indexes.alloc(indices);
var p = 0;
@@ -48,7 +50,7 @@ class MemoryManager {
indices.push(k + 3);
indices.push(SIZE);
- quadIndexes = h3d.Indexes.alloc(indices);
+ quadIndexes16 = h3d.Indexes.alloc(indices);
@@ -58,6 +60,22 @@ class MemoryManager {
public dynamic function garbage() {
+ public function getTriIndexes( vertices : Int ) {
+ if( vertices <= SIZE )
+ return triIndexes16;
+ if( triIndexes32 == null || triIndexes32.count < vertices )
+ throw "TODO";
+ return triIndexes32;
+ }
+ public function getQuadIndexes( vertices : Int ) {
+ return quadIndexes16;
+ if( quadIndexes32 == null || quadIndexes32.count < vertices )
+ return quadIndexes32;
// ------------------------------------- BUFFERS ------------------------------------------
function allocBuffer( b : Buffer ) {
@@ -197,10 +215,14 @@ class MemoryManager {
public function dispose() {
- if( triIndexes != null ) triIndexes.dispose();
- if( quadIndexes != null ) quadIndexes.dispose();
- triIndexes = null;
- quadIndexes = null;
+ if( triIndexes16 != null ) triIndexes16.dispose();
+ if( quadIndexes16 != null ) quadIndexes16.dispose();
+ if( triIndexes32 != null ) triIndexes32.dispose();
+ if( quadIndexes32 != null ) quadIndexes32.dispose();
+ triIndexes16 = null;
+ quadIndexes16 = null;
+ triIndexes32 = null;
+ quadIndexes32 = null;
for( t in textures.copy() )
t.dispose();
for( b in depths.copy() )
@@ -364,7 +364,7 @@ class Particles extends h3d.scene.Mesh {
var stride = 10;
if( hasColor ) stride += 4;
- var buffer = h3d.Buffer.ofSubFloats(tmp, stride, Std.int(pos/stride), [Quads, Dynamic, RawFormat]);
+ var buffer = h3d.Buffer.ofSubFloats(tmp, stride, Std.int(pos/stride), [Dynamic, RawFormat]);
if( pshader.is3D )
pshader.size.set(globalSize, globalSize);
else
@@ -26,7 +26,7 @@ class Instanced extends MeshPrimitive {
buffer = m.buffer;
indexes = m.indexes;
baseBounds = m.getBounds();
- if( indexes == null ) indexes = engine.mem.triIndexes;
+ if( indexes == null ) indexes = engine.mem.getTriIndexes(buffer.vertices);
for( bid in m.bufferCache.keys() ) {
var b = m.bufferCache.get(bid);
addBuffer(hxsl.Globals.getIDName(bid), b.buffer, b.offset);
@@ -35,7 +35,7 @@ class Plane2D extends Primitive {
v.push( 1);
v.push( 0);
- buffer = h3d.Buffer.ofFloats(v, 4, [Quads, RawFormat]);
+ buffer = h3d.Buffer.ofFloats(v, 4, [RawFormat]);
override function render(engine:h3d.Engine) {
@@ -84,7 +84,6 @@ class Polygon extends MeshPrimitive {
var flags : Array<h3d.Buffer.BufferFlag> = [];
- if( idx == null ) flags.push(Triangles);
if( normals == null || tangents != null ) flags.push(RawFormat);
buffer = h3d.Buffer.ofFloats(buf, size, flags);
@@ -281,10 +280,10 @@ class Polygon extends MeshPrimitive {
var bufs = getBuffers(engine);
if( indexes != null )
engine.renderMultiBuffers(bufs, indexes);
- else if( buffer.flags.has(Quads) )
- engine.renderMultiBuffers(bufs, engine.mem.quadIndexes, 0, triCount());
- else
- engine.renderMultiBuffers(bufs, engine.mem.triIndexes, 0, triCount());
+ else {
+ var count = triCount();
+ engine.renderMultiBuffers(bufs, engine.mem.getTriIndexes(count*3), 0, count);
@@ -103,12 +103,9 @@ class Primitive {
public function render( engine : h3d.Engine ) {
if( buffer == null || buffer.isDisposed() ) alloc(engine);
- if( indexes == null ) {
- if( buffer.flags.has(Quads) )
- engine.renderQuadBuffer(buffer);
- engine.renderTriBuffer(buffer);
- } else
+ if( indexes == null )
+ engine.renderTriBuffer(buffer);
+ else
engine.renderIndexed(buffer,indexes);
@@ -97,7 +97,7 @@ class Quads extends Primitive {
var size = 3;
if( normals != null ) size += 3;
if( uvs != null ) size += 2;
- var flags : Array<h3d.Buffer.BufferFlag> = [Quads];
+ var flags : Array<h3d.Buffer.BufferFlag> = [];
if( normals == null ) flags.push(RawFormat);
buffer = h3d.Buffer.ofFloats(v, size, flags);
@@ -5,7 +5,7 @@ class RawPrimitive extends Primitive {
var vcount : Int;
var tcount : Int;
var bounds : h3d.col.Bounds;
- public var onContextLost : Void -> { vbuf : hxd.FloatBuffer, stride : Int, ?ibuf : hxd.IndexBuffer, ?quads : Bool };
+ public var onContextLost : Void -> { vbuf : hxd.FloatBuffer, stride : Int, ?ibuf : hxd.IndexBuffer };
public function new( inf : { vbuf : hxd.FloatBuffer, stride : Int, ?ibuf : hxd.IndexBuffer, ?quads : Bool, ?bounds : h3d.col.Bounds }, persist = false ) {
onContextLost = function() return inf;
@@ -18,11 +18,10 @@ class RawPrimitive extends Primitive {
if( onContextLost == null ) throw "Cannot realloc " + this;
var inf = onContextLost();
- if( inf.ibuf == null ) flags.push(inf.quads ? Quads : Triangles);
if( inf.stride < 8 ) flags.push(RawFormat);
buffer = h3d.Buffer.ofFloats(inf.vbuf, inf.stride, flags);
vcount = buffer.vertices;
- tcount = inf.ibuf != null ? Std.int(inf.ibuf.length / 3) : inf.quads ? vcount >> 1 : Std.int(vcount/3);
+ tcount = inf.ibuf != null ? Std.int(inf.ibuf.length / 3) : Std.int(vcount/3);
if( inf.ibuf != null )
indexes = h3d.Indexes.alloc(inf.ibuf);
else if( indexes != null ) {
@@ -4,7 +4,6 @@ enum abstract BufferFlags(Int) {
public var Dynamic = 0;
public var UniformDynamic = 1;
public var RawFormat = 2;
- public var RawQuads = 3;
public inline function toInt() : Int {
return this;
@@ -23,7 +22,6 @@ class Allocator {
case Dynamic: [Dynamic];
case UniformDynamic: [UniformBuffer,Dynamic];
case RawFormat: [RawFormat];
- case RawQuads: [Quads, RawFormat];
});
@@ -66,7 +66,7 @@ class CacheAllocator extends Allocator {
override function disposeBuffer(b:h3d.Buffer) {
if( b.isDisposed() ) return;
var f = b.flags;
- var flags = f.has(RawFormat) ? (f.has(Quads) ? RawQuads : RawFormat) : (f.has(UniformBuffer) ? UniformDynamic : Dynamic);
+ var flags = f.has(RawFormat) ? RawFormat : (f.has(UniformBuffer) ? UniformDynamic : Dynamic);
var id = flags.toInt() | (b.stride << 3) | (b.vertices << 16);
var c = buffers.get(id);
if( c == null ) {