本文整理汇总了C#中Device.SetStreamSourceFrequency方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetStreamSourceFrequency方法的具体用法?C# Device.SetStreamSourceFrequency怎么用?C# Device.SetStreamSourceFrequency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetStreamSourceFrequency方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public new void Render(Effect effect, Device device, bool setMaterial)
{
int vbID = 0, ibID = 0, matID = 0;
device.VertexDeclaration = vertexDecl;
device.SetStreamSourceFrequency(0, nInstances, StreamSource.IndexedData);
//if (lightcubearr.Count <= 63 * 6 * 3 && lightcubearr.Count > 0)
// Renderer.Instance.effect.SetValue<float>("ambientLight", lightcubearr.ToArray());
//Renderer.Instance.effect.CommitChanges();
// Set InstanceBuffer
device.SetStreamSource(1, vb.VB, InstanceBufferOffset, D3DX.GetDeclarationVertexSize(VertexPropInstance.Elements, 1));
device.SetStreamSourceFrequency(1,1,StreamSource.InstanceData);
// Render Bodyparts
foreach (BodyPart part in Parts)
{
foreach (Model model in part.Models)
{
MDLMesh mesh = model.GetLODMesh(0);
mesh.Render(effect, device, ref vbID, ref ibID, ref matID);
}
}
}
示例2: RenderXMeshesWithInstancingShadows
private void RenderXMeshesWithInstancingShadows(Dictionary<SlimDX.Direct3D9.Mesh, RenderMesh> meshes, Device device)
{
int k = 0;
device.VertexFormat = VertexFormat.None;
device.VertexDeclaration = vd;
foreach (SlimDX.Direct3D9.Mesh mesh in meshes.Keys)
{
device.Indices = meshes[mesh].IndexBuffer;
foreach (Texture texture in meshes[mesh].Textures.Keys)
{
bool first = true;
int numberOfInstancedDraws = 0;
DataStream ds = null;
foreach (Common.Tuple<Graphics.Content.Model9, Entity, string> renderObject in meshes[mesh].Textures[texture].RenderObjects)
{
Entity entity = renderObject.Second;
if (entity.ActiveInShadowMap == Frame)
{
MetaModel metaModel = GetLatestMetaModel(entity, renderObject.Third);
if (first)
{
//if ((Settings.TerrainQualityPriorityRelation[Settings.TerrainQuality] + Settings.PriorityRelation[metaModel.Visible] < 3) ||
// !(Settings.PriorityRelation[metaModel.CastShadows] + Settings.ShadowQualityPriorityRelation[Settings.ShadowQuality] > 3))
// break;
meshEffect.SetTexture(EHTexture, texture);
ds = optimizedVB[k % optimizedVB.Length].Lock(0, meshes[mesh].Textures[texture].RenderObjects.Count * (Vector4.SizeInBytes * 4), LockFlags.None);
UpdateEffectWithMetaModel(meshEffect, metaModel, true);
meshEffect.CommitChanges();
first = false;
}
Matrix worldMatrix;
if (renderObject.First.SkinnedMesh != null)
worldMatrix = metaModel.StoredFrameMatrices[mesh][0][0];
else
worldMatrix = metaModel.GetWorldMatrix(Scene.Camera, renderObject.Second);
ds.Write(worldMatrix);
numberOfInstancedDraws++;
}
}
if (numberOfInstancedDraws == 0)
continue;
optimizedVB[k % optimizedVB.Length].Unlock();
DrawInstancedIndexedPrimitives(device, mesh, meshes[mesh].VertexBuffer, optimizedVB[k % optimizedVB.Length], instancedVertexElements,
numberOfInstancedDraws);
k++;
}
}
device.SetStreamSourceFrequency(0, 1, StreamSource.IndexedData);
device.SetStreamSourceFrequency(1, 0, StreamSource.InstanceData);
device.SetStreamSource(0, null, 0, 0);
device.SetStreamSource(1, null, 0, 0);
device.ResetStreamSourceFrequency(0);
}
示例3: DrawInstancedIndexedPrimitives
private void DrawInstancedIndexedPrimitives(Device device, SlimDX.Direct3D9.Mesh mesh, VertexBuffer vertexBuffer, VertexBuffer instancedVertexData, VertexElement[] vertexElements, int nIndexedElements)
{
device.SetStreamSourceFrequency(0, nIndexedElements, StreamSource.IndexedData);
device.SetStreamSource(0, vertexBuffer, 0, D3DX.GetDeclarationVertexSize(vertexElements, 0));
device.SetStreamSourceFrequency(1, 1, StreamSource.InstanceData);
device.SetStreamSource(1, instancedVertexData, 0, D3DX.GetDeclarationVertexSize(vertexElements, 1));
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, mesh.VertexCount, 0, mesh.FaceCount);
}
示例4: RenderXMeshesWithInstancing
//.........这里部分代码省略.........
foreach (SlimDX.Direct3D9.Mesh mesh in meshes.Keys)
{
device.Indices = meshes[mesh].IndexBuffer;
foreach (Texture texture in meshes[mesh].Textures.Keys)
{
bool first = true;
int numberOfInstancedDraws = 0;
DataStream ds = null;
foreach (Common.Tuple<Graphics.Content.Model9, Entity, string> renderObject in meshes[mesh].Textures[texture].RenderObjects)
{
Entity entity = renderObject.Second;
if (entity.ActiveInMain == Frame)
{
if (first)
{
MetaModel metaModel = GetLatestMetaModel(entity, renderObject.Third);
//if (Settings.PriorityRelation[metaModel.Visible] + Settings.TerrainQualityPriorityRelation[Settings.TerrainQuality] < 3)
// break;
effect.SetTexture(EHTexture, texture);
ds = optimizedVB[k % optimizedVB.Length].Lock(0, meshes[mesh].Textures[texture].RenderObjects.Count * (Vector4.SizeInBytes * 4), LockFlags.None);
if (renderObject.First.SpecularTexture != null)
effect.SetTexture(EHSpecularMap, renderObject.First.SpecularTexture);
UpdateEffectWithMetaModel(effect, metaModel, false);
effect.CommitChanges();
first = false;
}
Matrix worldMatrix;
//Matrix normalMatrix;
if (renderObject.First.SkinnedMesh != null)
{
Matrix[] storedMatrices =
GetLatestMetaModel(renderObject.Second, renderObject.Third).StoredFrameMatrices[mesh][0];
worldMatrix = storedMatrices[0];
//normalMatrix = storedMatrices.Second[0];
}
else
{
MetaModel metaModel = GetLatestMetaModel(entity, renderObject.Third);
worldMatrix = metaModel.GetWorldMatrix(Scene.Camera, renderObject.Second);
//normalMatrix = Matrix.Transpose(Matrix.Invert(worldMatrix));
}
ds.Write(worldMatrix);
//ThreeTimesThreeMatrix matrix;
//matrix.M11 = normalMatrix.M11;
//matrix.M12 = normalMatrix.M12;
//matrix.M13 = normalMatrix.M13;
//matrix.M21 = normalMatrix.M21;
//matrix.M22 = normalMatrix.M22;
//matrix.M23 = normalMatrix.M23;
//matrix.M31 = normalMatrix.M31;
//matrix.M32 = normalMatrix.M32;
//matrix.M33 = normalMatrix.M33;
//ds.Write(matrix);
numberOfInstancedDraws++;
}
}
#if RENDERER_STATISTICS
if (maxNumberOfInstancedDrawCalls < numberOfInstancedDraws)
maxNumberOfInstancedDrawCalls = numberOfInstancedDraws;
if (minNumberOfInstancedDrawCalls > numberOfInstancedDraws)
minNumberOfInstancedDrawCalls = numberOfInstancedDraws;
#endif
if (numberOfInstancedDraws == 0)
continue;
optimizedVB[k % optimizedVB.Length].Unlock();
DrawInstancedIndexedPrimitives(device, mesh, meshes[mesh].VertexBuffer, optimizedVB[k % optimizedVB.Length], instancedVertexElements,
numberOfInstancedDraws);
k++;
}
}
effect.EndPass();
effect.End();
device.SetStreamSourceFrequency(0, 1, StreamSource.IndexedData);
device.SetStreamSourceFrequency(1, 0, StreamSource.InstanceData);
device.SetStreamSource(0, null, 0, 0);
device.SetStreamSource(1, null, 0, 0);
device.ResetStreamSourceFrequency(0);
}
示例5: RenderInstances
private void RenderInstances(Device dev)
{
InstanceLoader.UpdateVisibility();
if (Meshes.Count == 0 || Textures.Count == 0 || InstanceDataBuffer == null || numInstances == 0)
return;
mModelInfo.BoneAnimator.OnFrame();
int counter = 0;
var shdr = Video.ShaderCollection.MDXShader;
dev.VertexDeclaration = InstanceDeclaration;
dev.SetRenderState(RenderState.VertexBlend, VertexBlend.Weights3);
foreach (VertexBuffer vb in Meshes)
{
dev.SetStreamSource(0, vb, 0, Marshal.SizeOf(typeof(Models.MDX.MdxVertex)));
dev.SetStreamSourceFrequency(0, numInstances, StreamSource.IndexedData);
dev.SetStreamSource(1, InstanceDataBuffer, 0, Marshal.SizeOf(typeof(Models.MDX.MdxInstanceData)));
dev.SetStreamSourceFrequency(1, 1, StreamSource.InstanceData);
setRenderValues(counter);
dev.Indices = Indices[counter];
shdr.SetTexture("MeshTexture", Textures[counter]);
if (mModelInfo.Passes[counter].BoneMatrices.Length == 0 || mModelInfo.Passes[counter].BoneMatrices.Length > 50)
{
shdr.SetValue("useAnimation", false);
}
else
{
shdr.SetValue<Matrix>("BoneMatrices", mModelInfo.Passes[counter].BoneMatrices);
shdr.SetValue("useAnimation", mModelInfo.Passes[counter].BoneMatrices.Length > 0);
}
shdr.DoRender((device) =>
{
dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, NumTriangles[counter] * 3, 0, NumTriangles[counter]);
}
);
unsetRenderValues();
++counter;
}
dev.VertexDeclaration = null;
dev.ResetStreamSourceFrequency(0);
dev.ResetStreamSourceFrequency(1);
dev.SetRenderState(RenderState.VertexBlend, VertexBlend.Disable);
}