Activate() приватный Метод

private Activate ( Microsoft.Xna.Framework.Graphics.GraphicsDevice device, TextureTarget target, bool useMipmaps = false ) : void
device Microsoft.Xna.Framework.Graphics.GraphicsDevice
target TextureTarget
useMipmaps bool
Результат void
Пример #1
0
 internal void SetSamplers(GraphicsDevice device)
 {
     for (int index = 0; index < this._samplers.Length; ++index)
     {
         SamplerState samplerState = this._samplers[index];
         Texture      texture      = device.Textures[index];
         if (samplerState != null && texture != null && samplerState != texture.glLastSamplerState)
         {
             GL.ActiveTexture((TextureUnit)(33984 + index));
             samplerState.Activate(texture.glTarget, texture.LevelCount > 1);
             texture.glLastSamplerState = samplerState;
         }
     }
 }
        public void DrawBatch(SpriteSortMode sortMode, SamplerState samplerState)
        {
            // nothing to do
            if (_batchItemList.Count == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
                _batchItemList.Sort(CompareTexture);
                break;

            case SpriteSortMode.FrontToBack:
                _batchItemList.Sort(CompareDepth);
                break;

            case SpriteSortMode.BackToFront:
                _batchItemList.Sort(CompareReverseDepth);
                break;
            }

            int size = sizeof(float) * 4 + sizeof(uint);

            GL.VertexPointer(2, VertexPointerType.Float, size, _vertexHandle.AddrOfPinnedObject());
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2)));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint))));

            // setup the vertexArray array
            int startIndex = 0;
            int index      = 0;
            int texID      = -1;

            // make sure the vertexArray has enough space
            if (_batchItemList.Count * 4 > _vertexArray.Length)
            {
                ExpandVertexArray(_batchItemList.Count);
            }

            foreach (SpriteBatchItem item in _batchItemList)
            {
                // if the texture changed, we need to flush and bind the new texture
                if (item.TextureID != texID)
                {
                    FlushVertexArray(startIndex, index);
                    startIndex = index;
                    texID      = item.TextureID;

                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.BindTexture(TextureTarget.Texture2D, texID);

                    samplerState.Activate();
                    //GL.Uniform1(1,texID);
                }
                // store the SpriteBatchItem data in our vertexArray
                _vertexArray[index++] = item.vertexTL;
                _vertexArray[index++] = item.vertexTR;
                _vertexArray[index++] = item.vertexBL;
                _vertexArray[index++] = item.vertexBR;

                _freeBatchItemQueue.Enqueue(item);
            }
            // flush the remaining vertexArray data
            FlushVertexArray(startIndex, index);
            _batchItemList.Clear();
        }
Пример #3
0
        public void DrawBatchGL11(SpriteSortMode sortMode, SamplerState samplerState)
        {
            // nothing to do
            if (_batchItemList.Count == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
                throw new NotSupportedException();

            //_batchItemList.Sort( CompareTexture );
            case SpriteSortMode.FrontToBack:
                throw new NotSupportedException();

            //_batchItemList.Sort ( CompareDepth );
            case SpriteSortMode.BackToFront:
                throw new NotSupportedException();
                //_batchItemList.Sort ( CompareReverseDepth );
            }

            // make sure an old draw isn't still going on.
            // cross fingers, commenting this out!!
            //GL.Flush();

            // make sure the vertexArray has enough space
            if (_batchItemList.Count * 6 > _index.Length)
            {
                ExpandIndexArray(_batchItemList.Count);
            }

            LinkVertexArray();

            int size = sizeof(float) * 4 + sizeof(uint);

            GL11.VertexPointer(2, ALL11.Float, size, _vertexHandle.AddrOfPinnedObject());
            GL11.ColorPointer(4, ALL11.UnsignedByte, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2)));
            GL11.TexCoordPointer(2, ALL11.Float, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint))));

            // setup the vertexArray array
            int startIndex = 0;
            int index      = 0;
            int texID      = -1;


            foreach (SpriteBatchItem item in _batchItemList)
            {
                // if the texture changed, we need to flush and bind the new texture
                if (item.TextureID != texID)
                {
                    FlushVertexArrayGL11(startIndex, index);
                    startIndex = index;
                    texID      = item.TextureID;
                    GL11.BindTexture(ALL11.Texture2D, texID);

                    samplerState.Activate();
                }
                // store the SpriteBatchItem data in our vertexArray
                index += 4;
            }
            // flush the remaining vertexArray data
            FlushVertexArrayGL11(startIndex, index);

            _batchItemList.Clear();
            _vertexArray.Clear();
        }
