From a3fabaf24671bb7766d88949dc302e922a1d2bf5 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 30 May 2013 10:57:58 -0400 Subject: [PATCH] Use loaded flag to upate texture object, and image format when setting pixels. Fixes #1830 --- .../processing/opengl/PGraphicsOpenGL.java | 6 ++-- core/src/processing/opengl/Texture.java | 30 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 619b260f2..49a82f710 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5773,7 +5773,7 @@ public class PGraphicsOpenGL extends PGraphics { Texture tex = (Texture)initCache(img); if (tex == null) return null; - if (img.isModified()) { + if (img.isModified() || img.isLoaded()) { if (img.width != tex.width || img.height != tex.height) { tex.init(img.width, img.height); } @@ -5801,7 +5801,8 @@ public class PGraphicsOpenGL extends PGraphics { tex = addTexture(img); if (tex != null) { img.loadPixels(); - tex.set(img.pixels); + tex.set(img.pixels, img.format); + img.setLoaded(false); } } return tex; @@ -5897,6 +5898,7 @@ public class PGraphicsOpenGL extends PGraphics { tex.set(img.pixels, x, y, w, h, img.format); } img.setModified(false); + img.setLoaded(false); } diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 005686fb0..82f0a1f19 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -524,21 +524,21 @@ public class Texture implements PConstants { * Copies the contents of the texture to the pixels array. * @param pixels */ - public void loadPixels(int[] pixels) { - if (hasBuffers()) { - // Updates the texture AND the pixels array of the image at the same time, - // getting the pixels directly from the buffer data (and thus avoiding - // expensive transfer between video and main memory). - bufferUpdate(pixels); - } - - if (isModified()) { - // Regular pixel copy from texture. - get(pixels); - } - - setModified(false); - } +// public void loadPixels(int[] pixels) { +// if (hasBuffers()) { +// // Updates the texture AND the pixels array of the image at the same time, +// // getting the pixels directly from the buffer data (and thus avoiding +// // expensive transfer between video and main memory). +// bufferUpdate(pixels); +// } +// +// if (isModified()) { +// // Regular pixel copy from texture. +// get(pixels); +// } +// +// setModified(false); +// } ////////////////////////////////////////////////////////////