Esempio n. 1
0
        public static void IntWrite(BufferBase dest, int n, uint value)
        {
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                switch (n)
                {
                case 1:
                    dest.ToBytePointer()[0] = (byte)value;
                    break;

                case 2:
                    dest.ToUShortPointer()[0] = (ushort)value;
                    break;

                case 3:
                    var d = dest.ToBytePointer();
#if AXIOM_BIG_ENDIAN
                    d[0] = (byte)((value >> 16) & 0xFF);
                    d[1] = (byte)((value >> 8) & 0xFF);
                    d[2] = (byte)(value & 0xFF);
#else
                    d[2] = (byte)((value >> 16) & 0xFF);
                    d[1] = (byte)((value >> 8) & 0xFF);
                    d[0] = (byte)(value & 0xFF);
#endif
                    break;

                case 4:
                    dest.ToUIntPointer()[0] = value;
                    break;
                }
            }
        }
Esempio n. 2
0
        public static uint IntRead(BufferBase src, int n)
        {
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                switch (n)
                {
                case 1:
                    return(src.ToBytePointer()[0]);

                case 2:
                    return(src.ToUShortPointer()[0]);

                case 3:
                    var s = src.ToBytePointer();
#if AXIOM_BIG_ENDIAN
                    return((uint)(s[0] << 16 |
                                  (s[1] << 8) |
                                  (s[2])));
#else
                    return((uint)(s[0] | (s[1] << 8) | (s[2] << 16)));
#endif
                case 4:
                    return(src.ToUIntPointer()[0]);
                }

                return(0); // ?
            }
        }
Esempio n. 3
0
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToBytePointer();
                    var outputPtr = output.ToUIntPointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = 0x000000FF | (((uint)inp) << 8) | (((uint)inp) << 16) | (((uint)inp) << 24);
                }
            }
Esempio n. 4
0
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToUIntPointer();
                    var outputPtr = output.ToUIntPointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = ((inp & 0xFFFFFF) << 8) | 0x000000FF;
                }
            }
Esempio n. 5
0
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToUIntPointer();
                    var outputPtr = output.ToBytePointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = (byte)((inp & 0x0000FF00) >> 8);
                }
            }
Esempio n. 6
0
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToUIntPointer();
                    var outputPtr = output.ToCol3BPointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = new Col3b
                    {
                        x = (byte)((inp >> 0) & 0xFF),
                        y = (byte)((inp >> 8) & 0xFF),
                        z = (byte)((inp >> 16) & 0xFF),
                    };
                }
            }
Esempio n. 7
0
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToCol3BPointer();
                    var outputPtr = output.ToUIntPointer();
                    var inp       = inputPtr[offset];

                    int xshift = 8, yshift = 16, zshift = 24, ashift = 0;

#if AXIOM_BIG_ENDIAN
                    outputPtr[offset] = ((uint)(0xFF << ashift)) | (((uint)inp.x) << xshift) |
                                        (((uint)inp.y) << yshift) | (((uint)inp.z) << zshift);
#else
                    outputPtr[offset] = ((uint)(0xFF << ashift)) | (((uint)inp.x) << zshift) | (((uint)inp.y) << yshift) |
                                        (((uint)inp.z) << xshift);
#endif
                }
            }
Esempio n. 8
0
		/// <summary>
		///		Caches a face group and calculates texture lighting coordinates.
		/// </summary>
		protected int CacheLightGeometry( TextureLight light, BufferBase pIndexesBuf, BufferBase pTexLightMapsBuf,
		                                  BufferBase pVerticesBuf, BspStaticFaceGroup faceGroup )
		{
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				// Skip sky always
				if ( faceGroup.isSky )
				{
					return 0;
				}

				int idxStart = 0;
				int numIdx = 0;
				int vertexStart = 0;

				if ( faceGroup.type == FaceGroup.FaceList )
				{
					idxStart = faceGroup.elementStart;
					numIdx = faceGroup.numElements;
					vertexStart = faceGroup.vertexStart;
				}
				else if ( faceGroup.type == FaceGroup.Patch )
				{
					idxStart = faceGroup.patchSurf.IndexOffset;
					numIdx = faceGroup.patchSurf.CurrentIndexCount;
					vertexStart = faceGroup.patchSurf.VertexOffset;
				}
				else
				{
					// Unsupported face type
					return 0;
				}

				var idxSize = this.level.Indexes.IndexSize;
				var idxSrc = this.level.Indexes.Lock( idxStart*idxSize, numIdx*idxSize, BufferLocking.ReadOnly );
#if SILVERLIGHT
				var src = idxSrc.ToUShortPointer();
#else
				var src = idxSrc.ToUIntPointer();
#endif

				int maxIndex = 0;
				for ( int i = 0; i < numIdx; i++ )
				{
					var index = (int)src[ i ];
					if ( index > maxIndex )
					{
						maxIndex = index;
					}
				}

				var vertexPos = new Vector3[maxIndex + 1];
				var vertexIsStored = new bool[maxIndex + 1];

				for ( int i = 0; i < numIdx; i++ )
				{
					var index = (int)src[ i ];
					var pVertices = pVerticesBuf.ToBspVertexPointer();
					if ( !vertexIsStored[ index ] )
					{
						vertexPos[ index ] = pVertices[ vertexStart + index ].position;
						vertexIsStored[ index ] = true;
					}
					pVerticesBuf.UnPin();
				}

				Vector2[] texCoors;
				ColorEx[] colors;

				bool res = light.CalculateTexCoordsAndColors( faceGroup.plane, vertexPos, out texCoors, out colors );

				if ( res )
				{
					var pTexLightMaps = pTexLightMapsBuf.ToTextureLightMapPointer();
					for ( int i = 0; i <= maxIndex; i++ )
					{
						pTexLightMaps[ vertexStart + i ] = new TextureLightMap
						                                   {
						                                   	color = Root.Instance.RenderSystem.ConvertColor( colors[ i ] ),
						                                   	textureLightMap = texCoors[ i ]
						                                   };
					}
					pTexLightMapsBuf.UnPin();

					// Offset the indexes here
					// we have to do this now rather than up-front because the
					// indexes are sometimes reused to address different vertex chunks
					if ( this.level.Indexes.Type == IndexType.Size16 )
					{
						var pIndexes = pIndexesBuf.ToUShortPointer();
						for ( int i = 0; i < numIdx; i++ )
						{
							pIndexes[ i ] = (ushort)( src[ i ] + vertexStart );
						}
					}
					else
					{
						var pIndexes = pIndexesBuf.ToUIntPointer();
						for ( int i = 0; i < numIdx; i++ )
						{
							pIndexes[ i ] = (uint)( src[ i ] + vertexStart );
						}
					}
					this.level.Indexes.Unlock();

					// return number of elements
					return numIdx;
				}
				else
				{
					this.level.Indexes.Unlock();

					return 0;
				}
			}
		}
