| Index: ddraw/ShaderGen2D.cpp |
| — | — | @@ -106,8 +106,10 @@ |
| 107 | 107 | static const char const_bt601_coeff[] =
|
| 108 | 108 | "const mat3 bt601_coeff = mat3(1.164,1.164,1.164,0.0,-0.392,2.017,1.596,-0.813,0.0);\n\
|
| 109 | 109 | const vec3 yuv_offsets = vec3(-0.0625, -0.5, -0.5);\n";
|
| | 110 | +static const char const_bt601_coeff_inv[] =
|
| | 111 | +"const mat3 bt601_coeff_inv = mat3(0.2569,-0.1483,.4394,.5044,-.2911,-.3679,.0979,.4394,-.0715);\n\
|
| | 112 | +const vec3 yuv_offsets_inv = vec3(0.0625, 0.5, 0.5);\n";
|
| 110 | 113 |
|
| 111 | | -
|
| 112 | 114 | // Attributes
|
| 113 | 115 | static const char attr_xy[] = "attribute vec2 xy;\n";
|
| 114 | 116 | static const char attr_rgb[] = "attribute vec3 rgb;\n";
|
| — | — | @@ -163,6 +165,7 @@ |
| 164 | 166 | static const char op_destoutdestblend[] = "gl_FragColor = (vec4(pixel)/vec4(colorsizedest)) * texture2D(desttex,gl_TexCoord[1].st);\n";
|
| 165 | 167 | static const char op_destout[] = "gl_FragColor = vec4(pixel)/vec4(colorsizedest);\n";
|
| 166 | 168 | static const char op_destoutyuvrgb[] = "gl_FragColor = yuvatorgba(vec4(pixel)/vec4(colorsizedest));\n";
|
| | 169 | +static const char op_destoutrgbyuv[] = "gl_FragColor = rgbatoyuva(vec4(pixel)/vec4(colorsizedest));\n";
|
| 167 | 170 | static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
|
| 168 | 171 | mat4 proj = mat4(\n\
|
| 169 | 172 | vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
|
| — | — | @@ -189,6 +192,11 @@ |
| 190 | 193 | {\n\
|
| 191 | 194 | return vec4(vec3(bt601_coeff * (yuva.rgb + yuv_offsets)),yuva.a);\n\
|
| 192 | 195 | }\n\n";
|
| | 196 | +static const char func_rgbatoyuva[] =
|
| | 197 | +"vec4 rgbatoyuva(vec4 rgba)\n\
|
| | 198 | +{\n\
|
| | 199 | + return vec4(vec3((bt601_coeff_inv * rgba.rgb) + yuv_offsets_inv),rgba.a);\n\
|
| | 200 | +}\n\n";
|
| 193 | 201 | static const char func_readrgbg[] = "";
|
| 194 | 202 | static const char func_readgrgb[] = "";
|
| 195 | 203 | static const char func_readuyvy[] = "";
|
| — | — | @@ -900,6 +908,17 @@ |
| 901 | 909 | break;
|
| 902 | 910 | }
|
| 903 | 911 |
|
| | 912 | + switch (desttype)
|
| | 913 | + {
|
| | 914 | + case 0:
|
| | 915 | + default:
|
| | 916 | + break;
|
| | 917 | + case 0x83:
|
| | 918 | + if ((srctype >= 0x80) && (srctype <= 0x83)) break;
|
| | 919 | + String_Append(fsrc, const_bt601_coeff_inv);
|
| | 920 | + break;
|
| | 921 | + }
|
| | 922 | +
|
| 904 | 923 | // Uniforms
|
| 905 | 924 | if (id & DDBLT_COLORFILL) String_Append(fsrc, unif_fillcolor);
|
| 906 | 925 | else
|
| — | — | @@ -969,7 +988,7 @@ |
| 970 | 989 | if (usedest) String_Append(fsrc, var_dest);
|
| 971 | 990 |
|
| 972 | 991 | // Functions
|
| 973 | | - switch (srctype2)
|
| | 992 | + switch (srctype)
|
| 974 | 993 | {
|
| 975 | 994 | case 0x20:
|
| 976 | 995 | break;
|
| — | — | @@ -982,6 +1001,7 @@ |
| 983 | 1002 | case 0x82:
|
| 984 | 1003 | break;
|
| 985 | 1004 | case 0x83:
|
| | 1005 | + if ((desttype >= 0x80) && (desttype <= 0x83)) break;
|
| 986 | 1006 | String_Append(fsrc, func_yuvatorgba);
|
| 987 | 1007 | break;
|
| 988 | 1008 | default:
|
| — | — | @@ -988,6 +1008,26 @@ |
| 989 | 1009 | break;
|
| 990 | 1010 | }
|
| 991 | 1011 |
|
| | 1012 | + switch (desttype)
|
| | 1013 | + {
|
| | 1014 | + case 0x20:
|
| | 1015 | + break;
|
| | 1016 | + case 0x21:
|
| | 1017 | + break;
|
| | 1018 | + case 0x80:
|
| | 1019 | + break;
|
| | 1020 | + case 0x81:
|
| | 1021 | + break;
|
| | 1022 | + case 0x82:
|
| | 1023 | + break;
|
| | 1024 | + case 0x83:
|
| | 1025 | + if ((srctype >= 0x80) && (srctype <= 0x83)) break;
|
| | 1026 | + String_Append(fsrc, func_rgbatoyuva);
|
| | 1027 | + break;
|
| | 1028 | + default:
|
| | 1029 | + break;
|
| | 1030 | + }
|
| | 1031 | +
|
| 992 | 1032 | // Main
|
| 993 | 1033 | String_Append(fsrc, mainstart);
|
| 994 | 1034 | if (id & 0x10000000) String_Append(fsrc, op_clip);
|
| — | — | @@ -1054,6 +1094,22 @@ |
| 1055 | 1095 | {
|
| 1056 | 1096 | switch (srctype)
|
| 1057 | 1097 | {
|
| | 1098 | + case 0x00:
|
| | 1099 | + case 0x10:
|
| | 1100 | + case 0x11:
|
| | 1101 | + case 0x12:
|
| | 1102 | + case 0x13:
|
| | 1103 | + switch (desttype)
|
| | 1104 | + {
|
| | 1105 | + case 0:
|
| | 1106 | + default:
|
| | 1107 | + String_Append(fsrc, op_destout);
|
| | 1108 | + break;
|
| | 1109 | + case 0x83:
|
| | 1110 | + String_Append(fsrc, op_destoutrgbyuv);
|
| | 1111 | + break;
|
| | 1112 | + }
|
| | 1113 | + break;
|
| 1058 | 1114 | case 0x83:
|
| 1059 | 1115 | if ((desttype >= 0x80) && (desttype <= 0x83))
|
| 1060 | 1116 | String_Append(fsrc, op_destout);
|