DRW: Convert common theme color to linear for viewport render

This is not 100% correct (it should use a transfer function depending
on the display profile) but this is already much better than using srgb.
This commit is contained in:
Clément Foucault 2018-09-11 17:05:07 +02:00
parent 3fbdcefa17
commit 57f9e31bf4
2 changed files with 16 additions and 0 deletions

View File

@ -132,6 +132,16 @@ void DRW_globals_update(void)
ts.sizeEdge = U.pixelsize * (1.0f / 2.0f); /* TODO Theme */
ts.sizeEdgeFix = U.pixelsize * (0.5f + 2.0f * (2.0f * (MAX2(ts.sizeVertex, ts.sizeEdge)) * (float)M_SQRT1_2));
/* Color management. */
if (DRW_state_is_image_render()) {
float *color = ts.UBO_FIRST_COLOR;
do {
/* TODO more accurate transform. */
srgb_to_linearrgb_v4(color, color);
color += 4;
} while (color != ts.UBO_LAST_COLOR);
}
if (globals_ubo == NULL) {
globals_ubo = DRW_uniformbuffer_create(sizeof(GlobalsUboStorage), &ts);
}

View File

@ -36,8 +36,12 @@ struct ModifierData;
struct ParticleSystem;
struct PTCacheEdit;
#define UBO_FIRST_COLOR colorWire
#define UBO_LAST_COLOR colorGridAxisZ
/* Used as ubo but colors can be directly referenced as well */
/* Keep in sync with: common_globals_lib.glsl (globalsBlock) */
/* NOTE! Also keep all color as vec4 and between UBO_FIRST_COLOR and UBO_LAST_COLOR */
typedef struct GlobalsUboStorage {
/* UBOs data needs to be 16 byte aligned (size of vec4) */
float colorWire[4];
@ -99,6 +103,8 @@ typedef struct GlobalsUboStorage {
float colorGridAxisY[4];
float colorGridAxisZ[4];
/* NOTE! Put all color before UBO_LAST_COLOR */
/* Pack individual float at the end of the buffer to avoid alignement errors */
float sizeLampCenter, sizeLampCircle, sizeLampCircleShadow;
float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot;