本文整理汇总了C#中SharpDX.Direct3D11.Device类的典型用法代码示例。如果您正苦于以下问题:C# Device类的具体用法?C# Device怎么用?C# Device使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Device类属于SharpDX.Direct3D11命名空间,在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Terrain
public Terrain(Device device, String texture, int pitch, Renderer renderer)
{
HeightMap = new System.Drawing.Bitmap(@"Data/Textures/"+texture);
WaterShader = new WaterShader(device);
TerrainShader = new TerrainShader(device);
_width = HeightMap.Width-1;
_height = HeightMap.Height-1;
_pitch = pitch;
_terrainTextures = new ShaderResourceView[4];
_terrainTextures[0] = new Texture(device, "Sand.png").TextureResource;
_terrainTextures[1] = new Texture(device, "Grass.png").TextureResource;
_terrainTextures[2] = new Texture(device, "Ground.png").TextureResource;
_terrainTextures[3] = new Texture(device, "Rock.png").TextureResource;
_reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
_refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f);
_noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000);
_reflectionTexture = new RenderTexture(device, renderer.ScreenSize);
_refractionTexture = new RenderTexture(device, renderer.ScreenSize);
_renderer = renderer;
_bitmap = new Bitmap(device,_refractionTexture.ShaderResourceView,renderer.ScreenSize, new Vector2I(100, 100), 0);
_bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0);
_bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0);
_bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120);
_bumpMap = _renderer.TextureManager.Create("OceanWater.png");
_skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png"));
BuildBuffers(device);
WaveTranslation = new Vector2(0,0);
}
示例2: GraphicsResource
/// <summary>
/// Creates a new graphics resource.
/// </summary>
/// <param name="device">The graphics device to use.</param>
/// <param name="dimensions">The resource dimensions.</param>
/// <param name="format">The resource's DXGI format.</param>
/// <param name="renderTargetView">Whether to bind as RTV.</param>
/// <param name="shaderResourceView">Whether to bind as SRV.</param>
/// <param name="hasMipMaps">Whether to enable mip-maps for this texture.</param>
public GraphicsResource(Device device, Size dimensions, Format format, Boolean renderTargetView = true, Boolean shaderResourceView = true, Boolean hasMipMaps = false)
{
if ((!renderTargetView) && (!shaderResourceView))
throw new ArgumentException("The requested resource cannot be bound at all to the pipeline.");
if ((hasMipMaps) && ((!renderTargetView) || (!shaderResourceView)))
throw new ArgumentException("A resource with mipmaps must be bound as both input and output.");
BindFlags bindFlags = (renderTargetView ? BindFlags.RenderTarget : 0) | (shaderResourceView ? BindFlags.ShaderResource : 0);
ResourceOptionFlags optionFlags = (hasMipMaps ? ResourceOptionFlags.GenerateMipMaps : 0);
int mipLevels = (hasMipMaps ? MipLevels(dimensions) : 1);
Resource = new Texture2D(device, new Texture2DDescription()
{
Format = format,
BindFlags = bindFlags,
Width = dimensions.Width,
Height = dimensions.Height,
ArraySize = 1,
MipLevels = mipLevels,
OptionFlags = optionFlags,
Usage = ResourceUsage.Default,
CpuAccessFlags = CpuAccessFlags.None,
SampleDescription = new SampleDescription(1, 0),
});
RTV = ( renderTargetView ? new RenderTargetView(device, Resource) : null);
SRV = (shaderResourceView ? new ShaderResourceView(device, Resource) : null);
}
示例3: IsDx11Supported
public static bool IsDx11Supported()
{
var factory = GetFactory();
FeatureLevel[] featureLevels = {FeatureLevel.Level_11_0};
for (int i = 0; i < factory.Adapters.Length; i++)
{
var adapter = factory.Adapters[i];
Device adapterTestDevice = null;
try
{
adapterTestDevice = new Device(adapter, DeviceCreationFlags.None, featureLevels);
}
catch (Exception)
{
continue;
}
UInt64 vram;
UInt64 svram;
GetRamSizes(out vram, adapter, out svram);
// microsoft software renderer allocates 256MB shared memory, cpu integrated graphic on notebooks has 0 preallocated, all shared
return (vram > 500000000 || svram > 500000000);
}
return false;
}
示例4: Initialize
public void Initialize()
{
DestroyResources();
var flags = DeviceCreationFlags.BgraSupport;
#if DEBUG
flags |= DeviceCreationFlags.Debug;
#endif
var featureLevels = new[]
{
FeatureLevel.Level_11_1,
FeatureLevel.Level_11_0
};
using(var device = new Device(DriverType.Hardware, flags, featureLevels))
{
Device = device.QueryInterface<Device1>();
Context = device.ImmediateContext.QueryInterface<DeviceContext1>();
}
IsInitialized = true;
// todo: Reinitialize all dependent resources by having them hook this event
var handler = Initialized;
if(handler != null)
handler();
}
示例5: CompositionEngine
// ReSharper restore InconsistentNaming
static CompositionEngine()
{
_wicFactory = new SharpDX.WIC.ImagingFactory();
_dWriteFactory = new SharpDX.DirectWrite.Factory();
var d3DDevice = new SharpDX.Direct3D11.Device(
DriverType.Hardware,
DeviceCreationFlags.BgraSupport
#if DEBUG
| DeviceCreationFlags.Debug
#endif
,
FeatureLevel.Level_11_1,
FeatureLevel.Level_11_0,
FeatureLevel.Level_10_1,
FeatureLevel.Level_10_0,
FeatureLevel.Level_9_3,
FeatureLevel.Level_9_2,
FeatureLevel.Level_9_1
);
var dxgiDevice = ComObject.As<SharpDX.DXGI.Device>(d3DDevice.NativePointer);
//new SharpDX.DXGI.Device2(d3DDevice.NativePointer);
var d2DDevice = new SharpDX.Direct2D1.Device(dxgiDevice);
_d2DFactory = d2DDevice.Factory;
_d2DDeviceContext = new SharpDX.Direct2D1.DeviceContext(d2DDevice, D2D.DeviceContextOptions.None);
_d2DDeviceContext.DotsPerInch = new Size2F(LogicalDpi, LogicalDpi);
}
示例6: FbxMesh
public FbxMesh(AssimpSharp.Mesh mesh, AssimpSharp.Material mat, Device device, string path)
{
this.device = device;
this.path = path;
LoadMesh(mesh);
LoadMaterial(mat);
}
示例7: MeshFactory
public MeshFactory(SharpDX11Graphics graphics)
{
this.device = graphics.Device;
this.inputAssembler = device.ImmediateContext.InputAssembler;
this.demo = graphics.Demo;
instanceDataDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
};
InputElement[] elements = new InputElement[]
{
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
new InputElement("WORLD", 0, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1),
new InputElement("WORLD", 1, Format.R32G32B32A32_Float, 16, 1, InputClassification.PerInstanceData, 1),
new InputElement("WORLD", 2, Format.R32G32B32A32_Float, 32, 1, InputClassification.PerInstanceData, 1),
new InputElement("WORLD", 3, Format.R32G32B32A32_Float, 48, 1, InputClassification.PerInstanceData, 1),
new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 64, 1, InputClassification.PerInstanceData, 1)
};
inputLayout = new InputLayout(device, graphics.GetEffectPass().Description.Signature, elements);
groundColor = ColorToUint(Color.Green);
activeColor = ColorToUint(Color.Orange);
passiveColor = ColorToUint(Color.OrangeRed);
softBodyColor = ColorToUint(Color.LightBlue);
}
示例8: Form1
public Form1(Factory factory, SharpDX.Direct3D11.Device device, Object renderLock)
{
InitializeComponent();
this.factory = factory;
this.device = device;
this.renderLock = renderLock;
}
示例9: DepthBuffer
public DepthBuffer(Device device, int width, int height)
{
try
{
_device = device;
_depthBuffer = new Texture2D(_device, new Texture2DDescription
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
_depthView = new DepthStencilView(device, _depthBuffer);
}
catch
{
Dispose();
throw;
}
}
示例10: RenderTarget
public RenderTarget(Device device, int width, int height, int sampleCount, int sampleQuality, Format format)
: this()
{
Texture = _disposer.Add(new Texture2D(device, new Texture2DDescription
{
Format = format,
Width = width,
Height = height,
ArraySize = 1,
MipLevels = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
SampleDescription = new SampleDescription(sampleCount, sampleQuality),
}));
RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture, new RenderTargetViewDescription
{
Format = format,
Dimension = RenderTargetViewDimension.Texture2DMultisampled,
//MipSlice = 0,
}));
ShaderResourceView = _disposer.Add(new ShaderResourceView(device, Texture));
Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f);
}
示例11: ProjectorFormLoader
public ProjectorFormLoader(String path)
{
Forms = new List<ProjectorForm>();
// load ensemble.xml
string directory = Path.GetDirectoryName(path);
var ensemble = ProjectorCameraEnsemble.FromFile(path);
// create d3d device
var factory = new Factory1();
var adapter = factory.Adapters[0];
// When using DeviceCreationFlags.Debug on Windows 10, ensure that "Graphics Tools" are installed via Settings/System/Apps & features/Manage optional features.
// Also, when debugging in VS, "Enable native code debugging" must be selected on the project.
var device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.None);
Object renderLock = new Object();
// create a form for each projector
foreach (var projector in ensemble.projectors) {
var form = new ProjectorForm(factory, device, renderLock, projector);
form.FullScreen = FULLSCREEN_ENABLED; // TODO: fix this so can be called after Show
form.Show();
Forms.Add(form);
}
}
示例12: Initialize
public bool Initialize(Device device, string heightMapFileName, string textureFileName)
{
// Set the number of vertices per quad (2 triangles)
NumberOfVerticesPerQuad = 6;
// Set the value of the topology
CurrentTopology = PrimitiveTopology.TriangleList;
// How many times the terrain texture will be repeated both over the width and length of the terrain.
TextureRepeat = 8;
// Load the height map for the terrain
if (!LoadHeightMapFilename(heightMapFileName))
return false;
// Normalize the height of the height map
NormalizeHeightMap();
// Calculate the normals for the terrain data.
if (!CalculateNormals())
return false;
// Calculate the texture coordinates.
CalculateTextureCoordinates();
// Load the texture for this model.
if (!LoadTexture(device, textureFileName))
return false;
// Initialize the vertex and index buffer.
if (!InitializeBuffers(device))
return false;
return true;
}
示例13: PhysicsDebugDraw
public PhysicsDebugDraw(DeviceManager manager)
{
device = manager.Direct3DDevice;
inputAssembler = device.ImmediateContext.InputAssembler;
lineArray = new PositionColored[0];
using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "VSMain", "vs_5_0"))
{
vertexShader = new VertexShader(device, bc);
InputElement[] elements = new InputElement[]
{
new InputElement("SV_POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
};
inputLayout = new InputLayout(device, bc, elements);
}
vertexBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.Write
};
vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);
using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "PSMain", "ps_5_0"))
pixelShader = new PixelShader(device, bc);
}
示例14: TextureShader
public TextureShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TextureVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TexturePixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.PositionTexture.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
// Create a texture sampler state description.
var samplerDesc = new SamplerStateDescription
{
Filter = Filter.Anisotropic,
AddressU = TextureAddressMode.Mirror,
AddressV = TextureAddressMode.Mirror,
AddressW = TextureAddressMode.Mirror,
MipLodBias = 0,
MaximumAnisotropy = 16,
ComparisonFunction = Comparison.Always,
BorderColor = new Color4(1, 1, 1, 1),
MinimumLod = 0,
MaximumLod = 0
};
// Create the texture sampler state.
SamplerState = new SamplerState(device, samplerDesc);
}
示例15: Copy
/// <summary>
/// Copies the content of the specified texture.
/// </summary>
/// <param name="device">The Direct3D 11 device.</param>
/// <param name="source">The source texture.</param>
/// <param name="target">The target texture.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="device"/>, <paramref name="source"/> or <paramref name="target"/> is
/// <see langword="null"/>.
/// </exception>
public static void Copy(Device device, Texture2D source, Texture2D target)
{
if (device == null)
throw new ArgumentNullException("device");
if (source == null)
throw new ArgumentNullException("source");
if (target == null)
throw new ArgumentNullException("target");
int sourceWidth = source.Description.Width;
int sourceHeight = source.Description.Height;
int targetWidth = target.Description.Width;
int targetHeight = target.Description.Height;
if (sourceWidth == targetWidth && sourceHeight == targetHeight)
{
device.ImmediateContext.CopyResource(source, target);
}
else
{
int width = Math.Min(sourceWidth, targetWidth);
int height = Math.Min(sourceHeight, targetHeight);
var region = new ResourceRegion(0, 0, 0, width, height, 1);
device.ImmediateContext.CopySubresourceRegion(source, 0, region, target, 0);
}
}