C RÉPARER ENFIN !!!!
La swapChain est correctement resize lors d'un changement de taille de fenetre.
This commit is contained in:
parent
ed325934ee
commit
a2dd35513e
@ -105,8 +105,7 @@ void CameraClass::Render()
|
||||
return;
|
||||
}
|
||||
|
||||
void CameraClass::GetViewMatrix(XMMATRIX& viewMatrix)
|
||||
XMMATRIX CameraClass::GetViewMatrix()
|
||||
{
|
||||
viewMatrix = m_viewMatrix;
|
||||
return;
|
||||
return m_viewMatrix;
|
||||
}
|
@ -29,7 +29,7 @@ public:
|
||||
XMFLOAT3 GetRotation();
|
||||
|
||||
void Render();
|
||||
void GetViewMatrix(XMMATRIX&);
|
||||
XMMATRIX GetViewMatrix();
|
||||
|
||||
private:
|
||||
float m_positionX, m_positionY, m_positionZ;
|
||||
|
@ -163,7 +163,7 @@ bool ApplicationClass::Frame()
|
||||
|
||||
bool ApplicationClass::Render(float rotation)
|
||||
{
|
||||
XMMATRIX worldMatrix, viewMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
|
||||
XMMATRIX worldMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
|
||||
bool result;
|
||||
|
||||
|
||||
@ -175,8 +175,6 @@ bool ApplicationClass::Render(float rotation)
|
||||
|
||||
// Get the world, view, and projection matrices from the camera and d3d objects.
|
||||
m_Direct3D->GetWorldMatrix(worldMatrix);
|
||||
m_Camera->GetViewMatrix(viewMatrix);
|
||||
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
||||
|
||||
for (auto cube : m_cubes)
|
||||
{
|
||||
@ -188,7 +186,7 @@ bool ApplicationClass::Render(float rotation)
|
||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||
|
||||
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(),
|
||||
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, m_Camera->GetViewMatrix(), m_Direct3D->GetProjectionMatrix(), cube->GetTexture(),
|
||||
m_Light->GetDirection(), m_Light->GetDiffuseColor());
|
||||
if (!result)
|
||||
{
|
||||
@ -234,9 +232,4 @@ void ApplicationClass::AddCube()
|
||||
newCube->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
|
||||
|
||||
m_cubes.push_back(newCube);
|
||||
}
|
||||
|
||||
void ApplicationClass::SelectedObject(int mouseX, int mouseY)
|
||||
{
|
||||
// TODO: Implement this function
|
||||
}
|
||||
}
|
@ -45,8 +45,6 @@ public:
|
||||
void AddCube();
|
||||
int GetCubeCount() const { return m_cubes.size(); };
|
||||
|
||||
void SelectedObject(int mouseX, int mouseY);
|
||||
|
||||
private:
|
||||
bool Render(float);
|
||||
|
||||
|
@ -293,6 +293,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
MessageBox(hwnd, L"Could not create the depth stencil view.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -423,6 +424,8 @@ void D3DClass::BeginScene(float red, float green, float blue, float alpha)
|
||||
// Clear the back buffer.
|
||||
m_deviceContext->ClearRenderTargetView(m_renderTargetView, color);
|
||||
|
||||
|
||||
|
||||
// Clear the depth buffer.
|
||||
m_deviceContext->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
|
||||
|
||||
@ -460,10 +463,9 @@ ID3D11DeviceContext* D3DClass::GetDeviceContext()
|
||||
}
|
||||
|
||||
|
||||
void D3DClass::GetProjectionMatrix(XMMATRIX& projectionMatrix)
|
||||
XMMATRIX D3DClass::GetProjectionMatrix()
|
||||
{
|
||||
projectionMatrix = m_projectionMatrix;
|
||||
return;
|
||||
return m_projectionMatrix;
|
||||
}
|
||||
|
||||
|
||||
@ -530,88 +532,9 @@ void D3DClass::ReleaseResources()
|
||||
}
|
||||
}
|
||||
|
||||
bool D3DClass::RecreateResources()
|
||||
// Reset the resources for the swap chain
|
||||
void D3DClass::ResetResources(int newWidth, int newHeight)
|
||||
{
|
||||
HRESULT result;
|
||||
ID3D11Texture2D* backBufferPtr;
|
||||
D3D11_TEXTURE2D_DESC depthBufferDesc;
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
||||
|
||||
// Recréez la vue de rendu.
|
||||
result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_device->CreateRenderTargetView(backBufferPtr, NULL, &m_renderTargetView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
backBufferPtr->Release();
|
||||
backBufferPtr = 0;
|
||||
|
||||
// Recréez le tampon de profondeur et la vue de profondeur.
|
||||
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
|
||||
depthBufferDesc.Width = m_viewport.Width;
|
||||
depthBufferDesc.Height = m_viewport.Height;
|
||||
depthBufferDesc.MipLevels = 1;
|
||||
depthBufferDesc.ArraySize = 1;
|
||||
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
depthBufferDesc.SampleDesc.Count = 1;
|
||||
depthBufferDesc.SampleDesc.Quality = 0;
|
||||
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
depthBufferDesc.CPUAccessFlags = 0;
|
||||
depthBufferDesc.MiscFlags = 0;
|
||||
|
||||
result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
|
||||
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
depthStencilViewDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Liez la vue de rendu et le tampon de profondeur à la pipeline de rendu de sortie.
|
||||
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDXGISwapChain* D3DClass::GetSwapChain()
|
||||
{
|
||||
return m_swapChain;
|
||||
}
|
||||
|
||||
void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
// Release existing DirectX resources
|
||||
m_renderTargetView->Release();
|
||||
m_depthStencilBuffer->Release();
|
||||
|
||||
// Resize the swap chain
|
||||
m_swapChain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0);
|
||||
if (FAILED(m_swapChain))
|
||||
{
|
||||
MessageBox(NULL, L"Failed to resize swap chain buffers", L"Error", MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// Recreate the render target view
|
||||
ID3D11Texture2D* backBuffer;
|
||||
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);
|
||||
m_device->CreateRenderTargetView(backBuffer, NULL, &m_renderTargetView);
|
||||
@ -638,13 +561,38 @@ void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
depthStencilViewDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
|
||||
// Other depthStencilDesc settings...
|
||||
m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
|
||||
// Set the new render target and depth/stencil views for rendering
|
||||
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
|
||||
}
|
||||
|
||||
IDXGISwapChain* D3DClass::GetSwapChain()
|
||||
{
|
||||
return m_swapChain;
|
||||
}
|
||||
|
||||
void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
// Release existing DirectX resources
|
||||
ReleaseResources();
|
||||
m_deviceContext->Flush();
|
||||
|
||||
// Resize the swap chain
|
||||
result = m_swapChain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0);
|
||||
if (FAILED(result))
|
||||
{
|
||||
MessageBox(NULL, L"Failed to resize the swap chain.", L"Error", MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the resources
|
||||
ResetResources(newWidth, newHeight);
|
||||
|
||||
// Update the viewport
|
||||
m_viewport.Width = static_cast<float>(newWidth);
|
||||
m_viewport.Height = static_cast<float>(newHeight);
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
IDXGISwapChain* GetSwapChain();
|
||||
void ResizeSwapChain(int, int);
|
||||
|
||||
void GetProjectionMatrix(XMMATRIX&);
|
||||
XMMATRIX GetProjectionMatrix();
|
||||
void GetWorldMatrix(XMMATRIX&);
|
||||
void GetOrthoMatrix(XMMATRIX&);
|
||||
|
||||
@ -54,7 +54,7 @@ public:
|
||||
void ResetViewport();
|
||||
|
||||
void ReleaseResources();
|
||||
bool RecreateResources();
|
||||
void ResetResources(int newWidth, int newHeight);
|
||||
|
||||
private:
|
||||
bool m_vsync_enabled;
|
||||
|
@ -3,6 +3,6 @@ Pos=60,60
|
||||
Size=400,400
|
||||
|
||||
[Window][Khaotic Engine]
|
||||
Pos=43,18
|
||||
Pos=54,81
|
||||
Size=694,367
|
||||
|
||||
|
@ -75,29 +75,3 @@ void imguiManager::WidgetAddObject(ApplicationClass* app)
|
||||
ImGui::Text("Number of cubes: %d", app->GetCubeCount());
|
||||
}
|
||||
}
|
||||
|
||||
void imguiManager::WidgetSelectedObject(ApplicationClass* app)
|
||||
{
|
||||
Object* selectedObject = app->SelectedObject();
|
||||
if (selectedObject)
|
||||
{
|
||||
if (ImGui::CollapsingHeader("Selected Object"))
|
||||
{
|
||||
XMFLOAT3 position, rotation, scale;
|
||||
// Get the current position, rotation, and scale of the object
|
||||
XMStoreFloat3(&position, selectedObject->GetTranslateMatrix().r[3]);
|
||||
XMStoreFloat3(&rotation, selectedObject->GetRotateMatrix().r[3]);
|
||||
XMStoreFloat3(&scale, selectedObject->GetScaleMatrix().r[3]);
|
||||
|
||||
// Create ImGui controls to modify these values
|
||||
ImGui::InputFloat3("Position", &position.x);
|
||||
ImGui::InputFloat3("Rotation", &rotation.x);
|
||||
ImGui::InputFloat3("Scale", &scale.x);
|
||||
|
||||
// Update the object's matrices with the new values
|
||||
selectedObject->SetTranslateMatrix(XMMatrixTranslationFromVector(XMLoadFloat3(&position)));
|
||||
selectedObject->SetRotateMatrix(XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&rotation)));
|
||||
selectedObject->SetScaleMatrix(XMMatrixScalingFromVector(XMLoadFloat3(&scale)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ public:
|
||||
void WidgetButton();
|
||||
void WidgetFPS();
|
||||
void WidgetAddObject(ApplicationClass* app);
|
||||
void WidgetSelectedObject(ApplicationClass* app);
|
||||
|
||||
private:
|
||||
ImGuiIO* io;
|
||||
|
@ -61,4 +61,4 @@ XMMATRIX Object::GetSRMatrix()
|
||||
XMMATRIX Object::GetWorldMatrix()
|
||||
{
|
||||
return m_worldMatrix;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user