1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics.OpenGL;
namespace Microsoft.Xna.Framework.Graphics
{
public class EffectParameter
{
EffectParameterType paramType;
EffectParameterClass paramClass;
int rowCount;
string name;
int colCount;
EffectParameterCollection elements;
string semantic;
EffectParameterCollection structMembers;
object _cachedValue = null;
private int internalIndex; // used by opengl processes.
private int uniformLocation;
private int userIndex; // desired index by the user
int internalLength;
Effect _parentEffect;
internal int UserInedx
{
get { return userIndex; }
}
internal int UniformLocation
{
get { return uniformLocation; }
}
internal EffectParameter(Effect parent, string paramName, int paramIndex, int userIndex, int uniformLocation,
string paramSType, int paramLength)
{
_parentEffect = parent;
name = paramName;
internalIndex = paramIndex;
internalLength = paramLength;
this.userIndex = userIndex;
this.uniformLocation = uniformLocation;
switch (paramSType ){
case "Float":
paramType = EffectParameterType.Single;
paramClass = EffectParameterClass.Scalar;
rowCount = 1;
colCount = 1;
_cachedValue = 0.0f;
break;
case "FloatVec2":
paramType = EffectParameterType.Single;
paramClass = EffectParameterClass.Vector;
rowCount = 1;
colCount = 2;
_cachedValue = OpenTK.Vector2.Zero;
break;
case "FloatVec3":
paramType = EffectParameterType.Single;
paramClass = EffectParameterClass.Vector;
rowCount = 1;
colCount = 3;
_cachedValue =OpenTK.Vector3.Zero;
break;
case "FloatVec4":
paramType = EffectParameterType.Single;
paramClass = EffectParameterClass.Vector;
rowCount = 1;
colCount = 4;
_cachedValue = OpenTK.Vector4.Zero;
break;
case "Sampler2D":
paramType = EffectParameterType.Texture2D;
paramClass = EffectParameterClass.Object;
rowCount = 0;
colCount = 0;
break;
case "FloatMat4":
paramType = EffectParameterType.Single;
paramClass = EffectParameterClass.Matrix;
rowCount = 4;
colCount = 4;
_cachedValue = OpenTK.Matrix4.Identity;
break;
}
}
public int ColumnCount {
get { return colCount; }
}
public EffectParameterCollection Elements {
get { return elements; }
}
public string Name {
get { return name; }
}
public EffectParameterClass ParameterClass {
get { return paramClass;}
}
public EffectParameterType ParameterType {
get { return paramType;}
}
public int RowCount {
get { return rowCount; }
}
public string Semantic {
get { return semantic; }
}
EffectParameterCollection StructureMembers {
get { return structMembers; }
}
public void SetValue (object value)
{
}
public bool GetValueBoolean ()
{
return true;
}
public bool[] GetValueBooleanArray ()
{
return new bool[0];
}
public int GetValueInt32 ()
{
return 0;
}
public int[] GetValueInt32Array ()
{
return new int[0];
}
public Matrix GetValueMatrix ()
{
return new Matrix ();
}
public Matrix[] GetValueMatrixArray ()
{
return new Matrix[0];
}
public Quaternion GetValueQuaternion ()
{
return new Quaternion ();
}
public Quaternion[] GetValueQuaternionArray ()
{
return new Quaternion[0];
}
public Single GetValueSingle ()
{
return new Single ();
}
public Single[] GetValueSingleArray ()
{
return new Single[0];
}
public string GetValueString ()
{
return String.Empty;
}
public Texture2D GetValueTexture2D ()
{
return null; //new Texture2D ();
}
// public Texture3D GetValueTexture3D ()
// {
// return new Texture3D ();
// }
// public TextureCube GetValueTextureCube ()
// {
// return null; //new TextureCube ();
// }
public Vector2 GetValueVector2 ()
{
return Vector2.One;
}
public Vector2[] GetValueVector2Array ()
{
return new Vector2[0];
}
public Vector3 GetValueVector3 ()
{
return Vector3.One;
}
public Vector3[] GetValueVector3Array ()
{
return new Vector3[0];
}
public Vector4 GetValueVector4 ()
{
return Vector4.One;
}
public Vector4[] GetValueVector4Array ()
{
return new Vector4[0];
}
public void SetValue (bool value)
{
}
public void SetValue (bool[] value)
{
}
public void SetValue (int value)
{
}
public void SetValue (int[] value)
{
}
public void SetValue (Matrix value)
{
}
public void SetValue (Matrix[] value)
{
}
public void SetValue (Quaternion value)
{
}
public void SetValue (Quaternion[] value)
{
}
public void SetValue (Single value)
{
GL.UseProgram(_parentEffect.CurrentTechnique.Passes[0].shaderProgram);
//MonoMac.OpenGL.Vector2 vect2 = new MonoMac.OpenGL.Vector2(value.X, value.Y);
_cachedValue = value;
GL.Uniform1(internalIndex,value);
GL.UseProgram(0);
}
public void SetValue (Single[] value)
{
}
public void SetValue (string value)
{
}
public void SetValue (Texture value)
{
GL.UseProgram(_parentEffect.CurrentTechnique.Passes[0].shaderProgram);
GL.ActiveTexture(TextureUnit.Texture1);
GL.BindTexture(TextureTarget.Texture2D,value._textureId);
GL.Uniform1(internalIndex, value._textureId);
_cachedValue = value._textureId;
GL.UseProgram(0);
}
public void SetValue (Vector2 value)
{
GL.UseProgram(_parentEffect.CurrentTechnique.Passes[0].shaderProgram);
OpenTK.Vector2 vect2 = new OpenTK.Vector2(value.X, value.Y);
_cachedValue = vect2;
GL.Uniform2(internalIndex,vect2);
GL.UseProgram(0);
}
public void SetValue (Vector2[] value)
{
}
public void SetValue (Vector3 value)
{
GL.UseProgram(_parentEffect.CurrentTechnique.Passes[0].shaderProgram);
OpenTK.Vector3 vect3 = new OpenTK.Vector3(value.X, value.Y, value.Z);
_cachedValue = vect3;
GL.Uniform3(internalIndex,vect3);
GL.UseProgram(0);
}
public void SetValue (Vector3[] value)
{
}
public void SetValue (Vector4 value)
{
GL.UseProgram(_parentEffect.CurrentTechnique.Passes[0].shaderProgram);
OpenTK.Vector4 vect4 = new OpenTK.Vector4(value.X, value.Y, value.Z, value.W);
_cachedValue = vect4;
GL.Uniform4(internalIndex,vect4);
GL.UseProgram(0);
}
public void SetValue (Vector4[] value)
{
}
internal void ApplyEffectValue()
{
switch (ParameterClass) {
case EffectParameterClass.Vector:
ApplyVectorValue();
break;
}
}
private void ApplyVectorValue()
{
switch (rowCount) {
case 2:
GL.Uniform2(internalIndex,(OpenTK.Vector2)_cachedValue);
break;
}
}
}
}
|