gfx: TEXTURE_NO_SRGB

main
Dominik Madarász 2024-03-26 21:14:42 +01:00
parent b8be40e489
commit fabbcc4aa7
15 changed files with 47 additions and 47 deletions

View File

@ -1076,7 +1076,7 @@ enum TEXTURE_FLAGS {
TEXTURE_RGB = IMAGE_RGB,
TEXTURE_RGBA = IMAGE_RGBA,
TEXTURE_FLIP = IMAGE_FLIP,
TEXTURE_SRGB = 1 << 24,
TEXTURE_NO_SRGB = 1 << 24,
TEXTURE_BGR = 1 << 25,
TEXTURE_BGRA = TEXTURE_BGR,
TEXTURE_ARRAY = 1 << 26,

View File

@ -9,7 +9,7 @@
void demo_kids(vec3 offs) {
// init
static texture_t kids; do_once kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR|TEXTURE_SRGB );
static texture_t kids; do_once kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR );
static vec3 pos[2] = {{490,362},{442,362}}, vel[2] = {0};
static int row[2] = {0,3}, frame[2] = {0};
static int inputs[2][4] = {{KEY_W,KEY_A,KEY_S,KEY_D},{KEY_UP,KEY_LEFT,KEY_DOWN,KEY_RIGHT}};
@ -39,7 +39,7 @@ void demo_kids(vec3 offs) {
void demo_hud() {
// draw pixel-art hud, 16x16 ui element, scaled and positioned in resolution-independant way
static texture_t inputs; do_once inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR|TEXTURE_SRGB );
static texture_t inputs; do_once inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR );
float spritesheet[3] = {17,34,24}, offset[2] = {0, - 2*absf(sin(window_time()*5))}; // sprite cell and animation
float scale[2] = {3, 3}, tile_w = 16 * scale[0], tile_h = 16 * scale[1]; // scaling
float position[3] = {window_width() - tile_w, window_height() - tile_h, window_height() }; // position in screen-coordinates (x,y,z-index)

View File

