public void Dispose() { isInitialized = false; if (CursorMesh != null) { CursorMesh.Dispose(); CursorMesh = null; } if (AxesMesh != null) { AxesMesh.Dispose(); AxesMesh = null; } if (BlendedVertexLayout != null) { BlendedVertexLayout.Dispose(); BlendedVertexLayout = null; } if (normalMapEffect != null) { normalMapEffect.Dispose(); normalMapEffect = null; } if (LineLayout != null) { LineLayout.Dispose(); LineLayout = null; } if (PositionColorEffect != null) { PositionColorEffect.Dispose(); PositionColorEffect = null; } if ((renderControl != null) && !renderControl.IsDisposed) { UnregisterControlEvents(); renderControl = null; } if (depthStencilView != null) { depthStencilView.Dispose(); depthStencilView = null; } if (depthStencilBuffer != null) { depthStencilBuffer.Dispose(); depthStencilBuffer = null; } if (renderTarget != null) { renderTarget.Dispose(); renderTarget = null; } if (transparentBS != null) { transparentBS.Dispose(); transparentBS = null; } if (swapChain != null) { swapChain.Dispose(); swapChain = null; } /* if (TextFont != null) * { * TextFont.Dispose(); * TextFont = null; * }*/ if (Device != null) { Device.Dispose(); Device = null; } }
public virtual void Render() { try { if (deviceLost) { ReinitializeRenderer(); return; } if (isInitialized && !isRendering && (swapChain != null)) { isRendering = true; if ((Control.ModifierKeys & Keys.Shift) != Keys.None || !LockLight) { Lights[0].Direction = -Vector3.Normalize(camera.Direction); } normalMapEffect.SetDirLights(Lights); Device.ImmediateContext.ClearRenderTargetView(renderTarget, new Color4(Background)); Device.ImmediateContext.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); Core.FX.ExtendedNormalMapEffect effect = (Core.FX.ExtendedNormalMapEffect)Effect; effect.SetWorld(Matrix.Identity); effect.SetWorldInvTranspose(Matrix.Identity); /* Matrix toTexSpace = Matrix.Identity; * toTexSpace.M11 = 0.5f; * toTexSpace.M22 = -0.5f; * toTexSpace.M41 = 0.5f; * toTexSpace.M42 = 0.5f; * effect.SetWorldViewProjTex(Matrix.Identity * toTexSpace);*/ Matrix wvp = camera.View * camera.Projection; effect.SetEyePosW(camera.position); effect.SetWorldViewProj(wvp); // effect.SetShadowTransform(Matrix.Identity); foreach (var pair in renderObjects) { pair.Value.Render(); } if (mouseDown != MouseButtons.None) { DrawAxes(); DrawCursor(); /* string camStr = "(" + camera.target.X.ToString("0.##") + ", " + camera.target.Y.ToString("0.##") + ", " + camera.target.Z.ToString("0.##") + ")"; * TextFont.DrawString(null, camStr, renderRect, DrawTextFormat.Right | DrawTextFormat.Top, TextColor);*/ } swapChain.Present(0, PresentFlags.None); isRendering = false; } } catch (Exception e) { Utility.ReportException(e); isInitialized = false; isRendering = false; ReinitializeRenderer(); isInitialized = true; if (!deviceLost) { // Render(); } } }
private void BuildFX() { try { PositionColorEffect = new Core.FX.ColorEffect(Device, Path.GetDirectoryName(Application.ExecutablePath) + "/FX/color.fxo"); EffectPassDescription passDesc = PositionColorEffect.ColorTech.GetPassByIndex(0).Description; LineLayout = new InputLayout ( Device, passDesc.Signature, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 12, 0, InputClassification.PerVertexData, 0) } ); normalMapEffect = new Core.FX.ExtendedNormalMapEffect(Device, Path.GetDirectoryName(Application.ExecutablePath) + "/FX/NormalMap.fxo"); passDesc = ((Core.FX.ExtendedNormalMapEffect)Effect).MorphTech.GetPassByIndex(0).Description; MorphedVertexLayout = new InputLayout ( Device, passDesc.Signature, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("POSITION", 1, Format.R32G32B32_Float, InputElement.AppendAligned, 1, InputClassification.PerVertexData, 0), new InputElement("NORMAL", 1, Format.R32G32B32_Float, InputElement.AppendAligned, 1, InputClassification.PerVertexData, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 2, InputClassification.PerVertexData, 0), } ); passDesc = ((Core.FX.ExtendedNormalMapEffect)Effect).Light1TexAlphaClipSkinnedTech.GetPassByIndex(0).Description; BlendedVertexLayout = new InputLayout ( Device, passDesc.Signature, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("TANGENT", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("BLENDWEIGHT", 0, Format.R32G32B32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("BLENDINDICES", 0, Format.R32G32B32A32_UInt, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0) } ); passDesc = ((Core.FX.ExtendedNormalMapEffect)Effect).NormalsTech.GetPassByIndex(0).Description; VertexNormalLayout = new InputLayout ( Device, passDesc.Signature, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("BLENDWEIGHT", 0, Format.R32G32B32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("BLENDINDICES", 0, Format.R32G32B32A32_UInt, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0) } ); passDesc = ((Core.FX.ExtendedNormalMapEffect)Effect).BonesTech.GetPassByIndex(0).Description; VertexBoneLayout = new InputLayout ( Device, passDesc.Signature, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("BLENDINDICES", 0, Format.R32_UInt, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0) } ); } catch (Exception ex) { Report.ReportLog("BuildFX crashed: " + ex.Message); throw ex; } }