Пример #4
0
		public void DrawBatch ( SpriteSortMode sortMode, SamplerState samplerState )
		{
			// nothing to do
			if ( _batchItemList.Count == 0 )
				return;
			
			// sort the batch items
			switch ( sortMode )
			{
			case SpriteSortMode.Texture :
				_batchItemList.Sort( CompareTexture );
				break;
			case SpriteSortMode.FrontToBack :
				_batchItemList.Sort ( CompareDepth );
				break;
			case SpriteSortMode.BackToFront :
				_batchItemList.Sort ( CompareReverseDepth );
				break;
			}
			
			int size = sizeof(float)*4 + sizeof(uint);
			
			GL.VertexPointer(2, VertexPointerType.Float,size,_vertexHandle.AddrOfPinnedObject() );
			GL.ColorPointer(4, ColorPointerType.UnsignedByte,size,(IntPtr)((UInt64)_vertexHandle.AddrOfPinnedObject()+sizeof(float)*2));
			GL.TexCoordPointer(2, TexCoordPointerType.Float,size,(IntPtr)((UInt64)_vertexHandle.AddrOfPinnedObject()+sizeof(float)*2+sizeof(uint)) );			
			
			// setup the vertexArray array
			int startIndex = 0;
			int index = 0;
			int texID = -1;

			// make sure the vertexArray has enough space
			if ( _batchItemList.Count*4 > _vertexArray.Length )
				ExpandVertexArray( _batchItemList.Count );
			
			foreach ( SpriteBatchItem item in _batchItemList )
			{
				// if the texture changed, we need to flush and bind the new texture
				if ( item.TextureID != texID )
				{
					FlushVertexArray( startIndex, index );
					startIndex = index;
					texID = item.TextureID;

					GL.ActiveTexture(TextureUnit.Texture0);
					GL.BindTexture ( TextureTarget.Texture2D, texID );

					samplerState.Activate ();
				}
				// store the SpriteBatchItem data in our vertexArray
				_vertexArray[index++] = item.vertexTL;
				_vertexArray[index++] = item.vertexTR;
				_vertexArray[index++] = item.vertexBL;
				_vertexArray[index++] = item.vertexBR;
				
				_freeBatchItemQueue.Enqueue ( item );				
			}
			// flush the remaining vertexArray data
			FlushVertexArray(startIndex, index);
			_batchItemList.Clear();
		}
Пример #5
0
        public void DrawBatchGL11( SpriteSortMode sortMode, SamplerState samplerState )
        {
            // nothing to do
            if ( _batchItemList.Count == 0 )
                return;

            // sort the batch items
            switch ( sortMode )
            {
            case SpriteSortMode.Texture :
                throw new NotSupportedException();
                //_batchItemList.Sort( CompareTexture );
            case SpriteSortMode.FrontToBack :
                throw new NotSupportedException();
                //_batchItemList.Sort ( CompareDepth );
            case SpriteSortMode.BackToFront :
                throw new NotSupportedException();
                //_batchItemList.Sort ( CompareReverseDepth );
            }

            // make sure an old draw isn't still going on.
            // cross fingers, commenting this out!!
            //GL.Flush();

            // make sure the vertexArray has enough space
            if ( _batchItemList.Count*6 > _index.Length )
                ExpandIndexArray( _batchItemList.Count );

            LinkVertexArray();

            int size = sizeof(float)*4+sizeof(uint);
            GL11.VertexPointer(2,ALL11.Float,size,_vertexHandle.AddrOfPinnedObject() );
            GL11.ColorPointer(4, ALL11.UnsignedByte,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2)));
            GL11.TexCoordPointer(2, ALL11.Float,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2+sizeof(uint))) );

            // setup the vertexArray array
            int startIndex = 0;
            int index = 0;
            int texID = -1;

            foreach ( SpriteBatchItem item in _batchItemList )
            {
                // if the texture changed, we need to flush and bind the new texture
                if ( item.TextureID != texID )
                {
                    FlushVertexArrayGL11( startIndex, index );
                    startIndex = index;
                    texID = item.TextureID;
                    GL11.BindTexture ( ALL11.Texture2D, texID );

                    samplerState.Activate();
                }
                // store the SpriteBatchItem data in our vertexArray
                index += 4;
            }
            // flush the remaining vertexArray data
            FlushVertexArrayGL11(startIndex, index);

            _batchItemList.Clear();
            _vertexArray.Clear();
        }
