Changeset 491 for trunk/src/gl/gl_device.cc
- Timestamp:
- 04/29/16 12:42:28 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_device.cc
r487 r491 17 17 gl_device::gl_device() 18 18 { 19 m_shader_header.append( "#version 330 \n" );19 m_shader_header.append( "#version 330 core\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 NV_ASSERT_ALWAYS( type != TEXTURE_1D_BUFFER && type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" ); 98 98 unsigned glid = 0; 99 99 unsigned gl_type = texture_type_to_enum( type ); 100 GLint gl_internal = GLint( nv::image_format_to_internal_enum( aformat.format ) ); 101 unsigned gl_enum = nv::image_format_to_enum( aformat.format ); 100 102 101 103 bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32; … … 106 108 107 109 // Detect if mipmapping was requested 108 if ( gl_type == GL_TEXTURE_2D && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )110 if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST ) 109 111 { 110 112 // TODO: This should not be done if we use framebuffers! … … 119 121 glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) ); 120 122 glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) ); 121 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s) ) ); 122 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t) ) ); 123 124 if ( gl_enum != GL_RED_INTEGER ) 125 { 126 glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) ); 127 glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) ); 128 } 123 129 124 130 if ( is_depth ) … … 140 146 // glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso ); 141 147 142 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 );148 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum(aformat.type), data ); 143 149 144 150 glBindTexture( gl_type, 0 ); … … 154 160 } 155 161 162 163 nv::texture nv::gl_device::create_texture( texture_type type, pixel_format format ) 164 { 165 NV_ASSERT_ALWAYS( type == TEXTURE_1D_BUFFER ); 166 unsigned glid = 0; 167 unsigned gl_type = texture_type_to_enum( type ); 168 169 glGenTextures( 1, &glid ); 170 171 texture result = m_textures.create(); 172 gl_texture_info* info = m_textures.get( result ); 173 info->type = type; 174 info->format = format; 175 info->tsampler = sampler(); 176 info->size = ivec3( 1, 1, 1 ); 177 info->glid = glid; 178 179 return result; 180 } 181 156 182 nv::texture nv::gl_device::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ ) 157 183 { … … 234 260 nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ ) 235 261 { 236 unsigned glid 262 unsigned glid = 0; 237 263 unsigned glenum = buffer_type_to_enum( type ); 238 264 glGenBuffers( 1, &glid ); 239 265 240 glBindBuffer( glenum, glid ); 241 glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) ); 242 glBindBuffer( glenum, 0 ); 266 if ( size > 0 ) 267 { 268 glBindBuffer( glenum, glid ); 269 glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) ); 270 glBindBuffer( glenum, 0 ); 271 } 243 272 244 273 buffer result = m_buffers.create(); … … 249 278 info->glid = glid; 250 279 return result; 280 } 281 282 void nv::gl_device::create_buffer( buffer b, size_t size, const void* source ) 283 { 284 gl_buffer_info* info = m_buffers.get( b ); 285 if ( info ) 286 { 287 unsigned glenum = buffer_type_to_enum( info->type ); 288 glBindBuffer( glenum, info->glid ); 289 glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( info->hint ) ); 290 glBindBuffer( glenum, 0 ); 291 } 251 292 } 252 293
Note: See TracChangeset
for help on using the changeset viewer.