Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HMaterial #164

Open
wants to merge 3 commits into
base: lib_staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/hype/H.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public static boolean mouseStarted() {
return mouse.started();
}

public static void useMaterials(boolean use){
stage.useMaterials(use);
}

/**
* Cast an image to PImage
* @param imgArg Type: PImage, HImageHolder, String
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/hype/HDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class HDrawable extends HNode<HDrawable> implements HDirectable,

/** The extras bundle of this drawable */
protected HBundle extras;
protected HMaterial material;

/** The x location of this drawable */
protected float x;
Expand Down Expand Up @@ -112,6 +113,8 @@ public HDrawable() {

width = DEFAULT_WIDTH;
height = DEFAULT_HEIGHT;

material = new HMaterial();
}

/**
Expand Down Expand Up @@ -143,6 +146,7 @@ public void copyPropertiesFrom(HDrawable other) {
stroke = other.stroke;
strokeCap = other.strokeCap;
strokeJoin = other.strokeJoin;
material = other.material;
}

/**
Expand Down Expand Up @@ -2025,6 +2029,7 @@ protected void applyStyle(PGraphics g, float currAlphaPc) {
g.strokeCap(strokeCap);
g.strokeJoin(strokeJoin);
} else g.noStroke();
material.bind(g);
}

/**
Expand Down Expand Up @@ -2058,9 +2063,17 @@ public void paintAll(PGraphics g, boolean usesZ, float currAlphaPc) {
// Compute current alpha
currAlphaPc *= alphaPc;

// TODO: check if the shader is already binded before doing it again. They are stored in pointShader, lineShader and polyShader here:https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGraphicsOpenGL.java
// if(material.shader != null){
// material.bind(g);
// }
// else
// g.resetShader();
// Draw self
draw(g, usesZ,-anchorX(),-anchorY(),currAlphaPc);

if( material.active)
g.resetShader();
// Draw children
HDrawable child = firstChild;
while(child != null) {
Expand All @@ -2087,6 +2100,15 @@ public abstract void draw( PGraphics g, boolean usesZ,
float drawX, float drawY, float currAlphaPc);


public HDrawable material(HMaterial mat){
this.material = mat;
this.material.setActive(true);
return this;
}

public HMaterial getMaterial(){
return material;
}

/**
* An HIterator used for iterating through HDrawable's children.
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/hype/HMaterial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package hype;

import processing.core.PGraphics;
import processing.opengl.PShader;

public class HMaterial {
PShader shader;
boolean active = false;

public HMaterial(){
shader = null;
}

public HMaterial(HMaterial copy){
shader = copy.shader;
}

public void bind(PGraphics pg){
if(!active)
return;
if(shader != null)
{
pg.shader(shader);
}
}

public boolean getActive() {
return active;
}

public HMaterial setActive(boolean _active) {
this.active = _active;
return this;
}
public PShader getShader() {
return shader;
}

public HMaterial setShader(PShader shader) {
this.shader = shader;
return this;
}


}
10 changes: 9 additions & 1 deletion src/main/java/hype/HStage.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hype;
package hype;

import hype.interfaces.HImageHolder;
import hype.interfaces.HConstants;
Expand Down Expand Up @@ -147,6 +147,14 @@ public void paintAll(PGraphics g, boolean usesZ, float currAlphaPc) {
}


public void useMaterials(boolean use){

HDrawable child = firstChild;
while(child != null) {
child.getMaterial().setActive(use);
child = child.next();
}
}
// DEACTIVATED HDRAWABLE METHODS //

@Override
Expand Down