1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
3 static inline void vg_tex2d_mipmap(void)
5 glGenerateMipmap( GL_TEXTURE_2D
);
8 static inline void vg_tex2d_linear(void)
10 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
11 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
14 static inline void vg_tex2d_nearest(void)
16 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
17 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
20 static inline void vg_tex2d_linear_mipmap(void)
22 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
23 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
26 static inline void vg_tex2d_repeat(void)
28 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
29 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
32 static inline void vg_tex2d_clamp(void)
34 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
35 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
38 static GLuint
vg_tex2d_rgba( const char *path
)
41 stbi_set_flip_vertically_on_load( 0 );
44 u8
*src_data
= vg_asset_read_s( path
, &length
);
47 glGenTextures( 1, &texture_name
);
48 glBindTexture( GL_TEXTURE_2D
, texture_name
);
52 u8
*tex_buffer
= stbi_load_from_memory( src_data
, length
, &x
, &y
, &nc
, 4 );
53 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, x
, y
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, tex_buffer
);
68 vg_error( "Loading texture failed (%s)\n", path
);
69 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, tex_err
);