openMSX
GLRGBScaler.cc
Go to the documentation of this file.
1#include "GLRGBScaler.hh"
2#include "RenderSettings.hh"
3#include "narrow.hh"
4
5namespace openmsx {
6
8 RenderSettings& renderSettings_, GLScaler& fallback_)
9 : GLScaler("rgb")
10 , renderSettings(renderSettings_)
11 , fallback(fallback_)
12{
13 for (auto i : xrange(2)) {
14 program[i].activate();
15 unifCnsts[i] = program[i].getUniformLocation("cnsts");
16 }
17}
18
20 gl::ColorTexture& src, gl::ColorTexture* superImpose,
21 unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
22 unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
23 unsigned logSrcHeight)
24{
25 int i = superImpose ? 1 : 0;
26
27 GLfloat blur = narrow<float>(renderSettings.getBlurFactor()) * (1.0f / 256.0f);
28 GLfloat scanline = narrow<float>(renderSettings.getScanlineFactor()) * (1.0f / 255.0f);
29 unsigned yScale = (dstEndY - dstStartY) / (srcEndY - srcStartY);
30 if (yScale == 0) {
31 // less lines in destination than in source
32 // (factor=1 / interlace) --> disable scanlines
33 scanline = 1.0f;
34 yScale = 1;
35 }
36 if ((blur != 0.0f) || (scanline != 1.0f) || superImpose) {
37 setup(superImpose != nullptr);
38 if (srcWidth != 1) {
39 // workaround for ATI cards
40 src.setInterpolation(true);
41 } else {
42 // treat border as 256-pixel wide display area
43 srcWidth = 320;
44 }
45 auto yScaleF = narrow<float>(yScale);
46 GLfloat a = (yScale & 1) ? 0.5f : ((yScaleF + 1.0f) / (2.0f * yScaleF));
47 GLfloat c1 = blur;
48 GLfloat c2 = 3.0f - 2.0f * c1;
49 glUniform4f(unifCnsts[i],
50 a, // scan_a
51 (1.0f - scanline) * 2.0f * c2, // scan_b_c2
52 scanline * c2, // scan_c_c2
53 (c1 - c2) / c2); // scan_c1_2_2
54 execute(src, superImpose,
55 srcStartY, srcEndY, srcWidth,
56 dstStartY, dstEndY, dstWidth,
57 logSrcHeight);
58 src.setInterpolation(false);
59 } else {
60 fallback.scaleImage(src, superImpose,
61 srcStartY, srcEndY, srcWidth,
62 dstStartY, dstEndY, dstWidth,
63 logSrcHeight);
64 }
65}
66
67} // namespace openmsx
void setInterpolation(bool interpolation)
Enable/disable bilinear interpolation for this texture.
Definition GLUtil.cc:58
void scaleImage(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight) override
Scales the image in the given area, which must consist of lines which are all equally wide.
GLRGBScaler(RenderSettings &renderSettings, GLScaler &fallback)
Definition GLRGBScaler.cc:7
Abstract base class for OpenGL scalers.
Definition GLScaler.hh:16
void setup(bool superImpose)
Setup scaler.
Definition GLScaler.cc:40
std::array< gl::ShaderProgram, 2 > program
Definition GLScaler.hh:85
void execute(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight, bool textureFromZero=false)
Helper method to draw a rectangle with multiple texture coordinates.
Definition GLScaler.cc:48
virtual void scaleImage(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight)=0
Scales the image in the given area, which must consist of lines which are all equally wide.
Class containing all settings for renderers.
This file implemented 3 utility functions:
Definition Autofire.cc:9
constexpr auto xrange(T e)
Definition xrange.hh:132