1 // Copyright 2016 Dolphin Emulator Project 2 // Licensed under GPLv2+ 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include "Common/BitField.h" 8 9 #include "VideoCommon/BPMemory.h" 10 #include "VideoCommon/BPStructs.h" 11 12 enum class AbstractTextureFormat : u32; 13 14 enum class PrimitiveType : u32 15 { 16 Points, 17 Lines, 18 Triangles, 19 TriangleStrip, 20 }; 21 22 union RasterizationState 23 { 24 void Generate(const BPMemory& bp, PrimitiveType primitive_type); 25 26 RasterizationState& operator=(const RasterizationState& rhs); 27 28 bool operator==(const RasterizationState& rhs) const { return hex == rhs.hex; } 29 bool operator!=(const RasterizationState& rhs) const { return hex != rhs.hex; } 30 bool operator<(const RasterizationState& rhs) const { return hex < rhs.hex; } 31 BitField<0, 2, GenMode::CullMode> cullmode; 32 BitField<3, 2, PrimitiveType> primitive; 33 34 u32 hex; 35 }; 36 37 union FramebufferState 38 { 39 BitField<0, 8, AbstractTextureFormat> color_texture_format; 40 BitField<8, 8, AbstractTextureFormat> depth_texture_format; 41 BitField<16, 8, u32> samples; 42 BitField<24, 1, u32> per_sample_shading; 43 44 bool operator==(const FramebufferState& rhs) const { return hex == rhs.hex; } 45 bool operator!=(const FramebufferState& rhs) const { return hex != rhs.hex; } 46 FramebufferState& operator=(const FramebufferState& rhs); 47 48 u32 hex; 49 }; 50 51 union DepthState 52 { 53 void Generate(const BPMemory& bp); 54 55 DepthState& operator=(const DepthState& rhs); 56 57 bool operator==(const DepthState& rhs) const { return hex == rhs.hex; } 58 bool operator!=(const DepthState& rhs) const { return hex != rhs.hex; } 59 bool operator<(const DepthState& rhs) const { return hex < rhs.hex; } 60 BitField<0, 1, u32> testenable; 61 BitField<1, 1, u32> updateenable; 62 BitField<2, 3, ZMode::CompareMode> func; 63 64 u32 hex; 65 }; 66 67 union BlendingState 68 { 69 void Generate(const BPMemory& bp); 70 71 // HACK: Replaces logical operations with blend operations. 72 // Will not be bit-correct, and in some cases not even remotely in the same ballpark. 73 void ApproximateLogicOpWithBlending(); 74 75 BlendingState& operator=(const BlendingState& rhs); 76 77 bool operator==(const BlendingState& rhs) const { return hex == rhs.hex; } 78 bool operator!=(const BlendingState& rhs) const { return hex != rhs.hex; } 79 bool operator<(const BlendingState& rhs) const { return hex < rhs.hex; } 80 BitField<0, 1, u32> blendenable; 81 BitField<1, 1, u32> logicopenable; 82 BitField<2, 1, u32> dstalpha; 83 BitField<3, 1, u32> colorupdate; 84 BitField<4, 1, u32> alphaupdate; 85 BitField<5, 1, u32> subtract; 86 BitField<6, 1, u32> subtractAlpha; 87 BitField<7, 1, u32> usedualsrc; 88 BitField<8, 3, BlendMode::BlendFactor> dstfactor; 89 BitField<11, 3, BlendMode::BlendFactor> srcfactor; 90 BitField<14, 3, BlendMode::BlendFactor> dstfactoralpha; 91 BitField<17, 3, BlendMode::BlendFactor> srcfactoralpha; 92 BitField<20, 4, BlendMode::LogicOp> logicmode; 93 94 u32 hex; 95 }; 96 97 union SamplerState 98 { 99 using StorageType = u64; 100 101 enum class Filter : StorageType 102 { 103 Point, 104 Linear 105 }; 106 107 enum class AddressMode : StorageType 108 { 109 Clamp, 110 Repeat, 111 MirroredRepeat 112 }; 113 114 void Generate(const BPMemory& bp, u32 index); 115 116 SamplerState& operator=(const SamplerState& rhs); 117 118 bool operator==(const SamplerState& rhs) const { return hex == rhs.hex; } 119 bool operator!=(const SamplerState& rhs) const { return hex != rhs.hex; } 120 bool operator<(const SamplerState& rhs) const { return hex < rhs.hex; } 121 BitField<0, 1, Filter> min_filter; 122 BitField<1, 1, Filter> mag_filter; 123 BitField<2, 1, Filter> mipmap_filter; 124 BitField<3, 2, AddressMode> wrap_u; 125 BitField<5, 2, AddressMode> wrap_v; 126 BitField<7, 16, s64> lod_bias; // multiplied by 256 127 BitField<23, 8, u64> min_lod; // multiplied by 16 128 BitField<31, 8, u64> max_lod; // multiplied by 16 129 BitField<39, 1, u64> anisotropic_filtering; 130 131 StorageType hex; 132 }; 133 134 namespace RenderState 135 { 136 RasterizationState GetInvalidRasterizationState(); 137 RasterizationState GetNoCullRasterizationState(PrimitiveType primitive); 138 RasterizationState GetCullBackFaceRasterizationState(PrimitiveType primitive); 139 DepthState GetInvalidDepthState(); 140 DepthState GetNoDepthTestingDepthState(); 141 DepthState GetAlwaysWriteDepthState(); 142 BlendingState GetInvalidBlendingState(); 143 BlendingState GetNoBlendingBlendState(); 144 BlendingState GetNoColorWriteBlendState(); 145 SamplerState GetInvalidSamplerState(); 146 SamplerState GetPointSamplerState(); 147 SamplerState GetLinearSamplerState(); 148 FramebufferState GetColorFramebufferState(AbstractTextureFormat format); 149 FramebufferState GetRGBA8FramebufferState(); 150 } // namespace RenderState 151