It's currently hardcoded in, but you should at least be able to set it at context creation time.
The current gfx-rs API may make this tricky, though.
Yeah this is tricky 'cause the render target format is a compile-time generic. So we can't necessarily change it without adding some quite pervasive traits involving GraphicsContextGeneric and connected type (basically everything that touches a render target or texture) or breaking the API.
We MIGHT be able to make the color format a property of the BackendSpec trait that GraphicsContextGeneric relies on, and then make multiple graphics context types that are generic on that, but then we would have to deal with Image's and Canvas's and such depending on it as well. This is basically the main style that gfx-ll uses. But it would also probably still be an API breaking change, or at least inconvenient as heck.
HOWEVER:
icefoxen > But I was wondering whether it's possible in gfx-rs 0.17 whether it's possible to somehow make a texture or render target's format generic at runtime instead of compile time.
kvark > sure, just use the RawRenderTargetView and other Raw* things
icefoxen > Hmmmmm.
...oooh. Let me look at that.
Is it just then up to you to make sure that the texture formats you use match up?
Like, it will let you draw a Bgra8 texture on an Rgba8 RawRenderTargetView and just get things wrong?
I don't see any way to check what format a RawRenderTargetView actually is...
kvark > yeah, the backend may have some safeguards but otherwise it's up to you
So we CAN set it at runtime and just enforce it everywhere at runtime, which should be possible since we basically control everywhere that it happens, so we can make it impossible to screw up at runtime -- just always create things with the color format matching the current GraphicsContext and disallow changing it or mixing it up.
This does create exciting opportunities for breakage like, create a context, create images from it, destroy it, create a new one with a different color format, and draw those images on it. Buuuuut textures are all attached to a particular OpenGL context anyway so this opportunity already exists. So, no big deal.
Doesn't seem to have exploded anything yet, but there's still lots of little place the sRGB assumption is hardwired in, even if the core types have removed it.
Man I haven't touched this in far too long.
Refactoring continues; we should be able to do this with https://docs.rs/gfx/0.17.1/gfx/format/trait.RenderChannel.html and https://docs.rs/gfx/0.17.1/gfx/format/trait.SurfaceTyped.html constraints in the BackendSpec definition. Hopefully this will let EVERYTHING be able to be parameterized on those types at compile time, and/or more ability to select at runtime.
DONE in PR #415.
Not perfect; see followup in #416
Most helpful comment
Doesn't seem to have exploded anything yet, but there's still lots of little place the
sRGBassumption is hardwired in, even if the core types have removed it.