/// <summary> /// Create Direct3D device and swap chain /// </summary> public void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(host.Handle, out swapChain); // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }, null); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)host.ActualWidth, Height = (uint)host.ActualHeight, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.SetViewports(new Viewport[] { vp }); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> public void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(host.Handle); swapChain = device.SwapChain; // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)host.ActualWidth, Height = (uint)host.ActualHeight, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.Viewports = new Viewport[] { vp }; }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain); // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)directControl.ClientSize.Width, Height = (uint)directControl.ClientSize.Height, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.SetViewports(new Viewport[] { vp }); }
public static D3DBuffer CreateBuffer <T>(D3DDevice device, T[] vertices) where T : struct { int byteLength = Marshal.SizeOf(typeof(T)) * vertices.Length; IntPtr nativeVertex = Marshal.AllocHGlobal(byteLength); byte[] byteBuffer = new byte[byteLength]; for (int i = 0; i < vertices.Length; i++) { byte[] vertexData = RawSerialize(vertices[i]); Buffer.BlockCopy(vertexData, 0, byteBuffer, vertexData.Length * i, vertexData.Length); } Marshal.Copy(byteBuffer, 0, nativeVertex, byteLength); // build vertex buffer BufferDescription bdv = new BufferDescription() { Usage = Usage.Default, ByteWidth = (uint)(Marshal.SizeOf(typeof(T)) * vertices.Length), BindingOptions = BindingOptions.VertexBuffer, CpuAccessOptions = CpuAccessOptions.None, MiscellaneousResourceOptions = MiscellaneousResourceOptions.None }; SubresourceData vertexInit = new SubresourceData() { SystemMemory = nativeVertex }; return(device.CreateBuffer(bdv, vertexInit)); }
protected virtual void DisposeDirectXResources() { DwFactory?.Dispose(); RenderTarget?.Dispose(); D2DFactory?.Dispose(); D3DDevice?.Dispose(); }
//mxd. public Vector2D GetHitPosition() { Vector3D start = General.Map.VisualCamera.Position; Vector3D delta = General.Map.VisualCamera.Target - General.Map.VisualCamera.Position; delta = delta.GetFixedLength(General.Settings.ViewDistance * 0.98f); VisualPickResult target = PickObject(start, start + delta); if (target.picked == null) { return(new Vector2D(float.NaN, float.NaN)); } // Now find where exactly did we hit VisualGeometry vg = target.picked as VisualGeometry; if (vg != null) { return(GetIntersection(start, start + delta, vg.BoundingBox[0], new Vector3D(vg.Vertices[0].nx, vg.Vertices[0].ny, vg.Vertices[0].nz))); } VisualThing vt = target.picked as VisualThing; if (vt != null) { return(GetIntersection(start, start + delta, vt.CenterV3D, D3DDevice.V3D(vt.Center - vt.PositionV3))); } return(new Vector2D(float.NaN, float.NaN)); }
static Effect LoadResourceShader(D3DDevice device, string resourceName) { using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream(resourceName)) { return(device.CreateEffectFromCompiledBinary(stream)); } }
private void RenderContent() { if (!IsVisible) { return; } if (_operator == null || _operator.Outputs.Count <= 0) { return; } if (TimeLoggingSourceEnabled) { TimeLogger.BeginFrame(App.Current.Model.GlobalTime); } D3DDevice.BeginFrame(); try { var context = new OperatorPartContext(_defaultContext, (float)App.Current.Model.GlobalTime); // FIXME: the following lines are commented out to enable different values for debugOverlay-Variable //if (context.Time != _previousTime) //{ var invalidator = new OperatorPart.InvalidateInvalidatables(); _operator.Outputs[_shownOutputIndex].TraverseWithFunctionUseSpecificBehavior(null, invalidator); //_previousTime = context.Time; //} var evaluationType = _operator.Outputs[_shownOutputIndex].Type; switch (evaluationType) { case FunctionType.Scene: case FunctionType.Mesh: _renderSetup.Operator = _operator; var isMeshType = evaluationType == FunctionType.Mesh; _renderSetup.Render(context, _shownOutputIndex, ShowGridAndGizmos, isMeshType); _D3DImageContainer.InvalidateD3DImage(); break; case FunctionType.Image: _renderSetup.Operator = _operator; _renderSetup.RenderImage(context, _shownOutputIndex); _D3DImageContainer.InvalidateD3DImage(); break; } } catch (Exception exception) { Logger.Error(exception.ToString()); } D3DDevice.EndFrame(); if (TimeLoggingSourceEnabled) { TimeLogger.EndFrame(); } }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle); swapChain = device.SwapChain; // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)directControl.ClientSize.Width, Height = (uint)directControl.ClientSize.Height, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.Viewports = new Viewport[] { vp }; }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle); swapChain = device.SwapChain; SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial04.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; InitVertexLayout(); InitVertexBuffer(); InitIndexBuffer(); // Set primitive topology device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList; InitMatrices(); needsResizing = false; }
public override void Dispose() { D3DDevice.Dispose(); DxgiDevice.Dispose(); D2DDevice.Dispose(); base.Dispose(); }
/// <summary> /// Creates the mesh manager /// </summary> /// <param name="device"></param> public XMeshManager(D3DDevice device) { this.device = device; // Create the effect //XMesh.fxo was compiled from XMesh.fx using: // "$(DXSDK_DIR)utilities\bin\x86\fxc" "$(ProjectDir)Mesh\MeshLoaders\XMesh.fx" /T fx_4_0 /Fo"$(ProjectDir)Mesh\MeshLoaders\XMesh.fxo" using (Stream effectStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "Microsoft.WindowsAPICodePack.DirectX.DirectXUtilities.XMesh.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the techniques techniqueRenderTexture = effect.GetTechniqueByName("RenderTextured"); techniqueRenderVertexColor = effect.GetTechniqueByName("RenderVertexColor"); techniqueRenderMaterialColor = effect.GetTechniqueByName("RenderMaterialColor"); // Obtain the variables brightnessVariable = effect.GetVariableByName("Brightness").AsScalar; materialColorVariable = effect.GetVariableByName("MaterialColor").AsVector; worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; diffuseVariable = effect.GetVariableByName("tex2D").AsShaderResource; }
protected virtual void DisposeDirectXResources() { DwFactory.Dispose(); RenderTarget.Dispose(); RenderTargetView.Dispose(); D2DFactory.Dispose(); SwapChain.Dispose(); D3DDeviceContext.Dispose(); D3DDevice.Dispose(); }
void InitDevice() { // create Direct 3D device device = D3DDevice.CreateDeviceAndSwapChain(renderHost.Handle); swapChain = device.SwapChain; // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } // Create depth stencil texture Texture2DDescription descDepth = new Texture2DDescription() { Width = (uint)renderHost.ActualWidth, Height = (uint)renderHost.ActualHeight, MipLevels = 1, ArraySize = 1, Format = Format.D32Float, SampleDescription = new SampleDescription() { Count = 1, Quality = 0 }, BindingOptions = BindingOptions.DepthStencil, }; depthStencil = device.CreateTexture2D(descDepth); // Create the depth stencil view DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription() { Format = descDepth.Format, ViewDimension = DepthStencilViewDimension.Texture2D }; depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc); // bind the views to the device device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)renderHost.ActualWidth, Height = (uint)renderHost.ActualHeight, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.Viewports = new Viewport[] { vp }; }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle); swapChain = device.SwapChain; SetViews(); meshManager = new XMeshManager(device); InitMatrices(); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain); SetViews(); meshManager = new XMeshManager(device); mesh = meshManager.Open("Media\\Tiger\\tiger.x"); InitMatrices(); }
/// <summary> /// Creates a ShaderResourceView from a bitmap in a Stream. /// </summary> /// <param name="device">The Direct3D device that will own the ShaderResourceView</param> /// <param name="stream">Any Windows Imaging Component decodable image</param> /// <returns>A ShaderResourceView object with the loaded texture.</returns> public static ShaderResourceView LoadTexture( D3DDevice device, Stream stream ) { ImagingFactory factory = new ImagingFactory( ); BitmapDecoder bitmapDecoder = factory.CreateDecoderFromStream( stream, DecodeMetadataCacheOptions.OnDemand ); return LoadFromDecoder(device, factory, bitmapDecoder); }
public void Dispose() { renderTargetView.Dispose(); ImmediateContext.ClearState(); ImmediateContext.Flush(); ImmediateContext.Dispose(); D3DDevice.Dispose(); swapChain.Dispose(); }
void InitDevice() { // create Direct 3D device device = D3DDevice.CreateDeviceAndSwapChain(renderHost.Handle); swapChain = device.SwapChain; // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } // Create depth stencil texture Texture2DDescription descDepth = new Texture2DDescription() { Width = (uint)renderHost.ActualWidth, Height = (uint)renderHost.ActualHeight, MipLevels = 1, ArraySize = 1, Format = Format.D32Float, SampleDescription = new SampleDescription() { Count = 1, Quality = 0 }, BindingOptions = BindingOptions.DepthStencil, }; depthStencil = device.CreateTexture2D(descDepth); // Create the depth stencil view DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription() { Format = descDepth.Format, ViewDimension = DepthStencilViewDimension.Texture2D }; depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc); // bind the views to the device device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)renderHost.ActualWidth, Height = (uint)renderHost.ActualHeight, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.Viewports = new Viewport[] { vp }; }
/// <summary> /// Creates a ShaderResourceView from a bitmap in a Stream. /// </summary> /// <param name="device">The Direct3D device that will own the ShaderResourceView</param> /// <param name="stream">Any Windows Imaging Component decodable image</param> /// <returns>A ShaderResourceView object with the loaded texture.</returns> public static ShaderResourceView LoadTexture(D3DDevice device, Stream stream) { ImagingFactory factory = ImagingFactory.Create(); BitmapDecoder bitmapDecoder = factory.CreateDecoderFromStream( stream, DecodeMetadataCacheOption.OnDemand); return(LoadFromDecoder(device, factory, bitmapDecoder)); }
/// <summary> /// Creates a ShaderResourceView from a bitmap in a file. /// </summary> /// <param name="device">The Direct3D device that will own the ShaderResourceView</param> /// <param name="filePath">Any Windows Imaging Component decodable image</param> /// <returns>A ShaderResourceView object with the loaded texture.</returns> public static ShaderResourceView LoadTexture(D3DDevice device, String filePath) { ImagingFactory factory = new ImagingFactory(); BitmapDecoder bitmapDecoder = factory.CreateDecoderFromFilename( filePath, DesiredAccess.Read, DecodeMetadataCacheOptions.OnDemand); return LoadFromDecoder(device, factory, bitmapDecoder); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> public void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(host.Handle, out swapChain); SetViews(); meshManager = new XMeshManager(device); mesh = meshManager.Open("Media\\Tiger\\tiger.x"); InitMatrices(); needsResizing = false; }
/// <summary> /// Creates a ShaderResourceView from a bitmap in a file. /// </summary> /// <param name="device">The Direct3D device that will own the ShaderResourceView</param> /// <param name="filePath">Any Windows Imaging Component decodable image</param> /// <returns>A ShaderResourceView object with the loaded texture.</returns> public static ShaderResourceView LoadTexture(D3DDevice device, String filePath) { ImagingFactory factory = ImagingFactory.Create(); BitmapDecoder bitmapDecoder = factory.CreateDecoderFromFileName( filePath, DesiredAccess.Read, DecodeMetadataCacheOption.OnDemand); return(LoadFromDecoder(device, factory, bitmapDecoder)); }
/// <summary> /// This sets the position to use for the thing geometry. /// </summary> public void SetPosition(Vector3D pos) { position_v3 = D3DDevice.V3(pos); //mxd position = Matrix.Translation(position_v3); updategeo = true; updatecage = true; //mxd //mxd. update bounding box? if (lightType != null && lightRadius > thing.Size) { UpdateBoundingBox(lightRadius, lightRadius * 2); } }
public void Destroy() { Application.Idle -= OnTick; Screen.OnDisposeBuffers(); Screen.OnDispose(); BackbufferRTV.Dispose(); D3DDevice.Dispose(); DXGISwapChain.Dispose(); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> public void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(host.Handle); swapChain = device.SwapChain; SetViews(); meshManager = new XMeshManager(device); mesh = meshManager.Open("Media\\Tiger\\tiger.x"); InitMatrices(); needsResizing = false; }
protected override void OnCreatedDevice(D3DDevice d3dDevice, D3DDeviceContext d3dContext) { renderDevice = d3dDevice; renderDeviceContext = d3dContext; mediaShaderInput = new D3DInputLayout(d3dDevice, mediaShaderInputDesc, mediaShaderVertexBytecode); mediaShaderVertex = new D3DVertexShader(d3dDevice, mediaShaderVertexBytecode); mediaShaderPixel = new D3DPixelShader(d3dDevice, mediaPixelShaderBytecode); mediaConstantBuffer = D3DBuffer.Create(d3dDevice, D3DBind.ConstantBuffer, D3DUsage.Default, D3DAccess.None, typeof(MediaConstantBuffer)); mediaVertexBuffer = D3DBuffer.Create(d3dDevice, D3DBind.VertexBuffer, D3DUsage.Dynamic, D3DAccess.Write, mediaVertices); mediaFrameTextureSampler = new D3DSamplerState(d3dDevice, D3DTextureAddressing.Clamp, D3DTextureAddressing.Clamp, D3DTextureFiltering.Anisotropic, 16); mediaFrameRasterizing = new D3DRasterizerState(d3dDevice, D3DFill.Solid, D3DCull.Back, true); mediaFrameBlending = new D3DBlendState(d3dDevice); var pathVariable = Environment.GetEnvironmentVariable("PATH"); Environment.SetEnvironmentVariable("PATH", $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\FFmpeg\\;{pathVariable}"); ffmpegEngine = new FFmpegEngine(HandleMediaEvent); // rtsp_transport tcp // thread_queue_size 1024 // buffer_size 31250000 // max_delay 5000000 // reorder_queue_size 1000 ffmpegEngine.SetSourceOption("hw", "true"); ffmpegEngine.SetSourceOption("rtsp_transport", "tcp"); ffmpegEngine.SetSourceOption("stimeout", "2000000"); // TCP I/O timeout [us] //ffmpegEngine.SetSource("rtsp://*****:*****@192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1"); ffmpegEngine.SetSource("rtsp://*****:*****@192.168.1.66:554/onvif-media/media.amp"); ffmpegEngine.Play(); }
private void Update() { var time = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetPosition(_soundStream, BASSMode.BASS_POS_BYTES)); if (time >= _soundLength) { if (_settings.Looped) { Bass.BASS_ChannelSetPosition(_soundStream, 0); } else if (!_exitTimer.IsRunning) { _exitTimer.Restart(); } else if (_exitTimer.ElapsedMilliseconds >= 2000) { _form.Close(); } } // try { // _undoRedoStack.ProcessReceivedCommands(); // } // catch (Exception exception) { // Logger.Warn("Error when excecuting remote command: {0}", exception.Message); // } //double time = (double)_globalTime.ElapsedTicks / Stopwatch.Frequency; TimeLogger.BeginFrame(time); D3DDevice.BeginFrame(); DrawFrame((float)time); D3DDevice.SwapChain.Present(_settings.VSyncEnabled ? 1 : 0, PresentFlags.None); Int64 elapsedTicks = _stopwatch.ElapsedTicks; Console.Write("time: {0:000.000}, fps: {1:000.0} ({2:000.0}/{3:000.0}), resources used: {4,2}, free: {5,2} \r", time, (double)_numMeasureValues * Stopwatch.Frequency / _averagedElapsed.Sum(e => e), (double)Stopwatch.Frequency / _averagedElapsed.Max(), (double)Stopwatch.Frequency / _averagedElapsed.Min(), ResourceManager.NumUsedResources, ResourceManager.NumFreeResources); _averagedElapsed[_currentAveragedElapsedIndex] = elapsedTicks; _currentAveragedElapsedIndex++; _currentAveragedElapsedIndex %= _numMeasureValues; _stopwatch.Restart(); D3DDevice.EndFrame(); TimeLogger.EndFrame(); }
/// <summary> /// Creates Direct3D device and swap chain, /// Initializes buffers, /// Loads and initializes the shader /// </summary> protected void InitializeDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle); swapChain = device.SwapChain; SetViews(); effects = new Effects(device); InitializeVertexLayout(); InitializeVertexBuffer(); InitializeIndexBuffer(); // Set primitive topology device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList; effects.ViewMatrix = DXUtil.Camera.MatrixLookAtLH(Eye, At, Up); effects.ProjectionMatrix = DXUtil.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.25f, ((float)this.ClientSize.Width / (float)this.ClientSize.Height), 0.1f, 4000.0f); }
/// <summary> /// Iniciar shaders comunes. /// </summary> /// <param name="shadersPath">Ruta donde estan los Shaders comunes.</param> /// <param name="d3dDevice">Device.</param> public void LoadCommonShaders(string shadersPath, D3DDevice d3dDevice) { CommonShadersPath = shadersPath; D3DDevice = d3dDevice; //Cargar shaders genericos para todo el framework. TgcMeshShader = LoadEffect(shadersPath + "TgcMeshShader.fx"); TgcMeshPhongShader = LoadEffect(shadersPath + "TgcMeshPhongShader.fx"); TgcMeshPointLightShader = LoadEffect(shadersPath + "TgcMeshPointLightShader.fx"); TgcMeshSpotLightShader = LoadEffect(shadersPath + "TgcMeshSpotLightShader.fx"); TgcSkeletalMeshShader = LoadEffect(shadersPath + "TgcSkeletalMeshShader.fx"); TgcSkeletalMeshPointLightShader = LoadEffect(shadersPath + "TgcSkeletalMeshPointLightShader.fx"); TgcKeyFrameMeshShader = LoadEffect(shadersPath + "TgcKeyFrameMeshShader.fx"); VariosShader = LoadEffect(shadersPath + "Varios.fx"); //Crear vertexDeclaration comunes. VdecPositionColoredTextured = new VertexDeclaration(d3dDevice.Device, PositionColoredTextured_VertexElements); VdecPositionTextured = new VertexDeclaration(d3dDevice.Device, PositionTextured_VertexElements); VdecPositionColored = new VertexDeclaration(d3dDevice.Device, PositionColored_VertexElements); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice1.CreateDeviceAndSwapChain1(host.Handle); swapChain = device.SwapChain; SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial07.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; meshColorVariable = effect.GetVariableByName("vMeshColor").AsVector; diffuseVariable = effect.GetVariableByName("txDiffuse").AsShaderResource; InitVertexLayout(); InitVertexBuffer(); InitIndexBuffer(); // Set primitive topology device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList; // Load the Texture using (FileStream stream = File.OpenRead("seafloor.png")) { textureRV = TextureLoader.LoadTexture(device, stream); } InitMatrices(); diffuseVariable.Resource = textureRV; needsResizing = false; }
/// <summary> /// 終了する。 /// </summary> public virtual void Dispose() { if (!D3DDeviceContext.IsDisposed && D3DDeviceContext.Rasterizer.State != null && !D3DDeviceContext.Rasterizer.State.IsDisposed) { D3DDeviceContext.Rasterizer.State.Dispose(); } if (D3DDevice != null && !D3DDevice.IsDisposed) { D3DDevice.Dispose(); } if (Adapter != null && !Adapter.IsDisposed) { Adapter.Dispose(); } if (DXGIFactory != null && !DXGIFactory.IsDisposed) { DXGIFactory.Dispose(); } }
private void InitializeDX() { //perform DX Device and Context initialization HwndSource hwnd = new HwndSource(0, 0, 0, 0, 0, "dxPlotterElement", IntPtr.Zero); device = D3DDevice.CreateDeviceAndSwapChain(hwnd.Handle); swapChain = device.SwapChain; deviceContext = device.ImmediateContext; CompositionTarget.Rendering += OnRenderingProccessReady; Texture2DDescription tdesc = new Texture2DDescription { ArraySize = 1, Width = 1, Height = 1, Format = Format.B8G8R8A8UNorm, MipLevels = 1, SampleDescription = new SampleDescription { Count = 1, Quality = 0 }, Usage = Usage.Default, BindingOptions = BindingOptions.RenderTarget | BindingOptions.ShaderResource, MiscellaneousResourceOptions = MiscellaneousResourceOptions.Shared, CpuAccessOptions = CpuAccessOptions.None }; using (Texture2D texture2D = device.CreateTexture2D(tdesc)) { renderTargetView = device.CreateRenderTargetView(texture2D); deviceContext.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }); d3dImage.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, texture2D.NativeInterface); } dxInitialized = true; OnDeviceInitialized(); }
public Effects(D3DDevice device) { // File compiled using the following command: // "$(DXSDK_DIR)\utilities\bin\x86\fxc" "WindowsFlag.fx" /T fx_4_0 /Fo "WindowsFlag.fxo" using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFlag.WindowsFlag.fxo")) { effect = device.CreateEffectFromCompiledBinary(stream); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix(); viewVariable = effect.GetVariableByName("View").AsMatrix(); projectionVariable = effect.GetVariableByName("Projection").AsMatrix(); lightDirVariable = effect.GetVariableByName("vLightDir").AsVector(); lightColorVariable = effect.GetVariableByName("vLightColor").AsVector(); baseColorVariable = effect.GetVariableByName("vBaseColor").AsVector(); // Set constants lightColorVariable.SetFloatVectorArray(vLightColors); lightDirVariable.SetFloatVectorArray(vLightDirs); }
/// <summary> /// Creates a DirectX 10 device and related device specific resources. /// </summary> /// <exception cref="InvalidOperationException"> /// A previous call to CreateResources has not been followed by a call to /// <see cref="FreeResources" />. /// </exception> /// <exception cref="ObjectDisposedException"> /// <see cref="Dispose()" /> has been called on this instance. /// </exception> /// <exception cref="Microsoft.WindowsAPICodePack.DirectX.DirectXException"> /// Unable to create a DirectX 10 device or an error occured creating /// device dependent resources. /// </exception> public void CreateResources() { MustNotDisposed(); if (_device != null) { throw new InvalidOperationException( "A previous call to CreateResources has not been followed by a call to FreeResources."); } // Try to create a hardware device first and fall back to a // software (WARP doens't let us share resources) D3DDevice1 device1 = TryCreateDevice1(DriverType.Hardware); if (device1 == null) { device1 = TryCreateDevice1(DriverType.Software); if (device1 == null) { throw new DirectXException("Unable to create a DirectX 10 device."); } } _device = device1.QueryInterface <D3DDevice>(); device1.Dispose(); }
public Effects(D3DDevice device) { // File compiled using the following command: // "$(DXSDK_DIR)\utilities\bin\x86\fxc" "WindowsFlag.fx" /T fx_4_0 /Fo "WindowsFlag.fxo" using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFlag.WindowsFlag.fxo")) { effect = device.CreateEffectFromCompiledBinary(stream); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; lightDirVariable = effect.GetVariableByName("vLightDir").AsVector; lightColorVariable = effect.GetVariableByName("vLightColor").AsVector; baseColorVariable = effect.GetVariableByName("vBaseColor").AsVector; // Set constants lightColorVariable.SetFloatVectorArray(vLightColors); lightDirVariable.SetFloatVectorArray(vLightDirs); }
public void RenderContent() { if (RenderConfig.Operator == null || RenderConfig.Operator.Outputs.Count <= 0) { return; } D3DDevice.BeginFrame(); try { var context = new OperatorPartContext( _defaultContext, (float)(App.Current.Model.GlobalTime + RenderConfig.TimeScrubOffset)); var invalidator = new OperatorPart.InvalidateInvalidatables(); RenderConfig.Operator.Outputs[RenderConfig.ShownOutputIndex].TraverseWithFunctionUseSpecificBehavior(null, invalidator); var evaluationType = RenderConfig.Operator.Outputs[RenderConfig.ShownOutputIndex].Type; switch (evaluationType) { case FunctionType.Float: RenderValuePlot(context, RenderConfig); break; case FunctionType.Scene: Action <OperatorPartContext, int> lambdaForScenes = (OperatorPartContext context2, int outputIdx) => { RenderConfig.Operator.Outputs[outputIdx].Eval(context); }; RenderGeometry( context, lambdaForScenes); break; case FunctionType.Mesh: { Action <OperatorPartContext, int> lambdaForMeshes = (OperatorPartContext context2, int outputIdx) => { var mesh = RenderConfig.Operator.Outputs[outputIdx].Eval(context2).Mesh; context2.Renderer.SetupEffect(context2); context2.Renderer.Render(mesh, context2); }; RenderGeometry( context, lambdaForMeshes); break; } case FunctionType.Image: SetupContextForRenderingImage( context, RenderConfig.RenderWithGammaCorrection); var image = RenderConfig.Operator.Outputs[RenderConfig.ShownOutputIndex].Eval(new OperatorPartContext(context)).Image; if (image == null) { break; } RenderedImageIsACubemap = image.Description.ArraySize > 1; var cubeMapSide = RenderedImageIsACubemap ? RenderConfig.PreferredCubeMapSideIndex : -1; if (cubeMapSide == 6) { RenderCubemapAsSphere(image, context); } else { RenderImage(image, context); } break; } _D3DImageContainer.InvalidateD3DImage(); } catch (Exception exception) { Logger.Error(exception.ToString()); } D3DDevice.EndFrame(); }
public override void BindToPass(D3DDevice device, Effect effect, int passIndex) { BindToSetupPass(device, effect, passIndex); }
private void BindToSetupPass(D3DDevice device, Effect effect, int passIndex) { gsOutput = new GeometryOutputStream<VertexTypes.Pos3Norm3Tex3>(device.Device, effect[passIndex], this.Indices.Length); base.BindToPass(device, effect, passIndex); CreateMinimapTarget(); }
public RenderTarget(D3DDevice device, int width, int height) : base(device.Device) { Resource = D3D.Texture2D.FromSwapChain<D3D.Texture2D>(device.SwapChain, 0); RenderView = new D3D.RenderTargetView(device.Device, Resource); }
private static ShaderResourceView LoadFromDecoder(D3DDevice device, ImagingFactory factory, BitmapDecoder bitmapDecoder) { if (bitmapDecoder.FrameCount == 0) throw new ArgumentException("Image file successfully loaded, but it has no image frames."); BitmapFrameDecode bitmapFrameDecode = bitmapDecoder.GetFrame(0); BitmapSource bitmapSource = bitmapFrameDecode.ToBitmapSource(); // create texture description Texture2DDescription textureDescription = new Texture2DDescription() { Width = bitmapSource.Size.Width, Height = bitmapSource.Size.Height, MipLevels = 1, ArraySize = 1, Format = Format.R8G8B8A8_UNORM, SampleDescription = new SampleDescription() { Count = 1, Quality = 0, }, Usage = Usage.Dynamic, BindFlags = BindFlag.ShaderResource, CpuAccessFlags = CpuAccessFlag.Write, MiscFlags = 0 }; // create texture Texture2D texture = device.CreateTexture2D(textureDescription); // Create a format converter WICFormatConverter converter = factory.CreateFormatConverter(); converter.Initialize( bitmapSource, PixelFormats.Pf32bppRGBA, BitmapDitherType.None, BitmapPaletteType.Custom); // get bitmap data byte[] buffer = converter.CopyPixels(); // Copy bitmap data to texture MappedTexture2D texmap = texture.Map(0, Map.WriteDiscard, MapFlag.Unspecified); Marshal.Copy(buffer, 0, texmap.Data, buffer.Length); texture.Unmap(0); // create shader resource view description ShaderResourceViewDescription srvDescription = new ShaderResourceViewDescription() { Format = textureDescription.Format, ViewDimension = ShaderResourceViewDimension.Texture2D, Texture2D = new Texture2DShaderResourceView() { MipLevels = textureDescription.MipLevels, MostDetailedMip = 0 } }; // create shader resource view from texture return device.CreateShaderResourceView(texture, srvDescription); }
/// <summary> /// Init device and required resources /// </summary> private void InitDevice() { // device creation device = D3DDevice.CreateDeviceAndSwapChain(host.Handle); swapChain = device.SwapChain; deviceContext = device.ImmediateContext; SetViews(); // vertex shader & layout // Open precompiled vertex shader // This file was compiled using: fxc Render.hlsl /T vs_4_0 /EVertShader /FoRender.vs using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs")) { vertexShader = device.CreateVertexShader(stream); deviceContext.VS.Shader = vertexShader; // input layout is for the vert shader InputElementDescription inputElementDescription = new InputElementDescription(); inputElementDescription.SemanticName = "POSITION"; inputElementDescription.SemanticIndex = 0; inputElementDescription.Format = Format.R32G32B32Float; inputElementDescription.InputSlot = 0; inputElementDescription.AlignedByteOffset = 0; inputElementDescription.InputSlotClass = InputClassification.PerVertexData; inputElementDescription.InstanceDataStepRate = 0; stream.Position = 0; InputLayout inputLayout = device.CreateInputLayout( new InputElementDescription[] { inputElementDescription }, stream); deviceContext.IA.InputLayout = inputLayout; } // Open precompiled vertex shader // This file was compiled using: fxc Render.hlsl /T ps_4_0 /EPixShader /FoRender.ps using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.ps")) { pixelShader = device.CreatePixelShader(stream); } deviceContext.PS.SetShader(pixelShader, null); // create some geometry to draw (1 triangle) SimpleVertexArray vertex = new SimpleVertexArray(); // put the vertices into a vertex buffer BufferDescription bufferDescription = new BufferDescription(); bufferDescription.Usage = Usage.Default; bufferDescription.ByteWidth = (uint)Marshal.SizeOf(vertex); bufferDescription.BindingOptions = BindingOptions.VertexBuffer; SubresourceData subresourceData = new SubresourceData(); IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex)); Marshal.StructureToPtr(vertex, vertexData, false); subresourceData.SystemMemory = vertexData; vertexBuffer = device.CreateBuffer(bufferDescription, subresourceData); deviceContext.IA.SetVertexBuffers(0, new D3DBuffer[] { vertexBuffer }, new uint[] { 12 }, new uint[] { 0 }); deviceContext.IA.PrimitiveTopology = PrimitiveTopology.TriangleList; Marshal.FreeCoTaskMem(vertexData); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(this.Handle); swapChain = device.SwapChain; // Create a render target view using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0)) { renderTargetView = device.CreateRenderTargetView(pBuffer); } device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null); // Setup the viewport Viewport vp = new Viewport() { Width = (uint)this.ClientSize.Width, Height = (uint)this.ClientSize.Height, MinDepth = 0.0f, MaxDepth = 1.0f, TopLeftX = 0, TopLeftY = 0 }; device.RS.Viewports = new Viewport[] { vp }; }
private void UpdateLocalShownContent() { //if (_showSceneControl == null) // return; //var op = _showSceneControl.Operator; //var d3DScene = _showSceneControl.RenderSetup; if (_renderConfig == null || _renderConfig.Operator == null || _renderConfig.Operator.Outputs.Count <= 0) { return; } //var op = d3DScene.RenderedOperator; var op = _renderConfig.Operator; D3DDevice.WindowSize = new SharpDX.Size2(Size.Width, Size.Height); D3DDevice.TouchWidth = Size.Width; D3DDevice.TouchHeight = Size.Height; TimeLogger.BeginFrame(CurrentTime); D3DDevice.BeginFrame(); ProcessKeyEvents(); try { var context = new OperatorPartContext(_defaultContext, (float)CurrentTime); if (Math.Abs(context.Time - _previousTime) > Constants.Epsilon) { var invalidator = new OperatorPart.InvalidateInvalidatables(); op.Outputs[0].TraverseWithFunctionUseSpecificBehavior(null, invalidator); _previousTime = context.Time; } context.D3DDevice = D3DDevice.Device; context.RenderTargetView = _renderTargetView; context.DepthStencilState = _renderer.DefaultDepthStencilState; context.BlendState = _renderer.DefaultBlendState; context.RasterizerState = _renderer.DefaultRasterizerState; context.SamplerState = _renderer.DefaultSamplerState; context.Viewport = _viewport; context.Texture0 = _shaderResourceView; var worldToCamera = Matrix.LookAtLH(_renderConfig.CameraSetup.Position, _renderConfig.CameraSetup.Target, _renderConfig.CameraSetup.UpDir); switch (op.FunctionType) { case FunctionType.Scene: context.Effect = _renderer.SceneDefaultEffect; context.InputLayout = _renderer.SceneDefaultInputLayout; context.DepthStencilView = _depthStencilView; D3DRenderSetup.SetupContextForRenderingCamToBuffer(context, op, _renderer, worldToCamera); op.Outputs[0].Eval(context); break; case FunctionType.Image: context.Effect = _renderer.ScreenRenderEffect; context.InputLayout = _renderer.ScreenQuadInputLayout; context.DepthStencilView = null; D3DRenderSetup.SetupContextForRenderingCamToBuffer(context, op, _renderer, worldToCamera); var image = op.Outputs[0].Eval(new OperatorPartContext(context)).Image; if (image != null) { _renderer.SetupBaseEffectParameters(context); _renderer.RenderToScreen(image, context); } break; } _swapChain.Present(1, PresentFlags.None); D3DDevice.EndFrame(); TimeLogger.EndFrame(); } catch (Exception exception) { Logger.Error("Exception while in fullscreen:\n", exception.ToString()); } }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain); SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial04.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix(); viewVariable = effect.GetVariableByName("View").AsMatrix(); projectionVariable = effect.GetVariableByName("Projection").AsMatrix(); InitVertexLayout(); InitVertexBuffer(); InitIndexBuffer(); // Set primitive topology device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList); InitMatrices(); needsResizing = false; }
/// <summary> /// Creates Direct3D device and swap chain, /// Initializes buffers, /// Loads and initializes the shader /// </summary> protected void InitializeDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain); SetViews(); effects = new Effects(device); InitializeVertexLayout(); InitializeVertexBuffer(); InitializeIndexBuffer(); // Set primitive topology device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList); effects.ViewMatrix = DXUtil.Camera.MatrixLookAtLH(Eye, At, Up); effects.ProjectionMatrix = DXUtil.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.25f, ((float)this.ClientSize.Width / (float)this.ClientSize.Height), 0.1f, 4000.0f); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain); SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial02.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Define the input layout InputElementDescription[] layout = { new InputElementDescription() { SemanticName = "POSITION", SemanticIndex = 0, Format = Format.R32G32B32_FLOAT, InputSlot = 0, AlignedByteOffset = 0, InputSlotClass = InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; PassDescription passDesc = technique.GetPassByIndex(0).Description; vertexLayout = device.CreateInputLayout( layout, passDesc.InputAssemblerInputSignature, passDesc.InputAssemblerInputSignatureSize); device.IA.SetInputLayout(vertexLayout); SimpleVertexArray vertex = new SimpleVertexArray(); BufferDescription bd = new BufferDescription() { Usage = Usage.Default, ByteWidth = (uint)Marshal.SizeOf(vertex), BindFlags = BindFlag.VertexBuffer, CpuAccessFlags = 0, MiscFlags = 0 }; IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex)); Marshal.StructureToPtr(vertex, vertexData, false); SubresourceData InitData = new SubresourceData() { SysMem = vertexData, SysMemPitch = 0, SysMemSlicePitch = 0 }; //D3DBuffer buffer = null; vertexBuffer = device.CreateBuffer(bd, InitData); // Set vertex buffer uint stride = (uint)Marshal.SizeOf(typeof(Vector3F)); uint offset = 0; device.IA.SetVertexBuffers(0, new Collection<D3DBuffer>() { vertexBuffer }, new uint[] { stride }, new uint[] { offset }); // Set primitive topology device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList); Marshal.FreeCoTaskMem(vertexData); }
public void BindToRenderPass(D3DDevice device, Effect effect, int passIndex) { renderPassIndex = passIndex; renderPassLayout = VertexTypes.GetInputLayout(this.Device.Device, effect[passIndex], typeof(VertexTypes.Pos3Norm3Tex3)); }
static Effect LoadResourceShader(D3DDevice device, string resourceName) { using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream(resourceName)) { return device.CreateEffectFromCompiledBinary(stream); } }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle); swapChain = device.SwapChain; SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial06.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); techniqueLight = effect.GetTechniqueByName("RenderLight"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; lightDirVariable = effect.GetVariableByName("vLightDir").AsVector; lightColorVariable = effect.GetVariableByName("vLightColor").AsVector; outputColorVariable = effect.GetVariableByName("vOutputColor").AsVector; InitVertexLayout(); InitVertexBuffer(); InitIndexBuffer(); // Set primitive topology device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList; InitMatrices(); }
/// <summary> /// Constructor that associates a device with the resulting mesh /// </summary> /// <param name="device"></param> public XMeshTextLoader( D3DDevice device ) { this.device = device; }
private void InitializeDX() { //perform DX Device and Context initialization HwndSource hwnd = new HwndSource(0, 0, 0, 0, 0, "dxPlotterElement", IntPtr.Zero); device = D3DDevice.CreateDeviceAndSwapChain(hwnd.Handle, out swapChain); deviceContext = device.GetImmediateContext(); CompositionTarget.Rendering += OnRenderingProccessReady; Texture2DDescription tdesc = new Texture2DDescription { ArraySize = 1, Width = 1, Height = 1, Format = Format.B8G8R8A8_UNORM, MipLevels = 1, SampleDescription = new SampleDescription { Count = 1, Quality = 0 }, Usage = Usage.Default, BindFlags = BindFlag.RenderTarget | BindFlag.ShaderResource, MiscFlags = ResourceMiscFlag.Shared, CpuAccessFlags = 0 }; using (Texture2D texture2D = device.CreateTexture2D(tdesc)) { renderTargetView = device.CreateRenderTargetView(texture2D); deviceContext.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }); d3dImage.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, texture2D.NativeInterface); } dxInitialized = true; OnDeviceInitialized(); }
private void InitDevice() { // device creation //device = D3DDevice.CreateDeviceAndSwapChain( // null, // DriverType.Hardware, // null, // CreateDeviceFlag.Default, // new []{FeatureLevel.FeatureLevel_10_1}, // new SwapChainDescription { // BufferCount = 1 // }, // out swapChain); device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain); deviceContext = device.GetImmediateContext(); SetViews(); // Open precompiled vertex shader // This file was compiled using: fxc Render.hlsl /T vs_4_0 /EVertShader /FoRender.vs using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs")) { vertexShader = device.CreateVertexShader(stream); } deviceContext.VS.SetShader(vertexShader, null); // input layout is for the vert shader InputElementDescription inputElementDescription = new InputElementDescription(); inputElementDescription.SemanticName = "POSITION"; inputElementDescription.SemanticIndex = 0; inputElementDescription.Format = Format.R32G32B32_FLOAT; inputElementDescription.InputSlot = 0; inputElementDescription.AlignedByteOffset = 0; inputElementDescription.InputSlotClass = InputClassification.PerVertexData; inputElementDescription.InstanceDataStepRate = 0; InputLayout inputLayout; using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.vs")) { inputLayout = device.CreateInputLayout(new [] { inputElementDescription }, stream); } deviceContext.IA.SetInputLayout(inputLayout); // Open precompiled pixel shader // This file was compiled using: fxc Render.hlsl /T ps_4_0 /EPixShader /FoRender.ps using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.WindowsAPICodePack.Samples.Direct3D11.Render.ps")) { pixelShader = device.CreatePixelShader(stream); } deviceContext.PS.SetShader(pixelShader, null); // create some geometry to draw (1 triangle) SimpleVertexArray vertex = new SimpleVertexArray(); // put the vertices into a vertex buffer BufferDescription bufferDescription = new BufferDescription(); bufferDescription.Usage = Usage.Default; bufferDescription.ByteWidth = (uint)Marshal.SizeOf(vertex); bufferDescription.BindFlags = BindFlag.VertexBuffer; SubresourceData subresourceData = new SubresourceData(); IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex)); Marshal.StructureToPtr(vertex, vertexData, false); subresourceData.SysMem = vertexData; vertexBuffer = device.CreateBuffer(bufferDescription, subresourceData); deviceContext.IA.SetVertexBuffers(0, new [] { vertexBuffer }, new uint[] { 12 }, new uint[] { 0 }); deviceContext.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList); Marshal.FreeCoTaskMem(vertexData); }