Add renderer support for additional vec* uniforms.
This commit is contained in:
@@ -60,7 +60,9 @@ namespace OpenRA.FileFormats.Graphics
|
|||||||
|
|
||||||
public interface IShader
|
public interface IShader
|
||||||
{
|
{
|
||||||
|
void SetVec(string name, float x);
|
||||||
void SetVec(string name, float x, float y);
|
void SetVec(string name, float x, float y);
|
||||||
|
void SetVec(string name, float[] vec, int length);
|
||||||
void SetTexture(string param, ITexture texture);
|
void SetTexture(string param, ITexture texture);
|
||||||
void SetMatrix(string param, float[] mtx);
|
void SetMatrix(string param, float[] mtx);
|
||||||
void Render(Action a);
|
void Render(Action a);
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ namespace OpenRA.Renderer.Cg
|
|||||||
Tao.Cg.CgGl.cgGLSetupSampler(param, texture.texture);
|
Tao.Cg.CgGl.cgGLSetupSampler(param, texture.texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetVec(string name, float x)
|
||||||
|
{
|
||||||
|
var param = Tao.Cg.Cg.cgGetNamedEffectParameter(effect, name);
|
||||||
|
if (param != IntPtr.Zero)
|
||||||
|
Tao.Cg.CgGl.cgGLSetParameter1f(param, x);
|
||||||
|
}
|
||||||
|
|
||||||
public void SetVec(string name, float x, float y)
|
public void SetVec(string name, float x, float y)
|
||||||
{
|
{
|
||||||
var param = Tao.Cg.Cg.cgGetNamedEffectParameter(effect, name);
|
var param = Tao.Cg.Cg.cgGetNamedEffectParameter(effect, name);
|
||||||
@@ -82,6 +89,22 @@ namespace OpenRA.Renderer.Cg
|
|||||||
Tao.Cg.CgGl.cgGLSetParameter2f(param, x, y);
|
Tao.Cg.CgGl.cgGLSetParameter2f(param, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetVec(string name, float[] vec, int length)
|
||||||
|
{
|
||||||
|
var param = Tao.Cg.Cg.cgGetNamedEffectParameter(effect, name);
|
||||||
|
if (param == IntPtr.Zero)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch(length)
|
||||||
|
{
|
||||||
|
case 1: Tao.Cg.CgGl.cgGLSetParameter1fv(param, vec); break;
|
||||||
|
case 2: Tao.Cg.CgGl.cgGLSetParameter2fv(param, vec); break;
|
||||||
|
case 3: Tao.Cg.CgGl.cgGLSetParameter3fv(param, vec); break;
|
||||||
|
case 4: Tao.Cg.CgGl.cgGLSetParameter4fv(param, vec); break;
|
||||||
|
default: throw new InvalidDataException("Invalid vector length");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetMatrix(string name, float[] mtx)
|
public void SetMatrix(string name, float[] mtx)
|
||||||
{
|
{
|
||||||
if (mtx.Length != 16)
|
if (mtx.Length != 16)
|
||||||
|
|||||||
@@ -141,6 +141,16 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
textures[texUnit] = t;
|
textures[texUnit] = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetVec(string name, float x)
|
||||||
|
{
|
||||||
|
Gl.glUseProgramObjectARB(program);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
int param = Gl.glGetUniformLocationARB(program, name);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
Gl.glUniform1fARB(param,x);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetVec(string name, float x, float y)
|
public void SetVec(string name, float x, float y)
|
||||||
{
|
{
|
||||||
Gl.glUseProgramObjectARB(program);
|
Gl.glUseProgramObjectARB(program);
|
||||||
@@ -151,6 +161,21 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetVec(string name, float[] vec, int length)
|
||||||
|
{
|
||||||
|
int param = Gl.glGetUniformLocationARB(program, name);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
switch(length)
|
||||||
|
{
|
||||||
|
case 1: Gl.glUniform1fv(param, 1, vec); break;
|
||||||
|
case 2: Gl.glUniform2fv(param, 1, vec); break;
|
||||||
|
case 3: Gl.glUniform3fv(param, 1, vec); break;
|
||||||
|
case 4: Gl.glUniform4fv(param, 1, vec); break;
|
||||||
|
default: throw new InvalidDataException("Invalid vector length");
|
||||||
|
}
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetMatrix(string name, float[] mtx)
|
public void SetMatrix(string name, float[] mtx)
|
||||||
{
|
{
|
||||||
if (mtx.Length != 16)
|
if (mtx.Length != 16)
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ namespace OpenRA.Renderer.Null
|
|||||||
|
|
||||||
public class NullShader : IShader
|
public class NullShader : IShader
|
||||||
{
|
{
|
||||||
|
public void SetVec(string name, float x) { }
|
||||||
public void SetVec(string name, float x, float y) { }
|
public void SetVec(string name, float x, float y) { }
|
||||||
|
public void SetVec(string name, float[] vec, int length) { }
|
||||||
public void SetTexture(string param, ITexture texture) { }
|
public void SetTexture(string param, ITexture texture) { }
|
||||||
public void SetMatrix(string param, float[] mtx) { }
|
public void SetMatrix(string param, float[] mtx) { }
|
||||||
public void Commit() { }
|
public void Commit() { }
|
||||||
|
|||||||
Reference in New Issue
Block a user