Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache/**
bin/**
build/**
compile_commands.json
126 changes: 126 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
cmake_minimum_required(VERSION 3.10)

project(VulkanRenderer
LANGUAGES CXX
)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (MSVC)
message(FATAL_ERROR
"Use the provided Visual Studio solution file to build this project with visual studio.\n"
"This cmake file is meant for non-windows platforms.")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
# Display unused parameters as warnings
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-parameter")
# Suppress warnings about unused parameters
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
endif ()

if (NOT WIN32)
include(FetchContent)

set(GLFW_LIBRARY_TYPE STATIC CACHE STRING "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 3.4
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(glfw)

find_package(Vulkan REQUIRED)
endif ()

add_executable(VulkanRenderer)
target_sources(VulkanRenderer
PRIVATE
code/Fileio.cpp
code/Fileio.h
code/Scene.cpp
code/Scene.h
code/application.cpp
code/application.h
code/main.cpp
code/Math/Bounds.cpp
code/Math/Bounds.h
code/Math/LCP.cpp
code/Math/LCP.h
code/Math/Matrix.h
code/Math/Quat.h
code/Math/Vector.h
code/Physics/Body.cpp
code/Physics/Body.h
code/Physics/Broadphase.cpp
code/Physics/Broadphase.h
code/Physics/Constraints.cpp
code/Physics/Constraints.h
code/Physics/Contact.cpp
code/Physics/Contact.h
code/Physics/GJK.cpp
code/Physics/GJK.h
code/Physics/Intersections.cpp
code/Physics/Intersections.h
code/Physics/Manifold.cpp
code/Physics/Manifold.h
code/Physics/Shapes.cpp
code/Physics/Shapes.h
code/Physics/Constraints/ConstraintBase.h
code/Physics/Constraints/ConstraintConstantVelocity.cpp
code/Physics/Constraints/ConstraintConstantVelocity.h
code/Physics/Constraints/ConstraintDistance.cpp
code/Physics/Constraints/ConstraintDistance.h
code/Physics/Constraints/ConstraintHinge.cpp
code/Physics/Constraints/ConstraintHinge.h
code/Physics/Constraints/ConstraintMotor.cpp
code/Physics/Constraints/ConstraintMotor.h
code/Physics/Constraints/ConstraintMover.cpp
code/Physics/Constraints/ConstraintMover.h
code/Physics/Constraints/ConstraintOrientation.cpp
code/Physics/Constraints/ConstraintOrientation.h
code/Physics/Constraints/ConstraintPenetration.cpp
code/Physics/Constraints/ConstraintPenetration.h
code/Physics/Shapes/ShapeBase.h
code/Physics/Shapes/ShapeBox.cpp
code/Physics/Shapes/ShapeBox.h
code/Physics/Shapes/ShapeConvex.cpp
code/Physics/Shapes/ShapeConvex.h
code/Physics/Shapes/ShapeSphere.cpp
code/Physics/Shapes/ShapeSphere.h
code/Renderer/Buffer.cpp
code/Renderer/Buffer.h
code/Renderer/Descriptor.cpp
code/Renderer/Descriptor.h
code/Renderer/DeviceContext.cpp
code/Renderer/DeviceContext.h
code/Renderer/Fence.cpp
code/Renderer/Fence.h
code/Renderer/FrameBuffer.cpp
code/Renderer/FrameBuffer.h
code/Renderer/Image.cpp
code/Renderer/Image.h
code/Renderer/OffscreenRenderer.cpp
code/Renderer/OffscreenRenderer.h
code/Renderer/Pipeline.cpp
code/Renderer/Pipeline.h
code/Renderer/Samplers.cpp
code/Renderer/Samplers.h
code/Renderer/SwapChain.cpp
code/Renderer/SwapChain.h
code/Renderer/model.cpp
code/Renderer/model.h
code/Renderer/shader.cpp
code/Renderer/shader.h
)

target_link_libraries(VulkanRenderer
PRIVATE
Vulkan::Vulkan
glfw
)

28 changes: 19 additions & 9 deletions code/Fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
#include <assert.h>
#include <string.h>

#include <direct.h>
#define GetCurrentDir _getcwd
#if defined(_WIN32)
#include <direct.h>
#define GetCurrentDir _getcwd
#elif defined(__linux__) || defined(__APPLE__)
#include <unistd.h>
#define GetCurrentDir getcwd
#else
#error "Add platform specific code to get current working directory"
#endif


static char g_ApplicationDirectory[ FILENAME_MAX ];
static bool g_WasInitialized = false;
Expand Down Expand Up @@ -53,12 +61,13 @@ Opens the file and stores it in data
bool GetFileData( const char * fileNameLocal, unsigned char ** data, unsigned int & size ) {
InitializeFileSystem();

char fileName[ 2048 ];
sprintf( fileName, "%s/%s", g_ApplicationDirectory, fileNameLocal );

char fileName[ FILENAME_MAX ];
int written = snprintf( fileName, sizeof(fileName), "%s/%s", g_ApplicationDirectory, fileNameLocal );
assert( written < FILENAME_MAX );

// open file for reading
FILE * file = fopen( fileName, "rb" );

// handle any errors
if ( file == NULL ) {
return false;
Expand Down Expand Up @@ -114,8 +123,9 @@ SaveFileData
bool SaveFileData( const char * fileNameLocal, const void * data, unsigned int size ) {
InitializeFileSystem();

char fileName[ 2048 ];
sprintf( fileName, "%s/%s", g_ApplicationDirectory, fileNameLocal );
char fileName[ FILENAME_MAX ];
int written = snprintf( fileName, FILENAME_MAX, "%s/%s", g_ApplicationDirectory, fileNameLocal );
assert( written < FILENAME_MAX );

// open file for writing
FILE * file = fopen( fileName, "wb" );
Expand All @@ -139,4 +149,4 @@ bool SaveFileData( const char * fileNameLocal, const void * data, unsigned int s
fclose( file );
printf( "Write file was success %s\n", fileName );
return true;
}
}
14 changes: 7 additions & 7 deletions code/Math/Quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ class Quat {
};

inline Quat::Quat() :
w( 1 ),
x( 0 ),
y( 0 ),
z( 0 ),
w( 1 ) {
z( 0 ) {
}

inline Quat::Quat( const Quat &rhs ) :
w( rhs.w ),
x( rhs.x ),
y( rhs.y ),
z( rhs.z ),
w( rhs.w ) {
z( rhs.z ) {
}

inline Quat::Quat( float X, float Y, float Z, float W ) :
w( W ),
x( X ),
y( Y ),
z( Z ),
w( W ) {
z( Z ) {
}

inline Quat::Quat( Vec3 n, const float angleRadians ) {
Expand Down Expand Up @@ -179,4 +179,4 @@ inline Mat3 Quat::ToMat3() const {
mat.rows[ 1 ] = RotatePoint( mat.rows[ 1 ] );
mat.rows[ 2 ] = RotatePoint( mat.rows[ 2 ] );
return mat;
}
}
6 changes: 5 additions & 1 deletion code/Physics/Constraints/ConstraintDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ void ConstraintDistance::PreSolve( const float dt_sec ) {
// TODO: Add code
}

void ConstraintDistance::Solve() {
// TODO: Add code
}

void ConstraintDistance::PostSolve() {
// TODO: Add code
}
}
6 changes: 3 additions & 3 deletions code/Physics/Constraints/ConstraintDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ ConstraintDistance
class ConstraintDistance : public Constraint {
public:
ConstraintDistance() : Constraint(),
m_cachedLambda( 1 ),
m_Jacobian( 1, 12 ) {
m_Jacobian( 1, 12 ),
m_cachedLambda( 1 ) {
m_cachedLambda.Zero();
m_baumgarte = 0.0f;
}
Expand All @@ -27,4 +27,4 @@ class ConstraintDistance : public Constraint {

VecN m_cachedLambda;
float m_baumgarte;
};
};
6 changes: 3 additions & 3 deletions code/Physics/Manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class Manifold {
static const int MAX_CONTACTS = 4;
contact_t m_contacts[ MAX_CONTACTS ];

int m_numContacts;

Body * m_bodyA;
Body * m_bodyB;

int m_numContacts;

ConstraintPenetration m_constraints[ MAX_CONTACTS ];

friend class ManifoldCollector;
Expand All @@ -59,4 +59,4 @@ class ManifoldCollector {

public:
std::vector< Manifold > m_manifolds;
};
};
2 changes: 2 additions & 0 deletions code/Physics/Shapes/ShapeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Shape
*/
class Shape {
public:
virtual ~Shape() = default;

virtual Mat3 InertiaTensor() const = 0;

virtual Bounds GetBounds( const Vec3 & pos, const Quat & orient ) const = 0;
Expand Down
3 changes: 2 additions & 1 deletion code/Renderer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Buffer.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>

/*
================================================================================================
Expand Down Expand Up @@ -101,4 +102,4 @@ Buffer::UnmapBuffer
*/
void Buffer::UnmapBuffer( DeviceContext * device ) {
vkUnmapMemory( device->m_vkDevice, m_vkBufferMemory );
}
}
3 changes: 1 addition & 2 deletions code/Renderer/Descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ bool Descriptors::Create( DeviceContext * device, const CreateParms_t & parms )

