uniform consolidation, nw

This commit is contained in:
Ryan Holtz 2013-08-29 00:56:33 +00:00
parent 8fe60e8831
commit ac119a8e15
12 changed files with 435 additions and 554 deletions

View file

@ -45,8 +45,7 @@ struct PS_INPUT
//-----------------------------------------------------------------------------
uniform float2 ScreenDims;
uniform float2 RawDims;
uniform float2 SourceDims;
uniform float YIQEnable;
@ -54,7 +53,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
float2 invDims = 1.0f / RawDims;
float2 invDims = 1.0f / SourceDims;
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y;

View file

@ -58,10 +58,8 @@ uniform float3 ConvergeX = float3(0.0f, 0.0f, 0.0f);
uniform float3 ConvergeY = float3(0.0f, 0.0f, 0.0f);
uniform float2 ScreenDims;
uniform float2 RawDims;
uniform float2 SizeRatio;
uniform float2 SourceDims;
uniform float2 SourceRect;
uniform float3 RadialConvergeX = float3(0.0f, 0.0f, 0.0f);
uniform float3 RadialConvergeY = float3(0.0f, 0.0f, 0.0f);
@ -72,8 +70,8 @@ VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
float2 invDims = 1.0f / RawDims;
float2 Ratios = SizeRatio;
float2 invDims = 1.0f / SourceDims;
float2 Ratios = SourceRect;
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y;
@ -88,10 +86,10 @@ VS_OUTPUT vs_main(VS_INPUT Input)
float2 ConvergeRed = float2(ConvergeX.x, ConvergeY.x);
float2 ConvergeGrn = float2(ConvergeX.y, ConvergeY.y);
float2 ConvergeBlu = float2(ConvergeX.z, ConvergeY.z);
float2 ScaledRatio = ((TexCoord * SizeRatio) - 0.5f);
float2 ScaledRatio = ((TexCoord * SourceRect) - 0.5f);
Output.CoordX = ((((TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + RadialConvergeX / RawDims.x) + 0.5f) * Ratios.x + ConvergeX * invDims.x;
Output.CoordY = ((((TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + RadialConvergeY / RawDims.y) + 0.5f) * Ratios.y + ConvergeY * invDims.y;
Output.CoordX = ((((TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + RadialConvergeX / SourceDims.x) + 0.5f) * Ratios.x + ConvergeX * invDims.x;
Output.CoordY = ((((TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + RadialConvergeY / SourceDims.y) + 0.5f) * Ratios.y + ConvergeY * invDims.y;
Output.TexCoord = TexCoord;
return Output;

View file

@ -92,17 +92,14 @@ uniform float PI = 3.14159265f;
uniform float PincushionAmountX = 0.1f;
uniform float PincushionAmountY = 0.1f;
uniform float WidthRatio;
uniform float HeightRatio;
uniform float2 ActiveArea;
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 Ratios = float2(WidthRatio, HeightRatio);
// -- Screen Pincushion Calculation --
float2 UnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f;
float2 UnitCoord = Input.TexCoord * ActiveArea * 2.0f - 1.0f;
float PincushionR2 = pow(length(UnitCoord),2.0f) / pow(length(Ratios), 2.0f);
float PincushionR2 = pow(length(UnitCoord),2.0f) / pow(length(ActiveArea), 2.0f);
float2 PincushionCurve = UnitCoord * PincushionAmountX * PincushionR2;
float2 BaseCoord = Input.TexCoord + PincushionCurve;

View file

@ -59,9 +59,9 @@ struct PS_INPUT
uniform float2 ScreenDims;
uniform float2 RawDims;
uniform float2 SourceDims;
uniform float2 SizeRatio;
uniform float2 SourceRect;
VS_OUTPUT vs_main(VS_INPUT Input)
{
@ -73,7 +73,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.Position.xy -= 0.5f;
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
Output.Color = Input.Color;
Output.TexCoord = Input.TexCoord + 0.5f / RawDims;
Output.TexCoord = Input.TexCoord + 0.5f / SourceDims;
return Output;
}
@ -110,7 +110,7 @@ uniform float3 Floor = float3(0.0f, 0.0f, 0.0f);
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 Ratios = 1.0f / SizeRatio;
float2 Ratios = 1.0f / SourceRect;
// -- Screen Pincushion Calculation --
float2 PinUnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f;
@ -145,12 +145,12 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 BaseTexel = tex2D(DiffuseSampler, BaseCoord);
// -- Alpha Clipping (1px border in drawd3d does not work for some reason) --
clip((BaseCoord < 1.0f / RawDims) ? -1 : 1);
clip((BaseCoord > (SizeRatio + 1.0f / RawDims)) ? -1 : 1);
clip((BaseCoord < 1.0f / SourceDims) ? -1 : 1);
clip((BaseCoord > (SourceRect + 1.0f / SourceDims)) ? -1 : 1);
// -- Scanline Simulation --
float InnerSine = ScanCoord.y * RawDims.y * ScanlineScale;
float ScanBrightMod = sin(InnerSine * PI + ScanlineOffset * RawDims.y);
float InnerSine = ScanCoord.y * SourceDims.y * ScanlineScale;
float ScanBrightMod = sin(InnerSine * PI + ScanlineOffset * SourceDims.y);
float3 ScanBrightness = lerp(1.0f, (pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f) * 0.5f, ScanlineAmount);
float3 Scanned = BaseTexel.rgb * ScanBrightness;

View file

@ -42,7 +42,6 @@ struct PS_INPUT
// Passthrough Vertex Shader
//-----------------------------------------------------------------------------
uniform float2 RawDims;
uniform float2 ScreenDims;
VS_OUTPUT vs_main(VS_INPUT Input)

View file

@ -55,27 +55,21 @@ struct PS_INPUT
// YIQ Decode Vertex Shader
//-----------------------------------------------------------------------------
uniform float ScreenWidth;
uniform float ScreenHeight;
uniform float2 RawDims;
uniform float WidthRatio;
uniform float HeightRatio;
uniform float2 ScreenDims;
uniform float2 SourceDims;
uniform float2 SourceRect;
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.x /= ScreenWidth;
Output.Position.y /= ScreenHeight;
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y;
Output.Position.x -= 0.5f;
Output.Position.y -= 0.5f;
Output.Position.xy -= 0.5f;
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
Output.Coord0.xy = Input.TexCoord;
Output.Coord0.zw = float2(1.0f / RawDims.x, 0.0f);
Output.Coord0.zw = float2(1.0f / SourceDims.x, 0.0f);
return Output;
}
@ -101,7 +95,7 @@ uniform float PI2 = 6.283185307178;
float4 ps_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / RawDims);
float4 BaseTexel = tex2D(DiffuseSampler, Input.Coord0.xy + 0.5f / SourceDims);
// YIQ convolution: N coefficients each
float4 YAccum = 0.0f;
@ -110,7 +104,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
float MaxC = 2.1183f;
float MinC = -1.1183f;
float CRange = MaxC - MinC;
float FrameWidthx4 = RawDims.x * 4.0f / WidthRatio;
float FrameWidthx4 = SourceDims.x * 4.0f / SourceRect.x;
float Fc_y1 = (CCValue - NotchHalfWidth) * ScanTime / FrameWidthx4;
float Fc_y2 = (CCValue + NotchHalfWidth) * ScanTime / FrameWidthx4;
float Fc_y3 = YFreqResponse * ScanTime / FrameWidthx4;
@ -130,14 +124,14 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 NOffset = float4(0.0f, 1.0f, 2.0f, 3.0f);
float W = PI2 * CCValue * ScanTime;
float4 CoordY = Input.Coord0.y;
float4 VPosition = CoordY * (RawDims.x * WidthRatio);
float4 VPosition = (CoordY / SourceRect.y) * (SourceDims.x * SourceRect.x);
for(float n = -41.0f; n < 42.0f; n += 4.0f)
{
float4 n4 = n + NOffset;
float4 CoordX = Input.Coord0.x + Input.Coord0.z * n4 * 0.25f;
float2 TexCoord = float2(CoordX.r, CoordY.r);
float4 C = tex2D(CompositeSampler, TexCoord + float2(0.5f, 0.0f) / RawDims) * CRange + MinC;
float4 WT = W * (CoordX * WidthRatio + VPosition + BValue) + OValue;
float4 C = tex2D(CompositeSampler, TexCoord + float2(0.5f, 0.0f) / SourceDims) * CRange + MinC;
float4 WT = W * (CoordX * SourceRect.x + VPosition + BValue) + OValue;
float4 SincKernel = 0.54f + 0.46f * cos(PI2Length * n4);
float4 SincYIn1 = Fc_y1_pi2 * n4;

View file

@ -44,19 +44,16 @@ struct PS_INPUT
// YIQ Encode Vertex Shader
//-----------------------------------------------------------------------------
uniform float ScreenWidth;
uniform float ScreenHeight;
uniform float2 ScreenDims;
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.x /= ScreenWidth;
Output.Position.y /= ScreenHeight;
Output.Position.xy /= ScreenDims;
Output.Position.y = 1.0f - Output.Position.y;
Output.Position.x -= 0.5f;
Output.Position.y -= 0.5f;
Output.Position.xy -= 0.5f;
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
Output.Color = Input.Color;
Output.TexCoord = Input.TexCoord;
@ -74,10 +71,8 @@ uniform float CCValue = 3.04183f;
uniform float PValue = 1.0f;
uniform float ScanTime = 52.6f;
uniform float2 RawDims;
uniform float WidthRatio;
uniform float HeightRatio;
uniform float2 SourceDims;
uniform float2 SourceRect;
uniform float4 YDot = float4(0.299f, 0.587f, 0.114f, 0.0f);
uniform float4 IDot = float4(0.595716f, -0.274453f, -0.321263f, 0.0f);
@ -93,7 +88,7 @@ uniform float CRange = 3.2366f;
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 InvDims = 1.0f / RawDims;
float2 InvDims = 1.0f / SourceDims;
float4 CoordX = float4(Input.TexCoord.x + OffsetX * InvDims.x);
float4 CoordY = Input.TexCoord.y;
@ -108,8 +103,8 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 Q = float4(dot(Texel0, QDot), dot(Texel1, QDot), dot(Texel2, QDot), dot(Texel3, QDot));
float4 W = PI2 * CCValue * ScanTime;
float4 VPosition = CoordY * (RawDims.x * WidthRatio);
float4 T = CoordX * WidthRatio + VPosition + BValue;
float4 VPosition = (CoordY / SourceRect.y) * (SourceDims.x * SourceRect.x);
float4 T = CoordX * SourceRect.x + VPosition + BValue;
float4 C = Y + I * cos(T * W) + Q * sin(T * W);
C = (C - MinC) / CRange;

View file

@ -42,7 +42,6 @@
// standard windows headers
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <d3d9.h>
#include <d3dx9.h>
#undef interface
@ -52,7 +51,6 @@
// MAMEOS headers
#include "d3dintf.h"
#include "strconv.h"
#include "winmain.h"
@ -63,10 +61,6 @@
typedef IDirect3D9 *(WINAPI *direct3dcreate9_ptr)(UINT SDKVersion);
typedef HRESULT (WINAPI *direct3dx9_loadeffect_ptr)(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXEFFECTPOOL pPool, LPD3DXEFFECT *ppEffect, LPD3DXBUFFER *ppCompilationErrors);
static direct3dx9_loadeffect_ptr g_load_effect = NULL;
namespace d3d
{
//============================================================
@ -106,14 +100,10 @@ INLINE void convert_present_params(const present_parameters *params, D3DPRESENT_
base *drawd3d9_init(void)
{
direct3dcreate9_ptr direct3dcreate9;
HINSTANCE dllhandle;
IDirect3D9 *d3d9;
base *d3dptr;
bool post_available = true;
// dynamically grab the create function from d3d9.dll
dllhandle = LoadLibrary(TEXT("d3d9.dll"));
HINSTANCE dllhandle = LoadLibrary(TEXT("d3d9.dll"));
if (dllhandle == NULL)
{
mame_printf_verbose("Direct3D: Unable to access d3d9.dll\n");
@ -121,7 +111,7 @@ base *drawd3d9_init(void)
}
// import the create function
direct3dcreate9 = (direct3dcreate9_ptr)GetProcAddress(dllhandle, "Direct3DCreate9");
direct3dcreate9_ptr direct3dcreate9 = (direct3dcreate9_ptr)GetProcAddress(dllhandle, "Direct3DCreate9");
if (direct3dcreate9 == NULL)
{
mame_printf_verbose("Direct3D: Unable to find Direct3DCreate9\n");
@ -131,7 +121,7 @@ base *drawd3d9_init(void)
}
// create our core direct 3d object
d3d9 = (*direct3dcreate9)(D3D_SDK_VERSION);
IDirect3D9 *d3d9 = (*direct3dcreate9)(D3D_SDK_VERSION);
if (d3d9 == NULL)
{
mame_printf_verbose("Direct3D: Error attempting to initialize Direct3D9\n");
@ -141,39 +131,30 @@ base *drawd3d9_init(void)
}
// dynamically grab the shader load function from d3dx9.dll
HINSTANCE fxhandle = LoadLibrary(TEXT("d3dx9_43.dll"));
if (fxhandle == NULL)
HINSTANCE fxhandle = NULL;
for (int idx = 99; idx >= 0; idx--) // a shameful moogle
{
post_available = false;
mame_printf_verbose("Direct3D: Warning - Unable to access d3dx9_43.dll; disabling post-effect rendering\n");
}
// import the create function
if(post_available)
{
g_load_effect = (direct3dx9_loadeffect_ptr)GetProcAddress(fxhandle, "D3DXCreateEffectFromFileW");
if (g_load_effect == NULL)
wchar_t dllbuf[13];
wsprintf(dllbuf, TEXT("d3dx9_%d.dll"), idx);
fxhandle = LoadLibrary(dllbuf);
if (fxhandle != NULL)
{
printf("Direct3D: Unable to find D3DXCreateEffectFromFileW\n");
FreeLibrary(dllhandle);
fxhandle = NULL;
dllhandle = NULL;
return NULL;
break;
}
}
else
if (fxhandle == NULL)
{
g_load_effect = NULL;
mame_printf_verbose("Direct3D: Warning - Unable find any D3D9 DLLs; disabling post-effect rendering\n");
post_available = false;
mame_printf_verbose("Direct3D: Warning - Unable to get a handle to D3DXCreateEffectFromFileW; disabling post-effect rendering\n");
}
// allocate an object to hold our data
d3dptr = global_alloc(base);
base *d3dptr = global_alloc(base);
d3dptr->version = 9;
d3dptr->d3dobj = d3d9;
d3dptr->dllhandle = dllhandle;
d3dptr->post_fx_available = post_available;
d3dptr->libhandle = fxhandle;
set_interfaces(d3dptr);
mame_printf_verbose("Direct3D: Using Direct3D 9\n");
@ -336,29 +317,6 @@ static HRESULT device_create_offscreen_plain_surface(device *dev, UINT width, UI
return IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format, pool, (IDirect3DSurface9 **)surface, NULL);
}
static HRESULT device_create_effect(device *dev, const WCHAR *name, effect **effect)
{
IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
LPD3DXBUFFER buffer_errors = NULL;
HRESULT hr = (*g_load_effect)(device, name, NULL, NULL, 0, NULL, (ID3DXEffect**)effect, &buffer_errors);
if(FAILED(hr))
{
if(buffer_errors != NULL)
{
LPVOID compile_errors = buffer_errors->GetBufferPointer();
printf("Unable to compile shader %s:\n%s\n", (const char*)name, (const char*)compile_errors);
}
else
{
printf("Unable to compile shader (unspecified reason)\n");
}
}
return hr;
}
static HRESULT device_create_texture(device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, texture **texture)
{
IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
@ -546,7 +504,6 @@ static const device_interface d3d9_device_interface =
device_begin_scene,
device_clear,
device_create_offscreen_plain_surface,
device_create_effect,
device_create_texture,
device_create_vertex_buffer,
device_create_render_target,
@ -680,237 +637,6 @@ static const vertex_buffer_interface d3d9_vertex_buffer_interface =
};
//============================================================
// Direct3DEffect interfaces
//============================================================
uniform::uniform(effect *shader, const char *name, uniform_type type)
{
m_shader = shader;
m_type = type;
m_next = NULL;
m_prev = NULL;
m_handle = m_shader->get_parameter(NULL, name);
m_ival = 0;
memset(m_vec, 0, sizeof(float) * 4);
m_mval = NULL;
m_texture = NULL;
switch (type)
{
case UT_INT:
case UT_FLOAT:
case UT_MATRIX:
case UT_SAMPLER:
m_count = 1;
break;
case UT_VEC2:
m_count = 2;
break;
case UT_VEC3:
m_count = 3;
break;
case UT_VEC4:
m_count = 4;
break;
default:
m_count = 1;
break;
}
}
void uniform::set_next(uniform *next)
{
m_next->set_prev(next);
next->set_next(m_next);
next->set_prev(this);
m_next = next;
}
void uniform::set_prev(uniform *prev)
{
m_prev->set_next(prev);
prev->set_prev(m_prev);
prev->set_next(this);
m_prev = prev;
}
void uniform::set(float x, float y, float z, float w)
{
m_vec[0] = x;
m_vec[1] = y;
m_vec[2] = z;
m_vec[3] = w;
}
void uniform::set(float x, float y, float z)
{
m_vec[0] = x;
m_vec[1] = y;
m_vec[2] = z;
}
void uniform::set(float x, float y)
{
m_vec[0] = x;
m_vec[1] = y;
}
void uniform::set(float x)
{
m_vec[0] = x;
}
void uniform::set(int x)
{
m_ival = x;
}
void uniform::set(matrix *mat)
{
m_mval = mat;
}
void uniform::set(texture *tex)
{
m_texture = tex;
}
void uniform::upload()
{
switch(m_type)
{
case UT_INT:
m_shader->set_int(m_handle, m_ival);
break;
case UT_FLOAT:
m_shader->set_float(m_handle, m_vec[0]);
break;
case UT_VEC2:
case UT_VEC3:
case UT_VEC4:
m_shader->set_vector(m_handle, m_count, m_vec);
break;
case UT_MATRIX:
m_shader->set_matrix(m_handle, m_mval);
break;
case UT_SAMPLER:
m_shader->set_texture(m_handle, m_texture);
break;
}
}
effect::effect(device *dev, const char *name, const char *path)
{
IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
LPD3DXBUFFER buffer_errors = NULL;
m_effect = NULL;
m_valid = false;
char name_cstr[1024];
sprintf(name_cstr, "%s\\%s", path, name);
TCHAR *effect_name = tstring_from_utf8(name_cstr);
HRESULT hr = (*g_load_effect)(device, effect_name, NULL, NULL, 0, NULL, &m_effect, &buffer_errors);
if(FAILED(hr))
{
if(buffer_errors != NULL)
{
LPVOID compile_errors = buffer_errors->GetBufferPointer();
printf("Unable to compile shader: %s\n", (const char*)compile_errors);
}
else
{
printf("Unable to compile shader (unspecified reason)\n");
}
}
else
{
m_valid = true;
}
osd_free(effect_name);
}
effect::~effect()
{
m_effect->Release();
m_effect = NULL;
}
void effect::begin(UINT *passes, DWORD flags)
{
m_effect->Begin(passes, flags);
}
void effect::end()
{
m_effect->End();
}
void effect::begin_pass(UINT pass)
{
m_effect->BeginPass(pass);
}
void effect::end_pass()
{
m_effect->EndPass();
}
void effect::set_technique(const char *name)
{
m_effect->SetTechnique(name);
}
void effect::set_vector(D3DXHANDLE param, int count, float *vector)
{
static D3DXVECTOR4 out_vector;
if (count > 0)
out_vector.x = vector[0];
if (count > 1)
out_vector.y = vector[1];
if (count > 2)
out_vector.z = vector[2];
if (count > 3)
out_vector.w = vector[3];
m_effect->SetVector(param, &out_vector);
}
void effect::set_float(D3DXHANDLE param, float value)
{
m_effect->SetFloat(param, value);
}
void effect::set_int(D3DXHANDLE param, int value)
{
m_effect->SetInt(param, value);
}
void effect::set_matrix(D3DXHANDLE param, matrix *matrix)
{
m_effect->SetMatrix(param, (D3DXMATRIX*)matrix);
}
void effect::set_texture(D3DXHANDLE param, texture *tex)
{
m_effect->SetTexture(param, (IDirect3DTexture9*)tex);
}
D3DXHANDLE effect::get_parameter(D3DXHANDLE param, const char *name)
{
return m_effect->GetParameterByName(param, name);
}
ULONG effect::release()
{
return m_effect->Release();
}
//============================================================
// set_interfaces
//============================================================

View file

@ -50,6 +50,7 @@
// standard windows headers
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <mmsystem.h>
#include <d3d9.h>
#include <d3dx9.h>
@ -74,6 +75,7 @@
#include "config.h"
#include "d3dcomm.h"
#include "drawd3d.h"
#include "strconv.h"
@ -189,6 +191,12 @@ hlsl_options shaders::s_hlsl_presets[4] =
static void get_vector(const char *data, int count, float *out, int report_error);
//============================================================
// TYPE DEFINITIONS
//============================================================
typedef HRESULT (WINAPI *direct3dx9_loadeffect_ptr)(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXEFFECTPOOL pPool, LPD3DXEFFECT *ppEffect, LPD3DXBUFFER *ppCompilationErrors);
static direct3dx9_loadeffect_ptr g_load_effect = NULL;
//============================================================
// shader manager constructor
@ -717,7 +725,6 @@ void shaders::set_texture(texture_info *texture)
yiq_encode_effect->set_texture("Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
else
color_effect->set_texture("Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
pincushion_effect->set_texture("Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
}
@ -730,6 +737,14 @@ void shaders::init(base *d3dintf, win_window_info *window)
if (!d3dintf->post_fx_available)
return;
g_load_effect = (direct3dx9_loadeffect_ptr)GetProcAddress(d3dintf->libhandle, "D3DXCreateEffectFromFileW");
if (g_load_effect == NULL)
{
printf("Direct3D: Unable to find D3DXCreateEffectFromFileW\n");
d3dintf->post_fx_available = false;
return;
}
this->d3dintf = d3dintf;
this->window = window;
@ -970,7 +985,6 @@ int shaders::create_resources(bool reset)
default_effect = new effect(d3d->get_device(), "primary.fx", fx_dir);
post_effect = new effect(d3d->get_device(), "post.fx", fx_dir);
prescale_effect = new effect(d3d->get_device(), "prescale.fx", fx_dir);
pincushion_effect = new effect(d3d->get_device(), "pincushion.fx", fx_dir);
phosphor_effect = new effect(d3d->get_device(), "phosphor.fx", fx_dir);
focus_effect = new effect(d3d->get_device(), "focus.fx", fx_dir);
deconverge_effect = new effect(d3d->get_device(), "deconverge.fx", fx_dir);
@ -984,7 +998,6 @@ int shaders::create_resources(bool reset)
if (!default_effect->is_valid()) return 1;
if (!post_effect->is_valid()) return 1;
if (!prescale_effect->is_valid()) return 1;
if (!pincushion_effect->is_valid()) return 1;
if (!phosphor_effect->is_valid()) return 1;
if (!focus_effect->is_valid()) return 1;
if (!deconverge_effect->is_valid()) return 1;
@ -1016,7 +1029,6 @@ void shaders::begin_draw()
default_effect->set_technique("TestTechnique");
post_effect->set_technique("ScanMaskTechnique");
pincushion_effect->set_technique("TestTechnique");
phosphor_effect->set_technique("TestTechnique");
focus_effect->set_technique("TestTechnique");
deconverge_effect->set_technique("DeconvergeTechnique");
@ -1104,8 +1116,6 @@ void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYP
vec2f screendims = d3d->get_dims();
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
curr_effect->set_float("ScreenWidth", (float)d3d->get_width());
curr_effect->set_float("ScreenHeight", (float)d3d->get_height());
curr_effect->set_float("PostPass", 1.0f);
curr_effect->set_float("PincushionAmount", options->pincushion);
curr_effect->set_float("Brighten", 1.0f);
@ -1193,11 +1203,7 @@ void shaders::init_effect_info(poly_info *poly)
shadow_dims.c.y = 1.0f;
}
if(PRIMFLAG_GET_TEXSHADE(d3d->get_last_texture_flags()))
{
curr_effect = pincushion_effect;
}
else if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
{
// Plug in all of the shader settings we're going to need
// This is extremely slow, but we're not rendering models here,
@ -1209,8 +1215,8 @@ void shaders::init_effect_info(poly_info *poly)
if(options->params_dirty)
{
vec2f delta = texture->get_uvstop() - texture->get_uvstart();
curr_effect->set_vector("RawDims", 2, &texture->get_rawdims().c.x);
curr_effect->set_vector("SizeRatio", 2, &delta.c.x);
curr_effect->set_vector("SourceDims", 2, &texture->get_rawdims().c.x);
curr_effect->set_vector("SourceRect", 2, &delta.c.x);
vec2f screendims = d3d->get_dims();
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
curr_effect->set_vector("Floor", 3, options->floor);
@ -1299,11 +1305,13 @@ cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int hei
return curr;
}
void shaders::ntsc_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta)
void shaders::ntsc_pass(render_target *rt, texture_info *texture, vec2f &sourcedims, vec2f &activearea)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
vec2f screendims = d3d->get_dims();
if(options->yiq_enable)
{
// Convert our signal into YIQ
@ -1311,11 +1319,9 @@ void shaders::ntsc_pass(render_target *rt, texture_info *texture, vec2f &texsize
if(options->params_dirty)
{
curr_effect->set_vector("RawDims", 2, &texsize.c.x);
curr_effect->set_float("WidthRatio", 1.0f / delta.c.x);
curr_effect->set_float("HeightRatio", 1.0f / delta.c.y);
curr_effect->set_float("ScreenWidth", d3d->get_width());
curr_effect->set_float("ScreenHeight", d3d->get_height());
curr_effect->set_vector("SourceDims", 2, &sourcedims.c.x);
curr_effect->set_vector("SourceRect", 2, &activearea.c.x);
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
curr_effect->set_float("CCValue", options->yiq_cc);
curr_effect->set_float("AValue", options->yiq_a);
@ -1354,11 +1360,9 @@ void shaders::ntsc_pass(render_target *rt, texture_info *texture, vec2f &texsize
curr_effect->set_texture("Diffuse", texture->get_finaltex());
if(true)//options->params_dirty)
{
curr_effect->set_vector("RawDims", 2, &texsize.c.x);
curr_effect->set_float("WidthRatio", 1.0f / delta.c.x);
curr_effect->set_float("HeightRatio", 1.0f / delta.c.y);
curr_effect->set_float("ScreenWidth", d3d->get_width());
curr_effect->set_float("ScreenHeight", d3d->get_height());
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
curr_effect->set_vector("SourceDims", 2, &sourcedims.c.x);
curr_effect->set_vector("SourceRect", 2, &activearea.c.x);
curr_effect->set_float("CCValue", options->yiq_cc);
curr_effect->set_float("AValue", options->yiq_a);
@ -1397,7 +1401,7 @@ void shaders::ntsc_pass(render_target *rt, texture_info *texture, vec2f &texsize
}
}
void shaders::color_convolution_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims)
void shaders::color_convolution_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1407,7 +1411,7 @@ void shaders::color_convolution_pass(render_target *rt, texture_info *texture, v
// Render the initial color-convolution pass
if(options->params_dirty)
{
curr_effect->set_vector("RawDims", 2, &rawdims.c.x);
curr_effect->set_vector("SourceDims", 2, &sourcedims.c.x);
vec2f screendims = d3d->get_dims();
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
@ -1440,7 +1444,7 @@ void shaders::color_convolution_pass(render_target *rt, texture_info *texture, v
curr_effect->end();
}
void shaders::prescale_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims)
void shaders::prescale_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1452,7 +1456,7 @@ void shaders::prescale_pass(render_target *rt, texture_info *texture, vec2f &tex
{
vec2f screendims = d3d->get_dims();
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
curr_effect->set_vector("RawDims", 2, &rawdims.c.x);
curr_effect->set_vector("SourceDims", 2, &sourcedims.c.x);
}
curr_effect->begin(&num_passes, 0);
@ -1474,7 +1478,7 @@ void shaders::prescale_pass(render_target *rt, texture_info *texture, vec2f &tex
curr_effect->end();
}
void shaders::deconverge_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims)
void shaders::deconverge_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1486,8 +1490,8 @@ void shaders::deconverge_pass(render_target *rt, texture_info *texture, vec2f &t
{
vec2f screendims = d3d->get_dims();
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
curr_effect->set_vector("RawDims", 2, &rawdims.c.x);
curr_effect->set_vector("SizeRatio", 2, &delta.c.x);
curr_effect->set_vector("SourceDims", 2, &sourcedims.c.x);
curr_effect->set_vector("SourceRect", 2, &delta.c.x);
curr_effect->set_vector("ConvergeX", 3, options->converge_x);
curr_effect->set_vector("ConvergeY", 3, options->converge_y);
curr_effect->set_vector("RadialConvergeX", 3, options->radial_converge_x);
@ -1513,7 +1517,7 @@ void shaders::deconverge_pass(render_target *rt, texture_info *texture, vec2f &t
curr_effect->end();
}
void shaders::defocus_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims)
void shaders::defocus_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1569,7 +1573,7 @@ void shaders::defocus_pass(render_target *rt, texture_info *texture, vec2f &texs
curr_effect->end();
}
void shaders::phosphor_pass(render_target *rt, cache_target *ct, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, bool focus_enable)
void shaders::phosphor_pass(render_target *rt, cache_target *ct, texture_info *texture, vec2f &texsize, vec2f &delta, bool focus_enable)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1633,7 +1637,7 @@ void shaders::phosphor_pass(render_target *rt, cache_target *ct, texture_info *t
curr_effect->end();
}
void shaders::avi_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, poly_info *poly, int vertnum)
void shaders::avi_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1689,7 +1693,7 @@ void shaders::avi_post_pass(render_target *rt, texture_info *texture, vec2f &tex
}
}
void shaders::screen_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, poly_info *poly, int vertnum)
void shaders::screen_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1697,8 +1701,8 @@ void shaders::screen_post_pass(render_target *rt, texture_info *texture, vec2f &
curr_effect = post_effect;
curr_effect->set_texture("Diffuse", rt->render_texture[0]);
curr_effect->set_vector("RawDims", 2, &rawdims.c.x);
curr_effect->set_vector("SizeRatio", 2, &delta.c.x);
curr_effect->set_vector("SourceDims", 2, &sourcedims.c.x);
curr_effect->set_vector("SourceRect", 2, &delta.c.x);
vec2f screendims = d3d->get_dims();
curr_effect->set_vector("ScreenDims", 2, &screendims.c.x);
@ -1725,7 +1729,7 @@ void shaders::screen_post_pass(render_target *rt, texture_info *texture, vec2f &
d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(poly->get_texture()->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
}
void shaders::raster_bloom_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, poly_info *poly, int vertnum)
void shaders::raster_bloom_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum)
{
renderer *d3d = (renderer *)window->drawdata;
UINT num_passes = 0;
@ -1779,12 +1783,9 @@ void shaders::raster_bloom_pass(render_target *rt, texture_info *texture, vec2f
curr_effect = bloom_effect;
curr_effect->set_vector("TargetSize", 2, &screendims.c.x);
float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight,
options->bloom_level2_weight, options->bloom_level3_weight };
float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight,
options->bloom_level6_weight, options->bloom_level7_weight };
float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight,
options->bloom_level10_weight };
float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight, options->bloom_level2_weight, options->bloom_level3_weight };
float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight, options->bloom_level6_weight, options->bloom_level7_weight };
float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight, options->bloom_level10_weight };
curr_effect->set_vector("Level0123Weight", 4, weight0123);
curr_effect->set_vector("Level4567Weight", 4, weight4567);
curr_effect->set_vector("Level89AWeight", 3, weight89A);
@ -1849,25 +1850,26 @@ void shaders::render_quad(poly_info *poly, int vertnum)
}
cache_target *ct = find_cache_target(rt->screen_index, texture->get_texinfo().width, texture->get_texinfo().height);
vec2f& rawdims = texture->get_rawdims();
vec2f& sourcedims = texture->get_rawdims();
vec2f delta = texture->get_uvstop() - texture->get_uvstart();
vec2f activearea = vec2f(1.0f / delta.c.x, 1.0f / delta.c.y);
vec2f texsize(rt->width, rt->height);
float defocus_x = options->defocus[0];
float defocus_y = options->defocus[1];
bool focus_enable = defocus_x != 0.0f || defocus_y != 0.0f;
ntsc_pass(rt, texture, texsize, delta);
color_convolution_pass(rt, texture, texsize, delta, rawdims);
prescale_pass(rt, texture, texsize, delta, rawdims);
deconverge_pass(rt, texture, texsize, delta, rawdims);
ntsc_pass(rt, texture, sourcedims, activearea);
color_convolution_pass(rt, texture, texsize, delta, sourcedims);
prescale_pass(rt, texture, texsize, delta, sourcedims);
deconverge_pass(rt, texture, texsize, delta, sourcedims);
if (focus_enable)
{
defocus_pass(rt, texture, texsize, delta, rawdims);
defocus_pass(rt, texture, texsize, delta);
}
phosphor_pass(rt, ct, texture, texsize, delta, rawdims, focus_enable);
avi_post_pass(rt, texture, texsize, delta, rawdims, poly, vertnum);
screen_post_pass(rt, texture, texsize, delta, rawdims, poly, vertnum);
raster_bloom_pass(rt, texture, texsize, delta, rawdims, poly, vertnum);
phosphor_pass(rt, ct, texture, texsize, delta, focus_enable);
avi_post_pass(rt, texture, texsize, delta, poly, vertnum);
screen_post_pass(rt, texture, texsize, delta, sourcedims, poly, vertnum);
raster_bloom_pass(rt, texture, texsize, delta, poly, vertnum);
texture->increment_frame_count();
texture->mask_frame_count(options->yiq_phase_count);
@ -2135,7 +2137,6 @@ bool shaders::register_prescaled_texture(texture_info *texture)
//============================================================
bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
{
printf("Adding cache target\n");
cache_target* target = (cache_target*)global_alloc_clear(cache_target);
if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
@ -2392,11 +2393,6 @@ void shaders::delete_resources(bool reset)
delete prescale_effect;
prescale_effect = NULL;
}
if (pincushion_effect != NULL)
{
delete pincushion_effect;
pincushion_effect = NULL;
}
if (phosphor_effect != NULL)
{
delete phosphor_effect;
@ -3043,6 +3039,228 @@ slider_state *shaders::init_slider_list()
return listhead;
}
//============================================================
// uniform functions
//============================================================
uniform::uniform(effect *shader, const char *name, uniform_type type)
{
m_shader = shader;
m_type = type;
m_next = NULL;
m_handle = m_shader->get_parameter(NULL, name);
m_ival = 0;
memset(m_vec, 0, sizeof(float) * 4);
m_mval = NULL;
m_texture = NULL;
switch (type)
{
case UT_INT:
case UT_FLOAT:
case UT_MATRIX:
case UT_SAMPLER:
m_count = 1;
break;
case UT_VEC2:
m_count = 2;
break;
case UT_VEC3:
m_count = 3;
break;
case UT_VEC4:
m_count = 4;
break;
default:
m_count = 1;
break;
}
}
void uniform::set_next(uniform *next)
{
next->set_next(m_next);
m_next = next;
}
void uniform::set(float x, float y, float z, float w)
{
m_vec[0] = x;
m_vec[1] = y;
m_vec[2] = z;
m_vec[3] = w;
}
void uniform::set(float x, float y, float z)
{
m_vec[0] = x;
m_vec[1] = y;
m_vec[2] = z;
}
void uniform::set(float x, float y)
{
m_vec[0] = x;
m_vec[1] = y;
}
void uniform::set(float x)
{
m_vec[0] = x;
}
void uniform::set(int x)
{
m_ival = x;
}
void uniform::set(matrix *mat)
{
m_mval = mat;
}
void uniform::set(texture *tex)
{
m_texture = tex;
}
void uniform::upload()
{
switch(m_type)
{
case UT_INT:
m_shader->set_int(m_handle, m_ival);
break;
case UT_FLOAT:
m_shader->set_float(m_handle, m_vec[0]);
break;
case UT_VEC2:
case UT_VEC3:
case UT_VEC4:
m_shader->set_vector(m_handle, m_count, m_vec);
break;
case UT_MATRIX:
m_shader->set_matrix(m_handle, m_mval);
break;
case UT_SAMPLER:
m_shader->set_texture(m_handle, m_texture);
break;
}
}
//============================================================
// effect functions
//============================================================
effect::effect(device *dev, const char *name, const char *path)
{
IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
LPD3DXBUFFER buffer_errors = NULL;
m_uniforms = NULL;
m_effect = NULL;
m_valid = false;
char name_cstr[1024];
sprintf(name_cstr, "%s\\%s", path, name);
TCHAR *effect_name = tstring_from_utf8(name_cstr);
HRESULT hr = (*g_load_effect)(device, effect_name, NULL, NULL, 0, NULL, &m_effect, &buffer_errors);
if(FAILED(hr))
{
if(buffer_errors != NULL)
{
LPVOID compile_errors = buffer_errors->GetBufferPointer();
printf("Unable to compile shader: %s\n", (const char*)compile_errors); fflush(stdout);
}
else
{
printf("Unable to compile shader (unspecified reason)\n"); fflush(stdout);
}
}
else
{
m_valid = true;
}
osd_free(effect_name);
}
effect::~effect()
{
m_effect->Release();
m_effect = NULL;
}
void effect::begin(UINT *passes, DWORD flags)
{
m_effect->Begin(passes, flags);
}
void effect::end()
{
m_effect->End();
}
void effect::begin_pass(UINT pass)
{
m_effect->BeginPass(pass);
}
void effect::end_pass()
{
m_effect->EndPass();
}
void effect::set_technique(const char *name)
{
m_effect->SetTechnique(name);
}
void effect::set_vector(D3DXHANDLE param, int count, float *vector)
{
static D3DXVECTOR4 out_vector;
if (count > 0)
out_vector.x = vector[0];
if (count > 1)
out_vector.y = vector[1];
if (count > 2)
out_vector.z = vector[2];
if (count > 3)
out_vector.w = vector[3];
m_effect->SetVector(param, &out_vector);
}
void effect::set_float(D3DXHANDLE param, float value)
{
m_effect->SetFloat(param, value);
}
void effect::set_int(D3DXHANDLE param, int value)
{
m_effect->SetInt(param, value);
}
void effect::set_matrix(D3DXHANDLE param, matrix *matrix)
{
m_effect->SetMatrix(param, (D3DXMATRIX*)matrix);
}
void effect::set_texture(D3DXHANDLE param, texture *tex)
{
m_effect->SetTexture(param, (IDirect3DTexture9*)tex);
}
D3DXHANDLE effect::get_parameter(D3DXHANDLE param, const char *name)
{
return m_effect->GetParameterByName(param, name);
}
ULONG effect::release()
{
return m_effect->Release();
}
};
//============================================================

View file

@ -55,6 +55,101 @@
namespace d3d
{
class effect;
class uniform
{
public:
typedef enum
{
UT_VEC4,
UT_VEC3,
UT_VEC2,
UT_FLOAT,
UT_INT,
UT_MATRIX,
UT_SAMPLER,
} uniform_type;
typedef enum
{
CU_SCREEN_DIMS,
CU_SOURCE_DIMS,
CU_SOURCE_RECT,
CU_NTSC_CCFREQ,
CU_NTSC_A,
CU_NTSC_B,
CU_NTSC_O,
CU_NTSC_P,
CU_NTSC_NOTCH,
CU_NTSC_YFREQ,
CU_NTSC_IFREQ,
CU_NTSC_QFREQ,
CU_NTSC_HTIME,
} common_uniform;
uniform(effect *shader, const char *name, uniform_type type);
void set_next(uniform *next);
void set(float x, float y, float z, float w);
void set(float x, float y, float z);
void set(float x, float y);
void set(float x);
void set(int x);
void set(matrix *mat);
void set(texture *tex);
void upload();
protected:
uniform *m_next;
float m_vec[4];
int m_ival;
matrix *m_mval;
texture *m_texture;
int m_count;
uniform_type m_type;
effect *m_shader;
D3DXHANDLE m_handle;
};
class effect
{
public:
effect(device *dev, const char *name, const char *path);
~effect();
void begin(UINT *passes, DWORD flags);
void begin_pass(UINT pass);
void end();
void end_pass();
void set_technique(const char *name);
void set_vector(D3DXHANDLE param, int count, float *vector);
void set_float(D3DXHANDLE param, float value);
void set_int(D3DXHANDLE param, int value);
void set_matrix(D3DXHANDLE param, matrix *matrix);
void set_texture(D3DXHANDLE param, texture *tex);
D3DXHANDLE get_parameter(D3DXHANDLE param, const char *name);
ULONG release();
bool is_valid() { return m_valid; }
private:
uniform *m_uniforms;
ID3DXEffect *m_effect;
bool m_valid;
};
class render_target;
class cache_target;
class renderer;
@ -207,14 +302,14 @@ private:
// Shader passes
void ntsc_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta);
void color_convolution_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims);
void prescale_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims);
void deconverge_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims);
void defocus_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims);
void phosphor_pass(render_target *rt, cache_target *ct, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, bool focus_enable);
void screen_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, poly_info *poly, int vertnum);
void avi_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, poly_info *poly, int vertnum);
void raster_bloom_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &rawdims, poly_info *poly, int vertnum);
void color_convolution_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims);
void prescale_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims);
void deconverge_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims);
void defocus_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta);
void phosphor_pass(render_target *rt, cache_target *ct, texture_info *texture, vec2f &texsize, vec2f &delta, bool focus_enable);
void screen_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum);
void avi_post_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum);
void raster_bloom_pass(render_target *rt, texture_info *texture, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum);
base * d3dintf; // D3D interface
win_window_info * window; // D3D window info
@ -271,7 +366,6 @@ private:
effect * default_effect; // pointer to the primary-effect object
effect * prescale_effect; // pointer to the prescale-effect object
effect * post_effect; // pointer to the post-effect object
effect * pincushion_effect; // pointer to the pincushion-effect object
effect * focus_effect; // pointer to the focus-effect object
effect * phosphor_effect; // pointer to the phosphor-effect object
effect * deconverge_effect; // pointer to the deconvergence-effect object

