aurora: Cleanup, rename ZTest to ZComp to more accurately describe purprose, implement colored_quad

This commit is contained in:
Phillip Stephens 2022-02-20 13:06:04 -08:00
parent 2648fc50e4
commit 49418f444f
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
16 changed files with 502 additions and 48 deletions

View File

@ -432,6 +432,8 @@ public:
// TODO: implement this // TODO: implement this
} }
void onAppDisplayScaleChanged(float scale) noexcept override { ImGuiEngine_Initialize(scale); }
void onControllerButton(uint32_t idx, aurora::ControllerButton button, bool pressed) noexcept override { void onControllerButton(uint32_t idx, aurora::ControllerButton button, bool pressed) noexcept override {
if (auto* input = g_InputGenerator) { if (auto* input = g_InputGenerator) {
input->controllerButton(idx, button, pressed); input->controllerButton(idx, button, pressed);

View File

@ -84,17 +84,17 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t
bool zTest = xac_drawFlags == EGuiModelDrawFlags::Shadeless || xac_drawFlags == EGuiModelDrawFlags::Opaque; bool zTest = xac_drawFlags == EGuiModelDrawFlags::Shadeless || xac_drawFlags == EGuiModelDrawFlags::Opaque;
if (noBlur) { if (noBlur) {
aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture(), aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture(),
aurora::gfx::ZTest::LEqual, zTest, useColor, xe0_coords, realUseUvs, 0); aurora::gfx::ZComp::LEqual, zTest, useColor, xe0_coords, realUseUvs, 0);
// quad.drawVerts(useColor, verts); // quad.drawVerts(useColor, verts);
} else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) { } else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) {
aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture(), aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture(),
aurora::gfx::ZTest::LEqual, zTest, useColor, xe0_coords, realUseUvs, 0); aurora::gfx::ZComp::LEqual, zTest, useColor, xe0_coords, realUseUvs, 0);
} else { } else {
const float tmp = (1.f - x14c_deResFactor) * alpha; const float tmp = (1.f - x14c_deResFactor) * alpha;
const float tmp3 = 1.f - tmp * tmp * tmp; const float tmp3 = 1.f - tmp * tmp * tmp;
const float mip = tmp3 * static_cast<float>(tex.GetNumMips() - 1); const float mip = tmp3 * static_cast<float>(tex.GetNumMips() - 1);
aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture(), aurora::gfx::queue_textured_quad_verts(aurora::gfx::CameraFilterType(filter), tex.GetTexture(),
aurora::gfx::ZTest::LEqual, zTest, useColor, xe0_coords, realUseUvs, mip); aurora::gfx::ZComp::LEqual, zTest, useColor, xe0_coords, realUseUvs, mip);
} }
} }

View File

@ -16,7 +16,7 @@ void CGuiPane::Draw(const CGuiWidgetDrawParms& parms) {
auto col = xa8_color2; auto col = xa8_color2;
col.a() = parms.x0_alphaMod * xa8_color2.a(); col.a() = parms.x0_alphaMod * xa8_color2.a();
aurora::gfx::queue_colored_quad_verts(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, col, aurora::gfx::queue_colored_quad_verts(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZComp::Always, false, col,
xc0_verts); xc0_verts);
} }
CGuiWidget::Draw(parms); CGuiWidget::Draw(parms);

View File

@ -76,7 +76,7 @@ void CSplashScreen::Draw() {
aurora::gfx::queue_textured_quad( aurora::gfx::queue_textured_quad(
aurora::gfx::CameraFilterType::Blend, aurora::gfx::CameraFilterType::Blend,
m_texture->GetTexture(), m_texture->GetTexture(),
aurora::gfx::ZTest::Always, aurora::gfx::ZComp::Always,
false, false,
color, color,
1.f, 1.f,

View File

@ -2046,7 +2046,7 @@ void CFrontEndUI::Draw() {
zeus::CColor color = zeus::skWhite; zeus::CColor color = zeus::skWhite;
color.a() = x64_pressStartAlpha; color.a() = x64_pressStartAlpha;
aurora::gfx::queue_textured_quad(aurora::gfx::CameraFilterType::Add, x38_pressStart->GetTexture(), aurora::gfx::queue_textured_quad(aurora::gfx::CameraFilterType::Add, x38_pressStart->GetTexture(),
aurora::gfx::ZTest::Always, false, color, 1.f, rect, 0.f); aurora::gfx::ZComp::Always, false, color, 1.f, rect, 0.f);
} }
if (xc0_attractCount > 0) { if (xc0_attractCount > 0) {
@ -2058,7 +2058,7 @@ void CFrontEndUI::Draw() {
zeus::CColor color = zeus::skBlack; zeus::CColor color = zeus::skBlack;
color.a() = 1.f - x58_fadeBlackTimer; color.a() = 1.f - x58_fadeBlackTimer;
zeus::CRectangle rect(0, 0, 1, 1); zeus::CRectangle rect(0, 0, 1, 1);
aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, color, aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZComp::Always, false, color,
rect, 0.f); rect, 0.f);
} }
} }
@ -2070,14 +2070,14 @@ void CFrontEndUI::Draw() {
zeus::CColor color = zeus::skBlack; zeus::CColor color = zeus::skBlack;
color.a() = zeus::clamp(0.f, 1.f - x58_fadeBlackTimer, 1.f); color.a() = zeus::clamp(0.f, 1.f - x58_fadeBlackTimer, 1.f);
zeus::CRectangle rect(0, 0, 1, 1); zeus::CRectangle rect(0, 0, 1, 1);
aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, color, aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZComp::Always, false, color,
rect, 0.f); rect, 0.f);
} else if (x50_curScreen == EScreen::Title && x54_nextScreen == EScreen::Title) { } else if (x50_curScreen == EScreen::Title && x54_nextScreen == EScreen::Title) {
/* From black with 30-sec skip to title */ /* From black with 30-sec skip to title */
zeus::CColor color = zeus::skBlack; zeus::CColor color = zeus::skBlack;
color.a() = 1.f - zeus::clamp(0.f, 30.f - x58_fadeBlackTimer, 1.f); color.a() = 1.f - zeus::clamp(0.f, 30.f - x58_fadeBlackTimer, 1.f);
zeus::CRectangle rect(0, 0, 1, 1); zeus::CRectangle rect(0, 0, 1, 1);
aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZTest::Always, false, color, aurora::gfx::queue_colored_quad(aurora::gfx::CameraFilterType::Blend, aurora::gfx::ZComp::Always, false, color,
rect, 0.f); rect, 0.f);
} }
} }

