Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for Microsoft Visual C++ compiler (2022) compatibility #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ option(EMBED_RESOURCES "Embed internal resources in the library executable" OFF)
# Compile flags
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
if(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols")
else()
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
endif()
set(OpenGL_GL_PREFERENCE "GLVND")

# Find required libraries
Expand Down
4 changes: 4 additions & 0 deletions Library/include/StonefishCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <vector>
#include <stdexcept>

// cmath
#define _USE_MATH_DEFINES // for Microsoft Visual C++ to get M_PI, M_PI_2 etc.
#include <cmath>

//Bullet Physics
#include "btBulletDynamicsCommon.h"
#include "btBulletCollisionCommon.h"
Expand Down
4 changes: 2 additions & 2 deletions Library/include/graphics/OpenGLAtmosphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace sf
{
//! A structure representing data of the SunSky UBO (std140 aligned).
#pragma pack(1)
#pragma pack(push, 1)
struct SunSkyUBO
{
glm::mat4 sunClipSpace[4];
Expand All @@ -43,7 +43,7 @@ namespace sf
glm::vec3 whitePoint;
GLfloat atmLengthUnitInMeters;
};
#pragma pack(0)
#pragma pack(pop)

//! An enum definind id's of atmosphere textures.
enum AtmosphereTextures
Expand Down
4 changes: 2 additions & 2 deletions Library/include/graphics/OpenGLContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace sf
: attach(attachment), target(target), tex(texture), lvl(level), z(zoffset) {}
};

#pragma pack(1)
#pragma pack(push, 1)
//! A structure representing data of the Lights UBO (std140 aligned)
struct LightsUBO
{
Expand All @@ -70,7 +70,7 @@ namespace sf
glm::vec3 params; //Additional params
GLuint type; //Type of velocity field
};
#pragma pack(0)
#pragma pack(pop)

//! A structure representing a material shader collection.
struct MaterialShader
Expand Down
4 changes: 2 additions & 2 deletions Library/include/graphics/OpenGLLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ namespace sf
enum class LightType {POINT, SPOT};

//! A structure representing a generic light in the Lights UBO.
#pragma pack(1)
#pragma pack(push, 1)
struct LightUBO {};
#pragma pack(0)
#pragma pack(pop)

class GLSLShader;
class OpenGLPipeline;
Expand Down
4 changes: 2 additions & 2 deletions Library/include/graphics/OpenGLOcean.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ namespace sf
float t;
};

#pragma pack(1)
#pragma pack(push, 1)
//! A structure representing the ocean currents UBO.
struct OceanCurrentsUBO
{
VelocityFieldUBO currents[MAX_OCEAN_CURRENTS]; //REMARK: type -> 0=uniform,1=jet,2=pipe,10=thruster
glm::vec3 gravity;
GLuint numCurrents;
};
#pragma pack(0)
#pragma pack(pop)

