Move display call from repaint to paintImmediatly()
Allows swing's grouping of multiple repaint() calls to a single immediate call to actually have an effect.
This commit is contained in:
parent
e2f810d3cd
commit
da502ab19a
@ -2,6 +2,7 @@ package net.sf.openrocket.gui.figure3d.photo;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.SplashScreen;
|
import java.awt.SplashScreen;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
@ -79,6 +80,7 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
void addImageCallback(ImageCallback a) {
|
void addImageCallback(ImageCallback a) {
|
||||||
imageCallbacks.add(a);
|
imageCallbacks.add(a);
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RocketRenderer rr;
|
private RocketRenderer rr;
|
||||||
@ -93,14 +95,15 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
rr = new RealisticRenderer(doc);
|
rr = new RealisticRenderer(doc);
|
||||||
rr.init(drawable);
|
rr.init(drawable);
|
||||||
|
|
||||||
doc.getDefaultConfiguration().addChangeListener(new StateChangeListener() {
|
doc.getDefaultConfiguration().addChangeListener(
|
||||||
@Override
|
new StateChangeListener() {
|
||||||
public void stateChanged(EventObject e) {
|
@Override
|
||||||
log.debug("Repainting on config state change");
|
public void stateChanged(EventObject e) {
|
||||||
needUpdate = true;
|
log.debug("Repainting on config state change");
|
||||||
PhotoPanel.this.repaint();
|
needUpdate = true;
|
||||||
}
|
PhotoPanel.this.repaint();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
doc.addDocumentChangeListener(new DocumentChangeListener() {
|
doc.addDocumentChangeListener(new DocumentChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -150,14 +153,16 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
final GLCapabilities caps = new GLCapabilities(glp);
|
final GLCapabilities caps = new GLCapabilities(glp);
|
||||||
|
|
||||||
if (Application.getPreferences().getBoolean(Preferences.OPENGL_ENABLE_AA, true)) {
|
if (Application.getPreferences().getBoolean(
|
||||||
|
Preferences.OPENGL_ENABLE_AA, true)) {
|
||||||
caps.setSampleBuffers(true);
|
caps.setSampleBuffers(true);
|
||||||
caps.setNumSamples(6);
|
caps.setNumSamples(6);
|
||||||
} else {
|
} else {
|
||||||
log.trace("GL - Not enabling AA by user pref");
|
log.trace("GL - Not enabling AA by user pref");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Application.getPreferences().getBoolean(Preferences.OPENGL_USE_FBO, false)) {
|
if (Application.getPreferences().getBoolean(
|
||||||
|
Preferences.OPENGL_USE_FBO, false)) {
|
||||||
log.trace("GL - Creating GLJPanel");
|
log.trace("GL - Creating GLJPanel");
|
||||||
canvas = new GLJPanel(caps);
|
canvas = new GLJPanel(caps);
|
||||||
} else {
|
} else {
|
||||||
@ -170,7 +175,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("An error occurred creating 3d View", t);
|
log.error("An error occurred creating 3d View", t);
|
||||||
canvas = null;
|
canvas = null;
|
||||||
this.add(new JLabel("Unable to load 3d Libraries: " + t.getMessage()));
|
this.add(new JLabel("Unable to load 3d Libraries: "
|
||||||
|
+ t.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +195,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
p.setViewDistance(p.getViewDistance() + 0.1 * e.getWheelRotation());
|
p.setViewDistance(p.getViewDistance() + 0.1
|
||||||
|
* e.getWheelRotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -206,7 +213,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
final double x2 = (width - 2 * e.getX()) / width;
|
final double x2 = (width - 2 * e.getX()) / width;
|
||||||
final double y2 = (2 * e.getY() - height) / height;
|
final double y2 = (2 * e.getY() - height) / height;
|
||||||
|
|
||||||
p.setViewAltAz(p.getViewAlt() - (y1 - y2), p.getViewAz() + (x1 - x2));
|
p.setViewAltAz(p.getViewAlt() - (y1 - y2), p.getViewAz()
|
||||||
|
+ (x1 - x2));
|
||||||
|
|
||||||
lastX = e.getX();
|
lastX = e.getX();
|
||||||
lastY = e.getY();
|
lastY = e.getY();
|
||||||
@ -219,12 +227,23 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void repaint() {
|
public void paintImmediately(Rectangle r) {
|
||||||
|
super.paintImmediately(r);
|
||||||
if (canvas != null)
|
if (canvas != null)
|
||||||
((GLAutoDrawable) canvas).display();
|
((GLAutoDrawable) canvas).display();
|
||||||
super.repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintImmediately(int x, int y, int w, int h) {
|
||||||
|
super.paintImmediately(x, y, w, h);
|
||||||
|
if (canvas != null)
|
||||||
|
((GLAutoDrawable) canvas).display();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Override public void repaint() { if (canvas != null) ((GLAutoDrawable)
|
||||||
|
* canvas).display(); super.repaint(); }
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void display(final GLAutoDrawable drawable) {
|
public void display(final GLAutoDrawable drawable) {
|
||||||
GL2 gl = drawable.getGL().getGL2();
|
GL2 gl = drawable.getGL().getGL2();
|
||||||
@ -253,9 +272,12 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!imageCallbacks.isEmpty()) {
|
if (!imageCallbacks.isEmpty()) {
|
||||||
BufferedImage i = (new AWTGLReadBufferUtil(GLProfile.get(GLProfile.GL2), false)).readPixelsToBufferedImage(
|
BufferedImage i = (new AWTGLReadBufferUtil(
|
||||||
drawable.getGL(), 0, 0, drawable.getWidth(), drawable.getHeight(), true);
|
GLProfile.get(GLProfile.GL2), false))
|
||||||
final Vector<ImageCallback> cbs = new Vector<PhotoPanel.ImageCallback>(imageCallbacks);
|
.readPixelsToBufferedImage(drawable.getGL(), 0, 0,
|
||||||
|
drawable.getWidth(), drawable.getHeight(), true);
|
||||||
|
final Vector<ImageCallback> cbs = new Vector<PhotoPanel.ImageCallback>(
|
||||||
|
imageCallbacks);
|
||||||
imageCallbacks.clear();
|
imageCallbacks.clear();
|
||||||
for (ImageCallback ia : cbs) {
|
for (ImageCallback ia : cbs) {
|
||||||
try {
|
try {
|
||||||
@ -291,12 +313,21 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
float amb = (float) p.getAmbiance();
|
float amb = (float) p.getAmbiance();
|
||||||
float dif = 1.0f - amb;
|
float dif = 1.0f - amb;
|
||||||
float spc = 1.0f;
|
float spc = 1.0f;
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT, new float[] { amb * color[0], amb * color[1],
|
gl.glLightfv(
|
||||||
amb * color[2], 1 }, 0);
|
GLLightingFunc.GL_LIGHT1,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE, new float[] { dif * color[0], dif * color[1],
|
GLLightingFunc.GL_AMBIENT,
|
||||||
dif * color[2], 1 }, 0);
|
new float[] { amb * color[0], amb * color[1], amb * color[2], 1 },
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR, new float[] { spc * color[0],
|
0);
|
||||||
spc * color[1], spc * color[2], 1 }, 0);
|
gl.glLightfv(
|
||||||
|
GLLightingFunc.GL_LIGHT1,
|
||||||
|
GLLightingFunc.GL_DIFFUSE,
|
||||||
|
new float[] { dif * color[0], dif * color[1], dif * color[2], 1 },
|
||||||
|
0);
|
||||||
|
gl.glLightfv(
|
||||||
|
GLLightingFunc.GL_LIGHT1,
|
||||||
|
GLLightingFunc.GL_SPECULAR,
|
||||||
|
new float[] { spc * color[0], spc * color[1], spc * color[2], 1 },
|
||||||
|
0);
|
||||||
|
|
||||||
convertColor(p.getSkyColor(), color);
|
convertColor(p.getSkyColor(), color);
|
||||||
gl.glClearColor(color[0], color[1], color[2], 1);
|
gl.glClearColor(color[0], color[1], color[2], 1);
|
||||||
@ -341,12 +372,16 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
gl.glRotated(p.getViewAlt() * (180.0 / Math.PI), 1, 0, 0);
|
gl.glRotated(p.getViewAlt() * (180.0 / Math.PI), 1, 0, 0);
|
||||||
gl.glRotated(p.getViewAz() * (180.0 / Math.PI), 0, 1, 0);
|
gl.glRotated(p.getViewAz() * (180.0 / Math.PI), 0, 1, 0);
|
||||||
|
|
||||||
float[] lightPosition = new float[] { (float) Math.cos(p.getLightAlt()) * (float) Math.sin(p.getLightAz()),//
|
float[] lightPosition = new float[] {
|
||||||
|
(float) Math.cos(p.getLightAlt())
|
||||||
|
* (float) Math.sin(p.getLightAz()),//
|
||||||
(float) Math.sin(p.getLightAlt()),//
|
(float) Math.sin(p.getLightAlt()),//
|
||||||
(float) Math.cos(p.getLightAlt()) * (float) Math.cos(p.getLightAz()), //
|
(float) Math.cos(p.getLightAlt())
|
||||||
|
* (float) Math.cos(p.getLightAz()), //
|
||||||
0 };
|
0 };
|
||||||
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION, lightPosition, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION,
|
||||||
|
lightPosition, 0);
|
||||||
|
|
||||||
// Change to LEFT Handed coordinates
|
// Change to LEFT Handed coordinates
|
||||||
gl.glScaled(1, 1, -1);
|
gl.glScaled(1, 1, -1);
|
||||||
@ -358,20 +393,23 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
if (p.isFlame()) {
|
if (p.isFlame()) {
|
||||||
convertColor(p.getFlameColor(), color);
|
convertColor(p.getFlameColor(), color);
|
||||||
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_AMBIENT, new float[] { 0, 0, 0, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_AMBIENT,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE, new float[] { color[0], color[1],
|
new float[] { 0, 0, 0, 1 }, 0);
|
||||||
color[2], 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_SPECULAR, new float[] { color[0], color[1],
|
new float[] { color[0], color[1], color[2], 1 }, 0);
|
||||||
color[2], 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_SPECULAR,
|
||||||
|
new float[] { color[0], color[1], color[2], 1 }, 0);
|
||||||
|
|
||||||
Bounds b = calculateBounds();
|
Bounds b = calculateBounds();
|
||||||
gl.glLightf(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_QUADRATIC_ATTENUATION, 20f);
|
gl.glLightf(GLLightingFunc.GL_LIGHT2,
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_POSITION, new float[] { (float) (b.xMax + .1f), 0,
|
GLLightingFunc.GL_QUADRATIC_ATTENUATION, 20f);
|
||||||
0, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_POSITION,
|
||||||
|
new float[] { (float) (b.xMax + .1f), 0, 0, 1 }, 0);
|
||||||
gl.glEnable(GLLightingFunc.GL_LIGHT2);
|
gl.glEnable(GLLightingFunc.GL_LIGHT2);
|
||||||
} else {
|
} else {
|
||||||
gl.glDisable(GLLightingFunc.GL_LIGHT2);
|
gl.glDisable(GLLightingFunc.GL_LIGHT2);
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE, new float[] { 0, 0, 0, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT2, GLLightingFunc.GL_DIFFUSE,
|
||||||
|
new float[] { 0, 0, 0, 1 }, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rr.render(drawable, configuration, new HashSet<RocketComponent>());
|
rr.render(drawable, configuration, new HashSet<RocketComponent>());
|
||||||
@ -384,12 +422,14 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
Motor motor = mount.getMotorConfiguration().get(motorID).getMotor();
|
Motor motor = mount.getMotorConfiguration().get(motorID).getMotor();
|
||||||
double length = motor.getLength();
|
double length = motor.getLength();
|
||||||
|
|
||||||
Coordinate[] position = ((RocketComponent) mount).toAbsolute(new Coordinate(((RocketComponent) mount)
|
Coordinate[] position = ((RocketComponent) mount)
|
||||||
.getLength() + mount.getMotorOverhang() - length));
|
.toAbsolute(new Coordinate(((RocketComponent) mount)
|
||||||
|
.getLength() + mount.getMotorOverhang() - length));
|
||||||
|
|
||||||
for (int i = 0; i < position.length; i++) {
|
for (int i = 0; i < position.length; i++) {
|
||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
gl.glTranslated(position[i].x + motor.getLength(), position[i].y, position[i].z);
|
gl.glTranslated(position[i].x + motor.getLength(),
|
||||||
|
position[i].y, position[i].z);
|
||||||
FlameRenderer.drawExhaust(gl, p, motor);
|
FlameRenderer.drawExhaust(gl, p, motor);
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
}
|
}
|
||||||
@ -426,7 +466,8 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) {
|
public void reshape(final GLAutoDrawable drawable, final int x,
|
||||||
|
final int y, final int w, final int h) {
|
||||||
log.trace("GL - reshape()");
|
log.trace("GL - reshape()");
|
||||||
ratio = (double) w / (double) h;
|
ratio = (double) w / (double) h;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user