Esempio n. 1
0
  protected void copyObject(Texture src) {
    // The OpenGL texture of this object is replaced with the one from the
    // source object, so we delete the former to avoid resource wasting.
    release();

    width = src.width;
    height = src.height;

    parent = src.parent;
    pg = src.pg;

    glName = src.glName;
    glTarget = src.glTarget;
    glFormat = src.glFormat;
    glMinFilter = src.glMinFilter;
    glMagFilter = src.glMagFilter;

    glWidth = src.glWidth;
    glHeight = src.glHeight;

    usingMipmaps = src.usingMipmaps;
    usingRepeat = src.usingRepeat;
    maxTexcoordU = src.maxTexcoordU;
    maxTexcoordV = src.maxTexcoordV;

    invertedX = src.invertedX;
    invertedY = src.invertedY;
  }
Esempio n. 2
0
  public void resize(int wide, int high) {
    // Marking the texture object as finalized so it is deleted
    // when creating the new texture.
    release();

    // Creating new texture with the appropriate size.
    Texture tex = new Texture(parent, wide, high, getParameters());

    // Copying the contents of this texture into tex.
    tex.set(this);

    // Now, overwriting "this" with tex.
    copyObject(tex);

    // Nullifying some utility objects so they are recreated with the
    // appropriate size when needed.
    tempFbo = null;
  }
Esempio n. 3
0
  /** Allocates the opengl texture object. */
  protected void allocate() {
    release(); // Just in the case this object is being re-allocated.

    boolean enabledTex = false;
    if (!pgl.texturingIsEnabled(glTarget)) {
      pgl.enableTexturing(glTarget);
      enabledTex = true;
    }

    context = pgl.getCurrentContext();
    glName = pg.createTextureObject(context);

    pgl.bindTexture(glTarget, glName);
    pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
    pgl.texParameteri(glTarget, PGL.TEXTURE_MAG_FILTER, glMagFilter);
    pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_S, glWrapS);
    pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT);
    if (PGraphicsOpenGL.anisoSamplingSupported) {
      pgl.texParameterf(glTarget, PGL.TEXTURE_MAX_ANISOTROPY, PGraphicsOpenGL.maxAnisoAmount);
    }

    // First, we use glTexImage2D to set the full size of the texture (glW/glH
    // might be diff from w/h in the case that the GPU doesn't support NPOT
    // textures)
    pgl.texImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, PGL.RGBA, PGL.UNSIGNED_BYTE, null);

    // Makes sure that the texture buffer in video memory doesn't contain
    // any garbage.
    pgl.initTexture(glTarget, PGL.RGBA, width, height);

    pgl.bindTexture(glTarget, 0);
    if (enabledTex) {
      pgl.disableTexturing(glTarget);
    }
    bound = false;
  }