Texture::~Texture() { #ifndef ARCH_PSP if (glTexId) { glDeleteTextures(1, (GLuint *)&glTexId); } #endif #if !defined(ARCH_DC) && !defined(ARCH_PSP) && !defined(OPENGL_ES) if (render_srf) { destroyRenderTarget(); } #endif };
//--------------------------------------------------------------------------------------------- void RenderSystem::destroyRenderTexture(const String& name) { destroyRenderTarget(name); }
//--------------------------------------------------------------------------------------------- void RenderSystem::destroyRenderWindow(const String& name) { destroyRenderTarget(name); }
void egResize() { if (!pBoundDevice) return; if (pBoundDevice->pRenderTargetView) pBoundDevice->pRenderTargetView->lpVtbl->Release(pBoundDevice->pRenderTargetView); // Delete buffers pBoundDevice->pSwapChain->lpVtbl->ResizeBuffers(pBoundDevice->pSwapChain, 0, 0, 0, DXGI_FORMAT_UNKNOWN, 0); for (uint32_t i = 0; i < 4; ++i) { SEGRenderTarget2D *pRenderTarget = pBoundDevice->gBuffer + i; destroyRenderTarget(pRenderTarget); } for (uint32_t i = 0; i < 8; ++i) { for (uint32_t k = 0; k < 2; ++k) { SEGRenderTarget2D *pRenderTarget = &pBoundDevice->blurBuffers[i][k]; destroyRenderTarget(pRenderTarget); } } destroyRenderTarget(&pBoundDevice->accumulationBuffer); ID3D11Texture2D *pBackBuffer; ID3D11Resource *pBackBufferRes; // Create render target pBoundDevice->pSwapChain->lpVtbl->GetBuffer(pBoundDevice->pSwapChain, 0, &IID_ID3D11Texture2D, (void**)&pBackBuffer); pBoundDevice->pSwapChain->lpVtbl->GetBuffer(pBoundDevice->pSwapChain, 0, &IID_ID3D11Resource, (void**)&pBackBufferRes); pBoundDevice->pDevice->lpVtbl->CreateRenderTargetView(pBoundDevice->pDevice, pBackBufferRes, NULL, &pBoundDevice->pRenderTargetView); pBackBuffer->lpVtbl->GetDesc(pBackBuffer, &pBoundDevice->backBufferDesc); pBackBufferRes->lpVtbl->Release(pBackBufferRes); pBackBuffer->lpVtbl->Release(pBackBuffer); // Recreate buffers // Create our G-Buffer createRenderTarget(pBoundDevice->gBuffer + G_DIFFUSE, pBoundDevice->backBufferDesc.Width, pBoundDevice->backBufferDesc.Height, DXGI_FORMAT_R8G8B8A8_UNORM); createRenderTarget(pBoundDevice->gBuffer + G_DEPTH, pBoundDevice->backBufferDesc.Width, pBoundDevice->backBufferDesc.Height, DXGI_FORMAT_R32_FLOAT); createRenderTarget(pBoundDevice->gBuffer + G_NORMAL, pBoundDevice->backBufferDesc.Width, pBoundDevice->backBufferDesc.Height, DXGI_FORMAT_R8G8B8A8_UNORM); createRenderTarget(pBoundDevice->gBuffer + G_MATERIAL, pBoundDevice->backBufferDesc.Width, pBoundDevice->backBufferDesc.Height, DXGI_FORMAT_R8G8B8A8_UNORM); // Accumulation buffer. This is an HDR texture createRenderTarget(&pBoundDevice->accumulationBuffer, pBoundDevice->backBufferDesc.Width, pBoundDevice->backBufferDesc.Height, DXGI_FORMAT_R16G16B16A16_FLOAT); // DXGI_FORMAT_R11G11B10_FLOAT // Create blur buffers for (int i = 0; i < 8; ++i) { UINT divider = (UINT)pow(2, (double)i); for (int k = 0; k < 2; ++k) { UINT w = pBoundDevice->backBufferDesc.Width / divider; UINT h = pBoundDevice->backBufferDesc.Height / divider; createRenderTarget(&pBoundDevice->blurBuffers[i][k], w, h, DXGI_FORMAT_R8G8B8A8_UNORM); } } }
void egDestroyDevice(EGDevice *pDeviceID) { SEGDevice *pDevice = devices + (*pDeviceID - 1); if (pDevice->bIsInBatch) return; // Textures for (uint32_t i = 0; i < pDevice->textureCount; ++i) { SEGTexture2D *pTexture = pDevice->textures + i; destroyTexture(pTexture); } free(pDevice->textures); for (uint32_t i = 0; i < 3; ++i) { SEGTexture2D *pTexture = pDevice->pDefaultTextureMaps + i; destroyTexture(pTexture); } destroyTexture(&pDevice->transparentBlackTexture); // Render targets for (uint32_t i = 0; i < 4; ++i) { SEGRenderTarget2D *pRenderTarget = pDevice->gBuffer + i; destroyRenderTarget(pRenderTarget); } for (uint32_t i = 0; i < 8; ++i) { for (uint32_t k = 0; k < 2; ++k) { SEGRenderTarget2D *pRenderTarget = &pDevice->blurBuffers[i][k]; destroyRenderTarget(pRenderTarget); } } destroyRenderTarget(&pBoundDevice->accumulationBuffer); // VBO for (int i = 0; i < 8; ++i) { if (pDevice->pVertexBufferResources[i]) pDevice->pVertexBufferResources[i]->lpVtbl->Release(pDevice->pVertexBufferResources[i]); if (pDevice->pVertexBuffers[i]) pDevice->pVertexBuffers[i]->lpVtbl->Release(pDevice->pVertexBuffers[i]); } if (pDevice->pCurrentBatchVertices) free(pDevice->pCurrentBatchVertices); // Constant buffers if (pDevice->pCBModel) pDevice->pCBModel->lpVtbl->Release(pDevice->pCBModel); if (pDevice->pCBViewProj) pDevice->pCBViewProj->lpVtbl->Release(pDevice->pCBViewProj); if (pDevice->pCBInvViewProj) pDevice->pCBInvViewProj->lpVtbl->Release(pDevice->pCBInvViewProj); if (pDevice->pCBAlphaTestRef) pDevice->pCBAlphaTestRef->lpVtbl->Release(pDevice->pCBAlphaTestRef); if (pDevice->pCBOmni) pDevice->pCBOmni->lpVtbl->Release(pDevice->pCBOmni); if (pDevice->pCBBlurSpread) pDevice->pCBBlurSpread->lpVtbl->Release(pDevice->pCBBlurSpread); // Input layouts if (pDevice->pInputLayout) pDevice->pInputLayout->lpVtbl->Release(pDevice->pInputLayout); if (pDevice->pInputLayoutPassThrough) pDevice->pInputLayout->lpVtbl->Release(pDevice->pInputLayoutPassThrough); // Shaders if (pDevice->pVS) pDevice->pVS->lpVtbl->Release(pDevice->pVS); for (int i = 0; i < 18; ++i) { if (pDevice->pPSes[i]) pDevice->pPSes[i]->lpVtbl->Release(pDevice->pPSes[i]); } if (pDevice->pPSPassThrough) pDevice->pPSPassThrough->lpVtbl->Release(pDevice->pPSPassThrough); if (pDevice->pVSPassThrough) pDevice->pVSPassThrough->lpVtbl->Release(pDevice->pVSPassThrough); if (pDevice->pPSAmbient) pDevice->pPSAmbient->lpVtbl->Release(pDevice->pPSAmbient); if (pDevice->pPSOmni) pDevice->pPSOmni->lpVtbl->Release(pDevice->pPSOmni); if (pDevice->pPSLDR) pDevice->pPSLDR->lpVtbl->Release(pDevice->pPSLDR); if (pDevice->pPSBlurH) pDevice->pPSBlurH->lpVtbl->Release(pDevice->pPSBlurH); if (pDevice->pPSBlurV) pDevice->pPSBlurV->lpVtbl->Release(pDevice->pPSBlurV); for (int i = 0; i < 2; ++i) { if (pDevice->pPSPostProcess[i]) pDevice->pPSPostProcess[i]->lpVtbl->Release(pDevice->pPSPostProcess[i]); } // States for (uint32_t i = 0; i < pDevice->stateCount; ++i) { SEGState *pState = pDevice->states + i; destroyState(pState); } free(pDevice->states); // Device if (pDevice->pDepthStencilView) pDevice->pDepthStencilView->lpVtbl->Release(pDevice->pDepthStencilView); if (pDevice->pRenderTargetView) pDevice->pRenderTargetView->lpVtbl->Release(pDevice->pRenderTargetView); if (pDevice->pDeviceContext) pDevice->pDeviceContext->lpVtbl->Release(pDevice->pDeviceContext); if (pDevice->pDevice) pDevice->pDevice->lpVtbl->Release(pDevice->pDevice); if (pDevice->pSwapChain) pDevice->pSwapChain->lpVtbl->Release(pDevice->pSwapChain); memset(pDevice, 0, sizeof(SEGDevice)); *pDeviceID = 0; }