@ -32,8 +32,8 @@ int main() {
// load video, RGB texture, no audio
video_t *v = video( "pexels-pachon-in-motion-17486489.mp4", VIDEO_RGB | VIDEO_NO_AUDIO | VIDEO_LOOP ); video_seek(v, 30);
// load texture
texture_t t1 = texture("kgirl/g01_texture.png", TEXTURE_SRGB);
texture_t t2 = texture("matcaps/material3", TEXTURE_SRGB);
texture_t t1 = texture("kgirl/g01_texture.png", 0);
texture_t t2 = texture("matcaps/material3", 0);
// load model
model_t m1 = model("suzanne.obj", MODEL_NO_ANIMATIONS);
model_t m2 = model("suzanne.obj", MODEL_NO_ANIMATIONS|MODEL_MATCAPS);

View File

@ -51,7 +51,7 @@ int main() {
// manual spawn & loading
model_t m1 = model("kgirl/kgirls01.fbx", 0); //MODEL_NO_ANIMS);
texture_t t1 = texture("kgirl/g01_texture.png", TEXTURE_SRGB);
texture_t t1 = texture("kgirl/g01_texture.png", 0);
object_t* obj3 = scene_spawn();
object_model(obj3, m1);
object_diffuse(obj3, t1);

View File

@ -20,8 +20,8 @@ int main() {
// present decoded textures as a fullscreen composed quad
profile( "Video quad" ) {
if(is_rgb) fullscreen_quad_rgb( textures[0], 2.2f );
else fullscreen_quad_ycbcr( textures, 1.3f );
if(is_rgb) fullscreen_quad_rgb( textures[0], 1.0 );
else fullscreen_quad_ycbcr( textures, 1.0f/2.2f );
}
// input controls

View File

@ -335,7 +335,7 @@ bool SkyboxLoad( Skybox *s, const char **slots ) { // hdr,env,ibl
// Reflection map
if( reflectionPath ) {
if( (s->reflection = LoadTextureRGBA8( reflectionPath, TEXTURE_SRGB )) != NULL ) {
if( (s->reflection = LoadTextureRGBA8( reflectionPath, 0 )) != NULL ) {
glBindTexture( GL_TEXTURE_2D, s->reflection->id );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
@ -345,7 +345,7 @@ bool SkyboxLoad( Skybox *s, const char **slots ) { // hdr,env,ibl
// Irradiance map
if( envPath ) {
if( (s->env = LoadTextureRGBA8( envPath, TEXTURE_SRGB )) != NULL ) {
if( (s->env = LoadTextureRGBA8( envPath, 0 )) != NULL ) {
glBindTexture( GL_TEXTURE_2D, s->env->id );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );

View File

@ -150,10 +150,10 @@ int main(int argc, char **argv) {
if(do_cats) NUM_SPRITES/=2; // cat-sprite+cat-shadow == 2 sprites
// load sprites and sheets
kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR|TEXTURE_SRGB );
catImage = texture( "cat.png", TEXTURE_LINEAR|TEXTURE_SRGB ); //
shadowImage = texture( "cat-shadow.png", TEXTURE_LINEAR|TEXTURE_SRGB );
inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR|TEXTURE_SRGB );
kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR );
catImage = texture( "cat.png", TEXTURE_LINEAR ); //
shadowImage = texture( "cat-shadow.png", TEXTURE_LINEAR );
inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR );
// load all fx files, including subdirs
fx_load("fx**.fs");

View File

@ -17130,7 +17130,7 @@ enum TEXTURE_FLAGS {
TEXTURE_FLIP = IMAGE_FLIP,
// @fixme
TEXTURE_SRGB = 1 << 24,
TEXTURE_NO_SRGB = 1 << 24,
TEXTURE_BGR = 1 << 25,
TEXTURE_BGRA = TEXTURE_BGR,
TEXTURE_ARRAY = 1 << 26,
@ -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_RGBA ) pixel_type = GL_BGRA;
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
if( !(flags & TEXTURE_NO_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_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
@ -371749,10 +371749,10 @@ skybox_t skybox_pbr(const char *sky_map, const char *refl_map, const char *env_m
}
}
if( refl_map ) {
sky.refl = load_env_tex(refl_map, TEXTURE_SRGB);
sky.refl = load_env_tex(refl_map, 0);
}
if( env_map ) {
sky.env = load_env_tex(env_map, TEXTURE_SRGB);
sky.env = load_env_tex(env_map, 0);
}
return sky;
@ -372584,7 +372584,7 @@ static void brdf_load() {
filename = "Skyboxes/brdf_lut2k_512x512_32F.ktx";
brdf = texture_compressed( filename,
TEXTURE_CLAMP | TEXTURE_NEAREST | TEXTURE_RG | TEXTURE_FLOAT | TEXTURE_SRGB
TEXTURE_CLAMP | TEXTURE_NEAREST | TEXTURE_RG | TEXTURE_FLOAT
);
unsigned texchecker = texture_checker().id;
ASSERT(brdf.id != texchecker, "!Couldn't load BRDF lookup table '%s'!", filename );
@ -372606,7 +372606,7 @@ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) {
FREE(cm->texture), cm->texture = NULL;
}
int srgb = load_as_srgb ? TEXTURE_SRGB : 0;
int srgb = !load_as_srgb ? TEXTURE_NO_SRGB : 0;
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0;
texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
@ -373345,7 +373345,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model,
if( reused ) continue;
// decode texture+material
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY|TEXTURE_SRGB; // LINEAR, NEAREST
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY; // LINEAR, NEAREST
if (!(_flags & MODEL_NO_FILTERING))
flags |= TEXTURE_LINEAR;
int invalid = texture_checker().id;
@ -375427,7 +375427,7 @@ int scene_merge(const char *source) {
//char *a = archive_read(animation_file);
object_t *o = scene_spawn();
object_model(o, m);
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), TEXTURE_SRGB|(opt_flip_uv ? IMAGE_FLIP : 0)) );
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), (opt_flip_uv ? IMAGE_FLIP : 0)) );
object_scale(o, scale);
object_teleport(o, position);
object_pivot(o, rotation); // object_rotate(o, rotation);
@ -376948,7 +376948,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
else if( strend(k, "bitmap") ) {
const char *text = v;
array(char) bin = base64_decode(text, strlen(text));
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? TEXTURE_SRGB : 0);
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? 0 : TEXTURE_NO_SRGB);
array_free(bin);
}
#if 0
@ -379068,7 +379068,7 @@ video_t* video( const char *filename, int flags ) {
} else {
int w16 = (w+15) & ~15;
int h16 = (h+15) & ~15;
v->texture = texture_create( w16, h16, 3, NULL, TEXTURE_SRGB );
v->texture = texture_create( w16, h16, 3, NULL, 0 );
v->surface = REALLOC( v->surface, w16 * h16 * 3 );
}

View File

@ -720,8 +720,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_RGBA ) pixel_type = GL_BGRA;
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
if( !(flags & TEXTURE_NO_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_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
@ -1726,10 +1726,10 @@ skybox_t skybox_pbr(const char *sky_map, const char *refl_map, const char *env_m
}
}
if( refl_map ) {
sky.refl = load_env_tex(refl_map, TEXTURE_SRGB);
sky.refl = load_env_tex(refl_map, 0);
}
if( env_map ) {
sky.env = load_env_tex(env_map, TEXTURE_SRGB);
sky.env = load_env_tex(env_map, 0);
}
return sky;
@ -2561,7 +2561,7 @@ static void brdf_load() {
filename = "Skyboxes/brdf_lut2k_512x512_32F.ktx";
brdf = texture_compressed( filename,
TEXTURE_CLAMP | TEXTURE_NEAREST | TEXTURE_RG | TEXTURE_FLOAT | TEXTURE_SRGB
TEXTURE_CLAMP | TEXTURE_NEAREST | TEXTURE_RG | TEXTURE_FLOAT
);
unsigned texchecker = texture_checker().id;
ASSERT(brdf.id != texchecker, "!Couldn't load BRDF lookup table '%s'!", filename );
@ -2583,7 +2583,7 @@ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) {
FREE(cm->texture), cm->texture = NULL;
}
int srgb = load_as_srgb ? TEXTURE_SRGB : 0;
int srgb = !load_as_srgb ? TEXTURE_NO_SRGB : 0;
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0;
texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
@ -3322,7 +3322,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model,
if( reused ) continue;
// decode texture+material
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY|TEXTURE_SRGB; // LINEAR, NEAREST
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY; // LINEAR, NEAREST
if (!(_flags & MODEL_NO_FILTERING))
flags |= TEXTURE_LINEAR;
int invalid = texture_checker().id;

View File

@ -108,7 +108,7 @@ enum TEXTURE_FLAGS {
TEXTURE_FLIP = IMAGE_FLIP,
// @fixme
TEXTURE_SRGB = 1 << 24,
TEXTURE_NO_SRGB = 1 << 24,
TEXTURE_BGR = 1 << 25,
TEXTURE_BGRA = TEXTURE_BGR,
TEXTURE_ARRAY = 1 << 26,

View File

@ -440,7 +440,7 @@ int scene_merge(const char *source) {
//char *a = archive_read(animation_file);
object_t *o = scene_spawn();
object_model(o, m);
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), TEXTURE_SRGB|(opt_flip_uv ? IMAGE_FLIP : 0)) );
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), (opt_flip_uv ? IMAGE_FLIP : 0)) );
object_scale(o, scale);
object_teleport(o, position);
object_pivot(o, rotation); // object_rotate(o, rotation);

