Add renderer support for matrix uniforms.

This commit is contained in:
Paul Chote
2013-02-22 23:05:13 +13:00
parent fb3e776cb9
commit 064938378f
4 changed files with 25 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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);
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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) { }
}