View File

@ -22,6 +22,7 @@ add_library(aurora STATIC
lib/gfx/texture.cpp lib/gfx/texture.cpp
lib/gfx/movie_player/shader.cpp lib/gfx/movie_player/shader.cpp
lib/gfx/textured_quad/shader.cpp lib/gfx/textured_quad/shader.cpp
lib/gfx/colored_quad/shader.cpp
# TODO move to imgui? or move imgui impl to here? # TODO move to imgui? or move imgui impl to here?
../extern/imgui/backends/imgui_impl_sdl.cpp ../extern/imgui/backends/imgui_impl_sdl.cpp
../extern/imgui/backends/imgui_impl_wgpu.cpp ../extern/imgui/backends/imgui_impl_wgpu.cpp

View File

@ -211,6 +211,7 @@ struct AppDelegate {
virtual void onAppPostDraw() noexcept = 0; virtual void onAppPostDraw() noexcept = 0;
virtual void onAppWindowResized(const WindowSize& size) noexcept = 0; virtual void onAppWindowResized(const WindowSize& size) noexcept = 0;
virtual void onAppWindowMoved(int32_t x, int32_t y) noexcept = 0; virtual void onAppWindowMoved(int32_t x, int32_t y) noexcept = 0;
virtual void onAppDisplayScaleChanged(float scale) noexcept = 0;
virtual void onAppExiting() noexcept = 0; virtual void onAppExiting() noexcept = 0;
// ImGui // ImGui

View File

@ -76,7 +76,7 @@ enum class CameraFilterType : uint8_t {
NoColor, NoColor,
InvDstMultiply, InvDstMultiply,
}; };
enum class ZTest : uint8_t { enum class ZComp : uint8_t {
Never, Never,
Less, Less,
Equal, Equal,
@ -104,14 +104,14 @@ void add_model(/* TODO */) noexcept;
void queue_aabb(const zeus::CAABox& aabb, const zeus::CColor& color, bool z_only) noexcept; void queue_aabb(const zeus::CAABox& aabb, const zeus::CColor& color, bool z_only) noexcept;
void queue_fog_volume_plane(const ArrayRef<zeus::CVector4f>& verts, uint8_t pass); void queue_fog_volume_plane(const ArrayRef<zeus::CVector4f>& verts, uint8_t pass);
void queue_fog_volume_filter(const zeus::CColor& color, bool two_way) noexcept; void queue_fog_volume_filter(const zeus::CColor& color, bool two_way) noexcept;
void queue_textured_quad_verts(CameraFilterType filter_type, const TextureHandle& texture, ZTest z_comparison, void queue_textured_quad_verts(CameraFilterType filter_type, const TextureHandle& texture, ZComp z_comparison,
bool z_test, const zeus::CColor& color, const ArrayRef<zeus::CVector3f>& pos, bool z_test, const zeus::CColor& color, const ArrayRef<zeus::CVector3f>& pos,
const ArrayRef<zeus::CVector2f>& uvs, float lod) noexcept; const ArrayRef<zeus::CVector2f>& uvs, float lod) noexcept;
void queue_textured_quad(CameraFilterType filter_type, const TextureHandle& texture, ZTest z_comparison, bool z_test, void queue_textured_quad(CameraFilterType filter_type, const TextureHandle& texture, ZComp z_comparison, bool z_test,
const zeus::CColor& color, float uv_scale, const zeus::CRectangle& rect, float z) noexcept; const zeus::CColor& color, float uv_scale, const zeus::CRectangle& rect, float z, float lod = 0) noexcept;
void queue_colored_quad_verts(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, void queue_colored_quad_verts(CameraFilterType filter_type, ZComp z_comparison, bool z_test, const zeus::CColor& color,
const ArrayRef<zeus::CVector3f>& pos) noexcept; const ArrayRef<zeus::CVector3f>& pos) noexcept;
void queue_colored_quad(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, void queue_colored_quad(CameraFilterType filter_type, ZComp z_comparison, bool z_test, const zeus::CColor& color,
const zeus::CRectangle& rect, float z) noexcept; const zeus::CRectangle& rect, float z) noexcept;
void queue_movie_player(const TextureHandle& tex_y, const TextureHandle& tex_u, const TextureHandle& tex_v, void queue_movie_player(const TextureHandle& tex_y, const TextureHandle& tex_u, const TextureHandle& tex_v,
const zeus::CColor& color, float h_pad, float v_pad) noexcept; const zeus::CColor& color, float h_pad, float v_pad) noexcept;

View File

@ -15,6 +15,7 @@ static logvisor::Module Log("aurora");
// TODO: Move global state to a class/struct? // TODO: Move global state to a class/struct?
static std::unique_ptr<AppDelegate> g_AppDelegate; static std::unique_ptr<AppDelegate> g_AppDelegate;
static std::vector<std::string> g_Args; static std::vector<std::string> g_Args;
static float g_AppDpi = 1.f;
// SDL // SDL
static SDL_Window* g_Window; static SDL_Window* g_Window;
@ -112,11 +113,17 @@ static bool poll_events() noexcept {
break; break;
} }
case SDL_WINDOWEVENT_DISPLAY_CHANGED: { case SDL_WINDOWEVENT_DISPLAY_CHANGED: {
// TODO: handle display chaaged event printf("DISPLAY_CHANGED!\n");
float scale = 1.0f;
if (SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(g_Window), nullptr, &scale, nullptr) == 0) {
scale /= 96.0f;
if (g_AppDpi != scale) {
g_AppDelegate->onAppDisplayScaleChanged(scale);
}
}
break; break;
} }
} }
/* TODO: More window events */
break; break;
} }
case SDL_CONTROLLERDEVICEADDED: { case SDL_CONTROLLERDEVICEADDED: {
@ -258,6 +265,10 @@ void app_run(std::unique_ptr<AppDelegate> app, Icon icon, int argc, char** argv)
gpu::initialize(g_Window); gpu::initialize(g_Window);
gfx::initialize(); gfx::initialize();
g_AppDpi = 1.0f;
if (SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(g_Window), nullptr, &g_AppDpi, nullptr) == 0) {
g_AppDpi /= 96.0f;
}
imgui::create_context(); imgui::create_context();
g_AppDelegate->onImGuiInit(1.f); // TODO scale g_AppDelegate->onImGuiInit(1.f); // TODO scale
@ -381,16 +392,16 @@ void set_fullscreen(bool fullscreen) noexcept {
} }
int32_t get_controller_player_index(uint32_t which) noexcept { int32_t get_controller_player_index(uint32_t which) noexcept {
return input::player_index(which); // TODO return input::player_index(which);
} }
void set_controller_player_index(uint32_t which, int32_t index) noexcept { input::set_player_index(which, index); } void set_controller_player_index(uint32_t which, int32_t index) noexcept { input::set_player_index(which, index); }
bool is_controller_gamecube(uint32_t which) noexcept { bool is_controller_gamecube(uint32_t which) noexcept {
return input::is_gamecube(which); // TODO return input::is_gamecube(which);
} }
std::string get_controller_name(uint32_t instance) noexcept { std::string get_controller_name(uint32_t instance) noexcept {
return input::controller_name(instance); // TODO return input::controller_name(instance);
} }
} // namespace aurora } // namespace aurora

