public ImGuiRender(DX11 dx11, RenderForm form, CoreSettings coreSettings) { _form = form; Dx11 = dx11; CoreSettings = coreSettings; FormBounds = form.Bounds; using (new PerformanceTimer("Init ImGui")) { Initialize(); } sizeOfImDrawVert = Utilities.SizeOf <ImDrawVert>(); sizeOfImDrawIdx = Utilities.SizeOf <ushort>(); VertexBufferSize = 10000; IndexBufferSize = 30000; // Compile the vertex shader code. var vertexShaderByteCode = ShaderBytecode.CompileFromFile("Shaders\\ImGuiVertexShader.hlsl", "VS", "vs_4_0"); // Compile the pixel shader code. var pixelShaderByteCode = ShaderBytecode.CompileFromFile("Shaders\\ImGuiPixelShader.hlsl", "PS", "ps_4_0"); VertexShader = new VertexShader(Dx11.D11Device, vertexShaderByteCode); PixelShader = new PixelShader(Dx11.D11Device, pixelShaderByteCode); VertexBuffer = new Buffer(Dx11.D11Device, new BufferDescription { Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.VertexBuffer, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, SizeInBytes = VertexBufferSizeBytes }); IndexBuffer = new Buffer(Dx11.D11Device, new BufferDescription { Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.IndexBuffer, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, SizeInBytes = IndexBufferSizeBytes }); ConstantBuffer = new Buffer(Dx11.D11Device, new BufferDescription { BindFlags = BindFlags.ConstantBuffer, Usage = ResourceUsage.Dynamic, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, SizeInBytes = Utilities.SizeOf <Matrix4x4>() }); var inputElements = new[] { new InputElement { SemanticName = "POSITION", SemanticIndex = 0, Format = Format.R32G32_Float, Slot = 0, AlignedByteOffset = 0, Classification = InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new InputElement { SemanticName = "TEXCOORD", SemanticIndex = 0, Format = Format.R32G32_Float, Slot = 0, AlignedByteOffset = InputElement.AppendAligned, Classification = InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new InputElement { SemanticName = "COLOR", SemanticIndex = 0, Format = Format.R8G8B8A8_UNorm, Slot = 0, AlignedByteOffset = InputElement.AppendAligned, Classification = InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; Layout = new InputLayout(Dx11.D11Device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements); CreateStates(); UpdateConstantBuffer(); vertexShaderByteCode.Dispose(); pixelShaderByteCode.Dispose(); }
public SpritesRender(DX11 dx11, RenderForm form, CoreSettings setCoreSettings) { _form = form; _dx11 = dx11; VertexBufferSize = MaxElements * Utilities.SizeOf <Vertex>() * 4; IndexBufferSize = MaxElements * Utilities.SizeOf <uint>() * 6; // Compile the vertex shader code. ShaderBytecode vertexShaderByteCode = ShaderBytecode.CompileFromFile("Shaders\\VertexShader.hlsl", "VS", "vs_4_0"); // Compile the pixel shader code. ShaderBytecode pixelShaderByteCode = ShaderBytecode.CompileFromFile("Shaders\\PixelShader.hlsl", "PS", "ps_4_0"); VertexShader = new VertexShader(_dx11.D11Device, vertexShaderByteCode); PixelShader = new PixelShader(_dx11.D11Device, pixelShaderByteCode); VertexBuffer = new Buffer(_dx11.D11Device, new BufferDescription { Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.VertexBuffer, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, SizeInBytes = VertexBufferSizeBytes }); IndexBuffer = new Buffer(_dx11.D11Device, new BufferDescription { Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.IndexBuffer, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, SizeInBytes = IndexBufferSizeBytes }); ConstantBuffer = new Buffer(_dx11.D11Device, new BufferDescription { BindFlags = BindFlags.ConstantBuffer, Usage = ResourceUsage.Dynamic, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, SizeInBytes = Utilities.SizeOf <Vector2>() * 2 }); var inputElements = new[] { new InputElement { SemanticName = "POSITION", SemanticIndex = 0, Format = Format.R32G32_Float, Slot = 0, AlignedByteOffset = 0, Classification = InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new InputElement { SemanticName = "TEXCOORD", SemanticIndex = 0, Format = Format.R32G32_Float, Slot = 0, AlignedByteOffset = InputElement.AppendAligned, Classification = InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new InputElement { SemanticName = "COLOR", SemanticIndex = 0, // Format = Format.R32G32B32A32_Float, Format = Format.R8G8B8A8_UNorm, Slot = 0, AlignedByteOffset = InputElement.AppendAligned, Classification = InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; Layout = new InputLayout(_dx11.D11Device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements); vertexShaderByteCode.Dispose(); pixelShaderByteCode.Dispose(); CreateStates(); imagingFactory2 = new ImagingFactory2(); }