Java Code Examples for processing.opengl.PGraphicsOpenGL#getTexture()

The following examples show how to use processing.opengl.PGraphicsOpenGL#getTexture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SummedAreaTable.java    From PixelFlow with MIT License 6 votes vote down vote up
/**
 * applies a box-blur using the SAT-Textures (needs to be created in previous step)
 * 
 * @param dst
 * @param radius
 */
public void apply(PGraphicsOpenGL dst, int radius){
  Texture tex_dst = dst.getTexture(); if(!tex_dst.available())  return;
  
  int w_sat = sat_src.w;
  int h_sat = sat_src.h;
  int w_dst = tex_dst.glWidth;
  int h_dst = tex_dst.glHeight;

  DwGLSLProgram shader = shader_blur;
  context.begin();
  context.beginDraw(dst);
  shader.begin();
  shader.uniform2f     ("wh_dst" , w_dst, h_dst);
  shader.uniform2f     ("wh_sat" , w_sat, h_sat);
  shader.uniformTexture("tex_sat", sat_src);
  shader.uniform1i     ("radius", radius);
  shader.drawFullScreenQuad();
  shader.end();
  context.endDraw();
  context.end("SummedAreaTable.apply");
}
 
Example 2
Source File: DistanceTransform.java    From PixelFlow with MIT License 6 votes vote down vote up
public void computeDistanceThreshold(PGraphicsOpenGL dst, float distance_threshold, float[] colA, float[] colB){
  Texture tex_dst  = dst.getTexture();  if(!tex_dst .available())  return;
 
  int w = dst.width;
  int h = dst.height;
  
  context.begin();
  context.beginDraw(dst);
  shader_threshold.begin();
  shader_threshold.uniform2f     ("wh_rcp"   , 1f/w, 1f/h);
  shader_threshold.uniform4fv    ("colA"     , 1, colA);
  shader_threshold.uniform4fv    ("colB"     , 1, colB);
  shader_threshold.uniform1f     ("threshold", distance_threshold);
  shader_threshold.uniformTexture("tex_dtnn" , tex_dtnn.src);
  shader_threshold.drawFullScreenQuad();
  shader_threshold.end();
  context.endDraw();
  context.end("DistanceTransform.computeDistanceThreshold");
}
 
Example 3
Source File: DwUtils.java    From PixelFlow with MIT License 6 votes vote down vote up
static public void changeTextureFormat(PGraphicsOpenGL pg, int internal_format, int format, int type, int filter, int wrap){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureFormat: PGraphicsOpenGL texture not available.");
    return;
  }
  
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MIN_FILTER, filter); // GL_NEAREST, GL_LINEAR
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MAG_FILTER, filter); 
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_WRAP_S, wrap);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_WRAP_T, wrap);
  pgl.texImage2D   (tex.glTarget, 0, internal_format, tex.glWidth, tex.glHeight, 0, format, type, null);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
  
  pg.beginDraw();
  pg.clear();
  pg.endDraw();
}
 
Example 4
Source File: Copy.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, PGraphicsOpenGL dst) {
  Texture tex_src = src.getTexture(); if(!tex_src.available())  return;
  Texture tex_dst = dst.getTexture(); if(!tex_dst.available())  return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.width, dst.height);
  context.endDraw();
  context.end("Copy.apply");
}
 
Example 5
Source File: DwUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public void changeTextureFilter(PGraphicsOpenGL pg, int min_filter, int mag_filter){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureFilter: PGraphicsOpenGL texture not available.");
    return;
  }
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MIN_FILTER, min_filter);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MAG_FILTER, mag_filter);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
}
 
Example 6
Source File: LuminanceThreshold.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, PGraphicsOpenGL dst) {
  Texture tex_src = src.getTexture(); if(!tex_src.available())  return;
  Texture tex_dst = dst.getTexture(); if(!tex_dst.available())  return;

  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.width, dst.height);
  context.endDraw();
  context.end("LuminanceThreshold.apply");
}
 
Example 7
Source File: Luminance.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, DwGLTexture dst) {
  Texture tex_src = src.getTexture();
  if(!tex_src.available()) 
    return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.w, dst.h);
  context.endDraw();
  context.end("Luminance.apply");
}
 
Example 8
Source File: MinMaxGlobal.java    From PixelFlow with MIT License 5 votes vote down vote up
/**
 * 
 * remap pixels [min, max] to [0, 1]
 * 
 */
public void map(PGraphicsOpenGL pg_src, PGraphicsOpenGL pg_dst, boolean per_channel){
  Texture tex_src = pg_src.getTexture(); if(!tex_src.available()) return;
  context.begin();
  context.beginDraw(pg_dst);
  map(pg_dst.width, pg_dst.height, tex_src.glName, per_channel);
  context.endDraw();
  context.end("MinMaxGlobal.map");
}
 
Example 9
Source File: RGBL.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, DwGLTexture dst) {
  Texture tex_src = src.getTexture();
  if(!tex_src.available()) 
    return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.w, dst.h);
  context.endDraw();
  context.end("RGBL.apply");
}
 
Example 10
Source File: DwUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
/**
 * When chaning multiple parameters, its better to use this source-code directly.
 * 
 * @param pg
 * @param pname
 * @param param
 */
static public void changeTextureParam(PGraphicsOpenGL pg, int pname, int param){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureParam: PGraphicsOpenGL texture not available.");
    return;
  }
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName);
  pgl.texParameteri(tex.glTarget, pname, param);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
}
 