View File

@ -0,0 +1,309 @@
#include "shader.hpp"
#include "../../gpu.hpp"
#include <logvisor/logvisor.hpp>
#include <magic_enum.hpp>
namespace aurora::gfx::colored_quad {
static logvisor::Module Log("aurora::gfx::colored_quad");
using gpu::g_device;
using gpu::g_graphicsConfig;
using gpu::utils::make_vertex_attributes;
using gpu::utils::make_vertex_buffer_layout;
using gpu::utils::make_vertex_state;
State construct_state() {
wgpu::ShaderModuleWGSLDescriptor wgslDescriptor{};
wgslDescriptor.source = R"""(
struct Uniform {
xf: mat4x4<f32>;
color: vec4<f32>;
};
@group(0) @binding(0)
var<uniform> ubuf: Uniform;
struct VertexOutput {
@builtin(position) pos: vec4<f32>;
//@builtin(normal) norm: vec4<f32>;
};
@stage(vertex)
fn vs_main(@location(0) in_pos: vec3<f32>) -> VertexOutput {//, @location(1) in_norm: vec3<f32>) -> VertexOutput {
var out: VertexOutput;
out.pos = ubuf.xf * vec4<f32>(in_pos, 1.0);
//out.norm = in_norm;
return out;
}
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return ubuf.color;
}
)""";
const auto shaderDescriptor = wgpu::ShaderModuleDescriptor{
.nextInChain = &wgslDescriptor,
.label = "Colored Quad Shader",
};
auto shader = g_device.CreateShaderModule(&shaderDescriptor);
wgpu::SupportedLimits limits;
g_device.GetLimits(&limits);
const auto uniform_alignment = limits.limits.minUniformBufferOffsetAlignment;
const auto uniform_size = ALIGN(sizeof(Uniform), uniform_alignment);
const std::array uniformLayoutEntries{
wgpu::BindGroupLayoutEntry{
.binding = 0,
.visibility = wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Fragment,
.buffer =
wgpu::BufferBindingLayout{
.type = wgpu::BufferBindingType::Uniform,
.hasDynamicOffset = true,
.minBindingSize = uniform_size,
},
},
};
const auto uniformLayoutDescriptor = wgpu::BindGroupLayoutDescriptor{
.label = "Colored Quad Uniform Bind Group Layout",
.entryCount = uniformLayoutEntries.size(),
.entries = uniformLayoutEntries.data(),
};
auto uniformLayout = g_device.CreateBindGroupLayout(&uniformLayoutDescriptor);
const std::array uniformBindGroupEntries{
wgpu::BindGroupEntry{
.binding = 0,
.buffer = g_uniformBuffer,
.size = uniform_size,
},
};
const auto uniformBindGroupDescriptor = wgpu::BindGroupDescriptor{
.label = "Colored Quad Uniform Bind Group",
.layout = uniformLayout,
.entryCount = uniformBindGroupEntries.size(),
.entries = uniformBindGroupEntries.data(),
};
auto uniformBindGroup = g_device.CreateBindGroup(&uniformBindGroupDescriptor);
const std::array bindGroupLayouts{
uniformLayout,
};
const auto pipelineLayoutDescriptor = wgpu::PipelineLayoutDescriptor{
.label = "Colored Quad Pipeline Layout",
.bindGroupLayoutCount = bindGroupLayouts.size(),
.bindGroupLayouts = bindGroupLayouts.data(),
};
auto pipelineLayout = g_device.CreatePipelineLayout(&pipelineLayoutDescriptor);
return {
.shader = shader,
.uniformLayout = uniformLayout,
.uniformBindGroup = uniformBindGroup,
.pipelineLayout = pipelineLayout,
};
}
wgpu::RenderPipeline create_pipeline(const State& state, [[maybe_unused]] PipelineConfig config) {
const auto attributes = make_vertex_attributes(std::array{wgpu::VertexFormat::Float32x3});
const std::array vertexBuffers{make_vertex_buffer_layout(sizeof(Vert), attributes)};
wgpu::CompareFunction depthCompare{};
switch (config.zComparison) {
case ZComp::Never:
depthCompare = wgpu::CompareFunction::Never;
break;
case ZComp::Less:
depthCompare = wgpu::CompareFunction::Less;
break;
case ZComp::Equal:
depthCompare = wgpu::CompareFunction::Equal;
break;
case ZComp::LEqual:
depthCompare = wgpu::CompareFunction::LessEqual;
break;
case ZComp::Greater:
depthCompare = wgpu::CompareFunction::Greater;
break;
case ZComp::NEqual:
depthCompare = wgpu::CompareFunction::NotEqual;
break;
case ZComp::GEqual:
depthCompare = wgpu::CompareFunction::GreaterEqual;
break;
case ZComp::Always:
depthCompare = wgpu::CompareFunction::Always;
break;
}
const auto depthStencil = wgpu::DepthStencilState{
.format = g_graphicsConfig.depthFormat,
.depthWriteEnabled = config.zTest,
.depthCompare = depthCompare,
};
bool alphaWrite = false;
wgpu::BlendComponent blendComponent{};
switch (config.filterType) {
case CameraFilterType::Multiply:
blendComponent = wgpu::BlendComponent{
.srcFactor = wgpu::BlendFactor::Zero,
.dstFactor = wgpu::BlendFactor::Src,
};
alphaWrite = true;
break;
case CameraFilterType::Add:
blendComponent = wgpu::BlendComponent{
.srcFactor = wgpu::BlendFactor::SrcAlpha,
.dstFactor = wgpu::BlendFactor::One,
};
alphaWrite = false;
break;
case CameraFilterType::Subtract:
blendComponent = wgpu::BlendComponent{
.operation = wgpu::BlendOperation::Subtract,
.srcFactor = wgpu::BlendFactor::SrcAlpha,
.dstFactor = wgpu::BlendFactor::One,
};
alphaWrite = false;
break;
case CameraFilterType::Blend:
blendComponent = wgpu::BlendComponent{
.srcFactor = wgpu::BlendFactor::SrcAlpha,
.dstFactor = wgpu::BlendFactor::OneMinusSrcAlpha,
};
alphaWrite = false;
break;
case CameraFilterType::InvDstMultiply:
blendComponent = wgpu::BlendComponent{
.srcFactor = wgpu::BlendFactor::Zero,
.dstFactor = wgpu::BlendFactor::OneMinusSrc,
};
alphaWrite = true;
break;
default:
Log.report(logvisor::Fatal, FMT_STRING("unimplemented filter type {}"), magic_enum::enum_name(config.filterType));
unreachable();
}
const auto blendState = wgpu::BlendState{
.color = blendComponent,
.alpha = blendComponent,
};
auto writeMask = wgpu::ColorWriteMask::Red | wgpu::ColorWriteMask::Green | wgpu::ColorWriteMask::Blue;
if (alphaWrite) {
writeMask = writeMask | wgpu::ColorWriteMask::Alpha;
}
const std::array colorTargets{
wgpu::ColorTargetState{
.format = g_graphicsConfig.colorFormat,
.blend = &blendState,
.writeMask = writeMask,
},
};
const auto fragmentState = wgpu::FragmentState{
.module = state.shader,
.entryPoint = "fs_main",
.targetCount = colorTargets.size(),
.targets = colorTargets.data(),
};
const auto pipelineDescriptor = wgpu::RenderPipelineDescriptor{
.label = "Colored Quad Pipeline",
.layout = state.pipelineLayout,
.vertex = make_vertex_state(state.shader, vertexBuffers),
.primitive =
wgpu::PrimitiveState{
.topology = wgpu::PrimitiveTopology::TriangleStrip,
},
.depthStencil = &depthStencil,
.multisample =
wgpu::MultisampleState{
.count = g_graphicsConfig.msaaSamples,
},
.fragment = &fragmentState,
};
return g_device.CreateRenderPipeline(&pipelineDescriptor);
}
DrawData make_draw_data(const State& state, CameraFilterType filter_type, ZComp z_comparison, bool z_test,
const zeus::CColor& color, const zeus::CRectangle& rect, float z) {
auto pipeline = pipeline_ref(PipelineConfig{
.filterType = filter_type,
.zComparison = z_comparison,
.zTest = z_test,
});
const std::array verts{
Vert{{0.f, 0.f, z}},
Vert{{0.f, 1.f, z}},
Vert{{1.f, 0.f, z}},
Vert{{1.f, 1.f, z}},
};
const auto vertRange = push_verts(ArrayRef{verts});
const auto uniform = Uniform{
.xf =
Mat4x4<float>{
Vec4<float>{rect.size.x() * 2.f, 0.f, 0.f, 0.f},
Vec4<float>{0.f, rect.size.y() * 2.f, 0.f, 0.f},
Vec4<float>{0.f, 0.f, 1.f, 0.f},
Vec4<float>{rect.position.x() * 2.f - 1.f, rect.position.y() * 2.f - 1.f, 0.f, 1.f},
},
.color = color,
};
const auto uniformRange = push_uniform(uniform);
return {
.pipeline = pipeline,
.vertRange = vertRange,
.uniformRange = uniformRange,
};
}
DrawData make_draw_data_verts(const State& state, CameraFilterType filter_type, ZComp z_comparison, bool z_test,
const zeus::CColor& color, const ArrayRef<zeus::CVector3f>& pos) {
auto pipeline = pipeline_ref(PipelineConfig{
.filterType = filter_type,
.zComparison = z_comparison,
.zTest = z_test,
});
assert(pos.size() == 4 && "Invalid pos size!");
const std::array verts{
Vert{pos[0]},
Vert{pos[1]},
Vert{pos[2]},
Vert{pos[3]},
};
const auto vertRange = push_verts(ArrayRef{verts});
const auto uniform = Uniform{
.xf = get_combined_matrix(),
.color = color,
};
const auto uniformRange = push_uniform(uniform);
return {
.pipeline = pipeline,
.vertRange = vertRange,
.uniformRange = uniformRange,
};
}
void render(const State& state, const DrawData& data, const wgpu::RenderPassEncoder& pass) {
if (!bind_pipeline(data.pipeline, pass)) {
return;
}
const std::array offsets{data.uniformRange.first};
pass.SetBindGroup(0, state.uniformBindGroup, offsets.size(), offsets.data());
pass.SetVertexBuffer(0, g_vertexBuffer, data.vertRange.first, data.vertRange.second);
pass.Draw(4);
}
} // namespace aurora::gfx::colored_quad

