22 , maxWidth(maxWidth_), maxHeight(maxHeight_)
27 glUniform1i(p.getUniformLocation(
"edgeTex"), 2);
28 glUniform1i(p.getUniformLocation(
"offsetTex"), 3);
29 glUniform1i(p.getUniformLocation(
"weightTex"), 4);
30 edgePosScaleUnif[i] = p.getUniformLocation(
"edgePosScale");
36 glTexImage2D(GL_TEXTURE_2D,
45#if OPENGL_VERSION >= OPENGL_3_3
46 GLint swizzleMask[] = {GL_RED, GL_RED, GL_RED, GL_ONE};
47 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
49 edgeBuffer.
allocate(maxWidth * maxHeight);
52 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
53 std::string offsetsName =
"shaders/HQ_xOffsets.dat";
54 std::string weightsName =
"shaders/HQ_xWeights.dat";
57 offsetsName[10] = narrow<char>(
'0' + n);
58 File offsetsFile(context.resolve(offsetsName));
59 offsetTexture[i].bind();
60 glTexImage2D(GL_TEXTURE_2D,
68 offsetsFile.
mmap().data());
70 weightsName[10] = narrow<char>(
'0' + n);
71 File weightsFile(context.resolve(weightsName));
72 weightTexture[i].bind();
73 glTexImage2D(GL_TEXTURE_2D,
81 weightsFile.
mmap().data());
83 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
88 unsigned srcStartY,
unsigned srcEndY,
unsigned srcWidth,
89 unsigned dstStartY,
unsigned dstEndY,
unsigned dstWidth,
90 unsigned logSrcHeight)
92 unsigned factorY = (dstEndY - dstStartY) / (srcEndY - srcStartY);
94 if ((factorY >= 2) && ((srcWidth % 320) == 0)) {
96 setup(superImpose !=
nullptr);
97 glActiveTexture(GL_TEXTURE4);
98 weightTexture[factorY - 2].bind();
99 glActiveTexture(GL_TEXTURE3);
100 offsetTexture[factorY - 2].bind();
101 glActiveTexture(GL_TEXTURE2);
103 glActiveTexture(GL_TEXTURE0);
105 int i = superImpose ? 1 : 0;
106 glUniform2f(edgePosScaleUnif[i],
107 float(src.
getWidth()) /
float(maxWidth),
108 float(src.
getHeight()) /
float(maxHeight));
111 srcStartY, srcEndY, srcWidth,
112 dstStartY, dstEndY, dstWidth,
116 srcStartY, srcEndY, srcWidth,
117 dstStartY, dstEndY, dstWidth,
122using Pixel = uint32_t;
124 unsigned srcStartY,
unsigned srcEndY,
unsigned lineWidth,
127 if ((lineWidth % 320) != 0)
return;
129 assert(maxWidth <= 1280);
138 auto curr = paintFrame.
getLine(narrow<int>(srcStartY) - 1, buf1);
139 auto next = paintFrame.
getLine(narrow<int>(srcStartY) + 0, buf2);
144 auto mapped = edgeBuffer.
mapWrite();
145 auto numLines = srcEndY - srcStartY;
146 for (
auto yy :
xrange(numLines)) {
148 std::swap(buf1, buf2);
149 next = paintFrame.
getLine(narrow<int>(yy + srcStartY + 1), buf2);
151 auto dest = mapped.subspan(yy *
size_t(lineWidth), lineWidth);
152 assert(dest.size_bytes() == std::span{tmpBuf2}.size_bytes());
153 memcpy(dest.data(), tmpBuf2.data(), std::span{tmpBuf2}.size_bytes());
159 glTexSubImage2D(GL_TEXTURE_2D,
162 narrow<GLint>(srcStartY),
163 narrow<GLint>(lineWidth),
164 narrow<GLint>(numLines),
GLsizei getHeight() const
void allocate(GLuint size)
Allocate the maximum required size for this buffer.
void unmap() const
Unmaps the contents of this buffer.
void unbind() const
Unbind this buffer.
void bind() const
Bind this PixelBuffer.
std::span< T > mapWrite()
Maps the contents of this buffer into memory.
void bind() const
Makes this texture the active GL texture.
std::span< const uint8_t > mmap()
Map file in memory.
Interface for getting lines from a video frame.
std::span< const Pixel > getLine(int line, std::span< Pixel > buf) const
Gets a pointer to the pixels of the given line number.
void uploadBlock(unsigned srcStartY, unsigned srcEndY, unsigned lineWidth, FrameSource &paintFrame) override
GLHQScaler(GLScaler &fallback, unsigned maxWidth, unsigned maxHeight)
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.
Abstract base class for OpenGL scalers.
void setup(bool superImpose)
Setup scaler.
std::array< gl::ShaderProgram, 2 > program
void execute(const gl::ColorTexture &src, const 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.
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.
EndianT< uint32_t, ConvLittle< BIG > > L32
void format(SectorAccessibleDisk &disk, MSXBootSectorType bootType)
Format the given disk (= a single partition).
This file implemented 3 utility functions:
const FileContext & systemFileContext()
CharacterConverter::Pixel Pixel
void calcEdgesGL(std::span< const uint32_t > curr, std::span< const uint32_t > next, std::span< Endian::L32 > edges2, EdgeOp edgeOp)
constexpr void fill(ForwardRange &&range, const T &value)
constexpr auto xrange(T e)