Exemple #1
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            EffectVariable annotation = EffectParseHelper.getAnnotation(variable, "Object", "string");

            if (annotation == null || string.IsNullOrWhiteSpace(annotation.AsString().GetString()))
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されませんでした。",
                              variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic));
            }
            string objectStr = annotation.AsString().GetString().ToLower();
            ObjectAnnotationType type;

            switch (objectStr)
            {
            case "camera":
                type = ObjectAnnotationType.Camera;
                break;

            case "light":
                type = ObjectAnnotationType.Light;
                break;

            default:
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されたのは,「string object=\"{3}\"でした。(スペルミス?)"
                              , variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic, objectStr));
            }
            return(GetSubscriberInstance(type));
        }
Exemple #2
0
        /// <summary>
        ///     If the matrix each examine the Camera or Light?
        /// </summary>
        /// <param name="variable"></param>
        /// <param name="context"></param>
        /// <param name="effectManager"></param>
        /// <param name="semanticIndex"></param>
        /// <param name="effect">Effect of test</param>
        /// <param name="index">Inspect variable index</param>
        /// <returns></returns>
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            string         obj;
            EffectVariable annotation = EffectParseHelper.getAnnotation(variable, "Object", "string");

            obj = annotation == null ? "" : annotation.AsString().GetString(); //The annotation is not present""とする
            if (string.IsNullOrWhiteSpace(obj))
            {
                return(GetSubscriberInstance(ObjectAnnotationType.Camera));
            }
            switch (obj.ToLower())
            {
            case "camera":
                return(GetSubscriberInstance(ObjectAnnotationType.Camera));

            case "light":
                return(GetSubscriberInstance(ObjectAnnotationType.Light));

            case "":
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」には、アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されませんでした。",
                              variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic));

            default:
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」には、アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されたのは「string Object=\"{3}\"」でした。(スペルミス?)",
                              variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic, obj));
            }
        }
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effect, int semanticIndex)
        {
            // 行列の場合は、それぞれCameraかLightか調べる。

            EffectVariable Objectアノテーション = EffectParseHelper.アノテーションを取得する(variable, "Object", "string");

            string obj = (Objectアノテーション == null) ? "" : Objectアノテーション.AsString().GetString();               // アノテーションが存在しない時は""とする

            switch (obj.ToLower())
            {
            case "camera":
                return(行列変数登録インスタンスを生成して返す(Object種別.カメラ));

            case "light":
                return(行列変数登録インスタンスを生成して返す(Object種別.ライト));

            case "":
                return(行列変数登録インスタンスを生成して返す(Object種別.カメラ));        // 既定値

            default:
                throw new InvalidMMEEffectShader例外(
                          $"変数「{variable.TypeInfo.Description.TypeName.ToLower()} {variable.Description.Name}:{variable.Description.Semantic}」には、" +
                          $"アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されたのは「string Object=\"{obj}\"」でした。(スペルミス?)");
            }
        }
Exemple #4
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            bool isVector3 =
                variable.GetVariableType().Description.TypeName.ToLower().Equals("float3");

            if (!NeedAnnotation.Contains(Semantics))
            {
                return(GetSubscriberInstance(TargetObject.UnUsed, isVector3));
            }
            EffectVariable objectAnnotation = EffectParseHelper.getAnnotation(variable, "Object", "string");

            if (objectAnnotation == null)
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format("このセマンティクス\"{0}\"にはアノテーション「Object」が必須ですが、記述されませんでした。", Semantics));
            }
            string annotation = objectAnnotation.AsString().GetString().ToLower();

            if (!string.IsNullOrWhiteSpace(annotation))
            {
                switch (annotation)
                {
                case "geometry":
                    return(GetSubscriberInstance(TargetObject.Geometry, isVector3));

                case "light":
                    return(GetSubscriberInstance(TargetObject.Light, isVector3));

                default:
                    throw new InvalidMMEEffectShaderException(string.Format("アノテーション\"{0}\"は認識されません。", annotation));
                }
            }
            throw new InvalidMMEEffectShaderException(
                      string.Format("このセマンティクス\"{0}\"にはアノテーション「Object」が必須ですが、記述されませんでした。", Semantics));
        }
