示例#1
0
        public RenderBreak(int itemNumber, Texture2D texture,
                           ColorOperation colorOperation,
                           BlendOperation blendOperation, TextureAddressMode textureAddressMode)
        {
#if DEBUG
            ObjectCausingBreak = null;
#endif
            LayerName = Renderer.CurrentLayerName;


            PrimitiveType = PrimitiveType.TriangleList;
            ItemNumber    = itemNumber;

            if (texture != null && texture.IsDisposed)
            {
                throw new ObjectDisposedException("Cannot create render break with disposed Texture2D");
            }

            mTexture               = texture;
            ColorOperation         = colorOperation;
            BlendOperation         = blendOperation;
            TextureAddressMode     = textureAddressMode;
            TextureFilter          = FlatRedBallServices.GraphicsOptions.TextureFilter;
            _originalTextureFilter = TextureFilter.Linear;

#if MONOGAME
            Red   = 0;
            Green = 0;
            Blue  = 0;
#endif
        }
示例#2
0
 void mDevice_DeviceLost(object sender, EventArgs e)
 {
     // set weird values which will indicate that the device's
     // render states need to be set.
     mAlphaBlend     = false;
     mAlphaArgument1 = TextureArgument.Temp;
     mAlphaArgument2 = TextureArgument.Temp;
     mAlphaOperation = TextureOperation.Add;
 }
示例#3
0
 public TextureSlot(Texture texture, int uvIndex, float blendFactor, TextureOperation operation, TextureWrap wrapS, TextureWrap wrapT)
 {
     this.Texture     = texture;
     this.UVIndex     = uvIndex;
     this.BlendFactor = blendFactor;
     this.Operation   = operation;
     this.WrapS       = wrapS;
     this.WrapT       = wrapT;
 }
示例#4
0
        /// <summary>
        /// 绘制一个进度条
        /// Draws the progress bar
        /// </summary>
        /// <param name="drawArgs"></param>
        /// <param name="x">屏幕上的 X 坐标 Center X position of progress.</param>
        /// <param name="y">屏幕上的 Y 坐标 Center Y position of progress.</param>
        /// <param name="progress">进度百分比 数值在0到1之间 Progress vale, in the range 0..1</param>
        /// <param name="color">进度条的颜色</param>

        public void Draw(DrawArgs drawArgs, float x, float y, float progress, int color)
        {
            if (x != this.x || y != this.y)
            {
                Initalize(x, y);
            }
            int barlength = (int)(progress * 2 * halfWidth);

            progressBar[0].X     = x - halfWidth;
            progressBar[0].Y     = y - halfHeight;
            progressBar[0].Rhw   = 0.5f;
            progressBar[0].Color = color;

            progressBar[1].X     = x - halfWidth;
            progressBar[1].Y     = y + halfHeight;
            progressBar[1].Rhw   = 0.5f;
            progressBar[1].Color = color;

            progressBar[2].X     = x - halfWidth + barlength;
            progressBar[2].Y     = y - halfHeight;
            progressBar[2].Color = color;
            progressBar[2].Rhw   = 0.5f;

            progressBar[3].Y     = y + halfHeight;
            progressBar[3].X     = x - halfWidth + barlength;
            progressBar[3].Color = color;
            progressBar[3].Rhw   = 0.5f;

            progressRight[0].X   = x - halfWidth + barlength;
            progressRight[0].Y   = y - halfHeight;
            progressRight[0].Rhw = 0.5f;

            progressRight[1].X   = x - halfWidth + barlength;
            progressRight[1].Y   = y + halfHeight;
            progressRight[1].Rhw = 0.5f;

            progressRight[2].X   = x + halfWidth;
            progressRight[2].Y   = y - halfHeight;
            progressRight[2].Rhw = 0.5f;

            progressRight[3].X   = x + halfWidth;
            progressRight[3].Y   = y + halfHeight;
            progressRight[3].Rhw = 0.5f;

            TextureOperation to = drawArgs.device.TextureState[0].ColorOperation;

            drawArgs.device.VertexFormat = CustomVertex.TransformedColored.Format;
            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, progressBar);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, progressRight);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, 4, progressBarOutline);

            drawArgs.device.TextureState[0].ColorOperation = to;
        }
示例#5
0
        private static void SetHandle(ShaderConfig config, TextureOperation texOp, int cbufOffset, int cbufSlot, bool rewriteSamplerType)
        {
            texOp.SetHandle(cbufOffset, cbufSlot);

            if (rewriteSamplerType)
            {
                texOp.Type = config.GpuAccessor.QuerySamplerType(cbufOffset, cbufSlot);
            }

            config.SetUsedTexture(texOp.Inst, texOp.Type, texOp.Format, texOp.Flags, cbufSlot, cbufOffset);
        }
示例#6
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapMode">Texture wrap mode</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, uint texIndex, TextureMapping mapping, uint uvIndex, float blendFactor,
     TextureOperation texOp, TextureWrapMode wrapMode, uint flags)
 {
     _filePath = (filePath == null) ? String.Empty : filePath;
         _type = typeSemantic;
         _index = texIndex;
         _mapping = mapping;
         _uvIndex = uvIndex;
         _blendFactor = blendFactor;
         _texOp = texOp;
         _wrapMode = wrapMode;
         _flags = flags;
 }
示例#7
0
        public RenderBreak(int itemNumber, Text text, int textureIndex)
        {
#if DEBUG
            ObjectCausingBreak = text;
#endif
            LayerName = Renderer.CurrentLayerName;


#if WINDOWS_PHONE || MONOGAME
            if (text.ColorOperation != Graphics.ColorOperation.Texture)
            {
                Red   = text.Red;
                Green = text.Green;
                Blue  = text.Blue;
            }
            else
            {
                Red   = 1;
                Green = 1;
                Blue  = 1;
            }
#endif

            ItemNumber = itemNumber;

            PrimitiveType          = PrimitiveType.TriangleList;
            TextureFilter          = FlatRedBallServices.GraphicsOptions.TextureFilter;
            _originalTextureFilter = TextureFilter.Linear;

            if (text != null)
            {
                if (text.Font.Texture != null && text.Font.Texture.IsDisposed)
                {
                    throw new ObjectDisposedException("Cannot create render break with disposed Texture2D");
                }

                mTexture = text.Font.Textures[textureIndex];

                ColorOperation     = text.ColorOperation;
                BlendOperation     = text.BlendOperation;
                TextureAddressMode = TextureAddressMode.Clamp;
            }
            else
            {
                mTexture           = null;
                ColorOperation     = ColorOperation.None;
                BlendOperation     = BlendOperation.Regular;
                TextureAddressMode = TextureAddressMode.Clamp;
            }
        }
示例#8
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapModeU">Texture wrap mode for U coordinate</param>
 /// <param name="wrapModeV">Texture wrap mode for V coordinate</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, int texIndex, TextureMapping mapping, int uvIndex, float blendFactor,
                    TextureOperation texOp, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV, int flags)
 {
     FilePath     = (filePath == null) ? String.Empty : filePath;
     TextureType  = typeSemantic;
     TextureIndex = texIndex;
     Mapping      = mapping;
     UVIndex      = uvIndex;
     BlendFactor  = blendFactor;
     Operation    = texOp;
     WrapModeU    = wrapModeU;
     WrapModeV    = wrapModeV;
     Flags        = flags;
 }
