public static void SetRegionData(ivec4 region, int[] data, int stride) { var x = region.x; var y = region.y; var width = region.width; var height = region.height; Debug.Assert(x > 0); Debug.Assert(y > 0); Debug.Assert(x < (m_nWidth - 1)); Debug.Assert((x + width) <= (m_nWidth - 1)); Debug.Assert(y < (m_nHeight - 1)); Debug.Assert((y + height) <= (m_nHeight - 1)); var depth = m_nDepth; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; j++) { var b = (byte)((data[i * stride + j] & 0xFF0000) >> 16); m_pData[((y + i) * m_nWidth + x) + j] = b << 24 | b << 16 | b << 8 | b; } // Array.Copy(data, (i * stride), m_pData, ((y + i) * m_nWidth + x), width); // Buffer.BlockCopy(data, (i * stride), m_pData, ((y + i) * m_nWidth + x) * depth, width * depth); } }
public void Indexer() { var v = new ivec4(9, -7, -3, -9); Assert.AreEqual(9, v[0]); Assert.AreEqual(-7, v[1]); Assert.AreEqual(-3, v[2]); Assert.AreEqual(-9, v[3]); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-2147483648]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[-2147483648] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-1]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[-1] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[4]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[4] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[2147483647]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[2147483647] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[5]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[5] = 0; }); v[3] = 0; Assert.AreEqual(0, v[3]); v[2] = 1; Assert.AreEqual(1, v[2]); v[1] = 2; Assert.AreEqual(2, v[1]); v[3] = 3; Assert.AreEqual(3, v[3]); v[1] = 4; Assert.AreEqual(4, v[1]); v[0] = 5; Assert.AreEqual(5, v[0]); v[1] = 6; Assert.AreEqual(6, v[1]); v[2] = 7; Assert.AreEqual(7, v[2]); v[1] = 8; Assert.AreEqual(8, v[1]); v[1] = 9; Assert.AreEqual(9, v[1]); v[2] = -1; Assert.AreEqual(-1, v[2]); v[1] = -2; Assert.AreEqual(-2, v[1]); v[0] = -3; Assert.AreEqual(-3, v[0]); v[1] = -4; Assert.AreEqual(-4, v[1]); v[1] = -5; Assert.AreEqual(-5, v[1]); v[0] = -6; Assert.AreEqual(-6, v[0]); v[3] = -7; Assert.AreEqual(-7, v[3]); v[2] = -8; Assert.AreEqual(-8, v[2]); v[1] = -9; Assert.AreEqual(-9, v[1]); }
public void PropertyValues() { var v = new ivec4(-7, -5, -7, -3); var vals = v.Values; Assert.AreEqual(-7, vals[0]); Assert.AreEqual(-5, vals[1]); Assert.AreEqual(-7, vals[2]); Assert.AreEqual(-3, vals[3]); Assert.That(vals.SequenceEqual(v.ToArray())); }
/// <summary> /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix. /// </summary> public imat2x4(ivec4 c0, ivec4 c1) { this.m00 = c0.x; this.m01 = c0.y; this.m02 = c0.z; this.m03 = c0.w; this.m10 = c1.x; this.m11 = c1.y; this.m12 = c1.z; this.m13 = c1.w; }
public void SerializationJson() { var v0 = new ivec4(-8, -1, 6, -1); var s0 = JsonConvert.SerializeObject(v0); var v1 = JsonConvert.DeserializeObject <ivec4>(s0); var s1 = JsonConvert.SerializeObject(v1); Assert.AreEqual(v0, v1); Assert.AreEqual(s0, s1); }
public void InvariantCommutative() { { var v0 = new ivec4(-2, -3, 4, 2); var v1 = new ivec4(2, 0, 4, 0); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(7, -6, 5, -4); var v1 = new ivec4(-4, -4, -1, -5); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(8, 5, -2, 0); var v1 = new ivec4(2, 2, -1, -3); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(-3, 1, -2, -3); var v1 = new ivec4(-2, 4, -9, -4); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(6, 6, 7, 0); var v1 = new ivec4(-4, -5, 5, -6); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(-8, -4, 8, -1); var v1 = new ivec4(-7, -5, -4, 6); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(-5, -8, -6, 6); var v1 = new ivec4(0, 2, -9, 9); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(1, -2, 9, 1); var v1 = new ivec4(8, -1, 8, 2); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(-7, -2, 6, 6); var v1 = new ivec4(5, -1, 1, -3); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new ivec4(0, -6, 1, 7); var v1 = new ivec4(-3, 0, -5, -7); Assert.AreEqual(v0 * v1, v1 * v0); } }
public void InvariantCommutativeNeg() { { var v0 = new ivec4(3, -6, 6, 4); var v1 = new ivec4(4, 1, -4, 4); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(4, 6, 3, -5); var v1 = new ivec4(9, -1, 1, -3); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(-2, 3, -2, 2); var v1 = new ivec4(-2, -6, -6, 2); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(5, 1, 7, 3); var v1 = new ivec4(1, -3, -7, 9); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(4, -3, -1, -8); var v1 = new ivec4(-2, -4, -8, -2); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(-4, -1, 3, 0); var v1 = new ivec4(-7, -3, -2, 3); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(1, -5, -6, -7); var v1 = new ivec4(9, 4, -1, 6); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(0, 3, -9, 3); var v1 = new ivec4(-4, -1, 2, -2); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(9, -4, -1, -6); var v1 = new ivec4(-9, 3, 0, -8); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new ivec4(4, 0, 7, 0); var v1 = new ivec4(-2, -5, 5, -3); Assert.AreEqual(v0 - v1, -(v1 - v0)); } }
public void TriangleInequality() { { var v0 = new ivec4(-4, 7, 2, 7); var v1 = new ivec4(5, 4, 9, 1); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(-2, 0, 1, -2); var v1 = new ivec4(2, -1, 5, -5); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(2, 7, -7, 1); var v1 = new ivec4(-6, -6, 9, -1); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(8, 6, 4, 0); var v1 = new ivec4(0, 8, -8, -5); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(-3, -3, -6, -8); var v1 = new ivec4(2, -2, 1, -5); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(-3, -5, 9, 7); var v1 = new ivec4(-6, 4, -5, 1); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(-3, 0, -3, -1); var v1 = new ivec4(-4, -5, -2, -8); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(-7, -2, -8, -9); var v1 = new ivec4(-9, 9, 0, 2); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(2, 6, -8, 9); var v1 = new ivec4(-5, 7, -3, 9); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new ivec4(5, 2, 8, 1); var v1 = new ivec4(6, 2, -4, 4); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } }
public void Operators() { var v1 = new ivec4(2, 5, 1, -8); var v2 = new ivec4(2, 5, 1, -8); var v3 = new ivec4(-8, 1, 5, 2); Assert.That(v1 == new ivec4(v1)); Assert.That(v2 == new ivec4(v2)); Assert.That(v3 == new ivec4(v3)); Assert.That(v1 == v2); Assert.That(v1 != v3); Assert.That(v2 != v3); }
public void StringInterop() { var v = new ivec4(8, 0, 3, -7); var s0 = v.ToString(); var s1 = v.ToString("#"); var v0 = ivec4.Parse(s0); var v1 = ivec4.Parse(s1, "#"); Assert.AreEqual(v, v0); Assert.AreEqual(v, v1); var b0 = ivec4.TryParse(s0, out v0); var b1 = ivec4.TryParse(s1, "#", out v1); Assert.That(b0); Assert.That(b1); Assert.AreEqual(v, v0); Assert.AreEqual(v, v1); b0 = ivec4.TryParse(null, out v0); Assert.False(b0); b0 = ivec4.TryParse("", out v0); Assert.False(b0); b0 = ivec4.TryParse(s0 + ", 0", out v0); Assert.False(b0); Assert.Throws <NullReferenceException>(() => { ivec4.Parse(null); }); Assert.Throws <FormatException>(() => { ivec4.Parse(""); }); Assert.Throws <FormatException>(() => { ivec4.Parse(s0 + ", 0"); }); var s2 = v.ToString(";", CultureInfo.InvariantCulture); Assert.That(s2.Length > 0); var s3 = v.ToString("; ", "G"); var s4 = v.ToString("; ", "G", CultureInfo.InvariantCulture); var v3 = ivec4.Parse(s3, "; ", NumberStyles.Number); var v4 = ivec4.Parse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture); Assert.AreEqual(v, v3); Assert.AreEqual(v, v4); var b4 = ivec4.TryParse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture, out v4); Assert.That(b4); Assert.AreEqual(v, v4); }
/// <summary> /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix. /// </summary> public imat3x4(ivec4 c0, ivec4 c1, ivec4 c2) { this.m00 = c0.x; this.m01 = c0.y; this.m02 = c0.z; this.m03 = c0.w; this.m10 = c1.x; this.m11 = c1.y; this.m12 = c1.z; this.m13 = c1.w; this.m20 = c2.x; this.m21 = c2.y; this.m22 = c2.z; this.m23 = c2.w; }
/// <summary> /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix. /// </summary> public imat3x4(ivec4 c0, ivec4 c1) { this.m00 = c0.x; this.m01 = c0.y; this.m02 = c0.z; this.m03 = c0.w; this.m10 = c1.x; this.m11 = c1.y; this.m12 = c1.z; this.m13 = c1.w; this.m20 = 0; this.m21 = 0; this.m22 = 1; this.m23 = 0; }
public void InvariantTriple() { { var v0 = new ivec4(3, 7, -8, 0); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(-3, 5, 3, -9); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(3, -5, 3, 1); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(9, 0, 3, 2); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(-7, -1, -1, -6); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(6, -6, -9, -5); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(-4, -9, 4, -4); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(-2, 0, -4, 6); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(-2, 2, 6, -8); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new ivec4(3, 4, -1, 6); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } }
public void InvariantId() { { var v0 = new ivec4(-1, -4, -9, -2); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(-7, -5, -7, 4); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(6, -2, -3, -2); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(9, 4, -3, 5); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(-2, 4, -5, -2); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(8, -7, -6, -6); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(9, -1, 8, -8); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(5, 0, 5, -6); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(5, 2, -2, -9); Assert.AreEqual(v0, +v0); } { var v0 = new ivec4(1, 9, -4, -3); Assert.AreEqual(v0, +v0); } }
public void InvariantDouble() { { var v0 = new ivec4(-1, 7, 8, 9); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(5, 5, 8, 8); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(9, 5, 2, -8); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(-4, 7, 1, 5); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(-8, 9, -2, 8); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(-7, 5, 1, -2); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(-5, -9, 9, 2); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(-4, 0, 4, -1); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(4, 1, 4, -8); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new ivec4(-5, 1, -8, -6); Assert.AreEqual(v0 + v0, 2 * v0); } }
public void InvariantIdNeg() { { var v0 = new ivec4(6, 7, -4, 7); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-3, 2, -1, 8); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-8, -9, -7, -4); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-8, -3, -2, 0); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-7, -1, 0, 6); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-3, 5, -2, -1); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-4, 3, 7, 2); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-2, -3, 8, 6); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(2, 2, -4, 8); Assert.AreEqual(v0, -(-v0)); } { var v0 = new ivec4(-6, 4, -8, -6); Assert.AreEqual(v0, -(-v0)); } }
public void InvariantNorm() { { var v0 = new ivec4(4, -1, -2, -1); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(2, 0, -8, -9); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(4, 8, -1, -3); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(-8, 6, 0, 8); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(-1, 7, 9, 2); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(4, 2, -3, 6); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(9, 4, -2, 8); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(-8, 5, -2, -2); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(-5, 1, -5, -9); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new ivec4(-1, -4, -7, -7); Assert.LessOrEqual(v0.NormMax, v0.Norm); } }
public void Constructors() { { var v = new ivec4(9); Assert.AreEqual(9, v.x); Assert.AreEqual(9, v.y); Assert.AreEqual(9, v.z); Assert.AreEqual(9, v.w); } { var v = new ivec4(5, 4, 2, 0); Assert.AreEqual(5, v.x); Assert.AreEqual(4, v.y); Assert.AreEqual(2, v.z); Assert.AreEqual(0, v.w); } { var v = new ivec4(new ivec2(2, -6)); Assert.AreEqual(2, v.x); Assert.AreEqual(-6, v.y); Assert.AreEqual(0, v.z); Assert.AreEqual(0, v.w); } { var v = new ivec4(new ivec3(-5, -9, 6)); Assert.AreEqual(-5, v.x); Assert.AreEqual(-9, v.y); Assert.AreEqual(6, v.z); Assert.AreEqual(0, v.w); } { var v = new ivec4(new ivec4(-1, -9, 3, -7)); Assert.AreEqual(-1, v.x); Assert.AreEqual(-9, v.y); Assert.AreEqual(3, v.z); Assert.AreEqual(-7, v.w); } }
/// <summary>Returns Min (Max (x, minVal), maxVal). Results are undefined if minVal > maxVal.</summary> protected internal static ivec4 Clamp(ivec4 x, ivec4 minVal, ivec4 maxVal) { throw _invalidAccess; }
/// <summary>Returns 1.0 if x > 0, 0.0 if x = 0, or –1.0 if x < 0.</summary> /// <returns>The sign of x</returns> protected static ivec4 sign(ivec4 x) { throw _invalidAccess; }
/// <summary> /// Returns true iff this equals rhs type- and component-wise. /// </summary> public static bool Equals(ivec4 v, object obj) => v.Equals(obj);
/// <summary> /// Returns the number of components (4). /// </summary> public static int Count(ivec4 v) => v.Count;
/// <summary> /// Returns a string representation of this vector using a provided seperator and a format for each component. /// </summary> public static string ToString(ivec4 v, string sep, string format) => v.ToString(sep, format);
public ivec3(ivec4 xyzw) { x = xyzw.x; y = xyzw.y; z = xyzw.z; }
public static ivec4 AllocateRegion(int width, int height) { ivec3 node, prev; ivec4 region = new ivec4() { x = 0, y = 0, width = width, height = height }; int i; int bestHeight = int.MaxValue; int bestIndex = -1; int bestWidth = int.MaxValue; for (i = 0; i < m_pNodes.Count; ++i) { int y = Fit(i, width, height); if (y >= 0) { node = m_pNodes[i]; if (((y + height) < bestHeight) || (((y + height) == bestHeight) && (node.z < bestWidth))) { bestHeight = y + height; bestIndex = i; bestWidth = node.z; region.x = node.x; region.y = y; } } } if (bestIndex == -1) { region.x = -1; region.y = -1; region.width = 0; region.height = 0; return region; } //New node node.x = region.x; node.y = region.y + height; node.z = width; m_pNodes.Insert(bestIndex, node); for (i = bestIndex + 1; i < m_pNodes.Count; ++i) { node = m_pNodes[i]; prev = m_pNodes[i - 1]; if (node.x < (prev.x + prev.z)) { int shrink = prev.x + prev.z - node.x; node.x += shrink; node.z -= shrink; if (node.z <= 0) { m_pNodes.RemoveAt(i); --i; } else { m_pNodes[i] = node; break; } } else { break; } } Merge(); m_nUsed += width * height; return region; }
/// <summary> /// Returns the reversal of the bits of value. The bit numbered n of the result will be taken from /// bit (bits - 1) - n of value, where bits is the total number of bits used to represent value. /// </summary> protected static ivec4 bitfieldReverse(ivec4 value) { throw _invalidAccess; }
/// <summary>Returns the number of bits set to 1 in the binary representation of value.</summary> protected static ivec4 bitCount(ivec4 value) { throw _invalidAccess; }
/// <summary> /// Returns the bit number of the most significant bit in the binary representation of value. /// For positive integers, the result will be the bit number of the most significant bit set to 1. /// For negative integers, the result will be the bit number of the most significant bit set to 0. /// For a value of zero or negative one, -1 will be returned. /// </summary> protected static ivec4 findMSB(ivec4 value) { throw _invalidAccess; }
/// <summary> /// Multiplies 32-bit integers x and y, producing a 64-bit result. /// The 32 least-significant bits are returned in lsb. The 32 most-significant bits are returned in msb. /// </summary> protected static void imulExtended(ivec4 x, ivec4 y, out ivec4 msb, out ivec4 lsb) { throw _invalidAccess; }
/// <summary>Returns x if x >= 0, otherwise it returns –x.</summary> /// <returns>The absolute value of x</returns> protected internal static ivec4 Abs(ivec4 x) { throw _invalidAccess; }
/// <summary>Returns y if x < y, otherwise it returns x.</summary> protected internal static ivec4 Max(ivec4 x, ivec4 y) { throw _invalidAccess; }
/// <summary> /// Returns a ivec4 with independent and identically distributed uniform integer values between minValue (inclusive) and maxValue (exclusive). (minValue == maxValue is allowed and returns minValue. Negative values are allowed.) /// </summary> public static ivec4 RandomUniform(Random random, ivec4 minValue, ivec4 maxValue) => ivec4.RandomUniform(random, minValue, maxValue);
/// <summary> /// Returns a bvec4 from component-wise application of Equal (lhs == rhs). /// </summary> public static bvec4 Equal(ivec4 lhs, ivec4 rhs) => ivec4.Equal(lhs, rhs);
/// <summary> /// </summary> /// <param name="uniformName"></param> /// <param name="values"></param> /// <returns></returns> public int SetUniform(string uniformName, ivec4[] values) { int location = GetUniformLocation(uniformName); if (location >= 0) { if (glUniform4iv == null) { glUniform4iv = OpenGL.GetDelegateFor<OpenGL.glUniform4iv>(); } int count = values.Length; var value = new int[count * 4]; int index = 0; for (int i = 0; i < value.Length; i++) { value[index++] = values[i].x; value[index++] = values[i].y; value[index++] = values[i].z; value[index++] = values[i].w; } glUniform4iv(location, count, value); } return location; }
/// <summary> /// Returns a bvec4 from component-wise application of GreaterThanEqual (lhs >= rhs). /// </summary> public static bvec4 GreaterThanEqual(ivec4 lhs, ivec4 rhs) => ivec4.GreaterThanEqual(lhs, rhs);
/// <summary> /// Returns a string representation of this vector using a provided seperator. /// </summary> public static string ToString(ivec4 v, string sep) => v.ToString(sep);
/// <summary> /// Returns the insertion the bits least-significant bits of insert into base. /// The result will have bits [offset, offset + bits - 1] taken from bits [0, bits – 1] /// of insert, and all other bits taken directly from the corresponding bits of base. /// If bits is zero, the result will simply be base. /// The result will be undefined if offset or bits is negative, or if the sum of /// offset and bits is greater than the number of bits used to store the operand. /// </summary> protected static ivec4 bitfieldInsert(ivec4 _base, ivec4 insert, int offset, int bits) { throw _invalidAccess; }
/// <summary> /// Returns a string representation of this vector using a provided seperator and a format and format provider for each component. /// </summary> public static string ToString(ivec4 v, string sep, string format, IFormatProvider provider) => v.ToString(sep, format, provider);
/// <summary> /// Splits x into a floating-point significand in the range [0.5, 1.0) /// and an integral exponent of two, such that: x=significand⋅2**exponent /// The significand is returned by the function and the exponent is returned in the parameter exp. /// For a floating-point value of zero, the significant and exponent are both zero. /// For a floating-point value that is an infinity or is not a number, the results are undefined. /// </summary> protected static dvec4 frexp(dvec4 x, out ivec4 exp) { throw _invalidAccess; }
/// <summary> /// Returns true iff this equals rhs component-wise. /// </summary> public static bool Equals(ivec4 v, ivec4 rhs) => v.Equals(rhs);
/// <summary> /// Returns a floating-point value corresponding to a signed integer encoding /// of a floating-point value. If a NaN is passed in, it will not signal, /// and the resulting floating point value is unspecified. If an Inf is passed in, /// the resulting floating-point value is the corresponding Inf. /// </summary> protected static vec4 intBitsToFloat(ivec4 value) { throw _invalidAccess; }
/// <summary> /// Returns a hash code for this instance. /// </summary> public static int GetHashCode(ivec4 v) => v.GetHashCode();
/// <summary> /// Builds a floating-point number from x and the corresponding integral exponent of two in exp, /// returning: significand⋅2*+exponent /// If this product is too large to be represented in the floating-point type, the result is undefined. /// </summary> protected static dvec4 ldexp(dvec4 x, ivec4 exp) { throw _invalidAccess; }
/// <summary> /// Returns a bvec4 from component-wise application of NotEqual (lhs != rhs). /// </summary> public static bvec4 NotEqual(ivec4 lhs, ivec4 rhs) => ivec4.NotEqual(lhs, rhs);
/// <summary>Returns y if y < x, otherwise it returns x.</summary> protected internal static ivec4 Min(ivec4 x, int y) { throw _invalidAccess; }
/* * private static Dictionary<string, Mesh> ParseGroupedMeshes(string[] lines) * { * var map = new Dictionary<string, Mesh>(); * var index = 0; * * Mesh mesh; * * while ((mesh = ParseMesh(lines, ref index, out var name)) != null) * { * map.Add(name, mesh); * } * * return map; * } * * private static Mesh ParseMesh(string[] lines, ref int index, out string name) * { * // This means that the end of the file was reached. * if (index >= lines.Length - 1 || lines[index].Length == 0) * { * name = null; * * return null; * } * * string line = lines[index]; * * while (!(line.StartsWith("o ") || line.StartsWith("g "))) * { * line = lines[++index]; * } * * name = line.Split(' ')[1]; * * // Custom object names often end with "_[Shape].XYZ", such as "Box_Cube.001". In those cases, the user-set * // name is just the first portion. The last underscore index is used in case the object name itself * // contains underscores. * var underscoreIndex = name.LastIndexOf("_", StringComparison.CurrentCulture); * * if (underscoreIndex > 0) * { * name = name.Substring(0, underscoreIndex); * } * * var points = new List<vec3>(); * var source = new List<vec2>(); * var normals = new List<vec3>(); * * // Parse points. * do * { * line = lines[++index]; * * if (line.StartsWith("v ")) * { * points.Add(ParseVec3(line)); * } * } * while (line.StartsWith("v ")); * * // Parse textures. * do * { * line = lines[++index]; * * if (line.StartsWith("vt")) * { * source.Add(ParseVec2(line)); * } * } * while (line.StartsWith("vt")); * * // If the exported mesh is untextured, a default grey texture is used. * if (source.Count == 0) * { * source.Add(vec2.Zero); * } * * // Parse normals. * do * { * line = lines[++index]; * * if (line.StartsWith("vn")) * { * points.Add(ParseVec3(line)); * } * } * while (line.StartsWith("vn")); * * // Advance to face lines. * //while (!lines[++index].StartsWith("f ")) * { * } * * var vertices = new List<ivec3>(); * var indices = new List<ushort>(); * * while (index < lines.Length - 1 && (line = lines[index]).StartsWith("f ")) * { * var tokens = line.Split(' '); * * for (int i = 1; i <= 3; i++) * { * var subTokens = tokens[i].Split('/'); * * // TODO: Support textures (using the second sub-token). * // .obj files use 1-indexing (rather than 0-indexing). * var pointIndex = int.Parse(subTokens[0]) - 1; * var normalIndex = int.Parse(subTokens[2]) - 1; * var vertex = new ivec3(pointIndex, 0, normalIndex); * * int vIndex; * * if ((vIndex = vertices.IndexOf(vertex)) != -1) * { * indices.Add((ushort)vIndex); * } * else * { * indices.Add((ushort)vertices.Count); * vertices.Add(vertex); * } * } * * index++; * } * * // When multiple meshes are present in a Blender scene, vertices are based on absolute position. In order * // to make positioning the mesh easier in-game, points are normalized back to the origin. * var minX = points.Min(p => p.x); * var minY = points.Min(p => p.y); * var minZ = points.Min(p => p.z); * * for (int i = 0; i < points.Count; i++) * { * points[i] -= new vec3(minX, minY, minZ); * } * * // Same applies to indexes. * var minPointIndex = vertices.Min(v => v.x); * var minNormalIndex = vertices.Min(v => v.z); * * for (int i = 0; i < vertices.Count; i++) * { * var v = vertices[i]; * v.x -= minPointIndex; * v.z -= minNormalIndex; * vertices[i] = v; * } * * // TODO: Load texture (if present in the file). * return new Mesh(points.ToArray(), source.ToArray(), normals.ToArray(), vertices.ToArray(), * indices.ToArray(), null); * } */ private static Mesh ParseUngroupedMesh(string filename, string[] lines) { var points = lines.Where(l => l.StartsWith("v ")).Select(ParseVec3); var normals = lines.Where(l => l.StartsWith("vn")).Select(ParseVec3); var sources = lines.Where(l => l.StartsWith("vt")).Select(ParseVec2).ToList(); // Source coordinates need to be flipped vertically in order to render properly. for (int i = 0; i < sources.Count; i++) { var s = sources[i]; s.y = 1 - s.y; sources[i] = s; } bool isUvMapped; string[] textures = null; Material[] materials = null; Dictionary <string, int> materialIndexes = null; if (sources.Count > 0) { ParseMaterials(filename, out textures, out materials, out materialIndexes); isUvMapped = true; } // If no material is specified, a default grey texture is used instead. else { sources.Add(vec2.Zero); isUvMapped = false; } var vertices = new List <ivec4>(); var indices = new List <ushort>(); var lineIndex = 0; if (isUvMapped) { for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("usemtl")) { lineIndex = i - 1; break; } } } else { for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("s ")) { lineIndex = i; break; } } } // Parse faces (indexes and vertices). do { var name = lines[lineIndex].Split(' ')[1]; var materialIndex = isUvMapped ? materialIndexes[name] : 0; if (isUvMapped) { lineIndex++; } do { var line = lines[++lineIndex]; // Smoothing lines can be ignored (since smoothing is implied through vertex order, I think). if (line.StartsWith("s ")) { continue; } var tokens = line.Split(' '); for (int i = 1; i <= 3; i++) { var subTokens = tokens[i].Split('/'); // .obj files use 1-indexing (rather than 0-indexing). var pointIndex = int.Parse(subTokens[0]) - 1; var sourceIndex = isUvMapped ? int.Parse(subTokens[1]) - 1 : 0; var normalIndex = int.Parse(subTokens[2]) - 1; var vertex = new ivec4(pointIndex, sourceIndex, materialIndex, normalIndex); int index; if ((index = vertices.IndexOf(vertex)) != -1) { indices.Add((ushort)index); } else { indices.Add((ushort)vertices.Count); vertices.Add(vertex); } } }while (lineIndex < lines.Length - 1 && !lines[lineIndex + 1].StartsWith("usemtl")); }while (lineIndex < lines.Length - 1); return(new Mesh(points.ToArray(), sources.ToArray(), normals.ToArray(), vertices.ToArray(), indices.ToArray(), textures, materials)); }
/// <summary> /// Extracts bits [offset, offset + bits - 1] from value, returning them /// in the least significant bits of the result. /// The most significant bits will be set to the value of bit offset + base – 1. /// If bits is zero, the result will be zero. The result will be undefined if /// offset or bits is negative, or if the sum of offset and bits is greater than /// the number of bits used to store the operand. /// </summary> /// <returns></returns> protected static ivec4 bitfieldExtract(ivec4 value, int offset, int bits) { throw _invalidAccess; }