View file

@ -81,83 +81,6 @@ class effect;
typedef D3DXVECTOR4 vector;
typedef D3DMATRIX matrix;
class uniform
{
public:
typedef enum
{
UT_VEC4,
UT_VEC3,
UT_VEC2,
UT_FLOAT,
UT_INT,
UT_MATRIX,
UT_SAMPLER,
} uniform_type;
uniform(effect *shader, const char *name, uniform_type type);
void set_next(uniform *next);
void set_prev(uniform *prev);
void set(float x, float y, float z, float w);
void set(float x, float y, float z);
void set(float x, float y);
void set(float x);
void set(int x);
void set(matrix *mat);
void set(texture *tex);
void upload();
protected:
uniform *m_next;
uniform *m_prev;
float m_vec[4];
int m_ival;
matrix *m_mval;
texture *m_texture;
int m_count;
uniform_type m_type;
effect *m_shader;
D3DXHANDLE m_handle;
};
class effect
{
public:
effect(device *dev, const char *name, const char *path);
~effect();
void begin(UINT *passes, DWORD flags);
void begin_pass(UINT pass);
void end();
void end_pass();
void set_technique(const char *name);
void set_vector(D3DXHANDLE param, int count, float *vector);
void set_float(D3DXHANDLE param, float value);
void set_int(D3DXHANDLE param, int value);
void set_matrix(D3DXHANDLE param, matrix *matrix);
void set_texture(D3DXHANDLE param, texture *tex);
D3DXHANDLE get_parameter(D3DXHANDLE param, const char *name);
ULONG release();
bool is_valid() { return m_valid; }
private:
bool m_valid;
ID3DXEffect *m_effect;
};
//============================================================
// Abstracted presentation parameters
//============================================================
@ -251,7 +174,6 @@ struct device_interface
HRESULT (*begin_scene)(device *dev);
HRESULT (*clear)(device *dev, DWORD count, const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil);
HRESULT (*create_offscreen_plain_surface)(device *dev, UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, surface **surface);
HRESULT (*create_effect)(device *dev, const WCHAR *name, effect **effect);
HRESULT (*create_texture)(device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, texture **texture);
HRESULT (*create_vertex_buffer)(device *dev, UINT length, DWORD usage, DWORD fvf, D3DPOOL pool, vertex_buffer **buf);
HRESULT (*create_render_target)(device *dev, UINT width, UINT height, D3DFORMAT format, surface **surface);
@ -323,6 +245,7 @@ struct base
void * d3dobj;
HINSTANCE dllhandle;
bool post_fx_available;
HINSTANCE libhandle;
// interface pointers
interface d3d;

