GLSimpleScaler.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "GLSimpleScaler.hh"
  2. #include "RenderSettings.hh"
  3. namespace openmsx {
  4. GLSimpleScaler::GLSimpleScaler(
  5. RenderSettings& renderSettings_, GLScaler& fallback_)
  6. : GLScaler("simple")
  7. , renderSettings(renderSettings_)
  8. , fallback(fallback_)
  9. {
  10. for (int i = 0; i < 2; ++i) {
  11. program[i].activate();
  12. unifTexStepX[i] = program[i].getUniformLocation("texStepX");
  13. unifCnst[i] = program[i].getUniformLocation("cnst");
  14. }
  15. }
  16. void GLSimpleScaler::scaleImage(
  17. gl::ColorTexture& src, gl::ColorTexture* superImpose,
  18. unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
  19. unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
  20. unsigned logSrcHeight)
  21. {
  22. int i = superImpose ? 1 : 0;
  23. GLfloat blur = renderSettings.getBlurFactor() / 256.0f;
  24. GLfloat scanline = renderSettings.getScanlineFactor() / 255.0f;
  25. unsigned yScale = (dstEndY - dstStartY) / (srcEndY - srcStartY);
  26. if (yScale == 0) {
  27. // less lines in destination than in source
  28. // (factor=1 / interlace) --> disable scanlines
  29. scanline = 1.0f;
  30. yScale = 1;
  31. }
  32. if ((blur != 0.0f) || (scanline != 1.0f) || superImpose) {
  33. setup(superImpose != nullptr);
  34. if ((blur != 0.0f) && (srcWidth != 1)) { // srcWidth check: workaround for ATI cards
  35. src.setInterpolation(true);
  36. }
  37. GLfloat scan_a = (yScale & 1) ? 0.5f : ((yScale + 1) / (2.0f * yScale));
  38. GLfloat scan_b = 2.0f - 2.0f * scanline;
  39. GLfloat scan_c = scanline;
  40. if (!superImpose) {
  41. // small optimization in simple.frag:
  42. // divide by 2 here instead of on every pixel
  43. scan_b *= 0.5f;
  44. scan_c *= 0.5f;
  45. }
  46. glUniform3f(unifTexStepX[i], 1.0f / srcWidth, 1.0f / srcWidth, 0.0f);
  47. glUniform4f(unifCnst[i], scan_a, scan_b, scan_c, blur);
  48. execute(src, superImpose,
  49. srcStartY, srcEndY, srcWidth,
  50. dstStartY, dstEndY, dstWidth,
  51. logSrcHeight);
  52. src.setInterpolation(false);
  53. } else {
  54. fallback.scaleImage(src, superImpose, srcStartY, srcEndY, srcWidth,
  55. dstStartY, dstEndY, dstWidth, logSrcHeight);
  56. }
  57. }
  58. } // namespace openmsx