Exemple #5
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effectManager, int semanticIndex)
        {
            // アノテーション "string Object = ..." を取得

            EffectVariable annotation = EffectParseHelper.アノテーションを取得する(variable, "Object", "string");

            if (annotation == null || string.IsNullOrWhiteSpace(annotation.AsString().GetString()))
            {
                throw new InvalidMMEEffectShader例外(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されませんでした。",
                              variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic));
            }


            // Object の内容で type を決める。

            Object種別 type;
            string   objectStr = annotation.AsString().GetString().ToLower();

            switch (objectStr)
            {
            case "camera":
                type = Object種別.カメラ;
                break;

            case "light":
                type = Object種別.ライト;
                break;

            default:
                throw new InvalidMMEEffectShader例外(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されたのは,「string object=\"{3}\"でした。(スペルミス?)",
                              variable.TypeInfo.Description.TypeName.ToLower(),
                              variable.Description.Name,
                              variable.Description.Semantic,
                              objectStr));
            }


            // 決定された type へ引き継ぐ。

            return(GetSubscriberInstance(type));
        }
Exemple #6
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable d3dEffectVariable, エフェクト effect, int semanticIndex)
        {
            bool isVector3 = d3dEffectVariable.TypeInfo.Description.TypeName.ToLower().Equals("float3");


            if (!_Objectアノテーションが必須なセマンティクス.Contains(セマンティクス))
            {
                // (A) Object アノテーションが不要なセマンティクスの場合

                return(材質変数登録インスタンスを生成して返す(ターゲット種別.未使用, isVector3));
            }
            else
            {
                // (B) Object アノテーションが必須のセマンティクスの場合

                EffectVariable Objectアノテーション = EffectParseHelper.アノテーションを取得する(d3dEffectVariable, "Object", "string");

                if (Objectアノテーション == null)
                {
                    throw new InvalidMMEEffectShader例外($"このセマンティクス\"{セマンティクス}\"にはアノテーション「Object」が必須ですが、記述されませんでした。");
                }

                string annotation = Objectアノテーション.AsString().GetString().ToLower();

                if (string.IsNullOrWhiteSpace(annotation))
                {
                    throw new InvalidMMEEffectShader例外($"このセマンティクス\"{セマンティクス}\"にはアノテーション「Object」が必須ですが、記述されませんでした。");
                }

                switch (annotation)
                {
                case "geometry":
                    return(材質変数登録インスタンスを生成して返す(ターゲット種別.ジオメトリ, isVector3));

                case "light":
                    return(材質変数登録インスタンスを生成して返す(ターゲット種別.ライト, isVector3));

                default:
                    throw new InvalidMMEEffectShader例外($"アノテーション\"{annotation}\"は認識されません。");
                }
            }
        }
