2011-03-31 10:53:28 +00:00
|
|
|
#include "quakedef.h"
|
|
|
|
|
2012-09-30 05:52:03 +00:00
|
|
|
#ifdef D3D9QUAKE
|
2011-03-31 10:53:28 +00:00
|
|
|
#include "shader.h"
|
2012-07-05 19:42:36 +00:00
|
|
|
#include "winquake.h"
|
2011-05-26 16:46:43 +00:00
|
|
|
#if !defined(HMONITOR_DECLARED) && (WINVER < 0x0500)
|
|
|
|
#define HMONITOR_DECLARED
|
|
|
|
DECLARE_HANDLE(HMONITOR);
|
|
|
|
#endif
|
2011-03-31 10:53:28 +00:00
|
|
|
#include <d3d9.h>
|
|
|
|
extern LPDIRECT3DDEVICE9 pD3DDev9;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
LPCSTR Name;
|
|
|
|
LPCSTR Definition;
|
|
|
|
} D3DXMACRO;
|
|
|
|
|
2011-09-03 03:49:43 +00:00
|
|
|
#define D3DXHANDLE void *
|
2011-03-31 10:53:28 +00:00
|
|
|
#define LPD3DXINCLUDE void *
|
|
|
|
|
2012-09-30 05:52:03 +00:00
|
|
|
#undef INTERFACE
|
|
|
|
#define INTERFACE d3dxbuffer
|
|
|
|
DECLARE_INTERFACE_(d3dxbuffer,IUnknown)
|
|
|
|
{
|
|
|
|
STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
|
|
|
|
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
|
|
|
|
STDMETHOD_(ULONG,Release)(THIS) PURE;
|
|
|
|
|
|
|
|
STDMETHOD_(LPVOID,GetBufferPointer)(THIS) PURE;
|
|
|
|
STDMETHOD_(SIZE_T,GetBufferSize)(THIS) PURE;
|
|
|
|
};
|
2011-03-31 10:53:28 +00:00
|
|
|
typedef struct d3dxbuffer *LPD3DXBUFFER;
|
|
|
|
|
2011-09-03 03:49:43 +00:00
|
|
|
typedef enum _D3DXREGISTER_SET
|
|
|
|
{
|
|
|
|
D3DXRS_BOOL,
|
|
|
|
D3DXRS_INT4,
|
|
|
|
D3DXRS_FLOAT4,
|
|
|
|
D3DXRS_SAMPLER,
|
|
|
|
D3DXRS_FORCE_DWORD = 0x7fffffff
|
|
|
|
} D3DXREGISTER_SET, *LPD3DXREGISTER_SET;
|
|
|
|
typedef enum _D3DXPARAMETER_CLASS
|
|
|
|
{
|
|
|
|
D3DXPC_SCALAR,
|
|
|
|
D3DXPC_VECTOR,
|
|
|
|
D3DXPC_MATRIX_ROWS,
|
|
|
|
D3DXPC_MATRIX_COLUMNS,
|
|
|
|
D3DXPC_OBJECT,
|
|
|
|
D3DXPC_STRUCT,
|
|
|
|
D3DXPC_FORCE_DWORD = 0x7fffffff
|
|
|
|
} D3DXPARAMETER_CLASS, *LPD3DXPARAMETER_CLASS;
|
|
|
|
typedef enum _D3DXPARAMETER_TYPE
|
|
|
|
{
|
|
|
|
D3DXPT_VOID,
|
|
|
|
D3DXPT_BOOL,
|
|
|
|
D3DXPT_INT,
|
|
|
|
D3DXPT_FLOAT,
|
|
|
|
D3DXPT_STRING,
|
|
|
|
D3DXPT_TEXTURE,
|
|
|
|
D3DXPT_TEXTURE1D,
|
|
|
|
D3DXPT_TEXTURE2D,
|
|
|
|
D3DXPT_TEXTURE3D,
|
|
|
|
D3DXPT_TEXTURECUBE,
|
|
|
|
D3DXPT_SAMPLER,
|
|
|
|
D3DXPT_SAMPLER1D,
|
|
|
|
D3DXPT_SAMPLER2D,
|
|
|
|
D3DXPT_SAMPLER3D,
|
|
|
|
D3DXPT_SAMPLERCUBE,
|
|
|
|
D3DXPT_PIXELSHADER,
|
|
|
|
D3DXPT_VERTEXSHADER,
|
|
|
|
D3DXPT_PIXELFRAGMENT,
|
|
|
|
D3DXPT_VERTEXFRAGMENT,
|
|
|
|
} D3DXPARAMETER_TYPE, *LPD3DXPARAMETER_TYPE;
|
|
|
|
typedef struct _D3DXCONSTANT_DESC
|
|
|
|
{
|
|
|
|
LPCSTR Name; // Constant name
|
|
|
|
|
|
|
|
D3DXREGISTER_SET RegisterSet; // Register set
|
|
|
|
UINT RegisterIndex; // Register index
|
|
|
|
UINT RegisterCount; // Number of registers occupied
|
|
|
|
|
|
|
|
D3DXPARAMETER_CLASS Class; // Class
|
|
|
|
D3DXPARAMETER_TYPE Type; // Component type
|
|
|
|
|
|
|
|
UINT Rows; // Number of rows
|
|
|
|
UINT Columns; // Number of columns
|
|
|
|
UINT Elements; // Number of array elements
|
|
|
|
UINT StructMembers; // Number of structure member sub-parameters
|
|
|
|
|
|
|
|
UINT Bytes; // Data size, in bytes
|
|
|
|
LPCVOID DefaultValue; // Pointer to default value
|
|
|
|
|
|
|
|
} D3DXCONSTANT_DESC, *LPD3DXCONSTANT_DESC;
|
|
|
|
typedef struct _D3DXCONSTANTTABLE_DESC
|
|
|
|
{
|
|
|
|
LPCSTR Creator; // Creator string
|
|
|
|
DWORD Version; // Shader version
|
|
|
|
UINT Constants; // Number of constants
|
|
|
|
|
|
|
|
} D3DXCONSTANTTABLE_DESC, *LPD3DXCONSTANTTABLE_DESC;
|
|
|
|
|
2012-09-30 05:52:03 +00:00
|
|
|
#undef INTERFACE
|
|
|
|
#define INTERFACE d3dxconstanttable
|
|
|
|
DECLARE_INTERFACE_(d3dxconstanttable,IUnknown)
|
|
|
|
{
|
|
|
|
STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
|
|
|
|
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
|
|
|
|
STDMETHOD_(ULONG,Release)(THIS) PURE;
|
|
|
|
|
|
|
|
STDMETHOD_(LPVOID,GetBufferPointer)(THIS) PURE;
|
|
|
|
STDMETHOD_(SIZE_T,GetBufferSize)(THIS) PURE;
|
|
|
|
|
2011-09-03 03:49:43 +00:00
|
|
|
STDMETHOD(GetDesc)(THIS_ D3DXCONSTANTTABLE_DESC *pDesc) PURE;
|
|
|
|
STDMETHOD(GetConstantDesc)(THIS_ D3DXHANDLE hConstant, D3DXCONSTANT_DESC *pConstantDesc, UINT *pCount) PURE;
|
|
|
|
|
|
|
|
STDMETHOD_(D3DXHANDLE, GetConstant)(THIS_ D3DXHANDLE hConstant, UINT Index) PURE;
|
|
|
|
STDMETHOD_(D3DXHANDLE, GetConstantByName)(THIS_ D3DXHANDLE hConstant, LPCSTR pName) PURE;
|
2012-09-30 05:52:03 +00:00
|
|
|
STDMETHOD_(D3DXHANDLE, GetConstantElement)(THIS_ D3DXHANDLE hConstant, UINT Index) PURE;
|
|
|
|
|
|
|
|
/*more stuff not included here cos I don't need it*/
|
|
|
|
};
|
2011-09-03 03:49:43 +00:00
|
|
|
typedef struct d3dxconstanttable *LPD3DXCONSTANTTABLE;
|
|
|
|
|
2011-03-31 10:53:28 +00:00
|
|
|
|
|
|
|
HRESULT (WINAPI *pD3DXCompileShader) (
|
|
|
|
LPCSTR pSrcData,
|
|
|
|
UINT SrcDataLen,
|
|
|
|
const D3DXMACRO *pDefines,
|
|
|
|
LPD3DXINCLUDE pInclude,
|
|
|
|
LPCSTR pEntrypoint,
|
|
|
|
LPCSTR pTarget,
|
|
|
|
UINT Flags,
|
|
|
|
LPD3DXBUFFER *ppCode,
|
|
|
|
LPD3DXBUFFER *ppErrorMsgs,
|
|
|
|
LPD3DXCONSTANTTABLE *constants
|
|
|
|
);
|
2012-12-04 19:37:57 +00:00
|
|
|
static dllhandle_t *shaderlib;
|
2011-03-31 10:53:28 +00:00
|
|
|
|
2014-03-30 08:55:06 +00:00
|
|
|
#ifndef IUnknown_Release
|
|
|
|
#define IUnknown_Release(This) \
|
|
|
|
(This)->lpVtbl -> Release(This)
|
|
|
|
#endif
|
2011-03-31 10:53:28 +00:00
|
|
|
|
2014-06-08 09:36:15 +00:00
|
|
|
static qboolean D3D9Shader_CreateProgram (program_t *prog, const char *sname, unsigned int permu, int ver, const char **precompilerconstants, const char *vert, const char *tcs, const char *tes, const char *frag, qboolean silent, vfsfile_t *blobfile)
|
2011-03-31 10:53:28 +00:00
|
|
|
{
|
|
|
|
D3DXMACRO defines[64];
|
|
|
|
LPD3DXBUFFER code = NULL, errors = NULL;
|
2012-01-21 07:53:49 +00:00
|
|
|
qboolean success = false;
|
2011-09-03 03:49:43 +00:00
|
|
|
|
2012-11-27 03:23:19 +00:00
|
|
|
prog->permu[permu].handle.hlsl.vert = NULL;
|
|
|
|
prog->permu[permu].handle.hlsl.frag = NULL;
|
2011-03-31 10:53:28 +00:00
|
|
|
|
|
|
|
if (pD3DXCompileShader)
|
|
|
|
{
|
|
|
|
int consts;
|
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
|
|
|
for (consts = 0; precompilerconstants[consts]; consts++)
|
2011-09-03 03:49:43 +00:00
|
|
|
;
|
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
|
|
|
consts+=2;
|
2011-03-31 10:53:28 +00:00
|
|
|
if (consts >= sizeof(defines) / sizeof(defines[0]))
|
2012-01-21 07:53:49 +00:00
|
|
|
return success;
|
2011-03-31 10:53:28 +00:00
|
|
|
|
|
|
|
consts = 0;
|
2011-09-03 03:49:43 +00:00
|
|
|
defines[consts].Name = NULL; /*shader type*/
|
2011-03-31 10:53:28 +00:00
|
|
|
defines[consts].Definition = "1";
|
|
|
|
consts++;
|
|
|
|
|
|
|
|
defines[consts].Name = "ENGINE_"DISTRIBUTION;
|
|
|
|
defines[consts].Definition = __DATE__;
|
|
|
|
consts++;
|
|
|
|
|
|
|
|
for (; *precompilerconstants; precompilerconstants++)
|
|
|
|
{
|
|
|
|
defines[consts].Name = NULL;
|
|
|
|
defines[consts].Definition = NULL;
|
|
|
|
consts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
defines[consts].Name = NULL;
|
|
|
|
defines[consts].Definition = NULL;
|
|
|
|
|
2012-01-21 07:53:49 +00:00
|
|
|
success = true;
|
|
|
|
|
2011-03-31 10:53:28 +00:00
|
|
|
defines[0].Name = "VERTEX_SHADER";
|
2012-11-27 03:23:19 +00:00
|
|
|
if (FAILED(pD3DXCompileShader(vert, strlen(vert), defines, NULL, "main", "vs_2_0", 0, &code, &errors, (LPD3DXCONSTANTTABLE*)&prog->permu[permu].handle.hlsl.ctabv)))
|
2012-01-21 07:53:49 +00:00
|
|
|
success = false;
|
|
|
|
else
|
2011-03-31 10:53:28 +00:00
|
|
|
{
|
2012-11-27 03:23:19 +00:00
|
|
|
IDirect3DDevice9_CreateVertexShader(pD3DDev9, code->lpVtbl->GetBufferPointer(code), (IDirect3DVertexShader9**)&prog->permu[permu].handle.hlsl.vert);
|
2011-03-31 10:53:28 +00:00
|
|
|
code->lpVtbl->Release(code);
|
|
|
|
}
|
|
|
|
if (errors)
|
|
|
|
{
|
|
|
|
char *messages = errors->lpVtbl->GetBufferPointer(errors);
|
2012-11-27 03:23:19 +00:00
|
|
|
Con_Printf("Error compiling vertex shader %s:\n%s", sname, messages);
|
2011-03-31 10:53:28 +00:00
|
|
|
errors->lpVtbl->Release(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
defines[0].Name = "FRAGMENT_SHADER";
|
2012-11-27 03:23:19 +00:00
|
|
|
if (FAILED(pD3DXCompileShader(frag, strlen(frag), defines, NULL, "main", "ps_2_0", 0, &code, &errors, (LPD3DXCONSTANTTABLE*)&prog->permu[permu].handle.hlsl.ctabf)))
|
2012-01-21 07:53:49 +00:00
|
|
|
success = false;
|
|
|
|
else
|
2011-03-31 10:53:28 +00:00
|
|
|
{
|
2012-11-27 03:23:19 +00:00
|
|
|
IDirect3DDevice9_CreatePixelShader(pD3DDev9, code->lpVtbl->GetBufferPointer(code), (IDirect3DPixelShader9**)&prog->permu[permu].handle.hlsl.frag);
|
2011-03-31 10:53:28 +00:00
|
|
|
code->lpVtbl->Release(code);
|
|
|
|
}
|
|
|
|
if (errors)
|
|
|
|
{
|
|
|
|
char *messages = errors->lpVtbl->GetBufferPointer(errors);
|
2012-11-27 03:23:19 +00:00
|
|
|
Con_Printf("Error compiling pixel shader %s:\n%s", sname, messages);
|
2011-03-31 10:53:28 +00:00
|
|
|
errors->lpVtbl->Release(errors);
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 07:53:49 +00:00
|
|
|
return success;
|
2011-09-03 03:49:43 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 00:14:43 +00:00
|
|
|
static int D3D9Shader_FindUniform_(LPD3DXCONSTANTTABLE ct, const char *name)
|
2011-09-03 03:49:43 +00:00
|
|
|
{
|
|
|
|
if (ct)
|
|
|
|
{
|
|
|
|
UINT dc = 1;
|
|
|
|
D3DXCONSTANT_DESC d;
|
2015-03-03 00:14:43 +00:00
|
|
|
if (!FAILED(ct->lpVtbl->GetConstantDesc(ct, (void*)name, &d, &dc)))
|
2011-09-03 03:49:43 +00:00
|
|
|
return d.RegisterIndex;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-03 00:14:43 +00:00
|
|
|
static int D3D9Shader_FindUniform(union programhandle_u *h, int type, const char *name)
|
2011-09-03 03:49:43 +00:00
|
|
|
{
|
|
|
|
int offs;
|
|
|
|
|
|
|
|
if (!type || type == 1)
|
|
|
|
{
|
2012-09-30 05:52:03 +00:00
|
|
|
offs = D3D9Shader_FindUniform_(h->hlsl.ctabv, name);
|
2011-09-03 03:49:43 +00:00
|
|
|
if (offs >= 0)
|
|
|
|
return offs;
|
|
|
|
}
|
|
|
|
if (!type || type == 2)
|
|
|
|
{
|
2012-09-30 05:52:03 +00:00
|
|
|
offs = D3D9Shader_FindUniform_(h->hlsl.ctabf, name);
|
2011-09-03 03:49:43 +00:00
|
|
|
if (offs >= 0)
|
|
|
|
return offs;
|
|
|
|
}
|
2011-03-31 10:53:28 +00:00
|
|
|
|
2011-09-03 03:49:43 +00:00
|
|
|
return -1;
|
2011-03-31 10:53:28 +00:00
|
|
|
}
|
2014-03-30 08:55:06 +00:00
|
|
|
|
|
|
|
static void D3D9Shader_ProgAutoFields(program_t *prog, char **cvarnames, int *cvartypes)
|
|
|
|
{
|
|
|
|
unsigned int i, p;
|
|
|
|
qboolean found;
|
|
|
|
int uniformloc;
|
|
|
|
char tmpname[128];
|
|
|
|
cvar_t *cvar;
|
|
|
|
|
2015-03-03 00:14:43 +00:00
|
|
|
static const char *defaultsamplers[] =
|
|
|
|
{
|
|
|
|
"s_diffuse",
|
|
|
|
"s_normalmap",
|
|
|
|
"s_specular",
|
|
|
|
"s_upper",
|
|
|
|
"s_lower",
|
|
|
|
"s_fullbright",
|
|
|
|
"s_paletted",
|
|
|
|
"s_shadowmap",
|
|
|
|
"s_projectionmap",
|
|
|
|
"s_lightmap",
|
|
|
|
"s_deluxmap"
|
|
|
|
#if MAXRLIGHTMAPS > 1
|
|
|
|
,"s_lightmap1"
|
|
|
|
,"s_lightmap2"
|
|
|
|
,"s_lightmap3"
|
|
|
|
,"s_deluxmap1"
|
|
|
|
,"s_deluxmap2"
|
|
|
|
,"s_deluxmap3"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2014-03-30 08:55:06 +00:00
|
|
|
prog->numparams = 0;
|
|
|
|
|
|
|
|
prog->nofixedcompat = true;
|
|
|
|
|
|
|
|
/*set cvar uniforms*/
|
|
|
|
for (i = 0; cvarnames[i]; i++)
|
|
|
|
{
|
|
|
|
for (p = 0; cvarnames[i][p] && (unsigned char)cvarnames[i][p] > 32 && p < sizeof(tmpname)-1; p++)
|
|
|
|
tmpname[p] = cvarnames[i][p];
|
|
|
|
tmpname[p] = 0;
|
|
|
|
cvar = Cvar_FindVar(tmpname);
|
|
|
|
if (!cvar)
|
|
|
|
continue;
|
|
|
|
cvar->flags |= CVAR_SHADERSYSTEM;
|
|
|
|
for (p = 0; p < PERMUTATIONS; p++)
|
|
|
|
{
|
|
|
|
if (!prog->permu[p].handle.hlsl.vert || !prog->permu[p].handle.hlsl.frag)
|
|
|
|
continue;
|
|
|
|
uniformloc = D3D9Shader_FindUniform(&prog->permu[p].handle, 1, va("cvar_%s", tmpname));
|
|
|
|
if (uniformloc != -1)
|
|
|
|
{
|
|
|
|
vec4_t v = {cvar->value, 0, 0, 0};
|
|
|
|
IDirect3DDevice9_SetVertexShader(pD3DDev9, prog->permu[p].handle.hlsl.vert);
|
|
|
|
IDirect3DDevice9_SetVertexShaderConstantF(pD3DDev9, 0, v, 1);
|
|
|
|
}
|
|
|
|
uniformloc = D3D9Shader_FindUniform(&prog->permu[p].handle, 2, va("cvar_%s", tmpname));
|
|
|
|
if (uniformloc != -1)
|
|
|
|
{
|
|
|
|
vec4_t v = {cvar->value, 0, 0, 0};
|
|
|
|
IDirect3DDevice9_SetPixelShader(pD3DDev9, prog->permu[p].handle.hlsl.frag);
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantF(pD3DDev9, 0, v, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; shader_unif_names[i].name; i++)
|
|
|
|
{
|
|
|
|
found = false;
|
|
|
|
for (p = 0; p < PERMUTATIONS; p++)
|
|
|
|
{
|
|
|
|
uniformloc = D3D9Shader_FindUniform(&prog->permu[p].handle, 0, shader_unif_names[i].name);
|
|
|
|
if (uniformloc != -1)
|
|
|
|
found = true;
|
|
|
|
prog->permu[p].parm[prog->numparams] = uniformloc;
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
prog->parm[prog->numparams].type = shader_unif_names[i].ptype;
|
|
|
|
prog->numparams++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*set texture uniforms*/
|
|
|
|
for (p = 0; p < PERMUTATIONS; p++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
uniformloc = D3D9Shader_FindUniform(&prog->permu[p].handle, 2, va("s_t%i", i));
|
|
|
|
if (uniformloc != -1)
|
|
|
|
{
|
|
|
|
int v[4] = {i};
|
|
|
|
IDirect3DDevice9_SetPixelShader(pD3DDev9, prog->permu[p].handle.hlsl.frag);
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantI(pD3DDev9, 0, v, 1);
|
2015-03-03 00:14:43 +00:00
|
|
|
|
|
|
|
if (prog->numsamplers < i+1)
|
|
|
|
prog->numsamplers = i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(defaultsamplers)/sizeof(defaultsamplers[0]); i++)
|
|
|
|
{
|
|
|
|
//figure out which ones are needed.
|
|
|
|
if (prog->defaulttextures & (1u<<i))
|
|
|
|
continue; //don't spam
|
|
|
|
uniformloc = D3D9Shader_FindUniform(&prog->permu[p].handle, 2, defaultsamplers[i]);
|
|
|
|
if (uniformloc != -1)
|
|
|
|
prog->defaulttextures |= (1u<<i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//multiple lightmaps is kinda hacky. if any are set, all must be.
|
|
|
|
if (prog->defaulttextures & ((1u<<11) | (1u<<12) | (1u<<13)))
|
|
|
|
prog->defaulttextures |=((1u<<11) | (1u<<12) | (1u<<13));
|
|
|
|
if (prog->defaulttextures & ((1u<<14) | (1u<<15) | (1u<<16)))
|
|
|
|
prog->defaulttextures |=((1u<<14) | (1u<<15) | (1u<<16));
|
|
|
|
|
|
|
|
if (prog->defaulttextures)
|
|
|
|
{
|
|
|
|
unsigned int sampnum;
|
|
|
|
/*set default texture uniforms*/
|
|
|
|
for (p = 0; p < PERMUTATIONS; p++)
|
|
|
|
{
|
|
|
|
if (!prog->permu[p].handle.glsl.handle)
|
|
|
|
continue;
|
|
|
|
sampnum = prog->numsamplers;
|
|
|
|
for (i = 0; i < sizeof(defaultsamplers)/sizeof(defaultsamplers[0]); i++)
|
|
|
|
{
|
|
|
|
if (prog->defaulttextures & (1u<<i))
|
|
|
|
{
|
|
|
|
uniformloc = D3D9Shader_FindUniform(&prog->permu[p].handle, 2, defaultsamplers[i]);
|
|
|
|
if (uniformloc != -1)
|
|
|
|
{
|
|
|
|
int v[4] = {sampnum};
|
|
|
|
IDirect3DDevice9_SetPixelShader(pD3DDev9, prog->permu[p].handle.hlsl.frag);
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantI(pD3DDev9, 0, v, 1);
|
|
|
|
}
|
|
|
|
sampnum++;
|
|
|
|
}
|
2014-03-30 08:55:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IDirect3DDevice9_SetVertexShader(pD3DDev9, NULL);
|
|
|
|
IDirect3DDevice9_SetPixelShader(pD3DDev9, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3D9Shader_DeleteProg(program_t *prog, unsigned int permu)
|
|
|
|
{
|
|
|
|
if (prog->permu[permu].handle.hlsl.vert)
|
|
|
|
{
|
|
|
|
IDirect3DVertexShader9 *vs = prog->permu[permu].handle.hlsl.vert;
|
|
|
|
prog->permu[permu].handle.hlsl.vert = NULL;
|
|
|
|
IDirect3DVertexShader9_Release(vs);
|
|
|
|
}
|
|
|
|
if (prog->permu[permu].handle.hlsl.frag)
|
|
|
|
{
|
|
|
|
IDirect3DPixelShader9 *fs = prog->permu[permu].handle.hlsl.frag;
|
|
|
|
prog->permu[permu].handle.hlsl.frag = NULL;
|
|
|
|
IDirect3DPixelShader9_Release(fs);
|
|
|
|
}
|
|
|
|
if (prog->permu[permu].handle.hlsl.ctabv)
|
|
|
|
{
|
|
|
|
LPD3DXCONSTANTTABLE vct = prog->permu[permu].handle.hlsl.ctabv;
|
|
|
|
prog->permu[permu].handle.hlsl.ctabv = NULL;
|
|
|
|
IUnknown_Release(vct);
|
|
|
|
}
|
|
|
|
if (prog->permu[permu].handle.hlsl.ctabf)
|
|
|
|
{
|
|
|
|
LPD3DXCONSTANTTABLE fct = prog->permu[permu].handle.hlsl.ctabf;
|
|
|
|
prog->permu[permu].handle.hlsl.ctabf = NULL;
|
|
|
|
IUnknown_Release(fct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3D9Shader_Init(void)
|
|
|
|
{
|
2014-10-11 19:39:45 +00:00
|
|
|
D3DCAPS9 caps;
|
|
|
|
|
2014-03-30 08:55:06 +00:00
|
|
|
dllfunction_t funcs[] =
|
|
|
|
{
|
|
|
|
{(void**)&pD3DXCompileShader, "D3DXCompileShader"},
|
|
|
|
{NULL,NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!shaderlib)
|
|
|
|
shaderlib = Sys_LoadLibrary("d3dx9_32", funcs);
|
|
|
|
if (!shaderlib)
|
|
|
|
shaderlib = Sys_LoadLibrary("d3dx9_34", funcs);
|
|
|
|
|
|
|
|
memset(&sh_config, 0, sizeof(sh_config));
|
|
|
|
sh_config.minver = 9;
|
|
|
|
sh_config.maxver = 9;
|
|
|
|
sh_config.blobpath = "hlsl/%s.blob";
|
|
|
|
sh_config.progpath = shaderlib?"hlsl/%s.hlsl":NULL;
|
|
|
|
sh_config.shadernamefmt = "%s_hlsl9";
|
|
|
|
|
|
|
|
sh_config.progs_supported = !!shaderlib;
|
|
|
|
sh_config.progs_required = false;
|
|
|
|
|
|
|
|
sh_config.pDeleteProg = D3D9Shader_DeleteProg;
|
|
|
|
sh_config.pLoadBlob = NULL;//D3D9Shader_LoadBlob;
|
|
|
|
sh_config.pCreateProgram = D3D9Shader_CreateProgram;
|
|
|
|
sh_config.pProgAutoFields = D3D9Shader_ProgAutoFields;
|
|
|
|
|
|
|
|
sh_config.tex_env_combine = 1;
|
|
|
|
sh_config.nv_tex_env_combine4 = 1;
|
|
|
|
sh_config.env_add = 1;
|
2014-10-11 19:39:45 +00:00
|
|
|
|
|
|
|
//FIXME: check caps
|
|
|
|
sh_config.texfmt[PTI_RGBX8] = true; //fixme: shouldn't support
|
|
|
|
sh_config.texfmt[PTI_RGBA8] = true; //fixme: shouldn't support
|
|
|
|
sh_config.texfmt[PTI_BGRX8] = true;
|
|
|
|
sh_config.texfmt[PTI_BGRA8] = true;
|
|
|
|
sh_config.texfmt[PTI_RGB565] = true;
|
|
|
|
sh_config.texfmt[PTI_ARGB1555] = true;
|
|
|
|
sh_config.texfmt[PTI_ARGB4444] = true;
|
|
|
|
|
|
|
|
IDirect3DDevice9_GetDeviceCaps(pD3DDev9, &caps);
|
2014-12-02 02:00:41 +00:00
|
|
|
|
|
|
|
if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
|
|
|
|
{ //this flag is a LIMITATION, not a capability.
|
|
|
|
sh_config.texture_non_power_of_two = false;
|
|
|
|
sh_config.texture_non_power_of_two_pic = !!(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL); //pic npot is supported if both flags are set.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //modern cards support npot
|
|
|
|
sh_config.texture_non_power_of_two_pic = true;
|
|
|
|
sh_config.texture_non_power_of_two = true;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:39:45 +00:00
|
|
|
sh_config.texture_maxsize = min(caps.MaxTextureWidth, caps.MaxTextureHeight);
|
2014-03-30 08:55:06 +00:00
|
|
|
}
|
2013-03-12 22:35:33 +00:00
|
|
|
#endif
|
|
|
|
|