Esempio n. 9
0
		/// <summary>
		///		Caches a face group for imminent rendering.
		/// </summary>
		protected int CacheGeometry( BufferBase indexes, BspStaticFaceGroup faceGroup )
		{
			// Skip sky always
			if ( faceGroup.isSky )
			{
				return 0;
			}

			int idxStart = 0;
			int numIdx = 0;
			int vertexStart = 0;

			if ( faceGroup.type == FaceGroup.FaceList )
			{
				idxStart = faceGroup.elementStart;
				numIdx = faceGroup.numElements;
				vertexStart = faceGroup.vertexStart;
			}
			else if ( faceGroup.type == FaceGroup.Patch )
			{
				idxStart = faceGroup.patchSurf.IndexOffset;
				numIdx = faceGroup.patchSurf.CurrentIndexCount;
				vertexStart = faceGroup.patchSurf.VertexOffset;
			}
			else
			{
				// Unsupported face type
				return 0;
			}

#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				// Offset the indexes here
				// we have to do this now rather than up-front because the
				// indexes are sometimes reused to address different vertex chunks
				var idxSize = this.level.Indexes.IndexSize;
				var idxSrc = this.level.Indexes.Lock( idxStart*idxSize, numIdx*idxSize, BufferLocking.ReadOnly );
				if ( this.level.Indexes.Type == IndexType.Size16 )
				{
					var src = idxSrc.ToUShortPointer();
					var pIndexes = indexes.ToUShortPointer();
					for ( int i = 0; i < numIdx; i++ )
					{
						pIndexes[ i ] = (ushort)( src[ i ] + vertexStart );
					}
				}
				else
				{
					var src = idxSrc.ToUIntPointer();
					var pIndexes = indexes.ToUIntPointer();
					for ( int i = 0; i < numIdx; i++ )
					{
						pIndexes[ i ] = (uint)( src[ i ] + vertexStart );
					}
				}
				this.level.Indexes.Unlock();
			}

			// return number of elements
			return numIdx;
		}
Esempio n. 10
0
		public static uint IntRead( BufferBase src, int n )
		{
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				switch ( n )
				{
					case 1:
						return src.ToBytePointer()[ 0 ];

					case 2:
						return src.ToUShortPointer()[ 0 ];

					case 3:
						var s = src.ToBytePointer();
#if AXIOM_BIG_ENDIAN
						return (uint)( s[ 0 ] << 16 |
									   ( s[ 1 ] << 8 ) |
									   ( s[ 2 ] ) );
#else
						return (uint)( s[ 0 ] | ( s[ 1 ] << 8 ) | ( s[ 2 ] << 16 ) );
#endif
					case 4:
						return src.ToUIntPointer()[ 0 ];
				}

				return 0; // ?
			}
		}
Esempio n. 11
0
		public static void IntWrite( BufferBase dest, int n, uint value )
		{
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				switch ( n )
				{
					case 1:
						dest.ToBytePointer()[ 0 ] = (byte)value;
						break;

					case 2:
						dest.ToUShortPointer()[ 0 ] = (ushort)value;
						break;

					case 3:
						var d = dest.ToBytePointer();
#if AXIOM_BIG_ENDIAN
						d[ 0 ] = (byte)( ( value >> 16 ) & 0xFF );
						d[ 1 ] = (byte)( ( value >> 8 ) & 0xFF );
						d[ 2 ] = (byte)( value & 0xFF );
#else
						d[ 2 ] = (byte)( ( value >> 16 ) & 0xFF );
						d[ 1 ] = (byte)( ( value >> 8 ) & 0xFF );
						d[ 0 ] = (byte)( value & 0xFF );
#endif
						break;

					case 4:
						dest.ToUIntPointer()[ 0 ] = value;
						break;
				}
			}
		}