本文整理汇总了C#中SharpDX.Direct3D11.BufferDescription类的典型用法代码示例。如果您正苦于以下问题:C# BufferDescription类的具体用法?C# BufferDescription怎么用?C# BufferDescription使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BufferDescription类属于SharpDX.Direct3D11命名空间,在下文中一共展示了BufferDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Buffer
public Buffer(BufferDescription description)
{
_description = description;
_flags = GetBufferFlagsFromDescription(description);
_nativeBuffer = new SharpDX.Direct3D11.Buffer(GraphicManager.Device, description);
}
示例2: FilterPixelShader
public FilterPixelShader(Device device, int imageWidth, int imageHeight, int constantBufferSize, string pixelShaderBytecodeFilename)
{
vertexShader = new VertexShader(device, new ShaderBytecode(File.ReadAllBytes("Content/FullScreenQuadVS.cso")));
pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes(pixelShaderBytecodeFilename)));
var rasterizerStateDesc = new RasterizerStateDescription()
{
CullMode = CullMode.None,
FillMode = FillMode.Solid,
IsDepthClipEnabled = false,
IsFrontCounterClockwise = true,
IsMultisampleEnabled = false,
};
rasterizerState = new RasterizerState(device, rasterizerStateDesc);
if (constantBufferSize > 0)
{
var constantBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.ConstantBuffer,
SizeInBytes = constantBufferSize,
CpuAccessFlags = CpuAccessFlags.Write,
StructureByteStride = 0,
OptionFlags = 0,
};
constantBuffer = new Buffer(device, constantBufferDesc);
}
viewport = new Viewport(0, 0, imageWidth, imageHeight); // TODO: get these dimensions
vertexBufferBinding = new VertexBufferBinding(null, 0, 0);
}
示例3: Init
internal void Init(string name, ref BufferDescription description, IntPtr? initData)
{
m_description = description;
m_elementCount = description.SizeInBytes / Math.Max(1, Description.StructureByteStride);
try
{
m_buffer = new Buffer(MyRender11.Device, initData ?? default(IntPtr), description)
{
DebugName = name,
};
}
catch (SharpDXException e)
{
MyRenderProxy.Log.WriteLine("Error during allocation of a directX buffer!");
LogStuff(e);
throw;
}
try
{
AfterBufferInit();
}
catch (SharpDXException e)
{
MyRenderProxy.Log.WriteLine("Error during creating a view or an unordered access to a directX buffer!");
LogStuff(e);
throw;
}
IsReleased = false;
}
示例4: InitializeInternal
protected override void InitializeInternal() {
base.InitializeInternal();
var device = D3DApp11.I.D3DDevice;
using (var r = CubeMapSRV.Resource) {
r.DebugName = "sky cubemap";
}
var sphere = GeometryGenerator.CreateSphere(_skySphereRadius, 30, 30);
var vertices = sphere.Vertices.Select(v => v.Position).ToArray();
var vbd = new BufferDescription(
VertPos.Stride * vertices.Length,
ResourceUsage.Immutable,
BindFlags.VertexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0
);
_vb = new Buffer(device, DataStream.Create(vertices, false, false), vbd);
_indexCount = sphere.Indices.Count;
var ibd = new BufferDescription(
_indexCount * sizeof(int),
ResourceUsage.Immutable,
BindFlags.IndexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0
);
_ib = new Buffer(device, DataStream.Create(sphere.Indices.ToArray(), false, false), ibd);
}
示例5: 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);
}
示例6: Init
public void Init()
{
{
BuildVertices();
var desc = new BufferDescription();
desc.BindFlags = BindFlags.VertexBuffer;
desc.Usage = ResourceUsage.Default;
desc.CpuAccessFlags = CpuAccessFlags.None;
desc.OptionFlags = ResourceOptionFlags.None;
desc.SizeInBytes = Utilities.SizeOf<LineVertex>() * vertices.Length;
desc.StructureByteStride = 0;
vertexBuffer = Buffer.Create(Device, vertices, desc);//new Buffer(Device, desc);
}
{
var passDesc = new MaterialPassDesc();
passDesc.ManualConstantBuffers = true;
passDesc.ShaderFile = InternalResources.SHADER_DEBUG_LINE;
passDesc.InputElements = new InputElement[]{
new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0),
new InputElement("COLOR", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 12, 0),
};
passDesc.RasteriazerStates.CullMode = CullMode.None;
passDesc.DepthStencilStates.DepthWriteMask = DepthWriteMask.Zero;
pass = new MaterialPass(Game.Instance.Device, passDesc, "Grid");
matrixBuffer = Material.CreateBuffer<Matrix>();
}
}
示例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: ProjectiveTexturingShader
public ProjectiveTexturingShader(Device device)
{
var shaderByteCode = new ShaderBytecode(File.ReadAllBytes("Content/DepthAndProjectiveTextureVS.cso"));
vertexShader = new VertexShader(device, shaderByteCode);
geometryShader = new GeometryShader(device, new ShaderBytecode(File.ReadAllBytes("Content/DepthAndColorGS.cso")));
pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes("Content/DepthAndColorPS.cso")));
// depth stencil state
var depthStencilStateDesc = new DepthStencilStateDescription()
{
IsDepthEnabled = true,
DepthWriteMask = DepthWriteMask.All,
DepthComparison = Comparison.LessEqual,
IsStencilEnabled = false,
};
depthStencilState = new DepthStencilState(device, depthStencilStateDesc);
// rasterizer states
var rasterizerStateDesc = new RasterizerStateDescription()
{
CullMode = CullMode.None,
FillMode = FillMode.Solid,
IsDepthClipEnabled = true,
IsFrontCounterClockwise = true,
IsMultisampleEnabled = true,
};
rasterizerState = new RasterizerState(device, rasterizerStateDesc);
// constant buffer
var constantBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.ConstantBuffer,
SizeInBytes = Constants.size,
CpuAccessFlags = CpuAccessFlags.Write,
StructureByteStride = 0,
OptionFlags = 0,
};
constantBuffer = new SharpDX.Direct3D11.Buffer(device, constantBufferDesc);
// user view sampler state
var colorSamplerStateDesc = new SamplerStateDescription()
{
Filter = Filter.MinMagMipLinear,
AddressU = TextureAddressMode.Border,
AddressV = TextureAddressMode.Border,
AddressW = TextureAddressMode.Border,
//BorderColor = new SharpDX.Color4(0.5f, 0.5f, 0.5f, 1.0f),
BorderColor = new SharpDX.Color4(0, 0, 0, 1.0f),
};
colorSamplerState = new SamplerState(device, colorSamplerStateDesc);
vertexInputLayout = new InputLayout(device, shaderByteCode.Data, new[]
{
new InputElement("SV_POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
});
}
示例9: LightShader
public LightShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "LightVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "LightPixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.PositionTextureNormal.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
var lightBufferDesc = new BufferDescription
{
Usage = ResourceUsage.Dynamic, // Updated each frame
SizeInBytes = Utilities.SizeOf<LightBuffer>(), // Contains three matrices
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
};
ConstantLightBuffer = new Buffer(device, lightBufferDesc);
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
var cameraBufferDesc = new BufferDescription
{
Usage = ResourceUsage.Dynamic, // Updated each frame
SizeInBytes = Utilities.SizeOf<CameraBuffer>(), // Contains three matrices
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
};
ConstantCameraBuffer = new Buffer(device, cameraBufferDesc);
// Create a texture sampler state description.
var samplerDesc = new SamplerStateDescription
{
Filter = Filter.Anisotropic,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
MipLodBias = 0,
MaximumAnisotropy = 16,
ComparisonFunction = Comparison.Always,
BorderColor = new Color4(0, 0, 0, 0),
MinimumLod = 0,
MaximumLod = 10
};
// Create the texture sampler state.
SamplerState = new SamplerState(device, samplerDesc);
}
示例10: SharpOutputBuffer
/// <summary>
/// Constructor
/// </summary>
/// <param name="device">Device</param>
/// <param name="size">Buffer size</param>
public SharpOutputBuffer(SharpDevice device, int size)
{
Device = device;
BufferDescription desc = new BufferDescription()
{
SizeInBytes = size,
BindFlags = BindFlags.VertexBuffer | BindFlags.StreamOutput,
Usage = ResourceUsage.Default,
};
_buffer = new Buffer11(Device.Device, desc);
}
示例11: MultiMeshContainer
public MultiMeshContainer(Engine.Serialize.MeshesContainer MC)
{
if (MC != null)
{
//Transform = Matrix.Scaling(1);
Hardpoints = MC.HardPoints;
if (MC.Materials != null && MC.Geometry != null && MC.Geometry.Meshes != null)
{
BSP = MC.Geometry.BSP;
LocalAABBMax = MC.Geometry.AABBMax;
LocalAABBMin = MC.Geometry.AABBMin;
Meshes = new Serialize.MeshLink[MC.Materials.Length];
Materials = new MaterialContainer[MC.Materials.Length];
for (int i = 0; i < MC.Materials.Length; i++)
{
Meshes[i] = MC.Geometry.Meshes[i];
Materials[i] = new MaterialContainer(MC.Materials[i]);
}
VertexsCount = MC.Geometry.VertexCount;
BytesPerVertex = MC.Geometry.VertexData.Length / VertexsCount;
FaceCount = MC.Geometry.IndexData.Length / 12;
using (var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true))
{
vertices.WriteRange<byte>(MC.Geometry.VertexData, 0, MC.Geometry.VertexData.Length);
vertices.Position = 0;
Vertexs = new Buffer(ModelViewer.Program.device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
}
using (var indices = new DataStream(4 * FaceCount * 3, true, true))
{
indices.WriteRange<byte>(MC.Geometry.IndexData, 0, MC.Geometry.IndexData.Length);
indices.Position = 0;
Indices = new Buffer(ModelViewer.Program.device, indices, 4 * FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
}
BufferDescription bd = new BufferDescription();
bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
bd.Usage = ResourceUsage.Dynamic;
bd.BindFlags = BindFlags.ConstantBuffer;
bd.CpuAccessFlags = CpuAccessFlags.Write;
bd.OptionFlags = ResourceOptionFlags.None;
bd.StructureByteStride = 0;
constantsBuffer = new Buffer(ModelViewer.Program.device, bd);
constants = new ShaderConstants();
}
}
}
示例12: CreateMesh
public model CreateMesh(Device device, aiMesh aiMesh, aiMaterialVector mMaterials, String directory)
{
var numFaces = (int)aiMesh.mNumFaces;
var numVertices = (int)aiMesh.mNumVertices;
var aiPositions = aiMesh.mVertices;
var aiNormals = aiMesh.mNormals;
var aiTextureCoordsAll = aiMesh.mTextureCoords;
var aiTextureCoords = (aiTextureCoordsAll != null) ? aiTextureCoordsAll[0] : null;
VertexPostitionTexture[] VertexPostitionTextures = new VertexPostitionTexture[aiMesh.mNumVertices];
for (int j = 0; j < aiMesh.mNumVertices; j++)
{
VertexPostitionTextures[j].position = new Vector3(aiMesh.mVertices[j].x, aiMesh.mVertices[j].y, aiMesh.mVertices[j].z);
VertexPostitionTextures[j].textcoord = new Vector2(aiMesh.mTextureCoords[0][j].x, aiMesh.mTextureCoords[0][j].y);
}
///being brute =P
int SizeInBytes = Marshal.SizeOf(typeof(VertexPostitionTexture));
BufferDescription bd = new BufferDescription(SizeInBytes * (int)aiMesh.mNumVertices, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, SizeInBytes);
var vertices = Buffer.Create<VertexPostitionTexture>(device, VertexPostitionTextures, bd);
var aiFaces = aiMesh.mFaces;
var dxIndices = new uint[numFaces * 3];
for (int i = 0; i < numFaces; ++i)
{
var aiFace = aiFaces[i];
var aiIndices = aiFace.mIndices;
for (int j = 0; j < 3; ++j)
{
dxIndices[i * 3 + j] = (uint)aiIndices[j];
}
}
BufferDescription bi = new BufferDescription(sizeof(uint) * numFaces * 3, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, sizeof(uint));
var indices = Buffer.Create<uint>(device, dxIndices, bd);
model modelteste = new model();
modelteste.indices = indices;
modelteste.numberIndices = numFaces * 3;
modelteste.vertex = vertices;
modelteste.numberVertices = numVertices;
aiString difuse = new aiString();
mMaterials[(int)aiMesh.mMaterialIndex].GetTextureDiffuse0(difuse);
modelteste.difuseTextureName = difuse.Data;
String fullPath = String.IsNullOrEmpty(directory) ? modelteste.difuseTextureName : Path.Combine(directory, modelteste.difuseTextureName);
modelteste.ShaderResourceView = ShaderResourceView.FromFile(device, fullPath);
return modelteste;
}
示例13: InitializeFromImpl
/// <summary>
/// Initializes a new instance of the <see cref="Buffer" /> class.
/// </summary>
/// <param name="description">The description.</param>
/// <param name="viewFlags">Type of the buffer.</param>
/// <param name="viewFormat">The view format.</param>
/// <param name="dataPointer">The data pointer.</param>
protected Buffer InitializeFromImpl(BufferDescription description, BufferFlags viewFlags, PixelFormat viewFormat, IntPtr dataPointer)
{
bufferDescription = description;
nativeDescription = ConvertToNativeDescription(Description);
ViewFlags = viewFlags;
InitCountAndViewFormat(out this.elementCount, ref viewFormat);
ViewFormat = viewFormat;
NativeDeviceChild = new SharpDX.Direct3D11.Buffer(GraphicsDevice.RootDevice.NativeDevice, dataPointer, nativeDescription);
// Staging resource don't have any views
if (nativeDescription.Usage != ResourceUsage.Staging)
this.InitializeViews();
return this;
}
示例14: ColorShader
public ColorShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(VertexShaderFileName, "ColorVertexShader", "vs_4_0", ShaderFlags.None, EffectFlags.None);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(PixelShaderFileName, "ColorPixelShader", "ps_4_0", ShaderFlags.None, EffectFlags.None);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
var inputElements = new InputElement[]
{
new InputElement
{
SemanticName = "POSITION",
SemanticIndex = 0,
Format = Format.R32G32B32_Float,
Slot = 0,
AlignedByteOffset = 0,
Classification = InputClassification.PerVertexData,
InstanceDataStepRate = 0
},
new InputElement
{
SemanticName = "COLOR",
SemanticIndex = 0,
Format = Format.R32G32B32A32_Float,
Slot = 0,
AlignedByteOffset = ColorShader.Vertex.AppendAlignedElement,
Classification = InputClassification.PerVertexData,
InstanceDataStepRate = 0
}
};
Layout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
var matrixBufferDesc = new BufferDescription
{
Usage = ResourceUsage.Dynamic, // Updated each frame
SizeInBytes = Utilities.SizeOf<MatrixBuffer>(), // Contains three matrices
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
};
ConstantMatrixBuffer = new Buffer(device, matrixBufferDesc);
}
示例15: NewDescription
private static BufferDescription NewDescription(int bufferSize, int elementSize, BufferFlags bufferFlags, ResourceUsage usage)
{
var desc = new BufferDescription()
{
SizeInBytes = bufferSize,
StructureByteStride = elementSize, // We keep the element size in the structure byte stride, even if it is not a structured buffer
CpuAccessFlags = GetCputAccessFlagsFromUsage(usage),
BindFlags = BindFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = usage,
};
if ((bufferFlags & BufferFlags.ConstantBuffer) != 0)
desc.BindFlags |= BindFlags.ConstantBuffer;
if ((bufferFlags & BufferFlags.IndexBuffer) != 0)
desc.BindFlags |= BindFlags.IndexBuffer;
if ((bufferFlags & BufferFlags.VertexBuffer) != 0)
desc.BindFlags |= BindFlags.VertexBuffer;
if ((bufferFlags & BufferFlags.RenderTarget) != 0)
desc.BindFlags |= BindFlags.RenderTarget;
if ((bufferFlags & BufferFlags.ShaderResource) != 0)
desc.BindFlags |= BindFlags.ShaderResource;
if ((bufferFlags & BufferFlags.UnorderedAccess) != 0)
desc.BindFlags |= BindFlags.UnorderedAccess;
if ((bufferFlags & BufferFlags.StreamOutput) != 0)
desc.BindFlags |= BindFlags.StreamOutput;
if ((bufferFlags & BufferFlags.StructuredBuffer) != 0)
{
desc.OptionFlags |= ResourceOptionFlags.BufferStructured;
if (elementSize == 0)
throw new ArgumentException("Element size cannot be set to 0 for structured buffer");
}
if ((bufferFlags & BufferFlags.RawBuffer) == BufferFlags.RawBuffer)
desc.OptionFlags |= ResourceOptionFlags.BufferAllowRawViews;
if ((bufferFlags & BufferFlags.ArgumentBuffer) == BufferFlags.ArgumentBuffer)
desc.OptionFlags |= ResourceOptionFlags.DrawIndirectArguments;
return desc;
}