2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2022-12-28 14:38:46 +00:00
|
|
|
#include <array>
|
2016-01-17 21:54:31 +00:00
|
|
|
#include <string>
|
2022-03-05 20:52:43 +00:00
|
|
|
#include <vector>
|
2016-01-17 21:54:31 +00:00
|
|
|
|
2022-12-28 14:38:46 +00:00
|
|
|
#include "Common/BitSet.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2022-12-28 14:38:46 +00:00
|
|
|
#include "Common/Matrix.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/ConstantManager.h"
|
2023-03-19 22:28:25 +00:00
|
|
|
#include "VideoCommon/NativeVertexFormat.h"
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2012-01-01 20:46:02 +00:00
|
|
|
class PointerWrap;
|
2022-06-18 06:09:35 +00:00
|
|
|
struct PortableVertexDeclaration;
|
2023-11-25 22:23:54 +00:00
|
|
|
class XFStateManager;
|
2012-01-01 20:46:02 +00:00
|
|
|
|
2008-12-26 10:43:18 +00:00
|
|
|
// The non-API dependent parts.
|
2022-12-28 14:38:46 +00:00
|
|
|
class alignas(16) VertexShaderManager
|
2008-12-26 10:43:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-12-28 14:38:46 +00:00
|
|
|
void Init();
|
|
|
|
void DoState(PointerWrap& p);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-09-15 21:49:15 +00:00
|
|
|
// constant management
|
2023-11-25 22:23:54 +00:00
|
|
|
void SetProjectionMatrix(XFStateManager& xf_state_manager);
|
|
|
|
void SetConstants(const std::vector<std::string>& textures, XFStateManager& xf_state_manager);
|
2017-07-20 05:25:27 +00:00
|
|
|
|
2015-01-23 14:15:09 +00:00
|
|
|
// data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index.
|
2015-01-24 20:12:52 +00:00
|
|
|
// out: 4 floats which will be initialized with the corresponding clip space coordinates
|
2022-12-28 15:00:15 +00:00
|
|
|
// NOTE: m_projection_matrix must be up to date when this is called
|
2015-01-24 20:12:52 +00:00
|
|
|
// (i.e. VertexShaderManager::SetConstants needs to be called before using this!)
|
2022-12-28 14:38:46 +00:00
|
|
|
void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2023-01-31 05:18:46 +00:00
|
|
|
static bool UseVertexDepthRange();
|
|
|
|
|
2022-12-28 14:38:46 +00:00
|
|
|
VertexShaderConstants constants{};
|
|
|
|
bool dirty = false;
|
|
|
|
|
2023-03-19 22:28:25 +00:00
|
|
|
static DOLPHIN_FORCE_INLINE void UpdateValue(bool* dirty, u32* old_value, u32 new_value)
|
|
|
|
{
|
|
|
|
if (*old_value == new_value)
|
|
|
|
return;
|
|
|
|
*old_value = new_value;
|
|
|
|
*dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DOLPHIN_FORCE_INLINE void UpdateOffset(bool* dirty, bool include_components,
|
|
|
|
u32* old_value, const AttributeFormat& attribute)
|
|
|
|
{
|
|
|
|
if (!attribute.enable)
|
|
|
|
return;
|
|
|
|
u32 new_value = attribute.offset / 4; // GPU uses uint offsets
|
|
|
|
if (include_components)
|
|
|
|
new_value |= attribute.components << 16;
|
|
|
|
UpdateValue(dirty, old_value, new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
static DOLPHIN_FORCE_INLINE void UpdateOffsets(bool* dirty, bool include_components,
|
|
|
|
std::array<u32, N>* old_value,
|
|
|
|
const std::array<AttributeFormat, N>& attribute)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < N; i++)
|
|
|
|
UpdateOffset(dirty, include_components, &(*old_value)[i], attribute[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOLPHIN_FORCE_INLINE void SetVertexFormat(u32 components, const PortableVertexDeclaration& format)
|
|
|
|
{
|
|
|
|
UpdateValue(&dirty, &constants.components, components);
|
|
|
|
UpdateValue(&dirty, &constants.vertex_stride, format.stride / 4);
|
|
|
|
UpdateOffset(&dirty, true, &constants.vertex_offset_position, format.position);
|
|
|
|
UpdateOffset(&dirty, false, &constants.vertex_offset_posmtx, format.posmtx);
|
|
|
|
UpdateOffsets(&dirty, true, &constants.vertex_offset_texcoords, format.texcoords);
|
|
|
|
UpdateOffsets(&dirty, false, &constants.vertex_offset_colors, format.colors);
|
|
|
|
UpdateOffsets(&dirty, false, &constants.vertex_offset_normals, format.normals);
|
|
|
|
}
|
|
|
|
|
2022-12-28 14:38:46 +00:00
|
|
|
private:
|
2022-12-28 15:00:15 +00:00
|
|
|
alignas(16) std::array<float, 16> m_projection_matrix;
|
2022-12-28 14:38:46 +00:00
|
|
|
|
|
|
|
// track changes
|
2022-12-28 15:00:15 +00:00
|
|
|
bool m_projection_graphics_mod_change = false;
|
2022-12-28 14:38:46 +00:00
|
|
|
|
2022-12-28 15:00:15 +00:00
|
|
|
Common::Matrix44 m_viewport_correction{};
|
2022-11-11 01:30:49 +00:00
|
|
|
|
|
|
|
Common::Matrix44 LoadProjectionMatrix();
|
2008-07-17 21:09:18 +00:00
|
|
|
};
|