示例#9
0
        public void SetDeviceStateTexture(Texture texture, int index)
        {
            if (texture == mLastTexture[index])
            {
                return;
            }

            mDevice.SetTexture(index, texture);

            mLastTexture[index] = texture;

            if (texture != null)
            {
                AlphaArgument1 = TextureArgument.Texture;
                AlphaArgument2 = TextureArgument.Diffuse;
                AlphaOperation = TextureOperation.Modulate;
            }
        }
示例#10
0
        public void SetDeviceStateTexture(Texture texture)
        {
            if (texture == mLastTexture)
            {
                return;
            }

            mDevice.SetTexture(0, texture);

            mLastTexture = texture;

            if (texture != null)
            {
                AlphaArgument1 = TextureArgument.TextureColor;
                AlphaArgument2 = TextureArgument.Diffuse;
                AlphaOperation = TextureOperation.Modulate;
            }
        }
示例#11
0
 private static void SetHandle(ShaderConfig config, TextureOperation texOp, int cbufOffset, int cbufSlot)
 {
     texOp.SetHandle(cbufOffset, cbufSlot);
     config.SetUsedTexture(texOp.Inst, texOp.Type, texOp.Format, texOp.Flags, cbufSlot, cbufOffset);
 }
示例#12
0
        private static void EmitTextureMipMapLevel(EmitterContext context, bool isBindless)
        {
            OpCodeTexture op = (OpCodeTexture)context.CurrOp;

            if (op.Rd.IsRZ)
            {
                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            TextureFlags flags = TextureFlags.None;

            List <Operand> sourcesList = new List <Operand>();

            if (isBindless)
            {
                sourcesList.Add(Rb());

                flags |= TextureFlags.Bindless;
            }

            SamplerType type = ConvertSamplerType(op.Dimensions);

            int coordsCount = type.GetDimensions();

            Operand arrayIndex = op.IsArray ? Ra() : null;

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (op.IsArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            Operand[] sources = sourcesList.ToArray();

            int rdIndex = op.Rd.Index;

            Operand GetDest()
            {
                if (rdIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(Register(rdIndex++, RegisterType.Gpr));
            }

            int handle = !isBindless ? op.Immediate : 0;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    // Components z and w aren't standard, we return 0 in this case and add a comment.
                    if (compIndex >= 2)
                    {
                        context.Add(new CommentNode("Unsupported component z or w found"));
                        context.Copy(dest, Const(0));
                    }
                    else
                    {
                        Operand tempDest = Local();

                        TextureOperation operation = new TextureOperation(
                            Instruction.Lod,
                            type,
                            flags,
                            handle,
                            compIndex,
                            tempDest,
                            sources);

                        context.Add(operation);

                        tempDest = context.FPMultiply(tempDest, ConstF(256.0f));

                        Operand finalValue = context.FPConvertToS32(tempDest);

                        context.Copy(dest, finalValue);
                    }
                }
            }
        }
示例#13
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapModeU">Texture wrap mode for U coordinate</param>
 /// <param name="wrapModeV">Texture wrap mode for V coordinate</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, int texIndex, TextureMapping mapping, int uvIndex, float blendFactor,
     TextureOperation texOp, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV, int flags) {
         FilePath = (filePath == null) ? String.Empty : filePath;
         TextureType = typeSemantic;
         TextureIndex = texIndex;
         Mapping = mapping;
         UVIndex = uvIndex;
         BlendFactor = blendFactor;
         Operation = texOp;
         WrapModeU = wrapModeU;
         WrapModeV = wrapModeV;
         Flags = flags;
 }
示例#14
0
 public Result SetTextureStageState(int stage, TextureStage type, TextureOperation textureOperation)
 {
     return(_device.SetTextureStageState(stage, type, textureOperation));
 }
