comparison src/video/SDL_renderer_gl.c @ 2846:3d7833d5a4be

Slight optimization of the shader, no need to scale into 0..255
author Sam Lantinga <slouken@libsdl.org>
date Sun, 07 Dec 2008 04:38:32 +0000
parents 1cc5d5b164e2
children 7d020441fa81
comparison
equal deleted inserted replaced
2845:1cc5d5b164e2 2846:3d7833d5a4be
378 info->texture_formats[j++] = info->texture_formats[i]; 378 info->texture_formats[j++] = info->texture_formats[i];
379 } 379 }
380 } 380 }
381 --info->num_texture_formats; 381 --info->num_texture_formats;
382 } 382 }
383 /*
383 if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) { 384 if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
384 data->GL_APPLE_ycbcr_422_supported = SDL_TRUE; 385 data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
385 } 386 }
386 if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) { 387 if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
387 data->GL_MESA_ycbcr_texture_supported = SDL_TRUE; 388 data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
388 } 389 }
390 */
389 if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) { 391 if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
390 data->glTextureRangeAPPLE = 392 data->glTextureRangeAPPLE =
391 (void (*)(GLenum, GLsizei, const GLvoid *)) 393 (void (*)(GLenum, GLsizei, const GLvoid *))
392 SDL_GL_GetProcAddress("glTextureRangeAPPLE"); 394 SDL_GL_GetProcAddress("glTextureRangeAPPLE");
393 } 395 }
513 // G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128) 515 // G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
514 // B = 1.164(Y-16) + 2.018(Cb-128) 516 // B = 1.164(Y-16) + 2.018(Cb-128)
515 // Byte layout is Cb, Y1, Cr, Y2. 517 // Byte layout is Cb, Y1, Cr, Y2.
516 // 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr 518 // 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
517 // !!! FIXME: this ignores blendmodes, etc. 519 // !!! FIXME: this ignores blendmodes, etc.
518 // !!! FIXME: this could be more efficient...use a dot product for green, not convert to 255.0 range, etc. 520 // !!! FIXME: this could be more efficient...use a dot product for green, etc.
519 static const char *fragment_program_UYVY_source_code = 521 static const char *fragment_program_UYVY_source_code =
520 "!!ARBfp1.0\n" 522 "!!ARBfp1.0\n"
521 523
522 // outputs... 524 // outputs...
523 "OUTPUT outcolor = result.color;\n" 525 "OUTPUT outcolor = result.color;\n"
529 531
530 // We need 32 bits to store the data, but each pixel is 16 bits in itself. 532 // We need 32 bits to store the data, but each pixel is 16 bits in itself.
531 // halve the coordinates to grab the correct 32 bits for the fragment. 533 // halve the coordinates to grab the correct 32 bits for the fragment.
532 "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n" 534 "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
533 535
534 // Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in r,g,b,a. 536 // Sample the YUV texture. Cb, Y1, Cr, Y2, are stored x,y,z,w
535 // !!! FIXME: "RECT" needs to be "2D" if we're not using texture_rectangle extension. :/ 537 // !!! FIXME: "RECT" needs to be "2D" if we're not using texture_rectangle extension. :/
536 "TEX uyvy, work, texture[0], RECT;\n" 538 "TEX uyvy, work, texture[0], RECT;\n"
537 539
538 // Scale from 0.0/1.0 to 0.0/255.0 and do subtractions. (!!! FIXME: optimize!) 540 // Do subtractions (128/255, 16/255, 128/255, 16/255)
539 "MUL uyvy, uyvy, { 255.0, 255.0, 255.0, 255.0 };\n" 541 "SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
540 "SUB uyvy, uyvy, { 128.0, 16.0, 128.0, 16.0 };\n"
541 542
542 // Choose the luminance component by texcoord. 543 // Choose the luminance component by texcoord.
543 // !!! FIXME: laziness wins out for now... just average Y1 and Y2. 544 // !!! FIXME: laziness wins out for now... just average Y1 and Y2.
544 "ADD luminance, uyvy.yyyy, uyvy.wwww;\n" 545 "ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
545 "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n" 546 "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
553 // Add luminance Cr and Cb, store to RGB channels. 554 // Add luminance Cr and Cb, store to RGB channels.
554 "ADD work.rgb, luminance, uyvy;\n" 555 "ADD work.rgb, luminance, uyvy;\n"
555 556
556 // Do final addition for Green channel. (!!! FIXME: this should be a DPH?) 557 // Do final addition for Green channel. (!!! FIXME: this should be a DPH?)
557 "ADD work.g, work.g, uyvy.w;\n" 558 "ADD work.g, work.g, uyvy.w;\n"
558
559 // Scale back to 0.0/1.0. (this number is 1.0/255.0).
560 "MUL work, work, { 0.0039215686274509803, 0.0039215686274509803, 0.0039215686274509803, 0.0039215686274509803 };\n"
561 559
562 // Make sure alpha channel is fully opaque. (!!! FIXME: blend modes!) 560 // Make sure alpha channel is fully opaque. (!!! FIXME: blend modes!)
563 "MOV work.a, { 1.0 };\n" 561 "MOV work.a, { 1.0 };\n"
564 562
565 // Store out the final fragment color. 563 // Store out the final fragment color.