Skip to content

Commit cac5c64

Browse files
committed
updated some tests and examples
1 parent 6e43607 commit cac5c64

File tree

8 files changed

+123
-7
lines changed

8 files changed

+123
-7
lines changed

core/src/processing/opengl/PGraphics2DX.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ protected void end2D() {
13191319

13201320
@Override
13211321
public void filter(PShader shader) {
1322+
// TODO: not working... the loadShader() method uses the P2 vertex stage
13221323
// The filter method needs to use the geometry-generation in the base class.
13231324
// We could re-implement it here, but this is easier.
13241325
if (!useParentImpl) {
@@ -1692,13 +1693,14 @@ private boolean checkShaderLocs(PShader shader) {
16921693
if (positionLoc == -1) {
16931694
positionLoc = shader.getAttributeLoc("vertex");
16941695
}
1695-
int colorLoc = shader.getAttributeLoc("color");
1696+
// int colorLoc = shader.getAttributeLoc("color");
16961697
int transformLoc = shader.getUniformLoc("transform");
16971698
if (transformLoc == -1) {
16981699
transformLoc = shader.getUniformLoc("transformMatrix");
16991700
}
17001701

17011702
/*
1703+
// Became less demanding and 2D shaders do not need to have texture uniforms/attribs
17021704
int texScaleLoc = shader.getUniformLoc("texScale");
17031705
if (texScaleLoc == -1) {
17041706
texScaleLoc = shader.getUniformLoc("texOffset");
@@ -1707,8 +1709,8 @@ private boolean checkShaderLocs(PShader shader) {
17071709
int texFactorLoc = shader.getAttributeLoc("texFactor");
17081710
*/
17091711

1710-
return positionLoc != -1 && colorLoc != -1 && transformLoc != -1;
1711-
// texCoordLoc != -1 && texFactorLoc != -1 && texScaleLoc != -1;
1712+
return positionLoc != -1 && transformLoc != -1;
1713+
// colorLoc != -1 && texCoordLoc != -1 && texFactorLoc != -1 && texScaleLoc != -1;
17121714
}
17131715

17141716

@@ -1732,6 +1734,8 @@ private void loadShaderLocs(PShader shader) {
17321734

17331735

17341736
private PShader getShader() {
1737+
// TODO: Perhaps a better way to handle the new 2D rendering would be to define a PShader2D
1738+
// subclass of PShader...
17351739
PShader shader;
17361740
if (twoShader == null) {
17371741
if (defTwoShader == null) {
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
varying vec4 vertColor;
7+
8+
void main() {
9+
gl_FragColor = vertColor;
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
uniform mat4 transform;
2+
3+
attribute vec3 position;
4+
attribute vec4 color;
5+
6+
varying vec4 vertColor;
7+
8+
void main() {
9+
gl_Position = transform * vec4(position, 1);
10+
11+
//we avoid affecting the Z component by the transform
12+
//because it would mess up our depth testing
13+
gl_Position.z = position.z;
14+
15+
vertColor = color.zyxw;
16+
}

debug/apps/fast2d/src/main/java/fast2d/MainActivity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ public class MainActivity extends AppCompatActivity {
1515
// private int TEST = 2; // Mouse controlled polygon
1616
// private int TEST = 3; // Textured poly
1717
// private int TEST = 4; // Text rendering
18-
// private int TEST = 5; // Shapes benchmark
18+
private int TEST = 5; // Shapes benchmark
1919
// private int TEST = 6; // Duplicated vertex
2020
// private int TEST = 7; // User-defined contours
2121
// private int TEST = 8; // Primitive types
2222
// private int TEST = 9; // Arc test
2323
// private int TEST = 10; // Arc test
2424
// private int TEST = 11; // Load and display SVG
2525
// private int TEST = 12; // Filter test
26-
private int TEST = 13; // Custom shader test
26+
// private int TEST = 13; // Custom shader test (texture)
27+
// private int TEST = 14; // Custom shader test (no texture)
2728

2829
private PApplet sketch;
2930

@@ -35,7 +36,6 @@ protected void onCreate(Bundle savedInstanceState) {
3536
setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
3637
ViewGroup.LayoutParams.MATCH_PARENT));
3738

38-
3939
if (TEST == 1) {
4040
sketch = new SketchBasicPoly();
4141
} else if (TEST == 2) {
@@ -62,6 +62,8 @@ protected void onCreate(Bundle savedInstanceState) {
6262
sketch = new SketchFilterTest();
6363
} else if (TEST == 13) {
6464
sketch = new SketchCustomShader();
65+
} else if (TEST == 14) {
66+
sketch = new SketchShaderNoTex();
6567
}
6668

6769
PFragment fragment = new PFragment(sketch);

debug/apps/fast2d/src/main/java/fast2d/Sketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void setup() {
4242
// orientation(LANDSCAPE);
4343

4444
//pardon the silly image
45-
img = loadImage("balmer_developers_poster.png");
45+
img = loadImage("leaves.jpg");
4646
font = createFont("SansSerif", displayDensity * 72);
4747

4848
//setup for demo 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fast2d;
2+
3+
import processing.core.PApplet;
4+
import processing.opengl.PShader;
5+
6+
public class SketchShaderNoTex extends PApplet {
7+
PShader sh;
8+
9+
public void settings() {
10+
// fullScreen(P2D);
11+
fullScreen(P2DX);
12+
}
13+
14+
public void setup() {
15+
orientation(LANDSCAPE);
16+
sh = loadShader("frag.glsl", "vert.glsl");
17+
shader(sh);
18+
}
19+
20+
public void draw() {
21+
translate(mouseX, mouseY);
22+
rect(0, 0, 400, 400);
23+
}
24+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
int join = MITER;
2+
int cap = SQUARE;
3+
4+
boolean premultiply = true;
5+
6+
float dev = 10; //deviation
7+
8+
//change these parameters to benchmark various things
9+
int unit = 10;
10+
//line, triangle, rect, ellipse, point
11+
int[] amount = { 20, 15, 10, 5, 40 };
12+
13+
void setup() {
14+
fullScreen(P2DX);
15+
strokeCap(cap);
16+
strokeJoin(join);
17+
PGraphics2DX.premultiplyMatrices = premultiply;
18+
19+
textFont(createFont("SansSerif", 15 * displayDensity));
20+
}
21+
22+
public void draw() {
23+
background(255);
24+
25+
strokeWeight(2 * displayDensity);
26+
stroke(0);
27+
fill(200);
28+
29+
for (int i = 0; i < amount[0]*unit; ++i) {
30+
float x = random(width);
31+
float y = random(height);
32+
line(x, y, x + random(-dev, dev), y + random(-dev, dev));
33+
}
34+
35+
for (int i = 0; i < amount[1]*unit; ++i) {
36+
float x = random(width);
37+
float y = random(height);
38+
triangle(x, y,
39+
x + random(-dev*2, dev*2), y + random(-dev*2, dev*2),
40+
x + random(-dev*2, dev*2), y + random(-dev*2, dev*2));
41+
}
42+
43+
for (int i = 0; i < amount[2]*unit; ++i) {
44+
rect(random(width), random(height), random(dev), random(dev));
45+
}
46+
47+
for (int i = 0; i < amount[3]*unit; ++i) {
48+
ellipse(random(width), random(height), random(dev*2), random(dev*2));
49+
}
50+
51+
for (int i = 0; i < amount[4]*unit; ++i) {
52+
point(random(width), random(height));
53+
}
54+
55+
//large ellipse to test smoothness of outline
56+
ellipse(width/2, height/2, width/2, height/4);
57+
58+
fill(255, 0, 0);
59+
text((int) frameRate + " fps", 30, 30);
60+
}

0 commit comments

Comments
 (0)