Skip to content

Instantly share code, notes, and snippets.

@Groovounet
Created August 31, 2016 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Groovounet/2ff369251a99938e595c178f8b4b0bb8 to your computer and use it in GitHub Desktop.
Save Groovounet/2ff369251a99938e595c178f8b4b0bb8 to your computer and use it in GitHub Desktop.
WGL_ARB_colorspace extension proposal
Name
ARB_colorspace
Name Strings
WGL_ARB_colorspace
Contact
Christophe Riccio (christophe 'dot' riccio 'at' unity3d 'dot' com)
IP Status
No known IP claims.
Status
Proposal Draft.
Version
Version 1, 2016-08-31
Number
TBD
Dependencies
WGL_ARB_pixel_format is required.
This extension is written against WGL_ARB_pixel_format extension.
OpenGL dependencies:
OpenGL 3.0 is required
OpenGL ES dependencies:
OpenGL ES 3.0 or GL_EXT_sRGB is required.
Overview
Applications may wish to use sRGB format default framebuffers to
more easily achieve sRGB rendering to display devices. This
extension allows creating pixel format which will be rendered to
in sRGB by OpenGL/ES contexts supporting that capability.
New Procedures and Functions
None.
New Tokens
Accepted as an attribute name by wglGetPixelFormatAttribivARB,
wglGetPixelFormatAttribivARB and wglChoosePixelFormatARB
WGL_COLORSPACE_ARB 0x309D
Accepted as attribute values for WGL_COLORSPACE_ARB by
wglGetPixelFormatAttribivARB, wglGetPixelFormatAttribivARB and
wglChoosePixelFormatARB
WGL_COLORSPACE_SRGB_ARB 0x3089
WGL_COLORSPACE_LINEAR_ARB 0x308A
(these enums are aliases of the corresponding VG colorspace
attribute values from EGL 1.3 and OpenGL/ES colorspace
attribute values from EGL_KHR_gl_colorspace)
Additions to the WGL Specification
Following:
WGL_AUX_BUFFERS_ARB
The number of auxiliary buffers.
Add a new attribute:
WGL_COLORSPACE_ARB
Buffers color space. This can be set to WGL_COLORSPACE_SRGB_ARB or
WGL_COLORSPACE_LINEAR_ARB.
Following:
WGL_AUX_BUFFERS_ARB integer minimum
Add:
WGL_COLORSPACE_ARB enum exact
Before paragraph:
Attributes that are specified in neither <piAttribIList>...
Add paragraph:
WGL_COLORSPACE_ARB specifies the color space used by OpenGL and
OpenGL ES when rendering to the surface[fn1]. If its value is
WGL_COLORSPACE_SRGB_ARB, then a non-linear, perceptually uniform
color space is assumed, with a corresponding
GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING value of GL_SRGB. If its value
is WGL_COLORSPACE_LINEAR_ARB, then a linear color space is assumed,
with a corresponding GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING value of
GL_LINEAR. The default value of WGL_COLORSPACE_ARB is
WGL_COLORSPACE_LINEAR_ARB for OpenGL ES and WGL_COLORSPACE_SRGB_ARB
for OpenGL for pixel formats that are sRGB capable
WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT and WGL_COLORSPACE_LINEAR_ARB
otherwise.
Only OpenGL and OpenGL ES contexts which support sRGB
rendering must respect requests for WGL_COLORSPACE_SRGB_ARB, and
only to sRGB formats supported by the context (normally just SRGB8)
Older versions not supporting sRGB rendering will ignore this
surface attribute. Applications using OpenGL must additionally
enable GL_FRAMEBUFFER_SRGB to perform sRGB rendering, even when an
sRGB surface is bound; this enable is not required (or supported)
for OpenGL ES.
WGL itself does not distinguish multiple colorspace models. Refer to
the 'sRGB Conversion' sections of the OpenGL 4.3 and OpenGL ES 3.0
specifications for more information.
Sample Code
bool SetupPixelFormat(HDC DC, bool Linear)
{
int const Attrib[] = {WGL_NUMBER_PIXEL_FORMATS_ARB};
int FormatCount = 0;
BOOL Result = wglGetPixelFormatAttribivARB(DC, NULL, NULL, 1, Attrib, &FormatCount);
if(Result != GL_TRUE)
return false;
std::vector<int> PixelFormats(static_cast<std::size_t>(FormatCount));
int Attributes[] =
{
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_RED_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
WGL_SAMPLES_ARB, 1,
WGL_STEREO_ARB, GL_FALSE,
WGL_COLORSPACE_ARB, Linear ? WGL_COLORSPACE_LINEAR_ARB : WGL_COLORSPACE_SRGB_ARB
0, 0
};
UINT ActualFormatCount = 0;
Result = wglChoosePixelFormatARB(DC, Attributes, NULL, FormatCount, &PixelFormats[0], &ActualFormatCount);
if(Result != GL_TRUE || ActualFormatCount <= 0)
return false;
PIXELFORMATDESCRIPTOR PixelFormatDesc =
{
sizeof(PIXELFORMATDESCRIPTOR), 1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, 32,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
kDepthBits, kStencilBits,
0, PFD_MAIN_PLANE, 0, 0, 0, 0
};
// Select the first PixelFormat
return SetPixelFormat(DC, 0, &PixelFormatDesc) == GL_TRUE;
}
bool IsDefaultFramebufferLinear()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLint Encoding = 0;
// Just like for framebuffer object, return GL_SRGB is the framebuffer support sRGB update and blending and GL_LINEAR is no sRGB conversion can be performed
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &Encoding);
return Encoding == GL_LINEAR;
}
Issues
1) Why do we need this extension?
On Windows, OpenGL ES implementation can not perform linear to sRGB
conversion on the default framebuffer (eg: back bufffer) due to the lack of
glEnable(GL_FRAMEBUFFER_SRGB) toogle.
As a result, an application needs to render into a sRGB framebuffer object
that support sRGB update and blending and then execute a shader simply to
copy the sRGB frmaebuffer object to the default framebuffer.
This extension allows to explicitly set the default framebuffer colorspace
to automatically performa the sRGB conversion without an intermediate
framebufer object.
2) What's the default colorspace of the default framebuffer with OpenGL and
OpenGL ES?
With OpenGL ES (WGL_CONTEXT_ES_PROFILE_BIT_EXT)
the default colorspace is WGL_COLORSPACE_LINEAR_ARB
With OpenGL (WGL_CONTEXT_CORE_PROFILE_BIT_ARB or
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB), the default colorspace
is WGL_COLORSPACE_SRGB_ARB for WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
pixel formats and WGL_COLORSPACE_LINEAR_ARB otherwise.
RESOLVED
3) Does all the context support sRGB?
This extension requires OpenGL 3.0, OpenGL ES 3.0 or GL_EXT_sRGB.
RESOLVED: Yes.
4) Does we want to support more colorspace than sRGB?
The field of color spaces is very vivid these days for good reasons
but new color space in OpenGL is not the purpose of this extension.
https://developer.nvidia.com/sites/default/files/akamai/gameworks/hdr/UHDColorForGames.pdf
RESOLVED: Not in this extension, deferred.
Revision History
2016-08-31 - criccio
+ Initial draft based on EGL_KHR_gl_colorspace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment