瀏覽代碼

Improved compatibility for multiple compilers in cmake.

Angel Ortiz 7 年之前
父節點
當前提交
b8b9d06974
共有 9 個文件被更改,包括 28 次插入11 次删除
  1. 3 1
      .gitignore
  2. 12 2
      CMakeLists.txt
  3. 1 0
      include/buffer.h
  4. 5 6
      include/shader.h
  5. 1 0
      src/camera.cpp
  6. 1 0
      src/displayManager.cpp
  7. 2 0
      src/geometry.cpp
  8. 2 2
      src/main.cpp
  9. 1 0
      src/matrix.cpp

+ 3 - 1
.gitignore

@@ -1,2 +1,4 @@
 build/
-.vscode/
+.vscode/
+/CMakeSettings.json
+/.vs

+ 12 - 2
CMakeLists.txt

@@ -1,8 +1,18 @@
 cmake_minimum_required(VERSION 3.7)
 project(softwareRenderer)
 
+#Location of cmake scripts
 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
-set(SDL2_PATH "C:\\vs_dev_lib\\SDL2-2.0.8")
+
+#Switching SDL2 files based on compiler 
+if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+  set(SDL2_PATH "C:\\vs_dev_lib\\SDL2-2.0.8-MinGW\\x86_64-w64-mingw32")
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
+  # using Intel C++
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+  set(SDL2_PATH "C:\\vs_dev_lib\\SDL2-2.0.8-MSVC")
+endif()
+
 find_package(SDL2 REQUIRED)
 find_package(OpenMP REQUIRED)
 include_directories(${SDL2_INCLUDE_DIR} include libs)
@@ -10,7 +20,7 @@ include_directories(${SDL2_INCLUDE_DIR} include libs)
 file(GLOB source_files "*.h" "*.cpp" "src/*.cpp" "include/*.h" "libs/*.h")
 add_executable(softwareRenderer ${source_files})
 #-fopt-info-vec-all -xCORE-AVX2 -no-prec-sqrt  
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -g  -ffast-math  ")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -g -ffast-math  ")
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g ")
 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g ")
 target_link_libraries(softwareRenderer ${SDL2_LIBRARY})

+ 1 - 0
include/buffer.h

@@ -8,6 +8,7 @@
 
 #include "SDL.h"
 #include <type_traits>
+#include <string.h>
 
 //Templated struct to emulate GPU buffers such as 
 //the frame buffer and the ZBuffer 

+ 5 - 6
include/shader.h

@@ -17,6 +17,7 @@
 #include "vector3D.h"
 #include "matrix.h"
 #include "texture.h"
+#define _USE_MATH_DEFINES
 #include <math.h>
 
 //Shader Interface for a class that emulates modern GPU fragment and vertex shaders
@@ -311,7 +312,7 @@ struct PBRShader : public IShader {
         float NdotH2 = NdotH*NdotH;
         
         float denom = (NdotH2 * (a2 - 1.0f) + 1.0f);
-        denom =  M_1_PIf32/ (denom * denom);
+        denom =  1.0f / (M_PI * denom * denom);
         
         return a2 * denom;
     }
@@ -378,8 +379,8 @@ struct PBRShader : public IShader {
         const int maxLights = numLights;
 
         //Fresnel, normal distribution function and geometry occlusion 
-        Vector3f* F = new Vector3f[maxLights];
-        float*  NDF = new float[maxLights];
+        Vector3f F[maxLights];
+        float  NDF[maxLights];
         float  G[maxLights];
         
         //Storing in array for vectorizing
@@ -422,7 +423,7 @@ struct PBRShader : public IShader {
             kD[light] = (Vector3f(1.0f) - F[light])*invMetal;
 
             //The rendering equation result for a given light
-            radianceLights[light] = (kD[light] * (interpCol * (M_1_PIf32)) + specular[light] ) * nDotL[light] * lightCol[light];
+            radianceLights[light] = (kD[light] * (interpCol * (1.0f / M_PI) + specular[light] )) * nDotL[light] * lightCol[light];
         }
 
         //Summing up all radiance values since SIMD won't work if I do this within the
@@ -435,8 +436,6 @@ struct PBRShader : public IShader {
         //Simplistic ambient term
         ambient =  interpCol * (ambientInt * interpAO);
 
-        delete [] F;
-
         return ambient + radianceOut;
     }
     

+ 1 - 0
src/camera.cpp

@@ -5,6 +5,7 @@
 
 //Headers
 #include "camera.h"
+#include "SDL.h"
 
 Camera::Camera(){
     side = front.crossProduct(up).normalized();

+ 1 - 0
src/displayManager.cpp

@@ -5,6 +5,7 @@
 
 //Includes
 #include "displayManager.h"
+#include <stdio.h>
 
 //Dummy constructors/destructors
 DisplayManager::DisplayManager(){}

+ 2 - 0
src/geometry.cpp

@@ -6,7 +6,9 @@
 //Headers
 #include "geometry.h"
 #include <limits>
+#define _USE_MATH_DEFINES
 #include <math.h>
+#include <cmath>
 
 //-------------------------------AABOX------------------------------------//
 

+ 2 - 2
src/main.cpp

@@ -5,9 +5,9 @@
 // ===============================
 
 #include "engine.h"
+#include "SDL.h"
 
-int main(int argc, char *argv[]){
-
+int main( int argc, char* args[] ){
     Engine SSGE; //"Simple" Software Graphics Engine
     if(SSGE.startUp()){
         SSGE.run();

+ 1 - 0
src/matrix.cpp

@@ -5,6 +5,7 @@
 
 //Headers
 #include "matrix.h"
+#define _USE_MATH_DEFINES
 #include <math.h>
 
 //The full matrix vector multiplication routine