Example #1
0
  public static Object createCGResource(int type, CGcontext context, String source, int profile) {
    Object id = null;

    if (type == CG_CONTEXT) {
      id = CgGL.cgCreateContext();
      cgContexts.add((CGcontext) id);
    } else if (type == CG_PROGRAM) {
      id = CgGL.cgCreateProgram(context, CgGL.CG_SOURCE, source, profile, null, null);
      cgPrograms.add((CGprogram) id);
    } else if (type == CG_EFFECT) {
      id = CgGL.cgCreateEffect(context, source, null);
      cgEffects.add((CGeffect) id);
    }

    return id;
  }
Example #2
0
  public static int createGLResource(int type, int param) {
    int id = 0;
    if (type == GL_TEXTURE_OBJECT) {
      int[] temp = new int[1];
      gl.glGenTextures(1, temp, 0);
      id = temp[0];
      glTextureObjects.add(id);
    } else if (type == GL_VERTEX_BUFFER) {
      int[] temp = new int[1];
      gl.glGenBuffersARB(1, temp, 0);
      id = temp[0];
      glVertexBuffers.add(id);
    } else if (type == GL_FRAME_BUFFER) {
      int[] temp = new int[1];
      gl.glGenFramebuffersEXT(1, temp, 0);
      id = temp[0];
      glFrameBuffers.add(id);
    } else if (type == GL_RENDER_BUFFER) {
      int[] temp = new int[1];
      gl.glGenRenderbuffersEXT(1, temp, 0);
      id = temp[0];
      glRenderBuffers.add(id);
    } else if (type == GLSL_PROGRAM) {
      id = gl.glCreateProgram();
      glslPrograms.add(id);
    } else if (type == GLSL_SHADER) {
      id = gl.glCreateShader(param);
      glslShaders.add(id);
    }

    return id;
  }
Example #3
0
 public static void deleteCGResource(Object id, int type) {
   if (type == CG_CONTEXT) {
     if (cgContexts.contains(id)) {
       CgGL.cgDestroyContext((CGcontext) id);
       cgContexts.remove(id);
     }
   } else if (type == CG_PROGRAM) {
     if (cgPrograms.contains(id)) {
       CgGL.cgDestroyProgram((CGprogram) id);
       cgPrograms.remove(id);
     }
   } else if (type == CG_EFFECT) {
     if (cgEffects.contains(id)) {
       CgGL.cgDestroyEffect((CGeffect) id);
       cgEffects.remove(id);
     }
   }
 }
Example #4
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();
    }
  }
Example #5
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);
     }
   }
 }