2016-03-02 22:16:38 -05:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-30 11:34:51 -04:00
|
|
|
#include <array>
|
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_types.h"
|
2017-04-17 03:01:45 -04:00
|
|
|
#include "common/vector_math.h"
|
2016-03-02 22:16:38 -05:00
|
|
|
#include "video_core/primitive_assembly.h"
|
2017-01-28 16:27:24 -05:00
|
|
|
#include "video_core/regs.h"
|
2016-03-02 22:16:38 -05:00
|
|
|
#include "video_core/shader/shader.h"
|
|
|
|
|
|
|
|
namespace Pica {
|
|
|
|
|
|
|
|
/// Struct used to describe current Pica state
|
|
|
|
struct State {
|
2016-03-05 17:49:23 -05:00
|
|
|
void Reset();
|
|
|
|
|
2016-03-02 22:16:38 -05:00
|
|
|
/// Pica registers
|
|
|
|
Regs regs;
|
|
|
|
|
|
|
|
Shader::ShaderSetup vs;
|
|
|
|
Shader::ShaderSetup gs;
|
|
|
|
|
2016-12-18 19:42:19 -05:00
|
|
|
Shader::AttributeBuffer input_default_attributes;
|
2016-05-12 04:06:35 -04:00
|
|
|
|
2017-04-17 03:01:45 -04:00
|
|
|
struct ProcTex {
|
|
|
|
union ValueEntry {
|
|
|
|
u32 raw;
|
|
|
|
|
|
|
|
// LUT value, encoded as 12-bit fixed point, with 12 fraction bits
|
|
|
|
BitField<0, 12, u32> value; // 0.0.12 fixed point
|
|
|
|
|
|
|
|
// Difference between two entry values. Used for efficient interpolation.
|
|
|
|
// 0.0.12 fixed point with two's complement. The range is [-0.5, 0.5).
|
|
|
|
// Note: the type of this is different from the one of lighting LUT
|
|
|
|
BitField<12, 12, s32> difference;
|
|
|
|
|
|
|
|
float ToFloat() const {
|
|
|
|
return static_cast<float>(value) / 4095.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float DiffToFloat() const {
|
|
|
|
return static_cast<float>(difference) / 4095.f;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
union ColorEntry {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 8, u32> r;
|
|
|
|
BitField<8, 8, u32> g;
|
|
|
|
BitField<16, 8, u32> b;
|
|
|
|
BitField<24, 8, u32> a;
|
|
|
|
|
|
|
|
Math::Vec4<u8> ToVector() const {
|
|
|
|
return {static_cast<u8>(r), static_cast<u8>(g), static_cast<u8>(b),
|
|
|
|
static_cast<u8>(a)};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
union ColorDifferenceEntry {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 8, s32> r; // half of the difference between two ColorEntry
|
|
|
|
BitField<8, 8, s32> g;
|
|
|
|
BitField<16, 8, s32> b;
|
|
|
|
BitField<24, 8, s32> a;
|
|
|
|
|
|
|
|
Math::Vec4<s32> ToVector() const {
|
|
|
|
return Math::Vec4<s32>{r, g, b, a} * 2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::array<ValueEntry, 128> noise_table;
|
|
|
|
std::array<ValueEntry, 128> color_map_table;
|
|
|
|
std::array<ValueEntry, 128> alpha_map_table;
|
|
|
|
std::array<ColorEntry, 256> color_table;
|
|
|
|
std::array<ColorDifferenceEntry, 256> color_diff_table;
|
|
|
|
} proctex;
|
|
|
|
|
2017-06-28 13:34:16 -04:00
|
|
|
struct Lighting {
|
2016-03-02 22:16:38 -05:00
|
|
|
union LutEntry {
|
|
|
|
// Used for raw access
|
|
|
|
u32 raw;
|
|
|
|
|
|
|
|
// LUT value, encoded as 12-bit fixed point, with 12 fraction bits
|
2016-09-17 20:38:01 -04:00
|
|
|
BitField<0, 12, u32> value; // 0.0.12 fixed point
|
2016-03-02 22:16:38 -05:00
|
|
|
|
2017-06-16 07:00:15 -04:00
|
|
|
// Used for efficient interpolation.
|
|
|
|
BitField<12, 11, u32> difference; // 0.0.11 fixed point
|
|
|
|
BitField<23, 1, u32> neg_difference;
|
2016-03-02 22:16:38 -05:00
|
|
|
|
2017-06-16 07:00:15 -04:00
|
|
|
float ToFloat() const {
|
2016-03-02 22:16:38 -05:00
|
|
|
return static_cast<float>(value) / 4095.f;
|
|
|
|
}
|
2017-06-16 07:00:15 -04:00
|
|
|
|
|
|
|
float DiffToFloat() const {
|
|
|
|
float diff = static_cast<float>(difference) / 2047.f;
|
|
|
|
return neg_difference ? -diff : diff;
|
|
|
|
}
|
2016-03-02 22:16:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
std::array<std::array<LutEntry, 256>, 24> luts;
|
|
|
|
} lighting;
|
|
|
|
|
2016-05-11 07:39:28 -04:00
|
|
|
struct {
|
|
|
|
union LutEntry {
|
|
|
|
// Used for raw access
|
|
|
|
u32 raw;
|
|
|
|
|
2016-09-17 20:38:01 -04:00
|
|
|
BitField<0, 13, s32> difference; // 1.1.11 fixed point
|
|
|
|
BitField<13, 11, u32> value; // 0.0.11 fixed point
|
2017-06-22 10:22:45 -04:00
|
|
|
|
|
|
|
float ToFloat() const {
|
|
|
|
return static_cast<float>(value) / 2047.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float DiffToFloat() const {
|
|
|
|
return static_cast<float>(difference) / 2047.0f;
|
|
|
|
}
|
2016-05-11 07:39:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
std::array<LutEntry, 128> lut;
|
|
|
|
} fog;
|
|
|
|
|
2016-03-02 22:16:38 -05:00
|
|
|
/// Current Pica command list
|
|
|
|
struct {
|
|
|
|
const u32* head_ptr;
|
|
|
|
const u32* current_ptr;
|
|
|
|
u32 length;
|
|
|
|
} cmd_list;
|
|
|
|
|
|
|
|
/// Struct used to describe immediate mode rendering state
|
|
|
|
struct ImmediateModeState {
|
2016-03-05 17:49:23 -05:00
|
|
|
// Used to buffer partial vertices for immediate-mode rendering.
|
2016-12-18 19:42:19 -05:00
|
|
|
Shader::AttributeBuffer input_vertex;
|
2016-03-05 17:49:23 -05:00
|
|
|
// Index of the next attribute to be loaded into `input_vertex`.
|
2016-04-25 16:10:03 -04:00
|
|
|
u32 current_attribute = 0;
|
2016-03-02 22:16:38 -05:00
|
|
|
} immediate;
|
2016-03-05 17:49:23 -05:00
|
|
|
|
|
|
|
// This is constructed with a dummy triangle topology
|
|
|
|
PrimitiveAssembler<Shader::OutputVertex> primitive_assembler;
|
2016-03-02 22:16:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
extern State g_state; ///< Current Pica state
|
|
|
|
|
|
|
|
} // namespace
|