VideoCommon: Make API_TYPE an enum class

Allows for forward declarations in most places, which prevents dumping
unrelated VideoCommon.h contents directly into headers.
This commit is contained in:
Lioncash
2016-07-21 19:04:57 -04:00
parent 66b11c5198
commit 14e0b48ae4
28 changed files with 130 additions and 175 deletions

View File

@ -15,6 +15,7 @@
#include "VideoCommon/LightingShaderGen.h"
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h" // for texture projection mode
@ -335,16 +336,16 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode)
}
static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, int n,
API_TYPE ApiType);
APIType ApiType);
static void WriteTevRegular(ShaderCode& out, const char* components, int bias, int op, int clamp,
int shift);
static void SampleTexture(ShaderCode& out, const char* texcoords, const char* texswap, int texmap,
bool stereo, API_TYPE ApiType);
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, API_TYPE ApiType,
bool stereo, APIType ApiType);
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType,
DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth);
static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data);
ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
const pixel_shader_uid_data* uid_data)
{
ShaderCode out;
@ -379,7 +380,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
"int3 itrunc(float3 x) { return int3(trunc(x)); }\n"
"int4 itrunc(float4 x) { return int4(trunc(x)); }\n\n");
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
{
out.Write("SAMPLER_BINDING(0) uniform sampler2DArray samp[8];\n");
}
@ -392,7 +393,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
}
out.Write("\n");
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
{
out.Write("layout(std140%s) uniform PSBlock {\n",
g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 1" : "");
@ -419,7 +420,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
{
out.Write("%s", s_lighting_struct);
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
{
out.Write("layout(std140%s) uniform VSBlock {\n",
g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 2" : "");
@ -434,7 +435,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
if (uid_data->bounding_box)
{
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
{
out.Write("layout(std140, binding = 3) buffer BBox {\n"
"\tint4 bbox_data;\n"
@ -487,7 +488,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
// ARB_image_load_store extension yet.
// D3D11 also has a way to force the driver to enable early-z, so we're fine here.
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
{
// This is a #define which signals whatever early-z method the driver supports.
out.Write("FORCE_EARLY_Z; \n");
@ -509,7 +510,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
warn_once = false;
}
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
{
out.Write("out vec4 ocol0;\n");
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
@ -715,7 +716,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
out.Write("\tfloat2 screenpos = rawpos.xy * " I_EFBSCALE ".xy;\n");
// Opengl has reversed vertical screenspace coordinates
if (ApiType == API_OPENGL)
if (ApiType == APIType::OpenGL)
out.Write("\tscreenpos.y = %i.0 - screenpos.y;\n", EFB_HEIGHT);
out.Write("\tint zCoord = int(" I_ZSLOPE ".z + " I_ZSLOPE ".x * screenpos.x + " I_ZSLOPE
@ -735,7 +736,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
}
else
{
if (ApiType == API_D3D)
if (ApiType == APIType::D3D)
out.Write("\tint zCoord = int((1.0 - rawpos.z) * 16777216.0);\n");
else
out.Write("\tint zCoord = int(rawpos.z * 16777216.0);\n");
@ -749,7 +750,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
// Note: z-textures are not written to depth buffer if early depth test is used
if (uid_data->per_pixel_depth && uid_data->early_ztest)
{
if (ApiType == API_D3D)
if (ApiType == APIType::D3D)
out.Write("\tdepth = 1.0 - float(zCoord) / 16777216.0;\n");
else
out.Write("\tdepth = float(zCoord) / 16777216.0;\n");
@ -770,7 +771,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
if (uid_data->per_pixel_depth && uid_data->late_ztest)
{
if (ApiType == API_D3D)
if (ApiType == APIType::D3D)
out.Write("\tdepth = 1.0 - float(zCoord) / 16777216.0;\n");
else
out.Write("\tdepth = float(zCoord) / 16777216.0;\n");
@ -800,7 +801,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
if (uid_data->bounding_box)
{
const char* atomic_op = ApiType == API_OPENGL ? "atomic" : "Interlocked";
const char* atomic_op = ApiType == APIType::OpenGL ? "atomic" : "Interlocked";
out.Write("\tif(bbox_data[0] > int(rawpos.x)) %sMin(bbox_data[0], int(rawpos.x));\n"
"\tif(bbox_data[1] < int(rawpos.x)) %sMax(bbox_data[1], int(rawpos.x));\n"
"\tif(bbox_data[2] > int(rawpos.y)) %sMin(bbox_data[2], int(rawpos.y));\n"
@ -814,7 +815,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,
}
static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, int n,
API_TYPE ApiType)
APIType ApiType)
{
auto& stage = uid_data->stagehash[n];
out.Write("\n\t// TEV stage %d\n", n);
@ -1142,11 +1143,11 @@ static void WriteTevRegular(ShaderCode& out, const char* components, int bias, i
}
static void SampleTexture(ShaderCode& out, const char* texcoords, const char* texswap, int texmap,
bool stereo, API_TYPE ApiType)
bool stereo, APIType ApiType)
{
out.SetConstantsUsed(C_TEXDIMS + texmap, C_TEXDIMS + texmap);
if (ApiType == API_D3D)
if (ApiType == APIType::D3D)
out.Write("iround(255.0 * Tex[%d].Sample(samp[%d], float3(%s.xy * " I_TEXDIMS
"[%d].xy, %s))).%s;\n",
texmap, texmap, texcoords, texmap, stereo ? "layer" : "0.0", texswap);
@ -1173,7 +1174,7 @@ static const char* tevAlphaFunclogicTable[] = {
" == " // xnor
};
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, API_TYPE ApiType,
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType,
DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth)
{
static const char* alphaRef[2] = {I_ALPHA ".r", I_ALPHA ".g"};
@ -1204,13 +1205,13 @@ static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_dat
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
out.Write("\t\tocol1 = float4(0.0, 0.0, 0.0, 0.0);\n");
if (per_pixel_depth)
out.Write("\t\tdepth = %s;\n", (ApiType == API_D3D) ? "0.0" : "1.0");
out.Write("\t\tdepth = %s;\n", (ApiType == APIType::D3D) ? "0.0" : "1.0");
// ZCOMPLOC HACK:
if (!uid_data->alpha_test_use_zcomploc_hack)
{
out.Write("\t\tdiscard;\n");
if (ApiType != API_D3D)
if (ApiType != APIType::D3D)
out.Write("\t\treturn;\n");
}