diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index fb3c1bc42..509a07f5c 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -2862,6 +2862,16 @@ public class PGL { } + protected static void updateByteBuffer(ByteBuffer buf, byte[] arr, + int offset, int size) { + if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) { + buf.position(4 * offset); + buf.put(arr, 4 * offset, 4 * size); + buf.rewind(); + } + } + + protected static void getByteArray(ByteBuffer buf, byte[] arr) { if (!buf.hasArray() || buf.array() != arr) { buf.position(0); @@ -2941,6 +2951,16 @@ public class PGL { } + protected static void updateShortBuffer(ShortBuffer buf, short[] arr, + int offset, int size) { + if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) { + buf.position(4 * offset); + buf.put(arr, 4 * offset, 4 * size); + buf.rewind(); + } + } + + protected static void getShortArray(ShortBuffer buf, short[] arr) { if (!buf.hasArray() || buf.array() != arr) { buf.position(0); @@ -3020,6 +3040,16 @@ public class PGL { } + protected static void updateIntBuffer(IntBuffer buf, int[] arr, + int offset, int size) { + if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) { + buf.position(4 * offset); + buf.put(arr, 4 * offset, 4 * size); + buf.rewind(); + } + } + + protected static void getIntArray(IntBuffer buf, int[] arr) { if (!buf.hasArray() || buf.array() != arr) { buf.position(0); @@ -3098,6 +3128,16 @@ public class PGL { } + protected static void updateFloatBuffer(FloatBuffer buf, float[] arr, + int offset, int size) { + if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) { + buf.position(4 * offset); + buf.put(arr, 4 * offset, 4 * size); + buf.rewind(); + } + } + + protected static void getFloatArray(FloatBuffer buf, float[] arr) { if (!buf.hasArray() || buf.array() != arr) { buf.position(0); @@ -3339,38 +3379,56 @@ public class PGL { // NEWT mouse listener class NEWTMouseListener extends com.jogamp.newt.event.MouseAdapter { + boolean pointerInside = false; + @Override public void mousePressed(com.jogamp.newt.event.MouseEvent e) { - nativeMouseEvent(e, MouseEvent.PRESS); + if (pointerInside) { + nativeMouseEvent(e, MouseEvent.PRESS); + } } @Override public void mouseReleased(com.jogamp.newt.event.MouseEvent e) { - nativeMouseEvent(e, MouseEvent.RELEASE); + if (pointerInside) { + nativeMouseEvent(e, MouseEvent.RELEASE); + } } @Override public void mouseClicked(com.jogamp.newt.event.MouseEvent e) { - nativeMouseEvent(e, MouseEvent.CLICK); + if (pointerInside) { + nativeMouseEvent(e, MouseEvent.CLICK); + } } @Override public void mouseDragged(com.jogamp.newt.event.MouseEvent e) { - nativeMouseEvent(e, MouseEvent.DRAG); + if (pointerInside) { + nativeMouseEvent(e, MouseEvent.DRAG); + } } @Override public void mouseMoved(com.jogamp.newt.event.MouseEvent e) { - nativeMouseEvent(e, MouseEvent.MOVE); + if (pointerInside) { + nativeMouseEvent(e, MouseEvent.MOVE); + } + } + @Override + public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent e) { + if (pointerInside) { + nativeMouseEvent(e, MouseEvent.WHEEL); + } } @Override public void mouseEntered(com.jogamp.newt.event.MouseEvent e) { + PApplet.println("mouse entered"); + pointerInside = true; nativeMouseEvent(e, MouseEvent.ENTER); } @Override public void mouseExited(com.jogamp.newt.event.MouseEvent e) { + PApplet.println("mouse exited"); + pointerInside = false; nativeMouseEvent(e, MouseEvent.EXIT); } - @Override - public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent e) { - nativeMouseEvent(e, MouseEvent.WHEEL); - } } // NEWT key listener diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 8e26e9999..6418f7abe 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -9227,9 +9227,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyVerticesBuffer(int offset, int size) { - polyVerticesBuffer.position(4 * offset); - polyVerticesBuffer.put(polyVertices, 4 * offset, 4 * size); - polyVerticesBuffer.rewind(); + PGL.updateFloatBuffer(polyVerticesBuffer, polyVertices, + 4 * offset, 4 * size); } protected void updatePolyColorsBuffer() { @@ -9237,9 +9236,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyColorsBuffer(int offset, int size) { - polyColorsBuffer.position(offset); - polyColorsBuffer.put(polyColors, offset, size); - polyColorsBuffer.rewind(); + PGL.updateIntBuffer(polyColorsBuffer, polyColors, offset, size); } protected void updatePolyNormalsBuffer() { @@ -9247,9 +9244,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyNormalsBuffer(int offset, int size) { - polyNormalsBuffer.position(3 * offset); - polyNormalsBuffer.put(polyNormals, 3 * offset, 3 * size); - polyNormalsBuffer.rewind(); + PGL.updateFloatBuffer(polyNormalsBuffer, polyNormals, + 3 * offset, 3 * size); } protected void updatePolyTexcoordsBuffer() { @@ -9257,9 +9253,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyTexcoordsBuffer(int offset, int size) { - polyTexcoordsBuffer.position(2 * offset); - polyTexcoordsBuffer.put(polyTexcoords, 2 * offset, 2 * size); - polyTexcoordsBuffer.rewind(); + PGL.updateFloatBuffer(polyTexcoordsBuffer, polyTexcoords, + 2 * offset, 2 * size); } protected void updatePolyAmbientBuffer() { @@ -9267,9 +9262,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyAmbientBuffer(int offset, int size) { - polyAmbientBuffer.position(offset); - polyAmbientBuffer.put(polyAmbient, offset, size); - polyAmbientBuffer.rewind(); + PGL.updateIntBuffer(polyAmbientBuffer, polyAmbient, offset, size); } protected void updatePolySpecularBuffer() { @@ -9277,9 +9270,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolySpecularBuffer(int offset, int size) { - polySpecularBuffer.position(offset); - polySpecularBuffer.put(polySpecular, offset, size); - polySpecularBuffer.rewind(); + PGL.updateIntBuffer(polySpecularBuffer, polySpecular, offset, size); } protected void updatePolyEmissiveBuffer() { @@ -9287,9 +9278,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyEmissiveBuffer(int offset, int size) { - polyEmissiveBuffer.position(offset); - polyEmissiveBuffer.put(polyEmissive, offset, size); - polyEmissiveBuffer.rewind(); + PGL.updateIntBuffer(polyEmissiveBuffer, polyEmissive, offset, size); } protected void updatePolyShininessBuffer() { @@ -9297,9 +9286,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyShininessBuffer(int offset, int size) { - polyShininessBuffer.position(offset); - polyShininessBuffer.put(polyShininess, offset, size); - polyShininessBuffer.rewind(); + PGL.updateFloatBuffer(polyShininessBuffer, polyShininess, offset, size); } protected void updatePolyIndicesBuffer() { @@ -9307,9 +9294,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePolyIndicesBuffer(int offset, int size) { - polyIndicesBuffer.position(offset); - polyIndicesBuffer.put(polyIndices, offset, size); - polyIndicesBuffer.rewind(); + PGL.updateShortBuffer(polyIndicesBuffer, polyIndices, offset, size); } protected void updateLineVerticesBuffer() { @@ -9317,9 +9302,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updateLineVerticesBuffer(int offset, int size) { - lineVerticesBuffer.position(4 * offset); - lineVerticesBuffer.put(lineVertices, 4 * offset, 4 * size); - lineVerticesBuffer.rewind(); + PGL.updateFloatBuffer(lineVerticesBuffer, lineVertices, + 4 * offset, 4 * size); } protected void updateLineColorsBuffer() { @@ -9327,9 +9311,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updateLineColorsBuffer(int offset, int size) { - lineColorsBuffer.position(offset); - lineColorsBuffer.put(lineColors, offset, size); - lineColorsBuffer.rewind(); + PGL.updateIntBuffer(lineColorsBuffer, lineColors, offset, size); } protected void updateLineAttribsBuffer() { @@ -9337,9 +9319,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updateLineAttribsBuffer(int offset, int size) { - lineAttribsBuffer.position(4 * offset); - lineAttribsBuffer.put(lineAttribs, 4 * offset, 4 * size); - lineAttribsBuffer.rewind(); + PGL.updateFloatBuffer(lineAttribsBuffer, lineAttribs, + 4 * offset, 4 * size); } protected void updateLineIndicesBuffer() { @@ -9347,9 +9328,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updateLineIndicesBuffer(int offset, int size) { - lineIndicesBuffer.position(offset); - lineIndicesBuffer.put(lineIndices, offset, size); - lineIndicesBuffer.rewind(); + PGL.updateShortBuffer(lineIndicesBuffer, lineIndices, offset, size); } protected void updatePointVerticesBuffer() { @@ -9357,9 +9336,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePointVerticesBuffer(int offset, int size) { - pointVerticesBuffer.position(4 * offset); - pointVerticesBuffer.put(pointVertices, 4 * offset, 4 * size); - pointVerticesBuffer.rewind(); + PGL.updateFloatBuffer(pointVerticesBuffer, pointVertices, + 4 * offset, 4 * size); } protected void updatePointColorsBuffer() { @@ -9367,9 +9345,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePointColorsBuffer(int offset, int size) { - pointColorsBuffer.position(offset); - pointColorsBuffer.put(pointColors, offset, size); - pointColorsBuffer.rewind(); + PGL.updateIntBuffer(pointColorsBuffer, pointColors, offset, size); } protected void updatePointAttribsBuffer() { @@ -9377,9 +9353,8 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePointAttribsBuffer(int offset, int size) { - pointAttribsBuffer.position(2 * offset); - pointAttribsBuffer.put(pointAttribs, 2 * offset, 2 * size); - pointAttribsBuffer.rewind(); + PGL.updateFloatBuffer(pointAttribsBuffer, pointAttribs, + 2 * offset, 2 * size); } protected void updatePointIndicesBuffer() { @@ -9387,9 +9362,7 @@ public class PGraphicsOpenGL extends PGraphics { } protected void updatePointIndicesBuffer(int offset, int size) { - pointIndicesBuffer.position(offset); - pointIndicesBuffer.put(pointIndices, offset, size); - pointIndicesBuffer.rewind(); + PGL.updateShortBuffer(pointIndicesBuffer, pointIndices, offset, size); } // -----------------------------------------------------------------