report memory usage for textures

This commit is contained in:
Chris Forbes
2011-02-23 07:32:56 +13:00
parent a8d849a1cb
commit ad2ae8b763
5 changed files with 42 additions and 10 deletions

View File

@@ -36,6 +36,7 @@ namespace OpenRA.FileFormats.Graphics
IShader CreateShader( string name ); IShader CreateShader( string name );
Size WindowSize { get; } Size WindowSize { get; }
int GpuMemoryUsed { get; }
void Clear( Color color ); void Clear( Color color );
void Present( IInputHandler inputHandler ); void Present( IInputHandler inputHandler );

View File

@@ -318,5 +318,8 @@ namespace OpenRA.Renderer.Cg
public ITexture CreateTexture() { return new Texture( this ); } public ITexture CreateTexture() { return new Texture( this ); }
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); } public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); }
public IShader CreateShader( string name ) { return new Shader( this, name ); } public IShader CreateShader( string name ) { return new Shader( this, name ); }
public int GpuMemoryUsed { get { return 0; } }
} }
} }

View File

@@ -311,5 +311,7 @@ namespace OpenRA.Renderer.Glsl
public ITexture CreateTexture() { return new Texture( this ); } public ITexture CreateTexture() { return new Texture( this ); }
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); } public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); }
public IShader CreateShader( string name ) { return new Shader( this, name ); } public IShader CreateShader( string name ) { return new Shader( this, name ); }
public int GpuMemoryUsed { get; internal set; }
} }
} }

View File

@@ -20,15 +20,21 @@ namespace OpenRA.Renderer.Glsl
public class Texture : ITexture public class Texture : ITexture
{ {
internal int texture; internal int texture;
internal int memory;
GraphicsDevice dev;
public Texture(GraphicsDevice dev) public Texture(GraphicsDevice dev)
{ {
this.dev = dev;
Gl.glGenTextures(1, out texture); Gl.glGenTextures(1, out texture);
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }
public Texture(GraphicsDevice dev, Bitmap bitmap) public Texture(GraphicsDevice dev, Bitmap bitmap)
{ {
this.dev = dev;
Gl.glGenTextures(1, out texture); Gl.glGenTextures(1, out texture);
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
SetData(bitmap); SetData(bitmap);
@@ -50,6 +56,18 @@ namespace OpenRA.Renderer.Glsl
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }
void UpdateMemoryUsage( int newSize )
{
if (newSize == memory)
return;
dev.GpuMemoryUsed -= memory;
memory = newSize;
dev.GpuMemoryUsed += memory;
Log.Write("debug", "GPU Memory: {0:F2} MiB", dev.GpuMemoryUsed / 1024 / 1024f);
}
public void SetData(byte[] colors, int width, int height) public void SetData(byte[] colors, int width, int height)
{ {
if (!IsPowerOf2(width) || !IsPowerOf2(height)) if (!IsPowerOf2(width) || !IsPowerOf2(height))
@@ -66,6 +84,8 @@ namespace OpenRA.Renderer.Glsl
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }
} }
UpdateMemoryUsage(colors.Length);
} }
// An array of RGBA // An array of RGBA
@@ -88,6 +108,8 @@ namespace OpenRA.Renderer.Glsl
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }
} }
UpdateMemoryUsage(width * height * sizeof(uint));
} }
public void SetData(Bitmap bitmap) public void SetData(Bitmap bitmap)
@@ -108,6 +130,8 @@ namespace OpenRA.Renderer.Glsl
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, bits.Scan0); // todo: weird strides 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, bits.Scan0); // todo: weird strides
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
bitmap.UnlockBits(bits); bitmap.UnlockBits(bits);
UpdateMemoryUsage(bitmap.Width * bitmap.Height * sizeof(uint));
} }
bool IsPowerOf2(int v) bool IsPowerOf2(int v)

View File

@@ -47,6 +47,8 @@ namespace OpenRA.Renderer.Null
public ITexture CreateTexture() { return new NullTexture(); } public ITexture CreateTexture() { return new NullTexture(); }
public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); } public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }
public IShader CreateShader(string name) { return new NullShader(); } public IShader CreateShader(string name) { return new NullShader(); }
public int GpuMemoryUsed { get { return 0; } }
} }
public class NullIndexBuffer : IIndexBuffer public class NullIndexBuffer : IIndexBuffer