static void Main() { AppDomain.CurrentDomain.UnhandledException += (args, e) => Log.Debug(e.ExceptionObject.ToString()); Settings.KeyBindings.Initialize(); var window = new EditorWindow(); var context = new GxContext(window.DrawTarget); context.InitContext(); InterfaceManager.Instance.Initialize(window.DrawTarget, context); WorldFrame.Instance.Initialize(window.DrawTarget, context); WorldFrame.Instance.OnResize((int) window.RenderSize.Width, (int) window.RenderSize.Height); InterfaceManager.Instance.RenderWindow.OnLoadFinished(); var app = new Application(); var timer = new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.ApplicationIdle, (sender, args) => { context.BeginFrame(); WorldFrame.Instance.OnFrame(); InterfaceManager.Instance.OnFrame(); context.EndFrame(); }, app.Dispatcher); app.Run(window); WorldFrame.Instance.Shutdown(); }
public DepthState(GxContext context) { mContext = context; mDescription = new DepthStencilStateDescription { BackFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Decrement, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, PassOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, DepthFailOperation = StencilOperation.Increment }, DepthComparison = Comparison.LessEqual, DepthWriteMask = DepthWriteMask.All, IsDepthEnabled = true, IsStencilEnabled = true, StencilReadMask = 0xFF, StencilWriteMask = 0xFF }; mChanged = true; }
public Mesh(GxContext context) { mContext = context; VertexBuffer = new VertexBuffer(context); IndexBuffer = new IndexBuffer(context); DepthState = new DepthState(context); RasterizerState = new RasterState(context); BlendState = new BlendState(context); }
private void Dispose(bool disposing) { if (mState != null) { mState.Dispose(); mState = null; } mContext = null; }
private void Dispose(bool disposing) { if (Native != null) { Native.Dispose(); Native = null; } mContext = null; }
public static void Initialize(GxContext context) { if (Color != null) { return; } Color = new Texture(context); Specular = new Texture(context); Specular.UpdateMemory(1, 1, Format.R8_UNorm, new byte[] { 255 }, 1); }
public void Initialize(GxContext context) { mContext = context; mDispatcher = Dispatcher.CurrentDispatcher; for(var i = 0; i < 2; ++i) { var t = new Thread(ThreadProc); t.Start(); mThreads.Add(t); } }
protected Buffer(GxContext context, BindFlags binding) { mContext = context; mDescription = new BufferDescription { BindFlags = binding, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 0, StructureByteStride = 0, Usage = ResourceUsage.Default }; }
public static InputLayout GetLayout(GxContext context, InputElement[] elements, Mesh mesh, ShaderProgram program) { Dictionary <ShaderProgram, InputLayout> meshEntry; InputLayout layout; if (Layouts.TryGetValue(mesh, out meshEntry)) { if (meshEntry.TryGetValue(program, out layout)) { return(layout); } layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements); meshEntry.Add(program, layout); return(layout); } bool hasInstance = false, hasVertex = false; for (var i = 0; i < elements.Length; ++i) { if (hasInstance && hasVertex) { break; } if (elements[i].Classification == InputClassification.PerInstanceData && hasInstance == false) { elements[i].AlignedByteOffset = 0; hasInstance = true; continue; } if (elements[i].Classification == InputClassification.PerVertexData && hasVertex == false) { elements[i].AlignedByteOffset = 0; hasVertex = true; } } layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements); meshEntry = new Dictionary <ShaderProgram, InputLayout>() { { program, layout } }; Layouts.Add(mesh, meshEntry); return(layout); }
private void Dispose(bool disposing) { if (mTexture != null) { mTexture.Dispose(); mTexture = null; } if (mView != null) { mView.Dispose(); mView = null; } mDevice = null; }
private void Dispose(bool disposing) { if (mTexture != gDefaultTexture) { if (mTexture != null) { mTexture.Dispose(); } if (NativeView != null) { NativeView.Dispose(); } } mContext = null; }
public static InputLayout GetLayout(GxContext context, InputElement[] elements, Mesh mesh, ShaderProgram program) { Dictionary<ShaderProgram, InputLayout> meshEntry; InputLayout layout; if (Layouts.TryGetValue(mesh, out meshEntry)) { if (meshEntry.TryGetValue(program, out layout)) return layout; layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements); meshEntry.Add(program, layout); return layout; } bool hasInstance = false, hasVertex = false; for(var i = 0; i < elements.Length; ++i) { if (hasInstance && hasVertex) break; if(elements[i].Classification == InputClassification.PerInstanceData && hasInstance == false) { elements[i].AlignedByteOffset = 0; hasInstance = true; continue; } if(elements[i].Classification == InputClassification.PerVertexData && hasVertex == false) { elements[i].AlignedByteOffset = 0; hasVertex = true; } } layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements); meshEntry = new Dictionary<ShaderProgram, InputLayout>() { {program, layout} }; Layouts.Add(mesh, meshEntry); return layout; }
public Sampler(GxContext context) { mContext = context; mDescription = new SamplerStateDescription { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = SharpDX.Color4.Black, ComparisonFunction = Comparison.Always, Filter = Filter.MinMagMipLinear, MaximumAnisotropy = 0, MaximumLod = float.MaxValue, MinimumLod = float.MinValue, MipLodBias = 0.0f }; mChanged = true; }
public RasterState(GxContext context) { mContext = context; mDescription = new RasterizerStateDescription { CullMode = CullMode.None, DepthBias = 0, DepthBiasClamp = 0.0f, FillMode = FillMode.Solid, IsAntialiasedLineEnabled = false, IsDepthClipEnabled = true, IsFrontCounterClockwise = true, IsMultisampleEnabled = false, IsScissorEnabled = false, SlopeScaledDepthBias = 0.0f }; mChanged = true; }
private void Dispose(bool disposing) { if (mVertexShader != null) { mVertexShader.Dispose(); } if (mPixelShader != null) { mPixelShader.Dispose(); } if (VertexShaderCode != null) { VertexShaderCode.Dispose(); } mContext = null; }
public static void InitDefaultTexture(GxContext context) { var desc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R8G8B8A8_UNorm, Height = 2, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Immutable, Width = 2 }; using (var strm = new DataStream(16, true, true)) { strm.WriteRange(new[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF }); var layerData = new DataBox(strm.DataPointer) { RowPitch = 8 }; gDefaultTexture = new Texture2D(context.Device, desc, new[] { layerData }); } var srvd = new ShaderResourceViewDescription { Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, Format = Format.R8G8B8A8_UNorm, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = 1, MostDetailedMip = 0 } }; gDefaultView = new ShaderResourceView(context.Device, gDefaultTexture, srvd); DefaultTextures.Initialize(context); }
private void Dispose(bool disposing) { if (mDepthView != null) { mDepthView.Dispose(); mDepthView = null; } if (mOldDepthView != null) { mOldDepthView.Dispose(); mOldDepthView = null; } if (mOldRenderTarget != null) { mOldRenderTarget.Dispose(); mOldRenderTarget = null; } if (mDepthTexture != null) { mDepthTexture.Dispose(); mDepthTexture = null; } if (Native != null) { Native.Dispose(); Native = null; } if (Texture != null) { Texture.Dispose(); Texture = null; } mContext = null; }
public BlendState(GxContext context) { mContext = context; mDescription = new BlendStateDescription { AlphaToCoverageEnable = false, IndependentBlendEnable = false }; mDescription.RenderTarget[0] = new RenderTargetBlendDescription { IsBlendEnabled = true, SourceBlend = BlendOption.SourceAlpha, DestinationBlend = BlendOption.InverseSourceAlpha, BlendOperation = BlendOperation.Add, SourceAlphaBlend = BlendOption.One, DestinationAlphaBlend = BlendOption.Zero, AlphaBlendOperation = BlendOperation.Add, RenderTargetWriteMask = ColorWriteMaskFlags.All }; mChanged = true; }
public SkySphere(float radius, int rings, int sectors, GxContext context) { mSampler = new Sampler(context); mMesh = new Mesh(context); mMesh.AddElement("POSITION", 0, 3); mMesh.AddElement("TEXCOORD", 0, 2); mMesh.BlendState.BlendEnabled = false; mMesh.DepthState.DepthEnabled = true; mMesh.Stride = IO.SizeCache<SphereVertex>.Size; InitVertices(radius, rings, sectors); mMesh.VertexBuffer.UpdateData(mVertices); mMatrixBuffer = new ConstantBuffer(context); mMatrixBuffer.UpdateData(Matrix.Identity); var program = new ShaderProgram(context); program.SetVertexShader(Resources.Shaders.SkyVertex); program.SetPixelShader(Resources.Shaders.SkyPixel); mMesh.Program = program; }
public RenderTarget(GxContext context) { mContext = context; }
public TextureArray(GxContext context) { mDevice = context; }
public static InputLayout GetLayout(GxContext context, InputElement[] elements, Mesh mesh, ShaderProgram program) { InputLayout layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements); return(layout); }
public Texture(GxContext context) { mContext = context; NativeView = gDefaultView; mTexture = gDefaultTexture; }
public static void Initialize(GxContext context) { ChunkMesh = new Mesh(context); InitMesh(context); }
public DrawSurface(GxContext context) { DirectWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated); Direct2DFactory = new Factory(); mDevice = context; }
public static void Initialize(GxContext context) { Mesh = new Mesh(context) { IndexCount = 16 * 16 * 4 * 3, Stride = IO.SizeCache<Vector3>.Size, DepthState = {DepthEnabled = false} }; Mesh.AddElement("POSITION", 0, 3); var indices = new uint[16 * 16 * 12]; for (var y = 0u; y < 16; ++y) { for (var x = 0u; x < 16; ++x) { var i = y * 16 * 12 + x * 12; indices[i + 0] = y * 33 + x; indices[i + 2] = y * 33 + x + 1; indices[i + 1] = y * 33 + x + 17; indices[i + 3] = y * 33 + x + 1; indices[i + 5] = y * 33 + x + 34; indices[i + 4] = y * 33 + x + 17; indices[i + 6] = y * 33 + x + 34; indices[i + 8] = y * 33 + x + 33; indices[i + 7] = y * 33 + x + 17; indices[i + 9] = y * 33 + x + 33; indices[i + 11] = y * 33 + x; indices[i + 10] = y * 33 + x + 17; } } Mesh.IndexBuffer.UpdateData(indices); Mesh.IndexBuffer.IndexFormat = SharpDX.DXGI.Format.R32_UInt; var program = new ShaderProgram(context); program.SetVertexShader(Resources.Shaders.MapLowVertex); program.SetPixelShader(Resources.Shaders.MapLowPixel); Mesh.Program = program; }
public ShaderProgram(GxContext context) { mContext = context; }
public static void InitDefaultTexture(GxContext context) { var desc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R8G8B8A8_UNorm, Height = 2, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Immutable, Width = 2 }; using (var strm = new DataStream(16, true, true)) { strm.WriteRange(new[] {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF}); var layerData = new DataBox(strm.DataPointer) {RowPitch = 8}; gDefaultTexture = new Texture2D(context.Device, desc, new[] { layerData }); } var srvd = new ShaderResourceViewDescription { Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D, Format = Format.R8G8B8A8_UNorm, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = 1, MostDetailedMip = 0 } }; gDefaultView = new ShaderResourceView(context.Device, gDefaultTexture, srvd); }
public void Initialize(RenderControl window, GxContext context) { mGlobalBuffer = new ConstantBuffer(context); mGlobalParamsBuffer = new ConstantBuffer(context); mGlobalParamsBufferStore = new GlobalParamsBuffer { mapAmbient = new Vector4(0.5f, 0.5f, 0.5f, 1.0f), mapDiffuse = new Vector4(0.25f, 0.5f, 1.0f, 1.0f), fogColor = new Vector4(0.25f, 0.5f, 1.0f, 1.0f), fogParams = new Vector4(500.0f, 900.0f, mMainCamera.FarClip, 0.0f), brushParameters = new Vector4(45.0f, 55.0f, 0.0f, 0.0f), mousePosition = new Vector4(float.MaxValue), eyePosition = Vector4.Zero, brushSettings = new Vector4(0, 1, 0, 0) }; mGlobalParamsBuffer.UpdateData(mGlobalParamsBufferStore); mGlobalBufferStore = new GlobalBuffer { eyePosition = Vector4.Zero, matProj = Matrix.Identity, matView = Matrix.Identity }; mGlobalBuffer.UpdateData(mGlobalBufferStore); Dispatcher = new GraphicsDispatcher(); MapChunkRender.Initialize(context); MapAreaLowRender.Initialize(context); WmoGroupRender.Initialize(context); M2BatchRenderer.Initialize(context); M2ModelRenderer.Initialize(context); StaticAnimationThread.Instance.Initialize(); WmoManager.Initialize(); M2Manager.Initialize(); GraphicsContext = context; SetActiveCamera(mMainCamera); TextureManager.Instance.Initialize(context); MapManager.Initialize(); mMainCamera.ViewChanged += ViewChanged; mMainCamera.ProjectionChanged += ProjectionChanged; ViewChanged(mMainCamera, mMainCamera.View); ProjectionChanged(mMainCamera, mMainCamera.Projection); CamControl = new CameraControl(window); CamControl.PositionChanged += MapManager.UpdatePosition; if (!LeftHandedCamera) CamControl.InvertY = true; }
public static void Initialize(GxContext context) { Mesh = new Mesh(context) { Stride = IO.SizeCache<M2Vertex>.Size, DepthState = { DepthEnabled = true } }; Mesh.BlendState.Dispose(); Mesh.IndexBuffer.Dispose(); Mesh.VertexBuffer.Dispose(); Mesh.AddElement("POSITION", 0, 3); Mesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true); Mesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte); Mesh.AddElement("NORMAL", 0, 3); Mesh.AddElement("TEXCOORD", 0, 2); Mesh.AddElement("TEXCOORD", 1, 2); var program = new ShaderProgram(context); program.SetVertexShader(Resources.Shaders.M2VertexPortrait); program.SetPixelShader(Resources.Shaders.M2PixelPortrait); Mesh.Program = program; Sampler = new Sampler(context) { AddressMode = SharpDX.Direct3D11.TextureAddressMode.Wrap, Filter = SharpDX.Direct3D11.Filter.MinMagMipLinear }; for (var i = 0; i < BlendStates.Length; ++i) BlendStates[i] = new BlendState(context); BlendStates[0] = new BlendState(context) { BlendEnabled = false }; BlendStates[1] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.One, DestinationBlend = SharpDX.Direct3D11.BlendOption.Zero, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.One, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero }; BlendStates[2] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha }; BlendStates[3] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceColor, DestinationBlend = SharpDX.Direct3D11.BlendOption.DestinationColor, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha }; BlendStates[4] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.One, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.One }; BlendStates[5] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha }; BlendStates[6] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.DestinationColor, DestinationBlend = SharpDX.Direct3D11.BlendOption.SourceColor, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha }; gNoBlendProgram = program; gBlendProgram = new ShaderProgram(context); gBlendProgram.SetPixelShader(Resources.Shaders.M2PixelPortraitBlend); gBlendProgram.SetVertexShader(Resources.Shaders.M2VertexPortrait); gNoCullState = new RasterState(context) {CullEnabled = false}; gCullState = new RasterState(context) {CullEnabled = true}; }
private static void InitMesh(GxContext context) { // all tiles will supply their own vertex buffer ChunkMesh.VertexBuffer.Dispose(); ChunkMesh.AddElement("POSITION", 0, 3); ChunkMesh.AddElement("NORMAL", 0, 3); ChunkMesh.AddElement("TEXCOORD", 0, 2); ChunkMesh.AddElement("TEXCOORD", 1, 2); ChunkMesh.AddElement("COLOR", 0, 4, DataType.Byte, true); ChunkMesh.AddElement("COLOR", 1, 4, DataType.Byte, true); ChunkMesh.IndexCount = 768; ChunkMesh.Stride = IO.SizeCache<IO.Files.Terrain.AdtVertex>.Size; ChunkMesh.BlendState.BlendEnabled = false; ChunkMesh.DepthState.DepthEnabled = true; ChunkMesh.RasterizerState.CullEnabled = true; BlendNew = new ShaderProgram(context); BlendNew.SetVertexShader(Resources.Shaders.TerrainVertex); BlendNew.SetPixelShader(Resources.Shaders.TerrainPixelNew); ChunkMesh.Program = BlendNew; BlendOld = new ShaderProgram(context); BlendOld.SetVertexShader(Resources.Shaders.TerrainVertex); BlendOld.SetPixelShader(Resources.Shaders.TerrainPixel); ColorSampler = new Sampler(context) { AddressMode = SharpDX.Direct3D11.TextureAddressMode.Wrap, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16, }; AlphaSampler = new Sampler(context) { AddressMode = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16, }; }
public IndexBuffer(GxContext context) : base(context, SharpDX.Direct3D11.BindFlags.IndexBuffer) { IndexFormat = Format.R16_UInt; }
public static void Initialize(GxContext context) { gNoBlendState = new BlendState(context) { BlendEnabled = false }; gAlphaBlendState = new BlendState(context) { BlendEnabled = true }; gNoCullState = new RasterState(context) {CullEnabled = false}; gCullState = new RasterState(context) {CullEnabled = true}; Sampler = new Sampler(context); InstanceBuffer = new ConstantBuffer(context); InstanceBuffer.UpdateData(Matrix.Identity); // preallocate space so the underlying buffer wont change anymore Mesh = new Mesh(context) { DepthState = { DepthEnabled = true }, Stride = IO.SizeCache<IO.Files.Models.WmoVertex>.Size }; Mesh.AddElement("POSITION", 0, 3); Mesh.AddElement("NORMAL", 0, 3); Mesh.AddElement("TEXCOORD", 0, 2); Mesh.AddElement("COLOR", 0, 4, DataType.Byte, true); gNoBlendProgram = new ShaderProgram(context); gNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixel); gBlendProgram = new ShaderProgram(context); gBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlend); gIndoorNoBlendProgram = new ShaderProgram(context); gIndoorNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gIndoorNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelIndoor); gIndoorBlendProgram = new ShaderProgram(context); gIndoorBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gIndoorBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlendIndoor); Mesh.Program = gNoBlendProgram; }