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); } } }
// 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(); } }