Previous 15994 Revisions Next

r11560 Monday 16th May, 2011 at 18:48:39 UTC by MooglyGuy
Implemented experimental HLSL post-processing support on Direct3D 9 targets. [Ryan Holtz, Bat Country Entertainment]
- You will need the latest DirectX redistributable from Microsoft's website.
- You will need a new set of headers found here, including the caveats within: http://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=69633
- 5-pass post-processing: Upscale, Post-Process, Store Last Frame, Defocus 1, Defocus 2
- Many tunable effects including: Scanlines, defocus, linear deconvergence, radial deconvergence, pincushion, RGB colorspace convolution, YIQ colorspace convolution, saturation, simulated dot crawl, simulated chroma subsampling, aperture masking, and more.
- Requires a GPU that supports Shader Model 3.0 to be enabled and a powerful GPU, the entire pipeline consists of approximately 30 texel fetches and approximately 230 arthimetic ops.
- Will supersample the framebuffer up to 9x in both X and Y, but this requires an enormously powerful GPU that has not been invented; users with Radeon 5000-class cards should limit themselves to 3x, Radeon 4000 to 1.5x.
- The default configuration will NOT appear to do anything; it requires tuning to the user's liking.
- Should nicely fall back in all cases except missing shaders, and it might fall back correctly in that case as well. Report any anomalies.
- For obvious reasons, the Direct3D8 renderer cannot support this.

Artwork:
aperture.png: Based on Aaron Giles's aperture_4x6 mask but with more prominent notching to bring out the "brick" pattern that was used on many period colour monitors, including the Commodore 1702 - which was, admittedly, not an arcade monitor, but it looks believable and can be changed. It currently requires considerable fine-tuning to change masks but is doable.
white.png: Default 8x8 255,255,255,255 texture.

Initial shader import:
Focus: 8-sample blur that averages 7 samples around a center sample.
Phosphor: Not currently used, treated as a pass-through by drawd3d.c, but could be used to implement additional convolutions in a second pass.
Pincushion: Used (when commented in in drawd3d.c) to pincushion an entire full-screen texture but not otherwise apply any convolutions.
Post: The meat and potatoes. It does scanlines, it does aperture masking, it does dot crawl, it does chroma subsampling, it does YIQ colorspace convolution, it does RGB colorspace convolution, it does pincushioning, it walks, it talks, it does the dishes.
Primary: Simple passthrough for UI and artwork.
[artwork]aperture.png* white.png*
[hlsl]focus.fx* phosphor.fx* pincushion.fx* post.fx* primary.fx*
[src/emu]render.c render.h
[src/osd/windows]d3d8intf.c d3d9intf.c d3dintf.h drawd3d.c winmain.c winmain.h winprefix.h