class GLSLShader;
class OpenGLCamera;
Expand Down
5 changes: 3 additions & 2 deletions Library/include/graphics/OpenGLPointLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
namespace sf
{
//! A structure representing point light in the Lights UBO.
#pragma pack(1)
#pragma pack(push, 1)
struct PointLightUBO : public LightUBO
{
glm::vec3 position;
GLfloat radius;
glm::vec3 color;
uint8_t pad[4];
};
#pragma pack(0)
#pragma pack(pop)


//! A class implementing an OpenGL point light (shadow not supported).
class OpenGLPointLight : public OpenGLLight
Expand Down
4 changes: 2 additions & 2 deletions Library/include/graphics/OpenGLSpotLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace sf
{
//! A structure representing a spot light in the Ligths UBO (std140 aligned).
#pragma pack(1)
#pragma pack(push, 1)
struct SpotLightUBO : public LightUBO
{
glm::mat4 clipSpace;
Expand All @@ -44,7 +44,7 @@ namespace sf
glm::vec3 radius; //UV + physical radius
uint8_t pad[4];
};
#pragma pack(0)
#pragma pack(pop)

//! A class implementing an OpenGL spot light with shadow.
class OpenGLSpotLight : public OpenGLLight
Expand Down
4 changes: 2 additions & 2 deletions Library/include/graphics/OpenGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ namespace sf
//! An enum defining types of views.
enum class ViewType {CAMERA, TRACKBALL, DEPTH_CAMERA, SONAR};

#pragma pack(1)
#pragma pack(push, 1)
struct ViewUBO
{
glm::mat4 VP;
glm::vec4 frustum[6];
glm::vec3 eye;
GLfloat pad;
};
#pragma pack(0)
#pragma pack(pop)

//! An abstract class representing an OpenGL view.
class OpenGLView
Expand Down
8 changes: 8 additions & 0 deletions Library/include/sensors/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ namespace sf
\param index a number specifying the id of the sample
*/
Sample(unsigned short nDimensions, Scalar* values, bool invalid = false, uint64_t index = 0);

//! Constructor for initialized sample.
/*!
\param nDimensions the number of dimensions of the measurement
\param invalid a flag to mark if it is and invalid output
\param index a number specifying the id of the sample
*/
Sample(unsigned short nDimensions, bool invalid = false, uint64_t index = 0);

//! A copy constructor.
/*!
Expand Down
50 changes: 2 additions & 48 deletions Library/include/utils/SystemUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <unistd.h>
#include <Carbon/Carbon.h>
#else //WINDOWS
#include <windows.h>
#endif

#include "core/GraphicalSimulationApp.h"
Expand All @@ -61,14 +60,7 @@ inline int64_t GetTimeInNanoseconds()
return std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
}

inline void GetCWD(char* buffer, int length)
{
#ifdef _MSC_VER
GetCurrentDirectory(length, buffer);
#else
getcwd(buffer, length);
#endif
}
void GetCWD(char* buffer, int length);

inline std::string GetShaderPath()
{
Expand All @@ -80,48 +72,11 @@ inline std::string GetDataPath()
return SimulationApp::getApp()->getDataPath();
}

inline const char* GetDataPathPrefix(const char* directory)
{
static char dataPathPrefix[PATH_MAX];

#ifdef __linux__

#elif __APPLE__
CFStringRef dir = CFStringCreateWithCString(CFAllocatorGetDefault(), directory, kCFStringEncodingMacRoman);

CFURLRef datafilesURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), dir, 0, 0);

CFURLGetFileSystemRepresentation(datafilesURL, true, reinterpret_cast<UInt8*>(dataPathPrefix), PATH_MAX);

if(datafilesURL != NULL)
CFRelease(datafilesURL);

CFRelease(dir);
#else //WINDOWS
char* envDataPath = 0;

// get data path from environment var
envDataPath = getenv(DATAPATH_VAR_NAME);

// set data path prefix / base directory. This will
// be either from an environment variable, or from
// a compiled in default based on original configure
// options
if (envDataPath != 0)
strcpy(dataPathPrefix, envDataPath);
else
strcpy(dataPathPrefix, CEGUI_SAMPLE_DATAPATH);
#endif

return dataPathPrefix;
}
const char* GetDataPathPrefix(const char* directory);

//Extensions
inline bool CheckForExtension(const char* extensionName)
{
#ifdef _MSC_VER
return glewIsSupported(extensionName);
#else
char* extensions = (char*)glGetString(GL_EXTENSIONS);
if(extensions == NULL)
return false;
Expand All @@ -137,7 +92,6 @@ inline bool CheckForExtension(const char* extensionName)
extensions += (n+1);
}
return false;
#endif
}

//Random functions
Expand Down
3 changes: 3 additions & 0 deletions Library/src/entities/solids/Cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
// Copyright (c) 2013-2019 Patryk Cieslak. All rights reserved.
//

#define _USE_MATH_DEFINES // for Microsoft Visual C++
#include <cmath>

#include "entities/solids/Cylinder.h"

#include "graphics/OpenGLContent.h"
Expand Down
3 changes: 3 additions & 0 deletions Library/src/entities/solids/Sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
// Copyright (c) 2013-2019 Patryk Cieslak. All rights reserved.
//

#define _USE_MATH_DEFINES // for Microsoft Visual C++
#include <cmath>

#include "entities/solids/Sphere.h"

#include "graphics/OpenGLContent.h"
Expand Down
4 changes: 4 additions & 0 deletions Library/src/entities/solids/Torus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
// Copyright (c) 2013-2021 Patryk Cieslak. All rights reserved.
//

#define _USE_MATH_DEFINES // for Microsoft Visual C++
#include <cmath>


#include "entities/solids/Torus.h"

#include "core/TorusShape.h"
Expand Down
4 changes: 2 additions & 2 deletions Library/src/entities/statics/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Terrain::Terrain(std::string uniqueName, std::string pathToHeightmap, Scalar sca
heightmap = new GLfloat[w*h];
for(int i=0; i<h; ++i)
for(int j=0; j<w; ++j)
heightmap[i*w+j] = (1.f - data[i*w+j]/(GLfloat)(__UINT16_MAX__)) * height;
heightmap[i*w+j] = (1.f - data[i*w+j]/(GLfloat)(UINT16_MAX)) * height;
stbi_image_free(data);
}
else //8 bit image
Expand All @@ -57,7 +57,7 @@ Terrain::Terrain(std::string uniqueName, std::string pathToHeightmap, Scalar sca
heightmap = new GLfloat[w*h];
for(int i=0; i<h; ++i)
for(int j=0; j<w; ++j)
heightmap[i*w+j] = (1.f - data[i*w+j]/(GLfloat)(__UINT8_MAX__)) * height;
heightmap[i*w+j] = (1.f - data[i*w+j]/(GLfloat)(UINT8_MAX)) * height;
stbi_image_free(data);
}

Expand Down
6 changes: 5 additions & 1 deletion Library/src/graphics/OpenGLCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ OpenGLCamera::OpenGLCamera(GLint x, GLint y, GLint width, GLint height, glm::vec
//---- Tonemapping ----
histogramBins = 256;
histogramRange = glm::vec2(-1.f,11.f);
#ifdef _MSC_VER
GLuint histogram[256];
#else
GLuint histogram[histogramBins];
#endif
memset(histogram, 0, histogramBins * sizeof(GLuint));
glGenBuffers(1, &histogramSSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, histogramSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, histogramBins * sizeof(GLuint), histogram, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);

GLfloat zero = 0.f;
exposureTex = OpenGLContent::GenerateTexture(GL_TEXTURE_2D, glm::uvec3(1,1,0),
GL_R32F, GL_RED, GL_FLOAT, &zero, FilteringMode::NEAREST, false);
Expand Down
2 changes: 1 addition & 1 deletion Library/src/graphics/OpenGLContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ Mesh* OpenGLContent::BuildWing(GLfloat baseChordLength, GLfloat tipChordLength,
GLfloat taper = tipChordLength/baseChordLength;
GLfloat offset = baseChordLength/2.f;

int div = 20;
constexpr int div = 20;
GLfloat xt[div+1];
GLfloat yt[div+1];
for(int i=0; i<=div; ++i)
Expand Down
20 changes: 20 additions & 0 deletions Library/src/graphics/OpenGLFLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,17 @@ OpenGLFLS::OpenGLFLS(glm::vec3 eyePosition, glm::vec3 direction, glm::vec3 sonar
glEnableVertexAttribArray(0);

fanDiv = btMin((GLuint)ceil(horizontalFOVDeg), nBeams);
#ifdef _MSC_VER
//make a (fanDiv + 1) * 2 x 4 automatic array, can't resize but is _really fast_.
//std::vector<std::array<GLfloat, 4>> fanData((fanDiv + 1) * 2);
//auto fanData = std::unique_ptr<GLfloat[]>([(fanDiv + 1) * 2][4]);

//GLfloat** fanData = (GLfloat**)malloc((fanDiv + 1) * 2 * 4 * sizeof(GLfloat*));

GLfloat (*fanData)[4] = (GLfloat(*)[4]) calloc((fanDiv + 1) * 2, sizeof * fanData);
#else
GLfloat fanData[(fanDiv+1)*2][4];
#endif
GLfloat Rmin = range.x/range.y;

//Flipped vertically to account for OpenGL window coordinates
Expand Down Expand Up @@ -189,6 +199,9 @@ OpenGLFLS::OpenGLFLS(glm::vec3 eyePosition, glm::vec3 direction, glm::vec3 sonar
sonarPostprocessShader->SetUniform("sonarOutput", TEX_POSTPROCESS1);
sonarPostprocessShader->SetUniform("sonarPost", TEX_POSTPROCESS2);
OpenGLState::UseProgram(0);
#ifdef _MSC_VER
free(fanData);
#endif
}

OpenGLFLS::~OpenGLFLS()
Expand Down Expand Up @@ -235,7 +248,11 @@ void OpenGLFLS::UpdateTransform()
projection[2] = glm::vec4(0.f, 0.f, -(far + near)/(far-near), -1.f);
projection[3] = glm::vec4(0.f, 0.f, -2.f*far*near/(far-near), 0.f);

#ifdef _MSC_VER
GLfloat(*fanData)[4] = (GLfloat(*)[4]) calloc((fanDiv + 1) * 2, sizeof * fanData);
#else
GLfloat fanData[(fanDiv+1)*2][4];
#endif
GLfloat Rmin = range.x/range.y;
GLfloat hFactor = sinf(fov.x/2.f);
//Flipped vertically to account for OpenGL window coordinates
Expand All @@ -257,6 +274,9 @@ void OpenGLFLS::UpdateTransform()
glBindBuffer(GL_ARRAY_BUFFER, displayVBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(fanData), fanData);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#ifdef _MSC_VER
free(fanData);
#endif
}

//Inform sonar to run callback
Expand Down
Loading