* If we do a partial replay of a frame, a query might be left open. We
track this and make sure we close any that were left open before the next
replay.
* This fixes issues where textures wouldn't render because they weren't
mipmap complete, and although I was point sampling a single mip the point
sampler was referencing the mipchain.
* We create fake backbuffer as SRGB if the original default backbuffer was
SRGB in the program.
* All of our output backbuffers are also SRGB, and we enable
GL_FRAMEBUFFER_SRGB when writing to them.
* Add the 'fake' srgb curve applied to linear data to display it as if it
were srgb, which tends to look intuitively correct even if it's not 100%
accurate. See the behaviour existing in D3D11 already.
* When we do glCopyImageSubData, this seems to require a complete texture
across all mips - ie. the full mip chain (up to MAX_LEVEL) must be set.
This requirement holds even if we only copy the mips that are present.
* However, for example attaching an image to a framebuffer, it doesn't
have to be mipmap complete even if the min/mag filters want mipmaps.
So in this case we have to force the texture to be complete enough for
our purposes, and we do this just by setting MAX_LEVEL to clamp the mips
* The general idea is that while idle we can handle these as normal -
If we ignore the map we ignore the map and mark the buffer dirty etc.
This is fine because modified but unflushed regions become undefined, and
we just let these become the modified values.
* While capturing a frame, we do everything to set up as normal, but then
instead of comparing the modified shadow buffer to an unmodified version,
detecting the modified range and making one big Unmap() chunk, we make a
chunk per Flush() call with the flushed range, and ignore the unmap.
* When glVertexAttrib*Pointer is called it 'latches' the current binding
of GL_ARRAY_BUFFER (it sets the attrib binding and vertex buffer on the
VAO internally).
* So when reading, we haven't serialised all the buffer bindings, so we
need to bind the right buffer by hand.
* If no program or pipeline is bound, need to make sure we don't try and
query a non-existant pipeline. This could happen if e.g. state is totally
cleared at the start of the frame.
* This most commonly happens with shaders and programs. A program record
takes a reference on shader records when they are attached and linked,
then a shader can be orphaned with only that reference remaining if the
user code detaches and deletes it.
* Previously we would go through, force-delete the shader, then when we
force-delete the program things would explode since it tries to decrement
the refcount on the shader and it becomes -1. So now we make all records
remove their parents (which might delete their parents), before we force
delete them.
* If you're capturing and replaying on the same driver it's insanely
unlikely that this translation will be anything other than the identity
map, although it wouldn't be illegal to renumber locations. However this
should allow moving captures between vendors/driver versions/platforms,
which in the past wasn't possible because locations would change (quite
validly) when the programs were recompiled. There might be other issues,
but at least this one is fixed.
* If it's immutable, fetch immutable size, otherwise calculate number from
top level width/height/depth.
* Then clamp by TEXTURE_MAX_LEVEL.
* THEN we need to go through each mip and check that it's been set if the
texture wasn't immutable, since some mips might be uninitialised and
that is legal, as long as those mips aren't used (e.g. by point sampling
or as a FBO attachment).
* Even this isn't quite enough. We're actually assuming a 'complete'
texture, i.e. one which has had all mips uploaded/init'd. It's actually
valid to have a texture that doesn't have all of its mips initialised
but as long as you don't use them, ie. you bind a point sampler or you
use it as a framebuffer attachments, it's valid. So REALLY in the
non-immutable case, we need to iterate over every level and query to see
if it's been configured, e.g. by fetching its width. Sigh.
* GL_TEXTURE_MAX_LEVEL acts as a bound on the number of mips for either
immutable or non-immutable textures. Instead for non-immutable textures
we do the standard mip calculation and that's what's necessary for a
"complete" texture.