Example 11
Source File: Difference.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL dst, PGraphicsOpenGL texA, PGraphicsOpenGL texB) {
  Texture tex_dst  = dst .getTexture(); if(!tex_dst .available())  return;
  Texture tex_texA = texA.getTexture(); if(!tex_texA.available())  return;
  Texture tex_texB = texB.getTexture(); if(!tex_texB.available())  return; 

  context.begin();
  context.beginDraw(dst);
  apply(tex_texA.glName, tex_texB.glName, dst.width, dst.height);
  context.endDraw();
  context.end("Difference.apply");
}
 
Example 12
Source File: Copy.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PImage src, DwGLTexture dst) {
  if(!src.parent.g.isGL()){
    return;
  }
  
  PGraphicsOpenGL pogl = (PGraphicsOpenGL) src.parent.g;
  Texture tex_src = pogl.getTexture(src); if(!tex_src.available())  return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.w, dst.h);
  context.endDraw();
  context.end("Copy.apply");
}
 
Example 13
Source File: Copy.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, DwGLTexture dst) {
  Texture tex_src = src.getTexture(); if(!tex_src.available())  return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.w, dst.h);
  context.endDraw();
  context.end("Copy.apply");
}
 
Example 14
Source File: DistanceTransform.java    From PixelFlow with MIT License 5 votes vote down vote up
/**
 * texel-data lookup at the nearest neighbor -> voronoi
 * 
 * @param src src color at nn-lookup position
 * @param dst
 */
public void apply(PGraphicsOpenGL src, PGraphicsOpenGL dst){
  Texture tex_src = src.getTexture();  if(!tex_src .available()) return;
  Texture tex_dst = dst.getTexture();  if(!tex_dst .available()) return;
  
  if(src == dst){
    System.out.println("DistanceTransform.apply error: read-write race");
  }
  int w_dst = dst.width;
  int h_dst = dst.height;
  
  int w_src = src.width;
  int h_src = src.height;
  
  int w_dtnn = tex_dtnn.src.w;
  int h_dtnn = tex_dtnn.src.h;

  context.begin();
  context.beginDraw(dst);
  shader_voronoi.begin();
  shader_voronoi.uniform2f     ("wh_rcp"     , 1f/w_dst, 1f/h_dst);
  shader_voronoi.uniform2f     ("wh_src_rcp" , 1f/w_src, 1f/h_src);
  shader_voronoi.uniform2f     ("wh_dtnn_rcp", 1f/w_dtnn, 1f/h_dtnn);
  shader_voronoi.uniform1f     ("dist_norm"  , param.voronoi_distance_normalization);
  shader_voronoi.uniformTexture("tex_src"    , tex_src.glName);
  shader_voronoi.uniformTexture("tex_dtnn"   , tex_dtnn.src);
  shader_voronoi.drawFullScreenQuad();
  shader_voronoi.end();
  context.endDraw();
  context.end("DistanceTransform.apply");
}
 
Example 15
Source File: GaussianBlur.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, PGraphicsOpenGL dst, PGraphicsOpenGL tmp, int radius, float sigma) {
    if(src == tmp || dst == tmp){
      System.out.println("GaussianBlur error: read-write race");
      return;
    }
    if(radius <= 0){
      return; 
    }
    
    Texture tex_src = src.getTexture(); if(!tex_src.available()) return;
    Texture tex_dst = dst.getTexture(); if(!tex_dst.available()) return;
    Texture tex_tmp = tmp.getTexture(); if(!tex_tmp.available()) return;
    
    context.begin();
    
    context.beginDraw(tmp);
    pass(tex_src.glName, tmp.width, tmp.height, radius, sigma, HORZ);
    context.endDraw("GaussianBlur.apply - HORZ");

//    Texture tex_tmp = tmp.getTexture();
    
    context.beginDraw(dst);
    pass(tex_tmp.glName, dst.width, dst.height, radius, sigma, VERT);
    context.endDraw("GaussianBlur.apply - VERT");
    
    context.end();
  }
 
Example 16
Source File: Mad.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(DwGLTexture src, PGraphicsOpenGL dst, float[] mad) {
  Texture tex_src = dst.getTexture();
  if(!tex_src.available()) 
    return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.width, dst.height, mad);
  context.endDraw();
  context.end("Mad.apply");
}
 
Example 17
Source File: Threshold.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, DwGLTexture dst) {
  Texture tex_src = src.getTexture();
  if(!tex_src.available()) 
    return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.w, dst.h);
  context.endDraw();
  context.end("Threshold.apply");
}
 
Example 18
Source File: Threshold.java    From PixelFlow with MIT License 5 votes vote down vote up
public void apply(PGraphicsOpenGL src, PGraphicsOpenGL dst) {
  Texture tex_src = src.getTexture(); if(!tex_src.available())  return;
  Texture tex_dst = dst.getTexture(); if(!tex_dst.available())  return;
     
  context.begin();
  context.beginDraw(dst);
  apply(tex_src.glName, dst.width, dst.height);
  context.endDraw();
  context.end("Threshold.apply");
}
 
Example 19
Source File: DwShadertoy.java    From PixelFlow with MIT License 5 votes vote down vote up
/**
 * execute shader, using the given PGRaphics-rendertarget.
 * @param tex_dst
 */
public void apply(PGraphicsOpenGL pg_dst){
  resize(pg_dst.width, pg_dst.height);
  pg_dst.getTexture();
  context.begin();
  context.beginDraw(pg_dst);
  render(pg_dst.width, pg_dst.height);
  context.endDraw();
  context.end();
}
 
Example 20
Source File: DwFlowField.java    From PixelFlow with MIT License 4 votes vote down vote up
public void create(PGraphicsOpenGL pg_src){
  Texture tex_src = pg_src.getTexture(); if(!tex_src.available())  return;
  create(tex_src.glName, tex_src.glWidth, tex_src.glHeight);
}