@yojimbo2000 I took your code and added more instances so I could check the average frames per second. Both programs draw 16240 rects. The first program uses instanceing and the second just creates a mesh with that many rects. The instanceing runs at an average FPS of 54.5 while the non instanceing runs at an average of 59.6 . I think I did everything right.
displayMode(FULLSCREEN)
--54.5
function setup()
m = mesh()
m:addRect(0,0,4,4)
m:setColors(color(255,200,0))
m.shader = shader(vert, frag)
numInstances = 140*116
tot,cnt=0,0
end
function draw()
background(40, 40, 50)
fill(255)
tot=tot+DeltaTime
cnt=cnt+1
text("Avg FPS "..string.format("%.2f",cnt/tot),WIDTH/2,HEIGHT-50)
text("numInstances "..numInstances,WIDTH/2,HEIGHT-80)
translate(30,50)
m:draw(numInstances)
end
vert=[[
#extension GL_EXT_draw_instanced: enable
uniform mat4 modelViewProjection;
attribute vec4 position;
attribute vec4 color;
varying lowp vec4 vColor;
void main()
{ vColor = color;
float xOffset = mod(float(gl_InstanceIDEXT), 140.) * 5.;
float yOffset = float(gl_InstanceIDEXT / 140) * 5.;
vec4 offset = vec4(xOffset, yOffset, 0, 0);
gl_Position = modelViewProjection * (position + offset);
}
]]
frag=[[
varying lowp vec4 vColor;
void main()
{ gl_FragColor = vColor;
}
]]
displayMode(FULLSCREEN)
--59.6
function setup()
m = mesh()
xs,ys=140,116
for x=1,xs do
for y=1,ys do
m:addRect(x*5,y*5,4,4)
end
end
m:setColors(color(255,200,0))
numInstances = xs*ys
tot,cnt=0,0
end
function draw()
background(40, 40, 50)
fill(255)
tot=tot+DeltaTime
cnt=cnt+1
text("Avg FPS "..string.format("%.2f",cnt/tot),WIDTH/2,HEIGHT-50)
text("numInstances "..numInstances,WIDTH/2,HEIGHT-80)
translate(30,50)
m:draw()
end