2019-09-12 02:53:04 +00:00
|
|
|
#pragma once
|
|
|
|
#include "gpu.h"
|
2019-09-13 16:07:31 +00:00
|
|
|
#include <sstream>
|
2019-09-14 06:27:24 +00:00
|
|
|
#include <string>
|
2019-09-12 02:53:04 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class GPU_HW : public GPU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GPU_HW();
|
|
|
|
virtual ~GPU_HW();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct HWVertex
|
|
|
|
{
|
|
|
|
s32 x;
|
|
|
|
s32 y;
|
|
|
|
u32 color;
|
2019-09-13 16:07:31 +00:00
|
|
|
u16 texcoord;
|
|
|
|
u16 padding;
|
2019-09-14 06:27:24 +00:00
|
|
|
|
2019-09-14 06:43:39 +00:00
|
|
|
static constexpr std::tuple<u8, u8> DecodeTexcoord(u16 texcoord)
|
2019-09-14 06:27:24 +00:00
|
|
|
{
|
|
|
|
return std::make_tuple(static_cast<u8>(texcoord), static_cast<u8>(texcoord >> 8));
|
|
|
|
}
|
2019-09-14 06:43:39 +00:00
|
|
|
static constexpr u16 EncodeTexcoord(u8 x, u8 y) { return ZeroExtend16(x) | (ZeroExtend16(y) << 8); }
|
2019-09-12 02:53:04 +00:00
|
|
|
};
|
|
|
|
|
2019-09-25 14:15:21 +00:00
|
|
|
struct HWRenderBatch
|
|
|
|
{
|
|
|
|
enum class Primitive : u8
|
|
|
|
{
|
|
|
|
Lines = 0,
|
|
|
|
Triangles = 1,
|
|
|
|
TriangleStrip = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
Primitive primitive;
|
|
|
|
bool transparency_enable;
|
|
|
|
bool texture_enable;
|
|
|
|
bool texture_blending_enable;
|
|
|
|
TransparencyMode transparency_mode;
|
|
|
|
|
|
|
|
std::vector<HWVertex> vertices;
|
|
|
|
};
|
|
|
|
|
2019-09-14 15:18:58 +00:00
|
|
|
static constexpr u32 VERTEX_BUFFER_SIZE = 1 * 1024 * 1024;
|
|
|
|
static constexpr u32 MAX_BATCH_VERTEX_COUNT = VERTEX_BUFFER_SIZE / sizeof(HWVertex);
|
|
|
|
|
2019-09-14 06:43:39 +00:00
|
|
|
static constexpr std::tuple<float, float, float, float> RGBA8ToFloat(u32 rgba)
|
|
|
|
{
|
|
|
|
return std::make_tuple(static_cast<float>(rgba & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
|
|
|
static_cast<float>((rgba >> 16) & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
|
|
|
static_cast<float>((rgba >> 8) & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
|
|
|
static_cast<float>(rgba >> 24) * (1.0f / 255.0f));
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:07:31 +00:00
|
|
|
virtual void UpdateTexturePageTexture();
|
|
|
|
|
2019-09-25 14:15:21 +00:00
|
|
|
bool IsFlushed() const { return m_batch.vertices.empty(); }
|
2019-09-13 16:07:31 +00:00
|
|
|
|
|
|
|
void DispatchRenderCommand(RenderCommand rc, u32 num_vertices) override;
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
void CalcScissorRect(int* left, int* top, int* right, int* bottom);
|
|
|
|
|
2019-09-12 02:53:04 +00:00
|
|
|
std::string GenerateVertexShader(bool textured);
|
2019-09-13 16:07:31 +00:00
|
|
|
std::string GenerateFragmentShader(bool textured, bool blending);
|
|
|
|
std::string GenerateScreenQuadVertexShader();
|
2019-09-14 06:43:39 +00:00
|
|
|
std::string GenerateTexturePageFragmentShader(TextureColorMode mode);
|
|
|
|
std::string GenerateFillFragmentShader();
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-09-25 14:15:21 +00:00
|
|
|
HWRenderBatch m_batch = {};
|
2019-09-13 16:07:31 +00:00
|
|
|
|
|
|
|
private:
|
2019-09-25 14:15:21 +00:00
|
|
|
static HWRenderBatch::Primitive GetPrimitiveForCommand(RenderCommand rc);
|
|
|
|
|
2019-09-13 16:07:31 +00:00
|
|
|
void GenerateShaderHeader(std::stringstream& ss);
|
|
|
|
|
|
|
|
void LoadVertices(RenderCommand rc, u32 num_vertices);
|
2019-09-12 02:53:04 +00:00
|
|
|
};
|