revert gamma correction code
parent
0c5731b7eb
commit
7037d7158b
15
bind/v4k.lua
15
bind/v4k.lua
|
@ -1076,7 +1076,7 @@ enum TEXTURE_FLAGS {
|
||||||
TEXTURE_RGB = IMAGE_RGB,
|
TEXTURE_RGB = IMAGE_RGB,
|
||||||
TEXTURE_RGBA = IMAGE_RGBA,
|
TEXTURE_RGBA = IMAGE_RGBA,
|
||||||
TEXTURE_FLIP = IMAGE_FLIP,
|
TEXTURE_FLIP = IMAGE_FLIP,
|
||||||
TEXTURE_NO_SRGB = 1 << 24,
|
TEXTURE_SRGB = 1 << 24,
|
||||||
TEXTURE_BGR = 1 << 25,
|
TEXTURE_BGR = 1 << 25,
|
||||||
TEXTURE_BGRA = TEXTURE_BGR,
|
TEXTURE_BGRA = TEXTURE_BGR,
|
||||||
TEXTURE_ARRAY = 1 << 26,
|
TEXTURE_ARRAY = 1 << 26,
|
||||||
|
@ -1111,10 +1111,10 @@ typedef struct colormap_t {
|
||||||
texture_t *texture;
|
texture_t *texture;
|
||||||
} colormap_t;
|
} colormap_t;
|
||||||
bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb );
|
bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb );
|
||||||
void fullscreen_quad_rgb( texture_t texture_rgb, float gamma );
|
void fullscreen_quad_rgb( texture_t texture_rgb );
|
||||||
void fullscreen_quad_rgb_flipped( texture_t texture, float gamma );
|
void fullscreen_quad_rgb_flipped( texture_t texture );
|
||||||
void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3], float gamma );
|
void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3] );
|
||||||
void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3], float gamma );
|
void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3] );
|
||||||
typedef struct cubemap_t {
|
typedef struct cubemap_t {
|
||||||
unsigned id;
|
unsigned id;
|
||||||
vec3 sh[9];
|
vec3 sh[9];
|
||||||
|
@ -1668,9 +1668,6 @@ typedef struct spine_t spine_t;
|
||||||
void spine_render(spine_t *p, vec3 offset, unsigned flags);
|
void spine_render(spine_t *p, vec3 offset, unsigned flags);
|
||||||
void spine_animate(spine_t *p, float delta);
|
void spine_animate(spine_t *p, float delta);
|
||||||
void ui_spine(spine_t *p);
|
void ui_spine(spine_t *p);
|
||||||
enum ATLAS_FLAGS {
|
|
||||||
ATLAS_SRGB = 2,
|
|
||||||
};
|
|
||||||
typedef struct atlas_frame_t {
|
typedef struct atlas_frame_t {
|
||||||
unsigned delay;
|
unsigned delay;
|
||||||
vec4 sheet;
|
vec4 sheet;
|
||||||
|
@ -1758,7 +1755,7 @@ typedef struct skinned_t {
|
||||||
atlas_t atlas;
|
atlas_t atlas;
|
||||||
float scale;
|
float scale;
|
||||||
} skinned_t;
|
} skinned_t;
|
||||||
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
|
guiskin_t gui_skinned(const char *asefile, float scale);
|
||||||
bool steam_init(unsigned app_id);
|
bool steam_init(unsigned app_id);
|
||||||
void steam_tick();
|
void steam_tick();
|
||||||
void steam_trophy(const char *trophy_id, bool redeem);
|
void steam_trophy(const char *trophy_id, bool redeem);
|
||||||
|
|
|
@ -50,7 +50,6 @@ int main() {
|
||||||
// window (80% sized, MSAA x4 flag)
|
// window (80% sized, MSAA x4 flag)
|
||||||
window_create(80.0, WINDOW_MSAA4);
|
window_create(80.0, WINDOW_MSAA4);
|
||||||
window_title(__FILE__);
|
window_title(__FILE__);
|
||||||
window_gamma(0);
|
|
||||||
|
|
||||||
// tiled map
|
// tiled map
|
||||||
tiled_t tmx = tiled(vfs_read("castle.tmx"));
|
tiled_t tmx = tiled(vfs_read("castle.tmx"));
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
window_create(75.0, WINDOW_MSAA8);
|
window_create(75.0, WINDOW_MSAA8);
|
||||||
window_gamma(0); // @fixme: disable gamma correction for now
|
|
||||||
|
|
||||||
// style: our aliases
|
// style: our aliases
|
||||||
#define FONT_REGULAR FONT_FACE1
|
#define FONT_REGULAR FONT_FACE1
|
||||||
|
|
|
@ -32,7 +32,7 @@ int main() {
|
||||||
// video api: decode frame and get associated textures (audio is sent to audiomixer automatically)
|
// video api: decode frame and get associated textures (audio is sent to audiomixer automatically)
|
||||||
textures = video_decode( v );
|
textures = video_decode( v );
|
||||||
// fullscreen video
|
// fullscreen video
|
||||||
// if(video_is_rgb(v)) fullscreen_quad_rgb( textures[0], 1.3f );
|
// if(video_is_rgb(v)) fullscreen_quad_rgb( textures[0] );
|
||||||
// else fullscreen_quad_ycbcr( textures, 1.3f );
|
// else fullscreen_quad_ycbcr( textures, 1.3f );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ int main() {
|
||||||
|
|
||||||
// present decoded textures as a fullscreen composed quad
|
// present decoded textures as a fullscreen composed quad
|
||||||
profile( "Video quad" ) {
|
profile( "Video quad" ) {
|
||||||
if(is_rgb) fullscreen_quad_rgb( textures[0], 1.0 );
|
if(is_rgb) fullscreen_quad_rgb( textures[0] );
|
||||||
else fullscreen_quad_ycbcr( textures, 1.0f/2.2f );
|
else fullscreen_quad_ycbcr( textures );
|
||||||
}
|
}
|
||||||
|
|
||||||
// input controls
|
// input controls
|
||||||
|
|
|
@ -29,7 +29,7 @@ int main() {
|
||||||
compute_dispatch(TEX_WIDTH/10, TEX_WIDTH/10, 1);
|
compute_dispatch(TEX_WIDTH/10, TEX_WIDTH/10, 1);
|
||||||
write_barrier_image();
|
write_barrier_image();
|
||||||
|
|
||||||
fullscreen_quad_rgb(tex, 2.2);
|
fullscreen_quad_rgb(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
int main() {
|
int main() {
|
||||||
window_create(75.0, 0 );
|
window_create(75.0, 0 );
|
||||||
|
|
||||||
gui_pushskin(gui_skinned("golden.ase", 3.0f, 1)); // x3 scale, sRGB enabled
|
gui_pushskin(gui_skinned("golden.ase", 3.0f)); // x3 scale
|
||||||
skinned_t *skinned = (skinned_t*)gui_userdata();
|
skinned_t *skinned = (skinned_t*)gui_userdata();
|
||||||
|
|
||||||
vec4 pos = vec4(400,400,100, 30);
|
vec4 pos = vec4(400,400,100, 30);
|
||||||
|
|
|
@ -81,7 +81,7 @@ int main() {
|
||||||
temp_calc(img);
|
temp_calc(img);
|
||||||
texture_update(&tex, TEX_WIDTH, TEX_WIDTH, 4, img, TEXTURE_LINEAR|TEXTURE_FLOAT);
|
texture_update(&tex, TEX_WIDTH, TEX_WIDTH, 4, img, TEXTURE_LINEAR|TEXTURE_FLOAT);
|
||||||
}
|
}
|
||||||
fullscreen_quad_rgb(tex, 2.2);
|
fullscreen_quad_rgb(tex);
|
||||||
ddraw_text2d(vec2(0,0), va("mode: %s\nimage res: %d\ninputs: %.01f %.01f %.01f %.01f %s", TEMP_GPU?"GPU compute":"CPU", TEX_WIDTH, mouse.x, mouse.y, mouse.z, mouse.w, strong>1?"lshift":""));
|
ddraw_text2d(vec2(0,0), va("mode: %s\nimage res: %d\ninputs: %.01f %.01f %.01f %.01f %s", TEMP_GPU?"GPU compute":"CPU", TEX_WIDTH, mouse.x, mouse.y, mouse.z, mouse.w, strong>1?"lshift":""));
|
||||||
ddraw_text2d(vec2(0,window_height() - 20), va("delta: %.2f ms", window_delta()*1000));
|
ddraw_text2d(vec2(0,window_height() - 20), va("delta: %.2f ms", window_delta()*1000));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ void render(void *arg) {
|
||||||
|
|
||||||
// present decoded textures as a fullscreen composed quad
|
// present decoded textures as a fullscreen composed quad
|
||||||
profile( "Video quad" ) {
|
profile( "Video quad" ) {
|
||||||
fullscreen_quad_rgb( textures[0], 1.3f );
|
fullscreen_quad_rgb( textures[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ui video
|
// ui video
|
||||||
|
|
|
@ -139,7 +139,7 @@ int main() {
|
||||||
|
|
||||||
while( window_swap() && SFG_mainLoopBody() ) {
|
while( window_swap() && SFG_mainLoopBody() ) {
|
||||||
texture_update(&t, SFG_SCREEN_RESOLUTION_X, SFG_SCREEN_RESOLUTION_Y, 4, screen, TEXTURE_RGB|TEXTURE_NEAREST);
|
texture_update(&t, SFG_SCREEN_RESOLUTION_X, SFG_SCREEN_RESOLUTION_Y, 4, screen, TEXTURE_RGB|TEXTURE_NEAREST);
|
||||||
fullscreen_quad_rgb(t, 1.0f);
|
fullscreen_quad_rgb(t);
|
||||||
|
|
||||||
uint16_t samples[128]; // 8 KHz 16-bit mono = 8000/60 = 133 samples/frame -> 256 samples/frame
|
uint16_t samples[128]; // 8 KHz 16-bit mono = 8000/60 = 133 samples/frame -> 256 samples/frame
|
||||||
audioFillCallback(NULL, (uint8_t*)samples, sizeof(samples));
|
audioFillCallback(NULL, (uint8_t*)samples, sizeof(samples));
|
||||||
|
|
|
@ -129,7 +129,7 @@ void logic() {
|
||||||
void blit() {
|
void blit() {
|
||||||
static texture_t screen; do_once screen = texture_checker();
|
static texture_t screen; do_once screen = texture_checker();
|
||||||
texture_update(&screen, DOOM_WIDTH, DOOM_HEIGHT, 4, doom_get_framebuffer(4), TEXTURE_RGBA/*|TEXTURE_LINEAR*/);
|
texture_update(&screen, DOOM_WIDTH, DOOM_HEIGHT, 4, doom_get_framebuffer(4), TEXTURE_RGBA/*|TEXTURE_LINEAR*/);
|
||||||
fullscreen_quad_rgb(screen, 1.0f); // gamma(1)
|
fullscreen_quad_rgb(screen); // gamma(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio() {
|
void audio() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
uniform float u_gamma;
|
uniform float u_gamma; /// set:2.2
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
vec2 uv = TEXCOORD.st;
|
vec2 uv = TEXCOORD.st;
|
||||||
vec4 src = texture2D(iChannel0, uv);
|
vec4 src = texture2D(iChannel0, uv);
|
||||||
color = vec4( pow(src.xyz, vec3(u_gamma)), src.a); // gamma correction
|
color = vec4( pow(src.xyz, vec3(1.0/u_gamma)), src.a); // gamma correction
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
uniform sampler2D texture0; /*unit0*/
|
uniform sampler2D texture0; /*unit0*/
|
||||||
uniform float u_inv_gamma;
|
|
||||||
|
|
||||||
|
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec4 fragcolor;
|
out vec4 fragcolor;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texel = texture( texture0, uv );
|
vec4 texel = texture( texture0, uv );
|
||||||
fragcolor = texel;
|
fragcolor = texel;
|
||||||
fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
uniform sampler2D u_texture_y; /*unit0*/
|
uniform sampler2D u_texture_y; /*unit0*/
|
||||||
uniform sampler2D u_texture_cb; /*unit1*/
|
uniform sampler2D u_texture_cb; /*unit1*/
|
||||||
uniform sampler2D u_texture_cr; /*unit2*/
|
uniform sampler2D u_texture_cr; /*unit2*/
|
||||||
uniform float u_gamma;
|
// uniform float u_gamma; /// set:2.2
|
||||||
|
|
||||||
|
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
|
@ -27,13 +27,11 @@ void main() {
|
||||||
dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);
|
dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);
|
||||||
*/
|
*/
|
||||||
// gamma correction
|
// gamma correction
|
||||||
texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));
|
// texel.rgb = pow(texel.rgb, vec3(u_gamma));
|
||||||
|
|
||||||
// saturation (algorithm from Chapter 16 of OpenGL Shading Language)
|
// saturation (algorithm from Chapter 16 of OpenGL Shading Language)
|
||||||
if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);
|
if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);
|
||||||
vec3 intensity = vec3(dot(texel.rgb, W));
|
vec3 intensity = vec3(dot(texel.rgb, W));
|
||||||
texel.rgb = mix(intensity, texel.rgb, saturation); }
|
texel.rgb = mix(intensity, texel.rgb, saturation); }
|
||||||
|
fragcolor = vec4(texel.rgb, 1.0);
|
||||||
|
|
||||||
fragcolor = vec4(texel.rgb, 1.0);
|
|
||||||
}
|
}
|
|
@ -702,8 +702,8 @@ void main(void)
|
||||||
float e = 0.14f;
|
float e = 0.14f;
|
||||||
color = clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
|
color = clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
|
||||||
// gamma correction
|
// gamma correction
|
||||||
color = pow( color, vec3(1. / 2.2) );
|
|
||||||
#endif
|
#endif
|
||||||
|
color = pow( color, vec3(1. / 2.2) );
|
||||||
|
|
||||||
// Technically this alpha may be too transparent, if there is a lot of reflected light we wouldn't
|
// Technically this alpha may be too transparent, if there is a lot of reflected light we wouldn't
|
||||||
// see the background, maybe we can approximate it well enough by adding a fresnel term
|
// see the background, maybe we can approximate it well enough by adding a fresnel term
|
||||||
|
|
|
@ -4,7 +4,6 @@ in float color_index;
|
||||||
uniform sampler2D sampler_font;
|
uniform sampler2D sampler_font;
|
||||||
uniform sampler1D sampler_colors;
|
uniform sampler1D sampler_colors;
|
||||||
uniform float num_colors;
|
uniform float num_colors;
|
||||||
uniform float u_gamma; /// set:2.2
|
|
||||||
|
|
||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
|
|
||||||
|
@ -12,5 +11,4 @@ void main() {
|
||||||
vec4 col = texture(sampler_colors, (color_index+0.5)/num_colors);
|
vec4 col = texture(sampler_colors, (color_index+0.5)/num_colors);
|
||||||
float s = texture(sampler_font, uv).r;
|
float s = texture(sampler_font, uv).r;
|
||||||
outColor = vec4(col.rgb, s*col.a);
|
outColor = vec4(col.rgb, s*col.a);
|
||||||
outColor.rgb = pow(outColor.rgb, vec3(u_gamma));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
void mainImage( out vec4 fragColor, in vec2 fragCoord );
|
void mainImage( out vec4 fragColor, in vec2 fragCoord );
|
||||||
void main() {
|
void main() {
|
||||||
mainImage(fragColor, texcoord.xy * iResolution);
|
mainImage(fragColor, texcoord.xy * iResolution);
|
||||||
fragColor.rgb = pow(fragColor.rgb, vec3(1.0/2.2));
|
|
||||||
}
|
}
|
|
@ -16,11 +16,10 @@ uniform sampler2D iChannel0; // input channel 0 /*sampler%s*/
|
||||||
uniform sampler2D iChannel1; // input channel 1
|
uniform sampler2D iChannel1; // input channel 1
|
||||||
uniform sampler2D iChannel2; // input channel 2
|
uniform sampler2D iChannel2; // input channel 2
|
||||||
uniform sampler2D iChannel3; // input channel 3
|
uniform sampler2D iChannel3; // input channel 3
|
||||||
uniform float iGamma; /// set:2.2
|
|
||||||
in vec2 texCoord;
|
in vec2 texCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
void mainImage( out vec4 fragColor, in vec2 fragCoord );
|
void mainImage( out vec4 fragColor, in vec2 fragCoord );
|
||||||
void main() {
|
void main() {
|
||||||
mainImage(fragColor, texCoord.xy);
|
mainImage(fragColor, texCoord.xy);
|
||||||
fragColor.rgb = pow(fragColor.rgb, vec3(iGamma));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17130,7 +17130,7 @@ enum TEXTURE_FLAGS {
|
||||||
TEXTURE_FLIP = IMAGE_FLIP,
|
TEXTURE_FLIP = IMAGE_FLIP,
|
||||||
|
|
||||||
// @fixme
|
// @fixme
|
||||||
TEXTURE_NO_SRGB = 1 << 24,
|
TEXTURE_SRGB = 1 << 24,
|
||||||
TEXTURE_BGR = 1 << 25,
|
TEXTURE_BGR = 1 << 25,
|
||||||
TEXTURE_BGRA = TEXTURE_BGR,
|
TEXTURE_BGRA = TEXTURE_BGR,
|
||||||
TEXTURE_ARRAY = 1 << 26,
|
TEXTURE_ARRAY = 1 << 26,
|
||||||
|
@ -17184,10 +17184,10 @@ API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb )
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// fullscreen quads
|
// fullscreen quads
|
||||||
|
|
||||||
API void fullscreen_quad_rgb( texture_t texture_rgb, float gamma );
|
API void fullscreen_quad_rgb( texture_t texture_rgb );
|
||||||
API void fullscreen_quad_rgb_flipped( texture_t texture, float gamma );
|
API void fullscreen_quad_rgb_flipped( texture_t texture );
|
||||||
API void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3], float gamma );
|
API void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3] );
|
||||||
API void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3], float gamma );
|
API void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3] );
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// cubemaps
|
// cubemaps
|
||||||
|
@ -18105,10 +18105,6 @@ API void ui_spine(spine_t *p);
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// atlas api
|
// atlas api
|
||||||
|
|
||||||
enum ATLAS_FLAGS {
|
|
||||||
ATLAS_SRGB = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct atlas_frame_t {
|
typedef struct atlas_frame_t {
|
||||||
unsigned delay;
|
unsigned delay;
|
||||||
vec4 sheet;
|
vec4 sheet;
|
||||||
|
@ -18250,7 +18246,7 @@ typedef struct skinned_t {
|
||||||
// - "_hover" (ex. "slider_cursor_hover")
|
// - "_hover" (ex. "slider_cursor_hover")
|
||||||
// - "_press"
|
// - "_press"
|
||||||
//
|
//
|
||||||
API guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
|
API guiskin_t gui_skinned(const char *asefile, float scale);
|
||||||
#line 0
|
#line 0
|
||||||
|
|
||||||
#line 1 "v4k_steam.h"
|
#line 1 "v4k_steam.h"
|
||||||
|
@ -363509,7 +363505,6 @@ void font_draw_cmd(font_t *f, const float *glyph_data, int glyph_idx, float fact
|
||||||
glUniform1f(glGetUniformLocation(f->program, "scale_factor"), factor);
|
glUniform1f(glGetUniformLocation(f->program, "scale_factor"), factor);
|
||||||
glUniform2fv(glGetUniformLocation(f->program, "string_offset"), 1, &offset.x);
|
glUniform2fv(glGetUniformLocation(f->program, "string_offset"), 1, &offset.x);
|
||||||
glUniform1f(glGetUniformLocation(f->program, "offset_firstline"), f->ascent*f->factor);
|
glUniform1f(glGetUniformLocation(f->program, "offset_firstline"), f->ascent*f->factor);
|
||||||
glUniform1f(glGetUniformLocation(f->program, "u_gamma"), (window_get_gamma() + !window_get_gamma()));
|
|
||||||
|
|
||||||
GLint dims[4] = {0};
|
GLint dims[4] = {0};
|
||||||
glGetIntegerv(GL_VIEWPORT, dims);
|
glGetIntegerv(GL_VIEWPORT, dims);
|
||||||
|
@ -364100,7 +364095,7 @@ API void gui_drawrect( texture_t spritesheet, vec2 tex_start, vec2 tex_end, int
|
||||||
|
|
||||||
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
|
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
|
||||||
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
|
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
|
||||||
float gamma = window_get_gamma();
|
float gamma = 1;
|
||||||
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
|
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/rect_2d.vs");
|
const char* vs = vfs_read("shaders/rect_2d.vs");
|
||||||
|
@ -364554,9 +364549,9 @@ void skinned_getscissorrect(void* userdata, const char *skin, const char *fallba
|
||||||
dims->w -= (skinsize.y - coresize.y);
|
dims->w -= (skinsize.y - coresize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb) {
|
guiskin_t gui_skinned(const char *asefile, float scale) {
|
||||||
skinned_t *a = REALLOC(0, sizeof(skinned_t));
|
skinned_t *a = REALLOC(0, sizeof(skinned_t));
|
||||||
a->atlas = atlas_create(asefile, load_as_srgb?ATLAS_SRGB:0);
|
a->atlas = atlas_create(asefile, 0);
|
||||||
a->scale = scale?scale:1.0f;
|
a->scale = scale?scale:1.0f;
|
||||||
guiskin_t skin={0};
|
guiskin_t skin={0};
|
||||||
skin.userdata = a;
|
skin.userdata = a;
|
||||||
|
@ -370575,7 +370570,12 @@ void shader_vec3(const char *uniform, vec3 v) { glUniform3fv(shader_uniform(un
|
||||||
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
|
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
|
||||||
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
|
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
|
||||||
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
|
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
|
||||||
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }
|
void shader_cubemap(const char *sampler, unsigned texture) {
|
||||||
|
int id = texture_unit();
|
||||||
|
glUniform1i(shader_uniform(sampler), id);
|
||||||
|
glActiveTexture(GL_TEXTURE0 + id);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
|
||||||
|
}
|
||||||
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
||||||
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
||||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
||||||
|
@ -370743,8 +370743,8 @@ unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const
|
||||||
|
|
||||||
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGB ) pixel_type = GL_BGR;
|
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGB ) pixel_type = GL_BGR;
|
||||||
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGBA ) pixel_type = GL_BGRA;
|
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGBA ) pixel_type = GL_BGRA;
|
||||||
if( !(flags & TEXTURE_NO_SRGB) ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
|
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
|
||||||
if( !(flags & TEXTURE_NO_SRGB) ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
|
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
|
||||||
|
|
||||||
if( flags & TEXTURE_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
if( flags & TEXTURE_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||||
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||||
|
@ -371345,7 +371345,7 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
|
||||||
// usage: bind empty vao & commit call for 6 (quad) or 3 vertices (tri).
|
// usage: bind empty vao & commit call for 6 (quad) or 3 vertices (tri).
|
||||||
// ie, glBindVertexArray(empty_vao); glDrawArrays(GL_TRIANGLES, 0, 3);
|
// ie, glBindVertexArray(empty_vao); glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
|
||||||
void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
void fullscreen_quad_rgb( texture_t texture ) {
|
||||||
static int program = -1, vao = -1, u_inv_gamma = -1;
|
static int program = -1, vao = -1, u_inv_gamma = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
||||||
|
@ -371359,7 +371359,8 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
||||||
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_inv_gamma, 1.0f / (gamma + !gamma) );
|
float gamma = 1;
|
||||||
|
glUniform1f( u_inv_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -371376,7 +371377,7 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
void fullscreen_quad_rgb_flipped( texture_t texture ) {
|
||||||
static int program = -1, vao = -1, u_inv_gamma = -1;
|
static int program = -1, vao = -1, u_inv_gamma = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
||||||
|
@ -371390,7 +371391,8 @@ void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
||||||
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_inv_gamma, 1.0f / (gamma + !gamma) );
|
float gamma = 1;
|
||||||
|
glUniform1f( u_inv_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -371407,7 +371409,7 @@ void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3] ) {
|
||||||
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
||||||
|
@ -371425,7 +371427,7 @@ void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
||||||
|
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_gamma, gamma );
|
// glUniform1f( u_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -371451,7 +371453,7 @@ void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3], float gamma ) {
|
void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3] ) {
|
||||||
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
||||||
|
@ -371469,7 +371471,7 @@ void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3], float gamma ) {
|
||||||
|
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_gamma, gamma );
|
// glUniform1f( u_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -371574,12 +371576,11 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
||||||
glGenTextures(1, &c.id);
|
glGenTextures(1, &c.id);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
|
||||||
|
|
||||||
float gammabg = window_get_gamma() + !window_get_gamma();
|
|
||||||
int samples = 0;
|
int samples = 0;
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||||
|
|
||||||
// calculate SH coefficients (@ands)
|
// calculate SH coefficients (@ands)
|
||||||
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
||||||
|
@ -371596,9 +371597,6 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
||||||
skyDir[i]); // texelDirection;
|
skyDir[i]); // texelDirection;
|
||||||
float l = len3(n);
|
float l = len3(n);
|
||||||
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
|
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
|
||||||
light.x = powf(light.x, gammabg);
|
|
||||||
light.y = powf(light.y, gammabg);
|
|
||||||
light.z = powf(light.z, gammabg);
|
|
||||||
n = norm3(n);
|
n = norm3(n);
|
||||||
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
|
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
|
||||||
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
|
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
|
||||||
|
@ -371890,8 +371888,6 @@ int skybox_push_state(skybox_t *sky, mat44 proj, mat44 view) {
|
||||||
shader_mat44("u_mvp", mvp);
|
shader_mat44("u_mvp", mvp);
|
||||||
if( sky->flags ) {
|
if( sky->flags ) {
|
||||||
shader_cubemap("u_cubemap", sky->cubemap.id);
|
shader_cubemap("u_cubemap", sky->cubemap.id);
|
||||||
} else {
|
|
||||||
shader_float("u_gamma", window_get_gamma() + !window_get_gamma());
|
|
||||||
}
|
}
|
||||||
return 0; // @fixme: return sortable hash here?
|
return 0; // @fixme: return sortable hash here?
|
||||||
}
|
}
|
||||||
|
@ -372149,6 +372145,9 @@ void viewport_clip(vec2 from, vec2 to) {
|
||||||
// fbos
|
// fbos
|
||||||
|
|
||||||
unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
||||||
|
int last_fb;
|
||||||
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb);
|
||||||
|
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
@ -372197,14 +372196,21 @@ unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glBindFramebuffer (GL_FRAMEBUFFER, 0);
|
glBindFramebuffer (GL_FRAMEBUFFER, last_fb);
|
||||||
return fbo;
|
return fbo;
|
||||||
}
|
}
|
||||||
|
static __thread array(handle) fbos;
|
||||||
void fbo_bind(unsigned id) {
|
void fbo_bind(unsigned id) {
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||||
|
array_push(fbos, id);
|
||||||
}
|
}
|
||||||
void fbo_unbind() {
|
void fbo_unbind() {
|
||||||
fbo_bind(0);
|
handle id = 0;
|
||||||
|
if (array_count(fbos)) {
|
||||||
|
array_pop(fbos);
|
||||||
|
id = *array_back(fbos);
|
||||||
|
}
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||||
}
|
}
|
||||||
void fbo_destroy(unsigned id) {
|
void fbo_destroy(unsigned id) {
|
||||||
// glDeleteRenderbuffers(1, &renderbuffer);
|
// glDeleteRenderbuffers(1, &renderbuffer);
|
||||||
|
@ -372383,20 +372389,13 @@ int ui_postfx(postfx *fx, int pass) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __thread array(handle) last_fb;
|
|
||||||
static postfx gamma_fx;
|
|
||||||
|
|
||||||
bool postfx_begin(postfx *fx, int width, int height) {
|
bool postfx_begin(postfx *fx, int width, int height) {
|
||||||
// reset clear color: needed in case transparent window is being used (alpha != 0)
|
// reset clear color: needed in case transparent window is being used (alpha != 0)
|
||||||
if (fx != &gamma_fx) glClearColor(0,0,0,0); // @transparent
|
glClearColor(0,0,0,0); // @transparent
|
||||||
|
|
||||||
width += !width;
|
width += !width;
|
||||||
height += !height;
|
height += !height;
|
||||||
|
|
||||||
int fb;
|
|
||||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
|
|
||||||
array_push(last_fb, fb);
|
|
||||||
|
|
||||||
// resize if needed
|
// resize if needed
|
||||||
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
|
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
|
||||||
texture_destroy(&fx->diffuse[0]);
|
texture_destroy(&fx->diffuse[0]);
|
||||||
|
@ -372420,20 +372419,18 @@ bool postfx_begin(postfx *fx, int width, int height) {
|
||||||
uint64_t num_active_passes = popcnt64(fx->mask);
|
uint64_t num_active_passes = popcnt64(fx->mask);
|
||||||
bool active = fx->enabled && num_active_passes;
|
bool active = fx->enabled && num_active_passes;
|
||||||
if( !active ) {
|
if( !active ) {
|
||||||
array_pop(last_fb);
|
|
||||||
fbo_bind(fb);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fbo_bind(fx->fb[1]);
|
fbo_bind(fx->fb[1]);
|
||||||
|
|
||||||
viewport_clear(true, true);
|
viewport_clear(true, true);
|
||||||
viewport_clip(vec2(0,0), vec2(width, height));
|
viewport_clip(vec2(0,0), vec2(width, height));
|
||||||
|
fbo_unbind();
|
||||||
|
|
||||||
fbo_bind(fx->fb[0]);
|
fbo_bind(fx->fb[0]);
|
||||||
|
|
||||||
viewport_clear(true, true);
|
viewport_clear(true, true);
|
||||||
viewport_clip(vec2(0,0), vec2(width, height));
|
viewport_clip(vec2(0,0), vec2(width, height));
|
||||||
|
// we keep fbo_0 bound so that user can render into it.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -372445,9 +372442,8 @@ bool postfx_end(postfx *fx) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle fb = *array_back(last_fb);
|
// unbind postfx fbo
|
||||||
array_pop(last_fb);
|
fbo_unbind();
|
||||||
fbo_bind(fb);
|
|
||||||
|
|
||||||
// disable depth test in 2d rendering
|
// disable depth test in 2d rendering
|
||||||
bool is_depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
|
bool is_depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
@ -372492,7 +372488,7 @@ bool postfx_end(postfx *fx) {
|
||||||
|
|
||||||
// bind the vao
|
// bind the vao
|
||||||
int bound = --num_active_passes;
|
int bound = --num_active_passes;
|
||||||
if( bound ) fbo_bind(fx->fb[frame ^= 1]);
|
if (bound) fbo_bind(fx->fb[frame ^= 1]);
|
||||||
|
|
||||||
// fullscreen quad
|
// fullscreen quad
|
||||||
glBindVertexArray(pass->m.vao);
|
glBindVertexArray(pass->m.vao);
|
||||||
|
@ -372501,10 +372497,10 @@ bool postfx_end(postfx *fx) {
|
||||||
profile_incstat("Render.num_triangles", +2);
|
profile_incstat("Render.num_triangles", +2);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
if( bound ) fbo_bind(fb);
|
if (bound) fbo_unbind();
|
||||||
else glUseProgram(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
if(is_depth_test_enabled);
|
if(is_depth_test_enabled);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
@ -372611,9 +372607,9 @@ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) {
|
||||||
FREE(cm->texture), cm->texture = NULL;
|
FREE(cm->texture), cm->texture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int srgb = !load_as_srgb ? TEXTURE_NO_SRGB : 0;
|
int srgb = load_as_srgb ? TEXTURE_SRGB : 0;
|
||||||
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0;
|
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT : 0;
|
||||||
texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
|
texture_t t = texture_compressed(texture_name, TEXTURE_RGBA | TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
|
||||||
|
|
||||||
if( t.id == texture_checker().id ) {
|
if( t.id == texture_checker().id ) {
|
||||||
cm->texture = NULL;
|
cm->texture = NULL;
|
||||||
|
@ -372652,7 +372648,6 @@ enum shadertoy_uniforms {
|
||||||
iSampleRate,
|
iSampleRate,
|
||||||
iChannelResolution,
|
iChannelResolution,
|
||||||
iChannelTime,
|
iChannelTime,
|
||||||
iGamma,
|
|
||||||
// iCameraScreen
|
// iCameraScreen
|
||||||
// iCameraPosition
|
// iCameraPosition
|
||||||
// iCameraActive
|
// iCameraActive
|
||||||
|
@ -372694,7 +372689,6 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
|
||||||
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
|
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
|
||||||
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
|
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
|
||||||
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
|
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
|
||||||
s.uniforms[iGamma] = glGetUniformLocation(s.program, "iGamma");
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -372722,7 +372716,6 @@ shadertoy_t* shadertoy_render(shadertoy_t *s, float delta) {
|
||||||
|
|
||||||
glUniform1i(s->uniforms[iFrame], (int)window_frame());
|
glUniform1i(s->uniforms[iFrame], (int)window_frame());
|
||||||
glUniform1f(s->uniforms[iTime], time_ss());
|
glUniform1f(s->uniforms[iTime], time_ss());
|
||||||
glUniform1f(s->uniforms[iGamma], window_get_gamma() + !window_get_gamma());
|
|
||||||
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
||||||
|
|
||||||
int unit = 0;
|
int unit = 0;
|
||||||
|
@ -374046,10 +374039,8 @@ static const char *dd_fs = "//" FILELINE "\n"
|
||||||
// "precision mediump float;\n"
|
// "precision mediump float;\n"
|
||||||
"in vec3 out_color;\n"
|
"in vec3 out_color;\n"
|
||||||
"out vec4 fragcolor;\n"
|
"out vec4 fragcolor;\n"
|
||||||
"uniform float u_gamma; /// set:2.2\n"
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" fragcolor = vec4(out_color, 1.0);\n"
|
" fragcolor = vec4(out_color, 1.0);\n"
|
||||||
" fragcolor.rgb = pow(fragcolor.rgb, vec3(u_gamma));\n"
|
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
#define X(x) RGBX(x,255)
|
#define X(x) RGBX(x,255)
|
||||||
|
@ -374109,7 +374100,6 @@ void ddraw_flush_projview(mat44 proj, mat44 view) {
|
||||||
|
|
||||||
glUseProgram(dd_program);
|
glUseProgram(dd_program);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(dd_program, "u_MVP"), 1, GL_FALSE, mvp);
|
glUniformMatrix4fv(glGetUniformLocation(dd_program, "u_MVP"), 1, GL_FALSE, mvp);
|
||||||
glUniform1f(glGetUniformLocation(dd_program, "u_gamma"), (window_get_gamma() + !window_get_gamma()));
|
|
||||||
|
|
||||||
static GLuint vao, vbo;
|
static GLuint vao, vbo;
|
||||||
if(!vao) glGenVertexArrays(1, &vao); glBindVertexArray(vao);
|
if(!vao) glGenVertexArrays(1, &vao); glBindVertexArray(vao);
|
||||||
|
@ -376956,7 +376946,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
||||||
else if( strend(k, "bitmap") ) {
|
else if( strend(k, "bitmap") ) {
|
||||||
const char *text = v;
|
const char *text = v;
|
||||||
array(char) bin = base64_decode(text, strlen(text));
|
array(char) bin = base64_decode(text, strlen(text));
|
||||||
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? 0 : TEXTURE_NO_SRGB);
|
a.tex = texture_from_mem(bin, array_count(bin), 0);
|
||||||
array_free(bin);
|
array_free(bin);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -377080,7 +377070,7 @@ void sprite_edit(sprite_t *s) {
|
||||||
|
|
||||||
sprite_t* sprite_new(const char *ase, int bindings[6]) {
|
sprite_t* sprite_new(const char *ase, int bindings[6]) {
|
||||||
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
|
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
|
||||||
atlas_t own = atlas_create(ase, ATLAS_SRGB);
|
atlas_t own = atlas_create(ase, 0);
|
||||||
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
|
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -379341,7 +379331,6 @@ static char title[128] = {0};
|
||||||
static char screenshot_file[DIR_MAX];
|
static char screenshot_file[DIR_MAX];
|
||||||
static int locked_aspect_ratio = 0;
|
static int locked_aspect_ratio = 0;
|
||||||
static vec4 winbgcolor = {0,0,0,1};
|
static vec4 winbgcolor = {0,0,0,1};
|
||||||
static float gamma = 2.2f;
|
|
||||||
|
|
||||||
vec4 window_getcolor_() { return winbgcolor; } // internal
|
vec4 window_getcolor_() { return winbgcolor; } // internal
|
||||||
|
|
||||||
|
@ -379498,13 +379487,7 @@ void glNewFrame() {
|
||||||
glViewport(0, 0, window_width(), window_height());
|
glViewport(0, 0, window_width(), window_height());
|
||||||
|
|
||||||
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
|
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
|
||||||
vec4 bgcolor = winbgcolor;
|
glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, window_has_transparent() ? 0 : winbgcolor.a); // @transparent
|
||||||
float gammabg = gamma + !gamma;
|
|
||||||
bgcolor.x = powf(bgcolor.x, gammabg);
|
|
||||||
bgcolor.y = powf(bgcolor.y, gammabg);
|
|
||||||
bgcolor.z = powf(bgcolor.z, gammabg);
|
|
||||||
bgcolor.w = powf(bgcolor.w, gammabg);
|
|
||||||
glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, window_has_transparent() ? 0 : bgcolor.a); // @transparent
|
|
||||||
//glClearColor(0.15,0.15,0.15,1);
|
//glClearColor(0.15,0.15,0.15,1);
|
||||||
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
|
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
||||||
|
@ -379818,10 +379801,6 @@ int window_frame_begin() {
|
||||||
void input_update();
|
void input_update();
|
||||||
input_update();
|
input_update();
|
||||||
|
|
||||||
if (gamma) {
|
|
||||||
postfx_begin(&gamma_fx, window_width(), window_height());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379839,10 +379818,6 @@ void window_frame_end() {
|
||||||
dd_ontop = 1;
|
dd_ontop = 1;
|
||||||
ddraw_flush();
|
ddraw_flush();
|
||||||
|
|
||||||
if (gamma) {
|
|
||||||
postfx_end(&gamma_fx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_render();
|
ui_render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380030,14 +380005,6 @@ void window_color(unsigned color) {
|
||||||
unsigned a = (color >> 24) & 255;
|
unsigned a = (color >> 24) & 255;
|
||||||
winbgcolor = vec4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
winbgcolor = vec4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
||||||
}
|
}
|
||||||
void window_gamma(float _gamma) {
|
|
||||||
gamma = _gamma;
|
|
||||||
shader_bind(gamma_fx.pass[postfx_find(&gamma_fx, "fxGamma.fs")].program);
|
|
||||||
shader_float("u_gamma", 1.0f / gamma);
|
|
||||||
}
|
|
||||||
float window_get_gamma() {
|
|
||||||
return gamma;
|
|
||||||
}
|
|
||||||
static int has_icon;
|
static int has_icon;
|
||||||
int window_has_icon() {
|
int window_has_icon() {
|
||||||
return has_icon;
|
return has_icon;
|
||||||
|
@ -382647,11 +382614,6 @@ static void v4k_post_init(float refresh_rate) {
|
||||||
|
|
||||||
hz = refresh_rate;
|
hz = refresh_rate;
|
||||||
// t = glfwGetTime();
|
// t = glfwGetTime();
|
||||||
do_once {
|
|
||||||
postfx_load_from_mem(&gamma_fx, "fxGamma.fs", vfs_read("fxGamma.fs"));
|
|
||||||
postfx_enable(&gamma_fx, 0, 1);
|
|
||||||
window_gamma(2.2f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -1957,7 +1957,6 @@ void font_draw_cmd(font_t *f, const float *glyph_data, int glyph_idx, float fact
|
||||||
glUniform1f(glGetUniformLocation(f->program, "scale_factor"), factor);
|
glUniform1f(glGetUniformLocation(f->program, "scale_factor"), factor);
|
||||||
glUniform2fv(glGetUniformLocation(f->program, "string_offset"), 1, &offset.x);
|
glUniform2fv(glGetUniformLocation(f->program, "string_offset"), 1, &offset.x);
|
||||||
glUniform1f(glGetUniformLocation(f->program, "offset_firstline"), f->ascent*f->factor);
|
glUniform1f(glGetUniformLocation(f->program, "offset_firstline"), f->ascent*f->factor);
|
||||||
glUniform1f(glGetUniformLocation(f->program, "u_gamma"), (window_get_gamma() + !window_get_gamma()));
|
|
||||||
|
|
||||||
GLint dims[4] = {0};
|
GLint dims[4] = {0};
|
||||||
glGetIntegerv(GL_VIEWPORT, dims);
|
glGetIntegerv(GL_VIEWPORT, dims);
|
||||||
|
|
|
@ -7,7 +7,7 @@ API void gui_drawrect( texture_t spritesheet, vec2 tex_start, vec2 tex_end, int
|
||||||
|
|
||||||
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
|
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
|
||||||
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
|
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
|
||||||
float gamma = window_get_gamma();
|
float gamma = 1;
|
||||||
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
|
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/rect_2d.vs");
|
const char* vs = vfs_read("shaders/rect_2d.vs");
|
||||||
|
@ -461,9 +461,9 @@ void skinned_getscissorrect(void* userdata, const char *skin, const char *fallba
|
||||||
dims->w -= (skinsize.y - coresize.y);
|
dims->w -= (skinsize.y - coresize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb) {
|
guiskin_t gui_skinned(const char *asefile, float scale) {
|
||||||
skinned_t *a = REALLOC(0, sizeof(skinned_t));
|
skinned_t *a = REALLOC(0, sizeof(skinned_t));
|
||||||
a->atlas = atlas_create(asefile, load_as_srgb?ATLAS_SRGB:0);
|
a->atlas = atlas_create(asefile, 0);
|
||||||
a->scale = scale?scale:1.0f;
|
a->scale = scale?scale:1.0f;
|
||||||
guiskin_t skin={0};
|
guiskin_t skin={0};
|
||||||
skin.userdata = a;
|
skin.userdata = a;
|
||||||
|
|
|
@ -62,4 +62,4 @@ typedef struct skinned_t {
|
||||||
// - "_hover" (ex. "slider_cursor_hover")
|
// - "_hover" (ex. "slider_cursor_hover")
|
||||||
// - "_press"
|
// - "_press"
|
||||||
//
|
//
|
||||||
API guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
|
API guiskin_t gui_skinned(const char *asefile, float scale);
|
||||||
|
|
|
@ -48,11 +48,6 @@ static void v4k_post_init(float refresh_rate) {
|
||||||
|
|
||||||
hz = refresh_rate;
|
hz = refresh_rate;
|
||||||
// t = glfwGetTime();
|
// t = glfwGetTime();
|
||||||
do_once {
|
|
||||||
postfx_load_from_mem(&gamma_fx, "fxGamma.fs", vfs_read("fxGamma.fs"));
|
|
||||||
postfx_enable(&gamma_fx, 0, 1);
|
|
||||||
window_gamma(2.2f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -552,7 +552,12 @@ void shader_vec3(const char *uniform, vec3 v) { glUniform3fv(shader_uniform(un
|
||||||
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
|
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
|
||||||
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
|
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
|
||||||
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
|
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
|
||||||
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }
|
void shader_cubemap(const char *sampler, unsigned texture) {
|
||||||
|
int id = texture_unit();
|
||||||
|
glUniform1i(shader_uniform(sampler), id);
|
||||||
|
glActiveTexture(GL_TEXTURE0 + id);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
|
||||||
|
}
|
||||||
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
||||||
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
||||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
||||||
|
@ -720,8 +725,8 @@ unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const
|
||||||
|
|
||||||
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGB ) pixel_type = GL_BGR;
|
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGB ) pixel_type = GL_BGR;
|
||||||
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGBA ) pixel_type = GL_BGRA;
|
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGBA ) pixel_type = GL_BGRA;
|
||||||
if( !(flags & TEXTURE_NO_SRGB) ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
|
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
|
||||||
if( !(flags & TEXTURE_NO_SRGB) ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
|
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
|
||||||
|
|
||||||
if( flags & TEXTURE_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
if( flags & TEXTURE_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||||
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||||
|
@ -1322,7 +1327,7 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
|
||||||
// usage: bind empty vao & commit call for 6 (quad) or 3 vertices (tri).
|
// usage: bind empty vao & commit call for 6 (quad) or 3 vertices (tri).
|
||||||
// ie, glBindVertexArray(empty_vao); glDrawArrays(GL_TRIANGLES, 0, 3);
|
// ie, glBindVertexArray(empty_vao); glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
|
||||||
void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
void fullscreen_quad_rgb( texture_t texture ) {
|
||||||
static int program = -1, vao = -1, u_inv_gamma = -1;
|
static int program = -1, vao = -1, u_inv_gamma = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
||||||
|
@ -1336,7 +1341,8 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
||||||
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_inv_gamma, 1.0f / (gamma + !gamma) );
|
float gamma = 1;
|
||||||
|
glUniform1f( u_inv_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -1353,7 +1359,7 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
void fullscreen_quad_rgb_flipped( texture_t texture ) {
|
||||||
static int program = -1, vao = -1, u_inv_gamma = -1;
|
static int program = -1, vao = -1, u_inv_gamma = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
||||||
|
@ -1367,7 +1373,8 @@ void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
||||||
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_inv_gamma, 1.0f / (gamma + !gamma) );
|
float gamma = 1;
|
||||||
|
glUniform1f( u_inv_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -1384,7 +1391,7 @@ void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3] ) {
|
||||||
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
||||||
|
@ -1402,7 +1409,7 @@ void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
||||||
|
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_gamma, gamma );
|
// glUniform1f( u_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -1428,7 +1435,7 @@ void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3], float gamma ) {
|
void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3] ) {
|
||||||
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
||||||
|
@ -1446,7 +1453,7 @@ void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3], float gamma ) {
|
||||||
|
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_gamma, gamma );
|
// glUniform1f( u_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -1551,12 +1558,11 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
||||||
glGenTextures(1, &c.id);
|
glGenTextures(1, &c.id);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
|
||||||
|
|
||||||
float gammabg = window_get_gamma() + !window_get_gamma();
|
|
||||||
int samples = 0;
|
int samples = 0;
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||||
|
|
||||||
// calculate SH coefficients (@ands)
|
// calculate SH coefficients (@ands)
|
||||||
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
||||||
|
@ -1573,9 +1579,6 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
||||||
skyDir[i]); // texelDirection;
|
skyDir[i]); // texelDirection;
|
||||||
float l = len3(n);
|
float l = len3(n);
|
||||||
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
|
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
|
||||||
light.x = powf(light.x, gammabg);
|
|
||||||
light.y = powf(light.y, gammabg);
|
|
||||||
light.z = powf(light.z, gammabg);
|
|
||||||
n = norm3(n);
|
n = norm3(n);
|
||||||
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
|
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
|
||||||
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
|
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
|
||||||
|
@ -1867,8 +1870,6 @@ int skybox_push_state(skybox_t *sky, mat44 proj, mat44 view) {
|
||||||
shader_mat44("u_mvp", mvp);
|
shader_mat44("u_mvp", mvp);
|
||||||
if( sky->flags ) {
|
if( sky->flags ) {
|
||||||
shader_cubemap("u_cubemap", sky->cubemap.id);
|
shader_cubemap("u_cubemap", sky->cubemap.id);
|
||||||
} else {
|
|
||||||
shader_float("u_gamma", window_get_gamma() + !window_get_gamma());
|
|
||||||
}
|
}
|
||||||
return 0; // @fixme: return sortable hash here?
|
return 0; // @fixme: return sortable hash here?
|
||||||
}
|
}
|
||||||
|
@ -2126,6 +2127,9 @@ void viewport_clip(vec2 from, vec2 to) {
|
||||||
// fbos
|
// fbos
|
||||||
|
|
||||||
unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
||||||
|
int last_fb;
|
||||||
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb);
|
||||||
|
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
@ -2174,14 +2178,21 @@ unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glBindFramebuffer (GL_FRAMEBUFFER, 0);
|
glBindFramebuffer (GL_FRAMEBUFFER, last_fb);
|
||||||
return fbo;
|
return fbo;
|
||||||
}
|
}
|
||||||
|
static __thread array(handle) fbos;
|
||||||
void fbo_bind(unsigned id) {
|
void fbo_bind(unsigned id) {
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||||
|
array_push(fbos, id);
|
||||||
}
|
}
|
||||||
void fbo_unbind() {
|
void fbo_unbind() {
|
||||||
fbo_bind(0);
|
handle id = 0;
|
||||||
|
if (array_count(fbos)) {
|
||||||
|
array_pop(fbos);
|
||||||
|
id = *array_back(fbos);
|
||||||
|
}
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||||
}
|
}
|
||||||
void fbo_destroy(unsigned id) {
|
void fbo_destroy(unsigned id) {
|
||||||
// glDeleteRenderbuffers(1, &renderbuffer);
|
// glDeleteRenderbuffers(1, &renderbuffer);
|
||||||
|
@ -2360,20 +2371,13 @@ int ui_postfx(postfx *fx, int pass) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __thread array(handle) last_fb;
|
|
||||||
static postfx gamma_fx;
|
|
||||||
|
|
||||||
bool postfx_begin(postfx *fx, int width, int height) {
|
bool postfx_begin(postfx *fx, int width, int height) {
|
||||||
// reset clear color: needed in case transparent window is being used (alpha != 0)
|
// reset clear color: needed in case transparent window is being used (alpha != 0)
|
||||||
if (fx != &gamma_fx) glClearColor(0,0,0,0); // @transparent
|
glClearColor(0,0,0,0); // @transparent
|
||||||
|
|
||||||
width += !width;
|
width += !width;
|
||||||
height += !height;
|
height += !height;
|
||||||
|
|
||||||
int fb;
|
|
||||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
|
|
||||||
array_push(last_fb, fb);
|
|
||||||
|
|
||||||
// resize if needed
|
// resize if needed
|
||||||
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
|
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
|
||||||
texture_destroy(&fx->diffuse[0]);
|
texture_destroy(&fx->diffuse[0]);
|
||||||
|
@ -2397,20 +2401,18 @@ bool postfx_begin(postfx *fx, int width, int height) {
|
||||||
uint64_t num_active_passes = popcnt64(fx->mask);
|
uint64_t num_active_passes = popcnt64(fx->mask);
|
||||||
bool active = fx->enabled && num_active_passes;
|
bool active = fx->enabled && num_active_passes;
|
||||||
if( !active ) {
|
if( !active ) {
|
||||||
array_pop(last_fb);
|
|
||||||
fbo_bind(fb);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fbo_bind(fx->fb[1]);
|
fbo_bind(fx->fb[1]);
|
||||||
|
|
||||||
viewport_clear(true, true);
|
viewport_clear(true, true);
|
||||||
viewport_clip(vec2(0,0), vec2(width, height));
|
viewport_clip(vec2(0,0), vec2(width, height));
|
||||||
|
fbo_unbind();
|
||||||
|
|
||||||
fbo_bind(fx->fb[0]);
|
fbo_bind(fx->fb[0]);
|
||||||
|
|
||||||
viewport_clear(true, true);
|
viewport_clear(true, true);
|
||||||
viewport_clip(vec2(0,0), vec2(width, height));
|
viewport_clip(vec2(0,0), vec2(width, height));
|
||||||
|
// we keep fbo_0 bound so that user can render into it.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2422,9 +2424,8 @@ bool postfx_end(postfx *fx) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle fb = *array_back(last_fb);
|
// unbind postfx fbo
|
||||||
array_pop(last_fb);
|
fbo_unbind();
|
||||||
fbo_bind(fb);
|
|
||||||
|
|
||||||
// disable depth test in 2d rendering
|
// disable depth test in 2d rendering
|
||||||
bool is_depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
|
bool is_depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
@ -2469,7 +2470,7 @@ bool postfx_end(postfx *fx) {
|
||||||
|
|
||||||
// bind the vao
|
// bind the vao
|
||||||
int bound = --num_active_passes;
|
int bound = --num_active_passes;
|
||||||
if( bound ) fbo_bind(fx->fb[frame ^= 1]);
|
if (bound) fbo_bind(fx->fb[frame ^= 1]);
|
||||||
|
|
||||||
// fullscreen quad
|
// fullscreen quad
|
||||||
glBindVertexArray(pass->m.vao);
|
glBindVertexArray(pass->m.vao);
|
||||||
|
@ -2478,10 +2479,10 @@ bool postfx_end(postfx *fx) {
|
||||||
profile_incstat("Render.num_triangles", +2);
|
profile_incstat("Render.num_triangles", +2);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
if( bound ) fbo_bind(fb);
|
if (bound) fbo_unbind();
|
||||||
else glUseProgram(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
if(is_depth_test_enabled);
|
if(is_depth_test_enabled);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
@ -2588,9 +2589,9 @@ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) {
|
||||||
FREE(cm->texture), cm->texture = NULL;
|
FREE(cm->texture), cm->texture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int srgb = !load_as_srgb ? TEXTURE_NO_SRGB : 0;
|
int srgb = load_as_srgb ? TEXTURE_SRGB : 0;
|
||||||
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0;
|
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT : 0;
|
||||||
texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
|
texture_t t = texture_compressed(texture_name, TEXTURE_RGBA | TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
|
||||||
|
|
||||||
if( t.id == texture_checker().id ) {
|
if( t.id == texture_checker().id ) {
|
||||||
cm->texture = NULL;
|
cm->texture = NULL;
|
||||||
|
@ -2629,7 +2630,6 @@ enum shadertoy_uniforms {
|
||||||
iSampleRate,
|
iSampleRate,
|
||||||
iChannelResolution,
|
iChannelResolution,
|
||||||
iChannelTime,
|
iChannelTime,
|
||||||
iGamma,
|
|
||||||
// iCameraScreen
|
// iCameraScreen
|
||||||
// iCameraPosition
|
// iCameraPosition
|
||||||
// iCameraActive
|
// iCameraActive
|
||||||
|
@ -2671,7 +2671,6 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
|
||||||
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
|
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
|
||||||
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
|
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
|
||||||
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
|
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
|
||||||
s.uniforms[iGamma] = glGetUniformLocation(s.program, "iGamma");
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -2699,7 +2698,6 @@ shadertoy_t* shadertoy_render(shadertoy_t *s, float delta) {
|
||||||
|
|
||||||
glUniform1i(s->uniforms[iFrame], (int)window_frame());
|
glUniform1i(s->uniforms[iFrame], (int)window_frame());
|
||||||
glUniform1f(s->uniforms[iTime], time_ss());
|
glUniform1f(s->uniforms[iTime], time_ss());
|
||||||
glUniform1f(s->uniforms[iGamma], window_get_gamma() + !window_get_gamma());
|
|
||||||
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
||||||
|
|
||||||
int unit = 0;
|
int unit = 0;
|
||||||
|
|
|
@ -108,7 +108,7 @@ enum TEXTURE_FLAGS {
|
||||||
TEXTURE_FLIP = IMAGE_FLIP,
|
TEXTURE_FLIP = IMAGE_FLIP,
|
||||||
|
|
||||||
// @fixme
|
// @fixme
|
||||||
TEXTURE_NO_SRGB = 1 << 24,
|
TEXTURE_SRGB = 1 << 24,
|
||||||
TEXTURE_BGR = 1 << 25,
|
TEXTURE_BGR = 1 << 25,
|
||||||
TEXTURE_BGRA = TEXTURE_BGR,
|
TEXTURE_BGRA = TEXTURE_BGR,
|
||||||
TEXTURE_ARRAY = 1 << 26,
|
TEXTURE_ARRAY = 1 << 26,
|
||||||
|
@ -162,10 +162,10 @@ API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb )
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// fullscreen quads
|
// fullscreen quads
|
||||||
|
|
||||||
API void fullscreen_quad_rgb( texture_t texture_rgb, float gamma );
|
API void fullscreen_quad_rgb( texture_t texture_rgb );
|
||||||
API void fullscreen_quad_rgb_flipped( texture_t texture, float gamma );
|
API void fullscreen_quad_rgb_flipped( texture_t texture );
|
||||||
API void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3], float gamma );
|
API void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3] );
|
||||||
API void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3], float gamma );
|
API void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3] );
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// cubemaps
|
// cubemaps
|
||||||
|
|
|
@ -13,10 +13,8 @@ static const char *dd_fs = "//" FILELINE "\n"
|
||||||
// "precision mediump float;\n"
|
// "precision mediump float;\n"
|
||||||
"in vec3 out_color;\n"
|
"in vec3 out_color;\n"
|
||||||
"out vec4 fragcolor;\n"
|
"out vec4 fragcolor;\n"
|
||||||
"uniform float u_gamma; /// set:2.2\n"
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" fragcolor = vec4(out_color, 1.0);\n"
|
" fragcolor = vec4(out_color, 1.0);\n"
|
||||||
" fragcolor.rgb = pow(fragcolor.rgb, vec3(u_gamma));\n"
|
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
#define X(x) RGBX(x,255)
|
#define X(x) RGBX(x,255)
|
||||||
|
@ -76,7 +74,6 @@ void ddraw_flush_projview(mat44 proj, mat44 view) {
|
||||||
|
|
||||||
glUseProgram(dd_program);
|
glUseProgram(dd_program);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(dd_program, "u_MVP"), 1, GL_FALSE, mvp);
|
glUniformMatrix4fv(glGetUniformLocation(dd_program, "u_MVP"), 1, GL_FALSE, mvp);
|
||||||
glUniform1f(glGetUniformLocation(dd_program, "u_gamma"), (window_get_gamma() + !window_get_gamma()));
|
|
||||||
|
|
||||||
static GLuint vao, vbo;
|
static GLuint vao, vbo;
|
||||||
if(!vao) glGenVertexArrays(1, &vao); glBindVertexArray(vao);
|
if(!vao) glGenVertexArrays(1, &vao); glBindVertexArray(vao);
|
||||||
|
|
|
@ -1363,7 +1363,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
||||||
else if( strend(k, "bitmap") ) {
|
else if( strend(k, "bitmap") ) {
|
||||||
const char *text = v;
|
const char *text = v;
|
||||||
array(char) bin = base64_decode(text, strlen(text));
|
array(char) bin = base64_decode(text, strlen(text));
|
||||||
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? 0 : TEXTURE_NO_SRGB);
|
a.tex = texture_from_mem(bin, array_count(bin), 0);
|
||||||
array_free(bin);
|
array_free(bin);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -1487,7 +1487,7 @@ void sprite_edit(sprite_t *s) {
|
||||||
|
|
||||||
sprite_t* sprite_new(const char *ase, int bindings[6]) {
|
sprite_t* sprite_new(const char *ase, int bindings[6]) {
|
||||||
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
|
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
|
||||||
atlas_t own = atlas_create(ase, ATLAS_SRGB);
|
atlas_t own = atlas_create(ase, 0);
|
||||||
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
|
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,10 +84,6 @@ API void ui_spine(spine_t *p);
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// atlas api
|
// atlas api
|
||||||
|
|
||||||
enum ATLAS_FLAGS {
|
|
||||||
ATLAS_SRGB = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct atlas_frame_t {
|
typedef struct atlas_frame_t {
|
||||||
unsigned delay;
|
unsigned delay;
|
||||||
vec4 sheet;
|
vec4 sheet;
|
||||||
|
|
|
@ -107,7 +107,6 @@ static char title[128] = {0};
|
||||||
static char screenshot_file[DIR_MAX];
|
static char screenshot_file[DIR_MAX];
|
||||||
static int locked_aspect_ratio = 0;
|
static int locked_aspect_ratio = 0;
|
||||||
static vec4 winbgcolor = {0,0,0,1};
|
static vec4 winbgcolor = {0,0,0,1};
|
||||||
static float gamma = 2.2f;
|
|
||||||
|
|
||||||
vec4 window_getcolor_() { return winbgcolor; } // internal
|
vec4 window_getcolor_() { return winbgcolor; } // internal
|
||||||
|
|
||||||
|
@ -264,13 +263,7 @@ void glNewFrame() {
|
||||||
glViewport(0, 0, window_width(), window_height());
|
glViewport(0, 0, window_width(), window_height());
|
||||||
|
|
||||||
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
|
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
|
||||||
vec4 bgcolor = winbgcolor;
|
glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, window_has_transparent() ? 0 : winbgcolor.a); // @transparent
|
||||||
float gammabg = gamma + !gamma;
|
|
||||||
bgcolor.x = powf(bgcolor.x, gammabg);
|
|
||||||
bgcolor.y = powf(bgcolor.y, gammabg);
|
|
||||||
bgcolor.z = powf(bgcolor.z, gammabg);
|
|
||||||
bgcolor.w = powf(bgcolor.w, gammabg);
|
|
||||||
glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, window_has_transparent() ? 0 : bgcolor.a); // @transparent
|
|
||||||
//glClearColor(0.15,0.15,0.15,1);
|
//glClearColor(0.15,0.15,0.15,1);
|
||||||
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
|
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
||||||
|
@ -584,10 +577,6 @@ int window_frame_begin() {
|
||||||
void input_update();
|
void input_update();
|
||||||
input_update();
|
input_update();
|
||||||
|
|
||||||
if (gamma) {
|
|
||||||
postfx_begin(&gamma_fx, window_width(), window_height());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,10 +594,6 @@ void window_frame_end() {
|
||||||
dd_ontop = 1;
|
dd_ontop = 1;
|
||||||
ddraw_flush();
|
ddraw_flush();
|
||||||
|
|
||||||
if (gamma) {
|
|
||||||
postfx_end(&gamma_fx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_render();
|
ui_render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,14 +781,6 @@ void window_color(unsigned color) {
|
||||||
unsigned a = (color >> 24) & 255;
|
unsigned a = (color >> 24) & 255;
|
||||||
winbgcolor = vec4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
winbgcolor = vec4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
||||||
}
|
}
|
||||||
void window_gamma(float _gamma) {
|
|
||||||
gamma = _gamma;
|
|
||||||
shader_bind(gamma_fx.pass[postfx_find(&gamma_fx, "fxGamma.fs")].program);
|
|
||||||
shader_float("u_gamma", 1.0f / gamma);
|
|
||||||
}
|
|
||||||
float window_get_gamma() {
|
|
||||||
return gamma;
|
|
||||||
}
|
|
||||||
static int has_icon;
|
static int has_icon;
|
||||||
int window_has_icon() {
|
int window_has_icon() {
|
||||||
return has_icon;
|
return has_icon;
|
||||||
|
|
130
engine/v4k.c
130
engine/v4k.c
|
@ -10659,7 +10659,6 @@ void font_draw_cmd(font_t *f, const float *glyph_data, int glyph_idx, float fact
|
||||||
glUniform1f(glGetUniformLocation(f->program, "scale_factor"), factor);
|
glUniform1f(glGetUniformLocation(f->program, "scale_factor"), factor);
|
||||||
glUniform2fv(glGetUniformLocation(f->program, "string_offset"), 1, &offset.x);
|
glUniform2fv(glGetUniformLocation(f->program, "string_offset"), 1, &offset.x);
|
||||||
glUniform1f(glGetUniformLocation(f->program, "offset_firstline"), f->ascent*f->factor);
|
glUniform1f(glGetUniformLocation(f->program, "offset_firstline"), f->ascent*f->factor);
|
||||||
glUniform1f(glGetUniformLocation(f->program, "u_gamma"), (window_get_gamma() + !window_get_gamma()));
|
|
||||||
|
|
||||||
GLint dims[4] = {0};
|
GLint dims[4] = {0};
|
||||||
glGetIntegerv(GL_VIEWPORT, dims);
|
glGetIntegerv(GL_VIEWPORT, dims);
|
||||||
|
@ -11250,7 +11249,7 @@ API void gui_drawrect( texture_t spritesheet, vec2 tex_start, vec2 tex_end, int
|
||||||
|
|
||||||
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
|
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
|
||||||
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
|
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
|
||||||
float gamma = window_get_gamma();
|
float gamma = 1;
|
||||||
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
|
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/rect_2d.vs");
|
const char* vs = vfs_read("shaders/rect_2d.vs");
|
||||||
|
@ -11704,9 +11703,9 @@ void skinned_getscissorrect(void* userdata, const char *skin, const char *fallba
|
||||||
dims->w -= (skinsize.y - coresize.y);
|
dims->w -= (skinsize.y - coresize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb) {
|
guiskin_t gui_skinned(const char *asefile, float scale) {
|
||||||
skinned_t *a = REALLOC(0, sizeof(skinned_t));
|
skinned_t *a = REALLOC(0, sizeof(skinned_t));
|
||||||
a->atlas = atlas_create(asefile, load_as_srgb?ATLAS_SRGB:0);
|
a->atlas = atlas_create(asefile, 0);
|
||||||
a->scale = scale?scale:1.0f;
|
a->scale = scale?scale:1.0f;
|
||||||
guiskin_t skin={0};
|
guiskin_t skin={0};
|
||||||
skin.userdata = a;
|
skin.userdata = a;
|
||||||
|
@ -17725,7 +17724,12 @@ void shader_vec3(const char *uniform, vec3 v) { glUniform3fv(shader_uniform(un
|
||||||
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
|
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
|
||||||
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
|
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
|
||||||
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
|
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
|
||||||
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }
|
void shader_cubemap(const char *sampler, unsigned texture) {
|
||||||
|
int id = texture_unit();
|
||||||
|
glUniform1i(shader_uniform(sampler), id);
|
||||||
|
glActiveTexture(GL_TEXTURE0 + id);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
|
||||||
|
}
|
||||||
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
||||||
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
||||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
||||||
|
@ -17893,8 +17897,8 @@ unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const
|
||||||
|
|
||||||
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGB ) pixel_type = GL_BGR;
|
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGB ) pixel_type = GL_BGR;
|
||||||
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGBA ) pixel_type = GL_BGRA;
|
if( flags & TEXTURE_BGR ) if( pixel_type == GL_RGBA ) pixel_type = GL_BGRA;
|
||||||
if( !(flags & TEXTURE_NO_SRGB) ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
|
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
|
||||||
if( !(flags & TEXTURE_NO_SRGB) ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
|
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
|
||||||
|
|
||||||
if( flags & TEXTURE_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
if( flags & TEXTURE_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||||
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||||
|
@ -18495,7 +18499,7 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
|
||||||
// usage: bind empty vao & commit call for 6 (quad) or 3 vertices (tri).
|
// usage: bind empty vao & commit call for 6 (quad) or 3 vertices (tri).
|
||||||
// ie, glBindVertexArray(empty_vao); glDrawArrays(GL_TRIANGLES, 0, 3);
|
// ie, glBindVertexArray(empty_vao); glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
|
||||||
void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
void fullscreen_quad_rgb( texture_t texture ) {
|
||||||
static int program = -1, vao = -1, u_inv_gamma = -1;
|
static int program = -1, vao = -1, u_inv_gamma = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
||||||
|
@ -18509,7 +18513,8 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
||||||
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_inv_gamma, 1.0f / (gamma + !gamma) );
|
float gamma = 1;
|
||||||
|
glUniform1f( u_inv_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -18526,7 +18531,7 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
void fullscreen_quad_rgb_flipped( texture_t texture ) {
|
||||||
static int program = -1, vao = -1, u_inv_gamma = -1;
|
static int program = -1, vao = -1, u_inv_gamma = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
||||||
|
@ -18540,7 +18545,8 @@ void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
||||||
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_inv_gamma, 1.0f / (gamma + !gamma) );
|
float gamma = 1;
|
||||||
|
glUniform1f( u_inv_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -18557,7 +18563,7 @@ void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3] ) {
|
||||||
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
|
||||||
|
@ -18575,7 +18581,7 @@ void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
||||||
|
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_gamma, gamma );
|
// glUniform1f( u_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -18601,7 +18607,7 @@ void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
|
||||||
// glDisable( GL_BLEND );
|
// glDisable( GL_BLEND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3], float gamma ) {
|
void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3] ) {
|
||||||
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
|
||||||
if( program < 0 ) {
|
if( program < 0 ) {
|
||||||
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
|
||||||
|
@ -18619,7 +18625,7 @@ void fullscreen_quad_ycbcr_flipped( texture_t textureYCbCr[3], float gamma ) {
|
||||||
|
|
||||||
// glEnable( GL_BLEND );
|
// glEnable( GL_BLEND );
|
||||||
glUseProgram( program );
|
glUseProgram( program );
|
||||||
glUniform1f( u_gamma, gamma );
|
// glUniform1f( u_gamma, gamma );
|
||||||
|
|
||||||
glBindVertexArray( vao );
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
|
@ -18724,12 +18730,11 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
||||||
glGenTextures(1, &c.id);
|
glGenTextures(1, &c.id);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
|
||||||
|
|
||||||
float gammabg = window_get_gamma() + !window_get_gamma();
|
|
||||||
int samples = 0;
|
int samples = 0;
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||||
|
|
||||||
// calculate SH coefficients (@ands)
|
// calculate SH coefficients (@ands)
|
||||||
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
||||||
|
@ -18746,9 +18751,6 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
||||||
skyDir[i]); // texelDirection;
|
skyDir[i]); // texelDirection;
|
||||||
float l = len3(n);
|
float l = len3(n);
|
||||||
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
|
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
|
||||||
light.x = powf(light.x, gammabg);
|
|
||||||
light.y = powf(light.y, gammabg);
|
|
||||||
light.z = powf(light.z, gammabg);
|
|
||||||
n = norm3(n);
|
n = norm3(n);
|
||||||
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
|
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
|
||||||
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
|
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
|
||||||
|
@ -19040,8 +19042,6 @@ int skybox_push_state(skybox_t *sky, mat44 proj, mat44 view) {
|
||||||
shader_mat44("u_mvp", mvp);
|
shader_mat44("u_mvp", mvp);
|
||||||
if( sky->flags ) {
|
if( sky->flags ) {
|
||||||
shader_cubemap("u_cubemap", sky->cubemap.id);
|
shader_cubemap("u_cubemap", sky->cubemap.id);
|
||||||
} else {
|
|
||||||
shader_float("u_gamma", window_get_gamma() + !window_get_gamma());
|
|
||||||
}
|
}
|
||||||
return 0; // @fixme: return sortable hash here?
|
return 0; // @fixme: return sortable hash here?
|
||||||
}
|
}
|
||||||
|
@ -19299,6 +19299,9 @@ void viewport_clip(vec2 from, vec2 to) {
|
||||||
// fbos
|
// fbos
|
||||||
|
|
||||||
unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
||||||
|
int last_fb;
|
||||||
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb);
|
||||||
|
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
@ -19347,14 +19350,21 @@ unsigned fbo(unsigned color_texture_id, unsigned depth_texture_id, int flags) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glBindFramebuffer (GL_FRAMEBUFFER, 0);
|
glBindFramebuffer (GL_FRAMEBUFFER, last_fb);
|
||||||
return fbo;
|
return fbo;
|
||||||
}
|
}
|
||||||
|
static __thread array(handle) fbos;
|
||||||
void fbo_bind(unsigned id) {
|
void fbo_bind(unsigned id) {
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||||
|
array_push(fbos, id);
|
||||||
}
|
}
|
||||||
void fbo_unbind() {
|
void fbo_unbind() {
|
||||||
fbo_bind(0);
|
handle id = 0;
|
||||||
|
if (array_count(fbos)) {
|
||||||
|
array_pop(fbos);
|
||||||
|
id = *array_back(fbos);
|
||||||
|
}
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||||
}
|
}
|
||||||
void fbo_destroy(unsigned id) {
|
void fbo_destroy(unsigned id) {
|
||||||
// glDeleteRenderbuffers(1, &renderbuffer);
|
// glDeleteRenderbuffers(1, &renderbuffer);
|
||||||
|
@ -19533,20 +19543,13 @@ int ui_postfx(postfx *fx, int pass) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __thread array(handle) last_fb;
|
|
||||||
static postfx gamma_fx;
|
|
||||||
|
|
||||||
bool postfx_begin(postfx *fx, int width, int height) {
|
bool postfx_begin(postfx *fx, int width, int height) {
|
||||||
// reset clear color: needed in case transparent window is being used (alpha != 0)
|
// reset clear color: needed in case transparent window is being used (alpha != 0)
|
||||||
if (fx != &gamma_fx) glClearColor(0,0,0,0); // @transparent
|
glClearColor(0,0,0,0); // @transparent
|
||||||
|
|
||||||
width += !width;
|
width += !width;
|
||||||
height += !height;
|
height += !height;
|
||||||
|
|
||||||
int fb;
|
|
||||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
|
|
||||||
array_push(last_fb, fb);
|
|
||||||
|
|
||||||
// resize if needed
|
// resize if needed
|
||||||
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
|
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
|
||||||
texture_destroy(&fx->diffuse[0]);
|
texture_destroy(&fx->diffuse[0]);
|
||||||
|
@ -19570,20 +19573,18 @@ bool postfx_begin(postfx *fx, int width, int height) {
|
||||||
uint64_t num_active_passes = popcnt64(fx->mask);
|
uint64_t num_active_passes = popcnt64(fx->mask);
|
||||||
bool active = fx->enabled && num_active_passes;
|
bool active = fx->enabled && num_active_passes;
|
||||||
if( !active ) {
|
if( !active ) {
|
||||||
array_pop(last_fb);
|
|
||||||
fbo_bind(fb);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fbo_bind(fx->fb[1]);
|
fbo_bind(fx->fb[1]);
|
||||||
|
|
||||||
viewport_clear(true, true);
|
viewport_clear(true, true);
|
||||||
viewport_clip(vec2(0,0), vec2(width, height));
|
viewport_clip(vec2(0,0), vec2(width, height));
|
||||||
|
fbo_unbind();
|
||||||
|
|
||||||
fbo_bind(fx->fb[0]);
|
fbo_bind(fx->fb[0]);
|
||||||
|
|
||||||
viewport_clear(true, true);
|
viewport_clear(true, true);
|
||||||
viewport_clip(vec2(0,0), vec2(width, height));
|
viewport_clip(vec2(0,0), vec2(width, height));
|
||||||
|
// we keep fbo_0 bound so that user can render into it.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -19595,9 +19596,8 @@ bool postfx_end(postfx *fx) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle fb = *array_back(last_fb);
|
// unbind postfx fbo
|
||||||
array_pop(last_fb);
|
fbo_unbind();
|
||||||
fbo_bind(fb);
|
|
||||||
|
|
||||||
// disable depth test in 2d rendering
|
// disable depth test in 2d rendering
|
||||||
bool is_depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
|
bool is_depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
@ -19642,7 +19642,7 @@ bool postfx_end(postfx *fx) {
|
||||||
|
|
||||||
// bind the vao
|
// bind the vao
|
||||||
int bound = --num_active_passes;
|
int bound = --num_active_passes;
|
||||||
if( bound ) fbo_bind(fx->fb[frame ^= 1]);
|
if (bound) fbo_bind(fx->fb[frame ^= 1]);
|
||||||
|
|
||||||
// fullscreen quad
|
// fullscreen quad
|
||||||
glBindVertexArray(pass->m.vao);
|
glBindVertexArray(pass->m.vao);
|
||||||
|
@ -19651,10 +19651,10 @@ bool postfx_end(postfx *fx) {
|
||||||
profile_incstat("Render.num_triangles", +2);
|
profile_incstat("Render.num_triangles", +2);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
if( bound ) fbo_bind(fb);
|
if (bound) fbo_unbind();
|
||||||
else glUseProgram(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
if(is_depth_test_enabled);
|
if(is_depth_test_enabled);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
@ -19761,9 +19761,9 @@ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) {
|
||||||
FREE(cm->texture), cm->texture = NULL;
|
FREE(cm->texture), cm->texture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int srgb = !load_as_srgb ? TEXTURE_NO_SRGB : 0;
|
int srgb = load_as_srgb ? TEXTURE_SRGB : 0;
|
||||||
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0;
|
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT : 0;
|
||||||
texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
|
texture_t t = texture_compressed(texture_name, TEXTURE_RGBA | TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
|
||||||
|
|
||||||
if( t.id == texture_checker().id ) {
|
if( t.id == texture_checker().id ) {
|
||||||
cm->texture = NULL;
|
cm->texture = NULL;
|
||||||
|
@ -19802,7 +19802,6 @@ enum shadertoy_uniforms {
|
||||||
iSampleRate,
|
iSampleRate,
|
||||||
iChannelResolution,
|
iChannelResolution,
|
||||||
iChannelTime,
|
iChannelTime,
|
||||||
iGamma,
|
|
||||||
// iCameraScreen
|
// iCameraScreen
|
||||||
// iCameraPosition
|
// iCameraPosition
|
||||||
// iCameraActive
|
// iCameraActive
|
||||||
|
@ -19844,7 +19843,6 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
|
||||||
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
|
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
|
||||||
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
|
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
|
||||||
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
|
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
|
||||||
s.uniforms[iGamma] = glGetUniformLocation(s.program, "iGamma");
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -19872,7 +19870,6 @@ shadertoy_t* shadertoy_render(shadertoy_t *s, float delta) {
|
||||||
|
|
||||||
glUniform1i(s->uniforms[iFrame], (int)window_frame());
|
glUniform1i(s->uniforms[iFrame], (int)window_frame());
|
||||||
glUniform1f(s->uniforms[iTime], time_ss());
|
glUniform1f(s->uniforms[iTime], time_ss());
|
||||||
glUniform1f(s->uniforms[iGamma], window_get_gamma() + !window_get_gamma());
|
|
||||||
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
||||||
|
|
||||||
int unit = 0;
|
int unit = 0;
|
||||||
|
@ -21196,10 +21193,8 @@ static const char *dd_fs = "//" FILELINE "\n"
|
||||||
// "precision mediump float;\n"
|
// "precision mediump float;\n"
|
||||||
"in vec3 out_color;\n"
|
"in vec3 out_color;\n"
|
||||||
"out vec4 fragcolor;\n"
|
"out vec4 fragcolor;\n"
|
||||||
"uniform float u_gamma; /// set:2.2\n"
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" fragcolor = vec4(out_color, 1.0);\n"
|
" fragcolor = vec4(out_color, 1.0);\n"
|
||||||
" fragcolor.rgb = pow(fragcolor.rgb, vec3(u_gamma));\n"
|
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
#define X(x) RGBX(x,255)
|
#define X(x) RGBX(x,255)
|
||||||
|
@ -21259,7 +21254,6 @@ void ddraw_flush_projview(mat44 proj, mat44 view) {
|
||||||
|
|
||||||
glUseProgram(dd_program);
|
glUseProgram(dd_program);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(dd_program, "u_MVP"), 1, GL_FALSE, mvp);
|
glUniformMatrix4fv(glGetUniformLocation(dd_program, "u_MVP"), 1, GL_FALSE, mvp);
|
||||||
glUniform1f(glGetUniformLocation(dd_program, "u_gamma"), (window_get_gamma() + !window_get_gamma()));
|
|
||||||
|
|
||||||
static GLuint vao, vbo;
|
static GLuint vao, vbo;
|
||||||
if(!vao) glGenVertexArrays(1, &vao); glBindVertexArray(vao);
|
if(!vao) glGenVertexArrays(1, &vao); glBindVertexArray(vao);
|
||||||
|
@ -24106,7 +24100,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
||||||
else if( strend(k, "bitmap") ) {
|
else if( strend(k, "bitmap") ) {
|
||||||
const char *text = v;
|
const char *text = v;
|
||||||
array(char) bin = base64_decode(text, strlen(text));
|
array(char) bin = base64_decode(text, strlen(text));
|
||||||
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? 0 : TEXTURE_NO_SRGB);
|
a.tex = texture_from_mem(bin, array_count(bin), 0);
|
||||||
array_free(bin);
|
array_free(bin);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -24230,7 +24224,7 @@ void sprite_edit(sprite_t *s) {
|
||||||
|
|
||||||
sprite_t* sprite_new(const char *ase, int bindings[6]) {
|
sprite_t* sprite_new(const char *ase, int bindings[6]) {
|
||||||
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
|
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
|
||||||
atlas_t own = atlas_create(ase, ATLAS_SRGB);
|
atlas_t own = atlas_create(ase, 0);
|
||||||
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
|
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -26491,7 +26485,6 @@ static char title[128] = {0};
|
||||||
static char screenshot_file[DIR_MAX];
|
static char screenshot_file[DIR_MAX];
|
||||||
static int locked_aspect_ratio = 0;
|
static int locked_aspect_ratio = 0;
|
||||||
static vec4 winbgcolor = {0,0,0,1};
|
static vec4 winbgcolor = {0,0,0,1};
|
||||||
static float gamma = 2.2f;
|
|
||||||
|
|
||||||
vec4 window_getcolor_() { return winbgcolor; } // internal
|
vec4 window_getcolor_() { return winbgcolor; } // internal
|
||||||
|
|
||||||
|
@ -26648,13 +26641,7 @@ void glNewFrame() {
|
||||||
glViewport(0, 0, window_width(), window_height());
|
glViewport(0, 0, window_width(), window_height());
|
||||||
|
|
||||||
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
|
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
|
||||||
vec4 bgcolor = winbgcolor;
|
glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, window_has_transparent() ? 0 : winbgcolor.a); // @transparent
|
||||||
float gammabg = gamma + !gamma;
|
|
||||||
bgcolor.x = powf(bgcolor.x, gammabg);
|
|
||||||
bgcolor.y = powf(bgcolor.y, gammabg);
|
|
||||||
bgcolor.z = powf(bgcolor.z, gammabg);
|
|
||||||
bgcolor.w = powf(bgcolor.w, gammabg);
|
|
||||||
glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, window_has_transparent() ? 0 : bgcolor.a); // @transparent
|
|
||||||
//glClearColor(0.15,0.15,0.15,1);
|
//glClearColor(0.15,0.15,0.15,1);
|
||||||
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
|
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
||||||
|
@ -26968,10 +26955,6 @@ int window_frame_begin() {
|
||||||
void input_update();
|
void input_update();
|
||||||
input_update();
|
input_update();
|
||||||
|
|
||||||
if (gamma) {
|
|
||||||
postfx_begin(&gamma_fx, window_width(), window_height());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26989,10 +26972,6 @@ void window_frame_end() {
|
||||||
dd_ontop = 1;
|
dd_ontop = 1;
|
||||||
ddraw_flush();
|
ddraw_flush();
|
||||||
|
|
||||||
if (gamma) {
|
|
||||||
postfx_end(&gamma_fx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_render();
|
ui_render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27180,14 +27159,6 @@ void window_color(unsigned color) {
|
||||||
unsigned a = (color >> 24) & 255;
|
unsigned a = (color >> 24) & 255;
|
||||||
winbgcolor = vec4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
winbgcolor = vec4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
||||||
}
|
}
|
||||||
void window_gamma(float _gamma) {
|
|
||||||
gamma = _gamma;
|
|
||||||
shader_bind(gamma_fx.pass[postfx_find(&gamma_fx, "fxGamma.fs")].program);
|
|
||||||
shader_float("u_gamma", 1.0f / gamma);
|
|
||||||
}
|
|
||||||
float window_get_gamma() {
|
|
||||||
return gamma;
|
|
||||||
}
|
|
||||||
static int has_icon;
|
static int has_icon;
|
||||||
int window_has_icon() {
|
int window_has_icon() {
|
||||||
return has_icon;
|
return has_icon;
|
||||||
|
@ -29797,11 +29768,6 @@ static void v4k_post_init(float refresh_rate) {
|
||||||
|
|
||||||
hz = refresh_rate;
|
hz = refresh_rate;
|
||||||
// t = glfwGetTime();
|
// t = glfwGetTime();
|
||||||
do_once {
|
|
||||||
postfx_load_from_mem(&gamma_fx, "fxGamma.fs", vfs_read("fxGamma.fs"));
|
|
||||||
postfx_enable(&gamma_fx, 0, 1);
|
|
||||||
window_gamma(2.2f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
16
engine/v4k.h
16
engine/v4k.h
|
@ -3197,7 +3197,7 @@ enum TEXTURE_FLAGS {
|
||||||
TEXTURE_FLIP = IMAGE_FLIP,
|
TEXTURE_FLIP = IMAGE_FLIP,
|
||||||
|
|
||||||
// @fixme
|
// @fixme
|
||||||
TEXTURE_NO_SRGB = 1 << 24,
|
TEXTURE_SRGB = 1 << 24,
|
||||||
TEXTURE_BGR = 1 << 25,
|
TEXTURE_BGR = 1 << 25,
|
||||||
TEXTURE_BGRA = TEXTURE_BGR,
|
TEXTURE_BGRA = TEXTURE_BGR,
|
||||||
TEXTURE_ARRAY = 1 << 26,
|
TEXTURE_ARRAY = 1 << 26,
|
||||||
|
@ -3251,10 +3251,10 @@ API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb )
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// fullscreen quads
|
// fullscreen quads
|
||||||
|
|
||||||
API void fullscreen_quad_rgb( texture_t texture_rgb, float gamma );
|
API void fullscreen_quad_rgb( texture_t texture_rgb );
|
||||||
API void fullscreen_quad_rgb_flipped( texture_t texture, float gamma );
|
API void fullscreen_quad_rgb_flipped( texture_t texture );
|
||||||
API void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3], float gamma );
|
API void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3] );
|
||||||
API void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3], float gamma );
|
API void fullscreen_quad_ycbcr_flipped( texture_t texture_YCbCr[3] );
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// cubemaps
|
// cubemaps
|
||||||
|
@ -4172,10 +4172,6 @@ API void ui_spine(spine_t *p);
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// atlas api
|
// atlas api
|
||||||
|
|
||||||
enum ATLAS_FLAGS {
|
|
||||||
ATLAS_SRGB = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct atlas_frame_t {
|
typedef struct atlas_frame_t {
|
||||||
unsigned delay;
|
unsigned delay;
|
||||||
vec4 sheet;
|
vec4 sheet;
|
||||||
|
@ -4317,7 +4313,7 @@ typedef struct skinned_t {
|
||||||
// - "_hover" (ex. "slider_cursor_hover")
|
// - "_hover" (ex. "slider_cursor_hover")
|
||||||
// - "_press"
|
// - "_press"
|
||||||
//
|
//
|
||||||
API guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
|
API guiskin_t gui_skinned(const char *asefile, float scale);
|
||||||
#line 0
|
#line 0
|
||||||
|
|
||||||
#line 1 "v4k_steam.h"
|
#line 1 "v4k_steam.h"
|
||||||
|
|
Loading…
Reference in New Issue