Exemple #7
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            TextureSubscriber subscriber = new TextureSubscriber();
            int    width, height, depth, mip;
            string typeName = variable.GetVariableType().Description.TypeName.ToLower();
            string type;
            Format format;

            TextureAnnotationParser.GetBasicTextureAnnotations(variable, context, Format.B8G8R8A8_UNorm, Vector2.Zero, true,
                                                               out width, out height, out depth, out mip, out format);
            EffectVariable rawTypeVariable   = EffectParseHelper.getAnnotation(variable, "ResourceType", "string");
            EffectVariable rawStringVariable = EffectParseHelper.getAnnotation(variable, "ResourceName", "string");

            if (rawTypeVariable != null)
            {
                switch (rawTypeVariable.AsString().GetString().ToLower())
                {
                case "cube":
                    if (!typeName.Equals("texturecube"))
                    {
                        throw new InvalidMMEEffectShaderException("ResourceTypeにはCubeが指定されていますが、型がtextureCUBEではありません。");
                    }
                    else
                    {
                        type = "texturecube";
                    }
                    break;

                case "2d":
                    if (!typeName.Equals("texture2d") && !typeName.Equals("texture"))
                    {
                        throw new InvalidMMEEffectShaderException("ResourceTypeには2Dが指定されていますが、型がtexture2Dもしくはtextureではありません。");
                    }
                    else
                    {
                        type = "texture2d";
                    }
                    break;

                case "3d":
                    if (!typeName.Equals("texture3d"))
                    {
                        throw new InvalidMMEEffectShaderException("ResourceTypeには3Dが指定されていますが、型がtexture3dではありません。");
                    }
                    else
                    {
                        type = "texture3d";
                    }
                    break;

                default:
                    throw new InvalidMMEEffectShaderException("認識できないResourceTypeが指定されました。");
                }
            }
            else
            {
                type = typeName;
            }
            if (rawStringVariable != null)
            {
                string resourceName          = rawStringVariable.AsString().GetString();
                ImageLoadInformation imgInfo = new ImageLoadInformation();
                Stream stream;
                switch (type)
                {
                case "texture2d":

                    imgInfo.Width          = width;
                    imgInfo.Height         = height;
                    imgInfo.MipLevels      = mip;
                    imgInfo.Format         = format;
                    imgInfo.Usage          = ResourceUsage.Default;
                    imgInfo.BindFlags      = BindFlags.ShaderResource;
                    imgInfo.CpuAccessFlags = CpuAccessFlags.None;
                    stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    if (stream != null)
                    {
                        subscriber.resourceTexture = Texture2D.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    }
                    break;

                case "texture3d":
                    imgInfo.Width          = width;
                    imgInfo.Height         = height;
                    imgInfo.Depth          = depth;
                    imgInfo.MipLevels      = mip;
                    imgInfo.Format         = format;
                    imgInfo.Usage          = ResourceUsage.Default;
                    imgInfo.BindFlags      = BindFlags.ShaderResource;
                    imgInfo.CpuAccessFlags = CpuAccessFlags.None;
                    stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    if (stream != null)
                    {
                        subscriber.resourceTexture = Texture3D.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    }
                    break;

                case "texturecube":
                    //TODO CUBEの場合に対応する
                    //imgInfo.Width = width;
                    //imgInfo.Height = height;
                    //imgInfo.Depth = depth;
                    //imgInfo.MipLevels = mip;
                    //imgInfo.Format = format;
                    //imgInfo.Usage=ResourceUsage.Default;
                    //imgInfo.BindFlags=BindFlags.ShaderResource;
                    //imgInfo.CpuAccessFlags=CpuAccessFlags.None;
                    //stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    //subscriber.resourceTexture=.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    break;
                }
            }
            subscriber.resourceView = new ShaderResourceView(context.DeviceManager.Device, subscriber.resourceTexture);
            return(subscriber);
        }
