From d6236a78571827957740a0df7c6830454563bb1c Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Thu, 2 Jan 2025 22:33:44 +0100 Subject: [PATCH] MSVC another fix --- CMakeLists.txt | 2 +- Engine/Graphics/3DRenderer.cpp | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eff0da8..f43caf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ endif() if(NOT MSVC) add_compile_options(-Wall) else() - add_compile_options(/Wall) + add_compile_options(/Wall /wd4710 /wd4711) endif() set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") diff --git a/Engine/Graphics/3DRenderer.cpp b/Engine/Graphics/3DRenderer.cpp index b7bb07c..902019c 100644 --- a/Engine/Graphics/3DRenderer.cpp +++ b/Engine/Graphics/3DRenderer.cpp @@ -9,7 +9,7 @@ //#define DISABLE_AABB_CLIPPING //#define DISABLE_TRIANGLE_CLIPPING -//#define DISABLE_WIREFRAME_MODE +#define DISABLE_WIREFRAME_MODE // Rendering pipeline: @@ -149,6 +149,8 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { #endif // Process scene's objects + size_t prevVCount = 0; + std::vector projVertices; for (auto& obj : mRenderList) { M3D_BoundingBox projAABB = obj->GetAABB(); auto oTMat = obj->GetTransform(); @@ -162,11 +164,12 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { { size_t vCount = obj->GetObjectVerticesCount(); auto& oMesh = obj->GetObjectMesh(); - M3D_F4 projVertices[vCount] = {}; + if (vCount > prevVCount) + projVertices.resize(vCount); // Vertices homogeneous clip space transformation M3D_V3Transform( - projVertices, sizeof(M3D_F4), + projVertices.data(), sizeof(M3D_F4), reinterpret_cast(oMesh.vertices.data()), sizeof(Vertex), vCount, oTMat * viewProjMat @@ -185,15 +188,15 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { // Triangle clipping #ifndef DISABLE_TRIANGLE_CLIPPING //TODO: scissor/clipping depending of how many vertices are outside/inside the clipspace, implement complete Cohen-Sutherland algo or Cyrus–Beck one - if (VertexClipTest(projVertices[indicePtr[i]], mRTSize, 2.5f) && - VertexClipTest(projVertices[indicePtr[i+1]], mRTSize, 2.5f) && - VertexClipTest(projVertices[indicePtr[i+2]], mRTSize, 2.5f)) + if (VertexClipTest(projVertices.at(indicePtr[i]), mRTSize, 2.5f) && + VertexClipTest(projVertices.at(indicePtr[i+1]), mRTSize, 2.5f) && + VertexClipTest(projVertices.at(indicePtr[i+2]), mRTSize, 2.5f)) #endif { - M3D_VECTOR V1 = M3D_V4LoadF4(&projVertices[indicePtr[i]]); - M3D_VECTOR V2 = M3D_V4LoadF4(&projVertices[indicePtr[i+1]]); - M3D_VECTOR V3 = M3D_V4LoadF4(&projVertices[indicePtr[i+2]]); + M3D_VECTOR V1 = M3D_V4LoadF4(&projVertices.at(indicePtr[i])); + M3D_VECTOR V2 = M3D_V4LoadF4(&projVertices.at(indicePtr[i+1])); + M3D_VECTOR V3 = M3D_V4LoadF4(&projVertices.at(indicePtr[i+2])); // Do the perspective divide V1 = M3D_V4Divide(V1, M3D_V4SplatW(V1)); @@ -234,6 +237,8 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { } } } + + prevVCount = prevVCount; } }