本文整理汇总了C#中SharpDX.Direct3D9.Macro类的典型用法代码示例。如果您正苦于以下问题:C# Macro类的具体用法?C# Macro怎么用?C# Macro使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Macro类属于SharpDX.Direct3D9命名空间,在下文中一共展示了Macro类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EffectCompiler
/// <summary>
/// Initializes a new instance of the <see cref="EffectCompiler"/> class.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="defines">The defines.</param>
/// <param name="includeFile">The include file.</param>
/// <param name="flags">The flags.</param>
/// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const char* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[In] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
public EffectCompiler(string data, Macro[] defines, Include includeFile, ShaderFlags flags) : base(IntPtr.Zero)
{
IntPtr dataPtr = Marshal.StringToHGlobalAnsi(data);
try
{
CreateEffectCompiler(dataPtr, data.Length, defines, includeFile, flags, this);
}
finally
{
Marshal.FreeHGlobal(dataPtr);
}
}
示例2: Initialize
public static void Initialize(ref Device device, ref RenderForm form)
{
Macro macro = new Macro("nblights", 2.ToString());
Basic_Effect = Effect.FromFile(device, "Effect.fx", new Macro[] { macro }, null, "", ShaderFlags.OptimizationLevel3);
Basic_Effect.Technique = Basic_Effect.GetTechnique(0);
Basic_Effect.SetValue("AmbientLightColor", new Vector4(0f, 0f, 0f, 0f));
Matrix proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 0.1f, 7000.0f);
}
示例3: CreateEffectCompiler
private static void CreateEffectCompiler(IntPtr data, int length, Macro[] defines, Include includeFile, ShaderFlags flags, EffectCompiler instance)
{
Blob blobForErrors = null;
try
{
D3DX9.CreateEffectCompiler(data, length, defines, IncludeShadow.ToIntPtr(includeFile), (int)flags, instance, out blobForErrors);
}
catch (SharpDXException ex)
{
if (blobForErrors != null)
throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
throw;
}
}
示例4: FromMemory
/// <summary>
/// Creates an effect compiler from a memory buffer containing an ASCII effect description .
/// </summary>
/// <param name="data">The data.</param>
/// <param name="defines">The defines.</param>
/// <param name="includeFile">The include file.</param>
/// <param name="flags">The flags.</param>
/// <returns>
/// An instance of <see cref="EffectCompiler"/>
/// </returns>
/// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
public static EffectCompiler FromMemory(byte[] data, Macro[] defines, Include includeFile, ShaderFlags flags)
{
unsafe
{
var compiler = new EffectCompiler(IntPtr.Zero);
fixed (void* pData = data)
CreateEffectCompiler((IntPtr)pData, data.Length, defines, includeFile, flags, compiler);
return compiler;
}
}
示例5: LoadFromSource
protected override void LoadFromSource()
{
// Populate preprocessor defines
var defines = new List<D3D9.Macro>();
if ( !string.IsNullOrEmpty( PreprocessorDefines ) )
{
var tmp = PreprocessorDefines.Split( ' ', ',', ';' );
foreach ( string define in tmp )
{
var macro = new D3D9.Macro();
if ( define.Contains( "=" ) )
{
var split = define.Split( '=' );
macro.Name = split[ 0 ];
macro.Definition = split[ 1 ];
}
else
{
macro.Name = define;
macro.Definition = "1";
}
if ( !string.IsNullOrEmpty( macro.Name ) )
{
defines.Add( macro );
}
}
}
// Populate compile flags
var compileFlags = UseColumnMajorMatrices
? D3D9.ShaderFlags.PackMatrixColumnMajor
: D3D9.ShaderFlags.PackMatrixRowMajor;
#if DEBUG
compileFlags |= D3D9.ShaderFlags.Debug;
#endif
switch ( OptimizationLevel )
{
case OptimizationLevel.Default:
compileFlags |= D3D9.ShaderFlags.OptimizationLevel1;
break;
case OptimizationLevel.None:
compileFlags |= D3D9.ShaderFlags.SkipOptimization;
break;
case OptimizationLevel.LevelZero:
compileFlags |= D3D9.ShaderFlags.OptimizationLevel0;
break;
case OptimizationLevel.LevelOne:
compileFlags |= D3D9.ShaderFlags.OptimizationLevel1;
break;
case OptimizationLevel.LevelTwo:
compileFlags |= D3D9.ShaderFlags.OptimizationLevel2;
break;
case OptimizationLevel.LevelThree:
compileFlags |= D3D9.ShaderFlags.OptimizationLevel3;
break;
}
var parseFlags = compileFlags;
compileFlags ^= UseColumnMajorMatrices ? D3D9.ShaderFlags.PackMatrixColumnMajor : D3D9.ShaderFlags.PackMatrixRowMajor;
// include handler
var includeHandler = new HLSLIncludeHandler( this );
// Compile & assemble into microcode
var effectCompiler = new D3D9.EffectCompiler( Source, defines.ToArray(), includeHandler, parseFlags );
var effectHandle = new D3D9.EffectHandle( EntryPoint );
var errors = string.Empty;
try
{
MicroCode = effectCompiler.CompileShader( effectHandle, Target, compileFlags, out this.constTable );
}
catch ( DX.SharpDXException ex )
{
if ( ex is DX.CompilationException )
{
errors = ex.Message;
}
// check for errors
if ( !string.IsNullOrEmpty( errors ) )
{
if ( MicroCode != null )
{
if ( LogManager.Instance != null )
{
LogManager.Instance.Write( "HLSL: Warnings while compiling high level shader {0}:\n{1}", Name, errors );
}
}
else
{
throw new AxiomException( "HLSL: Unable to compile high level shader {0}:\n{1}", Name, errors );
}
//.........这里部分代码省略.........
示例6: PrepareMacros
internal static Macro[] PrepareMacros(Macro[] macros)
{
if (macros == null)
return null;
if (macros.Length == 0)
return null;
if (macros[macros.Length - 1].Name == null && macros[macros.Length - 1].Definition == null)
return macros;
var macroArray = new Macro[macros.Length + 1];
Array.Copy(macros, macroArray, macros.Length);
macroArray[macros.Length] = new Macro(null, null);
return macroArray;
}
示例7: FromString
/// <summary>
/// Compiles an effect from a string.
/// </summary>
/// <param name="device">The device.</param>
/// <param name="sourceData">The source data.</param>
/// <param name="preprocessorDefines">The preprocessor defines.</param>
/// <param name="includeFile">The include file.</param>
/// <param name="skipConstants">The skip constants.</param>
/// <param name="flags">The flags.</param>
/// <returns>
/// An <see cref="Effect"/>
/// </returns>
/// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
public static Effect FromString(Device device, string sourceData, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags)
{
return FromString(device, sourceData, preprocessorDefines, includeFile, skipConstants, flags, null);
}
示例8: FromMemory
/// <summary>
/// Compiles an effect from a memory buffer.
/// </summary>
/// <param name="device">The device.</param>
/// <param name="memory">The buffer.</param>
/// <param name="preprocessorDefines">The preprocessor defines.</param>
/// <param name="includeFile">The include file.</param>
/// <param name="skipConstants">The skip constants.</param>
/// <param name="flags">The flags.</param>
/// <param name="pool">The pool.</param>
/// <returns>An <see cref="Effect"/></returns>
/// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
public static Effect FromMemory(Device device, byte[] memory, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags, EffectPool pool)
{
unsafe
{
Effect effect = null;
Blob blobForErrors = null;
try
{
fixed (void* pData = memory)
D3DX9.CreateEffectEx(
device,
(IntPtr)pData,
memory.Length,
PrepareMacros(preprocessorDefines),
IncludeShadow.ToIntPtr(includeFile),
skipConstants,
(int)flags,
pool,
out effect,
out blobForErrors);
}
catch (SharpDXException ex)
{
if (blobForErrors != null)
throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
throw;
}
return effect;
}
}
示例9: CompileFromFile
/// <summary>
/// Compiles a shader or effect from a file on disk.
/// </summary>
/// <param name="fileName">The name of the source file to compile.</param>
/// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
/// <param name="profile">The shader target or set of shader features to compile against.</param>
/// <param name="shaderFlags">Shader compilation options.</param>
/// <param name="defines">A set of macros to define during compilation.</param>
/// <param name="include">An interface for handling include files.</param>
/// <returns>
/// The compiled shader bytecode, or <c>null</c> if the method fails.
/// </returns>
/// <unmanaged>HRESULT D3DXCompileShader([In] const char* pSrcData,[In] unsigned int SrcDataLen,[In] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pFunctionName,[In] const char* pProfile,[In] unsigned int Flags,[In] ID3DXBuffer** ppShader,[In] ID3DXBuffer** ppErrorMsgs,[In] ID3DXConstantTable** ppConstantTable)</unmanaged>
public static CompilationResult CompileFromFile(string fileName, string entryPoint, string profile, ShaderFlags shaderFlags = ShaderFlags.None, Macro[] defines = null, Include include = null)
{
if (fileName == null)
{
throw new ArgumentNullException("fileName");
}
if (profile == null)
{
throw new ArgumentNullException("profile");
}
if (!File.Exists(fileName))
{
throw new FileNotFoundException("Could not open the shader or effect file.", fileName);
}
return Compile(File.ReadAllText(fileName), entryPoint, profile, shaderFlags, PrepareMacros(defines), include);
}
示例10: Compile
/// <summary>
/// Compiles the provided shader or effect source.
/// </summary>
/// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
/// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
/// <param name="profile">The shader target or set of shader features to compile against.</param>
/// <param name="shaderFlags">Shader compilation options.</param>
/// <param name="defines">A set of macros to define during compilation.</param>
/// <param name="include">An interface for handling include files.</param>
/// <returns>
/// The compiled shader bytecode, or <c>null</c> if the method fails.
/// </returns>
/// <unmanaged>HRESULT D3DXCompileShader([In] const char* pSrcData,[In] unsigned int SrcDataLen,[In] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pFunctionName,[In] const char* pProfile,[In] unsigned int Flags,[In] ID3DXBuffer** ppShader,[In] ID3DXBuffer** ppErrorMsgs,[In] ID3DXConstantTable** ppConstantTable)</unmanaged>
public static CompilationResult Compile(string shaderSource, string entryPoint, string profile, ShaderFlags shaderFlags, Macro[] defines, Include include)
{
if (string.IsNullOrEmpty(shaderSource))
{
throw new ArgumentNullException("shaderSource");
}
return Compile(Encoding.ASCII.GetBytes(shaderSource), entryPoint, profile, shaderFlags, defines, include);
}
示例11: AssembleFromFile
/// <summary>
/// Assembles a shader from file.
/// </summary>
/// <param name="fileName">Name of the shader file.</param>
/// <param name="defines">Macro definitions.</param>
/// <param name="includeFile">An <see cref="SharpDX.Direct3D9.Include"/> interface to use for handling #include directives.</param>
/// <param name="flags">Compilation options.</param>
/// <returns>
/// A <see cref="SharpDX.Direct3D9.CompilationResult"/> object representing the raw shader stream.
/// </returns>
public static CompilationResult AssembleFromFile(string fileName, Macro[] defines, Include includeFile, ShaderFlags flags)
{
return Assemble(File.ReadAllText(fileName), defines, includeFile, flags);
}
示例12: Assemble
/// <summary>
/// Assembles a shader from the given source data.
/// </summary>
/// <param name="sourceData">The source shader data.</param>
/// <param name="defines">Macro definitions.</param>
/// <param name="includeFile">An <see cref="SharpDX.Direct3D9.Include" /> interface to use for handling #include directives.</param>
/// <param name="flags">Compilation options.</param>
/// <returns>A <see cref="SharpDX.Direct3D9.CompilationResult" /> object representing the raw shader stream.</returns>
/// <unmanaged>HRESULT D3DXAssembleShader([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[In] ID3DXBuffer** ppShader,[In] ID3DXBuffer** ppErrorMsgs)</unmanaged>
public static CompilationResult Assemble(byte[] sourceData, Macro[] defines, Include includeFile, ShaderFlags flags)
{
unsafe
{
var resultCode = Result.Ok;
Blob blobForCode = null;
Blob blobForErrors = null;
try
{
fixed (void* pData = sourceData)
D3DX9.AssembleShader(
(IntPtr)pData,
sourceData.Length,
PrepareMacros(defines),
IncludeShadow.ToIntPtr(includeFile),
(int)flags,
out blobForCode,
out blobForErrors);
}
catch (SharpDXException ex)
{
if (blobForErrors != null)
{
resultCode = ex.ResultCode;
if (Configuration.ThrowOnShaderCompileError)
throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
}
else
{
throw;
}
}
return new CompilationResult(blobForCode != null ? new ShaderBytecode(blobForCode) : null, resultCode, Utilities.BlobToString(blobForErrors));
}
}
示例13: FromFile
/// <summary>
/// Compiles an effect from a file.
/// </summary>
/// <param name="device">The device.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="preprocessorDefines">The preprocessor defines.</param>
/// <param name="includeFile">The include file.</param>
/// <param name="skipConstants">The skip constants.</param>
/// <param name="flags">The flags.</param>
/// <param name="pool">The pool.</param>
/// <returns>
/// An <see cref="Effect"/>
/// </returns>
/// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
public static Effect FromFile(Device device, string fileName, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags, EffectPool pool)
{
return FromString(device, File.ReadAllText(fileName), preprocessorDefines, includeFile, skipConstants, flags, pool);
}
示例14: FromStream
/// <summary>
/// Compiles an effect from a stream.
/// </summary>
/// <param name="device">The device.</param>
/// <param name="stream">The stream.</param>
/// <param name="preprocessorDefines">The preprocessor defines.</param>
/// <param name="includeFile">The include file.</param>
/// <param name="skipConstants">The skip constants.</param>
/// <param name="flags">The flags.</param>
/// <param name="pool">The pool.</param>
/// <returns>An <see cref="Effect"/></returns>
/// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
public static Effect FromStream(Device device, Stream stream, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags, EffectPool pool)
{
unsafe
{
Effect effect = null;
Blob blobForErrors = null;
try
{
if (stream is DataStream)
{
D3DX9.CreateEffectEx(
device,
((DataStream)stream).PositionPointer,
(int)(stream.Length - stream.Position),
PrepareMacros(preprocessorDefines),
IncludeShadow.ToIntPtr(includeFile),
skipConstants,
(int)flags,
pool,
out effect,
out blobForErrors);
}
else
{
var data = Utilities.ReadStream(stream);
fixed (void* pData = data)
D3DX9.CreateEffectEx(
device,
(IntPtr)pData,
data.Length,
PrepareMacros(preprocessorDefines),
IncludeShadow.ToIntPtr(includeFile),
skipConstants,
(int)flags,
pool,
out effect,
out blobForErrors);
}
stream.Position = stream.Length;
}
catch (SharpDXException ex)
{
if (blobForErrors != null)
throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
throw;
}
return effect;
}
}
示例15: Preprocess
/// <summary>
/// Preprocesses the provided shader or effect source.
/// </summary>
/// <param name = "shaderSource">An array of bytes containing the raw source of the shader or effect to preprocess.</param>
/// <param name = "defines">A set of macros to define during preprocessing.</param>
/// <param name = "include">An interface for handling include files.</param>
/// <returns>The preprocessed shader source.</returns>
/// <unmanaged>HRESULT D3DXPreprocessShader([In] const void* pSrcData,[In] unsigned int SrcDataSize,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] ID3DXBuffer** ppShaderText,[In] ID3DXBuffer** ppErrorMsgs)</unmanaged>
public static string Preprocess(byte[] shaderSource, Macro[] defines = null, Include include = null)
{
string errors = null;
return Preprocess(shaderSource, defines, include, out errors);
}