From db7a11e8a660b261ed8931fc496b3df2c35b498b Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 19 Aug 2010 18:33:52 +1200 Subject: [PATCH] some random bits --- OpenRA.Game/Graphics/HardwarePalette.cs | 7 +++---- OpenRA.Gl/Texture.cs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index d146f9fc85..e38b0fc12b 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -10,11 +10,10 @@ using System; using System.Collections.Generic; -using System.Drawing; -using OpenRA.FileFormats; -using OpenRA.Traits; -using OpenRA.FileFormats.Graphics; using System.Linq; +using OpenRA.FileFormats; +using OpenRA.FileFormats.Graphics; +using OpenRA.Traits; namespace OpenRA.Graphics { diff --git a/OpenRA.Gl/Texture.cs b/OpenRA.Gl/Texture.cs index d134e889ba..126ab02570 100644 --- a/OpenRA.Gl/Texture.cs +++ b/OpenRA.Gl/Texture.cs @@ -34,6 +34,30 @@ namespace OpenRA.GlRenderer SetData(bitmap); } + public void SetData(byte[] colors, int width, int height) + { + if (!IsPowerOf2(width) || !IsPowerOf2(height)) + throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height)); + + unsafe + { + fixed (byte* ptr = &colors[0]) + { + IntPtr intPtr = new IntPtr((void*)ptr); + + Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); + GraphicsDevice.CheckGlError(); + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_BASE_LEVEL, 0); + GraphicsDevice.CheckGlError(); + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAX_LEVEL, 0); + GraphicsDevice.CheckGlError(); + Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, width, height, + 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr); + GraphicsDevice.CheckGlError(); + } + } + } + // An array of RGBA public void SetData(uint[,] colors) {