Changeset 501 for trunk/src/gl/gl_context.cc
- Timestamp:
- 06/15/16 18:34:37 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_context.cc
r500 r501 66 66 } 67 67 } 68 glBindBuffer( GL_ARRAY_BUFFER, 0 );69 68 glBindVertexArray( 0 ); 70 69 … … 104 103 { 105 104 if ( info->attr[i].owner ) 106 m_device->release( info->attr[i].vbuffer );107 } 108 if ( info->index.is_valid() && info->index_owner) m_device->release( info->index );105 release( info->attr[i].vbuffer ); 106 } 107 if ( info->index.is_valid() && info->index_owner) release( info->index ); 109 108 glDeleteVertexArrays( 1, &info->glid ); 110 109 m_vertex_arrays.destroy( va ); … … 223 222 glBindFramebuffer( GL_DRAW_FRAMEBUFFER, tinfo ? tinfo->glid : 0 ); 224 223 unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST; 225 int remove_below;226 filter = GL_NEAREST;227 224 glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter ); 228 225 glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); … … 270 267 } 271 268 269 272 270 void nv::gl_context::bind( buffer b, texture t ) 273 271 { … … 304 302 set_active_texture( slot ); 305 303 glBindTexture( texture_type_to_enum( info->type ), info->glid ); 304 m_bound_textures[slot] = t; 306 305 } 307 306 } … … 314 313 if ( info ) 315 314 { 316 glUseProgram( info->glid ); 315 if ( m_bound_program != p ) 316 glUseProgram( info->glid ); 317 317 gdevice->update_uniforms( info ); 318 318 if ( !info->validated ) … … 320 320 validate_program( p ); 321 321 } 322 m_bound_program = p; 322 323 } 323 324 } … … 369 370 void nv::gl_context::unbind( program ) 370 371 { 371 glUseProgram( 0 ); 372 if ( m_bound_program ) 373 glUseProgram( 0 ); 374 m_bound_program = program(); 372 375 } 373 376 … … 375 378 { 376 379 if ( slot != m_active_slot ) 380 { 377 381 glActiveTexture( GL_TEXTURE0 + static_cast<GLenum>( slot ) ); 382 m_active_slot = slot; 383 } 378 384 } 379 385 … … 419 425 unsigned gl_type = texture_type_to_enum( info->type ); 420 426 421 if ( m_bound_textures[ m_active_slot ] != t ) 422 glBindTexture( gl_type, info->glid ); 423 int this_should_be_subTexImage; 427 bind( t, texture_slot::TEXTURE_0 ); 424 428 if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY ) 425 glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data ); 429 // glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data ); 430 glTexSubImage3D( gl_type, 0, 0, 0, 0, size.x, size.y, size.z, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data ); 426 431 else 427 glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format.format) ), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data ); 432 // glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format.format) ), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data ); 433 glTexSubImage2D( gl_type, 0, 0, 0, size.x, size.y, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data ); 428 434 } 429 435 } … … 518 524 void gl_context::set_viewport( const ivec4& viewport ) 519 525 { 520 NV_ASSERT_ALWAYS( viewport.z > 0 && viewport.w > 0, "viewport dimensions must be greater than zero!" ); 521 m_viewport = viewport; 522 glViewport( viewport.x, viewport.y, viewport.z, viewport.w ); 526 if ( m_viewport != viewport ) 527 { 528 NV_ASSERT_ALWAYS( viewport.z > 0 && viewport.w > 0, "viewport dimensions must be greater than zero!" ); 529 m_viewport = viewport; 530 glViewport( viewport.x, viewport.y, viewport.z, viewport.w ); 531 } 523 532 } 524 533 … … 860 869 } 861 870 871 nv::texture nv::gl_context::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ ) 872 { 873 texture result = create_texture( type, aformat.format ); 874 gl_texture_info* info = static_cast<gl_device*>( m_device )->get_full_texture_info( result ); 875 bind( result, texture_slot::TEXTURE_0 ); 876 unsigned glid = info->glid; 877 unsigned gl_type = texture_type_to_enum( type ); 878 GLenum gl_internal = GLenum( image_format_to_internal_enum( aformat.format ) ); 879 unsigned gl_enum = image_format_to_enum( aformat.format ); 880 881 bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32; 882 883 // Detect if mipmapping was requested 884 // if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) 885 // { 886 // // TODO: This should not be done if we use framebuffers! 887 // glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE); 888 // } 889 890 if ( asampler.filter_max != sampler::NEAREST ) 891 { 892 asampler.filter_max = sampler::LINEAR; 893 } 894 895 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE ) 896 { 897 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) ); 898 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) ); 899 } 900 901 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE && gl_enum != GL_RED_INTEGER ) 902 { 903 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) ); 904 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) ); 905 } 906 907 if ( is_depth ) 908 { 909 // glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 910 // glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 911 912 // This is to allow usage of shadow2DProj function in the shader 913 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE ); 914 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); 915 } 916 917 // #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE 918 // #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF 919 // 920 // float aniso = 0.0f; 921 // glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso ); 922 // NV_LOG_INFO( "Anisotropy at ", aniso, " (", int( aniso ), " ) " ); 923 // glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso ); 924 925 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE ) 926 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum( aformat.type ), data ); 927 else 928 glTexImage2DMultisample( gl_type, 4, gl_internal, size.x, size.y, 1 ); 929 930 if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) 931 { 932 // TODO: This should not be done if we use framebuffers! 933 glGenerateMipmap( gl_type ); 934 } 935 936 bind( texture(), texture_slot::TEXTURE_0 ); 937 938 info->type = type; 939 info->format = aformat; 940 info->tsampler = asampler; 941 info->size = ivec3( size.x, size.y, 1 ); 942 info->glid = glid; 943 944 return result; 945 } 946 947 nv::texture nv::gl_context::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ ) 948 { 949 texture result = create_texture( type, aformat.format ); 950 gl_texture_info* info = static_cast<gl_device*>( m_device )->get_full_texture_info( result ); 951 bind( result, texture_slot::TEXTURE_0 ); 952 unsigned glid = info->glid; 953 954 unsigned gl_type = texture_type_to_enum( type ); 955 956 bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32; 957 958 if ( asampler.filter_max != sampler::NEAREST ) 959 { 960 asampler.filter_max = sampler::LINEAR; 961 } 962 963 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) ); 964 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) ); 965 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) ); 966 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) ); 967 968 if ( is_depth ) 969 { 970 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 971 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 972 973 // This is to allow usage of shadow2DProj function in the shader 974 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE ); 975 glTexParameteri( gl_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); 976 } 977 978 //glTexStorage3D( GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount ); 979 glTexImage3D( gl_type, 0, GLint( nv::image_format_to_internal_enum( aformat.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( aformat.format ), nv::datatype_to_gl_enum( aformat.type ), data ); 980 981 bind( texture(), texture_slot::TEXTURE_0 ); 982 983 info->type = type; 984 info->format = aformat; 985 info->tsampler = asampler; 986 info->size = size; 987 info->glid = glid; 988 989 return result; 990 } 991 992 nv::buffer nv::gl_context::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ ) 993 { 994 buffer result = static_cast<gl_device*>( m_device )->create_buffer( type, hint ); 995 if ( size > 0 ) create_buffer( result, size, source ); 996 return result; 997 } 998 999 void nv::gl_context::create_buffer( buffer b, size_t size, const void* source /*= nullptr */ ) 1000 { 1001 gl_buffer_info* info = static_cast<gl_device*>( m_device )->get_full_buffer_info( b ); 1002 if ( info ) 1003 { 1004 unsigned glenum = buffer_type_to_enum( info->type ); 1005 glBindBuffer( glenum, info->glid ); 1006 glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( info->hint ) ); 1007 glBindBuffer( glenum, 0 ); 1008 } 1009 } 1010 862 1011 void nv::gl_context::set_draw_buffers( uint32 count, const output_slot* slots ) 863 1012 {
Note: See TracChangeset
for help on using the changeset viewer.