Lightmap atlas shit

This commit is contained in:
Joshua Ashton 2023-11-03 03:01:06 +00:00
parent 41b580b3c7
commit 27a5cf0a4f
16 changed files with 1565 additions and 80 deletions

6
.gitmodules vendored
View File

@ -7,3 +7,9 @@
[submodule "subprojects/libspng"]
path = subprojects/libspng
url = https://github.com/randy408/libspng
[submodule "thirdparty/JoltPhysics"]
path = thirdparty/JoltPhysics
url = https://github.com/jrouwe/JoltPhysics
[submodule "thirdparty/xatlas"]
path = thirdparty/xatlas
url = https://github.com/jpcy/xatlas

View File

@ -0,0 +1,14 @@
#pragma once
#include <Orange/Graphics/Mesh.h>
#include <memory>
#include <xatlas.h>
namespace orange
{
using LightmapAtlas = std::unique_ptr<xatlas::Atlas, void(*)(xatlas::Atlas*)>;
Result<LightmapAtlas> CreateLightmapAtlasForMesh(MeshData& mesh);
Vector<uint8_t> GenerateDebugAtlasTexture(const LightmapAtlas& atlas);
}

View File

@ -20,22 +20,25 @@ namespace orange
struct alignas(8) StaticVertex
{
vec3 pos;
vec2 uv;
vec2 texUV;
vec2 lightUV;
vec3 normal;
//vec3 tangent;
static constexpr VkVertexInputAttributeDescription Attributes[] =
{
{ .location = 0, .binding = 0, .format = VK_FORMAT_R32G32B32_SFLOAT, .offset = uint32_t(offsetof2(StaticVertex, pos)) },
{ .location = 1, .binding = 0, .format = VK_FORMAT_R32G32_SFLOAT, .offset = uint32_t(offsetof2(StaticVertex, uv)) },
{ .location = 2, .binding = 0, .format = VK_FORMAT_R32G32B32_SFLOAT, .offset = uint32_t(offsetof2(StaticVertex, normal)) },
{ .location = 1, .binding = 0, .format = VK_FORMAT_R32G32_SFLOAT, .offset = uint32_t(offsetof2(StaticVertex, texUV)) },
{ .location = 2, .binding = 0, .format = VK_FORMAT_R32G32_SFLOAT, .offset = uint32_t(offsetof2(StaticVertex, lightUV)) },
{ .location = 3, .binding = 0, .format = VK_FORMAT_R32G32B32_SFLOAT, .offset = uint32_t(offsetof2(StaticVertex, normal)) },
};
bool operator == (const StaticVertex& other) const
{
return
pos == other.pos &&
uv == other.uv &&
texUV == other.texUV &&
lightUV == other.lightUV &&
normal == other.normal;// &&
//tangent == other.tangent;
}
@ -49,7 +52,8 @@ namespace orange
{
return
pos == other.pos &&
uv == other.uv &&
texUV == other.texUV &&
lightUV == other.lightUV &&
normal == other.normal &&
//tangent == other.tangent &&
boneIndices == other.boneIndices &&

View File

@ -32,4 +32,409 @@ spng_proj = subproject('libspng', default_options: [
])
spng_dep = spng_proj.get_variable('spng_dep')
xatlas_include = include_directories([
'thirdparty/xatlas/source/xatlas',
])
xatlas_src = files([
'thirdparty/xatlas/source/xatlas/xatlas.cpp',
])
joltphysics_include = include_directories([
'thirdparty/JoltPhysics',
])
joltphysics_src = files([
'thirdparty/JoltPhysics/Jolt/AABBTree/AABBTreeBuilder.cpp',
'thirdparty/JoltPhysics/Jolt/AABBTree/AABBTreeBuilder.h',
'thirdparty/JoltPhysics/Jolt/AABBTree/AABBTreeToBuffer.h',
'thirdparty/JoltPhysics/Jolt/AABBTree/NodeCodec/NodeCodecQuadTreeHalfFloat.h',
'thirdparty/JoltPhysics/Jolt/AABBTree/TriangleCodec/TriangleCodecIndexed8BitPackSOA4Flags.h',
'thirdparty/JoltPhysics/Jolt/Core/ARMNeon.h',
'thirdparty/JoltPhysics/Jolt/Core/Atomics.h',
'thirdparty/JoltPhysics/Jolt/Core/ByteBuffer.h',
'thirdparty/JoltPhysics/Jolt/Core/Color.cpp',
'thirdparty/JoltPhysics/Jolt/Core/Color.h',
'thirdparty/JoltPhysics/Jolt/Core/Core.h',
'thirdparty/JoltPhysics/Jolt/Core/Factory.cpp',
'thirdparty/JoltPhysics/Jolt/Core/Factory.h',
'thirdparty/JoltPhysics/Jolt/Core/FixedSizeFreeList.h',
'thirdparty/JoltPhysics/Jolt/Core/FPControlWord.h',
'thirdparty/JoltPhysics/Jolt/Core/FPException.h',
'thirdparty/JoltPhysics/Jolt/Core/FPFlushDenormals.h',
'thirdparty/JoltPhysics/Jolt/Core/HashCombine.h',
'thirdparty/JoltPhysics/Jolt/Core/InsertionSort.h',
'thirdparty/JoltPhysics/Jolt/Core/IssueReporting.cpp',
'thirdparty/JoltPhysics/Jolt/Core/IssueReporting.h',
'thirdparty/JoltPhysics/Jolt/Core/JobSystem.h',
'thirdparty/JoltPhysics/Jolt/Core/JobSystemThreadPool.cpp',
'thirdparty/JoltPhysics/Jolt/Core/JobSystemThreadPool.h',
'thirdparty/JoltPhysics/Jolt/Core/JobSystemWithBarrier.cpp',
'thirdparty/JoltPhysics/Jolt/Core/JobSystemWithBarrier.h',
'thirdparty/JoltPhysics/Jolt/Core/LinearCurve.cpp',
'thirdparty/JoltPhysics/Jolt/Core/LinearCurve.h',
'thirdparty/JoltPhysics/Jolt/Core/LockFreeHashMap.h',
'thirdparty/JoltPhysics/Jolt/Core/Memory.cpp',
'thirdparty/JoltPhysics/Jolt/Core/Memory.h',
'thirdparty/JoltPhysics/Jolt/Core/Mutex.h',
'thirdparty/JoltPhysics/Jolt/Core/MutexArray.h',
'thirdparty/JoltPhysics/Jolt/Core/NonCopyable.h',
'thirdparty/JoltPhysics/Jolt/Core/Profiler.cpp',
'thirdparty/JoltPhysics/Jolt/Core/Profiler.h',
'thirdparty/JoltPhysics/Jolt/Core/QuickSort.h',
'thirdparty/JoltPhysics/Jolt/Core/Reference.h',
'thirdparty/JoltPhysics/Jolt/Core/Result.h',
'thirdparty/JoltPhysics/Jolt/Core/RTTI.cpp',
'thirdparty/JoltPhysics/Jolt/Core/RTTI.h',
'thirdparty/JoltPhysics/Jolt/Core/Semaphore.cpp',
'thirdparty/JoltPhysics/Jolt/Core/Semaphore.h',
'thirdparty/JoltPhysics/Jolt/Core/StaticArray.h',
'thirdparty/JoltPhysics/Jolt/Core/StreamIn.h',
'thirdparty/JoltPhysics/Jolt/Core/StreamOut.h',
'thirdparty/JoltPhysics/Jolt/Core/StreamWrapper.h',
'thirdparty/JoltPhysics/Jolt/Core/StringTools.cpp',
'thirdparty/JoltPhysics/Jolt/Core/StringTools.h',
'thirdparty/JoltPhysics/Jolt/Core/STLAlignedAllocator.h',
'thirdparty/JoltPhysics/Jolt/Core/STLAllocator.h',
'thirdparty/JoltPhysics/Jolt/Core/STLTempAllocator.h',
'thirdparty/JoltPhysics/Jolt/Core/TempAllocator.h',
'thirdparty/JoltPhysics/Jolt/Core/TickCounter.cpp',
'thirdparty/JoltPhysics/Jolt/Core/TickCounter.h',
'thirdparty/JoltPhysics/Jolt/Core/UnorderedMap.h',
'thirdparty/JoltPhysics/Jolt/Core/UnorderedSet.h',
'thirdparty/JoltPhysics/Jolt/Geometry/AABox.h',
'thirdparty/JoltPhysics/Jolt/Geometry/AABox4.h',
'thirdparty/JoltPhysics/Jolt/Geometry/ClipPoly.h',
'thirdparty/JoltPhysics/Jolt/Geometry/ClosestPoint.h',
'thirdparty/JoltPhysics/Jolt/Geometry/ConvexHullBuilder.cpp',
'thirdparty/JoltPhysics/Jolt/Geometry/ConvexHullBuilder.h',
'thirdparty/JoltPhysics/Jolt/Geometry/ConvexHullBuilder2D.cpp',
'thirdparty/JoltPhysics/Jolt/Geometry/ConvexHullBuilder2D.h',
'thirdparty/JoltPhysics/Jolt/Geometry/ConvexSupport.h',
'thirdparty/JoltPhysics/Jolt/Geometry/Ellipse.h',
'thirdparty/JoltPhysics/Jolt/Geometry/EPAConvexHullBuilder.h',
'thirdparty/JoltPhysics/Jolt/Geometry/EPAPenetrationDepth.h',
'thirdparty/JoltPhysics/Jolt/Geometry/GJKClosestPoint.h',
'thirdparty/JoltPhysics/Jolt/Geometry/IndexedTriangle.h',
'thirdparty/JoltPhysics/Jolt/Geometry/Indexify.cpp',
'thirdparty/JoltPhysics/Jolt/Geometry/Indexify.h',
'thirdparty/JoltPhysics/Jolt/Geometry/MortonCode.h',
'thirdparty/JoltPhysics/Jolt/Geometry/OrientedBox.cpp',
'thirdparty/JoltPhysics/Jolt/Geometry/OrientedBox.h',
'thirdparty/JoltPhysics/Jolt/Geometry/Plane.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RayAABox.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RayAABox8.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RayCapsule.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RayCylinder.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RaySphere.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RayTriangle.h',
'thirdparty/JoltPhysics/Jolt/Geometry/RayTriangle8.h',
'thirdparty/JoltPhysics/Jolt/Geometry/Sphere.h',
'thirdparty/JoltPhysics/Jolt/Geometry/Triangle.h',
'thirdparty/JoltPhysics/Jolt/Jolt.h',
'thirdparty/JoltPhysics/Jolt/Math/DMat44.h',
'thirdparty/JoltPhysics/Jolt/Math/Double3.h',
'thirdparty/JoltPhysics/Jolt/Math/DVec3.h',
'thirdparty/JoltPhysics/Jolt/Math/DynMatrix.h',
'thirdparty/JoltPhysics/Jolt/Math/EigenValueSymmetric.h',
'thirdparty/JoltPhysics/Jolt/Math/FindRoot.h',
'thirdparty/JoltPhysics/Jolt/Math/Float2.h',
'thirdparty/JoltPhysics/Jolt/Math/Float3.h',
'thirdparty/JoltPhysics/Jolt/Math/Float4.h',
'thirdparty/JoltPhysics/Jolt/Math/GaussianElimination.h',
'thirdparty/JoltPhysics/Jolt/Math/HalfFloat.h',
'thirdparty/JoltPhysics/Jolt/Math/Mat44.h',
'thirdparty/JoltPhysics/Jolt/Math/Math.h',
'thirdparty/JoltPhysics/Jolt/Math/MathTypes.h',
'thirdparty/JoltPhysics/Jolt/Math/Matrix.h',
'thirdparty/JoltPhysics/Jolt/Math/Quat.h',
'thirdparty/JoltPhysics/Jolt/Math/Real.h',
'thirdparty/JoltPhysics/Jolt/Math/Swizzle.h',
'thirdparty/JoltPhysics/Jolt/Math/Trigonometry.h',
'thirdparty/JoltPhysics/Jolt/Math/UVec4.h',
'thirdparty/JoltPhysics/Jolt/Math/UVec8.h',
'thirdparty/JoltPhysics/Jolt/Math/Vec3.cpp',
'thirdparty/JoltPhysics/Jolt/Math/Vec3.h',
'thirdparty/JoltPhysics/Jolt/Math/Vec4.h',
'thirdparty/JoltPhysics/Jolt/Math/Vec8.h',
'thirdparty/JoltPhysics/Jolt/Math/Vector.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/GetPrimitiveTypeOfType.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStream.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStream.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamBinaryIn.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamBinaryIn.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamBinaryOut.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamBinaryOut.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamIn.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamIn.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamOut.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamOut.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamTextIn.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamTextIn.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamTextOut.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamTextOut.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/ObjectStreamTypes.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/SerializableAttribute.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/SerializableAttributeEnum.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/SerializableAttributeTyped.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/SerializableObject.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/SerializableObject.h',
'thirdparty/JoltPhysics/Jolt/ObjectStream/TypeDeclarations.cpp',
'thirdparty/JoltPhysics/Jolt/ObjectStream/TypeDeclarations.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/Body.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/Body.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyAccess.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyAccess.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyActivationListener.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyCreationSettings.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyCreationSettings.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyFilter.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyID.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyInterface.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyInterface.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyLock.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyLockInterface.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyLockMulti.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyManager.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyManager.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/BodyPair.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/MassProperties.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/MassProperties.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/MotionProperties.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Body/MotionProperties.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/MotionQuality.h',
'thirdparty/JoltPhysics/Jolt/Physics/Body/MotionType.h',
'thirdparty/JoltPhysics/Jolt/Physics/Character/Character.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Character/Character.h',
'thirdparty/JoltPhysics/Jolt/Physics/Character/CharacterBase.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Character/CharacterBase.h',
'thirdparty/JoltPhysics/Jolt/Physics/Character/CharacterVirtual.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Character/CharacterVirtual.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/AABoxCast.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ActiveEdgeMode.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ActiveEdges.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BackFaceMode.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhase.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhase.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhaseBruteForce.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhaseBruteForce.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhaseQuadTree.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhaseQuadTree.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/BroadPhaseQuery.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/QuadTree.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/BroadPhase/QuadTree.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CastConvexVsTriangles.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CastConvexVsTriangles.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CastSphereVsTriangles.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CastSphereVsTriangles.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CastResult.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollectFacesMode.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollideConvexVsTriangles.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollideConvexVsTriangles.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollidePointResult.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollideShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollideSphereVsTriangles.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollideSphereVsTriangles.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollisionCollector.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollisionCollectorImpl.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollisionDispatch.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollisionDispatch.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollisionGroup.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/CollisionGroup.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ContactListener.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/EstimateCollisionResponse.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/EstimateCollisionResponse.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/GroupFilter.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/GroupFilter.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/GroupFilterTable.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/GroupFilterTable.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ManifoldBetweenTwoFaces.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ManifoldBetweenTwoFaces.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/NarrowPhaseQuery.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/NarrowPhaseQuery.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/NarrowPhaseStats.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/NarrowPhaseStats.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ObjectLayer.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/PhysicsMaterial.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/PhysicsMaterial.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/PhysicsMaterialSimple.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/PhysicsMaterialSimple.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/RayCast.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/BoxShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/BoxShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CapsuleShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CapsuleShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CompoundShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CompoundShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CompoundShapeVisitors.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ConvexHullShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ConvexHullShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ConvexShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ConvexShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CylinderShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/CylinderShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/DecoratedShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/DecoratedShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/GetTrianglesContext.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/HeightFieldShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/HeightFieldShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/MeshShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/MeshShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/MutableCompoundShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/MutableCompoundShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/PolyhedronSubmergedVolumeCalculator.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/RotatedTranslatedShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ScaledShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ScaledShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/ScaleHelpers.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/Shape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/Shape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/SphereShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/SphereShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/StaticCompoundShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/StaticCompoundShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/SubShapeID.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/SubShapeIDPair.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/TriangleShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/Shape/TriangleShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ShapeCast.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/ShapeFilter.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/SortReverseAndStore.h',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/TransformedShape.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Collision/TransformedShape.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConeConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConeConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/Constraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/Constraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintManager.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintManager.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/AngleConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/AxisConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/DualAxisConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/GearConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/HingeRotationConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/IndependentAxisConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/PointConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/RackAndPinionConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/RotationEulerConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/SpringPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ConstraintPart/SwingTwistConstraintPart.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ContactConstraintManager.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/ContactConstraintManager.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/DistanceConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/DistanceConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/FixedConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/FixedConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/GearConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/GearConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/HingeConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/HingeConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/MotorSettings.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/MotorSettings.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PathConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PathConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PathConstraintPath.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PathConstraintPath.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PathConstraintPathHermite.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PathConstraintPathHermite.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PointConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PointConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PulleyConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/PulleyConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/RackAndPinionConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/RackAndPinionConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/SixDOFConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/SixDOFConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/SliderConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/SliderConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/SwingTwistConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/SwingTwistConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/TwoBodyConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Constraints/TwoBodyConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/DeterminismLog.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/DeterminismLog.h',
'thirdparty/JoltPhysics/Jolt/Physics/EActivation.h',
'thirdparty/JoltPhysics/Jolt/Physics/IslandBuilder.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/IslandBuilder.h',
'thirdparty/JoltPhysics/Jolt/Physics/LargeIslandSplitter.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/LargeIslandSplitter.h',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsLock.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsLock.h',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsScene.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsScene.h',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsSettings.h',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsStepListener.h',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsSystem.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsSystem.h',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsUpdateContext.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/PhysicsUpdateContext.h',
'thirdparty/JoltPhysics/Jolt/Physics/Ragdoll/Ragdoll.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Ragdoll/Ragdoll.h',
'thirdparty/JoltPhysics/Jolt/Physics/StateRecorder.h',
'thirdparty/JoltPhysics/Jolt/Physics/StateRecorderImpl.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/StateRecorderImpl.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/TrackedVehicleController.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/TrackedVehicleController.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleAntiRollBar.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleAntiRollBar.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleCollisionTester.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleCollisionTester.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleConstraint.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleConstraint.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleController.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleController.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleDifferential.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleDifferential.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleEngine.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleEngine.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleTrack.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleTrack.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleTransmission.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/VehicleTransmission.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/Wheel.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/Wheel.h',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/WheeledVehicleController.cpp',
'thirdparty/JoltPhysics/Jolt/Physics/Vehicle/WheeledVehicleController.h',
'thirdparty/JoltPhysics/Jolt/RegisterTypes.cpp',
'thirdparty/JoltPhysics/Jolt/RegisterTypes.h',
'thirdparty/JoltPhysics/Jolt/Renderer/DebugRenderer.cpp',
'thirdparty/JoltPhysics/Jolt/Renderer/DebugRenderer.h',
'thirdparty/JoltPhysics/Jolt/Renderer/DebugRendererPlayback.cpp',
'thirdparty/JoltPhysics/Jolt/Renderer/DebugRendererPlayback.h',
'thirdparty/JoltPhysics/Jolt/Renderer/DebugRendererRecorder.cpp',
'thirdparty/JoltPhysics/Jolt/Renderer/DebugRendererRecorder.h',
'thirdparty/JoltPhysics/Jolt/Skeleton/SkeletalAnimation.cpp',
'thirdparty/JoltPhysics/Jolt/Skeleton/SkeletalAnimation.h',
'thirdparty/JoltPhysics/Jolt/Skeleton/Skeleton.cpp',
'thirdparty/JoltPhysics/Jolt/Skeleton/Skeleton.h',
'thirdparty/JoltPhysics/Jolt/Skeleton/SkeletonMapper.cpp',
'thirdparty/JoltPhysics/Jolt/Skeleton/SkeletonMapper.h',
'thirdparty/JoltPhysics/Jolt/Skeleton/SkeletonPose.cpp',
'thirdparty/JoltPhysics/Jolt/Skeleton/SkeletonPose.h',
'thirdparty/JoltPhysics/Jolt/TriangleGrouper/TriangleGrouper.h',
'thirdparty/JoltPhysics/Jolt/TriangleGrouper/TriangleGrouperClosestCentroid.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleGrouper/TriangleGrouperClosestCentroid.h',
'thirdparty/JoltPhysics/Jolt/TriangleGrouper/TriangleGrouperMorton.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleGrouper/TriangleGrouperMorton.h',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitter.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitter.h',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterBinning.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterBinning.h',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterFixedLeafSize.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterFixedLeafSize.h',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterLongestAxis.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterLongestAxis.h',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterMean.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterMean.h',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterMorton.cpp',
'thirdparty/JoltPhysics/Jolt/TriangleSplitter/TriangleSplitterMorton.h',
])
subdir('src')

View File

@ -27,6 +27,48 @@
#include <spng.h>
#include <iomanip>
#include <Jolt/Jolt.h>
#include <Jolt/RegisterTypes.h>
#include <Jolt/Core/TempAllocator.h>
#include <Jolt/Core/JobSystemThreadPool.h>
#include <Jolt/Core/Factory.h>
#include <Jolt/Skeleton/Skeleton.h>
#include <Jolt/Physics/PhysicsSystem.h>
#include <Jolt/Physics/PhysicsScene.h>
#include <Jolt/Physics/Body/Body.h>
#include <Jolt/Physics/Body/BodyCreationSettings.h>
#include <Jolt/Physics/Collision/RayCast.h>
#include <Jolt/Physics/Collision/CastResult.h>
#include <Jolt/Physics/Collision/CollidePointResult.h>
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
#include <Jolt/Physics/Collision/Shape/MeshShape.h>
#include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
#include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
#include <Jolt/Physics/Collision/Shape/MeshShape.h>
#include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
#include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
#include <Jolt/Physics/Ragdoll/Ragdoll.h>
#include <Jolt/Physics/Collision/ShapeCast.h>
#include <Jolt/Physics/Collision/CollisionDispatch.h>
#include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
#include <Jolt/Physics/Collision/GroupFilter.h>
#include <Jolt/Physics/Collision/GroupFilterTable.h>
#include <Jolt/Physics/Constraints/ConeConstraint.h>
#include <Jolt/Physics/Constraints/PointConstraint.h>
#include <Jolt/Physics/Constraints/HingeConstraint.h>
#include <Jolt/Physics/Constraints/SwingTwistConstraint.h>
#include <Jolt/Physics/Constraints/FixedConstraint.h>
#include <Jolt/Physics/Constraints/SixDOFConstraint.h>
#include <Jolt/Physics/Constraints/DistanceConstraint.h>
#include <Jolt/Physics/Constraints/SliderConstraint.h>
#include <Jolt/Physics/Vehicle/VehicleConstraint.h>
#include <Jolt/Physics/Vehicle/VehicleCollisionTester.h>
#include <Jolt/Physics/Vehicle/WheeledVehicleController.h>
using namespace orange;
struct MiniPipelineInfo
@ -217,11 +259,7 @@ int main(int argc, char** argv)
if (!r_swapchain)
return 1;
//auto r_objData = fs::OpenFileIntoTextBuffer("/home/joshua/gman.obj");
//auto r_objData = fs::OpenFileIntoTextBuffer("/home/joshua/chair.obj");
auto r_objData = fs::OpenFileIntoTextBuffer("/home/joshua/frog.obj");
//auto r_objData = fs::OpenFileIntoTextBuffer("/home/joshua/deck.obj");
//auto r_objData = fs::OpenFileIntoTextBuffer("/home/joshua/cube.obj");
if (!r_objData)
return 1;
@ -243,61 +281,6 @@ int main(int argc, char** argv)
auto r_mesh = ParseOBJ(*r_objData);
#if 0
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
for (auto& vertex : r_mesh->vertexData.GetStaticVertices()) {
std::cout << std::hexfloat;
std::cout << "{ ";
std::cout << "{ " << std::setw(16) << vertex.pos[0] << ", " << std::setw(16) << vertex.pos[1] << ", " << std::setw(16) << vertex.pos[2] << " }, ";
std::cout << "{ " << std::setw(16) << vertex.uv[0] << ", " << std::setw(16) << vertex.uv[1] << " }, ";
std::cout << "{ " << std::setw(16) << vertex.normal[0] << ", " << std::setw(16) << vertex.normal[1] << ", " << std::setw(16) << vertex.normal[2] << " } ";
std::cout << "},";
std::cout << std::endl;
}
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
#endif
#if 0
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
int count = 0;
for (auto& index : r_mesh->indices) {
std::cout << std::setw(4) << index << "u, ";
count++;
if (count >= 16) {
std::cout << std::endl;
count = 0;
}
}
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
#endif
auto r_vmf = fs::OpenFileIntoTextBuffer("/home/joshua/Code/Desolation/game/sdk_content/maps/hl2_sdk/sdk_phys_constraint.vmf");
auto r_vmfkv = kv::KeyValues::ParseFromUTF8(*r_vmf);
if (!r_vmfkv)
{
fprintf(stderr, "Parsing VMF failed!\n");
return 1;
}
kv::KeyValues &vmfkv = *r_vmfkv;
std::cout << "editorversion: " << vmfkv["versioninfo"]["editorversion"].Get<StringView>() << std::endl;
auto newVertexSlice = *pooler.AllocSlice(sizeof(StaticVertex) * r_mesh->vertexData.VertexCount(), sizeof(StaticVertex));
auto newIndexSlice = *pooler.AllocSlice(sizeof(IndexType) * r_mesh->indices.size(), sizeof(IndexType));
r_mesh->vertexData.GetStaticVertices().copy((uint8_t*)(r_buffer->ptr) + newVertexSlice.offset);
@ -666,11 +649,11 @@ int main(int argc, char** argv)
// log::info("mouse: %d %d", mouseDelta.x, mouseDelta.y);
//}
const float sensitivity = 6.0f;
const float sensitivity = 0.002f;
camera.offsetOrientation(
-sensitivity * dt * Radian( mouseDelta.x ),
sensitivity * dt * Radian( mouseDelta.y ));
-sensitivity * Radian( mouseDelta.x ),
sensitivity * Radian( mouseDelta.y ));
frameData[r_swapchain->CurrentFrame()] = FrameData
{

View File

@ -0,0 +1,855 @@
#include <Orange/Core/Array.h>
#include <Orange/Core/FileSystem.h>
#include <Orange/Core/Result.h>
#include <Orange/Core/Span.h>
#include <Orange/Core/Time.h>
#include <Orange/Core/Variant.h>
#include <Orange/Core/Vector.h>
#include <Orange/Formats/KeyValues.h>
#include <Orange/Graphics/Camera.h>
#include <Orange/Graphics/LightmapAtlas.h>
#include <Orange/Graphics/Mesh.h>
#include <Orange/Math/Matrix.h>
#include <Orange/Math/Transformation.h>
#include <Orange/Math/Vector.h>
#include <Orange/Render/RenderContext.h>
#include <Orange/Render/Swapchain.h>
#include <Orange/Render/VulkanHelpers.h>
#include <Orange/Render/Window.h>
#include <vs_Mesh.h>
#include <vs_Fullscreen.h>
#include <fs_DebugVertColor.h>
#include <fs_Mesh.h>
#include <fs_SkyGradient.h>
#include <fs_Red.h>
#include <iostream>
#include <spng.h>
#include <iomanip>
using namespace orange;
struct MiniPipelineInfo
{
VkShaderModule vs;
VkShaderModule fs;
VkPipelineLayout pipelineLayout;
VkFormat colorFormat;
VkFormat depthFormat;
bool enableDepthTest;
bool enableDepthWrites;
Span<const VkVertexInputAttributeDescription> vertexAttributes;
};
static VulkanResult<VkPipeline> CreateGraphicsPipeline(VkDevice device, const MiniPipelineInfo& info)
{
VkPipelineShaderStageCreateInfo stages[] =
{
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = info.vs,
.pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = info.fs,
.pName = "main",
},
};
Array<VkDynamicState, 2> dynamicStates =
{
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR,
};
VkPipelineDynamicStateCreateInfo dynamicStateInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.dynamicStateCount = uint32_t(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(),
};
VkVertexInputBindingDescription inputBindingDescription =
{
.binding = 0,
.stride = sizeof(StaticVertex),
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
};
VkPipelineVertexInputStateCreateInfo vertexInputInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.vertexBindingDescriptionCount = info.vertexAttributes.size ? 1u : 0u,
.pVertexBindingDescriptions = &inputBindingDescription,
.vertexAttributeDescriptionCount = uint32_t(info.vertexAttributes.size),
.pVertexAttributeDescriptions = info.vertexAttributes.data,
};
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.primitiveRestartEnable = VK_FALSE,
};
VkPipelineViewportStateCreateInfo viewportStateInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
.viewportCount = 1,
.scissorCount = 1,
};
VkPipelineRasterizationStateCreateInfo rasterizationInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
.cullMode = VK_CULL_MODE_BACK_BIT,
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
.lineWidth = 1.0f,
};
VkPipelineMultisampleStateCreateInfo multisampleInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
};
VkPipelineDepthStencilStateCreateInfo depthStencilInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
.depthTestEnable = info.enableDepthTest,
.depthWriteEnable = info.enableDepthWrites,
.depthCompareOp = VK_COMPARE_OP_LESS,
.minDepthBounds = 0.0f,
.maxDepthBounds = 1.0f,
};
VkPipelineColorBlendAttachmentState attachmentBlendState =
{
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
};
VkPipelineColorBlendStateCreateInfo colorBlendStateInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
.attachmentCount = 1,
.pAttachments = &attachmentBlendState,
};
VkPipelineRenderingCreateInfo renderingInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.viewMask = 0u,
.colorAttachmentCount = 1u,
.pColorAttachmentFormats = &info.colorFormat,
.depthAttachmentFormat = info.depthFormat,
};
VkGraphicsPipelineCreateInfo pipelineInfo =
{
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.pNext = &renderingInfo,
.stageCount = Size(stages),
.pStages = stages,
.pVertexInputState = &vertexInputInfo,
.pInputAssemblyState = &inputAssemblyInfo,
.pViewportState = &viewportStateInfo,
.pRasterizationState = &rasterizationInfo,
.pMultisampleState = &multisampleInfo,
.pDepthStencilState = &depthStencilInfo,
.pColorBlendState = &colorBlendStateInfo,
.pDynamicState = &dynamicStateInfo,
.layout = info.pipelineLayout,
};
VkPipeline pipeline = VK_NULL_HANDLE;
VkResult res = VK_SUCCESS;
if ((res = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline)) != VK_SUCCESS)
return VulkanResult<VkPipeline>::Error(res);
return VulkanResult<VkPipeline>::Success(pipeline);
}
struct alignas(16) Mesh
{
uint32_t textureIdx;
uint32_t vertexOffset; // in sizeof(Vertex)
uint32_t indexOffset; // in sizeof(IndexType)
uint32_t indexCount;
AABB bounds;
};
struct alignas(16) Renderable
{
mat4 transform;
uint32_t meshIdx;
vec3 color; // should replace with something more interesting lmao
};
// look at moving me if binary is big
SmallVector<Mesh, 1024> g_meshes;
SmallVector<Renderable, 1024> g_renderables;
int main(int argc, char** argv)
{
(void)argc; (void)argv;
auto r_window = Window::Create();
if (!r_window)
return 1;
auto r_renderContext = RenderContext::Create("Cube Test");
if (!r_renderContext)
return 1;
auto r_surface = r_window->CreateSurface(r_renderContext->Instance());
if (!r_surface)
return 1;
auto r_swapchain = Swapchain::Create(*r_renderContext, *r_surface);
if (!r_swapchain)
return 1;
auto r_objData = fs::OpenFileIntoTextBuffer("/home/joshua/frog.obj");
if (!r_objData)
return 1;
auto r_buffer = r_renderContext->CreateBuffer(1024 * 1024 * 1024);
if (!r_buffer)
return 1;
auto pooler = MemoryPool{ *r_buffer };
auto r_vsMesh = r_renderContext->CreateShader(vs_Mesh);
if (!r_vsMesh) return 1;
auto r_vsFullscreen = r_renderContext->CreateShader(vs_Fullscreen);
if (!r_vsFullscreen) return 1;
auto r_fsMesh = r_renderContext->CreateShader(fs_Mesh);
if (!r_fsMesh) return 1;
auto r_fsRed = r_renderContext->CreateShader(fs_Red);
if (!r_fsRed) return 1;
auto r_fsSky = r_renderContext->CreateShader(fs_SkyGradient);
if (!r_fsSky) return 1;
auto r_mesh = ParseOBJ(*r_objData);
if (!r_mesh) return 1;
auto r_atlas = CreateLightmapAtlasForMesh(*r_mesh);
if (!r_atlas) return 1;
auto atlas = std::move(*r_atlas);
auto lightmapDebugTex = GenerateDebugAtlasTexture(atlas);
auto newVertexSlice = *pooler.AllocSlice(sizeof(StaticVertex) * r_mesh->vertexData.VertexCount(), sizeof(StaticVertex));
auto newIndexSlice = *pooler.AllocSlice(sizeof(IndexType) * r_mesh->indices.size(), sizeof(IndexType));
r_mesh->vertexData.GetStaticVertices().copy((uint8_t*)(r_buffer->ptr) + newVertexSlice.offset);
r_mesh->indices.copy ((uint8_t*)(r_buffer->ptr) + newIndexSlice.offset);
uint32_t meshIdx = uint32_t(g_meshes.emplace_back(Mesh
{
.textureIdx = 0,
.vertexOffset = uint32_t(newVertexSlice.offset / sizeof(StaticVertex)),
.indexOffset = uint32_t(newIndexSlice.offset / sizeof(IndexType)),
.indexCount = uint32_t(r_mesh->indices.size()),
.bounds = r_mesh->bounds,
}));
g_renderables.emplace_back(Renderable
{
.transform = mat4{},
.meshIdx = meshIdx,
.color = 1_vec3,
});
//
#pragma region "make descriptor n shit"
VkSamplerCreateInfo samplerInfo =
{
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.magFilter = VK_FILTER_LINEAR,
.minFilter = VK_FILTER_LINEAR,
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.mipLodBias = 0.0f,
.anisotropyEnable = VK_TRUE,
.maxAnisotropy = 16.0f,
.minLod = -FLT_MAX,
.maxLod = FLT_MAX,
};
VkSampler sampler = VK_NULL_HANDLE;
vkCreateSampler(r_renderContext->Device(), &samplerInfo, nullptr, &sampler);
constexpr uint32_t MaxBindlessResources = 32768;
VkDescriptorPoolSize bindlessPoolSizes[] =
{
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2u},
{ VK_DESCRIPTOR_TYPE_SAMPLER, 1u},
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MaxBindlessResources },
};
VkDescriptorPoolCreateInfo poolInfo =
{
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
.maxSets = 1u,
.poolSizeCount = uint32_t(Size(bindlessPoolSizes)),
.pPoolSizes = bindlessPoolSizes,
};
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
vkCreateDescriptorPool(r_renderContext->Device(), &poolInfo, nullptr, &descriptorPool);
VkDescriptorSetLayoutBinding layoutBindings[] =
{
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_ALL,
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
.pImmutableSamplers = &sampler,
},
{
.binding = 2,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_ALL,
},
{
.binding = 3,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = MaxBindlessResources,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
},
};
constexpr VkDescriptorBindingFlags bindingFlags[] =
{
0,
0,
0,
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT,
};
Assert(Size(bindingFlags) == Size(layoutBindings));
VkDescriptorSetLayoutBindingFlagsCreateInfo layoutBindingFlagsInfo =
{
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT,
.bindingCount = Size(bindingFlags),
.pBindingFlags = bindingFlags,
};
VkDescriptorSetLayoutCreateInfo layoutInfo =
{
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = &layoutBindingFlagsInfo,
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT,
.bindingCount = Size(layoutBindings),
.pBindings = layoutBindings,
};
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
vkCreateDescriptorSetLayout(r_renderContext->Device(), &layoutInfo, nullptr, &descriptorSetLayout);
VkDescriptorSetVariableDescriptorCountAllocateInfoEXT descriptorCountAllocInfo =
{
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT,
.descriptorSetCount = 1,
.pDescriptorCounts = &MaxBindlessResources,
};
VkDescriptorSetAllocateInfo descriptorSetAllocInfo =
{
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.pNext = &descriptorCountAllocInfo,
.descriptorPool = descriptorPool,
.descriptorSetCount = 1,
.pSetLayouts = &descriptorSetLayout,
};
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
vkAllocateDescriptorSets(r_renderContext->Device(), &descriptorSetAllocInfo, &descriptorSet);
struct PushConstants
{
uint32_t frameIdx;
};
VkPushConstantRange pushConstantRange =
{
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
.size = sizeof(PushConstants),
};
VkPipelineLayoutCreateInfo pipelineLayoutInfo =
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = 1,
.pSetLayouts = &descriptorSetLayout,
.pushConstantRangeCount = 1,
.pPushConstantRanges = &pushConstantRange,
};
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
vkCreatePipelineLayout(r_renderContext->Device(), &pipelineLayoutInfo, nullptr, &pipelineLayout);
//
VkFormat depthFormat = *FindDepthFormat(r_renderContext->PhysicalDevice());
auto pipeline = *CreateGraphicsPipeline(r_renderContext->Device(), MiniPipelineInfo
{
.vs = *r_vsMesh,
.fs = *r_fsMesh,
.pipelineLayout = pipelineLayout,
.colorFormat = FormatToSrgbFormat(r_swapchain->Format()),
.depthFormat = depthFormat,
.enableDepthTest = true,
.enableDepthWrites = true,
.vertexAttributes = Span<const VkVertexInputAttributeDescription>(StaticVertex::Attributes),
});
auto skyPipeline = *CreateGraphicsPipeline(r_renderContext->Device(), MiniPipelineInfo
{
.vs = *r_vsFullscreen,
.fs = *r_fsSky,
.pipelineLayout = pipelineLayout,
.colorFormat = FormatToSrgbFormat(r_swapchain->Format()),
.depthFormat = depthFormat,
.enableDepthTest = false,
.enableDepthWrites = false,
.vertexAttributes = Span<const VkVertexInputAttributeDescription>(nullptr),
});
#pragma endregion
struct ImageUpload
{
BufferSlice from;
VkImage to;
VkExtent3D extent;
};
Vector<ImageUpload> imageUploads;
//auto r_pngData = fs::OpenFileIntoBuffer("/home/joshua/chair_color.png");
auto r_pngData = fs::OpenFileIntoBuffer("/home/joshua/frog001.png");
//auto r_pngData = fs::OpenFileIntoBuffer("/home/joshua/deck.png");
if (!r_pngData)
return 1;
spng_ctx *ctx = spng_ctx_new(0);
spng_set_png_buffer(ctx, r_pngData->data, r_pngData->size);
size_t pngOutSize = 0zu;
spng_decoded_image_size(ctx, SPNG_FMT_RGBA8, &pngOutSize);
auto pngLinearSlice = *pooler.AllocSlice(pngOutSize, 16);
spng_decode_image(ctx, pngLinearSlice.ptr, pngOutSize, SPNG_FMT_RGBA8, 0);
struct spng_ihdr ihdr;
spng_get_ihdr(ctx, &ihdr);
spng_ctx_free(ctx);
// BLAH DEDUPE
auto r_texture = r_renderContext->CreateImage(pooler, ihdr.width, ihdr.height, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
auto r_textureView = r_renderContext->CreateImageView(*r_texture, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_ASPECT_COLOR_BIT);
{
VkDescriptorImageInfo descriptorImageInfo =
{
.imageView = *r_textureView,
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
};
VkWriteDescriptorSet writeImageDescriptorSet[] =
{
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptorSet,
.dstBinding = 3,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.pImageInfo = &descriptorImageInfo,
},
};
vkUpdateDescriptorSets(r_renderContext->Device(), Size(writeImageDescriptorSet), writeImageDescriptorSet, 0, nullptr);
imageUploads.push_back(ImageUpload
{
.from = pngLinearSlice,
.to = *r_texture,
.extent = VkExtent3D{ ihdr.width, ihdr.height, 1u },
});
}
//
auto r_lightTexture = r_renderContext->CreateImage(pooler, atlas->width, atlas->height, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
auto r_lightTextureView = r_renderContext->CreateImageView(*r_lightTexture, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_ASPECT_COLOR_BIT);
{
auto lightmapTextureData = *pooler.AllocSlice(pngOutSize, 16);
memcpy(lightmapTextureData.ptr, lightmapDebugTex.data(), lightmapDebugTex.size());
VkDescriptorImageInfo descriptorImageInfo =
{
.imageView = *r_lightTextureView,
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
};
VkWriteDescriptorSet writeImageDescriptorSet[] =
{
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptorSet,
.dstBinding = 3,
.dstArrayElement = 1,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.pImageInfo = &descriptorImageInfo,
},
};
vkUpdateDescriptorSets(r_renderContext->Device(), Size(writeImageDescriptorSet), writeImageDescriptorSet, 0, nullptr);
imageUploads.push_back(ImageUpload
{
.from = lightmapTextureData,
.to = *r_lightTexture,
.extent = VkExtent3D{ atlas->width, atlas->height, 1u },
});
}
//
Camera camera;
camera.transform.position = vec3{0.0f, 0.0f, 80.0f};
camera.viewportAspectRatio = 16.0f / 9.0f;
//camera.offsetOrientation(1_deg * Seconds(t2 - t1).count(), 0_deg);
//camera.lookAt(vec3{40.0f, 40.0f, 0.0f});
camera.transform.orientation = eulerAnglesToQuaternion(EulerAngles{ 0_deg, 0_deg, 0_deg });
auto meshData = r_mesh->vertexData.View();
auto r_depthImage = r_renderContext->CreateImage(pooler, 1280, 720, depthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
auto depthImageView = *r_renderContext->CreateImageView(*r_depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT);
struct FrameData
{
mat4 view_projection;
};
auto frameDataSlice = *pooler.AllocSlice(MaxFramesInFlight * sizeof(FrameData), 16);
FrameData* frameData = reinterpret_cast<FrameData*>(frameDataSlice.ptr);
VkDescriptorBufferInfo bufferInfo =
{
.buffer = r_buffer->buffer,
.offset = frameDataSlice.offset,
.range = frameDataSlice.size,
};
VkWriteDescriptorSet writeDescriptorSet[] =
{
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptorSet,
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pBufferInfo = &bufferInfo,
},
};
vkUpdateDescriptorSets(r_renderContext->Device(), Size(writeDescriptorSet), writeDescriptorSet, 0, nullptr);
struct Renderables
{
Renderable renderables[1024];
};
auto renderablesSlice = *pooler.AllocSlice(MaxFramesInFlight * sizeof(Renderables), 16);
Renderables* gpuRenderables = reinterpret_cast<Renderables*>(renderablesSlice.ptr);
VkDescriptorBufferInfo renderblesBufferInfo =
{
.buffer = r_buffer->buffer,
.offset = renderablesSlice.offset,
.range = renderablesSlice.size,
};
VkWriteDescriptorSet renderablesWriteDescriptorSet[] =
{
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptorSet,
.dstBinding = 2,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pBufferInfo = &renderblesBufferInfo,
},
};
vkUpdateDescriptorSets(r_renderContext->Device(), Size(renderablesWriteDescriptorSet), renderablesWriteDescriptorSet, 0, nullptr);
Input::InputHandler handler;
r_window->EnableRelativeMouse(true);
auto indirectBuffer = *pooler.AllocSlice(1024 * sizeof(VkDrawIndexedIndirectCommand), 256);
auto indirectPtr = reinterpret_cast<VkDrawIndexedIndirectCommand *>(indirectBuffer.ptr);
for (size_t i = 0; i < g_renderables.size(); i++) {
const auto& renderable = g_renderables[i];
const uint32_t meshIdx = renderable.meshIdx;
indirectPtr[i] = VkDrawIndexedIndirectCommand
{
.indexCount = g_meshes[meshIdx].indexCount,
.instanceCount = 1u,
.firstIndex = g_meshes[meshIdx].indexOffset,
.vertexOffset = int32_t(g_meshes[meshIdx].vertexOffset),
.firstInstance = 0u,
};
}
auto countBuffer = *pooler.AllocSlice(sizeof(uint32_t), 16);
auto countPtr = reinterpret_cast<uint32_t*>(countBuffer.ptr);
*countPtr = uint32_t(g_renderables.size());
auto t1 = Time::now();
while (r_window->Update(handler))
{
const auto t2 = Time::now();
auto delta = t2 - t1;
const float dt = Seconds(delta).count();
t1 = t2;
//char title[64];
//stbsp_snprintf(title, sizeof(title), "CubeTest - %gfps", 1.0f / dt);
//r_window->SetTitle(title);
{
auto mouseDelta = handler.getMouseMotionDelta();
auto scrollDelta = handler.getMouseScrollDelta();
//if (mouseDelta.x || mouseDelta.y)
//{
// log::info("mouse: %d %d", mouseDelta.x, mouseDelta.y);
//}
const float sensitivity = 0.002f;
camera.offsetOrientation(
-sensitivity * Radian( mouseDelta.x ),
sensitivity * Radian( mouseDelta.y ));
frameData[r_swapchain->CurrentFrame()] = FrameData
{
.view_projection = camera.projection() * camera.view(),
};
g_renderables.copy(gpuRenderables[r_swapchain->CurrentFrame()].renderables);
const float movementSpeed = handler.get(Input::ButtonCodes::Key_LShift) ? 64.0f : 16.0f;
if (scrollDelta.y)
{
camera.fieldOfView += Radian(5_deg) * -scrollDelta.y;
camera.fieldOfView = Clamp(camera.fieldOfView, Radian(5_deg), Radian(175_deg));
}
if (handler.get(Input::ButtonCodes::Key_W))
camera.transform.position += camera.forward() * movementSpeed * dt;
else if (handler.get(Input::ButtonCodes::Key_S))
camera.transform.position += camera.backward() * movementSpeed * dt;
if (handler.get(Input::ButtonCodes::Key_A))
camera.transform.position += camera.left() * movementSpeed * dt;
else if (handler.get(Input::ButtonCodes::Key_D))
camera.transform.position += camera.right() * movementSpeed * dt;
}
VkCommandBuffer cmdBuf = r_swapchain->CommandBuffer();
r_renderContext->BeginCommandBuffer(cmdBuf);
{
for (auto& upload : imageUploads)
{
VkImageMemoryBarrier transferBarrier =
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.image = upload.to,
.subresourceRange = FirstColorMipSubresourceRange,
};
vkCmdPipelineBarrier(cmdBuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &transferBarrier);
VkBufferImageCopy region =
{
.bufferOffset = upload.from.offset,
.imageSubresource =
{
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.mipLevel = 0u,
.baseArrayLayer = 0u,
.layerCount = 1u,
},
.imageExtent = upload.extent,
};
vkCmdCopyBufferToImage(cmdBuf, upload.from.buffer, upload.to, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
VkImageMemoryBarrier optimalBarrier =
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.image = upload.to,
.subresourceRange = FirstColorMipSubresourceRange,
};
vkCmdPipelineBarrier(cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1, &optimalBarrier);
}
imageUploads.clear();
VkViewport viewport =
{
.x = 0.0f,
.y = 0.0f,
.width = float(r_swapchain->Extent().width),
.height = float(r_swapchain->Extent().height),
.minDepth = 0.0f,
.maxDepth = 1.0f,
};
VkRect2D scissor =
{
.offset = {0u, 0u},
.extent = r_swapchain->Extent(),
};
vkCmdSetViewport(cmdBuf, 0, 1, &viewport);
vkCmdSetScissor(cmdBuf, 0, 1, &scissor);
PushConstants pushConstants =
{
.frameIdx = r_swapchain->CurrentFrame(),
};
vkCmdPushConstants(cmdBuf, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(PushConstants), &pushConstants);
vkCmdBindDescriptorSets(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
VkDeviceSize zero = 0;
VkDeviceSize wholeSize = VK_WHOLE_SIZE;
VkDeviceSize validationBruhMoment = r_buffer->size;
//vkCmdBindVertexBuffers2(cmdBuf, 0, 1, &r_buffer->buffer, &zero, &wholeSize, nullptr);
vkCmdBindVertexBuffers2(cmdBuf, 0, 1, &r_buffer->buffer, &zero, &validationBruhMoment, nullptr);
vkCmdBindIndexBuffer(cmdBuf, r_buffer->buffer, zero, VulkanIndexType);
const VkImageMemoryBarrier undefinedToColorBarrier =
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.image = r_swapchain->Image(),
.subresourceRange = FirstColorMipSubresourceRange,
};
vkCmdPipelineBarrier(
cmdBuf,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
0,
0, nullptr,
0, nullptr,
1, &undefinedToColorBarrier);
const VkImageMemoryBarrier undefinedToDepthBarrier =
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.image = *r_depthImage,
.subresourceRange = FirstDepthMipSubresourceRange,
};
vkCmdPipelineBarrier(
cmdBuf,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
0,
0, nullptr,
0, nullptr,
1, &undefinedToDepthBarrier);
const VkRenderingAttachmentInfoKHR colorAttachmentInfos[] =
{
{
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR,
.imageView = r_swapchain->ImageView(),
.imageLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.clearValue = { .color = { .float32 = { 1.0f, 1.0f, 1.0f, 1.0f } } },
},
};
const VkRenderingAttachmentInfoKHR depthAttachmentInfo =
{
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR,
.imageView = depthImageView,
.imageLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.clearValue = { .color = { .float32 = { 1.0f, 1.0f, 1.0f, 1.0f } } },
};
const VkRenderingInfo renderInfo =
{
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.renderArea = { {}, r_swapchain->Extent() },
.layerCount = 1,
.colorAttachmentCount = Size(colorAttachmentInfos),
.pColorAttachments = colorAttachmentInfos,
.pDepthAttachment = &depthAttachmentInfo,
};
vkCmdBeginRendering(cmdBuf, &renderInfo);
{
vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, skyPipeline);
vkCmdDraw(cmdBuf, 3, 1, 0, 0);
vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdDrawIndexedIndirectCount(cmdBuf, indirectBuffer.buffer, indirectBuffer.offset, countBuffer.buffer, countBuffer.offset, 1024u, sizeof(VkDrawIndexedIndirectCommand));
}
vkCmdEndRendering(cmdBuf);
const VkImageMemoryBarrier colorToPresentBarrier =
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
.image = r_swapchain->Image(),
.subresourceRange = FirstColorMipSubresourceRange,
};
vkCmdPipelineBarrier(
cmdBuf,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0,
0, nullptr,
0, nullptr,
1, &colorToPresentBarrier);
}
r_renderContext->EndCommandBuffer(cmdBuf);
r_swapchain->Present();
}
return 0;
}

View File

@ -1,9 +1,14 @@
executable('CubeTest', 'CubeTest.cpp', orange_src, orange_shaders,
executable('FrogTest', 'FrogTest.cpp', orange_src, orange_shaders, joltphysics_src, xatlas_src,
dependencies : [ sdl2_dep, vulkan_dep, spng_dep, miniz_dep ],
include_directories : [ orange_include ]
include_directories : [ orange_include, xatlas_include, joltphysics_include ]
)
executable('HDRTest', 'HDRTest.cpp', orange_src, orange_shaders,
executable('Lightmapper', 'Lightmapper.cpp', orange_src, orange_shaders, xatlas_src,
dependencies : [ sdl2_dep, vulkan_dep, spng_dep, miniz_dep ],
include_directories : [ orange_include ]
include_directories : [ orange_include, xatlas_include, joltphysics_include ]
)
executable('HDRTest', 'HDRTest.cpp', orange_src, orange_shaders, xatlas_src,
dependencies : [ sdl2_dep, vulkan_dep, spng_dep, miniz_dep ],
include_directories : [ orange_include, xatlas_include, joltphysics_include ]