Skip to content

Commit

Permalink
updated some tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed Jun 3, 2019
1 parent 6e43607 commit cac5c64
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 7 deletions.
10 changes: 7 additions & 3 deletions core/src/processing/opengl/PGraphics2DX.java
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ protected void end2D() {

@Override
public void filter(PShader shader) {
// TODO: not working... the loadShader() method uses the P2 vertex stage
// The filter method needs to use the geometry-generation in the base class.
// We could re-implement it here, but this is easier.
if (!useParentImpl) {
Expand Down Expand Up @@ -1692,13 +1693,14 @@ private boolean checkShaderLocs(PShader shader) {
if (positionLoc == -1) {
positionLoc = shader.getAttributeLoc("vertex");
}
int colorLoc = shader.getAttributeLoc("color");
// int colorLoc = shader.getAttributeLoc("color");
int transformLoc = shader.getUniformLoc("transform");
if (transformLoc == -1) {
transformLoc = shader.getUniformLoc("transformMatrix");
}

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

return positionLoc != -1 && colorLoc != -1 && transformLoc != -1;
// texCoordLoc != -1 && texFactorLoc != -1 && texScaleLoc != -1;
return positionLoc != -1 && transformLoc != -1;
// colorLoc != -1 && texCoordLoc != -1 && texFactorLoc != -1 && texScaleLoc != -1;
}


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


private PShader getShader() {
// TODO: Perhaps a better way to handle the new 2D rendering would be to define a PShader2D
// subclass of PShader...
PShader shader;
if (twoShader == null) {
if (defTwoShader == null) {
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions debug/apps/fast2d/src/main/assets/frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

varying vec4 vertColor;

void main() {
gl_FragColor = vertColor;
}
16 changes: 16 additions & 0 deletions debug/apps/fast2d/src/main/assets/vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
uniform mat4 transform;

attribute vec3 position;
attribute vec4 color;

varying vec4 vertColor;

void main() {
gl_Position = transform * vec4(position, 1);

//we avoid affecting the Z component by the transform
//because it would mess up our depth testing
gl_Position.z = position.z;

vertColor = color.zyxw;
}
8 changes: 5 additions & 3 deletions debug/apps/fast2d/src/main/java/fast2d/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ public class MainActivity extends AppCompatActivity {
// private int TEST = 2; // Mouse controlled polygon
// private int TEST = 3; // Textured poly
// private int TEST = 4; // Text rendering
// private int TEST = 5; // Shapes benchmark
private int TEST = 5; // Shapes benchmark
// private int TEST = 6; // Duplicated vertex
// private int TEST = 7; // User-defined contours
// private int TEST = 8; // Primitive types
// private int TEST = 9; // Arc test
// private int TEST = 10; // Arc test
// private int TEST = 11; // Load and display SVG
// private int TEST = 12; // Filter test
private int TEST = 13; // Custom shader test
// private int TEST = 13; // Custom shader test (texture)
// private int TEST = 14; // Custom shader test (no texture)

private PApplet sketch;

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


if (TEST == 1) {
sketch = new SketchBasicPoly();
} else if (TEST == 2) {
Expand All @@ -62,6 +62,8 @@ protected void onCreate(Bundle savedInstanceState) {
sketch = new SketchFilterTest();
} else if (TEST == 13) {
sketch = new SketchCustomShader();
} else if (TEST == 14) {
sketch = new SketchShaderNoTex();
}

PFragment fragment = new PFragment(sketch);
Expand Down
2 changes: 1 addition & 1 deletion debug/apps/fast2d/src/main/java/fast2d/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setup() {
// orientation(LANDSCAPE);

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

//setup for demo 2
Expand Down
24 changes: 24 additions & 0 deletions debug/apps/fast2d/src/main/java/fast2d/SketchShaderNoTex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fast2d;

import processing.core.PApplet;
import processing.opengl.PShader;

public class SketchShaderNoTex extends PApplet {
PShader sh;

public void settings() {
// fullScreen(P2D);
fullScreen(P2DX);
}

public void setup() {
orientation(LANDSCAPE);
sh = loadShader("frag.glsl", "vert.glsl");
shader(sh);
}

public void draw() {
translate(mouseX, mouseY);
rect(0, 0, 400, 400);
}
}
60 changes: 60 additions & 0 deletions mode/examples/Demos/Performance/P2DXDemo/P2DXDemo.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
int join = MITER;
int cap = SQUARE;

boolean premultiply = true;

float dev = 10; //deviation

//change these parameters to benchmark various things
int unit = 10;
//line, triangle, rect, ellipse, point
int[] amount = { 20, 15, 10, 5, 40 };

void setup() {
fullScreen(P2DX);
strokeCap(cap);
strokeJoin(join);
PGraphics2DX.premultiplyMatrices = premultiply;

textFont(createFont("SansSerif", 15 * displayDensity));
}

public void draw() {
background(255);

strokeWeight(2 * displayDensity);
stroke(0);
fill(200);

for (int i = 0; i < amount[0]*unit; ++i) {
float x = random(width);
float y = random(height);
line(x, y, x + random(-dev, dev), y + random(-dev, dev));
}

for (int i = 0; i < amount[1]*unit; ++i) {
float x = random(width);
float y = random(height);
triangle(x, y,
x + random(-dev*2, dev*2), y + random(-dev*2, dev*2),
x + random(-dev*2, dev*2), y + random(-dev*2, dev*2));
}

for (int i = 0; i < amount[2]*unit; ++i) {
rect(random(width), random(height), random(dev), random(dev));
}

for (int i = 0; i < amount[3]*unit; ++i) {
ellipse(random(width), random(height), random(dev*2), random(dev*2));
}

for (int i = 0; i < amount[4]*unit; ++i) {
point(random(width), random(height));
}

//large ellipse to test smoothness of outline
ellipse(width/2, height/2, width/2, height/4);

fill(255, 0, 0);
text((int) frameRate + " fps", 30, 30);
}

0 comments on commit cac5c64

Please sign in to comment.