CCameraBlurFilter: Make use of std::array where applicable

Same behavior, less hardcoded sizes.
This commit is contained in:
Lioncash 2020-04-22 00:08:41 -04:00
parent 4741172f9f
commit fe642bde8b
2 changed files with 22 additions and 18 deletions

View File

@ -1,6 +1,7 @@
#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp" #include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp"
#include <algorithm> #include <algorithm>
#include <array>
#include <cmath> #include <cmath>
#include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CGraphics.hpp"
@ -26,39 +27,41 @@ CCameraBlurFilter::CCameraBlurFilter() {
CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {m_uniBuf.get()}; const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; constexpr std::array stages{boo::PipelineStage::Vertex};
boo::ObjToken<boo::ITexture> texs[] = {CGraphics::g_SpareTexture.get()}; const std::array<boo::ObjToken<boo::ITexture>, 1> texs{CGraphics::g_SpareTexture.get()};
m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
1, texs, nullptr, nullptr); stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
return true; return true;
} BooTrace); } BooTrace);
} }
void CCameraBlurFilter::draw(float amount, bool clearDepth) { void CCameraBlurFilter::draw(float amount, bool clearDepth) {
if (amount <= 0.f) if (amount <= 0.f) {
return; return;
}
SCOPED_GRAPHICS_DEBUG_GROUP("CCameraBlurFilter::draw", zeus::skMagenta); SCOPED_GRAPHICS_DEBUG_GROUP("CCameraBlurFilter::draw", zeus::skMagenta);
SClipScreenRect clipRect(g_Viewport); const SClipScreenRect clipRect(g_Viewport);
CGraphics::ResolveSpareTexture(clipRect, 0, clearDepth); CGraphics::ResolveSpareTexture(clipRect, 0, clearDepth);
float aspect = CGraphics::g_CroppedViewport.xc_width / float(CGraphics::g_CroppedViewport.x10_height); const float aspect = float(CGraphics::g_CroppedViewport.xc_width) / float(CGraphics::g_CroppedViewport.x10_height);
float xFac = CGraphics::g_CroppedViewport.xc_width / float(g_Viewport.x8_width); const float xFac = float(CGraphics::g_CroppedViewport.xc_width) / float(g_Viewport.x8_width);
float yFac = CGraphics::g_CroppedViewport.x10_height / float(g_Viewport.xc_height); const float yFac = float(CGraphics::g_CroppedViewport.x10_height) / float(g_Viewport.xc_height);
float xBias = CGraphics::g_CroppedViewport.x4_left / float(g_Viewport.x8_width); const float xBias = float(CGraphics::g_CroppedViewport.x4_left) / float(g_Viewport.x8_width);
float yBias = CGraphics::g_CroppedViewport.x8_top / float(g_Viewport.xc_height); const float yBias = float(CGraphics::g_CroppedViewport.x8_top) / float(g_Viewport.xc_height);
Vert verts[4] = { const std::array<Vert, 4> verts{{
{{-1.0, -1.0}, {xBias, yBias}}, {{-1.0, -1.0}, {xBias, yBias}},
{{-1.0, 1.0}, {xBias, yBias + yFac}}, {{-1.0, 1.0}, {xBias, yBias + yFac}},
{{1.0, -1.0}, {xBias + xFac, yBias}}, {{1.0, -1.0}, {xBias + xFac, yBias}},
{{1.0, 1.0}, {xBias + xFac, yBias + yFac}}, {{1.0, 1.0}, {xBias + xFac, yBias + yFac}},
}; }};
m_vbo->load(verts, sizeof(verts)); m_vbo->load(verts.data(), sizeof(verts));
for (int i = 0; i < 6; ++i) { for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) {
float tmp = i; auto tmp = static_cast<float>(i);
tmp *= 2.f * M_PIF; tmp *= 2.f * M_PIF;
tmp /= 6.f; tmp /= 6.f;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include <boo/graphicsdev/IGraphicsDataFactory.hpp> #include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CVector4f.hpp> #include <zeus/CVector4f.hpp>
@ -7,7 +8,7 @@ namespace urde {
class CCameraBlurFilter { class CCameraBlurFilter {
struct Uniform { struct Uniform {
zeus::CVector4f m_uv[6]; std::array<zeus::CVector4f, 6> m_uv;
float m_opacity = 1.f; float m_opacity = 1.f;
}; };