// Public facing interface for loading a texture. Given a texture path it will return a handle // (index into managedTextures vector) which can later be used to draw the texture. public int LoadTexture(string texturePath) { if (!isInitialized) { Error("Trying to load texture without intializing texture manager!"); } // First, check if the texture is already being managed. If it is, increase ref count and // return the textures index. for (int i = 0; i < managedTextures.Count; ++i) { if (managedTextures[i].path == texturePath) { managedTextures[i].refCount += 1; return(i); } } // If the texture was not being tracked, go trough the list and look for an open space, if an // open space is found, unload it's texture from GPU memory, and load our new texture, override // the reference count, path, width, height and texture handle with new values for (int i = 0; i < managedTextures.Count; ++i) { if (managedTextures[i].refCount <= 0) { GL.DeleteTexture(managedTextures[i].glHandle); managedTextures[i].glHandle = LoadGLTexture(texturePath, out managedTextures[i].width, out managedTextures[i].height, UseNearestFiltering); managedTextures[i].refCount = 1; managedTextures[i].path = texturePath; return(i); } } // Finally we get here if the texture we are trying to load is not an already managed texture // and we have no open spots for new textures to be managed. Here we just create a new texture // and add it to the managed textures vector TextureInstance newTexture = new TextureInstance(); newTexture.refCount = 1; newTexture.glHandle = LoadGLTexture(texturePath, out newTexture.width, out newTexture.height, UseNearestFiltering); newTexture.path = texturePath; managedTextures.Add(newTexture); return(managedTextures.Count - 1); }
public int LoadTexture(string texturePath, bool UseNearestFiltering = false) { InitCheck("Trying to laod texture without initializing TextureManager!"); if (string.IsNullOrEmpty(texturePath)) { Error("Load texture file path was null"); throw new ArgumentException(texturePath); } //check if texture is already loaded, increase ref count if it is for (int i = 0; i < managedTextures.Count; i++) { if (managedTextures[i].path == texturePath) { managedTextures[i].refCount++; return(i); } } //try to recycle an old texture handle for (int i = 0; i < managedTextures.Count; i++) { if (managedTextures[i].refCount <= 0) { managedTextures[i].glHandle = LoadGLTexture(texturePath, out managedTextures[i].width, out managedTextures[i].height, UseNearestFiltering); managedTextures[i].refCount = 1; managedTextures[i].path = texturePath; return(i); } } //texture no loaded, no recyclable slots in array //load texture into new slot TextureInstance newTexture = new TextureInstance(); newTexture.refCount = 1; newTexture.glHandle = LoadGLTexture(texturePath, out newTexture.width, out newTexture.height, UseNearestFiltering); newTexture.path = texturePath; managedTextures.Add(newTexture); return(managedTextures.Count - 1); }
// Public facing interface for loading a texture. Given a texture path it will return a handle // (index into managedTextures vector) which can later be used to draw the texture. public int LoadTexture(string texturePath) { if (!isInitialized) { Error("Trying to load texture without intializing texture manager!"); } // First, check if the texture is already being managed. If it is, increase ref count and // return the textures index. for (int i = 0; i < managedTextures.Count; ++i) { if (managedTextures[i].path == texturePath) { managedTextures[i].refCount += 1; return i; } } // If the texture was not being tracked, go trough the list and look for an open space, if an // open space is found, unload it's texture from GPU memory, and load our new texture, override // the reference count, path, width, height and texture handle with new values for (int i = 0; i < managedTextures.Count; ++i) { if (managedTextures[i].refCount <= 0) { GL.DeleteTexture(managedTextures[i].glHandle); managedTextures[i].glHandle = LoadGLTexture(texturePath, out managedTextures[i].width, out managedTextures[i].height); managedTextures[i].refCount = 1; managedTextures[i].path = texturePath; return i; } } // Finally we get here if the texture we are trying to load is not an already managed texture // and we have no open spots for new textures to be managed. Here we just create a new texture // and add it to the managed textures vector TextureInstance newTexture = new TextureInstance(); newTexture.refCount = 1; newTexture.glHandle = LoadGLTexture(texturePath, out newTexture.width, out newTexture.height); newTexture.path = texturePath; managedTextures.Add(newTexture); return managedTextures.Count - 1; }
public int LoadTexture(string texturePath, bool UseNearestFiltering = false) { InitCheck("Trying to laod texture without initializing TextureManager!"); if (string.IsNullOrEmpty(texturePath)) { Error("Load texture file path was null"); throw new ArgumentException(texturePath); } //check if texture is already loaded, increase ref count if it is for (int i = 0; i < managedTextures.Count; i++) { if (managedTextures[i].path == texturePath) { managedTextures[i].refCount++; return i; } } //try to recycle an old texture handle for (int i = 0; i < managedTextures.Count; i++) { if (managedTextures[i].refCount <= 0) { managedTextures[i].glHandle = LoadGLTexture(texturePath, out managedTextures[i].width, out managedTextures[i].height, UseNearestFiltering); managedTextures[i].refCount = 1; managedTextures[i].path = texturePath; return i; } } //texture no loaded, no recyclable slots in array //load texture into new slot TextureInstance newTexture = new TextureInstance(); newTexture.refCount = 1; newTexture.glHandle = LoadGLTexture(texturePath, out newTexture.width, out newTexture.height, UseNearestFiltering); newTexture.path = texturePath; managedTextures.Add(newTexture); return managedTextures.Count - 1; }