Ejemplo n.º 1
0
 public static void deleteGLResource(int id, int type) {
   if (type == GL_TEXTURE_OBJECT) {
     if (glTextureObjects.contains(id)) {
       int[] temp = {id};
       gl.glDeleteTextures(1, temp, 0);
       glTextureObjects.remove(id);
     }
   } else if (type == GL_VERTEX_BUFFER) {
     if (glVertexBuffers.contains(id)) {
       int[] temp = {id};
       gl.glDeleteBuffersARB(1, temp, 0);
       glVertexBuffers.remove(id);
     }
   } else if (type == GL_FRAME_BUFFER) {
     if (glFrameBuffers.contains(id)) {
       int[] temp = {id};
       gl.glDeleteFramebuffersEXT(1, temp, 0);
       glFrameBuffers.remove(id);
     }
   } else if (type == GL_RENDER_BUFFER) {
     if (glRenderBuffers.contains(id)) {
       int[] temp = {id};
       gl.glDeleteRenderbuffersEXT(1, temp, 0);
       glRenderBuffers.remove(id);
     }
   } else if (type == GLSL_PROGRAM) {
     if (glslPrograms.contains(id)) {
       gl.glDeleteProgram(id);
       glslPrograms.remove(id);
     }
   } else if (type == GLSL_SHADER) {
     if (glslShaders.contains(id)) {
       gl.glDeleteShader(id);
       glslShaders.remove(id);
     }
   }
 }
Ejemplo n.º 2
0
  // Releases any remaining OpenGL resources (including CG resources).
  public static void deleteAllGLResources() {
    if (!glTextureObjects.isEmpty()) {
      Object[] glids = glTextureObjects.toArray();
      for (int i = 0; i < glids.length; i++) {
        int id = ((Integer) glids[i]).intValue();
        int[] temp = {id};
        gl.glDeleteTextures(1, temp, 0);
      }
      glTextureObjects.clear();
    }

    if (!glVertexBuffers.isEmpty()) {
      Object[] glids = glVertexBuffers.toArray();
      for (int i = 0; i < glids.length; i++) {
        int id = ((Integer) glids[i]).intValue();
        int[] temp = {id};
        gl.glDeleteBuffersARB(1, temp, 0);
      }
      glVertexBuffers.clear();
    }

    if (!glFrameBuffers.isEmpty()) {
      Object[] glids = glFrameBuffers.toArray();
      for (int i = 0; i < glids.length; i++) {
        int id = ((Integer) glids[i]).intValue();
        int[] temp = {id};
        gl.glDeleteFramebuffersEXT(1, temp, 0);
      }
      glFrameBuffers.clear();
    }

    if (!glRenderBuffers.isEmpty()) {
      Object[] glids = glRenderBuffers.toArray();
      for (int i = 0; i < glids.length; i++) {
        int id = ((Integer) glids[i]).intValue();
        int[] temp = {id};
        gl.glDeleteRenderbuffersEXT(1, temp, 0);
      }
      glRenderBuffers.clear();
    }

    if (!glslPrograms.isEmpty()) {
      Object[] glids = glslPrograms.toArray();
      for (int i = 0; i < glids.length; i++) {
        int id = ((Integer) glids[i]).intValue();
        gl.glDeleteProgram(id);
      }
      glslPrograms.clear();
    }

    if (!glslShaders.isEmpty()) {
      Object[] glids = glslShaders.toArray();
      for (int i = 0; i < glids.length; i++) {
        int id = ((Integer) glids[i]).intValue();
        gl.glDeleteShader(id);
      }
      glslShaders.clear();
    }

    if (!cgContexts.isEmpty()) {
      Object[] glids = cgContexts.toArray();
      for (int i = 0; i < glids.length; i++) {
        Object id = glids[i];
        CgGL.cgDestroyContext((CGcontext) id);
      }
      cgContexts.clear();
    }

    if (!cgPrograms.isEmpty()) {
      Object[] glids = cgPrograms.toArray();
      for (int i = 0; i < glids.length; i++) {
        Object id = glids[i];
        CgGL.cgDestroyProgram((CGprogram) id);
      }
      cgPrograms.clear();
    }

    if (!cgEffects.isEmpty()) {
      Object[] glids = cgEffects.toArray();
      for (int i = 0; i < glids.length; i++) {
        Object id = glids[i];
        CgGL.cgDestroyEffect((CGeffect) id);
      }
      cgEffects.clear();
    }
  }