/* * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ package jogamp.opengl; import javax.media.opengl.*; import com.jogamp.common.util.IntLongHashMap; /** * Tracks as closely as possible the sizes of allocated OpenGL buffer * objects. *
* glMapBuffer
or glMapBufferRange
etc
* returns a java.nio.ByteBuffer
* instance reflecting the returned native address of respective calls
* and the actual buffer size.
*
* In case the buffer size is unknown, we need to compute this size by using
* glGetBufferParameteriv
with a pname of GL_BUFFER_SIZE
.
* The latter appears to be problematic due to the returned int
value,
* where size should be of type long
.
* Further more, this query appears to be costly for each glMapBuffer call
* at for Apple's new multithreaded OpenGL implementation.
*
* The buffer size state is shared across all shared OpenGL context, * hence we share the GLBufferSizeTracker instance across all shared GLContexts. * Hence utilizing this instance must be synchronized to be thread safe due to multithreading usage. *
*
* We track the sizes of allocated buffer objects.
* We track calls to glBindBuffer
etc to see which buffer is bound to
* which target and to glBufferData
to see how large the buffer's
* allocated size is. When glMapBuffer
is called, we consult our table
* of buffer sizes to see if we can return an answer without a glGet
* call.
*
* In the face of calls to glPushClientAttrib / glPopClientAttrib we currently punt
* and re-fetch the bound buffer object for the state in question;
* see, for example, glVertexPointer
and the calls down to
* GLBufferStateTracker.getBoundBufferObject()
. Note that we currently
* ignore new binding targets such as GL_TRANSFORM_FEEDBACK_BUFFER_NV
;
* the fact that new binding targets may be added in the future makes
* it impossible to cache state for these new targets.
*
* Ignoring new binding targets, the primary situation in which we may
* not be able to return a cached answer is in the case of an error,
* where glBindBuffer
may not have been called before trying to call
* glBufferData
. Also, if external native code modifies a buffer
* object, we may return an incorrect answer. (FIXME: this case
* requires more thought, and perhaps stochastic and
* exponential-fallback checking. However, note that it can only occur
* in the face of external native code which requires that the
* application be signed anyway, so there is no security risk in this
* area.)
*