hlsl/primary.fx
r0r11560
1//-----------------------------------------------------------------------------
2// Effect File Variables
3//-----------------------------------------------------------------------------
4
5texture Diffuse;
6
7sampler DiffuseSampler = sampler_state
8{
9   Texture   = <Diffuse>;
10   MipFilter = LINEAR;
11   MinFilter = LINEAR;
12   MagFilter = LINEAR;
13   AddressU = CLAMP;
14   AddressV = CLAMP;
15   AddressW = CLAMP;
16};
17
18//-----------------------------------------------------------------------------
19// Vertex Definitions
20//-----------------------------------------------------------------------------
21
22struct VS_OUTPUT
23{
24   float4 Position : POSITION;
25   float4 Color : COLOR0;
26   float2 TexCoord : TEXCOORD0;
27   float2 ExtraInfo : TEXCOORD1;
28};
29
30struct VS_INPUT
31{
32   float3 Position : POSITION;
33   float4 Color : COLOR0;
34   float2 TexCoord : TEXCOORD0;
35   float2 ExtraInfo : TEXCOORD1;
36};
37
38struct PS_INPUT
39{
40   float4 Color : COLOR0;
41   float2 TexCoord : TEXCOORD0;
42   float2 ExtraInfo : TEXCOORD1;
43};
44
45//-----------------------------------------------------------------------------
46// Simple Vertex Shader
47//-----------------------------------------------------------------------------
48
49uniform float TargetWidth;
50uniform float TargetHeight;
51uniform float PostPass;
52uniform float FixedAlpha;
53
54VS_OUTPUT vs_main(VS_INPUT Input)
55{
56   VS_OUTPUT Output = (VS_OUTPUT)0;
57   
58   Output.Position = float4(Input.Position.xyz, 1.0f);
59   Output.Position.x /= TargetWidth;
60   Output.Position.y /= TargetHeight;
61   Output.Position.y = 1.0f - Output.Position.y;
62   Output.Position.x -= 0.5f;
63   Output.Position.y -= 0.5f;
64   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
65   Output.Color = Input.Color;
66   Output.TexCoord = lerp(Input.TexCoord, Input.Position.xy / float2(TargetWidth, TargetHeight), PostPass);
67   Output.ExtraInfo = Input.ExtraInfo;
68
69   return Output;
70}
71
72//-----------------------------------------------------------------------------
73// Simple Pixel Shader
74//-----------------------------------------------------------------------------
75
76float4 ps_main(PS_INPUT Input) : COLOR
77{
78   float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
79   return lerp(Input.Color, BaseTexel * Input.Color, Input.ExtraInfo.x);
80}
81
82//-----------------------------------------------------------------------------
83// Simple Effect
84//-----------------------------------------------------------------------------
85
86technique TestTechnique
87{
88   pass Pass0
89   {
90      Lighting = FALSE;
91
92      //Sampler[0] = <DiffuseSampler>;
93
94      VertexShader = compile vs_2_0 vs_main();
95      PixelShader  = compile ps_2_0 ps_main();
96   }
97}
hlsl/post.fx
r0r11560
1//-----------------------------------------------------------------------------
2// Post-Processing Effect
3//-----------------------------------------------------------------------------
4
5texture Diffuse;
6
7sampler DiffuseSampler = sampler_state
8{
9   Texture   = <Diffuse>;
10   MipFilter = LINEAR;
11   MinFilter = LINEAR;
12   MagFilter = LINEAR;
13   AddressU = CLAMP;
14   AddressV = CLAMP;
15   AddressW = CLAMP;
16};
17
18texture Shadow;
19
20sampler ShadowSampler = sampler_state
21{
22   Texture   = <Shadow>;
23   MipFilter = LINEAR;
24   MinFilter = LINEAR;
25   MagFilter = LINEAR;
26   AddressU = WRAP;
27   AddressV = WRAP;
28   AddressW = WRAP;
29};
30
31//-----------------------------------------------------------------------------
32// Vertex Definitions
33//-----------------------------------------------------------------------------
34
35struct VS_OUTPUT
36{
37   float4 Position : POSITION;
38   float4 Color : COLOR0;
39   float2 TexCoord : TEXCOORD0;
40   float2 ExtraInfo : TEXCOORD1;
41   float3 CoordX : TEXCOORD2;
42   float3 CoordY : TEXCOORD3;
43   float2 ShadowCoord : TEXCOORD4;
44};
45
46struct VS_INPUT
47{
48   float4 Position : POSITION;
49   float4 Color : COLOR0;
50   float2 TexCoord : TEXCOORD0;
51   float2 ExtraInfo : TEXCOORD1;
52};
53
54struct PS_INPUT
55{
56   float4 Color : COLOR0;
57   float2 TexCoord : TEXCOORD0;
58   float2 ExtraInfo : TEXCOORD1;
59   float3 CoordX : TEXCOORD2;
60   float3 CoordY : TEXCOORD3;
61   float2 ShadowCoord : TEXCOORD4;
62};
63
64//-----------------------------------------------------------------------------
65// Post-Processing Vertex Shader
66//-----------------------------------------------------------------------------
67
68uniform float RedConvergeX;
69uniform float RedConvergeY;
70uniform float GrnConvergeX;
71uniform float GrnConvergeY;
72uniform float BluConvergeX;
73uniform float BluConvergeY;
74
75uniform float TargetWidth;
76uniform float TargetHeight;
77
78uniform float RawWidth;
79uniform float RawHeight;
80
81uniform float WidthRatio;
82uniform float HeightRatio;
83
84uniform float RedRadialConvergeX;
85uniform float RedRadialConvergeY;
86uniform float GrnRadialConvergeX;
87uniform float GrnRadialConvergeY;
88uniform float BluRadialConvergeX;
89uniform float BluRadialConvergeY;
90
91VS_OUTPUT vs_main(VS_INPUT Input)
92{
93   VS_OUTPUT Output = (VS_OUTPUT)0;
94   
95   float2 invDims = float2(1.0f / RawWidth, 1.0f / RawHeight);
96   float2 Ratios = float2(1.0f / WidthRatio, 1.0f / HeightRatio);
97   Output.Position = float4(Input.Position.xyz, 1.0f);
98   Output.Position.x /= TargetWidth;
99   Output.Position.y /= TargetHeight;
100   Output.Position.y = 1.0f - Output.Position.y;
101   Output.Position.x -= 0.5f;
102   Output.Position.y -= 0.5f;
103   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
104   Output.Color = Input.Color;
105   Output.TexCoord = Input.TexCoord;//(Input.TexCoord - float2(0.5f, 0.5f)) / 8.0f + float2(0.25f, 0.25f);
106   Output.ExtraInfo = Input.ExtraInfo;
107   
108   Output.CoordX.x = ((((Output.TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + RedRadialConvergeX / RawWidth) + 0.5f) * Ratios.x + RedConvergeX * invDims.x;
109   Output.CoordX.y = ((((Output.TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + GrnRadialConvergeX / RawWidth) + 0.5f) * Ratios.x + GrnConvergeX * invDims.x;
110   Output.CoordX.z = ((((Output.TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + BluRadialConvergeX / RawWidth) + 0.5f) * Ratios.x + GrnConvergeX * invDims.x;
111   
112   Output.CoordY.x = ((((Output.TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + RedRadialConvergeY / RawHeight) + 0.5f) * Ratios.y + RedConvergeY * invDims.y;
113   Output.CoordY.y = ((((Output.TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + GrnRadialConvergeY / RawHeight) + 0.5f) * Ratios.y + BluConvergeY * invDims.y;
114   Output.CoordY.z = ((((Output.TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + BluRadialConvergeY / RawHeight) + 0.5f) * Ratios.y + BluConvergeY * invDims.y;
115   
116   Output.ShadowCoord = Output.TexCoord * float2(RawWidth, RawHeight);
117   return Output;
118}
119
120//-----------------------------------------------------------------------------
121// Post-Processing Pixel Shader
122//-----------------------------------------------------------------------------
123
124uniform float PI = 3.14159265f;
125
126uniform float PincushionAmountX = 0.1f;
127uniform float PincushionAmountY = 0.1f;
128
129uniform float ScanlineAmount = 1.0f;
130uniform float ScanlineScale = 1.0f;
131uniform float ScanlineBrightScale = 1.0f;
132uniform float ScanlineBrightOffset = 1.0f;
133uniform float ScanlineOffset = 1.0f;
134
135uniform float RedFromRed = 1.0f;
136uniform float RedFromGrn = 0.0f;
137uniform float RedFromBlu = 0.0f;
138uniform float GrnFromRed = 0.0f;
139uniform float GrnFromGrn = 1.0f;
140uniform float GrnFromBlu = 0.0f;
141uniform float BluFromRed = 0.0f;
142uniform float BluFromGrn = 0.0f;
143uniform float BluFromBlu = 1.0f;
144
145uniform float YfromY = 1.0f;
146uniform float YfromI = 0.0f;
147uniform float YfromQ = 0.0f;
148uniform float IfromY = 0.0f;
149uniform float IfromI = 1.0f;
150uniform float IfromQ = 0.0f;
151uniform float QfromY = 0.0f;
152uniform float QfromI = 0.0f;
153uniform float QfromQ = 1.0f;
154
155uniform float RedOffset = 0.0f;
156uniform float GrnOffset = 0.0f;
157uniform float BluOffset = 0.0f;
158
159uniform float RedScale = 1.0f;
160uniform float GrnScale = 1.0f;
161uniform float BluScale = 1.0f;
162
163uniform float RedFloor = 0.0f;
164uniform float GrnFloor = 0.0f;
165uniform float BluFloor = 0.0f;
166
167uniform float Saturation = 1.0f;
168
169uniform float YScale = 1.0f;
170uniform float IScale = 1.0f;
171uniform float QScale = 1.0f;
172uniform float YOffset = 0.0f;
173uniform float IOffset = 0.0f;
174uniform float QOffset = 0.0f;
175
176uniform float RedPower = 2.2f;
177uniform float GrnPower = 2.2f;
178uniform float BluPower = 2.2f;
179
180uniform float EdgeDetectScale = 1.0f;
181uniform float EdgeToBaseRatio = 0.0f;
182
183uniform float SubsampleLength = 3.0f;
184
185uniform float CurrFrame = 0.0f;
186uniform float CrawlWidth = 3.0f;
187uniform float CrawlHeight = 3.0f;
188uniform float CrawlRate = 3.0f;
189
190uniform float UseShadow = 0.0f;
191uniform float ShadowBrightness = 1.0f;
192uniform float ShadowPixelSizeX = 3.0f;
193uniform float ShadowPixelSizeY = 3.0f;
194uniform float ShadowU = 0.375f;
195uniform float ShadowV = 0.375f;
196uniform float ShadowWidth = 8.0f;
197uniform float ShadowHeight = 8.0f;
198
199float4 ps_main(PS_INPUT Input) : COLOR
200{
201   float2 Ratios = float2(WidthRatio, HeightRatio);
202
203   // -- Screen Pincushion Calculation --
204   float2 UnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f;
205
206   float PincushionR2 = pow(length(UnitCoord),2.0f) / pow(length(Ratios), 2.0f);
207   float2 PincushionCurve = UnitCoord * PincushionAmountX * PincushionR2;
208   float2 BaseCoord = Input.TexCoord + PincushionCurve;
209
210   // RGB Pincushion Calculation
211   float3 PincushionCurveX = UnitCoord.x * PincushionAmountX * PincushionR2;
212   float3 PincushionCurveY = UnitCoord.y * PincushionAmountX * PincushionR2;
213
214   float4 BaseTexel = tex2D(DiffuseSampler, BaseCoord);
215
216   // -- Alpha Clipping (1px border in drawd3d does not work for some reason) --
217   clip((BaseCoord.x < 1.0f / TargetWidth) ? -1 : 1);
218   clip((BaseCoord.y < 3.0f / TargetHeight) ? -1 : 1);
219   clip((BaseCoord.x > 1.0f / WidthRatio) ? -1 : 1);
220   clip((BaseCoord.y > 1.0f / HeightRatio) ? -1 : 1);
221
222   // -- Chroma Subsampling & RGB Deconvergence --
223   float3 CoordX = Input.CoordX + PincushionCurveX;
224   float3 CoordY = Input.CoordY + PincushionCurveY;
225   float RedTexel = tex2D(DiffuseSampler, float2(CoordX.x, CoordY.x)).r;
226   float GrnTexel = tex2D(DiffuseSampler, float2(CoordX.y, CoordY.y)).g;
227   float BluTexel = tex2D(DiffuseSampler, float2(CoordX.z, CoordY.z)).b;
228
229   float ChromaSubsampleWidth = RawWidth / SubsampleLength;
230   float LumaSubsampleWidth = RawWidth / SubsampleLength; // For now
231   float3 YFrac = frac((CoordY * RawHeight) / CrawlHeight);
232   float3 CrawlPercent = frac(CurrFrame / CrawlRate + (YFrac - frac(YFrac * CrawlWidth) / CrawlWidth)) * CrawlWidth;
233   float3 ChromaCoordX = Input.CoordX + CrawlPercent / RawWidth;
234   float3 ChannelFrac = frac((ChromaCoordX + PincushionCurveX) * ChromaSubsampleWidth);
235   ChromaCoordX = ((ChromaCoordX + PincushionCurveX) * ChromaSubsampleWidth - ChannelFrac) / ChromaSubsampleWidth + ChannelFrac / (ChromaSubsampleWidth * 2.0f);
236   float3 ChromaCoordY = Input.CoordY + PincushionCurveY;
237
238   float3 BaseTexelRight = tex2D(DiffuseSampler, BaseCoord + float2(1.0f / TargetWidth, 0.0f)).rgb;
239   float3 BaseTexelUpper = tex2D(DiffuseSampler, BaseCoord + float2(0.0f, 1.0f / TargetHeight)).rgb;
240
241   float3 UpperDifference = abs(BaseTexel.rgb - BaseTexelUpper);
242   float3 RightDifference = abs(BaseTexel.rgb - BaseTexelRight);
243   float3 EdgeDifference = (UpperDifference + RightDifference) * EdgeDetectScale;
244
245   float RedChromaTexel = tex2D(DiffuseSampler, float2(ChromaCoordX.x, ChromaCoordY.x)).r;
246   float GrnChromaTexel = tex2D(DiffuseSampler, float2(ChromaCoordX.y, ChromaCoordY.y)).g;
247   float BluChromaTexel = tex2D(DiffuseSampler, float2(ChromaCoordX.z, ChromaCoordY.z)).b;
248
249   float3 LumaTexel = float3(RedTexel, GrnTexel, BluTexel);
250   float3 ChromaTexel = lerp(float3(RedChromaTexel, GrnChromaTexel, BluChromaTexel), LumaTexel, ChannelFrac);
251
252   // -- RGB Tint & Shift --
253   float ShiftedRed = dot(LumaTexel, float3(RedFromRed, RedFromGrn, RedFromBlu));
254   float ShiftedGrn = dot(LumaTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu));
255   float ShiftedBlu = dot(LumaTexel, float3(BluFromRed, BluFromGrn, BluFromBlu));
256   float ShiftedRedChroma = dot(ChromaTexel, float3(RedFromRed, RedFromGrn, RedFromBlu));
257   float ShiftedGrnChroma = dot(ChromaTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu));
258   float ShiftedBluChroma = dot(ChromaTexel, float3(BluFromRed, BluFromGrn, BluFromBlu));
259   float EdgeRed = dot(EdgeDifference, float3(RedFromRed, RedFromGrn, RedFromBlu));
260   float EdgeGrn = dot(EdgeDifference, float3(GrnFromRed, GrnFromGrn, GrnFromBlu));
261   float EdgeBlu = dot(EdgeDifference, float3(BluFromRed, BluFromGrn, BluFromBlu));
262   
263   // -- RGB Offset & Scale --
264   float3 OutTexelLuma = float3(ShiftedRed, ShiftedGrn, ShiftedBlu) * float3(RedScale, GrnScale, BluScale) + float3(RedOffset, GrnOffset, BluOffset);
265   float3 OutTexelChroma = float3(ShiftedRedChroma, ShiftedGrnChroma, ShiftedBluChroma) * float3(RedScale, GrnScale, BluScale) + float3(RedOffset, GrnOffset, BluOffset);
266   
267   // -- Saturation --
268   float OutLumaLuma = dot(OutTexelLuma, float3(0.3f, 0.59f, 0.11f));
269   float3 OutChromaLuma = OutTexelLuma - float3(OutLumaLuma, OutLumaLuma, OutLumaLuma);
270   float3 SaturatedLuma = OutLumaLuma + OutChromaLuma * Saturation;
271   
272   float OutLumaChroma = dot(OutTexelChroma, float3(0.3f, 0.59f, 0.11f));
273   float3 OutChromaChroma = OutTexelChroma  - float3(OutLumaChroma, OutLumaChroma, OutLumaChroma);
274   float3 SaturatedChroma = OutLumaChroma + OutChromaChroma * Saturation;
275   
276   // -- YIQ Convolution --
277   float Y = dot(SaturatedLuma, float3(0.299f, 0.587f, 0.114f));
278   float I = dot(SaturatedChroma, float3(0.595716f, -0.274453f, -0.321263f));
279   float Q = dot(SaturatedChroma, float3(0.211456f, -0.522591f, 0.311135f));
280   Y = dot(float3(Y, I, Q), float3(YfromY, YfromI, YfromQ));
281   I = dot(float3(Y, I, Q), float3(IfromY, IfromI, IfromQ));
282   Q = dot(float3(Y, I, Q), float3(QfromY, QfromI, QfromQ));
283   float3 OutYIQ = float3(Y, I, Q) * float3(YScale, IScale, QScale) + float3(YOffset, IOffset, QOffset);
284   float3 OutRGB = float3(dot(OutYIQ, float3(1.0f, 0.9563f, 0.6210f)), dot(OutYIQ, float3(1.0f, -0.2721f, -0.6474f)), dot(OutYIQ, float3(1.0f, -1.1070f, 1.7046f)));
285
286   OutRGB = lerp(OutRGB, float3(EdgeRed, EdgeGrn, EdgeBlu), EdgeToBaseRatio);
287
288   OutRGB.r = pow(OutRGB.r, RedPower);
289   OutRGB.g = pow(OutRGB.g, GrnPower);
290   OutRGB.b = pow(OutRGB.b, BluPower);
291
292   // -- Color Compression (increasing the floor of the signal without affecting the ceiling) --
293   OutRGB = float3(RedFloor + (1.0f - RedFloor) * OutRGB.r, GrnFloor + (1.0f - GrnFloor) * OutRGB.g, BluFloor + (1.0f - BluFloor) * OutRGB.b);
294
295   // -- Scanline Simulation --
296   float3 ScanBrightness = lerp(1.0f, abs(sin(((CoordY * RawHeight * ScanlineScale) * PI + ScanlineOffset * RawHeight))) * ScanlineBrightScale + ScanlineBrightOffset, ScanlineAmount);
297   float3 Scanned = OutRGB * ScanBrightness;
298
299   float2 ShadowCoord = BaseCoord * float2(RawWidth, RawHeight);
300   float ShadowCoordX = frac(ShadowCoord.x / ShadowPixelSizeX) * ShadowU + 0.5f / (ShadowWidth * ShadowU);
301   float ShadowCoordY = frac(ShadowCoord.y / ShadowPixelSizeY) * ShadowV + 0.5f / (ShadowHeight * ShadowV);
302   float3 ShadowTexel = lerp(1.0f, tex2D(ShadowSampler, float2(ShadowCoordX, ShadowCoordY)), UseShadow);
303   
304   // -- Final Pixel --
305   float4 Output = lerp(Input.Color, float4(Scanned * lerp(1.0f, ShadowTexel * 1.25f, ShadowBrightness), BaseTexel.a) * Input.Color, Input.ExtraInfo.x);
306   
307   return Output;
308}
309
310//-----------------------------------------------------------------------------
311// Post-Processing Effect
312//-----------------------------------------------------------------------------
313
314technique TestTechnique
315{
316   pass Pass0
317   {
318      Lighting = FALSE;
319
320      //Sampler[0] = <DiffuseSampler>;
321
322      VertexShader = compile vs_3_0 vs_main();
323      PixelShader  = compile ps_3_0 ps_main();
324   }
325}
hlsl/focus.fx
r0r11560
1//-----------------------------------------------------------------------------
2// Effect File Variables
3//-----------------------------------------------------------------------------
4
5texture Diffuse;
6
7sampler DiffuseSampler = sampler_state
8{
9   Texture   = <Diffuse>;
10   MipFilter = LINEAR;
11   MinFilter = LINEAR;
12   MagFilter = LINEAR;
13   AddressU = CLAMP;
14   AddressV = CLAMP;
15   AddressW = CLAMP;
16};
17
18//-----------------------------------------------------------------------------
19// Vertex Definitions
20//-----------------------------------------------------------------------------
21
22struct VS_OUTPUT
23{
24   float4 Position : POSITION;
25   float4 Color : COLOR0;
26   float2 TexCoord0 : TEXCOORD0;
27   float2 TexCoord1 : TEXCOORD1;
28   float2 TexCoord2 : TEXCOORD2;
29   float2 TexCoord3 : TEXCOORD3;
30   float2 TexCoord4 : TEXCOORD4;
31   float2 TexCoord5 : TEXCOORD5;
32   float2 TexCoord6 : TEXCOORD6;
33   float2 TexCoord7 : TEXCOORD7;
34};
35
36struct VS_INPUT
37{
38   float3 Position : POSITION;
39   float4 Color : COLOR0;
40   float2 TexCoord : TEXCOORD0;
41   float2 ExtraInfo : TEXCOORD1;
42};
43
44struct PS_INPUT
45{
46   float4 Color : COLOR0;
47   float2 TexCoord0 : TEXCOORD0;
48   float2 TexCoord1 : TEXCOORD1;
49   float2 TexCoord2 : TEXCOORD2;
50   float2 TexCoord3 : TEXCOORD3;
51   float2 TexCoord4 : TEXCOORD4;
52   float2 TexCoord5 : TEXCOORD5;
53   float2 TexCoord6 : TEXCOORD6;
54   float2 TexCoord7 : TEXCOORD7;
55};
56
57//-----------------------------------------------------------------------------
58// Simple Vertex Shader
59//-----------------------------------------------------------------------------
60
61uniform float TargetWidth;
62uniform float TargetHeight;
63uniform float DefocusX;
64uniform float DefocusY;
65uniform float FocusEnable;
66
67float2 Coord0Offset = float2( 0.0f,  0.0f);
68float2 Coord1Offset = float2(-0.2f, -0.6f);
69float2 Coord2Offset = float2( 0.4f, -0.4f);
70float2 Coord3Offset = float2( 0.6f,  0.2f);
71float2 Coord4Offset = float2( 0.2f,  0.6f);
72float2 Coord5Offset = float2(-0.4f,  0.6f);
73float2 Coord6Offset = float2(-0.6f,  0.2f);
74float2 Coord7Offset = float2(-0.6f, -0.4f);
75
76VS_OUTPUT vs_main(VS_INPUT Input)
77{
78   VS_OUTPUT Output = (VS_OUTPUT)0;
79   
80   Output.Position = float4(Input.Position.xyz, 1.0f);
81   Output.Position.x /= TargetWidth;
82   Output.Position.y /= TargetHeight;
83   Output.Position.y = 1.0f - Output.Position.y;
84   Output.Position.x -= 0.5f;
85   Output.Position.y -= 0.5f;
86   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
87   Output.Color = Input.Color;
88   
89   float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight);
90   float2 TexCoord = Input.Position.xy * InvTexSize;
91   float2 DefocusVal = float2(DefocusX, DefocusY);
92   Output.TexCoord0 = TexCoord + Coord0Offset * InvTexSize * DefocusVal;
93   Output.TexCoord1 = TexCoord + Coord1Offset * InvTexSize * DefocusVal;
94   Output.TexCoord2 = TexCoord + Coord2Offset * InvTexSize * DefocusVal;
95   Output.TexCoord3 = TexCoord + Coord3Offset * InvTexSize * DefocusVal;
96   Output.TexCoord4 = TexCoord + Coord4Offset * InvTexSize * DefocusVal;
97   Output.TexCoord5 = TexCoord + Coord5Offset * InvTexSize * DefocusVal;
98   Output.TexCoord6 = TexCoord + Coord6Offset * InvTexSize * DefocusVal;
99   Output.TexCoord7 = TexCoord + Coord7Offset * InvTexSize * DefocusVal;
100
101   return Output;
102}
103
104//-----------------------------------------------------------------------------
105// Simple Pixel Shader
106//-----------------------------------------------------------------------------
107
108float4 ps_main(PS_INPUT Input) : COLOR
109{
110   float3 d0 = tex2D(DiffuseSampler, Input.TexCoord0).rgb;
111   float3 d1 = tex2D(DiffuseSampler, Input.TexCoord1).rgb;
112   float3 d2 = tex2D(DiffuseSampler, Input.TexCoord2).rgb;
113   float3 d3 = tex2D(DiffuseSampler, Input.TexCoord3).rgb;
114   float3 d4 = tex2D(DiffuseSampler, Input.TexCoord4).rgb;
115   float3 d5 = tex2D(DiffuseSampler, Input.TexCoord5).rgb;
116   float3 d6 = tex2D(DiffuseSampler, Input.TexCoord6).rgb;
117   float3 d7 = tex2D(DiffuseSampler, Input.TexCoord7).rgb;
118
119   float3 blurred = (d0 + d1 + d2 + d3 + d4 + d5 + d6 + d7) / 8.0f;
120
121   blurred = lerp(d0, blurred, FocusEnable);
122   return float4(blurred, 1.0f);
123}
124
125//-----------------------------------------------------------------------------
126// Simple Effect
127//-----------------------------------------------------------------------------
128
129technique TestTechnique
130{
131   pass Pass0
132   {
133      Lighting = FALSE;
134
135      Sampler[0] = <DiffuseSampler>;
136
137      VertexShader = compile vs_2_0 vs_main();
138      PixelShader  = compile ps_2_0 ps_main();
139   }
140}
hlsl/pincushion.fx
r0r11560
1//-----------------------------------------------------------------------------
2// Pincushion Post-Processing Effect
3//-----------------------------------------------------------------------------
4
5texture Diffuse;
6
7sampler DiffuseSampler = sampler_state
8{
9   Texture   = <Diffuse>;
10   MipFilter = LINEAR;
11   MinFilter = LINEAR;
12   MagFilter = LINEAR;
13   AddressU = CLAMP;
14   AddressV = CLAMP;
15   AddressW = CLAMP;
16};
17
18//-----------------------------------------------------------------------------
19// Vertex Definitions
20//-----------------------------------------------------------------------------
21
22struct VS_OUTPUT
23{
24   float4 Position : POSITION;
25   float4 Color : COLOR0;
26   float2 TexCoord : TEXCOORD0;
27   float2 ExtraInfo : TEXCOORD1;
28   float2 RedCoord : TEXCOORD2;
29   float2 GreenCoord : TEXCOORD3;
30   float2 BlueCoord : TEXCOORD4;
31};
32
33struct VS_INPUT
34{
35   float3 Position : POSITION;
36   float4 Color : COLOR0;
37   float2 TexCoord : TEXCOORD0;
38   float2 ExtraInfo : TEXCOORD1;
39};
40
41struct PS_INPUT
42{
43   float4 Color : COLOR0;
44   float2 TexCoord : TEXCOORD0;
45   float2 ExtraInfo : TEXCOORD1;
46   float2 RedCoord : TEXCOORD2;
47   float2 GreenCoord : TEXCOORD3;
48   float2 BlueCoord : TEXCOORD4;
49};
50
51//-----------------------------------------------------------------------------
52// Post-Processing Vertex Shader
53//-----------------------------------------------------------------------------
54
55uniform float TargetWidth;
56uniform float TargetHeight;
57
58uniform float RawWidth;
59uniform float RawHeight;
60
61VS_OUTPUT vs_main(VS_INPUT Input)
62{
63   VS_OUTPUT Output = (VS_OUTPUT)0;
64   
65   float2 invDims = float2(1.0f / RawWidth, 1.0f / RawHeight);
66   Output.Position = float4(Input.Position.xyz, 1.0f);
67   Output.Position.x /= TargetWidth;
68   Output.Position.y /= TargetHeight;
69   Output.Position.y = 1.0f - Output.Position.y;
70   Output.Position.x -= 0.5f;
71   Output.Position.y -= 0.5f;
72   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
73   Output.Color = Input.Color;
74   Output.TexCoord = Input.TexCoord;
75   
76   Output.TexCoord.x -= 0.25f;
77   Output.TexCoord.y -= 0.25f;
78   Output.TexCoord.x -= 0.5f;
79   Output.TexCoord.y -= 0.5f;
80   Output.TexCoord.x /= 18.0f * (TargetWidth / RawWidth);
81   Output.TexCoord.y /= 18.0f * (TargetHeight / RawHeight);
82   Output.TexCoord.x += 0.5f;
83   Output.TexCoord.y += 0.5f;
84
85   return Output;
86}
87
88//-----------------------------------------------------------------------------
89// Post-Processing Pixel Shader
90//-----------------------------------------------------------------------------
91
92uniform float PI = 3.14159265f;
93
94uniform float PincushionAmountX = 0.1f;
95uniform float PincushionAmountY = 0.1f;
96
97uniform float WidthRatio;
98uniform float HeightRatio;
99
100float4 ps_main(PS_INPUT Input) : COLOR
101{
102   float2 Ratios = float2(WidthRatio, HeightRatio);
103
104   // -- Screen Pincushion Calculation --
105   float2 UnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f;
106
107   float PincushionR2 = pow(length(UnitCoord),2.0f) / pow(length(Ratios), 2.0f);
108   float2 PincushionCurve = UnitCoord * PincushionAmountX * PincushionR2;
109   float2 BaseCoord = Input.TexCoord + PincushionCurve;
110
111   return tex2D(DiffuseSampler, BaseCoord);
112}
113
114//-----------------------------------------------------------------------------
115// Post-Processing Effect
116//-----------------------------------------------------------------------------
117
118technique TestTechnique
119{
120   pass Pass0
121   {
122      Lighting = FALSE;
123
124      Sampler[0] = <DiffuseSampler>;
125
126      VertexShader = compile vs_2_0 vs_main();
127      PixelShader  = compile ps_2_0 ps_main();
128   }
129}
hlsl/phosphor.fx
r0r11560
1//-----------------------------------------------------------------------------
2// Effect File Variables
3//-----------------------------------------------------------------------------
4
5texture Diffuse;
6
7sampler DiffuseSampler = sampler_state
8{
9   Texture   = <Diffuse>;
10   MipFilter = LINEAR;
11   MinFilter = LINEAR;
12   MagFilter = LINEAR;
13   AddressU = CLAMP;
14   AddressV = CLAMP;
15   AddressW = CLAMP;
16};
17
18texture LastPass;
19
20sampler PreviousSampler = sampler_state
21{
22   Texture   = <LastPass>;
23   MipFilter = LINEAR;
24   MinFilter = LINEAR;
25   MagFilter = LINEAR;
26   AddressU = CLAMP;
27   AddressV = CLAMP;
28   AddressW = CLAMP;
29};
30
31//-----------------------------------------------------------------------------
32// Vertex Definitions
33//-----------------------------------------------------------------------------
34
35struct VS_OUTPUT
36{
37   float4 Position : POSITION;
38   float4 Color : COLOR0;
39   float2 TexCoord : TEXCOORD0;
40   float2 PrevCoord : TEXCOORD1;
41};
42
43struct VS_INPUT
44{
45   float3 Position : POSITION;
46   float4 Color : COLOR0;
47   float2 TexCoord : TEXCOORD0;
48   float2 ExtraInfo : TEXCOORD1;
49};
50
51struct PS_INPUT
52{
53   float4 Color : COLOR0;
54   float2 TexCoord : TEXCOORD0;
55   float2 PrevCoord : TEXCOORD1;
56};
57
58//-----------------------------------------------------------------------------
59// Simple Vertex Shader
60//-----------------------------------------------------------------------------
61
62uniform float TargetWidth;
63uniform float TargetHeight;
64
65uniform float RawWidth;
66uniform float RawHeight;
67
68VS_OUTPUT vs_main(VS_INPUT Input)
69{
70   VS_OUTPUT Output = (VS_OUTPUT)0;
71   
72   Output.Position = float4(Input.Position.xyz, 1.0f);
73   Output.Position.x /= TargetWidth;
74   Output.Position.y /= TargetHeight;
75   Output.Position.y = 1.0f - Output.Position.y;
76   Output.Position.x -= 0.5f;
77   Output.Position.y -= 0.5f;
78   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
79   Output.Color = Input.Color;
80   
81   float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight);
82   Output.TexCoord = Input.Position.xy * InvTexSize;
83   Output.TexCoord += 0.5f / float2(TargetWidth, TargetHeight);
84
85   Output.PrevCoord = Output.TexCoord;
86   
87   return Output;
88}
89
90//-----------------------------------------------------------------------------
91// Simple Pixel Shader
92//-----------------------------------------------------------------------------
93
94uniform float RedPhosphor = 0.0f;
95uniform float GreenPhosphor = 0.0f;
96uniform float BluePhosphor = 0.0f;
97
98float4 ps_main(PS_INPUT Input) : COLOR
99{
100   float4 CurrPix = tex2D(DiffuseSampler, Input.TexCoord);
101   float3 PrevPix = tex2D(PreviousSampler, Input.PrevCoord).rgb * float3(RedPhosphor, GreenPhosphor, BluePhosphor);
102   
103   float RedMax = max(CurrPix.r, PrevPix.r);
104   float GreenMax = max(CurrPix.g, PrevPix.g);
105   float BlueMax = max(CurrPix.b, PrevPix.b);
106
107   return float4(RedMax, GreenMax, BlueMax, CurrPix.a);
108}
109
110//-----------------------------------------------------------------------------
111// Simple Effect
112//-----------------------------------------------------------------------------
113
114technique TestTechnique
115{
116   pass Pass0
117   {
118      Lighting = FALSE;
119
120      //Sampler[0] = <DiffuseSampler>;
121      //Sampler[1] = <PreviousSampler>;
122
123      VertexShader = compile vs_2_0 vs_main();
124      PixelShader  = compile ps_2_0 ps_main();
125   }
126}
src/osd/windows/d3dintf.h
r11559r11560
7171    D3DTSS_MAXMIPLEVEL    = 20,
7272    D3DTSS_MAXANISOTROPY  = 21
7373};
74
7475#endif
7576#endif
7677
r11559r11560
8485typedef struct _d3d_surface d3d_surface;
8586typedef struct _d3d_texture d3d_texture;
8687typedef struct _d3d_vertex_buffer d3d_vertex_buffer;
88typedef struct _d3d_effect d3d_effect;
89typedef D3DXVECTOR4 d3d_vector;
90typedef D3DMATRIX d3d_matrix;
8791
8892
8993//============================================================
r11559r11560
147151   CAPS_MAX_TEXTURE_ASPECT,
148152   CAPS_MAX_TEXTURE_WIDTH,
149153   CAPS_MAX_TEXTURE_HEIGHT,
150   CAPS_STRETCH_RECT_FILTER
154   CAPS_STRETCH_RECT_FILTER,
155   CAPS_MAX_PS30_INSN_SLOTS
151156};
152157typedef enum _d3d_caps_index d3d_caps_index;
153158
r11559r11560
183188   HRESULT (*begin_scene)(d3d_device *dev);
184189   HRESULT (*clear)(d3d_device *dev, DWORD count, const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil);
185190   HRESULT (*create_offscreen_plain_surface)(d3d_device *dev, UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, d3d_surface **surface);
191   HRESULT (*create_effect)(d3d_device *dev, const WCHAR *name, d3d_effect **effect);
186192   HRESULT (*create_texture)(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture);
187193   HRESULT (*create_vertex_buffer)(d3d_device *dev, UINT length, DWORD usage, DWORD fvf, D3DPOOL pool, d3d_vertex_buffer **buf);
194   HRESULT (*create_render_target)(d3d_device *dev, UINT width, UINT height, D3DFORMAT format, d3d_surface **surface);
188195   HRESULT (*draw_primitive)(d3d_device *dev, D3DPRIMITIVETYPE type, UINT start, UINT count);
189196   HRESULT (*end_scene)(d3d_device *dev);
190197   HRESULT (*get_raster_status)(d3d_device *dev, D3DRASTER_STATUS *status);
r11559r11560
198205   HRESULT (*set_stream_source)(d3d_device *dev, UINT number, d3d_vertex_buffer *vbuf, UINT stride);
199206   HRESULT (*set_texture)(d3d_device *dev, DWORD stage, d3d_texture *tex);
200207   HRESULT (*set_texture_stage_state)(d3d_device *dev, DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value);
201   HRESULT (*set_vertex_shader)(d3d_device *dev, D3DFORMAT format);
208   HRESULT (*set_vertex_format)(d3d_device *dev, D3DFORMAT format);
202209   HRESULT (*stretch_rect)(d3d_device *dev, d3d_surface *source, const RECT *srcrect, d3d_surface *dest, const RECT *dstrect, D3DTEXTUREFILTERTYPE filter);
203210   HRESULT (*test_cooperative_level)(d3d_device *dev);
204211};
r11559r11560
245252
246253
247254//============================================================
255//  Direct3DEffect interfaces
256//============================================================
257
258typedef struct _d3d_effect_interface d3d_effect_interface;
259struct _d3d_effect_interface
260{
261   void     (*begin)(d3d_effect *effect, UINT *passes, DWORD flags);
262   void     (*end)(d3d_effect *effect);
263   void     (*begin_pass)(d3d_effect *effect, UINT pass);
264   void     (*end_pass)(d3d_effect *effect);
265   void     (*set_technique)(d3d_effect *effect, const char *name);
266   void     (*set_vector)(d3d_effect *effect, const char *name, d3d_vector *vector);
267   void     (*set_float)(d3d_effect *effect, const char *name, float value);
268   void     (*set_int)(d3d_effect *effect, const char *name, int value);
269   void     (*set_matrix)(d3d_effect *effect, const char *name, d3d_matrix *matrix);
270   void     (*set_texture)(d3d_effect *effect, const char *name, d3d_texture *tex);
271   ULONG    (*release)(d3d_effect *effect);
272};
273
274
275//============================================================
248276//  Core D3D object
249277//============================================================
250278
r11559r11560
254282   int                     version;
255283   void *                  d3dobj;
256284   HINSTANCE               dllhandle;
285   bool                  post_fx_available;
257286
258287   // interface pointers
259288   d3d_interface            d3d;
r11559r11560
261290   d3d_surface_interface      surface;
262291   d3d_texture_interface      texture;
263292   d3d_vertex_buffer_interface vertexbuf;
293   d3d_effect_interface        effect;
264294};
265295
266296
src/osd/windows/winprefix.h
r11559r11560
5555#ifndef alloca
5656#define alloca   __builtin_alloca
5757#endif
58#define min(x,y) fmin(x,y)
59#define max(x,y) fmax(x,y)
5860#endif
5961
6062#define PATH_SEPARATOR      "\\"
src/osd/windows/d3d8intf.c
r11559r11560
4343#define WIN32_LEAN_AND_MEAN
4444#include <windows.h>
4545#include <d3d8.h>
46#define D3DXVECTOR4 void
4647#undef interface
4748
4849// MAME headers
r11559r11560
141142   d3dptr->version = 8;
142143   d3dptr->d3dobj = d3d8;
143144   d3dptr->dllhandle = dllhandle;
145   d3dptr->post_fx_available = false;
144146   set_interfaces(d3dptr);
145147
146148   mame_printf_verbose("Direct3D: Using Direct3D 8\n");
r11559r11560
249251      case CAPS_MAX_TEXTURE_WIDTH:      *value = caps.MaxTextureWidth;         break;
250252      case CAPS_MAX_TEXTURE_HEIGHT:      *value = caps.MaxTextureHeight;         break;
251253      case CAPS_STRETCH_RECT_FILTER:      *value = 0;                        break;
254      case CAPS_MAX_PS30_INSN_SLOTS:      *value = 0;                        break;
252255   }
253256   return result;
254257}
r11559r11560
306309}
307310
308311
312static HRESULT d3d_device_create_effect(d3d_device *dev, const WCHAR *name, d3d_effect **effect)
313{
314   assert(FALSE);
315   return D3D_OK;
316}
317
318
319
309320static HRESULT d3d_device_create_texture(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture)
310321{
311322   IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev;
r11559r11560
395406}
396407
397408
409static HRESULT d3d_device_create_render_target(d3d_device *dev, UINT width, UINT height, D3DFORMAT format, d3d_surface **surface)
410{
411   assert(false);
412   return D3D_OK;
413}
414
415
398416static HRESULT d3d_device_set_stream_source(d3d_device *dev, UINT number, d3d_vertex_buffer *vbuf, UINT stride)
399417{
400418   IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev;
r11559r11560
418436}
419437
420438
421static HRESULT d3d_device_set_vertex_shader(d3d_device *dev, D3DFORMAT format)
439static HRESULT d3d_device_set_vertex_format(d3d_device *dev, D3DFORMAT format)
422440{
423441   IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev;
424442   return IDirect3DDevice8_SetVertexShader(device, format);
r11559r11560
444462   d3d_device_begin_scene,
445463   d3d_device_clear,
446464   d3d_device_create_offscreen_plain_surface,
465   d3d_device_create_effect,
447466   d3d_device_create_texture,
448467   d3d_device_create_vertex_buffer,
468   d3d_device_create_render_target,
449469   d3d_device_draw_primitive,
450470   d3d_device_end_scene,
451471   d3d_device_get_raster_status,
r11559r11560
459479   d3d_device_set_stream_source,
460480   d3d_device_set_texture,
461481   d3d_device_set_texture_stage_state,
462   d3d_device_set_vertex_shader,
482   d3d_device_set_vertex_format,
463483   d3d_device_stretch_rect,
464484   d3d_device_test_cooperative_level
465485};
r11559r11560
577597
578598
579599//============================================================
600//  Direct3DEffect interfaces
601//============================================================
602
603static void d3d_effect_begin(d3d_effect *effect, UINT *passes, DWORD flags)
604{
605   assert(FALSE);
606}
607
608
609static void d3d_effect_end(d3d_effect *effect)
610{
611   assert(FALSE);
612}
613
614
615static void d3d_effect_begin_pass(d3d_effect *effect, UINT pass)
616{
617   assert(FALSE);
618}
619
620
621static void d3d_effect_end_pass(d3d_effect *effect)
622{
623   assert(FALSE);
624}
625
626
627static void d3d_effect_set_technique(d3d_effect *effect, const char *name)
628{
629   assert(FALSE);
630}
631
632
633static void d3d_effect_set_vector(d3d_effect *effect, const char *name, d3d_vector *vector)
634{
635   assert(FALSE);
636}
637
638
639static void d3d_effect_set_float(d3d_effect *effect, const char *name, float value)
640{
641   assert(FALSE);
642}
643
644
645static void d3d_effect_set_int(d3d_effect *effect, const char *name, int value)
646{
647   assert(FALSE);
648}
649
650
651static void d3d_effect_set_matrix(d3d_effect *effect, const char *name, d3d_matrix *matrix)
652{
653   assert(FALSE);
654}
655
656
657static void d3d_effect_set_texture(d3d_effect *effect, const char *name, d3d_texture *tex)
658{
659   assert(FALSE);
660}
661
662
663static ULONG d3d_effect_release(d3d_effect *effect)
664{
665   assert(FALSE);
666   return 0;
667}
668
669
670static const d3d_effect_interface d3d8_effect_interface =
671{
672   d3d_effect_begin,
673   d3d_effect_end,
674   d3d_effect_begin_pass,
675   d3d_effect_end_pass,
676   d3d_effect_set_technique,
677   d3d_effect_set_vector,
678   d3d_effect_set_float,
679   d3d_effect_set_int,
680   d3d_effect_set_matrix,
681   d3d_effect_set_texture,
682   d3d_effect_release
683};
684
685
686
687//============================================================
580688//  set_interfaces
581689//============================================================
582690
r11559r11560
587695   d3dptr->surface = d3d8_surface_interface;
588696   d3dptr->texture = d3d8_texture_interface;
589697   d3dptr->vertexbuf = d3d8_vertex_buffer_interface;
698   d3dptr->effect = d3d8_effect_interface;
590699}
src/osd/windows/d3d9intf.c
r11559r11560
4343#define WIN32_LEAN_AND_MEAN
4444#include <windows.h>
4545#include <d3d9.h>
46#include <d3dx9.h>
4647#undef interface
4748
4849// MAME headers
r11559r11560
6061
6162typedef IDirect3D9 *(WINAPI *direct3dcreate9_ptr)(UINT SDKVersion);
6263
64typedef HRESULT (WINAPI *direct3dx9_loadeffect_ptr)(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXEFFECTPOOL pPool, LPD3DXEFFECT *ppEffect, LPD3DXBUFFER *ppCompilationErrors);
65static direct3dx9_loadeffect_ptr g_load_effect = NULL;
6366
6467
6568//============================================================
r11559r11560
6871
6972static void set_interfaces(d3d *d3dptr);
7073
71
72
7374//============================================================
7475//  INLINES
7576//============================================================
r11559r11560
105106   HINSTANCE dllhandle;
106107   IDirect3D9 *d3d9;
107108   d3d *d3dptr;
109   bool post_available = true;
108110
109111   // dynamically grab the create function from d3d9.dll
110112   dllhandle = LoadLibrary(TEXT("d3d9.dll"));
r11559r11560
134136      return NULL;
135137   }
136138
139   // dynamically grab the shader load function from d3dx9.dll
140   HINSTANCE fxhandle = LoadLibrary(TEXT("d3dx9_43.dll"));
141   if (fxhandle == NULL)
142   {
143      post_available = false;
144      mame_printf_verbose("Direct3D: Warning - Unable to access d3dx9_43.dll; disabling post-effect rendering\n");
145   }
146
147   // import the create function
148   if(post_available)
149   {
150      g_load_effect = (direct3dx9_loadeffect_ptr)GetProcAddress(fxhandle, "D3DXCreateEffectFromFileW");
151      if (g_load_effect == NULL)
152      {
153         printf("Direct3D: Unable to find D3DXCreateEffectFromFileW\n");
154         FreeLibrary(dllhandle);
155         fxhandle = NULL;
156         dllhandle = NULL;
157         return NULL;
158      }
159   }
160   else
161   {
162      g_load_effect = NULL;
163      post_available = false;
164      mame_printf_verbose("Direct3D: Warning - Unable to get a handle to D3DXCreateEffectFromFileW; disabling post-effect rendering\n");
165   }
166
137167   // allocate an object to hold our data
138168   d3dptr = global_alloc(d3d);
139169   d3dptr->version = 9;
140170   d3dptr->d3dobj = d3d9;
141171   d3dptr->dllhandle = dllhandle;
172   d3dptr->post_fx_available = post_available;
142173   set_interfaces(d3dptr);
143174
144175   mame_printf_verbose("Direct3D: Using Direct3D 9\n");
r11559r11560
164195   return IDirect3D9_CheckDeviceType(d3d9, adapter, devtype, format, backformat, windowed);
165196}
166197
167
168198static HRESULT d3d_create_device(d3d *d3dptr, UINT adapter, D3DDEVTYPE devtype, HWND focus, DWORD behavior, d3d_present_parameters *params, d3d_device **dev)
169199{
170200   IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
r11559r11560
173203   return IDirect3D9_CreateDevice(d3d9, adapter, devtype, focus, behavior, &d3d9params, (IDirect3DDevice9 **)dev);
174204}
175205
176
177206static HRESULT d3d_enum_adapter_modes(d3d *d3dptr, UINT adapter, D3DFORMAT format, UINT index, D3DDISPLAYMODE *mode)
178207{
179208   IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
r11559r11560
247276      case CAPS_MAX_TEXTURE_WIDTH:      *value = caps.MaxTextureWidth;         break;
248277      case CAPS_MAX_TEXTURE_HEIGHT:      *value = caps.MaxTextureHeight;         break;
249278      case CAPS_STRETCH_RECT_FILTER:      *value = caps.StretchRectFilterCaps;   break;
279      case CAPS_MAX_PS30_INSN_SLOTS:      *value = caps.MaxPixelShader30InstructionSlots; break;
250280   }
251281   return result;
252282}
r11559r11560
289319   return IDirect3DDevice9_BeginScene(device);
290320}
291321
292
293322static HRESULT d3d_device_clear(d3d_device *dev, DWORD count, const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
294323{
295324   IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
r11559r11560
304333}
305334
306335
336static HRESULT d3d_device_create_effect(d3d_device *dev, const WCHAR *name, d3d_effect **effect)
337{
338   IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
339
340   LPD3DXBUFFER buffer_errors = NULL;
341   HRESULT hr = (*g_load_effect)(device, name, NULL, NULL, 0, NULL, (ID3DXEffect**)effect, &buffer_errors);
342   if(FAILED(hr))
343   {
344      LPVOID compile_errors = buffer_errors->GetBufferPointer();
345      printf("Unable to compile shader: %s\n", (const char*)compile_errors);
346   }
347
348   return hr;
349}
350
351
307352static HRESULT d3d_device_create_texture(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture)
308353{
309354   IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
r11559r11560
402447}
403448
404449
450static HRESULT d3d_device_create_render_target(d3d_device *dev, UINT width, UINT height, D3DFORMAT format, d3d_surface **surface)
451{
452   IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
453   return IDirect3DDevice9_CreateRenderTarget(device, width, height, format, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)surface, NULL);
454}
455
456
405457static HRESULT d3d_device_set_stream_source(d3d_device *dev, UINT number, d3d_vertex_buffer *vbuf, UINT stride)
406458{
407459   IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
r11559r11560
449501}
450502
451503
452static HRESULT d3d_device_set_vertex_shader(d3d_device *dev, D3DFORMAT format)
504static HRESULT d3d_device_set_vertex_format(d3d_device *dev, D3DFORMAT format)
453505{
454506   IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
455507   return IDirect3DDevice9_SetFVF(device, format);
r11559r11560
477529   d3d_device_begin_scene,
478530   d3d_device_clear,
479531   d3d_device_create_offscreen_plain_surface,
532   d3d_device_create_effect,
480533   d3d_device_create_texture,
481534   d3d_device_create_vertex_buffer,
535   d3d_device_create_render_target,
482536   d3d_device_draw_primitive,
483537   d3d_device_end_scene,
484538   d3d_device_get_raster_status,
r11559r11560
492546   d3d_device_set_stream_source,
493547   d3d_device_set_texture,
494548   d3d_device_set_texture_stage_state,
495   d3d_device_set_vertex_shader,
549   d3d_device_set_vertex_format,
496550   d3d_device_stretch_rect,
497551   d3d_device_test_cooperative_level
498552};
r11559r11560
610664
611665
612666//============================================================
667//  Direct3DEffect interfaces
668//============================================================
669
670static void d3d_effect_begin(d3d_effect *effect, UINT *passes, DWORD flags)
671{
672   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
673   d3dfx->Begin(passes, flags);
674}
675
676
677static void d3d_effect_end(d3d_effect *effect)
678{
679   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
680   d3dfx->End();
681}
682
683
684static void d3d_effect_begin_pass(d3d_effect *effect, UINT pass)
685{
686   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
687   d3dfx->BeginPass(pass);
688}
689
690
691static void d3d_effect_end_pass(d3d_effect *effect)
692{
693   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
694   d3dfx->EndPass();
695}
696
697
698static void d3d_effect_set_technique(d3d_effect *effect, const char *name)
699{
700   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
701   d3dfx->SetTechnique(name);
702}
703
704
705static void d3d_effect_set_vector(d3d_effect *effect, const char *name, d3d_vector *vector)
706{
707   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
708   d3dfx->SetVector(name, (D3DXVECTOR4*)vector);
709}
710
711
712static void d3d_effect_set_float(d3d_effect *effect, const char *name, float value)
713{
714   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
715   d3dfx->SetFloat(name, value);
716}
717
718
719static void d3d_effect_set_int(d3d_effect *effect, const char *name, int value)
720{
721   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
722   d3dfx->SetInt(name, value);
723}
724
725
726static void d3d_effect_set_matrix(d3d_effect *effect, const char *name, d3d_matrix *matrix)
727{
728   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
729   d3dfx->SetMatrix(name, (D3DXMATRIX*)matrix);
730}
731
732
733static void d3d_effect_set_texture(d3d_effect *effect, const char *name, d3d_texture *tex)
734{
735   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
736   d3dfx->SetTexture(name, (IDirect3DTexture9*)tex);
737}
738
739
740static ULONG d3d_effect_release(d3d_effect *effect)
741{
742   ID3DXEffect *d3dfx = (ID3DXEffect*)effect;
743   return d3dfx->Release();
744}
745
746
747static const d3d_effect_interface d3d9_effect_interface =
748{
749   d3d_effect_begin,
750   d3d_effect_end,
751   d3d_effect_begin_pass,
752   d3d_effect_end_pass,
753   d3d_effect_set_technique,
754   d3d_effect_set_vector,
755   d3d_effect_set_float,
756   d3d_effect_set_int,
757   d3d_effect_set_matrix,
758   d3d_effect_set_texture,
759   d3d_effect_release
760};
761
762
763
764//============================================================
613765//  set_interfaces
614766//============================================================
615767
r11559r11560
620772   d3dptr->surface = d3d9_surface_interface;
621773   d3dptr->texture = d3d9_texture_interface;
622774   d3dptr->vertexbuf = d3d9_vertex_buffer_interface;
775   d3dptr->effect = d3d9_effect_interface;
623776}
src/osd/windows/winmain.c
r11559r11560
326326   { WINOPTION_D3DVERSION "(8-9)",                   "9",        OPTION_INTEGER,    "specify the preferred Direct3D version (8 or 9)" },
327327   { WINOPTION_FILTER ";d3dfilter;flt",              "1",        OPTION_BOOLEAN,    "enable bilinear filtering on screen output" },
328328
329   // post-processing options
330   { NULL,                                                    NULL,        OPTION_HEADER,     "DIRECT3D POST-PROCESSING OPTIONS" },
331   { WINOPTION_HLSL_ENABLE";hlsl",                           "0",           OPTION_BOOLEAN,    "enable HLSL post-processing (PS3.0 required)" },
332   { WINOPTION_HLSLPATH,                                       "hlsl",       OPTION_STRING,     "path to hlsl files" },
333   { WINOPTION_SHADOW_MASK_ALPHA";fs_shadwa(0.0-1.0)",         "0.0",         OPTION_FLOAT,       "shadow mask alpha-blend value (1.0 is fully blended, 0.0 is no mask)" },
334   { WINOPTION_SHADOW_MASK_TEXTURE";fs_shadwt(0.0-1.0)",       "aperture.png", OPTION_STRING,  "shadow mask texture name" },
335   { WINOPTION_SHADOW_MASK_WIDTH";fs_shadww",               "3.0",       OPTION_FLOAT,      "shadow mask width, in shadow mask pixels per emulated pixel" },
336   { WINOPTION_SHADOW_MASK_HEIGHT";fs_shadwh",               "3.0",       OPTION_FLOAT,      "shadow mask height, in shadow mask pixels per emulated pixel" },
337   { WINOPTION_SHADOW_MASK_USIZE";fs_shadwu(0.0-1.0)",         "0.1875",    OPTION_FLOAT,      "shadow mask texture size in U direction" },
338   { WINOPTION_SHADOW_MASK_VSIZE";fs_shadwv(0.0-1.0)",         "0.1875",    OPTION_FLOAT,      "shadow mask texture size in V direction" },
339   { WINOPTION_OVERSAMPLE_X";fs_overx(1.0-9.0)",               "1.0",         OPTION_FLOAT,       "oversample amount in screen-relative X direction, multiple" },
340   { WINOPTION_OVERSAMPLE_Y";fs_overy(1.0-9.0)",               "1.0",         OPTION_FLOAT,        "oversample amount in screen-relative Y direction, multiple" },
341   /* Beam-related values below this line*/
342   { WINOPTION_PINCUSHION_X";fs_pinx(0.0-4.0)",               "0.0",       OPTION_FLOAT,       "pincushion amount in screen-relative X direction" },
343   { WINOPTION_PINCUSHION_Y";fs_piny(0.0-4.0)",               "0.0",       OPTION_FLOAT,       "pincushion amount in screen-relative Y direction" },
344   { WINOPTION_SCANLINE_AMOUNT";fs_scanam(0.0-4.0)",          "0.0",       OPTION_FLOAT,       "overall alpha scaling value for scanlines" },
345   { WINOPTION_SCANLINE_SCALE";fs_scansc(0.0-4.0)",           "1.0",       OPTION_FLOAT,       "overall height scaling value for scanlines" },
346   { WINOPTION_SCANLINE_BRIGHT_SCALE";fs_scanbs(0.0-1.0)",    "1.0",       OPTION_FLOAT,       "overall brightness scaling value for scanlines (multiplicative)" },
347   { WINOPTION_SCANLINE_BRIGHT_OFFSET";fs_scanbo(0.0-1.0)",   "0.6",       OPTION_FLOAT,       "overall brightness offset value for scanlines (additive)" },
348   { WINOPTION_SCANLINE_OFFSET";fs_scanjt(0.0-4.0)",          "0.0",       OPTION_FLOAT,       "overall interlace jitter scaling value for scanlines" },
349   { WINOPTION_DEFOCUS_X";fs_focusx(0.0-16.0)",                "0.0",       OPTION_FLOAT,      "overall defocus scaling value in screen-relative X direction" },
350   { WINOPTION_DEFOCUS_Y";fs_focusy(0.0-16.0)",                "0.0",       OPTION_FLOAT,      "overall defocus scaling value in screen-relative Y direction" },
351   { WINOPTION_RED_CONVERGE_X";fs_redcvx(-1.0-1.0)",          "0.0",       OPTION_FLOAT,       "red convergence in screen-relative X direction" },
352   { WINOPTION_RED_CONVERGE_Y";fs_redcvy(-1.0-1.0)",          "0.0",       OPTION_FLOAT,       "red convergence in screen-relative Y direction" },
353   { WINOPTION_GREEN_CONVERGE_X";fs_grncvx(-1.0-1.0)",        "0.0",       OPTION_FLOAT,       "green convergence in screen-relative X direction" },
354   { WINOPTION_GREEN_CONVERGE_Y";fs_grncvy(-1.0-1.0)",        "0.0",       OPTION_FLOAT,       "green convergence in screen-relative Y direction" },
355   { WINOPTION_BLUE_CONVERGE_X";fs_blucvx(-1.0-1.0)",         "0.0",       OPTION_FLOAT,       "blue convergence in screen-relative X direction" },
356   { WINOPTION_BLUE_CONVERGE_Y";fs_blucvy(-1.0-1.0)",         "0.0",       OPTION_FLOAT,       "blue convergence in screen-relative Y direction" },
357   { WINOPTION_RED_RADIAL_CONVERGE_X";fs_redrcvx(-16 - 16)",   "0.0",       OPTION_FLOAT,       "red radial convergence in screen-relative X direction" },
358   { WINOPTION_RED_RADIAL_CONVERGE_Y";fs_redrcvy(-16 - 16)",   "0.0",       OPTION_FLOAT,       "red radial convergence in screen-relative Y direction" },
359   { WINOPTION_GREEN_RADIAL_CONVERGE_X";fs_grnrcvx(-16 - 16)",   "0.0",       OPTION_FLOAT,       "green radial convergence in screen-relative X direction" },
360   { WINOPTION_GREEN_RADIAL_CONVERGE_Y";fs_grnrcvy(-16 - 16)",   "0.0",       OPTION_FLOAT,       "green radial convergence in screen-relative Y direction" },
361   { WINOPTION_BLUE_RADIAL_CONVERGE_X";fs_blurcvx(-16 - 16)",   "0.0",       OPTION_FLOAT,       "blue radial convergence in screen-relative X direction" },
362   { WINOPTION_BLUE_RADIAL_CONVERGE_Y";fs_blurcvy(-16 - 16)",   "0.0",       OPTION_FLOAT,       "blue radial convergence in screen-relative Y direction" },
363   /* RGB colorspace convolution below this line */
364   { WINOPTION_RED_MATRIX_R";fs_matrr(-2.0-2.0)",              "1.0",       OPTION_FLOAT,       "red output signal generated by red input signal" },
365   { WINOPTION_RED_MATRIX_G";fs_matrg(-2.0-2.0)",              "0.0",       OPTION_FLOAT,       "red output signal generated by green input signal" },
366   { WINOPTION_RED_MATRIX_B";fs_matrb(-2.0-2.0)",              "0.0",       OPTION_FLOAT,       "red output signal generated by blue input signal" },
367   { WINOPTION_GREEN_MATRIX_R";fs_matgr(-2.0-2.0)",            "0.0",       OPTION_FLOAT,       "green output signal generated by red input signal" },
368   { WINOPTION_GREEN_MATRIX_G";fs_matgg(-2.0-2.0)",           "1.0",       OPTION_FLOAT,       "green output signal generated by green input signal" },
369   { WINOPTION_GREEN_MATRIX_B";fs_matgb(-2.0-2.0)",           "0.0",       OPTION_FLOAT,       "green output signal generated by blue input signal" },
370   { WINOPTION_BLUE_MATRIX_R";fs_matbr(-2.0-2.0)",              "0.0",       OPTION_FLOAT,       "blue output signal generated by red input signal" },
371   { WINOPTION_BLUE_MATRIX_G";fs_matbg(-2.0-2.0)",              "0.0",       OPTION_FLOAT,       "blue output signal generated by green input signal" },
372   { WINOPTION_BLUE_MATRIX_B";fs_matbb(-2.0-2.0)",              "1.0",       OPTION_FLOAT,       "blue output signal generated by blue input signal" },
373   { WINOPTION_GREEN_MATRIX_R";fs_matgr(-2.0-2.0)",            "0.0",       OPTION_FLOAT,       "green output signal generated by red input signal" },
374   { WINOPTION_GREEN_MATRIX_G";fs_matgg(-2.0-2.0)",           "1.0",       OPTION_FLOAT,       "green output signal generated by green input signal" },
375   { WINOPTION_GREEN_MATRIX_B";fs_matgb(-2.0-2.0)",           "0.0",       OPTION_FLOAT,       "green output signal generated by blue input signal" },
376   { WINOPTION_BLUE_MATRIX_R";fs_matbr(-2.0-2.0)",              "0.0",       OPTION_FLOAT,       "blue output signal generated by red input signal" },
377   { WINOPTION_BLUE_MATRIX_G";fs_matbg(-2.0-2.0)",              "0.0",       OPTION_FLOAT,       "blue output signal generated by green input signal" },
378   { WINOPTION_BLUE_MATRIX_B";fs_matbb(-2.0-2.0)",              "1.0",       OPTION_FLOAT,       "blue output signal generated by blue input signal" },
379   { WINOPTION_SATURATION";fs_sat(0.0-4.0)",                  "1.0",       OPTION_FLOAT,      "saturation scaling value" },
380   { WINOPTION_RED_OFFSET";fs_redoff(-1.0-1.0)",              "0.0",       OPTION_FLOAT,      "red signal offset value (additive)" },
381   { WINOPTION_GREEN_OFFSET";fs_grnoff(-1.0-1.0)",            "0.0",       OPTION_FLOAT,      "green signal offset value (additive)" },
382   { WINOPTION_BLUE_OFFSET";fs_bluoff(-1.0-1.0)",             "0.0",       OPTION_FLOAT,      "blue signal offset value (additive)" },
383   { WINOPTION_RED_SCALE";fs_redmul(0.0-2.0)",                "1.0",       OPTION_FLOAT,      "red signal scaling value (multiplicative)" },
384   { WINOPTION_GREEN_SCALE";fs_grnmul(0.0-2.0)",              "1.0",       OPTION_FLOAT,      "green signal scaling value (multiplicative)" },
385   { WINOPTION_BLUE_SCALE";fs_blumul(0.0-2.0)",               "1.0",       OPTION_FLOAT,      "blue signal scaling value (multiplicative)" },
386   { WINOPTION_RED_POWER";fs_redpow(0.01-32.0)",                "1.0",       OPTION_FLOAT,      "red signal power value (exponential)" },
387   { WINOPTION_GREEN_POWER";fs_grnpow(0.01-32.0)",              "1.0",       OPTION_FLOAT,      "green signal power value (exponential)" },
388   { WINOPTION_BLUE_POWER";fs_blupow(0.01-32.0)",               "1.0",       OPTION_FLOAT,      "blue signal power value (exponential)" },
389   { WINOPTION_RED_FLOOR";fs_redfl(0.0-1.0)",                 "0.0",       OPTION_FLOAT,      "red signal floor level" },
390   { WINOPTION_GREEN_FLOOR";fs_grnfl(0.0-1.0)",               "0.0",       OPTION_FLOAT,      "green signal floor level" },
391   { WINOPTION_BLUE_FLOOR";fs_blufl(0.0-1.0)",                "0.0",       OPTION_FLOAT,      "blue signal floor level" },
392   { WINOPTION_RED_PHOSPHOR";fs_redpho(0.0-1.0)",             "0.0",       OPTION_FLOAT,      "red phosphorescence decay rate (0.0 is instant, 1.0 is forever)" },
393   { WINOPTION_GREEN_PHOSPHOR";fs_grnpho(0.0-1.0)",           "0.0",       OPTION_FLOAT,      "green phosphorescence decay rate (0.0 is instant, 1.0 is forever)" },
394   { WINOPTION_BLUE_PHOSPHOR";fs_grnpho(0.0-1.0)",            "0.0",       OPTION_FLOAT,      "blue phosphorescence decay rate (0.0 is instant, 1.0 is forever)" },
395   /* NTSC simulation below this line */
396   { WINOPTION_Y_MATRIX_Y";fs_matyy(-2.0-2.0)",                 "1.0",       OPTION_FLOAT,       "Y output signal generated by Y input signal" },
397   { WINOPTION_Y_MATRIX_I";fs_matyi(-2.0-2.0)",                 "0.0",       OPTION_FLOAT,       "Y output signal generated by I input signal" },
398   { WINOPTION_Y_MATRIX_Q";fs_matyq(-2.0-2.0)",                 "0.0",       OPTION_FLOAT,       "Y output signal generated by Q input signal" },
399   { WINOPTION_I_MATRIX_Y";fs_matiy(-2.0-2.0)",                 "0.0",       OPTION_FLOAT,       "I output signal generated by Y input signal" },
400   { WINOPTION_I_MATRIX_I";fs_matii(-2.0-2.0)",                 "1.0",       OPTION_FLOAT,       "I output signal generated by I input signal" },
401   { WINOPTION_I_MATRIX_Q";fs_matiq(-2.0-2.0)",                 "0.0",       OPTION_FLOAT,       "I output signal generated by Q input signal" },
402   { WINOPTION_Q_MATRIX_Y";fs_matqy(-2.0-2.0)",                 "0.0",       OPTION_FLOAT,       "Q output signal generated by Y input signal" },
403   { WINOPTION_Q_MATRIX_I";fs_matqi(-2.0-2.0)",                 "0.0",       OPTION_FLOAT,       "Q output signal generated by I input signal" },
404   { WINOPTION_Q_MATRIX_Q";fs_matqq(-2.0-2.0)",                 "1.0",       OPTION_FLOAT,       "Q output signal generated by Q input signal" },
405   { WINOPTION_Y_SCALE";fs_yscale(-2.0-2.0)",                 "1.0",       OPTION_FLOAT,      "Y signal scaling value for NTSC colorspace convolution (multiplicative)" },
406   { WINOPTION_I_SCALE";fs_iscale(-2.0-2.0)",                 "1.0",       OPTION_FLOAT,      "I signal scaling value for NTSC colorspace convolution (multiplicative)" },
407   { WINOPTION_Q_SCALE";fs_qscale(-2.0-2.0)",                 "1.0",       OPTION_FLOAT,      "Q signal scaling value for NTSC colorspace convolution (multiplicative)" },
408   { WINOPTION_Y_OFFSET";fs_yoffs(-1.0-1.0)",                 "0.0",       OPTION_FLOAT,      "Y signal offset value for NTSC colorspace convolution (additive)" },
409   { WINOPTION_I_OFFSET";fs_ioffs(-1.0-1.0)",                 "0.0",       OPTION_FLOAT,      "I signal offset value for NTSC colorspace convolution (additive)" },
410   { WINOPTION_Q_OFFSET";fs_qoffs(-1.0-1.0)",                 "0.0",       OPTION_FLOAT,      "Q signal offset value for NTSC colorspace convolution (additive)" },
411   { WINOPTION_SUBSAMPLE_LENGTH";fs_chrsub(1.0+)",            "1.0",       OPTION_FLOAT,      "chroma signal subsampling value, in pixels" },
412   { WINOPTION_CRAWL_WIDTH";fs_crawlw(0.0-8.0)",                 "0.0",       OPTION_FLOAT,      "dot crawl width (in pixels, 1.0 upward)" },
413   { WINOPTION_CRAWL_HEIGHT";fs_crawlh(0.0-8.0)",                "2.0",       OPTION_FLOAT,      "dot crawl height (in pixels, 1.0 upward)" },
414   { WINOPTION_CRAWL_RATE";fs_crawlr(1-8)",                    "2",         OPTION_INTEGER,    "dot crawl rate (in total frames, 1 upward)" },
415   { WINOPTION_CRAWL_SKIP";fs_crawls(0-7)",                      "2",         OPTION_INTEGER,    "dot crawl frame to skip (frame index, 0 upward)" },
416   /* "Just for fun" below this line */
417   { WINOPTION_EDGE_AMOUNT";fs_edgeen(0.0-2.0)",              "1.0",       OPTION_FLOAT,      "edge-detection alpha (just for fun)" },
418   { WINOPTION_EDGE_RATIO";fs_edgert(0.0-1.0)",               "0.0",       OPTION_FLOAT,      "edge-detection to baseline texel ratio (just for fun)" },
419
329420   // per-window options
330421   { NULL,                                           NULL,       OPTION_HEADER,     "PER-WINDOW VIDEO OPTIONS" },
331422   { WINOPTION_SCREEN,                               "auto",     OPTION_STRING,     "explicit name of all screens; 'auto' here will try to make a best guess" },
src/osd/windows/winmain.h
r11559r11560
7878#define WINOPTION_D3DVERSION         "d3dversion"
7979#define WINOPTION_FILTER            "filter"
8080
81// core post-processing options
82#define WINOPTION_HLSL_ENABLE            "hlsl_enable"
83#define WINOPTION_HLSLPATH               "hlslpath"
84#define WINOPTION_SHADOW_MASK_ALPHA         "shadow_mask_alpha"
85#define WINOPTION_SHADOW_MASK_TEXTURE      "shadow_mask_texture"
86#define WINOPTION_SHADOW_MASK_WIDTH         "shadow_mask_pix_width"
87#define WINOPTION_SHADOW_MASK_HEIGHT      "shadow_mask_pix_height"
88#define WINOPTION_SHADOW_MASK_USIZE         "shadow_mask_usize"
89#define WINOPTION_SHADOW_MASK_VSIZE         "shadow_mask_vsize"
90#define WINOPTION_PINCUSHION_X            "pincushion_x"
91#define WINOPTION_PINCUSHION_Y            "pincushion_y"
92#define WINOPTION_OVERSAMPLE_X            "oversample_x"
93#define WINOPTION_OVERSAMPLE_Y            "oversample_y"
94#define WINOPTION_SCANLINE_AMOUNT         "scanline_alpha"
95#define WINOPTION_SCANLINE_SCALE         "scanline_size"
96#define WINOPTION_SCANLINE_BRIGHT_SCALE    "scanline_bright_scale"
97#define WINOPTION_SCANLINE_BRIGHT_OFFSET    "scanline_bright_offset"
98#define WINOPTION_SCANLINE_OFFSET         "scanline_jitter"
99#define WINOPTION_DEFOCUS_X               "defocus_x"
100#define WINOPTION_DEFOCUS_Y               "defocus_y"
101#define WINOPTION_RED_CONVERGE_X         "red_converge_x"
102#define WINOPTION_RED_CONVERGE_Y         "red_converge_y"
103#define WINOPTION_GREEN_CONVERGE_X         "green_converge_x"
104#define WINOPTION_GREEN_CONVERGE_Y         "green_converge_y"
105#define WINOPTION_BLUE_CONVERGE_X         "blue_converge_x"
106#define WINOPTION_BLUE_CONVERGE_Y         "blue_converge_y"
107#define WINOPTION_RED_RADIAL_CONVERGE_X      "red_radial_converge_x"
108#define WINOPTION_RED_RADIAL_CONVERGE_Y      "red_radial_converge_y"
109#define WINOPTION_GREEN_RADIAL_CONVERGE_X   "green_radial_converge_x"
110#define WINOPTION_GREEN_RADIAL_CONVERGE_Y   "green_radial_converge_y"
111#define WINOPTION_BLUE_RADIAL_CONVERGE_X   "blue_radial_converge_x"
112#define WINOPTION_BLUE_RADIAL_CONVERGE_Y   "blue_radial_converge_y"
113#define WINOPTION_RED_MATRIX_R            "red_from_r"
114#define WINOPTION_RED_MATRIX_G            "red_from_g"
115#define WINOPTION_RED_MATRIX_B            "red_from_b"
116#define WINOPTION_GREEN_MATRIX_R         "green_from_r"
117#define WINOPTION_GREEN_MATRIX_G         "green_from_g"
118#define WINOPTION_GREEN_MATRIX_B         "green_from_b"
119#define WINOPTION_BLUE_MATRIX_R            "blue_from_r"
120#define WINOPTION_BLUE_MATRIX_G            "blue_from_g"
121#define WINOPTION_BLUE_MATRIX_B            "blue_from_b"
122#define WINOPTION_Y_MATRIX_Y            "y_from_y"
123#define WINOPTION_Y_MATRIX_I            "y_from_i"
124#define WINOPTION_Y_MATRIX_Q            "y_from_q"
125#define WINOPTION_I_MATRIX_Y            "i_from_y"
126#define WINOPTION_I_MATRIX_I            "i_from_i"
127#define WINOPTION_I_MATRIX_Q            "i_from_q"
128#define WINOPTION_Q_MATRIX_Y            "q_from_y"
129#define WINOPTION_Q_MATRIX_I            "q_from_i"
130#define WINOPTION_Q_MATRIX_Q            "q_from_q"
131#define WINOPTION_RED_OFFSET            "red_offset"
132#define WINOPTION_GREEN_OFFSET            "green_offset"
133#define WINOPTION_BLUE_OFFSET            "blue_offset"
134#define WINOPTION_RED_SCALE               "red_scale"
135#define WINOPTION_GREEN_SCALE            "green_scale"
136#define WINOPTION_BLUE_SCALE            "blue_scale"
137#define WINOPTION_RED_POWER               "red_power"
138#define WINOPTION_GREEN_POWER            "green_power"
139#define WINOPTION_BLUE_POWER            "blue_power"
140#define WINOPTION_RED_FLOOR               "red_floor"
141#define WINOPTION_GREEN_FLOOR            "green_floor"
142#define WINOPTION_BLUE_FLOOR            "blue_floor"
143#define WINOPTION_SATURATION            "saturation"
144#define WINOPTION_Y_SCALE               "y_scale"
145#define WINOPTION_I_SCALE               "i_scale"
146#define WINOPTION_Q_SCALE               "q_scale"
147#define WINOPTION_Y_OFFSET               "y_offset"
148#define WINOPTION_I_OFFSET               "i_offset"
149#define WINOPTION_Q_OFFSET               "q_offset"
150#define WINOPTION_EDGE_AMOUNT            "edge_amount"
151#define WINOPTION_EDGE_RATIO            "edge_ratio"
152#define WINOPTION_SUBSAMPLE_LENGTH         "subsample_length"
153#define WINOPTION_RED_PHOSPHOR            "red_phosphor_life"
154#define WINOPTION_GREEN_PHOSPHOR         "green_phosphor_life"
155#define WINOPTION_BLUE_PHOSPHOR            "blue_phosphor_life"
156#define WINOPTION_CRAWL_WIDTH            "dot_crawl_width"
157#define WINOPTION_CRAWL_HEIGHT            "dot_crawl_height"
158#define WINOPTION_CRAWL_RATE            "dot_crawl_rate"
159#define WINOPTION_CRAWL_SKIP            "dot_crawl_skip"
160
81161// per-window options
82162#define WINOPTION_SCREEN            "screen"
83163#define WINOPTION_ASPECT            "aspect"
r11559r11560
140220   int d3d_version() const { return int_value(WINOPTION_D3DVERSION); }
141221   bool filter() const { return bool_value(WINOPTION_FILTER); }
142222
223   // core post-processing options
224   const char *screen_post_fx_dir() const { return value(WINOPTION_HLSLPATH); }
225   bool d3d_hlsl_enable() const { return bool_value(WINOPTION_HLSL_ENABLE); }
226   float screen_pincushion_x() const { return float_value(WINOPTION_PINCUSHION_X); }
227   float screen_pincushion_y() const { return float_value(WINOPTION_PINCUSHION_Y); }
228   float screen_shadow_mask_alpha() const { return float_value(WINOPTION_SHADOW_MASK_ALPHA); }
229   const char *screen_shadow_mask_texture() const { return value(WINOPTION_SHADOW_MASK_TEXTURE); }
230   float screen_shadow_mask_width() const { return float_value(WINOPTION_SHADOW_MASK_WIDTH); }
231   float screen_shadow_mask_height() const { return float_value(WINOPTION_SHADOW_MASK_HEIGHT); }
232   float screen_shadow_mask_u_size() const { return float_value(WINOPTION_SHADOW_MASK_USIZE); }
233   float screen_shadow_mask_v_size() const { return float_value(WINOPTION_SHADOW_MASK_VSIZE); }
234   float screen_shadow_width_y() const { return float_value(WINOPTION_SHADOW_MASK_HEIGHT); }
235   float screen_oversample_x() const { return float_value(WINOPTION_OVERSAMPLE_X); }
236   float screen_oversample_y() const { return float_value(WINOPTION_OVERSAMPLE_Y); }
237   float screen_scanline_amount() const { return float_value(WINOPTION_SCANLINE_AMOUNT); }
238   float screen_scanline_scale() const { return float_value(WINOPTION_SCANLINE_SCALE); }
239   float screen_scanline_bright_scale() const { return float_value(WINOPTION_SCANLINE_BRIGHT_SCALE); }
240   float screen_scanline_bright_offset() const { return float_value(WINOPTION_SCANLINE_BRIGHT_OFFSET); }
241   float screen_scanline_offset() const { return float_value(WINOPTION_SCANLINE_OFFSET); }
242   float screen_defocus_x() const { return float_value(WINOPTION_DEFOCUS_X); }
243   float screen_defocus_y() const { return float_value(WINOPTION_DEFOCUS_Y); }
244   float screen_red_converge_x() const { return float_value(WINOPTION_RED_CONVERGE_X); }
245   float screen_red_converge_y() const { return float_value(WINOPTION_RED_CONVERGE_Y); }
246   float screen_green_converge_x() const { return float_value(WINOPTION_GREEN_CONVERGE_X); }
247   float screen_green_converge_y() const { return float_value(WINOPTION_GREEN_CONVERGE_Y); }
248   float screen_blue_converge_x() const { return float_value(WINOPTION_BLUE_CONVERGE_X); }
249   float screen_blue_converge_y() const { return float_value(WINOPTION_BLUE_CONVERGE_Y); }
250   float screen_red_radial_converge_x() const { return float_value(WINOPTION_RED_RADIAL_CONVERGE_X); }
251   float screen_red_radial_converge_y() const { return float_value(WINOPTION_RED_RADIAL_CONVERGE_Y); }
252   float screen_green_radial_converge_x() const { return float_value(WINOPTION_GREEN_RADIAL_CONVERGE_X); }
253   float screen_green_radial_converge_y() const { return float_value(WINOPTION_GREEN_RADIAL_CONVERGE_Y); }
254   float screen_blue_radial_converge_x() const { return float_value(WINOPTION_BLUE_RADIAL_CONVERGE_X); }
255   float screen_blue_radial_converge_y() const { return float_value(WINOPTION_BLUE_RADIAL_CONVERGE_Y); }
256   float screen_red_from_red() const { return float_value(WINOPTION_RED_MATRIX_R); }
257   float screen_red_from_green() const { return float_value(WINOPTION_RED_MATRIX_G); }
258   float screen_red_from_blue() const { return float_value(WINOPTION_RED_MATRIX_B); }
259   float screen_green_from_red() const { return float_value(WINOPTION_GREEN_MATRIX_R); }
260   float screen_green_from_green() const { return float_value(WINOPTION_GREEN_MATRIX_G); }
261   float screen_green_from_blue() const { return float_value(WINOPTION_GREEN_MATRIX_B); }
262   float screen_blue_from_red() const { return float_value(WINOPTION_BLUE_MATRIX_R); }
263   float screen_blue_from_green() const { return float_value(WINOPTION_BLUE_MATRIX_G); }
264   float screen_blue_from_blue() const { return float_value(WINOPTION_BLUE_MATRIX_B); }
265   float screen_y_from_y() const { return float_value(WINOPTION_Y_MATRIX_Y); }
266   float screen_y_from_i() const { return float_value(WINOPTION_Y_MATRIX_I); }
267   float screen_y_from_q() const { return float_value(WINOPTION_Y_MATRIX_Q); }
268   float screen_i_from_y() const { return float_value(WINOPTION_I_MATRIX_Y); }
269   float screen_i_from_i() const { return float_value(WINOPTION_I_MATRIX_I); }
270   float screen_i_from_q() const { return float_value(WINOPTION_I_MATRIX_Q); }
271   float screen_q_from_y() const { return float_value(WINOPTION_Q_MATRIX_Y); }
272   float screen_q_from_i() const { return float_value(WINOPTION_Q_MATRIX_I); }
273   float screen_q_from_q() const { return float_value(WINOPTION_Q_MATRIX_Q); }
274   float screen_red_offset() const { return float_value(WINOPTION_RED_OFFSET); }
275   float screen_green_offset() const { return float_value(WINOPTION_GREEN_OFFSET); }
276   float screen_blue_offset() const { return float_value(WINOPTION_BLUE_OFFSET); }
277   float screen_red_scale() const { return float_value(WINOPTION_RED_SCALE); }
278   float screen_green_scale() const { return float_value(WINOPTION_GREEN_SCALE); }
279   float screen_blue_scale() const { return float_value(WINOPTION_BLUE_SCALE); }
280   float screen_red_power() const { return float_value(WINOPTION_RED_POWER); }
281   float screen_green_power() const { return float_value(WINOPTION_GREEN_POWER); }
282   float screen_blue_power() const { return float_value(WINOPTION_BLUE_POWER); }
283   float screen_red_floor() const { return float_value(WINOPTION_RED_FLOOR); }
284   float screen_green_floor() const { return float_value(WINOPTION_GREEN_FLOOR); }
285   float screen_blue_floor() const { return float_value(WINOPTION_BLUE_FLOOR); }
286   float screen_saturation() const { return float_value(WINOPTION_SATURATION); }
287   float screen_y_scale() const { return float_value(WINOPTION_Y_SCALE); }
288   float screen_i_scale() const { return float_value(WINOPTION_I_SCALE); }
289   float screen_q_scale() const { return float_value(WINOPTION_Q_SCALE); }
290   float screen_y_offset() const { return float_value(WINOPTION_Y_OFFSET); }
291   float screen_i_offset() const { return float_value(WINOPTION_I_OFFSET); }
292   float screen_q_offset() const { return float_value(WINOPTION_Q_OFFSET); }
293   float screen_edge_amount() const { return float_value(WINOPTION_EDGE_AMOUNT); }
294   float screen_edge_ratio() const { return float_value(WINOPTION_EDGE_RATIO); }
295   float screen_chroma_subsample_length() const { return float_value(WINOPTION_SUBSAMPLE_LENGTH); }
296   float screen_red_phosphor() const { return float_value(WINOPTION_RED_PHOSPHOR); }
297   float screen_green_phosphor() const { return float_value(WINOPTION_GREEN_PHOSPHOR); }
298   float screen_blue_phosphor() const { return float_value(WINOPTION_BLUE_PHOSPHOR); }
299   float screen_dot_crawl_width() const { return float_value(WINOPTION_CRAWL_WIDTH); }
300   float screen_dot_crawl_height() const { return float_value(WINOPTION_CRAWL_HEIGHT); }
301   int screen_dot_crawl_rate() const { return int_value(WINOPTION_CRAWL_RATE); }
302   int screen_dot_crawl_skip() const { return int_value(WINOPTION_CRAWL_SKIP); }
303
143304   // per-window options
144305   const char *screen() const { return value(WINOPTION_SCREEN); }
145306   const char *aspect() const { return value(WINOPTION_ASPECT); }
src/osd/windows/drawd3d.c
r11559r11560
5353#include <tchar.h>
5454#include <mmsystem.h>
5555#include <d3d9.h>
56#include <d3dx9.h>
5657#undef interface
5758
5859// MAME headers
r11559r11560
8586
8687#define ENABLE_BORDER_PIX   (1)
8788
88#define VERTEX_FORMAT      (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)
89#define VERTEX_BASE_FORMAT   (D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEX2)
8990#define VERTEX_BUFFER_SIZE   (2048*4)
9091
9192enum
r11559r11560
125126   int                  yborderpix;               // number of border pixels in Y
126127   int                  xprescale;               // what is our X prescale factor?
127128   int                  yprescale;               // what is our Y prescale factor?
129   int                  cur_frame;               // what is our current frame?
128130   d3d_texture *         d3dtex;                  // Direct3D texture pointer
129131   d3d_surface *         d3dsurface;               // Direct3D offscreen plain surface pointer
132   d3d_surface *         d3dtarget0;               // Direct3D render target surface pointer (pass 0, if necessary)
133   d3d_surface *         d3dtarget1;               // Direct3D render target surface pointer (pass 2, if necessary)
134   d3d_surface *         d3dtarget2;               // Direct3D render target surface pointer (pass 3, if necessary)
135   d3d_texture *         d3dtexture0;            // Direct3D render target texture pointer (pass 0, if necessary)
136   d3d_texture *         d3dtexture1;            // Direct3D render target texture pointer (pass 2, if necessary)
137   d3d_texture *         d3dtexture2;            // Direct3D render target texture pointer (pass 3, if necessary)
130138   d3d_texture *         d3dfinaltex;            // Direct3D final (post-scaled) texture
131139};
132140
r11559r11560
149157struct _d3d_vertex
150158{
151159   float               x, y, z;               // X,Y,Z coordinates
152   float               rhw;                  // 1/W coordinate
160   float               rhw;                  // RHW when no HLSL, padding when HLSL
153161   D3DCOLOR            color;                  // diffuse color
154162   float               u0, v0;                  // texture stage 0 coordinates
163   float               uv_stretch, pad;         // UV stretch (used by HLSL)
155164};
156165
157166
r11559r11560
164173   int                  refresh;               // current refresh rate
165174   int                  create_error_count;         // number of consecutive create errors
166175
176   win_window_info *      window;                  // current window info
177
167178   d3d_device *         device;                  // pointer to the Direct3DDevice object
168179   int                  gamma_supported;         // is full screen gamma supported?
169180   d3d_present_parameters   presentation;            // set of presentation parameters
r11559r11560
174185   d3d_vertex *         lockedbuf;               // pointer to the locked vertex buffer
175186   int                  numverts;               // number of accumulated vertices
176187
188   d3d_effect *         effect;                  // pointer to the current effect object
189   d3d_effect *         post_effect;            // pointer to the current post-effect object
190   d3d_effect *         pincushion_effect;         // pointer to the current pincushion-effect object
191   d3d_effect *         focus_effect;            // pointer to the current focus-effect object
192   d3d_effect *         phosphor_effect;         // pointer to the current phosphor-effect object
193
177194   poly_info            poly[VERTEX_BUFFER_SIZE / 3];// array to hold polygons as they are created
178195   int                  numpolys;               // number of accumulated polygons
179196
r11559r11560
191208   DWORD               texture_max_height;         // texture maximum height
192209
193210   texture_info *         last_texture;            // previous texture
211   UINT32               last_texture_flags;         // previous texture flags
194212   int                  last_blendenable;         // previous blendmode
195213   int                  last_blendop;            // previous blendmode
196214   int                  last_blendsrc;            // previous blendmode
r11559r11560
201219
202220   bitmap_t *            vector_bitmap;            // experimental: bitmap for vectors
203221   texture_info *         vector_texture;            // experimental: texture for vectors
222
223   bitmap_t *            default_bitmap;            // experimental: default bitmap
224   texture_info *         default_texture;         // experimental: default texture
225
226   bool               hlsl_enable;            // experimental: HLSL enable flag
227   d3d_surface *         last_d3dtarget[9];         // Direct3D render target surface pointer for each screen's previous frame
228   d3d_texture *         last_d3dtexture[9];         // Direct3D render target texture pointer for each screen's previous frame
229   float               oversample_x;            // experimental: render target oversampling factor (width) for shader prettification
230   float               oversample_y;            // experimental: render target oversampling factor (height) for shader prettification
231   bitmap_t *            shadow_bitmap;            // experimental: shadow mask bitmap for post-processing shader
232   texture_info *         shadow_texture;            // experimental: shadow mask texture for post-processing shader
233   int                  registered_targets;         // Number of registered HLSL targets (i.e., screens)
204234};
205235
206236
r11559r11560
322352   if (texture != d3d->last_texture)
323353   {
324354      d3d->last_texture = texture;
355      d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags);
325356      result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? NULL : texture->d3dfinaltex);
357      if(d3d->hlsl_enable && d3d->effect != NULL)
358      {
359         (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
360         (*d3dintf->effect.set_texture)(d3d->post_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
361         (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
362      }
326363      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
327364   }
328365}
r11559r11560
338375      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
339376      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
340377      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
378      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
379      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
380      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
381      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
341382   }
342383}
343384
r11559r11560
352393      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
353394      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
354395      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
396      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
397      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
398      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
399      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
355400   }
356401}
357402
r11559r11560
364409      d3d->last_modmode = modmode;
365410      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, modmode);
366411      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
412      result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_COLOROP, modmode);
413      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
367414   }
368415}
369416
r11559r11560
447494static int device_create_resources(d3d_info *d3d);
448495static void device_delete(d3d_info *d3d);
449496static void device_delete_resources(d3d_info *d3d);
450static int device_verify_caps(d3d_info *d3d);
497static int device_verify_caps(d3d_info *d3d, win_window_info *window);
451498static int device_test_cooperative(d3d_info *d3d);
452499
453500// video modes
r11559r11560
534581   // allocate memory for our structures
535582   d3d = global_alloc_clear(d3d_info);
536583   window->drawdata = d3d;
584   d3d->window = window;
537585
538586   // experimental: load a PNG to use for vector rendering; it is treated
539587   // as a brightness map
r11559r11560
545593      d3d->vector_bitmap = render_load_png(file, NULL, "vector.png", d3d->vector_bitmap, NULL);
546594   }
547595
596   d3d->shadow_texture = NULL;
597
598   d3d->default_bitmap = auto_bitmap_alloc(window->machine(), 8, 8, BITMAP_FORMAT_RGB32);
599   bitmap_fill(d3d->default_bitmap, NULL, MAKE_ARGB(0xff,0xff,0xff,0xff));
600
548601   // configure the adapter for the mode we want
549602   if (config_adapter_mode(window))
550603      goto error;
r11559r11560
580633
581634   // experimental: free the vector PNG
582635   global_free(d3d->vector_bitmap);
636   d3d->vector_bitmap = NULL;
583637
638   // experimental: free the shadow PNG
639   if(d3d->hlsl_enable)
640   {
641      global_free(d3d->shadow_bitmap);
642      d3d->shadow_bitmap = NULL;
643   }
644
584645   // free the memory in the window
585646   global_free(d3d);
586647   window->drawdata = NULL;
r11559r11560
618679   render_primitive *prim;
619680   HRESULT result;
620681
682   // if we're in the middle of resizing, leave things alone
683   if (window->resize_state == RESIZE_STATE_RESIZING)
684      return 0;
685
621686   // if we haven't been created, just punt
622687   if (d3d == NULL)
623688      return 1;
r11559r11560
644709
645710mtlog_add("drawd3d_window_draw: begin");
646711
712   result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0);
713   if(result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
714
647715   // first update any textures
648716   window->primlist->acquire_lock();
649717   for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
r11559r11560
692760   result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0);
693761mtlog_add("drawd3d_window_draw: present end");
694762   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device present call\n", (int)result);
763
695764   return 0;
696765}
697766
r11559r11560
712781      device_delete(d3d);
713782
714783   // verify the caps
715   verify = device_verify_caps(d3d);
784   verify = device_verify_caps(d3d, window);
716785   if (verify == 2)
717786   {
718787      mame_printf_error("Error: Device does not meet minimum requirements for Direct3D rendering\n");
r11559r11560
778847   d3d->presentation.FullScreen_RefreshRateInHz   = d3d->refresh;
779848   d3d->presentation.PresentationInterval         = ((video_config.triplebuf && window->fullscreen) || video_config.waitvsync || video_config.syncrefresh) ?
780849                                          D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
850
781851   // create the D3D device
782852   result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd,
783853               D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device);
r11559r11560
829899      }
830900   }
831901
902   // experimental: initialize some more things if we're using HLSL
903   if(d3d->hlsl_enable)
904   {
905      const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir();
906      char primary_name_cstr[1024];
907      char post_name_cstr[1024];
908      char pincushion_name_cstr[1024];
909      char phosphor_name_cstr[1024];
910      char focus_name_cstr[1024];
911
912      sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir);
913      TCHAR *primary_name = tstring_from_utf8(primary_name_cstr);
914
915      sprintf(post_name_cstr, "%s\\post.fx", fx_dir);
916      TCHAR *post_name = tstring_from_utf8(post_name_cstr);
917
918      sprintf(pincushion_name_cstr, "%s\\pincushion.fx", fx_dir);
919      TCHAR *pincushion_name = tstring_from_utf8(pincushion_name_cstr);
920
921      sprintf(phosphor_name_cstr, "%s\\phosphor.fx", fx_dir);
922      TCHAR *phosphor_name = tstring_from_utf8(phosphor_name_cstr);
923
924      sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir);
925      TCHAR *focus_name = tstring_from_utf8(focus_name_cstr);
926
927      // create the regular shader
928      result = (*d3dintf->device.create_effect)(d3d->device, primary_name, &d3d->effect);
929
930      // create the post-processing shader
931      result = (*d3dintf->device.create_effect)(d3d->device, post_name, &d3d->post_effect);
932
933      // create the pincushion shader
934      result = (*d3dintf->device.create_effect)(d3d->device, pincushion_name, &d3d->pincushion_effect);
935
936      // create the phosphor shader
937      result = (*d3dintf->device.create_effect)(d3d->device, phosphor_name, &d3d->phosphor_effect);
938
939      // create the focus shader
940      result = (*d3dintf->device.create_effect)(d3d->device, focus_name, &d3d->focus_effect);
941
942      if (primary_name)
943         osd_free(primary_name);
944      if (post_name)
945         osd_free(post_name);
946      if (pincushion_name)
947         osd_free(pincushion_name);
948      if (phosphor_name)
949         osd_free(phosphor_name);
950      if (focus_name)
951         osd_free(focus_name);
952   }
953
832954   return device_create_resources(d3d);
833955}
834956
r11559r11560
846968   result = (*d3dintf->device.create_vertex_buffer)(d3d->device,
847969            sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE,
848970            D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY,
849            VERTEX_FORMAT, D3DPOOL_DEFAULT, &d3d->vertexbuf);
971            VERTEX_BASE_FORMAT | (d3d->hlsl_enable ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf);
850972   if (result != D3D_OK)
851973   {
852974      mame_printf_error("Error creating vertex buffer (%08X)", (UINT32)result);
r11559r11560
854976   }
855977
856978   // set the vertex format
857   result = (*d3dintf->device.set_vertex_shader)(d3d->device, (D3DFORMAT)VERTEX_FORMAT);
979   result = (*d3dintf->device.set_vertex_format)(d3d->device, (D3DFORMAT)(VERTEX_BASE_FORMAT | (d3d->hlsl_enable ? D3DFVF_XYZW : D3DFVF_XYZRHW)));
858980   if (result != D3D_OK)
859981   {
860      mame_printf_error("Error setting vertex shader (%08X)", (UINT32)result);
982      mame_printf_error("Error setting vertex format (%08X)", (UINT32)result);
861983      return 1;
862984   }
863985
r11559r11560
8831005
8841006   result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
8851007   result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
1008   result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
1009   result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
8861010
8871011   // reset the local states to force updates
8881012   reset_render_states(d3d);
8891013
8901014   // clear the buffer
891   result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1015   result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0);
8921016   result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0);
8931017
8941018   // experimental: if we have a vector bitmap, create a texture for it
r11559r11560
9081032      d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
9091033   }
9101034
1035   // experimental: initialize some more things if we're using HLSL
1036   if(d3d->hlsl_enable)
1037   {
1038      // experimental: create a default bitmap for our shader
1039      if (d3d->default_bitmap != NULL)
1040      {
1041         render_texinfo texture;
1042
1043         // fake in the basic data so it looks like it came from render.c
1044         texture.base = d3d->default_bitmap->base;
1045         texture.rowpixels = d3d->default_bitmap->rowpixels;
1046         texture.width = d3d->default_bitmap->width;
1047         texture.height = d3d->default_bitmap->height;
1048         texture.palette = NULL;
1049         texture.seqid = 0;
1050
1051         // now create it
1052         d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
1053      }
1054
1055      // experimental: load a PNG to use for vector rendering; it is treated
1056      // as a brightness map
1057      emu_file file(d3d->window->machine().options().art_path(), OPEN_FLAG_READ);
1058      d3d->shadow_bitmap = render_load_png(file, NULL, downcast<windows_options &>(d3d->window->machine().options()).screen_shadow_mask_texture(), NULL, NULL);
1059
1060      // experimental: if we have a shadow bitmap, create a texture for it
1061      if (d3d->shadow_bitmap != NULL)
1062      {
1063         render_texinfo texture;
1064
1065         // fake in the basic data so it looks like it came from render.c
1066         texture.base = d3d->shadow_bitmap->base;
1067         texture.rowpixels = d3d->shadow_bitmap->rowpixels;
1068         texture.width = d3d->shadow_bitmap->width;
1069         texture.height = d3d->shadow_bitmap->height;
1070         texture.palette = NULL;
1071         texture.seqid = 0;
1072
1073         // now create it
1074         d3d->shadow_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
1075      }
1076   }
1077
9111078   return 0;
9121079}
9131080
r11559r11560
9471114         (*d3dintf->texture.release)(tex->d3dtex);
9481115      if (tex->d3dsurface != NULL)
9491116         (*d3dintf->surface.release)(tex->d3dsurface);
1117      if (tex->d3dtexture0 != NULL)
1118         (*d3dintf->texture.release)(tex->d3dtexture0);
1119      if (tex->d3dtexture1 != NULL)
1120         (*d3dintf->texture.release)(tex->d3dtexture1);
1121      if (tex->d3dtexture2 != NULL)
1122         (*d3dintf->texture.release)(tex->d3dtexture2);
1123      if (tex->d3dtarget0 != NULL)
1124         (*d3dintf->surface.release)(tex->d3dtarget0);
1125      if (tex->d3dtarget1 != NULL)
1126         (*d3dintf->surface.release)(tex->d3dtarget1);
1127      if (tex->d3dtarget2 != NULL)
1128         (*d3dintf->surface.release)(tex->d3dtarget2);
9501129      global_free(tex);
9511130   }
9521131
r11559r11560
9541133   if (d3d->vertexbuf != NULL)
9551134      (*d3dintf->vertexbuf.release)(d3d->vertexbuf);
9561135   d3d->vertexbuf = NULL;
1136
1137   global_free(d3d->default_texture);
1138
1139   // free our effects
1140   if(d3d->effect != NULL)
1141   {
1142      (*d3dintf->effect.release)(d3d->effect);
1143      d3d->effect = NULL;
1144   }
1145   if(d3d->post_effect != NULL)
1146   {
1147      (*d3dintf->effect.release)(d3d->post_effect);
1148      d3d->post_effect = NULL;
1149   }
1150   if(d3d->pincushion_effect != NULL)
1151   {
1152      (*d3dintf->effect.release)(d3d->pincushion_effect);
1153      d3d->pincushion_effect = NULL;
1154   }
1155   if(d3d->phosphor_effect != NULL)
1156   {
1157      (*d3dintf->effect.release)(d3d->phosphor_effect);
1158      d3d->phosphor_effect = NULL;
1159   }
1160   if(d3d->focus_effect != NULL)
1161   {
1162      (*d3dintf->effect.release)(d3d->focus_effect);
1163      d3d->focus_effect = NULL;
1164   }
1165
1166   for(int index = 0; index < 9; index++)
1167   {
1168      if(d3d->last_d3dtexture[index] != NULL)
1169      {
1170         (*d3dintf->texture.release)(d3d->last_d3dtexture[index]);
1171         d3d->last_d3dtexture[index] = NULL;
1172      }
1173      if(d3d->last_d3dtarget[index] != NULL)
1174      {
1175         (*d3dintf->surface.release)(d3d->last_d3dtarget[index]);
1176         d3d->last_d3dtarget[index] = NULL;
1177      }
1178   }
1179
1180   d3d->registered_targets = 0;
1181
1182   if(d3d->shadow_texture != NULL)
1183   {
1184      global_free(d3d->shadow_texture);
1185      d3d->shadow_texture = NULL;
1186   }
9571187}
9581188
9591189
r11559r11560
9621192//  device_verify_caps
9631193//============================================================
9641194
965static int device_verify_caps(d3d_info *d3d)
1195static int device_verify_caps(d3d_info *d3d, win_window_info *window)
9661196{
9671197   int retval = 0;
9681198   HRESULT result;
r11559r11560
9781208   result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_HEIGHT, &d3d->texture_max_height);
9791209   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
9801210
1211   d3d->hlsl_enable = downcast<windows_options &>(window->machine().options()).d3d_hlsl_enable() && d3dintf->post_fx_available;
1212   result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
1213   if (result != D3D_OK) mame_printf_verbose("Direct3D Error %08X during get_caps_dword call\n", (int)result);
1214   if(tempcaps < 512 && d3d->hlsl_enable)
1215   {
1216      mame_printf_verbose("Direct3D: Warning - Device does not support Pixel Shader 3.0, falling back to non-PS rendering\n");
1217      d3d->hlsl_enable = false;
1218   }
1219
9811220   // verify presentation capabilities
9821221   result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps);
9831222   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
r11559r11560
14741713
14751714         vertex[3].u0 = d3d->vector_texture->ustop;
14761715         vertex[3].v0 = d3d->vector_texture->vstop;
1716
1717         vertex[0].uv_stretch = 1.0f;
1718         vertex[1].uv_stretch = 1.0f;
1719         vertex[2].uv_stretch = 1.0f;
1720         vertex[3].uv_stretch = 1.0f;
14771721      }
1722      else if(d3d->default_texture != NULL)
1723      {
1724         vertex[0].u0 = d3d->default_texture->ustart;
1725         vertex[0].v0 = d3d->default_texture->vstart;
14781726
1727         vertex[2].u0 = d3d->default_texture->ustart;
1728         vertex[2].v0 = d3d->default_texture->vstart;
1729
1730         vertex[1].u0 = d3d->default_texture->ustart;
1731         vertex[1].v0 = d3d->default_texture->vstart;
1732
1733         vertex[3].u0 = d3d->default_texture->ustart;
1734         vertex[3].v0 = d3d->default_texture->vstart;
1735
1736         vertex[0].uv_stretch = 0.0f;
1737         vertex[1].uv_stretch = 0.0f;
1738         vertex[2].uv_stretch = 0.0f;
1739         vertex[3].uv_stretch = 0.0f;
1740      }
1741      else
1742      {
1743         vertex[0].uv_stretch = 0.0f;
1744         vertex[1].uv_stretch = 0.0f;
1745         vertex[2].uv_stretch = 0.0f;
1746         vertex[3].uv_stretch = 0.0f;
1747      }
1748
14791749      // set the color, Z parameters to standard values
14801750      for (i = 0; i < 4; i++)
14811751      {
r11559r11560
15101780   poly_info *poly;
15111781   int i;
15121782
1783   texture = texture != NULL ? texture : d3d->default_texture;
1784
15131785   // get a pointer to the vertex buffer
1514   vertex = primitive_alloc(d3d, 4);
1786   vertex = primitive_alloc(d3d, 6);
15151787   if (vertex == NULL)
15161788      return;
15171789
r11559r11560
15221794   vertex[1].y = prim->bounds.y0 - 0.5f;
15231795   vertex[2].x = prim->bounds.x0 - 0.5f;
15241796   vertex[2].y = prim->bounds.y1 - 0.5f;
1525   vertex[3].x = prim->bounds.x1 - 0.5f;
1526   vertex[3].y = prim->bounds.y1 - 0.5f;
15271797
1798   vertex[3].x = vertex[1].x;
1799   vertex[3].y = vertex[1].y;
1800   vertex[4].x = vertex[2].x;
1801   vertex[4].y = vertex[2].y;
1802   vertex[5].x = prim->bounds.x1 - 0.5f;
1803   vertex[5].y = prim->bounds.y1 - 0.5f;
1804
15281805   // set the texture coordinates
1529   if (texture != NULL)
1806   if(texture != NULL)
15301807   {
15311808      float du = texture->ustop - texture->ustart;
15321809      float dv = texture->vstop - texture->vstart;
r11559r11560
15361813      vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v;
15371814      vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u;
15381815      vertex[2].v0 = texture->vstart + dv * prim->texcoords.bl.v;
1539      vertex[3].u0 = texture->ustart + du * prim->texcoords.br.u;
1540      vertex[3].v0 = texture->vstart + dv * prim->texcoords.br.v;
1816
1817      vertex[3].u0 = texture->ustart + du * prim->texcoords.tr.u;
1818      vertex[3].v0 = texture->vstart + dv * prim->texcoords.tr.v;
1819      vertex[4].u0 = texture->ustart + du * prim->texcoords.bl.u;
1820      vertex[4].v0 = texture->vstart + dv * prim->texcoords.bl.v;
1821      vertex[5].u0 = texture->ustart + du * prim->texcoords.br.u;
1822      vertex[5].v0 = texture->vstart + dv * prim->texcoords.br.v;
1823
1824      vertex[0].uv_stretch = 1.0f;
1825      vertex[1].uv_stretch = 1.0f;
1826      vertex[2].uv_stretch = 1.0f;
1827      vertex[3].uv_stretch = 1.0f;
1828      vertex[4].uv_stretch = 1.0f;
1829      vertex[5].uv_stretch = 1.0f;
15411830   }
1831   else
1832   {
1833      vertex[0].uv_stretch = 1.0f;
1834      vertex[1].uv_stretch = 1.0f;
1835      vertex[2].uv_stretch = 1.0f;
1836      vertex[3].uv_stretch = 1.0f;
1837      vertex[4].uv_stretch = 1.0f;
1838      vertex[5].uv_stretch = 1.0f;
1839   }
15421840
15431841   // determine the color, allowing for over modulation
15441842   r = (INT32)(prim->color.r * 255.0f);
r11559r11560
15691867   color = D3DCOLOR_ARGB(a, r, g, b);
15701868
15711869   // set the color, Z parameters to standard values
1572   for (i = 0; i < 4; i++)
1870   for (i = 0; i < 6; i++)
15731871   {
15741872      vertex[i].z = 0.0f;
15751873      vertex[i].rhw = 1.0f;
r11559r11560
15781876
15791877   // now add a polygon entry
15801878   poly = &d3d->poly[d3d->numpolys++];
1581   poly->type = D3DPT_TRIANGLESTRIP;
1879   poly->type = D3DPT_TRIANGLELIST;
15821880   poly->count = 2;
1583   poly->numverts = 4;
1881   poly->numverts = 6;
15841882   poly->flags = prim->flags;
15851883   poly->modmode = modmode;
15861884   poly->texture = texture;
r11559r11560
16431941   result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex));
16441942   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result);
16451943
1944   d3d_effect *curr_effect = d3d->effect;
1945
1946   if(d3d->hlsl_enable)
1947   {
1948      (*d3dintf->effect.set_technique)(d3d->effect, "TestTechnique");
1949      (*d3dintf->effect.set_technique)(d3d->post_effect, "TestTechnique");
1950      (*d3dintf->effect.set_technique)(d3d->pincushion_effect, "TestTechnique");
1951      (*d3dintf->effect.set_technique)(d3d->phosphor_effect, "TestTechnique");
1952      (*d3dintf->effect.set_technique)(d3d->focus_effect, "TestTechnique");
1953   }
1954
1955   d3d_surface *backbuffer;
1956
1957   // first remember the original render target in case we need to set a new one
1958   result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer);
1959   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
1960
1961   windows_options &options = downcast<windows_options &>(d3d->window->machine().options());
1962
1963   int cur_render_screen = 0;
16461964   // now do the polys
16471965   for (polynum = vertnum = 0; polynum < d3d->numpolys; polynum++)
16481966   {
r11559r11560
16611979         set_filter(d3d, newfilter);
16621980         set_wrap(d3d, PRIMFLAG_GET_TEXWRAP(poly->flags));
16631981         set_modmode(d3d, poly->modmode);
1982
1983         if(d3d->hlsl_enable)
1984         {
1985            if(PRIMFLAG_GET_TEXSHADE(d3d->last_texture_flags))
1986            {
1987               curr_effect = d3d->pincushion_effect;
1988            }
1989            else if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags))
1990            {
1991               curr_effect = d3d->post_effect;
1992
1993               (*d3dintf->effect.set_texture)(curr_effect, "Shadow", d3d->shadow_texture == NULL ? NULL : d3d->shadow_texture->d3dfinaltex);
1994               (*d3dintf->effect.set_float)(curr_effect, "UseShadow", d3d->shadow_texture == NULL ? 0.0f : 1.0f);
1995               (*d3dintf->effect.set_float)(curr_effect, "ShadowBrightness", (float)options.screen_shadow_mask_alpha());
1996               (*d3dintf->effect.set_float)(curr_effect, "ShadowPixelSizeX", (float)options.screen_shadow_mask_width());
1997               (*d3dintf->effect.set_float)(curr_effect, "ShadowPixelSizeY", (float)options.screen_shadow_mask_height());
1998               (*d3dintf->effect.set_float)(curr_effect, "ShadowU", (float)options.screen_shadow_mask_u_size());
1999               (*d3dintf->effect.set_float)(curr_effect, "ShadowV", (float)options.screen_shadow_mask_v_size());
2000               (*d3dintf->effect.set_float)(curr_effect, "ShadowWidth", d3d->shadow_texture == NULL ? 1.0f : (float)d3d->shadow_texture->rawwidth);
2001               (*d3dintf->effect.set_float)(curr_effect, "ShadowHeight", d3d->shadow_texture == NULL ? 1.0f : (float)d3d->shadow_texture->rawheight);
2002               (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f);
2003               (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f);
2004               (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f);
2005               (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f);
2006               (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
2007               (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
2008               (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f);
2009               (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountX", (float)options.screen_pincushion_x());
2010               (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountY", (float)options.screen_pincushion_y());
2011               (*d3dintf->effect.set_float)(curr_effect, "ScanlineAmount", (float)options.screen_scanline_amount());
2012               (*d3dintf->effect.set_float)(curr_effect, "ScanlineScale", (float)options.screen_scanline_scale());
2013               (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightScale", (float)options.screen_scanline_bright_scale());
2014               (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightOffset", (float)options.screen_scanline_bright_offset());
2015               (*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture != NULL && poly->texture->cur_frame == 0) ? 0.0f : (float)options.screen_scanline_offset());
2016               (*d3dintf->effect.set_float)(curr_effect, "RedConvergeX", (float)options.screen_red_converge_x());
2017               (*d3dintf->effect.set_float)(curr_effect, "RedConvergeY", (float)options.screen_red_converge_y());
2018               (*d3dintf->effect.set_float)(curr_effect, "GrnConvergeX", (float)options.screen_green_converge_x());
2019               (*d3dintf->effect.set_float)(curr_effect, "GrnConvergeY", (float)options.screen_green_converge_y());
2020               (*d3dintf->effect.set_float)(curr_effect, "BluConvergeX", (float)options.screen_blue_converge_x());
2021               (*d3dintf->effect.set_float)(curr_effect, "BluConvergeY", (float)options.screen_blue_converge_y());
2022               (*d3dintf->effect.set_float)(curr_effect, "RedRadialConvergeX", (float)options.screen_red_radial_converge_x());
2023               (*d3dintf->effect.set_float)(curr_effect, "RedRadialConvergeY", (float)options.screen_red_radial_converge_y());
2024               (*d3dintf->effect.set_float)(curr_effect, "GrnRadialConvergeX", (float)options.screen_green_radial_converge_x());
2025               (*d3dintf->effect.set_float)(curr_effect, "GrnRadialConvergeY", (float)options.screen_green_radial_converge_y());
2026               (*d3dintf->effect.set_float)(curr_effect, "BluRadialConvergeX", (float)options.screen_blue_radial_converge_x());
2027               (*d3dintf->effect.set_float)(curr_effect, "BluRadialConvergeY", (float)options.screen_blue_radial_converge_y());
2028               (*d3dintf->effect.set_float)(curr_effect, "RedFromRed", (float)options.screen_red_from_red());
2029               (*d3dintf->effect.set_float)(curr_effect, "RedFromGrn", (float)options.screen_red_from_green());
2030               (*d3dintf->effect.set_float)(curr_effect, "RedFromBlu", (float)options.screen_red_from_blue());
2031               (*d3dintf->effect.set_float)(curr_effect, "GrnFromRed", (float)options.screen_green_from_red());
2032               (*d3dintf->effect.set_float)(curr_effect, "GrnFromGrn", (float)options.screen_green_from_green());
2033               (*d3dintf->effect.set_float)(curr_effect, "GrnFromBlu", (float)options.screen_green_from_blue());
2034               (*d3dintf->effect.set_float)(curr_effect, "BluFromRed", (float)options.screen_blue_from_red());
2035               (*d3dintf->effect.set_float)(curr_effect, "BluFromGrn", (float)options.screen_blue_from_green());
2036               (*d3dintf->effect.set_float)(curr_effect, "BluFromBlu", (float)options.screen_blue_from_blue());
2037               (*d3dintf->effect.set_float)(curr_effect, "YfromY", (float)options.screen_y_from_y());
2038               (*d3dintf->effect.set_float)(curr_effect, "YfromI", (float)options.screen_y_from_i());
2039               (*d3dintf->effect.set_float)(curr_effect, "YfromQ", (float)options.screen_y_from_q());
2040               (*d3dintf->effect.set_float)(curr_effect, "IfromY", (float)options.screen_i_from_y());
2041               (*d3dintf->effect.set_float)(curr_effect, "IfromI", (float)options.screen_i_from_i());
2042               (*d3dintf->effect.set_float)(curr_effect, "IfromQ", (float)options.screen_i_from_q());
2043               (*d3dintf->effect.set_float)(curr_effect, "QfromY", (float)options.screen_q_from_y());
2044               (*d3dintf->effect.set_float)(curr_effect, "QfromI", (float)options.screen_q_from_i());
2045               (*d3dintf->effect.set_float)(curr_effect, "QfromQ", (float)options.screen_q_from_q());
2046               (*d3dintf->effect.set_float)(curr_effect, "RedOffset", (float)options.screen_red_offset());
2047               (*d3dintf->effect.set_float)(curr_effect, "GrnOffset", (float)options.screen_green_offset());
2048               (*d3dintf->effect.set_float)(curr_effect, "BluOffset", (float)options.screen_blue_offset());
2049               (*d3dintf->effect.set_float)(curr_effect, "RedScale", (float)options.screen_red_scale());
2050               (*d3dintf->effect.set_float)(curr_effect, "GrnScale", (float)options.screen_green_scale());
2051               (*d3dintf->effect.set_float)(curr_effect, "BluScale", (float)options.screen_blue_scale());
2052               (*d3dintf->effect.set_float)(curr_effect, "RedPower", (float)options.screen_red_power());
2053               (*d3dintf->effect.set_float)(curr_effect, "GrnPower", (float)options.screen_green_power());
2054               (*d3dintf->effect.set_float)(curr_effect, "BluPower", (float)options.screen_blue_power());
2055               (*d3dintf->effect.set_float)(curr_effect, "RedFloor", (float)options.screen_red_floor());
2056               (*d3dintf->effect.set_float)(curr_effect, "GrnFloor", (float)options.screen_green_floor());
2057               (*d3dintf->effect.set_float)(curr_effect, "BluFloor", (float)options.screen_blue_floor());
2058               (*d3dintf->effect.set_float)(curr_effect, "Saturation", (float)options.screen_saturation());
2059               (*d3dintf->effect.set_float)(curr_effect, "YScale", (float)options.screen_y_scale());
2060               (*d3dintf->effect.set_float)(curr_effect, "IScale", (float)options.screen_i_scale());
2061               (*d3dintf->effect.set_float)(curr_effect, "QScale", (float)options.screen_q_scale());
2062               (*d3dintf->effect.set_float)(curr_effect, "YOffset", (float)options.screen_y_offset());
2063               (*d3dintf->effect.set_float)(curr_effect, "IOffset", (float)options.screen_i_offset());
2064               (*d3dintf->effect.set_float)(curr_effect, "QOffset", (float)options.screen_q_offset());
2065               (*d3dintf->effect.set_float)(curr_effect, "EdgeDetectScale", (float)options.screen_edge_amount());
2066               (*d3dintf->effect.set_float)(curr_effect, "EdgeToBaseRatio", (float)options.screen_edge_ratio());
2067               (*d3dintf->effect.set_float)(curr_effect, "SubsampleLength", (float)options.screen_chroma_subsample_length());
2068               int frame = (poly->texture != NULL && poly->texture->cur_frame) ? (float)poly->texture->cur_frame : 0;
2069               frame = (frame == options.screen_dot_crawl_skip()) ? 0 : frame;
2070               (*d3dintf->effect.set_float)(curr_effect, "CurrFrame", (float)frame);
2071               (*d3dintf->effect.set_float)(curr_effect, "CrawlWidth", (float)options.screen_dot_crawl_width());
2072               (*d3dintf->effect.set_float)(curr_effect, "CrawlHeight", (float)options.screen_dot_crawl_height());
2073               (*d3dintf->effect.set_float)(curr_effect, "CrawlRate", (float)options.screen_dot_crawl_rate());
2074               (*d3dintf->effect.set_float)(curr_effect, "CrawlSkip", (float)options.screen_dot_crawl_skip());
2075            }
2076            else
2077            {
2078               curr_effect = d3d->effect;
2079
2080               (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f);
2081            }
2082         }
16642083      }
16652084
16662085      // set the blendmode if different
16672086      set_blendmode(d3d, PRIMFLAG_GET_BLENDMODE(poly->flags));
16682087
1669      // add the primitives
1670      assert(vertnum + poly->numverts <= d3d->numverts);
1671      result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
1672      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2088      if(d3d->hlsl_enable)
2089      {
2090         assert(vertnum + poly->numverts <= d3d->numverts);
2091
2092         UINT num_passes = 0;
2093
2094         if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL)
2095         {
2096            /* Render the initial screen pass */
2097            (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f);
2098
2099            result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0);
2100
2101            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 3\n", (int)result);
2102            result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2103            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2104
2105            (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2106
2107            for (UINT pass = 0; pass < num_passes; pass++)
2108            {
2109               (*d3dintf->effect.begin_pass)(curr_effect, pass);
2110               // add the primitives
2111               result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2112               if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2113               (*d3dintf->effect.end_pass)(curr_effect);
2114            }
2115
2116            (*d3dintf->effect.end)(curr_effect);
2117
2118            // max() the two previous frames
2119            curr_effect = d3d->phosphor_effect;
2120
2121            (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
2122            (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
2123            (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
2124            (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
2125            (*d3dintf->effect.set_float)(curr_effect, "RedPhosphor", (float)options.screen_red_phosphor());
2126            (*d3dintf->effect.set_float)(curr_effect, "GreenPhosphor", (float)options.screen_green_phosphor());
2127            (*d3dintf->effect.set_float)(curr_effect, "BluePhosphor", (float)options.screen_blue_phosphor());
2128
2129            (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture0);
2130            (*d3dintf->effect.set_texture)(curr_effect, "LastPass", d3d->last_d3dtexture[cur_render_screen]);
2131
2132            result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget1);
2133            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result);
2134            result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2135            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2136
2137            (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2138
2139            for (UINT pass = 0; pass < num_passes; pass++)
2140            {
2141               (*d3dintf->effect.begin_pass)(curr_effect, pass);
2142               // add the primitives
2143               result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2144               if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2145               (*d3dintf->effect.end_pass)(curr_effect);
2146            }
2147
2148            (*d3dintf->effect.end)(curr_effect);
2149
2150            /* Pass along our phosphor'd screen */
2151            curr_effect = d3d->phosphor_effect;
2152
2153            (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f);
2154
2155            (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1);
2156            (*d3dintf->effect.set_texture)(curr_effect, "LastPass", poly->texture->d3dtexture1);
2157
2158            result = (*d3dintf->device.set_render_target)(d3d->device, 0, d3d->last_d3dtarget[cur_render_screen++]);
2159            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result);
2160            result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2161            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2162
2163            (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2164
2165            for (UINT pass = 0; pass < num_passes; pass++)
2166            {
2167               (*d3dintf->effect.begin_pass)(curr_effect, pass);
2168               // add the primitives
2169               result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2170               if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2171               (*d3dintf->effect.end_pass)(curr_effect);
2172            }
2173
2174            (*d3dintf->effect.end)(curr_effect);
2175
2176            /* Next, defocus pass 1 */
2177            curr_effect = d3d->focus_effect;
2178
2179            (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1);
2180
2181            float defocus_x = (float)options.screen_defocus_x();
2182            float defocus_y = (float)options.screen_defocus_y();
2183            (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
2184            (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
2185            (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
2186            (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
2187            (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x);
2188            (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y);
2189            (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f);
2190
2191            (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2192
2193            result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget2);
2194            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
2195            result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2196            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2197
2198            for (UINT pass = 0; pass < num_passes; pass++)
2199            {
2200               (*d3dintf->effect.begin_pass)(curr_effect, pass);
2201               // add the primitives
2202               result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2203               if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2204               (*d3dintf->effect.end_pass)(curr_effect);
2205            }
2206
2207            (*d3dintf->effect.end)(curr_effect);
2208
2209            /* Lastly, defocus pass 1 */
2210            (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture2);
2211
2212            (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
2213            (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
2214            (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
2215            (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
2216            (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x);
2217            (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y);
2218            (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f);
2219
2220            (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2221
2222            result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer);
2223            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result);
2224
2225            for (UINT pass = 0; pass < num_passes; pass++)
2226            {
2227               (*d3dintf->effect.begin_pass)(curr_effect, pass);
2228               // add the primitives
2229               result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2230               if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2231               (*d3dintf->effect.end_pass)(curr_effect);
2232            }
2233
2234            (*d3dintf->effect.end)(curr_effect);
2235
2236            poly->texture->cur_frame++;
2237            poly->texture->cur_frame %= options.screen_dot_crawl_rate();
2238         }
2239         else
2240         {
2241            (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f);
2242            (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f);
2243            (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f);
2244            (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f);
2245            (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
2246            (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
2247            (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f);
2248            (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountX", (float)options.screen_pincushion_x());
2249            (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountY", (float)options.screen_pincushion_y());
2250
2251            (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2252
2253            for (UINT pass = 0; pass < num_passes; pass++)
2254            {
2255               (*d3dintf->effect.begin_pass)(curr_effect, pass);
2256               // add the primitives
2257               result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2258               if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2259               (*d3dintf->effect.end_pass)(curr_effect);
2260            }
2261
2262            (*d3dintf->effect.end)(curr_effect);
2263         }
2264      }
2265      else
2266      {
2267         assert(vertnum + poly->numverts <= d3d->numverts);
2268
2269         // add the primitives
2270         result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
2271         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2272      }
2273
16732274      vertnum += poly->numverts;
16742275   }
16752276
2277   (*d3dintf->surface.release)(backbuffer);
2278
16762279   // reset the vertex count
16772280   d3d->numverts = 0;
16782281   d3d->numpolys = 0;
r11559r11560
17022305   // compute the size
17032306   texture_compute_size(d3d, texsource->width, texsource->height, texture);
17042307
2308   d3d->oversample_x = downcast<windows_options &>(d3d->window->machine().options()).screen_oversample_x();
2309   d3d->oversample_y = downcast<windows_options &>(d3d->window->machine().options()).screen_oversample_y();
2310
17052311   // non-screen textures are easy
17062312   if (!PRIMFLAG_GET_SCREENTEX(flags))
17072313   {
r11559r11560
17572363            {
17582364               texture->d3dfinaltex = texture->d3dtex;
17592365               texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
2366               result = (*d3dintf->device.create_texture)(d3d->device, (int)(d3d->width * d3d->oversample_x), (int)(d3d->height * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture0);
2367               if (result != D3D_OK)
2368                  goto error;
2369               (*d3dintf->texture.get_surface_level)(texture->d3dtexture0, 0, &texture->d3dtarget0);
2370
2371               result = (*d3dintf->device.create_texture)(d3d->device, (int)(d3d->width * d3d->oversample_x), (int)(d3d->height * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3d->last_d3dtexture[d3d->registered_targets]);
2372               if (result != D3D_OK)
2373                  goto error;
2374               (*d3dintf->texture.get_surface_level)(d3d->last_d3dtexture[d3d->registered_targets], 0, &d3d->last_d3dtarget[d3d->registered_targets]);
2375               d3d->registered_targets++;
2376
2377               result = (*d3dintf->device.create_texture)(d3d->device, (int)(d3d->width * d3d->oversample_x), (int)(d3d->height * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture1);
2378               if (result != D3D_OK)
2379                  goto error;
2380               (*d3dintf->texture.get_surface_level)(texture->d3dtexture1, 0, &texture->d3dtarget1);
2381
2382               result = (*d3dintf->device.create_texture)(d3d->device, (int)(d3d->width * d3d->oversample_x), (int)(d3d->height * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture2);
2383               if (result != D3D_OK)
2384                  goto error;
2385               (*d3dintf->texture.get_surface_level)(texture->d3dtexture2, 0, &texture->d3dtarget2);
17602386               break;
17612387            }
17622388         }
r11559r11560
17942420            finalfmt = (format != d3d->yuv_format) ? format : D3DFMT_A8R8G8B8;
17952421            result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &texture->d3dfinaltex);
17962422            if (result == D3D_OK)
2423            {
2424               result = (*d3dintf->device.create_texture)(d3d->device, (int)(scwidth * d3d->oversample_x), (int)(scheight * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture0);
2425               if (result != D3D_OK)
2426                  goto error;
2427               (*d3dintf->texture.get_surface_level)(texture->d3dtexture0, 0, &texture->d3dtarget0);
2428
2429               result = (*d3dintf->device.create_texture)(d3d->device, (int)(scwidth * d3d->oversample_x), (int)(scheight * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3d->last_d3dtexture[d3d->registered_targets]);
2430               if (result != D3D_OK)
2431                  goto error;
2432               (*d3dintf->texture.get_surface_level)(d3d->last_d3dtexture[d3d->registered_targets], 0, &d3d->last_d3dtarget[d3d->registered_targets]);
2433               d3d->registered_targets++;
2434
2435               result = (*d3dintf->device.create_texture)(d3d->device, (int)(scwidth * d3d->oversample_x), (int)(scheight * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture1);
2436               if (result != D3D_OK)
2437                  goto error;
2438               (*d3dintf->texture.get_surface_level)(texture->d3dtexture1, 0, &texture->d3dtarget1);
2439
2440               result = (*d3dintf->device.create_texture)(d3d->device, (int)(scwidth * d3d->oversample_x), (int)(scheight * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture2);
2441               if (result != D3D_OK)
2442                  goto error;
2443               (*d3dintf->texture.get_surface_level)(texture->d3dtexture2, 0, &texture->d3dtarget2);
2444
17972445               break;
2446            }
17982447            (*d3dintf->texture.release)(texture->d3dtex);
17992448            texture->d3dtex = NULL;
18002449         }
r11559r11560
24383087      result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer);
24393088      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
24403089      result = (*d3dintf->device.set_render_target)(d3d->device, 0, surface);
2441      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
3090      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 1\n", (int)result);
24423091      reset_render_states(d3d);
24433092
24443093      // start the scene
r11559r11560
25003149
25013150      // reset the render target and release our reference to the backbuffer
25023151      result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer);
2503      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
3152      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 2\n", (int)result);
25043153      (*d3dintf->surface.release)(backbuffer);
25053154      reset_render_states(d3d);
25063155   }
r11559r11560
25453194
25463195   // if we didn't find one, create a new texture
25473196   if (texture == NULL)
3197   {
25483198      texture = texture_create(d3d, &prim->texture, prim->flags);
3199   }
25493200
25503201   // if we found it, but with a different seqid, copy the data
25513202   if (texture->texinfo.seqid != prim->texture.seqid)
src/emu/render.c
r11559r11560
18971897         // set the flags and add it to the list
18981898         prim->flags = PRIMFLAG_TEXORIENT(container_xform.orientation) |
18991899                     PRIMFLAG_BLENDMODE(BLENDMODE_RGB_MULTIPLY) |
1900                     PRIMFLAG_TEXFORMAT(container.overlay()->format());
1900                     PRIMFLAG_TEXFORMAT(container.overlay()->format()) |
1901                     PRIMFLAG_TEXSHADE(1);
19011902      }
19021903      list.append_or_return(*prim, !got_scaled);
19031904   }
src/emu/render.h
r11559r11560
132132const int PRIMFLAG_TEXWRAP_SHIFT = 14;
133133const UINT32 PRIMFLAG_TEXWRAP_MASK = 1 << PRIMFLAG_TEXWRAP_SHIFT;
134134
135const int PRIMFLAG_TEXSHADE_SHIFT = 15;
136const UINT32 PRIMFLAG_TEXSHADE_MASK = 3 << PRIMFLAG_TEXSHADE_SHIFT;
135137
136138
137139//**************************************************************************
r11559r11560
156158#define PRIMFLAG_TEXWRAP(x)         ((x) << PRIMFLAG_TEXWRAP_SHIFT)
157159#define PRIMFLAG_GET_TEXWRAP(x)      (((x) & PRIMFLAG_TEXWRAP_MASK) >> PRIMFLAG_TEXWRAP_SHIFT)
158160
161#define PRIMFLAG_TEXSHADE(x)      ((x) << PRIMFLAG_TEXSHADE_SHIFT)
162#define PRIMFLAG_GET_TEXSHADE(x)   (((x) & PRIMFLAG_TEXSHADE_MASK) >> PRIMFLAG_TEXSHADE_SHIFT)
159163
160164
165
161166//**************************************************************************
162167//  TYPE DEFINITIONS
163168//**************************************************************************
artwork/white.png
artwork/aperture.png

Previous 15994 Revisions Next


© 1998-2018 The MESS Team