# How to speed up texture() calls?

**URL:** <https://discourse.processing.org/t/how-to-speed-up-texture-calls/18414>\
**Category:** Coding Questions\
**Created:** [March 5, 2020, 12:37pm UTC](https://discourse.processing.org/t/how-to-speed-up-texture-calls/18414 "2020-03-05T12:37:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![George](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/george/32/5858_2.png) [@George](https://discourse.processing.org/u/George)\
**Post date:** [March 5, 2020, 12:37pm UTC](https://discourse.processing.org/t/how-to-speed-up-texture-calls/18414/1 "2020-03-05T12:37:48Z")

</div>

Hi,

I’ve stumbled upon a weird issue on Windows I’m trying to get a workaround going.

Here’s a basic sketch to replicate the issue:

```auto
PImage texture;

void setup(){
  size(1280,720,P3D);
  
  texture = createImage(3840,2166,RGB);
  for(int i = 0 ; i < texture.pixels.length; i++){
    texture.pixels[i] = color(random(255),random(255),random(255),255);
  }
  texture.updatePixels();
}

void draw(){
  background(0);
  //image(texture,0,0);
  
  int x1 = 0;
  int y1 = 0;
  int x2 = width;
  int y2 = height;
  
  int u1 = 0;
  int v1 = 0;
  int u2 = width;
  int v2 = height;
  
  beginShape(QUADS);
  texture(texture);
  vertex(x1, y1, u1, v1);
  vertex(x1, y2, u1, v2);
  vertex(x2, y2, u2, v2);
  vertex(x2, y1, u2, v1);
  endShape();
  
  println(frameCount,millis());
  surface.setTitle((int)frameRate+"fps");
}

```

The output starts printing:

```auto
1 1558
2 17342

```

In short, using texture() is slow the first time it’s called for large textures.

I’ve profiled the sketch and it points to JOGL’s `dispatch_glTexSubImage2D1()` when called by PGraphicsOpenGL’s initCache()/addTexture() cycle.

 ![2020-03-05 12_11_33-VisualVM 2.0](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/55a91f4c135f0cc117834f43086d7381faf0cd30.png)

I google a bit and it seems to be a JOGL issue related to temp folder permissions ?

Relevant threads:  
[http://forum.jogamp.org/Java-3D-initialization-is-super-slow-td4037070.html](http://forum.jogamp.org/Java-3D-initialization-is-super-slow-td4037070.html)  
[https://jogamp.org/bugzilla/show\_bug.cgi?id=1301](https://jogamp.org/bugzilla/show_bug.cgi?id=1301)

> <https://stackoverflow.com/questions/47291255/jogl-platform-init-1-minute/51100411#51100411>

  

> <https://stackoverflow.com/questions/40851464/jogl-takes-too-long-to-start>

  

> <https://stackoverflow.com/questions/40419184/world-wind-java-sdk-2-0-netbeans-8-mcve-project>

I’ve tried temporarily disabling Windows Defender and allowing C:\Windows\Temp more permissions, but it didn’t seem to fix anything. I’ve also attempted to pass `-Djogamp.gluegen.UseTempJarCache=false` to processing-java in the hope the flag would make it’s way to JVM, but this didn’t seem to work.

Has anyone else experienced this issue ? Is there a quick workaround for the Processing IDE  
(before drilling down to running an exported jar from command line or using eclipse ?) ?

---

<div class="post-metadata">

**Author:** ![George](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/george/32/5858_2.png) [@George](https://discourse.processing.org/u/George)\
**Post date:** [March 9, 2020, 5:58pm UTC](https://discourse.processing.org/t/how-to-speed-up-texture-calls/18414/2 "2020-03-09T17:58:13Z")

</div>

**Update**  
I’ve noticed the jogamp temp folder (in my case ) is still readonly.  
Tried to remove the readonly attribute (using [these superuser answers](https://superuser.com/questions/866120/cant-remove-read-only-attribute-from-folder-windows-8-1)), but it didn’t work.  
I’ve installed eclipse and tested the suggestions from what I thought were relevant posts, however it also didn’t work 😕

The sample looks like this:

```java
import processing.core.PApplet;
import processing.core.PImage;

public class TextureTest extends PApplet {
	
	PImage texture;
	
	public void settings() {
	  size(1280, 720, P3D);
	  println("jogamp.gluegen.UseTempJarCache =",System.getProperty("jogamp.gluegen.UseTempJarCache"));
	}
	
	public void setup(){
	  
	  texture = createImage(4096,2166,RGB);
	  for(int i = 0 ; i < texture.pixels.length; i++){
	    texture.pixels[i] = color(random(255),random(255),random(255),255);
	  }
	  texture.updatePixels();
	  
	}

	public void draw(){
	  background(0);
	  //image(texture,0,0);
	  
	  int x1 = 0;
	  int y1 = 0;
	  int x2 = width;
	  int y2 = height;
	  
	  int u1 = 0;
	  int v1 = 0;
	  int u2 = width;
	  int v2 = height;
	  
	  beginShape(QUADS);
	  texture(texture);
	  vertex(x1, y1, u1, v1);
	  vertex(x1, y2, u1, v2);
	  vertex(x2, y2, u2, v2);
	  vertex(x2, y1, u2, v1);
	  endShape();
	  
	  println(frameCount,millis());
	  surface.setTitle((int)frameRate+"fps");
	}
	
	public static void main(String[] args) {
		PApplet.main(TextureTest.class.getCanonicalName());
	}

}

```

The output is still about the same (~17.5 seconds delay before texture caching completes):

```auto
jogamp.gluegen.UseTempJarCache = false
1 1375
2 18952

```

The caveat being the windows dll’s would now be unzipped in the natives folder relative to the project (instead of being unzipped in a temp folder).  
I’ve uploaded the eclipse project [here](http://lifesine.eu/so/P5Tests.zip)

@Andres Have you ever ran into this issue ? Woulld you be able to advise what else I could try / point me in the right direction ? Many thanks

---

<div class="post-metadata">

**Author:** ![George](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/george/32/5858_2.png) [@George](https://discourse.processing.org/u/George)\
**Post date:** [March 11, 2020, 9:29pm UTC](https://discourse.processing.org/t/how-to-speed-up-texture-calls/18414/3 "2020-03-11T21:29:49Z")

</div>

I haven’t found the specific issue, but it is definitely GPU related and I have a fix/workaround !

On my machine I have two GPUs and Intel GPU and an nVidia GPU.

The issue occours on the Intel GPU. To explicitly tell Windows to use the nVidia GPU has a gotcha:

1. Go to **Settings \> Graphics Settings** and use the **Classic app \> Browse** button
2. Instead of browsing for the editor (processing.exe), browse for the java version the editor ships with (e.g. processing-3.5.3\java\bin\java.exe)
3. Press **Options** and select **High Performance**

 ![2020-03-11 21_18_34-Settings](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1cdc92bf983593e2f6644b97807b7f78d0e5853e.png)

The screenshot is confusing I know. (Sometimes it actually displays the correct information 😉 )  
You can check from the sketch using **PGraphicsOpenGL** :

```java
PGraphicsOpenGL pg = (PGraphicsOpenGL)g;
  println(PGraphicsOpenGL.OPENGL_VENDOR);
  println(PGraphicsOpenGL.OPENGL_RENDERER);
  println(PGraphicsOpenGL.OPENGL_VERSION);

```

(Thanks to @Andres and his **Topics \> Demos \> Tests \> SpecsTest** example)

Now the texture cache time is much shorter:

```auto
NVIDIA Corporation
GeForce RTX 2060/PCIe/SSE2
4.6.0 NVIDIA 442.19
1 3856
2 4091

```
