Using MipMap in Juce OpenGL


#1

Hello, is there any way of using MipMap in Juce OpenGL?

I am making desktop application which has to be resizable smoothly.
Now it is being rendered with OpenGL renderer by attaching OpenGL context to top level component. And so all the drawing is performed by OpenGL. But rescaled images are too sharp or too smooth. So I need to use MipMap.

I have changed some Juce OpenGL codes following.

juce_OpenGLFrameBuffer.cpp

#if JUCE_OPENGL3
    glTextParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTextParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
#else
    glTextParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTextParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 #endif

#if JUCE_OPENGL3
    glGenerateMipmap(GL_TEXTURE_2D);
#else
#endif

Now it renders by using MipMap. Anyhow is there any way to do this correctly?
It uses MipMap on OpenGL 3.0 or later version only.


#2

I have faced another issue with OpenGLGraphicsContextCustomShader and LowLevelGraphicsContext.
I made some codes to make texture from image and draw it with shader.
It was really hard to get correct mapping values and finally I did it.

float texMatrix[] = {
    1, 0, 0,
    0, 1, 0,
    0, 0, 1,
};

float texWidth = texture.getWidth();
float texHeight = texture.getHeight();

auto rect = getTopLevelComponent()->getLocalArea(this, getLocalBounds());
float totalHeight = getTopLevelComponent()->getHeight();

Rectangle<int> targetRect(dstX, dstY, dstW, dstH);

texMatrix[0] = srcW / dstW / texWidth;
texMatrix[6] = ((-dstX - rect.getX()) * srcW / dstW + srcX) / texWidth;
texMatrix[4] = srcH / dstH / texHeight;
texMatrix[7] = 1 + (-srcY - (totalHeight - dstY - rect.getY()) * srcH / dstH) / texHeight;

unifroms->texMatrix->setMatrix3(texMatrix, 1, false);

shader->fillRect(g.getInternalContext(), targetRect);

It seems fine, but soon I have faced the important issue which happens when the scaling factor does not equal with 1.f.
I have tried to find some valuable posts in Juce Forum but not found any one.
So again I made my own codes and resolved that issue like following.

float scale = g.getInternalContext().getPhysicalPixelScaleFactor();

texMatrix[0] = srcW / dstW / texWidth / scale;
texMatrix[4] = srcH / dstH / texHeight / scale;

It works fine now.
But I can’t be sure this is the regular way to resolve above issues.
Have you any ideas about this?