gpu: fix stretched mode scaling issues on macos
This fixes the following issues: 1) resize events for the client not being propagated to the listener on the canvas 2) resizing the client in fixed mode not triggering a resetSize due to the underlying canvas size not changing 3) maximizing the client calling restSize too soon causing it to have no effect
This commit is contained in:
@@ -44,9 +44,13 @@ import com.jogamp.opengl.GLFBODrawable;
|
|||||||
import com.jogamp.opengl.GLProfile;
|
import com.jogamp.opengl.GLProfile;
|
||||||
import com.jogamp.opengl.math.Matrix4;
|
import com.jogamp.opengl.math.Matrix4;
|
||||||
import java.awt.Canvas;
|
import java.awt.Canvas;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.ComponentListener;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.DataBufferInt;
|
import java.awt.image.DataBufferInt;
|
||||||
@@ -293,6 +297,24 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
private int uniSmoothBanding;
|
private int uniSmoothBanding;
|
||||||
private int uniTextureLightMode;
|
private int uniTextureLightMode;
|
||||||
|
|
||||||
|
private int needsReset;
|
||||||
|
|
||||||
|
private final ComponentListener resizeListener = new ComponentAdapter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e)
|
||||||
|
{
|
||||||
|
// forward to the JAWTWindow component listener on the canvas. The JAWTWindow component
|
||||||
|
// listener listens for resizes or movement of the component in order to resize and move
|
||||||
|
// the associated offscreen layer (calayer on macos only)
|
||||||
|
canvas.dispatchEvent(e);
|
||||||
|
// resetSize needs to be run awhile after the resize is completed.
|
||||||
|
// I've tried waiting until all EDT events are completed and even that is too soon.
|
||||||
|
// Not sure why, so we just wait a few frames.
|
||||||
|
needsReset = 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp()
|
protected void startUp()
|
||||||
{
|
{
|
||||||
@@ -447,6 +469,11 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
{
|
{
|
||||||
invokeOnMainThread(this::uploadScene);
|
invokeOnMainThread(this::uploadScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OSType.getOSType() == OSType.MacOS)
|
||||||
|
{
|
||||||
|
SwingUtilities.invokeAndWait(() -> ((Component) client).addComponentListener(resizeListener));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
@@ -474,6 +501,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
@Override
|
@Override
|
||||||
protected void shutDown()
|
protected void shutDown()
|
||||||
{
|
{
|
||||||
|
((Component) client).removeComponentListener(resizeListener);
|
||||||
clientThread.invoke(() ->
|
clientThread.invoke(() ->
|
||||||
{
|
{
|
||||||
client.setGpu(false);
|
client.setGpu(false);
|
||||||
@@ -1091,16 +1119,22 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
gl.glBindTexture(gl.GL_TEXTURE_2D, interfaceTexture);
|
gl.glBindTexture(gl.GL_TEXTURE_2D, interfaceTexture);
|
||||||
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, canvasWidth, canvasHeight, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, null);
|
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, canvasWidth, canvasHeight, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, null);
|
||||||
gl.glBindTexture(gl.GL_TEXTURE_2D, 0);
|
gl.glBindTexture(gl.GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (OSType.getOSType() == OSType.MacOS && glDrawable instanceof GLFBODrawable)
|
if (needsReset > 0)
|
||||||
|
{
|
||||||
|
assert OSType.getOSType() == OSType.MacOS;
|
||||||
|
if (needsReset == 1 && glDrawable instanceof GLFBODrawable)
|
||||||
{
|
{
|
||||||
// GLDrawables created with createGLDrawable() do not have a resize listener
|
// GLDrawables created with createGLDrawable() do not have a resize listener
|
||||||
// I don't know why this works with Windows/Linux, but on OSX
|
// I don't know why this works with Windows/Linux, but on OSX
|
||||||
// it prevents JOGL from resizing its FBOs and underlying GL textures. So,
|
// it prevents JOGL from resizing its FBOs and underlying GL textures. So,
|
||||||
// we manually trigger a resize here.
|
// we manually trigger a resize here.
|
||||||
GLFBODrawable glfboDrawable = (GLFBODrawable) glDrawable;
|
GLFBODrawable glfboDrawable = (GLFBODrawable) glDrawable;
|
||||||
|
log.debug("Resetting GLFBODrawable size");
|
||||||
glfboDrawable.resetSize(gl);
|
glfboDrawable.resetSize(gl);
|
||||||
}
|
}
|
||||||
|
needsReset--;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BufferProvider bufferProvider = client.getBufferProvider();
|
final BufferProvider bufferProvider = client.getBufferProvider();
|
||||||
|
|||||||
Reference in New Issue
Block a user