commit ffa0a0b157b2c1c377c2cc2d5c63911fc259ba27 parent 7a8d6595d0f08334bdfc23a3b65f143070275391 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Jul 2 21:49:14 +0300 Texture filter modes in the renderer Diffstat:
renderer.cc | | | 23 | +++++++++++++++++++++-- |
renderer.h | | | 12 | +++++++++--- |
diff --git a/renderer.cc b/renderer.cc @@ -103,6 +103,21 @@ static GLenum texturewrap_to_glenum( TextureWrapMode mode ) { return GL_INVALID_ENUM; } +static void texturefilter_to_glenum( TextureFilterMode mode, bool mipmaps, GLenum * min_filter, GLenum * mag_filter ) { + switch( mode ) { + case TEXFILTER_LINEAR: + *min_filter = mipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; + *mag_filter = GL_LINEAR; + return; + case TEXFILTER_POINT: + *min_filter = mipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST; + *mag_filter = GL_NEAREST; + return; + } + + FATAL( "unsupported TextureFilterMode: {}", mode ); +} + static bool is_compressed( TextureFormat format ) { return format == TEXFMT_BC1 || format == TEXFMT_BC3 || format == TEXFMT_BC4 || format == TEXFMT_BC5; @@ -399,15 +414,19 @@ static u32 texture_byte_size( u32 width, u32 height, TextureFormat format, bool Texture renderer_new_texture( TextureConfig config ) { ASSERT( config.format != TEXFMT_INVALID ); + ASSERT( !config.has_mipmaps ); // TODO GLuint texture; glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texturewrap_to_glenum( config.wrap ) ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texturewrap_to_glenum( config.wrap ) ); + GLenum min_filter, mag_filter; + texturefilter_to_glenum( config.filter, config.has_mipmaps, &min_filter, &mag_filter ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter ); + if( config.wrap == TEXWRAP_BORDER ) { glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, ( GLfloat * ) &config.border_colour ); } diff --git a/renderer.h b/renderer.h @@ -77,6 +77,11 @@ enum TextureWrapMode { TEXWRAP_BORDER, }; +enum TextureFilterMode { + TEXFILTER_LINEAR, + TEXFILTER_POINT, +}; + enum FramebufferAttachment { FB_COLOUR, FB_DEPTH, @@ -167,17 +172,18 @@ struct TextureConfig { TextureFormat format = TEXFMT_INVALID; TextureWrapMode wrap = TEXWRAP_REPEAT; - // TODO: min/mag filters, mipmaps + TextureFilterMode filter = TEXFILTER_LINEAR; + bool has_mipmaps = false; v4 border_colour; - bool srgb = false; + bool srgb = false; // TODO: this should be true by default. maybe needs enum TextureColorSpace too }; enum ClearColourBool { RENDERER_CLEAR_COLOUR_DONT, RENDERER_CLEAR_COLOUR_DO }; enum ClearDepthBool { RENDERER_CLEAR_DEPTH_DONT, RENDERER_CLEAR_DEPTH_DO }; void renderer_begin_frame( ClearColourBool clear_colour = RENDERER_CLEAR_COLOUR_DO, ClearDepthBool clear_depth = RENDERER_CLEAR_DEPTH_DO ); -// TODO +// TODO: define render passes that have clear/undefined input framebuffers #define renderer_clear renderer_begin_frame VB renderer_new_vb( const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_STATIC );