2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
#ifndef GCOGL_PIXELSHADER_H
|
|
|
|
#define GCOGL_PIXELSHADER_H
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2010-06-14 14:36:01 +00:00
|
|
|
#include "VideoCommon.h"
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
#define I_COLORS "color"
|
|
|
|
#define I_KCOLORS "k"
|
|
|
|
#define I_ALPHA "alphaRef"
|
|
|
|
#define I_TEXDIMS "texdim"
|
|
|
|
#define I_ZBIAS "czbias"
|
2008-12-08 04:46:09 +00:00
|
|
|
#define I_INDTEXSCALE "cindscale"
|
2009-07-26 09:52:35 +00:00
|
|
|
#define I_INDTEXMTX "cindmtx"
|
|
|
|
#define I_FOG "cfog"
|
2010-09-23 02:17:48 +00:00
|
|
|
#define I_PLIGHTS "cLights"
|
2012-03-24 03:47:28 +00:00
|
|
|
#define I_PMATERIALS "cmtrl"
|
2010-09-23 02:17:48 +00:00
|
|
|
|
2011-01-07 19:23:57 +00:00
|
|
|
#define C_COLORMATRIX 0 // 0
|
|
|
|
#define C_COLORS 0 // 0
|
|
|
|
#define C_KCOLORS (C_COLORS + 4) // 4
|
|
|
|
#define C_ALPHA (C_KCOLORS + 4) // 8
|
|
|
|
#define C_TEXDIMS (C_ALPHA + 1) // 9
|
2012-03-24 03:47:28 +00:00
|
|
|
#define C_ZBIAS (C_TEXDIMS + 8) //17
|
|
|
|
#define C_INDTEXSCALE (C_ZBIAS + 2) //19
|
|
|
|
#define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
|
|
|
|
#define C_FOG (C_INDTEXMTX + 6) //27
|
|
|
|
|
|
|
|
#define C_PLIGHTS (C_FOG + 3)
|
|
|
|
#define C_PMATERIALS (C_PLIGHTS + 40)
|
|
|
|
#define C_PENVCONST_END (C_PMATERIALS + 4)
|
2011-09-29 21:32:05 +00:00
|
|
|
#define PIXELSHADERUID_MAX_VALUES 70
|
|
|
|
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2010-01-17 17:44:09 +00:00
|
|
|
// DO NOT make anything in this class virtual.
|
2011-09-04 00:10:07 +00:00
|
|
|
template<bool safe>
|
|
|
|
class _PIXELSHADERUID
|
2008-12-26 10:43:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-09-04 00:10:07 +00:00
|
|
|
u32 values[safe ? PIXELSHADERUID_MAX_VALUES_SAFE : PIXELSHADERUID_MAX_VALUES];
|
2011-09-29 21:32:05 +00:00
|
|
|
int num_values;
|
2008-12-26 10:43:18 +00:00
|
|
|
|
2011-09-04 00:10:07 +00:00
|
|
|
_PIXELSHADERUID()
|
2009-07-26 09:52:35 +00:00
|
|
|
{
|
2008-12-26 10:43:18 +00:00
|
|
|
}
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2011-09-04 00:10:07 +00:00
|
|
|
_PIXELSHADERUID(const _PIXELSHADERUID& r)
|
2008-12-26 10:43:18 +00:00
|
|
|
{
|
2011-09-08 00:09:44 +00:00
|
|
|
num_values = r.num_values;
|
|
|
|
if (safe) memcpy(values, r.values, PIXELSHADERUID_MAX_VALUES_SAFE);
|
|
|
|
else memcpy(values, r.values, r.GetNumValues() * sizeof(values[0]));
|
2008-12-26 10:43:18 +00:00
|
|
|
}
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2011-06-04 19:56:18 +00:00
|
|
|
int GetNumValues() const
|
2009-07-26 09:52:35 +00:00
|
|
|
{
|
2011-09-04 00:10:07 +00:00
|
|
|
if (safe) return (sizeof(values) / sizeof(u32));
|
2011-09-08 00:09:44 +00:00
|
|
|
else return num_values;
|
2008-12-26 10:43:18 +00:00
|
|
|
}
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2011-09-04 00:10:07 +00:00
|
|
|
bool operator <(const _PIXELSHADERUID& _Right) const
|
2008-12-26 10:43:18 +00:00
|
|
|
{
|
2011-09-08 00:09:44 +00:00
|
|
|
int N = GetNumValues();
|
|
|
|
if (N < _Right.GetNumValues())
|
2008-12-26 10:43:18 +00:00
|
|
|
return true;
|
2011-09-08 00:09:44 +00:00
|
|
|
else if (N > _Right.GetNumValues())
|
2008-12-26 10:43:18 +00:00
|
|
|
return false;
|
2011-09-08 00:09:44 +00:00
|
|
|
for (int i = 0; i < N; ++i)
|
2009-07-26 09:52:35 +00:00
|
|
|
{
|
2008-12-26 10:43:18 +00:00
|
|
|
if (values[i] < _Right.values[i])
|
|
|
|
return true;
|
|
|
|
else if (values[i] > _Right.values[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2011-09-04 00:10:07 +00:00
|
|
|
bool operator ==(const _PIXELSHADERUID& _Right) const
|
2008-12-26 10:43:18 +00:00
|
|
|
{
|
|
|
|
int N = GetNumValues();
|
2011-09-08 00:09:44 +00:00
|
|
|
if (N != _Right.GetNumValues())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < N; ++i)
|
2009-07-26 09:52:35 +00:00
|
|
|
{
|
2008-12-26 10:43:18 +00:00
|
|
|
if (values[i] != _Right.values[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2011-09-04 00:10:07 +00:00
|
|
|
typedef _PIXELSHADERUID<false> PIXELSHADERUID;
|
|
|
|
typedef _PIXELSHADERUID<true> PIXELSHADERUIDSAFE;
|
2008-12-26 10:43:18 +00:00
|
|
|
|
2012-08-10 16:57:37 +00:00
|
|
|
// Different ways to achieve rendering with destination alpha
|
|
|
|
enum DSTALPHA_MODE
|
2010-10-21 05:22:18 +00:00
|
|
|
{
|
2012-08-10 16:57:37 +00:00
|
|
|
DSTALPHA_NONE, // Render normally, without destination alpha
|
|
|
|
DSTALPHA_ALPHA_PASS, // Render normally first, then render again for alpha
|
|
|
|
DSTALPHA_DUAL_SOURCE_BLEND // Use dual-source blending
|
2010-10-21 05:22:18 +00:00
|
|
|
};
|
|
|
|
|
2012-08-10 16:57:37 +00:00
|
|
|
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
|
2011-09-07 18:20:29 +00:00
|
|
|
|
2012-08-10 16:57:37 +00:00
|
|
|
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
|
|
|
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
2010-01-17 17:44:09 +00:00
|
|
|
|
2011-09-08 22:32:04 +00:00
|
|
|
// Used to make sure that our optimized pixel shader IDs don't lose any possible shader code changes
|
2012-08-10 16:57:37 +00:00
|
|
|
void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::string& old_code, DSTALPHA_MODE dstAlphaMode, u32 components);
|
2011-09-08 22:32:04 +00:00
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
#endif // GCOGL_PIXELSHADER_H
|