View File

@ -1363,7 +1363,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
else if( strend(k, "bitmap") ) {
const char *text = v;
array(char) bin = base64_decode(text, strlen(text));
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? TEXTURE_SRGB : 0);
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? 0 : TEXTURE_NO_SRGB);
array_free(bin);
}
#if 0

View File

@ -74,7 +74,7 @@ video_t* video( const char *filename, int flags ) {
} else {
int w16 = (w+15) & ~15;
int h16 = (h+15) & ~15;
v->texture = texture_create( w16, h16, 3, NULL, TEXTURE_SRGB );
v->texture = texture_create( w16, h16, 3, NULL, 0 );
v->surface = REALLOC( v->surface, w16 * h16 * 3 );
}

View File

@ -17893,8 +17893,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_RGBA ) pixel_type = GL_BGRA;
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGB ) texel_type = GL_SRGB;
if( flags & TEXTURE_SRGB ) if( texel_type == GL_RGBA ) texel_type = GL_SRGB_ALPHA; // GL_SRGB8_ALPHA8 ?
if( !(flags & TEXTURE_NO_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_BC1 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
if( flags & TEXTURE_BC2 ) texel_type = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
@ -18899,10 +18899,10 @@ skybox_t skybox_pbr(const char *sky_map, const char *refl_map, const char *env_m
}
}
if( refl_map ) {
sky.refl = load_env_tex(refl_map, TEXTURE_SRGB);
sky.refl = load_env_tex(refl_map, 0);
}
if( env_map ) {
sky.env = load_env_tex(env_map, TEXTURE_SRGB);
sky.env = load_env_tex(env_map, 0);
}
return sky;
@ -19734,7 +19734,7 @@ static void brdf_load() {
filename = "Skyboxes/brdf_lut2k_512x512_32F.ktx";
brdf = texture_compressed( filename,
TEXTURE_CLAMP | TEXTURE_NEAREST | TEXTURE_RG | TEXTURE_FLOAT | TEXTURE_SRGB
TEXTURE_CLAMP | TEXTURE_NEAREST | TEXTURE_RG | TEXTURE_FLOAT
);
unsigned texchecker = texture_checker().id;
ASSERT(brdf.id != texchecker, "!Couldn't load BRDF lookup table '%s'!", filename );
@ -19756,7 +19756,7 @@ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) {
FREE(cm->texture), cm->texture = NULL;
}
int srgb = load_as_srgb ? TEXTURE_SRGB : 0;
int srgb = !load_as_srgb ? TEXTURE_NO_SRGB : 0;
int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0;
texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb);
@ -20495,7 +20495,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model,
if( reused ) continue;
// decode texture+material
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY|TEXTURE_SRGB; // LINEAR, NEAREST
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY; // LINEAR, NEAREST
if (!(_flags & MODEL_NO_FILTERING))
flags |= TEXTURE_LINEAR;
int invalid = texture_checker().id;
@ -22577,7 +22577,7 @@ int scene_merge(const char *source) {
//char *a = archive_read(animation_file);
object_t *o = scene_spawn();
object_model(o, m);
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), TEXTURE_SRGB|(opt_flip_uv ? IMAGE_FLIP : 0)) );
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), (opt_flip_uv ? IMAGE_FLIP : 0)) );
object_scale(o, scale);
object_teleport(o, position);
object_pivot(o, rotation); // object_rotate(o, rotation);
@ -24098,7 +24098,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
else if( strend(k, "bitmap") ) {
const char *text = v;
array(char) bin = base64_decode(text, strlen(text));
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? TEXTURE_SRGB : 0);
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? 0 : TEXTURE_NO_SRGB);
array_free(bin);
}
#if 0
@ -26218,7 +26218,7 @@ video_t* video( const char *filename, int flags ) {
} else {
int w16 = (w+15) & ~15;
int h16 = (h+15) & ~15;
v->texture = texture_create( w16, h16, 3, NULL, TEXTURE_SRGB );
v->texture = texture_create( w16, h16, 3, NULL, 0 );
v->surface = REALLOC( v->surface, w16 * h16 * 3 );
}

View File

@ -3197,7 +3197,7 @@ enum TEXTURE_FLAGS {
TEXTURE_FLIP = IMAGE_FLIP,
// @fixme
TEXTURE_SRGB = 1 << 24,
TEXTURE_NO_SRGB = 1 << 24,
TEXTURE_BGR = 1 << 25,
TEXTURE_BGRA = TEXTURE_BGR,
TEXTURE_ARRAY = 1 << 26,