|
@@ -72,25 +72,27 @@ Function Pow2Size( n )
|
|
|
Return t
|
|
|
End Function
|
|
|
|
|
|
-Global dead_texs[], n_dead_texs, dead_tex_seq
|
|
|
+Global dead_texs[],n_dead_texs,dead_tex_seq,n_live_texs
|
|
|
|
|
|
-'Enqueues a texture for deletion, to prevent release textures on wrong thread.
|
|
|
-'
|
|
|
-'Not thread safe, but that's OK because all threads are stopped when TGLImageFrame.Delete()
|
|
|
-'is called, which is what calls us.
|
|
|
+Extern
|
|
|
+ Function bbAtomicAdd:Int( target:Int Ptr,value:Int )="int bbAtomicAdd( int *,int )!"
|
|
|
+End Extern
|
|
|
|
|
|
-Function DeleteTex( name, seq )
|
|
|
+'Enqueues a texture for deletion, to prevent release textures on wrong thread.
|
|
|
+Function DeleteTex( name,seq )
|
|
|
+ If seq<>dead_tex_seq Return
|
|
|
+
|
|
|
+ Local n:Int = bbAtomicAdd(Varptr n_dead_texs, 1)
|
|
|
+ bbAtomicAdd(Varptr n_live_texs, -1)
|
|
|
|
|
|
- If seq <> dead_tex_seq Return
|
|
|
+ dead_texs[n] = name
|
|
|
+End Function
|
|
|
|
|
|
- 'add tex to queue
|
|
|
- If dead_texs.length = n_dead_texs
|
|
|
- dead_texs = dead_texs[..n_dead_texs + 256]
|
|
|
+Function _ManageDeadTexArray()
|
|
|
+ If dead_texs.length <= n_live_texs
|
|
|
+ ' expand array so it's large enough to hold all the current live textures.
|
|
|
+ dead_texs=dead_texs[..n_live_texs+20]
|
|
|
EndIf
|
|
|
-
|
|
|
- dead_texs[n_dead_texs] = name
|
|
|
- n_dead_texs :+ 1
|
|
|
-
|
|
|
End Function
|
|
|
|
|
|
Function CreateTex( width, height, flags )
|
|
@@ -99,6 +101,9 @@ Function CreateTex( width, height, flags )
|
|
|
Local name
|
|
|
glGenTextures( 1, Varptr name )
|
|
|
|
|
|
+ n_live_texs :+ 1
|
|
|
+ _ManageDeadTexArray()
|
|
|
+
|
|
|
'flush dead texs
|
|
|
If dead_tex_seq = GraphicsSeq
|
|
|
For Local i = 0 Until n_dead_texs
|