View file

@ -646,67 +646,6 @@ texture_info *texture_manager::find_texinfo(const render_texinfo *texinfo, UINT3
}
}
// Nothing found
/*int checkidx = 0;
for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
{
printf("Checking texture index %d\n", checkidx);
UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1;
UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1;
UINT32 prim_screen = (UINT32)texinfo->osddata >> 1;
UINT32 prim_page = (UINT32)texinfo->osddata & 1;
if (test_screen != prim_screen || test_page != prim_page)
{
printf("No screen/page match: %d vs. %d, %d vs. %d\n", test_screen, prim_screen, test_page, prim_page);
continue;
}
if (texture->get_hash() == hash &&
texture->get_texinfo().base == texinfo->base &&
texture->get_texinfo().width == texinfo->width &&
texture->get_texinfo().height == texinfo->height &&
((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
{
// Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
{
if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
{
return texture;
}
}
else
{
return texture;
}
}
if (texture->get_hash() != hash)
{
printf("No hash match: %d vs. %d\n", texture->get_hash(), hash);
}
if (texture->get_texinfo().base != texinfo->base)
{
printf("No base match\n");
}
if (texture->get_texinfo().width != texinfo->width)
{
printf("No width match: %d vs. %d\n", texture->get_texinfo().width, texinfo->width);
}
if (texture->get_texinfo().height != texinfo->height)
{
printf("No height match: %d vs. %d\n", texture->get_texinfo().height, texinfo->height);
}
if (((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) != 0)
{
printf("No flag match: %08x & %08x = %08x\n", texture->get_flags(), flags, ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)));
}
printf("\n");
checkidx++;
}
printf("\n\n\n\n");*/
// Nothing found, check if we need to unregister something with HLSL
if (m_renderer->get_shaders()->enabled())
{
@ -1897,7 +1836,6 @@ vertex *renderer::mesh_alloc(int numverts)
// if we're going to overflow, flush
if (m_lockedbuf != NULL && m_numverts + numverts >= VERTEX_BUFFER_SIZE)
{
printf("request for %d verts\n", numverts);
primitive_flush_pending();
if(m_shaders->enabled())