RenderSettings.hh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #ifndef RENDERSETTINGS_HH
  2. #define RENDERSETTINGS_HH
  3. #include "BooleanSetting.hh"
  4. #include "EnumSetting.hh"
  5. #include "FloatSetting.hh"
  6. #include "IntegerSetting.hh"
  7. #include "StringSetting.hh"
  8. #include "Observer.hh"
  9. #include "gl_mat.hh"
  10. namespace openmsx {
  11. class CommandController;
  12. class Interpreter;
  13. /** Class containing all settings for renderers.
  14. * Keeping the settings here makes sure they are preserved when the user
  15. * switches to another renderer.
  16. */
  17. class RenderSettings final : private Observer<Setting>
  18. {
  19. public:
  20. /** Enumeration of Renderers known to openMSX.
  21. * This is the full list, the list of available renderers may be smaller.
  22. */
  23. enum RendererID { UNINITIALIZED, DUMMY, SDL, SDLGL_PP };
  24. using RendererSetting = EnumSetting<RendererID>;
  25. /** Render accuracy: granularity of the rendered area.
  26. */
  27. enum Accuracy { ACC_SCREEN, ACC_LINE, ACC_PIXEL };
  28. /** Scaler algorithm
  29. */
  30. enum ScaleAlgorithm {
  31. SCALER_SIMPLE, SCALER_SAI, SCALER_SCALE,
  32. SCALER_HQ, SCALER_HQLITE, SCALER_RGBTRIPLET, SCALER_TV, SCALER_MLAA,
  33. NO_SCALER
  34. };
  35. enum DisplayDeform {
  36. DEFORM_NORMAL, DEFORM_3D
  37. };
  38. explicit RenderSettings(CommandController& commandController);
  39. ~RenderSettings();
  40. /** Accuracy [screen, line, pixel]. */
  41. Accuracy getAccuracy() const { return accuracySetting.getEnum(); }
  42. /** Deinterlacing [on, off]. */
  43. bool getDeinterlace() const { return deinterlaceSetting.getBoolean(); }
  44. /** Deflicker [on, off]. */
  45. bool getDeflicker() const { return deflickerSetting.getBoolean(); }
  46. /** The current max frameskip. */
  47. IntegerSetting& getMaxFrameSkipSetting() { return maxFrameSkipSetting; }
  48. int getMaxFrameSkip() const { return maxFrameSkipSetting.getInt(); }
  49. /** The current min frameskip. */
  50. IntegerSetting& getMinFrameSkipSetting() { return minFrameSkipSetting; }
  51. int getMinFrameSkip() const { return minFrameSkipSetting.getInt(); }
  52. /** Full screen [on, off]. */
  53. BooleanSetting& getFullScreenSetting() { return fullScreenSetting; }
  54. bool getFullScreen() const { return fullScreenSetting.getBoolean(); }
  55. /** The amount of gamma correction. */
  56. FloatSetting& getGammaSetting() { return gammaSetting; }
  57. float getGamma() const { return gammaSetting.getDouble(); }
  58. /** Brightness video setting. */
  59. FloatSetting& getBrightnessSetting() { return brightnessSetting; }
  60. float getBrightness() const { return brightnessSetting.getDouble(); }
  61. /** Contrast video setting. */
  62. FloatSetting& getContrastSetting() { return contrastSetting; }
  63. float getContrast() const { return contrastSetting.getDouble(); }
  64. /** Color matrix setting. */
  65. StringSetting& getColorMatrixSetting() { return colorMatrixSetting; }
  66. /** Returns true iff the current color matrix is the identity matrix. */
  67. bool isColorMatrixIdentity() { return cmIdentity; }
  68. /** The amount of glow [0..100]. */
  69. int getGlow() const { return glowSetting.getInt(); }
  70. /** The amount of noise to add to the frame. */
  71. FloatSetting& getNoiseSetting() { return noiseSetting; }
  72. float getNoise() const { return noiseSetting.getDouble(); }
  73. /** The amount of horizontal blur [0..256]. */
  74. int getBlurFactor() const {
  75. return (horizontalBlurSetting.getInt()) * 256 / 100;
  76. }
  77. /** The alpha value [0..255] of the gap between scanlines. */
  78. int getScanlineFactor() const {
  79. return 255 - ((scanlineAlphaSetting.getInt() * 255) / 100);
  80. }
  81. /** The amount of space [0..1] between scanlines. */
  82. float getScanlineGap() const {
  83. return scanlineAlphaSetting.getInt() * 0.01f;
  84. }
  85. /** The current renderer. */
  86. RendererSetting& getRendererSetting() { return rendererSetting; }
  87. RendererID getRenderer() const { return rendererSetting.getEnum(); }
  88. /** The current scaling algorithm. */
  89. ScaleAlgorithm getScaleAlgorithm() const {
  90. return scaleAlgorithmSetting.getEnum();
  91. }
  92. /** The current scaling factor. */
  93. IntegerSetting& getScaleFactorSetting() { return scaleFactorSetting; }
  94. int getScaleFactor() const { return scaleFactorSetting.getInt(); }
  95. /** Limit number of sprites per line?
  96. * If true, limit number of sprites per line as real VDP does.
  97. * If false, display all sprites.
  98. * For accurate emulation, this setting should be on.
  99. * Turning it off can improve games with a lot of flashing sprites,
  100. * such as Aleste. */
  101. BooleanSetting& getLimitSpritesSetting() { return limitSpritesSetting; }
  102. /** Disable sprite rendering? */
  103. bool getDisableSprites() const { return disableSpritesSetting.getBoolean(); }
  104. /** CmdTiming [real, broken].
  105. * This setting is intended for debugging only, not for users. */
  106. EnumSetting<bool>& getCmdTimingSetting() { return cmdTimingSetting; }
  107. /** TooFastAccess [real, ignored].
  108. * Indicates whether too fast VDP VRAM access should be correctly
  109. * emulated (= some accesses are dropped) or ignored (= all accesses
  110. * are correctly executed). */
  111. EnumSetting<bool>& getTooFastAccessSetting() { return tooFastAccessSetting; }
  112. /** Display deformation (normal, 3d)
  113. * ATM this only works when using the SDLGL-PP renderer. */
  114. DisplayDeform getDisplayDeform() { return displayDeformSetting.getEnum(); }
  115. /** VSync [on, off]
  116. * ATM this only works when using the SDLGL-PP renderer. */
  117. BooleanSetting& getVSyncSetting() { return vSyncSetting; }
  118. /** Amount of horizontal stretch.
  119. * This number represents the amount of MSX pixels (normal width) that
  120. * will be stretched to the complete width of the host window. */
  121. FloatSetting& getHorizontalStretchSetting() {
  122. return horizontalStretchSetting;
  123. }
  124. float getHorizontalStretch() const {
  125. return horizontalStretchSetting.getDouble();
  126. }
  127. /** The amount of time until the pointer is hidden in the openMSX
  128. * window. negative means: no hiding, 0 means immediately. */
  129. FloatSetting& getPointerHideDelaySetting() {
  130. return pointerHideDelaySetting;
  131. }
  132. float getPointerHideDelay() const {
  133. return pointerHideDelaySetting.getDouble();
  134. }
  135. /** Is black frame interleaving enabled? */
  136. bool getInterleaveBlackFrame() const {
  137. return interleaveBlackFrameSetting.getBoolean();
  138. }
  139. /** Apply brightness, contrast and gamma transformation on the input
  140. * color component. The component is expected to be in the range
  141. * [0.0 .. 1.0] but it's not an error if it lays outside of this range.
  142. * The return value is guaranteed to lay inside this range.
  143. * This method skips the cross-influence of color components on each
  144. * other that is controlled by the "color_matrix" setting.
  145. */
  146. float transformComponent(float c) const;
  147. /** Apply brightness, contrast and gamma transformation on the input
  148. * color. The R, G and B component are expected to be in the range
  149. * [0.0 .. 1.0] but it's not an error if a component lays outside of
  150. * this range. After transformation it's guaranteed all components
  151. * lay inside this range.
  152. */
  153. gl::vec3 transformRGB(gl::vec3 rgb) const;
  154. private:
  155. static EnumSetting<ScaleAlgorithm>::Map getScalerMap();
  156. static EnumSetting<RendererID>::Map getRendererMap();
  157. // Observer:
  158. void update(const Setting& setting) override;
  159. /** Sets the "brightness" and "contrast" fields according to the setting
  160. * values.
  161. */
  162. void updateBrightnessAndContrast();
  163. void parseColorMatrix(Interpreter& interp, const TclObject& value);
  164. EnumSetting<Accuracy> accuracySetting;
  165. BooleanSetting deinterlaceSetting;
  166. BooleanSetting deflickerSetting;
  167. IntegerSetting maxFrameSkipSetting;
  168. IntegerSetting minFrameSkipSetting;
  169. BooleanSetting fullScreenSetting;
  170. FloatSetting gammaSetting;
  171. FloatSetting brightnessSetting;
  172. FloatSetting contrastSetting;
  173. StringSetting colorMatrixSetting;
  174. IntegerSetting glowSetting;
  175. FloatSetting noiseSetting;
  176. RendererSetting rendererSetting;
  177. IntegerSetting horizontalBlurSetting;
  178. EnumSetting<ScaleAlgorithm> scaleAlgorithmSetting;
  179. IntegerSetting scaleFactorSetting;
  180. IntegerSetting scanlineAlphaSetting;
  181. BooleanSetting limitSpritesSetting;
  182. BooleanSetting disableSpritesSetting;
  183. EnumSetting<bool> cmdTimingSetting;
  184. EnumSetting<bool> tooFastAccessSetting;
  185. EnumSetting<DisplayDeform> displayDeformSetting;
  186. BooleanSetting vSyncSetting;
  187. FloatSetting horizontalStretchSetting;
  188. FloatSetting pointerHideDelaySetting;
  189. BooleanSetting interleaveBlackFrameSetting;
  190. float brightness;
  191. float contrast;
  192. /** Parsed color matrix, kept in sync with colorMatrix setting. */
  193. gl::mat3 colorMatrix;
  194. /** True iff color matrix is identity matrix. */
  195. bool cmIdentity;
  196. };
  197. } // namespace openmsx
  198. #endif