Clean references to disposed textures.
This commit is contained in:
committed by
RoosterDragon
parent
d712bdea85
commit
91c63034d3
@@ -297,6 +297,9 @@ namespace OpenRA.Platforms.Default
|
|||||||
public delegate void DeleteTextures(int n, ref uint textures);
|
public delegate void DeleteTextures(int n, ref uint textures);
|
||||||
public static DeleteTextures glDeleteTextures { get; private set; }
|
public static DeleteTextures glDeleteTextures { get; private set; }
|
||||||
|
|
||||||
|
public delegate bool IsTexture(uint texture);
|
||||||
|
public static IsTexture glIsTexture { get; private set; }
|
||||||
|
|
||||||
public delegate void BindTexture(int target, uint texture);
|
public delegate void BindTexture(int target, uint texture);
|
||||||
public static BindTexture glBindTexture { get; private set; }
|
public static BindTexture glBindTexture { get; private set; }
|
||||||
|
|
||||||
@@ -423,6 +426,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
glReadPixels = Bind<ReadPixels>("glReadPixels");
|
glReadPixels = Bind<ReadPixels>("glReadPixels");
|
||||||
glGenTextures = Bind<GenTextures>("glGenTextures");
|
glGenTextures = Bind<GenTextures>("glGenTextures");
|
||||||
glDeleteTextures = Bind<DeleteTextures>("glDeleteTextures");
|
glDeleteTextures = Bind<DeleteTextures>("glDeleteTextures");
|
||||||
|
glIsTexture = Bind<IsTexture>("glIsTexture");
|
||||||
glBindTexture = Bind<BindTexture>("glBindTexture");
|
glBindTexture = Bind<BindTexture>("glBindTexture");
|
||||||
glActiveTexture = Bind<ActiveTexture>("glActiveTexture");
|
glActiveTexture = Bind<ActiveTexture>("glActiveTexture");
|
||||||
glTexImage2D = Bind<TexImage2D>("glTexImage2D");
|
glTexImage2D = Bind<TexImage2D>("glTexImage2D");
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
|
|
||||||
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
|
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
|
||||||
readonly Dictionary<int, ITexture> textures = new Dictionary<int, ITexture>();
|
readonly Dictionary<int, ITexture> textures = new Dictionary<int, ITexture>();
|
||||||
|
readonly Queue<int> unbindTextures = new Queue<int>();
|
||||||
readonly uint program;
|
readonly uint program;
|
||||||
|
|
||||||
protected uint CompileShaderObject(int type, string name)
|
protected uint CompileShaderObject(int type, string name)
|
||||||
@@ -138,10 +139,21 @@ namespace OpenRA.Platforms.Default
|
|||||||
// bind the textures
|
// bind the textures
|
||||||
foreach (var kv in textures)
|
foreach (var kv in textures)
|
||||||
{
|
{
|
||||||
OpenGL.glActiveTexture(OpenGL.GL_TEXTURE0 + kv.Key);
|
var id = ((ITextureInternal)kv.Value).ID;
|
||||||
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, ((ITextureInternal)kv.Value).ID);
|
|
||||||
|
// Evict disposed textures from the cache
|
||||||
|
if (OpenGL.glIsTexture(id))
|
||||||
|
{
|
||||||
|
OpenGL.glActiveTexture(OpenGL.GL_TEXTURE0 + kv.Key);
|
||||||
|
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
unbindTextures.Enqueue(kv.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (unbindTextures.Count > 0)
|
||||||
|
textures.Remove(unbindTextures.Dequeue());
|
||||||
|
|
||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user