EUREKA !!!!!!
SetMeshMemblockVertexColor is really bugged !!!
here is a piece of code to do the demonstration.
First, run the prog. with Test1 function and it crashes after a while - Look the fps. 22 at home on a old card.
then re-run the prog with Test2 function (comment test1) and .... it works very well and look the fps. 32 on the same pc.
How do you make the information go up to the editor ?
// Project: maxverts
// Created: 2018-03-08
//#insert "mesh.agc"
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Vertex Color" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
Setcameraposition(1,-10,10,-10)
SetCameraLookAt(1,50,0,50,0)
Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype
col = 0
color as integer [2,200,200]
Nb = 200
grid as Mesh
for z = 0 to Nb step 2
for x = 0 to Nb step 2
Height = 0
Color[0,x,z] = random(0,255)
Color[1,x,z] = Random(0,255)
Color[2,x,z] = Random(0,255)
rgb = makecolor(Color[0,x,z],color[1,x,z],color[2,x,z])
AddVertex(grid,x,height,z,0,1,0,mod(x,2),mod(z,2),rgb)
AddVertex(grid,x+2,height,z,0,1,0,mod(x,2),mod(z,2),rgb)
AddVertex(grid,x+2,height,z+2,0,1,0,mod(x,2),mod(z,2),rgb)
AddVertex(grid,x,height,z+2,0,1,0,mod(x,2),mod(z,2),rgb)
AddTriangle (grid,col,col+1,col+2)
AddTriangle (grid,col+2,col+3,col)
col=col+4
next x
next z
global memblock as integer
gridObject = CreateObjectFromMesh(grid)
vertex = GetMemblockInt(memblock,0)-1 //gridmem,0)-1
do
for z= 0 to nb step 2//Nb-1
time = GetMilliseconds()
for x = 0 to nb step 2//Nb-1
v0=x+z*(nb+1)*(z<nb+1)
v1=v0+1
v2=v1+nb+1
v3=v0+nb+1
test1(v0,v1,v2,v3) // <----- Version with SetMeshMemblockVertexColor and .... BUUUUUGGGGGG
// test2(v0,v1,v2,v3) // <----- Version with SetMemblockInt and .... IT'S GOOOOOD, Yeahhh
next x
next z
SetObjectMeshFromMemblock( GridObject, 1, memblock )
Print( ScreenFPS() )
print("Vertex = "+str(GetMemblockInt(memblock,0)))
print("Tris = "+str(grid.TriangleList.Length+1))
Sync()
loop
Function Test1(v0 as Integer, v1 as Integer, v2 as Integer, v3 as Integer)
r= random(0,255)
g= Random(0,255)
b= Random(0,255)
SetMeshMemblockVertexColor(memblock,v0,r,g,b,255)
SetMeshMemblockVertexColor(memblock,v1,r,g,b,255)
SetMeshMemblockVertexColor(memblock,v2,r,g,b,255)
SetMeshMemblockVertexColor(memblock,v3,r,g,b,255)
EndFunction
Function Test2(v0 as Integer, v1 as Integer, v2 as Integer, v3 as Integer)
rgb=makecolor(Random(0,255),Random(0,255),Random(0,255))
SetMemblockInt(memblock,104+v0*36,rgb)
SetMemblockInt(memblock,104+v1*36,rgb)
SetMemblockInt(memblock,104+v2*36,rgb)
SetMemblockInt(memblock,104+v3*36,rgb)
EndFunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction
Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer)
t as Triangle
t.v1 = v1
t.v2 = v2
t.v3 = v3
m.TriangleList.Insert(t)
endfunction
Function CreateObjectFromMesh(m ref as mesh)
VertexCount = m.VertexList.Length +1
IndexCount = (m.TriangleList.Length +1) * 3
IndexOffset = 72 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,4)
SetMemblockInt(memblock,12,36)
SetmemblockInt(memblock,16,72)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
SetMemblockInt(memblock,60,0x08010401)
SetMemblockString(memblock,64,"color")
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,72+i*36,m.VertexList[i].x)
SetMemblockFloat(memblock,76+i*36,m.VertexList[i].y)
SetMemblockFloat(memblock,80+i*36,m.VertexList[i].z)
SetMemblockFloat(memblock,84+i*36,m.VertexList[i].nx)
SetMemblockFloat(memblock,88+i*36,m.VertexList[i].ny)
SetMemblockFloat(memblock,92+i*36,m.VertexList[i].nz)
SetMemblockFloat(memblock,96+i*36,m.VertexList[i].u)
SetMemblockFloat(memblock,100+i*36,m.VertexList[i].v)
SetMemblockInt(memblock,104+i*36,m.VertexList[i].color)
next
for i = 0 to m.TriangleList.Length
SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
next
id = CreateObjectFromMeshMemblock(memblock)
//DeleteMemblock(memblock)
endfunction id