From 064938378f4fd5ebe9db8d55a515f07945e797e7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 22 Feb 2013 23:05:13 +1300 Subject: [PATCH] Add renderer support for matrix uniforms. --- OpenRA.FileFormats/Graphics/IGraphicsDevice.cs | 1 + OpenRA.Renderer.Cg/Shader.cs | 10 ++++++++++ OpenRA.Renderer.Gl/Shader.cs | 13 +++++++++++++ OpenRA.Renderer.Null/NullGraphicsDevice.cs | 1 + 4 files changed, 25 insertions(+) diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index 12231dadca..620f633011 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -62,6 +62,7 @@ namespace OpenRA.FileFormats.Graphics { void SetVec(string name, float x, float y); void SetTexture(string param, ITexture texture); + void SetMatrix(string param, float[] mtx); void Render(Action a); } diff --git a/OpenRA.Renderer.Cg/Shader.cs b/OpenRA.Renderer.Cg/Shader.cs index 59aac51084..88b341adce 100644 --- a/OpenRA.Renderer.Cg/Shader.cs +++ b/OpenRA.Renderer.Cg/Shader.cs @@ -81,5 +81,15 @@ namespace OpenRA.Renderer.Cg if (param != IntPtr.Zero) Tao.Cg.CgGl.cgGLSetParameter2f(param, x, y); } + + public void SetMatrix(string name, float[] mtx) + { + if (mtx.Length != 16) + throw new InvalidDataException("Invalid 4x4 matrix"); + + var param = Tao.Cg.Cg.cgGetNamedEffectParameter(effect, name); + if (param != IntPtr.Zero) + Tao.Cg.CgGl.cgGLSetMatrixParameterfr(param, mtx); + } } } diff --git a/OpenRA.Renderer.Gl/Shader.cs b/OpenRA.Renderer.Gl/Shader.cs index 069f15d536..9df56e1504 100644 --- a/OpenRA.Renderer.Gl/Shader.cs +++ b/OpenRA.Renderer.Gl/Shader.cs @@ -150,5 +150,18 @@ namespace OpenRA.Renderer.Glsl Gl.glUniform2fARB(param,x,y); ErrorHandler.CheckGlError(); } + + public void SetMatrix(string name, float[] mtx) + { + if (mtx.Length != 16) + throw new InvalidDataException("Invalid 4x4 matrix"); + + Gl.glUseProgramObjectARB(program); + ErrorHandler.CheckGlError(); + int param = Gl.glGetUniformLocationARB(program, name); + ErrorHandler.CheckGlError(); + Gl.glUniformMatrix4fv(param, 1, Gl.GL_FALSE, mtx); + ErrorHandler.CheckGlError(); + } } } diff --git a/OpenRA.Renderer.Null/NullGraphicsDevice.cs b/OpenRA.Renderer.Null/NullGraphicsDevice.cs index 742ac7f6b9..79497ead37 100644 --- a/OpenRA.Renderer.Null/NullGraphicsDevice.cs +++ b/OpenRA.Renderer.Null/NullGraphicsDevice.cs @@ -60,6 +60,7 @@ namespace OpenRA.Renderer.Null { public void SetVec(string name, float x, float y) { } public void SetTexture(string param, ITexture texture) { } + public void SetMatrix(string param, float[] mtx) { } public void Commit() { } public void Render(Action a) { } }