2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-07 21:46:09 -07: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 03:52:35 -06:00
|
|
|
#ifndef GCOGL_PIXELSHADER_H
|
|
|
|
#define GCOGL_PIXELSHADER_H
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2010-06-14 08:36:01 -06:00
|
|
|
#include "VideoCommon.h"
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2009-07-26 03:52:35 -06:00
|
|
|
#define I_COLORS "color"
|
|
|
|
#define I_KCOLORS "k"
|
|
|
|
#define I_ALPHA "alphaRef"
|
|
|
|
#define I_TEXDIMS "texdim"
|
|
|
|
#define I_ZBIAS "czbias"
|
2008-12-07 21:46:09 -07:00
|
|
|
#define I_INDTEXSCALE "cindscale"
|
2009-07-26 03:52:35 -06:00
|
|
|
#define I_INDTEXMTX "cindmtx"
|
|
|
|
#define I_FOG "cfog"
|
2010-09-22 20:17:48 -06:00
|
|
|
#define I_PLIGHTS "cLights"
|
2012-03-23 21:47:28 -06:00
|
|
|
#define I_PMATERIALS "cmtrl"
|
2010-09-22 20:17:48 -06:00
|
|
|
|
2011-01-07 12:23:57 -07: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-23 21:47:28 -06: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 15:32:05 -06:00
|
|
|
#define PIXELSHADERUID_MAX_VALUES 70
|
|
|
|
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2010-01-17 10:44:09 -07:00
|
|
|
// DO NOT make anything in this class virtual.
|
2011-09-03 18:10:07 -06:00
|
|
|
template<bool safe>
|
|
|
|
class _PIXELSHADERUID
|
2008-12-26 03:43:18 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-09-03 18:10:07 -06:00
|
|
|
u32 values[safe ? PIXELSHADERUID_MAX_VALUES_SAFE : PIXELSHADERUID_MAX_VALUES];
|
2011-09-29 15:32:05 -06:00
|
|
|
int num_values;
|
2008-12-26 03:43:18 -07:00
|
|
|
|
2011-09-03 18:10:07 -06:00
|
|
|
_PIXELSHADERUID()
|
2009-07-26 03:52:35 -06:00
|
|
|
{
|
2008-12-26 03:43:18 -07:00
|
|
|
}
|
2009-07-26 03:52:35 -06:00
|
|
|
|
2011-09-03 18:10:07 -06:00
|
|
|
_PIXELSHADERUID(const _PIXELSHADERUID& r)
|
2008-12-26 03:43:18 -07:00
|
|
|
{
|
2011-09-07 18:09:44 -06: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 03:43:18 -07:00
|
|
|
}
|
2009-07-26 03:52:35 -06:00
|
|
|
|
2011-06-04 13:56:18 -06:00
|
|
|
int GetNumValues() const
|
2009-07-26 03:52:35 -06:00
|
|
|
{
|
2011-09-03 18:10:07 -06:00
|
|
|
if (safe) return (sizeof(values) / sizeof(u32));
|
2011-09-07 18:09:44 -06:00
|
|
|
else return num_values;
|
2008-12-26 03:43:18 -07:00
|
|
|
}
|
2009-07-26 03:52:35 -06:00
|
|
|
|
2011-09-03 18:10:07 -06:00
|
|
|
bool operator <(const _PIXELSHADERUID& _Right) const
|
2008-12-26 03:43:18 -07:00
|
|
|
{
|
2011-09-07 18:09:44 -06:00
|
|
|
int N = GetNumValues();
|
|
|
|
if (N < _Right.GetNumValues())
|
2008-12-26 03:43:18 -07:00
|
|
|
return true;
|
2011-09-07 18:09:44 -06:00
|
|
|
else if (N > _Right.GetNumValues())
|
2008-12-26 03:43:18 -07:00
|
|
|
return false;
|
2011-09-07 18:09:44 -06:00
|
|
|
for (int i = 0; i < N; ++i)
|
2009-07-26 03:52:35 -06:00
|
|
|
{
|
2008-12-26 03:43:18 -07:00
|
|
|
if (values[i] < _Right.values[i])
|
|
|
|
return true;
|
|
|
|
else if (values[i] > _Right.values[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-26 03:52:35 -06:00
|
|
|
|
2011-09-03 18:10:07 -06:00
|
|
|
bool operator ==(const _PIXELSHADERUID& _Right) const
|
2008-12-26 03:43:18 -07:00
|
|
|
{
|
|
|
|
int N = GetNumValues();
|
2011-09-07 18:09:44 -06:00
|
|
|
if (N != _Right.GetNumValues())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < N; ++i)
|
2009-07-26 03:52:35 -06:00
|
|
|
{
|
2008-12-26 03:43:18 -07:00
|
|
|
if (values[i] != _Right.values[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2011-09-03 18:10:07 -06:00
|
|
|
typedef _PIXELSHADERUID<false> PIXELSHADERUID;
|
|
|
|
typedef _PIXELSHADERUID<true> PIXELSHADERUIDSAFE;
|
2008-12-26 03:43:18 -07:00
|
|
|
|
2012-04-02 21:08:36 -06:00
|
|
|
// Different ways to achieve rendering
|
|
|
|
enum PSGRENDER_MODE
|
2010-10-20 23:22:18 -06:00
|
|
|
{
|
2012-04-02 21:08:36 -06:00
|
|
|
PSGRENDER_NORMAL, // Render normally, without destination alpha
|
|
|
|
PSGRENDER_DSTALPHA_ALPHA_PASS, // Render normally first, then render again for alpha
|
|
|
|
PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND, // Use dual-source blending
|
2012-08-05 17:29:01 -06:00
|
|
|
PSGRENDER_ZCOMPLOC //Render to Depth Channel only with no depth dextures enabled
|
2010-10-20 23:22:18 -06:00
|
|
|
};
|
|
|
|
|
2012-04-02 21:08:36 -06:00
|
|
|
enum ALPHA_PRETEST_RESULT
|
|
|
|
{
|
|
|
|
ALPHAPT_UNDEFINED, // AlphaTest Result is not defined
|
|
|
|
ALPHAPT_ALWAYSFAIL, // Alpha test alway Fail
|
|
|
|
ALPHAPT_ALWAYSPASS // Alpha test alway Pass
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *GeneratePixelShaderCode(PSGRENDER_MODE PSGRenderMode, API_TYPE ApiType, u32 components);
|
2011-09-07 12:20:29 -06:00
|
|
|
|
2012-04-02 21:08:36 -06:00
|
|
|
void GetPixelShaderId(PIXELSHADERUID *uid, PSGRENDER_MODE PSGRenderMode, u32 components);
|
|
|
|
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, PSGRENDER_MODE PSGRenderMode, u32 components);
|
2010-01-17 10:44:09 -07:00
|
|
|
|
2011-09-08 16:32:04 -06:00
|
|
|
// Used to make sure that our optimized pixel shader IDs don't lose any possible shader code changes
|
2012-04-02 21:08:36 -06:00
|
|
|
void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::string& old_code, PSGRENDER_MODE PSGRenderMode, u32 components);
|
2011-09-08 16:32:04 -06:00
|
|
|
|
2009-07-26 03:52:35 -06:00
|
|
|
#endif // GCOGL_PIXELSHADER_H
|