Пример #1
0
        public ShaderVariable(VideoCom video, string name, IntPtr vertexHandle, IntPtr pixelHandel, ShaderModelCom vertexModel, ShaderModelCom pixelModel)
        {
            Name = name;
            com = new ShaderVariableCom(video, vertexHandle, pixelHandel, vertexModel, pixelModel);

            valueArrayObject = new WeakReference(null);
            Apply = setNothing;
        }
Пример #2
0
        public ShaderModel(Shader shader, byte[] code, ShaderTypes shaderType)
                #endif
            : base(shader)
        {
            try
            {
                                #if WINRT || WP8
                this.shader = shader;
                                #endif
                var video = shader.FindParentOrSelfWithException <Video>();
                com = new ShaderModelCom();

                                #if WIN32
                string shaderLvl = "";
                switch (shaderVersion)
                {
                case ShaderVersions.HLSL_2_0: shaderLvl = "_4_0_level_9_1"; break;

                case ShaderVersions.HLSL_2_a: shaderLvl = "_4_0_level_9_2"; break;

                case ShaderVersions.HLSL_3_0: shaderLvl = "_4_0_level_9_3"; break;

                case ShaderVersions.HLSL_4_0: shaderLvl = "_4_0"; break;

                case ShaderVersions.HLSL_4_1: shaderLvl = "_4_1"; break;

                case ShaderVersions.HLSL_5_0: shaderLvl = "_5_0"; break;

                default: Debug.ThrowError("ShaderModel", "Unsuported ShaderVersion: " + shaderVersion); break;
                }

                string errorText;
                var    error = com.Init(video.com, code, code.Length, shaderType.ToString().ToLower() + shaderLvl, out errorText);
                                #else
                var error = com.Init
                            (
                    video.com, code, code.Length,
                    shaderType == ShaderTypes.VS ? shader.vsVariableBufferSize : shader.psVariableBufferSize,
                    shaderType == ShaderTypes.VS ? shader.vsResourceCount : shader.psResourceCount
                            );
                                #endif

                switch (error)
                {
                                        #if WIN32
                case ShaderModelErrors.CompileCode: Debug.ThrowError("ShaderModel", "Shader compiler error: " + errorText); break;
                                        #endif
                case ShaderModelErrors.VariableBuffer: Debug.ThrowError("ShaderModel", "Failed to create VariableBuffer"); break;

                case ShaderModelErrors.Reflect: Debug.ThrowError("ShaderModel", "Failed to Reflect the shader"); break;
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Пример #3
0
 public override void Dispose()
 {
     disposeChilderen();
     if (com != null)
     {
         com.Dispose();
         com = null;
     }
     base.Dispose();
 }
Пример #4
0
 public ShaderVariable(string name, ShaderModelCom vertexShader, ShaderModelCom pixelShader, int vertexOffset, int pixelOffset)
 {
     Name = name;
     com  = new ShaderVariableCom(vertexShader, pixelShader, vertexOffset, pixelOffset);
                 #if WP8
     this.vertexOffset = vertexOffset;
     this.pixelOffset  = pixelOffset;
     int vsPtr, psPtr;
     com.GetDataPtrs(out vsPtr, out psPtr);
     vertexBytes = new IntPtr(vsPtr);
     pixelBytes  = new IntPtr(psPtr);
                 #endif
 }
Пример #5
0
 public ShaderVariable(string name, ShaderModelCom vertexShader, ShaderModelCom pixelShader, int vertexOffset, int pixelOffset)
 {
     Name = name;
     com = new ShaderVariableCom(vertexShader, pixelShader, vertexOffset, pixelOffset);
     #if WP8
     this.vertexOffset = vertexOffset;
     this.pixelOffset = pixelOffset;
     int vsPtr, psPtr;
     com.GetDataPtrs(out vsPtr, out psPtr);
     vertexBytes = new IntPtr(vsPtr);
     pixelBytes = new IntPtr(psPtr);
     #endif
 }
Пример #6
0
		public ShaderModel(Shader shader, byte[] code, ShaderTypes shaderType)
		#endif
		: base(shader)
		{
			try
			{
				#if WINRT || WP8
				this.shader = shader;
				#endif
				var video = shader.FindParentOrSelfWithException<Video>();
				com = new ShaderModelCom();

				#if WIN32
				string shaderLvl = "";
				switch (shaderVersion)
				{
					case ShaderVersions.HLSL_2_0: shaderLvl = "_4_0_level_9_1"; break;
					case ShaderVersions.HLSL_2_a: shaderLvl = "_4_0_level_9_2"; break;
					case ShaderVersions.HLSL_3_0: shaderLvl = "_4_0_level_9_3"; break;
					case ShaderVersions.HLSL_4_0: shaderLvl = "_4_0"; break;
					case ShaderVersions.HLSL_4_1: shaderLvl = "_4_1"; break;
					case ShaderVersions.HLSL_5_0: shaderLvl = "_5_0"; break;
					default: Debug.ThrowError("ShaderModel", "Unsuported ShaderVersion: " + shaderVersion); break;
				}

				string errorText;
				var error = com.Init(video.com, code, code.Length, shaderType.ToString().ToLower() + shaderLvl, out errorText);
				#else
				var error = com.Init
				(
					video.com, code, code.Length,
					shaderType == ShaderTypes.VS ? shader.vsVariableBufferSize : shader.psVariableBufferSize,
					shaderType == ShaderTypes.VS ? shader.vsResourceCount : shader.psResourceCount
				);
				#endif

				switch (error)
				{
					#if WIN32
					case ShaderModelErrors.CompileCode: Debug.ThrowError("ShaderModel", "Shader compiler error: " + errorText); break;
					#endif
					case ShaderModelErrors.VariableBuffer: Debug.ThrowError("ShaderModel", "Failed to create VariableBuffer"); break;
					case ShaderModelErrors.Reflect: Debug.ThrowError("ShaderModel", "Failed to Reflect the shader"); break;
				}
			}
			catch (Exception e)
			{
				Dispose();
				throw e;
			}
		}
Пример #7
0
        public ShaderModel(IDisposableResource parent, string code, ShaderVersions shaderVersion, ShaderTypes shaderType)
            : base(parent)
        {
            try
            {
                var video = parent.FindParentOrSelfWithException <Video>();

                string shaderLvl = "";
                switch (shaderVersion)
                {
                case ShaderVersions.HLSL_2_0: shaderLvl = "_2_0"; break;

                case ShaderVersions.HLSL_2_a: shaderLvl = "_2_a"; break;

                case ShaderVersions.HLSL_3_0: shaderLvl = "_3_0"; break;

                default: Debug.ThrowError("ShaderModel", "Unsuported ShaderVersion: " + shaderVersion); break;
                }
                string shaderVersionType = shaderType.ToString().ToLower() + shaderLvl;

                com = new ShaderModelCom();
                var    codePtr = Marshal.StringToHGlobalAnsi(code);
                var    shaderVersionTypePtr = Marshal.StringToHGlobalAnsi(shaderVersionType);
                string errorText;
                var    error = com.Init(video.com, codePtr, code.Length, shaderVersionTypePtr, out errorText);
                if (codePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(codePtr);
                }
                if (shaderVersionTypePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(shaderVersionTypePtr);
                }

                switch (error)
                {
                case ShaderModelErrors.Compile: Debug.ThrowError("ShaderModel", string.Format("Failed to compile {0} shader: Errors: {1}", shaderType == ShaderTypes.VS ? "vs" : "ps", errorText)); break;
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Пример #8
0
 public ShaderResource(string name, VideoCom video, ShaderModelCom vertexShader, ShaderModelCom pixelShader, int vertexIndex, int pixelIndex)
 {
     Name = name;
     com  = new ShaderResourceCom(video, vertexShader, pixelShader, vertexIndex, pixelIndex);
 }
Пример #9
0
        public ShaderVariable(VideoCom video, string name, IntPtr vertexHandle, IntPtr pixelHandel, ShaderModelCom vertexModel, ShaderModelCom pixelModel)
        {
            Name = name;
            com  = new ShaderVariableCom(video, vertexHandle, pixelHandel, vertexModel, pixelModel);

            valueArrayObject = new WeakReference(null);
            Apply            = setNothing;
        }
Пример #10
0
 public ShaderResource(string name, VideoCom video, ShaderModelCom vertexShader, ShaderModelCom pixelShader, int vertexIndex, int pixelIndex)
 {
     Name = name;
     com = new ShaderResourceCom(video, vertexShader, pixelShader, vertexIndex, pixelIndex);
 }