Thx for the comments.
@Ando Hm, I thought quads were only for fullscreen shaders. No Problem, all fine.
@blink0k Yes, I found the helper functions and use them for the attribute settings like position, normal, uv, and color. I found the main error of the last code: I had set the indices as float. But they are Integer. So the hole app crash without warning.
I try now to attach a main file from todays work, because it have > 1400 lines. It works and I have testet it. So it should out of bugs now. If anyone is interested in the code for FPS testing. It creates a clustered map (x,y,z) where each cluster is an object with multiple meshes. I build the Memblock for the mesh from scratch without a template primitive. I hope it's not hard to read. A help is written after the window creation.
It seems so that memblock created objects can have much more then 255 meshes, except the heighmaps. At least it has worked with a 20 x 20 cluster. Or it's an illusion. If some one have an idea how I can get more FPS in this test app, my eyes are wide open to read some ideas to optimize. I target a map of (250,5,250).
So have all a nice day or night.
The typ I need for the mesh memblock to pass by ref.
//----------------------------------------------------------------------
// create type for the mesh to pass by ref
//----------------------------------------------------------------------
type TMesh
Normal as integer
UV as integer
Color as integer
Memblock as integer
Vertices as integer
VertexOffset as integer
Indices as integer
IndexOffset as integer
x as float
y as float
z as float
Size as float
endtype
This function works to create a mesh memblock header. The attributes become added dynamic if they were enabled in TMesh.
//----------------------------------------------------------------------
// create the mesh memblock header
//----------------------------------------------------------------------
function SetMeshMemblockHeader(Mesh ref as TMesh)
Error = 0
// set mesh memblock header data for a simple plane
Mesh.Vertices = 4 // min points needed
Mesh.Indices = 6 // min points for triangles
Attributes = 1 // min attribute is 1 for position
// add attributes if enabled
if Mesh.Normal = 1 then inc Attributes
if Mesh.UV = 1 then inc Attributes
if Mesh.Color = 1 then inc Attributes
// additional attributes count must add her
// ...
// main header block end -> attribute pos in header
MainSize = 24
// measure the attribute block
// position is a must have
PositionSize = 4 + 12
PositionOffset = MainSize
VertexSize = 3 * 4
Offset = PositionOffset + PositionSize
// add dynamic attributes
// normals for light
NormalSize = 4 + 8
NormalOffset = Mesh.Normal * Offset
VertexSize = VertexSize + Mesh.Normal * 3 * 4
Offset = Offset + Mesh.Normal * NormalSize
// uv for texture
UVSize = 4 + 4
UVOffset = Mesh.UV * Offset
VertexSize = VertexSize + Mesh.UV * 2 * 4
Offset = Offset + Mesh.UV * UVSize
// vertex colors
ColorSize = 4 + 8
ColorOffset = Mesh.Color * Offset
VertexSize = VertexSize + Mesh.Color * 4
Offset = Offset + Mesh.Color * ColorSize
// more additional attributes must added here
// ...
// position of vertex paylod
Mesh.VertexOffset = Offset
// index size for triangle points remember it's integer not float
IndexSize = 4
// position of index payload
Mesh.IndexOffset = Mesh.VertexOffset + VertexSize * Mesh.Vertices
// prophesy the memblock size for the plane
MemblockSize = MainSize + PositionSize
MemblockSize = MemblockSize + Mesh.Normal * NormalSize
MemblockSize = MemblockSize + Mesh.UV * UVSize
MemblockSize = MemblockSize + Mesh.Color * ColorSize
// size of additinal attributes must added here
// ...
MemblockSize = MemblockSize + VertexSize * Mesh.Vertices
MemblockSize = MemblockSize + IndexSize * Mesh.Indices
if MemblockSize <> Mesh.IndexOffset + IndexSize * Mesh.Indices
Error = 1
else
// create a memblock object
Mesh.Memblock = CreateMemblock(MemblockSize)
// write memblock for a plane
// the header block for basic usage
SetMemblockInt(Mesh.Memblock,0,Mesh.Vertices) // vertex count (min points)
SetMemblockInt(Mesh.Memblock,4,Mesh.Indices) // indice count (min 2 triangles * 3 points)
SetMemblockInt(Mesh.Memblock,8,Attributes) // attribute count (position, normals, uv, color)
SetMemblockInt(Mesh.Memblock,12,VertexSize) // size of vertex data from defined attributes (8 floats + 4 color bytes)
SetMemblockInt(Mesh.Memblock,16,Mesh.VertexOffset)
SetMemblockInt(Mesh.Memblock,20,Mesh.IndexOffset)
// only basic attributes
// for other attributes count is a new calculation for offsets needed
// no idea for a good generic solution
// attribute discription position
SetMemblockByte(Mesh.Memblock,PositionOffset+0,0) // float type
SetMemblockByte(Mesh.Memblock,PositionOffset+1,3) // 3 components (x,y,z)
SetMemblockByte(Mesh.Memblock,PositionOffset+2,0) // normalize 0 (normalize is only for colors needed)
SetMemblockByte(Mesh.Memblock,PositionOffset+3,12) // 8 character + 1 nul terminator Round up to = 12
SetMemblockString(Mesh.Memblock,PositionOffset+4,"position") // can be all you mind
// attribute discription normals vector -1, 0 and 1
// no normal no light
if Mesh.Normal = 1
SetMemblockByte(Mesh.Memblock,NormalOffset+0,0)
SetMemblockByte(Mesh.Memblock,NormalOffset+1,3)
SetMemblockByte(Mesh.Memblock,NormalOffset+2,0)
SetMemblockByte(Mesh.Memblock,NormalOffset+3,8)
SetMemblockString(Mesh.Memblock,NormalOffset+4,"normal")
endif
// attribute discription uv 0.0 - 1.0
// no uv no sunburn no texture
if Mesh.UV = 1
SetMemblockByte(Mesh.Memblock,UVOffset+0,0)
SetMemblockByte(Mesh.Memblock,UVOffset+1,2)
SetMemblockByte(Mesh.Memblock,UVOffset+2,0)
SetMemblockByte(Mesh.Memblock,UVOffset+3,4)
SetMemblockString(Mesh.Memblock,UVOffset+4,"uv")
endif
// attribute discription color 0 - 255 * 4
// not clear if needed except for rainbow unicorns
if Mesh.Color = 1
SetMemblockByte(Mesh.Memblock,ColorOffset+0,1)
SetMemblockByte(Mesh.Memblock,ColorOffset+1,4)
SetMemblockByte(Mesh.Memblock,ColorOffset+2,1)
SetMemblockByte(Mesh.Memblock,ColorOffset+3,8)
SetMemblockString(Mesh.Memblock,ColorOffset+4,"color")
endif
endif
endfunction Error
The payload functions of the memblock to set the planes and cliffs in the cluster.
//----------------------------------------------------------------------
// create the mesh memblock payload for plane
//----------------------------------------------------------------------
function SetMeshMemblockSimplePlane(Mesh ref as TMesh)
// the payload for the memblock
// write vertex data
// first Corner 0,0
SetMeshMemblockVertexPosition(Mesh.Memblock,0,0,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,0,0,1,0)
if Mesh.UV = 1 then SetMeshMemblockVertexUV(Mesh.Memblock,0,0,0)
if Mesh.Color = 1 then SetMeshMemblockVertexColor(Mesh.Memblock,0,255,255,255,255)
// second corner 0,1
SetMeshMemblockVertexPosition(Mesh.Memblock,1,0,0,Mesh.Size)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,1,0,1,0)
if Mesh.UV = 1 then SetMeshMemblockVertexUV(Mesh.Memblock,1,0,1)
if Mesh.Color = 1 then SetMeshMemblockVertexColor(Mesh.Memblock,1,255,255,255,255)
// third corner 1,1
SetMeshMemblockVertexPosition(Mesh.Memblock,2,Mesh.Size,0,Mesh.Size)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,2,0,1,0)
if Mesh.UV = 1 then SetMeshMemblockVertexUV(Mesh.Memblock,2,1,1)
if Mesh.Color = 1 then SetMeshMemblockVertexColor(Mesh.Memblock,2,255,255,255,255)
// fourth corner 1,0
SetMeshMemblockVertexPosition(Mesh.Memblock,3,Mesh.Size,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,3,0,1,0)
if Mesh.UV = 1 then SetMeshMemblockVertexUV(Mesh.Memblock,3,1,0)
if Mesh.Color = 1 then SetMeshMemblockVertexColor(Mesh.Memblock,3,255,255,255,255)
// write the index data
// keep direction of triangles for top view of Plane
SetMemblockInt(Mesh.Memblock,Mesh.IndexOffset,0)
SetMemblockInt(Mesh.Memblock,Mesh.IndexOffset+4,3)
SetMemblockInt(Mesh.Memblock,Mesh.IndexOffset+8,1)
SetMemblockInt(Mesh.Memblock,Mesh.IndexOffset+12,2)
SetMemblockInt(Mesh.Memblock,Mesh.IndexOffset+16,1)
SetMemblockInt(Mesh.Memblock,Mesh.IndexOffset+20,3)
endfunction
//----------------------------------------------------------------------
// set only the position of mesh ground plane for cluster object
//----------------------------------------------------------------------
function SetMeshMemblockGroundPlanePosition(Mesh ref as TMesh)
SetMeshMemblockVertexPosition(Mesh.Memblock,0,Mesh.x,Mesh.y,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,1,Mesh.x,Mesh.y,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,2,Mesh.x+Mesh.Size,Mesh.y,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,3,Mesh.x+Mesh.Size,Mesh.y,Mesh.z)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,0,0,1,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,1,0,1,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,2,0,1,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,3,0,1,0)
endfunction
//----------------------------------------------------------------------
// set only the position of mesh cliff plane for cluster object
//----------------------------------------------------------------------
// SouthEast
function SetMeshMemblockGroundPlaneSouthEastPosition(Mesh ref as TMesh)
SetMeshMemblockVertexPosition(Mesh.Memblock,0,Mesh.x,Mesh.y-Mesh.Size,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,1,Mesh.x,Mesh.y,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,2,Mesh.x+Mesh.Size,Mesh.y,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,3,Mesh.x+Mesh.Size,Mesh.y-Mesh.Size,Mesh.z)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,0,0,0,-1)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,1,0,0,-1)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,2,0,0,-1)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,3,0,0,-1)
endfunction
// SouthWest
function SetMeshMemblockGroundPlaneSouthWestPosition(Mesh ref as TMesh)
SetMeshMemblockVertexPosition(Mesh.Memblock,0,Mesh.x,Mesh.y-Mesh.Size,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,1,Mesh.x,Mesh.y,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,2,Mesh.x,Mesh.y,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,3,Mesh.x,Mesh.y-Mesh.Size,Mesh.z)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,0,-1,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,1,-1,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,2,-1,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,3,-1,0,0)
endfunction
// NorthEast
function SetMeshMemblockGroundPlaneNorthEastPosition(Mesh ref as TMesh)
SetMeshMemblockVertexPosition(Mesh.Memblock,0,Mesh.x+Mesh.Size,Mesh.y-Mesh.Size,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,1,Mesh.x+Mesh.Size,Mesh.y,Mesh.z)
SetMeshMemblockVertexPosition(Mesh.Memblock,2,Mesh.x+Mesh.Size,Mesh.y,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,3,Mesh.x+Mesh.Size,Mesh.y-Mesh.Size,Mesh.z+Mesh.Size)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,0,1,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,1,1,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,2,1,0,0)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,3,1,0,0)
endfunction
// NorthWest
function SetMeshMemblockGroundPlaneNorthWestPosition(Mesh ref as TMesh)
SetMeshMemblockVertexPosition(Mesh.Memblock,0,Mesh.x+Mesh.Size,Mesh.y-Mesh.Size,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,1,Mesh.x+Mesh.Size,Mesh.y,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,2,Mesh.x,Mesh.y,Mesh.z+Mesh.Size)
SetMeshMemblockVertexPosition(Mesh.Memblock,3,Mesh.x,Mesh.y-Mesh.Size,Mesh.z+Mesh.Size)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,0,0,0,1)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,1,0,0,1)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,2,0,0,1)
if Mesh.Normal = 1 then SetMeshMemblockVertexNormal(Mesh.Memblock,3,0,0,1)
endfunction