Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// vorher: // Allocate a swap chain descriptor. //DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 }; //swapChainDesc.Width = 0; // use automatic sizing //swapChainDesc.Height = 0; //swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format //swapChainDesc.Stereo = false; //swapChainDesc.SampleDesc.Count = 1; // don't use multi-sampling //swapChainDesc.SampleDesc.Quality = 0; //swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; //swapChainDesc.BufferCount = 2; // use double buffering to enable flip //swapChainDesc.Scaling = DXGI_SCALING_NONE; //swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // all apps must use this SwapEffect //swapChainDesc.Flags = 0; // nachher: DXGI_SWAP_CHAIN_DESC1 swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); swapChainDesc.Width = width; swapChainDesc.Height = height; swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 2; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
void DeviceResources::InitWindowSizeDependentResources(HWND hWnd) { HRESULT hr; RECT rc; GetClientRect(hWnd, &rc); UINT width = rc.right - rc.left; UINT height = rc.bottom - rc.top; // Identify the physical adapter (GPU or card) this device is runs on. ComPtr<IDXGIAdapter> dxgiAdapter; hr = m_dxgiDevice->GetAdapter(&dxgiAdapter); if (FAILED(hr)) { throw std::exception("Identification of IDXGIAdapter failed"); } // Get the factory object that created the DXGI device. ComPtr<IDXGIFactory2> dxgiFactory; hr = dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory)); if (FAILED(hr)) { throw std::exception("Get IDXGIFactory2 failed"); } // Allocate a swap chain descriptor. //DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 }; //swapChainDesc.Width = 0; // use automatic sizing //swapChainDesc.Height = 0; //swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format //swapChainDesc.Stereo = false; //swapChainDesc.SampleDesc.Count = 1; // don't use multi-sampling //swapChainDesc.SampleDesc.Quality = 0; //swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; //swapChainDesc.BufferCount = 2; // use double buffering to enable flip //swapChainDesc.Scaling = DXGI_SCALING_NONE; //swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // all apps must use this SwapEffect //swapChainDesc.Flags = 0; DXGI_SWAP_CHAIN_DESC1 swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); swapChainDesc.Width = width; swapChainDesc.Height = height; swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 2; // Get the final swap chain for this window from the DXGI factory. hr = dxgiFactory->CreateSwapChainForHwnd( m_d3dDevice.Get(), hWnd, &swapChainDesc, NULL, NULL, &m_dxgiSwapChain ); if (FAILED(hr)) { throw std::exception("Creation of IDXGISwapChain failed"); } // Ensure that DXGI doesn't queue more than one frame at a time (minimize power consumption). hr = m_dxgiDevice->SetMaximumFrameLatency(1); if (FAILED(hr)) { throw std::exception("Set MaximumFrameLatency failed"); } // Get the backbuffer for this window which is be the final 3D render target. ID3D11Texture2D* pBackBuffer; hr = m_dxgiSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer)); //GetBuffer(0, IID_PPV_ARGS(&backBuffer)); if (FAILED(hr)) { throw std::exception("Get BackBuffer failed"); } // Create a Direct2D target bitmap associated with the // swap chain back buffer and set it as the current target. D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1( D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), 96.0f, 96.0f ); ComPtr<IDXGISurface2> dxgiBackBuffer; hr = m_dxgiSwapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer)); hr = m_d2dContext->CreateBitmapFromDxgiSurface( dxgiBackBuffer.Get(), &bitmapProperties, &m_d2dRenderTargetBitmap ); m_d2dContext->SetTarget(m_d2dRenderTargetBitmap.Get()); hr = m_d3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &m_d3dRenderTargetView); if (FAILED(hr)) { throw std::exception("CreateRenderTargetView failed"); } // Create depth stencil texture D3D11_TEXTURE2D_DESC descDepth; ZeroMemory(&descDepth, sizeof(descDepth)); descDepth.Width = width; descDepth.Height = height; descDepth.MipLevels = 1; descDepth.ArraySize = 1; descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; descDepth.SampleDesc.Count = 1; descDepth.SampleDesc.Quality = 0; descDepth.Usage = D3D11_USAGE_DEFAULT; descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; hr = m_d3dDevice->CreateTexture2D(&descDepth, nullptr, &m_d3dDepthStencil); if (FAILED(hr)) { throw std::exception("CreateTexture2D failed"); } // Create the depth stencil view D3D11_DEPTH_STENCIL_VIEW_DESC descDSV; ZeroMemory(&descDSV, sizeof(descDSV)); descDSV.Format = descDepth.Format; descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; descDSV.Texture2D.MipSlice = 0; hr = m_d3dDevice->CreateDepthStencilView(m_d3dDepthStencil.Get(), &descDSV, &m_d3dDepthStencilView); if (FAILED(hr)) { throw std::exception("CreateDepthStencilView failed"); } m_d3dContext->OMSetRenderTargets(1, m_d3dRenderTargetView.GetAddressOf(), m_d3dDepthStencilView.Get()); // Setup the viewport // todo: wozu genau? (eingebaut, damit es in SpriteBatch.End() nicht knallt...) D3D11_VIEWPORT vp; vp.Width = (FLOAT)width; vp.Height = (FLOAT)height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; m_d3dContext->RSSetViewports(1, &vp); } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »BlueCobold« (02.10.2014, 07:10)
Hallo Legend,
danke für die Antwort.
Doofe Frage: welches Colorformat benötige ich nun? Und wieso benutze ich jetzt das falsche? Ich verstehe den Zusammenhang nicht
Gruß
n2k
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige