Mercurial > mplayer.hg
comparison libvo/gl_common.c @ 33926:6e3f257d7b05
Add disabled feature: noise filter for vo_gl.
author | reimar |
---|---|
date | Fri, 26 Aug 2011 18:51:51 +0000 |
parents | 2d87bbea9e0f |
children | 9bb97722d8c7 |
comparison
equal
deleted
inserted
replaced
33925:162828e38481 | 33926:6e3f257d7b05 |
---|---|
895 mpglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); | 895 mpglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
896 mpglActiveTexture(GL_TEXTURE0); | 896 mpglActiveTexture(GL_TEXTURE0); |
897 free(tex); | 897 free(tex); |
898 } | 898 } |
899 | 899 |
900 #define NOISE_RES 2048 | |
901 | |
902 /** | |
903 * \brief creates the 1D lookup texture needed to generate pseudo-random numbers. | |
904 * \param unit texture unit to attach texture to | |
905 */ | |
906 static void gen_noise_lookup_tex(GLenum unit) { | |
907 GLfloat *tex = calloc(NOISE_RES, sizeof(*tex)); | |
908 uint32_t lcg = 0x79381c11; | |
909 int i; | |
910 for (i = 0; i < NOISE_RES; i++) | |
911 tex[i] = (double)i / (NOISE_RES - 1); | |
912 for (i = 0; i < NOISE_RES - 1; i++) { | |
913 int remain = NOISE_RES - i; | |
914 int idx = i + (lcg >> 16) % remain; | |
915 GLfloat tmp = tex[i]; | |
916 tex[i] = tex[idx]; | |
917 tex[idx] = tmp; | |
918 lcg = lcg * 1664525 + 1013904223; | |
919 } | |
920 mpglActiveTexture(unit); | |
921 mpglTexImage1D(GL_TEXTURE_1D, 0, 1, NOISE_RES, 0, GL_RED, GL_FLOAT, tex); | |
922 mpglTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_PRIORITY, 1.0); | |
923 mpglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
924 mpglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
925 mpglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); | |
926 mpglActiveTexture(GL_TEXTURE0); | |
927 free(tex); | |
928 } | |
929 | |
900 static const char *bilin_filt_template = | 930 static const char *bilin_filt_template = |
901 "TEX yuv.%c, fragment.texcoord[%c], texture[%c], %s;\n"; | 931 "TEX yuv.%c, fragment.texcoord[%c], texture[%c], %s;\n"; |
902 | 932 |
903 #define BICUB_FILT_MAIN(textype) \ | 933 #define BICUB_FILT_MAIN(textype) \ |
904 /* first y-interpolation */ \ | 934 /* first y-interpolation */ \ |
1022 "PARAM vcoef = {%e, %e, %e};\n" | 1052 "PARAM vcoef = {%e, %e, %e};\n" |
1023 "PARAM offsets = {%e, %e, %e};\n" | 1053 "PARAM offsets = {%e, %e, %e};\n" |
1024 "TEMP res;\n" | 1054 "TEMP res;\n" |
1025 "MAD res.rgb, yuv.rrrr, ycoef, offsets;\n" | 1055 "MAD res.rgb, yuv.rrrr, ycoef, offsets;\n" |
1026 "MAD res.rgb, yuv.gggg, ucoef, res;\n" | 1056 "MAD res.rgb, yuv.gggg, ucoef, res;\n" |
1027 "MAD result.color.rgb, yuv.bbbb, vcoef, res;\n" | 1057 "MAD res.rgb, yuv.bbbb, vcoef, res;\n"; |
1028 "END"; | |
1029 | 1058 |
1030 static const char *yuv_pow_prog_template = | 1059 static const char *yuv_pow_prog_template = |
1031 "PARAM ycoef = {%e, %e, %e};\n" | 1060 "PARAM ycoef = {%e, %e, %e};\n" |
1032 "PARAM ucoef = {%e, %e, %e};\n" | 1061 "PARAM ucoef = {%e, %e, %e};\n" |
1033 "PARAM vcoef = {%e, %e, %e};\n" | 1062 "PARAM vcoef = {%e, %e, %e};\n" |
1035 "PARAM gamma = {%e, %e, %e};\n" | 1064 "PARAM gamma = {%e, %e, %e};\n" |
1036 "TEMP res;\n" | 1065 "TEMP res;\n" |
1037 "MAD res.rgb, yuv.rrrr, ycoef, offsets;\n" | 1066 "MAD res.rgb, yuv.rrrr, ycoef, offsets;\n" |
1038 "MAD res.rgb, yuv.gggg, ucoef, res;\n" | 1067 "MAD res.rgb, yuv.gggg, ucoef, res;\n" |
1039 "MAD_SAT res.rgb, yuv.bbbb, vcoef, res;\n" | 1068 "MAD_SAT res.rgb, yuv.bbbb, vcoef, res;\n" |
1040 "POW result.color.r, res.r, gamma.r;\n" | 1069 "POW res.r, res.r, gamma.r;\n" |
1041 "POW result.color.g, res.g, gamma.g;\n" | 1070 "POW res.g, res.g, gamma.g;\n" |
1042 "POW result.color.b, res.b, gamma.b;\n" | 1071 "POW res.b, res.b, gamma.b;\n"; |
1043 "END"; | |
1044 | 1072 |
1045 static const char *yuv_lookup_prog_template = | 1073 static const char *yuv_lookup_prog_template = |
1046 "PARAM ycoef = {%e, %e, %e, 0};\n" | 1074 "PARAM ycoef = {%e, %e, %e, 0};\n" |
1047 "PARAM ucoef = {%e, %e, %e, 0};\n" | 1075 "PARAM ucoef = {%e, %e, %e, 0};\n" |
1048 "PARAM vcoef = {%e, %e, %e, 0};\n" | 1076 "PARAM vcoef = {%e, %e, %e, 0};\n" |
1049 "PARAM offsets = {%e, %e, %e, 0.125};\n" | 1077 "PARAM offsets = {%e, %e, %e, 0.125};\n" |
1050 "TEMP res;\n" | 1078 "TEMP res;\n" |
1051 "MAD res, yuv.rrrr, ycoef, offsets;\n" | 1079 "MAD res, yuv.rrrr, ycoef, offsets;\n" |
1052 "MAD res.rgb, yuv.gggg, ucoef, res;\n" | 1080 "MAD res.rgb, yuv.gggg, ucoef, res;\n" |
1053 "MAD res.rgb, yuv.bbbb, vcoef, res;\n" | 1081 "MAD res.rgb, yuv.bbbb, vcoef, res;\n" |
1054 "TEX result.color.r, res.raaa, texture[%c], 2D;\n" | 1082 "TEX res.r, res.raaa, texture[%c], 2D;\n" |
1055 "ADD res.a, res.a, 0.25;\n" | 1083 "ADD res.a, res.a, 0.25;\n" |
1056 "TEX result.color.g, res.gaaa, texture[%c], 2D;\n" | 1084 "TEX res.g, res.gaaa, texture[%c], 2D;\n" |
1057 "ADD res.a, res.a, 0.25;\n" | 1085 "ADD res.a, res.a, 0.25;\n" |
1058 "TEX result.color.b, res.baaa, texture[%c], 2D;\n" | 1086 "TEX res.b, res.baaa, texture[%c], 2D;\n"; |
1059 "END"; | |
1060 | 1087 |
1061 static const char *yuv_lookup3d_prog_template = | 1088 static const char *yuv_lookup3d_prog_template = |
1062 "TEX result.color, yuv, texture[%c], 3D;\n" | 1089 "TEMP res;\n" |
1063 "END"; | 1090 "TEX res, yuv, texture[%c], 3D;\n"; |
1091 | |
1092 static const char *noise_filt_template = | |
1093 "MUL coord.xy, fragment.texcoord[0], {%e, %e};\n" | |
1094 "TEMP rand;\n" | |
1095 "TEX rand.r, coord.x, texture[%c], 1D;\n" | |
1096 "ADD rand.r, rand.r, coord.y;\n" | |
1097 "TEX rand.r, rand.r, texture[%c], 1D;\n" | |
1098 "MAD res.rgb, rand.rrrr, {%e, %e, %e}, res;\n"; | |
1064 | 1099 |
1065 /** | 1100 /** |
1066 * \brief creates and initializes helper textures needed for scaling texture read | 1101 * \brief creates and initializes helper textures needed for scaling texture read |
1067 * \param scaler scaler type to create texture for | 1102 * \param scaler scaler type to create texture for |
1068 * \param texu contains next free texture unit number | 1103 * \param texu contains next free texture unit number |
1304 char *yuv_prog, *prog_pos; | 1339 char *yuv_prog, *prog_pos; |
1305 int cur_texu = 3; | 1340 int cur_texu = 3; |
1306 char lum_scale_texs[1]; | 1341 char lum_scale_texs[1]; |
1307 char chrom_scale_texs[1]; | 1342 char chrom_scale_texs[1]; |
1308 char conv_texs[1]; | 1343 char conv_texs[1]; |
1344 char filt_texs[1]; | |
1309 GLint i; | 1345 GLint i; |
1310 // this is the conversion matrix, with y, u, v factors | 1346 // this is the conversion matrix, with y, u, v factors |
1311 // for red, green, blue and the constant offsets | 1347 // for red, green, blue and the constant offsets |
1312 float yuv2rgb[3][4]; | 1348 float yuv2rgb[3][4]; |
1349 int noise = 0; | |
1313 create_conv_textures(params, &cur_texu, conv_texs); | 1350 create_conv_textures(params, &cur_texu, conv_texs); |
1314 create_scaler_textures(YUV_LUM_SCALER(type), &cur_texu, lum_scale_texs); | 1351 create_scaler_textures(YUV_LUM_SCALER(type), &cur_texu, lum_scale_texs); |
1315 if (YUV_CHROM_SCALER(type) == YUV_LUM_SCALER(type)) | 1352 if (YUV_CHROM_SCALER(type) == YUV_LUM_SCALER(type)) |
1316 memcpy(chrom_scale_texs, lum_scale_texs, sizeof(chrom_scale_texs)); | 1353 memcpy(chrom_scale_texs, lum_scale_texs, sizeof(chrom_scale_texs)); |
1317 else | 1354 else |
1318 create_scaler_textures(YUV_CHROM_SCALER(type), &cur_texu, chrom_scale_texs); | 1355 create_scaler_textures(YUV_CHROM_SCALER(type), &cur_texu, chrom_scale_texs); |
1356 | |
1357 if (noise) { | |
1358 gen_noise_lookup_tex(cur_texu); | |
1359 filt_texs[0] = '0' + cur_texu++; | |
1360 } | |
1361 | |
1319 mpglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &i); | 1362 mpglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &i); |
1320 if (i < cur_texu) | 1363 if (i < cur_texu) |
1321 mp_msg(MSGT_VO, MSGL_ERR, | 1364 mp_msg(MSGT_VO, MSGL_ERR, |
1322 "[gl] %i texture units needed for this type of YUV fragment support (found %i)\n", | 1365 "[gl] %i texture units needed for this type of YUV fragment support (found %i)\n", |
1323 cur_texu, i); | 1366 cur_texu, i); |
1365 break; | 1408 break; |
1366 default: | 1409 default: |
1367 mp_msg(MSGT_VO, MSGL_ERR, "[gl] unknown conversion type %i\n", YUV_CONVERSION(type)); | 1410 mp_msg(MSGT_VO, MSGL_ERR, "[gl] unknown conversion type %i\n", YUV_CONVERSION(type)); |
1368 break; | 1411 break; |
1369 } | 1412 } |
1413 prog_remain -= strlen(prog_pos); | |
1414 prog_pos += strlen(prog_pos); | |
1415 | |
1416 if (noise) { | |
1417 double str = 1.0 / 8; | |
1418 double scale_x = (double)NOISE_RES / texw; | |
1419 double scale_y = (double)NOISE_RES / texh; | |
1420 if (rect) { | |
1421 scale_x /= texw; | |
1422 scale_y /= texh; | |
1423 } | |
1424 snprintf(prog_pos, prog_remain, noise_filt_template, | |
1425 scale_x, scale_y, | |
1426 filt_texs[0], filt_texs[0], | |
1427 str, str, str); | |
1428 prog_remain -= strlen(prog_pos); | |
1429 prog_pos += strlen(prog_pos); | |
1430 } | |
1431 snprintf(prog_pos, prog_remain, "MOV result.color.rgb, res;\nEND"); | |
1432 | |
1370 mp_msg(MSGT_VO, MSGL_DBG2, "[gl] generated fragment program:\n%s\n", yuv_prog); | 1433 mp_msg(MSGT_VO, MSGL_DBG2, "[gl] generated fragment program:\n%s\n", yuv_prog); |
1371 loadGPUProgram(GL_FRAGMENT_PROGRAM, yuv_prog); | 1434 loadGPUProgram(GL_FRAGMENT_PROGRAM, yuv_prog); |
1372 free(yuv_prog); | 1435 free(yuv_prog); |
1373 } | 1436 } |
1374 | 1437 |