- Timestamp:
- 08/28/15 18:28:34 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_context.cc
r462 r463 111 111 } 112 112 113 void nv::gl_context::attach( framebuffer f, texture depth )113 void nv::gl_context::attach( framebuffer f, texture depth, int layer /*= -1*/ ) 114 114 { 115 115 // TODO: framebuffer variable, so no re-binding? … … 121 121 glBindFramebuffer( GL_FRAMEBUFFER, info->glid ); 122 122 unsigned gl_type = texture_type_to_enum( tinfo->type ); 123 if ( tinfo ) 124 { 125 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gl_type, tinfo->glid, 0 ); 123 unsigned glid = ( tinfo ? tinfo->glid : 0 ); 124 if ( layer >= 0 ) 125 { 126 glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, tinfo->glid, 0, layer ); 126 127 } 127 128 else 128 129 { 129 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gl_type, 0, 0 ); 130 } 131 } 130 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gl_type, glid, 0 ); 131 } 132 } 133 132 134 } 133 135 … … 328 330 { 329 331 image_format format = info->format; 330 ivec 2size = info->size;332 ivec3 size = info->size; 331 333 unsigned gl_type = texture_type_to_enum( info->type ); 332 334 333 335 glBindTexture( gl_type, info->glid ); 334 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 ); 336 if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY ) 337 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 ); 338 else 339 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 ); 335 340 } 336 341 } … … 690 695 { 691 696 // TODO: configurable: 692 load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT );697 load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY ); 693 698 force_apply_render_state( m_render_state ); 694 699 -
trunk/src/gl/gl_device.cc
r461 r463 17 17 gl_device::gl_device() 18 18 { 19 m_shader_header.append( "#version 120\n " );19 m_shader_header.append( "#version 120\n#extension GL_EXT_texture_array : require\n" ); 20 20 for ( auto& i : get_uniform_factory() ) 21 21 m_shader_header.append( "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ i.first +";\n" ); … … 95 95 nv::texture nv::gl_device::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ ) 96 96 { 97 NV_ASSERT_ALWAYS( type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" ); 97 98 unsigned glid = 0; 98 99 unsigned gl_type = texture_type_to_enum( type ); 100 101 bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32; 102 99 103 glGenTextures( 1, &glid ); 100 104 … … 117 121 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s) ) ); 118 122 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t) ) ); 123 124 if ( is_depth ) 125 { 126 #define GL_TEXTURE_DEPTH_SIZE 0x884A 127 #define GL_DEPTH_TEXTURE_MODE 0x884B 128 #define GL_TEXTURE_COMPARE_MODE 0x884C 129 #define GL_TEXTURE_COMPARE_FUNC 0x884D 130 #define GL_COMPARE_R_TO_TEXTURE 0x884E 131 132 #define GL_INTENSITY 0x8049 133 #define GL_LUMINANCE 0x1909 134 // glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE ); 135 // glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); 136 // glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE ); 137 // glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, 0 ); 138 // glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY ); 139 } 140 141 // #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE 142 // #define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF 143 // 144 // float aniso = 0.0f; 145 // glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso ); 146 // NV_LOG_INFO( "Anisotropy at ", aniso, " (", int( aniso ), " ) " ); 147 // glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso ); 119 148 120 149 glTexImage2D( gl_type, 0, GLint( nv::image_format_to_internal_enum(aformat.format) ), size.x, size.y, 0, nv::image_format_to_enum(aformat.format), nv::datatype_to_gl_enum(aformat.type), data ); … … 127 156 info->format = aformat; 128 157 info->tsampler = asampler; 129 info->size = size;158 info->size = ivec3( size.x, size.y, 1 ); 130 159 info->glid = glid; 131 160 return result; 132 161 } 162 163 nv::texture nv::gl_device::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ ) 164 { 165 NV_ASSERT_ALWAYS( type == TEXTURE_3D || type == TEXTURE_2D_ARRAY, "3D texture type expected!" ); 166 unsigned glid = 0; 167 unsigned gl_type = texture_type_to_enum( type ); 168 169 bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32; 170 171 glGenTextures( 1, &glid ); 172 glBindTexture( gl_type, glid ); 173 174 if ( asampler.filter_max != sampler::NEAREST ) 175 { 176 asampler.filter_max = sampler::LINEAR; 177 } 178 179 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) ); 180 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) ); 181 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) ); 182 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) ); 183 184 //glTexStorage3D( GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount ); 185 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 ); 186 glBindTexture( gl_type, 0 ); 187 188 texture result = m_textures.create(); 189 gl_texture_info* info = m_textures.get( result ); 190 info->type = type; 191 info->format = aformat; 192 info->tsampler = asampler; 193 info->size = size; 194 info->glid = glid; 195 return result; 196 } 197 198 133 199 134 200 void nv::gl_device::release( texture t ) -
trunk/src/gl/gl_enum.cc
r462 r463 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; 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; 22 24 NV_RETURN_COVERED_DEFAULT( 0 ); 23 25 } … … 347 349 case GL_SAMPLER_1D_SHADOW : return INT; 348 350 case GL_SAMPLER_2D_SHADOW : return INT; 349 // TODO: implement? 351 case GL_SAMPLER_1D_ARRAY : return INT; 352 case GL_SAMPLER_2D_ARRAY : return INT; 353 case GL_SAMPLER_1D_ARRAY_SHADOW: return INT; 354 case GL_SAMPLER_2D_ARRAY_SHADOW: return INT; 355 // TODO: implement? 350 356 // case GL_BOOL 351 357 // case GL_BOOL_VEC2 -
trunk/src/lib/gl.cc
r440 r463 269 269 #include <nv/lib/detail/gl_ext/gl_ext_framebuffer_object_functions.inc> 270 270 } break; 271 case GL_EXT_TEXTURE_ARRAY: { 272 #include <nv/lib/detail/gl_ext/gl_ext_texture_array_functions.inc> 273 } break; 271 274 default : { 272 275 NV_LOG_ERROR( "load_gl_extension - unknown extension \"", name, "\"!" );
Note: See TracChangeset
for help on using the changeset viewer.