Пример #6
0
        public void DrawBatch( SpriteSortMode sortMode, SamplerState samplerState )
        {
            // nothing to do
            if ( _batchItemList.Count == 0 )
                return;

            // sort the batch items
            switch ( sortMode )
            {
            case SpriteSortMode.Texture :
                _batchItemList.Sort( CompareTexture );
                break;
            case SpriteSortMode.FrontToBack :
                _batchItemList.Sort ( CompareDepth );
                break;
            case SpriteSortMode.BackToFront :
                _batchItemList.Sort ( CompareReverseDepth );
                break;
            }

            GL.EnableVertexAttribArray(attributePosition);
            GL.EnableVertexAttribArray(attributeTexCoord);

            int size = VertexPosition2ColorTexture.GetSize();
            GL.VertexAttribPointer(attributePosition,2,VertexAttribPointerType.Float,false,size,_vertexHandle.AddrOfPinnedObject());
            GL.VertexAttribPointer(attributeTexCoord,2,VertexAttribPointerType.Float,false,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2+sizeof(uint))));
            //GL.VertexAttribPointer(
            // setup the vertexArray array
            int startIndex = 0;
            int index = 0;
            int texID = -1;
            // store last tint color
            Color lastTint =  new Color(0.0f,0.0f,0.0f,0.0f);

            // make sure the vertexArray has enough space
            if ( _batchItemList.Count*4 > _vertexArray.Length )
                ExpandVertexArray( _batchItemList.Count );

            foreach ( SpriteBatchItem item in _batchItemList )
            {
                //Tint Color
                Vector4 vtint = item.Tint.ToVector4();
                //vtint /= 255;
                //GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W);

                // if the texture changed, we need to flush and bind the new texture
                if ( item.TextureID != texID || item.Tint != lastTint)
                {
                    FlushVertexArrayGL20( startIndex, index );
                    startIndex = index;
                    texID = item.TextureID;
                    lastTint = item.Tint;

                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.BindTexture ( TextureTarget.Texture2D, texID );
                    //GL.Uniform1(texID, 0);
                    GL.VertexAttrib4(attributeTint,vtint.X, vtint.Y, vtint.Z, vtint.W);

                    samplerState.Activate();
                }
                // store the SpriteBatchItem data in our vertexArray
                _vertexArray[index++] = item.vertexTL;
                _vertexArray[index++] = item.vertexTR;
                _vertexArray[index++] = item.vertexBL;
                _vertexArray[index++] = item.vertexBR;

                _freeBatchItemQueue.Enqueue ( item );
            }
            // flush the remaining vertexArray data
            FlushVertexArrayGL20(startIndex, index);

            _batchItemList.Clear();
        }
Пример #7
0
        public void DrawBatchGL20(SpriteSortMode sortMode, SamplerState samplerState)
        {
            // nothing to do
            if (_batchItemList.Count == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
                _batchItemList.Sort(CompareTexture);
                break;

            case SpriteSortMode.FrontToBack:
                _batchItemList.Sort(CompareDepth);
                break;

            case SpriteSortMode.BackToFront:
                _batchItemList.Sort(CompareReverseDepth);
                break;
            }

            GL20.EnableVertexAttribArray(attributePosition);
            GL20.EnableVertexAttribArray(attributeTexCoord);

            int size = VertexPosition2ColorTexture.GetSize();

            GL20.VertexAttribPointer(attributePosition, 2, ALL20.Float, false, size, _vertexHandle.AddrOfPinnedObject());
            GL20.VertexAttribPointer(attributeTexCoord, 2, ALL20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint))));

            // setup the vertexArray array
            int startIndex = 0;
            int index      = 0;
            int texID      = -1;
            // store last tint color
            Color lastTint = new Color(0.0f, 0.0f, 0.0f, 0.0f);

            // make sure the vertexArray has enough space
            if (_batchItemList.Count * 4 > _vertexArray.Length)
            {
                ExpandVertexArray(_batchItemList.Count);
            }

            foreach (SpriteBatchItem item in _batchItemList)
            {
                //Tint Color
                Vector4 vtint = item.Tint.ToVector4();
                //vtint /= 255;
                //GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W);

                // if the texture changed, we need to flush and bind the new texture
                if (item.TextureID != texID || item.Tint != lastTint)
                {
                    FlushVertexArrayGL20(startIndex, index);
                    startIndex = index;
                    texID      = item.TextureID;
                    lastTint   = item.Tint;
                    GL20.ActiveTexture(ALL20.Texture0);
                    GL20.BindTexture(ALL20.Texture2D, texID);
                    GL20.Uniform1(texID, 0);
                    GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W);

                    samplerState.Activate();
                }
                // store the SpriteBatchItem data in our vertexArray
                _vertexArray[index++] = item.vertexTL;
                _vertexArray[index++] = item.vertexTR;
                _vertexArray[index++] = item.vertexBL;
                _vertexArray[index++] = item.vertexBR;

                _freeBatchItemQueue.Enqueue(item);
            }
            // flush the remaining vertexArray data
            FlushVertexArrayGL20(startIndex, index);

            _batchItemList.Clear();
        }