int idx = 0;

const int numVertexUniforms = parms.numUniformsVertex;
for ( int i = 0; i < parms.numUniformsVertex; i++ ) {
uniformBindings[ idx ].binding = idx;
uniformBindings[ idx ].descriptorCount = 1;
Expand Down Expand Up @@ -233,4 +232,4 @@ void Descriptor::BindDescriptor( DeviceContext * device, VkCommandBuffer vkComma

vkUpdateDescriptorSets( device->m_vkDevice, (uint32_t)numDescriptors, descriptorWrites, 0, nullptr );
vkCmdBindDescriptorSets( vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pso->m_vkPipelineLayout, 0, 1, &m_parent->m_vkDescriptorSets[ m_id ], 0, nullptr );
}
}
3 changes: 2 additions & 1 deletion code/Renderer/Descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DeviceContext;
class Buffer;
class Pipeline;
class Image;
class Descriptors;
struct RenderModel;

/*
Expand Down Expand Up @@ -77,4 +78,4 @@ class Descriptors {
m_numDescriptorUsed++;
return descriptor;
}
};
};
14 changes: 8 additions & 6 deletions code/Renderer/DeviceContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "DeviceContext.h"
#include "Fence.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>

/*
================================================================================================
Expand Down Expand Up @@ -145,7 +147,7 @@ bool PhysicalDeviceProperties::HasExtensions( const char ** extensions, const in
const char * extension = extensions[ i ];

bool doesExist = false;
for ( int j = 0; j < m_vkExtensionProperties.size(); j++ ) {
for ( size_t j = 0; j < m_vkExtensionProperties.size(); j++ ) {
if ( 0 == strcmp( extension, m_vkExtensionProperties[ j ].extensionName ) ) {
doesExist = true;
break;
Expand Down Expand Up @@ -207,7 +209,7 @@ bool DeviceContext::CreateInstance( bool enableLayers, const std::vector< const
std::vector< VkLayerProperties > layerProperties( numLayers );
vkEnumerateInstanceLayerProperties( &numLayers, layerProperties.data() );

for ( int i = 0; i < numLayers; i++ ) {
for ( uint32_t i = 0; i < numLayers; i++ ) {
printf( "Layer: %i %s\n", i, layerProperties[ i ].layerName );

if ( 0 == strcmp( "VK_LAYER_KHRONOS_validation", layerProperties[ i ].layerName ) ) {
Expand Down Expand Up @@ -368,7 +370,7 @@ bool DeviceContext::CreatePhysicalDevice() {
//
// Select a physical device
//
for ( int i = 0; i < m_physicalDevices.size(); i++ ) {
for ( size_t i = 0; i < m_physicalDevices.size(); i++ ) {
const PhysicalDeviceProperties & deviceProperties = m_physicalDevices[ i ];

// Ignore non-drawing devices
Expand All @@ -388,7 +390,7 @@ bool DeviceContext::CreatePhysicalDevice() {
// Find graphics queue family
//
int graphicsIdx = -1;
for ( int j = 0; j < deviceProperties.m_vkQueueFamilyProperties.size(); ++j ) {
for ( size_t j = 0; j < deviceProperties.m_vkQueueFamilyProperties.size(); ++j ) {
const VkQueueFamilyProperties & props = deviceProperties.m_vkQueueFamilyProperties[ j ];

if ( props.queueCount == 0 ) {
Expand All @@ -410,7 +412,7 @@ bool DeviceContext::CreatePhysicalDevice() {
// Find present queue family
//
int presentIdx = -1;
for ( int j = 0; j < deviceProperties.m_vkQueueFamilyProperties.size(); ++j ) {
for ( size_t j = 0; j < deviceProperties.m_vkQueueFamilyProperties.size(); ++j ) {
const VkQueueFamilyProperties & props = deviceProperties.m_vkQueueFamilyProperties[ j ];

if ( props.queueCount == 0 ) {
Expand Down Expand Up @@ -651,4 +653,4 @@ int DeviceContext::GetAligendUniformByteOffset( const int offset ) const {
const int n = ( offset + minByteOffsetAlignment - 1 ) / minByteOffsetAlignment;
const int alignedOffset = n * minByteOffsetAlignment;
return alignedOffset;
}
}
Loading