private long getBufferSizeImpl(int target, int buffer, GL caller) { // See whether we know the size of this buffer object; at this // point we almost certainly should if the application is // written correctly long sz = bufferSizeMap.get(buffer); if (0 > sz) { // For robustness, try to query this value from the GL as we used to // FIXME: both functions return 'int' types, which is not suitable, // since buffer lenght is 64bit ? int[] tmp = new int[1]; if (0 == target) { // DirectState .. if (caller.isFunctionAvailable("glGetNamedBufferParameterivEXT")) { caller.getGL2().glGetNamedBufferParameterivEXT(buffer, GL.GL_BUFFER_SIZE, tmp, 0); } else { throw new GLException( "Error: getDirectStateBufferSize called with unknown state and GL function 'glGetNamedBufferParameterivEXT' n/a to query size"); } } else { caller.glGetBufferParameteriv(target, GL.GL_BUFFER_SIZE, tmp, 0); } if (tmp[0] == 0) { // Assume something is wrong rather than silently going along throw new GLException( "Error: buffer size returned by " + ((0 == target) ? "glGetNamedBufferParameterivEXT" : "glGetBufferParameteriv") + " was zero; probably application error"); } // Assume we just don't know what's happening sz = (long) tmp[0]; bufferSizeMap.put(buffer, sz); if (DEBUG) { System.err.println( "GLBufferSizeTracker.getBufferSize(): made slow query to cache size " + sz + " for buffer " + buffer); } } return sz; }
public GLBufferSizeTracker() { bufferSizeMap = new IntLongHashMap(); bufferSizeMap.setKeyNotFoundValue(-1); }
// This should be called on any major event where we might start // producing wrong answers, such as OpenGL context creation and // destruction if we don't know whether there are other currently- // created contexts that might be keeping the buffer objects alive // that we're dealing with public void clearCachedBufferSizes() { bufferSizeMap.clear(); }
public void setDirectStateBufferSize(int buffer, GL caller, long size) { bufferSizeMap.put(buffer, size); }