3459{
3460 D3D11_SUBRESOURCE_DATA buffer_data;
3463 D3D11_BUFFER_DESC buffer_desc;
3468
3470 {
3474 };
3476 {
3483 };
3485 {
3487 };
3489 {
3492 };
3493 static const char vs_code_outline[] =
3494 "float3x2 transform_geometry;\n"
3495 "float stroke_width;\n"
3496 "float4 transform_rtx;\n"
3497 "float4 transform_rty;\n"
3498 "\n"
3499 "struct output\n"
3500 "{\n"
3501 " float2 p : WORLD_POSITION;\n"
3502 " float4 b : BEZIER;\n"
3503 " nointerpolation float2x2 stroke_transform : STROKE_TRANSFORM;\n"
3504 " float4 position : SV_POSITION;\n"
3505 "};\n"
3506 "\n"
3507 "/* The lines PₚᵣₑᵥP₀ and P₀Pₙₑₓₜ, both offset by ±½w, intersect each other at:\n"
3508 " *\n"
3509 " * Pᵢ = P₀ ± w · ½q⃑ᵢ.\n"
3510 " *\n"
3511 " * Where:\n"
3512 " *\n"
3513 " * q⃑ᵢ = q̂ₚᵣₑᵥ⊥ + tan(½θ) · -q̂ₚᵣₑᵥ\n"
3514 " * θ = ∠PₚᵣₑᵥP₀Pₙₑₓₜ\n"
3515 " * q⃑ₚᵣₑᵥ = P₀ - Pₚᵣₑᵥ */\n"
3516 "void main(float2 position : POSITION, float2 prev : PREV, float2 next : NEXT, out struct output o)\n"
3517 "{\n"
3518 " float2 q_prev, q_next, v_p, q_i;\n"
3519 " float2x2 geom;\n"
3520 " float l;\n"
3521 "\n"
3522 " o.stroke_transform = float2x2(transform_rtx.xy, transform_rty.xy) * stroke_width * 0.5f;\n"
3523 "\n"
3524 " geom = float2x2(transform_geometry._11_21, transform_geometry._12_22);\n"
3525 " q_prev = normalize(mul(geom, prev));\n"
3526 " q_next = normalize(mul(geom, next));\n"
3527 "\n"
3528 " /* tan(½θ) = sin(θ) / (1 + cos(θ))\n"
3529 " * = (q̂ₚᵣₑᵥ⊥ · q̂ₙₑₓₜ) / (1 + (q̂ₚᵣₑᵥ · q̂ₙₑₓₜ)) */\n"
3530 " v_p = float2(-q_prev.y, q_prev.x);\n"
3531 " l = -dot(v_p, q_next) / (1.0f + dot(q_prev, q_next));\n"
3532 " q_i = l * q_prev + v_p;\n"
3533 "\n"
3534 " o.b = float4(0.0, 0.0, 0.0, 0.0);\n"
3535 "\n"
3536 " o.p = mul(float3(position, 1.0f), transform_geometry) + stroke_width * 0.5f * q_i;\n"
3537 " position = mul(float2x3(transform_rtx.xyz, transform_rty.xyz), float3(o.p, 1.0f))\n"
3538 " * float2(transform_rtx.w, transform_rty.w);\n"
3539 " o.position = float4(position + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
3540 "}\n";
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558 static const char vs_code_bezier_outline[] =
3559 "float3x2 transform_geometry;\n"
3560 "float stroke_width;\n"
3561 "float4 transform_rtx;\n"
3562 "float4 transform_rty;\n"
3563 "\n"
3564 "struct output\n"
3565 "{\n"
3566 " float2 p : WORLD_POSITION;\n"
3567 " float4 b : BEZIER;\n"
3568 " nointerpolation float2x2 stroke_transform : STROKE_TRANSFORM;\n"
3569 " float4 position : SV_POSITION;\n"
3570 "};\n"
3571 "\n"
3572 "void main(float2 position : POSITION, float2 p0 : P0, float2 p1 : P1, float2 p2 : P2,\n"
3573 " float2 prev : PREV, float2 next : NEXT, out struct output o)\n"
3574 "{\n"
3575 " float2 q_prev, q_next, v_p, q_i, p;\n"
3576 " float2x2 geom, rt;\n"
3577 " float l;\n"
3578 "\n"
3579 " geom = float2x2(transform_geometry._11_21, transform_geometry._12_22);\n"
3580 " rt = float2x2(transform_rtx.xy, transform_rty.xy);\n"
3581 " o.stroke_transform = rt * stroke_width * 0.5f;\n"
3582 "\n"
3583 " p = mul(geom, position);\n"
3584 " p0 = mul(geom, p0);\n"
3585 " p1 = mul(geom, p1);\n"
3586 " p2 = mul(geom, p2);\n"
3587 "\n"
3588 " p -= p0;\n"
3589 " p1 -= p0;\n"
3590 " p2 -= p0;\n"
3591 "\n"
3592 " q_prev = normalize(mul(geom, prev));\n"
3593 " q_next = normalize(mul(geom, next));\n"
3594 "\n"
3595 " v_p = float2(-q_prev.y, q_prev.x);\n"
3596 " l = -dot(v_p, q_next) / (1.0f + dot(q_prev, q_next));\n"
3597 " q_i = l * q_prev + v_p;\n"
3598 " p += 0.5f * stroke_width * q_i;\n"
3599 "\n"
3600 " v_p = mul(rt, p2);\n"
3601 " v_p = normalize(float2(-v_p.y, v_p.x));\n"
3602 " if (abs(dot(mul(rt, p1), v_p)) < 1.0f)\n"
3603 " {\n"
3604 " o.b.xzw = float3(0.0f, 0.0f, 0.0f);\n"
3605 " o.b.y = dot(mul(rt, p), v_p);\n"
3606 " }\n"
3607 " else\n"
3608 " {\n"
3609 " o.b.zw = sign(dot(mul(rt, p1), v_p)) * v_p;\n"
3610 " v_p = -float2(-p.y, p.x) / dot(float2(-p1.y, p1.x), p2);\n"
3611 " o.b.x = dot(v_p, p1 - 0.5f * p2);\n"
3612 " o.b.y = dot(v_p, p1);\n"
3613 " }\n"
3614 "\n"
3615 " o.p = mul(float3(position, 1.0f), transform_geometry) + 0.5f * stroke_width * q_i;\n"
3616 " position = mul(float2x3(transform_rtx.xyz, transform_rty.xyz), float3(o.p, 1.0f))\n"
3617 " * float2(transform_rtx.w, transform_rty.w);\n"
3618 " o.position = float4(position + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
3619 "}\n";
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637 static const char vs_code_arc_outline[] =
3638 "float3x2 transform_geometry;\n"
3639 "float stroke_width;\n"
3640 "float4 transform_rtx;\n"
3641 "float4 transform_rty;\n"
3642 "\n"
3643 "struct output\n"
3644 "{\n"
3645 " float2 p : WORLD_POSITION;\n"
3646 " float4 b : BEZIER;\n"
3647 " nointerpolation float2x2 stroke_transform : STROKE_TRANSFORM;\n"
3648 " float4 position : SV_POSITION;\n"
3649 "};\n"
3650 "\n"
3651 "void main(float2 position : POSITION, float2 p0 : P0, float2 p1 : P1, float2 p2 : P2,\n"
3652 " float2 prev : PREV, float2 next : NEXT, out struct output o)\n"
3653 "{\n"
3654 " float2 q_prev, q_next, v_p, q_i, p;\n"
3655 " float2x2 geom, rt, p_inv;\n"
3656 " float l;\n"
3657 " float a;\n"
3658 " float2 bc;\n"
3659 "\n"
3660 " geom = float2x2(transform_geometry._11_21, transform_geometry._12_22);\n"
3661 " rt = float2x2(transform_rtx.xy, transform_rty.xy);\n"
3662 " o.stroke_transform = rt * stroke_width * 0.5f;\n"
3663 "\n"
3664 " p = mul(geom, position);\n"
3665 " p0 = mul(geom, p0);\n"
3666 " p1 = mul(geom, p1);\n"
3667 " p2 = mul(geom, p2);\n"
3668 "\n"
3669 " p -= p0;\n"
3670 " p1 -= p0;\n"
3671 " p2 -= p0;\n"
3672 "\n"
3673 " q_prev = normalize(mul(geom, prev));\n"
3674 " q_next = normalize(mul(geom, next));\n"
3675 "\n"
3676 " v_p = float2(-q_prev.y, q_prev.x);\n"
3677 " l = -dot(v_p, q_next) / (1.0f + dot(q_prev, q_next));\n"
3678 " q_i = l * q_prev + v_p;\n"
3679 " p += 0.5f * stroke_width * q_i;\n"
3680 "\n"
3681 " p_inv = float2x2(p1.y, -p1.x, p2.y - p1.y, p1.x - p2.x) / (p1.x * p2.y - p2.x * p1.y);\n"
3682 " o.b.xy = mul(p_inv, p) + float2(1.0f, 0.0f);\n"
3683 " o.b.zw = 0.0f;\n"
3684 "\n"
3685 " o.p = mul(float3(position, 1.0f), transform_geometry) + 0.5f * stroke_width * q_i;\n"
3686 " position = mul(float2x3(transform_rtx.xyz, transform_rty.xyz), float3(o.p, 1.0f))\n"
3687 " * float2(transform_rtx.w, transform_rty.w);\n"
3688 " o.position = float4(position + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
3689 "}\n";
3690 static const char vs_code_triangle[] =
3691 "float3x2 transform_geometry;\n"
3692 "float4 transform_rtx;\n"
3693 "float4 transform_rty;\n"
3694 "\n"
3695 "struct output\n"
3696 "{\n"
3697 " float2 p : WORLD_POSITION;\n"
3698 " float4 b : BEZIER;\n"
3699 " nointerpolation float2x2 stroke_transform : STROKE_TRANSFORM;\n"
3700 " float4 position : SV_POSITION;\n"
3701 "};\n"
3702 "\n"
3703 "void main(float2 position : POSITION, out struct output o)\n"
3704 "{\n"
3705 " o.p = mul(float3(position, 1.0f), transform_geometry);\n"
3706 " o.b = float4(1.0, 0.0, 1.0, 1.0);\n"
3707 " o.stroke_transform = float2x2(1.0, 0.0, 0.0, 1.0);\n"
3708 " position = mul(float2x3(transform_rtx.xyz, transform_rty.xyz), float3(o.p, 1.0f))\n"
3709 " * float2(transform_rtx.w, transform_rty.w);\n"
3710 " o.position = float4(position + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
3711 "}\n";
3712 static const char vs_code_curve[] =
3713 "float3x2 transform_geometry;\n"
3714 "float4 transform_rtx;\n"
3715 "float4 transform_rty;\n"
3716 "\n"
3717 "struct output\n"
3718 "{\n"
3719 " float2 p : WORLD_POSITION;\n"
3720 " float4 b : BEZIER;\n"
3721 " nointerpolation float2x2 stroke_transform : STROKE_TRANSFORM;\n"
3722 " float4 position : SV_POSITION;\n"
3723 "};\n"
3724 "\n"
3725 "void main(float2 position : POSITION, float3 texcoord : TEXCOORD0, out struct output o)\n"
3726 "{\n"
3727 " o.p = mul(float3(position, 1.0f), transform_geometry);\n"
3728 " o.b = float4(texcoord, 1.0);\n"
3729 " o.stroke_transform = float2x2(1.0, 0.0, 0.0, 1.0);\n"
3730 " position = mul(float2x3(transform_rtx.xyz, transform_rty.xyz), float3(o.p, 1.0f))\n"
3731 " * float2(transform_rtx.w, transform_rty.w);\n"
3732 " o.position = float4(position + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
3733 "}\n";
3734 static const char ps_code[] =
3735 "#define BRUSH_TYPE_SOLID 0\n"
3736 "#define BRUSH_TYPE_LINEAR 1\n"
3737 "#define BRUSH_TYPE_RADIAL 2\n"
3738 "#define BRUSH_TYPE_BITMAP 3\n"
3739 "#define BRUSH_TYPE_COUNT 4\n"
3740 "\n"
3741 "bool outline;\n"
3742 "bool is_arc;\n"
3743 "struct brush\n"
3744 "{\n"
3745 " uint type;\n"
3746 " float opacity;\n"
3747 " float4 data[3];\n"
3748 "} colour_brush, opacity_brush;\n"
3749 "\n"
3750 "SamplerState s0, s1;\n"
3751 "Texture2D t0, t1;\n"
3752 "Buffer<float4> b0, b1;\n"
3753 "\n"
3754 "struct input\n"
3755 "{\n"
3756 " float2 p : WORLD_POSITION;\n"
3757 " float4 b : BEZIER;\n"
3758 " nointerpolation float2x2 stroke_transform : STROKE_TRANSFORM;\n"
3759 "};\n"
3760 "\n"
3761 "float4 sample_gradient(Buffer<float4> gradient, uint stop_count, float position)\n"
3762 "{\n"
3763 " float4 c_low, c_high;\n"
3764 " float p_low, p_high;\n"
3765 " uint i;\n"
3766 "\n"
3767 " p_low = gradient.Load(0).x;\n"
3768 " c_low = gradient.Load(1);\n"
3769 " c_high = c_low;\n"
3770 "\n"
3771 " if (position < p_low)\n"
3772 " return c_low;\n"
3773 "\n"
3774 " for (i = 1; i < stop_count; ++i)\n"
3775 " {\n"
3776 " p_high = gradient.Load(i * 2).x;\n"
3777 " c_high = gradient.Load(i * 2 + 1);\n"
3778 "\n"
3779 " if (position >= p_low && position <= p_high)\n"
3780 " return lerp(c_low, c_high, (position - p_low) / (p_high - p_low));\n"
3781 "\n"
3782 " p_low = p_high;\n"
3783 " c_low = c_high;\n"
3784 " }\n"
3785 "\n"
3786 " return c_high;\n"
3787 "}\n"
3788 "\n"
3789 "float4 brush_linear(struct brush brush, Buffer<float4> gradient, float2 position)\n"
3790 "{\n"
3791 " float2 start, end, v_p, v_q;\n"
3792 " uint stop_count;\n"
3793 " float p;\n"
3794 "\n"
3795 " start = brush.data[0].xy;\n"
3796 " end = brush.data[0].zw;\n"
3797 " stop_count = asuint(brush.data[1].x);\n"
3798 "\n"
3799 " v_p = position - start;\n"
3800 " v_q = end - start;\n"
3801 " p = dot(v_q, v_p) / dot(v_q, v_q);\n"
3802 "\n"
3803 " return sample_gradient(gradient, stop_count, p);\n"
3804 "}\n"
3805 "\n"
3806 "float4 brush_radial(struct brush brush, Buffer<float4> gradient, float2 position)\n"
3807 "{\n"
3808 " float2 centre, offset, ra, rb, v_p, v_q, r;\n"
3809 " float b, c, l, t;\n"
3810 " uint stop_count;\n"
3811 "\n"
3812 " centre = brush.data[0].xy;\n"
3813 " offset = brush.data[0].zw;\n"
3814 " ra = brush.data[1].xy;\n"
3815 " rb = brush.data[1].zw;\n"
3816 " stop_count = asuint(brush.data[2].x);\n"
3817 "\n"
3818 " /* Project onto ra, rb. */\n"
3819 " r = float2(dot(ra, ra), dot(rb, rb));\n"
3820 " v_p = position - (centre + offset);\n"
3821 " v_p = float2(dot(v_p, ra), dot(v_p, rb)) / r;\n"
3822 " v_q = float2(dot(offset, ra), dot(offset, rb)) / r;\n"
3823 "\n"
3824 " /* ‖t·p̂ + q⃑‖ = 1\n"
3825 " * (t·p̂ + q⃑) · (t·p̂ + q⃑) = 1\n"
3826 " * t² + 2·(p̂·q⃑)·t + (q⃑·q⃑) = 1\n"
3827 " *\n"
3828 " * b = p̂·q⃑\n"
3829 " * c = q⃑·q⃑ - 1\n"
3830 " * t = -b + √(b² - c) */\n"
3831 " l = length(v_p);\n"
3832 " b = dot(v_p, v_q) / l;\n"
3833 " c = dot(v_q, v_q) - 1.0;\n"
3834 " t = -b + sqrt(b * b - c);\n"
3835 "\n"
3836 " return sample_gradient(gradient, stop_count, l / t);\n"
3837 "}\n"
3838 "\n"
3839 "float4 brush_bitmap(struct brush brush, Texture2D t, SamplerState s, float2 position)\n"
3840 "{\n"
3841 " float3 transform[2];\n"
3842 " bool ignore_alpha;\n"
3843 " float2 texcoord;\n"
3844 " float4 colour;\n"
3845 "\n"
3846 " transform[0] = brush.data[0].xyz;\n"
3847 " transform[1] = brush.data[1].xyz;\n"
3848 " ignore_alpha = asuint(brush.data[1].w);\n"
3849 "\n"
3850 " texcoord.x = dot(position.xy, transform[0].xy) + transform[0].z;\n"
3851 " texcoord.y = dot(position.xy, transform[1].xy) + transform[1].z;\n"
3852 " colour = t.Sample(s, texcoord);\n"
3853 " if (ignore_alpha)\n"
3854 " colour.a = 1.0;\n"
3855 " return colour;\n"
3856 "}\n"
3857 "\n"
3858 "float4 sample_brush(struct brush brush, Texture2D t, SamplerState s, Buffer<float4> b, float2 position)\n"
3859 "{\n"
3860 " if (brush.type == BRUSH_TYPE_SOLID)\n"
3861 " return brush.data[0] * brush.opacity;\n"
3862 " if (brush.type == BRUSH_TYPE_LINEAR)\n"
3863 " return brush_linear(brush, b, position) * brush.opacity;\n"
3864 " if (brush.type == BRUSH_TYPE_RADIAL)\n"
3865 " return brush_radial(brush, b, position) * brush.opacity;\n"
3866 " if (brush.type == BRUSH_TYPE_BITMAP)\n"
3867 " return brush_bitmap(brush, t, s, position) * brush.opacity;\n"
3868 " return float4(0.0, 0.0, 0.0, brush.opacity);\n"
3869 "}\n"
3870 "\n"
3871 "float4 main(struct input i) : SV_Target\n"
3872 "{\n"
3873 " float4 colour;\n"
3874 "\n"
3875 " colour = sample_brush(colour_brush, t0, s0, b0, i.p);\n"
3876 " if (opacity_brush.type < BRUSH_TYPE_COUNT)\n"
3877 " colour *= sample_brush(opacity_brush, t1, s1, b1, i.p).a;\n"
3878 "\n"
3879 " if (outline)\n"
3880 " {\n"
3881 " float2 du, dv, df;\n"
3882 " float4 uv;\n"
3883 "\n"
3884 " /* Evaluate the implicit form of the curve (u² - v = 0\n"
3885 " * for Béziers, u² + v² - 1 = 0 for arcs) in texture\n"
3886 " * space, using the screen-space partial derivatives\n"
3887 " * to convert the calculated distance to object space.\n"
3888 " *\n"
3889 " * d(x, y) = |f(x, y)| / ‖∇f(x, y)‖\n"
3890 " * = |f(x, y)| / √((∂f/∂x)² + (∂f/∂y)²)\n"
3891 " *\n"
3892 " * For Béziers:\n"
3893 " * f(x, y) = u(x, y)² - v(x, y)\n"
3894 " * ∂f/∂x = 2u · ∂u/∂x - ∂v/∂x\n"
3895 " * ∂f/∂y = 2u · ∂u/∂y - ∂v/∂y\n"
3896 " *\n"
3897 " * For arcs:\n"
3898 " * f(x, y) = u(x, y)² + v(x, y)² - 1\n"
3899 " * ∂f/∂x = 2u · ∂u/∂x + 2v · ∂v/∂x\n"
3900 " * ∂f/∂y = 2u · ∂u/∂y + 2v · ∂v/∂y */\n"
3901 " uv = i.b;\n"
3902 " du = float2(ddx(uv.x), ddy(uv.x));\n"
3903 " dv = float2(ddx(uv.y), ddy(uv.y));\n"
3904 "\n"
3905 " if (!is_arc)\n"
3906 " {\n"
3907 " df = 2.0f * uv.x * du - dv;\n"
3908 "\n"
3909 " clip(dot(df, uv.zw));\n"
3910 " clip(length(mul(i.stroke_transform, df)) - abs(uv.x * uv.x - uv.y));\n"
3911 " }\n"
3912 " else\n"
3913 " {\n"
3914 " df = 2.0f * uv.x * du + 2.0f * uv.y * dv;\n"
3915 "\n"
3916 " clip(dot(df, uv.zw));\n"
3917 " clip(length(mul(i.stroke_transform, df)) - abs(uv.x * uv.x + uv.y * uv.y - 1.0f));\n"
3918 " }\n"
3919 " }\n"
3920 " else\n"
3921 " {\n"
3922 " /* Evaluate the implicit form of the curve in texture space.\n"
3923 " * \"i.b.z\" determines which side of the curve is shaded. */\n"
3924 " if (!is_arc)\n"
3925 " {\n"
3926 " clip((i.b.x * i.b.x - i.b.y) * i.b.z);\n"
3927 " }\n"
3928 " else\n"
3929 " {\n"
3930 " clip((i.b.x * i.b.x + i.b.y * i.b.y - 1.0) * i.b.z);\n"
3931 " }\n"
3932 " }\n"
3933 "\n"
3934 " return colour;\n"
3935 "}\n";
3936 static const struct shape_info
3937 {
3940 unsigned int il_element_count;
3942 const char *vs_code;
3943 size_t vs_code_size;
3944 }
3945 shape_info[] =
3946 {
3948 "outline", vs_code_outline, sizeof(vs_code_outline) - 1},
3950 "bezier_outline", vs_code_bezier_outline, sizeof(vs_code_bezier_outline) - 1},
3952 "arc_outline", vs_code_arc_outline, sizeof(vs_code_arc_outline) - 1},
3954 "triangle", vs_code_triangle, sizeof(vs_code_triangle) - 1},
3956 "curve", vs_code_curve, sizeof(vs_code_curve) - 1},
3957 };
3958 static const struct
3959 {
3961 }
3963 {
3964 {-1.0f, 1.0f},
3965 {-1.0f, -1.0f},
3966 { 1.0f, 1.0f},
3967 { 1.0f, -1.0f},
3968 };
3971
3979 ID2D1Device6_AddRef(&render_target->
device->ID2D1Device6_iface);
3980
3984
3986 render_target->
ops = ops;
3987
3989 &IID_ID3D11Device1, (
void **)&render_target->
d3d_device)))
3990 {
3991 WARN(
"Failed to query ID3D11Device1 interface, hr %#lx.\n",
hr);
3993 }
3994
3998 {
3999 WARN(
"Failed to create device context state, hr %#lx.\n",
hr);
4001 }
4002
4004 {
4005 const struct shape_info *
si = &shape_info[
i];
4006
4008 "main",
"vs_4_0", 0, 0, &compiled,
NULL)))
4009 {
4010 WARN(
"Failed to compile shader for shape type %#x, hr %#lx.\n",
si->shape_type,
hr);
4012 }
4013
4014 if (
FAILED(
hr = ID3D11Device1_CreateInputLayout(render_target->
d3d_device,
si->il_desc,
si->il_element_count,
4015 ID3D10Blob_GetBufferPointer(compiled), ID3D10Blob_GetBufferSize(compiled),
4017 {
4018 WARN(
"Failed to create input layout for shape type %#x, hr %#lx.\n",
si->shape_type,
hr);
4019 ID3D10Blob_Release(compiled);
4021 }
4022
4024 ID3D10Blob_GetBufferPointer(compiled), ID3D10Blob_GetBufferSize(compiled),
4026 {
4027 WARN(
"Failed to create vertex shader for shape type %#x, hr %#lx.\n",
si->shape_type,
hr);
4028 ID3D10Blob_Release(compiled);
4030 }
4031
4032 ID3D10Blob_Release(compiled);
4033 }
4034
4035 buffer_desc.ByteWidth =
sizeof(
struct d2d_vs_cb);
4036 buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
4037 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
4038 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
4039 buffer_desc.MiscFlags = 0;
4040
4042 &render_target->
vs_cb)))
4043 {
4044 WARN(
"Failed to create constant buffer, hr %#lx.\n",
hr);
4046 }
4047
4048 if (
FAILED(
hr =
D3DCompile(ps_code,
sizeof(ps_code) - 1,
"ps",
NULL,
NULL,
"main",
"ps_4_0", 0, 0, &compiled,
NULL)))
4049 {
4050 WARN(
"Failed to compile the pixel shader, hr %#lx.\n",
hr);
4052 }
4053
4055 ID3D10Blob_GetBufferPointer(compiled), ID3D10Blob_GetBufferSize(compiled),
4056 NULL, &render_target->
ps)))
4057 {
4058 WARN(
"Failed to create pixel shader, hr %#lx.\n",
hr);
4059 ID3D10Blob_Release(compiled);
4061 }
4062
4063 ID3D10Blob_Release(compiled);
4064
4065 buffer_desc.ByteWidth =
sizeof(
struct d2d_ps_cb);
4066 buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
4067 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
4068 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
4069 buffer_desc.MiscFlags = 0;
4070
4072 &render_target->
ps_cb)))
4073 {
4074 WARN(
"Failed to create constant buffer, hr %#lx.\n",
hr);
4076 }
4077
4078 buffer_desc.ByteWidth =
sizeof(
indices);
4079 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4080 buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
4081 buffer_desc.CPUAccessFlags = 0;
4082 buffer_desc.MiscFlags = 0;
4083
4084 buffer_data.pSysMem =
indices;
4085 buffer_data.SysMemPitch = 0;
4086 buffer_data.SysMemSlicePitch = 0;
4087
4089 &buffer_desc, &buffer_data, &render_target->
ib)))
4090 {
4091 WARN(
"Failed to create clear index buffer, hr %#lx.\n",
hr);
4093 }
4094
4095 buffer_desc.ByteWidth =
sizeof(
quad);
4096 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4097 buffer_data.pSysMem =
quad;
4098
4099 render_target->
vb_stride =
sizeof(*quad);
4101 &buffer_desc, &buffer_data, &render_target->
vb)))
4102 {
4103 WARN(
"Failed to create clear vertex buffer, hr %#lx.\n",
hr);
4105 }
4106
4117 if (
FAILED(
hr = ID3D11Device1_CreateRasterizerState(render_target->
d3d_device, &rs_desc, &render_target->
rs)))
4118 {
4119 WARN(
"Failed to create clear rasteriser state, hr %#lx.\n",
hr);
4121 }
4122
4124 &IID_IDWriteFactory, (
IUnknown **)&dwrite_factory)))
4125 {
4126 ERR(
"Failed to create dwrite factory, hr %#lx.\n",
hr);
4128 }
4129
4131 IDWriteFactory_Release(dwrite_factory);
4133 {
4134 ERR(
"Failed to create default text rendering parameters, hr %#lx.\n",
hr);
4136 }
4137
4139
4141 {
4142 WARN(
"Failed to initialize clip stack.\n");
4145 }
4146
4149
4151
4155 if (render_target->
rs)
4156 ID3D11RasterizerState_Release(render_target->
rs);
4157 if (render_target->
vb)
4158 ID3D11Buffer_Release(render_target->
vb);
4159 if (render_target->
ib)
4160 ID3D11Buffer_Release(render_target->
ib);
4161 if (render_target->
ps_cb)
4162 ID3D11Buffer_Release(render_target->
ps_cb);
4163 if (render_target->
ps)
4164 ID3D11PixelShader_Release(render_target->
ps);
4165 if (render_target->
vs_cb)
4166 ID3D11Buffer_Release(render_target->
vs_cb);
4168 {
4173 }
4175 ID3DDeviceContextState_Release(render_target->
d3d_state);
4177 ID3D11Device1_Release(render_target->
d3d_device);
4178 ID2D1Device6_Release(&render_target->
device->ID2D1Device6_iface);
4179 ID2D1Factory_Release(render_target->
factory);
4181}
@ D2D1_FACTORY_TYPE_MULTI_THREADED
static struct d2d_factory * unsafe_impl_from_ID2D1Factory(ID2D1Factory *iface)
@ D3D11_INPUT_PER_VERTEX_DATA
HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages)
static BOOL d2d_clip_stack_init(struct d2d_clip_stack *stack)
static const struct ID2D1GdiInteropRenderTargetVtbl d2d_gdi_interop_render_target_vtbl
static const struct ID2D1DeviceContext6Vtbl d2d_device_context_vtbl
static const struct IDWriteTextRendererVtbl d2d_text_renderer_vtbl
static const struct IUnknownVtbl d2d_device_context_inner_unknown_vtbl
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei GLenum const GLvoid * indices
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL * feature_levels
static void quad(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
BOOL FrontCounterClockwise
BOOL AntialiasedLineEnable
FLOAT SlopeScaledDepthBias
IDWriteRenderingParams * default_text_rendering_params
ID2D1DeviceContext6 ID2D1DeviceContext6_iface
ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface
struct d2d_device * device