View File

@ -0,0 +1,47 @@
#include "../common.hpp"
namespace aurora::gfx::colored_quad {
struct DrawData {
PipelineRef pipeline;
Range vertRange;
Range uniformRange;
};
struct PipelineConfig {
CameraFilterType filterType;
ZComp zComparison;
bool zTest;
};
static const std::array INITIAL_PIPELINES {
PipelineConfig{}, // TODO
};
struct State {
wgpu::ShaderModule shader;
wgpu::BindGroupLayout uniformLayout;
wgpu::BindGroup uniformBindGroup;
wgpu::Sampler sampler;
wgpu::PipelineLayout pipelineLayout;
};
struct alignas(4) Vert {
Vec3<float> pos;
};
struct alignas(4) Uniform {
Mat4x4<float> xf;
Vec4<float> color;
};
static_assert(sizeof(Uniform) == 80);
State construct_state();
wgpu::RenderPipeline create_pipeline(const State& state, [[maybe_unused]] PipelineConfig config);
DrawData make_draw_data(const State& state, CameraFilterType filter_type, ZComp z_comparison, bool z_test,
const zeus::CColor& color, const zeus::CRectangle& rect, float z);
DrawData make_draw_data_verts(const State& state, CameraFilterType filter_type, ZComp z_comparison, bool z_test,
const zeus::CColor& color, const ArrayRef<zeus::CVector3f>& pos);
void render(const State& state, const DrawData& data, const wgpu::RenderPassEncoder& pass);
} // namespace aurora::gfx::colored_quad

