Include older iterations as separate applications.
This commit is contained in:
parent
5f8a4656fe
commit
b552a09885
24
private/sdl_gpu_test/0_clear_swapchain/app.cpp
Normal file
24
private/sdl_gpu_test/0_clear_swapchain/app.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#include "./app.hpp"
|
||||||
|
|
||||||
|
namespace sdl_gpu_test
|
||||||
|
{
|
||||||
|
void ClearSwapchainApp::update(const AppUpdateArgs& args)
|
||||||
|
{
|
||||||
|
Application::update(args);
|
||||||
|
|
||||||
|
sdlpp::GPUCommandBuffer cmdBuffer = mDevice.acquireCommandBuffer();
|
||||||
|
Uint32 swapchainWidth = 0, swapchainHeight = 0;
|
||||||
|
sdlpp::GPUTexture swapchainTexture = cmdBuffer.acquireSwapchainTexture(mWindow, swapchainWidth, swapchainHeight);
|
||||||
|
std::array colorTargets = {sdlpp::GPUColorTargetInfo{
|
||||||
|
.texture = swapchainTexture,
|
||||||
|
.clearColor = {.r = 1.f, .g = 0.f, .b = 0.f, .a = 1.f},
|
||||||
|
.loadOp = sdlpp::GPULoadOp::CLEAR,
|
||||||
|
}};
|
||||||
|
sdlpp::GPURenderPass renderPass = cmdBuffer.beginRenderPass({
|
||||||
|
.colorTargetInfos = colorTargets
|
||||||
|
});
|
||||||
|
renderPass.end();
|
||||||
|
cmdBuffer.submit();
|
||||||
|
}
|
||||||
|
}
|
18
private/sdl_gpu_test/0_clear_swapchain/app.hpp
Normal file
18
private/sdl_gpu_test/0_clear_swapchain/app.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_0_CLEAR_SWAPCHAIN_APP_HPP_INCLUDED)
|
||||||
|
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_0_CLEAR_SWAPCHAIN_APP_HPP_INCLUDED 1
|
||||||
|
|
||||||
|
#include "../application.hpp"
|
||||||
|
|
||||||
|
namespace sdl_gpu_test
|
||||||
|
{
|
||||||
|
class ClearSwapchainApp : public Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void update(const AppUpdateArgs& args) override;
|
||||||
|
};
|
||||||
|
} // namespace sdl_gpu_test
|
||||||
|
|
||||||
|
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_0_CLEAR_SWAPCHAIN_APP_HPP_INCLUDED)
|
91
private/sdl_gpu_test/1_green_triangle/app.cpp
Normal file
91
private/sdl_gpu_test/1_green_triangle/app.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
|
||||||
|
#include "./app.hpp"
|
||||||
|
|
||||||
|
namespace sdl_gpu_test
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const char* const VERTEX_SOURCE = R"(
|
||||||
|
#version 460
|
||||||
|
const vec2 vertices[3] = vec2[3](
|
||||||
|
vec2(-0.5, 0.5),
|
||||||
|
vec2( 0.5, 0.5),
|
||||||
|
vec2( 0.0, -0.5)
|
||||||
|
);
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(vertices[gl_VertexIndex], 0.0, 1.0);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
const char* const FRAGMENT_SOURCE = R"(
|
||||||
|
#version 460
|
||||||
|
layout(location = 0)
|
||||||
|
out vec4 o_color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
o_color = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
void GreenTriangleApp::init(const AppInitArgs& args)
|
||||||
|
{
|
||||||
|
Application::init(args);
|
||||||
|
|
||||||
|
// create vertex shader
|
||||||
|
mijin::TypelessBuffer vertexSpv = getFileContentsBinary("shaders/glsl/triangle.vert.spv");
|
||||||
|
sdlpp::GPUShader vertexShader;
|
||||||
|
vertexShader.create(mDevice, {
|
||||||
|
.code = {static_cast<const Uint8*>(vertexSpv.data()), vertexSpv.byteSize()},
|
||||||
|
.format = sdlpp::GPUShaderFormat::SPIRV,
|
||||||
|
.stage = sdlpp::GPUShaderStage::VERTEX
|
||||||
|
});
|
||||||
|
|
||||||
|
// create fragment shader
|
||||||
|
mijin::TypelessBuffer fragmentSpv = getFileContentsBinary("shaders/glsl/green.frag.spv");
|
||||||
|
sdlpp::GPUShader fragmentShader;
|
||||||
|
fragmentShader.create(mDevice, {
|
||||||
|
.code = {static_cast<const Uint8*>(fragmentSpv.data()), fragmentSpv.byteSize()},
|
||||||
|
.format = sdlpp::GPUShaderFormat::SPIRV,
|
||||||
|
.stage = sdlpp::GPUShaderStage::FRAGMENT
|
||||||
|
});
|
||||||
|
|
||||||
|
// create graphics pipeline
|
||||||
|
std::array colorTargetsDescs = {
|
||||||
|
sdlpp::GPUColorTargetDescription{
|
||||||
|
.format = mDevice.getSwapchainTextureFormat(mWindow)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mPipeline.create(mDevice, {
|
||||||
|
.vertexShader = vertexShader,
|
||||||
|
.fragmentShader = fragmentShader,
|
||||||
|
.targetInfo = {
|
||||||
|
.colorTargetDescriptions = colorTargetsDescs
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void GreenTriangleApp::update(const AppUpdateArgs& args)
|
||||||
|
{
|
||||||
|
Application::update(args);
|
||||||
|
|
||||||
|
sdlpp::GPUCommandBuffer cmdBuffer = mDevice.acquireCommandBuffer();
|
||||||
|
Uint32 swapchainWidth = 0, swapchainHeight = 0;
|
||||||
|
sdlpp::GPUTexture swapchainTexture = cmdBuffer.acquireSwapchainTexture(mWindow, swapchainWidth, swapchainHeight);
|
||||||
|
std::array colorTargets = {sdlpp::GPUColorTargetInfo{
|
||||||
|
.texture = swapchainTexture,
|
||||||
|
.clearColor = {.r = 1.f, .g = 0.f, .b = 0.f, .a = 1.f},
|
||||||
|
.loadOp = sdlpp::GPULoadOp::CLEAR,
|
||||||
|
}};
|
||||||
|
sdlpp::GPURenderPass renderPass = cmdBuffer.beginRenderPass({
|
||||||
|
.colorTargetInfos = colorTargets
|
||||||
|
});
|
||||||
|
renderPass.bindGraphicsPipeline(mPipeline);
|
||||||
|
renderPass.drawPrimitives({.numVertices = 3});
|
||||||
|
renderPass.end();
|
||||||
|
cmdBuffer.submit();
|
||||||
|
}
|
||||||
|
}
|
21
private/sdl_gpu_test/1_green_triangle/app.hpp
Normal file
21
private/sdl_gpu_test/1_green_triangle/app.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_1_GREEN_TRIANGLE_APP_HPP_INCLUDED)
|
||||||
|
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_1_GREEN_TRIANGLE_APP_HPP_INCLUDED 1
|
||||||
|
|
||||||
|
#include "../application.hpp"
|
||||||
|
|
||||||
|
namespace sdl_gpu_test
|
||||||
|
{
|
||||||
|
class GreenTriangleApp : public Application
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
sdlpp::GPUGraphicsPipeline mPipeline;
|
||||||
|
public:
|
||||||
|
void init(const AppInitArgs& args) override;
|
||||||
|
void update(const AppUpdateArgs& args) override;
|
||||||
|
};
|
||||||
|
} // namespace sdl_gpu_test
|
||||||
|
|
||||||
|
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_1_GREEN_TRIANGLE_APP_HPP_INCLUDED)
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_0_TRIANGLE_WITH_TEXCOORDS_APP_HPP_INCLUDED)
|
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_2_TRIANGLE_WITH_TEXCOORDS_APP_HPP_INCLUDED)
|
||||||
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_0_TRIANGLE_WITH_TEXCOORDS_APP_HPP_INCLUDED 1
|
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_2_TRIANGLE_WITH_TEXCOORDS_APP_HPP_INCLUDED 1
|
||||||
|
|
||||||
#include "../application.hpp"
|
#include "../application.hpp"
|
||||||
|
|
||||||
@ -19,4 +19,4 @@ public:
|
|||||||
};
|
};
|
||||||
} // namespace sdl_gpu_test
|
} // namespace sdl_gpu_test
|
||||||
|
|
||||||
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_0_TRIANGLE_WITH_TEXCOORDS_APP_HPP_INCLUDED)
|
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_2_TRIANGLE_WITH_TEXCOORDS_APP_HPP_INCLUDED)
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_1_TEXTURED_QUAD_APP_HPP_INCLUDED)
|
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_3_TEXTURED_QUAD_APP_HPP_INCLUDED)
|
||||||
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_1_TEXTURED_QUAD_APP_HPP_INCLUDED 1
|
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_3_TEXTURED_QUAD_APP_HPP_INCLUDED 1
|
||||||
|
|
||||||
#include "../application.hpp"
|
#include "../application.hpp"
|
||||||
|
|
||||||
@ -21,4 +21,4 @@ public:
|
|||||||
};
|
};
|
||||||
} // namespace sdl_gpu_test
|
} // namespace sdl_gpu_test
|
||||||
|
|
||||||
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_1_TEXTURED_QUAD_APP_HPP_INCLUDED)
|
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_3_TEXTURED_QUAD_APP_HPP_INCLUDED)
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_2_TEXTURED_CUBE_APP_HPP_INCLUDED)
|
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_4_TEXTURED_CUBE_APP_HPP_INCLUDED)
|
||||||
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_2_TEXTURED_CUBE_APP_HPP_INCLUDED 1
|
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_4_TEXTURED_CUBE_APP_HPP_INCLUDED 1
|
||||||
|
|
||||||
#include "../application.hpp"
|
#include "../application.hpp"
|
||||||
|
|
||||||
@ -25,4 +25,4 @@ public:
|
|||||||
};
|
};
|
||||||
} // namespace sdl_gpu_test
|
} // namespace sdl_gpu_test
|
||||||
|
|
||||||
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_2_TEXTURED_CUBE_APP_HPP_INCLUDED)
|
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_4_TEXTURED_CUBE_APP_HPP_INCLUDED)
|
@ -8,9 +8,11 @@ src_files = Split("""
|
|||||||
util/bitmap.cpp
|
util/bitmap.cpp
|
||||||
util/mesh.cpp
|
util/mesh.cpp
|
||||||
|
|
||||||
0_triangle_with_texcoords/app.cpp
|
0_clear_swapchain/app.cpp
|
||||||
1_textured_quad/app.cpp
|
1_green_triangle/app.cpp
|
||||||
2_textured_cube/app.cpp
|
2_triangle_with_texcoords/app.cpp
|
||||||
|
3_textured_quad/app.cpp
|
||||||
|
4_textured_cube/app.cpp
|
||||||
""")
|
""")
|
||||||
|
|
||||||
shader_files = env.Glob("#assets/shaders/glsl/*.frag") \
|
shader_files = env.Glob("#assets/shaders/glsl/*.frag") \
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
#include "./0_triangle_with_texcoords/app.hpp"
|
#include "./0_clear_swapchain/app.hpp"
|
||||||
#include "./1_textured_quad/app.hpp"
|
#include "./1_green_triangle/app.hpp"
|
||||||
#include "./2_textured_cube/app.hpp"
|
#include "./2_triangle_with_texcoords/app.hpp"
|
||||||
|
#include "./3_textured_quad/app.hpp"
|
||||||
|
#include "./4_textured_cube/app.hpp"
|
||||||
|
|
||||||
#include <mijin/debug/stacktrace.hpp>
|
#include <mijin/debug/stacktrace.hpp>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
@ -23,6 +25,8 @@ int main(int argc, char* argv[])
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// make sure app is destructed before shutting down SDL
|
// make sure app is destructed before shutting down SDL
|
||||||
|
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::ClearSwapchainApp>();
|
||||||
|
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::GreenTriangleApp>();
|
||||||
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TriangleWithTexcoordsApp>();
|
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TriangleWithTexcoordsApp>();
|
||||||
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TexturedQuadApp>();
|
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TexturedQuadApp>();
|
||||||
std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TexturedCubeApp>();
|
std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TexturedCubeApp>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user