; RenderInstancedDraws Example ; ---------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,6,-20 CameraClsColor camera,20,30,50 light=CreateLight() RotateEntity light,45,45,0 ground=CreatePlane() EntityColor ground,60,80,55 ; Two mesh families: copies within each family share a mesh, so each ; family collapses into one draw call carrying many hardware instances crate=CreateCube() ScaleMesh crate,0.5,0.5,0.5 EntityColor crate,180,90,60 orb=CreateSphere(8) ScaleMesh orb,0.6,0.6,0.6 EntityColor orb,80,200,255 Dim crates(59) Dim orbs(59) For n=0 To 59 crates(n)=CopyEntity(crate) PositionEntity crates(n),(n Mod 10)*3-13,0.5,(n/10)*3+4 orbs(n)=CopyEntity(orb) PositionEntity orbs(n),(n Mod 10)*3-12,2.5,(n/10)*3+4 Next HideEntity crate HideEntity orb orbs_on=True While Not KeyDown(1) ; Space hides or shows the orb family - one instanced draw appears/vanishes If KeyHit(57) orbs_on=Not orbs_on For n=0 To 59 If orbs_on ShowEntity orbs(n) Else HideEntity orbs(n) EndIf Next EndIf ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld ; Draw calls that carried more than one hardware instance Text 0,0,"Arrow keys: move camera Space: toggle orbs Esc: exit" Text 0,20,"RenderInstancedDraws() = "+RenderInstancedDraws() Text 0,40,"60 crates = 1 instanced draw, 60 orbs = 1 more" Flip Wend End