View File

@ -1,7 +1,8 @@
#include "common.hpp" #include "common.hpp"
#include "../gpu.hpp" #include "../gpu.hpp"
#include "textured_quad//shader.hpp" #include "colored_quad/shader.hpp"
#include "textured_quad/shader.hpp"
#include "movie_player/shader.hpp" #include "movie_player/shader.hpp"
#include <condition_variable> #include <condition_variable>
@ -18,12 +19,14 @@ using gpu::g_queue;
struct ShaderState { struct ShaderState {
movie_player::State moviePlayer; movie_player::State moviePlayer;
colored_quad::State coloredQuad;
textured_quad::State texturedQuad; textured_quad::State texturedQuad;
}; };
struct ShaderDrawCommand { struct ShaderDrawCommand {
ShaderType type; ShaderType type;
union { union {
movie_player::DrawData moviePlayer; movie_player::DrawData moviePlayer;
colored_quad::DrawData coloredQuad;
textured_quad::DrawData texturedQuad; textured_quad::DrawData texturedQuad;
}; };
}; };
@ -31,6 +34,7 @@ struct PipelineCreateCommand {
ShaderType type; ShaderType type;
union { union {
movie_player::PipelineConfig moviePlayer; movie_player::PipelineConfig moviePlayer;
colored_quad::PipelineConfig coloredQuad;
textured_quad::PipelineConfig texturedQuad; textured_quad::PipelineConfig texturedQuad;
}; };
}; };
@ -148,15 +152,18 @@ void queue_fog_volume_filter(const zeus::CColor& color, bool two_way) noexcept {
// TODO // TODO
} }
void queue_textured_quad_verts(CameraFilterType filter_type, const TextureHandle& texture, ZTest z_comparison, void queue_textured_quad_verts(CameraFilterType filter_type, const TextureHandle& texture, ZComp z_comparison,
bool z_test, const zeus::CColor& color, const ArrayRef<zeus::CVector3f>& pos, bool z_test, const zeus::CColor& color, const ArrayRef<zeus::CVector3f>& pos,
const ArrayRef<zeus::CVector2f>& uvs, float lod) noexcept { const ArrayRef<zeus::CVector2f>& uvs, float lod) noexcept {
// TODO auto data = textured_quad::make_draw_data_verts(g_state.texturedQuad, filter_type, texture, z_comparison, z_test,
color, pos, uvs, lod);
push_draw_command({.type = ShaderType::TexturedQuad, .texturedQuad = data});
} }
void queue_textured_quad(CameraFilterType filter_type, const TextureHandle& texture, ZTest z_comparison, bool z_test, void queue_textured_quad(CameraFilterType filter_type, const TextureHandle& texture, ZComp z_comparison, bool z_test,
const zeus::CColor& color, float uv_scale, const zeus::CRectangle& rect, float z) noexcept { const zeus::CColor& color, float uv_scale, const zeus::CRectangle& rect, float z,
float lod) noexcept {
auto data = textured_quad::make_draw_data(g_state.texturedQuad, filter_type, texture, z_comparison, z_test, color, auto data = textured_quad::make_draw_data(g_state.texturedQuad, filter_type, texture, z_comparison, z_test, color,
uv_scale, rect, z); uv_scale, rect, z, lod);
push_draw_command({.type = ShaderType::TexturedQuad, .texturedQuad = data}); push_draw_command({.type = ShaderType::TexturedQuad, .texturedQuad = data});
} }
template <> template <>
@ -165,13 +172,21 @@ PipelineRef pipeline_ref(textured_quad::PipelineConfig config) {
[=]() { return create_pipeline(g_state.texturedQuad, config); }); [=]() { return create_pipeline(g_state.texturedQuad, config); });
} }
void queue_colored_quad_verts(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, void queue_colored_quad_verts(CameraFilterType filter_type, ZComp z_comparison, bool z_test, const zeus::CColor& color,
const ArrayRef<zeus::CVector3f>& pos) noexcept { const ArrayRef<zeus::CVector3f>& pos) noexcept {
// TODO auto data = colored_quad::make_draw_data_verts(g_state.coloredQuad, filter_type, z_comparison, z_test, color, pos);
push_draw_command({.type = ShaderType::ColoredQuad, .coloredQuad = data});
} }
void queue_colored_quad(CameraFilterType filter_type, ZTest z_comparison, bool z_test, const zeus::CColor& color, void queue_colored_quad(CameraFilterType filter_type, ZComp z_comparison, bool z_test, const zeus::CColor& color,
const zeus::CRectangle& rect, float z) noexcept { const zeus::CRectangle& rect, float z) noexcept {
// TODO auto data = colored_quad::make_draw_data(g_state.coloredQuad, filter_type, z_comparison, z_test, color, rect, z);
push_draw_command({.type = ShaderType::ColoredQuad, .coloredQuad = data});
}
template <>
PipelineRef pipeline_ref(colored_quad::PipelineConfig config) {
return find_pipeline({.type = ShaderType::ColoredQuad, .coloredQuad = config},
[=]() { return create_pipeline(g_state.coloredQuad, config); });
} }
void queue_movie_player(const TextureHandle& tex_y, const TextureHandle& tex_u, const TextureHandle& tex_v, void queue_movie_player(const TextureHandle& tex_y, const TextureHandle& tex_u, const TextureHandle& tex_v,
@ -245,6 +260,7 @@ void initialize() {
} }
g_state.moviePlayer = movie_player::construct_state(); g_state.moviePlayer = movie_player::construct_state();
g_state.coloredQuad = colored_quad::construct_state();
g_state.texturedQuad = textured_quad::construct_state(); g_state.texturedQuad = textured_quad::construct_state();
} }
@ -289,6 +305,9 @@ void render(const wgpu::RenderPassEncoder& pass) {
case ShaderType::Aabb: case ShaderType::Aabb:
// TODO // TODO
break; break;
case ShaderType::ColoredQuad:
colored_quad::render(g_state.coloredQuad, draw.coloredQuad, pass);
break;
case ShaderType::TexturedQuad: case ShaderType::TexturedQuad:
textured_quad::render(g_state.texturedQuad, draw.texturedQuad, pass); textured_quad::render(g_state.texturedQuad, draw.texturedQuad, pass);
break; break;

View File

@ -150,6 +150,7 @@ using Range = std::pair<uint32_t, uint32_t>;
enum class ShaderType { enum class ShaderType {
Aabb, Aabb,
ColoredQuad,
TexturedQuad, TexturedQuad,
MoviePlayer, MoviePlayer,
}; };

View File

@ -161,28 +161,28 @@ wgpu::RenderPipeline create_pipeline(const State& state, [[maybe_unused]] Pipeli
wgpu::CompareFunction depthCompare; wgpu::CompareFunction depthCompare;
switch (config.zComparison) { switch (config.zComparison) {
case ZTest::Never: case ZComp::Never:
depthCompare = wgpu::CompareFunction::Never; depthCompare = wgpu::CompareFunction::Never;
break; break;
case ZTest::Less: case ZComp::Less:
depthCompare = wgpu::CompareFunction::Less; depthCompare = wgpu::CompareFunction::Less;
break; break;
case ZTest::Equal: case ZComp::Equal:
depthCompare = wgpu::CompareFunction::Equal; depthCompare = wgpu::CompareFunction::Equal;
break; break;
case ZTest::LEqual: case ZComp::LEqual:
depthCompare = wgpu::CompareFunction::LessEqual; depthCompare = wgpu::CompareFunction::LessEqual;
break; break;
case ZTest::Greater: case ZComp::Greater:
depthCompare = wgpu::CompareFunction::Greater; depthCompare = wgpu::CompareFunction::Greater;
break; break;
case ZTest::NEqual: case ZComp::NEqual:
depthCompare = wgpu::CompareFunction::NotEqual; depthCompare = wgpu::CompareFunction::NotEqual;
break; break;
case ZTest::GEqual: case ZComp::GEqual:
depthCompare = wgpu::CompareFunction::GreaterEqual; depthCompare = wgpu::CompareFunction::GreaterEqual;
break; break;
case ZTest::Always: case ZComp::Always:
depthCompare = wgpu::CompareFunction::Always; depthCompare = wgpu::CompareFunction::Always;
break; break;
} }
@ -277,8 +277,8 @@ wgpu::RenderPipeline create_pipeline(const State& state, [[maybe_unused]] Pipeli
} }
DrawData make_draw_data(const State& state, CameraFilterType filter_type, const TextureHandle& texture, DrawData make_draw_data(const State& state, CameraFilterType filter_type, const TextureHandle& texture,
ZTest z_comparison, bool z_test, const zeus::CColor& color, float uv_scale, ZComp z_comparison, bool z_test, const zeus::CColor& color, float uv_scale,
const zeus::CRectangle& rect, float z) { const zeus::CRectangle& rect, float z, float lod) {
auto pipeline = pipeline_ref(PipelineConfig{ auto pipeline = pipeline_ref(PipelineConfig{
.filterType = filter_type, .filterType = filter_type,
.zComparison = z_comparison, .zComparison = z_comparison,
@ -302,7 +302,54 @@ DrawData make_draw_data(const State& state, CameraFilterType filter_type, const
Vec4<float>{rect.position.x() * 2.f - 1.f, rect.position.y() * 2.f - 1.f, 0.f, 1.f}, Vec4<float>{rect.position.x() * 2.f - 1.f, rect.position.y() * 2.f - 1.f, 0.f, 1.f},
}, },
.color = color, .color = color,
.lod = 0.f, .lod = lod,
};
const auto uniformRange = push_uniform(uniform);
const std::array entries{
wgpu::BindGroupEntry{
.binding = 0,
.textureView = texture.ref->view,
},
};
const auto textureBindGroup = bind_group_ref(wgpu::BindGroupDescriptor{
.label = "Textured Quad Texture Bind Group",
.layout = state.textureLayout,
.entryCount = entries.size(),
.entries = entries.data(),
});
return {
.pipeline = pipeline,
.vertRange = vertRange,
.uniformRange = uniformRange,
.textureBindGroup = textureBindGroup,
};
}
DrawData make_draw_data_verts(const State& state, CameraFilterType filter_type, const TextureHandle& texture,
ZComp z_comparison, bool z_test, const zeus::CColor& color,
const ArrayRef<zeus::CVector3f>& pos, const ArrayRef<zeus::CVector2f>& uvs, float lod) {
auto pipeline = pipeline_ref(PipelineConfig{
.filterType = filter_type,
.zComparison = z_comparison,
.zTest = z_test,
});
assert(pos.size() == 4 && uvs.size() == 4 && "Invalid pos/uv sizes!");
const std::array verts{
Vert{pos[0], uvs[0]},
Vert{pos[1], uvs[1]},
Vert{pos[2], uvs[2]},
Vert{pos[3], uvs[3]},
};
const auto vertRange = push_verts(ArrayRef{verts});
const auto uniform = Uniform{
.xf = get_combined_matrix(),
.color = color,
.lod = lod,
}; };
const auto uniformRange = push_uniform(uniform); const auto uniformRange = push_uniform(uniform);

View File

@ -10,7 +10,7 @@ struct DrawData {
struct PipelineConfig { struct PipelineConfig {
CameraFilterType filterType; CameraFilterType filterType;
ZTest zComparison; ZComp zComparison;
bool zTest; bool zTest;
}; };
static const std::array INITIAL_PIPELINES{ static const std::array INITIAL_PIPELINES{
@ -40,7 +40,10 @@ static_assert(sizeof(Uniform) == 84);
State construct_state(); State construct_state();
wgpu::RenderPipeline create_pipeline(const State& state, [[maybe_unused]] PipelineConfig config); wgpu::RenderPipeline create_pipeline(const State& state, [[maybe_unused]] PipelineConfig config);
DrawData make_draw_data(const State& state, CameraFilterType filter_type, const TextureHandle& texture, DrawData make_draw_data(const State& state, CameraFilterType filter_type, const TextureHandle& texture,
ZTest z_comparison, bool z_test, const zeus::CColor& color, float uv_scale, ZComp z_comparison, bool z_test, const zeus::CColor& color, float uv_scale,
const zeus::CRectangle& rect, float z); const zeus::CRectangle& rect, float z, float lod);
DrawData make_draw_data_verts(const State& state, CameraFilterType filter_type, const TextureHandle& texture,
ZComp z_comparison, bool z_test, const zeus::CColor& color,
const ArrayRef<zeus::CVector3f>& pos, const ArrayRef<zeus::CVector2f>& uvs, float lod);
void render(const State& state, const DrawData& data, const wgpu::RenderPassEncoder& pass); void render(const State& state, const DrawData& data, const wgpu::RenderPassEncoder& pass);
} // namespace aurora::gfx::textured_quad } // namespace aurora::gfx::textured_quad

View File

@ -54,10 +54,24 @@ void ImGuiEngine_Initialize(float scale) {
ImGuiEngine::fontLarge = io.Fonts->AddFont(&fontConfig); ImGuiEngine::fontLarge = io.Fonts->AddFont(&fontConfig);
auto& style = ImGui::GetStyle(); auto& style = ImGui::GetStyle();
style.WindowPadding = ImVec2(15, 15);
style.WindowRounding = 5.0f;
style.FrameBorderSize = 1.f;
style.FramePadding = ImVec2(5, 5);
style.FrameRounding = 4.0f; style.FrameRounding = 4.0f;
style.GrabRounding = 4.0f; style.ItemSpacing = ImVec2(12, 8);
style.ItemInnerSpacing = ImVec2(8, 6);
style.IndentSpacing = 25.0f;
style.ScrollbarSize = 15.0f;
style.ScrollbarRounding = 9.0f;
style.GrabMinSize = 5.0f;
style.GrabRounding = 3.0f;
style.PopupBorderSize = 1.f;
style.PopupRounding = 7.0;
style.TabBorderSize = 1.f;
style.TabRounding = 3.f;
auto colors = style.Colors; auto* colors = style.Colors;
colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f); colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.36f, 0.42f, 0.47f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.36f, 0.42f, 0.47f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f); colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
@ -125,7 +139,6 @@ Icon GetIcon() {
void ImGuiEngine_AddTextures() { void ImGuiEngine_AddTextures() {
auto icon = GetIcon(); auto icon = GetIcon();
ImGuiEngine::metaforceIcon = ImGuiEngine::metaforceIcon = aurora::imgui::add_texture(icon.width, icon.height, {icon.data.get(), icon.size});
aurora::imgui::add_texture(icon.width, icon.height, {icon.data.get(), icon.size});
} }
} // namespace metaforce } // namespace metaforce