| 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 |
| r0 | r11560 | |
|---|---|---|
| 1 | //----------------------------------------------------------------------------- | |
| 2 | // Effect File Variables | |
| 3 | //----------------------------------------------------------------------------- | |
| 4 | ||
| 5 | texture Diffuse; | |
| 6 | ||
| 7 | sampler 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 | ||
| 22 | struct VS_OUTPUT | |
| 23 | { | |
| 24 | float4 Position : POSITION; | |
| 25 | float4 Color : COLOR0; | |
| 26 | float2 TexCoord : TEXCOORD0; | |
| 27 | float2 ExtraInfo : TEXCOORD1; | |
| 28 | }; | |
| 29 | ||
| 30 | struct VS_INPUT | |
| 31 | { | |
| 32 | float3 Position : POSITION; | |
| 33 | float4 Color : COLOR0; | |
| 34 | float2 TexCoord : TEXCOORD0; | |
| 35 | float2 ExtraInfo : TEXCOORD1; | |
| 36 | }; | |
| 37 | ||
| 38 | struct PS_INPUT | |
| 39 | { | |
| 40 | float4 Color : COLOR0; | |
| 41 | float2 TexCoord : TEXCOORD0; | |
| 42 | float2 ExtraInfo : TEXCOORD1; | |
| 43 | }; | |
| 44 | ||
| 45 | //----------------------------------------------------------------------------- | |
| 46 | // Simple Vertex Shader | |
| 47 | //----------------------------------------------------------------------------- | |
| 48 | ||
| 49 | uniform float TargetWidth; | |
| 50 | uniform float TargetHeight; | |
| 51 | uniform float PostPass; | |
| 52 | uniform float FixedAlpha; | |
| 53 | ||
| 54 | VS_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 | ||
| 76 | float4 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 | ||
| 86 | technique 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 | } |
| r0 | r11560 | |
|---|---|---|
| 1 | //----------------------------------------------------------------------------- | |
| 2 | // Post-Processing Effect | |
| 3 | //----------------------------------------------------------------------------- | |
| 4 | ||
| 5 | texture Diffuse; | |
| 6 | ||
| 7 | sampler 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 | texture Shadow; | |
| 19 | ||
| 20 | sampler 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 | ||
| 35 | struct 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 | ||
| 46 | struct VS_INPUT | |
| 47 | { | |
| 48 | float4 Position : POSITION; | |
| 49 | float4 Color : COLOR0; | |
| 50 | float2 TexCoord : TEXCOORD0; | |
| 51 | float2 ExtraInfo : TEXCOORD1; | |
| 52 | }; | |
| 53 | ||
| 54 | struct 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 | ||
| 68 | uniform float RedConvergeX; | |
| 69 | uniform float RedConvergeY; | |
| 70 | uniform float GrnConvergeX; | |
| 71 | uniform float GrnConvergeY; | |
| 72 | uniform float BluConvergeX; | |
| 73 | uniform float BluConvergeY; | |
| 74 | ||
| 75 | uniform float TargetWidth; | |
| 76 | uniform float TargetHeight; | |
| 77 | ||
| 78 | uniform float RawWidth; | |
| 79 | uniform float RawHeight; | |
| 80 | ||
| 81 | uniform float WidthRatio; | |
| 82 | uniform float HeightRatio; | |
| 83 | ||
| 84 | uniform float RedRadialConvergeX; | |
| 85 | uniform float RedRadialConvergeY; | |
| 86 | uniform float GrnRadialConvergeX; | |
| 87 | uniform float GrnRadialConvergeY; | |
| 88 | uniform float BluRadialConvergeX; | |
| 89 | uniform float BluRadialConvergeY; | |
| 90 | ||
| 91 | VS_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 | ||
| 124 | uniform float PI = 3.14159265f; | |
| 125 | ||
| 126 | uniform float PincushionAmountX = 0.1f; | |
| 127 | uniform float PincushionAmountY = 0.1f; | |
| 128 | ||
| 129 | uniform float ScanlineAmount = 1.0f; | |
| 130 | uniform float ScanlineScale = 1.0f; | |
| 131 | uniform float ScanlineBrightScale = 1.0f; | |
| 132 | uniform float ScanlineBrightOffset = 1.0f; | |
| 133 | uniform float ScanlineOffset = 1.0f; | |
| 134 | ||
| 135 | uniform float RedFromRed = 1.0f; | |
| 136 | uniform float RedFromGrn = 0.0f; | |
| 137 | uniform float RedFromBlu = 0.0f; | |
| 138 | uniform float GrnFromRed = 0.0f; | |
| 139 | uniform float GrnFromGrn = 1.0f; | |
| 140 | uniform float GrnFromBlu = 0.0f; | |
| 141 | uniform float BluFromRed = 0.0f; | |
| 142 | uniform float BluFromGrn = 0.0f; | |
| 143 | uniform float BluFromBlu = 1.0f; | |
| 144 | ||
| 145 | uniform float YfromY = 1.0f; | |
| 146 | uniform float YfromI = 0.0f; | |
| 147 | uniform float YfromQ = 0.0f; | |
| 148 | uniform float IfromY = 0.0f; | |
| 149 | uniform float IfromI = 1.0f; | |
| 150 | uniform float IfromQ = 0.0f; | |
| 151 | uniform float QfromY = 0.0f; | |
| 152 | uniform float QfromI = 0.0f; | |
| 153 | uniform float QfromQ = 1.0f; | |
| 154 | ||
| 155 | uniform float RedOffset = 0.0f; | |
| 156 | uniform float GrnOffset = 0.0f; | |
| 157 | uniform float BluOffset = 0.0f; | |
| 158 | ||
| 159 | uniform float RedScale = 1.0f; | |
| 160 | uniform float GrnScale = 1.0f; | |
| 161 | uniform float BluScale = 1.0f; | |
| 162 | ||
| 163 | uniform float RedFloor = 0.0f; | |
| 164 | uniform float GrnFloor = 0.0f; | |
| 165 | uniform float BluFloor = 0.0f; | |
| 166 | ||
| 167 | uniform float Saturation = 1.0f; | |
| 168 | ||
| 169 | uniform float YScale = 1.0f; | |
| 170 | uniform float IScale = 1.0f; | |
| 171 | uniform float QScale = 1.0f; | |
| 172 | uniform float YOffset = 0.0f; | |
| 173 | uniform float IOffset = 0.0f; | |
| 174 | uniform float QOffset = 0.0f; | |
| 175 | ||
| 176 | uniform float RedPower = 2.2f; | |
| 177 | uniform float GrnPower = 2.2f; | |
| 178 | uniform float BluPower = 2.2f; | |
| 179 | ||
| 180 | uniform float EdgeDetectScale = 1.0f; | |
| 181 | uniform float EdgeToBaseRatio = 0.0f; | |
| 182 | ||
| 183 | uniform float SubsampleLength = 3.0f; | |
| 184 | ||
| 185 | uniform float CurrFrame = 0.0f; | |
| 186 | uniform float CrawlWidth = 3.0f; | |
| 187 | uniform float CrawlHeight = 3.0f; | |
| 188 | uniform float CrawlRate = 3.0f; | |
| 189 | ||
| 190 | uniform float UseShadow = 0.0f; | |
| 191 | uniform float ShadowBrightness = 1.0f; | |
| 192 | uniform float ShadowPixelSizeX = 3.0f; | |
| 193 | uniform float ShadowPixelSizeY = 3.0f; | |
| 194 | uniform float ShadowU = 0.375f; | |
| 195 | uniform float ShadowV = 0.375f; | |
| 196 | uniform float ShadowWidth = 8.0f; | |
| 197 | uniform float ShadowHeight = 8.0f; | |
| 198 | ||
| 199 | float4 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 | ||
| 314 | technique 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 | } |
| r0 | r11560 | |
|---|---|---|
| 1 | //----------------------------------------------------------------------------- | |
| 2 | // Effect File Variables | |
| 3 | //----------------------------------------------------------------------------- | |
| 4 | ||
| 5 | texture Diffuse; | |
| 6 | ||
| 7 | sampler 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 | ||
| 22 | struct 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 | ||
| 36 | struct VS_INPUT | |
| 37 | { | |
| 38 | float3 Position : POSITION; | |
| 39 | float4 Color : COLOR0; | |
| 40 | float2 TexCoord : TEXCOORD0; | |
| 41 | float2 ExtraInfo : TEXCOORD1; | |
| 42 | }; | |
| 43 | ||
| 44 | struct 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 | ||
| 61 | uniform float TargetWidth; | |
| 62 | uniform float TargetHeight; | |
| 63 | uniform float DefocusX; | |
| 64 | uniform float DefocusY; | |
| 65 | uniform float FocusEnable; | |
| 66 | ||
| 67 | float2 Coord0Offset = float2( 0.0f, 0.0f); | |
| 68 | float2 Coord1Offset = float2(-0.2f, -0.6f); | |
| 69 | float2 Coord2Offset = float2( 0.4f, -0.4f); | |
| 70 | float2 Coord3Offset = float2( 0.6f, 0.2f); | |
| 71 | float2 Coord4Offset = float2( 0.2f, 0.6f); | |
| 72 | float2 Coord5Offset = float2(-0.4f, 0.6f); | |
| 73 | float2 Coord6Offset = float2(-0.6f, 0.2f); | |
| 74 | float2 Coord7Offset = float2(-0.6f, -0.4f); | |
| 75 | ||
| 76 | VS_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 | ||
| 108 | float4 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 | ||
| 129 | technique 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 | } |
| r0 | r11560 | |
|---|---|---|
| 1 | //----------------------------------------------------------------------------- | |
| 2 | // Pincushion Post-Processing Effect | |
| 3 | //----------------------------------------------------------------------------- | |
| 4 | ||
| 5 | texture Diffuse; | |
| 6 | ||
| 7 | sampler 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 | ||
| 22 | struct 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 | ||
| 33 | struct VS_INPUT | |
| 34 | { | |
| 35 | float3 Position : POSITION; | |
| 36 | float4 Color : COLOR0; | |
| 37 | float2 TexCoord : TEXCOORD0; | |
| 38 | float2 ExtraInfo : TEXCOORD1; | |
| 39 | }; | |
| 40 | ||
| 41 | struct 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 | ||
| 55 | uniform float TargetWidth; | |
| 56 | uniform float TargetHeight; | |
| 57 | ||
| 58 | uniform float RawWidth; | |
| 59 | uniform float RawHeight; | |
| 60 | ||
| 61 | VS_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 | ||
| 92 | uniform float PI = 3.14159265f; | |
| 93 | ||
| 94 | uniform float PincushionAmountX = 0.1f; | |
| 95 | uniform float PincushionAmountY = 0.1f; | |
| 96 | ||
| 97 | uniform float WidthRatio; | |
| 98 | uniform float HeightRatio; | |
| 99 | ||
| 100 | float4 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 | ||
| 118 | technique 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 | } |
| r0 | r11560 | |
|---|---|---|
| 1 | //----------------------------------------------------------------------------- | |
| 2 | // Effect File Variables | |
| 3 | //----------------------------------------------------------------------------- | |
| 4 | ||
| 5 | texture Diffuse; | |
| 6 | ||
| 7 | sampler 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 | texture LastPass; | |
| 19 | ||
| 20 | sampler 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 | ||
| 35 | struct VS_OUTPUT | |
| 36 | { | |
| 37 | float4 Position : POSITION; | |
| 38 | float4 Color : COLOR0; | |
| 39 | float2 TexCoord : TEXCOORD0; | |
| 40 | float2 PrevCoord : TEXCOORD1; | |
| 41 | }; | |
| 42 | ||
| 43 | struct VS_INPUT | |
| 44 | { | |
| 45 | float3 Position : POSITION; | |
| 46 | float4 Color : COLOR0; | |
| 47 | float2 TexCoord : TEXCOORD0; | |
| 48 | float2 ExtraInfo : TEXCOORD1; | |
| 49 | }; | |
| 50 | ||
| 51 | struct PS_INPUT | |
| 52 | { | |
| 53 | float4 Color : COLOR0; | |
| 54 | float2 TexCoord : TEXCOORD0; | |
| 55 | float2 PrevCoord : TEXCOORD1; | |
| 56 | }; | |
| 57 | ||
| 58 | //----------------------------------------------------------------------------- | |
| 59 | // Simple Vertex Shader | |
| 60 | //----------------------------------------------------------------------------- | |
| 61 | ||
| 62 | uniform float TargetWidth; | |
| 63 | uniform float TargetHeight; | |
| 64 | ||
| 65 | uniform float RawWidth; | |
| 66 | uniform float RawHeight; | |
| 67 | ||
| 68 | VS_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 | ||
| 94 | uniform float RedPhosphor = 0.0f; | |
| 95 | uniform float GreenPhosphor = 0.0f; | |
| 96 | uniform float BluePhosphor = 0.0f; | |
| 97 | ||
| 98 | float4 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 | ||
| 114 | technique 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 | } |
| r11559 | r11560 | |
|---|---|---|
| 71 | 71 | D3DTSS_MAXMIPLEVEL = 20, |
| 72 | 72 | D3DTSS_MAXANISOTROPY = 21 |
| 73 | 73 | }; |
| 74 | ||
| 74 | 75 | #endif |
| 75 | 76 | #endif |
| 76 | 77 | |
| r11559 | r11560 | |
| 84 | 85 | typedef struct _d3d_surface d3d_surface; |
| 85 | 86 | typedef struct _d3d_texture d3d_texture; |
| 86 | 87 | typedef struct _d3d_vertex_buffer d3d_vertex_buffer; |
| 88 | typedef struct _d3d_effect d3d_effect; | |
| 89 | typedef D3DXVECTOR4 d3d_vector; | |
| 90 | typedef D3DMATRIX d3d_matrix; | |
| 87 | 91 | |
| 88 | 92 | |
| 89 | 93 | //============================================================ |
| r11559 | r11560 | |
| 147 | 151 | CAPS_MAX_TEXTURE_ASPECT, |
| 148 | 152 | CAPS_MAX_TEXTURE_WIDTH, |
| 149 | 153 | CAPS_MAX_TEXTURE_HEIGHT, |
| 150 | CAPS_STRETCH_RECT_FILTER | |
| 154 | CAPS_STRETCH_RECT_FILTER, | |
| 155 | CAPS_MAX_PS30_INSN_SLOTS | |
| 151 | 156 | }; |
| 152 | 157 | typedef enum _d3d_caps_index d3d_caps_index; |
| 153 | 158 | |
| r11559 | r11560 | |
| 183 | 188 | HRESULT (*begin_scene)(d3d_device *dev); |
| 184 | 189 | HRESULT (*clear)(d3d_device *dev, DWORD count, const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil); |
| 185 | 190 | 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); | |
| 186 | 192 | HRESULT (*create_texture)(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture); |
| 187 | 193 | 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); | |
| 188 | 195 | HRESULT (*draw_primitive)(d3d_device *dev, D3DPRIMITIVETYPE type, UINT start, UINT count); |
| 189 | 196 | HRESULT (*end_scene)(d3d_device *dev); |
| 190 | 197 | HRESULT (*get_raster_status)(d3d_device *dev, D3DRASTER_STATUS *status); |
| r11559 | r11560 | |
| 198 | 205 | HRESULT (*set_stream_source)(d3d_device *dev, UINT number, d3d_vertex_buffer *vbuf, UINT stride); |
| 199 | 206 | HRESULT (*set_texture)(d3d_device *dev, DWORD stage, d3d_texture *tex); |
| 200 | 207 | HRESULT (*set_texture_stage_state)(d3d_device *dev, DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value); |
| 201 | HRESULT (*set_vertex_ | |
| 208 | HRESULT (*set_vertex_fo | |
| 202 | 209 | HRESULT (*stretch_rect)(d3d_device *dev, d3d_surface *source, const RECT *srcrect, d3d_surface *dest, const RECT *dstrect, D3DTEXTUREFILTERTYPE filter); |
| 203 | 210 | HRESULT (*test_cooperative_level)(d3d_device *dev); |
| 204 | 211 | }; |
| r11559 | r11560 | |
| 245 | 252 | |
| 246 | 253 | |
| 247 | 254 | //============================================================ |
| 255 | // Direct3DEffect interfaces | |
| 256 | //============================================================ | |
| 257 | ||
| 258 | typedef struct _d3d_effect_interface d3d_effect_interface; | |
| 259 | struct _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 | //============================================================ | |
| 248 | 276 | // Core D3D object |
| 249 | 277 | //============================================================ |
| 250 | 278 | |
| r11559 | r11560 | |
| 254 | 282 | int version; |
| 255 | 283 | void * d3dobj; |
| 256 | 284 | HINSTANCE dllhandle; |
| 285 | bool post_fx_available; | |
| 257 | 286 | |
| 258 | 287 | // interface pointers |
| 259 | 288 | d3d_interface d3d; |
| r11559 | r11560 | |
| 261 | 290 | d3d_surface_interface surface; |
| 262 | 291 | d3d_texture_interface texture; |
| 263 | 292 | d3d_vertex_buffer_interface vertexbuf; |
| 293 | d3d_effect_interface effect; | |
| 264 | 294 | }; |
| 265 | 295 | |
| 266 | 296 |
| r11559 | r11560 | |
|---|---|---|
| 55 | 55 | #ifndef alloca |
| 56 | 56 | #define alloca __builtin_alloca |
| 57 | 57 | #endif |
| 58 | #define min(x,y) fmin(x,y) | |
| 59 | #define max(x,y) fmax(x,y) | |
| 58 | 60 | #endif |
| 59 | 61 | |
| 60 | 62 | #define PATH_SEPARATOR "\\" |
| r11559 | r11560 | |
|---|---|---|
| 43 | 43 | #define WIN32_LEAN_AND_MEAN |
| 44 | 44 | #include <windows.h> |
| 45 | 45 | #include <d3d8.h> |
| 46 | #define D3DXVECTOR4 void | |
| 46 | 47 | #undef interface |
| 47 | 48 | |
| 48 | 49 | // MAME headers |
| r11559 | r11560 | |
| 141 | 142 | d3dptr->version = 8; |
| 142 | 143 | d3dptr->d3dobj = d3d8; |
| 143 | 144 | d3dptr->dllhandle = dllhandle; |
| 145 | d3dptr->post_fx_available = false; | |
| 144 | 146 | set_interfaces(d3dptr); |
| 145 | 147 | |
| 146 | 148 | mame_printf_verbose("Direct3D: Using Direct3D 8\n"); |
| r11559 | r11560 | |
| 249 | 251 | case CAPS_MAX_TEXTURE_WIDTH: *value = caps.MaxTextureWidth; break; |
| 250 | 252 | case CAPS_MAX_TEXTURE_HEIGHT: *value = caps.MaxTextureHeight; break; |
| 251 | 253 | case CAPS_STRETCH_RECT_FILTER: *value = 0; break; |
| 254 | case CAPS_MAX_PS30_INSN_SLOTS: *value = 0; break; | |
| 252 | 255 | } |
| 253 | 256 | return result; |
| 254 | 257 | } |
| r11559 | r11560 | |
| 306 | 309 | } |
| 307 | 310 | |
| 308 | 311 | |
| 312 | static 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 | ||
| 309 | 320 | static HRESULT d3d_device_create_texture(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture) |
| 310 | 321 | { |
| 311 | 322 | IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev; |
| r11559 | r11560 | |
| 395 | 406 | } |
| 396 | 407 | |
| 397 | 408 | |
| 409 | static 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 | ||
| 398 | 416 | static HRESULT d3d_device_set_stream_source(d3d_device *dev, UINT number, d3d_vertex_buffer *vbuf, UINT stride) |
| 399 | 417 | { |
| 400 | 418 | IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev; |
| r11559 | r11560 | |
| 418 | 436 | } |
| 419 | 437 | |
| 420 | 438 | |
| 421 | static HRESULT d3d_device_set_vertex_ | |
| 439 | static HRESULT d3d_device_set_vertex_fo | |
| 422 | 440 | { |
| 423 | 441 | IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev; |
| 424 | 442 | return IDirect3DDevice8_SetVertexShader(device, format); |
| r11559 | r11560 | |
| 444 | 462 | d3d_device_begin_scene, |
| 445 | 463 | d3d_device_clear, |
| 446 | 464 | d3d_device_create_offscreen_plain_surface, |
| 465 | d3d_device_create_effect, | |
| 447 | 466 | d3d_device_create_texture, |
| 448 | 467 | d3d_device_create_vertex_buffer, |
| 468 | d3d_device_create_render_target, | |
| 449 | 469 | d3d_device_draw_primitive, |
| 450 | 470 | d3d_device_end_scene, |
| 451 | 471 | d3d_device_get_raster_status, |
| r11559 | r11560 | |
| 459 | 479 | d3d_device_set_stream_source, |
| 460 | 480 | d3d_device_set_texture, |
| 461 | 481 | d3d_device_set_texture_stage_state, |
| 462 | d3d_device_set_vertex_ | |
| 482 | d3d_device_set_vertex_fo | |
| 463 | 483 | d3d_device_stretch_rect, |
| 464 | 484 | d3d_device_test_cooperative_level |
| 465 | 485 | }; |
| r11559 | r11560 | |
| 577 | 597 | |
| 578 | 598 | |
| 579 | 599 | //============================================================ |
| 600 | // Direct3DEffect interfaces | |
| 601 | //============================================================ | |
| 602 | ||
| 603 | static void d3d_effect_begin(d3d_effect *effect, UINT *passes, DWORD flags) | |
| 604 | { | |
| 605 | assert(FALSE); | |
| 606 | } | |
| 607 | ||
| 608 | ||
| 609 | static void d3d_effect_end(d3d_effect *effect) | |
| 610 | { | |
| 611 | assert(FALSE); | |
| 612 | } | |
| 613 | ||
| 614 | ||
| 615 | static void d3d_effect_begin_pass(d3d_effect *effect, UINT pass) | |
| 616 | { | |
| 617 | assert(FALSE); | |
| 618 | } | |
| 619 | ||
| 620 | ||
| 621 | static void d3d_effect_end_pass(d3d_effect *effect) | |
| 622 | { | |
| 623 | assert(FALSE); | |
| 624 | } | |
| 625 | ||
| 626 | ||
| 627 | static void d3d_effect_set_technique(d3d_effect *effect, const char *name) | |
| 628 | { | |
| 629 | assert(FALSE); | |
| 630 | } | |
| 631 | ||
| 632 | ||
| 633 | static void d3d_effect_set_vector(d3d_effect *effect, const char *name, d3d_vector *vector) | |
| 634 | { | |
| 635 | assert(FALSE); | |
| 636 | } | |
| 637 | ||
| 638 | ||
| 639 | static void d3d_effect_set_float(d3d_effect *effect, const char *name, float value) | |
| 640 | { | |
| 641 | assert(FALSE); | |
| 642 | } | |
| 643 | ||
| 644 | ||
| 645 | static void d3d_effect_set_int(d3d_effect *effect, const char *name, int value) | |
| 646 | { | |
| 647 | assert(FALSE); | |
| 648 | } | |
| 649 | ||
| 650 | ||
| 651 | static void d3d_effect_set_matrix(d3d_effect *effect, const char *name, d3d_matrix *matrix) | |
| 652 | { | |
| 653 | assert(FALSE); | |
| 654 | } | |
| 655 | ||
| 656 | ||
| 657 | static void d3d_effect_set_texture(d3d_effect *effect, const char *name, d3d_texture *tex) | |
| 658 | { | |
| 659 | assert(FALSE); | |
| 660 | } | |
| 661 | ||
| 662 | ||
| 663 | static ULONG d3d_effect_release(d3d_effect *effect) | |
| 664 | { | |
| 665 | assert(FALSE); | |
| 666 | return 0; | |
| 667 | } | |
| 668 | ||
| 669 | ||
| 670 | static 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 | //============================================================ | |
| 580 | 688 | // set_interfaces |
| 581 | 689 | //============================================================ |
| 582 | 690 | |
| r11559 | r11560 | |
| 587 | 695 | d3dptr->surface = d3d8_surface_interface; |
| 588 | 696 | d3dptr->texture = d3d8_texture_interface; |
| 589 | 697 | d3dptr->vertexbuf = d3d8_vertex_buffer_interface; |
| 698 | d3dptr->effect = d3d8_effect_interface; | |
| 590 | 699 | } |
| r11559 | r11560 | |
|---|---|---|
| 43 | 43 | #define WIN32_LEAN_AND_MEAN |
| 44 | 44 | #include <windows.h> |
| 45 | 45 | #include <d3d9.h> |
| 46 | #include <d3dx9.h> | |
| 46 | 47 | #undef interface |
| 47 | 48 | |
| 48 | 49 | // MAME headers |
| r11559 | r11560 | |
| 60 | 61 | |
| 61 | 62 | typedef IDirect3D9 *(WINAPI *direct3dcreate9_ptr)(UINT SDKVersion); |
| 62 | 63 | |
| 64 | typedef HRESULT (WINAPI *direct3dx9_loadeffect_ptr)(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXEFFECTPOOL pPool, LPD3DXEFFECT *ppEffect, LPD3DXBUFFER *ppCompilationErrors); | |
| 65 | static direct3dx9_loadeffect_ptr g_load_effect = NULL; | |
| 63 | 66 | |
| 64 | 67 | |
| 65 | 68 | //============================================================ |
| r11559 | r11560 | |
| 68 | 71 | |
| 69 | 72 | static void set_interfaces(d3d *d3dptr); |
| 70 | 73 | |
| 71 | ||
| 72 | ||
| 73 | 74 | //============================================================ |
| 74 | 75 | // INLINES |
| 75 | 76 | //============================================================ |
| r11559 | r11560 | |
| 105 | 106 | HINSTANCE dllhandle; |
| 106 | 107 | IDirect3D9 *d3d9; |
| 107 | 108 | d3d *d3dptr; |
| 109 | bool post_available = true; | |
| 108 | 110 | |
| 109 | 111 | // dynamically grab the create function from d3d9.dll |
| 110 | 112 | dllhandle = LoadLibrary(TEXT("d3d9.dll")); |
| r11559 | r11560 | |
| 134 | 136 | return NULL; |
| 135 | 137 | } |
| 136 | 138 | |
| 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 | ||
| 137 | 167 | // allocate an object to hold our data |
| 138 | 168 | d3dptr = global_alloc(d3d); |
| 139 | 169 | d3dptr->version = 9; |
| 140 | 170 | d3dptr->d3dobj = d3d9; |
| 141 | 171 | d3dptr->dllhandle = dllhandle; |
| 172 | d3dptr->post_fx_available = post_available; | |
| 142 | 173 | set_interfaces(d3dptr); |
| 143 | 174 | |
| 144 | 175 | mame_printf_verbose("Direct3D: Using Direct3D 9\n"); |
| r11559 | r11560 | |
| 164 | 195 | return IDirect3D9_CheckDeviceType(d3d9, adapter, devtype, format, backformat, windowed); |
| 165 | 196 | } |
| 166 | 197 | |
| 167 | ||
| 168 | 198 | static HRESULT d3d_create_device(d3d *d3dptr, UINT adapter, D3DDEVTYPE devtype, HWND focus, DWORD behavior, d3d_present_parameters *params, d3d_device **dev) |
| 169 | 199 | { |
| 170 | 200 | IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj; |
| r11559 | r11560 | |
| 173 | 203 | return IDirect3D9_CreateDevice(d3d9, adapter, devtype, focus, behavior, &d3d9params, (IDirect3DDevice9 **)dev); |
| 174 | 204 | } |
| 175 | 205 | |
| 176 | ||
| 177 | 206 | static HRESULT d3d_enum_adapter_modes(d3d *d3dptr, UINT adapter, D3DFORMAT format, UINT index, D3DDISPLAYMODE *mode) |
| 178 | 207 | { |
| 179 | 208 | IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj; |
| r11559 | r11560 | |
| 247 | 276 | case CAPS_MAX_TEXTURE_WIDTH: *value = caps.MaxTextureWidth; break; |
| 248 | 277 | case CAPS_MAX_TEXTURE_HEIGHT: *value = caps.MaxTextureHeight; break; |
| 249 | 278 | case CAPS_STRETCH_RECT_FILTER: *value = caps.StretchRectFilterCaps; break; |
| 279 | case CAPS_MAX_PS30_INSN_SLOTS: *value = caps.MaxPixelShader30InstructionSlots; break; | |
| 250 | 280 | } |
| 251 | 281 | return result; |
| 252 | 282 | } |
| r11559 | r11560 | |
| 289 | 319 | return IDirect3DDevice9_BeginScene(device); |
| 290 | 320 | } |
| 291 | 321 | |
| 292 | ||
| 293 | 322 | static HRESULT d3d_device_clear(d3d_device *dev, DWORD count, const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil) |
| 294 | 323 | { |
| 295 | 324 | IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev; |
| r11559 | r11560 | |
| 304 | 333 | } |
| 305 | 334 | |
| 306 | 335 | |
| 336 | static 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 | ||
| 307 | 352 | static HRESULT d3d_device_create_texture(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture) |
| 308 | 353 | { |
| 309 | 354 | IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev; |
| r11559 | r11560 | |
| 402 | 447 | } |
| 403 | 448 | |
| 404 | 449 | |
| 450 | static 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 | ||
| 405 | 457 | static HRESULT d3d_device_set_stream_source(d3d_device *dev, UINT number, d3d_vertex_buffer *vbuf, UINT stride) |
| 406 | 458 | { |
| 407 | 459 | IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev; |
| r11559 | r11560 | |
| 449 | 501 | } |
| 450 | 502 | |
| 451 | 503 | |
| 452 | static HRESULT d3d_device_set_vertex_ | |
| 504 | static HRESULT d3d_device_set_vertex_fo | |
| 453 | 505 | { |
| 454 | 506 | IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev; |
| 455 | 507 | return IDirect3DDevice9_SetFVF(device, format); |
| r11559 | r11560 | |
| 477 | 529 | d3d_device_begin_scene, |
| 478 | 530 | d3d_device_clear, |
| 479 | 531 | d3d_device_create_offscreen_plain_surface, |
| 532 | d3d_device_create_effect, | |
| 480 | 533 | d3d_device_create_texture, |
| 481 | 534 | d3d_device_create_vertex_buffer, |
| 535 | d3d_device_create_render_target, | |
| 482 | 536 | d3d_device_draw_primitive, |
| 483 | 537 | d3d_device_end_scene, |
| 484 | 538 | d3d_device_get_raster_status, |
| r11559 | r11560 | |
| 492 | 546 | d3d_device_set_stream_source, |
| 493 | 547 | d3d_device_set_texture, |
| 494 | 548 | d3d_device_set_texture_stage_state, |
| 495 | d3d_device_set_vertex_ | |
| 549 | d3d_device_set_vertex_fo | |
| 496 | 550 | d3d_device_stretch_rect, |
| 497 | 551 | d3d_device_test_cooperative_level |
| 498 | 552 | }; |
| r11559 | r11560 | |
| 610 | 664 | |
| 611 | 665 | |
| 612 | 666 | //============================================================ |
| 667 | // Direct3DEffect interfaces | |
| 668 | //============================================================ | |
| 669 | ||
| 670 | static 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 | ||
| 677 | static void d3d_effect_end(d3d_effect *effect) | |
| 678 | { | |
| 679 | ID3DXEffect *d3dfx = (ID3DXEffect*)effect; | |
| 680 | d3dfx->End(); | |
| 681 | } | |
| 682 | ||
| 683 | ||
| 684 | static void d3d_effect_begin_pass(d3d_effect *effect, UINT pass) | |
| 685 | { | |
| 686 | ID3DXEffect *d3dfx = (ID3DXEffect*)effect; | |
| 687 | d3dfx->BeginPass(pass); | |
| 688 | } | |
| 689 | ||
| 690 | ||
| 691 | static void d3d_effect_end_pass(d3d_effect *effect) | |
| 692 | { | |
| 693 | ID3DXEffect *d3dfx = (ID3DXEffect*)effect; | |
| 694 | d3dfx->EndPass(); | |
| 695 | } | |
| 696 | ||
| 697 | ||
| 698 | static void d3d_effect_set_technique(d3d_effect *effect, const char *name) | |
| 699 | { | |
| 700 | ID3DXEffect *d3dfx = (ID3DXEffect*)effect; | |
| 701 | d3dfx->SetTechnique(name); | |
| 702 | } | |
| 703 | ||
| 704 | ||
| 705 | static 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 | ||
| 712 | static 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 | ||
| 719 | static 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 | ||
| 726 | static 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 | ||
| 733 | static 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 | ||
| 740 | static ULONG d3d_effect_release(d3d_effect *effect) | |
| 741 | { | |
| 742 | ID3DXEffect *d3dfx = (ID3DXEffect*)effect; | |
| 743 | return d3dfx->Release(); | |
| 744 | } | |
| 745 | ||
| 746 | ||
| 747 | static 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 | //============================================================ | |
| 613 | 765 | // set_interfaces |
| 614 | 766 | //============================================================ |
| 615 | 767 | |
| r11559 | r11560 | |
| 620 | 772 | d3dptr->surface = d3d9_surface_interface; |
| 621 | 773 | d3dptr->texture = d3d9_texture_interface; |
| 622 | 774 | d3dptr->vertexbuf = d3d9_vertex_buffer_interface; |
| 775 | d3dptr->effect = d3d9_effect_interface; | |
| 623 | 776 | } |
| r11559 | r11560 | |
|---|---|---|
| 326 | 326 | { WINOPTION_D3DVERSION "(8-9)", "9", OPTION_INTEGER, "specify the preferred Direct3D version (8 or 9)" }, |
| 327 | 327 | { WINOPTION_FILTER ";d3dfilter;flt", "1", OPTION_BOOLEAN, "enable bilinear filtering on screen output" }, |
| 328 | 328 | |
| 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 | ||
| 329 | 420 | // per-window options |
| 330 | 421 | { NULL, NULL, OPTION_HEADER, "PER-WINDOW VIDEO OPTIONS" }, |
| 331 | 422 | { WINOPTION_SCREEN, "auto", OPTION_STRING, "explicit name of all screens; 'auto' here will try to make a best guess" }, |
| r11559 | r11560 | |
|---|---|---|
| 78 | 78 | #define WINOPTION_D3DVERSION "d3dversion" |
| 79 | 79 | #define WINOPTION_FILTER "filter" |
| 80 | 80 | |
| 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 | ||
| 81 | 161 | // per-window options |
| 82 | 162 | #define WINOPTION_SCREEN "screen" |
| 83 | 163 | #define WINOPTION_ASPECT "aspect" |
| r11559 | r11560 | |
| 140 | 220 | int d3d_version() const { return int_value(WINOPTION_D3DVERSION); } |
| 141 | 221 | bool filter() const { return bool_value(WINOPTION_FILTER); } |
| 142 | 222 | |
| 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 | ||
| 143 | 304 | // per-window options |
| 144 | 305 | const char *screen() const { return value(WINOPTION_SCREEN); } |
| 145 | 306 | const char *aspect() const { return value(WINOPTION_ASPECT); } |
| r11559 | r11560 | |
|---|---|---|
| 53 | 53 | #include <tchar.h> |
| 54 | 54 | #include <mmsystem.h> |
| 55 | 55 | #include <d3d9.h> |
| 56 | #include <d3dx9.h> | |
| 56 | 57 | #undef interface |
| 57 | 58 | |
| 58 | 59 | // MAME headers |
| r11559 | r11560 | |
| 85 | 86 | |
| 86 | 87 | #define ENABLE_BORDER_PIX (1) |
| 87 | 88 | |
| 88 | #define VERTEX_FORMAT | |
| 89 | #define VERTEX_BASE_FORMAT | |
| 89 | 90 | #define VERTEX_BUFFER_SIZE (2048*4) |
| 90 | 91 | |
| 91 | 92 | enum |
| r11559 | r11560 | |
| 125 | 126 | int yborderpix; // number of border pixels in Y |
| 126 | 127 | int xprescale; // what is our X prescale factor? |
| 127 | 128 | int yprescale; // what is our Y prescale factor? |
| 129 | int cur_frame; // what is our current frame? | |
| 128 | 130 | d3d_texture * d3dtex; // Direct3D texture pointer |
| 129 | 131 | 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) | |
| 130 | 138 | d3d_texture * d3dfinaltex; // Direct3D final (post-scaled) texture |
| 131 | 139 | }; |
| 132 | 140 | |
| r11559 | r11560 | |
| 149 | 157 | struct _d3d_vertex |
| 150 | 158 | { |
| 151 | 159 | float x, y, z; // X,Y,Z coordinates |
| 152 | float rhw; // | |
| 160 | float rhw; // RHW when no HLSL, padding when HLSL | |
| 153 | 161 | D3DCOLOR color; // diffuse color |
| 154 | 162 | float u0, v0; // texture stage 0 coordinates |
| 163 | float uv_stretch, pad; // UV stretch (used by HLSL) | |
| 155 | 164 | }; |
| 156 | 165 | |
| 157 | 166 | |
| r11559 | r11560 | |
| 164 | 173 | int refresh; // current refresh rate |
| 165 | 174 | int create_error_count; // number of consecutive create errors |
| 166 | 175 | |
| 176 | win_window_info * window; // current window info | |
| 177 | ||
| 167 | 178 | d3d_device * device; // pointer to the Direct3DDevice object |
| 168 | 179 | int gamma_supported; // is full screen gamma supported? |
| 169 | 180 | d3d_present_parameters presentation; // set of presentation parameters |
| r11559 | r11560 | |
| 174 | 185 | d3d_vertex * lockedbuf; // pointer to the locked vertex buffer |
| 175 | 186 | int numverts; // number of accumulated vertices |
| 176 | 187 | |
| 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 | ||
| 177 | 194 | poly_info poly[VERTEX_BUFFER_SIZE / 3];// array to hold polygons as they are created |
| 178 | 195 | int numpolys; // number of accumulated polygons |
| 179 | 196 | |
| r11559 | r11560 | |
| 191 | 208 | DWORD texture_max_height; // texture maximum height |
| 192 | 209 | |
| 193 | 210 | texture_info * last_texture; // previous texture |
| 211 | UINT32 last_texture_flags; // previous texture flags | |
| 194 | 212 | int last_blendenable; // previous blendmode |
| 195 | 213 | int last_blendop; // previous blendmode |
| 196 | 214 | int last_blendsrc; // previous blendmode |
| r11559 | r11560 | |
| 201 | 219 | |
| 202 | 220 | bitmap_t * vector_bitmap; // experimental: bitmap for vectors |
| 203 | 221 | 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) | |
| 204 | 234 | }; |
| 205 | 235 | |
| 206 | 236 | |
| r11559 | r11560 | |
| 322 | 352 | if (texture != d3d->last_texture) |
| 323 | 353 | { |
| 324 | 354 | d3d->last_texture = texture; |
| 355 | d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags); | |
| 325 | 356 | 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 | } | |
| 326 | 363 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result); |
| 327 | 364 | } |
| 328 | 365 | } |
| r11559 | r11560 | |
| 338 | 375 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 339 | 376 | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 340 | 377 | 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); | |
| 341 | 382 | } |
| 342 | 383 | } |
| 343 | 384 | |
| r11559 | r11560 | |
| 352 | 393 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 353 | 394 | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 354 | 395 | 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); | |
| 355 | 400 | } |
| 356 | 401 | } |
| 357 | 402 | |
| r11559 | r11560 | |
| 364 | 409 | d3d->last_modmode = modmode; |
| 365 | 410 | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, modmode); |
| 366 | 411 | 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); | |
| 367 | 414 | } |
| 368 | 415 | } |
| 369 | 416 | |
| r11559 | r11560 | |
| 447 | 494 | static int device_create_resources(d3d_info *d3d); |
| 448 | 495 | static void device_delete(d3d_info *d3d); |
| 449 | 496 | static void device_delete_resources(d3d_info *d3d); |
| 450 | static int device_verify_caps(d3d_info *d3d); | |
| 497 | static int device_verify_caps(d3d_info *d3d, win_window_info *window); | |
| 451 | 498 | static int device_test_cooperative(d3d_info *d3d); |
| 452 | 499 | |
| 453 | 500 | // video modes |
| r11559 | r11560 | |
| 534 | 581 | // allocate memory for our structures |
| 535 | 582 | d3d = global_alloc_clear(d3d_info); |
| 536 | 583 | window->drawdata = d3d; |
| 584 | d3d->window = window; | |
| 537 | 585 | |
| 538 | 586 | // experimental: load a PNG to use for vector rendering; it is treated |
| 539 | 587 | // as a brightness map |
| r11559 | r11560 | |
| 545 | 593 | d3d->vector_bitmap = render_load_png(file, NULL, "vector.png", d3d->vector_bitmap, NULL); |
| 546 | 594 | } |
| 547 | 595 | |
| 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 | ||
| 548 | 601 | // configure the adapter for the mode we want |
| 549 | 602 | if (config_adapter_mode(window)) |
| 550 | 603 | goto error; |
| r11559 | r11560 | |
| 580 | 633 | |
| 581 | 634 | // experimental: free the vector PNG |
| 582 | 635 | global_free(d3d->vector_bitmap); |
| 636 | d3d->vector_bitmap = NULL; | |
| 583 | 637 | |
| 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 | ||
| 584 | 645 | // free the memory in the window |
| 585 | 646 | global_free(d3d); |
| 586 | 647 | window->drawdata = NULL; |
| r11559 | r11560 | |
| 618 | 679 | render_primitive *prim; |
| 619 | 680 | HRESULT result; |
| 620 | 681 | |
| 682 | // if we're in the middle of resizing, leave things alone | |
| 683 | if (window->resize_state == RESIZE_STATE_RESIZING) | |
| 684 | return 0; | |
| 685 | ||
| 621 | 686 | // if we haven't been created, just punt |
| 622 | 687 | if (d3d == NULL) |
| 623 | 688 | return 1; |
| r11559 | r11560 | |
| 644 | 709 | |
| 645 | 710 | mtlog_add("drawd3d_window_draw: begin"); |
| 646 | 711 | |
| 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 | ||
| 647 | 715 | // first update any textures |
| 648 | 716 | window->primlist->acquire_lock(); |
| 649 | 717 | for (prim = window->primlist->first(); prim != NULL; prim = prim->next()) |
| r11559 | r11560 | |
| 692 | 760 | result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0); |
| 693 | 761 | mtlog_add("drawd3d_window_draw: present end"); |
| 694 | 762 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device present call\n", (int)result); |
| 763 | ||
| 695 | 764 | return 0; |
| 696 | 765 | } |
| 697 | 766 | |
| r11559 | r11560 | |
| 712 | 781 | device_delete(d3d); |
| 713 | 782 | |
| 714 | 783 | // verify the caps |
| 715 | verify = device_verify_caps(d3d); | |
| 784 | verify = device_verify_caps(d3d, window); | |
| 716 | 785 | if (verify == 2) |
| 717 | 786 | { |
| 718 | 787 | mame_printf_error("Error: Device does not meet minimum requirements for Direct3D rendering\n"); |
| r11559 | r11560 | |
| 778 | 847 | d3d->presentation.FullScreen_RefreshRateInHz = d3d->refresh; |
| 779 | 848 | d3d->presentation.PresentationInterval = ((video_config.triplebuf && window->fullscreen) || video_config.waitvsync || video_config.syncrefresh) ? |
| 780 | 849 | D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; |
| 850 | ||
| 781 | 851 | // create the D3D device |
| 782 | 852 | result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd, |
| 783 | 853 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device); |
| r11559 | r11560 | |
| 829 | 899 | } |
| 830 | 900 | } |
| 831 | 901 | |
| 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 | ||
| 832 | 954 | return device_create_resources(d3d); |
| 833 | 955 | } |
| 834 | 956 | |
| r11559 | r11560 | |
| 846 | 968 | result = (*d3dintf->device.create_vertex_buffer)(d3d->device, |
| 847 | 969 | sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE, |
| 848 | 970 | 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); | |
| 850 | 972 | if (result != D3D_OK) |
| 851 | 973 | { |
| 852 | 974 | mame_printf_error("Error creating vertex buffer (%08X)", (UINT32)result); |
| r11559 | r11560 | |
| 854 | 976 | } |
| 855 | 977 | |
| 856 | 978 | // set the vertex format |
| 857 | result = (*d3dintf->device.set_vertex_ | |
| 979 | result = (*d3dintf->device.set_vertex_fo | |
| 858 | 980 | if (result != D3D_OK) |
| 859 | 981 | { |
| 860 | mame_printf_error("Error setting vertex | |
| 982 | mame_printf_error("Error setting vertex fo | |
| 861 | 983 | return 1; |
| 862 | 984 | } |
| 863 | 985 | |
| r11559 | r11560 | |
| 883 | 1005 | |
| 884 | 1006 | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); |
| 885 | 1007 | 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); | |
| 886 | 1010 | |
| 887 | 1011 | // reset the local states to force updates |
| 888 | 1012 | reset_render_states(d3d); |
| 889 | 1013 | |
| 890 | 1014 | // clear the buffer |
| 891 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB( | |
| 1015 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0); | |
| 892 | 1016 | result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0); |
| 893 | 1017 | |
| 894 | 1018 | // experimental: if we have a vector bitmap, create a texture for it |
| r11559 | r11560 | |
| 908 | 1032 | d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 909 | 1033 | } |
| 910 | 1034 | |
| 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 | ||
| 911 | 1078 | return 0; |
| 912 | 1079 | } |
| 913 | 1080 | |
| r11559 | r11560 | |
| 947 | 1114 | (*d3dintf->texture.release)(tex->d3dtex); |
| 948 | 1115 | if (tex->d3dsurface != NULL) |
| 949 | 1116 | (*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); | |
| 950 | 1129 | global_free(tex); |
| 951 | 1130 | } |
| 952 | 1131 | |
| r11559 | r11560 | |
| 954 | 1133 | if (d3d->vertexbuf != NULL) |
| 955 | 1134 | (*d3dintf->vertexbuf.release)(d3d->vertexbuf); |
| 956 | 1135 | 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 | } | |
| 957 | 1187 | } |
| 958 | 1188 | |
| 959 | 1189 | |
| r11559 | r11560 | |
| 962 | 1192 | // device_verify_caps |
| 963 | 1193 | //============================================================ |
| 964 | 1194 | |
| 965 | static int device_verify_caps(d3d_info *d3d) | |
| 1195 | static int device_verify_caps(d3d_info *d3d, win_window_info *window) | |
| 966 | 1196 | { |
| 967 | 1197 | int retval = 0; |
| 968 | 1198 | HRESULT result; |
| r11559 | r11560 | |
| 978 | 1208 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_HEIGHT, &d3d->texture_max_height); |
| 979 | 1209 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 980 | 1210 | |
| 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 | ||
| 981 | 1220 | // verify presentation capabilities |
| 982 | 1221 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps); |
| 983 | 1222 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| r11559 | r11560 | |
| 1474 | 1713 | |
| 1475 | 1714 | vertex[3].u0 = d3d->vector_texture->ustop; |
| 1476 | 1715 | 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; | |
| 1477 | 1721 | } |
| 1722 | else if(d3d->default_texture != NULL) | |
| 1723 | { | |
| 1724 | vertex[0].u0 = d3d->default_texture->ustart; | |
| 1725 | vertex[0].v0 = d3d->default_texture->vstart; | |
| 1478 | 1726 | |
| 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 | ||
| 1479 | 1749 | // set the color, Z parameters to standard values |
| 1480 | 1750 | for (i = 0; i < 4; i++) |
| 1481 | 1751 | { |
| r11559 | r11560 | |
| 1510 | 1780 | poly_info *poly; |
| 1511 | 1781 | int i; |
| 1512 | 1782 | |
| 1783 | texture = texture != NULL ? texture : d3d->default_texture; | |
| 1784 | ||
| 1513 | 1785 | // get a pointer to the vertex buffer |
| 1514 | vertex = primitive_alloc(d3d, | |
| 1786 | vertex = primitive_alloc(d3d, 6); | |
| 1515 | 1787 | if (vertex == NULL) |
| 1516 | 1788 | return; |
| 1517 | 1789 | |
| r11559 | r11560 | |
| 1522 | 1794 | vertex[1].y = prim->bounds.y0 - 0.5f; |
| 1523 | 1795 | vertex[2].x = prim->bounds.x0 - 0.5f; |
| 1524 | 1796 | 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; | |
| 1527 | 1797 | |
| 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 | ||
| 1528 | 1805 | // set the texture coordinates |
| 1529 | if | |
| 1806 | if | |
| 1530 | 1807 | { |
| 1531 | 1808 | float du = texture->ustop - texture->ustart; |
| 1532 | 1809 | float dv = texture->vstop - texture->vstart; |
| r11559 | r11560 | |
| 1536 | 1813 | vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v; |
| 1537 | 1814 | vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u; |
| 1538 | 1815 | 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; | |
| 1541 | 1830 | } |
| 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 | } | |
| 1542 | 1840 | |
| 1543 | 1841 | // determine the color, allowing for over modulation |
| 1544 | 1842 | r = (INT32)(prim->color.r * 255.0f); |
| r11559 | r11560 | |
| 1569 | 1867 | color = D3DCOLOR_ARGB(a, r, g, b); |
| 1570 | 1868 | |
| 1571 | 1869 | // set the color, Z parameters to standard values |
| 1572 | for (i = 0; i < | |
| 1870 | for (i = 0; i < 6; i++) | |
| 1573 | 1871 | { |
| 1574 | 1872 | vertex[i].z = 0.0f; |
| 1575 | 1873 | vertex[i].rhw = 1.0f; |
| r11559 | r11560 | |
| 1578 | 1876 | |
| 1579 | 1877 | // now add a polygon entry |
| 1580 | 1878 | poly = &d3d->poly[d3d->numpolys++]; |
| 1581 | poly->type = D3DPT_TRIANGLEST | |
| 1879 | poly->type = D3DPT_TRIANGLELIST | |
| 1582 | 1880 | poly->count = 2; |
| 1583 | poly->numverts = | |
| 1881 | poly->numverts = 6; | |
| 1584 | 1882 | poly->flags = prim->flags; |
| 1585 | 1883 | poly->modmode = modmode; |
| 1586 | 1884 | poly->texture = texture; |
| r11559 | r11560 | |
| 1643 | 1941 | result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex)); |
| 1644 | 1942 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result); |
| 1645 | 1943 | |
| 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; | |
| 1646 | 1964 | // now do the polys |
| 1647 | 1965 | for (polynum = vertnum = 0; polynum < d3d->numpolys; polynum++) |
| 1648 | 1966 | { |
| r11559 | r11560 | |
| 1661 | 1979 | set_filter(d3d, newfilter); |
| 1662 | 1980 | set_wrap(d3d, PRIMFLAG_GET_TEXWRAP(poly->flags)); |
| 1663 | 1981 | 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 | } | |
| 1664 | 2083 | } |
| 1665 | 2084 | |
| 1666 | 2085 | // set the blendmode if different |
| 1667 | 2086 | set_blendmode(d3d, PRIMFLAG_GET_BLENDMODE(poly->flags)); |
| 1668 | 2087 | |
| 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 | ||
| 1673 | 2274 | vertnum += poly->numverts; |
| 1674 | 2275 | } |
| 1675 | 2276 | |
| 2277 | (*d3dintf->surface.release)(backbuffer); | |
| 2278 | ||
| 1676 | 2279 | // reset the vertex count |
| 1677 | 2280 | d3d->numverts = 0; |
| 1678 | 2281 | d3d->numpolys = 0; |
| r11559 | r11560 | |
| 1702 | 2305 | // compute the size |
| 1703 | 2306 | texture_compute_size(d3d, texsource->width, texsource->height, texture); |
| 1704 | 2307 | |
| 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 | ||
| 1705 | 2311 | // non-screen textures are easy |
| 1706 | 2312 | if (!PRIMFLAG_GET_SCREENTEX(flags)) |
| 1707 | 2313 | { |
| r11559 | r11560 | |
| 1757 | 2363 | { |
| 1758 | 2364 | texture->d3dfinaltex = texture->d3dtex; |
| 1759 | 2365 | 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); | |
| 1760 | 2386 | break; |
| 1761 | 2387 | } |
| 1762 | 2388 | } |
| r11559 | r11560 | |
| 1794 | 2420 | finalfmt = (format != d3d->yuv_format) ? format : D3DFMT_A8R8G8B8; |
| 1795 | 2421 | result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &texture->d3dfinaltex); |
| 1796 | 2422 | 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 | ||
| 1797 | 2445 | break; |
| 2446 | } | |
| 1798 | 2447 | (*d3dintf->texture.release)(texture->d3dtex); |
| 1799 | 2448 | texture->d3dtex = NULL; |
| 1800 | 2449 | } |
| r11559 | r11560 | |
| 2438 | 3087 | result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 2439 | 3088 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 2440 | 3089 | 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); | |
| 2442 | 3091 | reset_render_states(d3d); |
| 2443 | 3092 | |
| 2444 | 3093 | // start the scene |
| r11559 | r11560 | |
| 2500 | 3149 | |
| 2501 | 3150 | // reset the render target and release our reference to the backbuffer |
| 2502 | 3151 | 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); | |
| 2504 | 3153 | (*d3dintf->surface.release)(backbuffer); |
| 2505 | 3154 | reset_render_states(d3d); |
| 2506 | 3155 | } |
| r11559 | r11560 | |
| 2545 | 3194 | |
| 2546 | 3195 | // if we didn't find one, create a new texture |
| 2547 | 3196 | if (texture == NULL) |
| 3197 | { | |
| 2548 | 3198 | texture = texture_create(d3d, &prim->texture, prim->flags); |
| 3199 | } | |
| 2549 | 3200 | |
| 2550 | 3201 | // if we found it, but with a different seqid, copy the data |
| 2551 | 3202 | if (texture->texinfo.seqid != prim->texture.seqid) |
| r11559 | r11560 | |
|---|---|---|
| 1897 | 1897 | // set the flags and add it to the list |
| 1898 | 1898 | prim->flags = PRIMFLAG_TEXORIENT(container_xform.orientation) | |
| 1899 | 1899 | PRIMFLAG_BLENDMODE(BLENDMODE_RGB_MULTIPLY) | |
| 1900 | PRIMFLAG_TEXFORMAT(container.overlay()->format()); | |
| 1900 | PRIMFLAG_TEXFORMAT(container.overlay()->format()) | | |
| 1901 | PRIMFLAG_TEXSHADE(1); | |
| 1901 | 1902 | } |
| 1902 | 1903 | list.append_or_return(*prim, !got_scaled); |
| 1903 | 1904 | } |
| r11559 | r11560 | |
|---|---|---|
| 132 | 132 | const int PRIMFLAG_TEXWRAP_SHIFT = 14; |
| 133 | 133 | const UINT32 PRIMFLAG_TEXWRAP_MASK = 1 << PRIMFLAG_TEXWRAP_SHIFT; |
| 134 | 134 | |
| 135 | const int PRIMFLAG_TEXSHADE_SHIFT = 15; | |
| 136 | const UINT32 PRIMFLAG_TEXSHADE_MASK = 3 << PRIMFLAG_TEXSHADE_SHIFT; | |
| 135 | 137 | |
| 136 | 138 | |
| 137 | 139 | //************************************************************************** |
| r11559 | r11560 | |
| 156 | 158 | #define PRIMFLAG_TEXWRAP(x) ((x) << PRIMFLAG_TEXWRAP_SHIFT) |
| 157 | 159 | #define PRIMFLAG_GET_TEXWRAP(x) (((x) & PRIMFLAG_TEXWRAP_MASK) >> PRIMFLAG_TEXWRAP_SHIFT) |
| 158 | 160 | |
| 161 | #define PRIMFLAG_TEXSHADE(x) ((x) << PRIMFLAG_TEXSHADE_SHIFT) | |
| 162 | #define PRIMFLAG_GET_TEXSHADE(x) (((x) & PRIMFLAG_TEXSHADE_MASK) >> PRIMFLAG_TEXSHADE_SHIFT) | |
| 159 | 163 | |
| 160 | 164 | |
| 165 | ||
| 161 | 166 | //************************************************************************** |
| 162 | 167 | // TYPE DEFINITIONS |
| 163 | 168 | //************************************************************************** |
| Previous | 15994 Revisions | Next |