public bool UpdateBuffers(DeviceContextProxy context, IDeviceResources deviceResources) { if (SpriteCount == 0 || IndexCount == 0 || Sprites == null || Indices == null || Sprites.Length < SpriteCount || Indices.Length < IndexCount) { return(false); } vertextBuffer.UploadDataToBuffer(context, Sprites, SpriteCount); IndexBuffer.UploadDataToBuffer(context, Indices, IndexCount); return(true); }
protected override void OnRender(RenderContext renderContext) { this.bHasInstances.Set(this.hasInstances); // --- set constant paramerers var worldMatrix = this.modelMatrix * renderContext.worldMatrix; this.EffectTransforms.mWorld.SetMatrix(ref worldMatrix); // --- check shadowmaps this.hasShadowMap = this.renderHost.IsShadowMapEnabled; this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap); this.effectMaterial.AttachMaterial(geometryInternal as MeshGeometry3D); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = this.vertexLayout; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderContext.DeviceContext.InputAssembler.SetIndexBuffer(this.IndexBuffer.Buffer, Format.R32_UInt, 0); // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = this.RasterState; renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); hasBonesVar.Set(hasBoneParameter && hasBoneMatrices); if (hasBoneMatrices) { boneMatricesVar.SetMatrix(mBones.Bones); } if (this.hasBoneParameter) { if (isBoneParamChanged && this.VertexBoneIds.Count >= geometryInternal.Positions.Count) { vertexBoneParamsBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.VertexBoneIds); this.isBoneParamChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this.vertexBoneParamsBuffer.Buffer, this.vertexBoneParamsBuffer.StructureSize, 0)); } if (this.hasInstances) { // --- update instance buffer if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0)); OnInstancedDrawCall(renderContext); } else { // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); OnDrawCall(renderContext); } }
protected override void OnRender(RenderContext renderContext) { // --- check to render the model var geometry = geometryInternal as IBillboardText; if (geometry == null) { throw new System.Exception("Geometry must implement IBillboardText"); } this.bHasInstances.Set(this.hasInstances); this.hasInstanceParamVar.Set(this.hasInstanceParams); // --- set constant paramerers var worldMatrix = modelMatrix * renderContext.worldMatrix; EffectTransforms.mWorld.SetMatrix(ref worldMatrix); this.bFixedSizeVariable.Set(FixedSize); // --- check shadowmaps //this.hasShadowMap = this.renderHost.IsShadowMapEnabled; //this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = vertexLayout; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = RasterState; // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer.Buffer, VertexBuffer.StructureSize, 0)); // --- render the geometry this.bHasBillboardTexture.Set(geometry.Texture != null); if (geometry.Texture != null) { billboardTextureVariable.SetResource(billboardTextureView); } this.bHasBillboardAlphaTexture.Set(geometry.AlphaTexture != null); if (geometry.AlphaTexture != null) { billboardAlphaTextureVariable.SetResource(billboardAlphaTextureView); } var vertexCount = geometryInternal.Positions.Count; if (this.hasInstances) { if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0)); if (this.hasInstanceParams) { if (instanceParamArrayChanged) { instanceParamBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.InstanceParamArray); this.instanceParamArrayChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(this.instanceParamBuffer.Buffer, this.instanceParamBuffer.StructureSize, 0)); } switch (billboardType) { case BillboardType.SingleImage: // Use foreground shader to draw text effectTechnique.GetPassByIndex(2).Apply(renderContext.DeviceContext); // --- draw text, foreground vertex is beginning from 0. renderContext.DeviceContext.DrawInstanced(vertexCount, this.instanceInternal.Count, 0, 0); break; case BillboardType.SingleText: if (vertexCount == 8) { var half = vertexCount / 2; // Use background shader to draw background first effectTechnique.GetPassByIndex(1).Apply(renderContext.DeviceContext); // --- draw background, background vertex is beginning from middle. <see cref="BillboardSingleText3D"/> renderContext.DeviceContext.DrawInstanced(half, this.instanceInternal.Count, half, 0); // Use foreground shader to draw text effectTechnique.GetPassByIndex(0).Apply(renderContext.DeviceContext); // --- draw text, foreground vertex is beginning from 0. renderContext.DeviceContext.DrawInstanced(half, this.instanceInternal.Count, 0, 0); } break; } } this.bHasInstances.Set(false); this.hasInstanceParamVar.Set(false); }