Exemple #8
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effect, int semanticIndex)
        {
            数型           type     = 0;
            TargetObject target   = TargetObject.UnUsed;
            string       itemName = null;
            string       typeName = variable.TypeInfo.Description.TypeName.ToLower();

            switch (typeName)
            {
            case "bool":
                type = 数型.Bool;
                break;

            case "float":
                type = 数型.Float;
                break;

            case "float3":
                type = 数型.Float3;
                break;

            case "float4":
                type = 数型.Float4;
                break;

            case "float4x4":
                type = 数型.Float4x4;
                break;

            default:
                break;
            }

            EffectVariable nameVariable = EffectParseHelper.アノテーションを取得する(variable, "name", "string");

            if (nameVariable == null)
            {
                throw new InvalidMMEEffectShader例外($"定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{typeName} {variable.Description.Name}:CONTROLOBJECT」に対してはアノテーション「string name」は必須ですが、指定されませんでした。");
            }

            string name = nameVariable.AsString().GetString();

            // Selfの場合はターゲットは自分自身となる

            if (name.ToLower().Equals("(self)"))
            {
                _isSelf = true;
            }
            else
            {
                // TODO: (OffscreenOwner)がnameに指定されたときの対応
            }


            EffectVariable itemVariable = EffectParseHelper.アノテーションを取得する(variable, "item", "string");

            if (itemVariable != null)
            {
                itemName = itemVariable.AsString().GetString();

                switch (itemName.ToLower())
                {
                case "x":
                    target = TargetObject.X;
                    break;

                case "y":
                    target = TargetObject.Y;
                    break;

                case "z":
                    target = TargetObject.Z;
                    break;

                case "xyz":
                    target = TargetObject.XYZ;
                    break;

                case "rx":
                    target = TargetObject.Rx;
                    break;

                case "ry":
                    target = TargetObject.Ry;
                    break;

                case "rz":
                    target = TargetObject.Rz;
                    break;

                case "rxyz":
                    target = TargetObject.Rxyz;
                    break;

                case "si":
                    target = TargetObject.Si;
                    break;

                case "tr":
                    target = TargetObject.Tr;
                    break;

                default:
                    target = type == 数型.Float ? TargetObject.FaceName : TargetObject.BoneName;
                    break;
                }

                if (NeedFloat.Contains(target) && type != 数型.Float)
                {
                    throw new InvalidMMEEffectShader例外($"定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{typeName} {variable.Description.Name}:CONTROLOBJECT」にはアノテーション「string item=\"{itemName}\"」が適用されていますが、「{itemName}」の場合は「float {variable.Description.Name}:CONTROLOBJECT」である必要があります。");
                }

                if (NeedFloat3.Contains(target) && type != 数型.Float3)
                {
                    throw new InvalidMMEEffectShader例外($"定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{typeName} {variable.Description.Name}:CONTROLOBJECT」にはアノテーション「string item=\"{itemName}\"」が適用されていますが、「{itemName}」の場合は「float3 {variable.Description.Name}:CONTROLOBJECT」である必要があります。");
                }
            }

            return(new CONTROLOBJECT変数(type, itemName, name, target, _isSelf));
        }
Exemple #9
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effect, int semanticIndex)
        {
            var    subscriber = new テクスチャ変数();
            string typeName   = variable.TypeInfo.Description.TypeName.ToLower();

            int    width, height, depth, mip;
            Format textureFormat, viewFormat, resourceFormat;

            テクスチャのアノテーション解析.解析する(variable, Format.B8G8R8A8_UNorm, Vector2.Zero, true, out width, out height, out depth, out mip, out textureFormat, out viewFormat, out resourceFormat);

            EffectVariable rawTypeVariable   = EffectParseHelper.アノテーションを取得する(variable, "ResourceType", "string");
            EffectVariable rawStringVariable = EffectParseHelper.アノテーションを取得する(variable, "ResourceName", "string");


            // type を決定

            string type;

            if (rawTypeVariable != null)
            {
                switch (rawTypeVariable.AsString().GetString().ToLower())
                {
                case "cube":
                    type = (typeName.Equals("texturecube")) ? "texturecube" : throw new InvalidMMEEffectShader例外("ResourceTypeにはCubeが指定されていますが、型がtextureCUBEではありません。");
                    break;

                case "2d":
                    type = (typeName.Equals("texture2d") || typeName.Equals("texture")) ? "texture2d" : throw new InvalidMMEEffectShader例外("ResourceTypeには2Dが指定されていますが、型がtexture2Dもしくはtextureではありません。");
                    break;

                case "3d":
                    type = (typeName.Equals("texture3d")) ? "texture3d" : throw new InvalidMMEEffectShader例外("ResourceTypeには3Dが指定されていますが、型がtexture3dではありません。");
                    break;

                default:
                    throw new InvalidMMEEffectShader例外("認識できないResourceTypeが指定されました。");
                }
            }
            else
            {
                type = typeName;
            }


            // テクスチャリソースを読み込む

            if (rawStringVariable != null)
            {
                string resourceName = rawStringVariable.AsString().GetString();
                Stream stream;

                switch (type)
                {
                case "texture2d":
                    stream = effect.テクスチャなどのパスの解決に利用するローダー.リソースのストリームを返す(resourceName);
                    if (stream != null)
                    {
                        subscriber._resourceTexture = MMFTexture2D.FromStream(RenderContext.Instance.DeviceManager.D3DDevice, stream);
                    }
                    break;

                case "texture3d":
                    stream = effect.テクスチャなどのパスの解決に利用するローダー.リソースのストリームを返す(resourceName);
                    if (stream != null)
                    {
                        subscriber._resourceTexture = MMFTexture3D.FromStream(RenderContext.Instance.DeviceManager.D3DDevice, stream);
                    }
                    break;

                case "texturecube":
                    //TODO CUBEの場合を実装する
                    //stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    //subscriber.resourceTexture=.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    break;
                }
            }

            // シェーダーリソースビューを割り当て
            subscriber._resourceView = new ShaderResourceView(RenderContext.Instance.DeviceManager.D3DDevice, subscriber._resourceTexture);

            return(subscriber);
        }
