commit aae6df0a2f07950a4578884b40325986948e77bd parent 2afea6c75d063267d6c8b3ab0d345b40e2b0c05b Author: Michael Savage <mikejsavage@gmail.com> Date: Thu Aug 31 22:59:04 +0300 Really fix those warnings and more renderer cleanup Diffstat:
renderer.cc | | | 41 | +++++------------------------------------ |
renderer.h | | | 15 | ++++++--------- |
diff --git a/renderer.cc b/renderer.cc @@ -68,9 +68,9 @@ static bool in_frame; static bool in_pass; static UB uniforms; -static u32 ubo_offset_alignment; +static size_t ubo_offset_alignment; static u8 * uniforms_buffer; -static u32 uniforms_offset; +static size_t uniforms_offset; static RenderState previous_render_state; static u32 previous_viewport_width, previous_viewport_height; @@ -109,7 +109,7 @@ void renderer_init() { GLint alignment; glGetIntegerv( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment ); - ubo_offset_alignment = checked_cast< u32 >( alignment ); + ubo_offset_alignment = checked_cast< size_t >( alignment ); } void renderer_term() { @@ -199,14 +199,14 @@ void renderer_end_frame() { } } -UniformBinding renderer_ub_data( const void * data, u32 size, u32 alignment ) { +UniformBinding renderer_ub_data( const void * data, size_t size, size_t alignment ) { alignment = max( alignment, ubo_offset_alignment ); UniformBinding binding; binding.offset = align_power_of_2( uniforms_offset, alignment ); binding.size = size; - u32 new_uniforms_offset = binding.offset + binding.size; + size_t new_uniforms_offset = binding.offset + binding.size; ASSERT( new_uniforms_offset < UNIFORM_BUFFER_SIZE ); // memset so we don't leave any gaps. good for write combined memory! @@ -389,32 +389,6 @@ void renderer_delete_ib( IB ib ) { glDeleteBuffers( 1, &ib ); } -UB renderer_new_ub( const void * data, u32 len ) { - ASSERT( len < S32_MAX ); - - GLuint ubo; - glGenBuffers( 1, &ubo ); - - if( data != NULL ) { - glBindBuffer( GL_UNIFORM_BUFFER, ubo ); - glBufferData( GL_UNIFORM_BUFFER, len, data, GL_DYNAMIC_DRAW ); - } - - return ubo; -} - -void renderer_ub_data( UB ub, const void * data, u32 len ) { - ASSERT( len < S32_MAX ); - - glBindBuffer( GL_UNIFORM_BUFFER, ub ); - glBufferData( GL_UNIFORM_BUFFER, len, NULL, GL_DYNAMIC_DRAW ); - glBufferData( GL_UNIFORM_BUFFER, len, data, GL_DYNAMIC_DRAW ); -} - -void renderer_delete_ub( UB ub ) { - glDeleteBuffers( 1, &ub ); -} - TB renderer_new_tb( TextureFormat format, const void * data, u32 len, BufferUsage usage ) { ASSERT( len < S32_MAX ); ASSERT( !is_compressed( format ) ); @@ -853,11 +827,6 @@ static GLenum primitivetype_to_glenum( PrimitiveType primitive_type ) { return GL_INVALID_ENUM; } -void renderer_clear_fb( FB fb ) { - bind_fb( fb ); - glClear( fb.attachment == FB_COLOUR ? GL_COLOR_BUFFER_BIT : GL_DEPTH_BUFFER_BIT ); -} - static bool operator!=( UniformBinding a, UniformBinding b ) { return a.offset != b.offset || a.size != b.size; } diff --git a/renderer.h b/renderer.h @@ -197,6 +197,8 @@ void renderer_begin_pass( ClearColourBool clear_colour, ClearDepthBool clear_dep void renderer_end_pass(); void renderer_end_frame(); +UniformBinding renderer_ub_data( const void * data, size_t size, size_t alignment ); + // void renderer_begin_frame( ClearColourBool clear_colour = RENDERER_CLEAR_COLOUR_DO, ClearDepthBool clear_depth = RENDERER_CLEAR_DEPTH_DO ); // TODO: define render passes that have clear/undefined input framebuffers #define renderer_clear renderer_begin_frame @@ -207,11 +209,6 @@ void renderer_delete_vb( VB vb ); IB renderer_new_ib( const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_STATIC ); void renderer_delete_ib( IB ib ); -UB renderer_new_ub( const void * data = NULL, u32 len = 0 ); -void renderer_ub_data( UB ub, const void * data, u32 len ); -UniformBinding renderer_ub_data( const void * data, u32 size, u32 alignment ); -void renderer_delete_ub( UB ub ); - TB renderer_new_tb( TextureFormat format, const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); void renderer_tb_data( TB tb, const void * data, u32 len, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); void renderer_delete_tb( TB ub ); @@ -251,22 +248,22 @@ VB renderer_new_ib( const array< T > data, BufferUsage usage = BUFFERUSAGE_STATI */ template< typename T > -constexpr u32 renderer_ubo_alignment() { +constexpr size_t renderer_ubo_alignment() { return min( align4( sizeof( T ) ), 4 * sizeof( float ) ); } template<> -constexpr u32 renderer_ubo_alignment< v3 >() { +constexpr size_t renderer_ubo_alignment< v3 >() { return 4 * sizeof( float ); } template< typename T > -constexpr u32 renderer_ub_alignment() { +constexpr size_t renderer_ub_alignment() { return renderer_ubo_alignment< T >(); } template< typename S, typename T, typename... Rest > -constexpr u32 renderer_ub_alignment() { +constexpr size_t renderer_ub_alignment() { return max( renderer_ub_alignment< T, Rest... >(), renderer_ubo_alignment< S >() ); }