81 lines
3.5 KiB
C++
81 lines
3.5 KiB
C++
// IAEngine: 2D Game Engine by IA
|
|
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include <IAEngine/Rendering/Pipeline/PostProcess.hpp>
|
|
|
|
#include <SDL3/SDL_gpu.h>
|
|
|
|
#include <EmbeddedShaders.hpp>
|
|
|
|
namespace ia::iae
|
|
{
|
|
EXTERN SDL_GPUDevice *g_gpuDevice;
|
|
EXTERN SDL_Window *g_windowHandle;
|
|
|
|
Pipeline_PostProcess::~Pipeline_PostProcess()
|
|
{
|
|
if (m_handle)
|
|
SDL_ReleaseGPUGraphicsPipeline(g_gpuDevice, (SDL_GPUGraphicsPipeline *) m_handle);
|
|
}
|
|
|
|
RefPtr<Pipeline_PostProcess> Pipeline_PostProcess::Create()
|
|
{
|
|
const auto res = MakeRefPtr<Pipeline_PostProcess>();
|
|
|
|
const auto vertexShader = LoadShaderFromMemory(ShaderStage::VERTEX, SHADER_SOURCE_POSTPROCESS_VERT,
|
|
sizeof(SHADER_SOURCE_POSTPROCESS_VERT), 0, 0, 0, 0);
|
|
const auto pixelShader = LoadShaderFromMemory(ShaderStage::PIXEL, SHADER_SOURCE_POSTPROCESS_FRAG,
|
|
sizeof(SHADER_SOURCE_POSTPROCESS_FRAG), 2, 0, 0, 0);
|
|
|
|
SDL_GPUColorTargetDescription colorTargets[] = {{
|
|
.format = SDL_GetGPUSwapchainTextureFormat(g_gpuDevice, g_windowHandle),
|
|
}};
|
|
SDL_GPUGraphicsPipelineCreateInfo createInfo = {
|
|
.vertex_shader = (SDL_GPUShader *) vertexShader,
|
|
.fragment_shader = (SDL_GPUShader *) pixelShader,
|
|
.vertex_input_state = SDL_GPUVertexInputState{.vertex_buffer_descriptions = nullptr,
|
|
.num_vertex_buffers = 0,
|
|
.vertex_attributes = nullptr,
|
|
.num_vertex_attributes = 0},
|
|
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
|
|
.rasterizer_state = SDL_GPURasterizerState{.fill_mode = SDL_GPU_FILLMODE_FILL,
|
|
.cull_mode = SDL_GPU_CULLMODE_NONE,
|
|
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE},
|
|
.target_info = {.color_target_descriptions = colorTargets,
|
|
.num_color_targets = sizeof(colorTargets) / sizeof(colorTargets[0]),
|
|
.has_depth_stencil_target = false},
|
|
};
|
|
|
|
SDL_GPUGraphicsPipeline *handle{};
|
|
if (!(handle = SDL_CreateGPUGraphicsPipeline(g_gpuDevice, &createInfo)))
|
|
{
|
|
IAE_LOG_ERROR("Failed to create a SDL graphics pipeline: ", SDL_GetError());
|
|
return nullptr;
|
|
}
|
|
|
|
UnloadShader(pixelShader);
|
|
UnloadShader(vertexShader);
|
|
|
|
res->m_handle = (Handle) handle;
|
|
|
|
return res;
|
|
}
|
|
|
|
VOID Pipeline_PostProcess::Bind(IN Handle renderPassHandle)
|
|
{
|
|
SDL_BindGPUGraphicsPipeline((SDL_GPURenderPass *) renderPassHandle, (SDL_GPUGraphicsPipeline *) m_handle);
|
|
}
|
|
} // namespace ia::iae
|