# How to use filter on PGraphics in thread?

**URL:** https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949
**Category:** Coding Questions
**Created:** [August 16, 2024, 9:19pm UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949 "2024-08-16T21:19:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![varenek111](https://avatars.discourse-cdn.com/v4/letter/v/71c47a/32.png) [@varenek111](https://discourse.processing.org/u/varenek111)
#### Post date: [August 16, 2024, 9:19pm UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949/1 "2024-08-16T21:19:43Z")

</div>

How to use filter on PGraphics in thread?

```auto
void setup() {
  size(512, 512, P2D);
  thread("thread");
}
void thread() {
  PGraphics graphic = createGraphics(512, 512, P2D);
  PShader blur = loadShader("blur.glsl");
  graphic.beginDraw();
  graphic.background(200);
  graphic.ellipse(255, 255, 255, 255);
  graphic.filter(blur);
  graphic.endDraw();
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 16, 2024, 10:28pm UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949/2 "2024-08-16T22:28:11Z")

</div>

> [@Problems when trying to draw to a P3D PGraphics when called from a thread?](https://discourse.processing.org/t/problems-when-trying-to-draw-to-a-p3d-pgraphics-when-called-from-a-thread/6301/4):
>
> Although it’s pretty much a hack, here’s the workaround I’ve come up w/: crazy_face /\*\* \* Threaded PGraphics II (v1.0.1) \* GoToLoop (2018/Dec/07) \* \* https://Discourse.Processing.org/t/ \* problems-when-trying-to-draw-to-a-p3d-pgraphics- \* when-called-from-a-thread/6301/4 \* \* https://Forum.Processing.org/two/discussion/25799/ \* how-to-draw-a-rect-in-a-thread#Item\_2 \*/ static final int W = 250, H = 200, FPS = 10; Layer layer; void settings() { size(W, H, JAVA2D); smooth(3); } v…

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [August 17, 2024, 1:54am UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949/3 "2024-08-17T01:54:11Z")

</div>

Have you seen this:

 ![e](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/f/cfd67913931870f0da1a22d68ef09d4b2fed45fe.png)

---

<div class="post-metadata">

### Author: ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)
#### Post date: [August 18, 2024, 11:55pm UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949/4 "2024-08-18T23:55:25Z")

</div>

It’s probably better to use the Java Thread API.  
[https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html)

---

<div class="post-metadata">

### Author: ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)
#### Post date: [August 19, 2024, 12:01am UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949/5 "2024-08-19T00:01:09Z")

</div>

Why does this need to be in a separate Thread?  
The shader will (hopefully) be computed by the GPU.

Why do you need to create a separate CPU Thread for it?

---

<div class="post-metadata">

### Author: ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)
#### Post date: [August 19, 2024, 12:03am UTC](https://discourse.processing.org/t/how-to-use-filter-on-pgraphics-in-thread/44949/6 "2024-08-19T00:03:30Z")

</div>

The P2D renderer is not necessarily faster than the default Java2D renderer.

Does your GPU driver support OpenGL?  
(Only really valid for Linux)
