GLScaler.hh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef GLSCALER_HH
  2. #define GLSCALER_HH
  3. #include "GLUtil.hh"
  4. namespace openmsx {
  5. class FrameSource;
  6. /** Abstract base class for OpenGL scalers.
  7. * A scaler is an algorithm that converts low-res graphics to hi-res graphics.
  8. */
  9. class GLScaler
  10. {
  11. public:
  12. virtual ~GLScaler() = default;
  13. /** Scales the image in the given area, which must consist of lines which
  14. * are all equally wide.
  15. * Scaling factor depends on the concrete scaler.
  16. * @param src Source: texture containing the frame to be scaled.
  17. * @param superImpose Texture containing the to-be-superimposed image (can be nullptr).
  18. * @param srcStartY Y-coordinate of the top source line (inclusive).
  19. * @param srcEndY Y-coordinate of the bottom source line (exclusive).
  20. * @param srcWidth The number of pixels per line for the given area.
  21. * @param dstStartY Y-coordinate of the top destination line (inclusive).
  22. * @param dstEndY Y-coordinate of the bottom destination line (exclusive).
  23. * @param dstWidth The number of pixels per line on the output screen.
  24. * @param logSrcHeight The logical height of the complete src texture
  25. * (actual texture height can be double as high in case of
  26. * non-interlace). This is needed to translate src-Y-coordinates
  27. * to superImpose-Y-coordinates.
  28. */
  29. virtual void scaleImage(
  30. gl::ColorTexture& src, gl::ColorTexture* superImpose,
  31. unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
  32. unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
  33. unsigned logSrcHeight) = 0;
  34. virtual void uploadBlock(
  35. unsigned srcStartY, unsigned srcEndY,
  36. unsigned lineWidth, FrameSource& paintFrame);
  37. protected:
  38. explicit GLScaler(const std::string& progName);
  39. void setup(bool superImpose);
  40. /** Helper method to draw a rectangle with multiple texture coordinates.
  41. * This method is similar to Texture::drawRect() but it calculates a
  42. * seconds set of texture coordinates. The first tex-coords are used
  43. * for the MSX texture (textur unit 0), and are calculated from
  44. * src{Start,End}Y and src.getHeight(). The second set of tex-coord are
  45. * used for the superimpose texture (texture unit 1) and are calculated
  46. * from src{Start,End}Y and logSrcHeight.
  47. * @param src
  48. * @param superImpose
  49. * @param srcStartY
  50. * @param srcEndY
  51. * @param srcWidth
  52. * @param dstStartY
  53. * @param dstEndY
  54. * @param dstWidth
  55. * @param logSrcHeight
  56. * @param textureFromZero If true, the texture coordinates of subpixels
  57. * will start from zero: for example in 4x zoom the source coordinates
  58. * will be 0.0, 0.25, 0.5, 0.75. If false, the texture coordinates of
  59. * subpixels will be centered: for example in 4x zoom the source
  60. * coordinates will be 0.125, 0.375, 0.625, 0.875.
  61. */
  62. void execute(gl::ColorTexture& src, gl::ColorTexture* superImpose,
  63. unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
  64. unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
  65. unsigned logSrcHeight,
  66. bool textureFromZero = false);
  67. protected:
  68. gl::VertexArray vao;
  69. gl::BufferObject vbo[2];
  70. gl::ShaderProgram program[2];
  71. GLint unifTexSize[2];
  72. };
  73. } // namespace openmsx
  74. #endif // GLSCALER_HH