Exemple #10
0
        /// <summary>
        /// テクスチャのアノテーション解釈に一般的に必要な項目を取得するメソッド
        /// </summary>
        /// <param name="variable">エフェクト変数</param>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="defaultFormat"></param>
        /// <param name="defaultViewPortRatio"></param>
        /// <param name="width">テクスチャの幅</param>
        /// <param name="height">テクスチャの高さ</param>
        /// <param name="depth">テクスチャの深さ(ない場合は-1)</param>
        /// <param name="mip">mipレベル</param>
        /// <param name="textureFormat">指定されているフォーマット</param>
        public static void GetBasicTextureAnnotations(EffectVariable variable, RenderContext context, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth,
                                                      out int mip, out Format textureFormat)
        {
            width         = -1;
            height        = -1;
            depth         = -1;
            mip           = 0;
            textureFormat = defaultFormat;
            EffectVariable rawWidthVal  = EffectParseHelper.getAnnotation(variable, "width", "int");
            EffectVariable rawHeightVal = EffectParseHelper.getAnnotation(variable, "height", "int");
            EffectVariable rawDepthVal  = EffectParseHelper.getAnnotation(variable, "depth", "int");

            if (rawWidthVal != null)
            {
                width = rawWidthVal.AsScalar().GetInt();
            }
            if (rawHeightVal != null)
            {
                height = rawHeightVal.AsScalar().GetInt();
            }
            if (rawDepthVal != null)
            {
                depth = rawDepthVal.AsScalar().GetInt();
            }
            EffectVariable rawViewportRatio = EffectParseHelper.getAnnotation(variable, "viewportratio", "float2");

            if (rawViewportRatio != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                            variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    Vector4  rawRatio = rawViewportRatio.AsVector().GetVector();
                    Viewport vp       = context.DeviceManager.Context.Rasterizer.GetViewports()[0];
                    width  = (int)(vp.Width * rawRatio.X);
                    height = (int)(vp.Height * rawRatio.Y);
                }
            }
            EffectVariable rawDimensions = EffectParseHelper.getAnnotation(variable, "dimension", "uint2/uint3");

            if (rawDimensions != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format(
                                  "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                  variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    string typeName = rawDimensions.GetVariableType().Description.TypeName.ToLower();
                    if (typeName == "int2")
                    {
                        int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(2);
                        width  = rawDimension[0];
                        height = rawDimension[1];
                    }
                    else
                    {
                        int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(3);
                        width  = rawDimension[0];
                        height = rawDimension[1];
                        depth  = rawDimension[2];
                    }
                }
            }
            if (width == -1 || height == -1)
            {
                if (defaultViewPortRatio != Vector2.Zero)
                {
                    Viewport port = context.DeviceManager.Context.Rasterizer.GetViewports()[0];
                    width  = (int)(port.Width * defaultViewPortRatio.X);
                    height = (int)(port.Height * defaultViewPortRatio.Y);
                }
                else
                {
                    if (!isTextureSubscriber)
                    {
                        throw new InvalidMMEEffectShaderException(string.Format("width,heightのどちらかの指定は必須です。"));
                    }
                }
            }
            EffectVariable rawMipLevel = EffectParseHelper.getAnnotation(variable, "MipLevels", "int");
            EffectVariable rawLevel    = EffectParseHelper.getAnnotation(variable, "levels", "int");

            if (rawMipLevel != null && rawLevel != null)
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format("変数「{0} {1}」のミップマップレベルが重複して指定されています。「int Miplevels」、「int Levels」は片方しか指定できません。",
                                        variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
            }
            else if (rawMipLevel != null || rawLevel != null)
            {
                EffectVariable mipVal = rawMipLevel ?? rawLevel;
                mip = mipVal.AsScalar().GetInt();
            }
            EffectVariable rawFormat = EffectParseHelper.getAnnotation(variable, "format", "string");

            if (rawFormat != null)
            {
                string formatString = rawFormat.AsString().GetString();
                textureFormat = TextureFormat(formatString);
            }
        }
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            VariableType type     = 0;
            TargetObject target   = TargetObject.UnUsed;
            string       itemName = null;
            string       typeName = variable.GetVariableType().Description.TypeName.ToLower();

            switch (typeName)
            {
            case "bool":
                type = VariableType.Bool;
                break;

            case "float":
                type = VariableType.Float;
                break;

            case "float3":
                type = VariableType.Float3;
                break;

            case "float4":
                type = VariableType.Float4;
                break;

            case "float4x4":
                type = VariableType.Float4x4;
                break;

            default:
                break;
            }
            EffectVariable nameVariable = EffectParseHelper.getAnnotation(variable, "name", "string");

            if (nameVariable == null)
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」に対してはアノテーション「string name」は必須ですが、指定されませんでした。", typeName, variable.Description.Name));
            }
            string name = nameVariable.AsString().GetString();

            //Selfの場合はターゲットは自分自身となる
            if (name.ToLower().Equals("(self)"))
            {
                isSelf = true;
            }
            else
            {
            }
            //TODO (OffscreenOwner)がnameに指定されたときの対応
            EffectVariable itemVariable = EffectParseHelper.getAnnotation(variable, "item", "string");

            if (itemVariable != null)
            {
                itemName = itemVariable.AsString().GetString();
                switch (itemName.ToLower())
                {
                case "x":
                    target = TargetObject.X;
                    break;

                case "y":
                    target = TargetObject.Y;
                    break;

                case "z":
                    target = TargetObject.Z;
                    break;

                case "xyz":
                    target = TargetObject.XYZ;
                    break;

                case "rx":
                    target = TargetObject.Rx;
                    break;

                case "ry":
                    target = TargetObject.Ry;
                    break;

                case "rz":
                    target = TargetObject.Rz;
                    break;

                case "rxyz":
                    target = TargetObject.Rxyz;
                    break;

                case "si":
                    target = TargetObject.Si;
                    break;

                case "tr":
                    target = TargetObject.Tr;
                    break;

                default:
                    target = type == VariableType.Float ? TargetObject.FaceName : TargetObject.BoneName;
                    break;
                }
                if (NeedFloat.Contains(target) && type != VariableType.Float)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」にはアノテーション「string item=\"{2}\"」が適用されていますが、「{2}」の場合は「float {1}:CONTROLOBJECT」である必要があります。", typeName, variable.Description.Name, itemName));
                }
                if (NeedFloat3.Contains(target) && type != VariableType.Float3)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」にはアノテーション「string item=\"{2}\"」が適用されていますが、「{2}」の場合は「float3 {1}:CONTROLOBJECT」である必要があります。", typeName, variable.Description.Name, itemName));
                }
            }
            return(new ControlObjectSubscriber(type, itemName, name, target, isSelf));
        }
        /// <summary>
        /// テクスチャのアノテーション解釈に一般的に必要な項目を取得するメソッド
        /// </summary>
        /// <param name="variable">エフェクト変数</param>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="defaultFormat"></param>
        /// <param name="defaultViewPortRatio"></param>
        /// <param name="width">テクスチャの幅</param>
        /// <param name="height">テクスチャの高さ</param>
        /// <param name="depth">テクスチャの深さ(ない場合は-1)</param>
        /// <param name="mip">mipレベル</param>
        /// <param name="textureFormat">指定されているフォーマット</param>
        public static void 解析する(EffectVariable variable, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth, out int mip, out Format textureFormat, out Format viewFormat, out Format resourceFormat)
        {
            width          = -1;
            height         = -1;
            depth          = -1;
            mip            = 0;
            textureFormat  = defaultFormat;
            viewFormat     = defaultFormat;
            resourceFormat = defaultFormat;

            #region " int width = ... "
            //----------------
            EffectVariable rawWidthVal = EffectParseHelper.アノテーションを取得する(variable, "width", "int");
            if (rawWidthVal != null)
            {
                width = rawWidthVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " int height = ... "
            //----------------
            EffectVariable rawHeightVal = EffectParseHelper.アノテーションを取得する(variable, "height", "int");
            if (rawHeightVal != null)
            {
                height = rawHeightVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " int depth = ... "
            //----------------
            EffectVariable rawDepthVal = EffectParseHelper.アノテーションを取得する(variable, "depth", "int");
            if (rawDepthVal != null)
            {
                depth = rawDepthVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " float2 ViewportRatio = ... "
            //----------------
            EffectVariable rawViewportRatio = EffectParseHelper.アノテーションを取得する(variable, "viewportratio", "float2");
            if (rawViewportRatio != null)

            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShader例外(
                              string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。", variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    Vector4 rawRatio = rawViewportRatio.AsVector().GetFloatVector();
                    var     vp       = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];
                    width  = (int)(vp.Width * rawRatio.X);
                    height = (int)(vp.Height * rawRatio.Y);
                }
            }
            //----------------
            #endregion

            #region " uing2/uint3 Dimensions = ... "
            //----------------
            EffectVariable rawDimensions = EffectParseHelper.アノテーションを取得する(variable, "dimensions", "uint2/uint3");

            if (rawDimensions != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShader例外(
                              string.Format(
                                  "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                  variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    string typeName = rawDimensions.TypeInfo.Description.TypeName.ToLower();
                    if (typeName == "int2")
                    {
                        var rawDimension = rawDimensions.AsVector().GetIntVector();
                        width  = rawDimension.X;
                        height = rawDimension.Y;
                    }
                    else
                    {
                        var rawDimension = rawDimensions.AsVector().GetIntVector();
                        width  = rawDimension.X;
                        height = rawDimension.Y;
                        depth  = rawDimension.Z;
                    }
                }
            }
            //----------------
            #endregion

            #region "width, height チェック "
            //----------------
            if (width == -1 || height == -1)
            {
                if (defaultViewPortRatio != Vector2.Zero)
                {
                    var port = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];
                    width  = (int)(port.Width * defaultViewPortRatio.X);
                    height = (int)(port.Height * defaultViewPortRatio.Y);
                }
                else
                {
                    if (!isTextureSubscriber)
                    {
                        throw new InvalidMMEEffectShader例外(string.Format("width,heightのどちらかの指定は必須です。"));
                    }
                }
            }
            //----------------
            #endregion

            #region " int MipLevels = ... / int RawLevel = ... "
            //----------------
            EffectVariable rawMipLevel = EffectParseHelper.アノテーションを取得する(variable, "MipLevels", "int");
            EffectVariable rawLevel    = EffectParseHelper.アノテーションを取得する(variable, "levels", "int");

            if (rawMipLevel != null && rawLevel != null)
            {
                throw new InvalidMMEEffectShader例外(
                          string.Format("変数「{0} {1}」のミップマップレベルが重複して指定されています。「int Miplevels」、「int Levels」は片方しか指定できません。",
                                        variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
            }
            else if (rawMipLevel != null || rawLevel != null)
            {
                EffectVariable mipVal = rawMipLevel ?? rawLevel;
                mip = mipVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " string Format = ... "
            //----------------
            EffectVariable rawFormat = EffectParseHelper.アノテーションを取得する(variable, "format", "string");

            if (rawFormat != null)
            {
                string formatString = rawFormat.AsString().GetString();
                テクスチャフォーマットを返す(formatString, out textureFormat, out viewFormat, out resourceFormat);
            }
            //----------------
            #endregion
        }