Changeset 492 for trunk/src/gl
- Timestamp:
- 05/05/16 19:37:28 (9 years ago)
- Location:
- trunk/src/gl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_context.cc
r491 r492 74 74 } 75 75 76 for ( uint32 i = 0; i < info->count; ++i )77 {78 glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );79 }76 // for ( uint32 i = 0; i < info->count; ++i ) 77 // { 78 // glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) ); 79 // } 80 80 81 81 … … 83 83 } 84 84 85 nv::framebuffer nv::gl_context::create_framebuffer( )85 nv::framebuffer nv::gl_context::create_framebuffer( uint32 temp_samples ) 86 86 { 87 87 unsigned glid = 0; … … 92 92 info->depth_rb_glid = 0; 93 93 info->color_attachment_count = 0; 94 info->sample_count = temp_samples; 94 95 return result; 95 96 } … … 192 193 glGenRenderbuffers( 1, &(info->depth_rb_glid) ); 193 194 glBindRenderbuffer( GL_RENDERBUFFER, info->depth_rb_glid ); 194 glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.x, size.y ); 195 if ( info->sample_count > 1 ) 196 glRenderbufferStorageMultisample( GL_RENDERBUFFER, info->sample_count, GL_DEPTH_COMPONENT16, size.x, size.y ); 197 else 198 glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.x, size.y ); 195 199 glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, info->depth_rb_glid ); 196 200 glBindRenderbuffer( GL_RENDERBUFFER, 0 ); … … 211 215 212 216 217 void nv::gl_context::blit( framebuffer from, framebuffer to, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 ) 218 { 219 gl_framebuffer_info* finfo = m_framebuffers.get( from ); 220 gl_framebuffer_info* tinfo = m_framebuffers.get( to ); 221 if ( finfo ) 222 { 223 glBindFramebuffer( GL_READ_FRAMEBUFFER, finfo->glid ); 224 glBindFramebuffer( GL_DRAW_FRAMEBUFFER, tinfo ? tinfo->glid : 0 ); 225 unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST; 226 int remove_below; 227 filter = GL_NEAREST; 228 glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter ); 229 glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); 230 if ( tinfo ) glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); 231 } 232 } 233 213 234 bool nv::gl_context::check( framebuffer_slot ft ) 214 235 { … … 220 241 switch ( result ) 221 242 { 243 case GL_FRAMEBUFFER_UNDEFINED : NV_LOG_ERROR( "gl_context::check : Framebuffer undefined!" ); break; 244 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE : NV_LOG_ERROR( "gl_context::check : Incomplete multisample!" ); break; 245 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS : NV_LOG_ERROR( "gl_context::check : Incomplete layer targets!" ); break; 222 246 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete attachment!" ); break; 223 247 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer missing attachment!" ); break; … … 255 279 { 256 280 NV_ASSERT_ALWAYS( binfo->type == TEXTURE_BUFFER && tinfo->type == TEXTURE_1D_BUFFER, "bad texture or buffer type!" ); 257 glActiveTexture( GL_TEXTURE0 ); 258 glBindTexture( GL_TEXTURE_BUFFER, tinfo->glid ); 281 bind( t, TEXTURE_0 ); 259 282 glTexBuffer( GL_TEXTURE_BUFFER, image_format_to_internal_enum( tinfo->format.format ), binfo->glid ); 260 glBindTexture( GL_TEXTURE_BUFFER, 0 );261 283 } 262 284 } … … 276 298 void gl_context::bind( texture t, texture_slot slot ) 277 299 { 278 const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) ); 279 if ( info ) 280 { 281 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) ); 282 glBindTexture( texture_type_to_enum( info->type ), info->glid ); 300 if ( m_bound_textures[ slot ] != t ) 301 { 302 const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) ); 303 if ( info ) 304 { 305 set_active_texture( slot ); 306 glBindTexture( texture_type_to_enum( info->type ), info->glid ); 307 } 283 308 } 284 309 } … … 318 343 } 319 344 345 void nv::gl_context::set_active_texture( texture_slot slot ) 346 { 347 if ( slot != m_active_slot ) 348 glActiveTexture( GL_TEXTURE0 + static_cast<GLenum>( slot ) ); 349 } 350 320 351 // void nv::gl_context::unbind( buffer b ) 321 352 // { … … 352 383 const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) ); 353 384 NV_ASSERT_ALWAYS( info->type != TEXTURE_1D_BUFFER, "Buffer texture passed to update!" ); 385 NV_ASSERT_ALWAYS( info->type != TEXTURE_2D_MULTISAMPLE, "Multisample texture passed to update!" ); 354 386 if ( info ) 355 387 { … … 358 390 unsigned gl_type = texture_type_to_enum( info->type ); 359 391 360 glBindTexture( gl_type, info->glid ); 392 if ( m_bound_textures[ m_active_slot ] != t ) 393 glBindTexture( gl_type, info->glid ); 361 394 int this_should_be_subTexImage; 362 395 if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY ) … … 543 576 glDepthMask( mask ); 544 577 m_render_state.depth_mask = mask; 578 } 579 } 580 581 void gl_context::apply_multisample( bool multisample ) 582 { 583 if ( m_render_state.multisample != multisample ) 584 { 585 glDepthMask( multisample ); 586 m_render_state.multisample = multisample; 545 587 } 546 588 } … … 727 769 apply_color_mask( state.color_mask ); 728 770 apply_depth_mask( state.depth_mask ); 771 apply_multisample( state.multisample ); 729 772 apply_polygon_mode( state.polygon_mode ); 730 773 } … … 736 779 // TODO: configurable: 737 780 // load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY ); 781 m_active_slot = texture_slot( -1 ); 738 782 force_apply_render_state( m_render_state ); 739 783 } -
trunk/src/gl/gl_device.cc
r491 r492 98 98 unsigned glid = 0; 99 99 unsigned gl_type = texture_type_to_enum( type ); 100 GL int gl_internal = GLint( nv::image_format_to_internal_enum( aformat.format ) );100 GLenum gl_internal = GLenum( nv::image_format_to_internal_enum( aformat.format ) ); 101 101 unsigned gl_enum = nv::image_format_to_enum( aformat.format ); 102 102 … … 119 119 } 120 120 121 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) ); 122 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) ); 121 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE ) 122 { 123 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) ); 124 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) ); 125 } 123 126 124 if ( gl_ enum != GL_RED_INTEGER )127 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE && gl_enum != GL_RED_INTEGER ) 125 128 { 126 129 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) ); … … 130 133 if ( is_depth ) 131 134 { 132 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );133 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );135 // glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 136 // glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 134 137 135 138 // This is to allow usage of shadow2DProj function in the shader … … 146 149 // glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso ); 147 150 148 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum(aformat.type), data ); 151 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE ) 152 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum(aformat.type), data ); 153 else 154 glTexImage2DMultisample( gl_type, 4, gl_internal, size.x, size.y, 1 ); 149 155 150 156 glBindTexture( gl_type, 0 ); … … 163 169 nv::texture nv::gl_device::create_texture( texture_type type, pixel_format format ) 164 170 { 165 NV_ASSERT_ALWAYS( type == TEXTURE_1D_BUFFER );171 NV_ASSERT_ALWAYS( type == TEXTURE_1D_BUFFER, "create_texture not texture buffer!" ); 166 172 unsigned glid = 0; 167 unsigned gl_type = texture_type_to_enum( type );168 173 169 174 glGenTextures( 1, &glid ); … … 552 557 NV_ASSERT( u, "Unknown uniform type!" ); 553 558 (*p->m_uniform_map)[ name ] = u; 559 //NV_LOG_DEBUG( "Uniform : ", name, " - ", utype, "/", uni_len ); 560 554 561 } 555 562 -
trunk/src/gl/gl_enum.cc
r491 r492 15 15 switch( type ) 16 16 { 17 case TEXTURE_1D : return GL_TEXTURE_1D; 18 case TEXTURE_2D : return GL_TEXTURE_2D; 19 case TEXTURE_RECT : return GL_TEXTURE_RECTANGLE; 20 case TEXTURE_3D : return GL_TEXTURE_3D; 21 case TEXTURE_CUBE : return GL_TEXTURE_CUBE_MAP; 22 case TEXTURE_1D_ARRAY : return GL_TEXTURE_1D_ARRAY; 23 case TEXTURE_2D_ARRAY : return GL_TEXTURE_2D_ARRAY; 24 case TEXTURE_1D_BUFFER: return GL_TEXTURE_BUFFER; 17 case TEXTURE_1D : return GL_TEXTURE_1D; 18 case TEXTURE_2D : return GL_TEXTURE_2D; 19 case TEXTURE_RECT : return GL_TEXTURE_RECTANGLE; 20 case TEXTURE_3D : return GL_TEXTURE_3D; 21 case TEXTURE_CUBE : return GL_TEXTURE_CUBE_MAP; 22 case TEXTURE_1D_ARRAY : return GL_TEXTURE_1D_ARRAY; 23 case TEXTURE_2D_ARRAY : return GL_TEXTURE_2D_ARRAY; 24 case TEXTURE_1D_BUFFER : return GL_TEXTURE_BUFFER; 25 case TEXTURE_2D_MULTISAMPLE : return GL_TEXTURE_2D_MULTISAMPLE; 25 26 NV_RETURN_COVERED_DEFAULT( 0 ); 26 27 }
Note: See TracChangeset
for help on using the changeset viewer.