本文整理汇总了C#中SharpDX.Direct3D9.Device类的典型用法代码示例。如果您正苦于以下问题:C# Device类的具体用法?C# Device怎么用?C# Device使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Device类属于SharpDX.Direct3D9命名空间,在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialise
public bool Initialise(Device device)
{
Debug.Assert(!_initialised);
if (_initialising)
return false;
_initialising = true;
try
{
_device = device;
_sprite = ToDispose(new Sprite(_device));
// Initialise any resources required for overlay elements
IntialiseElementResources();
_initialised = true;
return true;
}
finally
{
_initialising = false;
}
}
示例2: FromScene
public static Model FromScene(Scene scene, Device device)
{
VertexDeclaration vertexDeclaration = new VertexDeclaration(device,
VertexPositionNormalTexture.VertexElements);
Model result = new Model(scene, device, vertexDeclaration);
foreach (Mesh mesh in scene.Meshes.Where(x => x.Positions.Any()))
{
VertexBuffer vertexBuffer = new VertexBuffer(device,
mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
Usage.WriteOnly, VertexFormat.None, Pool.Default);
DataStream vertexDataStream = vertexBuffer.Lock(0,
mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
LockFlags.None);
VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[mesh.Positions.Count];
for (int i = 0; i < vertices.Length; ++i)
vertices[i] = new VertexPositionNormalTexture(mesh.Positions[i],
(mesh.Normals.Count > i) ? mesh.Normals[i] : Vector3D.Zero,
(mesh.TextureCoordinates.Count > i) ? mesh.TextureCoordinates[i].Xy : Point2D.Zero);
vertexDataStream.WriteRange(vertices);
vertexBuffer.Unlock();
IndexBuffer indexBuffer = new IndexBuffer(device, mesh.Indices.Count * sizeof(int),
Usage.WriteOnly, Pool.Default, false);
DataStream indexDataStream = indexBuffer.Lock(0, mesh.Indices.Count * sizeof(int), LockFlags.None);
indexDataStream.WriteRange(mesh.Indices.ToArray());
indexBuffer.Unlock();
ModelMesh modelMesh = new ModelMesh(mesh, device, vertexBuffer,
mesh.Positions.Count, indexBuffer, mesh.PrimitiveCount,
Matrix3D.Identity, mesh.Material);
result.Meshes.Add(modelMesh);
}
return result;
}
示例3: Generate
unsafe static Tuple<CUDADevice, IntPtr> Generate(D3D9Device d3d9Device)
{
var cuContext = IntPtr.Zero;
var cuDevice = -1;
CUDAInterop.cuSafeCall(CUDAInterop.cuD3D9CtxCreate(&cuContext, &cuDevice, 0u, d3d9Device.NativePointer));
return (new Tuple<CUDADevice, IntPtr>(CUDADevice.DeviceDict[cuDevice], cuContext));
}
示例4: RecursiveSetViewportImage
internal void RecursiveSetViewportImage(ViewportImage viewportImage)
{
if (viewportImage == null)
{
this.DisposeDisposables();
this.viewportImage = null;
this.graphicsDevice = null;
this.layer2D = null;
Children.viewportImage = null;
}
else
{
this.graphicsDevice = viewportImage.GraphicsDevice;
this.layer2D = viewportImage.Layer2D;
OnViewportImageChanged(viewportImage);
BindToViewportImage();
Children.viewportImage = viewportImage;
this.RecreateDisposables();
}
foreach (Model3D model in this.Children)
{
model.RecursiveSetViewportImage(viewportImage);
}
// TODO Set target on all children, checking for maximum depth or
// circular dependencies
}
示例5: SpriteBatch
public SpriteBatch(Device d, ContentManager c)
{
Device = d;
cubeVert = new VertexBuffer(Device, 4 * 28, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
cubeVert.Lock(0, 0, LockFlags.None).WriteRange(new[]
{
new VertexPositionTextureColor() { Color = Color.White.ToArgb(), Position = new Vector4f(0, 0, 0.0f, 1.0f), TexCoord = new Vector2f(0.0f, 1.0f) },
new VertexPositionTextureColor() { Color = Color.White.ToArgb(), Position = new Vector4f(0, 1, 0.0f, 1.0f), TexCoord = new Vector2f(0.0f, 0.0f) },
new VertexPositionTextureColor() { Color = Color.White.ToArgb(), Position = new Vector4f(1, 0, 0.0f, 1.0f), TexCoord = new Vector2f(1.0f, 1.0f) },
new VertexPositionTextureColor() { Color = Color.White.ToArgb(), Position = new Vector4f(1, 1, 0.0f, 1.0f), TexCoord = new Vector2f(1.0f, 0.0f) }
});
cubeVert.Unlock();
var cubeElems = new[]
{
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 16, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
new VertexElement(0, 24, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
cubeDecl = new VertexDeclaration(Device, cubeElems);
renderEffect = c.LoadString<Content.Effect>("float4 c;Texture b;sampler s=sampler_state{texture=<b>;magfilter=LINEAR;minfilter=LINEAR;mipfilter=LINEAR;AddressU=wrap;AddressV=wrap;};float4 f(float2 t:TEXCOORD0):COLOR{return tex2D(s, t) * c;}technique t{pass p{PixelShader = compile ps_2_0 f();}}");
}
示例6: GBuffer
public GBuffer(IKernel kernel)
{
IDeviceProvider provider = kernel.Get<IDeviceProvider>();
_device = provider.Device;
_form = provider.RenderForm;
}
示例7: Render
public void Render(Device device, float w, float h, float scale)
{
if (_handle != IntPtr.Zero)
{
AnimatedModel_Render(_handle, device.NativePointer, w, h, scale);
}
}
示例8: Main
static void Main()
{
var form = new RenderForm("SlimDX2 - MiniTri Direct3D9 Sample");
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(form.ClientSize.Width,form.ClientSize.Height));
var vertices = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new Vertex() { Color = Color.Red, Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Blue, Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Green, Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) }
});
vertices.Unlock();
var vertexElems = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexDecl = new VertexDeclaration(device, vertexElems);
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.BeginScene();
device.SetStreamSource(0, vertices, 0, 20);
device.VertexDeclaration = vertexDecl;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.EndScene();
device.Present();
});
}
示例9: Render
public void Render(Device device, float w, float h, float xTrans, float yTrans, float scale)
{
ParticleSystem_SetObjPos(ScreenPosition.X, ScreenPosition.Y);
ParticleSystem_SetPos(_handle, ScreenPosition.X, ScreenPosition.Y);
ParticleSystem_Render(device.NativePointer, _handle, w, h, xTrans, yTrans, scale);
}
示例10: RenderVideo
public bool RenderVideo(Device device, Color background, string fileName)
{
ParticleSystem_SetObjPos(ScreenPosition.X, ScreenPosition.Y);
ParticleSystem_SetPos(_handle, ScreenPosition.X, ScreenPosition.Y);
return ParticleSystem_RenderVideo(device.NativePointer, _handle, background.ToArgb(), fileName, 60);
}
示例11: ModelMesh
internal ModelMesh(Mesh sourceMesh, Device device, VertexBuffer vertexBuffer, int numVertices,
IndexBuffer indexBuffer, int primitiveCount,
Matrix3D world, Material material)
{
SourceMesh = sourceMesh;
_device = device;
_vertexBuffer = vertexBuffer;
_numVertices = numVertices;
_indexBuffer = indexBuffer;
_primitiveCount = primitiveCount;
_effect = new SimpleEffect(device)
{
World = world,
AmbientLightColor = new ColorRgbF(0.1f, 0.1f, 0.1f),
DiffuseColor = material.DiffuseColor,
SpecularColor = material.SpecularColor,
SpecularPower = material.Shininess,
Alpha = material.Transparency
};
if (!string.IsNullOrEmpty(material.DiffuseTextureName))
_effect.DiffuseTexture = Texture.FromFile(device, material.DiffuseTextureName, Usage.None, Pool.Default);
_effect.CurrentTechnique = "RenderScene";
Opaque = (material.Transparency == 1.0f);
}
示例12: CreateFullScreenQuad
/// <summary>
/// Creates the VertexBuffer for the quad
/// </summary>
/// <param name="graphicsDevice">The GraphicsDevice to use</param>
public void CreateFullScreenQuad(Device graphicsDevice)
{
// Create a vertex buffer for the quad, and fill it in
m_vertexBuffer = new VertexBuffer(graphicsDevice, MyVertexFormatFullScreenQuad.Stride * 4, Usage.WriteOnly, VertexFormat.None, Pool.Default);
m_vertexBuffer.DebugName = "FullScreenQuad";
MyVertexFormatFullScreenQuad[] vbData = new MyVertexFormatFullScreenQuad[4];
// Upper right
vbData[0].Position = new Vector3(1, 1, 1);
vbData[0].TexCoordAndCornerIndex = new Vector3(1, 0, 1);
// Lower right
vbData[1].Position = new Vector3(1, -1, 1);
vbData[1].TexCoordAndCornerIndex = new Vector3(1, 1, 2);
// Upper left
vbData[2].Position = new Vector3(-1, 1, 1);
vbData[2].TexCoordAndCornerIndex = new Vector3(0, 0, 0);
// Lower left
vbData[3].Position = new Vector3(-1, -1, 1);
vbData[3].TexCoordAndCornerIndex = new Vector3(0, 1, 3);
m_vertexBuffer.SetData(vbData);
}
示例13: Poll
public Poll(Device device, float height)
{
_height = height;
Texture = Texture ?? Texture.FromFile(device, "Assets/Textures/poll.png");
TextureTop = TextureTop ?? Texture.FromFile(device, "Assets/Textures/poll_top.png");
_topFlagLocation = new Vector3(-0.5f, 0.25f + (height / 2 - 1.5f), 0);
_flag = Add(new Sprite(device, "flag", 1));
_flag.Translate(_topFlagLocation);
Add(new GameObject
{
new MeshRenderer
{
Mesh = new TexturedCube(device, 0.5f, 0.5f, 0.5f, DefaultUV, DefaultUV, DefaultUV, DefaultUV, DefaultUV, DefaultUV),
Material = new TextureMaterial(TextureTop, false)
}
}).Translate(0, 0.25f + (height / 2 - 0.5f), 0);
Add(new GameObject
{
new MeshRenderer
{
Mesh = new TexturedCube(device, 0.2f, height - 0.5f, 0.2f, DefaultUV, DefaultUV, DefaultUV, DefaultUV, DefaultUV, DefaultUV),
Material = new TextureMaterial(Texture, false)
}
}).Translate(0, -0.25f, 0);
Add(new Trigger(SlideDown, 0.5f, height, 0.5f, Vector3.Zero));
}
示例14: GetOrCreateDevice
private Device GetOrCreateDevice(IntPtr devicePointer)
{
if (this.Device == null)
this.Device = Device.FromPointer<Device>(devicePointer);
return this.Device;
}
示例15: BlurComponent
public BlurComponent(Device graphics, int size)
{
_graphics = graphics;
Dims = size;
Format = Format.A8R8G8B8;
_sampleOffsetsHoriz = new Vector4D[SampleCount];
_sampleOffsetsVert = new Vector4D[SampleCount];
_sampleWeightsHoriz = new float[SampleCount];
_sampleWeightsVert = new float[SampleCount];
int width = Dims - 5;
int height = Dims - 5;
SetBlurEffectParameters(1.0f / width, 0, ref _sampleOffsetsHoriz, ref _sampleWeightsHoriz);
SetBlurEffectParameters(0, 1.0f / height, ref _sampleOffsetsVert, ref _sampleWeightsVert);
_effect = new GaussianBlurEffect(_graphics);
OutputTexture = new Texture(_graphics, Dims, Dims, 1, Usage.RenderTarget, Format, Pool.Default);
_intermediateTexture = new Texture(_graphics, Dims, Dims, 1, Usage.RenderTarget, Format, Pool.Default);
_sprite = new Sprite(_graphics);
}