-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
448 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#include "graphicsApp.h" | ||
#include "colorTable.h" | ||
#include "quadric/include/cube.h" | ||
#include "quadric/include/sphere.h" | ||
#include "quadric/include/teapot.h" | ||
|
||
class EdgeDetection : public GraphicsApp | ||
{ | ||
enum { | ||
Cube = 0, Teapot, Sphere, | ||
MaxObjects | ||
}; | ||
|
||
std::unique_ptr<quadric::Quadric> objects[MaxObjects]; | ||
std::shared_ptr<magma::GraphicsPipeline> depthPipeline; | ||
std::shared_ptr<magma::aux::DepthFramebuffer> depthFramebuffer; | ||
DescriptorSet descriptor; | ||
|
||
rapid::matrix objTransforms[MaxObjects]; | ||
|
||
public: | ||
explicit EdgeDetection(const AppEntry& entry): | ||
GraphicsApp(entry, TEXT("Edge detection"), 1280, 720, false) | ||
{ | ||
setupViewProjection(); | ||
setupTransforms(); | ||
createDepthFramebuffer(); | ||
createMeshObjects(); | ||
setupDescriptorSets(); | ||
setupGraphicsPipelines(); | ||
|
||
renderScene(drawCmdBuffer); | ||
blit(msaaFramebuffer->getColorView(), FrontBuffer); | ||
blit(msaaFramebuffer->getColorView(), BackBuffer); | ||
} | ||
|
||
virtual void render(uint32_t bufferIndex) override | ||
{ | ||
updateTransforms(); | ||
submitCommandBuffers(bufferIndex); | ||
sleep(2); // Cap fps | ||
} | ||
|
||
void setupViewProjection() | ||
{ | ||
viewProj = std::make_unique<LeftHandedViewProjection>(); | ||
viewProj->setPosition(0.f, 11.f, -18.f); | ||
viewProj->setFocus(0.f, 0.f, -1.f); | ||
viewProj->setFieldOfView(45.f); | ||
viewProj->setNearZ(1.f); | ||
viewProj->setFarZ(100.f); | ||
viewProj->setAspectRatio(width/(float)height); | ||
viewProj->updateView(); | ||
viewProj->updateProjection(); | ||
|
||
updateViewProjTransforms(); | ||
} | ||
|
||
void setupTransforms() | ||
{ | ||
createTransformBuffer(MaxObjects); | ||
constexpr float radius = 4.f; | ||
objTransforms[Cube] = rapid::translation(radius, 1.f, 0.f) * rapid::rotationY(rapid::radians(30.f)); | ||
objTransforms[Teapot] = rapid::translation(radius, 0.f, 0.f) * rapid::rotationY(rapid::radians(150.f)); | ||
objTransforms[Sphere] = rapid::translation(radius, 1.5f, 0.f) * rapid::rotationY(rapid::radians(270.f)); | ||
} | ||
|
||
void updateTransforms() | ||
{ | ||
const rapid::matrix rotation = rapid::rotationY(rapid::radians(-spinX/4.f)); | ||
std::vector<rapid::matrix, core::aligned_allocator<rapid::matrix>> transforms(MaxObjects); | ||
transforms[Cube] = objTransforms[Cube] * rotation, | ||
transforms[Teapot] = objTransforms[Teapot] * rotation, | ||
transforms[Sphere] = objTransforms[Sphere] * rotation, | ||
updateObjectTransforms(transforms); | ||
} | ||
|
||
void createDepthFramebuffer() | ||
{ | ||
depthFramebuffer = std::make_shared<magma::aux::DepthFramebuffer>(device, VK_FORMAT_D16_UNORM, msaaFramebuffer->getExtent()); | ||
} | ||
|
||
void createMeshObjects() | ||
{ | ||
objects[Cube] = std::make_unique<quadric::Cube>(cmdCopyBuf); | ||
objects[Teapot] = std::make_unique<quadric::Teapot>(16, cmdCopyBuf); | ||
objects[Sphere] = std::make_unique<quadric::Sphere>(1.5f, 64, 64, false, cmdCopyBuf); | ||
} | ||
|
||
void setupDescriptorSets() | ||
{ | ||
using namespace magma::bindings; | ||
using namespace magma::descriptors; | ||
descriptor.layout = std::shared_ptr<magma::DescriptorSetLayout>(new magma::DescriptorSetLayout(device, | ||
VertexStageBinding(0, DynamicUniformBuffer(1)))); | ||
descriptor.set = descriptorPool->allocateDescriptorSet(descriptor.layout); | ||
descriptor.set->update(0, transforms); | ||
} | ||
|
||
void setupGraphicsPipelines() | ||
{ | ||
depthPipeline = createDepthOnlyPipeline( | ||
"transform.o", | ||
objects[0]->getVertexInput(), | ||
descriptor.layout, | ||
depthFramebuffer); | ||
} | ||
|
||
void renderScene(std::shared_ptr<magma::CommandBuffer> cmdBuffer) | ||
{ | ||
cmdBuffer->begin(); | ||
{ | ||
depthPass(cmdBuffer); | ||
edgeDetectPass(cmdBuffer); | ||
} | ||
cmdBuffer->end(); | ||
} | ||
|
||
void depthPass(std::shared_ptr<magma::CommandBuffer> cmdBuffer) | ||
{ | ||
cmdBuffer->beginRenderPass(depthFramebuffer->getRenderPass(), depthFramebuffer->getFramebuffer(), | ||
{ | ||
magma::clears::depthOne | ||
}); | ||
{ | ||
cmdBuffer->setViewport(magma::Viewport(0, 0, depthFramebuffer->getExtent())); | ||
cmdBuffer->setScissor(magma::Scissor(0, 0, depthFramebuffer->getExtent())); | ||
cmdBuffer->bindPipeline(depthPipeline); | ||
for (uint32_t i = Cube; i < MaxObjects; ++i) | ||
{ | ||
cmdBuffer->bindDescriptorSet(depthPipeline, descriptor.set, transforms->getDynamicOffset(i)); | ||
objects[i]->draw(cmdBuffer); | ||
} | ||
} | ||
cmdBuffer->endRenderPass(); | ||
} | ||
|
||
void edgeDetectPass(std::shared_ptr<magma::CommandBuffer> cmdBuffer) | ||
{ | ||
cmdBuffer->beginRenderPass(msaaFramebuffer->getRenderPass(), msaaFramebuffer->getFramebuffer()); | ||
{ | ||
if (!bltRect) | ||
bltRect = std::make_unique<magma::aux::BlitRectangle>(renderPass, loadShader("edgeDetect.o")); | ||
bltRect->blit(cmdBuffer, | ||
depthFramebuffer->getDepthView(), | ||
VK_FILTER_NEAREST, | ||
VkRect2D{0, 0, msaaFramebuffer->getExtent()}); | ||
} | ||
cmdBuffer->endRenderPass(); | ||
} | ||
}; | ||
|
||
std::unique_ptr<IApplication> appFactory(const AppEntry& entry) | ||
{ | ||
return std::unique_ptr<EdgeDetection>(new EdgeDetection(entry)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>15.0</VCProjectVersion> | ||
<ProjectGuid>{591F9775-8088-457A-B237-A7EA1DEF699D}</ProjectGuid> | ||
<RootNamespace>edgedetection</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>$(VK_SDK_PATH)\Include;..\third-party;..\framework</AdditionalIncludeDirectories> | ||
<PreprocessorDefinitions>_DEBUG;VK_USE_PLATFORM_WIN32_KHR;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(VK_SDK_PATH)\Lib32;..\Debug</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>vulkan-1.lib;magma.lib;quadric.lib;framework.lib;Shcore.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>$(VK_SDK_PATH)\Include;..\third-party;..\framework</AdditionalIncludeDirectories> | ||
<PreprocessorDefinitions>_DEBUG;VK_USE_PLATFORM_WIN32_KHR;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<AdditionalLibraryDirectories>$(VK_SDK_PATH)\Lib;..\x64\Debug</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>vulkan-1.lib;magma.lib;quadric.lib;framework.lib;Shcore.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
<SubSystem>Windows</SubSystem> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>$(VK_SDK_PATH)\Include;..\third-party;..\framework</AdditionalIncludeDirectories> | ||
<PreprocessorDefinitions>NDEBUG;VK_USE_PLATFORM_WIN32_KHR;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(VK_SDK_PATH)\Lib32;..\Release</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>vulkan-1.lib;magma.lib;quadric.lib;framework.lib;Shcore.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>$(VK_SDK_PATH)\Include;..\third-party;..\framework</AdditionalIncludeDirectories> | ||
<PreprocessorDefinitions>NDEBUG;VK_USE_PLATFORM_WIN32_KHR;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(VK_SDK_PATH)\Lib;..\x64\Release</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>vulkan-1.lib;magma.lib;quadric.lib;framework.lib;Shcore.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="edge-detection.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="shaders\sobel.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<CustomBuild Include="shaders\edgeDetect.frag"> | ||
<FileType>Document</FileType> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).o</Outputs> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).o</Outputs> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).o</Outputs> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).o</Outputs> | ||
</CustomBuild> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<CustomBuild Include="shaders\transform.vert"> | ||
<FileType>Document</FileType> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(VK_SDK_PATH)\Bin32\glslangValidator.exe -V %(FullPath) -I..\framework\shaders -o %(Filename).o</Command> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).o</Outputs> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).o</Outputs> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).o</Outputs> | ||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).o</Outputs> | ||
</CustomBuild> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
Oops, something went wrong.