示例#15
0
        public static void Sust(EmitterContext context)
        {
            OpCodeImage op = (OpCodeImage)context.CurrOp;

            SamplerType type = ConvertSamplerType(op.Dimensions);

            if (type == SamplerType.None)
            {
                context.Config.GpuAccessor.Log("Invalid image store sampler type.");

                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            bool isArray = op.Dimensions == ImageDimensions.Image1DArray ||
                           op.Dimensions == ImageDimensions.Image2DArray;

            Operand arrayIndex = isArray ? Ra() : null;

            List <Operand> sourcesList = new List <Operand>();

            if (op.IsBindless)
            {
                sourcesList.Add(context.Copy(Register(op.Rc)));
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (isArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            TextureFormat format = TextureFormat.Unknown;

            if (op.UseComponents)
            {
                int componentMask = (int)op.Components;

                for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
                {
                    if ((compMask & 1) != 0)
                    {
                        sourcesList.Add(Rb());
                    }
                }

                if (!op.IsBindless)
                {
                    format = context.Config.GetTextureFormat(op.Immediate);
                }
            }
            else
            {
                if (op.ByteAddress)
                {
                    int xIndex = op.IsBindless ? 1 : 0;

                    sourcesList[xIndex] = context.ShiftRightS32(sourcesList[xIndex], Const(GetComponentSizeInBytesLog2(op.Size)));
                }

                int components = GetComponents(op.Size);

                for (int compIndex = 0; compIndex < components; compIndex++)
                {
                    sourcesList.Add(Rb());
                }

                format = GetTextureFormat(op.Size);
            }

            Operand[] sources = sourcesList.ToArray();

            int handle = !op.IsBindless ? op.Immediate : 0;

            TextureFlags flags = op.IsBindless ? TextureFlags.Bindless : TextureFlags.None;

            TextureOperation operation = new TextureOperation(
                Instruction.ImageStore,
                type,
                flags,
                handle,
                0,
                null,
                sources)
            {
                Format = format
            };

            context.Add(operation);
        }
示例#16
0
        private static void EmitSust(
            EmitterContext context,
            CacheOpSt cacheOp,
            SuDim dimensions,
            SuSize size,
            int imm,
            SuRgba componentMask,
            int srcA,
            int srcB,
            int srcC,
            bool useComponents,
            bool byteAddress,
            bool isBindless)
        {
            SamplerType type = ConvertSamplerType(dimensions);

            if (type == SamplerType.None)
            {
                context.Config.GpuAccessor.Log("Invalid image store sampler type.");
                return;
            }

            Operand Ra()
            {
                if (srcA > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(srcA++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (srcB > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(srcB++, RegisterType.Gpr)));
            }

            List <Operand> sourcesList = new List <Operand>();

            if (isBindless)
            {
                sourcesList.Add(context.Copy(Register(srcC, RegisterType.Gpr)));
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (Sample1DAs2D && (type & SamplerType.Mask) == SamplerType.Texture1D)
            {
                sourcesList.Add(Const(0));

                type &= ~SamplerType.Mask;
                type |= SamplerType.Texture2D;
            }

            if (type.HasFlag(SamplerType.Array))
            {
                sourcesList.Add(Ra());
            }

            TextureFormat format = TextureFormat.Unknown;

            if (useComponents)
            {
                for (int compMask = (int)componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
                {
                    if ((compMask & 1) != 0)
                    {
                        sourcesList.Add(Rb());
                    }
                }

                if (!isBindless)
                {
                    format = context.Config.GetTextureFormat(imm);
                }
            }
            else
            {
                if (byteAddress)
                {
                    int xIndex = isBindless ? 1 : 0;

                    sourcesList[xIndex] = context.ShiftRightS32(sourcesList[xIndex], Const(GetComponentSizeInBytesLog2(size)));
                }

                int components = GetComponents(size);

                for (int compIndex = 0; compIndex < components; compIndex++)
                {
                    sourcesList.Add(Rb());
                }

                format = GetTextureFormat(size);
            }

            Operand[] sources = sourcesList.ToArray();

            int handle = imm;

            TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;

            if (cacheOp == CacheOpSt.Cg)
            {
                flags |= TextureFlags.Coherent;
            }

            TextureOperation operation = context.CreateTextureOperation(
                Instruction.ImageStore,
                type,
                format,
                flags,
                handle,
                0,
                null,
                sources);

            context.Add(operation);
        }
示例#17
0
        public static void Texs(EmitterContext context)
        {
            OpCodeTextureScalar op = (OpCodeTextureScalar)context.CurrOp;

            if (op.Rd0.IsRZ && op.Rd1.IsRZ)
            {
                return;
            }

            List <Operand> sourcesList = new List <Operand>();

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            void AddTextureOffset(int coordsCount, int stride, int size)
            {
                Operand packedOffs = Rb();

                for (int index = 0; index < coordsCount; index++)
                {
                    sourcesList.Add(context.BitfieldExtractS32(packedOffs, Const(index * stride), Const(size)));
                }
            }

            SamplerType  type;
            TextureFlags flags;

            if (op is OpCodeTexs texsOp)
            {
                type = ConvertSamplerType(texsOp.Target);

                if (type == SamplerType.None)
                {
                    context.Config.PrintLog("Invalid texture sampler type.");

                    return;
                }

                flags = ConvertTextureFlags(texsOp.Target);

                if ((type & SamplerType.Array) != 0)
                {
                    Operand arrayIndex = Ra();

                    sourcesList.Add(Ra());
                    sourcesList.Add(Rb());

                    sourcesList.Add(arrayIndex);

                    if ((type & SamplerType.Shadow) != 0)
                    {
                        sourcesList.Add(Rb());
                    }

                    if ((flags & TextureFlags.LodLevel) != 0)
                    {
                        sourcesList.Add(ConstF(0));
                    }
                }
                else
                {
                    switch (texsOp.Target)
                    {
                    case TextureTarget.Texture1DLodZero:
                        sourcesList.Add(Ra());
                        break;

                    case TextureTarget.Texture2D:
                        sourcesList.Add(Ra());
                        sourcesList.Add(Rb());
                        break;

                    case TextureTarget.Texture2DLodZero:
                        sourcesList.Add(Ra());
                        sourcesList.Add(Rb());
                        sourcesList.Add(ConstF(0));
                        break;

                    case TextureTarget.Texture2DLodLevel:
                    case TextureTarget.Texture2DDepthCompare:
                    case TextureTarget.Texture3D:
                    case TextureTarget.TextureCube:
                        sourcesList.Add(Ra());
                        sourcesList.Add(Ra());
                        sourcesList.Add(Rb());
                        break;

                    case TextureTarget.Texture2DLodZeroDepthCompare:
                    case TextureTarget.Texture3DLodZero:
                        sourcesList.Add(Ra());
                        sourcesList.Add(Ra());
                        sourcesList.Add(Rb());
                        sourcesList.Add(ConstF(0));
                        break;

                    case TextureTarget.Texture2DLodLevelDepthCompare:
                    case TextureTarget.TextureCubeLodLevel:
                        sourcesList.Add(Ra());
                        sourcesList.Add(Ra());
                        sourcesList.Add(Rb());
                        sourcesList.Add(Rb());
                        break;
                    }
                }
            }
            else if (op is OpCodeTlds tldsOp)
            {
                type = ConvertSamplerType(tldsOp.Target);

                if (type == SamplerType.None)
                {
                    context.Config.PrintLog("Invalid texel fetch sampler type.");

                    return;
                }

                flags = ConvertTextureFlags(tldsOp.Target) | TextureFlags.IntCoords;

                switch (tldsOp.Target)
                {
                case TexelLoadTarget.Texture1DLodZero:
                    sourcesList.Add(Ra());
                    sourcesList.Add(Const(0));
                    break;

                case TexelLoadTarget.Texture1DLodLevel:
                    sourcesList.Add(Ra());
                    sourcesList.Add(Rb());
                    break;

                case TexelLoadTarget.Texture2DLodZero:
                    sourcesList.Add(Ra());
                    sourcesList.Add(Rb());
                    sourcesList.Add(Const(0));
                    break;

                case TexelLoadTarget.Texture2DLodZeroOffset:
                    sourcesList.Add(Ra());
                    sourcesList.Add(Ra());
                    sourcesList.Add(Const(0));
                    break;

                case TexelLoadTarget.Texture2DLodZeroMultisample:
                case TexelLoadTarget.Texture2DLodLevel:
                case TexelLoadTarget.Texture2DLodLevelOffset:
                    sourcesList.Add(Ra());
                    sourcesList.Add(Ra());
                    sourcesList.Add(Rb());
                    break;

                case TexelLoadTarget.Texture3DLodZero:
                    sourcesList.Add(Ra());
                    sourcesList.Add(Ra());
                    sourcesList.Add(Rb());
                    sourcesList.Add(Const(0));
                    break;

                case TexelLoadTarget.Texture2DArrayLodZero:
                    sourcesList.Add(Rb());
                    sourcesList.Add(Rb());
                    sourcesList.Add(Ra());
                    sourcesList.Add(Const(0));
                    break;
                }

                if ((flags & TextureFlags.Offset) != 0)
                {
                    AddTextureOffset(type.GetDimensions(), 4, 4);
                }
            }
            else if (op is OpCodeTld4s tld4sOp)
            {
                if (!(tld4sOp.HasDepthCompare || tld4sOp.HasOffset))
                {
                    sourcesList.Add(Ra());
                    sourcesList.Add(Rb());
                }
                else
                {
                    sourcesList.Add(Ra());
                    sourcesList.Add(Ra());
                }

                type  = SamplerType.Texture2D;
                flags = TextureFlags.Gather;

                if (tld4sOp.HasDepthCompare)
                {
                    sourcesList.Add(Rb());

                    type |= SamplerType.Shadow;
                }

                if (tld4sOp.HasOffset)
                {
                    AddTextureOffset(type.GetDimensions(), 8, 6);

                    flags |= TextureFlags.Offset;
                }

                sourcesList.Add(Const(tld4sOp.GatherCompIndex));
            }
            else
            {
                throw new InvalidOperationException($"Invalid opcode type \"{op.GetType().Name}\".");
            }

            Operand[] sources = sourcesList.ToArray();

            Operand[] rd0 = new Operand[2] {
                ConstF(0), ConstF(0)
            };
            Operand[] rd1 = new Operand[2] {
                ConstF(0), ConstF(0)
            };

            int destIncrement = 0;

            Operand GetDest()
            {
                int high = destIncrement >> 1;
                int low  = destIncrement & 1;

                destIncrement++;

                if (op.IsFp16)
                {
                    return(high != 0
                        ? (rd1[low] = Local())
                        : (rd0[low] = Local()));
                }
                else
                {
                    int rdIndex = high != 0 ? op.Rd1.Index : op.Rd0.Index;

                    if (rdIndex < RegisterConsts.RegisterZeroIndex)
                    {
                        rdIndex += low;
                    }

                    return(Register(rdIndex, RegisterType.Gpr));
                }
            }

            int handle = op.Immediate;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    TextureOperation operation = new TextureOperation(
                        Instruction.TextureSample,
                        type,
                        flags,
                        handle,
                        compIndex,
                        dest,
                        sources);

                    context.Add(operation);
                }
            }

            if (op.IsFp16)
            {
                context.Copy(Register(op.Rd0), context.PackHalf2x16(rd0[0], rd0[1]));
                context.Copy(Register(op.Rd1), context.PackHalf2x16(rd1[0], rd1[1]));
            }
        }
        public SpriteFramePropertyGrid(Cursor cursor)
            : base(cursor)
        {
            ExcludeAllMembers();

            #region Include Basic Members

            IncludeMember("X", "Basic");
            IncludeMember("Y", "Basic");
            IncludeMember("Z", "Basic");

            IncludeMember("RotationX", "Basic");
            IncludeMember("RotationY", "Basic");
            IncludeMember("RotationZ", "Basic");

            IncludeMember("Visible", "Basic");
            IncludeMember("CursorSelectable", "Basic");

            IncludeMember("Name", "Basic");

            mOrderingMode = new ComboBox(mCursor);
            mOrderingMode.AddItem("Distance from Camera", OrderingMode.DistanceFromCamera);
            mOrderingMode.AddItem("ZBuffered", OrderingMode.ZBuffered);
            mOrderingMode.ScaleX = 6.5f;
            AddWindow(mOrderingMode, "Basic");
            SetLabelForWindow(mOrderingMode, "OrderingMode");
            mOrderingMode.ItemClick += SetOrderingMode;

            #endregion

            #region Scale Members

            IncludeMember("ScaleX", "Scale");
            IncludeMember("ScaleY", "Scale");

            Button setPixelPerfectScale = new Button(mCursor);
            setPixelPerfectScale.ScaleX = 5;
            setPixelPerfectScale.ScaleY = 2;

            setPixelPerfectScale.Text = "Set Pixel\nPerfect";

            setPixelPerfectScale.Click += SetPixelPerfectClick;

            AddWindow(setPixelPerfectScale, "Scale");

            #endregion

            IncludeMember("Texture", "Texture");
            SetMemberChangeEvent("Texture", OnTextureChange);

            #region Animation members

            IncludeMember("AnimationChains", "Animation");
            IncludeMember("CurrentChainName", "Animation");
            IncludeMember("Animate", "Animation");
            IncludeMember("AnimationSpeed", "Animation");

            #endregion

            #region Include Color Members

            IncludeMember("ColorOperation", "Color");

#if !FRB_XNA
            ComboBox colorOperationComboBox = GetUIElementForMember("ColorOperation") as ComboBox;

            for (int i = colorOperationComboBox.Count - 1; i > -1; i--)
            {
                TextureOperation textureOperation =
                    ((TextureOperation)colorOperationComboBox[i].ReferenceObject);

                if (!FlatRedBall.Graphics.GraphicalEnumerations.IsTextureOperationSupportedInFrbXna(
                        textureOperation))
                {
                    colorOperationComboBox.RemoveAt(i);
                }
            }
#endif

            IncludeMember("Red", "Color");
            IncludeMember("Green", "Color");
            IncludeMember("Blue", "Color");

            #endregion

            #region Include Blend Members

            IncludeMember("BlendOperation", "Blend");
            IncludeMember("Alpha", "Blend");

            #endregion

            #region Include Border Members

            IncludeMember("TextureBorderWidth", "Border");
            IncludeMember("SpriteBorderWidth", "Border");
            IncludeMember("Borders", "Border");
            IncludeMember("PixelSize", "Border");

            #endregion

            #region Customize "Borders"

            SetMemberChangeEvent("Borders", OnBordersChanged);

            #endregion

            #region Customize TextureBorderWidth

            UpDown upDown = GetUIElementForMember("TextureBorderWidth") as UpDown;
            upDown.MinValue = 0;
            upDown.MaxValue = .5f;

            mTextureBorderWidthInPixels               = new UpDown(mCursor);
            mTextureBorderWidthInPixels.ScaleX        = 6;
            mTextureBorderWidthInPixels.ValueChanged += ChangeTextureBorderWidthInPixels;
            mTextureBorderWidthInPixels.RoundTo       = 1;
            AddWindow(mTextureBorderWidthInPixels, "Border");


            #endregion


            #region Replace the CurrentChainName UI element

            mCurrentChainNameComboBox        = new ComboBox(this.mCursor);
            mCurrentChainNameComboBox.ScaleX = 5;
            ReplaceMemberUIElement("CurrentChainName", mCurrentChainNameComboBox);

            #endregion

            mAnimationChainFileTextBox                     = new FileTextBox(this.mCursor);
            mAnimationChainFileTextBox.ScaleX              = 8;
            mAnimationChainFileTextBox.TextBox.CursorOver += ShowAnimationPopup;
            this.AddWindow(mAnimationChainFileTextBox, "Animation");
            mAnimationChainFileTextBox.SetFileType("achx");
            this.SetLabelForWindow(mAnimationChainFileTextBox, "Animation File");

            mAnimationChainFileTextBox.FileSelect += SetAnimationChainOnSprite;


            AfterUpdateDisplayedProperties += new GuiMessage(UpdateTextureBorderWidthUI);

            RemoveCategory("Uncategorized");

            SelectCategory("Basic");
        }
示例#19
0
        private static void EmitSuld(
            EmitterContext context,
            CacheOpLd cacheOp,
            SuDim dimensions,
            SuSize size,
            int imm,
            SuRgba componentMask,
            int srcA,
            int srcB,
            int srcC,
            bool useComponents,
            bool byteAddress,
            bool isBindless)
        {
            context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);

            SamplerType type = ConvertSamplerType(dimensions);

            if (type == SamplerType.None)
            {
                context.Config.GpuAccessor.Log("Invalid image store sampler type.");
                return;
            }

            Operand Ra()
            {
                if (srcA > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(srcA++, RegisterType.Gpr)));
            }

            List <Operand> sourcesList = new List <Operand>();

            if (isBindless)
            {
                sourcesList.Add(context.Copy(Register(srcC, RegisterType.Gpr)));
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (Sample1DAs2D && (type & SamplerType.Mask) == SamplerType.Texture1D)
            {
                sourcesList.Add(Const(0));

                type &= ~SamplerType.Mask;
                type |= SamplerType.Texture2D;
            }

            if (type.HasFlag(SamplerType.Array))
            {
                sourcesList.Add(Ra());
            }

            Operand[] sources = sourcesList.ToArray();

            int handle = imm;

            TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;

            if (cacheOp == CacheOpLd.Cg)
            {
                flags |= TextureFlags.Coherent;
            }

            if (useComponents)
            {
                for (int compMask = (int)componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
                {
                    if ((compMask & 1) == 0)
                    {
                        continue;
                    }

                    if (srcB == RegisterConsts.RegisterZeroIndex)
                    {
                        break;
                    }

                    Operand rd = Register(srcB++, RegisterType.Gpr);

                    TextureOperation operation = context.CreateTextureOperation(
                        Instruction.ImageLoad,
                        type,
                        flags,
                        handle,
                        compIndex,
                        rd,
                        sources);

                    if (!isBindless)
                    {
                        operation.Format = context.Config.GetTextureFormat(handle);
                    }

                    context.Add(operation);
                }
            }
            else
            {
                if (byteAddress)
                {
                    int xIndex = isBindless ? 1 : 0;

                    sources[xIndex] = context.ShiftRightS32(sources[xIndex], Const(GetComponentSizeInBytesLog2(size)));
                }

                int components = GetComponents(size);

                for (int compIndex = 0; compIndex < components; compIndex++)
                {
                    if (srcB == RegisterConsts.RegisterZeroIndex)
                    {
                        break;
                    }

                    Operand rd = Register(srcB++, RegisterType.Gpr);

                    TextureOperation operation = context.CreateTextureOperation(
                        Instruction.ImageLoad,
                        type,
                        GetTextureFormat(size),
                        flags,
                        handle,
                        compIndex,
                        rd,
                        sources);

                    context.Add(operation);

                    switch (size)
                    {
                    case SuSize.U8: context.Copy(rd, ZeroExtendTo32(context, rd, 8)); break;

                    case SuSize.U16: context.Copy(rd, ZeroExtendTo32(context, rd, 16)); break;

                    case SuSize.S8: context.Copy(rd, SignExtendTo32(context, rd, 8)); break;

                    case SuSize.S16: context.Copy(rd, SignExtendTo32(context, rd, 16)); break;
                    }
                }
            }
        }
示例#20
0
 private void SetTextureStageState(int stage, TextureStage type, TextureOperation value)
 {
     SetTextureStageState(stage, type, (int)value);
 }
示例#21
0
        public RenderBreak(int itemNumber, Sprite sprite)
        {
#if DEBUG
            ObjectCausingBreak = sprite;
#endif
            LayerName              = Renderer.CurrentLayerName;
            ItemNumber             = itemNumber;
            PrimitiveType          = PrimitiveType.TriangleList;
            _originalTextureFilter = TextureFilter.Linear;

            if (sprite != null)
            {
                if (sprite.Texture != null && sprite.Texture.IsDisposed)
                {
                    throw new ObjectDisposedException("The Sprite with the name \"" + sprite.Name +
                                                      "\" references a disposed texture of the name " + sprite.Texture.Name +
                                                      ".  If you're using Screens you may have forgotten to remove a Sprite that was " +
                                                      "added in the Screen.");
                }

                mTexture = sprite.Texture;

                ColorOperation = sprite.ColorOperation;
                BlendOperation = sprite.BlendOperation;
                TextureFilter  = sprite.TextureFilter.HasValue ? sprite.TextureFilter.Value : FlatRedBallServices.GraphicsOptions.TextureFilter;

#if FRB_XNA
                if (sprite.Texture == null)
                {
                    // requirement for reach profile - this shouldn't impact anything
                    TextureAddressMode = Microsoft.Xna.Framework.Graphics.TextureAddressMode.Clamp;
                }
                else
#endif
                {
                    TextureAddressMode = sprite.TextureAddressMode;
                }


#if WINDOWS_PHONE || MONOGAME
                Red   = sprite.Red;
                Green = sprite.Green;
                Blue  = sprite.Blue;
#endif
            }
            else
            {
#if WINDOWS_PHONE || MONOGAME
                Red   = 0;
                Green = 0;
                Blue  = 0;
#endif

                mTexture = null;
#if FRB_MDX
                ColorOperation = TextureOperation.SelectArg1;
#else
                ColorOperation = ColorOperation.None;
#endif
                BlendOperation     = BlendOperation.Regular;
                TextureAddressMode = TextureAddressMode.Clamp;
                TextureFilter      = FlatRedBallServices.GraphicsOptions.TextureFilter;
            }
        }
示例#22
0
        public void SetStates()
        {
            //if (Renderer.RendererDiagnosticSettings.RenderBreaksPerformStateChanges)
            {
#if FRB_MDX
                if (Texture != null)
                {
                    Renderer.Texture = Texture.texture;
                }
                else
                {
                    Renderer.Texture = null;
                }

                if (Texture == null && ColorOperation == TextureOperation.SelectArg1)
                {
                    ColorOperation = TextureOperation.SelectArg2;
                }
#else
                if (ColorOperation != Graphics.ColorOperation.Color)
                {
                    Renderer.Texture = Texture;
                }

                if (Texture == null && ColorOperation == ColorOperation.Texture)
                {
                    ColorOperation = ColorOperation.Color;
                }
#endif

                Renderer.ColorOperation     = ColorOperation;
                Renderer.BlendOperation     = BlendOperation;
                Renderer.TextureAddressMode = TextureAddressMode;
                _originalTextureFilter      = FlatRedBallServices.GraphicsOptions.TextureFilter;
                if (TextureFilter != FlatRedBallServices.GraphicsOptions.TextureFilter)
                {
                    FlatRedBallServices.GraphicsOptions.TextureFilter = TextureFilter;
                }

#if WINDOWS_PHONE || MONOGAME
                if (ColorOperation == Graphics.ColorOperation.ColorTextureAlpha)
                {
                    Renderer.SetFogForColorOperation(Red, Green, Blue);
                }
                // Vic says - can we do add?  Do we have to use dual texturing?  Crappy!
                //if (ColorOperation == Graphics.ColorOperation.Add)
                //{
                //    BasicEffect effect = Renderer.CurrentEffect as BasicEffect;



                //    effect.LightingEnabled = true;

                //    effect.AmbientLightColor = Microsoft.Xna.Framework.Vector3.One;

                //    effect.DirectionalLight0.Enabled = true;
                //    effect.DirectionalLight0.DiffuseColor = new Microsoft.Xna.Framework.Vector3(Red, Green, Blue);
                //    //effect.EmissiveColor = new Microsoft.Xna.Framework.Vector3(Red, Green, Blue);


                //}
                //else
                //{
                //    BasicEffect effect = Renderer.CurrentEffect as BasicEffect;

                //    effect.EmissiveColor = new Microsoft.Xna.Framework.Vector3(0, 0, 0);


                //}
#endif
            }
        }
示例#23
0
		public TextureSlot(Texture texture, int uvIndex, float blendFactor, TextureOperation operation, TextureWrap wrapS, TextureWrap wrapT) {
			this.Texture = texture;
			this.UVIndex = uvIndex;
			this.BlendFactor = blendFactor;
			this.Operation = operation;
			this.WrapS = wrapS;
			this.WrapT = wrapT;
		}
示例#24
0
        /// <summary>
        /// This is where we do our rendering
        /// Called from UI thread = UI code safe in this function
        /// </summary>
        public override void OnRender(DrawArgs drawArgs)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            // Device shortcuts ;
            Device device = drawArgs.device;

            // Read star catalog and build vertex list if not done yet
            if (StarListVB == null || refWidth != device.Viewport.Width)
            {
                if (StarListVB != null)
                {
                    StarListVB = null;
                }
                if (FlareMesh != null)
                {
                    FlareMesh.Dispose();
                    FlareMesh = null;
                }
                LoadStars();
            }


            if (drawArgs.WorldCamera.Altitude < 10e3)
            {
                return;
            }

            // save world and projection transform
            Matrix origWorld      = drawArgs.device.Transform.World;
            Matrix origProjection = drawArgs.device.Transform.Projection;

            TextureOperation a0 = drawArgs.device.TextureState[0].AlphaOperation;
            TextureArgument  a1 = drawArgs.device.TextureState[0].AlphaArgument1;
            TextureOperation c0 = drawArgs.device.TextureState[0].ColorOperation;
            TextureArgument  c1 = drawArgs.device.TextureState[0].ColorArgument1;
            TextureArgument  c2 = drawArgs.device.TextureState[0].ColorArgument2;


            // Save fog status
            bool origFog = drawArgs.device.RenderState.FogEnable;
            bool islight = drawArgs.device.RenderState.Lighting;

            device.RenderState.FogEnable = false;
            device.RenderState.Lighting  = false;
            // Set new projection (to avoid being clipped) - probably better ways of doing this?
            float aspectRatio = (float)device.Viewport.Width / device.Viewport.Height;

            device.Transform.Projection = Matrix.PerspectiveFovRH((float)drawArgs.WorldCamera.Fov.Radians, aspectRatio, 1, float.MaxValue);

            // This is where we can rotate the star dome to acomodate time and seasons

            device.Transform.World = Matrix.RotationZ(
                (float)(TimeKeeper.CurrentTimeUtc.Hour +
                        TimeKeeper.CurrentTimeUtc.Minute / 60.0 +
                        TimeKeeper.CurrentTimeUtc.Second / 3600.0 +
                        TimeKeeper.CurrentTimeUtc.Millisecond / 3600000.0) / 24.0f * (float)(-2 * Math.PI));


            // Render textured flares if set
            if (showFlares)
            {
                device.SetTexture(0, texture);

                device.TextureState[0].AlphaOperation = TextureOperation.BlendCurrentAlpha;
                device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                device.TextureState[0].ColorOperation = TextureOperation.AddSmooth;
                device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;

                device.VertexFormat = CustomVertex.PositionTextured.Format;

                FlareMesh.DrawSubset(0);
            }
            drawArgs.device.TextureState[0].AlphaOperation = a0;
            drawArgs.device.TextureState[0].AlphaArgument1 = a1;
            drawArgs.device.TextureState[0].ColorOperation = c0;
            drawArgs.device.TextureState[0].ColorArgument1 = c1;
            drawArgs.device.TextureState[0].ColorArgument2 = c2;

            // draw StarListVB
            device.SetTexture(0, null);
            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.SetStreamSource(0, StarListVB, 0);
            device.DrawPrimitives(PrimitiveType.PointList, 0, StarCount);

            // Restore device states
            drawArgs.device.Transform.World       = origWorld;
            drawArgs.device.Transform.Projection  = origProjection;
            drawArgs.device.RenderState.FogEnable = origFog;
            drawArgs.device.RenderState.Lighting  = islight;
        }
示例#25
0
		public MeshTextureSlot(int index, float blendFactor, TextureOperation operation) {
			this.Index = index;
			this.BlendFactor = blendFactor;
			this.Operation = operation;
		}
示例#26
0
        public static void Txd(EmitterContext context)
        {
            OpCodeTxd op = (OpCodeTxd)context.CurrOp;

            if (op.Rd.IsRZ)
            {
                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            TextureFlags flags = TextureFlags.Derivatives;

            List <Operand> sourcesList = new List <Operand>();

            if (op.IsBindless)
            {
                sourcesList.Add(Ra());
            }

            SamplerType type = ConvertSamplerType(op.Dimensions);

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            Operand packedParams = Ra();

            if (op.IsArray)
            {
                sourcesList.Add(context.BitwiseAnd(packedParams, Const(0xffff)));

                type |= SamplerType.Array;
            }

            // Derivatives (X and Y).
            for (int dIndex = 0; dIndex < 2 * coordsCount; dIndex++)
            {
                sourcesList.Add(Rb());
            }

            if (op.HasOffset)
            {
                for (int index = 0; index < coordsCount; index++)
                {
                    sourcesList.Add(context.BitfieldExtractS32(packedParams, Const(16 + index * 4), Const(4)));
                }

                flags |= TextureFlags.Offset;
            }

            Operand[] sources = sourcesList.ToArray();

            int rdIndex = op.Rd.Index;

            Operand GetDest()
            {
                if (rdIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(Register(rdIndex++, RegisterType.Gpr));
            }

            int handle = !op.IsBindless ? op.Immediate : 0;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    TextureOperation operation = new TextureOperation(
                        Instruction.TextureSample,
                        type,
                        flags,
                        handle,
                        compIndex,
                        dest,
                        sources);

                    context.Add(operation);
                }
            }
        }
示例#27
0
        private static void EmitSured(
            EmitterContext context,
            SuDim dimensions,
            RedOp atomicOp,
            SuatomSize size,
            int imm,
            int srcA,
            int srcB,
            int srcC,
            bool byteAddress,
            bool isBindless)
        {
            SamplerType type = ConvertSamplerType(dimensions);

            if (type == SamplerType.None)
            {
                context.Config.GpuAccessor.Log("Invalid image reduction sampler type.");
                return;
            }

            Operand Ra()
            {
                if (srcA > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(srcA++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (srcB > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(srcB++, RegisterType.Gpr)));
            }

            List <Operand> sourcesList = new List <Operand>();

            if (isBindless)
            {
                sourcesList.Add(context.Copy(GetSrcReg(context, srcC)));
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (Sample1DAs2D && (type & SamplerType.Mask) == SamplerType.Texture1D)
            {
                sourcesList.Add(Const(0));

                type &= ~SamplerType.Mask;
                type |= SamplerType.Texture2D;
            }

            if (type.HasFlag(SamplerType.Array))
            {
                sourcesList.Add(Ra());

                type |= SamplerType.Array;
            }

            if (byteAddress)
            {
                int xIndex = isBindless ? 1 : 0;

                sourcesList[xIndex] = context.ShiftRightS32(sourcesList[xIndex], Const(GetComponentSizeInBytesLog2(size)));
            }

            // TODO: FP and 64-bit formats.
            TextureFormat format = size == SuatomSize.Sd32 || size == SuatomSize.Sd64
                ? (isBindless ? TextureFormat.Unknown : context.Config.GetTextureFormatAtomic(imm))
                : GetTextureFormat(size);

            sourcesList.Add(Rb());

            Operand[] sources = sourcesList.ToArray();

            TextureFlags flags = GetAtomicOpFlags((SuatomOp)atomicOp);

            if (isBindless)
            {
                flags |= TextureFlags.Bindless;
            }

            TextureOperation operation = context.CreateTextureOperation(
                Instruction.ImageAtomic,
                type,
                format,
                flags,
                imm,
                0,
                null,
                sources);

            context.Add(operation);
        }
示例#28
0
        private static void EmitTextureSample(EmitterContext context, TextureFlags flags)
        {
            OpCodeTexture op = (OpCodeTexture)context.CurrOp;

            bool isBindless = (flags & TextureFlags.Bindless) != 0;

            if (op.Rd.IsRZ)
            {
                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            Operand arrayIndex = op.IsArray ? Ra() : null;

            List <Operand> sourcesList = new List <Operand>();

            if (isBindless)
            {
                sourcesList.Add(Rb());
            }

            SamplerType type = ConvertSamplerType(op.Dimensions);

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (op.IsArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            bool hasLod = op.LodMode > TextureLodMode.LodZero;

            Operand lodValue = hasLod ? Rb() : ConstF(0);

            Operand packedOffs = op.HasOffset ? Rb() : null;

            if (op.HasDepthCompare)
            {
                sourcesList.Add(Rb());

                type |= SamplerType.Shadow;
            }

            if ((op.LodMode == TextureLodMode.LodZero ||
                 op.LodMode == TextureLodMode.LodLevel ||
                 op.LodMode == TextureLodMode.LodLevelA) && !op.IsMultisample)
            {
                sourcesList.Add(lodValue);

                flags |= TextureFlags.LodLevel;
            }

            if (op.HasOffset)
            {
                for (int index = 0; index < coordsCount; index++)
                {
                    sourcesList.Add(context.BitfieldExtractS32(packedOffs, Const(index * 4), Const(4)));
                }

                flags |= TextureFlags.Offset;
            }

            if (op.LodMode == TextureLodMode.LodBias ||
                op.LodMode == TextureLodMode.LodBiasA)
            {
                sourcesList.Add(lodValue);

                flags |= TextureFlags.LodBias;
            }

            if (op.IsMultisample)
            {
                sourcesList.Add(Rb());

                type |= SamplerType.Multisample;
            }

            Operand[] sources = sourcesList.ToArray();

            int rdIndex = op.Rd.Index;

            Operand GetDest()
            {
                if (rdIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(Register(rdIndex++, RegisterType.Gpr));
            }

            int handle = !isBindless ? op.Immediate : 0;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    TextureOperation operation = new TextureOperation(
                        Instruction.TextureSample,
                        type,
                        flags,
                        handle,
                        compIndex,
                        dest,
                        sources);

                    context.Add(operation);
                }
            }
        }
示例#29
0
        public static void Sust(EmitterContext context)
        {
            OpCodeImage op = (OpCodeImage)context.CurrOp;

            SamplerType type = ConvertSamplerType(op.Dimensions);

            if (type == SamplerType.None)
            {
                context.Config.PrintLog("Invalid image store sampler type.");

                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            bool isArray = op.Dimensions == ImageDimensions.Image1DArray ||
                           op.Dimensions == ImageDimensions.Image2DArray;

            Operand arrayIndex = isArray ? Ra() : null;

            List <Operand> sourcesList = new List <Operand>();

            if (op.IsBindless)
            {
                sourcesList.Add(context.Copy(Register(op.Rc)));
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (isArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            if (op.UseComponents)
            {
                int componentMask = (int)op.Components;

                for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
                {
                    if ((compMask & 1) != 0)
                    {
                        sourcesList.Add(Rb());
                    }
                }
            }
            else
            {
                context.Config.PrintLog("Unsized image store not supported.");
            }

            Operand[] sources = sourcesList.ToArray();

            int handle = !op.IsBindless ? op.Immediate : 0;

            TextureFlags flags = op.IsBindless ? TextureFlags.Bindless : TextureFlags.None;

            TextureOperation operation = new TextureOperation(
                Instruction.ImageStore,
                type,
                flags,
                handle,
                0,
                null,
                sources);

            context.Add(operation);
        }
示例#30
0
 public MeshTextureSlot(int index, float blendFactor, TextureOperation operation)
 {
     this.Index       = index;
     this.BlendFactor = blendFactor;
     this.Operation   = operation;
 }
示例#31
0
        public static void Tld4(EmitterContext context)
        {
            IOpCodeTld4 op = (IOpCodeTld4)context.CurrOp;

            if (op.Rd.IsRZ)
            {
                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            Operand arrayIndex = op.IsArray ? Ra() : null;

            List <Operand> sourcesList = new List <Operand>();

            SamplerType type = ConvertSamplerType(op.Dimensions);

            TextureFlags flags = TextureFlags.Gather;

            if (op.Bindless)
            {
                sourcesList.Add(Rb());

                flags |= TextureFlags.Bindless;
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (op.IsArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            Operand[] packedOffs = new Operand[2];

            packedOffs[0] = op.Offset != TextureGatherOffset.None    ? Rb() : null;
            packedOffs[1] = op.Offset == TextureGatherOffset.Offsets ? Rb() : null;

            if (op.HasDepthCompare)
            {
                sourcesList.Add(Rb());

                type |= SamplerType.Shadow;
            }

            if (op.Offset != TextureGatherOffset.None)
            {
                int offsetTexelsCount = op.Offset == TextureGatherOffset.Offsets ? 4 : 1;

                for (int index = 0; index < coordsCount * offsetTexelsCount; index++)
                {
                    Operand packed = packedOffs[(index >> 2) & 1];

                    sourcesList.Add(context.BitfieldExtractS32(packed, Const((index & 3) * 8), Const(6)));
                }

                flags |= op.Offset == TextureGatherOffset.Offsets
                    ? TextureFlags.Offsets
                    : TextureFlags.Offset;
            }

            sourcesList.Add(Const(op.GatherCompIndex));

            Operand[] sources = sourcesList.ToArray();

            int rdIndex = op.Rd.Index;

            Operand GetDest()
            {
                if (rdIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(Register(rdIndex++, RegisterType.Gpr));
            }

            int handle = op.Immediate;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    TextureOperation operation = new TextureOperation(
                        Instruction.TextureSample,
                        type,
                        flags,
                        handle,
                        compIndex,
                        dest,
                        sources);

                    context.Add(operation);
                }
            }
        }
示例#32
0
        public static void Suld(EmitterContext context)
        {
            OpCodeImage op = (OpCodeImage)context.CurrOp;

            SamplerType type = ConvertSamplerType(op.Dimensions);

            if (type == SamplerType.None)
            {
                context.Config.GpuAccessor.Log("Invalid image store sampler type.");

                return;
            }

            // Rb is Rd on the SULD instruction.
            int rdIndex = op.Rb.Index;
            int raIndex = op.Ra.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            bool isArray = op.Dimensions == ImageDimensions.Image1DArray ||
                           op.Dimensions == ImageDimensions.Image2DArray;

            Operand arrayIndex = isArray ? Ra() : null;

            List <Operand> sourcesList = new List <Operand>();

            if (op.IsBindless)
            {
                sourcesList.Add(context.Copy(Register(op.Rc)));
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (isArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            Operand[] sources = sourcesList.ToArray();

            int handle = !op.IsBindless ? op.Immediate : 0;

            TextureFlags flags = op.IsBindless ? TextureFlags.Bindless : TextureFlags.None;

            if (op.UseComponents)
            {
                int componentMask = (int)op.Components;

                for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
                {
                    if ((compMask & 1) == 0)
                    {
                        continue;
                    }

                    if (rdIndex == RegisterConsts.RegisterZeroIndex)
                    {
                        break;
                    }

                    Operand rd = Register(rdIndex++, RegisterType.Gpr);

                    TextureOperation operation = new TextureOperation(
                        Instruction.ImageLoad,
                        type,
                        flags,
                        handle,
                        compIndex,
                        rd,
                        sources);

                    if (!op.IsBindless)
                    {
                        operation.Format = context.Config.GetTextureFormat(handle);
                    }

                    context.Add(operation);
                }
            }
            else
            {
                if (op.ByteAddress)
                {
                    int xIndex = op.IsBindless ? 1 : 0;

                    sources[xIndex] = context.ShiftRightS32(sources[xIndex], Const(GetComponentSizeInBytesLog2(op.Size)));
                }

                int components = GetComponents(op.Size);

                for (int compIndex = 0; compIndex < components; compIndex++)
                {
                    if (rdIndex == RegisterConsts.RegisterZeroIndex)
                    {
                        break;
                    }

                    Operand rd = Register(rdIndex++, RegisterType.Gpr);

                    TextureOperation operation = new TextureOperation(
                        Instruction.ImageLoad,
                        type,
                        flags,
                        handle,
                        compIndex,
                        rd,
                        sources)
                    {
                        Format = GetTextureFormat(op.Size)
                    };

                    context.Add(operation);

                    switch (op.Size)
                    {
                    case IntegerSize.U8:  context.Copy(rd, ZeroExtendTo32(context, rd, 8));  break;

                    case IntegerSize.U16: context.Copy(rd, ZeroExtendTo32(context, rd, 16)); break;

                    case IntegerSize.S8:  context.Copy(rd, SignExtendTo32(context, rd, 8));  break;

                    case IntegerSize.S16: context.Copy(rd, SignExtendTo32(context, rd, 16)); break;
                    }
                }
            }
        }
示例#33
0
        private static void EmitTextureQuery(EmitterContext context, bool bindless)
        {
            OpCodeTex op = (OpCodeTex)context.CurrOp;

            if (op.Rd.IsRZ)
            {
                return;
            }

            TextureProperty property = (TextureProperty)op.RawOpCode.Extract(22, 6);

            // TODO: Validate and use property.
            Instruction inst = Instruction.TextureSize;

            SamplerType type = SamplerType.Texture2D;

            TextureFlags flags = bindless ? TextureFlags.Bindless : TextureFlags.None;

            int raIndex = op.Ra.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            List <Operand> sourcesList = new List <Operand>();

            if (bindless)
            {
                sourcesList.Add(Ra());
            }

            sourcesList.Add(Ra());

            Operand[] sources = sourcesList.ToArray();

            int rdIndex = op.Rd.Index;

            Operand GetDest()
            {
                if (rdIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(Register(rdIndex++, RegisterType.Gpr));
            }

            int handle = !bindless ? op.Immediate : 0;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    TextureOperation operation = new TextureOperation(
                        inst,
                        type,
                        flags,
                        handle,
                        compIndex,
                        dest,
                        sources);

                    context.Add(operation);
                }
            }
        }
示例#34
0
        public override void Begin()
        {
            SDX_Display mDisplay = (SDX_Display)AgateLib.DisplayLib.Display.Impl;

            Set2DDrawState();

            mDisplay.D3D_Device.Device.SetRenderState(RenderState.Lighting, true);
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.Ambient, AmbientLight.ToArgb());
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.ColorVertex, true);

            TextureArgument  arg0 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg0);
            TextureArgument  arg1 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg1);
            TextureArgument  arg2 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg2);
            TextureOperation op   = (TextureOperation)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorOperation);

            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg0, TextureArgument.Current);
            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Current);
            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.Modulate);
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Color1);
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Color1);

            Material material = new Material();

            material.Diffuse = new SlimDX.Color4(Color.White.ToArgb());
            material.Ambient = new SlimDX.Color4(Color.White.ToArgb());


            mDisplay.D3D_Device.Device.Material = material;

            int index = 0;

            for (int i = 0; i < Lights.Count; i++)
            {
                var agateLight = Lights[i];

                if (agateLight == null)
                {
                    continue;
                }
                if (agateLight.Enabled == false)
                {
                    continue;
                }

                SlimDX.Direct3D9.Light l = new SlimDX.Direct3D9.Light();

                l.Ambient      = new SlimDX.Color4(agateLight.AmbientColor.ToArgb());
                l.Attenuation0 = agateLight.AttenuationConstant;
                l.Attenuation1 = agateLight.AttenuationLinear;
                l.Attenuation2 = agateLight.AttenuationQuadratic;
                l.Diffuse      = new SlimDX.Color4(agateLight.DiffuseColor.ToArgb());
                l.Type         = LightType.Point;
                l.Direction    = new SlimDX.Vector3(0, 0, 1);
                l.Range        = 100;


                Vector3 pos = agateLight.Position;

                l.Position = new SlimDX.Vector3(pos.X, pos.Y, pos.Z);

                mDisplay.D3D_Device.Device.SetLight(index, l);
                mDisplay.D3D_Device.Device.EnableLight(index, true);

                index++;
            }
        }
示例#35
0
        private static void EmitTextureSample(EmitterContext context, TextureFlags flags)
        {
            OpCodeTexture op = (OpCodeTexture)context.CurrOp;

            bool isBindless = (flags & TextureFlags.Bindless) != 0;

            if (op.Rd.IsRZ)
            {
                return;
            }

            int raIndex = op.Ra.Index;
            int rbIndex = op.Rb.Index;

            Operand Ra()
            {
                if (raIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(raIndex++, RegisterType.Gpr)));
            }

            Operand Rb()
            {
                if (rbIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(context.Copy(Register(rbIndex++, RegisterType.Gpr)));
            }

            Operand arrayIndex = op.IsArray ? Ra() : null;

            List <Operand> sourcesList = new List <Operand>();

            if (isBindless)
            {
                sourcesList.Add(Rb());
            }

            SamplerType type = ConvertSamplerType(op.Dimensions);

            bool hasLod = op.LodMode > TextureLodMode.LodZero;

            if (type == SamplerType.Texture1D && (flags & ~TextureFlags.Bindless) == TextureFlags.IntCoords && !(hasLod ||
                                                                                                                 op.HasDepthCompare ||
                                                                                                                 op.HasOffset ||
                                                                                                                 op.IsArray ||
                                                                                                                 op.IsMultisample))
            {
                // For bindless, we don't have any way to know the texture type,
                // so we assume it's texture buffer when the sampler type is 1D, since that's more common.
                bool isTypeBuffer = isBindless || context.Config.GpuAccessor.QueryIsTextureBuffer(op.Immediate);

                if (isTypeBuffer)
                {
                    type = SamplerType.TextureBuffer;
                }
            }

            int coordsCount = type.GetDimensions();

            for (int index = 0; index < coordsCount; index++)
            {
                sourcesList.Add(Ra());
            }

            if (op.IsArray)
            {
                sourcesList.Add(arrayIndex);

                type |= SamplerType.Array;
            }

            Operand lodValue = hasLod ? Rb() : ConstF(0);

            Operand packedOffs = op.HasOffset ? Rb() : null;

            if (op.HasDepthCompare)
            {
                sourcesList.Add(Rb());

                type |= SamplerType.Shadow;
            }

            if ((op.LodMode == TextureLodMode.LodZero ||
                 op.LodMode == TextureLodMode.LodLevel ||
                 op.LodMode == TextureLodMode.LodLevelA) && !op.IsMultisample && type != SamplerType.TextureBuffer)
            {
                sourcesList.Add(lodValue);

                flags |= TextureFlags.LodLevel;
            }

            if (op.HasOffset)
            {
                for (int index = 0; index < coordsCount; index++)
                {
                    sourcesList.Add(context.BitfieldExtractS32(packedOffs, Const(index * 4), Const(4)));
                }

                flags |= TextureFlags.Offset;
            }

            if (op.LodMode == TextureLodMode.LodBias ||
                op.LodMode == TextureLodMode.LodBiasA)
            {
                sourcesList.Add(lodValue);

                flags |= TextureFlags.LodBias;
            }

            if (op.IsMultisample)
            {
                sourcesList.Add(Rb());

                type |= SamplerType.Multisample;
            }

            Operand[] sources = sourcesList.ToArray();

            int rdIndex = op.Rd.Index;

            Operand GetDest()
            {
                if (rdIndex > RegisterConsts.RegisterZeroIndex)
                {
                    return(Const(0));
                }

                return(Register(rdIndex++, RegisterType.Gpr));
            }

            int handle = !isBindless ? op.Immediate : 0;

            for (int compMask = op.ComponentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
            {
                if ((compMask & 1) != 0)
                {
                    Operand dest = GetDest();

                    TextureOperation operation = new TextureOperation(
                        Instruction.TextureSample,
                        type,
                        flags,
                        handle,
                        compIndex,
                        dest,
                        sources);

                    context.Add(operation);
                }
            }
        }
示例#36
0
 private static extern ReturnCode aiGetMaterialTexture(ref AiMaterial mat, TextureType type, uint index, out AiString path, out TextureMapping mapping, out uint uvIndex, out float blendFactor, out TextureOperation textureOp, out TextureWrapMode wrapMode, out uint flags);