I have a problem
for v8 of my landscape series, i want to enlarge the terrain (to have the same depth of view as in my "mountains" demo)
until now all tiles were built in advance
in v8, the tiles are built in real time
to avoid latency, I want to do it in multithreading
but in opengl, the mesh creation in multithreading doesn't work
someone has a solution ?
Below is an example of multithreaded mesh creation (compile in opengl to see the crash)
Code: Select all
Procedure threadmesh(i)
Shared Mutex
;LockMutex(Mutex)
CreateSphere(i,10+i*2)
;UnlockMutex(Mutex)
Debug "threadmesh "+i
EndProcedure
InitEngine3D():InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0, 0, 0,0, "test",#PB_Window_Maximize)
ex=WindowWidth (0,#PB_Window_InnerCoordinate)
ey=WindowHeight(0,#PB_Window_InnerCoordinate)
OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,0,-30):CameraLookAt(0,0,0,0)
CreateLight(0,$888888, 10000, 5000, 2000)
CameraBackColor(0,$220000)
AmbientColor($444444)
ndt=4
Mutex = CreateMutex()
Dim thread(ndt-1)
For i=0 To ndt-1
thread(i)=CreateThread(@ threadmesh(),i)
Debug ""+thread(i)+" "+i
Next
For i=0 To ndt-1:WaitThread(thread(i)):Next
Debug "ok"
CreateTexture(0,256,256):StartDrawing(TextureOutput(0)):For i=0 To 1000:Circle(Random(255),Random(255),Random(10),Random($ffffff)):Next:StopDrawing()
CreateMaterial(0,TextureID(0)):ScaleMaterial(0,0.1,0.2)
CreateEntity(0,MeshID(0),MaterialID(0))
Define.f depx,depz,mousex,mousey,dist
Repeat
WaitWindowEvent()
ExamineKeyboard()
ExamineMouse()
depx=(-Bool(KeyboardPushed(#PB_Key_Left))+Bool(KeyboardPushed(#PB_Key_Right)))*0.1
depz=(-Bool(KeyboardPushed(#PB_Key_Down))+Bool(KeyboardPushed(#PB_Key_Up )))*0.1+MouseWheel()*2
MouseX = -MouseDeltaX() * 0.05
MouseY = -MouseDeltaY() * 0.05
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
dist+(depz-dist)*0.05:MoveCamera (0, depX, 0, -dist)
RenderWorld()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)