diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index 9c87ed95db..5d8c0d9e2c 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -32,6 +32,7 @@ namespace OpenRA.FileFormats.Graphics IVertexBuffer CreateVertexBuffer( int length ); IIndexBuffer CreateIndexBuffer( int length ); ITexture CreateTexture( Bitmap bitmap ); + ITexture CreateTexture(); IShader CreateShader( Stream stream ); Size WindowSize { get; } diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index 8879af56e0..af9521bfe0 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -21,16 +21,18 @@ namespace OpenRA.Graphics { public const int MaxPalettes = 64; int allocated = 0; - + ITexture texture; + // We need to store the Palettes themselves for the remap palettes to work // We should probably try to fix this somehow Dictionary palettes; Dictionary indices; - + public HardwarePalette(Map map) { palettes = new Dictionary(); indices = new Dictionary(); + texture = Game.Renderer.Device.CreateTexture(); } public Palette GetPalette(string name) @@ -81,17 +83,17 @@ namespace OpenRA.Graphics //foreach (var mod in paletteMods) // mod.AdjustPalette(b); - var data = new uint[256,MaxPalettes]; + var data = new uint[MaxPalettes,256]; foreach (var pal in palettes) { var j = indices[pal.Key]; var c = pal.Value.Values; for (var i = 0; i < 256; i++) - data[i,j] = c[i]; + data[j,i] = c[i]; } // Doesn't work - Texture.SetData(data); + texture.SetData(data); /* // Works var foo = new Bitmap(256,MaxPalettes); @@ -102,19 +104,7 @@ namespace OpenRA.Graphics Texture.SetData(foo); */ - Game.Renderer.PaletteTexture = Texture; - } - - ITexture texture; - public ITexture Texture - { - get - { - if (texture == null) - texture = Game.Renderer.Device.CreateTexture(new Bitmap(MaxPalettes, 256)); - - return texture; - } + Game.Renderer.PaletteTexture = texture; } } } diff --git a/OpenRA.Gl/GraphicsDevice.cs b/OpenRA.Gl/GraphicsDevice.cs index 385690a608..184fd7f312 100644 --- a/OpenRA.Gl/GraphicsDevice.cs +++ b/OpenRA.Gl/GraphicsDevice.cs @@ -283,6 +283,7 @@ namespace OpenRA.GlRenderer public IVertexBuffer CreateVertexBuffer(int size) { return new VertexBuffer(this, size); } public IIndexBuffer CreateIndexBuffer(int size) { return new IndexBuffer(this, size); } + public ITexture CreateTexture() { return new Texture(this); } public ITexture CreateTexture(Bitmap bitmap) { return new Texture(this, bitmap); } public IShader CreateShader(Stream stream) { return new Shader(this, stream); } } diff --git a/OpenRA.Gl/Texture.cs b/OpenRA.Gl/Texture.cs index b040d67dd8..fe8dc43682 100644 --- a/OpenRA.Gl/Texture.cs +++ b/OpenRA.Gl/Texture.cs @@ -20,7 +20,13 @@ namespace OpenRA.GlRenderer public class Texture : ITexture { internal int texture; - + + public Texture(GraphicsDevice dev) + { + Gl.glGenTextures(1, out texture); + GraphicsDevice.CheckGlError(); + } + public Texture(GraphicsDevice dev, Bitmap bitmap) { Gl.glGenTextures(1, out texture);